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
Kirill Smelkov
cython
Commits
cad41704
Commit
cad41704
authored
Oct 06, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix two more closure bugs.
parent
92135ccf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
5 deletions
+34
-5
Cython/Compiler/ControlFlow.py
Cython/Compiler/ControlFlow.py
+1
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+5
-4
tests/run/closures_T82.pyx
tests/run/closures_T82.pyx
+28
-0
No files found.
Cython/Compiler/ControlFlow.py
View file @
cad41704
...
...
@@ -70,7 +70,7 @@ class ControlFlow(object):
if
current
is
None
:
return
(
None
,
None
)
state
=
current
.
_get_pos_state_local
(
item
,
pos
)
while
state
is
None
and
current
.
incoming
is
not
None
:
while
(
state
is
None
or
state
==
(
None
,
None
))
and
current
.
incoming
is
not
None
:
current
=
current
.
incoming
state
=
current
.
_get_pos_state_local
(
item
,
pos
)
if
state
is
None
:
...
...
Cython/Compiler/Nodes.py
View file @
cad41704
...
...
@@ -1220,8 +1220,6 @@ class FuncDefNode(StatNode, BlockNode):
if
lenv
.
control_flow
.
get_state
((
entry
.
name
,
'initalized'
))
is
not
True
:
entry
.
xdecref_cleanup
=
1
if
self
.
needs_closure
:
code
.
put_decref
(
Naming
.
cur_scope_cname
,
lenv
.
scope_class
.
type
)
for
entry
in
lenv
.
var_entries
:
if
entry
.
used
and
not
entry
.
in_closure
:
code
.
put_var_decref
(
entry
)
...
...
@@ -1234,6 +1232,8 @@ class FuncDefNode(StatNode, BlockNode):
code
.
put_var_giveref
(
entry
)
elif
not
entry
.
in_closure
and
src
!=
'arg'
:
code
.
put_var_decref
(
entry
)
if
self
.
needs_closure
:
code
.
put_decref
(
Naming
.
cur_scope_cname
,
lenv
.
scope_class
.
type
)
# ----- Return
# This code is duplicated in ModuleNode.generate_module_init_func
...
...
@@ -1861,10 +1861,11 @@ class DefNode(FuncDefNode):
for
arg
in
self
.
args
:
if
not
arg
.
name
:
error
(
arg
.
pos
,
"Missing argument name"
)
if
arg
.
needs_conversion
:
arg
.
entry
=
env
.
declare_var
(
arg
.
name
,
arg
.
type
,
arg
.
pos
)
else
:
env
.
control_flow
.
set_state
((),
(
arg
.
name
,
'source'
),
'arg'
)
env
.
control_flow
.
set_state
((),
(
arg
.
name
,
'initalized'
),
True
)
if
arg
.
needs_conversion
:
arg
.
entry
=
env
.
declare_var
(
arg
.
name
,
arg
.
type
,
arg
.
pos
)
if
arg
.
type
.
is_pyobject
:
arg
.
entry
.
init
=
"0"
arg
.
entry
.
init_to_none
=
0
...
...
tests/run/closures_T82.pyx
View file @
cad41704
...
...
@@ -50,6 +50,15 @@ True
>>> inner_funcs[0](16), inner_funcs[1](32), inner_funcs[2](64)
(19, 37, 73)
>>> switch_funcs([1,2,3], [4,5,6], 0)([10])
[1, 2, 3, 10]
>>> switch_funcs([1,2,3], [4,5,6], 1)([10])
[4, 5, 6, 10]
>>> switch_funcs([1,2,3], [4,5,6], 2) is None
True
>>> call_ignore_func()
"""
def
add_n
(
int
n
):
...
...
@@ -125,6 +134,25 @@ def cy_twofuncs(x):
return
x
+
b
return
f
def
switch_funcs
(
a
,
b
,
int
ix
):
def
f
(
x
):
return
a
+
x
def
g
(
x
):
return
b
+
x
if
ix
==
0
:
return
f
elif
ix
==
1
:
return
g
else
:
return
None
def
ignore_func
(
x
):
def
f
():
return
x
return
None
def
call_ignore_func
():
ignore_func
((
1
,
2
,
3
))
def
more_inner_funcs
(
x
):
# called with x==1
...
...
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