Commit 08971cba authored by Lisandro Dalcin's avatar Lisandro Dalcin

fixes for "exec" statement implementation.

- fix broken compile with MSVC (does not like preprocessor #if/#else/#endif inside call to macro PyRun_String)
- enable "exectest" testcase for Python 3
parent f4203a77
...@@ -168,6 +168,7 @@ impl = """ ...@@ -168,6 +168,7 @@ impl = """
static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) { static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
PyObject* result; PyObject* result;
PyObject* s = 0; PyObject* s = 0;
char *code = 0;
if (!locals && !globals) { if (!locals && !globals) {
globals = PyModule_GetDict(%s);""" % Naming.module_cname + """ globals = PyModule_GetDict(%s);""" % Naming.module_cname + """
...@@ -195,13 +196,12 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) { ...@@ -195,13 +196,12 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
goto bad; goto bad;
} }
result = PyRun_String(
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
PyBytes_AS_STRING(o), code = PyBytes_AS_STRING(o);
#else #else
PyString_AS_STRING(o), code = PyString_AS_STRING(o);
#endif #endif
Py_file_input, globals, locals); result = PyRun_String(code, Py_file_input, globals, locals);
Py_XDECREF(s); Py_XDECREF(s);
return result; return result;
......
__doc__ = """# no unicode string, not tested in Python3! __doc__ = u"""
#>>> a #>>> a
#Traceback (most recent call last): #Traceback (most recent call last):
#NameError: name 'a' is not defined #NameError: name 'a' is not defined
...@@ -10,32 +10,32 @@ __doc__ = """# no unicode string, not tested in Python3! ...@@ -10,32 +10,32 @@ __doc__ = """# no unicode string, not tested in Python3!
>>> d = {} >>> d = {}
>>> test_dict_scope2(d) >>> test_dict_scope2(d)
>>> print d['b'] >>> print (d['b'])
2 2
>>> d1 = {} >>> d1 = {}
>>> test_dict_scope3(d1, d1) >>> test_dict_scope3(d1, d1)
>>> print d1['b'] >>> print (d1['b'])
2 2
>>> d1, d2 = {}, {} >>> d1, d2 = {}, {}
>>> test_dict_scope3(d1, d2) >>> test_dict_scope3(d1, d2)
>>> print d1.get('b'), d2.get('b') >>> print ((d1.get('b'), d2.get('b')))
None 2 (None, 2)
>>> d1, d2 = {}, {} >>> d1, d2 = {}, {}
>>> test_dict_scope3(d1, d2) >>> test_dict_scope3(d1, d2)
>>> print d1.get('b'), d2.get('b') >>> print ((d1.get('b'), d2.get('b')))
None 2 (None, 2)
>>> d1, d2 = dict(a=11), dict(c=5) >>> d1, d2 = dict(a=11), dict(c=5)
>>> test_dict_scope_ref(d1, d2) >>> test_dict_scope_ref(d1, d2)
>>> print d1.get('b'), d2.get('b') >>> print ((d1.get('b'), d2.get('b')))
None 16 (None, 16)
>>> d = dict(a=11, c=5) >>> d = dict(a=11, c=5)
>>> test_dict_scope_ref(d, d) >>> test_dict_scope_ref(d, d)
>>> print d['b'] >>> print (d['b'])
16 16
>>> d = dict(seq = [1,2,3,4]) >>> d = dict(seq = [1,2,3,4])
...@@ -57,22 +57,22 @@ NameError: name 'a' is not defined ...@@ -57,22 +57,22 @@ NameError: name 'a' is not defined
def test_dict_scope1(): def test_dict_scope1():
cdef dict d = {} cdef dict d = {}
exec "b=1+1" in d exec u"b=1+1" in d
return d['b'] return d[u'b']
def test_dict_scope2(d): def test_dict_scope2(d):
exec "b=1+1" in d exec u"b=1+1" in d
def test_dict_scope3(d1, d2): def test_dict_scope3(d1, d2):
exec "b=1+1" in d1, d2 exec u"b=1+1" in d1, d2
def test_dict_scope_ref(d1, d2): def test_dict_scope_ref(d1, d2):
exec "b=a+c" in d1, d2 exec u"b=a+c" in d1, d2
def test_def(d, varref): def test_def(d, varref):
exec """ exec u"""
def test(): def test():
for x in %s: for x in %s:
yield x+1 yield x+1
""" % varref in d """ % varref in d
return d['test'] return d[u'test']
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