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 6b451fa
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 @@ -1405,7 +1406,8 @@ _tracemalloc__get_object_traceback(PyObject *module, PyObject *obj)

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

0 comments on commit 6b451fa

Please sign in to comment.