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
5748aa14
Commit
5748aa14
authored
Nov 27, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix refcount bug with buffers of objects
May have been introduced by the result_code refactor.
parent
751d5612
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-6
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+27
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
5748aa14
...
...
@@ -1719,17 +1719,12 @@ class IndexNode(ExprNode):
# Must manage refcounts. Decref what is already there
# and incref what we put in.
ptr
=
code
.
funcstate
.
allocate_temp
(
self
.
buffer_type
.
buffer_ptr_type
,
manage_ref
=
False
)
if
rhs
.
is_temp
:
rhs_code
=
code
.
funcstate
.
allocate_temp
(
rhs
.
type
,
manage_ref
=
False
)
else
:
rhs_code
=
rhs
.
result
()
rhs_code
=
rhs
.
result
()
code
.
putln
(
"%s = %s;"
%
(
ptr
,
ptrexpr
))
code
.
putln
(
"Py_DECREF(*%s); Py_INCREF(%s);"
%
(
ptr
,
rhs_code
))
code
.
putln
(
"*%s %s= %s;"
%
(
ptr
,
op
,
rhs_code
))
if
rhs
.
is_temp
:
code
.
funcstate
.
release_temp
(
rhs_code
)
code
.
funcstate
.
release_temp
(
ptr
)
else
:
# Simple case
...
...
tests/run/bufaccess.pyx
View file @
5748aa14
...
...
@@ -972,6 +972,33 @@ def assign_to_object(object[object] buf, int idx, obj):
"""
buf
[
idx
]
=
obj
@
testcase
def
assign_temporary_to_object
(
object
[
object
]
buf
):
"""
See comments on printbuf_object above.
>>> a, b = [1, 2, 3], {4:23}
>>> get_refcount(a)
2
>>> addref(a)
>>> A = ObjectMockBuffer(None, [b, a])
>>> get_refcount(a)
3
>>> assign_temporary_to_object(A)
>>> get_refcount(a)
2
>>> printbuf_object(A, (2,))
{4: 23} 2
{1: 8} 2
To avoid leaking a reference in our testcase we need to
replace the temporary with something we can manually decref :-)
>>> assign_to_object(A, 1, a)
>>> decref(a)
"""
buf
[
1
]
=
{
3
-
2
:
2
+
(
2
*
4
)
-
2
}
#
# cast option
#
...
...
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