Skip to content
Merged
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();
}
}
2 changes: 1 addition & 1 deletion test/cppia/CppiaHost.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class CppiaHost extends Test
// load cppia client
Host.main();

UTest.run(Common.CLIENT_CASES.concat([ new cases.TestCommon() ]));
UTest.run(Common.CLIENT_CASES.concat([new cases.TestCommon(), new cases.TestLoad()]));
}
}
12 changes: 12 additions & 0 deletions test/cppia/cases/TestLoad.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cases;

import utest.Test;
import utest.Assert;

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

Assert.exception(() -> cpp.cppia.Module.fromData(source.getData()), String, (e) -> e == 'Bad link', 'Linked a new of a class the host does not have');
}
}
5 changes: 5 additions & 0 deletions test/cppia/compile-client.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ cases.client.TestClient
-D dll_import=host_classes.info
-L utest
--cppia bin/client.cppia

--next
Comment thread
tobil4sk marked this conversation as resolved.
Resolved

-m ClientUnlinked
--cppia bin/unlinked.cppia
Loading