Skip to content

CPPIA JIT: typed-array helper exceptions bypass script catches and terminate the host #404

Open

Description

@dimensionscape

CPPIA's JIT terminates the host when these typed-array operations throw, even when the script wraps the operation in try/catch:

  • cpp.NativeArray.blit(dest, -1, source, 0, 1) with two-element Int arrays.
  • cpp.NativeArray.setSize(values, -1) with a two-element Int array.
  • values.resize(0x40000000) with an Int array. The runtime rejects the element count before allocating the buffer.

The same script catches all three exceptions and continues under the interpreter and native C++. A mixed Array<Dynamic> blit with an invalid source range also recovers under both CPPIA engines in this test.

Minimal example:

var values = [7, 8];
try {
    cpp.NativeArray.setSize(values, -1);
} catch (e:Dynamic) {
    Sys.println("caught");
}
Sys.println("continued");

Expected: the script catches the exception and continues with the original array intact.

Observed on Windows x64: the JIT child exits with -529697949 (0xE06D7363, an unhandled C++ exception). Neither the script catch nor the host catch around Host.runFile runs.

src/hx/cppia/ArrayBuiltin.cpp calls runBlit, runSetSizeExact and runResize directly from generated code. These helpers do not use TRY_NATIVE / CATCH_NATIVE, and their call sites do not check the pending exception. Helpers such as runSort and runToString already use that exception bridge.

Added the conventional local regression fixture test/regression/CppiaBlitException/{Script.hx,Main.hx,build.hxml,stdout.txt} before reporting. It runs each engine and operation in a separate child, checks array contents after the catch, and includes a valid blit and the dynamic-array control. No runtime fix is included. The fixture is local and has not been committed.

Validation on 4cdca96, Haxe 4.3.7, MSVC 19.44, Windows x64 release:

Case Native C++ Interpreter JIT
Typed blit range error Pass Pass Process exits
Dynamic blit range error Pass Pass Pass
Negative exact size Pass Pass Process exits
Resize size limit Pass Pass Process exits

The fix belongs in libhxcpp's JIT/native exception bridge and does not require a compiler or stdlib change. This is separate from #66, which concerned script exceptions returning to native callers.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions