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
84ce8038
Commit
84ce8038
authored
Sep 18, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Const tests.
parent
d1a536dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
0 deletions
+114
-0
tests/compile/const_decl.pyx
tests/compile/const_decl.pyx
+7
-0
tests/errors/const_decl_errors.pyx
tests/errors/const_decl_errors.pyx
+21
-0
tests/run/cpp_const_method.pyx
tests/run/cpp_const_method.pyx
+86
-0
No files found.
tests/compile/const_decl.pyx
0 → 100644
View file @
84ce8038
# mode: compile
cdef
const_args
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
):
print
a
print
b
[
0
]
b
=
NULL
# OK, the pointer itself is not const
c
[
0
]
=
4
# OK, the value is not const
tests/errors/const_decl_errors.pyx
0 → 100644
View file @
84ce8038
# mode: error
cdef
const
object
o
# TODO: This requires making the assignment at declaration time.
# (We could fake this case by dropping the const here in the C code,
# as it's not needed for agreeing with external libraries.
cdef
const
int
x
=
10
cdef
func
(
const
int
a
,
const
int
*
b
,
const
(
int
*
)
c
):
a
=
10
b
[
0
]
=
100
c
=
NULL
_ERRORS
=
"""
3:5: Const base type cannot be a Python object
8:5: Assignment to const 'x'
11:6: Assignment to const 'a'
12:5: Assignment to const dereference
13:6: Assignment to const 'c'
"""
tests/run/cpp_const_method.pyx
0 → 100644
View file @
84ce8038
# cython: experimental_cpp_class_def=True
# tag: cpp
from
libcpp.vector
cimport
vector
cdef
cppclass
Wrapper
[
T
]:
T
value
__init__
(
T
&
value
):
this
.
value
=
value
void
set
(
T
&
value
):
this
.
value
=
value
T
get
()
const
:
return
this
.
value
def
test_const_get
(
int
x
):
"""
>>> test_const_get(10)
10
"""
cdef
const
Wrapper
[
int
]
*
wrapper
=
new
Wrapper
[
int
](
x
)
try
:
return
const_get
(
wrapper
[
0
])
finally
:
del
wrapper
cdef
int
const_get
(
const
Wrapper
[
int
]
wrapper
):
return
wrapper
.
get
()
def
test_const_ref_get
(
int
x
):
"""
>>> test_const_ref_get(100)
100
"""
cdef
const
Wrapper
[
int
]
*
wrapper
=
new
Wrapper
[
int
](
x
)
try
:
return
const_ref_get
(
wrapper
[
0
])
finally
:
del
wrapper
cdef
int
const_ref_get
(
const
Wrapper
[
int
]
&
wrapper
):
return
wrapper
.
get
()
def
test_const_pointer_get
(
int
x
):
"""
>>> test_const_pointer_get(1000)
1000
"""
cdef
Wrapper
[
int
]
*
wrapper
=
new
Wrapper
[
int
](
x
)
cdef
const
Wrapper
[
int
]
*
const_wrapper
=
wrapper
try
:
return
const_wrapper
.
get
()
finally
:
del
wrapper
# TODO: parse vector[Wrapper[int]*]
ctypedef
Wrapper
[
int
]
wrapInt
def
test_vector_members
(
py_a
,
py_b
):
"""
>>> test_vector_members([1, 2, 3], [4,5, 6])
([1, 2, 3], 4)
"""
cdef
Wrapper
[
int
]
*
value
cdef
const
Wrapper
[
int
]
*
const_value
cdef
vector
[
const
Wrapper
[
int
]
*
]
a
cdef
vector
[
wrapInt
*
]
b
for
x
in
py_a
:
a
.
push_back
(
new
Wrapper
[
int
](
x
))
for
x
in
py_b
:
b
.
push_back
(
new
Wrapper
[
int
](
x
))
try
:
return
vector_members
(
a
,
b
)
finally
:
for
const_value
in
a
:
del
const_value
for
value
in
b
:
del
value
cdef
vector_members
(
vector
[
const
Wrapper
[
int
]
*
]
a
,
const
vector
[
wrapInt
*
]
b
):
# TODO: Cython-level error.
# b[0].set(100)
# TODO: const_iterator
return
[
x
.
get
()
for
x
in
a
],
b
[
0
].
get
()
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