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
0b414387
Commit
0b414387
authored
May 23, 2013
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix external reference assignment
parent
d0627fcb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
5 deletions
+54
-5
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+6
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+13
-5
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+9
-0
tests/run/external_ref_reassignment.pyx
tests/run/external_ref_reassignment.pyx
+26
-0
No files found.
Cython/Compiler/Code.py
View file @
0b414387
...
...
@@ -1738,6 +1738,12 @@ class CCodeWriter(object):
self
.
putln
(
"%s_%sDECREF(%s);"
%
(
prefix
,
X
,
self
.
as_pyobject
(
cname
,
type
)))
def
put_decref_set
(
self
,
cname
,
rhs_cname
):
self
.
putln
(
"__Pyx_DECREF_SET(%s, %s);"
%
(
cname
,
rhs_cname
))
def
put_xdecref_set
(
self
,
cname
,
rhs_cname
):
self
.
putln
(
"__Pyx_XDECREF_SET(%s, %s);"
%
(
cname
,
rhs_cname
))
def
put_var_decref
(
self
,
entry
):
if
entry
.
type
.
is_pyobject
:
self
.
putln
(
"__Pyx_XDECREF(%s);"
%
self
.
entry_as_pyobject
(
entry
))
...
...
Cython/Compiler/ExprNodes.py
View file @
0b414387
...
...
@@ -1895,7 +1895,7 @@ class NameNode(AtomicExprNode):
# variables that the acquired buffer info is stored to is allocated
# per entry and coupled with it.
self
.
generate_acquire_buffer
(
rhs
,
code
)
assigned
=
False
if
self
.
type
.
is_pyobject
:
#print "NameNode.generate_assignment_code: to", self.name ###
#print "...from", rhs ###
...
...
@@ -1910,18 +1910,26 @@ class NameNode(AtomicExprNode):
code
.
put_xgotref
(
self
.
py_result
())
else
:
code
.
put_gotref
(
self
.
py_result
())
assigned
=
True
if
entry
.
is_cglobal
:
code
.
put_decref
(
self
.
result
(),
self
.
ctype
())
code
.
put_decref_set
(
self
.
result
(),
rhs
.
result_as
(
self
.
ctype
()))
else
:
if
not
self
.
cf_is_null
:
if
self
.
cf_maybe_null
:
code
.
put_xdecref
(
self
.
result
(),
self
.
ctype
())
code
.
put_xdecref_set
(
self
.
result
(),
rhs
.
result_as
(
self
.
ctype
()))
else
:
code
.
put_decref
(
self
.
result
(),
self
.
ctype
())
code
.
put_decref_set
(
self
.
result
(),
rhs
.
result_as
(
self
.
ctype
()))
else
:
assigned
=
False
if
is_external_ref
:
code
.
put_giveref
(
rhs
.
py_result
())
if
not
self
.
type
.
is_memoryviewslice
:
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
rhs
.
result_as
(
self
.
ctype
())))
if
not
assigned
:
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
rhs
.
result_as
(
self
.
ctype
())))
if
debug_disposal_code
:
print
(
"NameNode.generate_assignment_code:"
)
print
(
"...generating post-assignment code for %s"
%
rhs
)
...
...
Cython/Utility/ModuleSetupCode.c
View file @
0b414387
...
...
@@ -531,6 +531,15 @@ static int __Pyx_check_binary_version(void) {
#define __Pyx_XGIVEREF(r)
#endif
/* CYTHON_REFNANNY */
#define __Pyx_XDECREF_SET(r, v) do { \
PyObject *tmp = (PyObject *) r; \
r = v; __Pyx_XDECREF(tmp); \
} while (0)
#define __Pyx_DECREF_SET(r, v) do { \
PyObject *tmp = (PyObject *) r; \
r = v; __Pyx_DECREF(tmp); \
} while (0)
#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
...
...
tests/run/external_ref_reassignment.pyx
0 → 100644
View file @
0b414387
# Test that variable visible outside of the local scope (e.g. closure, cglobals)
# is set before original value is decrefed.
cdef
object
g
def
test_cglobals_reassignment
():
"""
>>> test_cglobals_reassignment()
1234
"""
global
g
class
Special
:
def
__del__
(
self
):
print
g
g
=
(
Special
(),)
g
=
1234
def
test_closure_reassignment
():
"""
>>> test_closure_reassignment()
4321
"""
class
Special
:
def
__del__
(
self
):
print
c
c
=
(
Special
(),)
c
=
4321
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