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
e4792365
Commit
e4792365
authored
Jul 19, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test case for function default values (worked straight away)
parent
11f1bc8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
21 deletions
+35
-21
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+35
-21
No files found.
tests/run/bufaccess.pyx
View file @
e4792365
...
...
@@ -22,7 +22,15 @@ __doc__ = u"""
acquired A
released A
>>> print_buffer_as_argument(MockBuffer("i", range(6)), 6)
>>> as_argument(MockBuffer("i", range(6)), 6)
acquired
0 1 2 3 4 5
released
>>> as_argument_defval()
acquired
0 1 2 3 4 5
released
>>> as_argument_defval(MockBuffer("i", range(6)), 6)
acquired
0 1 2 3 4 5
released
...
...
@@ -38,6 +46,23 @@ __doc__ = u"""
released
"""
ctypedef
char
*
(
*
write_func_ptr
)(
char
*
,
object
)
cdef
char
*
write_float
(
char
*
buf
,
object
value
):
(
<
float
*>
buf
)[
0
]
=
<
float
>
value
return
buf
+
sizeof
(
float
)
cdef
char
*
write_int
(
char
*
buf
,
object
value
):
(
<
int
*>
buf
)[
0
]
=
<
int
>
value
return
buf
+
sizeof
(
int
)
# long can hold a pointer on all target platforms,
# though really we should have a seperate typedef for this..
# TODO: Should create subclasses of MockBuffer instead.
typemap
=
{
'f'
:
(
sizeof
(
float
),
<
unsigned
long
>&
write_float
),
'i'
:
(
sizeof
(
int
),
<
unsigned
long
>&
write_int
)
}
cimport
stdlib
def
acquire_release
(
o1
,
o2
):
cdef
object
[
int
]
buf
...
...
@@ -49,12 +74,20 @@ def acquire_raise(o):
buf
=
o
raise
Exception
(
"on purpose"
)
def
print_buffer_
as_argument
(
object
[
int
]
bufarg
,
int
n
):
def
as_argument
(
object
[
int
]
bufarg
,
int
n
):
cdef
int
i
for
i
in
range
(
n
):
print
bufarg
[
i
],
print
def
as_argument_defval
(
object
[
int
]
bufarg
=
MockBuffer
(
'i'
,
range
(
6
)),
int
n
=
6
):
cdef
int
i
for
i
in
range
(
n
):
print
bufarg
[
i
],
print
# default values
#
...
...
@@ -78,25 +111,6 @@ def printbuf_int_2d(o, shape):
print
buf
[
i
,
j
],
print
ctypedef
char
*
(
*
write_func_ptr
)(
char
*
,
object
)
cdef
char
*
write_float
(
char
*
buf
,
object
value
):
(
<
float
*>
buf
)[
0
]
=
<
float
>
value
return
buf
+
sizeof
(
float
)
cdef
char
*
write_int
(
char
*
buf
,
object
value
):
(
<
int
*>
buf
)[
0
]
=
<
int
>
value
return
buf
+
sizeof
(
int
)
# long can hold a pointer on all target platforms,
# though really we should have a seperate typedef for this..
# TODO: Should create subclasses of MockBuffer instead.
typemap
=
{
'f'
:
(
sizeof
(
float
),
<
unsigned
long
>&
write_float
),
'i'
:
(
sizeof
(
int
),
<
unsigned
long
>&
write_int
)
}
cimport
stdlib
cdef
class
MockBuffer
:
cdef
object
format
cdef
char
*
buffer
...
...
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