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
622d6734
Commit
622d6734
authored
May 23, 2013
by
Vitja Makarov
Committed by
Stefan Behnel
Jul 14, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix external reference assignment
parent
47bbbff7
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 @
622d6734
...
...
@@ -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 @
622d6734
...
...
@@ -1883,7 +1883,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 ###
...
...
@@ -1898,18 +1898,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 @
622d6734
...
...
@@ -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 @
622d6734
# 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