Expand description
FFI types and functions for time event handling.
The TimeEventHandler_API handed to Cython stores only a borrowed Py<PyAny>*
(callback_ptr). To make sure the pointed-to Python object stays alive while
any handler referencing it exists, we keep a single Arc<Py<PyAny>> per raw
pointer in an internal registry together with a manual reference counter.
Why a registry instead of extra fields:
- The C ABI must remain
struct { TimeEvent, char * }- adding bytes to the struct would break all generated headers. Arc<Py<..>>guarantees GIL-safe INC/DEC but cannot be represented in C. Storing it externally preserves layout while retaining safety.
Drop strategy:
- Cloning a handler increments the per-pointer counter.
- Dropping a handler decrements it; if the count hits zero we remove the
entry then release the
ArcunderPython::attach. The drop happens outside the mutex guard to avoid dead-locking when Python finalisers re-enter the registry.
This design removes all manual INCREF/DECREF on callback_ptr, eliminates
leaks, and is safe on any thread.
Structs§
- Time
Event Handler_ API - FFI time event handler for Cython interoperability.
Functions§
- cleanup_
callback_ registry - dummy
- registry_
size - time_
event_ handler_ drop - Drops a
TimeEventHandler_API, releasing any Python callback reference. - time_
event_ ⚠new - Safety
- time_
event_ to_ cstr - Returns a
TimeEventas a C string pointer.