Commit 5bb27ff1 authored by Andrey Plotnikov's avatar Andrey Plotnikov

code object support in exec statement

parent a5e49f6e
...@@ -182,6 +182,14 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) { ...@@ -182,6 +182,14 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
globals = locals; globals = locals;
} }
if (PyDict_GetItemString(globals, "__builtins__") == NULL) {
PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins());
}
if (PyCode_Check(o)) {
result = PyEval_EvalCode((PyCodeObject *)o, globals, locals);
}
else {
if (PyUnicode_Check(o)) { if (PyUnicode_Check(o)) {
s = PyUnicode_AsUTF8String(o); s = PyUnicode_AsUTF8String(o);
if (!s) goto bad; if (!s) goto bad;
...@@ -191,18 +199,17 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) { ...@@ -191,18 +199,17 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
#else #else
} else if (!PyString_Check(o)) { } else if (!PyString_Check(o)) {
#endif #endif
/* FIXME: support file objects and code objects */
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"exec currently requires a string as code input."); "exec: arg 1 must be string, bytes or code object");
goto bad; goto bad;
} }
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
code = PyBytes_AS_STRING(o); code = PyBytes_AS_STRING(o);
#else #else
code = PyString_AS_STRING(o); code = PyString_AS_STRING(o);
#endif #endif
result = PyRun_String(code, Py_file_input, globals, locals); result = PyRun_String(code, Py_file_input, globals, locals);
}
Py_XDECREF(s); Py_XDECREF(s);
return result; return result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment