mirror of
https://github.com/python/cpython.git
synced 2025-09-09 02:11:51 +00:00
Patches by Jack Jansen: new type OptionalInBuffer allows
passing either a string/input buffer or None.
This commit is contained in:
parent
8bd738278e
commit
fa968ac35b
2 changed files with 14 additions and 1 deletions
|
@ -108,6 +108,14 @@ class OutputOnlyBufferMixIn(OutputOnlyMixIn):
|
|||
def declareInputBuffer(self, name):
|
||||
pass
|
||||
|
||||
class OptionalInputBufferMixIn:
|
||||
|
||||
"""Add to input buffers if the buffer may be omitted: pass None in Python
|
||||
and the C code will get a NULL pointer and zero size"""
|
||||
|
||||
def getargsFormat(self):
|
||||
return "z#"
|
||||
|
||||
|
||||
class FixedInputBufferType(InputOnlyBufferMixIn, FixedInputOutputBufferType):
|
||||
|
||||
|
@ -119,6 +127,8 @@ class FixedInputBufferType(InputOnlyBufferMixIn, FixedInputOutputBufferType):
|
|||
def passInput(self, name):
|
||||
return "%s__in__" % name
|
||||
|
||||
class OptionalFixedInputBufferType(OptionalInputBufferMixIn, FixedInputBufferType):
|
||||
pass
|
||||
|
||||
class FixedOutputBufferType(OutputOnlyBufferMixIn, FixedInputOutputBufferType):
|
||||
|
||||
|
@ -147,7 +157,9 @@ class VarInputBufferType(FixedInputBufferType):
|
|||
def passInput(self, name):
|
||||
return "%s__in__, %s__len__" % (name, name)
|
||||
|
||||
|
||||
class OptionalVarInputBufferType(OptionalInputBufferMixIn, VarInputBufferType):
|
||||
pass
|
||||
|
||||
# ----- PART 2: Structure buffers -----
|
||||
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ OSStatus = OSErrType("OSStatus", 'l')
|
|||
# Various buffer types
|
||||
|
||||
InBuffer = VarInputBufferType('char', 'long', 'l') # (buf, len)
|
||||
OptionalInBuffer = OptionalVarInputBufferType('char', 'long', 'l') # (buf, len)
|
||||
|
||||
InOutBuffer = HeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, len)
|
||||
VarInOutBuffer = VarHeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, &len)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue