1 """Buffers used to hold null-terminated strings."""
4 from bgenBuffer
import FixedOutputBufferType
5 from bgenStackBuffer
import StackOutputBufferType
6 from bgenHeapBuffer
import HeapOutputBufferType
9 class StringBufferMixIn
:
11 """Mix-in class to create various string buffer types.
13 Strings are character arrays terminated by a null byte.
14 (For input, this is also covered by stringptr.)
15 For output, there are again three variants:
16 - Fixed: size is a constant given in the documentation; or
17 - Stack: size is passed to the C function but we decide on a size at
18 code generation time so we can still allocate on the heap); or
19 - Heap: size is passed to the C function and we let the Python caller
21 (Note that this doesn't cover output parameters in which a string
22 pointer is returned. These are actually easier (no allocation) but far
23 less common. I'll write the classes when there is demand.)
26 def declareSize(self
, name
):
29 def getargsFormat(self
):
32 def getargsArgs(self
, name
):
33 return "&%s__in__" % name
35 def mkvalueFormat(self
):
38 def mkvalueArgs(self
, name
):
39 return "%s__out__" % name
42 class FixedOutputStringType(StringBufferMixIn
, FixedOutputBufferType
):
44 """Null-terminated output string -- passed without size.
46 Instantiate with buffer size as parameter.
50 class StackOutputStringType(StringBufferMixIn
, StackOutputBufferType
):
52 """Null-terminated output string -- passed as (buffer, size).
54 Instantiate with buffer size as parameter.
58 class HeapOutputStringType(StringBufferMixIn
, HeapOutputBufferType
):
60 """Null-terminated output string -- passed as (buffer, size).
62 Instantiate without parameters.
63 Call from Python with buffer size.