diff options
author | Victor Stinner <vstinner@python.org> | 2020-12-01 08:56:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-01 08:56:42 (GMT) |
commit | 00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0 (patch) | |
tree | 26ebb0fe409768193bb85be90c0229a0f44d6f8e /Objects | |
parent | b2d0c66e881301ed8908da3cb41bbf253c449b0c (diff) | |
download | cpython-00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0.zip cpython-00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0.tar.gz cpython-00d7abd7ef588fc4ff0571c8579ab4aba8ada1c0.tar.bz2 |
bpo-42519: Replace PyMem_MALLOC() with PyMem_Malloc() (GH-23586)
No longer use deprecated aliases to functions:
* Replace PyMem_MALLOC() with PyMem_Malloc()
* Replace PyMem_REALLOC() with PyMem_Realloc()
* Replace PyMem_FREE() with PyMem_Free()
* Replace PyMem_Del() with PyMem_Free()
* Replace PyMem_DEL() with PyMem_Free()
Modify also the PyMem_DEL() macro to use directly PyMem_Free().
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/capsule.c | 4 | ||||
-rw-r--r-- | Objects/codeobject.c | 16 | ||||
-rw-r--r-- | Objects/dictobject.c | 2 | ||||
-rw-r--r-- | Objects/listobject.c | 24 | ||||
-rw-r--r-- | Objects/moduleobject.c | 6 | ||||
-rw-r--r-- | Objects/odictobject.c | 10 | ||||
-rw-r--r-- | Objects/setobject.c | 6 | ||||
-rw-r--r-- | Objects/stringlib/join.h | 2 | ||||
-rw-r--r-- | Objects/structseq.c | 6 | ||||
-rw-r--r-- | Objects/typeobject.c | 6 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 24 |
11 files changed, 53 insertions, 53 deletions
diff --git a/Objects/capsule.c b/Objects/capsule.c index ed24cc1..a2ff642 100644 --- a/Objects/capsule.c +++ b/Objects/capsule.c @@ -198,7 +198,7 @@ PyCapsule_Import(const char *name, int no_block) void *return_value = NULL; char *trace; size_t name_length = (strlen(name) + 1) * sizeof(char); - char *name_dup = (char *)PyMem_MALLOC(name_length); + char *name_dup = (char *)PyMem_Malloc(name_length); if (!name_dup) { return PyErr_NoMemory(); @@ -247,7 +247,7 @@ PyCapsule_Import(const char *name, int no_block) EXIT: Py_XDECREF(object); if (name_dup) { - PyMem_FREE(name_dup); + PyMem_Free(name_dup); } return return_value; } diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 7b224cc..0257295 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -213,7 +213,7 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, PyObject *arg = PyTuple_GET_ITEM(varnames, j); int cmp = PyUnicode_Compare(cell, arg); if (cmp == -1 && PyErr_Occurred()) { - PyMem_FREE(cell2arg); + PyMem_Free(cell2arg); return NULL; } if (cmp == 0) { @@ -224,14 +224,14 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, } } if (!used_cell2arg) { - PyMem_FREE(cell2arg); + PyMem_Free(cell2arg); cell2arg = NULL; } } co = PyObject_New(PyCodeObject, &PyCode_Type); if (co == NULL) { if (cell2arg) - PyMem_FREE(cell2arg); + PyMem_Free(cell2arg); return NULL; } co->co_argcount = argcount; @@ -314,12 +314,12 @@ _PyCode_InitOpcache(PyCodeObject *co) if (opts) { co->co_opcache = (_PyOpcache *)PyMem_Calloc(opts, sizeof(_PyOpcache)); if (co->co_opcache == NULL) { - PyMem_FREE(co->co_opcache_map); + PyMem_Free(co->co_opcache_map); return -1; } } else { - PyMem_FREE(co->co_opcache_map); + PyMem_Free(co->co_opcache_map); co->co_opcache_map = NULL; co->co_opcache = NULL; } @@ -631,10 +631,10 @@ static void code_dealloc(PyCodeObject *co) { if (co->co_opcache != NULL) { - PyMem_FREE(co->co_opcache); + PyMem_Free(co->co_opcache); } if (co->co_opcache_map != NULL) { - PyMem_FREE(co->co_opcache_map); + PyMem_Free(co->co_opcache_map); } co->co_opcache_flag = 0; co->co_opcache_size = 0; @@ -664,7 +664,7 @@ code_dealloc(PyCodeObject *co) Py_XDECREF(co->co_name); Py_XDECREF(co->co_linetable); if (co->co_cell2arg != NULL) - PyMem_FREE(co->co_cell2arg); + PyMem_Free(co->co_cell2arg); if (co->co_zombieframe != NULL) PyObject_GC_Del(co->co_zombieframe); if (co->co_weakreflist != NULL) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index faa8696..ee1a9d1 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -640,7 +640,7 @@ free_keys_object(PyDictKeysObject *keys) } #define new_values(size) PyMem_NEW(PyObject *, size) -#define free_values(values) PyMem_FREE(values) +#define free_values(values) PyMem_Free(values) /* Consumes a reference to the keys object */ static PyObject * diff --git a/Objects/listobject.c b/Objects/listobject.c index aac87ea..ca9df59 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -341,7 +341,7 @@ list_dealloc(PyListObject *op) while (--i >= 0) { Py_XDECREF(op->ob_item[i]); } - PyMem_FREE(op->ob_item); + PyMem_Free(op->ob_item); } struct _Py_list_state *state = get_list_state(); #ifdef Py_DEBUG @@ -592,7 +592,7 @@ _list_clear(PyListObject *a) while (--i >= 0) { Py_XDECREF(item[i]); } - PyMem_FREE(item); + PyMem_Free(item); } /* Never fails; the return value can be ignored. Note that there is no guarantee that the list is actually empty @@ -668,7 +668,7 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) /* If norig == 0, item might be NULL, in which case we may not memcpy from it. */ if (s) { if (s > sizeof(recycle_on_stack)) { - recycle = (PyObject **)PyMem_MALLOC(s); + recycle = (PyObject **)PyMem_Malloc(s); if (recycle == NULL) { PyErr_NoMemory(); goto Error; @@ -706,7 +706,7 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) result = 0; Error: if (recycle != recycle_on_stack) - PyMem_FREE(recycle); + PyMem_Free(recycle); Py_XDECREF(v_as_SF); return result; #undef b @@ -2230,7 +2230,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) /* Leverage stack space we allocated but won't otherwise use */ keys = &ms.temparray[saved_ob_size+1]; else { - keys = PyMem_MALLOC(sizeof(PyObject *) * saved_ob_size); + keys = PyMem_Malloc(sizeof(PyObject *) * saved_ob_size); if (keys == NULL) { PyErr_NoMemory(); goto keyfunc_fail; @@ -2243,7 +2243,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) for (i=i-1 ; i>=0 ; i--) Py_DECREF(keys[i]); if (saved_ob_size >= MERGESTATE_TEMP_SIZE/2) - PyMem_FREE(keys); + PyMem_Free(keys); goto keyfunc_fail; } } @@ -2414,7 +2414,7 @@ fail: for (i = 0; i < saved_ob_size; i++) Py_DECREF(keys[i]); if (saved_ob_size >= MERGESTATE_TEMP_SIZE/2) - PyMem_FREE(keys); + PyMem_Free(keys); } if (self->allocated != -1 && result != NULL) { @@ -2442,7 +2442,7 @@ keyfunc_fail: while (--i >= 0) { Py_XDECREF(final_ob_item[i]); } - PyMem_FREE(final_ob_item); + PyMem_Free(final_ob_item); } Py_XINCREF(result); return result; @@ -2908,7 +2908,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) } garbage = (PyObject**) - PyMem_MALLOC(slicelength*sizeof(PyObject*)); + PyMem_Malloc(slicelength*sizeof(PyObject*)); if (!garbage) { PyErr_NoMemory(); return -1; @@ -2949,7 +2949,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) for (i = 0; i < slicelength; i++) { Py_DECREF(garbage[i]); } - PyMem_FREE(garbage); + PyMem_Free(garbage); return res; } @@ -2990,7 +2990,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) } garbage = (PyObject**) - PyMem_MALLOC(slicelength*sizeof(PyObject*)); + PyMem_Malloc(slicelength*sizeof(PyObject*)); if (!garbage) { Py_DECREF(seq); PyErr_NoMemory(); @@ -3011,7 +3011,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) Py_DECREF(garbage[i]); } - PyMem_FREE(garbage); + PyMem_Free(garbage); Py_DECREF(seq); return 0; diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index c3ceb78..6590387 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -211,7 +211,7 @@ _PyModule_CreateInitialized(struct PyModuleDef* module, int module_api_version) return NULL; if (module->m_size > 0) { - m->md_state = PyMem_MALLOC(module->m_size); + m->md_state = PyMem_Malloc(module->m_size); if (!m->md_state) { PyErr_NoMemory(); Py_DECREF(m); @@ -377,7 +377,7 @@ PyModule_ExecDef(PyObject *module, PyModuleDef *def) if (md->md_state == NULL) { /* Always set a state pointer; this serves as a marker to skip * multiple initialization (importlib.reload() is no-op) */ - md->md_state = PyMem_MALLOC(def->m_size); + md->md_state = PyMem_Malloc(def->m_size); if (!md->md_state) { PyErr_NoMemory(); return -1; @@ -681,7 +681,7 @@ module_dealloc(PyModuleObject *m) Py_XDECREF(m->md_dict); Py_XDECREF(m->md_name); if (m->md_state != NULL) - PyMem_FREE(m->md_state); + PyMem_Free(m->md_state); Py_TYPE(m)->tp_free((PyObject *)m); } diff --git a/Objects/odictobject.c b/Objects/odictobject.c index b4ac560..83b326b 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -567,14 +567,14 @@ _odict_resize(PyODictObject *od) i = _odict_get_index_raw(od, _odictnode_KEY(node), _odictnode_HASH(node)); if (i < 0) { - PyMem_FREE(fast_nodes); + PyMem_Free(fast_nodes); return -1; } fast_nodes[i] = node; } /* Replace the old fast nodes table. */ - PyMem_FREE(od->od_fast_nodes); + PyMem_Free(od->od_fast_nodes); od->od_fast_nodes = fast_nodes; od->od_fast_nodes_size = size; od->od_resize_sentinel = ((PyDictObject *)od)->ma_keys; @@ -683,7 +683,7 @@ _odict_add_new_node(PyODictObject *od, PyObject *key, Py_hash_t hash) } /* must not be added yet */ - node = (_ODictNode *)PyMem_MALLOC(sizeof(_ODictNode)); + node = (_ODictNode *)PyMem_Malloc(sizeof(_ODictNode)); if (node == NULL) { Py_DECREF(key); PyErr_NoMemory(); @@ -701,7 +701,7 @@ _odict_add_new_node(PyODictObject *od, PyObject *key, Py_hash_t hash) #define _odictnode_DEALLOC(node) \ do { \ Py_DECREF(_odictnode_KEY(node)); \ - PyMem_FREE((void *)node); \ + PyMem_Free((void *)node); \ } while (0) /* Repeated calls on the same node are no-ops. */ @@ -776,7 +776,7 @@ _odict_clear_nodes(PyODictObject *od) { _ODictNode *node, *next; - PyMem_FREE(od->od_fast_nodes); + PyMem_Free(od->od_fast_nodes); od->od_fast_nodes = NULL; od->od_fast_nodes_size = 0; od->od_resize_sentinel = NULL; diff --git a/Objects/setobject.c b/Objects/setobject.c index af8ee03..79e8451 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -289,7 +289,7 @@ set_table_resize(PySetObject *so, Py_ssize_t minused) } if (is_oldtable_malloced) - PyMem_DEL(oldtable); + PyMem_Free(oldtable); return 0; } @@ -424,7 +424,7 @@ set_clear_internal(PySetObject *so) } if (table_is_malloced) - PyMem_DEL(table); + PyMem_Free(table); return 0; } @@ -484,7 +484,7 @@ set_dealloc(PySetObject *so) } } if (so->table != so->smalltable) - PyMem_DEL(so->table); + PyMem_Free(so->table); Py_TYPE(so)->tp_free(so); Py_TRASHCAN_END } diff --git a/Objects/stringlib/join.h b/Objects/stringlib/join.h index 53bcbde..62e4c98 100644 --- a/Objects/stringlib/join.h +++ b/Objects/stringlib/join.h @@ -155,7 +155,7 @@ done: for (i = 0; i < nbufs; i++) PyBuffer_Release(&buffers[i]); if (buffers != static_buffers) - PyMem_FREE(buffers); + PyMem_Free(buffers); return res; } diff --git a/Objects/structseq.c b/Objects/structseq.c index bb28e11..5d71fcf 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -467,14 +467,14 @@ PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc) type->tp_members = members; if (PyType_Ready(type) < 0) { - PyMem_FREE(members); + PyMem_Free(members); return -1; } Py_INCREF(type); if (initialize_structseq_dict( desc, type->tp_dict, n_members, n_unnamed_members) < 0) { - PyMem_FREE(members); + PyMem_Free(members); Py_DECREF(type); return -1; } @@ -526,7 +526,7 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc) spec.slots = slots; type = (PyTypeObject *)PyType_FromSpecWithBases(&spec, (PyObject *)&PyTuple_Type); - PyMem_FREE(members); + PyMem_Free(members); if (type == NULL) { return NULL; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 3a6143a..fbadd31 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1779,7 +1779,7 @@ pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size) } out: - PyMem_Del(remain); + PyMem_Free(remain); return res; } @@ -1859,7 +1859,7 @@ mro_implementation(PyTypeObject *type) result = PyList_New(1); if (result == NULL) { - PyMem_Del(to_merge); + PyMem_Free(to_merge); return NULL; } @@ -1869,7 +1869,7 @@ mro_implementation(PyTypeObject *type) Py_CLEAR(result); } - PyMem_Del(to_merge); + PyMem_Free(to_merge); return result; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 70688c8..ba6d07a 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3298,7 +3298,7 @@ PyUnicode_AsWideCharString(PyObject *unicode, *size = buflen; } else if (wcslen(buffer) != (size_t)buflen) { - PyMem_FREE(buffer); + PyMem_Free(buffer); PyErr_SetString(PyExc_ValueError, "embedded null character"); return NULL; @@ -10211,7 +10211,7 @@ case_operation(PyObject *self, PyErr_SetString(PyExc_OverflowError, "string is too long"); return NULL; } - tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * length); + tmp = PyMem_Malloc(sizeof(Py_UCS4) * 3 * length); if (tmp == NULL) return PyErr_NoMemory(); newlength = perform(kind, data, length, tmp, &maxchar); @@ -10235,7 +10235,7 @@ case_operation(PyObject *self, Py_UNREACHABLE(); } leave: - PyMem_FREE(tmp); + PyMem_Free(tmp); return res; } @@ -11050,11 +11050,11 @@ replace(PyObject *self, PyObject *str1, assert(release1 == (buf1 != PyUnicode_DATA(str1))); assert(release2 == (buf2 != PyUnicode_DATA(str2))); if (srelease) - PyMem_FREE((void *)sbuf); + PyMem_Free((void *)sbuf); if (release1) - PyMem_FREE((void *)buf1); + PyMem_Free((void *)buf1); if (release2) - PyMem_FREE((void *)buf2); + PyMem_Free((void *)buf2); assert(_PyUnicode_CheckConsistency(u, 1)); return u; @@ -11064,11 +11064,11 @@ replace(PyObject *self, PyObject *str1, assert(release1 == (buf1 != PyUnicode_DATA(str1))); assert(release2 == (buf2 != PyUnicode_DATA(str2))); if (srelease) - PyMem_FREE((void *)sbuf); + PyMem_Free((void *)sbuf); if (release1) - PyMem_FREE((void *)buf1); + PyMem_Free((void *)buf1); if (release2) - PyMem_FREE((void *)buf2); + PyMem_Free((void *)buf2); return unicode_result_unchanged(self); error: @@ -11076,11 +11076,11 @@ replace(PyObject *self, PyObject *str1, assert(release1 == (buf1 != PyUnicode_DATA(str1))); assert(release2 == (buf2 != PyUnicode_DATA(str2))); if (srelease) - PyMem_FREE((void *)sbuf); + PyMem_Free((void *)sbuf); if (release1) - PyMem_FREE((void *)buf1); + PyMem_Free((void *)buf1); if (release2) - PyMem_FREE((void *)buf2); + PyMem_Free((void *)buf2); return NULL; } |