Skip to content

Commit

Permalink
gh-101430: Update tracemalloc to handle presize properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Feb 9, 2023
1 parent ecfd2d3 commit f3808bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update :mod:`tracemalloc` to handle presize of object properly. Patch by
Dong-hee Na.
7 changes: 5 additions & 2 deletions Modules/_tracemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1404,8 +1405,9 @@ _tracemalloc__get_object_traceback(PyObject *module, PyObject *obj)
traceback_t *traceback;

type = Py_TYPE(obj);
const size_t presize = _PyType_PreHeaderSize(type);
if (PyType_IS_GC(type)) {
ptr = (void *)((char *)obj - sizeof(PyGC_Head));
ptr = (void *)((char *)obj - presize);
}
else {
ptr = (void *)obj;
Expand Down Expand Up @@ -1725,8 +1727,9 @@ _PyTraceMalloc_NewReference(PyObject *op)

uintptr_t ptr;
PyTypeObject *type = Py_TYPE(op);
const size_t presize = _PyType_PreHeaderSize(type);
if (PyType_IS_GC(type)) {
ptr = (uintptr_t)((char *)op - sizeof(PyGC_Head));
ptr = (uintptr_t)((char *)op - presize);
}
else {
ptr = (uintptr_t)op;
Expand Down

0 comments on commit f3808bf

Please sign in to comment.