Skip to content

Commit 1612cea

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 68f1a45 commit 1612cea

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
@@ -227,7 +227,12 @@ Dynamic CppiaVar::setValue(hx::Object *inThis, Dynamic inValue)
227227
case fsInt: *(int *)(base) = inValue; return inValue;
228228
case fsBool: *(bool *)(base) = inValue; return inValue;
229229
case fsFloat: *(Float *)(base) = inValue; return inValue;
230-
case fsString: *(String *)(base) = inValue; return inValue;
230+
case fsString:
231+
*(String *)(base) = inValue;
232+
#ifdef HXCPP_GC_GENERATIONAL
233+
HX_OBJ_WB_GET(inThis, hx::PointerOf(*(String *)(base)));
234+
#endif
235+
return inValue;
231236
case fsObject:
232237
switch(type->arrayType)
233238
{
@@ -259,6 +264,10 @@ Dynamic CppiaVar::setValue(hx::Object *inThis, Dynamic inValue)
259264
*(Array<Dynamic> *)(base) = inValue;
260265
break;
261266
}
267+
// Every case above stores one object pointer at base.
268+
#ifdef HXCPP_GC_GENERATIONAL
269+
HX_OBJ_WB_GET(inThis, *(hx::Object **)(base));
270+
#endif
262271
return inValue;
263272
case fsUnknown:
264273
break;

0 commit comments

Comments
 (0)