Skip to content

Commit 0d623b7

Browse files
Give cpp::Function a null mPtr for generational write barriers
With HXCPP_GC_GENERATIONAL, Haxe 4.3.7 writes a barrier on _hx_v.mPtr in the setter of every cpp.Function field, and cpp::Function had no mPtr, so any class with such a field failed to compile. A static null mPtr under HXCPP_GC_GENERATIONAL makes the barrier compile and do nothing; HX_OBJ_WB skips a null value, and a function pointer is not a GC object. HaxeFoundation/haxe#13002 stops the generator emitting the barrier, for compilers that have it. From HaxeFoundation/hxcpp#1425 by Tutez64. Fixes #167 Co-authored-by: Enzo Persillet (Tutez) <enzopersillet@gmail.com>
1 parent f1f5277 commit 0d623b7

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎Changes.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
libhxcpp 6.0.0 (unreleased)
33
------------------------------------------------------------
44

5+
* Fixed a class with a cpp.Function field failing to compile with HXCPP_GC_GENERATIONAL: Haxe 4.3 write barriers the field's setter as if it held an object, and cpp::Function now has the null mPtr that barrier needs (HaxeFoundation/hxcpp#1425 by Tutez64)
6+
57
libhxcpp 6.0.0-rc.1
68
------------------------------------------------------------
79

‎include/cpp/Pointer.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ class Function
426426
public:
427427
T *call;
428428

429+
#ifdef HXCPP_GC_GENERATIONAL
430+
// Haxe versions without HaxeFoundation/haxe#13002 write barrier cpp.Function
431+
// fields as objects. A null mPtr turns those barriers into no-ops.
432+
static constexpr hx::Object *mPtr = 0;
433+
#endif
434+
429435
inline Function( ) { }
430436
inline Function( const Function &inRHS ) : call(inRHS.call) { }
431437
inline Function( const Dynamic &inRHS) { call = inRHS==null()?0: (T*)inRHS->__GetHandle(); }

‎test/haxe/TestTypes.hx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class TestTypes extends Test
1212
var i6:cpp.UInt8 = 1;
1313
var i7:cpp.Int16 = 1;
1414
var i8:cpp.UInt16 = 1;
15+
var callback:cpp.Function<Int->Int, cpp.abi.Abi>;
1516

1617
public function new() super();
1718

@@ -49,4 +50,15 @@ class TestTypes extends Test
4950
Assert.equals(d.i6, 1);
5051
Assert.equals(d.i7, 1);
5152
}
53+
54+
static function increment(value:Int):Int
55+
{
56+
return value + 1;
57+
}
58+
59+
public function testFunctionField()
60+
{
61+
callback = cpp.Function.fromStaticFunction(increment);
62+
Assert.equals(callback.call(41), 42);
63+
}
5264
}

0 commit comments

Comments
 (0)