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
b3a21330
Commit
b3a21330
authored
Apr 26, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix default arguments
parent
0bc88c6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
10 deletions
+35
-10
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+2
-2
Cython/Compiler/FusedNode.pyx
Cython/Compiler/FusedNode.pyx
+9
-8
tests/run/cyfunction_defaults.pyx
tests/run/cyfunction_defaults.pyx
+24
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
b3a21330
...
...
@@ -6217,7 +6217,7 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
env
.
use_utility_code
(
fused_function_utility_code
)
else
:
env
.
use_utility_code
(
binding_cfunc_utility_code
)
self
.
analyse_default_args
(
env
)
self
.
analyse_default_args
(
env
)
#TODO(craig,haoyu) This should be moved to a better place
self
.
set_mod_name
(
env
)
...
...
@@ -6240,7 +6240,7 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
else
:
arg
.
default
=
DefaultLiteralArgNode
(
arg
.
pos
,
arg
.
default
)
default_args
.
append
(
arg
)
if
nonliteral_objects
or
nonliteral_o
bjects
:
if
nonliteral_objects
or
nonliteral_o
ther
:
module_scope
=
env
.
global_scope
()
cname
=
module_scope
.
next_id
(
Naming
.
defaults_struct_prefix
)
scope
=
Symtab
.
StructOrUnionScope
(
cname
)
...
...
Cython/Compiler/FusedNode.pyx
View file @
b3a21330
...
...
@@ -679,18 +679,18 @@ class FusedCFuncDefNode(StatListNode):
else
:
defaults
.
append
(
None
)
for
node
in
self
.
stats
:
node
.
analyse_expressions
(
env
)
if
isinstance
(
node
,
FuncDefNode
):
for
arg
,
default
in
zip
(
node
.
args
,
defaults
):
for
stat
in
self
.
stats
:
stat
.
analyse_expressions
(
env
)
if
isinstance
(
stat
,
FuncDefNode
):
for
arg
,
default
in
zip
(
stat
.
args
,
defaults
):
if
default
is
not
None
:
arg
.
default
=
CloneNode
(
default
).
coerce_to
(
arg
.
type
,
env
)
if
self
.
py_func
:
args
=
[
CloneNode
(
default
)
for
default
in
defaults
if
default
]
defaults_tuple
=
TupleNode
(
self
.
pos
,
args
=
args
)
defaults_tuple
.
analyse_types
(
env
,
skip_children
=
True
)
self
.
defaults_tuple
=
ProxyNode
(
defaults_tuple
)
self
.
defaults_tuple
=
TupleNode
(
self
.
pos
,
args
=
args
)
self
.
defaults_tuple
.
analyse_types
(
env
,
skip_children
=
True
)
self
.
defaults_tuple
=
ProxyNode
(
self
.
defaults_tuple
)
self
.
code_object
=
ProxyNode
(
self
.
specialized_pycfuncs
[
0
].
code_object
)
fused_func
=
self
.
resulting_fused_function
.
arg
...
...
@@ -698,8 +698,9 @@ class FusedCFuncDefNode(StatListNode):
fused_func
.
code_object
=
CloneNode
(
self
.
code_object
)
for
pycfunc
in
self
.
specialized_pycfuncs
:
pycfunc
.
defaults_tuple
=
CloneNode
(
self
.
defaults_tuple
)
pycfunc
.
code_object
=
CloneNode
(
self
.
code_object
)
pycfunc
.
analyse_types
(
env
)
pycfunc
.
defaults_tuple
=
CloneNode
(
self
.
defaults_tuple
)
def
synthesize_defnodes
(
self
):
"""
...
...
tests/run/cyfunction_defaults.pyx
View file @
b3a21330
...
...
@@ -107,3 +107,27 @@ def test_defaults_fused(cython.floating arg1, cython.floating arg2 = counter2())
(2.0,)
"""
print
arg1
,
arg2
funcs
=
[]
for
i
in
range
(
10
):
def
defaults_fused
(
cython
.
floating
a
,
cython
.
floating
b
=
i
):
return
a
,
b
funcs
.
append
(
defaults_fused
)
def
test_dynamic_defaults_fused
():
"""
>>> test_dynamic_defaults_fused()
i 0 func result (1.0, 0.0) defaults (0,)
i 1 func result (1.0, 1.0) defaults (1,)
i 2 func result (1.0, 2.0) defaults (2,)
i 3 func result (1.0, 3.0) defaults (3,)
i 4 func result (1.0, 4.0) defaults (4,)
i 5 func result (1.0, 5.0) defaults (5,)
i 6 func result (1.0, 6.0) defaults (6,)
i 7 func result (1.0, 7.0) defaults (7,)
i 8 func result (1.0, 8.0) defaults (8,)
i 9 func result (1.0, 9.0) defaults (9,)
"""
for
i
,
f
in
enumerate
(
funcs
):
print
"i"
,
i
,
"func result"
,
f
(
1.0
),
"defaults"
,
get_defaults
(
f
)
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