Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-42519: Replace PyObject_MALLOC() with PyObject_Malloc() #23587

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Include/objimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Include/pymem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Modules/_blake2/blake2b_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ py_blake2b_dealloc(PyObject *self)
}

PyTypeObject *type = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(type);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_blake2/blake2s_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ py_blake2s_dealloc(PyObject *self)
}

PyTypeObject *type = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(type);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ static void
PyCArg_dealloc(PyCArgObject *self)
{
Py_XDECREF(self->obj);
PyObject_Del(self);
PyObject_Free(self);
}

static int
Expand Down
2 changes: 1 addition & 1 deletion Modules/_curses_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ PyCursesPanel_Dealloc(PyCursesPanelObject *po)
Py_DECREF(po->wo);
remove_lop(po);
}
PyObject_DEL(po);
PyObject_Free(po);
Py_DECREF(tp);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ ctxmanager_dealloc(PyDecContextManagerObject *self)
{
Py_XDECREF(self->local);
Py_XDECREF(self->global);
PyObject_Del(self);
PyObject_Free(self);
}

static PyObject *
Expand Down
4 changes: 2 additions & 2 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ keyobject_dealloc(keyobject *ko)
{
Py_DECREF(ko->cmp);
Py_XDECREF(ko->object);
PyObject_FREE(ko);
PyObject_Free(ko);
}

static int
Expand Down Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_multiprocessing/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sha3/sha3module.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ SHA3_dealloc(SHA3object *self)
}

PyTypeObject *tp = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(tp);
}

Expand Down
6 changes: 3 additions & 3 deletions Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/_testbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ ndarray_dealloc(NDArrayObject *self)
ndbuf_pop(self);
}
}
PyObject_Del(self);
PyObject_Free(self);
}

static int
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -6664,7 +6664,7 @@ static void
heapctype_dealloc(HeapCTypeObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(tp);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -6968,7 +6968,7 @@ static void
heapctypesetattr_dealloc(HeapCTypeSetattrObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(tp);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -2823,7 +2823,7 @@ Tktt_Dealloc(PyObject *self)

Py_XDECREF(func);

PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(tp);
}

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/cjkcodecs/multibytecodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions Modules/gcmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Modules/md5module.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static void
MD5_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_Del(ptr);
PyObject_Free(ptr);
Py_DECREF(tp);
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/ossaudiodev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion Modules/overlapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ Overlapped_dealloc(OverlappedObject *self)
SetLastError(olderr);

PyTypeObject *tp = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(tp);
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/sha1module.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ static void
SHA1_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_Del(ptr);
PyObject_Free(ptr);
Py_DECREF(tp);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/sha256module.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static void
SHA_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_Del(ptr);
PyObject_Free(ptr);
Py_DECREF(tp);
}

Expand Down
Loading