Mercurial > cpython-lru_cache-weakref
diff Python/ceval.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 | 6f6f965c5e2d |
| children | 25ddd3dc7a7a |
line wrap: on
line diff
--- a/Python/ceval.c Tue Sep 19 20:51:17 2000 +0000 +++ b/Python/ceval.c Tue Sep 19 21:04:18 2000 +0000 @@ -3042,6 +3042,7 @@ else if (locals == Py_None) locals = globals; if (!PyString_Check(prog) && + !PyUnicode_Check(prog) && !PyCode_Check(prog) && !PyFile_Check(prog)) { PyErr_SetString(PyExc_TypeError, @@ -3064,13 +3065,10 @@ v = PyRun_File(fp, name, Py_file_input, globals, locals); } else { - char *s = PyString_AsString(prog); - if (strlen(s) != (size_t)PyString_Size(prog)) { - PyErr_SetString(PyExc_ValueError, - "embedded '\\0' in exec string"); + char *str; + if (PyString_AsStringAndSize(prog, &str, NULL)) return -1; - } - v = PyRun_String(s, Py_file_input, globals, locals); + v = PyRun_String(str, Py_file_input, globals, locals); } if (plain) PyFrame_LocalsToFast(f, 0);
