Skip to content

Commit 6b491b9

Browse files
authored
bpo-40170: Remove _Py_GetAllocatedBlocks() function (GH-30940)
Move _Py_GetAllocatedBlocks() and _PyObject_DebugMallocStats() private functions to the internal C API.
1 parent af32b3e commit 6b491b9

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

Include/cpython/objimpl.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@
5252
the 1st step is performed automatically for you, so in a C++ class
5353
constructor you would start directly with PyObject_Init/InitVar. */
5454

55-
/* This function returns the number of allocated memory blocks, regardless of size */
56-
PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void);
57-
58-
/* Macros */
59-
#ifdef WITH_PYMALLOC
60-
PyAPI_FUNC(int) _PyObject_DebugMallocStats(FILE *out);
61-
#endif
62-
6355

6456
typedef struct {
6557
/* user context passed as the first argument to the 2 functions */

Include/internal/pycore_object.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ extern void _PyObject_FreeInstanceAttributes(PyObject *self);
232232
extern int _PyObject_IsInstanceDictEmpty(PyObject *);
233233
extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
234234

235+
/* This function returns the number of allocated memory blocks, regardless of size */
236+
PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void);
237+
238+
/* Macros */
239+
#ifdef WITH_PYMALLOC
240+
// Export the symbol for the 3rd party guppy3 project
241+
PyAPI_FUNC(int) _PyObject_DebugMallocStats(FILE *out);
242+
#endif
243+
235244
#ifdef __cplusplus
236245
}
237246
#endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Move _Py_GetAllocatedBlocks() and _PyObject_DebugMallocStats() private
2+
functions to the internal C API. Patch by Victor Stinner.

Objects/obmalloc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
/* Defined in tracemalloc.c */
99
extern void _PyMem_DumpTraceback(int fd, const void *ptr);
1010

11+
// Forward declaration
12+
int _PyObject_DebugMallocStats(FILE *out);
13+
1114

1215
/* Python's malloc wrappers (see pymem.h) */
1316

@@ -1569,8 +1572,9 @@ new_arena(void)
15691572
const char *opt = Py_GETENV("PYTHONMALLOCSTATS");
15701573
debug_stats = (opt != NULL && *opt != '\0');
15711574
}
1572-
if (debug_stats)
1575+
if (debug_stats) {
15731576
_PyObject_DebugMallocStats(stderr);
1577+
}
15741578

15751579
if (unused_arena_objects == NULL) {
15761580
uint i;

0 commit comments

Comments
 (0)