Skip to content

Commit fda6bd8

Browse files
authored
Replace PyObject_Del with PyObject_Free (#122453)
PyObject_Del() is just a alias to PyObject_Free() kept for backward compatibility. Use directly PyObject_Free() instead.
1 parent 8803086 commit fda6bd8

13 files changed

+18
-18
lines changed

Doc/c-api/typeobj.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
650650
(doesn't have the :c:macro:`Py_TPFLAGS_BASETYPE` flag bit set), it is
651651
permissible to call the object deallocator directly instead of via
652652
:c:member:`~PyTypeObject.tp_free`. The object deallocator should be the one used to allocate the
653-
instance; this is normally :c:func:`PyObject_Del` if the instance was allocated
653+
instance; this is normally :c:func:`PyObject_Free` if the instance was allocated
654654
using :c:macro:`PyObject_New` or :c:macro:`PyObject_NewVar`, or
655655
:c:func:`PyObject_GC_Del` if the instance was allocated using
656656
:c:macro:`PyObject_GC_New` or :c:macro:`PyObject_GC_NewVar`.
@@ -1954,7 +1954,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
19541954
match :c:func:`PyType_GenericAlloc` and the value of the
19551955
:c:macro:`Py_TPFLAGS_HAVE_GC` flag bit.
19561956

1957-
For static subtypes, :c:data:`PyBaseObject_Type` uses :c:func:`PyObject_Del`.
1957+
For static subtypes, :c:data:`PyBaseObject_Type` uses :c:func:`PyObject_Free`.
19581958

19591959

19601960
.. c:member:: inquiry PyTypeObject.tp_is_gc

Modules/_testcapi/gc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ without_gc(PyObject *Py_UNUSED(self), PyObject *obj)
7272
if (PyType_IS_GC(tp)) {
7373
// Don't try this at home, kids:
7474
tp->tp_flags -= Py_TPFLAGS_HAVE_GC;
75-
tp->tp_free = PyObject_Del;
75+
tp->tp_free = PyObject_Free;
7676
tp->tp_traverse = NULL;
7777
tp->tp_clear = NULL;
7878
}

Modules/_testcapimodule.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static PyTypeObject _HashInheritanceTester_Type = {
289289
"hashinheritancetester", /* Name of this type */
290290
sizeof(PyObject), /* Basic object size */
291291
0, /* Item size for varobject */
292-
(destructor)PyObject_Del, /* tp_dealloc */
292+
(destructor)PyObject_Free, /* tp_dealloc */
293293
0, /* tp_vectorcall_offset */
294294
0, /* tp_getattr */
295295
0, /* tp_setattr */
@@ -3587,7 +3587,7 @@ static PyTypeObject matmulType = {
35873587
0,
35883588
0,
35893589
PyType_GenericNew, /* tp_new */
3590-
PyObject_Del, /* tp_free */
3590+
PyObject_Free, /* tp_free */
35913591
};
35923592

35933593
typedef struct {
@@ -3699,7 +3699,7 @@ static PyTypeObject awaitType = {
36993699
0,
37003700
0,
37013701
awaitObject_new, /* tp_new */
3702-
PyObject_Del, /* tp_free */
3702+
PyObject_Free, /* tp_free */
37033703
};
37043704

37053705

Objects/bytearrayobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ PyTypeObject PyByteArray_Type = {
24262426
(initproc)bytearray___init__, /* tp_init */
24272427
PyType_GenericAlloc, /* tp_alloc */
24282428
PyType_GenericNew, /* tp_new */
2429-
PyObject_Del, /* tp_free */
2429+
PyObject_Free, /* tp_free */
24302430
};
24312431

24322432
/*********************** Bytearray Iterator ****************************/

Objects/bytesobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3066,7 +3066,7 @@ PyTypeObject PyBytes_Type = {
30663066
0, /* tp_init */
30673067
bytes_alloc, /* tp_alloc */
30683068
bytes_new, /* tp_new */
3069-
PyObject_Del, /* tp_free */
3069+
PyObject_Free, /* tp_free */
30703070
};
30713071

30723072
void

Objects/codeobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ PyTypeObject _PyLineIterator = {
13521352
0, /* tp_init */
13531353
0, /* tp_alloc */
13541354
0, /* tp_new */
1355-
PyObject_Del, /* tp_free */
1355+
PyObject_Free, /* tp_free */
13561356
};
13571357

13581358
static lineiterator *
@@ -1443,7 +1443,7 @@ PyTypeObject _PyPositionsIterator = {
14431443
0, /* tp_init */
14441444
0, /* tp_alloc */
14451445
0, /* tp_new */
1446-
PyObject_Del, /* tp_free */
1446+
PyObject_Free, /* tp_free */
14471447
};
14481448

14491449
static PyObject*

Objects/complexobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1247,5 +1247,5 @@ PyTypeObject PyComplex_Type = {
12471247
0, /* tp_init */
12481248
PyType_GenericAlloc, /* tp_alloc */
12491249
actual_complex_new, /* tp_new */
1250-
PyObject_Del, /* tp_free */
1250+
PyObject_Free, /* tp_free */
12511251
};

Objects/fileobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ PyTypeObject PyStdPrinter_Type = {
462462
0, /* tp_init */
463463
PyType_GenericAlloc, /* tp_alloc */
464464
0, /* tp_new */
465-
PyObject_Del, /* tp_free */
465+
PyObject_Free, /* tp_free */
466466
};
467467

468468

Objects/odictobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ tp_dictoffset (__dict__) - -
276276
tp_init __init__ object_init dict_init
277277
tp_alloc - PyType_GenericAlloc (repeated)
278278
tp_new __new__ object_new dict_new
279-
tp_free - PyObject_Del PyObject_GC_Del
279+
tp_free - PyObject_Free PyObject_GC_Del
280280
================= ================ =================== ================
281281
282282
Relevant Methods

Objects/rangeobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ PyTypeObject PyRangeIter_Type = {
899899
sizeof(_PyRangeIterObject), /* tp_basicsize */
900900
0, /* tp_itemsize */
901901
/* methods */
902-
(destructor)PyObject_Del, /* tp_dealloc */
902+
(destructor)PyObject_Free, /* tp_dealloc */
903903
0, /* tp_vectorcall_offset */
904904
0, /* tp_getattr */
905905
0, /* tp_setattr */

Objects/typeobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7456,7 +7456,7 @@ PyTypeObject PyBaseObject_Type = {
74567456
object_init, /* tp_init */
74577457
PyType_GenericAlloc, /* tp_alloc */
74587458
object_new, /* tp_new */
7459-
PyObject_Del, /* tp_free */
7459+
PyObject_Free, /* tp_free */
74607460
};
74617461

74627462

@@ -8180,7 +8180,7 @@ type_ready_inherit(PyTypeObject *type)
81808180

81818181
/* Sanity check for tp_free. */
81828182
if (_PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) &&
8183-
(type->tp_free == NULL || type->tp_free == PyObject_Del))
8183+
(type->tp_free == NULL || type->tp_free == PyObject_Free))
81848184
{
81858185
/* This base class needs to call tp_free, but doesn't have
81868186
* one, or its tp_free is for non-gc'ed objects.

Objects/unicodeobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15265,7 +15265,7 @@ PyTypeObject PyUnicode_Type = {
1526515265
0, /* tp_init */
1526615266
0, /* tp_alloc */
1526715267
unicode_new, /* tp_new */
15268-
PyObject_Del, /* tp_free */
15268+
PyObject_Free, /* tp_free */
1526915269
.tp_vectorcall = unicode_vectorcall,
1527015270
};
1527115271

Python/optimizer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ PyTypeObject _PyCounterOptimizer_Type = {
13741374
.tp_itemsize = 0,
13751375
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
13761376
.tp_methods = counter_optimizer_methods,
1377-
.tp_dealloc = (destructor)PyObject_Del,
1377+
.tp_dealloc = (destructor)PyObject_Free,
13781378
};
13791379

13801380
PyObject *

0 commit comments

Comments
 (0)