This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add API to allow extensions to set callback function on creation and destruction of PyCodeObject
Type: enhancement Stage:
Components: C API Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: carljm, dino.viehland, itamaro, mpage
Priority: normal Keywords:

Created on 2022-03-01 22:20 by mpage, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg414309 - (view) Author: Matt Page (mpage) * Date: 2022-03-01 22:20
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();

```
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 91054
2022-03-01 22:20:58mpagecreate