Commit dae30554 authored by Stefan Behnel's avatar Stefan Behnel

merge

parents 7d5d84ac 098f56b9
......@@ -11,3 +11,5 @@ cdf889c30e7a7053de20bae3a578dad09ebcbdf5 0.10.3
a4abf0156540db4d3ebaa95712b65811c43c5acb 0.11-beta
838a6b7cae62e01dc0ce663cccab1f93f649fdbd 0.11.rc
4497f635d5fdbd38ebb841be4869fbfa2bbfdbb6 0.11.1.alpha
7bc36a0f81723117a19f92ffde1676a0884fef65 0.11.1.beta
6454db601984145f38e28d34176fca8a3a22329c 0.11.1
......@@ -165,6 +165,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 + """
......@@ -192,13 +193,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;
......
......@@ -38,8 +38,9 @@ Options:
-a, --annotate Produce a colorized HTML version of the source.
--line-directives Produce #line directives pointing to the .pyx source
--cplus Output a c++ rather than c file.
-X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive
--directive <name>=<value>[,<name=value,...] Overrides a compiler directive
"""
#The following experimental options are supported only on MacOSX:
# -C, --compile Compile generated .c file to .o file
# -X, --link Link .o file to produce extension module (implies -C)
......@@ -80,6 +81,10 @@ def parse_command_line(args):
elif option in ("-C", "--compile"):
options.c_only = 0
elif option in ("-X", "--link"):
if option == "-X":
print >>sys.stderr, "Deprecation warning: The -X command line switch will be changed to a"
print >>sys.stderr, "shorthand for --directive in Cython 0.12. Please use --link instead."
print >>sys.stderr
options.c_only = 0
options.obj_only = 0
elif option in ("-+", "--cplus"):
......
......@@ -2021,7 +2021,7 @@ class SliceIndexNode(ExprNode):
check = stop
if check:
code.putln("if (unlikely((%s) != %d)) {" % (check, target_size))
code.putln('PyErr_Format(PyExc_ValueError, "Assignment to slice of wrong length, expected %%d, got %%d", %d, (%s));' % (
code.putln('PyErr_Format(PyExc_ValueError, "Assignment to slice of wrong length, expected %%"PY_FORMAT_SIZE_T"d, got %%"PY_FORMAT_SIZE_T"d", (Py_ssize_t)%d, (Py_ssize_t)(%s));' % (
target_size, check))
code.putln(code.error_goto(self.pos))
code.putln("}")
......@@ -4277,12 +4277,24 @@ class DivNode(NumBinopNode):
cdivision = None
cdivision_warnings = False
zerodivision_check = None
def analyse_types(self, env):
NumBinopNode.analyse_types(self, env)
if not self.type.is_pyobject and env.directives['cdivision_warnings']:
if not self.type.is_pyobject:
self.zerodivision_check = self.cdivision is None and not env.directives['cdivision']
if self.zerodivision_check or env.directives['cdivision_warnings']:
# Need to check ahead of time to warn or raise zero division error
self.operand1 = self.operand1.coerce_to_simple(env)
self.operand2 = self.operand2.coerce_to_simple(env)
if env.nogil:
error(self.pos, "Pythonic division not allowed without gil, consider using cython.cdivision(True)")
def zero_division_message(self):
if self.type.is_int:
return "integer division or modulo by zero"
else:
return "float division"
def generate_evaluation_code(self, code):
if not self.type.is_pyobject:
......@@ -4293,10 +4305,25 @@ class DivNode(NumBinopNode):
if not self.cdivision:
code.globalstate.use_utility_code(div_int_utility_code.specialize(self.type))
NumBinopNode.generate_evaluation_code(self, code)
if not self.type.is_pyobject and code.globalstate.directives['cdivision_warnings']:
self.generate_div_warning_code(code)
def generate_div_warning_code(self, code):
if not self.type.is_pyobject:
if self.zerodivision_check:
code.putln("if (unlikely(%s == 0)) {" % self.operand2.result())
code.putln('PyErr_Format(PyExc_ZeroDivisionError, "%s");' % self.zero_division_message())
code.putln(code.error_goto(self.pos))
code.putln("}")
if self.type.is_int and self.type.signed and self.operator != '%':
code.globalstate.use_utility_code(division_overflow_test_code)
code.putln("else if (sizeof(%s) == sizeof(long) && unlikely(%s == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(%s))) {" % (
self.type.declaration_code(''),
self.operand2.result(),
self.operand1.result()))
code.putln('PyErr_Format(PyExc_OverflowError, "value too large to perform division");')
code.putln(code.error_goto(self.pos))
code.putln("}")
if code.globalstate.directives['cdivision_warnings']:
code.globalstate.use_utility_code(cdivision_warning_utility_code)
code.putln("if ((%s < 0) ^ (%s < 0)) {" % (
self.operand1.result(),
......@@ -4330,6 +4357,12 @@ class ModNode(DivNode):
or self.operand2.type.is_string
or NumBinopNode.is_py_operation(self))
def zero_division_message(self):
if self.type.is_int:
return "integer division or modulo by zero"
else:
return "float divmod()"
def generate_evaluation_code(self, code):
if not self.type.is_pyobject:
if self.cdivision is None:
......@@ -4341,7 +4374,6 @@ class ModNode(DivNode):
code.globalstate.use_utility_code(
mod_float_utility_code.specialize(self.type, math_h_modifier=self.type.math_h_modifier))
NumBinopNode.generate_evaluation_code(self, code)
if not self.type.is_pyobject and code.globalstate.directives['cdivision_warnings']:
self.generate_div_warning_code(code)
def calculate_result_code(self):
......@@ -5762,3 +5794,10 @@ static int __Pyx_cdivision_warning(void) {
'MODULENAME': Naming.modulename_cname,
'LINENO': Naming.lineno_cname,
})
# from intobject.c
division_overflow_test_code = UtilityCode(
proto="""
#define UNARY_NEG_WOULD_OVERFLOW(x) \
(((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))
""")
......@@ -417,6 +417,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln(" typedef int Py_ssize_t;")
code.putln(" #define PY_SSIZE_T_MAX INT_MAX")
code.putln(" #define PY_SSIZE_T_MIN INT_MIN")
code.putln(" #define PY_FORMAT_SIZE_T \"\"")
code.putln(" #define PyInt_FromSsize_t(z) PyInt_FromLong(z)")
code.putln(" #define PyInt_AsSsize_t(o) PyInt_AsLong(o)")
code.putln(" #define PyNumber_Index(o) PyNumber_Int(o)")
......@@ -549,6 +550,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
env.use_utility_code(streq_utility_code)
# XXX this is a mess
for utility_code in PyrexTypes.c_int_from_py_function.specialize_list:
env.use_utility_code(utility_code)
for utility_code in PyrexTypes.c_long_from_py_function.specialize_list:
env.use_utility_code(utility_code)
def generate_extern_c_macro_definition(self, code):
name = Naming.extern_c_macro
code.putln("#ifdef __cplusplus")
......@@ -1948,10 +1955,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if weakref_entry:
if weakref_entry.type is py_object_type:
tp_weaklistoffset = "%s.tp_weaklistoffset" % typeobj_cname
code.putln("if (%s == 0) %s = offsetof(struct %s, %s);" % (
if type.typedef_flag:
objstruct = type.objstruct_cname
else:
objstruct = "struct %s" % type.objstruct_cname
code.putln("if (%s == 0) %s = offsetof(%s, %s);" % (
tp_weaklistoffset,
tp_weaklistoffset,
type.objstruct_cname,
objstruct,
weakref_entry.cname))
else:
error(weakref_entry.pos, "__weakref__ slot must be of type 'object'")
......
......@@ -891,12 +891,13 @@ class CEnumDefNode(StatNode):
temp,
item.cname,
code.error_goto_if_null(temp, item.pos)))
code.put_gotref(temp)
code.putln('if (__Pyx_SetAttrString(%s, "%s", %s) < 0) %s' % (
Naming.module_cname,
item.name,
temp,
code.error_goto(item.pos)))
code.putln("%s = 0;" % temp)
code.put_decref_clear(temp, PyrexTypes.py_object_type)
code.funcstate.release_temp(temp)
......@@ -984,6 +985,7 @@ class FuncDefNode(StatNode, BlockNode):
if type.is_cfunction:
lenv.nogil = type.nogil and not type.with_gil
self.local_scope = lenv
lenv.directives = env.directives
return lenv
def generate_function_definitions(self, env, code):
......@@ -1257,9 +1259,7 @@ class CFuncDefNode(FuncDefNode):
return self.entry.name
def analyse_declarations(self, env):
if 'locals' in env.directives and env.directives['locals']:
self.directive_locals = env.directives['locals']
directive_locals = self.directive_locals
directive_locals = self.directive_locals = env.directives['locals']
base_type = self.base_type.analyse(env)
# The 2 here is because we need both function and argument names.
name_declarator, type = self.declarator.analyse(base_type, env, nonempty = 2 * (self.body is not None))
......@@ -1606,11 +1606,7 @@ class DefNode(FuncDefNode):
directive_locals = getattr(cfunc, 'directive_locals', {}))
def analyse_declarations(self, env):
if 'locals' in env.directives:
directive_locals = env.directives['locals']
else:
directive_locals = {}
self.directive_locals = directive_locals
directive_locals = self.directive_locals = env.directives['locals']
for arg in self.args:
if hasattr(arg, 'name'):
type = arg.type
......@@ -2524,6 +2520,7 @@ class PyClassDefNode(ClassDefNode):
def analyse_declarations(self, env):
self.target.analyse_target_declaration(env)
cenv = self.create_scope(env)
cenv.directives = env.directives
cenv.class_obj_cname = self.target.entry.cname
self.body.analyse_declarations(cenv)
......@@ -2660,6 +2657,8 @@ class CClassDefNode(ClassDefNode):
if home_scope is not env and self.visibility == 'extern':
env.add_imported_entry(self.class_name, self.entry, pos)
scope = self.entry.type.scope
if scope is not None:
scope.directives = env.directives
if self.doc and Options.docstrings:
scope.doc = embed_position(self.pos, self.doc)
......@@ -2705,6 +2704,7 @@ class PropertyNode(StatNode):
def analyse_declarations(self, env):
entry = env.declare_property(self.name, self.doc, self.pos)
if entry:
entry.scope.directives = env.directives
self.body.analyse_declarations(entry.scope)
def analyse_expressions(self, env):
......@@ -3874,12 +3874,28 @@ class ForFromStatNode(LoopNode, StatNode):
self.body.generate_execution_code(code)
code.put_label(code.continue_label)
if self.py_loopvar_node:
# Reassign py variable to loop var here.
# (For consistancy, should rarely come up in practice.)
# This mess is to make for..from loops with python targets behave
# exactly like those with C targets with regards to re-assignment
# of the loop variable.
import ExprNodes
from_py_node = ExprNodes.CoerceFromPyTypeNode(self.loopvar_node.type, self.target, None)
if self.target.entry.is_pyglobal:
# We know target is a NameNode, this is the only ugly case.
target_node = ExprNodes.PyTempNode(self.target.pos, None)
target_node.result_code = code.funcstate.allocate_temp(py_object_type, False)
code.putln("%s = __Pyx_GetName(%s, %s); %s" % (
target_node.result_code,
Naming.module_cname,
self.target.entry.interned_cname,
code.error_goto_if_null(target_node.result_code, self.target.pos)))
code.put_gotref(target_node.result_code)
else:
target_node = self.target
from_py_node = ExprNodes.CoerceFromPyTypeNode(self.loopvar_node.type, target_node, None)
from_py_node.temp_code = loopvar_name
from_py_node.generate_result_code(code)
if self.target.entry.is_pyglobal:
code.put_decref_clear(target_node.result_code, py_object_type)
code.funcstate.release_temp(target_node.result_code)
code.putln("}")
if self.py_loopvar_node:
# This is potentially wasteful, but we don't want the semantics to
......
......@@ -332,13 +332,20 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
def __init__(self, context, compilation_option_overrides):
super(InterpretCompilerDirectives, self).__init__(context)
self.compilation_option_overrides = compilation_option_overrides
self.compilation_option_overrides = {}
for key, value in compilation_option_overrides.iteritems():
self.compilation_option_overrides[unicode(key)] = value
self.cython_module_names = set()
self.option_names = {}
# Set up processing and handle the cython: comments.
def visit_ModuleNode(self, node):
options = copy.copy(Options.option_defaults)
for key, value in self.compilation_option_overrides.iteritems():
if key in node.option_comments and node.option_comments[key] != value:
warning(node.pos, "Compiler directive differs between environment and file header; this will change "
"in Cython 0.12. See http://article.gmane.org/gmane.comp.python.cython.devel/5233", 2)
break
options.update(node.option_comments)
options.update(self.compilation_option_overrides)
self.options = options
......@@ -659,7 +666,6 @@ class DecoratorTransform(CythonTransform, SkipDeclarations):
return [func_node, reassignment]
ERR_DEC_AFTER = "cdef variable '%s' declared after it is used"
class AnalyseDeclarationsTransform(CythonTransform):
basic_property = TreeFragment(u"""
......@@ -673,22 +679,22 @@ property NAME:
def __call__(self, root):
self.env_stack = [root.scope]
# needed to determine if a cdef var is declared after it's used.
self.local_scope_stack = []
self.seen_vars_stack = []
return super(AnalyseDeclarationsTransform, self).__call__(root)
def visit_NameNode(self, node):
self.local_scope_stack[-1].add(node.name)
self.seen_vars_stack[-1].add(node.name)
return node
def visit_ModuleNode(self, node):
self.local_scope_stack.append(set())
self.seen_vars_stack.append(set())
node.analyse_declarations(self.env_stack[-1])
self.visitchildren(node)
self.local_scope_stack.pop()
self.seen_vars_stack.pop()
return node
def visit_FuncDefNode(self, node):
self.local_scope_stack.append(set())
self.seen_vars_stack.append(set())
lenv = node.create_local_scope(self.env_stack[-1])
node.body.analyse_control_flow(lenv) # this will be totally refactored
node.declare_arguments(lenv)
......@@ -703,7 +709,7 @@ property NAME:
self.env_stack.append(lenv)
self.visitchildren(node)
self.env_stack.pop()
self.local_scope_stack.pop()
self.seen_vars_stack.pop()
return node
# Some nodes are no longer needed after declaration
......@@ -728,9 +734,10 @@ property NAME:
return None
def visit_CNameDeclaratorNode(self, node):
if node.name in self.local_scope_stack[-1]:
# cdef variable declared after it's used.
error(node.pos, ERR_DEC_AFTER % node.name)
if node.name in self.seen_vars_stack[-1]:
entry = self.env_stack[-1].lookup(node.name)
if entry is None or entry.visibility != 'extern':
warning(node.pos, "cdef variable '%s' declared after it is used" % node.name, 2)
self.visitchildren(node)
return node
......
This diff is collapsed.
......@@ -48,6 +48,7 @@ def hash_source_file(path):
from hashlib import md5 as new_md5
except ImportError:
from md5 import new as new_md5
f = None
try:
try:
f = open(path, "rU")
......@@ -56,6 +57,7 @@ def hash_source_file(path):
print("Unable to hash scanner source file (%s)" % e)
return ""
finally:
if f:
f.close()
# Normalise spaces/tabs. We don't know what sort of
# space-tab substitution the file may have been
......
......@@ -208,7 +208,6 @@ class Scope(object):
scope_prefix = ""
in_cinclude = 0
nogil = 0
directives = {}
def __init__(self, name, outer_scope, parent_scope):
# The outer_scope is the next scope in the lookup chain.
......
version = '0.11.1.alpha'
version = '0.11.1'
cdef extern from "stdio.h":
cdef extern from "stdio.h" nogil:
ctypedef struct FILE
int printf(char *format, ...) nogil
int fprintf(FILE *stream, char *format, ...) nogil
int sprintf(char *str, char *format, ...) nogil
FILE *fopen(char *path, char *mode) nogil
int fclose(FILE *strea) nogil
int printf(char *format, ...)
int fprintf(FILE *stream, char *format, ...)
int sprintf(char *str, char *format, ...)
FILE *fopen(char *path, char *mode)
int fclose(FILE *strea)
cdef FILE *stdout
int scanf(char *format, ...) nogil
int scanf(char *format, ...)
cdef extern from "stdlib.h":
void free(void *ptr) nogil
void *malloc(size_t size) nogil
void *realloc(void *ptr, size_t size) nogil
size_t strlen(char *s) nogil
char *strcpy(char *dest, char *src) nogil
cdef extern from "stdlib.h" nogil:
void free(void *ptr)
void *malloc(size_t size)
void *realloc(void *ptr, size_t size)
size_t strlen(char *s)
char *strcpy(char *dest, char *src)
......@@ -105,6 +105,7 @@ class UtilityCode(object):
self.cleanup = cleanup
self.requires = requires
self._cache = {}
self.specialize_list = []
def write_init_code(self, writer, pos):
if not self.init:
......@@ -141,4 +142,5 @@ class UtilityCode(object):
none_or_sub(self.init, data),
none_or_sub(self.cleanup, data),
requires)
self.specialize_list.append(s)
return s
......@@ -10,7 +10,7 @@ from distutils.command.build_ext import build_ext as _build_ext
distutils_distro = Distribution()
TEST_DIRS = ['compile', 'errors', 'run', 'pyregr']
TEST_RUN_DIRS = ['run', 'pyregr', 'bugs']
TEST_RUN_DIRS = ['run', 'pyregr']
# Lists external modules, and a matcher matching tests
# which should be excluded if the module is not present.
......@@ -91,8 +91,6 @@ class TestBuilder(object):
def build_suite(self):
suite = unittest.TestSuite()
test_dirs = TEST_DIRS
if self.test_bugs and 'bugs' not in test_dirs:
test_dirs.append('bugs')
filenames = os.listdir(self.rootdir)
filenames.sort()
for filename in filenames:
......@@ -147,6 +145,9 @@ class TestBuilder(object):
languages = self.languages[:1]
else:
languages = self.languages
if 'cpp' in module and 'c' in languages:
languages = list(languages)
languages.remove('c')
tests = [ self.build_test(test_class, path, workdir, module,
language, expect_errors)
for language in languages ]
......@@ -463,6 +464,18 @@ class VersionDependencyExcluder:
return True
return False
class FileListExcluder:
def __init__(self, list_file):
self.excludes = {}
for line in open(list_file).readlines():
line = line.strip()
if line and line[0] != '#':
self.excludes[line.split()[0]] = True
def __call__(self, testname):
return testname.split('.')[-1] in self.excludes
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser()
......@@ -580,7 +593,7 @@ if __name__ == '__main__':
if options.tickets:
for ticket_number in options.tickets:
test_bugs = True
cmd_args.append('bugs.*T%s$' % ticket_number)
cmd_args.append('.*T%s$' % ticket_number)
if not test_bugs:
for selector in cmd_args:
if selector.startswith('bugs'):
......@@ -601,6 +614,9 @@ if __name__ == '__main__':
if options.exclude:
exclude_selectors += [ re.compile(r, re.I|re.U).search for r in options.exclude ]
if not test_bugs:
exclude_selectors += [ FileListExcluder("tests/bugs.txt") ]
languages = []
if options.use_c:
languages.append('c')
......
# This file contains tests corresponding to of unresolved bugs,
# which will be skipped in the normal testing run.
methodmangling_T5
class_attribute_init_values_T18
return_outside_function_T135
builtin_types_none_T166
numpy_ValueError_T172
unsignedbehaviour_T184
funcexc_iter_T228
pxd_override_T230
ext_instance_type_T232
large_consts_T237
bad_c_struct_T252
missing_baseclass_in_predecl_T262
ifelseexpr_T267
cdef_setitem_T284
extern int generic_error(void);
extern int specified_error(void);
extern int dynamic_error(void);
cdef void raise_py_error():
pass
cdef extern from "foo.h":
cdef extern from "cpp_exceptions.h":
cdef int generic_error() except +
cdef int specified_error() except +MemoryError
cdef int dynamic_error() except +raise_py_error
......
__doc__ = u"""
"""
cdef class A:
cdef __weakref__
ctypedef public class B [type B_Type, object BObject]:
cdef __weakref__
cdef public class C [type C_Type, object CObject]:
cdef __weakref__
......@@ -49,8 +49,8 @@ cdef int *baz
print var[0][0]
cdef unsigned long long var[100][100]
_ERRORS = u"""
# in 0.11.1 these are warnings
FUTURE_ERRORS = u"""
4:13: cdef variable 's' declared after it is used
4:16: cdef variable 'vv' declared after it is used
9:14: cdef variable 'i' declared after it is used
......@@ -63,3 +63,12 @@ _ERRORS = u"""
47:10: cdef variable 'baz' declared after it is used
50:24: cdef variable 'var' declared after it is used
"""
syntax error
_ERRORS = u"""
40:17: cdef variable 't' declared after it is used
47:10: cdef variable 'baz' declared after it is used
50:24: cdef variable 'var' declared after it is used
67:7: Syntax error in simple statement list
"""
This diff is collapsed.
__doc__ = u'''
>>> no_cdef()
>>> with_cdef()
'''
def no_cdef():
lst = range(11)
ob = 10L
lst[ob] = -10
dd = {}
dd[ob] = -10
def with_cdef():
cdef list lst = range(11)
ob = 10L
lst[ob] = -10
cdef dict dd = {}
dd[ob] = -10
......@@ -42,12 +42,36 @@ division with oppositely signed operands, C and Python semantics differ
>>> div_int_c_warn(-17, 10)
division with oppositely signed operands, C and Python semantics differ
-1
>>> complex_expression(-150, 20, 20, -7)
verbose_call(-150)
division with oppositely signed operands, C and Python semantics differ
>>> complex_expression(-150, 20, 19, -7)
verbose_call(20)
division with oppositely signed operands, C and Python semantics differ
verbose_call(19)
division with oppositely signed operands, C and Python semantics differ
-2
>>> mod_div_zero_int(25, 10, 2)
verbose_call(5)
2
>>> mod_div_zero_int(25, 10, 0)
verbose_call(5)
'integer division or modulo by zero'
>>> mod_div_zero_int(25, 0, 0)
'integer division or modulo by zero'
>>> mod_div_zero_float(25, 10, 2)
2.5
>>> mod_div_zero_float(25, 10, 0)
'float division'
>>> mod_div_zero_float(25, 0, 0)
'float divmod()'
>>> import sys
>>> py_div_long(-5, -1)
5
>>> py_div_long(-sys.maxint-1, -1)
Traceback (most recent call last):
...
OverflowError: value too large to perform division
"""
cimport cython
......@@ -109,8 +133,29 @@ def div_int_c_warn(int a, int b):
@cython.cdivision(False)
@cython.cdivision_warnings(True)
def complex_expression(int a, int b, int c, int d):
return (verbose_call(a) // b) % (verbose_call(c) // d)
return (a // verbose_call(b)) % (verbose_call(c) // d)
cdef int verbose_call(int x):
print "verbose_call(%s)" % x
return x
# These may segfault with cdivision
@cython.cdivision(False)
def mod_div_zero_int(int a, int b, int c):
try:
return verbose_call(a % b) / c
except ZeroDivisionError, ex:
return ex.message
@cython.cdivision(False)
def mod_div_zero_float(float a, float b, float c):
try:
return (a % b) / c
except ZeroDivisionError, ex:
return ex.message
@cython.cdivision(False)
def py_div_long(long a, long b):
return a / b
__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']
>>> d['b']
2
>>> d1 = {}
>>> test_dict_scope3(d1, d1)
>>> print d1['b']
>>> d1['b']
2
>>> d1, d2 = {}, {}
>>> test_dict_scope3(d1, d2)
>>> print d1.get('b'), d2.get('b')
None 2
>>> (d1.get('b'), d2.get('b'))
(None, 2)
>>> d1, d2 = {}, {}
>>> test_dict_scope3(d1, d2)
>>> print d1.get('b'), d2.get('b')
None 2
>>> (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
>>> (d1.get('b'), d2.get('b'))
(None, 16)
>>> d = dict(a=11, c=5)
>>> test_dict_scope_ref(d, d)
>>> print d['b']
>>> 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']
......@@ -46,6 +46,12 @@ at 1
at 3
at 7
15
>>> for_from_py_global_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
>>> for_in_target_reassignment(10, 2)
at 0
at 1
......@@ -112,6 +118,13 @@ def for_from_py_target_reassignment(int bound, int factor):
i *= factor
return i
def for_from_py_global_target_reassignment(int bound, int factor):
global g_var
for g_var from 0 <= g_var < bound:
print "at", g_var
g_var *= factor
return g_var
def for_in_target_reassignment(int bound, int factor):
cdef int i = 100
for i in range(bound):
......
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