mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
Years in the making.
objimpl.h, pymem.h: Stop mapping PyMem_{Del, DEL} and PyMem_{Free, FREE}
to PyObject_{Free, FREE} in a release build. They're aliases for the
system free() now.
_subprocess.c/sp_handle_dealloc(): Since the memory was originally
obtained via PyObject_NEW, it must be released via PyObject_FREE (or
_DEL).
pythonrun.c, tokenizer.c, parsermodule.c: I lost count of the number of
PyObject vs PyMem mismatches in these -- it's like the specific
function called at each site was picked at random, sometimes even with
memory obtained via PyMem getting released via PyObject. Changed most
to use PyObject uniformly, since the blobs allocated are predictably
small in most cases, and obmalloc is generally faster than system
mallocs then.
If extension modules in real life prove as sloppy as Python's front
end, we'll have to revert the objimpl.h + pymem.h part of this patch.
Note that no problems will show up in a debug build (all calls still go
thru obmalloc then). Problems will show up only in a release build, most
likely segfaults.
This commit is contained in:
parent
1c168d8eeb
commit
c9d78aa470
7 changed files with 72 additions and 63 deletions
|
|
@ -701,7 +701,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
|
|||
}
|
||||
}
|
||||
len = PyString_GET_SIZE(temp) + 1;
|
||||
strn = (char *)PyMem_MALLOC(len);
|
||||
strn = (char *)PyObject_MALLOC(len);
|
||||
if (strn != NULL)
|
||||
(void) memcpy(strn, PyString_AS_STRING(temp), len);
|
||||
Py_DECREF(temp);
|
||||
|
|
@ -719,11 +719,11 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
|
|||
}
|
||||
err = PyNode_AddChild(root, type, strn, *line_num, 0);
|
||||
if (err == E_NOMEM) {
|
||||
PyMem_DEL(strn);
|
||||
PyObject_FREE(strn);
|
||||
return (node *) PyErr_NoMemory();
|
||||
}
|
||||
if (err == E_OVERFLOW) {
|
||||
PyMem_DEL(strn);
|
||||
PyObject_FREE(strn);
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"unsupported number of child nodes");
|
||||
return NULL;
|
||||
|
|
@ -742,7 +742,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
|
|||
}
|
||||
Py_XDECREF(elem);
|
||||
}
|
||||
return (root);
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -787,7 +787,7 @@ build_node_tree(PyObject *tuple)
|
|||
if (res && encoding) {
|
||||
Py_ssize_t len;
|
||||
len = PyString_GET_SIZE(encoding) + 1;
|
||||
res->n_str = (char *)PyMem_MALLOC(len);
|
||||
res->n_str = (char *)PyObject_MALLOC(len);
|
||||
if (res->n_str != NULL)
|
||||
(void) memcpy(res->n_str, PyString_AS_STRING(encoding), len);
|
||||
Py_DECREF(encoding);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue