for entry in lenv.arg_entries:
if entry.type.is_pyobject and lenv.control_flow.get_state((entry.name, 'source')) != 'arg':
code.put_var_incref(entry)
- if entry.type.is_buffer:
- Buffer.put_acquire_arg_buffer(entry, code, self.pos)
# ----- Initialise local variables
for entry in lenv.var_entries:
if entry.type.is_pyobject and entry.init_to_none and entry.used:
code.putln("%s.buf = NULL;" % entry.buffer_aux.buffer_info_var.cname)
# ----- Check and convert arguments
self.generate_argument_type_tests(code)
+ # ----- Acquire buffer arguments
+ for entry in lenv.arg_entries:
+ if entry.type.is_buffer:
+ Buffer.put_acquire_arg_buffer(entry, code, self.pos)
# ----- Function body
self.body.generate_execution_code(code)
# ----- Default return value
print
-
-
#
-# Testcase support code
+# Testcase support code (more tests below!, because of scope rules)
#
return 0
cdef get_itemsize(self): return sizeof(unsigned short)
cdef get_default_format(self): return "=H"
+
+cdef class IntStridedMockBuffer(MockBuffer):
+ cdef __cythonbufferdefaults__ = {"mode" : "strided"}
cdef class ErrorBuffer:
cdef object label
def __releasebuffer__(MockBuffer self, Py_buffer* buffer):
raise Exception("releasing %s" % self.label)
+#
+# Typed buffers
+#
+@testcase
+def typedbuffer1(obj):
+ """
+ >>> typedbuffer1(IntMockBuffer("A", range(10)))
+ acquired A
+ released A
+ >>> typedbuffer1(None)
+ >>> typedbuffer1(4)
+ Traceback (most recent call last):
+ ...
+ TypeError: Cannot convert int to bufaccess.IntMockBuffer
+ """
+ cdef IntMockBuffer[int, 1] buf = obj
+
+@testcase
+def typedbuffer2(IntMockBuffer[int, 1] obj):
+ """
+ >>> typedbuffer2(IntMockBuffer("A", range(10)))
+ acquired A
+ released A
+ >>> typedbuffer2(None)
+ >>> typedbuffer2(4)
+ Traceback (most recent call last):
+ ...
+ TypeError: Argument 'obj' has incorrect type (expected bufaccess.IntMockBuffer, got int)
+ """
+ pass
+
+#
+# Test __cythonbufferdefaults__
+#
+@testcase
+def bufdefaults1(IntStridedMockBuffer[int, 1] buf):
+ """
+ >>> A = IntStridedMockBuffer("A", range(10))
+ >>> bufdefaults1(A)
+ acquired A
+ released A
+ >>> A.recieved_flags
+ ['FORMAT', 'ND', 'STRIDES']
+ """
+ pass
+
+