mirror of https://github.com/python/cpython
gh-126076: Account for relocated objects in tracemalloc (#126077)
This commit is contained in:
parent
899fdb213d
commit
30aeb00d36
|
@ -94,6 +94,14 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
|
||||||
#define _Py_FatalRefcountError(message) \
|
#define _Py_FatalRefcountError(message) \
|
||||||
_Py_FatalRefcountErrorFunc(__func__, (message))
|
_Py_FatalRefcountErrorFunc(__func__, (message))
|
||||||
|
|
||||||
|
#define _PyReftracerTrack(obj, operation) \
|
||||||
|
do { \
|
||||||
|
struct _reftracer_runtime_state *tracer = &_PyRuntime.ref_tracer; \
|
||||||
|
if (tracer->tracer_func != NULL) { \
|
||||||
|
void *data = tracer->tracer_data; \
|
||||||
|
tracer->tracer_func((obj), (operation), data); \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#ifdef Py_REF_DEBUG
|
#ifdef Py_REF_DEBUG
|
||||||
/* The symbol is only exposed in the API for the sake of extensions
|
/* The symbol is only exposed in the API for the sake of extensions
|
||||||
|
@ -208,11 +216,7 @@ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
|
||||||
#ifdef Py_TRACE_REFS
|
#ifdef Py_TRACE_REFS
|
||||||
_Py_ForgetReference(op);
|
_Py_ForgetReference(op);
|
||||||
#endif
|
#endif
|
||||||
struct _reftracer_runtime_state *tracer = &_PyRuntime.ref_tracer;
|
_PyReftracerTrack(op, PyRefTracer_DESTROY);
|
||||||
if (tracer->tracer_func != NULL) {
|
|
||||||
void* data = tracer->tracer_data;
|
|
||||||
tracer->tracer_func(op, PyRefTracer_DESTROY, data);
|
|
||||||
}
|
|
||||||
destruct(op);
|
destruct(op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Relocated objects such as ``tuple``, ``bytes`` and ``str`` objects are
|
||||||
|
properly tracked by :mod:`tracemalloc` and its associated hooks. Patch by
|
||||||
|
Pablo Galindo.
|
|
@ -3196,6 +3196,7 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
|
||||||
#ifdef Py_TRACE_REFS
|
#ifdef Py_TRACE_REFS
|
||||||
_Py_ForgetReference(v);
|
_Py_ForgetReference(v);
|
||||||
#endif
|
#endif
|
||||||
|
_PyReftracerTrack(v, PyRefTracer_DESTROY);
|
||||||
*pv = (PyObject *)
|
*pv = (PyObject *)
|
||||||
PyObject_Realloc(v, PyBytesObject_SIZE + newsize);
|
PyObject_Realloc(v, PyBytesObject_SIZE + newsize);
|
||||||
if (*pv == NULL) {
|
if (*pv == NULL) {
|
||||||
|
|
|
@ -2457,11 +2457,7 @@ new_reference(PyObject *op)
|
||||||
#ifdef Py_TRACE_REFS
|
#ifdef Py_TRACE_REFS
|
||||||
_Py_AddToAllObjects(op);
|
_Py_AddToAllObjects(op);
|
||||||
#endif
|
#endif
|
||||||
struct _reftracer_runtime_state *tracer = &_PyRuntime.ref_tracer;
|
_PyReftracerTrack(op, PyRefTracer_CREATE);
|
||||||
if (tracer->tracer_func != NULL) {
|
|
||||||
void* data = tracer->tracer_data;
|
|
||||||
tracer->tracer_func(op, PyRefTracer_CREATE, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2554,10 +2550,6 @@ _Py_ResurrectReference(PyObject *op)
|
||||||
#ifdef Py_TRACE_REFS
|
#ifdef Py_TRACE_REFS
|
||||||
_Py_AddToAllObjects(op);
|
_Py_AddToAllObjects(op);
|
||||||
#endif
|
#endif
|
||||||
if (_PyRuntime.ref_tracer.tracer_func != NULL) {
|
|
||||||
void* data = _PyRuntime.ref_tracer.tracer_data;
|
|
||||||
_PyRuntime.ref_tracer.tracer_func(op, PyRefTracer_CREATE, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2947,15 +2939,10 @@ _Py_Dealloc(PyObject *op)
|
||||||
Py_INCREF(type);
|
Py_INCREF(type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct _reftracer_runtime_state *tracer = &_PyRuntime.ref_tracer;
|
|
||||||
if (tracer->tracer_func != NULL) {
|
|
||||||
void* data = tracer->tracer_data;
|
|
||||||
tracer->tracer_func(op, PyRefTracer_DESTROY, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef Py_TRACE_REFS
|
#ifdef Py_TRACE_REFS
|
||||||
_Py_ForgetReference(op);
|
_Py_ForgetReference(op);
|
||||||
#endif
|
#endif
|
||||||
|
_PyReftracerTrack(op, PyRefTracer_DESTROY);
|
||||||
(*dealloc)(op);
|
(*dealloc)(op);
|
||||||
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
|
|
|
@ -966,6 +966,7 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
|
||||||
for (i = newsize; i < oldsize; i++) {
|
for (i = newsize; i < oldsize; i++) {
|
||||||
Py_CLEAR(v->ob_item[i]);
|
Py_CLEAR(v->ob_item[i]);
|
||||||
}
|
}
|
||||||
|
_PyReftracerTrack((PyObject *)v, PyRefTracer_DESTROY);
|
||||||
sv = PyObject_GC_Resize(PyTupleObject, v, newsize);
|
sv = PyObject_GC_Resize(PyTupleObject, v, newsize);
|
||||||
if (sv == NULL) {
|
if (sv == NULL) {
|
||||||
*pv = NULL;
|
*pv = NULL;
|
||||||
|
|
|
@ -1129,6 +1129,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
|
||||||
#ifdef Py_TRACE_REFS
|
#ifdef Py_TRACE_REFS
|
||||||
_Py_ForgetReference(unicode);
|
_Py_ForgetReference(unicode);
|
||||||
#endif
|
#endif
|
||||||
|
_PyReftracerTrack(unicode, PyRefTracer_DESTROY);
|
||||||
|
|
||||||
new_unicode = (PyObject *)PyObject_Realloc(unicode, new_size);
|
new_unicode = (PyObject *)PyObject_Realloc(unicode, new_size);
|
||||||
if (new_unicode == NULL) {
|
if (new_unicode == NULL) {
|
||||||
|
|
|
@ -99,11 +99,7 @@
|
||||||
} \
|
} \
|
||||||
_Py_DECREF_STAT_INC(); \
|
_Py_DECREF_STAT_INC(); \
|
||||||
if (--op->ob_refcnt == 0) { \
|
if (--op->ob_refcnt == 0) { \
|
||||||
struct _reftracer_runtime_state *tracer = &_PyRuntime.ref_tracer; \
|
_PyReftracerTrack(op, PyRefTracer_DESTROY); \
|
||||||
if (tracer->tracer_func != NULL) { \
|
|
||||||
void* data = tracer->tracer_data; \
|
|
||||||
tracer->tracer_func(op, PyRefTracer_DESTROY, data); \
|
|
||||||
} \
|
|
||||||
destructor d = (destructor)(dealloc); \
|
destructor d = (destructor)(dealloc); \
|
||||||
d(op); \
|
d(op); \
|
||||||
} \
|
} \
|
||||||
|
|
Loading…
Reference in New Issue