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

Diff for: Include/objimpl.h

+3-1
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

Diff for: Include/pymem.h

+4-2
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

Diff for: Modules/_blake2/blake2b_impl.c

+1-1
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

Diff for: Modules/_blake2/blake2s_impl.c

+1-1
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

Diff for: Modules/_ctypes/callproc.c

+1-1
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

Diff for: Modules/_curses_panel.c

+1-1
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

Diff for: Modules/_cursesmodule.c

+1-1
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 */

Diff for: Modules/_decimal/_decimal.c

+1-1
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 *

Diff for: Modules/_functoolsmodule.c

+2-2
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 = {

Diff for: Modules/_hashopenssl.c

+3-3
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

Diff for: Modules/_multiprocessing/semaphore.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ semlock_dealloc(SemLockObject* self)
571571
if (self->handle != SEM_FAILED)
572572
SEM_CLOSE(self->handle);
573573
PyMem_Free(self->name);
574-
PyObject_Del(self);
574+
PyObject_Free(self);
575575
}
576576

577577
/*[clinic input]

Diff for: Modules/_pickle.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ Pdata_dealloc(Pdata *self)
443443
Py_DECREF(self->data[i]);
444444
}
445445
PyMem_Free(self->data);
446-
PyObject_Del(self);
446+
PyObject_Free(self);
447447
}
448448

449449
static PyTypeObject Pdata_Type = {

Diff for: Modules/_sha3/sha3module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ SHA3_dealloc(SHA3object *self)
274274
}
275275

276276
PyTypeObject *tp = Py_TYPE(self);
277-
PyObject_Del(self);
277+
PyObject_Free(self);
278278
Py_DECREF(tp);
279279
}
280280

Diff for: Modules/_sre.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ pattern_dealloc(PatternObject* self)
571571
Py_XDECREF(self->pattern);
572572
Py_XDECREF(self->groupindex);
573573
Py_XDECREF(self->indexgroup);
574-
PyObject_DEL(self);
574+
PyObject_Free(self);
575575
Py_DECREF(tp);
576576
}
577577

@@ -1944,7 +1944,7 @@ match_dealloc(MatchObject* self)
19441944
Py_XDECREF(self->regs);
19451945
Py_XDECREF(self->string);
19461946
Py_DECREF(self->pattern);
1947-
PyObject_DEL(self);
1947+
PyObject_Free(self);
19481948
Py_DECREF(tp);
19491949
}
19501950

@@ -2450,7 +2450,7 @@ scanner_dealloc(ScannerObject* self)
24502450

24512451
state_fini(&self->state);
24522452
Py_XDECREF(self->pattern);
2453-
PyObject_DEL(self);
2453+
PyObject_Free(self);
24542454
Py_DECREF(tp);
24552455
}
24562456

Diff for: Modules/_ssl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,7 @@ PySSL_dealloc(PySSLSocket *self)
22952295
Py_XDECREF(self->ctx);
22962296
Py_XDECREF(self->server_hostname);
22972297
Py_XDECREF(self->owner);
2298-
PyObject_Del(self);
2298+
PyObject_Free(self);
22992299
Py_DECREF(tp);
23002300
}
23012301

Diff for: Modules/_testbuffer.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ ndarray_dealloc(NDArrayObject *self)
236236
ndbuf_pop(self);
237237
}
238238
}
239-
PyObject_Del(self);
239+
PyObject_Free(self);
240240
}
241241

242242
static int
@@ -2734,7 +2734,7 @@ staticarray_init(PyObject *self, PyObject *args, PyObject *kwds)
27342734
static void
27352735
staticarray_dealloc(StaticArrayObject *self)
27362736
{
2737-
PyObject_Del(self);
2737+
PyObject_Free(self);
27382738
}
27392739

27402740
/* Return a buffer for a PyBUF_FULL_RO request. Flags are not checked,

Diff for: Modules/_testcapimodule.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -6010,7 +6010,7 @@ test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
60106010
static void
60116011
test_structmembers_free(PyObject *ob)
60126012
{
6013-
PyObject_FREE(ob);
6013+
PyObject_Free(ob);
60146014
}
60156015

60166016
static PyTypeObject test_structmembersType = {
@@ -6664,7 +6664,7 @@ static void
66646664
heapctype_dealloc(HeapCTypeObject *self)
66656665
{
66666666
PyTypeObject *tp = Py_TYPE(self);
6667-
PyObject_Del(self);
6667+
PyObject_Free(self);
66686668
Py_DECREF(tp);
66696669
}
66706670

@@ -6854,7 +6854,7 @@ heapctypewithdict_dealloc(HeapCTypeWithDictObject* self)
68546854

68556855
PyTypeObject *tp = Py_TYPE(self);
68566856
Py_XDECREF(self->dict);
6857-
PyObject_DEL(self);
6857+
PyObject_Free(self);
68586858
Py_DECREF(tp);
68596859
}
68606860

@@ -6925,7 +6925,7 @@ heapctypewithweakref_dealloc(HeapCTypeWithWeakrefObject* self)
69256925
if (self->weakreflist != NULL)
69266926
PyObject_ClearWeakRefs((PyObject *) self);
69276927
Py_XDECREF(self->weakreflist);
6928-
PyObject_DEL(self);
6928+
PyObject_Free(self);
69296929
Py_DECREF(tp);
69306930
}
69316931

@@ -6968,7 +6968,7 @@ static void
69686968
heapctypesetattr_dealloc(HeapCTypeSetattrObject *self)
69696969
{
69706970
PyTypeObject *tp = Py_TYPE(self);
6971-
PyObject_Del(self);
6971+
PyObject_Free(self);
69726972
Py_DECREF(tp);
69736973
}
69746974

Diff for: Modules/_threadmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ lock_dealloc(lockobject *self)
3434
PyThread_release_lock(self->lock_lock);
3535
PyThread_free_lock(self->lock_lock);
3636
}
37-
PyObject_Del(self);
37+
PyObject_Free(self);
3838
}
3939

4040
/* Helper to acquire an interruptible lock with a timeout. If the lock acquire

Diff for: Modules/_tkinter.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ PyTclObject_dealloc(PyTclObject *self)
904904
PyObject *tp = (PyObject *) Py_TYPE(self);
905905
Tcl_DecrRefCount(self->value);
906906
Py_XDECREF(self->string);
907-
PyObject_Del(self);
907+
PyObject_Free(self);
908908
Py_DECREF(tp);
909909
}
910910

@@ -2823,7 +2823,7 @@ Tktt_Dealloc(PyObject *self)
28232823

28242824
Py_XDECREF(func);
28252825

2826-
PyObject_Del(self);
2826+
PyObject_Free(self);
28272827
Py_DECREF(tp);
28282828
}
28292829

@@ -3096,7 +3096,7 @@ Tkapp_Dealloc(PyObject *self)
30963096
ENTER_TCL
30973097
Tcl_DeleteInterp(Tkapp_Interp(self));
30983098
LEAVE_TCL
3099-
PyObject_Del(self);
3099+
PyObject_Free(self);
31003100
Py_DECREF(tp);
31013101
DisableEventHook();
31023102
}

Diff for: Modules/cjkcodecs/multibytecodec.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static struct PyMethodDef multibytecodec_methods[] = {
691691
static void
692692
multibytecodec_dealloc(MultibyteCodecObject *self)
693693
{
694-
PyObject_Del(self);
694+
PyObject_Free(self);
695695
}
696696

697697
static PyTypeObject MultibyteCodec_Type = {

Diff for: Modules/gcmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ _PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
22902290
}
22912291

22922292
PyGC_Head *g = AS_GC(op);
2293-
g = (PyGC_Head *)PyObject_REALLOC(g, sizeof(PyGC_Head) + basicsize);
2293+
g = (PyGC_Head *)PyObject_Realloc(g, sizeof(PyGC_Head) + basicsize);
22942294
if (g == NULL)
22952295
return (PyVarObject *)PyErr_NoMemory();
22962296
op = (PyVarObject *) FROM_GC(g);
@@ -2309,7 +2309,7 @@ PyObject_GC_Del(void *op)
23092309
if (gcstate->generations[0].count > 0) {
23102310
gcstate->generations[0].count--;
23112311
}
2312-
PyObject_FREE(g);
2312+
PyObject_Free(g);
23132313
}
23142314

23152315
int

Diff for: Modules/md5module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static void
342342
MD5_dealloc(PyObject *ptr)
343343
{
344344
PyTypeObject *tp = Py_TYPE(ptr);
345-
PyObject_Del(ptr);
345+
PyObject_Free(ptr);
346346
Py_DECREF(tp);
347347
}
348348

Diff for: Modules/ossaudiodev.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ oss_dealloc(oss_audio_t *self)
154154
/* if already closed, don't reclose it */
155155
if (self->fd != -1)
156156
close(self->fd);
157-
PyObject_Del(self);
157+
PyObject_Free(self);
158158
}
159159

160160

@@ -199,7 +199,7 @@ oss_mixer_dealloc(oss_mixer_t *self)
199199
/* if already closed, don't reclose it */
200200
if (self->fd != -1)
201201
close(self->fd);
202-
PyObject_Del(self);
202+
PyObject_Free(self);
203203
}
204204

205205

Diff for: Modules/overlapped.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ Overlapped_dealloc(OverlappedObject *self)
722722
SetLastError(olderr);
723723

724724
PyTypeObject *tp = Py_TYPE(self);
725-
PyObject_Del(self);
725+
PyObject_Free(self);
726726
Py_DECREF(tp);
727727
}
728728

Diff for: Modules/selectmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ poll_dealloc(pollObject *self)
742742
if (self->ufds != NULL)
743743
PyMem_Free(self->ufds);
744744
Py_XDECREF(self->dict);
745-
PyObject_Del(self);
745+
PyObject_Free(self);
746746
Py_DECREF(type);
747747
}
748748

@@ -1130,7 +1130,7 @@ devpoll_dealloc(devpollObject *self)
11301130
PyObject *type = (PyObject *)Py_TYPE(self);
11311131
(void)devpoll_internal_close(self);
11321132
PyMem_Free(self->fds);
1133-
PyObject_Del(self);
1133+
PyObject_Free(self);
11341134
Py_DECREF(type);
11351135
}
11361136

Diff for: Modules/sha1module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static void
320320
SHA1_dealloc(PyObject *ptr)
321321
{
322322
PyTypeObject *tp = Py_TYPE(ptr);
323-
PyObject_Del(ptr);
323+
PyObject_Free(ptr);
324324
Py_DECREF(tp);
325325
}
326326

Diff for: Modules/sha256module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static void
397397
SHA_dealloc(PyObject *ptr)
398398
{
399399
PyTypeObject *tp = Py_TYPE(ptr);
400-
PyObject_Del(ptr);
400+
PyObject_Free(ptr);
401401
Py_DECREF(tp);
402402
}
403403

0 commit comments

Comments
 (0)