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
3c635dec
Commit
3c635dec
authored
Oct 19, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disallow names as keys in struct dict literals
parent
d4dd8baa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
13 deletions
+11
-13
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+7
-9
tests/run/struct_conversion.pyx
tests/run/struct_conversion.pyx
+4
-4
No files found.
Cython/Compiler/ExprNodes.py
View file @
3c635dec
...
@@ -1880,7 +1880,7 @@ class CallNode(ExprNode):
...
@@ -1880,7 +1880,7 @@ class CallNode(ExprNode):
args
,
kwds
=
self
.
explicit_args_kwds
()
args
,
kwds
=
self
.
explicit_args_kwds
()
items
=
[]
items
=
[]
for
arg
,
member
in
zip
(
args
,
type
.
scope
.
var_entries
):
for
arg
,
member
in
zip
(
args
,
type
.
scope
.
var_entries
):
items
.
append
(
DictItemNode
(
pos
=
arg
.
pos
,
key
=
NameNode
(
pos
=
arg
.
pos
,
nam
e
=
member
.
name
),
value
=
arg
))
items
.
append
(
DictItemNode
(
pos
=
arg
.
pos
,
key
=
IdentifierStringNode
(
pos
=
arg
.
pos
,
valu
e
=
member
.
name
),
value
=
arg
))
if
kwds
:
if
kwds
:
items
+=
kwds
.
key_value_pairs
items
+=
kwds
.
key_value_pairs
self
.
key_value_pairs
=
items
self
.
key_value_pairs
=
items
...
@@ -2947,15 +2947,13 @@ class DictNode(ExprNode):
...
@@ -2947,15 +2947,13 @@ class DictNode(ExprNode):
for
item
in
self
.
key_value_pairs
:
for
item
in
self
.
key_value_pairs
:
if
isinstance
(
item
.
key
,
CoerceToPyTypeNode
):
if
isinstance
(
item
.
key
,
CoerceToPyTypeNode
):
item
.
key
=
item
.
key
.
arg
item
.
key
=
item
.
key
.
arg
if
isinstance
(
item
.
key
,
(
StringNode
,
IdentifierStringNode
)):
if
not
isinstance
(
item
.
key
,
(
StringNode
,
IdentifierStringNode
)):
item
.
key
=
NameNode
(
pos
=
item
.
key
.
pos
,
name
=
item
.
key
.
value
)
error
(
item
.
key
.
pos
,
"Invalid struct field identifier"
)
if
not
isinstance
(
item
.
key
,
NameNode
):
item
.
key
=
IdentifierStringNode
(
item
.
key
.
pos
,
value
=
"<error>"
)
print
item
.
key
error
(
item
.
key
.
pos
,
"Struct field must be a name"
)
else
:
else
:
member
=
dst_type
.
scope
.
lookup_here
(
item
.
key
.
nam
e
)
member
=
dst_type
.
scope
.
lookup_here
(
item
.
key
.
valu
e
)
if
not
member
:
if
not
member
:
error
(
item
.
key
.
pos
,
"struct '%s' has no field '%s'"
%
(
dst_type
,
item
.
key
.
nam
e
))
error
(
item
.
key
.
pos
,
"struct '%s' has no field '%s'"
%
(
dst_type
,
item
.
key
.
valu
e
))
else
:
else
:
value
=
item
.
value
value
=
item
.
value
if
isinstance
(
value
,
CoerceToPyTypeNode
):
if
isinstance
(
value
,
CoerceToPyTypeNode
):
...
@@ -3003,7 +3001,7 @@ class DictNode(ExprNode):
...
@@ -3003,7 +3001,7 @@ class DictNode(ExprNode):
else
:
else
:
code
.
putln
(
"%s.%s = %s;"
%
(
code
.
putln
(
"%s.%s = %s;"
%
(
self
.
result
(),
self
.
result
(),
item
.
key
.
nam
e
,
item
.
key
.
valu
e
,
item
.
value
.
result
()))
item
.
value
.
result
()))
item
.
generate_disposal_code
(
code
)
item
.
generate_disposal_code
(
code
)
...
...
tests/run/struct_conversion.pyx
View file @
3c635dec
...
@@ -40,7 +40,7 @@ def test_constructor_kwds(x, y, color):
...
@@ -40,7 +40,7 @@ def test_constructor_kwds(x, y, color):
return
p
return
p
def
test_dict_construction
(
x
,
y
,
color
):
def
test_dict_construction
(
x
,
y
,
color
):
cdef
Point
p
=
{
color
:
color
,
x
:
x
,
y
:
y
}
cdef
Point
p
=
{
'color'
:
color
,
'x'
:
x
,
'y'
:
y
}
return
p
return
p
cdef
union
int_or_float
:
cdef
union
int_or_float
:
...
@@ -53,8 +53,8 @@ cdef struct with_pointers:
...
@@ -53,8 +53,8 @@ cdef struct with_pointers:
void
*
ptr
void
*
ptr
def
test_pointers
(
int
n
,
double
x
):
def
test_pointers
(
int
n
,
double
x
):
cdef
with_pointers
a
=
[
True
,
{
n
:
n
},
NULL
]
cdef
with_pointers
a
=
[
True
,
{
'n'
:
n
},
NULL
]
cdef
with_pointers
b
=
with_pointers
(
False
,
{
x
:
x
},
NULL
)
cdef
with_pointers
b
=
with_pointers
(
False
,
{
'x'
:
x
},
NULL
)
print
a
.
data
.
n
print
a
.
data
.
n
print
b
.
data
.
x
print
b
.
data
.
x
print
a
.
ptr
==
b
.
ptr
==
NULL
print
a
.
ptr
==
b
.
ptr
==
NULL
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