Skip to content

Commit addbb73

Browse files
authored
Update PyObject_Del() documentation (#122597)
Replace PyMem_Del() with PyMem_Free().
1 parent 03b8852 commit addbb73

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

Doc/c-api/allocation.rst

+1-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ Allocating Objects on the Heap
5454
5555
.. c:function:: void PyObject_Del(void *op)
5656
57-
Releases memory allocated to an object using :c:macro:`PyObject_New` or
58-
:c:macro:`PyObject_NewVar`. This is normally called from the
59-
:c:member:`~PyTypeObject.tp_dealloc` handler specified in the object's type. The fields of
60-
the object should not be accessed after this call as the memory is no
61-
longer a valid Python object.
62-
57+
Same as :c:func:`PyObject_Free`.
6358
6459
.. c:var:: PyObject _Py_NoneStruct
6560

Doc/c-api/memory.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ The same code using the type-oriented function set::
734734
return PyErr_NoMemory();
735735
/* ...Do some I/O operation involving buf... */
736736
res = PyBytes_FromString(buf);
737-
PyMem_Del(buf); /* allocated with PyMem_New */
737+
PyMem_Free(buf); /* allocated with PyMem_New */
738738
return res;
739739
740740
Note that in the two examples above, the buffer is always manipulated via
@@ -750,11 +750,11 @@ allocators operating on different heaps. ::
750750
...
751751
PyMem_Del(buf3); /* Wrong -- should be PyMem_Free() */
752752
free(buf2); /* Right -- allocated via malloc() */
753-
free(buf1); /* Fatal -- should be PyMem_Del() */
753+
free(buf1); /* Fatal -- should be PyMem_Free() */
754754
755755
In addition to the functions aimed at handling raw memory blocks from the Python
756756
heap, objects in Python are allocated and released with :c:macro:`PyObject_New`,
757-
:c:macro:`PyObject_NewVar` and :c:func:`PyObject_Del`.
757+
:c:macro:`PyObject_NewVar` and :c:func:`PyObject_Free`.
758758
759759
These will be explained in the next chapter on defining and implementing new
760760
object types in C.

Modules/_sre/sre.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ state_fini(SRE_STATE* state)
530530
PyBuffer_Release(&state->buffer);
531531
Py_XDECREF(state->string);
532532
data_stack_dealloc(state);
533-
/* See above PyMem_Del for why we explicitly cast here. */
533+
/* See above PyMem_Free() for why we explicitly cast here. */
534534
PyMem_Free((void*) state->mark);
535535
state->mark = NULL;
536536
}

Modules/_testcapi/heaptype.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,16 @@ test_type_from_ephemeral_spec(PyObject *self, PyObject *Py_UNUSED(ignored))
269269
// (Explicitly overwrite memory before freeing,
270270
// so bugs show themselves even without the debug allocator's help.)
271271
memset(spec, 0xdd, sizeof(PyType_Spec));
272-
PyMem_Del(spec);
272+
PyMem_Free(spec);
273273
spec = NULL;
274274
memset(name, 0xdd, sizeof(NAME));
275-
PyMem_Del(name);
275+
PyMem_Free(name);
276276
name = NULL;
277277
memset(doc, 0xdd, sizeof(DOC));
278-
PyMem_Del(doc);
278+
PyMem_Free(doc);
279279
doc = NULL;
280280
memset(slots, 0xdd, 3 * sizeof(PyType_Slot));
281-
PyMem_Del(slots);
281+
PyMem_Free(slots);
282282
slots = NULL;
283283

284284
/* check that everything works */
@@ -304,10 +304,10 @@ test_type_from_ephemeral_spec(PyObject *self, PyObject *Py_UNUSED(ignored))
304304

305305
result = Py_NewRef(Py_None);
306306
finally:
307-
PyMem_Del(spec);
308-
PyMem_Del(name);
309-
PyMem_Del(doc);
310-
PyMem_Del(slots);
307+
PyMem_Free(spec);
308+
PyMem_Free(name);
309+
PyMem_Free(doc);
310+
PyMem_Free(slots);
311311
Py_XDECREF(class);
312312
Py_XDECREF(instance);
313313
Py_XDECREF(obj);

0 commit comments

Comments
 (0)