Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4377)

Delta Between Two Patch Sets: Include/objimpl.h

Issue 13390: Hunt memory allocations in addition to reference leaks
Left Patch Set: Created 7 years, 11 months ago
Right Patch Set: Created 6 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/sys.rst ('k') | Lib/test/regrtest.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(Both sides are equal)
1 /* The PyObject_ memory family: high-level object memory interfaces. 1 /* The PyObject_ memory family: high-level object memory interfaces.
2 See pymem.h for the low-level PyMem_ family. 2 See pymem.h for the low-level PyMem_ family.
3 */ 3 */
4 4
5 #ifndef Py_OBJIMPL_H 5 #ifndef Py_OBJIMPL_H
6 #define Py_OBJIMPL_H 6 #define Py_OBJIMPL_H
7 7
8 #include "pymem.h" 8 #include "pymem.h"
9 9
10 #ifdef __cplusplus 10 #ifdef __cplusplus
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 */ 96 */
97 PyAPI_FUNC(void *) PyObject_Malloc(size_t); 97 PyAPI_FUNC(void *) PyObject_Malloc(size_t);
98 PyAPI_FUNC(void *) PyObject_Realloc(void *, size_t); 98 PyAPI_FUNC(void *) PyObject_Realloc(void *, size_t);
99 PyAPI_FUNC(void) PyObject_Free(void *); 99 PyAPI_FUNC(void) PyObject_Free(void *);
100 100
101 /* This function returns the number of allocated memory blocks, regardless of si ze */ 101 /* This function returns the number of allocated memory blocks, regardless of si ze */
102 PyAPI_FUNC(Py_ssize_t) _Py_GetAllocedBlocks(void); 102 PyAPI_FUNC(Py_ssize_t) _Py_GetAllocedBlocks(void);
103 103
104 /* Macros */ 104 /* Macros */
105 #ifdef WITH_PYMALLOC 105 #ifdef WITH_PYMALLOC
106 #ifndef Py_LIMITED_API
107 PyAPI_FUNC(void) _PyObject_DebugMallocStats(FILE *out);
108 #endif /* #ifndef Py_LIMITED_API */
106 #ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */ 109 #ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */
107 PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes); 110 PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes);
108 PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes); 111 PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes);
109 PyAPI_FUNC(void) _PyObject_DebugFree(void *p); 112 PyAPI_FUNC(void) _PyObject_DebugFree(void *p);
110 PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p); 113 PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p);
111 PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p); 114 PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p);
112 PyAPI_FUNC(void) _PyObject_DebugMallocStats(void);
113 PyAPI_FUNC(void *) _PyObject_DebugMallocApi(char api, size_t nbytes); 115 PyAPI_FUNC(void *) _PyObject_DebugMallocApi(char api, size_t nbytes);
114 PyAPI_FUNC(void *) _PyObject_DebugReallocApi(char api, void *p, size_t nbytes); 116 PyAPI_FUNC(void *) _PyObject_DebugReallocApi(char api, void *p, size_t nbytes);
115 PyAPI_FUNC(void) _PyObject_DebugFreeApi(char api, void *p); 117 PyAPI_FUNC(void) _PyObject_DebugFreeApi(char api, void *p);
116 PyAPI_FUNC(void) _PyObject_DebugCheckAddressApi(char api, const void *p); 118 PyAPI_FUNC(void) _PyObject_DebugCheckAddressApi(char api, const void *p);
117 PyAPI_FUNC(void *) _PyMem_DebugMalloc(size_t nbytes); 119 PyAPI_FUNC(void *) _PyMem_DebugMalloc(size_t nbytes);
118 PyAPI_FUNC(void *) _PyMem_DebugRealloc(void *p, size_t nbytes); 120 PyAPI_FUNC(void *) _PyMem_DebugRealloc(void *p, size_t nbytes);
119 PyAPI_FUNC(void) _PyMem_DebugFree(void *p); 121 PyAPI_FUNC(void) _PyMem_DebugFree(void *p);
120 #define PyObject_MALLOC _PyObject_DebugMalloc 122 #define PyObject_MALLOC _PyObject_DebugMalloc
121 #define PyObject_Malloc _PyObject_DebugMalloc 123 #define PyObject_Malloc _PyObject_DebugMalloc
122 #define PyObject_REALLOC _PyObject_DebugRealloc 124 #define PyObject_REALLOC _PyObject_DebugRealloc
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 str or long, so that pointers can be stored after the embedded data). 176 str or long, so that pointers can be stored after the embedded data).
175 177
176 Note that there's no memory wastage in doing this, as malloc has to 178 Note that there's no memory wastage in doing this, as malloc has to
177 return (at worst) pointer-aligned memory anyway. 179 return (at worst) pointer-aligned memory anyway.
178 */ 180 */
179 #if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0 181 #if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0
180 # error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2" 182 # error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"
181 #endif 183 #endif
182 184
183 #define _PyObject_VAR_SIZE(typeobj, nitems) \ 185 #define _PyObject_VAR_SIZE(typeobj, nitems) \
184 (size_t) \ 186 _Py_SIZE_ROUND_UP((typeobj)->tp_basicsize + \
185 ( ( (typeobj)->tp_basicsize + \ 187 (nitems)*(typeobj)->tp_itemsize, \
186 (nitems)*(typeobj)->tp_itemsize + \ 188 SIZEOF_VOID_P)
187 (SIZEOF_VOID_P - 1) \
188 ) & ~(SIZEOF_VOID_P - 1) \
189 )
190 189
191 #define PyObject_NEW(type, typeobj) \ 190 #define PyObject_NEW(type, typeobj) \
192 ( (type *) PyObject_Init( \ 191 ( (type *) PyObject_Init( \
193 (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) ) 192 (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
194 193
195 #define PyObject_NEW_VAR(type, typeobj, n) \ 194 #define PyObject_NEW_VAR(type, typeobj, n) \
196 ( (type *) PyObject_InitVar( \ 195 ( (type *) PyObject_InitVar( \
197 (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\ 196 (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\
198 (typeobj), (n)) ) 197 (typeobj), (n)) )
199 198
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 /* Test if a type supports weak references */ 330 /* Test if a type supports weak references */
332 #define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0) 331 #define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
333 332
334 #define PyObject_GET_WEAKREFS_LISTPTR(o) \ 333 #define PyObject_GET_WEAKREFS_LISTPTR(o) \
335 ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset)) 334 ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
336 335
337 #ifdef __cplusplus 336 #ifdef __cplusplus
338 } 337 }
339 #endif 338 #endif
340 #endif /* !Py_OBJIMPL_H */ 339 #endif /* !Py_OBJIMPL_H */
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+