Make identifiers str (not str8) objects throughout.
This affects the parser, various object implementations,
and all places that put identifiers into C string literals.
In testing, a number of crashes occurred as code would
fail when the recursion limit was reached (such as the
Unicode interning dictionary having key/value pairs where
key is not value). To solve these, I added an overflowed
flag, which allows for 50 more recursions after the
limit was reached and the exception was raised, and
a recursion_critical flag, which indicates that recursion
absolutely must be allowed, i.e. that a certain call
must not cause a stack overflow exception.
There are still some places where both str and str8 are
accepted as identifiers; these should eventually be
removed.
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index cd766c3..de5270d 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -172,7 +172,7 @@
&PyString_Type, &str, &errors))
return NULL;
- size = PyUnicode_GET_SIZE(str);
+ size = PyString_GET_SIZE(str);
newsize = 4*size;
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
PyErr_SetString(PyExc_OverflowError,
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 21bd383..fc4a1de 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -810,7 +810,7 @@
PyObject *name = PyDict_GetItem(dict, obj);
if (name == NULL) {
if (pack_define_func(self, fileno, fcode->co_firstlineno,
- PyString_AS_STRING(fcode->co_name)) < 0) {
+ PyUnicode_AsString(fcode->co_name)) < 0) {
Py_DECREF(obj);
return -1;
}
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 68990c9..a4dff7b 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -1829,8 +1829,8 @@
(name_size = PyString_Size(global_name)) < 0)
goto finally;
- module_str = PyString_AS_STRING((PyStringObject *)module);
- name_str = PyString_AS_STRING((PyStringObject *)global_name);
+ module_str = PyUnicode_AsString(module);
+ name_str = PyUnicode_AsString(global_name);
/* XXX This can be doing a relative import. Clearly it shouldn't,
but I don't know how to stop it. :-( */
@@ -1842,7 +1842,7 @@
"OS", args, module);
goto finally;
}
- klass = PyObject_GetAttrString(mod, name_str);
+ klass = PyObject_GetAttr(mod, global_name);
if (klass == NULL) {
cPickle_ErrFormat(PicklingError,
"Can't pickle %s: attribute lookup %s.%s "
@@ -2223,7 +2223,7 @@
res = save_string(self, args, 0);
goto finally;
}
- if ((type == &PyUnicode_Type) && (PyString_GET_SIZE(args) < 2)) {
+ if ((type == &PyUnicode_Type) && (PyUnicode_GET_SIZE(args) < 2)) {
res = save_unicode(self, args, 0);
goto finally;
}
@@ -3584,7 +3584,7 @@
Py_DECREF(module_name);
return bad_readline();
}
- if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
+ if ((class_name = PyUnicode_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name,
self->find_class);
Py_DECREF(class_name);
@@ -5379,7 +5379,7 @@
{
PyObject *copy_reg, *t, *r;
-#define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1;
+#define INIT_STR(S) if (!( S ## _str=PyUnicode_InternFromString(#S))) return -1;
if (PyType_Ready(&Unpicklertype) < 0)
return -1;
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 2dd058e..adcdb5f 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -713,7 +713,7 @@
double t1 = 0.0;
if (delstr == NULL) {
- delstr = PyString_InternFromString("__del__");
+ delstr = PyUnicode_InternFromString("__del__");
if (delstr == NULL)
Py_FatalError("gc couldn't allocate \"__del__\"");
}
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index da8af34..f660046 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -515,7 +515,7 @@
/* Hangul Decomposition adds three characters in
a single step, so we need atleast that much room. */
if (space < 3) {
- Py_ssize_t newsize = PyString_GET_SIZE(result) + 10;
+ Py_ssize_t newsize = PyUnicode_GET_SIZE(result) + 10;
space += 10;
if (PyUnicode_Resize(&result, newsize) == -1)
return NULL;