summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-06-10 09:51:05 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-06-10 09:51:05 (GMT)
commit5b222135f8d2492713994f2cb003980e87ce6a72 (patch)
tree3ac3a6a1d7805360ed779e884ca6c4b3f000321f /Python/bltinmodule.c
parent38e43c25eede3fa77d90ac8183cc0335f4861f4a (diff)
downloadcpython-5b222135f8d2492713994f2cb003980e87ce6a72.zip
cpython-5b222135f8d2492713994f2cb003980e87ce6a72.tar.gz
cpython-5b222135f8d2492713994f2cb003980e87ce6a72.tar.bz2
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.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 97b2c5e..d4c8a74 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -48,7 +48,7 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
}
func = PyTuple_GET_ITEM(args, 0); /* Better be callable */
name = PyTuple_GET_ITEM(args, 1);
- if (!PyString_Check(name)) {
+ if ((!PyString_Check(name) && !PyUnicode_Check(name))) {
PyErr_SetString(PyExc_TypeError,
"__build_class__: name is not a string");
return NULL;
@@ -835,20 +835,23 @@ globals and locals. If only globals is given, locals defaults to it.");
static PyObject *
builtin_getattr(PyObject *self, PyObject *args)
{
- PyObject *v, *result, *dflt = NULL;
+ PyObject *v, *result, *dflt = NULL, *release = NULL;
PyObject *name;
if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt))
return NULL;
- if (PyUnicode_Check(name)) {
- name = _PyUnicode_AsDefaultEncodedString(name, NULL);
- if (name == NULL)
+
+ if (PyString_Check(name)) {
+ release = PyString_AsDecodedObject(name, NULL, NULL);
+ if (!release)
return NULL;
+ name = release;
}
- if (!PyString_Check(name)) {
+ if (!PyUnicode_Check(name)) {
PyErr_SetString(PyExc_TypeError,
"getattr(): attribute name must be string");
+ Py_XDECREF(release);
return NULL;
}
result = PyObject_GetAttr(v, name);
@@ -859,6 +862,7 @@ builtin_getattr(PyObject *self, PyObject *args)
Py_INCREF(dflt);
result = dflt;
}
+ Py_XDECREF(release);
return result;
}
@@ -894,13 +898,7 @@ builtin_hasattr(PyObject *self, PyObject *args)
if (!PyArg_UnpackTuple(args, "hasattr", 2, 2, &v, &name))
return NULL;
- if (PyUnicode_Check(name)) {
- name = _PyUnicode_AsDefaultEncodedString(name, NULL);
- if (name == NULL)
- return NULL;
- }
-
- if (!PyString_Check(name)) {
+ if (!PyUnicode_Check(name)) {
PyErr_SetString(PyExc_TypeError,
"hasattr(): attribute name must be string");
return NULL;