From 32bd68c839adb7b42af12366ab0892303115d1d1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 1 Dec 2020 10:37:39 +0100 Subject: [PATCH] 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() --- Include/objimpl.h | 4 ++- Include/pymem.h | 6 ++-- Modules/_blake2/blake2b_impl.c | 2 +- Modules/_blake2/blake2s_impl.c | 2 +- Modules/_ctypes/callproc.c | 2 +- Modules/_curses_panel.c | 2 +- Modules/_cursesmodule.c | 2 +- Modules/_decimal/_decimal.c | 2 +- Modules/_functoolsmodule.c | 4 +-- Modules/_hashopenssl.c | 6 ++-- Modules/_multiprocessing/semaphore.c | 2 +- Modules/_pickle.c | 2 +- Modules/_sha3/sha3module.c | 2 +- Modules/_sre.c | 6 ++-- Modules/_ssl.c | 2 +- Modules/_testbuffer.c | 4 +-- Modules/_testcapimodule.c | 10 +++---- Modules/_threadmodule.c | 2 +- Modules/_tkinter.c | 6 ++-- Modules/cjkcodecs/multibytecodec.c | 2 +- Modules/gcmodule.c | 4 +-- Modules/md5module.c | 2 +- Modules/ossaudiodev.c | 4 +-- Modules/overlapped.c | 2 +- Modules/selectmodule.c | 4 +-- Modules/sha1module.c | 2 +- Modules/sha256module.c | 2 +- Modules/sha512module.c | 2 +- Modules/sre_lib.h | 4 +-- Modules/unicodedata.c | 2 +- Modules/xxmodule.c | 2 +- Modules/zlibmodule.c | 2 +- Objects/bytesobject.c | 8 +++--- Objects/capsule.c | 2 +- Objects/codeobject.c | 2 +- Objects/complexobject.c | 2 +- Objects/dictobject.c | 8 +++--- Objects/floatobject.c | 4 +-- Objects/longobject.c | 2 +- Objects/object.c | 4 +-- Objects/odictobject.c | 2 +- Objects/rangeobject.c | 4 +-- Objects/stringlib/unicode_format.h | 4 +-- Objects/typeobject.c | 6 ++-- Objects/unicodeobject.c | 42 ++++++++++++++-------------- PC/_msi.c | 2 +- PC/winreg.c | 4 +-- Python/symtable.c | 2 +- 48 files changed, 102 insertions(+), 98 deletions(-) diff --git a/Include/objimpl.h b/Include/objimpl.h index 464b1bf93ba..1408d051ba7 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -38,7 +38,7 @@ Functions and macros for modules that implement new object types. object with room for n items. In addition to the refcount and type pointer fields, this also fills in the ob_size field. - - PyObject_Del(op) releases the memory allocated for an object. It does not + - PyObject_Free(op) releases the memory allocated for an object. It does not run a destructor -- it only frees the memory. PyObject_Free is identical. - PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) don't @@ -103,6 +103,8 @@ PyAPI_FUNC(void) PyObject_Free(void *ptr); // Deprecated aliases only kept for backward compatibility. +// PyObject_Del and PyObject_DEL are defined with no parameter to be able to +// use them as function pointers (ex: tp_free = PyObject_Del). #define PyObject_MALLOC PyObject_Malloc #define PyObject_REALLOC PyObject_Realloc #define PyObject_FREE PyObject_Free diff --git a/Include/pymem.h b/Include/pymem.h index 5b9dd421994..92cd5369589 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -79,13 +79,15 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr); // Deprecated aliases only kept for backward compatibility. +// PyMem_Del and PyMem_DEL are defined with no parameter to be able to use +// them as function pointers (ex: dealloc = PyMem_Del). #define PyMem_MALLOC(n) PyMem_Malloc(n) #define PyMem_NEW(type, n) PyMem_New(type, n) #define PyMem_REALLOC(p, n) PyMem_Realloc(p, n) #define PyMem_RESIZE(p, type, n) PyMem_Resize(p, type, n) #define PyMem_FREE(p) PyMem_Free(p) -#define PyMem_Del(p) PyMem_Free(p) -#define PyMem_DEL(p) PyMem_Free(p) +#define PyMem_Del PyMem_Free +#define PyMem_DEL PyMem_Free #ifndef Py_LIMITED_API diff --git a/Modules/_blake2/blake2b_impl.c b/Modules/_blake2/blake2b_impl.c index 8e1acce56b1..5d108ed008a 100644 --- a/Modules/_blake2/blake2b_impl.c +++ b/Modules/_blake2/blake2b_impl.c @@ -393,7 +393,7 @@ py_blake2b_dealloc(PyObject *self) } PyTypeObject *type = Py_TYPE(self); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(type); } diff --git a/Modules/_blake2/blake2s_impl.c b/Modules/_blake2/blake2s_impl.c index e1de5df37d0..85c2d4edad7 100644 --- a/Modules/_blake2/blake2s_impl.c +++ b/Modules/_blake2/blake2s_impl.c @@ -392,7 +392,7 @@ py_blake2s_dealloc(PyObject *self) } PyTypeObject *type = Py_TYPE(self); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(type); } diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 9b629877a8a..40a05a44edd 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -475,7 +475,7 @@ static void PyCArg_dealloc(PyCArgObject *self) { Py_XDECREF(self->obj); - PyObject_Del(self); + PyObject_Free(self); } static int diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c index 1a8f0b63682..7d252244e24 100644 --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -282,7 +282,7 @@ PyCursesPanel_Dealloc(PyCursesPanelObject *po) Py_DECREF(po->wo); remove_lop(po); } - PyObject_DEL(po); + PyObject_Free(po); Py_DECREF(tp); } diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index a59858632e7..1f4789baf7a 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -689,7 +689,7 @@ PyCursesWindow_Dealloc(PyCursesWindowObject *wo) if (wo->win != stdscr) delwin(wo->win); if (wo->encoding != NULL) PyMem_Free(wo->encoding); - PyObject_DEL(wo); + PyObject_Free(wo); } /* Addch, Addstr, Addnstr */ diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index ea16c5a6cd9..9c85d76c6b5 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1765,7 +1765,7 @@ ctxmanager_dealloc(PyDecContextManagerObject *self) { Py_XDECREF(self->local); Py_XDECREF(self->global); - PyObject_Del(self); + PyObject_Free(self); } static PyObject * diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 9fad21fc332..ff03c334766 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -478,7 +478,7 @@ keyobject_dealloc(keyobject *ko) { Py_DECREF(ko->cmp); Py_XDECREF(ko->object); - PyObject_FREE(ko); + PyObject_Free(ko); } static int @@ -742,7 +742,7 @@ lru_list_elem_dealloc(lru_list_elem *link) { Py_XDECREF(link->key); Py_XDECREF(link->result); - PyObject_Del(link); + PyObject_Free(link); } static PyTypeObject lru_list_elem_type = { diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 7e176cf21d6..d4295d7c363 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -341,7 +341,7 @@ EVP_dealloc(EVPobject *self) if (self->lock != NULL) PyThread_free_lock(self->lock); EVP_MD_CTX_free(self->ctx); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } @@ -1453,7 +1453,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj, error: if (ctx) HMAC_CTX_free(ctx); - if (self) PyObject_Del(self); + if (self) PyObject_Free(self); return NULL; } @@ -1546,7 +1546,7 @@ _hmac_dealloc(HMACobject *self) PyThread_free_lock(self->lock); } HMAC_CTX_free(self->ctx); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index 8732750e11b..9a2d1f85c92 100644 --- a/Modules/_multiprocessing/semaphore.c +++ b/Modules/_multiprocessing/semaphore.c @@ -571,7 +571,7 @@ semlock_dealloc(SemLockObject* self) if (self->handle != SEM_FAILED) SEM_CLOSE(self->handle); PyMem_Free(self->name); - PyObject_Del(self); + PyObject_Free(self); } /*[clinic input] diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 7ecaeea18c6..5a8aad9de76 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -443,7 +443,7 @@ Pdata_dealloc(Pdata *self) Py_DECREF(self->data[i]); } PyMem_Free(self->data); - PyObject_Del(self); + PyObject_Free(self); } static PyTypeObject Pdata_Type = { diff --git a/Modules/_sha3/sha3module.c b/Modules/_sha3/sha3module.c index da6dde6812f..cae10f99d5b 100644 --- a/Modules/_sha3/sha3module.c +++ b/Modules/_sha3/sha3module.c @@ -274,7 +274,7 @@ SHA3_dealloc(SHA3object *self) } PyTypeObject *tp = Py_TYPE(self); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } diff --git a/Modules/_sre.c b/Modules/_sre.c index c67f38d75b8..57faf7bdaae 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -571,7 +571,7 @@ pattern_dealloc(PatternObject* self) Py_XDECREF(self->pattern); Py_XDECREF(self->groupindex); Py_XDECREF(self->indexgroup); - PyObject_DEL(self); + PyObject_Free(self); Py_DECREF(tp); } @@ -1944,7 +1944,7 @@ match_dealloc(MatchObject* self) Py_XDECREF(self->regs); Py_XDECREF(self->string); Py_DECREF(self->pattern); - PyObject_DEL(self); + PyObject_Free(self); Py_DECREF(tp); } @@ -2450,7 +2450,7 @@ scanner_dealloc(ScannerObject* self) state_fini(&self->state); Py_XDECREF(self->pattern); - PyObject_DEL(self); + PyObject_Free(self); Py_DECREF(tp); } diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 87fe3a16078..edb850ee461 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -2295,7 +2295,7 @@ PySSL_dealloc(PySSLSocket *self) Py_XDECREF(self->ctx); Py_XDECREF(self->server_hostname); Py_XDECREF(self->owner); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c index d8321768bc9..1b4fb09fb8f 100644 --- a/Modules/_testbuffer.c +++ b/Modules/_testbuffer.c @@ -236,7 +236,7 @@ ndarray_dealloc(NDArrayObject *self) ndbuf_pop(self); } } - PyObject_Del(self); + PyObject_Free(self); } static int @@ -2734,7 +2734,7 @@ staticarray_init(PyObject *self, PyObject *args, PyObject *kwds) static void staticarray_dealloc(StaticArrayObject *self) { - PyObject_Del(self); + PyObject_Free(self); } /* Return a buffer for a PyBUF_FULL_RO request. Flags are not checked, diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 916d10a1e41..d2104423c58 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -6010,7 +6010,7 @@ test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static void test_structmembers_free(PyObject *ob) { - PyObject_FREE(ob); + PyObject_Free(ob); } static PyTypeObject test_structmembersType = { @@ -6664,7 +6664,7 @@ static void heapctype_dealloc(HeapCTypeObject *self) { PyTypeObject *tp = Py_TYPE(self); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } @@ -6854,7 +6854,7 @@ heapctypewithdict_dealloc(HeapCTypeWithDictObject* self) PyTypeObject *tp = Py_TYPE(self); Py_XDECREF(self->dict); - PyObject_DEL(self); + PyObject_Free(self); Py_DECREF(tp); } @@ -6925,7 +6925,7 @@ heapctypewithweakref_dealloc(HeapCTypeWithWeakrefObject* self) if (self->weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *) self); Py_XDECREF(self->weakreflist); - PyObject_DEL(self); + PyObject_Free(self); Py_DECREF(tp); } @@ -6968,7 +6968,7 @@ static void heapctypesetattr_dealloc(HeapCTypeSetattrObject *self) { PyTypeObject *tp = Py_TYPE(self); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index dcefa8dbaa9..86d5f544fcf 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -34,7 +34,7 @@ lock_dealloc(lockobject *self) PyThread_release_lock(self->lock_lock); PyThread_free_lock(self->lock_lock); } - PyObject_Del(self); + PyObject_Free(self); } /* Helper to acquire an interruptible lock with a timeout. If the lock acquire diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 24aeb3da94c..46d6a6e0954 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -904,7 +904,7 @@ PyTclObject_dealloc(PyTclObject *self) PyObject *tp = (PyObject *) Py_TYPE(self); Tcl_DecrRefCount(self->value); Py_XDECREF(self->string); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } @@ -2823,7 +2823,7 @@ Tktt_Dealloc(PyObject *self) Py_XDECREF(func); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } @@ -3096,7 +3096,7 @@ Tkapp_Dealloc(PyObject *self) ENTER_TCL Tcl_DeleteInterp(Tkapp_Interp(self)); LEAVE_TCL - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); DisableEventHook(); } diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 37a80a781da..9208b86b0c9 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -691,7 +691,7 @@ static struct PyMethodDef multibytecodec_methods[] = { static void multibytecodec_dealloc(MultibyteCodecObject *self) { - PyObject_Del(self); + PyObject_Free(self); } static PyTypeObject MultibyteCodec_Type = { diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 45201435f24..fdbba6a7afc 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -2290,7 +2290,7 @@ _PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems) } PyGC_Head *g = AS_GC(op); - g = (PyGC_Head *)PyObject_REALLOC(g, sizeof(PyGC_Head) + basicsize); + g = (PyGC_Head *)PyObject_Realloc(g, sizeof(PyGC_Head) + basicsize); if (g == NULL) return (PyVarObject *)PyErr_NoMemory(); op = (PyVarObject *) FROM_GC(g); @@ -2309,7 +2309,7 @@ PyObject_GC_Del(void *op) if (gcstate->generations[0].count > 0) { gcstate->generations[0].count--; } - PyObject_FREE(g); + PyObject_Free(g); } int diff --git a/Modules/md5module.c b/Modules/md5module.c index 9bd2bd17e4f..1c401e88438 100644 --- a/Modules/md5module.c +++ b/Modules/md5module.c @@ -342,7 +342,7 @@ static void MD5_dealloc(PyObject *ptr) { PyTypeObject *tp = Py_TYPE(ptr); - PyObject_Del(ptr); + PyObject_Free(ptr); Py_DECREF(tp); } diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c index 2a1ac10814a..4f2d9cb8b7c 100644 --- a/Modules/ossaudiodev.c +++ b/Modules/ossaudiodev.c @@ -154,7 +154,7 @@ oss_dealloc(oss_audio_t *self) /* if already closed, don't reclose it */ if (self->fd != -1) close(self->fd); - PyObject_Del(self); + PyObject_Free(self); } @@ -199,7 +199,7 @@ oss_mixer_dealloc(oss_mixer_t *self) /* if already closed, don't reclose it */ if (self->fd != -1) close(self->fd); - PyObject_Del(self); + PyObject_Free(self); } diff --git a/Modules/overlapped.c b/Modules/overlapped.c index 3829932070a..38dd98f0848 100644 --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -722,7 +722,7 @@ Overlapped_dealloc(OverlappedObject *self) SetLastError(olderr); PyTypeObject *tp = Py_TYPE(self); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 0b9f20d6bbd..f80da589540 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -742,7 +742,7 @@ poll_dealloc(pollObject *self) if (self->ufds != NULL) PyMem_Free(self->ufds); Py_XDECREF(self->dict); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(type); } @@ -1130,7 +1130,7 @@ devpoll_dealloc(devpollObject *self) PyObject *type = (PyObject *)Py_TYPE(self); (void)devpoll_internal_close(self); PyMem_Free(self->fds); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(type); } diff --git a/Modules/sha1module.c b/Modules/sha1module.c index c22437de256..5209857041d 100644 --- a/Modules/sha1module.c +++ b/Modules/sha1module.c @@ -320,7 +320,7 @@ static void SHA1_dealloc(PyObject *ptr) { PyTypeObject *tp = Py_TYPE(ptr); - PyObject_Del(ptr); + PyObject_Free(ptr); Py_DECREF(tp); } diff --git a/Modules/sha256module.c b/Modules/sha256module.c index edd4d010928..6b8bd8f1d27 100644 --- a/Modules/sha256module.c +++ b/Modules/sha256module.c @@ -397,7 +397,7 @@ static void SHA_dealloc(PyObject *ptr) { PyTypeObject *tp = Py_TYPE(ptr); - PyObject_Del(ptr); + PyObject_Free(ptr); Py_DECREF(tp); } diff --git a/Modules/sha512module.c b/Modules/sha512module.c index 725098def4d..3fd9fa4c8d1 100644 --- a/Modules/sha512module.c +++ b/Modules/sha512module.c @@ -453,7 +453,7 @@ static void SHA512_dealloc(PyObject *ptr) { PyTypeObject *tp = Py_TYPE(ptr); - PyObject_Del(ptr); + PyObject_Free(ptr); Py_DECREF(tp); } diff --git a/Modules/sre_lib.h b/Modules/sre_lib.h index cfe0a4af2c4..322f66fb4da 100644 --- a/Modules/sre_lib.h +++ b/Modules/sre_lib.h @@ -986,7 +986,7 @@ entrance: ctx->pattern[1], ctx->pattern[2])); /* install new repeat context */ - ctx->u.rep = (SRE_REPEAT*) PyObject_MALLOC(sizeof(*ctx->u.rep)); + ctx->u.rep = (SRE_REPEAT*) PyObject_Malloc(sizeof(*ctx->u.rep)); if (!ctx->u.rep) { PyErr_NoMemory(); RETURN_FAILURE; @@ -1000,7 +1000,7 @@ entrance: state->ptr = ctx->ptr; DO_JUMP(JUMP_REPEAT, jump_repeat, ctx->pattern+ctx->pattern[0]); state->repeat = ctx->u.rep->prev; - PyObject_FREE(ctx->u.rep); + PyObject_Free(ctx->u.rep); if (ret) { RETURN_ON_ERROR(ret); diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index fcf801dc9e4..4b8c46c7797 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -1418,7 +1418,7 @@ static void ucd_dealloc(PreviousDBVersion *self) { PyTypeObject *tp = Py_TYPE(self); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(tp); } diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c index 17b049c4b9a..edcd62157c0 100644 --- a/Modules/xxmodule.c +++ b/Modules/xxmodule.c @@ -44,7 +44,7 @@ static void Xxo_dealloc(XxoObject *self) { Py_XDECREF(self->x_attr); - PyObject_Del(self); + PyObject_Free(self); } static PyObject * diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index def617671f1..a537087d19d 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -591,7 +591,7 @@ Dealloc(compobject *self) Py_XDECREF(self->unused_data); Py_XDECREF(self->unconsumed_tail); Py_XDECREF(self->zdict); - PyObject_Del(self); + PyObject_Free(self); Py_DECREF(type); } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index bb844090b86..13216b9bb21 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -198,7 +198,7 @@ PyBytes_FromString(const char *str) } /* Inline PyObject_NewVar */ - op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + size); + op = (PyBytesObject *)PyObject_Malloc(PyBytesObject_SIZE + size); if (op == NULL) { return PyErr_NoMemory(); } @@ -1475,7 +1475,7 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n) "repeated bytes are too long"); return NULL; } - op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + nbytes); + op = (PyBytesObject *)PyObject_Malloc(PyBytesObject_SIZE + nbytes); if (op == NULL) { return PyErr_NoMemory(); } @@ -3054,9 +3054,9 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize) _Py_ForgetReference(v); #endif *pv = (PyObject *) - PyObject_REALLOC(v, PyBytesObject_SIZE + newsize); + PyObject_Realloc(v, PyBytesObject_SIZE + newsize); if (*pv == NULL) { - PyObject_Del(v); + PyObject_Free(v); PyErr_NoMemory(); return -1; } diff --git a/Objects/capsule.c b/Objects/capsule.c index a2ff642526c..800a6c4b25c 100644 --- a/Objects/capsule.c +++ b/Objects/capsule.c @@ -260,7 +260,7 @@ capsule_dealloc(PyObject *o) if (capsule->destructor) { capsule->destructor(o); } - PyObject_DEL(o); + PyObject_Free(o); } diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 0257295f1e9..0b0b8f98ae4 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -669,7 +669,7 @@ code_dealloc(PyCodeObject *co) PyObject_GC_Del(co->co_zombieframe); if (co->co_weakreflist != NULL) PyObject_ClearWeakRefs((PyObject*)co); - PyObject_DEL(co); + PyObject_Free(co); } static PyObject * diff --git a/Objects/complexobject.c b/Objects/complexobject.c index a481d9ad8bb..a65ebdfa6cd 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -233,7 +233,7 @@ PyObject * PyComplex_FromCComplex(Py_complex cval) { /* Inline PyObject_New */ - PyComplexObject *op = PyObject_MALLOC(sizeof(PyComplexObject)); + PyComplexObject *op = PyObject_Malloc(sizeof(PyComplexObject)); if (op == NULL) { return PyErr_NoMemory(); } diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ee1a9d1d7e7..7a37313df8a 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -269,7 +269,7 @@ _PyDict_ClearFreeList(PyThreadState *tstate) PyObject_GC_Del(op); } while (state->keys_numfree) { - PyObject_FREE(state->keys_free_list[--state->keys_numfree]); + PyObject_Free(state->keys_free_list[--state->keys_numfree]); } } @@ -597,7 +597,7 @@ new_keys_object(Py_ssize_t size) } else { - dk = PyObject_MALLOC(sizeof(PyDictKeysObject) + dk = PyObject_Malloc(sizeof(PyDictKeysObject) + es * size + sizeof(PyDictKeyEntry) * usable); if (dk == NULL) { @@ -636,7 +636,7 @@ free_keys_object(PyDictKeysObject *keys) state->keys_free_list[state->keys_numfree++] = keys; return; } - PyObject_FREE(keys); + PyObject_Free(keys); } #define new_values(size) PyMem_NEW(PyObject *, size) @@ -1303,7 +1303,7 @@ dictresize(PyDictObject *mp, Py_ssize_t newsize) state->keys_free_list[state->keys_numfree++] = oldkeys; } else { - PyObject_FREE(oldkeys); + PyObject_Free(oldkeys); } } diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 1550b2eedc8..34fb57a946a 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -237,7 +237,7 @@ float_dealloc(PyFloatObject *op) assert(state->numfree != -1); #endif if (state->numfree >= PyFloat_MAXFREELIST) { - PyObject_FREE(op); + PyObject_Free(op); return; } state->numfree++; @@ -2032,7 +2032,7 @@ _PyFloat_ClearFreeList(PyThreadState *tstate) PyFloatObject *f = state->free_list; while (f != NULL) { PyFloatObject *next = (PyFloatObject*) Py_TYPE(f); - PyObject_FREE(f); + PyObject_Free(f); f = next; } state->free_list = NULL; diff --git a/Objects/longobject.c b/Objects/longobject.c index e0d6410fe68..240e92a41e0 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -131,7 +131,7 @@ _PyLong_New(Py_ssize_t size) "too many digits in integer"); return NULL; } - result = PyObject_MALLOC(offsetof(PyLongObject, ob_digit) + + result = PyObject_Malloc(offsetof(PyLongObject, ob_digit) + size*sizeof(digit)); if (!result) { PyErr_NoMemory(); diff --git a/Objects/object.c b/Objects/object.c index 2e8717f506c..0a8621b3503 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -161,7 +161,7 @@ PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size) PyObject * _PyObject_New(PyTypeObject *tp) { - PyObject *op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp)); + PyObject *op = (PyObject *) PyObject_Malloc(_PyObject_SIZE(tp)); if (op == NULL) { return PyErr_NoMemory(); } @@ -174,7 +174,7 @@ _PyObject_NewVar(PyTypeObject *tp, Py_ssize_t nitems) { PyVarObject *op; const size_t size = _PyObject_VAR_SIZE(tp, nitems); - op = (PyVarObject *) PyObject_MALLOC(size); + op = (PyVarObject *) PyObject_Malloc(size); if (op == NULL) { return (PyVarObject *)PyErr_NoMemory(); } diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 83b326b2067..4eb15f999bd 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -459,7 +459,7 @@ later: - implement a fuller MutableMapping API in C? - move the MutableMapping implementation to abstract.c? - optimize mutablemapping_update -- use PyObject_MALLOC (small object allocator) for odict nodes? +- use PyObject_Malloc (small object allocator) for odict nodes? - support subclasses better (e.g. in odict_richcompare) */ diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 787d1138009..530426c8ac9 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -171,7 +171,7 @@ range_dealloc(rangeobject *r) Py_DECREF(r->stop); Py_DECREF(r->step); Py_DECREF(r->length); - PyObject_Del(r); + PyObject_Free(r); } /* Return number of items in range (lo, hi, step) as a PyLong object, @@ -1021,7 +1021,7 @@ longrangeiter_dealloc(longrangeiterobject *r) Py_XDECREF(r->start); Py_XDECREF(r->step); Py_XDECREF(r->len); - PyObject_Del(r); + PyObject_Free(r); } static PyObject * diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h index b526ad21b82..7152ec6ebe7 100644 --- a/Objects/stringlib/unicode_format.h +++ b/Objects/stringlib/unicode_format.h @@ -983,7 +983,7 @@ static void formatteriter_dealloc(formatteriterobject *it) { Py_XDECREF(it->str); - PyObject_FREE(it); + PyObject_Free(it); } /* returns a tuple: @@ -1147,7 +1147,7 @@ static void fieldnameiter_dealloc(fieldnameiterobject *it) { Py_XDECREF(it->str); - PyObject_FREE(it); + PyObject_Free(it); } /* returns a tuple: diff --git a/Objects/typeobject.c b/Objects/typeobject.c index fbadd31f1a4..83bc877eb7d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1059,7 +1059,7 @@ PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) obj = _PyObject_GC_Malloc(size); } else { - obj = (PyObject *)PyObject_MALLOC(size); + obj = (PyObject *)PyObject_Malloc(size); } if (obj == NULL) { @@ -2707,7 +2707,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) goto error; /* Silently truncate the docstring if it contains null bytes. */ len = strlen(doc_str); - tp_doc = (char *)PyObject_MALLOC(len + 1); + tp_doc = (char *)PyObject_Malloc(len + 1); if (tp_doc == NULL) { PyErr_NoMemory(); goto error; @@ -3047,7 +3047,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) continue; } size_t len = strlen(slot->pfunc)+1; - char *tp_doc = PyObject_MALLOC(len); + char *tp_doc = PyObject_Malloc(len); if (tp_doc == NULL) { type->tp_doc = NULL; PyErr_NoMemory(); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index ba6d07a67d2..f6473c02d30 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1061,7 +1061,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length) new_size = (struct_size + (length + 1) * char_size); if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) { - PyObject_DEL(_PyUnicode_UTF8(unicode)); + PyObject_Free(_PyUnicode_UTF8(unicode)); _PyUnicode_UTF8(unicode) = NULL; _PyUnicode_UTF8_LENGTH(unicode) = 0; } @@ -1072,7 +1072,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length) _Py_ForgetReference(unicode); #endif - new_unicode = (PyObject *)PyObject_REALLOC(unicode, new_size); + new_unicode = (PyObject *)PyObject_Realloc(unicode, new_size); if (new_unicode == NULL) { _Py_NewReference(unicode); PyErr_NoMemory(); @@ -1088,7 +1088,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length) _PyUnicode_WSTR_LENGTH(unicode) = length; } else if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) { - PyObject_DEL(_PyUnicode_WSTR(unicode)); + PyObject_Free(_PyUnicode_WSTR(unicode)); _PyUnicode_WSTR(unicode) = NULL; if (!PyUnicode_IS_ASCII(unicode)) _PyUnicode_WSTR_LENGTH(unicode) = 0; @@ -1131,12 +1131,12 @@ resize_inplace(PyObject *unicode, Py_ssize_t length) if (!share_utf8 && _PyUnicode_HAS_UTF8_MEMORY(unicode)) { - PyObject_DEL(_PyUnicode_UTF8(unicode)); + PyObject_Free(_PyUnicode_UTF8(unicode)); _PyUnicode_UTF8(unicode) = NULL; _PyUnicode_UTF8_LENGTH(unicode) = 0; } - data = (PyObject *)PyObject_REALLOC(data, new_size); + data = (PyObject *)PyObject_Realloc(data, new_size); if (data == NULL) { PyErr_NoMemory(); return -1; @@ -1169,7 +1169,7 @@ resize_inplace(PyObject *unicode, Py_ssize_t length) } new_size = sizeof(wchar_t) * (length + 1); wstr = _PyUnicode_WSTR(unicode); - wstr = PyObject_REALLOC(wstr, new_size); + wstr = PyObject_Realloc(wstr, new_size); if (!wstr) { PyErr_NoMemory(); return -1; @@ -1259,7 +1259,7 @@ _PyUnicode_New(Py_ssize_t length) _PyUnicode_UTF8(unicode) = NULL; _PyUnicode_UTF8_LENGTH(unicode) = 0; - _PyUnicode_WSTR(unicode) = (Py_UNICODE*) PyObject_MALLOC(new_size); + _PyUnicode_WSTR(unicode) = (Py_UNICODE*) PyObject_Malloc(new_size); if (!_PyUnicode_WSTR(unicode)) { Py_DECREF(unicode); PyErr_NoMemory(); @@ -1456,7 +1456,7 @@ PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar) * PyObject_New() so we are able to allocate space for the object and * it's data buffer. */ - obj = (PyObject *) PyObject_MALLOC(struct_size + (size + 1) * char_size); + obj = (PyObject *) PyObject_Malloc(struct_size + (size + 1) * char_size); if (obj == NULL) { return PyErr_NoMemory(); } @@ -1838,7 +1838,7 @@ _PyUnicode_Ready(PyObject *unicode) return -1; if (maxchar < 256) { - _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC(_PyUnicode_WSTR_LENGTH(unicode) + 1); + _PyUnicode_DATA_ANY(unicode) = PyObject_Malloc(_PyUnicode_WSTR_LENGTH(unicode) + 1); if (!_PyUnicode_DATA_ANY(unicode)) { PyErr_NoMemory(); return -1; @@ -1859,7 +1859,7 @@ _PyUnicode_Ready(PyObject *unicode) _PyUnicode_UTF8(unicode) = NULL; _PyUnicode_UTF8_LENGTH(unicode) = 0; } - PyObject_FREE(_PyUnicode_WSTR(unicode)); + PyObject_Free(_PyUnicode_WSTR(unicode)); _PyUnicode_WSTR(unicode) = NULL; _PyUnicode_WSTR_LENGTH(unicode) = 0; } @@ -1879,7 +1879,7 @@ _PyUnicode_Ready(PyObject *unicode) _PyUnicode_UTF8_LENGTH(unicode) = 0; #else /* sizeof(wchar_t) == 4 */ - _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC( + _PyUnicode_DATA_ANY(unicode) = PyObject_Malloc( 2 * (_PyUnicode_WSTR_LENGTH(unicode) + 1)); if (!_PyUnicode_DATA_ANY(unicode)) { PyErr_NoMemory(); @@ -1893,7 +1893,7 @@ _PyUnicode_Ready(PyObject *unicode) _PyUnicode_STATE(unicode).kind = PyUnicode_2BYTE_KIND; _PyUnicode_UTF8(unicode) = NULL; _PyUnicode_UTF8_LENGTH(unicode) = 0; - PyObject_FREE(_PyUnicode_WSTR(unicode)); + PyObject_Free(_PyUnicode_WSTR(unicode)); _PyUnicode_WSTR(unicode) = NULL; _PyUnicode_WSTR_LENGTH(unicode) = 0; #endif @@ -1908,7 +1908,7 @@ _PyUnicode_Ready(PyObject *unicode) PyErr_NoMemory(); return -1; } - _PyUnicode_DATA_ANY(unicode) = PyObject_MALLOC(4 * (length_wo_surrogates + 1)); + _PyUnicode_DATA_ANY(unicode) = PyObject_Malloc(4 * (length_wo_surrogates + 1)); if (!_PyUnicode_DATA_ANY(unicode)) { PyErr_NoMemory(); return -1; @@ -1920,7 +1920,7 @@ _PyUnicode_Ready(PyObject *unicode) /* unicode_convert_wchar_to_ucs4() requires a ready string */ _PyUnicode_STATE(unicode).ready = 1; unicode_convert_wchar_to_ucs4(_PyUnicode_WSTR(unicode), end, unicode); - PyObject_FREE(_PyUnicode_WSTR(unicode)); + PyObject_Free(_PyUnicode_WSTR(unicode)); _PyUnicode_WSTR(unicode) = NULL; _PyUnicode_WSTR_LENGTH(unicode) = 0; #else @@ -1973,13 +1973,13 @@ unicode_dealloc(PyObject *unicode) } if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) { - PyObject_DEL(_PyUnicode_WSTR(unicode)); + PyObject_Free(_PyUnicode_WSTR(unicode)); } if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) { - PyObject_DEL(_PyUnicode_UTF8(unicode)); + PyObject_Free(_PyUnicode_UTF8(unicode)); } if (!PyUnicode_IS_COMPACT(unicode) && _PyUnicode_DATA_ANY(unicode)) { - PyObject_DEL(_PyUnicode_DATA_ANY(unicode)); + PyObject_Free(_PyUnicode_DATA_ANY(unicode)); } Py_TYPE(unicode)->tp_free(unicode); @@ -4199,7 +4199,7 @@ PyUnicode_AsUnicodeAndSize(PyObject *unicode, Py_ssize_t *size) PyErr_NoMemory(); return NULL; } - w = (wchar_t *) PyObject_MALLOC(sizeof(wchar_t) * (wlen + 1)); + w = (wchar_t *) PyObject_Malloc(sizeof(wchar_t) * (wlen + 1)); if (w == NULL) { PyErr_NoMemory(); return NULL; @@ -5627,7 +5627,7 @@ unicode_fill_utf8(PyObject *unicode) PyBytes_AS_STRING(writer.buffer); Py_ssize_t len = end - start; - char *cache = PyObject_MALLOC(len + 1); + char *cache = PyObject_Malloc(len + 1); if (cache == NULL) { _PyBytesWriter_Dealloc(&writer); PyErr_NoMemory(); @@ -8544,7 +8544,7 @@ PyUnicode_BuildEncodingMap(PyObject* string) } /* Create a three-level trie */ - result = PyObject_MALLOC(sizeof(struct encoding_map) + + result = PyObject_Malloc(sizeof(struct encoding_map) + 16*count2 + 128*count3 - 1); if (!result) { return PyErr_NoMemory(); @@ -15567,7 +15567,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode) PyErr_NoMemory(); goto onError; } - data = PyObject_MALLOC((length + 1) * char_size); + data = PyObject_Malloc((length + 1) * char_size); if (data == NULL) { PyErr_NoMemory(); goto onError; diff --git a/PC/_msi.c b/PC/_msi.c index 504899d0757..01516e85ccf 100644 --- a/PC/_msi.c +++ b/PC/_msi.c @@ -351,7 +351,7 @@ msiobj_dealloc(msiobj* msidb) { MsiCloseHandle(msidb->h); msidb->h = 0; - PyObject_Del(msidb); + PyObject_Free(msidb); } static PyObject* diff --git a/PC/winreg.c b/PC/winreg.c index fee51ac1bbe..d62a7be28d3 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -145,7 +145,7 @@ PyHKEY_deallocFunc(PyObject *ob) PyHKEYObject *obkey = (PyHKEYObject *)ob; if (obkey->hkey) RegCloseKey((HKEY)obkey->hkey); - PyObject_DEL(ob); + PyObject_Free(ob); } static int @@ -459,7 +459,7 @@ PyObject * PyHKEY_FromHKEY(HKEY h) { /* Inline PyObject_New */ - PyHKEYObject *op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject)); + PyHKEYObject *op = (PyHKEYObject *) PyObject_Malloc(sizeof(PyHKEYObject)); if (op == NULL) { return PyErr_NoMemory(); } diff --git a/Python/symtable.c b/Python/symtable.c index 0464cd898b2..cce1b1b5f32 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -128,7 +128,7 @@ ste_dealloc(PySTEntryObject *ste) Py_XDECREF(ste->ste_varnames); Py_XDECREF(ste->ste_children); Py_XDECREF(ste->ste_directives); - PyObject_Del(ste); + PyObject_Free(ste); } #define OFF(x) offsetof(PySTEntryObject, x)