From 4c74212132f3f57fa6bbc865f31277a1ecc08d28 Mon Sep 17 00:00:00 2001 From: "Enzo Persillet (Tutez)" Date: Sat, 3 Oct 2026 00:40:06 +0200 Subject: [PATCH 1/3] Report a cppia new with nothing to construct as a link failure. NewExpr::link left a NEW whose type was neither an array, a host class with a constructor, nor a script class, and both paths then dereferenced the null cppiaClass: runObject when the line ran, and genCode while the JIT compiled the module. It now reports "Could not link new" and throws "Bad link", as the other link failures do. Co-Authored-By: Claude Opus 5.5 --- src/hx/cppia/Cppia.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hx/cppia/Cppia.cpp b/src/hx/cppia/Cppia.cpp index 4ef92a0a7..669a892c2 100644 --- a/src/hx/cppia/Cppia.cpp +++ b/src/hx/cppia/Cppia.cpp @@ -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; } From 5cbf9967fe451d26a2a6f2484bf27f661c454ad5 Mon Sep 17 00:00:00 2001 From: "Enzo Persillet (Tutez)" Date: Sat, 3 Oct 2026 16:41:33 +0200 Subject: [PATCH 2/3] Test a cppia new of a class the host does not have. ClientUnlinked constructs an extern class, which the cppia module only names. Loading it must fail to link: before the fix, the JIT segfaulted while compiling the module, and without the JIT the load succeeded and left a null class to construct. Co-Authored-By: Claude Opus 5.5 --- test/cppia/ClientUnlinked.hx | 13 +++++++++++++ test/cppia/cases/TestCommon.hx | 6 ++++++ test/cppia/compile-client.hxml | 5 +++++ 3 files changed, 24 insertions(+) create mode 100644 test/cppia/ClientUnlinked.hx diff --git a/test/cppia/ClientUnlinked.hx b/test/cppia/ClientUnlinked.hx new file mode 100644 index 000000000..c48769c07 --- /dev/null +++ b/test/cppia/ClientUnlinked.hx @@ -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(); + } +} diff --git a/test/cppia/cases/TestCommon.hx b/test/cppia/cases/TestCommon.hx index cbbb3a20a..f83f52b04 100644 --- a/test/cppia/cases/TestCommon.hx +++ b/test/cppia/cases/TestCommon.hx @@ -55,6 +55,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'); + } + function testInterfaceCalling() { final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []); diff --git a/test/cppia/compile-client.hxml b/test/cppia/compile-client.hxml index 686135e2c..18c0996d5 100644 --- a/test/cppia/compile-client.hxml +++ b/test/cppia/compile-client.hxml @@ -3,3 +3,8 @@ cases.client.TestClient -D dll_import=host_classes.info -L utest --cppia bin/client.cppia + +--next + +-m ClientUnlinked +--cppia bin/unlinked.cppia From 50df98f636e806f109dcacfa2ea95c0aa7d61727 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Mon, 2 Nov 2026 22:54:24 +0000 Subject: [PATCH 3/3] Adjust unlinked cppia test Move it out of TestCommon, since that is for testing values shared between client and host. --- test/cppia/CppiaHost.hx | 2 +- test/cppia/cases/TestCommon.hx | 6 ------ test/cppia/cases/TestLoad.hx | 12 ++++++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 test/cppia/cases/TestLoad.hx diff --git a/test/cppia/CppiaHost.hx b/test/cppia/CppiaHost.hx index 46f93dc62..5eae36229 100644 --- a/test/cppia/CppiaHost.hx +++ b/test/cppia/CppiaHost.hx @@ -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()])); } } diff --git a/test/cppia/cases/TestCommon.hx b/test/cppia/cases/TestCommon.hx index f83f52b04..cbbb3a20a 100644 --- a/test/cppia/cases/TestCommon.hx +++ b/test/cppia/cases/TestCommon.hx @@ -55,12 +55,6 @@ 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'); - } - function testInterfaceCalling() { final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []); diff --git a/test/cppia/cases/TestLoad.hx b/test/cppia/cases/TestLoad.hx new file mode 100644 index 000000000..51553ac0d --- /dev/null +++ b/test/cppia/cases/TestLoad.hx @@ -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'); + } +}