Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 42013:cd125fe83051
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.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sun, 10 Jun 2007 09:51:05 +0000 |
| parents | 9d02a4adf574 |
| children | 825041fc8e2c |
line wrap: on
line diff
--- a/Python/bltinmodule.c Sat Jun 09 16:13:23 2007 +0000 +++ b/Python/bltinmodule.c Sun Jun 10 09:51:05 2007 +0000 @@ -48,7 +48,7 @@ } 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 @@ 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 @@ Py_INCREF(dflt); result = dflt; } + Py_XDECREF(release); return result; } @@ -894,13 +898,7 @@ 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;
