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
cd9b22bf
Commit
cd9b22bf
authored
Sep 29, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Join '*' and '**' parsing in declarators to avoid differences for 'const' parsing etc.
parent
d941d208
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
31 deletions
+37
-31
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+16
-23
tests/compile/const_decl.pyx
tests/compile/const_decl.pyx
+10
-5
tests/errors/const_decl_errors.pyx
tests/errors/const_decl_errors.pyx
+11
-3
No files found.
Cython/Compiler/Parsing.py
View file @
cd9b22bf
...
@@ -2858,31 +2858,24 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
...
@@ -2858,31 +2858,24 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
assignable
,
nonempty
):
assignable
,
nonempty
):
pos
=
s
.
position
()
pos
=
s
.
position
()
calling_convention
=
p_calling_convention
(
s
)
calling_convention
=
p_calling_convention
(
s
)
if
s
.
sy
==
'*'
:
if
s
.
sy
in
(
'*'
,
'**'
):
# scanner returns '**' as a single token
is_ptrptr
=
s
.
sy
==
'**'
s
.
next
()
s
.
next
()
if
s
.
systring
==
'const'
:
const_pos
=
s
.
position
()
const_pos
=
s
.
position
()
is_const
=
s
.
systring
==
'const'
and
s
.
sy
==
'IDENT'
if
is_const
:
s
.
next
()
s
.
next
()
const_base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
cmethod_flag
=
cmethod_flag
,
cmethod_flag
=
cmethod_flag
,
assignable
=
assignable
,
assignable
=
assignable
,
nonempty
=
nonempty
)
nonempty
=
nonempty
)
if
is_const
:
base
=
Nodes
.
CConstDeclaratorNode
(
const_pos
,
base
=
const_base
)
base
=
Nodes
.
CConstDeclaratorNode
(
const_pos
,
base
=
base
)
else
:
if
is_ptrptr
:
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
base
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
base
)
cmethod_flag
=
cmethod_flag
,
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
base
)
assignable
=
assignable
,
nonempty
=
nonempty
)
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
base
)
elif
s
.
sy
==
'**'
:
# scanner returns this as a single token
s
.
next
()
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
cmethod_flag
=
cmethod_flag
,
assignable
=
assignable
,
nonempty
=
nonempty
)
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
base
))
elif
s
.
sy
==
'&'
:
elif
s
.
sy
==
'&'
:
s
.
next
()
s
.
next
()
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
...
...
tests/compile/const_decl.pyx
View file @
cd9b22bf
# mode: compile
# mode: compile
cdef
const_args
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
,
int
*
const
d
):
cdef
const_args
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
,
int
*
const
d
,
int
**
const
e
,
int
*
const
*
f
):
print
a
print
a
print
b
[
0
]
print
b
[
0
]
b
=
NULL
# OK, the pointer itself is not const
b
=
NULL
# OK, the pointer itself is not const
c
[
0
]
=
4
# OK, the value is not const
c
[
0
]
=
4
# OK, the value is not const
d
[
0
]
=
7
# OK, the value is not const
d
[
0
]
=
7
# OK, the value is not const
e
[
0
][
0
]
=
1
# OK, the value is not const
e
[
0
]
=
NULL
# OK, the pointed pointer is not const
f
[
0
][
0
]
=
1
# OK, the value is not const
f
=
NULL
# OK, the pointer is not const
def
call_const_args
(
x
):
def
call_const_args
(
x
):
cdef
int
k
=
x
cdef
int
k
=
x
const_args
(
x
,
&
k
,
&
k
,
&
k
)
cdef
int
*
arr
=
[
x
]
const_args
(
x
,
&
k
,
&
k
,
&
k
,
&
arr
,
&
arr
)
tests/errors/const_decl_errors.pyx
View file @
cd9b22bf
...
@@ -10,13 +10,19 @@ cdef const int x = 10
...
@@ -10,13 +10,19 @@ cdef const int x = 10
cdef
struct
S
:
cdef
struct
S
:
int
member
int
member
cdef
func
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
,
const
S
s
,
int
*
const
d
,
cdef
func
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
,
const
S
s
,
int
*
const
d
,
int
**
const
e
,
int
*
const
*
f
,
const
S
*
const
t
):
const
S
*
const
t
):
a
=
10
a
=
10
c
=
NULL
c
=
NULL
b
[
0
]
=
100
b
[
0
]
=
100
s
.
member
=
1000
s
.
member
=
1000
d
=
NULL
d
=
NULL
e
[
0
][
0
]
=
1
# ok
e
[
0
]
=
NULL
# ok
e
=
NULL
# nok
f
[
0
][
0
]
=
1
# ok
f
[
0
]
=
NULL
# nok
f
=
NULL
# ok
t
=
&
s
t
=
&
s
cdef
volatile
object
v
cdef
volatile
object
v
...
@@ -30,6 +36,8 @@ _ERRORS = """
...
@@ -30,6 +36,8 @@ _ERRORS = """
17:5: Assignment to const dereference
17:5: Assignment to const dereference
18:5: Assignment to const attribute 'member'
18:5: Assignment to const attribute 'member'
19:4: Assignment to const 'd'
19:4: Assignment to const 'd'
20:4: Assignment to const 't'
22:4: Assignment to const 'e'
22:5: Const/volatile base type cannot be a Python object
24:5: Assignment to const dereference
26:4: Assignment to const 't'
28:5: Const/volatile base type cannot be a Python object
"""
"""
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