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
Boxiang Sun
cython
Commits
37ceab84
Commit
37ceab84
authored
Apr 02, 2013
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #203 from vmx/const-pointer
Add support for const pointers
parents
7538ecd2
5e149737
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
10 deletions
+39
-10
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+13
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+13
-3
tests/compile/const_decl.pyx
tests/compile/const_decl.pyx
+3
-2
tests/errors/const_decl_errors.pyx
tests/errors/const_decl_errors.pyx
+10
-5
No files found.
Cython/Compiler/Nodes.py
View file @
37ceab84
...
@@ -713,6 +713,19 @@ class CFuncDeclaratorNode(CDeclaratorNode):
...
@@ -713,6 +713,19 @@ class CFuncDeclaratorNode(CDeclaratorNode):
func_type
.
op_arg_struct
=
PyrexTypes
.
c_ptr_type
(
op_args_struct
.
type
)
func_type
.
op_arg_struct
=
PyrexTypes
.
c_ptr_type
(
op_args_struct
.
type
)
class
CConstDeclaratorNode
(
CDeclaratorNode
):
# base CDeclaratorNode
child_attrs
=
[
"base"
]
def
analyse
(
self
,
base_type
,
env
,
nonempty
=
0
):
if
base_type
.
is_pyobject
:
error
(
self
.
pos
,
"Const base type cannot be a Python object"
)
const
=
PyrexTypes
.
c_const_type
(
base_type
)
return
self
.
base
.
analyse
(
const
,
env
,
nonempty
=
nonempty
)
class
CArgDeclNode
(
Node
):
class
CArgDeclNode
(
Node
):
# Item in a function declaration argument list.
# Item in a function declaration argument list.
#
#
...
...
Cython/Compiler/Parsing.py
View file @
37ceab84
...
@@ -2366,9 +2366,19 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
...
@@ -2366,9 +2366,19 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
calling_convention
=
p_calling_convention
(
s
)
calling_convention
=
p_calling_convention
(
s
)
if
s
.
sy
==
'*'
:
if
s
.
sy
==
'*'
:
s
.
next
()
s
.
next
()
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
if
s
.
systring
==
'const'
:
cmethod_flag
=
cmethod_flag
,
const_pos
=
s
.
position
()
assignable
=
assignable
,
nonempty
=
nonempty
)
s
.
next
()
const_base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
cmethod_flag
=
cmethod_flag
,
assignable
=
assignable
,
nonempty
=
nonempty
)
base
=
Nodes
.
CConstDeclaratorNode
(
const_pos
,
base
=
const_base
)
else
:
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
cmethod_flag
=
cmethod_flag
,
assignable
=
assignable
,
nonempty
=
nonempty
)
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
base
)
base
=
base
)
elif
s
.
sy
==
'**'
:
# scanner returns this as a single token
elif
s
.
sy
==
'**'
:
# scanner returns this as a single token
...
...
tests/compile/const_decl.pyx
View file @
37ceab84
# mode: compile
# mode: compile
cdef
const_args
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
):
cdef
const_args
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
,
int
*
const
d
):
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
def
call_const_args
(
x
):
def
call_const_args
(
x
):
cdef
int
k
=
x
cdef
int
k
=
x
const_args
(
x
,
&
k
,
&
k
)
const_args
(
x
,
&
k
,
&
k
,
&
k
)
tests/errors/const_decl_errors.pyx
View file @
37ceab84
...
@@ -10,17 +10,22 @@ cdef const int x = 10
...
@@ -10,17 +10,22 @@ 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
):
cdef
func
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
,
const
S
s
,
int
*
const
d
,
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
t
=
&
s
_ERRORS
=
"""
_ERRORS
=
"""
3:5: Const base type cannot be a Python object
3:5: Const base type cannot be a Python object
8:5: Assignment to const 'x'
8:5: Assignment to const 'x'
14:6: Assignment to const 'a'
15:6: Assignment to const 'a'
15:6: Assignment to const 'c'
16:6: Assignment to const 'c'
16:5: Assignment to const dereference
17:5: Assignment to const dereference
17:5: Assignment to const attribute 'member'
18:5: Assignment to const attribute 'member'
19:6: Assignment to const 'd'
20:6: Assignment to const 't'
"""
"""
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