Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 14696:85038a024b19 legacy-trunk
This patch adds a new Python C API called PyString_AsStringAndSize()
which implements the automatic conversion from Unicode to a string
object using the default encoding.
The new API is then put to use to have eval() and exec accept
Unicode objects as code parameter. This closes bugs #110924
and #113890.
As side-effect, the traditional C APIs PyString_Size() and
PyString_AsString() will also accept Unicode objects as
parameters.
| author | Marc-André Lemburg <mal@egenix.com> |
|---|---|
| date | Tue, 19 Sep 2000 21:04:18 +0000 |
| parents | 2d6188c2ea56 |
| children | 25ddd3dc7a7a |
line wrap: on
line diff
--- a/Python/bltinmodule.c Tue Sep 19 20:51:17 2000 +0000 +++ b/Python/bltinmodule.c Tue Sep 19 21:04:18 2000 +0000 @@ -748,17 +748,14 @@ } if (PyCode_Check(cmd)) return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals); - if (!PyString_Check(cmd)) { + if (!PyString_Check(cmd) && + !PyUnicode_Check(cmd)) { PyErr_SetString(PyExc_TypeError, "eval() argument 1 must be string or code object"); return NULL; } - str = PyString_AsString(cmd); - if (strlen(str) != (size_t)PyString_Size(cmd)) { - PyErr_SetString(PyExc_ValueError, - "embedded '\\0' in string arg"); + if (PyString_AsStringAndSize(cmd, &str, NULL)) return NULL; - } while (*str == ' ' || *str == '\t') str++; return PyRun_String(str, Py_eval_input, globals, locals);
