From: Robert Bradshaw Date: Thu, 10 Sep 2009 09:20:16 +0000 (-0700) Subject: #344, stop pipeline before code generation in case of errors X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=caac4358061da546a875d0576d4b240ca7e163f6;p=cython.git #344, stop pipeline before code generation in case of errors --- diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 61576421..804e3221 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -34,6 +34,12 @@ def dumptree(t): print t.dump() return t +def abort_on_errors(node): + # Stop the pipeline if there are any errors. + if Errors.num_errors != 0: + raise InternalError, "abort" + return node + class CompilationData(object): # Bundles the information that is passed from transform to transform. # (For now, this is only) @@ -157,6 +163,7 @@ class Context(object): create_parse(self), ] + self.create_pipeline(pxd=False, py=py) + [ inject_pxd_code, + abort_on_errors, generate_pyx_code, ]) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index efba286b..d2556284 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1006,8 +1006,10 @@ class FuncDefNode(StatNode, BlockNode): def analyse_default_values(self, env): genv = env.global_scope() + default_seen = 0 for arg in self.args: if arg.default: + default_seen = 1 if arg.is_generic: if not hasattr(arg, 'default_entry'): arg.default.analyse_types(env) @@ -1028,6 +1030,10 @@ class FuncDefNode(StatNode, BlockNode): error(arg.pos, "This argument cannot have a default value") arg.default = None + elif arg.kw_only: + default_seen = 1 + elif default_seen: + error(arg.pos, "Non-default argument following default argument") def need_gil_acquisition(self, lenv): return 0 @@ -1106,7 +1112,7 @@ class FuncDefNode(StatNode, BlockNode): # ----- Extern library function declarations lenv.generate_library_function_declarations(code) # ----- GIL acquisition - acquire_gil = self.need_gil_acquisition(lenv) + acquire_gil = self.acquire_gil if acquire_gil: env.use_utility_code(force_init_threads_utility_code) code.putln("PyGILState_STATE _save = PyGILState_Ensure();") @@ -1446,6 +1452,7 @@ class CFuncDefNode(FuncDefNode): self.analyse_default_values(env) if self.py_func is not None: self.py_func.analyse_expressions(env) + self.acquire_gil = self.need_gil_acquisition(self.local_scope) def generate_function_header(self, code, with_pymethdef, with_opt_args = 1, with_dispatch = 1, cname = None): arg_decls = [] @@ -1869,6 +1876,7 @@ class DefNode(FuncDefNode): self.analyse_default_values(env) if env.is_py_class_scope: self.synthesize_assignment_node(env) + self.acquire_gil = 0 def synthesize_assignment_node(self, env): import ExprNodes @@ -1971,12 +1979,10 @@ class DefNode(FuncDefNode): else: positional_args = [] kw_only_args = [] - default_seen = 0 for arg in self.args: arg_entry = arg.entry if arg.is_generic: if arg.default: - default_seen = 1 if not arg.is_self_arg: if arg.kw_only: kw_only_args.append(arg) @@ -1984,9 +1990,6 @@ class DefNode(FuncDefNode): positional_args.append(arg) elif arg.kw_only: kw_only_args.append(arg) - default_seen = 1 - elif default_seen: - error(arg.pos, "Non-default argument following default argument") elif not arg.is_self_arg: positional_args.append(arg) diff --git a/tests/errors/e_argdefault.pyx b/tests/errors/e_argdefault.pyx index 752e738b..70c472dd 100644 --- a/tests/errors/e_argdefault.pyx +++ b/tests/errors/e_argdefault.pyx @@ -11,6 +11,7 @@ cdef class Grail: _ERRORS = u""" 1:10: Non-default argument follows default argument -9:16: This argument cannot have a default value +1:36: Non-default argument following default argument 4:23: Non-default argument following default argument +9:16: This argument cannot have a default value """ diff --git a/tests/errors/e_del.pyx b/tests/errors/e_del.pyx index befed049..548f9ad5 100644 --- a/tests/errors/e_del.pyx +++ b/tests/errors/e_del.pyx @@ -8,13 +8,11 @@ def f(a): del f() # error del i # error: deletion of non-Python object del j # error: deletion of non-Python object - del a # error: deletion of local name not supported del x[i] # error: deletion of non-Python object del s.m # error: deletion of non-Python object _ERRORS = u""" 8:6: Cannot assign to or delete this 9:45: Deletion of non-Python object +11:6: Deletion of non-Python object 12:6: Deletion of non-Python object -13:6: Deletion of non-Python object -11:52: Deletion of local or C global name not supported """ diff --git a/tests/errors/e_del2.pyx b/tests/errors/e_del2.pyx new file mode 100644 index 00000000..20dac71a --- /dev/null +++ b/tests/errors/e_del2.pyx @@ -0,0 +1,12 @@ +# Errors reported during code generation. + +cdef int i + +def f(a): + del a # error: deletion of local name not supported + del i # error: deletion of local name not supported + +_ERRORS = u""" +6:52: Deletion of local or C global name not supported +7:52: Deletion of local or C global name not supported +""" diff --git a/tests/errors/nogil.pyx b/tests/errors/nogil.pyx index 570aeb14..a72848d0 100644 --- a/tests/errors/nogil.pyx +++ b/tests/errors/nogil.pyx @@ -103,7 +103,7 @@ _ERRORS = u""" 38:11: Accessing Python attribute not allowed without gil 39: 9: Constructing Python tuple not allowed without gil 40: 8: Constructing Python list not allowed without gil -41: 8: Constructing Python dict not allowed without gil +#41: 8: Constructing Python dict not allowed without gil 42:12: Truth-testing Python object not allowed without gil 43:13: Python type test not allowed without gil #44: 4: Converting to Python object not allowed without gil