Skip to content

Report a cppia new with nothing to construct as a link failure. - #1410

Open
Tutez64 wants to merge 2 commits into
HaxeFoundation:masterfrom
Tutez64:bugfix/cppia-new-unlinked-class
Open

Tutez64 wants to merge 2 commits into
HaxeFoundation:masterfrom
Tutez64:bugfix/cppia-new-unlinked-class

Conversation

@Tutez64

@Tutez64 Tutez64 commented Oct 2, 2026

Copy link
Copy Markdown

A cppia NEW naming a class the host does not have ends the process instead of failing to link.

NewExpr::link picks how to construct: an array type, a host class's mConstructArgs, or the script class (type->cppiaClass). When none of the three exists it carries on, and then:

  • without the JIT, runObject calls type->cppiaClass->createInstance on a null pointer when the line runs;
  • with the JIT, genCode reads type->cppiaClass while compiling the module, so loading it crashes.

A script built against another version of a host reaches this, as does a generator that names a type with no runtime class (an abstract, for instance). The other link failures report and throw "Bad link" (Could not link static ..., Could not link %s::%s), which LoadCppia turns into an error the host can catch. NewExpr::link now does the same when it has nothing to construct.

Repro (host, two ASCII cppia scripts that differ only in the class name): hxcpp-cppia-new-unlinked-class.zip.
With master, new Missing() segfaults with and without the JIT; with the fix, both print Could not link new Missing and the load throws Bad link, while the script constructing a host class still runs. test/cppia (CppiaHost, with and without -jit): ALL TESTS OK, 15/15 in both.

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 <noreply@anthropic.com>
@tobil4sk

tobil4sk commented Oct 3, 2026

Copy link
Copy Markdown
Member

It would be good to turn the sample into a minimal test case that can fix cleanly into the existing cppia tests

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 <noreply@anthropic.com>
@Tutez64

Tutez64 commented Oct 3, 2026

Copy link
Copy Markdown
Author

Done in 7d2d8cc: ClientUnlinked constructs an extern class the host doesn't have, built by compile-client.hxml, and TestCommon.testNewOfUnlinkedClass checks that loading it throws, so it runs both with and without -jit. Without the fix, the test fails in both modes: the module loads without the JIT, and it segfaults with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants