mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-114569: Use PyMem_* APIs for most non-PyObject uses (#114574)
Fix usage in Modules, Objects, and Parser subdirectories.
This commit is contained in:
parent
d0f7f5c41d
commit
dcd28b5c35
7 changed files with 36 additions and 33 deletions
|
@ -3493,7 +3493,7 @@ type_new_set_doc(PyTypeObject *type)
|
|||
|
||||
// Silently truncate the docstring if it contains a null byte
|
||||
Py_ssize_t size = strlen(doc_str) + 1;
|
||||
char *tp_doc = (char *)PyObject_Malloc(size);
|
||||
char *tp_doc = (char *)PyMem_Malloc(size);
|
||||
if (tp_doc == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return -1;
|
||||
|
@ -4166,12 +4166,12 @@ _PyType_FromMetaclass_impl(
|
|||
goto finally;
|
||||
}
|
||||
if (slot->pfunc == NULL) {
|
||||
PyObject_Free(tp_doc);
|
||||
PyMem_Free(tp_doc);
|
||||
tp_doc = NULL;
|
||||
}
|
||||
else {
|
||||
size_t len = strlen(slot->pfunc)+1;
|
||||
tp_doc = PyObject_Malloc(len);
|
||||
tp_doc = PyMem_Malloc(len);
|
||||
if (tp_doc == NULL) {
|
||||
PyErr_NoMemory();
|
||||
goto finally;
|
||||
|
@ -4501,7 +4501,7 @@ _PyType_FromMetaclass_impl(
|
|||
Py_CLEAR(res);
|
||||
}
|
||||
Py_XDECREF(bases);
|
||||
PyObject_Free(tp_doc);
|
||||
PyMem_Free(tp_doc);
|
||||
Py_XDECREF(ht_name);
|
||||
PyMem_Free(_ht_tpname);
|
||||
return (PyObject*)res;
|
||||
|
@ -5099,7 +5099,7 @@ type_dealloc(PyObject *self)
|
|||
/* A type's tp_doc is heap allocated, unlike the tp_doc slots
|
||||
* of most other objects. It's okay to cast it to char *.
|
||||
*/
|
||||
PyObject_Free((char *)type->tp_doc);
|
||||
PyMem_Free((char *)type->tp_doc);
|
||||
|
||||
PyHeapTypeObject *et = (PyHeapTypeObject *)type;
|
||||
Py_XDECREF(et->ht_name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue