https://github.com/python/cpython/commit/addbb73927f55855dfcc62fd47b0018de8a814ed
commit: addbb73927f55855dfcc62fd47b0018de8a814ed
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2024-08-02T12:13:33+02:00
summary:

Update PyObject_Del() documentation (#122597)

Replace PyMem_Del() with PyMem_Free().

files:
M Doc/c-api/allocation.rst
M Doc/c-api/memory.rst
M Modules/_sre/sre.c
M Modules/_testcapi/heaptype.c

diff --git a/Doc/c-api/allocation.rst b/Doc/c-api/allocation.rst
index b3609c233156b6..0d53b18ea87d5e 100644
--- a/Doc/c-api/allocation.rst
+++ b/Doc/c-api/allocation.rst
@@ -54,12 +54,7 @@ Allocating Objects on the Heap
 
 .. c:function:: void PyObject_Del(void *op)
 
-   Releases memory allocated to an object using :c:macro:`PyObject_New` or
-   :c:macro:`PyObject_NewVar`.  This is normally called from the
-   :c:member:`~PyTypeObject.tp_dealloc` handler specified in the object's 
type.  The fields of
-   the object should not be accessed after this call as the memory is no
-   longer a valid Python object.
-
+   Same as :c:func:`PyObject_Free`.
 
 .. c:var:: PyObject _Py_NoneStruct
 
diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst
index 9da09a21607f61..4ecc998b37e598 100644
--- a/Doc/c-api/memory.rst
+++ b/Doc/c-api/memory.rst
@@ -734,7 +734,7 @@ The same code using the type-oriented function set::
        return PyErr_NoMemory();
    /* ...Do some I/O operation involving buf... */
    res = PyBytes_FromString(buf);
-   PyMem_Del(buf); /* allocated with PyMem_New */
+   PyMem_Free(buf); /* allocated with PyMem_New */
    return res;
 
 Note that in the two examples above, the buffer is always manipulated via
@@ -750,11 +750,11 @@ allocators operating on different heaps. ::
    ...
    PyMem_Del(buf3);  /* Wrong -- should be PyMem_Free() */
    free(buf2);       /* Right -- allocated via malloc() */
-   free(buf1);       /* Fatal -- should be PyMem_Del()  */
+   free(buf1);       /* Fatal -- should be PyMem_Free()  */
 
 In addition to the functions aimed at handling raw memory blocks from the 
Python
 heap, objects in Python are allocated and released with 
:c:macro:`PyObject_New`,
-:c:macro:`PyObject_NewVar` and :c:func:`PyObject_Del`.
+:c:macro:`PyObject_NewVar` and :c:func:`PyObject_Free`.
 
 These will be explained in the next chapter on defining and implementing new
 object types in C.
diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c
index 0a888af31b0497..01420d1a10b1cf 100644
--- a/Modules/_sre/sre.c
+++ b/Modules/_sre/sre.c
@@ -530,7 +530,7 @@ state_fini(SRE_STATE* state)
         PyBuffer_Release(&state->buffer);
     Py_XDECREF(state->string);
     data_stack_dealloc(state);
-    /* See above PyMem_Del for why we explicitly cast here. */
+    /* See above PyMem_Free() for why we explicitly cast here. */
     PyMem_Free((void*) state->mark);
     state->mark = NULL;
 }
diff --git a/Modules/_testcapi/heaptype.c b/Modules/_testcapi/heaptype.c
index 4526583a8059d9..b45b890b88d81f 100644
--- a/Modules/_testcapi/heaptype.c
+++ b/Modules/_testcapi/heaptype.c
@@ -269,16 +269,16 @@ test_type_from_ephemeral_spec(PyObject *self, PyObject 
*Py_UNUSED(ignored))
     // (Explicitly overwrite memory before freeing,
     // so bugs show themselves even without the debug allocator's help.)
     memset(spec, 0xdd, sizeof(PyType_Spec));
-    PyMem_Del(spec);
+    PyMem_Free(spec);
     spec = NULL;
     memset(name, 0xdd, sizeof(NAME));
-    PyMem_Del(name);
+    PyMem_Free(name);
     name = NULL;
     memset(doc, 0xdd, sizeof(DOC));
-    PyMem_Del(doc);
+    PyMem_Free(doc);
     doc = NULL;
     memset(slots, 0xdd, 3 * sizeof(PyType_Slot));
-    PyMem_Del(slots);
+    PyMem_Free(slots);
     slots = NULL;
 
     /* check that everything works */
@@ -304,10 +304,10 @@ test_type_from_ephemeral_spec(PyObject *self, PyObject 
*Py_UNUSED(ignored))
 
     result = Py_NewRef(Py_None);
   finally:
-    PyMem_Del(spec);
-    PyMem_Del(name);
-    PyMem_Del(doc);
-    PyMem_Del(slots);
+    PyMem_Free(spec);
+    PyMem_Free(name);
+    PyMem_Free(doc);
+    PyMem_Free(slots);
     Py_XDECREF(class);
     Py_XDECREF(instance);
     Py_XDECREF(obj);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to