[New-bugs-announce] [issue46898] Add API to allow extensions to set callback function on creation and destruction of PyCodeObject

Matt Page report at bugs.python.org
Tue Mar 1 17:20:58 EST 2022


New submission from Matt Page <mpage at cs.stanford.edu>:

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();

```

----------
components: C API
messages: 414309
nosy: carljm, dino.viehland, itamaro, mpage
priority: normal
severity: normal
status: open
title: Add API to allow extensions to set callback function on creation and destruction of PyCodeObject
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46898>
_______________________________________


More information about the New-bugs-announce mailing list