From e47923658c6c0045702c2a180d93ef7a02d98d89 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Sat, 19 Jul 2008 20:29:27 +0200 Subject: [PATCH] Test case for function default values (worked straight away) --- tests/run/bufaccess.pyx | 56 +++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/tests/run/bufaccess.pyx b/tests/run/bufaccess.pyx index e3139cec..6c7cb544 100644 --- a/tests/run/bufaccess.pyx +++ b/tests/run/bufaccess.pyx @@ -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): + (buf)[0] = value + return buf + sizeof(float) +cdef char* write_int(char* buf, object value): + (buf)[0] = 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), &write_float), + 'i': (sizeof(int), &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): - (buf)[0] = value - return buf + sizeof(float) -cdef char* write_int(char* buf, object value): - (buf)[0] = 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), &write_float), - 'i': (sizeof(int), &write_int) -} - -cimport stdlib - cdef class MockBuffer: cdef object format cdef char* buffer -- 2.26.2