mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
Update PyObject_Del() documentation (#122597)
Replace PyMem_Del() with PyMem_Free().
This commit is contained in:
parent
03b88522f5
commit
addbb73927
4 changed files with 13 additions and 18 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue