Skip to content

Commit 32bd68c

Browse files
authored
bpo-42519: Replace PyObject_MALLOC() with PyObject_Malloc() (GH-23587)
No longer use deprecated aliases to functions: * Replace PyObject_MALLOC() with PyObject_Malloc() * Replace PyObject_REALLOC() with PyObject_Realloc() * Replace PyObject_FREE() with PyObject_Free() * Replace PyObject_Del() with PyObject_Free() * Replace PyObject_DEL() with PyObject_Free()
1 parent 00d7abd commit 32bd68c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+102
-98
lines changed

Include/objimpl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Functions and macros for modules that implement new object types.
3838
object with room for n items. In addition to the refcount and type pointer
3939
fields, this also fills in the ob_size field.
4040
41-
- PyObject_Del(op) releases the memory allocated for an object. It does not
41+
- PyObject_Free(op) releases the memory allocated for an object. It does not
4242
run a destructor -- it only frees the memory. PyObject_Free is identical.
4343
4444
- PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) don't
@@ -103,6 +103,8 @@ PyAPI_FUNC(void) PyObject_Free(void *ptr);
103103

104104

105105
// Deprecated aliases only kept for backward compatibility.
106+
// PyObject_Del and PyObject_DEL are defined with no parameter to be able to
107+
// use them as function pointers (ex: tp_free = PyObject_Del).
106108
#define PyObject_MALLOC PyObject_Malloc
107109
#define PyObject_REALLOC PyObject_Realloc
108110
#define PyObject_FREE PyObject_Free

Include/pymem.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr);
7979

8080

8181
// Deprecated aliases only kept for backward compatibility.
82+
// PyMem_Del and PyMem_DEL are defined with no parameter to be able to use
83+
// them as function pointers (ex: dealloc = PyMem_Del).
8284
#define PyMem_MALLOC(n) PyMem_Malloc(n)
8385
#define PyMem_NEW(type, n) PyMem_New(type, n)
8486
#define PyMem_REALLOC(p, n) PyMem_Realloc(p, n)
8587
#define PyMem_RESIZE(p, type, n) PyMem_Resize(p, type, n)
8688
#define PyMem_FREE(p) PyMem_Free(p)
87-
#define PyMem_Del(p) PyMem_Free(p)
88-
#define PyMem_DEL(p) PyMem_Free(p)
89+
#define PyMem_Del PyMem_Free
90+
#define PyMem_DEL PyMem_Free
8991

9092

9193
#ifndef Py_LIMITED_API

Modules/_blake2/blake2b_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ py_blake2b_dealloc(PyObject *self)
393393
}
394394

395395
PyTypeObject *type = Py_TYPE(self);
396-
PyObject_Del(self);
396+
PyObject_Free(self);
397397
Py_DECREF(type);
398398
}
399399

Modules/_blake2/blake2s_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ py_blake2s_dealloc(PyObject *self)
392392
}
393393

394394
PyTypeObject *type = Py_TYPE(self);
395-
PyObject_Del(self);
395+
PyObject_Free(self);
396396
Py_DECREF(type);
397397
}
398398

Modules/_ctypes/callproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ static void
475475
PyCArg_dealloc(PyCArgObject *self)
476476
{
477477
Py_XDECREF(self->obj);
478-
PyObject_Del(self);
478+
PyObject_Free(self);
479479
}
480480

481481
static int

Modules/_curses_panel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ PyCursesPanel_Dealloc(PyCursesPanelObject *po)
282282
Py_DECREF(po->wo);
283283
remove_lop(po);
284284
}
285-
PyObject_DEL(po);
285+
PyObject_Free(po);
286286
Py_DECREF(tp);
287287
}
288288

Modules/_cursesmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
689689
if (wo->win != stdscr) delwin(wo->win);
690690
if (wo->encoding != NULL)
691691
PyMem_Free(wo->encoding);
692-
PyObject_DEL(wo);
692+
PyObject_Free(wo);
693693
}
694694

695695
/* Addch, Addstr, Addnstr */

Modules/_decimal/_decimal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ ctxmanager_dealloc(PyDecContextManagerObject *self)
17651765
{
17661766
Py_XDECREF(self->local);
17671767
Py_XDECREF(self->global);
1768-
PyObject_Del(self);
1768+
PyObject_Free(self);
17691769
}
17701770

17711771
static PyObject *

Modules/_functoolsmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ keyobject_dealloc(keyobject *ko)
478478
{
479479
Py_DECREF(ko->cmp);
480480
Py_XDECREF(ko->object);
481-
PyObject_FREE(ko);
481+
PyObject_Free(ko);
482482
}
483483

484484
static int
@@ -742,7 +742,7 @@ lru_list_elem_dealloc(lru_list_elem *link)
742742
{
743743
Py_XDECREF(link->key);
744744
Py_XDECREF(link->result);
745-
PyObject_Del(link);
745+
PyObject_Free(link);
746746
}
747747

748748
static PyTypeObject lru_list_elem_type = {

Modules/_hashopenssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ EVP_dealloc(EVPobject *self)
341341
if (self->lock != NULL)
342342
PyThread_free_lock(self->lock);
343343
EVP_MD_CTX_free(self->ctx);
344-
PyObject_Del(self);
344+
PyObject_Free(self);
345345
Py_DECREF(tp);
346346
}
347347

@@ -1453,7 +1453,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
14531453

14541454
error:
14551455
if (ctx) HMAC_CTX_free(ctx);
1456-
if (self) PyObject_Del(self);
1456+
if (self) PyObject_Free(self);
14571457
return NULL;
14581458
}
14591459

@@ -1546,7 +1546,7 @@ _hmac_dealloc(HMACobject *self)
15461546
PyThread_free_lock(self->lock);
15471547
}
15481548
HMAC_CTX_free(self->ctx);
1549-
PyObject_Del(self);
1549+
PyObject_Free(self);
15501550
Py_DECREF(tp);
15511551
}
15521552

0 commit comments

Comments
 (0)