]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | """Buffers used to hold null-terminated strings."""\r |
2 | \r | |
3 | \r | |
4 | from bgenBuffer import FixedOutputBufferType\r | |
5 | from bgenStackBuffer import StackOutputBufferType\r | |
6 | from bgenHeapBuffer import HeapOutputBufferType\r | |
7 | \r | |
8 | \r | |
9 | class StringBufferMixIn:\r | |
10 | \r | |
11 | """Mix-in class to create various string buffer types.\r | |
12 | \r | |
13 | Strings are character arrays terminated by a null byte.\r | |
14 | (For input, this is also covered by stringptr.)\r | |
15 | For output, there are again three variants:\r | |
16 | - Fixed: size is a constant given in the documentation; or\r | |
17 | - Stack: size is passed to the C function but we decide on a size at\r | |
18 | code generation time so we can still allocate on the heap); or\r | |
19 | - Heap: size is passed to the C function and we let the Python caller\r | |
20 | pass a size.\r | |
21 | (Note that this doesn't cover output parameters in which a string\r | |
22 | pointer is returned. These are actually easier (no allocation) but far\r | |
23 | less common. I'll write the classes when there is demand.)\r | |
24 | """\r | |
25 | \r | |
26 | def getSizeDeclarations(self, name):\r | |
27 | return []\r | |
28 | \r | |
29 | def getAuxDeclarations(self, name):\r | |
30 | return []\r | |
31 | \r | |
32 | def getargsFormat(self):\r | |
33 | return "s"\r | |
34 | \r | |
35 | def getargsArgs(self, name):\r | |
36 | return "&%s__in__" % name\r | |
37 | \r | |
38 | def mkvalueFormat(self):\r | |
39 | return "s"\r | |
40 | \r | |
41 | def mkvalueArgs(self, name):\r | |
42 | return "%s__out__" % name\r | |
43 | \r | |
44 | \r | |
45 | class FixedOutputStringType(StringBufferMixIn, FixedOutputBufferType):\r | |
46 | \r | |
47 | """Null-terminated output string -- passed without size.\r | |
48 | \r | |
49 | Instantiate with buffer size as parameter.\r | |
50 | """\r | |
51 | \r | |
52 | \r | |
53 | class StackOutputStringType(StringBufferMixIn, StackOutputBufferType):\r | |
54 | \r | |
55 | """Null-terminated output string -- passed as (buffer, size).\r | |
56 | \r | |
57 | Instantiate with buffer size as parameter.\r | |
58 | """\r | |
59 | \r | |
60 | \r | |
61 | class HeapOutputStringType(StringBufferMixIn, HeapOutputBufferType):\r | |
62 | \r | |
63 | """Null-terminated output string -- passed as (buffer, size).\r | |
64 | \r | |
65 | Instantiate without parameters.\r | |
66 | Call from Python with buffer size.\r | |
67 | """\r |