Commit a5bba3a5 authored by Stefan Behnel's avatar Stefan Behnel

merged in latest cython-devel

parents 238d5e66 4b446b49
......@@ -402,6 +402,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln('#define PY_SSIZE_T_CLEAN')
for filename in env.python_include_files:
code.putln('#include "%s"' % filename)
code.putln("#ifndef Py_PYTHON_H")
code.putln(" #error Python headers needed to compile C extensions, please install development version of Python.")
code.putln("#endif")
code.putln("#ifndef PY_LONG_LONG")
code.putln(" #define PY_LONG_LONG LONG_LONG")
code.putln("#endif")
......
......@@ -1033,7 +1033,7 @@ class FuncDefNode(StatNode, BlockNode):
# ----- GIL acquisition
acquire_gil = self.need_gil_acquisition(lenv)
if acquire_gil:
env.use_utility_code(py23_init_threads_utility_code)
env.use_utility_code(force_init_threads_utility_code)
code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
# ----- Automatic lead-ins for certain special functions
if not lenv.nogil:
......@@ -3931,16 +3931,20 @@ class ForFromStatNode(LoopNode, StatNode):
decop = "%s=%s" % (decop[0], step)
loopvar_name = self.loopvar_node.result()
if from_range:
range_bound = code.funcstate.allocate_temp(self.bound2.type, manage_ref=False)
code.putln("%s = %s;" % (range_bound, self.bound2.result()))
# Skip the loop entirely (and avoid assigning to the loopvar) if
# the loop is empty:
code.putln("if (%s%s %s %s) {" % (
self.bound1.result(), offset, self.relation2, self.bound2.result()
self.bound1.result(), offset, self.relation2, range_bound
))
else:
range_bound = self.bound2.result()
code.putln(
"for (%s = %s%s; %s %s %s; %s%s) {" % (
loopvar_name,
self.bound1.result(), offset,
loopvar_name, self.relation2, self.bound2.result(),
loopvar_name, self.relation2, range_bound,
loopvar_name, incop))
if self.py_loopvar_node:
self.py_loopvar_node.generate_evaluation_code(code)
......@@ -3952,6 +3956,7 @@ class ForFromStatNode(LoopNode, StatNode):
code.putln("} %s%s;" % (loopvar_name, decop))
# End the outer if statement:
code.putln("} /* end if */")
code.funcstate.release_temp(range_bound)
else:
code.putln("}")
break_label = code.break_label
......@@ -4492,7 +4497,7 @@ class GILStatNode(TryFinallyStatNode):
finally_clause = GILExitNode(pos, state = state))
def analyse_expressions(self, env):
env.use_utility_code(py23_init_threads_utility_code)
env.use_utility_code(force_init_threads_utility_code)
was_nogil = env.nogil
env.nogil = 1
TryFinallyStatNode.analyse_expressions(self, env)
......@@ -4502,11 +4507,11 @@ class GILStatNode(TryFinallyStatNode):
pass
def generate_execution_code(self, code):
code.putln("/*with %s:*/ {" % self.state)
code.mark_pos(self.pos)
if self.state == 'gil':
code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
code.putln("{ PyGILState_STATE _save = PyGILState_Ensure();")
else:
code.putln("PyThreadState *_save;")
code.putln("{ PyThreadState *_save;")
code.putln("Py_UNBLOCK_THREADS")
TryFinallyStatNode.generate_execution_code(self, code)
code.putln("}")
......@@ -5588,7 +5593,7 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb)
#------------------------------------------------------------------------------------
py23_init_threads_utility_code = UtilityCode(
force_init_threads_utility_code = UtilityCode(
proto="""
#ifndef __PYX_FORCE_INIT_THREADS
#if PY_VERSION_HEX < 0x02040200
......
......@@ -3,6 +3,7 @@
#
cdef class Spam:
cdef public int amount
def __new__(self):
self.amount = 0
......
__doc__ = u"""
>>> test_var(10, 5)
at 0
at 1
at 2
at 3
at 4
5
>>> test_func(5)
get_bound(5)
at 0
at 1
at 2
at 3
at 4
5
>>> test_f()
9
>>> f()
g called
0
1
2
2
"""
cdef int get_bound(int m):
print "get_bound(%s)"%m
return m
def test_var(int n, int m):
cdef int i
for i from 0 <= i < n:
print "at", i
n = m
return i
def test_func(int n):
cdef int i
for i from 0 <= i < get_bound(n):
print "at", i
return i
def test_f():
cdef int i,n
n = 10
for i in range(n):
if i == 5: n *= 2
print i
cdef int g():
print "g called"
return 3
def f():
cdef int i = -1
for i in range(g()):
print i
print i
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