Perhaps the error message should be this one (taken from Python 3)?: "exec: arg 1 must be string, bytes or code object"
On Tue, Aug 18, 2009 at 7:27 AM, Andrey Plotnikov<[email protected]> wrote: > Is it right place for posting patches? > > diff -r adbef02d669f Cython/Compiler/Builtin.py > --- a/Cython/Compiler/Builtin.py Sat Aug 08 20:58:14 2009 +0200 > +++ b/Cython/Compiler/Builtin.py Tue Aug 18 18:19:08 2009 +0800 > @@ -182,27 +182,34 @@ > globals = locals; > } > > - if (PyUnicode_Check(o)) { > - s = PyUnicode_AsUTF8String(o); > - if (!s) goto bad; > - o = s; > - #if PY_MAJOR_VERSION >= 3 > - } else if (!PyBytes_Check(o)) { > - #else > - } else if (!PyString_Check(o)) { > - #endif > - /* FIXME: support file objects and code objects */ > - PyErr_SetString(PyExc_TypeError, > - "exec currently requires a string as code input."); > - goto bad; > + if (PyDict_GetItemString(globals, "__builtins__") == NULL) { > + PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins()); > } > - > - #if PY_MAJOR_VERSION >= 3 > - code = PyBytes_AS_STRING(o); > - #else > - code = PyString_AS_STRING(o); > - #endif > - result = PyRun_String(code, Py_file_input, globals, locals); > + > + if (PyCode_Check(o)) { > + result = PyEval_EvalCode((PyCodeObject *)o, globals, locals); > + } > + else { > + if (PyUnicode_Check(o)) { > + s = PyUnicode_AsUTF8String(o); > + if (!s) goto bad; > + o = s; > + #if PY_MAJOR_VERSION >= 3 > + } else if (!PyBytes_Check(o)) { > + #else > + } else if (!PyString_Check(o)) { > + #endif > + PyErr_SetString(PyExc_TypeError, > + "exec: arg 1 must be string or code object"); > + goto bad; > + } > + #if PY_MAJOR_VERSION >= 3 > + code = PyBytes_AS_STRING(o); > + #else > + code = PyString_AS_STRING(o); > + #endif > + result = PyRun_String(code, Py_file_input, globals, locals); > + } > > Py_XDECREF(s); > return result; > > -- > Andrey Plotnikov > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
