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

Delta Between Two Patch Sets: Include/objimpl.h

Issue 13390: Hunt memory allocations in addition to reference leaks
Left Patch Set: Created 7 years, 10 months ago
Right Patch Set: Created 6 years, 9 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
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 possible. The PyObject_{Malloc, Realloc, Free} family is exposed 91 possible. The PyObject_{Malloc, Realloc, Free} family is exposed
92 so that you can exploit Python's small-block allocator for non-object 92 so that you can exploit Python's small-block allocator for non-object
93 uses. If you must use these routines to allocate object memory, make sure 93 uses. If you must use these routines to allocate object memory, make sure
94 the object gets initialized via PyObject_{Init, InitVar} after obtaining 94 the object gets initialized via PyObject_{Init, InitVar} after obtaining
95 the raw memory. 95 the raw memory.
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 is the number of allocated memory blocks, regardless of size */ 101 /* This function returns the number of allocated memory blocks, regardless of si ze */
102 PyAPI_DATA(Py_ssize_t) _Py_AllocedBlocks; 102 PyAPI_FUNC(Py_ssize_t) _Py_GetAllocedBlocks(void);
Nick Coghlan 2011/11/13 01:52:44 Do you have any particular reason for only exposin
103
104 103
105 /* Macros */ 104 /* Macros */
106 #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 */
107 #ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */ 109 #ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */
108 PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes); 110 PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes);
109 PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes); 111 PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes);
110 PyAPI_FUNC(void) _PyObject_DebugFree(void *p); 112 PyAPI_FUNC(void) _PyObject_DebugFree(void *p);
111 PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p); 113 PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p);
112 PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p); 114 PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p);
113 PyAPI_FUNC(void) _PyObject_DebugMallocStats(void);
114 PyAPI_FUNC(void *) _PyObject_DebugMallocApi(char api, size_t nbytes); 115 PyAPI_FUNC(void *) _PyObject_DebugMallocApi(char api, size_t nbytes);
115 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);
116 PyAPI_FUNC(void) _PyObject_DebugFreeApi(char api, void *p); 117 PyAPI_FUNC(void) _PyObject_DebugFreeApi(char api, void *p);
117 PyAPI_FUNC(void) _PyObject_DebugCheckAddressApi(char api, const void *p); 118 PyAPI_FUNC(void) _PyObject_DebugCheckAddressApi(char api, const void *p);
118 PyAPI_FUNC(void *) _PyMem_DebugMalloc(size_t nbytes); 119 PyAPI_FUNC(void *) _PyMem_DebugMalloc(size_t nbytes);
119 PyAPI_FUNC(void *) _PyMem_DebugRealloc(void *p, size_t nbytes); 120 PyAPI_FUNC(void *) _PyMem_DebugRealloc(void *p, size_t nbytes);
120 PyAPI_FUNC(void) _PyMem_DebugFree(void *p); 121 PyAPI_FUNC(void) _PyMem_DebugFree(void *p);
121 #define PyObject_MALLOC _PyObject_DebugMalloc 122 #define PyObject_MALLOC _PyObject_DebugMalloc
122 #define PyObject_Malloc _PyObject_DebugMalloc 123 #define PyObject_Malloc _PyObject_DebugMalloc
123 #define PyObject_REALLOC _PyObject_DebugRealloc 124 #define PyObject_REALLOC _PyObject_DebugRealloc
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 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).
176 177
177 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
178 return (at worst) pointer-aligned memory anyway. 179 return (at worst) pointer-aligned memory anyway.
179 */ 180 */
180 #if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0 181 #if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0
181 # 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"
182 #endif 183 #endif
183 184
184 #define _PyObject_VAR_SIZE(typeobj, nitems) \ 185 #define _PyObject_VAR_SIZE(typeobj, nitems) \
185 (size_t) \ 186 _Py_SIZE_ROUND_UP((typeobj)->tp_basicsize + \
186 ( ( (typeobj)->tp_basicsize + \ 187 (nitems)*(typeobj)->tp_itemsize, \
187 (nitems)*(typeobj)->tp_itemsize + \ 188 SIZEOF_VOID_P)
188 (SIZEOF_VOID_P - 1) \
189 ) & ~(SIZEOF_VOID_P - 1) \
190 )
191 189
192 #define PyObject_NEW(type, typeobj) \ 190 #define PyObject_NEW(type, typeobj) \
193 ( (type *) PyObject_Init( \ 191 ( (type *) PyObject_Init( \
194 (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) ) 192 (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
195 193
196 #define PyObject_NEW_VAR(type, typeobj, n) \ 194 #define PyObject_NEW_VAR(type, typeobj, n) \
197 ( (type *) PyObject_InitVar( \ 195 ( (type *) PyObject_InitVar( \
198 (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\ 196 (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\
199 (typeobj), (n)) ) 197 (typeobj), (n)) )
200 198
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 /* Test if a type supports weak references */ 330 /* Test if a type supports weak references */
333 #define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0) 331 #define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
334 332
335 #define PyObject_GET_WEAKREFS_LISTPTR(o) \ 333 #define PyObject_GET_WEAKREFS_LISTPTR(o) \
336 ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset)) 334 ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
337 335
338 #ifdef __cplusplus 336 #ifdef __cplusplus
339 } 337 }
340 #endif 338 #endif
341 #endif /* !Py_OBJIMPL_H */ 339 #endif /* !Py_OBJIMPL_H */
LEFTRIGHT

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