Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/hx/cppia/Cppia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,13 @@ struct NewExpr : public CppiaDynamicExpr
if (!type->cppiaClass && type->haxeClass.mPtr)
constructor = type->haxeClass.mPtr->mConstructArgs;

// Nothing to construct: runObject and genCode would dereference the null cppiaClass.
if (!type->arrayType && !constructor && !type->cppiaClass)
{
CPPIALOG("Could not link new %s\n", type->name.c_str());
throw "Bad link";
}

LinkExpressions(args,inModule);
return this;
}
Expand Down
13 changes: 13 additions & 0 deletions test/cppia/ClientUnlinked.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// The host does not have this class: a module constructing it must fail to link.
extern class Unlinked
{
public function new();
}

class ClientUnlinked
{
public static function main()
{
new Unlinked();
}
}
6 changes: 6 additions & 0 deletions test/cppia/cases/TestCommon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class TestCommon extends Test {
Assert.equals(2, Common.callbackSet, 'Bad cppia closure');
}

function testNewOfUnlinkedClass() {
final source = sys.io.File.getBytes('bin/unlinked.cppia');

Assert.raises(() -> cpp.cppia.Module.fromData(source.getData()), String, 'Linked a new of a class the host does not have');
}

@:depends(testStatus)
function testInterfaceCalling() {
final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []);
Expand Down
7 changes: 6 additions & 1 deletion test/cppia/compile-client.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-m Client
-D dll_import=host_classes.info
--cppia bin/client.cppia
--cppia bin/client.cppia

--next

-m ClientUnlinked
--cppia bin/unlinked.cppia