From 6b491b9dc0b0fdfd1f07ea4e2151236186d8e7e6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 27 Jan 2022 03:35:51 +0100 Subject: bpo-40170: Remove _Py_GetAllocatedBlocks() function (GH-30940) Move _Py_GetAllocatedBlocks() and _PyObject_DebugMallocStats() private functions to the internal C API. --- Include/cpython/objimpl.h | 8 -------- Include/internal/pycore_object.h | 9 +++++++++ Misc/NEWS.d/next/C API/2022-01-27-02-37-18.bpo-40170.XxQB0i.rst | 2 ++ Objects/obmalloc.c | 6 +++++- 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2022-01-27-02-37-18.bpo-40170.XxQB0i.rst diff --git a/Include/cpython/objimpl.h b/Include/cpython/objimpl.h index 7fff96e..d7c76ea 100644 --- a/Include/cpython/objimpl.h +++ b/Include/cpython/objimpl.h @@ -52,14 +52,6 @@ the 1st step is performed automatically for you, so in a C++ class constructor you would start directly with PyObject_Init/InitVar. */ -/* This function returns the number of allocated memory blocks, regardless of size */ -PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void); - -/* Macros */ -#ifdef WITH_PYMALLOC -PyAPI_FUNC(int) _PyObject_DebugMallocStats(FILE *out); -#endif - typedef struct { /* user context passed as the first argument to the 2 functions */ diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 5fe4ddb..c520122 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -232,6 +232,15 @@ extern void _PyObject_FreeInstanceAttributes(PyObject *self); extern int _PyObject_IsInstanceDictEmpty(PyObject *); extern PyObject* _PyType_GetSubclasses(PyTypeObject *); +/* This function returns the number of allocated memory blocks, regardless of size */ +PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void); + +/* Macros */ +#ifdef WITH_PYMALLOC +// Export the symbol for the 3rd party guppy3 project +PyAPI_FUNC(int) _PyObject_DebugMallocStats(FILE *out); +#endif + #ifdef __cplusplus } #endif diff --git a/Misc/NEWS.d/next/C API/2022-01-27-02-37-18.bpo-40170.XxQB0i.rst b/Misc/NEWS.d/next/C API/2022-01-27-02-37-18.bpo-40170.XxQB0i.rst new file mode 100644 index 0000000..7b74382 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-01-27-02-37-18.bpo-40170.XxQB0i.rst @@ -0,0 +1,2 @@ +Move _Py_GetAllocatedBlocks() and _PyObject_DebugMallocStats() private +functions to the internal C API. Patch by Victor Stinner. diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 4e17bf4..ea0faff 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -8,6 +8,9 @@ /* Defined in tracemalloc.c */ extern void _PyMem_DumpTraceback(int fd, const void *ptr); +// Forward declaration +int _PyObject_DebugMallocStats(FILE *out); + /* Python's malloc wrappers (see pymem.h) */ @@ -1569,8 +1572,9 @@ new_arena(void) const char *opt = Py_GETENV("PYTHONMALLOCSTATS"); debug_stats = (opt != NULL && *opt != '\0'); } - if (debug_stats) + if (debug_stats) { _PyObject_DebugMallocStats(stderr); + } if (unused_arena_objects == NULL) { uint i; -- cgit v0.12