When HXCPP_GC_GENERATIONAL is enabled, assigning a cpp.Function instance field emits a generational write barrier even though cpp::Function is a native function-pointer wrapper rather than a GC object.
This affects Haxe 4.3.7 and the current development branch (2f724abd255c5c0204d350c55bc64068c18c4ad1).
Minimal reproduction:
class Main {
static function main():Void {
var holder = new NativeCallbackHolder(cpp.Callable.fromStaticFunction(increment));
if (holder.callback.call(41) != 42) {
throw "Invalid native callback result";
}
}
static function increment(value:Int):Int {
return value + 1;
}
}
class NativeCallbackHolder {
public var callback:cpp.Function<Int->Int, cpp.abi.Abi>;
public function new(callback:cpp.Function<Int->Int, cpp.abi.Abi>) {
this.callback = callback;
}
}
-main Main
-D HXCPP_GC_GENERATIONAL
-cpp out
The generated setter uses HX_OBJ_WB_SET for the field. That macro expects an object-like value with an mPtr member, which cpp::Function<int(int)> does not have, so the generated C++ fails to compile:
error: cpp::Function<int(int)> has no member named mPtr
Without HXCPP_GC_GENERATIONAL, the same program compiles and runs successfully.
Expected behavior: cpp.Function fields should not receive GC write barriers, and the program should compile and return the expected callback result.
When
HXCPP_GC_GENERATIONALis enabled, assigning acpp.Functioninstance field emits a generational write barrier even thoughcpp::Functionis a native function-pointer wrapper rather than a GC object.This affects Haxe 4.3.7 and the current development branch (
2f724abd255c5c0204d350c55bc64068c18c4ad1).Minimal reproduction:
The generated setter uses
HX_OBJ_WB_SETfor the field. That macro expects an object-like value with anmPtrmember, whichcpp::Function<int(int)>does not have, so the generated C++ fails to compile:Without
HXCPP_GC_GENERATIONAL, the same program compiles and runs successfully.Expected behavior:
cpp.Functionfields should not receive GC write barriers, and the program should compile and return the expected callback result.