1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# This script generates a Python interface for an Apple Macintosh Manager.
# It uses the "bgen" package to generate C code.
# The function specifications are generated by scanning the mamager's header file,
# using the "scantools" package (customized for this particular manager).
import string
# Declarations that change for each manager
MACHEADERFILE = 'OSA.h' # The Apple header file
MODNAME = '_OSA' # The name of the module
# The following is *usually* unchanged but may still require tuning
MODPREFIX = 'OSA' # The prefix for module-wide routines
OBJECTPREFIX = 'OSAObj' # The prefix for object methods
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
from macsupport import *
# Create the type objects
includestuff = includestuff + """
#include <Carbon/Carbon.h>
#ifdef USE_TOOLBOX_OBJECT_GLUE
extern PyObject *_OSAObj_New(ComponentInstance);
extern int _OSAObj_Convert(PyObject *, ComponentInstance *);
#define OSAObj_New _OSAObj_New
#define OSAObj_Convert _OSAObj_Convert
#endif
"""
initstuff = initstuff + """
/*
PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, OSAObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, OSAObj_Convert);
*/
"""
ComponentInstance = OpaqueByValueType('ComponentInstance', OBJECTPREFIX)
OSAError = OSErrType("OSAError", "l")
# OSALocalOrGlobal = Type("OSALocalOrGlobal", "l")
OSAID = Type("OSAID", "l")
OSADebugCallFrameRef = Type("OSADebugCallFrameRef", "l")
OSADebugSessionRef = Type("OSADebugSessionRef", "l")
OSADebugStepKind = Type("OSADebugStepKind", "l")
DescType = OSTypeType("DescType")
AEDesc = OpaqueType('AEDesc')
AEDesc_ptr = OpaqueType('AEDesc')
AEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc')
AEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc')
AEDescList = OpaqueType('AEDescList', 'AEDesc')
AEDescList_ptr = OpaqueType('AEDescList', 'AEDesc')
AERecord = OpaqueType('AERecord', 'AEDesc')
AERecord_ptr = OpaqueType('AERecord', 'AEDesc')
AppleEvent = OpaqueType('AppleEvent', 'AEDesc')
AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc')
# NOTE: at the moment OSA.ComponentInstance is not a subclass
# of Cm.ComponentInstance. If this is a problem it can be fixed.
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("""if (itself == NULL) {
PyErr_SetString(OSA_Error,"NULL ComponentInstance");
return NULL;
}""")
# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
object = MyObjectDefinition('ComponentInstance', OBJECTPREFIX,
'ComponentInstance')
module.addobject(object)
# Create the generator classes used to populate the lists
Function = OSErrWeakLinkFunctionGenerator
Method = OSErrWeakLinkMethodGenerator
# Test which types we are still missing.
execfile(string.lower(MODPREFIX) + 'typetest.py')
# Create and populate the lists
functions = []
methods = []
execfile(INPUTFILE)
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in functions: module.add(f)
for f in methods: object.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()
|