Skip to content

Commit 48d54dc

Browse files
Tutez64dimensionscape
authored andcommitted
Barrier the pointer stores of a cppia field set by name.
CppiaVar::setValue, behind Reflect.setField and Reflect.setProperty on a cppia instance, stored object and string pointers without a generational write barrier. A young value set on an old instance was reachable only through it, so the next minor collection freed it, and the instance then pointed at reused memory. The JIT and interpreted field setters already had the barrier. HaxeFoundation/hxcpp#1408 Fixes #24
1 parent 8b52508 commit 48d54dc

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/hx/cppia/CppiaVars.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ Dynamic CppiaVar::setValue(hx::Object *inThis, Dynamic inValue)
220220
case fsInt: *(int *)(base) = inValue; return inValue;
221221
case fsBool: *(bool *)(base) = inValue; return inValue;
222222
case fsFloat: *(Float *)(base) = inValue; return inValue;
223-
case fsString: *(String *)(base) = inValue; return inValue;
223+
case fsString:
224+
*(String *)(base) = inValue;
225+
#ifdef HXCPP_GC_GENERATIONAL
226+
HX_OBJ_WB_GET(inThis, hx::PointerOf(*(String *)(base)));
227+
#endif
228+
return inValue;
224229
case fsObject:
225230
switch(type->arrayType)
226231
{
@@ -252,6 +257,10 @@ Dynamic CppiaVar::setValue(hx::Object *inThis, Dynamic inValue)
252257
*(Array<Dynamic> *)(base) = inValue;
253258
break;
254259
}
260+
// Every case above stores one object pointer at base.
261+
#ifdef HXCPP_GC_GENERATIONAL
262+
HX_OBJ_WB_GET(inThis, *(hx::Object **)(base));
263+
#endif
255264
return inValue;
256265
case fsUnknown:
257266
break;

0 commit comments

Comments
 (0)