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()
This commit is contained in:
Victor Stinner 2020-12-01 10:37:39 +01:00 committed by GitHub
parent 00d7abd7ef
commit 32bd68c839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 102 additions and 98 deletions

View File

@ -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

View File

@ -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

View File

@ -393,7 +393,7 @@ py_blake2b_dealloc(PyObject *self)
}
PyTypeObject *type = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(type);
}

View File

@ -392,7 +392,7 @@ py_blake2s_dealloc(PyObject *self)
}
PyTypeObject *type = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(type);
}

View File

@ -475,7 +475,7 @@ static void
PyCArg_dealloc(PyCArgObject *self)
{
Py_XDECREF(self->obj);
PyObject_Del(self);
PyObject_Free(self);
}
static int

View File

@ -282,7 +282,7 @@ PyCursesPanel_Dealloc(PyCursesPanelObject *po)
Py_DECREF(po->wo);
remove_lop(po);
}
PyObject_DEL(po);
PyObject_Free(po);
Py_DECREF(tp);
}

View File

@ -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 */

View File

@ -1765,7 +1765,7 @@ ctxmanager_dealloc(PyDecContextManagerObject *self)
{
Py_XDECREF(self->local);
Py_XDECREF(self->global);
PyObject_Del(self);
PyObject_Free(self);
}
static PyObject *

View File

@ -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 = {

View File

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

View File

@ -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]

View File

@ -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 = {

View File

@ -274,7 +274,7 @@ SHA3_dealloc(SHA3object *self)
}
PyTypeObject *tp = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(tp);
}

View File

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

View File

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

View File

@ -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,

View File

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

View File

@ -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

View File

@ -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();
}

View File

@ -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 = {

View File

@ -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

View File

@ -342,7 +342,7 @@ static void
MD5_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_Del(ptr);
PyObject_Free(ptr);
Py_DECREF(tp);
}

View File

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

View File

@ -722,7 +722,7 @@ Overlapped_dealloc(OverlappedObject *self)
SetLastError(olderr);
PyTypeObject *tp = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(tp);
}

View File

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

View File

@ -320,7 +320,7 @@ static void
SHA1_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_Del(ptr);
PyObject_Free(ptr);
Py_DECREF(tp);
}

View File

@ -397,7 +397,7 @@ static void
SHA_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_Del(ptr);
PyObject_Free(ptr);
Py_DECREF(tp);
}

View File

@ -453,7 +453,7 @@ static void
SHA512_dealloc(PyObject *ptr)
{
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_Del(ptr);
PyObject_Free(ptr);
Py_DECREF(tp);
}

View File

@ -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);

View File

@ -1418,7 +1418,7 @@ static void
ucd_dealloc(PreviousDBVersion *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_Del(self);
PyObject_Free(self);
Py_DECREF(tp);
}

View File

@ -44,7 +44,7 @@ static void
Xxo_dealloc(XxoObject *self)
{
Py_XDECREF(self->x_attr);
PyObject_Del(self);
PyObject_Free(self);
}
static PyObject *

View File

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

View File

@ -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;
}

View File

@ -260,7 +260,7 @@ capsule_dealloc(PyObject *o)
if (capsule->destructor) {
capsule->destructor(o);
}
PyObject_DEL(o);
PyObject_Free(o);
}

View File

@ -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 *

View File

@ -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();
}

View File

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

View File

@ -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;

View File

@ -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();

View File

@ -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();
}

View File

@ -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)
*/

View File

@ -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 *

View File

@ -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:

View File

@ -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();

View File

@ -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;

View File

@ -351,7 +351,7 @@ msiobj_dealloc(msiobj* msidb)
{
MsiCloseHandle(msidb->h);
msidb->h = 0;
PyObject_Del(msidb);
PyObject_Free(msidb);
}
static PyObject*

View File

@ -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();
}

View File

@ -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)