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/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;