CPython extensions providing optimized execution of Python bytecode (e.g. the Cinder JIT) may need to hook into the lifecycle of code objects to determine what to optimize or to free resources allocated for code objects that no longer exist. We propose adding an API to allow extensions to set callbacks that will be invoked whenever code objects are created or destroyed.
Proposed API:
```
typedef enum {
PYCODE_LCEVT_CREATED,
PYCODE_LCEVT_DESTROYED
} PyCode_LifecycleEvent;
// A callback to be called when a code object is created or about to be destroyed.
typedef void(*PyCode_LifecycleCallback)(
PyCode_LifecycleEvent event,
PyCodeObject* code);
void PyCode_SetLifecycleCallback(PyCode_LifecycleCallback callback);
PyCode_LifecycleCallback PyCode_GetLifecycleCallback();
```
|