Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa968ac

Browse files
committed
Patches by Jack Jansen: new type OptionalInBuffer allows
passing either a string/input buffer or None.
1 parent 8bd7382 commit fa968ac

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Tools/bgen/bgen/bgenBuffer.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ class OutputOnlyBufferMixIn(OutputOnlyMixIn):
108108
def declareInputBuffer(self, name):
109109
pass
110110

111+
class OptionalInputBufferMixIn:
112+
113+
"""Add to input buffers if the buffer may be omitted: pass None in Python
114+
and the C code will get a NULL pointer and zero size"""
115+
116+
def getargsFormat(self):
117+
return "z#"
118+
111119

112120
class FixedInputBufferType(InputOnlyBufferMixIn, FixedInputOutputBufferType):
113121

@@ -119,6 +127,8 @@ class FixedInputBufferType(InputOnlyBufferMixIn, FixedInputOutputBufferType):
119127
def passInput(self, name):
120128
return "%s__in__" % name
121129

130+
class OptionalFixedInputBufferType(OptionalInputBufferMixIn, FixedInputBufferType):
131+
pass
122132

123133
class FixedOutputBufferType(OutputOnlyBufferMixIn, FixedInputOutputBufferType):
124134

@@ -147,7 +157,9 @@ def getargsCheck(self, name):
147157
def passInput(self, name):
148158
return "%s__in__, %s__len__" % (name, name)
149159

150-
160+
class OptionalVarInputBufferType(OptionalInputBufferMixIn, VarInputBufferType):
161+
pass
162+
151163
# ----- PART 2: Structure buffers -----
152164

153165

Tools/bgen/bgen/macsupport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def errorCheck(self, name):
8484
# Various buffer types
8585

8686
InBuffer = VarInputBufferType('char', 'long', 'l') # (buf, len)
87+
OptionalInBuffer = OptionalVarInputBufferType('char', 'long', 'l') # (buf, len)
8788

8889
InOutBuffer = HeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, len)
8990
VarInOutBuffer = VarHeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, &len)

0 commit comments

Comments
 (0)