gh-93502: Add new C-API functions to trace object creation and destruction (#115945)

This commit is contained in:
Pablo Galindo Salgado 2024-05-02 19:30:00 +02:00 committed by GitHub
parent 2770d5caca
commit 6bcbee09df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 207 additions and 8 deletions

View file

@ -257,7 +257,7 @@ extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);
when a memory block is reused from a free list.
Internal function called by _Py_NewReference(). */
extern int _PyTraceMalloc_NewReference(PyObject *op);
extern int _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event, void*);
// Fast inlined version of PyType_HasFeature()
static inline int

View file

@ -132,6 +132,12 @@ typedef struct _Py_DebugOffsets {
} unicode_object;
} _Py_DebugOffsets;
/* Reference tracer state */
struct _reftracer_runtime_state {
PyRefTracer tracer_func;
void* tracer_data;
};
/* Full Python runtime state */
/* _PyRuntimeState holds the global state for the CPython runtime.
@ -236,6 +242,7 @@ typedef struct pyruntimestate {
struct _fileutils_state fileutils;
struct _faulthandler_runtime_state faulthandler;
struct _tracemalloc_runtime_state tracemalloc;
struct _reftracer_runtime_state ref_tracer;
// The rwmutex is used to prevent overlapping global and per-interpreter
// stop-the-world events. Global stop-the-world events lock the mutex

View file

@ -128,6 +128,10 @@ extern PyTypeObject _PyExc_MemoryError;
}, \
.faulthandler = _faulthandler_runtime_state_INIT, \
.tracemalloc = _tracemalloc_runtime_state_INIT, \
.ref_tracer = { \
.tracer_func = NULL, \
.tracer_data = NULL, \
}, \
.stoptheworld = { \
.is_global = 1, \
}, \