mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
patch #683515: "Add unicode support to compile(), eval() and exec"
Incorporated nnorwitz's comment re. Py__USING_UNICODE.
This commit is contained in:
parent
4adc9abc32
commit
3aaf42c613
5 changed files with 61 additions and 9 deletions
|
@ -3122,7 +3122,7 @@ int
|
|||
PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
|
||||
{
|
||||
PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
|
||||
int result = 0;
|
||||
int result = cf->cf_flags != 0;
|
||||
|
||||
if (current_frame != NULL) {
|
||||
const int codeflags = current_frame->f_code->co_flags;
|
||||
|
@ -3898,16 +3898,27 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
|
|||
locals);
|
||||
}
|
||||
else {
|
||||
PyObject *tmp = NULL;
|
||||
char *str;
|
||||
PyCompilerFlags cf;
|
||||
cf.cf_flags = 0;
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(prog)) {
|
||||
tmp = PyUnicode_AsUTF8String(prog);
|
||||
if (tmp == NULL)
|
||||
return -1;
|
||||
prog = tmp;
|
||||
cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
|
||||
}
|
||||
#endif
|
||||
if (PyString_AsStringAndSize(prog, &str, NULL))
|
||||
return -1;
|
||||
cf.cf_flags = 0;
|
||||
if (PyEval_MergeCompilerFlags(&cf))
|
||||
v = PyRun_StringFlags(str, Py_file_input, globals,
|
||||
locals, &cf);
|
||||
else
|
||||
v = PyRun_String(str, Py_file_input, globals, locals);
|
||||
Py_XDECREF(tmp);
|
||||
}
|
||||
if (plain)
|
||||
PyFrame_LocalsToFast(f, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue