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.
This commit is contained in:
Martin v. Löwis 2007-06-10 09:51:05 +00:00
parent 38e43c25ee
commit 5b222135f8
40 changed files with 462 additions and 289 deletions

View File

@ -50,7 +50,10 @@ PyAPI_FUNC(int) Py_GetRecursionLimit(void);
(_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \ (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
_Py_CheckRecursiveCall(where)) _Py_CheckRecursiveCall(where))
#define Py_LeaveRecursiveCall() \ #define Py_LeaveRecursiveCall() \
(--PyThreadState_GET()->recursion_depth) do{ if((--PyThreadState_GET()->recursion_depth) < \
_Py_CheckRecursionLimit - 50); \
PyThreadState_GET()->overflowed = 0; \
} while(0)
PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where); PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);
PyAPI_DATA(int) _Py_CheckRecursionLimit; PyAPI_DATA(int) _Py_CheckRecursionLimit;
#ifdef USE_STACKCHECK #ifdef USE_STACKCHECK
@ -59,6 +62,14 @@ PyAPI_DATA(int) _Py_CheckRecursionLimit;
# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit) # define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
#endif #endif
#define Py_ALLOW_RECURSION \
do { unsigned char _old = PyThreadState_GET()->recursion_critical;\
PyThreadState_GET()->recursion_critical = 1;
#define Py_END_ALLOW_RECURSION \
PyThreadState_GET()->recursion_critical = _old; \
} while(0);
PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *); PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *); PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);

View File

@ -61,6 +61,10 @@ typedef struct _ts {
struct _frame *frame; struct _frame *frame;
int recursion_depth; int recursion_depth;
char overflowed; /* The stack has overflowed. Allow 50 more calls
to handle the runtime error. */
char recursion_critical; /* The current calls must not cause
a stack overflow. */
/* 'tracing' keeps track of the execution depth when tracing/profiling. /* 'tracing' keeps track of the execution depth when tracing/profiling.
This is to prevent the actual trace/profile code from being recorded in This is to prevent the actual trace/profile code from being recorded in
the trace/profile. */ the trace/profile. */

View File

@ -84,8 +84,8 @@ PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
#define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate) #define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
/* Macro, trading safety for speed */ /* Macro, trading safety for speed */
#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval) #define PyString_AS_STRING(op) (assert(PyString_Check(op)),(((PyStringObject *)(op))->ob_sval))
#define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size) #define PyString_GET_SIZE(op) (assert(PyString_Check(op)),(((PyStringObject *)(op))->ob_size))
/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*, /* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
x must be an iterable object. */ x must be an iterable object. */

View File

@ -410,13 +410,13 @@ PyAPI_DATA(PyTypeObject) PyUnicode_Type;
/* Fast access macros */ /* Fast access macros */
#define PyUnicode_GET_SIZE(op) \ #define PyUnicode_GET_SIZE(op) \
(((PyUnicodeObject *)(op))->length) (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->length))
#define PyUnicode_GET_DATA_SIZE(op) \ #define PyUnicode_GET_DATA_SIZE(op) \
(((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE)) (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE)))
#define PyUnicode_AS_UNICODE(op) \ #define PyUnicode_AS_UNICODE(op) \
(((PyUnicodeObject *)(op))->str) (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->str))
#define PyUnicode_AS_DATA(op) \ #define PyUnicode_AS_DATA(op) \
((const char *)((PyUnicodeObject *)(op))->str) (assert(PyUnicode_Check(op)),((const char *)((PyUnicodeObject *)(op))->str))
/* --- Constants ---------------------------------------------------------- */ /* --- Constants ---------------------------------------------------------- */
@ -627,6 +627,13 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromOrdinal(int ordinal);
PyAPI_FUNC(PyObject *) _PyUnicode_AsDefaultEncodedString( PyAPI_FUNC(PyObject *) _PyUnicode_AsDefaultEncodedString(
PyObject *, const char *); PyObject *, const char *);
/* Return a char* holding the default encoded value of the
Unicode object.
*/
PyAPI_FUNC(char *) PyUnicode_AsString(PyObject*);
/* Returns the currently active default encoding. /* Returns the currently active default encoding.
The default encoding is currently implemented as run-time settable The default encoding is currently implemented as run-time settable
@ -1193,6 +1200,11 @@ PyAPI_FUNC(int) PyUnicode_Compare(
PyObject *right /* Right string */ PyObject *right /* Right string */
); );
PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString(
PyObject *left,
const char *right
);
/* Rich compare two strings and return one of the following: /* Rich compare two strings and return one of the following:
- NULL in case an exception was raised - NULL in case an exception was raised
@ -1310,6 +1322,22 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha(
Py_UNICODE ch /* Unicode character */ Py_UNICODE ch /* Unicode character */
); );
PyAPI_FUNC(size_t) Py_UNICODE_strlen(const Py_UNICODE *u);
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy(
Py_UNICODE *s1, const Py_UNICODE *s2);
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy(
Py_UNICODE *s1, const Py_UNICODE *s2, size_t n);
PyAPI_FUNC(int) Py_UNICODE_strcmp(
const Py_UNICODE *s1, const Py_UNICODE *s2);
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr(
const Py_UNICODE *s, Py_UNICODE c
);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -10,6 +10,8 @@
from test.test_support import TestFailed from test.test_support import TestFailed
import sys, os import sys, os
raise TestFailed, "test currently causes assertion in debug mode"
try: try:
import __hello__ import __hello__
except ImportError as x: except ImportError as x:

View File

@ -143,7 +143,7 @@ class NewTest(unittest.TestCase):
firstlineno, lnotab) firstlineno, lnotab)
# new.code used to be a way to mutate a tuple... # new.code used to be a way to mutate a tuple...
class S(str8): class S(str):
pass pass
t = (S("ab"),) t = (S("ab"),)
d = new.code(argcount, kwonlyargcount, nlocals, stacksize, d = new.code(argcount, kwonlyargcount, nlocals, stacksize,

View File

@ -321,12 +321,6 @@ class SysModuleTest(unittest.TestCase):
self.assertRaises(TypeError, sys.intern, S("abc")) self.assertRaises(TypeError, sys.intern, S("abc"))
# It's still safe to pass these strings to routines that
# call intern internally, e.g. PyObject_SetAttr().
s = S("abc")
setattr(s, s, s)
self.assertEqual(getattr(s, s), s)
s = "never interned as unicode before" s = "never interned as unicode before"
self.assert_(sys.intern(s) is s) self.assert_(sys.intern(s) is s)
s2 = s.swapcase().swapcase() s2 = s.swapcase().swapcase()
@ -338,6 +332,12 @@ class SysModuleTest(unittest.TestCase):
self.assertRaises(TypeError, sys.intern, U("abc")) self.assertRaises(TypeError, sys.intern, U("abc"))
# It's still safe to pass these strings to routines that
# call intern internally, e.g. PyObject_SetAttr().
s = U("abc")
setattr(s, s, s)
self.assertEqual(getattr(s, s), s)
def test_main(): def test_main():
test.test_support.run_unittest(SysModuleTest) test.test_support.run_unittest(SysModuleTest)

View File

@ -172,7 +172,7 @@ escape_encode(PyObject *self,
&PyString_Type, &str, &errors)) &PyString_Type, &str, &errors))
return NULL; return NULL;
size = PyUnicode_GET_SIZE(str); size = PyString_GET_SIZE(str);
newsize = 4*size; newsize = 4*size;
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) { if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,

View File

@ -810,7 +810,7 @@ get_fileno(ProfilerObject *self, PyCodeObject *fcode)
PyObject *name = PyDict_GetItem(dict, obj); PyObject *name = PyDict_GetItem(dict, obj);
if (name == NULL) { if (name == NULL) {
if (pack_define_func(self, fileno, fcode->co_firstlineno, 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); Py_DECREF(obj);
return -1; return -1;
} }

View File

@ -1829,8 +1829,8 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
(name_size = PyString_Size(global_name)) < 0) (name_size = PyString_Size(global_name)) < 0)
goto finally; goto finally;
module_str = PyString_AS_STRING((PyStringObject *)module); module_str = PyUnicode_AsString(module);
name_str = PyString_AS_STRING((PyStringObject *)global_name); name_str = PyUnicode_AsString(global_name);
/* XXX This can be doing a relative import. Clearly it shouldn't, /* XXX This can be doing a relative import. Clearly it shouldn't,
but I don't know how to stop it. :-( */ but I don't know how to stop it. :-( */
@ -1842,7 +1842,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
"OS", args, module); "OS", args, module);
goto finally; goto finally;
} }
klass = PyObject_GetAttrString(mod, name_str); klass = PyObject_GetAttr(mod, global_name);
if (klass == NULL) { if (klass == NULL) {
cPickle_ErrFormat(PicklingError, cPickle_ErrFormat(PicklingError,
"Can't pickle %s: attribute lookup %s.%s " "Can't pickle %s: attribute lookup %s.%s "
@ -2223,7 +2223,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
res = save_string(self, args, 0); res = save_string(self, args, 0);
goto finally; 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); res = save_unicode(self, args, 0);
goto finally; goto finally;
} }
@ -3584,7 +3584,7 @@ load_global(Unpicklerobject *self)
Py_DECREF(module_name); Py_DECREF(module_name);
return bad_readline(); 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, class = find_class(module_name, class_name,
self->find_class); self->find_class);
Py_DECREF(class_name); Py_DECREF(class_name);
@ -5379,7 +5379,7 @@ init_stuff(PyObject *module_dict)
{ {
PyObject *copy_reg, *t, *r; 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) if (PyType_Ready(&Unpicklertype) < 0)
return -1; return -1;

View File

@ -713,7 +713,7 @@ collect(int generation)
double t1 = 0.0; double t1 = 0.0;
if (delstr == NULL) { if (delstr == NULL) {
delstr = PyString_InternFromString("__del__"); delstr = PyUnicode_InternFromString("__del__");
if (delstr == NULL) if (delstr == NULL)
Py_FatalError("gc couldn't allocate \"__del__\""); Py_FatalError("gc couldn't allocate \"__del__\"");
} }

View File

@ -515,7 +515,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
/* Hangul Decomposition adds three characters in /* Hangul Decomposition adds three characters in
a single step, so we need atleast that much room. */ a single step, so we need atleast that much room. */
if (space < 3) { if (space < 3) {
Py_ssize_t newsize = PyString_GET_SIZE(result) + 10; Py_ssize_t newsize = PyUnicode_GET_SIZE(result) + 10;
space += 10; space += 10;
if (PyUnicode_Resize(&result, newsize) == -1) if (PyUnicode_Resize(&result, newsize) == -1)
return NULL; return NULL;

View File

@ -207,7 +207,7 @@ PyObject_DelItemString(PyObject *o, char *key)
null_error(); null_error();
return -1; return -1;
} }
okey = PyString_FromString(key); okey = PyUnicode_FromString(key);
if (okey == NULL) if (okey == NULL)
return -1; return -1;
ret = PyObject_DelItem(o, okey); ret = PyObject_DelItem(o, okey);
@ -1598,7 +1598,7 @@ PyMapping_GetItemString(PyObject *o, char *key)
if (key == NULL) if (key == NULL)
return null_error(); return null_error();
okey = PyString_FromString(key); okey = PyUnicode_FromString(key);
if (okey == NULL) if (okey == NULL)
return NULL; return NULL;
r = PyObject_GetItem(o, okey); r = PyObject_GetItem(o, okey);
@ -1617,7 +1617,7 @@ PyMapping_SetItemString(PyObject *o, char *key, PyObject *value)
return -1; return -1;
} }
okey = PyString_FromString(key); okey = PyUnicode_FromString(key);
if (okey == NULL) if (okey == NULL)
return -1; return -1;
r = PyObject_SetItem(o, okey, value); r = PyObject_SetItem(o, okey, value);
@ -1989,11 +1989,13 @@ abstract_get_bases(PyObject *cls)
PyObject *bases; PyObject *bases;
if (__bases__ == NULL) { if (__bases__ == NULL) {
__bases__ = PyString_FromString("__bases__"); __bases__ = PyUnicode_FromString("__bases__");
if (__bases__ == NULL) if (__bases__ == NULL)
return NULL; return NULL;
} }
Py_ALLOW_RECURSION
bases = PyObject_GetAttr(cls, __bases__); bases = PyObject_GetAttr(cls, __bases__);
Py_END_ALLOW_RECURSION
if (bases == NULL) { if (bases == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError)) if (PyErr_ExceptionMatches(PyExc_AttributeError))
PyErr_Clear(); PyErr_Clear();
@ -2067,7 +2069,7 @@ recursive_isinstance(PyObject *inst, PyObject *cls, int recursion_depth)
int retval = 0; int retval = 0;
if (__class__ == NULL) { if (__class__ == NULL) {
__class__ = PyString_FromString("__class__"); __class__ = PyUnicode_FromString("__class__");
if (__class__ == NULL) if (__class__ == NULL)
return -1; return -1;
} }

View File

@ -1078,7 +1078,7 @@ bytes_count(PyBytesObject *self, PyObject *args)
else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len)) else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
return NULL; return NULL;
_adjust_indices(&start, &end, PyString_GET_SIZE(self)); _adjust_indices(&start, &end, PyBytes_GET_SIZE(self));
return PyInt_FromSsize_t( return PyInt_FromSsize_t(
stringlib_count(str + start, end - start, sub, sub_len) stringlib_count(str + start, end - start, sub, sub_len)

View File

@ -100,7 +100,7 @@ method_get_doc(PyMethodObject *im, void *context)
{ {
static PyObject *docstr; static PyObject *docstr;
if (docstr == NULL) { if (docstr == NULL) {
docstr= PyString_InternFromString("__doc__"); docstr= PyUnicode_InternFromString("__doc__");
if (docstr == NULL) if (docstr == NULL)
return NULL; return NULL;
} }
@ -235,12 +235,12 @@ method_repr(PyMethodObject *a)
return NULL; return NULL;
PyErr_Clear(); PyErr_Clear();
} }
else if (!PyString_Check(funcname)) { else if (!PyUnicode_Check(funcname)) {
Py_DECREF(funcname); Py_DECREF(funcname);
funcname = NULL; funcname = NULL;
} }
else else
sfuncname = PyString_AS_STRING(funcname); sfuncname = PyUnicode_AsString(funcname);
if (klass == NULL) if (klass == NULL)
klassname = NULL; klassname = NULL;
else { else {
@ -250,12 +250,12 @@ method_repr(PyMethodObject *a)
return NULL; return NULL;
PyErr_Clear(); PyErr_Clear();
} }
else if (!PyString_Check(klassname)) { else if (!PyUnicode_Check(klassname)) {
Py_DECREF(klassname); Py_DECREF(klassname);
klassname = NULL; klassname = NULL;
} }
else else
sklassname = PyString_AS_STRING(klassname); sklassname = PyUnicode_AsString(klassname);
} }
if (self == NULL) if (self == NULL)
result = PyUnicode_FromFormat("<unbound method %s.%s>", result = PyUnicode_FromFormat("<unbound method %s.%s>",

View File

@ -32,10 +32,10 @@ intern_strings(PyObject *tuple)
for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
PyObject *v = PyTuple_GET_ITEM(tuple, i); PyObject *v = PyTuple_GET_ITEM(tuple, i);
if (v == NULL || !PyString_CheckExact(v)) { if (v == NULL || !PyUnicode_CheckExact(v)) {
Py_FatalError("non-string found in code slot"); Py_FatalError("non-string found in code slot");
} }
PyString_InternInPlace(&PyTuple_GET_ITEM(tuple, i)); PyUnicode_InternInPlace(&PyTuple_GET_ITEM(tuple, i));
} }
} }
@ -58,7 +58,7 @@ PyCode_New(int argcount, int kwonlyargcount,
varnames == NULL || !PyTuple_Check(varnames) || varnames == NULL || !PyTuple_Check(varnames) ||
freevars == NULL || !PyTuple_Check(freevars) || freevars == NULL || !PyTuple_Check(freevars) ||
cellvars == NULL || !PyTuple_Check(cellvars) || cellvars == NULL || !PyTuple_Check(cellvars) ||
name == NULL || !PyString_Check(name) || name == NULL || (!PyString_Check(name) && !PyUnicode_Check(name)) ||
filename == NULL || !PyString_Check(filename) || filename == NULL || !PyString_Check(filename) ||
lnotab == NULL || !PyString_Check(lnotab) || lnotab == NULL || !PyString_Check(lnotab) ||
!PyObject_CheckReadBuffer(code)) { !PyObject_CheckReadBuffer(code)) {
@ -148,10 +148,10 @@ validate_and_copy_tuple(PyObject *tup)
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
item = PyTuple_GET_ITEM(tup, i); item = PyTuple_GET_ITEM(tup, i);
if (PyString_CheckExact(item)) { if (PyUnicode_CheckExact(item)) {
Py_INCREF(item); Py_INCREF(item);
} }
else if (!PyString_Check(item)) { else if (!PyUnicode_Check(item)) {
PyErr_Format( PyErr_Format(
PyExc_TypeError, PyExc_TypeError,
"name tuples must contain only " "name tuples must contain only "
@ -161,9 +161,9 @@ validate_and_copy_tuple(PyObject *tup)
return NULL; return NULL;
} }
else { else {
item = PyString_FromStringAndSize( item = PyUnicode_FromUnicode(
PyString_AS_STRING(item), PyUnicode_AS_UNICODE(item),
PyString_GET_SIZE(item)); PyUnicode_GET_SIZE(item));
if (item == NULL) { if (item == NULL) {
Py_DECREF(newtuple); Py_DECREF(newtuple);
return NULL; return NULL;

View File

@ -269,7 +269,7 @@ PyComplex_AsCComplex(PyObject *op)
{ {
PyObject *complexfunc; PyObject *complexfunc;
if (!complex_str) { if (!complex_str) {
if (!(complex_str = PyString_FromString("__complex__"))) if (!(complex_str = PyUnicode_FromString("__complex__")))
return cv; return cv;
} }
complexfunc = _PyType_Lookup(op->ob_type, complex_str); complexfunc = _PyType_Lookup(op->ob_type, complex_str);
@ -900,7 +900,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
/* XXX Hack to support classes with __complex__ method */ /* XXX Hack to support classes with __complex__ method */
if (complexstr == NULL) { if (complexstr == NULL) {
complexstr = PyString_InternFromString("__complex__"); complexstr = PyUnicode_InternFromString("__complex__");
if (complexstr == NULL) if (complexstr == NULL)
return NULL; return NULL;
} }

View File

@ -15,7 +15,10 @@ descr_dealloc(PyDescrObject *descr)
static char * static char *
descr_name(PyDescrObject *descr) descr_name(PyDescrObject *descr)
{ {
if (descr->d_name != NULL && PyString_Check(descr->d_name)) if (descr->d_name != NULL && PyUnicode_Check(descr->d_name))
return PyUnicode_AsString(descr->d_name);
else if (descr->d_name != NULL && PyString_Check(descr->d_name))
/* XXX this should not happen */
return PyString_AS_STRING(descr->d_name); return PyString_AS_STRING(descr->d_name);
else else
return "?"; return "?";
@ -581,7 +584,7 @@ descr_new(PyTypeObject *descrtype, PyTypeObject *type, const char *name)
if (descr != NULL) { if (descr != NULL) {
Py_XINCREF(type); Py_XINCREF(type);
descr->d_type = type; descr->d_type = type;
descr->d_name = PyString_InternFromString(name); descr->d_name = PyUnicode_InternFromString(name);
if (descr->d_name == NULL) { if (descr->d_name == NULL) {
Py_DECREF(descr); Py_DECREF(descr);
descr = NULL; descr = NULL;

View File

@ -1040,7 +1040,7 @@ dict_subscript(dictobject *mp, register PyObject *key)
static PyObject *missing_str = NULL; static PyObject *missing_str = NULL;
if (missing_str == NULL) if (missing_str == NULL)
missing_str = missing_str =
PyString_InternFromString("__missing__"); PyUnicode_InternFromString("__missing__");
missing = _PyType_Lookup(mp->ob_type, missing_str); missing = _PyType_Lookup(mp->ob_type, missing_str);
if (missing != NULL) if (missing != NULL)
return PyObject_CallFunctionObjArgs(missing, return PyObject_CallFunctionObjArgs(missing,
@ -2073,7 +2073,7 @@ PyObject *
PyDict_GetItemString(PyObject *v, const char *key) PyDict_GetItemString(PyObject *v, const char *key)
{ {
PyObject *kv, *rv; PyObject *kv, *rv;
kv = PyString_FromString(key); kv = PyUnicode_FromString(key);
if (kv == NULL) if (kv == NULL)
return NULL; return NULL;
rv = PyDict_GetItem(v, kv); rv = PyDict_GetItem(v, kv);
@ -2086,10 +2086,10 @@ PyDict_SetItemString(PyObject *v, const char *key, PyObject *item)
{ {
PyObject *kv; PyObject *kv;
int err; int err;
kv = PyString_FromString(key); kv = PyUnicode_FromString(key);
if (kv == NULL) if (kv == NULL)
return -1; return -1;
PyString_InternInPlace(&kv); /* XXX Should we really? */ PyUnicode_InternInPlace(&kv); /* XXX Should we really? */
err = PyDict_SetItem(v, kv, item); err = PyDict_SetItem(v, kv, item);
Py_DECREF(kv); Py_DECREF(kv);
return err; return err;
@ -2100,7 +2100,7 @@ PyDict_DelItemString(PyObject *v, const char *key)
{ {
PyObject *kv; PyObject *kv;
int err; int err;
kv = PyString_FromString(key); kv = PyUnicode_FromString(key);
if (kv == NULL) if (kv == NULL)
return -1; return -1;
err = PyDict_DelItem(v, kv); err = PyDict_DelItem(v, kv);

View File

@ -542,7 +542,7 @@ static PyObject *builtin_object;
int _PyFrame_Init() int _PyFrame_Init()
{ {
builtin_object = PyString_InternFromString("__builtins__"); builtin_object = PyUnicode_InternFromString("__builtins__");
return (builtin_object != NULL); return (builtin_object != NULL);
} }
@ -722,7 +722,7 @@ map_to_dict(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
for (j = nmap; --j >= 0; ) { for (j = nmap; --j >= 0; ) {
PyObject *key = PyTuple_GET_ITEM(map, j); PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = values[j]; PyObject *value = values[j];
assert(PyString_Check(key)); assert(PyString_Check(key)/*XXX this should go*/ || PyUnicode_Check(key));
if (deref) { if (deref) {
assert(PyCell_Check(value)); assert(PyCell_Check(value));
value = PyCell_GET(value); value = PyCell_GET(value);
@ -770,7 +770,7 @@ dict_to_map(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
for (j = nmap; --j >= 0; ) { for (j = nmap; --j >= 0; ) {
PyObject *key = PyTuple_GET_ITEM(map, j); PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = PyObject_GetItem(dict, key); PyObject *value = PyObject_GetItem(dict, key);
assert(PyString_Check(key)); assert(PyUnicode_Check(key));
/* We only care about NULLs if clear is true. */ /* We only care about NULLs if clear is true. */
if (value == NULL) { if (value == NULL) {
PyErr_Clear(); PyErr_Clear();

View File

@ -322,7 +322,7 @@ func_set_name(PyFunctionObject *op, PyObject *value)
/* Not legal to del f.func_name or to set it to anything /* Not legal to del f.func_name or to set it to anything
* other than a string object. */ * other than a string object. */
if (value == NULL || !PyString_Check(value)) { if (value == NULL || (!PyString_Check(value) && !PyUnicode_Check(value))) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"__name__ must be set to a string object"); "__name__ must be set to a string object");
return -1; return -1;
@ -516,7 +516,7 @@ func_new(PyTypeObject* type, PyObject* args, PyObject* kw)
if (nfree != nclosure) if (nfree != nclosure)
return PyErr_Format(PyExc_ValueError, return PyErr_Format(PyExc_ValueError,
"%s requires closure of length %zd, not %zd", "%s requires closure of length %zd, not %zd",
PyString_AS_STRING(code->co_name), PyUnicode_AsString(code->co_name),
nfree, nclosure); nfree, nclosure);
if (nclosure) { if (nclosure) {
Py_ssize_t i; Py_ssize_t i;

View File

@ -143,7 +143,7 @@ meth_get__doc__(PyCFunctionObject *m, void *closure)
static PyObject * static PyObject *
meth_get__name__(PyCFunctionObject *m, void *closure) meth_get__name__(PyCFunctionObject *m, void *closure)
{ {
return PyString_FromString(m->m_ml->ml_name); return PyUnicode_FromString(m->m_ml->ml_name);
} }
static int static int
@ -297,7 +297,7 @@ listmethodchain(PyMethodChain *chain)
i = 0; i = 0;
for (c = chain; c != NULL; c = c->link) { for (c = chain; c != NULL; c = c->link) {
for (ml = c->methods; ml->ml_name != NULL; ml++) { for (ml = c->methods; ml->ml_name != NULL; ml++) {
PyList_SetItem(v, i, PyString_FromString(ml->ml_name)); PyList_SetItem(v, i, PyUnicode_FromString(ml->ml_name));
i++; i++;
} }
} }

View File

@ -22,7 +22,7 @@ PyModule_New(const char *name)
m = PyObject_GC_New(PyModuleObject, &PyModule_Type); m = PyObject_GC_New(PyModuleObject, &PyModule_Type);
if (m == NULL) if (m == NULL)
return NULL; return NULL;
nameobj = PyString_FromString(name); nameobj = PyUnicode_FromString(name);
m->md_dict = PyDict_New(); m->md_dict = PyDict_New();
if (m->md_dict == NULL || nameobj == NULL) if (m->md_dict == NULL || nameobj == NULL)
goto fail; goto fail;

View File

@ -465,7 +465,7 @@ PyObject_Unicode(PyObject *v)
check this before trying the __unicode__ check this before trying the __unicode__
method. */ method. */
if (unicodestr == NULL) { if (unicodestr == NULL) {
unicodestr= PyString_InternFromString("__unicode__"); unicodestr= PyUnicode_InternFromString("__unicode__");
if (unicodestr == NULL) if (unicodestr == NULL)
return NULL; return NULL;
} }
@ -852,7 +852,7 @@ PyObject_GetAttrString(PyObject *v, const char *name)
if (v->ob_type->tp_getattr != NULL) if (v->ob_type->tp_getattr != NULL)
return (*v->ob_type->tp_getattr)(v, (char*)name); return (*v->ob_type->tp_getattr)(v, (char*)name);
w = PyString_InternFromString(name); w = PyUnicode_InternFromString(name);
if (w == NULL) if (w == NULL)
return NULL; return NULL;
res = PyObject_GetAttr(v, w); res = PyObject_GetAttr(v, w);
@ -880,7 +880,7 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
if (v->ob_type->tp_setattr != NULL) if (v->ob_type->tp_setattr != NULL)
return (*v->ob_type->tp_setattr)(v, (char*)name, w); return (*v->ob_type->tp_setattr)(v, (char*)name, w);
s = PyString_InternFromString(name); s = PyUnicode_InternFromString(name);
if (s == NULL) if (s == NULL)
return -1; return -1;
res = PyObject_SetAttr(v, s, w); res = PyObject_SetAttr(v, s, w);
@ -893,30 +893,19 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
{ {
PyTypeObject *tp = v->ob_type; PyTypeObject *tp = v->ob_type;
if (!PyString_Check(name)) { if (!PyUnicode_Check(name)) {
/* The Unicode to string conversion is done here because the PyErr_Format(PyExc_TypeError,
existing tp_getattro slots expect a string object as name "attribute name must be string, not '%.200s'",
and we wouldn't want to break those. */ name->ob_type->tp_name);
if (PyUnicode_Check(name)) { return NULL;
name = _PyUnicode_AsDefaultEncodedString(name, NULL);
if (name == NULL)
return NULL;
}
else
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
name->ob_type->tp_name);
return NULL;
}
} }
if (tp->tp_getattro != NULL) if (tp->tp_getattro != NULL)
return (*tp->tp_getattro)(v, name); return (*tp->tp_getattro)(v, name);
if (tp->tp_getattr != NULL) if (tp->tp_getattr != NULL)
return (*tp->tp_getattr)(v, PyString_AS_STRING(name)); return (*tp->tp_getattr)(v, PyUnicode_AsString(name));
PyErr_Format(PyExc_AttributeError, PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%.400s'", "'%.50s' object has no attribute '%.400s'",
tp->tp_name, PyString_AS_STRING(name)); tp->tp_name, PyUnicode_AsString(name));
return NULL; return NULL;
} }
@ -938,33 +927,22 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
PyTypeObject *tp = v->ob_type; PyTypeObject *tp = v->ob_type;
int err; int err;
if (!PyString_Check(name)) { if (!PyUnicode_Check(name)) {
/* The Unicode to string conversion is done here because the PyErr_Format(PyExc_TypeError,
existing tp_setattro slots expect a string object as name "attribute name must be string, not '%.200s'",
and we wouldn't want to break those. */ name->ob_type->tp_name);
if (PyUnicode_Check(name)) { return -1;
name = _PyUnicode_AsDefaultEncodedString(name, NULL);
if (name == NULL)
return -1;
}
else
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
name->ob_type->tp_name);
return -1;
}
} }
Py_INCREF(name); Py_INCREF(name);
PyString_InternInPlace(&name); PyUnicode_InternInPlace(&name);
if (tp->tp_setattro != NULL) { if (tp->tp_setattro != NULL) {
err = (*tp->tp_setattro)(v, name, value); err = (*tp->tp_setattro)(v, name, value);
Py_DECREF(name); Py_DECREF(name);
return err; return err;
} }
if (tp->tp_setattr != NULL) { if (tp->tp_setattr != NULL) {
err = (*tp->tp_setattr)(v, PyString_AS_STRING(name), value); err = (*tp->tp_setattr)(v, PyUnicode_AsString(name), value);
Py_DECREF(name); Py_DECREF(name);
return err; return err;
} }
@ -976,14 +954,14 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
"(%s .%.100s)", "(%s .%.100s)",
tp->tp_name, tp->tp_name,
value==NULL ? "del" : "assign to", value==NULL ? "del" : "assign to",
PyString_AS_STRING(name)); PyUnicode_AsString(name));
else else
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"'%.100s' object has only read-only attributes " "'%.100s' object has only read-only attributes "
"(%s .%.100s)", "(%s .%.100s)",
tp->tp_name, tp->tp_name,
value==NULL ? "del" : "assign to", value==NULL ? "del" : "assign to",
PyString_AS_STRING(name)); PyUnicode_AsString(name));
return -1; return -1;
} }
@ -1033,22 +1011,11 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
Py_ssize_t dictoffset; Py_ssize_t dictoffset;
PyObject **dictptr; PyObject **dictptr;
if (!PyString_Check(name)){ if (!PyUnicode_Check(name)){
/* The Unicode to string conversion is done here because the PyErr_Format(PyExc_TypeError,
existing tp_setattro slots expect a string object as name "attribute name must be string, not '%.200s'",
and we wouldn't want to break those. */ name->ob_type->tp_name);
if (PyUnicode_Check(name)) { return NULL;
name = PyUnicode_AsEncodedString(name, NULL, NULL);
if (name == NULL)
return NULL;
}
else
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
name->ob_type->tp_name);
return NULL;
}
} }
else else
Py_INCREF(name); Py_INCREF(name);
@ -1134,7 +1101,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
PyErr_Format(PyExc_AttributeError, PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%.400s'", "'%.50s' object has no attribute '%.400s'",
tp->tp_name, PyString_AS_STRING(name)); tp->tp_name, PyUnicode_AsString(name));
done: done:
Py_DECREF(name); Py_DECREF(name);
return res; return res;
@ -1149,22 +1116,11 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
PyObject **dictptr; PyObject **dictptr;
int res = -1; int res = -1;
if (!PyString_Check(name)){ if (!PyUnicode_Check(name)){
/* The Unicode to string conversion is done here because the PyErr_Format(PyExc_TypeError,
existing tp_setattro slots expect a string object as name "attribute name must be string, not '%.200s'",
and we wouldn't want to break those. */ name->ob_type->tp_name);
if (PyUnicode_Check(name)) { return -1;
name = PyUnicode_AsEncodedString(name, NULL, NULL);
if (name == NULL)
return -1;
}
else
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
name->ob_type->tp_name);
return -1;
}
} }
else else
Py_INCREF(name); Py_INCREF(name);
@ -1212,13 +1168,13 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
if (descr == NULL) { if (descr == NULL) {
PyErr_Format(PyExc_AttributeError, PyErr_Format(PyExc_AttributeError,
"'%.100s' object has no attribute '%.200s'", "'%.100s' object has no attribute '%.200s'",
tp->tp_name, PyString_AS_STRING(name)); tp->tp_name, PyUnicode_AsString(name));
goto done; goto done;
} }
PyErr_Format(PyExc_AttributeError, PyErr_Format(PyExc_AttributeError,
"'%.50s' object attribute '%.400s' is read-only", "'%.50s' object attribute '%.400s' is read-only",
tp->tp_name, PyString_AS_STRING(name)); tp->tp_name, PyUnicode_AsString(name));
done: done:
Py_DECREF(name); Py_DECREF(name);
return res; return res;

View File

@ -686,6 +686,11 @@ string_getbuffer(register PyObject *op)
Py_ssize_t Py_ssize_t
PyString_Size(register PyObject *op) PyString_Size(register PyObject *op)
{ {
if (PyUnicode_Check(op)) {
op = _PyUnicode_AsDefaultEncodedString(op, NULL);
if (!op)
return -1;
}
if (!PyString_Check(op)) if (!PyString_Check(op))
return string_getsize(op); return string_getsize(op);
return ((PyStringObject *)op) -> ob_size; return ((PyStringObject *)op) -> ob_size;
@ -694,6 +699,11 @@ PyString_Size(register PyObject *op)
/*const*/ char * /*const*/ char *
PyString_AsString(register PyObject *op) PyString_AsString(register PyObject *op)
{ {
if (PyUnicode_Check(op)) {
op = _PyUnicode_AsDefaultEncodedString(op, NULL);
if (!op)
return NULL;
}
if (!PyString_Check(op)) if (!PyString_Check(op))
return string_getbuffer(op); return string_getbuffer(op);
return ((PyStringObject *)op) -> ob_sval; return ((PyStringObject *)op) -> ob_sval;
@ -824,7 +834,7 @@ PyString_Repr(PyObject *obj, int smartquotes)
{ {
static const char *hexdigits = "0123456789abcdef"; static const char *hexdigits = "0123456789abcdef";
register PyStringObject* op = (PyStringObject*) obj; register PyStringObject* op = (PyStringObject*) obj;
Py_ssize_t length = PyUnicode_GET_SIZE(op); Py_ssize_t length = PyString_GET_SIZE(op);
size_t newsize = 2 + 4 * op->ob_size; size_t newsize = 2 + 4 * op->ob_size;
PyObject *v; PyObject *v;
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != op->ob_size) { if (newsize > PY_SSIZE_T_MAX || newsize / 4 != op->ob_size) {

View File

@ -35,7 +35,7 @@ type_name(PyTypeObject *type, void *context)
s = type->tp_name; s = type->tp_name;
else else
s++; s++;
return PyString_FromString(s); return PyUnicode_FromString(s);
} }
} }
@ -97,9 +97,9 @@ type_module(PyTypeObject *type, void *context)
else { else {
s = strrchr(type->tp_name, '.'); s = strrchr(type->tp_name, '.');
if (s != NULL) if (s != NULL)
return PyString_FromStringAndSize( return PyUnicode_FromStringAndSize(
type->tp_name, (Py_ssize_t)(s - type->tp_name)); type->tp_name, (Py_ssize_t)(s - type->tp_name));
return PyString_FromString("__builtin__"); return PyUnicode_FromString("__builtin__");
} }
} }
@ -371,7 +371,7 @@ type_repr(PyTypeObject *type)
mod = type_module(type, NULL); mod = type_module(type, NULL);
if (mod == NULL) if (mod == NULL)
PyErr_Clear(); PyErr_Clear();
else if (!PyString_Check(mod)) { else if (!PyUnicode_Check(mod)) {
Py_DECREF(mod); Py_DECREF(mod);
mod = NULL; mod = NULL;
} }
@ -384,11 +384,11 @@ type_repr(PyTypeObject *type)
else else
kind = "type"; kind = "type";
if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) { if (mod != NULL && strcmp(PyUnicode_AsString(mod), "__builtin__")) {
rtn = PyUnicode_FromFormat("<%s '%s.%s'>", rtn = PyUnicode_FromFormat("<%s '%s.%s'>",
kind, kind,
PyString_AS_STRING(mod), PyUnicode_AsString(mod),
PyString_AS_STRING(name)); PyUnicode_AsString(name));
} }
else else
rtn = PyUnicode_FromFormat("<%s '%s'>", kind, type->tp_name); rtn = PyUnicode_FromFormat("<%s '%s'>", kind, type->tp_name);
@ -859,7 +859,7 @@ lookup_maybe(PyObject *self, char *attrstr, PyObject **attrobj)
PyObject *res; PyObject *res;
if (*attrobj == NULL) { if (*attrobj == NULL) {
*attrobj = PyString_InternFromString(attrstr); *attrobj = PyUnicode_InternFromString(attrstr);
if (*attrobj == NULL) if (*attrobj == NULL)
return NULL; return NULL;
} }
@ -1415,7 +1415,7 @@ get_dict_descriptor(PyTypeObject *type)
PyObject *descr; PyObject *descr;
if (dict_str == NULL) { if (dict_str == NULL) {
dict_str = PyString_InternFromString("__dict__"); dict_str = PyUnicode_InternFromString("__dict__");
if (dict_str == NULL) if (dict_str == NULL)
return NULL; return NULL;
} }
@ -1564,14 +1564,14 @@ valid_identifier(PyObject *s)
unsigned char *p; unsigned char *p;
Py_ssize_t i, n; Py_ssize_t i, n;
if (!PyString_Check(s)) { if (!PyUnicode_Check(s)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"__slots__ items must be strings, not '%.200s'", "__slots__ items must be strings, not '%.200s'",
s->ob_type->tp_name); s->ob_type->tp_name);
return 0; return 0;
} }
p = (unsigned char *) PyString_AS_STRING(s); p = (unsigned char *) PyUnicode_AsString(s);
n = PyString_GET_SIZE(s); n = strlen((char*)p)/*XXX PyString_GET_SIZE(s)*/;
/* We must reject an empty name. As a hack, we bump the /* We must reject an empty name. As a hack, we bump the
length to 1 so that the loop will balk on the trailing \0. */ length to 1 so that the loop will balk on the trailing \0. */
if (n == 0) if (n == 0)
@ -1792,22 +1792,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
return NULL; return NULL;
} }
tmp = _unicode_to_string(slots, nslots);
if (tmp == NULL)
goto bad_slots;
if (tmp != slots) {
Py_DECREF(slots);
slots = tmp;
}
/* Check for valid slot names and two special cases */ /* Check for valid slot names and two special cases */
for (i = 0; i < nslots; i++) { for (i = 0; i < nslots; i++) {
PyObject *tmp = PyTuple_GET_ITEM(slots, i); PyObject *tmp = PyTuple_GET_ITEM(slots, i);
char *s;
if (!valid_identifier(tmp)) if (!valid_identifier(tmp))
goto bad_slots; goto bad_slots;
assert(PyString_Check(tmp)); assert(PyUnicode_Check(tmp));
s = PyString_AS_STRING(tmp); if (PyUnicode_CompareWithASCIIString(tmp, "__dict__") == 0) {
if (strcmp(s, "__dict__") == 0) {
if (!may_add_dict || add_dict) { if (!may_add_dict || add_dict) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"__dict__ slot disallowed: " "__dict__ slot disallowed: "
@ -1816,7 +1807,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
} }
add_dict++; add_dict++;
} }
if (strcmp(s, "__weakref__") == 0) { if (PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0) {
if (!may_add_weak || add_weak) { if (!may_add_weak || add_weak) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"__weakref__ slot disallowed: " "__weakref__ slot disallowed: "
@ -1836,11 +1827,11 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
if (newslots == NULL) if (newslots == NULL)
goto bad_slots; goto bad_slots;
for (i = j = 0; i < nslots; i++) { for (i = j = 0; i < nslots; i++) {
char *s;
tmp = PyTuple_GET_ITEM(slots, i); tmp = PyTuple_GET_ITEM(slots, i);
s = PyString_AS_STRING(tmp); if ((add_dict &&
if ((add_dict && strcmp(s, "__dict__") == 0) || PyUnicode_CompareWithASCIIString(tmp, "__dict__") == 0) ||
(add_weak && strcmp(s, "__weakref__") == 0)) (add_weak &&
PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0))
continue; continue;
tmp =_Py_Mangle(name, tmp); tmp =_Py_Mangle(name, tmp);
if (!tmp) if (!tmp)
@ -1917,7 +1908,15 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
type->tp_as_sequence = &et->as_sequence; type->tp_as_sequence = &et->as_sequence;
type->tp_as_mapping = &et->as_mapping; type->tp_as_mapping = &et->as_mapping;
type->tp_as_buffer = &et->as_buffer; type->tp_as_buffer = &et->as_buffer;
type->tp_name = PyString_AS_STRING(name); if (PyString_Check(name))
type->tp_name = PyString_AsString(name);
else {
type->tp_name = PyUnicode_AsString(name);
if (!type->tp_name) {
Py_DECREF(type);
return NULL;
}
}
/* Set tp_base and tp_bases */ /* Set tp_base and tp_bases */
type->tp_bases = bases; type->tp_bases = bases;
@ -1980,7 +1979,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
slotoffset = base->tp_basicsize; slotoffset = base->tp_basicsize;
if (slots != NULL) { if (slots != NULL) {
for (i = 0; i < nslots; i++, mp++) { for (i = 0; i < nslots; i++, mp++) {
mp->name = PyString_AS_STRING( mp->name = PyUnicode_AsString(
PyTuple_GET_ITEM(slots, i)); PyTuple_GET_ITEM(slots, i));
mp->type = T_OBJECT_EX; mp->type = T_OBJECT_EX;
mp->offset = slotoffset; mp->offset = slotoffset;
@ -2157,7 +2156,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
/* Give up */ /* Give up */
PyErr_Format(PyExc_AttributeError, PyErr_Format(PyExc_AttributeError,
"type object '%.50s' has no attribute '%.400s'", "type object '%.50s' has no attribute '%.400s'",
type->tp_name, PyString_AS_STRING(name)); type->tp_name, PyUnicode_AsString(name));
return NULL; return NULL;
} }
@ -2473,7 +2472,7 @@ object_repr(PyObject *self)
mod = type_module(type, NULL); mod = type_module(type, NULL);
if (mod == NULL) if (mod == NULL)
PyErr_Clear(); PyErr_Clear();
else if (!PyString_Check(mod)) { else if (!PyUnicode_Check(mod)) {
Py_DECREF(mod); Py_DECREF(mod);
mod = NULL; mod = NULL;
} }
@ -2482,8 +2481,8 @@ object_repr(PyObject *self)
return NULL; return NULL;
if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__"))
rtn = PyUnicode_FromFormat("<%s.%s object at %p>", rtn = PyUnicode_FromFormat("<%s.%s object at %p>",
PyString_AS_STRING(mod), PyUnicode_AsString(mod),
PyString_AS_STRING(name), PyUnicode_AsString(name),
self); self);
else else
rtn = PyUnicode_FromFormat("<%s object at %p>", rtn = PyUnicode_FromFormat("<%s object at %p>",
@ -2686,7 +2685,7 @@ import_copy_reg(void)
static PyObject *copy_reg_str; static PyObject *copy_reg_str;
if (!copy_reg_str) { if (!copy_reg_str) {
copy_reg_str = PyString_InternFromString("copy_reg"); copy_reg_str = PyUnicode_InternFromString("copy_reg");
if (copy_reg_str == NULL) if (copy_reg_str == NULL)
return NULL; return NULL;
} }
@ -4330,7 +4329,7 @@ slot_sq_item(PyObject *self, Py_ssize_t i)
descrgetfunc f; descrgetfunc f;
if (getitem_str == NULL) { if (getitem_str == NULL) {
getitem_str = PyString_InternFromString("__getitem__"); getitem_str = PyUnicode_InternFromString("__getitem__");
if (getitem_str == NULL) if (getitem_str == NULL)
return NULL; return NULL;
} }
@ -4760,13 +4759,13 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
static PyObject *getattr_str = NULL; static PyObject *getattr_str = NULL;
if (getattr_str == NULL) { if (getattr_str == NULL) {
getattr_str = PyString_InternFromString("__getattr__"); getattr_str = PyUnicode_InternFromString("__getattr__");
if (getattr_str == NULL) if (getattr_str == NULL)
return NULL; return NULL;
} }
if (getattribute_str == NULL) { if (getattribute_str == NULL) {
getattribute_str = getattribute_str =
PyString_InternFromString("__getattribute__"); PyUnicode_InternFromString("__getattribute__");
if (getattribute_str == NULL) if (getattribute_str == NULL)
return NULL; return NULL;
} }
@ -4898,7 +4897,7 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
static PyObject *get_str = NULL; static PyObject *get_str = NULL;
if (get_str == NULL) { if (get_str == NULL) {
get_str = PyString_InternFromString("__get__"); get_str = PyUnicode_InternFromString("__get__");
if (get_str == NULL) if (get_str == NULL)
return NULL; return NULL;
} }
@ -4968,7 +4967,7 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_ssize_t i, n; Py_ssize_t i, n;
if (new_str == NULL) { if (new_str == NULL) {
new_str = PyString_InternFromString("__new__"); new_str = PyUnicode_InternFromString("__new__");
if (new_str == NULL) if (new_str == NULL)
return NULL; return NULL;
} }
@ -5490,7 +5489,7 @@ init_slotdefs(void)
if (initialized) if (initialized)
return; return;
for (p = slotdefs; p->name; p++) { for (p = slotdefs; p->name; p++) {
p->name_strobj = PyString_InternFromString(p->name); p->name_strobj = PyUnicode_InternFromString(p->name);
if (!p->name_strobj) if (!p->name_strobj)
Py_FatalError("Out of memory interning slotdef names"); Py_FatalError("Out of memory interning slotdef names");
} }
@ -5717,9 +5716,9 @@ super_getattro(PyObject *self, PyObject *name)
if (!skip) { if (!skip) {
/* We want __class__ to return the class of the super object /* We want __class__ to return the class of the super object
(i.e. super, or a subclass), not the class of su->obj. */ (i.e. super, or a subclass), not the class of su->obj. */
skip = (PyString_Check(name) && skip = (PyUnicode_Check(name) &&
PyString_GET_SIZE(name) == 9 && PyUnicode_GET_SIZE(name) == 9 &&
strcmp(PyString_AS_STRING(name), "__class__") == 0); PyUnicode_CompareWithASCIIString(name, "__class__") == 0);
} }
if (!skip) { if (!skip) {
@ -5809,7 +5808,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
PyObject *class_attr; PyObject *class_attr;
if (class_str == NULL) { if (class_str == NULL) {
class_str = PyString_FromString("__class__"); class_str = PyUnicode_FromString("__class__");
if (class_str == NULL) if (class_str == NULL)
return NULL; return NULL;
} }

View File

@ -458,8 +458,10 @@ PyObject *PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
/* Copy the Unicode data into the new object */ /* Copy the Unicode data into the new object */
if (u != NULL) { if (u != NULL) {
Py_UNICODE *p = unicode->str; Py_UNICODE *p = unicode->str;
while ((*p++ = *u++)) while (size--)
; *p++ = *u++;
/* Don't need to write trailing 0 because
that's already done by _PyUnicode_New */
} }
return (PyObject *)unicode; return (PyObject *)unicode;
@ -1184,6 +1186,16 @@ PyObject *_PyUnicode_AsDefaultEncodedString(PyObject *unicode,
return v; return v;
} }
char*
PyUnicode_AsString(PyObject *unicode)
{
assert(PyUnicode_Check(unicode));
unicode = _PyUnicode_AsDefaultEncodedString(unicode, NULL);
if (!unicode)
return NULL;
return PyString_AsString(unicode);
}
Py_UNICODE *PyUnicode_AsUnicode(PyObject *unicode) Py_UNICODE *PyUnicode_AsUnicode(PyObject *unicode)
{ {
if (!PyUnicode_Check(unicode)) { if (!PyUnicode_Check(unicode)) {
@ -3247,7 +3259,7 @@ PyObject *PyUnicode_DecodeASCII(const char *s,
goto onError; goto onError;
} }
} }
if (p - PyUnicode_AS_UNICODE(v) < PyString_GET_SIZE(v)) if (p - PyUnicode_AS_UNICODE(v) < PyUnicode_GET_SIZE(v))
if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0) if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
goto onError; goto onError;
Py_XDECREF(errorHandler); Py_XDECREF(errorHandler);
@ -5861,6 +5873,24 @@ int PyUnicode_Compare(PyObject *left,
return -1; return -1;
} }
int
PyUnicode_CompareWithASCIIString(PyObject* uni, const char* str)
{
int i;
Py_UNICODE *id;
assert(PyUnicode_Check(uni));
id = PyUnicode_AS_UNICODE(uni);
/* Compare Unicode string and source character set string */
for (i = 0; id[i] && str[i]; i++)
if (id[i] != str[i])
return ((int)id[i] < (int)str[i]) ? -1 : 1;
if (id[i])
return 1; /* uni is longer */
if (str[i])
return -1; /* str is longer */
return 0;
}
PyObject *PyUnicode_RichCompare(PyObject *left, PyObject *PyUnicode_RichCompare(PyObject *left,
PyObject *right, PyObject *right,
int op) int op)
@ -8671,7 +8701,13 @@ PyUnicode_InternInPlace(PyObject **p)
return; return;
} }
} }
/* It might be that the GetItem call fails even
though the key is present in the dictionary,
namely when this happens during a stack overflow. */
Py_ALLOW_RECURSION
t = PyDict_GetItem(interned, (PyObject *)s); t = PyDict_GetItem(interned, (PyObject *)s);
Py_END_ALLOW_RECURSION
if (t) { if (t) {
Py_INCREF(t); Py_INCREF(t);
Py_DECREF(*p); Py_DECREF(*p);
@ -8679,10 +8715,13 @@ PyUnicode_InternInPlace(PyObject **p)
return; return;
} }
PyThreadState_GET()->recursion_critical = 1;
if (PyDict_SetItem(interned, (PyObject *)s, (PyObject *)s) < 0) { if (PyDict_SetItem(interned, (PyObject *)s, (PyObject *)s) < 0) {
PyErr_Clear(); PyErr_Clear();
PyThreadState_GET()->recursion_critical = 0;
return; return;
} }
PyThreadState_GET()->recursion_critical = 0;
/* The two references in interned are not counted by refcnt. /* The two references in interned are not counted by refcnt.
The deallocator will take care of this */ The deallocator will take care of this */
s->ob_refcnt -= 2; s->ob_refcnt -= 2;
@ -8879,6 +8918,58 @@ unicode_iter(PyObject *seq)
return (PyObject *)it; return (PyObject *)it;
} }
size_t
Py_UNICODE_strlen(const Py_UNICODE *u)
{
int res = 0;
while(*u++)
res++;
return res;
}
Py_UNICODE*
Py_UNICODE_strcpy(Py_UNICODE *s1, const Py_UNICODE *s2)
{
Py_UNICODE *u = s1;
while ((*u++ = *s2++));
return s1;
}
Py_UNICODE*
Py_UNICODE_strncpy(Py_UNICODE *s1, const Py_UNICODE *s2, size_t n)
{
Py_UNICODE *u = s1;
while ((*u++ = *s2++))
if (n-- == 0)
break;
return s1;
}
int
Py_UNICODE_strcmp(const Py_UNICODE *s1, const Py_UNICODE *s2)
{
while (*s1 && *s2 && *s1 == *s2)
s1++, s2++;
if (*s1 && *s2)
return (*s1 < *s2) ? -1 : +1;
if (*s1)
return 1;
if (*s2)
return -1;
return 0;
}
Py_UNICODE*
Py_UNICODE_strchr(const Py_UNICODE *s, Py_UNICODE c)
{
const Py_UNICODE *p;
for (p = s; *p; p++)
if (*p == c)
return (Py_UNICODE*)p;
return NULL;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -18,6 +18,17 @@
#include "abstract.h" #include "abstract.h"
#endif /* PGEN */ #endif /* PGEN */
#define is_potential_identifier_start(c) (\
(c >= 'a' && c <= 'z')\
|| (c >= 'A' && c <= 'Z')\
|| c == '_')
#define is_potential_identifier_char(c) (\
(c >= 'a' && c <= 'z')\
|| (c >= 'A' && c <= 'Z')\
|| (c >= '0' && c <= '9')\
|| c == '_')
extern char *PyOS_Readline(FILE *, FILE *, char *); extern char *PyOS_Readline(FILE *, FILE *, char *);
/* Return malloc'ed string including trailing \n; /* Return malloc'ed string including trailing \n;
empty malloc'ed string for EOF; empty malloc'ed string for EOF;
@ -1209,7 +1220,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
} }
/* Identifier (most frequent token!) */ /* Identifier (most frequent token!) */
if (isalpha(c) || c == '_') { if (is_potential_identifier_start(c)) {
/* Process r"", u"" and ur"" */ /* Process r"", u"" and ur"" */
switch (c) { switch (c) {
case 'r': case 'r':
@ -1227,7 +1238,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
goto letter_quote; goto letter_quote;
break; break;
} }
while (isalnum(c) || c == '_') { while (is_potential_identifier_char(c)) {
c = tok_nextc(tok); c = tok_nextc(tok);
} }
tok_backup(tok, c); tok_backup(tok, c);

View File

@ -3280,3 +3280,5 @@ PyObject* PyAST_mod2obj(mod_ty t)
init_types(); init_types();
return ast2obj_mod(t); return ast2obj_mod(t);
} }

View File

@ -48,7 +48,8 @@ static PyObject *parsestrplus(struct compiling *, const node *n,
static identifier static identifier
new_identifier(const char* n, PyArena *arena) { new_identifier(const char* n, PyArena *arena) {
PyObject* id = PyString_InternFromString(n); PyObject* id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
PyUnicode_InternInPlace(&id);
PyArena_AddPyObject(arena, id); PyArena_AddPyObject(arena, id);
return id; return id;
} }
@ -334,12 +335,10 @@ static const char* FORBIDDEN[] = {
static int static int
forbidden_name(expr_ty e, const node *n) forbidden_name(expr_ty e, const node *n)
{ {
const char *id;
const char **p; const char **p;
assert(PyString_Check(e->v.Name.id)); assert(PyUnicode_Check(e->v.Name.id));
id = PyString_AS_STRING(e->v.Name.id);
for (p = FORBIDDEN; *p; p++) { for (p = FORBIDDEN; *p; p++) {
if (strcmp(*p, id) == 0) { if (PyUnicode_CompareWithASCIIString(e->v.Name.id, *p) == 0) {
ast_error(n, "assignment to keyword"); ast_error(n, "assignment to keyword");
return 1; return 1;
} }
@ -375,7 +374,7 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n)
switch (e->kind) { switch (e->kind) {
case Attribute_kind: case Attribute_kind:
if (ctx == Store && if (ctx == Store &&
!strcmp(PyString_AS_STRING(e->v.Attribute.attr), "None")) { !PyUnicode_CompareWithASCIIString(e->v.Attribute.attr, "None")) {
return ast_error(n, "assignment to None"); return ast_error(n, "assignment to None");
} }
e->v.Attribute.ctx = ctx; e->v.Attribute.ctx = ctx;
@ -2235,6 +2234,7 @@ alias_for_import_name(struct compiling *c, const node *n)
int i; int i;
size_t len; size_t len;
char *s; char *s;
PyObject *uni;
len = 0; len = 0;
for (i = 0; i < NCH(n); i += 2) for (i = 0; i < NCH(n); i += 2)
@ -2255,13 +2255,20 @@ alias_for_import_name(struct compiling *c, const node *n)
} }
--s; --s;
*s = '\0'; *s = '\0';
PyString_InternInPlace(&str); uni = PyUnicode_DecodeUTF8(PyString_AS_STRING(str),
PyString_GET_SIZE(str),
NULL);
Py_DECREF(str);
if (!uni)
return NULL;
str = uni;
PyUnicode_InternInPlace(&str);
PyArena_AddPyObject(c->c_arena, str); PyArena_AddPyObject(c->c_arena, str);
return alias(str, NULL, c->c_arena); return alias(str, NULL, c->c_arena);
} }
break; break;
case STAR: case STAR:
str = PyString_InternFromString("*"); str = PyUnicode_InternFromString("*");
PyArena_AddPyObject(c->c_arena, str); PyArena_AddPyObject(c->c_arena, str);
return alias(str, NULL, c->c_arena); return alias(str, NULL, c->c_arena);
default: default:

View File

@ -48,7 +48,7 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
} }
func = PyTuple_GET_ITEM(args, 0); /* Better be callable */ func = PyTuple_GET_ITEM(args, 0); /* Better be callable */
name = PyTuple_GET_ITEM(args, 1); name = PyTuple_GET_ITEM(args, 1);
if (!PyString_Check(name)) { if ((!PyString_Check(name) && !PyUnicode_Check(name))) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"__build_class__: name is not a string"); "__build_class__: name is not a string");
return NULL; return NULL;
@ -835,20 +835,23 @@ globals and locals. If only globals is given, locals defaults to it.");
static PyObject * static PyObject *
builtin_getattr(PyObject *self, PyObject *args) builtin_getattr(PyObject *self, PyObject *args)
{ {
PyObject *v, *result, *dflt = NULL; PyObject *v, *result, *dflt = NULL, *release = NULL;
PyObject *name; PyObject *name;
if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt)) if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt))
return NULL; return NULL;
if (PyUnicode_Check(name)) {
name = _PyUnicode_AsDefaultEncodedString(name, NULL); if (PyString_Check(name)) {
if (name == NULL) release = PyString_AsDecodedObject(name, NULL, NULL);
if (!release)
return NULL; return NULL;
name = release;
} }
if (!PyString_Check(name)) { if (!PyUnicode_Check(name)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"getattr(): attribute name must be string"); "getattr(): attribute name must be string");
Py_XDECREF(release);
return NULL; return NULL;
} }
result = PyObject_GetAttr(v, name); result = PyObject_GetAttr(v, name);
@ -859,6 +862,7 @@ builtin_getattr(PyObject *self, PyObject *args)
Py_INCREF(dflt); Py_INCREF(dflt);
result = dflt; result = dflt;
} }
Py_XDECREF(release);
return result; return result;
} }
@ -894,13 +898,7 @@ builtin_hasattr(PyObject *self, PyObject *args)
if (!PyArg_UnpackTuple(args, "hasattr", 2, 2, &v, &name)) if (!PyArg_UnpackTuple(args, "hasattr", 2, 2, &v, &name))
return NULL; return NULL;
if (PyUnicode_Check(name)) { if (!PyUnicode_Check(name)) {
name = _PyUnicode_AsDefaultEncodedString(name, NULL);
if (name == NULL)
return NULL;
}
if (!PyString_Check(name)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"hasattr(): attribute name must be string"); "hasattr(): attribute name must be string");
return NULL; return NULL;

View File

@ -454,8 +454,19 @@ _Py_CheckRecursiveCall(char *where)
return -1; return -1;
} }
#endif #endif
if (tstate->recursion_critical)
/* Somebody asked that we don't check for recursion. */
return 0;
if (tstate->overflowed) {
if (tstate->recursion_depth > recursion_limit + 50) {
/* Overflowing while handling an overflow. Give up. */
Py_FatalError("Cannot recover from stack overflow.");
}
return 0;
}
if (tstate->recursion_depth > recursion_limit) { if (tstate->recursion_depth > recursion_limit) {
--tstate->recursion_depth; --tstate->recursion_depth;
tstate->overflowed = 1;
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"maximum recursion depth exceeded%s", "maximum recursion depth exceeded%s",
where); where);
@ -2759,7 +2770,7 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
vars into frame. This isn't too efficient right now. */ vars into frame. This isn't too efficient right now. */
if (PyTuple_GET_SIZE(co->co_cellvars)) { if (PyTuple_GET_SIZE(co->co_cellvars)) {
int i, j, nargs, found; int i, j, nargs, found;
char *cellname, *argname; Py_UNICODE *cellname, *argname;
PyObject *c; PyObject *c;
nargs = co->co_argcount; nargs = co->co_argcount;
@ -2776,13 +2787,13 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
list so that we can march over it more efficiently? list so that we can march over it more efficiently?
*/ */
for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) {
cellname = PyString_AS_STRING( cellname = PyUnicode_AS_UNICODE(
PyTuple_GET_ITEM(co->co_cellvars, i)); PyTuple_GET_ITEM(co->co_cellvars, i));
found = 0; found = 0;
for (j = 0; j < nargs; j++) { for (j = 0; j < nargs; j++) {
argname = PyString_AS_STRING( argname = PyUnicode_AS_UNICODE(
PyTuple_GET_ITEM(co->co_varnames, j)); PyTuple_GET_ITEM(co->co_varnames, j));
if (strcmp(cellname, argname) == 0) { if (Py_UNICODE_strcmp(cellname, argname) == 0) {
c = PyCell_New(GETLOCAL(j)); c = PyCell_New(GETLOCAL(j));
if (c == NULL) if (c == NULL)
goto fail; goto fail;
@ -3428,7 +3439,7 @@ PyEval_GetFuncName(PyObject *func)
if (PyMethod_Check(func)) if (PyMethod_Check(func))
return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func)); return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func));
else if (PyFunction_Check(func)) else if (PyFunction_Check(func))
return PyString_AsString(((PyFunctionObject*)func)->func_name); return PyUnicode_AsString(((PyFunctionObject*)func)->func_name);
else if (PyCFunction_Check(func)) else if (PyCFunction_Check(func))
return ((PyCFunctionObject*)func)->m_ml->ml_name; return ((PyCFunctionObject*)func)->m_ml->ml_name;
else else
@ -4052,8 +4063,8 @@ import_all_from(PyObject *locals, PyObject *v)
break; break;
} }
if (skip_leading_underscores && if (skip_leading_underscores &&
PyString_Check(name) && PyUnicode_Check(name) &&
PyString_AS_STRING(name)[0] == '_') PyUnicode_AS_UNICODE(name)[0] == '_')
{ {
Py_DECREF(name); Py_DECREF(name);
continue; continue;

View File

@ -194,16 +194,16 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident)
{ {
/* Name mangling: __private becomes _classname__private. /* Name mangling: __private becomes _classname__private.
This is independent from how the name is used. */ This is independent from how the name is used. */
const char *p, *name = PyString_AsString(ident); const Py_UNICODE *p, *name = PyUnicode_AS_UNICODE(ident);
char *buffer; Py_UNICODE *buffer;
size_t nlen, plen; size_t nlen, plen;
if (privateobj == NULL || !PyString_Check(privateobj) || if (privateobj == NULL || !PyUnicode_Check(privateobj) ||
name == NULL || name[0] != '_' || name[1] != '_') { name == NULL || name[0] != '_' || name[1] != '_') {
Py_INCREF(ident); Py_INCREF(ident);
return ident; return ident;
} }
p = PyString_AsString(privateobj); p = PyUnicode_AS_UNICODE(privateobj);
nlen = strlen(name); nlen = Py_UNICODE_strlen(name);
/* Don't mangle __id__ or names with dots. /* Don't mangle __id__ or names with dots.
The only time a name with a dot can occur is when The only time a name with a dot can occur is when
@ -214,26 +214,26 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident)
mangling of the module name, e.g. __M.X. mangling of the module name, e.g. __M.X.
*/ */
if ((name[nlen-1] == '_' && name[nlen-2] == '_') if ((name[nlen-1] == '_' && name[nlen-2] == '_')
|| strchr(name, '.')) { || Py_UNICODE_strchr(name, '.')) {
Py_INCREF(ident); Py_INCREF(ident);
return ident; /* Don't mangle __whatever__ */ return ident; /* Don't mangle __whatever__ */
} }
/* Strip leading underscores from class name */ /* Strip leading underscores from class name */
while (*p == '_') while (*p == '_')
p++; p++;
if (*p == '\0') { if (*p == 0) {
Py_INCREF(ident); Py_INCREF(ident);
return ident; /* Don't mangle if class is just underscores */ return ident; /* Don't mangle if class is just underscores */
} }
plen = strlen(p); plen = Py_UNICODE_strlen(p);
ident = PyString_FromStringAndSize(NULL, 1 + nlen + plen); ident = PyUnicode_FromStringAndSize(NULL, 1 + nlen + plen);
if (!ident) if (!ident)
return 0; return 0;
/* ident = "_" + p[:plen] + name # i.e. 1+plen+nlen bytes */ /* ident = "_" + p[:plen] + name # i.e. 1+plen+nlen bytes */
buffer = PyString_AS_STRING(ident); buffer = PyUnicode_AS_UNICODE(ident);
buffer[0] = '_'; buffer[0] = '_';
strncpy(buffer+1, p, plen); Py_UNICODE_strncpy(buffer+1, p, plen);
strcpy(buffer+1+plen, name); Py_UNICODE_strcpy(buffer+1+plen, name);
return ident; return ident;
} }
@ -259,7 +259,7 @@ PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags,
int merged; int merged;
if (!__doc__) { if (!__doc__) {
__doc__ = PyString_InternFromString("__doc__"); __doc__ = PyUnicode_InternFromString("__doc__");
if (!__doc__) if (!__doc__)
return NULL; return NULL;
} }
@ -551,7 +551,7 @@ compiler_new_tmpname(struct compiler *c)
{ {
char tmpname[256]; char tmpname[256];
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", ++c->u->u_tmpname); PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", ++c->u->u_tmpname);
return PyString_FromString(tmpname); return PyUnicode_FromString(tmpname);
} }
/* Allocate a new block and return a pointer to it. /* Allocate a new block and return a pointer to it.
@ -1143,7 +1143,7 @@ compiler_mod(struct compiler *c, mod_ty mod)
int addNone = 1; int addNone = 1;
static PyObject *module; static PyObject *module;
if (!module) { if (!module) {
module = PyString_FromString("<module>"); module = PyUnicode_FromString("<module>");
if (!module) if (!module)
return NULL; return NULL;
} }
@ -1362,7 +1362,7 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,
goto error; goto error;
if (!return_str) { if (!return_str) {
return_str = PyString_InternFromString("return"); return_str = PyUnicode_InternFromString("return");
if (!return_str) if (!return_str)
goto error; goto error;
} }
@ -1488,12 +1488,12 @@ compiler_class(struct compiler *c, stmt_ty s)
/* initialize statics */ /* initialize statics */
if (build_class == NULL) { if (build_class == NULL) {
build_class = PyString_FromString("__build_class__"); build_class = PyUnicode_FromString("__build_class__");
if (build_class == NULL) if (build_class == NULL)
return 0; return 0;
} }
if (locals == NULL) { if (locals == NULL) {
locals = PyString_FromString("__locals__"); locals = PyUnicode_FromString("__locals__");
if (locals == NULL) if (locals == NULL)
return 0; return 0;
} }
@ -1533,7 +1533,7 @@ compiler_class(struct compiler *c, stmt_ty s)
/* ... and store it into f_locals */ /* ... and store it into f_locals */
ADDOP_IN_SCOPE(c, STORE_LOCALS); ADDOP_IN_SCOPE(c, STORE_LOCALS);
/* load __name__ ... */ /* load __name__ ... */
str = PyString_InternFromString("__name__"); str = PyUnicode_InternFromString("__name__");
if (!str || !compiler_nameop(c, str, Load)) { if (!str || !compiler_nameop(c, str, Load)) {
Py_XDECREF(str); Py_XDECREF(str);
compiler_exit_scope(c); compiler_exit_scope(c);
@ -1541,7 +1541,7 @@ compiler_class(struct compiler *c, stmt_ty s)
} }
Py_DECREF(str); Py_DECREF(str);
/* ... and store it as __module__ */ /* ... and store it as __module__ */
str = PyString_InternFromString("__module__"); str = PyUnicode_InternFromString("__module__");
if (!str || !compiler_nameop(c, str, Store)) { if (!str || !compiler_nameop(c, str, Store)) {
Py_XDECREF(str); Py_XDECREF(str);
compiler_exit_scope(c); compiler_exit_scope(c);
@ -1627,7 +1627,7 @@ compiler_lambda(struct compiler *c, expr_ty e)
assert(e->kind == Lambda_kind); assert(e->kind == Lambda_kind);
if (!name) { if (!name) {
name = PyString_InternFromString("<lambda>"); name = PyUnicode_InternFromString("<lambda>");
if (!name) if (!name)
return 0; return 0;
} }
@ -2027,17 +2027,17 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname)
If there is a dot in name, we need to split it and emit a If there is a dot in name, we need to split it and emit a
LOAD_ATTR for each name. LOAD_ATTR for each name.
*/ */
const char *src = PyString_AS_STRING(name); const Py_UNICODE *src = PyUnicode_AS_UNICODE(name);
const char *dot = strchr(src, '.'); const Py_UNICODE *dot = Py_UNICODE_strchr(src, '.');
if (dot) { if (dot) {
/* Consume the base module name to get the first attribute */ /* Consume the base module name to get the first attribute */
src = dot + 1; src = dot + 1;
while (dot) { while (dot) {
/* NB src is only defined when dot != NULL */ /* NB src is only defined when dot != NULL */
PyObject *attr; PyObject *attr;
dot = strchr(src, '.'); dot = Py_UNICODE_strchr(src, '.');
attr = PyString_FromStringAndSize(src, attr = PyUnicode_FromUnicode(src,
dot ? dot - src : strlen(src)); dot ? dot - src : Py_UNICODE_strlen(src));
if (!attr) if (!attr)
return -1; return -1;
ADDOP_O(c, LOAD_ATTR, attr, names); ADDOP_O(c, LOAD_ATTR, attr, names);
@ -2081,11 +2081,11 @@ compiler_import(struct compiler *c, stmt_ty s)
} }
else { else {
identifier tmp = alias->name; identifier tmp = alias->name;
const char *base = PyString_AS_STRING(alias->name); const Py_UNICODE *base = PyUnicode_AS_UNICODE(alias->name);
char *dot = strchr(base, '.'); Py_UNICODE *dot = Py_UNICODE_strchr(base, '.');
if (dot) if (dot)
tmp = PyString_FromStringAndSize(base, tmp = PyUnicode_FromUnicode(base,
dot - base); dot - base);
r = compiler_nameop(c, tmp, Store); r = compiler_nameop(c, tmp, Store);
if (dot) { if (dot) {
Py_DECREF(tmp); Py_DECREF(tmp);
@ -2122,8 +2122,8 @@ compiler_from_import(struct compiler *c, stmt_ty s)
} }
if (s->lineno > c->c_future->ff_lineno) { if (s->lineno > c->c_future->ff_lineno) {
if (!strcmp(PyString_AS_STRING(s->v.ImportFrom.module), if (!PyUnicode_CompareWithASCIIString(s->v.ImportFrom.module,
"__future__")) { "__future__")) {
Py_DECREF(level); Py_DECREF(level);
Py_DECREF(names); Py_DECREF(names);
return compiler_error(c, return compiler_error(c,
@ -2142,7 +2142,7 @@ compiler_from_import(struct compiler *c, stmt_ty s)
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i); alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i);
identifier store_name; identifier store_name;
if (i == 0 && *PyString_AS_STRING(alias->name) == '*') { if (i == 0 && *PyUnicode_AS_UNICODE(alias->name) == '*') {
assert(n == 1); assert(n == 1);
ADDOP(c, IMPORT_STAR); ADDOP(c, IMPORT_STAR);
return 1; return 1;
@ -2172,7 +2172,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
if (Py_OptimizeFlag) if (Py_OptimizeFlag)
return 1; return 1;
if (assertion_error == NULL) { if (assertion_error == NULL) {
assertion_error = PyString_FromString("AssertionError"); assertion_error = PyUnicode_FromString("AssertionError");
if (assertion_error == NULL) if (assertion_error == NULL)
return 0; return 0;
} }
@ -2417,7 +2417,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
/* First check for assignment to __debug__. Param? */ /* First check for assignment to __debug__. Param? */
if ((ctx == Store || ctx == AugStore || ctx == Del) if ((ctx == Store || ctx == AugStore || ctx == Del)
&& !strcmp(PyString_AS_STRING(name), "__debug__")) { && !PyUnicode_CompareWithASCIIString(name, "__debug__")) {
return compiler_error(c, "can not assign to __debug__"); return compiler_error(c, "can not assign to __debug__");
} }
@ -2455,7 +2455,7 @@ mangled = _Py_Mangle(c->u->u_private, name);
} }
/* XXX Leave assert here, but handle __doc__ and the like better */ /* XXX Leave assert here, but handle __doc__ and the like better */
assert(scope || PyString_AS_STRING(name)[0] == '_'); assert(scope || PyUnicode_AS_UNICODE(name)[0] == '_');
switch (optype) { switch (optype) {
case OP_DEREF: case OP_DEREF:
@ -2889,7 +2889,7 @@ compiler_genexp(struct compiler *c, expr_ty e)
{ {
static identifier name; static identifier name;
if (!name) { if (!name) {
name = PyString_FromString("<genexp>"); name = PyUnicode_FromString("<genexp>");
if (!name) if (!name)
return 0; return 0;
} }
@ -2904,7 +2904,7 @@ compiler_listcomp(struct compiler *c, expr_ty e)
{ {
static identifier name; static identifier name;
if (!name) { if (!name) {
name = PyString_FromString("<listcomp>"); name = PyUnicode_FromString("<listcomp>");
if (!name) if (!name)
return 0; return 0;
} }
@ -2919,7 +2919,7 @@ compiler_setcomp(struct compiler *c, expr_ty e)
{ {
static identifier name; static identifier name;
if (!name) { if (!name) {
name = PyString_FromString("<setcomp>"); name = PyUnicode_FromString("<setcomp>");
if (!name) if (!name)
return 0; return 0;
} }
@ -2957,8 +2957,8 @@ expr_constant(expr_ty e)
case Name_kind: case Name_kind:
/* __debug__ is not assignable, so we can optimize /* __debug__ is not assignable, so we can optimize
* it away in if and while statements */ * it away in if and while statements */
if (strcmp(PyString_AS_STRING(e->v.Name.id), if (PyUnicode_CompareWithASCIIString(e->v.Name.id,
"__debug__") == 0) "__debug__") == 0)
return ! Py_OptimizeFlag; return ! Py_OptimizeFlag;
/* fall through */ /* fall through */
default: default:
@ -2999,12 +2999,12 @@ compiler_with(struct compiler *c, stmt_ty s)
assert(s->kind == With_kind); assert(s->kind == With_kind);
if (!enter_attr) { if (!enter_attr) {
enter_attr = PyString_InternFromString("__enter__"); enter_attr = PyUnicode_InternFromString("__enter__");
if (!enter_attr) if (!enter_attr)
return 0; return 0;
} }
if (!exit_attr) { if (!exit_attr) {
exit_attr = PyString_InternFromString("__exit__"); exit_attr = PyUnicode_InternFromString("__exit__");
if (!exit_attr) if (!exit_attr)
return 0; return 0;
} }

View File

@ -55,7 +55,7 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename)
static PyObject *future; static PyObject *future;
if (!future) { if (!future) {
future = PyString_InternFromString("__future__"); future = PyUnicode_InternFromString("__future__");
if (!future) if (!future)
return 0; return 0;
} }

View File

@ -1920,7 +1920,7 @@ PyImport_ImportFrozenModule(char *name)
if (m == NULL) if (m == NULL)
goto err_return; goto err_return;
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
s = PyString_InternFromString(name); s = PyUnicode_InternFromString(name);
if (s == NULL) if (s == NULL)
goto err_return; goto err_return;
err = PyDict_SetItemString(d, "__path__", s); err = PyDict_SetItemString(d, "__path__", s);
@ -1949,7 +1949,7 @@ PyImport_ImportModule(const char *name)
PyObject *pname; PyObject *pname;
PyObject *result; PyObject *result;
pname = PyString_FromString(name); pname = PyUnicode_FromString(name);
if (pname == NULL) if (pname == NULL)
return NULL; return NULL;
result = PyImport_Import(pname); result = PyImport_Import(pname);
@ -2084,12 +2084,12 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
return Py_None; return Py_None;
if (namestr == NULL) { if (namestr == NULL) {
namestr = PyString_InternFromString("__name__"); namestr = PyUnicode_InternFromString("__name__");
if (namestr == NULL) if (namestr == NULL)
return NULL; return NULL;
} }
if (pathstr == NULL) { if (pathstr == NULL) {
pathstr = PyString_InternFromString("__path__"); pathstr = PyUnicode_InternFromString("__path__");
if (pathstr == NULL) if (pathstr == NULL)
return NULL; return NULL;
} }
@ -2097,9 +2097,18 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
*buf = '\0'; *buf = '\0';
*p_buflen = 0; *p_buflen = 0;
modname = PyDict_GetItem(globals, namestr); modname = PyDict_GetItem(globals, namestr);
if (modname == NULL || !PyString_Check(modname)) if (modname == NULL || (!PyString_Check(modname) && !PyUnicode_Check(modname)))
return Py_None; return Py_None;
if (PyUnicode_Check(modname)) {
/* XXX need to support Unicode better */
modname = _PyUnicode_AsDefaultEncodedString(modname, NULL);
if (!modname) {
PyErr_Clear();
return NULL;
}
}
modpath = PyDict_GetItem(globals, pathstr); modpath = PyDict_GetItem(globals, pathstr);
if (modpath != NULL) { if (modpath != NULL) {
Py_ssize_t len = PyString_GET_SIZE(modname); Py_ssize_t len = PyString_GET_SIZE(modname);
@ -2254,13 +2263,23 @@ ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, Py_ssize_t buflen,
} }
return 0; return 0;
} }
if (!PyString_Check(item)) { if (PyString_Check(item)) {
/* XXX there shouldn't be any str8 objects here */
PyObject *uni = PyUnicode_DecodeASCII(PyString_AsString(item),
PyString_Size(item),
"strict");
Py_DECREF(item);
if (!uni)
return 0;
item = uni;
}
if (!PyUnicode_Check(item)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"Item in ``from list'' not a string"); "Item in ``from list'' not a unicode string");
Py_DECREF(item); Py_DECREF(item);
return 0; return 0;
} }
if (PyString_AS_STRING(item)[0] == '*') { if (PyUnicode_AS_UNICODE(item)[0] == '*') {
PyObject *all; PyObject *all;
Py_DECREF(item); Py_DECREF(item);
/* See if the package defines __all__ */ /* See if the package defines __all__ */
@ -2279,9 +2298,23 @@ ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, Py_ssize_t buflen,
} }
hasit = PyObject_HasAttr(mod, item); hasit = PyObject_HasAttr(mod, item);
if (!hasit) { if (!hasit) {
char *subname = PyString_AS_STRING(item); PyObject *item8;
char *subname;
PyObject *submod; PyObject *submod;
char *p; char *p;
if (!Py_FileSystemDefaultEncoding) {
item8 = PyUnicode_EncodeASCII(PyUnicode_AsUnicode(item),
PyUnicode_GetSize(item),
"strict");
} else {
item8 = PyUnicode_AsEncodedObject(item,
Py_FileSystemDefaultEncoding, "strict");
}
if (!item8) {
PyErr_SetString(PyExc_ValueError, "Cannot encode path item");
return 0;
}
subname = PyBytes_AsString(item8);
if (buflen + strlen(subname) >= MAXPATHLEN) { if (buflen + strlen(subname) >= MAXPATHLEN) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"Module name too long"); "Module name too long");
@ -2292,6 +2325,7 @@ ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, Py_ssize_t buflen,
*p++ = '.'; *p++ = '.';
strcpy(p, subname); strcpy(p, subname);
submod = import_submodule(mod, subname, buf); submod = import_submodule(mod, subname, buf);
Py_DECREF(item8);
Py_XDECREF(submod); Py_XDECREF(submod);
if (submod == NULL) { if (submod == NULL) {
Py_DECREF(item); Py_DECREF(item);
@ -2515,10 +2549,10 @@ PyImport_Import(PyObject *module_name)
/* Initialize constant string objects */ /* Initialize constant string objects */
if (silly_list == NULL) { if (silly_list == NULL) {
import_str = PyString_InternFromString("__import__"); import_str = PyUnicode_InternFromString("__import__");
if (import_str == NULL) if (import_str == NULL)
return NULL; return NULL;
builtins_str = PyString_InternFromString("__builtins__"); builtins_str = PyUnicode_InternFromString("__builtins__");
if (builtins_str == NULL) if (builtins_str == NULL)
return NULL; return NULL;
silly_list = Py_BuildValue("[s]", "__doc__"); silly_list = Py_BuildValue("[s]", "__doc__");

View File

@ -65,7 +65,7 @@ Py_InitModule4(const char *name, PyMethodDef *methods, const char *doc,
return NULL; return NULL;
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
if (methods != NULL) { if (methods != NULL) {
n = PyString_FromString(name); n = PyUnicode_FromString(name);
if (n == NULL) if (n == NULL)
return NULL; return NULL;
for (ml = methods; ml->ml_name != NULL; ml++) { for (ml = methods; ml->ml_name != NULL; ml++) {
@ -689,5 +689,5 @@ PyModule_AddIntConstant(PyObject *m, const char *name, long value)
int int
PyModule_AddStringConstant(PyObject *m, const char *name, const char *value) PyModule_AddStringConstant(PyObject *m, const char *name, const char *value)
{ {
return PyModule_AddObject(m, name, PyString_FromString(value)); return PyModule_AddObject(m, name, PyUnicode_FromString(value));
} }

View File

@ -167,6 +167,8 @@ PyThreadState_New(PyInterpreterState *interp)
tstate->frame = NULL; tstate->frame = NULL;
tstate->recursion_depth = 0; tstate->recursion_depth = 0;
tstate->overflowed = 0;
tstate->recursion_critical = 0;
tstate->tracing = 0; tstate->tracing = 0;
tstate->use_tracing = 0; tstate->use_tracing = 0;
tstate->tick_counter = 0; tstate->tick_counter = 0;

View File

@ -1132,6 +1132,8 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
int err = 0; int err = 0;
PyObject *f = PySys_GetObject("stderr"); PyObject *f = PySys_GetObject("stderr");
Py_INCREF(value); Py_INCREF(value);
if (f == NULL)
_PyObject_Dump(value);
if (f == NULL) if (f == NULL)
fprintf(stderr, "lost sys.stderr\n"); fprintf(stderr, "lost sys.stderr\n");
else { else {

View File

@ -92,7 +92,7 @@ ste_repr(PySTEntryObject *ste)
PyOS_snprintf(buf, sizeof(buf), PyOS_snprintf(buf, sizeof(buf),
"<symtable entry %.100s(%ld), line %d>", "<symtable entry %.100s(%ld), line %d>",
PyString_AS_STRING(ste->ste_name), PyUnicode_AsString(ste->ste_name),
PyInt_AS_LONG(ste->ste_id), ste->ste_lineno); PyInt_AS_LONG(ste->ste_id), ste->ste_lineno);
return PyUnicode_FromString(buf); return PyUnicode_FromString(buf);
} }
@ -190,7 +190,7 @@ static identifier top = NULL, lambda = NULL, genexpr = NULL,
listcomp = NULL, setcomp = NULL; listcomp = NULL, setcomp = NULL;
#define GET_IDENTIFIER(VAR) \ #define GET_IDENTIFIER(VAR) \
((VAR) ? (VAR) : ((VAR) = PyString_InternFromString(# VAR))) ((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR)))
#define DUPLICATE_ARGUMENT \ #define DUPLICATE_ARGUMENT \
"duplicate argument '%s' in function definition" "duplicate argument '%s' in function definition"
@ -390,13 +390,13 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
if (flags & DEF_PARAM) { if (flags & DEF_PARAM) {
PyErr_Format(PyExc_SyntaxError, PyErr_Format(PyExc_SyntaxError,
"name '%s' is parameter and global", "name '%s' is parameter and global",
PyString_AS_STRING(name)); PyUnicode_AsString(name));
return 0; return 0;
} }
if (flags & DEF_NONLOCAL) { if (flags & DEF_NONLOCAL) {
PyErr_Format(PyExc_SyntaxError, PyErr_Format(PyExc_SyntaxError,
"name '%s' is nonlocal and global", "name '%s' is nonlocal and global",
PyString_AS_STRING(name)); PyUnicode_AsString(name));
return 0; return 0;
} }
SET_SCOPE(scopes, name, GLOBAL_EXPLICIT); SET_SCOPE(scopes, name, GLOBAL_EXPLICIT);
@ -410,7 +410,7 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
if (flags & DEF_PARAM) { if (flags & DEF_PARAM) {
PyErr_Format(PyExc_SyntaxError, PyErr_Format(PyExc_SyntaxError,
"name '%s' is parameter and nonlocal", "name '%s' is parameter and nonlocal",
PyString_AS_STRING(name)); PyUnicode_AsString(name));
return 0; return 0;
} }
if (!bound) { if (!bound) {
@ -421,7 +421,7 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
if (!PySet_Contains(bound, name)) { if (!PySet_Contains(bound, name)) {
PyErr_Format(PyExc_SyntaxError, PyErr_Format(PyExc_SyntaxError,
"no binding for nonlocal '%s' found", "no binding for nonlocal '%s' found",
PyString_AS_STRING(name)); PyUnicode_AsString(name));
return 0; return 0;
} }
@ -524,7 +524,7 @@ check_unoptimized(const PySTEntryObject* ste) {
PyOS_snprintf(buf, sizeof(buf), PyOS_snprintf(buf, sizeof(buf),
"import * is not allowed in function '%.100s' " "import * is not allowed in function '%.100s' "
"because it is %s", "because it is %s",
PyString_AS_STRING(ste->ste_name), trailer); PyUnicode_AsString(ste->ste_name), trailer);
break; break;
} }
@ -984,7 +984,7 @@ symtable_new_tmpname(struct symtable *st)
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
++st->st_cur->ste_tmpname); ++st->st_cur->ste_tmpname);
tmp = PyString_InternFromString(tmpname); tmp = PyUnicode_InternFromString(tmpname);
if (!tmp) if (!tmp)
return 0; return 0;
if (!symtable_add_def(st, tmp, DEF_LOCAL)) if (!symtable_add_def(st, tmp, DEF_LOCAL))
@ -1129,7 +1129,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
asdl_seq *seq = s->v.Global.names; asdl_seq *seq = s->v.Global.names;
for (i = 0; i < asdl_seq_LEN(seq); i++) { for (i = 0; i < asdl_seq_LEN(seq); i++) {
identifier name = (identifier)asdl_seq_GET(seq, i); identifier name = (identifier)asdl_seq_GET(seq, i);
char *c_name = PyString_AS_STRING(name); char *c_name = PyUnicode_AsString(name);
long cur = symtable_lookup(st, name); long cur = symtable_lookup(st, name);
if (cur < 0) if (cur < 0)
return 0; return 0;
@ -1156,7 +1156,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
asdl_seq *seq = s->v.Nonlocal.names; asdl_seq *seq = s->v.Nonlocal.names;
for (i = 0; i < asdl_seq_LEN(seq); i++) { for (i = 0; i < asdl_seq_LEN(seq); i++) {
identifier name = (identifier)asdl_seq_GET(seq, i); identifier name = (identifier)asdl_seq_GET(seq, i);
char *c_name = PyString_AS_STRING(name); char *c_name = PyUnicode_AsString(name);
long cur = symtable_lookup(st, name); long cur = symtable_lookup(st, name);
if (cur < 0) if (cur < 0)
return 0; return 0;
@ -1316,7 +1316,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
static int static int
symtable_implicit_arg(struct symtable *st, int pos) symtable_implicit_arg(struct symtable *st, int pos)
{ {
PyObject *id = PyString_FromFormat(".%d", pos); PyObject *id = PyUnicode_FromFormat(".%d", pos);
if (id == NULL) if (id == NULL)
return 0; return 0;
if (!symtable_add_def(st, id, DEF_PARAM)) { if (!symtable_add_def(st, id, DEF_PARAM)) {
@ -1425,10 +1425,10 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
*/ */
PyObject *store_name; PyObject *store_name;
PyObject *name = (a->asname == NULL) ? a->name : a->asname; PyObject *name = (a->asname == NULL) ? a->name : a->asname;
const char *base = PyString_AS_STRING(name); const Py_UNICODE *base = PyUnicode_AS_UNICODE(name);
char *dot = strchr(base, '.'); Py_UNICODE *dot = Py_UNICODE_strchr(base, '.');
if (dot) { if (dot) {
store_name = PyString_FromStringAndSize(base, dot - base); store_name = PyUnicode_FromUnicode(base, dot - base);
if (!store_name) if (!store_name)
return 0; return 0;
} }
@ -1436,7 +1436,7 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
store_name = name; store_name = name;
Py_INCREF(store_name); Py_INCREF(store_name);
} }
if (strcmp(PyString_AS_STRING(name), "*")) { if (PyUnicode_CompareWithASCIIString(name, "*")) {
int r = symtable_add_def(st, store_name, DEF_IMPORT); int r = symtable_add_def(st, store_name, DEF_IMPORT);
Py_DECREF(store_name); Py_DECREF(store_name);
return r; return r;

View File

@ -280,7 +280,7 @@ trace_init(void)
int i; int i;
for (i = 0; i < 7; ++i) { for (i = 0; i < 7; ++i) {
if (whatstrings[i] == NULL) { if (whatstrings[i] == NULL) {
name = PyString_InternFromString(whatnames[i]); name = PyUnicode_InternFromString(whatnames[i]);
if (name == NULL) if (name == NULL)
return -1; return -1;
whatstrings[i] = name; whatstrings[i] = name;
@ -801,7 +801,7 @@ list_builtin_module_names(void)
if (list == NULL) if (list == NULL)
return NULL; return NULL;
for (i = 0; PyImport_Inittab[i].name != NULL; i++) { for (i = 0; PyImport_Inittab[i].name != NULL; i++) {
PyObject *name = PyString_FromString( PyObject *name = PyUnicode_FromString(
PyImport_Inittab[i].name); PyImport_Inittab[i].name);
if (name == NULL) if (name == NULL)
break; break;