mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
This commit is contained in:
parent
2808b744e8
commit
b18618dab7
73 changed files with 658 additions and 407 deletions
|
@ -200,14 +200,13 @@ PyUnicodeObject *_PyUnicode_New(int length)
|
|||
unicode = unicode_freelist;
|
||||
unicode_freelist = *(PyUnicodeObject **)unicode_freelist;
|
||||
unicode_freelist_size--;
|
||||
unicode->ob_type = &PyUnicode_Type;
|
||||
_Py_NewReference((PyObject *)unicode);
|
||||
PyObject_INIT(unicode, &PyUnicode_Type);
|
||||
if (unicode->str) {
|
||||
/* Keep-Alive optimization: we only upsize the buffer,
|
||||
never downsize it. */
|
||||
if ((unicode->length < length) &&
|
||||
_PyUnicode_Resize(unicode, length)) {
|
||||
free(unicode->str);
|
||||
PyMem_DEL(unicode->str);
|
||||
goto onError;
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +232,7 @@ PyUnicodeObject *_PyUnicode_New(int length)
|
|||
|
||||
onError:
|
||||
_Py_ForgetReference((PyObject *)unicode);
|
||||
PyMem_DEL(unicode);
|
||||
PyObject_DEL(unicode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -243,7 +242,7 @@ void _PyUnicode_Free(register PyUnicodeObject *unicode)
|
|||
if (unicode_freelist_size < MAX_UNICODE_FREELIST_SIZE) {
|
||||
/* Keep-Alive optimization */
|
||||
if (unicode->length >= KEEPALIVE_SIZE_LIMIT) {
|
||||
free(unicode->str);
|
||||
PyMem_DEL(unicode->str);
|
||||
unicode->str = NULL;
|
||||
unicode->length = 0;
|
||||
}
|
||||
|
@ -257,9 +256,9 @@ void _PyUnicode_Free(register PyUnicodeObject *unicode)
|
|||
unicode_freelist_size++;
|
||||
}
|
||||
else {
|
||||
free(unicode->str);
|
||||
PyMem_DEL(unicode->str);
|
||||
Py_XDECREF(unicode->utf8str);
|
||||
PyMem_DEL(unicode);
|
||||
PyObject_DEL(unicode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4662,9 +4661,9 @@ _PyUnicode_Fini()
|
|||
PyUnicodeObject *v = u;
|
||||
u = *(PyUnicodeObject **)u;
|
||||
if (v->str)
|
||||
free(v->str);
|
||||
PyMem_DEL(v->str);
|
||||
Py_XDECREF(v->utf8str);
|
||||
free(v);
|
||||
PyObject_DEL(v);
|
||||
}
|
||||
Py_XDECREF(unicode_empty);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue