Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9e7452

Browse files
committed
First cut at repairing out-of-date comments; make alignment of macro defs
all the same within the #ifdef WITH_PYMALLOC block.
1 parent d2560cd commit e9e7452

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

Include/objimpl.h

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ You must first include "object.h".
1717
represent the object and 'typeobj' the address of the corresponding
1818
type object. Reference count and type pointer are filled in; the
1919
rest of the bytes of the object are *undefined*! The resulting
20-
expression type is 'type *'. The size of the object is actually
21-
determined by the tp_basicsize field of the type object.
20+
expression type is 'type *'. The size of the object is determined
21+
by the tp_basicsize field of the type object.
2222
2323
- PyObject_NewVar(type, typeobj, n) is similar but allocates a
2424
variable-size object with n extra items. The size is computed as
2525
tp_basicsize plus n * tp_itemsize. This fills in the ob_size field
2626
as well.
2727
28-
- PyObject_Del(op) releases the memory allocated for an object.
28+
- PyObject_Del(op) releases the memory allocated for an object. It
29+
does not run a destructor -- it only frees the memory. PyObject_Free
30+
is identical.
2931
3032
- PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) are
3133
similar to PyObject_{New, NewVar} except that they don't allocate
@@ -34,7 +36,9 @@ You must first include "object.h".
3436
allocator) and initialize its object header fields.
3537
3638
Note that objects created with PyObject_{New, NewVar} are allocated
37-
using the specialized Python allocator (implemented in obmalloc.c).
39+
using the specialized Python allocator (implemented in obmalloc.c), if
40+
WITH_PYMALLOC is enabled. In addition, a special debugging allocator
41+
is used if PYMALLOC_DEBUG is also #defined.
3842
3943
In case a specific form of memory management is needed, implying that
4044
the objects would not reside in the Python heap (for example standard
@@ -70,11 +74,16 @@ recommended to use PyObject_{New, NewVar, Del}. */
7074

7175
/* Functions */
7276

73-
/* Wrappers that useful if you need to be sure that you are using the
74-
same object memory allocator as Python. These wrappers *do not* make
75-
sure that allocating 0 bytes returns a non-NULL pointer. Returned
76-
pointers must be checked for NULL explicitly; no action is performed
77-
on failure. */
77+
/* Functions to call the same malloc/realloc/free as used by Python's
78+
object allocator. If WITH_PYMALLOC is enabled, these may differ from
79+
the platform malloc/realloc/free. The Python object allocator is
80+
designed for fast, cache-conscious allocation of many "small" objects,
81+
with low hidden memory overhead. PyObject_Malloc(0) returns a unique
82+
non-NULL pointer if possible. PyObject_Realloc(NULL, n) acts like
83+
PyObject_Malloc(n). PyObject_Realloc(p != NULL, 0) does not return
84+
NULL or free the memory at p. Returned pointers must be checked for
85+
NULL explicitly; no action is performed on failure other than to return
86+
NULL. */
7887
extern DL_IMPORT(void *) PyObject_Malloc(size_t);
7988
extern DL_IMPORT(void *) PyObject_Realloc(void *, size_t);
8089
extern DL_IMPORT(void) PyObject_Free(void *);
@@ -89,12 +98,12 @@ DL_IMPORT(void) _PyObject_DebugFree(void *p);
8998
DL_IMPORT(void) _PyObject_DebugDumpAddress(const void *p);
9099
DL_IMPORT(void) _PyObject_DebugCheckAddress(const void *p);
91100
DL_IMPORT(void) _PyObject_DebugDumpStats(void);
92-
#define PyObject_MALLOC _PyObject_DebugMalloc
93-
#define PyObject_Malloc _PyObject_DebugMalloc
94-
#define PyObject_REALLOC _PyObject_DebugRealloc
95-
#define PyObject_Realloc _PyObject_DebugRealloc
96-
#define PyObject_FREE _PyObject_DebugFree
97-
#define PyObject_Free _PyObject_DebugFree
101+
#define PyObject_MALLOC _PyObject_DebugMalloc
102+
#define PyObject_Malloc _PyObject_DebugMalloc
103+
#define PyObject_REALLOC _PyObject_DebugRealloc
104+
#define PyObject_Realloc _PyObject_DebugRealloc
105+
#define PyObject_FREE _PyObject_DebugFree
106+
#define PyObject_Free _PyObject_DebugFree
98107

99108
#else /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */
100109
#define PyObject_MALLOC PyObject_Malloc

0 commit comments

Comments
 (0)