From 08fc215726f150a9b678b9666d40f41f7c4c7e1c Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 19 Oct 2025 18:52:33 +0100 Subject: [PATCH 1/3] Fix cpp.Pointer.ofArray with empty arrays array[0] had a side effect of extending an empty array to size 1. Now, the pointer is retrieved directly without the [] access which prevents the array being extended. --- include/cpp/Pointer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cpp/Pointer.h b/include/cpp/Pointer.h index 25c28b451..d1899df0c 100644 --- a/include/cpp/Pointer.h +++ b/include/cpp/Pointer.h @@ -499,7 +499,7 @@ class Pointer_obj } template - inline static AutoCast ofArray(::Array array) { return AutoCast(&array[0]); } + inline static AutoCast ofArray(::Array array) { return AutoCast(array->Pointer()); } inline static AutoCast ofArray(Dynamic inVal) { if (inVal==null() || !inVal->__IsArray()) From e7ebe4e1340dd7d0cadd8d1103c24331fe920297 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 19 Oct 2025 18:50:09 +0100 Subject: [PATCH 2/3] [ci] Add support for regression tests --- .github/workflows/test.yml | 16 ++++++++++ test/regression/Run.hx | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 test/regression/Run.hx diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2e3ddbf6d..2289108c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -221,3 +221,19 @@ jobs: run: haxe compile-cpp.hxml -D ${{ env.HXCPP_ARCH_FLAG }} -D no_http - name: run run: bin${{ inputs.sep }}cpp${{ inputs.sep }}TestMain-debug + + regression: + runs-on: ${{ inputs.os }} + name: regression tests + defaults: + run: + working-directory: test/regression + steps: + - name: checkout + uses: actions/checkout@v4 + - name: setup + uses: ./.github/workflows/setup + with: + haxe: ${{ inputs.haxe }} + - name: run + run: haxe --run Run -D ${{ env.HXCPP_ARCH_FLAG }} diff --git a/test/regression/Run.hx b/test/regression/Run.hx new file mode 100644 index 000000000..a233a18c7 --- /dev/null +++ b/test/regression/Run.hx @@ -0,0 +1,60 @@ +import sys.io.Process; +import sys.io.File; +import sys.FileSystem; + +using StringTools; + +function runOutput(test:String):String { + final slash = Sys.systemName() == "Windows" ? "\\" : "/"; + final proc = new Process([test, "bin", 'Main'].join(slash)); + final code = proc.exitCode(); + + if (code != 0) { + throw 'return code was $code'; + } + + return proc.stdout.readAll().toString().replace("\r\n", "\n"); +} + +function main() { + var successes = 0; + var total = 0; + + final args = Sys.args(); + + for (test in FileSystem.readDirectory(".")) { + if (!FileSystem.isDirectory(test)) { + continue; + } + + total++; + + final buildExitCode = Sys.command("haxe", ["-C", test, "build.hxml"].concat(args)); + if (buildExitCode != 0) { + Sys.println('Failed to build test $test. Exit code: $buildExitCode'); + continue; + } + + final expectedStdout = File.getContent('$test/stdout.txt').replace("\r\n", "\n"); + final actualStdout = try { + runOutput(test); + } catch (e) { + Sys.println('Test $test failed: $e'); + continue; + }; + + if (actualStdout != expectedStdout) { + Sys.println('Test $test failed: Output did not match'); + + Sys.println("Expected stdout:"); + Sys.println(expectedStdout); + Sys.println("Actual stdout:"); + Sys.println(actualStdout); + continue; + } + + successes++; + } + + Sys.println('Regression tests complete. Successes: $successes / $total'); +} From 773d932d392716f4de3004edb9f3a8bc3e39b82e Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 19 Oct 2025 20:06:54 +0100 Subject: [PATCH 3/3] Add test for cpp.Pointer.ofArray with empty array --- test/regression/Issue1028/Main.hx | 7 +++++++ test/regression/Issue1028/build.hxml | 2 ++ test/regression/Issue1028/stdout.txt | 1 + 3 files changed, 10 insertions(+) create mode 100644 test/regression/Issue1028/Main.hx create mode 100644 test/regression/Issue1028/build.hxml create mode 100644 test/regression/Issue1028/stdout.txt diff --git a/test/regression/Issue1028/Main.hx b/test/regression/Issue1028/Main.hx new file mode 100644 index 000000000..86f94f7cc --- /dev/null +++ b/test/regression/Issue1028/Main.hx @@ -0,0 +1,7 @@ +class Main { + static function main() { + var array:Array = []; + cpp.Pointer.ofArray(array); + trace(array.length); + } +} diff --git a/test/regression/Issue1028/build.hxml b/test/regression/Issue1028/build.hxml new file mode 100644 index 000000000..ea891d9fc --- /dev/null +++ b/test/regression/Issue1028/build.hxml @@ -0,0 +1,2 @@ +--cpp bin +-m Main diff --git a/test/regression/Issue1028/stdout.txt b/test/regression/Issue1028/stdout.txt new file mode 100644 index 000000000..d6a5d4108 --- /dev/null +++ b/test/regression/Issue1028/stdout.txt @@ -0,0 +1 @@ +Main.hx:5: 0