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