Fixed bugs in resizetuple and extended the interface.
Added ifdefs in stringobject.c for shared strings of length 1.
Renamed free_list in tupleobject.c to free_tuples.
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 61863b6..0d03a3b 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -39,7 +39,9 @@
#endif
static stringobject *characters[UCHAR_MAX + 1];
+#ifndef DONT_SHARE_SHORT_STRINGS
static stringobject *nullstring;
+#endif
/*
Newsizedstringobject() and newstringobject() try in certain cases
@@ -62,6 +64,7 @@
int size;
{
register stringobject *op;
+#ifndef DONT_SHARE_SHORT_STRINGS
if (size == 0 && (op = nullstring) != NULL) {
#ifdef COUNT_ALLOCS
null_strings++;
@@ -76,6 +79,7 @@
INCREF(op);
return (object *)op;
}
+#endif /* DONT_SHARE_SHORT_STRINGS */
op = (stringobject *)
malloc(sizeof(stringobject) + size * sizeof(char));
if (op == NULL)
@@ -89,6 +93,7 @@
if (str != NULL)
memcpy(op->ob_sval, str, size);
op->ob_sval[size] = '\0';
+#ifndef DONT_SHARE_SHORT_STRINGS
if (size == 0) {
nullstring = op;
INCREF(op);
@@ -96,6 +101,7 @@
characters[*str & UCHAR_MAX] = op;
INCREF(op);
}
+#endif
return (object *) op;
}
@@ -105,6 +111,7 @@
{
register unsigned int size = strlen(str);
register stringobject *op;
+#ifndef DONT_SHARE_SHORT_STRINGS
if (size == 0 && (op = nullstring) != NULL) {
#ifdef COUNT_ALLOCS
null_strings++;
@@ -119,6 +126,7 @@
INCREF(op);
return (object *)op;
}
+#endif /* DONT_SHARE_SHORT_STRINGS */
op = (stringobject *)
malloc(sizeof(stringobject) + size * sizeof(char));
if (op == NULL)
@@ -130,6 +138,7 @@
#endif
NEWREF(op);
strcpy(op->ob_sval, str);
+#ifndef DONT_SHARE_SHORT_STRINGS
if (size == 0) {
nullstring = op;
INCREF(op);
@@ -137,6 +146,7 @@
characters[*str & UCHAR_MAX] = op;
INCREF(op);
}
+#endif
return (object *) op;
}