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
759e8ee0
Commit
759e8ee0
authored
Jan 03, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for some evil cdef attribute assignments and fix them
parent
c961e9dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
10 deletions
+114
-10
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+8
-10
tests/run/ext_attr_assign.pyx
tests/run/ext_attr_assign.pyx
+106
-0
No files found.
Cython/Compiler/Nodes.py
View file @
759e8ee0
...
@@ -4640,8 +4640,8 @@ class SingleAssignmentNode(AssignmentNode):
...
@@ -4640,8 +4640,8 @@ class SingleAssignmentNode(AssignmentNode):
dtype
=
self
.
lhs
.
type
dtype
=
self
.
lhs
.
type
self
.
rhs
=
self
.
rhs
.
coerce_to
(
dtype
,
env
)
self
.
rhs
=
self
.
rhs
.
coerce_to
(
dtype
,
env
)
if
use_temp
or
(
self
.
rhs
.
is_attribute
and
not
self
.
lhs
.
is_name
)
:
if
use_temp
or
not
self
.
rhs
.
is_name
:
#
(cdef) attribute access is not safe as it traverses pointers
#
things like (cdef) attribute access are not safe (traverses pointers)
self
.
rhs
=
self
.
rhs
.
coerce_to_temp
(
env
)
self
.
rhs
=
self
.
rhs
.
coerce_to_temp
(
env
)
elif
self
.
rhs
.
type
.
is_pyobject
:
elif
self
.
rhs
.
type
.
is_pyobject
:
self
.
rhs
=
self
.
rhs
.
coerce_to_simple
(
env
)
self
.
rhs
=
self
.
rhs
.
coerce_to_simple
(
env
)
...
@@ -4683,15 +4683,13 @@ class CascadedAssignmentNode(AssignmentNode):
...
@@ -4683,15 +4683,13 @@ class CascadedAssignmentNode(AssignmentNode):
def
analyse_types
(
self
,
env
,
use_temp
=
0
):
def
analyse_types
(
self
,
env
,
use_temp
=
0
):
from
ExprNodes
import
CloneNode
,
ProxyNode
from
ExprNodes
import
CloneNode
,
ProxyNode
self
.
rhs
=
self
.
rhs
.
analyse_types
(
env
)
rhs
=
self
.
rhs
.
analyse_types
(
env
)
# (cdef) attribute access is not safe as it traverses pointers
if
rhs
.
is_name
:
if
self
.
rhs
.
is_attribute
or
not
self
.
rhs
.
is_simple
():
rhs
=
rhs
.
coerce_to_simple
(
env
)
if
use_temp
:
else
:
self
.
rhs
=
self
.
rhs
.
coerce_to_temp
(
env
)
rhs
=
rhs
.
coerce_to_temp
(
env
)
else
:
self
.
rhs
=
ProxyNode
(
rhs
)
self
.
rhs
=
self
.
rhs
.
coerce_to_simple
(
env
)
self
.
rhs
=
ProxyNode
(
self
.
rhs
)
self
.
coerced_rhs_list
=
[]
self
.
coerced_rhs_list
=
[]
for
lhs
in
self
.
lhs_list
:
for
lhs
in
self
.
lhs_list
:
lhs
.
analyse_target_types
(
env
)
lhs
.
analyse_target_types
(
env
)
...
...
tests/run/ext_attr_assign.pyx
0 → 100644
View file @
759e8ee0
# mode: run
# tag: assign, exttype
cdef
struct
X
:
int
ix
X
*
x
cdef
class
A
:
cdef
int
i
cdef
list
l
cdef
object
o
cdef
X
x
def
assign_A
(
self
):
"""
>>> A().assign_A()
(2, [1, 2, 3])
"""
a
=
A
()
a
.
i
=
1
a
.
l
=
[
1
,
2
,
3
]
a
.
o
=
a
.
l
a
.
o
=
a
.
o
a
.
l
=
a
.
o
a
.
i
=
a
.
l
[
1
]
return
a
.
i
,
a
.
l
def
assign_A_struct
(
self
):
"""
>>> A().assign_A_struct()
(5, 2, 2, 5)
"""
cdef
X
x
a
=
A
()
a
.
x
.
ix
=
2
a
.
x
.
x
=
&
x
x
.
ix
=
5
x
.
x
=
&
a
.
x
assert
a
.
x
.
x
.
x
is
&
a
.
x
a
.
x
.
x
.
x
.
x
.
x
.
x
.
x
=
a
.
x
.
x
.
x
.
x
assert
x
.
x
is
&
x
assert
x
.
x
.
x
is
&
x
assert
a
.
x
.
x
is
&
x
a
.
x
.
x
.
x
.
x
.
x
.
x
.
x
,
a
.
x
.
x
.
x
=
a
.
x
.
x
.
x
.
x
,
&
a
.
x
# replay+undo :)
assert
x
.
x
is
&
a
.
x
assert
x
.
x
.
x
is
&
x
return
x
.
ix
,
x
.
x
.
ix
,
a
.
x
.
ix
,
a
.
x
.
x
.
ix
cdef
class
B
(
A
):
cdef
int
ib
cdef
object
ob
cdef
A
a
def
assign_B
(
self
):
"""
>>> B().assign_B()
(1, 2, 5, 9, 2)
"""
b
=
B
()
b
.
i
=
1
b
.
ib
=
2
b
.
l
=
[
b
.
i
,
b
.
ib
]
b
.
o
=
b
.
l
b
.
ob
=
b
.
o
assert
b
.
ob
==
b
.
l
b
.
o
=
b
.
ob
=
b
.
l
b
.
a
=
A
()
# only one reference!
b
.
a
.
o
=
5
b
.
a
.
i
=
5
b
.
a
,
b
.
a
.
i
=
A
(),
b
.
a
.
i
# overwrite b.a but keep b.a.i
assert
b
.
a
.
i
==
5
assert
b
.
a
.
o
is
None
b
.
a
.
o
=
9
b
.
a
,
b
.
a
.
i
,
b
.
a
.
o
=
A
(),
b
.
a
.
i
,
b
.
a
.
o
return
b
.
i
,
b
.
ib
,
b
.
a
.
i
,
b
.
a
.
o
,
b
.
o
[
1
]
def
cross_assign_Ba
(
self
):
"""
>>> B().cross_assign_Ba()
2
"""
b
=
B
()
b
.
a
=
A
()
b
.
a
.
i
=
1
b
.
a
.
o
=
A
()
# only one reference!
(
<
A
>
b
.
a
.
o
).
i
=
2
b
.
a
=
b
.
a
.
o
return
b
.
a
.
i
def
cascaded_assign_B
(
self
):
"""
>>> B().cascaded_assign_B()
(2, 2)
"""
cdef
B
b
=
B
()
b
.
ib
=
1
b
.
a
=
A
()
b
.
a
.
o
=
B
()
# only one reference!
(
<
B
>
b
.
a
.
o
).
ib
=
2
b
=
b
.
ob
=
b
.
a
.
o
return
b
.
ib
,
(
<
B
>
b
.
ob
).
ib
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