globals_utility_code = UtilityCode.load_cached("Globals", "Builtins.c")
pyexec_utility_code = UtilityCode.load_cached("PyExec", "Builtins.c")
+pyexec_globals_utility_code = UtilityCode.load_cached("PyExecGlobals", "Builtins.c")
intern_utility_code = UtilityCode(
proto = """
BuiltinFunction('delattr', "OO", "r", "PyObject_DelAttr"),
BuiltinFunction('dir', "O", "O", "PyObject_Dir"),
BuiltinFunction('divmod', "OO", "O", "PyNumber_Divmod"),
- BuiltinFunction('exec', "OOO", "O", "__Pyx_PyRun3",
+ BuiltinFunction('exec', "OOO", "O", "__Pyx_PyExec3",
utility_code = pyexec_utility_code),
- BuiltinFunction('exec', "OO", "O", "__Pyx_PyRun2",
+ BuiltinFunction('exec', "OO", "O", "__Pyx_PyExec2",
utility_code = pyexec_utility_code),
+ BuiltinFunction('exec', "O", "O", "__Pyx_PyExecGlobals",
+ utility_code = pyexec_globals_utility_code),
#('eval', "", "", ""),
#('execfile', "", "", ""),
#('filter', "", "", ""),
args.append( arg.py_result() )
args = tuple(args + ['0', '0'][:3-len(args)])
temp_result = code.funcstate.allocate_temp(PyrexTypes.py_object_type, manage_ref=True)
- code.putln("%s = __Pyx_PyRun3(%s, %s, %s);" % (
+ code.putln("%s = __Pyx_PyExec3(%s, %s, %s);" % (
(temp_result,) + args))
for arg in self.args:
arg.generate_disposal_code(code)
// of Python names. Supporting cdef names in the module and write
// access requires a rewrite as a dedicated class.
-static PyObject* __Pyx_Globals() {
+static PyObject* __Pyx_Globals(void) {
Py_ssize_t i;
/*PyObject *d;*/
PyObject *names = NULL;
return NULL;
}
+//////////////////// PyExecGlobals.proto ////////////////////
+
+static PyObject* __Pyx_PyExecGlobals(PyObject*);
+
+//////////////////// PyExecGlobals ////////////////////
+//@requires: Globals
+//@requires: PyExec
+
+static PyObject* __Pyx_PyExecGlobals(PyObject* code) {
+ PyObject* result;
+ PyObject* globals = __Pyx_Globals();
+ if (unlikely(!globals))
+ return NULL;
+ result = __Pyx_PyExec2(code, globals);
+ Py_DECREF(globals);
+ return result;
+}
+
//////////////////// PyExec.proto ////////////////////
-static PyObject* __Pyx_PyRun3(PyObject*, PyObject*, PyObject*);
-static CYTHON_INLINE PyObject* __Pyx_PyRun2(PyObject*, PyObject*);
+static PyObject* __Pyx_PyExec3(PyObject*, PyObject*, PyObject*);
+static CYTHON_INLINE PyObject* __Pyx_PyExec2(PyObject*, PyObject*);
//////////////////// PyExec ////////////////////
//@substitute: naming
-static CYTHON_INLINE PyObject* __Pyx_PyRun2(PyObject* o, PyObject* globals) {
- return __Pyx_PyRun3(o, globals, NULL);
+static CYTHON_INLINE PyObject* __Pyx_PyExec2(PyObject* o, PyObject* globals) {
+ return __Pyx_PyExec3(o, globals, NULL);
}
-static PyObject* __Pyx_PyRun3(PyObject* o, PyObject* globals, PyObject* locals) {
+static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals) {
PyObject* result;
PyObject* s = 0;
char *code = 0;
cimport cython
__doc__ = """
->>> items = list(locals_function(1).items())
->>> items.sort()
+>>> items = sorted(locals_function(1).items())
>>> for item in items:
... print('%s = %r' % item)
a = 1
exec(cmd, g)
return g
+EXEC_GLOBAL = [5]
+
+def exec1_function(cmd):
+ """
+ >>> exec1_function('EXEC_GLOBAL.append(1)')
+ [1]
+ """
+ old = len(EXEC_GLOBAL)
+ exec(cmd)
+ return EXEC_GLOBAL[old:]
+
ustring = "abcdefg"
def unicode_literals():