You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prevent copying thread-attachment and GC-free-zone ownership guards #227
hx::NativeAttach and hx::AutoGCFreeZone are scope owners but permit implicit copying and copy assignment. A copy duplicates the ownership flag without performing another attach or GC-free-zone entry, while both destructors still perform cleanup.
Regression coverage first: test/regression/GcScopeOwnership in the existing Main.hx/build.hxml/stdout.txt layout. Check copy construction and copy assignment through std::type_traits. These ownership guards should prevent accidental copying. Keep explicit move or ownership-transfer behavior a separate design choice.
A separate native probe exercised a copied NativeAttach on the already-attached main thread:
int before = hx::GcGetThreadAttachedCount();
{
hx::NativeAttach original;
{ hx::NativeAttach duplicate = original; }
// Query attachment count while original is still alive.
}
// Query again after original is destroyed.
The observed counts were 1, 1, 0. They should have been 1, 2, 1 if the original guard's attachment remains owned until its destructor. The probe restored the missing attachment count before returning and did not perform a GC allocation while the counter was unbalanced.
include/hx/Native.h stores isAttached on NativeAttach. Its compiler-generated copy operations copy that flag, and both destructors call detach. On a temporarily attached native thread this can release registration while an outer guard is still alive, removing its stack from GC scanning too early. On an already-attached thread the same copy corrupts the nesting count.
include/hx/GC.h has the corresponding ownership problem in AutoGCFreeZone: copying locked allows multiple exits for one entry. That class's copyability was verified, but this report does not claim a reproduced zone-mismatch crash. Copy assignment can also overwrite an existing ownership state without releasing it.
Delete copy construction and copy assignment for both classes, or implement explicitly defined ownership semantics. If moves are supported, clear the source's ownership and test destruction after transfer. Keep normal nested independently constructed guards working, and verify exception unwinding restores attachment and GC-zone state.
This affects native integrations that copy these C++ helpers, not normal Haxe value assignment. No runtime implementation changes are included.
Activity
Make the native attach and GC-free-zone guards non-copyable