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.)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 7a68dd4..601b987 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -200,14 +200,13 @@
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 @@
onError:
_Py_ForgetReference((PyObject *)unicode);
- PyMem_DEL(unicode);
+ PyObject_DEL(unicode);
return NULL;
}
@@ -243,7 +242,7 @@
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 @@
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 @@
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);
}