Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
a5bba3a5
Commit
a5bba3a5
authored
Mar 20, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merged in latest cython-devel
parents
238d5e66
4b446b49
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
9 deletions
+78
-9
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+3
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+14
-9
Demos/spam.pyx
Demos/spam.pyx
+1
-0
tests/run/range_optimisation_T203.pyx
tests/run/range_optimisation_T203.pyx
+60
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
a5bba3a5
...
...
@@ -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"
)
...
...
Cython/Compiler/Nodes.py
View file @
a5bba3a5
...
...
@@ -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
...
...
Demos/spam.pyx
View file @
a5bba3a5
...
...
@@ -3,6 +3,7 @@
#
cdef
class
Spam
:
cdef
public
int
amount
def
__new__
(
self
):
self
.
amount
=
0
...
...
tests/run/range_optimisation_T203.pyx
0 → 100644
View file @
a5bba3a5
__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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment