Commit caac4358 authored by Robert Bradshaw's avatar Robert Bradshaw

#344, stop pipeline before code generation in case of errors

parent a5c7de87
...@@ -34,6 +34,12 @@ def dumptree(t): ...@@ -34,6 +34,12 @@ def dumptree(t):
print t.dump() print t.dump()
return t 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): class CompilationData(object):
# Bundles the information that is passed from transform to transform. # Bundles the information that is passed from transform to transform.
# (For now, this is only) # (For now, this is only)
...@@ -157,6 +163,7 @@ class Context(object): ...@@ -157,6 +163,7 @@ class Context(object):
create_parse(self), create_parse(self),
] + self.create_pipeline(pxd=False, py=py) + [ ] + self.create_pipeline(pxd=False, py=py) + [
inject_pxd_code, inject_pxd_code,
abort_on_errors,
generate_pyx_code, generate_pyx_code,
]) ])
......
...@@ -1006,8 +1006,10 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1006,8 +1006,10 @@ class FuncDefNode(StatNode, BlockNode):
def analyse_default_values(self, env): def analyse_default_values(self, env):
genv = env.global_scope() genv = env.global_scope()
default_seen = 0
for arg in self.args: for arg in self.args:
if arg.default: if arg.default:
default_seen = 1
if arg.is_generic: if arg.is_generic:
if not hasattr(arg, 'default_entry'): if not hasattr(arg, 'default_entry'):
arg.default.analyse_types(env) arg.default.analyse_types(env)
...@@ -1028,6 +1030,10 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1028,6 +1030,10 @@ class FuncDefNode(StatNode, BlockNode):
error(arg.pos, error(arg.pos,
"This argument cannot have a default value") "This argument cannot have a default value")
arg.default = None 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): def need_gil_acquisition(self, lenv):
return 0 return 0
...@@ -1106,7 +1112,7 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1106,7 +1112,7 @@ class FuncDefNode(StatNode, BlockNode):
# ----- Extern library function declarations # ----- Extern library function declarations
lenv.generate_library_function_declarations(code) lenv.generate_library_function_declarations(code)
# ----- GIL acquisition # ----- GIL acquisition
acquire_gil = self.need_gil_acquisition(lenv) acquire_gil = self.acquire_gil
if acquire_gil: if acquire_gil:
env.use_utility_code(force_init_threads_utility_code) env.use_utility_code(force_init_threads_utility_code)
code.putln("PyGILState_STATE _save = PyGILState_Ensure();") code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
...@@ -1446,6 +1452,7 @@ class CFuncDefNode(FuncDefNode): ...@@ -1446,6 +1452,7 @@ class CFuncDefNode(FuncDefNode):
self.analyse_default_values(env) self.analyse_default_values(env)
if self.py_func is not None: if self.py_func is not None:
self.py_func.analyse_expressions(env) 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): def generate_function_header(self, code, with_pymethdef, with_opt_args = 1, with_dispatch = 1, cname = None):
arg_decls = [] arg_decls = []
...@@ -1869,6 +1876,7 @@ class DefNode(FuncDefNode): ...@@ -1869,6 +1876,7 @@ class DefNode(FuncDefNode):
self.analyse_default_values(env) self.analyse_default_values(env)
if env.is_py_class_scope: if env.is_py_class_scope:
self.synthesize_assignment_node(env) self.synthesize_assignment_node(env)
self.acquire_gil = 0
def synthesize_assignment_node(self, env): def synthesize_assignment_node(self, env):
import ExprNodes import ExprNodes
...@@ -1971,12 +1979,10 @@ class DefNode(FuncDefNode): ...@@ -1971,12 +1979,10 @@ class DefNode(FuncDefNode):
else: else:
positional_args = [] positional_args = []
kw_only_args = [] kw_only_args = []
default_seen = 0
for arg in self.args: for arg in self.args:
arg_entry = arg.entry arg_entry = arg.entry
if arg.is_generic: if arg.is_generic:
if arg.default: if arg.default:
default_seen = 1
if not arg.is_self_arg: if not arg.is_self_arg:
if arg.kw_only: if arg.kw_only:
kw_only_args.append(arg) kw_only_args.append(arg)
...@@ -1984,9 +1990,6 @@ class DefNode(FuncDefNode): ...@@ -1984,9 +1990,6 @@ class DefNode(FuncDefNode):
positional_args.append(arg) positional_args.append(arg)
elif arg.kw_only: elif arg.kw_only:
kw_only_args.append(arg) 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: elif not arg.is_self_arg:
positional_args.append(arg) positional_args.append(arg)
......
...@@ -11,6 +11,7 @@ cdef class Grail: ...@@ -11,6 +11,7 @@ cdef class Grail:
_ERRORS = u""" _ERRORS = u"""
1:10: Non-default argument follows default argument 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 4:23: Non-default argument following default argument
9:16: This argument cannot have a default value
""" """
...@@ -8,13 +8,11 @@ def f(a): ...@@ -8,13 +8,11 @@ def f(a):
del f() # error del f() # error
del i # error: deletion of non-Python object del i # error: deletion of non-Python object
del j # 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 x[i] # error: deletion of non-Python object
del s.m # error: deletion of non-Python object del s.m # error: deletion of non-Python object
_ERRORS = u""" _ERRORS = u"""
8:6: Cannot assign to or delete this 8:6: Cannot assign to or delete this
9:45: Deletion of non-Python object 9:45: Deletion of non-Python object
11:6: Deletion of non-Python object
12: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
""" """
# 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
"""
...@@ -103,7 +103,7 @@ _ERRORS = u""" ...@@ -103,7 +103,7 @@ _ERRORS = u"""
38:11: Accessing Python attribute not allowed without gil 38:11: Accessing Python attribute not allowed without gil
39: 9: Constructing Python tuple not allowed without gil 39: 9: Constructing Python tuple not allowed without gil
40: 8: Constructing Python list 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 42:12: Truth-testing Python object not allowed without gil
43:13: Python type test not allowed without gil 43:13: Python type test not allowed without gil
#44: 4: Converting to Python object not allowed without gil #44: 4: Converting to Python object not allowed without gil
......
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