diff --git a/test/regression/CppiaAdoptInstances/Main.hx b/test/regression/CppiaAdoptInstances/Main.hx index c644647a0..1f42b21dd 100644 --- a/test/regression/CppiaAdoptInstances/Main.hx +++ b/test/regression/CppiaAdoptInstances/Main.hx @@ -10,7 +10,12 @@ import cpp.cppia.Module; // // Every call into script code runs on a joined native worker, so stale values // it leaves on a stack do not decide what keeps a module loaded. The main -// thread only collects and prints. +// thread only collects and prints. The collection that counts what a module +// keeps scans the frames it runs in for pointers, and a slot nothing has +// written yet still holds what an earlier call left there, which can be the +// address of an object freed since and of a closure of the old module now: +// once, under ASan on Linux, the count found two closures where one stayed. +// So the stack below main's frame is cleared before each count @:cppFileCode(' #include #include @@ -19,6 +24,16 @@ static void runJoined(Dynamic callback) { hx::AutoGCFreeZone freeZone; worker.join(); } +#ifdef _MSC_VER +__declspec(noinline) +#else +__attribute__((noinline)) +#endif +static void clearStack() { + void * volatile area[8192]; + for (int i = 0; i < 8192; i++) + area[i] = 0; +} ') class Main { static var dir:String; @@ -100,8 +115,10 @@ class Main { untyped __cpp__("runJoined({0})", adopt); untyped __cpp__("runJoined({0})", useMoved); untyped __cpp__("runJoined({0})", useOld); + untyped __cpp__("clearStack()"); lines.push('the old module keeps only what stayed: ${retained()}'); untyped __cpp__("runJoined({0})", dropOld); + untyped __cpp__("clearStack()"); lines.push('and is freed once they go: "${retained()}"'); untyped __cpp__("runJoined({0})", dropAll); for (line in lines)