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
Xavier Thompson
cython
Commits
cd9d2b2a
Commit
cd9d2b2a
authored
Dec 26, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug 633: make sure we own references to Python arguments passed into C functions
parent
e3c9a786
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+8
-1
tests/run/owned_arg_refs.pyx
tests/run/owned_arg_refs.pyx
+28
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
cd9d2b2a
...
...
@@ -2953,7 +2953,14 @@ class SimpleCallNode(CallNode):
# Coerce arguments
for
i
in
range
(
min
(
max_nargs
,
actual_nargs
)):
formal_type
=
func_type
.
args
[
i
].
type
self
.
args
[
i
]
=
self
.
args
[
i
].
coerce_to
(
formal_type
,
env
)
arg
=
self
.
args
[
i
].
coerce_to
(
formal_type
,
env
)
if
arg
.
is_attribute
or
not
arg
.
is_simple
:
# we do not own the argument's reference, but we must
# make sure it cannot be collected before we return
# from the function, so we create an owned temp
# reference to it
arg
=
arg
.
coerce_to_temp
(
env
)
self
.
args
[
i
]
=
arg
for
i
in
range
(
max_nargs
,
actual_nargs
):
if
self
.
args
[
i
].
type
.
is_pyobject
:
error
(
self
.
args
[
i
].
pos
,
...
...
tests/run/owned_arg_refs.pyx
0 → 100644
View file @
cd9d2b2a
cdef
class
Owner
:
cdef
object
x
cdef
call_me_with_owner
(
Owner
owner
,
x
):
owner
.
x
=
"def"
# overwrite external reference
return
x
# crashes if x is not owned by function or caller
def
test_ext_type_attr
():
"""
>>> test_ext_type_attr()
'abc5'
"""
owner
=
Owner
()
owner
.
x
=
''
.
join
(
"abc%d"
%
5
)
# non-interned object
return
call_me_with_owner
(
owner
,
owner
.
x
)
cdef
call_me_with_list
(
list
l
,
x
):
l
[:]
=
[(
1
,
2
),
(
3
,
4
)]
# overwrite external reference
return
x
# crashes if x is not owned by function or caller
def
test_index
():
"""
>>> test_index()
[3, 4]
"""
l
=
[[
1
,
2
],[
3
,
4
]]
return
call_me_with_list
(
l
,
l
[
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