diff options
author | Dong-hee Na <donghee.na@python.org> | 2023-02-09 23:30:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-09 23:30:03 (GMT) |
commit | 5b946d371979a772120e6ee7d37f9b735769d433 (patch) | |
tree | 2c48db4788406bf49a07416055513e37cb5661a2 /Modules/_tracemalloc.c | |
parent | f1f3af7b8245e61a2e0abef03b2c6c5902ed7df8 (diff) | |
download | cpython-5b946d371979a772120e6ee7d37f9b735769d433.zip cpython-5b946d371979a772120e6ee7d37f9b735769d433.tar.gz cpython-5b946d371979a772120e6ee7d37f9b735769d433.tar.bz2 |
gh-101430: Update tracemalloc to handle presize properly. (gh-101745)
Diffstat (limited to 'Modules/_tracemalloc.c')
-rw-r--r-- | Modules/_tracemalloc.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 9826ad2..d69c563 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -2,6 +2,7 @@ #include "pycore_fileutils.h" // _Py_write_noraise() #include "pycore_gc.h" // PyGC_Head #include "pycore_hashtable.h" // _Py_hashtable_t +#include "pycore_object.h" // _PyType_PreHeaderSize #include "pycore_pymem.h" // _Py_tracemalloc_config #include "pycore_runtime.h" // _Py_ID() #include "pycore_traceback.h" @@ -1400,20 +1401,16 @@ _tracemalloc__get_object_traceback(PyObject *module, PyObject *obj) /*[clinic end generated code: output=41ee0553a658b0aa input=29495f1b21c53212]*/ { PyTypeObject *type; - void *ptr; traceback_t *traceback; type = Py_TYPE(obj); - if (PyType_IS_GC(type)) { - ptr = (void *)((char *)obj - sizeof(PyGC_Head)); - } - else { - ptr = (void *)obj; - } + const size_t presize = _PyType_PreHeaderSize(type); + uintptr_t ptr = (uintptr_t)((char *)obj - presize); - traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr); - if (traceback == NULL) + traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, ptr); + if (traceback == NULL) { Py_RETURN_NONE; + } return traceback_to_pyobject(traceback, NULL); } @@ -1723,14 +1720,9 @@ _PyTraceMalloc_NewReference(PyObject *op) return -1; } - uintptr_t ptr; PyTypeObject *type = Py_TYPE(op); - if (PyType_IS_GC(type)) { - ptr = (uintptr_t)((char *)op - sizeof(PyGC_Head)); - } - else { - ptr = (uintptr_t)op; - } + const size_t presize = _PyType_PreHeaderSize(type); + uintptr_t ptr = (uintptr_t)((char *)op - presize); int res = -1; |