Commit 47f84661 authored by Stefan Behnel's avatar Stefan Behnel

Make assignments of None to C typed variables a compile time error.

Always coerce Python arguments as "num_threads" in parallel sections to C integers, also to catch some coercion problems at compile time.

Closes #1957.
parent 58c928c1
...@@ -1081,6 +1081,12 @@ class NoneNode(PyConstNode): ...@@ -1081,6 +1081,12 @@ class NoneNode(PyConstNode):
def may_be_none(self): def may_be_none(self):
return True return True
def coerce_to(self, dst_type, env):
if not (dst_type.is_pyobject or dst_type.is_error):
# Catch this error early and loudly.
error(self.pos, "Cannot assign None to %s" % dst_type)
return super(NoneNode, self).coerce_to(dst_type, env)
class EllipsisNode(PyConstNode): class EllipsisNode(PyConstNode):
# '...' in a subscript list. # '...' in a subscript list.
......
...@@ -8060,7 +8060,7 @@ class ParallelStatNode(StatNode, ParallelNode): ...@@ -8060,7 +8060,7 @@ class ParallelStatNode(StatNode, ParallelNode):
self.num_threads.compile_time_value(env) <= 0): self.num_threads.compile_time_value(env) <= 0):
error(self.pos, "argument to num_threads must be greater than 0") error(self.pos, "argument to num_threads must be greater than 0")
if not self.num_threads.is_simple(): if not self.num_threads.is_simple() or self.num_threads.type.is_pyobject:
self.num_threads = self.num_threads.coerce_to( self.num_threads = self.num_threads.coerce_to(
PyrexTypes.c_int_type, env).coerce_to_temp(env) PyrexTypes.c_int_type, env).coerce_to_temp(env)
return self return self
......
...@@ -149,6 +149,10 @@ with nogil, cython.parallel.parallel(): ...@@ -149,6 +149,10 @@ with nogil, cython.parallel.parallel():
with cython.parallel.parallel(): with cython.parallel.parallel():
pass pass
with nogil, cython.parallel.parallel(num_threads=None):
pass
_ERRORS = u""" _ERRORS = u"""
3:8: cython.parallel.parallel is not a module 3:8: cython.parallel.parallel is not a module
4:0: No such directive: cython.parallel.something 4:0: No such directive: cython.parallel.something
...@@ -183,4 +187,6 @@ _ERRORS = u""" ...@@ -183,4 +187,6 @@ _ERRORS = u"""
139:62: Chunksize not valid for the schedule runtime 139:62: Chunksize not valid for the schedule runtime
145:70: Calling gil-requiring function not allowed without gil 145:70: Calling gil-requiring function not allowed without gil
149:33: Nested parallel with blocks are disallowed 149:33: Nested parallel with blocks are disallowed
152:49: Cannot assign None to int
152:49: Coercion from Python not allowed without the 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