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
1946f805
Commit
1946f805
authored
Oct 28, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drop ref-counting on C attribute swaps
parent
3cf560bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
7 deletions
+46
-7
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+12
-6
tests/run/parallel_swap_assign_T425.pyx
tests/run/parallel_swap_assign_T425.pyx
+33
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
1946f805
...
@@ -3098,7 +3098,7 @@ class AttributeNode(ExprNode):
...
@@ -3098,7 +3098,7 @@ class AttributeNode(ExprNode):
self
.
put_nonecheck
(
code
)
self
.
put_nonecheck
(
code
)
select_code
=
self
.
result
()
select_code
=
self
.
result
()
if
self
.
type
.
is_pyobject
:
if
self
.
type
.
is_pyobject
and
self
.
use_managed_ref
:
rhs
.
make_owned_reference
(
code
)
rhs
.
make_owned_reference
(
code
)
code
.
put_giveref
(
rhs
.
py_result
())
code
.
put_giveref
(
rhs
.
py_result
())
code
.
put_gotref
(
select_code
)
code
.
put_gotref
(
select_code
)
...
...
Cython/Compiler/Optimize.py
View file @
1946f805
...
@@ -634,8 +634,8 @@ class DropRefcountingTransform(Visitor.VisitorTransform):
...
@@ -634,8 +634,8 @@ class DropRefcountingTransform(Visitor.VisitorTransform):
if
left_names
or
right_names
:
if
left_names
or
right_names
:
# lhs/rhs names must be a non-redundant permutation
# lhs/rhs names must be a non-redundant permutation
lnames
=
[
n
.
name
for
n
in
left_names
]
lnames
=
[
path
for
path
,
n
in
left_names
]
rnames
=
[
n
.
name
for
n
in
right_names
]
rnames
=
[
path
for
path
,
n
in
right_names
]
if
set
(
lnames
)
!=
set
(
rnames
):
if
set
(
lnames
)
!=
set
(
rnames
):
return
node
return
node
if
len
(
set
(
lnames
))
!=
len
(
right_names
):
if
len
(
set
(
lnames
))
!=
len
(
right_names
):
...
@@ -670,7 +670,7 @@ class DropRefcountingTransform(Visitor.VisitorTransform):
...
@@ -670,7 +670,7 @@ class DropRefcountingTransform(Visitor.VisitorTransform):
for
temp
in
temps
:
for
temp
in
temps
:
temp
.
use_managed_ref
=
False
temp
.
use_managed_ref
=
False
for
name_node
in
left_names
+
right_names
:
for
_
,
name_node
in
left_names
+
right_names
:
if
name_node
not
in
temp_args
:
if
name_node
not
in
temp_args
:
name_node
.
use_managed_ref
=
False
name_node
.
use_managed_ref
=
False
...
@@ -686,10 +686,16 @@ class DropRefcountingTransform(Visitor.VisitorTransform):
...
@@ -686,10 +686,16 @@ class DropRefcountingTransform(Visitor.VisitorTransform):
if
isinstance
(
node
,
ExprNodes
.
CoerceToTempNode
):
if
isinstance
(
node
,
ExprNodes
.
CoerceToTempNode
):
temps
.
append
(
node
)
temps
.
append
(
node
)
node
=
node
.
arg
node
=
node
.
arg
if
isinstance
(
node
,
ExprNodes
.
NameNode
):
name_path
=
[]
if
node
.
entry
.
is_builtin
or
node
.
entry
.
is_pyglobal
:
obj_node
=
node
while
isinstance
(
obj_node
,
ExprNodes
.
AttributeNode
):
if
obj_node
.
is_py_attr
:
return
False
return
False
names
.
append
(
node
)
name_path
.
append
(
obj_node
.
member
)
obj_node
=
obj_node
.
obj
if
isinstance
(
obj_node
,
ExprNodes
.
NameNode
):
name_path
.
append
(
obj_node
.
name
)
names
.
append
(
(
'.'
.
join
(
name_path
[::
-
1
]),
node
)
)
elif
isinstance
(
node
,
ExprNodes
.
IndexNode
):
elif
isinstance
(
node
,
ExprNodes
.
IndexNode
):
if
node
.
base
.
type
!=
Builtin
.
list_type
:
if
node
.
base
.
type
!=
Builtin
.
list_type
:
return
False
return
False
...
...
tests/run/parallel_swap_assign_T425.pyx
View file @
1946f805
...
@@ -68,10 +68,43 @@ def swap_cmp5(a,b,c,d,e):
...
@@ -68,10 +68,43 @@ def swap_cmp5(a,b,c,d,e):
"//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode[@use_managed_ref=False]"
,
"//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode[@use_managed_ref=False]"
,
)
)
def
swap_py
(
a
,
b
):
def
swap_py
(
a
,
b
):
"""
>>> swap_py(1,2)
(1, 2)
"""
a
,
a
=
b
,
a
a
,
a
=
b
,
a
return
a
,
b
return
a
,
b
cdef
class
A
:
cdef
readonly
object
x
cdef
readonly
object
y
def
__init__
(
self
,
x
,
y
):
self
.
x
,
self
.
y
=
x
,
y
@
cython
.
test_assert_path_exists
(
"//ParallelAssignmentNode"
,
"//ParallelAssignmentNode/SingleAssignmentNode"
,
"//ParallelAssignmentNode/SingleAssignmentNode//AttributeNode/NameNode"
,
"//ParallelAssignmentNode/SingleAssignmentNode//AttributeNode[@use_managed_ref=False]/NameNode"
,
)
@
cython
.
test_fail_if_path_exists
(
# "//ParallelAssignmentNode/SingleAssignmentNode//AttributeNode[@use_managed_ref=True]",
)
def
swap_attr_values
(
A
a
,
A
b
):
"""
>>> a, b = A(1,2), A(3,4)
>>> a.x, a.y, b.x, b.y
(1, 2, 3, 4)
>>> swap_attr_values(a,b)
>>> a.x, a.y, b.x, b.y
(3, 2, 1, 4)
"""
a
.
x
,
a
.
y
,
b
.
x
,
b
.
y
=
a
.
y
,
b
.
x
,
b
.
y
,
a
.
x
# shift by one
a
.
x
,
a
.
y
,
b
.
x
,
b
.
y
=
b
.
x
,
b
.
y
,
a
.
x
,
a
.
y
# shift by two
a
.
x
,
a
.
y
,
b
.
x
,
b
.
y
=
b
.
y
,
b
.
x
,
a
.
y
,
a
.
x
# reverse
@
cython
.
test_assert_path_exists
(
@
cython
.
test_assert_path_exists
(
# "//ParallelAssignmentNode",
# "//ParallelAssignmentNode",
# "//ParallelAssignmentNode/SingleAssignmentNode",
# "//ParallelAssignmentNode/SingleAssignmentNode",
...
...
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