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
C++ deletes objects still referenced by Python wrappers (dangling pointers, double free) #132
Several bound C++ methods delete sub-objects (profiles, parameters, atoms) that Python may still hold through wrappers (reference_internal). A held wrapper then dangles. With nanobind, a new object allocated at the same address can be returned as the stale wrapper, possibly with the wrong type. This is the root cause of the intermittent failure in #121. The underlying issue is that ObjCryst manages ownership manually (RegisterClient/delete) rather than with reference counting shared with Python.
Checked against vendored ObjCryst ba6ca89 with the rc0 wheel (macOS arm64, cp312, MallocScribble=1).
Confirmed crashes
Python call
Deleted by C++
Result
Crystal.ConnectAtoms()
merged atoms, via RemoveScatterer(atom, true) (delete is hard-coded, so SetDeleteSubObjInDestructor(false) has no effect)
Internal-only objects (mpGaussian, cctbx space group, temporaries) and functions that are not bound.
Proposed solution
Short term: the bindings take ownership of the old object (nb::find + nb::inst_set_state(w, true, true)), or forbid or invalidate held wrappers. ConnectAtoms must honour the del convention.
Long term (upstream in vincefn/objcryst): reference counting in RefinableObj via (De)RegisterClient, shared with Python through nanobind intrusive reference counting.
Activity
fix: keep Python wrappers valid when ObjCryst++ releases sub-objects