Kaydet (Commit) 2cf08ab4 authored tarafından Jack Jansen's avatar Jack Jansen

Sigh, due to sloppiness on my part bgen has become pretty mixed up wrt. tabs

and spaces. Detabbed the lot.
üst 28256f27
This diff is collapsed.
...@@ -2,39 +2,39 @@ from bgenOutput import * ...@@ -2,39 +2,39 @@ from bgenOutput import *
class GeneratorGroup: class GeneratorGroup:
def __init__(self, prefix): def __init__(self, prefix):
self.prefix = prefix self.prefix = prefix
self.generators = [] self.generators = []
def add(self, g, dupcheck=0): def add(self, g, dupcheck=0):
if dupcheck: if dupcheck:
if g in self.generators: if g in self.generators:
print 'DUP', g.name print 'DUP', g.name
return return
g.setprefix(self.prefix) g.setprefix(self.prefix)
self.generators.append(g) self.generators.append(g)
def generate(self): def generate(self):
for g in self.generators: for g in self.generators:
g.generate() g.generate()
Output() Output()
Output("static PyMethodDef %s_methods[] = {", self.prefix) Output("static PyMethodDef %s_methods[] = {", self.prefix)
IndentLevel() IndentLevel()
for g in self.generators: for g in self.generators:
g.reference() g.reference()
Output("{NULL, NULL, 0}") Output("{NULL, NULL, 0}")
DedentLevel() DedentLevel()
Output("};") Output("};")
def _test(): def _test():
void = None void = None
from bgenGenerator import FunctionGenerator from bgenGenerator import FunctionGenerator
group = GeneratorGroup("spam") group = GeneratorGroup("spam")
eggs = FunctionGenerator(void, "eggs") eggs = FunctionGenerator(void, "eggs")
group.add(eggs) group.add(eggs)
print "/* START */" print "/* START */"
group.generate() group.generate()
if __name__ == "__main__": if __name__ == "__main__":
_test() _test()
...@@ -7,105 +7,105 @@ from bgenBuffer import FixedInputOutputBufferType ...@@ -7,105 +7,105 @@ from bgenBuffer import FixedInputOutputBufferType
class HeapInputOutputBufferType(FixedInputOutputBufferType): class HeapInputOutputBufferType(FixedInputOutputBufferType):
"""Input-output buffer allocated on the heap -- passed as (inbuffer, outbuffer, size). """Input-output buffer allocated on the heap -- passed as (inbuffer, outbuffer, size).
Instantiate without parameters. Instantiate without parameters.
Call from Python with input buffer. Call from Python with input buffer.
""" """
def __init__(self, datatype = 'char', sizetype = 'int', sizeformat = None): def __init__(self, datatype = 'char', sizetype = 'int', sizeformat = None):
FixedInputOutputBufferType.__init__(self, "0", datatype, sizetype, sizeformat) FixedInputOutputBufferType.__init__(self, "0", datatype, sizetype, sizeformat)
def declareOutputBuffer(self, name): def declareOutputBuffer(self, name):
Output("%s *%s__out__;", self.datatype, name) Output("%s *%s__out__;", self.datatype, name)
def getargsCheck(self, name): def getargsCheck(self, name):
Output("if ((%s__out__ = malloc(%s__in_len__)) == NULL)", name, name) Output("if ((%s__out__ = malloc(%s__in_len__)) == NULL)", name, name)
OutLbrace() OutLbrace()
Output('PyErr_NoMemory();') Output('PyErr_NoMemory();')
Output("goto %s__error__;", name) Output("goto %s__error__;", name)
self.label_needed = 1 self.label_needed = 1
OutRbrace() OutRbrace()
Output("%s__len__ = %s__in_len__;", name, name) Output("%s__len__ = %s__in_len__;", name, name)
def passOutput(self, name): def passOutput(self, name):
return "%s__in__, %s__out__, (%s)%s__len__" % \ return "%s__in__, %s__out__, (%s)%s__len__" % \
(name, name, self.sizetype, name) (name, name, self.sizetype, name)
def mkvalueArgs(self, name): def mkvalueArgs(self, name):
return "%s__out__, (int)%s__len__" % (name, name) return "%s__out__, (int)%s__len__" % (name, name)
def cleanup(self, name): def cleanup(self, name):
Output("free(%s__out__);", name) Output("free(%s__out__);", name)
FixedInputOutputBufferType.cleanup(self, name) FixedInputOutputBufferType.cleanup(self, name)
class VarHeapInputOutputBufferType(HeapInputOutputBufferType): class VarHeapInputOutputBufferType(HeapInputOutputBufferType):
"""same as base class, but passed as (inbuffer, outbuffer, &size)""" """same as base class, but passed as (inbuffer, outbuffer, &size)"""
def passOutput(self, name): def passOutput(self, name):
return "%s__in__, %s__out__, &%s__len__" % (name, name, name) return "%s__in__, %s__out__, &%s__len__" % (name, name, name)
class HeapCombinedInputOutputBufferType(HeapInputOutputBufferType): class HeapCombinedInputOutputBufferType(HeapInputOutputBufferType):
"""same as base class, but passed as (inoutbuffer, size)""" """same as base class, but passed as (inoutbuffer, size)"""
def passOutput(self, name): def passOutput(self, name):
return "(%s *)memcpy(%s__out__, %s__in__, %s__len__)" % \ return "(%s *)memcpy(%s__out__, %s__in__, %s__len__)" % \
(self.datatype, name, name, name) (self.datatype, name, name, name)
class VarHeapCombinedInputOutputBufferType(HeapInputOutputBufferType): class VarHeapCombinedInputOutputBufferType(HeapInputOutputBufferType):
"""same as base class, but passed as (inoutbuffer, &size)""" """same as base class, but passed as (inoutbuffer, &size)"""
def passOutput(self, name): def passOutput(self, name):
return "(%s *)memcpy(%s__out__, %s__in__, &%s__len__)" % \ return "(%s *)memcpy(%s__out__, %s__in__, &%s__len__)" % \
(self.datatype, name, name, name) (self.datatype, name, name, name)
class HeapOutputBufferType(OutputOnlyMixIn, HeapInputOutputBufferType): class HeapOutputBufferType(OutputOnlyMixIn, HeapInputOutputBufferType):
"""Output buffer allocated on the heap -- passed as (buffer, size). """Output buffer allocated on the heap -- passed as (buffer, size).
Instantiate without parameters. Instantiate without parameters.
Call from Python with buffer size. Call from Python with buffer size.
""" """
def declareInputBuffer(self, name): def declareInputBuffer(self, name):
pass pass
def getargsFormat(self): def getargsFormat(self):
return "i" return "i"
def getargsArgs(self, name): def getargsArgs(self, name):
return "&%s__in_len__" % name return "&%s__in_len__" % name
def passOutput(self, name): def passOutput(self, name):
return "%s__out__, %s__len__" % (name, name) return "%s__out__, %s__len__" % (name, name)
class VarHeapOutputBufferType(HeapOutputBufferType): class VarHeapOutputBufferType(HeapOutputBufferType):
"""Output buffer allocated on the heap -- passed as (buffer, &size). """Output buffer allocated on the heap -- passed as (buffer, &size).
Instantiate without parameters. Instantiate without parameters.
Call from Python with buffer size. Call from Python with buffer size.
""" """
def passOutput(self, name): def passOutput(self, name):
return "%s__out__, &%s__len__" % (name, name) return "%s__out__, &%s__len__" % (name, name)
class VarVarHeapOutputBufferType(VarHeapOutputBufferType): class VarVarHeapOutputBufferType(VarHeapOutputBufferType):
"""Output buffer allocated on the heap -- passed as (buffer, size, &size). """Output buffer allocated on the heap -- passed as (buffer, size, &size).
Instantiate without parameters. Instantiate without parameters.
Call from Python with buffer size. Call from Python with buffer size.
""" """
def passOutput(self, name): def passOutput(self, name):
return "%s__out__, %s__len__, &%s__len__" % (name, name, name) return "%s__out__, %s__len__, &%s__len__" % (name, name, name)
...@@ -3,92 +3,92 @@ from bgenGeneratorGroup import GeneratorGroup ...@@ -3,92 +3,92 @@ from bgenGeneratorGroup import GeneratorGroup
class Module(GeneratorGroup): class Module(GeneratorGroup):
def __init__(self, name, prefix = None, def __init__(self, name, prefix = None,
includestuff = None, includestuff = None,
finalstuff = None, finalstuff = None,
initstuff = None, initstuff = None,
variablestuff = None, variablestuff = None,
longname = None): longname = None):
GeneratorGroup.__init__(self, prefix or name) GeneratorGroup.__init__(self, prefix or name)
self.name = name self.name = name
if longname: if longname:
self.longname = longname self.longname = longname
else: else:
self.longname = name self.longname = name
self.includestuff = includestuff self.includestuff = includestuff
self.initstuff = initstuff self.initstuff = initstuff
self.finalstuff = finalstuff self.finalstuff = finalstuff
self.variablestuff = variablestuff self.variablestuff = variablestuff
self.typeobjects = [] self.typeobjects = []
def addobject(self, od): def addobject(self, od):
self.generators.append(od) self.generators.append(od)
self.typeobjects.append(od) self.typeobjects.append(od)
od.setmodulename(self.longname) od.setmodulename(self.longname)
def generate(self): def generate(self):
OutHeader1("Module " + self.name) OutHeader1("Module " + self.name)
Output("#include \"Python.h\"") Output("#include \"Python.h\"")
Output() Output()
if self.includestuff: if self.includestuff:
Output() Output()
Output("%s", self.includestuff) Output("%s", self.includestuff)
self.declareModuleVariables() self.declareModuleVariables()
GeneratorGroup.generate(self) GeneratorGroup.generate(self)
if self.finalstuff: if self.finalstuff:
Output() Output()
Output("%s", self.finalstuff) Output("%s", self.finalstuff)
Output() Output()
Output("void init%s(void)", self.name) Output("void init%s(void)", self.name)
OutLbrace() OutLbrace()
Output("PyObject *m;") Output("PyObject *m;")
Output("PyObject *d;") Output("PyObject *d;")
Output() Output()
if self.initstuff: if self.initstuff:
Output("%s", self.initstuff) Output("%s", self.initstuff)
Output() Output()
Output("m = Py_InitModule(\"%s\", %s_methods);", Output("m = Py_InitModule(\"%s\", %s_methods);",
self.name, self.prefix) self.name, self.prefix)
Output("d = PyModule_GetDict(m);") Output("d = PyModule_GetDict(m);")
self.createModuleVariables() self.createModuleVariables()
OutRbrace() OutRbrace()
OutHeader1("End module " + self.name) OutHeader1("End module " + self.name)
def declareModuleVariables(self): def declareModuleVariables(self):
self.errorname = self.prefix + "_Error" self.errorname = self.prefix + "_Error"
Output("static PyObject *%s;", self.errorname) Output("static PyObject *%s;", self.errorname)
def createModuleVariables(self): def createModuleVariables(self):
Output("""%s = %s;""", self.errorname, self.exceptionInitializer()) Output("""%s = %s;""", self.errorname, self.exceptionInitializer())
Output("""if (%s == NULL ||""", self.errorname) Output("""if (%s == NULL ||""", self.errorname)
Output(""" PyDict_SetItemString(d, "Error", %s) != 0)""", Output(""" PyDict_SetItemString(d, "Error", %s) != 0)""",
self.errorname) self.errorname)
IndentLevel() IndentLevel()
Output("""return;""") Output("""return;""")
DedentLevel() DedentLevel()
for tp in self.typeobjects: for tp in self.typeobjects:
tp.outputTypeObjectInitializer() tp.outputTypeObjectInitializer()
if self.variablestuff: if self.variablestuff:
Output("%s", self.variablestuff) Output("%s", self.variablestuff)
Output() Output()
def exceptionInitializer(self): def exceptionInitializer(self):
return """PyErr_NewException("%s.Error", NULL, NULL)""" % self.name return """PyErr_NewException("%s.Error", NULL, NULL)""" % self.name
def _test(): def _test():
from bgenGenerator import FunctionGenerator from bgenGenerator import FunctionGenerator
m = Module("spam", "", "#include <stdio.h>") m = Module("spam", "", "#include <stdio.h>")
g = FunctionGenerator(None, "bacon") g = FunctionGenerator(None, "bacon")
m.add(g) m.add(g)
m.generate() m.generate()
if __name__ == "__main__": if __name__ == "__main__":
_test() _test()
This diff is collapsed.
...@@ -6,54 +6,54 @@ from bgenBuffer import FixedInputBufferType, FixedOutputBufferType ...@@ -6,54 +6,54 @@ from bgenBuffer import FixedInputBufferType, FixedOutputBufferType
class StackOutputBufferType(FixedOutputBufferType): class StackOutputBufferType(FixedOutputBufferType):
"""Fixed output buffer allocated on the stack -- passed as (buffer, size). """Fixed output buffer allocated on the stack -- passed as (buffer, size).
Instantiate with the buffer size as parameter. Instantiate with the buffer size as parameter.
""" """
def passOutput(self, name): def passOutput(self, name):
return "%s__out__, %s" % (name, self.size) return "%s__out__, %s" % (name, self.size)
class VarStackOutputBufferType(StackOutputBufferType): class VarStackOutputBufferType(StackOutputBufferType):
"""Output buffer allocated on the stack -- passed as (buffer, &size). """Output buffer allocated on the stack -- passed as (buffer, &size).
Instantiate with the buffer size as parameter. Instantiate with the buffer size as parameter.
""" """
def declareSize(self, name): def declareSize(self, name):
Output("int %s__len__ = %s;", name, self.size) Output("int %s__len__ = %s;", name, self.size)
def passOutput(self, name): def passOutput(self, name):
return "%s__out__, &%s__len__" % (name, name) return "%s__out__, &%s__len__" % (name, name)
def mkvalueArgs(self, name): def mkvalueArgs(self, name):
return "%s__out__, (int)%s__len__" % (name, name) return "%s__out__, (int)%s__len__" % (name, name)
class VarVarStackOutputBufferType(VarStackOutputBufferType): class VarVarStackOutputBufferType(VarStackOutputBufferType):
"""Output buffer allocated on the stack -- passed as (buffer, size, &size). """Output buffer allocated on the stack -- passed as (buffer, size, &size).
Instantiate with the buffer size as parameter. Instantiate with the buffer size as parameter.
""" """
def passOutput(self, name): def passOutput(self, name):
return "%s__out__, %s__len__, &%s__len__" % (name, name, name) return "%s__out__, %s__len__, &%s__len__" % (name, name, name)
class ReturnVarStackOutputBufferType(VarStackOutputBufferType): class ReturnVarStackOutputBufferType(VarStackOutputBufferType):
"""Output buffer allocated on the stack -- passed as (buffer, size) -> size. """Output buffer allocated on the stack -- passed as (buffer, size) -> size.
Instantiate with the buffer size as parameter. Instantiate with the buffer size as parameter.
The function's return value is the size. The function's return value is the size.
(XXX Should have a way to suppress returning it separately, too.) (XXX Should have a way to suppress returning it separately, too.)
""" """
def passOutput(self, name): def passOutput(self, name):
return "%s__out__, %s__len__" % (name, name) return "%s__out__, %s__len__" % (name, name)
def mkvalueArgs(self, name): def mkvalueArgs(self, name):
return "%s__out__, (int)_rv" % name return "%s__out__, (int)_rv" % name
...@@ -8,57 +8,57 @@ from bgenHeapBuffer import HeapOutputBufferType ...@@ -8,57 +8,57 @@ from bgenHeapBuffer import HeapOutputBufferType
class StringBufferMixIn: class StringBufferMixIn:
"""Mix-in class to create various string buffer types. """Mix-in class to create various string buffer types.
Strings are character arrays terminated by a null byte. Strings are character arrays terminated by a null byte.
(For input, this is also covered by stringptr.) (For input, this is also covered by stringptr.)
For output, there are again three variants: For output, there are again three variants:
- Fixed: size is a constant given in the documentation; or - Fixed: size is a constant given in the documentation; or
- Stack: size is passed to the C function but we decide on a size at - Stack: size is passed to the C function but we decide on a size at
code generation time so we can still allocate on the heap); or code generation time so we can still allocate on the heap); or
- Heap: size is passed to the C function and we let the Python caller - Heap: size is passed to the C function and we let the Python caller
pass a size. pass a size.
(Note that this doesn't cover output parameters in which a string (Note that this doesn't cover output parameters in which a string
pointer is returned. These are actually easier (no allocation) but far pointer is returned. These are actually easier (no allocation) but far
less common. I'll write the classes when there is demand.) less common. I'll write the classes when there is demand.)
""" """
def declareSize(self, name): def declareSize(self, name):
pass pass
def getargsFormat(self): def getargsFormat(self):
return "s" return "s"
def getargsArgs(self, name): def getargsArgs(self, name):
return "&%s__in__" % name return "&%s__in__" % name
def mkvalueFormat(self): def mkvalueFormat(self):
return "s" return "s"
def mkvalueArgs(self, name): def mkvalueArgs(self, name):
return "%s__out__" % name return "%s__out__" % name
class FixedOutputStringType(StringBufferMixIn, FixedOutputBufferType): class FixedOutputStringType(StringBufferMixIn, FixedOutputBufferType):
"""Null-terminated output string -- passed without size. """Null-terminated output string -- passed without size.
Instantiate with buffer size as parameter. Instantiate with buffer size as parameter.
""" """
class StackOutputStringType(StringBufferMixIn, StackOutputBufferType): class StackOutputStringType(StringBufferMixIn, StackOutputBufferType):
"""Null-terminated output string -- passed as (buffer, size). """Null-terminated output string -- passed as (buffer, size).
Instantiate with buffer size as parameter. Instantiate with buffer size as parameter.
""" """
class HeapOutputStringType(StringBufferMixIn, HeapOutputBufferType): class HeapOutputStringType(StringBufferMixIn, HeapOutputBufferType):
"""Null-terminated output string -- passed as (buffer, size). """Null-terminated output string -- passed as (buffer, size).
Instantiate without parameters. Instantiate without parameters.
Call from Python with buffer size. Call from Python with buffer size.
""" """
This diff is collapsed.
...@@ -17,72 +17,72 @@ ErrorMode = 16+OutMode # this is an error status -- turn it into an exception ...@@ -17,72 +17,72 @@ ErrorMode = 16+OutMode # this is an error status -- turn it into an exception
class Variable: class Variable:
"""A Variable holds a type, a name, a transfer mode and flags. """A Variable holds a type, a name, a transfer mode and flags.
Most of its methods call the correponding type method with the Most of its methods call the correponding type method with the
variable name. variable name.
""" """
def __init__(self, type, name = None, flags = InMode): def __init__(self, type, name = None, flags = InMode):
"""Call with a type, a name and flags. """Call with a type, a name and flags.
If name is None, it muse be set later. If name is None, it muse be set later.
flags defaults to InMode. flags defaults to InMode.
""" """
self.type = type self.type = type
self.name = name self.name = name
self.flags = flags self.flags = flags
self.mode = flags & ModeMask self.mode = flags & ModeMask
def declare(self): def declare(self):
"""Declare the variable if necessary. """Declare the variable if necessary.
If it is "self", it is not declared. If it is "self", it is not declared.
""" """
if self.flags != SelfMode: if self.flags != SelfMode:
self.type.declare(self.name) self.type.declare(self.name)
def getargsFormat(self): def getargsFormat(self):
"""Call the type's getargsFormatmethod.""" """Call the type's getargsFormatmethod."""
return self.type.getargsFormat() return self.type.getargsFormat()
def getargsArgs(self): def getargsArgs(self):
"""Call the type's getargsArgsmethod.""" """Call the type's getargsArgsmethod."""
return self.type.getargsArgs(self.name) return self.type.getargsArgs(self.name)
def getargsCheck(self): def getargsCheck(self):
return self.type.getargsCheck(self.name) return self.type.getargsCheck(self.name)
def passArgument(self): def passArgument(self):
"""Return the string required to pass the variable as argument. """Return the string required to pass the variable as argument.
For "in" arguments, return the variable name. For "in" arguments, return the variable name.
For "out" and "in out" arguments, For "out" and "in out" arguments,
return its name prefixed with "&". return its name prefixed with "&".
""" """
if self.mode == InMode: if self.mode == InMode:
return self.type.passInput(self.name) return self.type.passInput(self.name)
if self.mode in (OutMode, InOutMode): if self.mode in (OutMode, InOutMode):
return self.type.passOutput(self.name) return self.type.passOutput(self.name)
# XXX Shouldn't get here # XXX Shouldn't get here
return "/*mode?*/" + self.type.passInput(self.name) return "/*mode?*/" + self.type.passInput(self.name)
def errorCheck(self): def errorCheck(self):
"""Check for an error if necessary. """Check for an error if necessary.
This only generates code if the variable's mode is ErrorMode. This only generates code if the variable's mode is ErrorMode.
""" """
if self.flags == ErrorMode: if self.flags == ErrorMode:
self.type.errorCheck(self.name) self.type.errorCheck(self.name)
def mkvalueFormat (self): def mkvalueFormat (self):
"""Call the type's mkvalueFormat method.""" """Call the type's mkvalueFormat method."""
return self.type.mkvalueFormat() return self.type.mkvalueFormat()
def mkvalueArgs(self): def mkvalueArgs(self):
"""Call the type's mkvalueArgs method.""" """Call the type's mkvalueArgs method."""
return self.type.mkvalueArgs(self.name) return self.type.mkvalueArgs(self.name)
def cleanup(self): def cleanup(self):
"""Call the type's cleanup method.""" """Call the type's cleanup method."""
return self.type.cleanup(self.name) return self.type.cleanup(self.name)
...@@ -52,7 +52,7 @@ FSRef = OpaqueByValueStructType("FSRef", "PyMac_BuildFSRef", "PyMac_GetFSRef") ...@@ -52,7 +52,7 @@ FSRef = OpaqueByValueStructType("FSRef", "PyMac_BuildFSRef", "PyMac_GetFSRef")
# OSType and ResType: 4-byte character strings # OSType and ResType: 4-byte character strings
def OSTypeType(typename): def OSTypeType(typename):
return OpaqueByValueType(typename, "PyMac_BuildOSType", "PyMac_GetOSType") return OpaqueByValueType(typename, "PyMac_BuildOSType", "PyMac_GetOSType")
OSType = OSTypeType("OSType") OSType = OSTypeType("OSType")
ResType = OSTypeType("ResType") ResType = OSTypeType("ResType")
FourCharCode = OSTypeType("FourCharCode") FourCharCode = OSTypeType("FourCharCode")
...@@ -104,35 +104,35 @@ OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj") ...@@ -104,35 +104,35 @@ OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
# OSErr is special because it is turned into an exception # OSErr is special because it is turned into an exception
# (Could do this with less code using a variant of mkvalue("O&")?) # (Could do this with less code using a variant of mkvalue("O&")?)
class OSErrType(Type): class OSErrType(Type):
def errorCheck(self, name): def errorCheck(self, name):
Output("if (%s != noErr) return PyMac_Error(%s);", name, name) Output("if (%s != noErr) return PyMac_Error(%s);", name, name)
self.used = 1 self.used = 1
OSErr = OSErrType("OSErr", 'h') OSErr = OSErrType("OSErr", 'h')
OSStatus = OSErrType("OSStatus", 'l') OSStatus = OSErrType("OSStatus", 'l')
# Various buffer types # Various buffer types
InBuffer = VarInputBufferType('char', 'long', 'l') # (buf, len) InBuffer = VarInputBufferType('char', 'long', 'l') # (buf, len)
UcharInBuffer = VarInputBufferType('unsigned char', 'long', 'l') # (buf, len) UcharInBuffer = VarInputBufferType('unsigned char', 'long', 'l') # (buf, len)
OptionalInBuffer = OptionalVarInputBufferType('char', 'long', 'l') # (buf, len) OptionalInBuffer = OptionalVarInputBufferType('char', 'long', 'l') # (buf, len)
InOutBuffer = HeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, len) InOutBuffer = HeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, len)
VarInOutBuffer = VarHeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, &len) VarInOutBuffer = VarHeapInputOutputBufferType('char', 'long', 'l') # (inbuf, outbuf, &len)
OutBuffer = HeapOutputBufferType('char', 'long', 'l') # (buf, len) OutBuffer = HeapOutputBufferType('char', 'long', 'l') # (buf, len)
VarOutBuffer = VarHeapOutputBufferType('char', 'long', 'l') # (buf, &len) VarOutBuffer = VarHeapOutputBufferType('char', 'long', 'l') # (buf, &len)
VarVarOutBuffer = VarVarHeapOutputBufferType('char', 'long', 'l') # (buf, len, &len) VarVarOutBuffer = VarVarHeapOutputBufferType('char', 'long', 'l') # (buf, len, &len)
# Unicode arguments sometimes have reversed len, buffer (don't understand why Apple did this...) # Unicode arguments sometimes have reversed len, buffer (don't understand why Apple did this...)
class VarUnicodeInputBufferType(VarInputBufferType): class VarUnicodeInputBufferType(VarInputBufferType):
def getargsFormat(self): def getargsFormat(self):
return "u#" return "u#"
class VarUnicodeReverseInputBufferType(ReverseInputBufferMixin, VarUnicodeInputBufferType): class VarUnicodeReverseInputBufferType(ReverseInputBufferMixin, VarUnicodeInputBufferType):
pass pass
UnicodeInBuffer = VarUnicodeInputBufferType('UniChar', 'UniCharCount', 'l') UnicodeInBuffer = VarUnicodeInputBufferType('UniChar', 'UniCharCount', 'l')
UnicodeReverseInBuffer = VarUnicodeReverseInputBufferType('UniChar', 'UniCharCount', 'l') UnicodeReverseInBuffer = VarUnicodeReverseInputBufferType('UniChar', 'UniCharCount', 'l')
UniChar_ptr = InputOnlyType("UniCharPtr", "u") UniChar_ptr = InputOnlyType("UniCharPtr", "u")
...@@ -151,9 +151,9 @@ includestuff = """ ...@@ -151,9 +151,9 @@ includestuff = """
/* Macro to test whether a weak-loaded CFM function exists */ /* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\\ #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\\
PyErr_SetString(PyExc_NotImplementedError, \\ PyErr_SetString(PyExc_NotImplementedError, \\
"Not available in this shared library/OS version"); \\ "Not available in this shared library/OS version"); \\
return NULL; \\ return NULL; \\
}} while(0) }} while(0)
""" """
...@@ -173,23 +173,23 @@ initstuff = """ ...@@ -173,23 +173,23 @@ initstuff = """
# This requires that the OSErr type (defined above) has a non-trivial # This requires that the OSErr type (defined above) has a non-trivial
# errorCheck method. # errorCheck method.
class OSErrMixIn: class OSErrMixIn:
"Mix-in class to treat OSErr/OSStatus return values special" "Mix-in class to treat OSErr/OSStatus return values special"
def makereturnvar(self): def makereturnvar(self):
if self.returntype.__class__ == OSErrType: if self.returntype.__class__ == OSErrType:
return Variable(self.returntype, "_err", ErrorMode) return Variable(self.returntype, "_err", ErrorMode)
else: else:
return Variable(self.returntype, "_rv", OutMode) return Variable(self.returntype, "_rv", OutMode)
class OSErrFunctionGenerator(OSErrMixIn, FunctionGenerator): pass class OSErrFunctionGenerator(OSErrMixIn, FunctionGenerator): pass
class OSErrMethodGenerator(OSErrMixIn, MethodGenerator): pass class OSErrMethodGenerator(OSErrMixIn, MethodGenerator): pass
class WeakLinkMixIn: class WeakLinkMixIn:
"Mix-in to test the function actually exists (!= NULL) before calling" "Mix-in to test the function actually exists (!= NULL) before calling"
def precheck(self): def precheck(self):
Output('#ifndef %s', self.name) Output('#ifndef %s', self.name)
Output('PyMac_PRECHECK(%s);', self.name) Output('PyMac_PRECHECK(%s);', self.name)
Output('#endif') Output('#endif')
class WeakLinkFunctionGenerator(WeakLinkMixIn, FunctionGenerator): pass class WeakLinkFunctionGenerator(WeakLinkMixIn, FunctionGenerator): pass
class WeakLinkMethodGenerator(WeakLinkMixIn, MethodGenerator): pass class WeakLinkMethodGenerator(WeakLinkMixIn, MethodGenerator): pass
...@@ -197,14 +197,14 @@ class OSErrWeakLinkFunctionGenerator(OSErrMixIn, WeakLinkMixIn, FunctionGenerato ...@@ -197,14 +197,14 @@ class OSErrWeakLinkFunctionGenerator(OSErrMixIn, WeakLinkMixIn, FunctionGenerato
class OSErrWeakLinkMethodGenerator(OSErrMixIn, WeakLinkMixIn, MethodGenerator): pass class OSErrWeakLinkMethodGenerator(OSErrMixIn, WeakLinkMixIn, MethodGenerator): pass
class MacModule(Module): class MacModule(Module):
"Subclass which gets the exception initializer from macglue.c" "Subclass which gets the exception initializer from macglue.c"
def exceptionInitializer(self): def exceptionInitializer(self):
return "PyMac_GetOSErrException()" return "PyMac_GetOSErrException()"
_SetOutputFileName = SetOutputFileName # Save original _SetOutputFileName = SetOutputFileName # Save original
def SetOutputFileName(file = None): def SetOutputFileName(file = None):
"Set the output file name and set its creator&type to CWIE&TEXT" "Set the output file name and set its creator&type to CWIE&TEXT"
_SetOutputFileName(file) _SetOutputFileName(file)
if file: if file:
import MacOS import MacOS
MacOS.SetCreatorAndType(file, 'CWIE', 'TEXT') MacOS.SetCreatorAndType(file, 'CWIE', 'TEXT')
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment