Commit e4792365 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Test case for function default values (worked straight away)

parent 11f1bc8f
...@@ -22,7 +22,15 @@ __doc__ = u""" ...@@ -22,7 +22,15 @@ __doc__ = u"""
acquired A acquired A
released 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 acquired
0 1 2 3 4 5 0 1 2 3 4 5
released released
...@@ -38,6 +46,23 @@ __doc__ = u""" ...@@ -38,6 +46,23 @@ __doc__ = u"""
released 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): def acquire_release(o1, o2):
cdef object[int] buf cdef object[int] buf
...@@ -49,12 +74,20 @@ def acquire_raise(o): ...@@ -49,12 +74,20 @@ def acquire_raise(o):
buf = o buf = o
raise Exception("on purpose") 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 cdef int i
for i in range(n): for i in range(n):
print bufarg[i], print bufarg[i],
print 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 # default values
# #
...@@ -78,25 +111,6 @@ def printbuf_int_2d(o, shape): ...@@ -78,25 +111,6 @@ def printbuf_int_2d(o, shape):
print buf[i, j], print buf[i, j],
print 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 class MockBuffer:
cdef object format cdef object format
cdef char* buffer cdef char* buffer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment