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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
ac88a9fa
Commit
ac88a9fa
authored
Jan 17, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support borrowed slices in cdef functions
parent
e6d71f56
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-3
tests/run/memslice.pyx
tests/run/memslice.pyx
+31
-0
No files found.
Cython/Compiler/Nodes.py
View file @
ac88a9fa
...
...
@@ -1551,11 +1551,11 @@ class FuncDefNode(StatNode, BlockNode):
not
entry
.
in_closure
):
code
.
put_var_incref
(
entry
)
# Note: defaults are always incref
f
ed. For def functions, we
# Note: defaults are always incref
-
ed. For def functions, we
# we aquire arguments from object converstion, so we have
# new references. If we are a cdef function, we need to
# incref our arguments
if
is_cdef
and
entry
.
type
.
is_memoryviewslice
:
elif
is_cdef
and
entry
.
type
.
is_memoryviewslice
and
len
(
entry
.
cf_assignments
)
>
1
:
code
.
put_incref_memoryviewslice
(
entry
.
cname
,
have_gil
=
not
lenv
.
nogil
)
for
entry
in
lenv
.
var_entries
:
...
...
@@ -1715,7 +1715,10 @@ class FuncDefNode(StatNode, BlockNode):
if
((
acquire_gil
or
len
(
entry
.
cf_assignments
)
>
1
)
and
not
entry
.
in_closure
):
code
.
put_var_decref
(
entry
)
if
entry
.
type
.
is_memoryviewslice
:
elif
(
entry
.
type
.
is_memoryviewslice
and
(
not
is_cdef
or
len
(
entry
.
cf_assignments
)
>
1
)):
# decref slices of def functions and acquired slices from cdef
# functions, but not borrowed slices from cdef functions.
code
.
put_xdecref_memoryviewslice
(
entry
.
cname
,
have_gil
=
not
lenv
.
nogil
)
if
self
.
needs_closure
:
...
...
tests/run/memslice.pyx
View file @
ac88a9fa
...
...
@@ -1849,3 +1849,34 @@ cdef _test_slice_assignment_broadcast_strides(slice_1d src, slice_2d dst, slice_
for
j
in
range
(
1
,
3
):
assert
dst
[
i
,
j
]
==
dst_f
[
i
,
j
]
==
j
-
1
,
(
dst
[
i
,
j
],
dst_f
[
i
,
j
],
j
-
1
)
@
testcase
def
test_borrowed_slice
():
"""
Test the difference between borrowed an non-borrowed slices. If you delete or assign
to a slice in a cdef function, it is not borrowed.
>>> test_borrowed_slice()
5
5
5
"""
cdef
int
i
,
carray
[
10
]
for
i
in
range
(
10
):
carray
[
i
]
=
i
_borrowed
(
carray
)
_not_borrowed
(
carray
)
_not_borrowed2
(
carray
)
cdef
_borrowed
(
int
[:]
m
):
print
m
[
5
]
cdef
_not_borrowed
(
int
[:]
m
):
print
m
[
5
]
if
object
():
del
m
cdef
_not_borrowed2
(
int
[:]
m
):
cdef
int
[
10
]
carray
print
m
[
5
]
if
object
():
m
=
carray
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