Add better error reporting for MemoryErrors caused by str->float conversions.
[python.git] / Mac / Modules / launch / launchsupport.py
blob34c2efbcfd5e35740bfad7dae4318c8198a5db3a
1 # This script generates a Python interface for an Apple Macintosh Manager.
2 # It uses the "bgen" package to generate C code.
3 # The function specifications are generated by scanning the mamager's header file,
4 # using the "scantools" package (customized for this particular manager).
6 import string
8 # Declarations that change for each manager
9 MODNAME = '_Launch' # The name of the module
10 OBJECTNAME = 'UNUSED' # The basic name of the objects used here
11 KIND = 'Record' # Usually 'Ptr' or 'Handle'
13 # The following is *usually* unchanged but may still require tuning
14 MODPREFIX = 'Launch' # The prefix for module-wide routines
15 OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
16 OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
17 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
18 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
20 from macsupport import *
22 # Create the type objects
23 LSAcceptanceFlags = Type("LSAcceptanceFlags", "l")
24 LSInitializeFlags = Type("LSInitializeFlags", "l")
25 LSRequestedInfo = Type("LSRequestedInfo", "l")
26 LSRolesMask = Type("LSRolesMask", "l")
27 UniCharCount = Type("UniCharCount", "l")
28 OptCFStringRef = OpaqueByValueType("CFStringRef", "OptCFStringRefObj")
29 LSItemInfoRecord = OpaqueType("LSItemInfoRecord", "LSItemInfoRecord")
31 includestuff = includestuff + """
32 #if PY_VERSION_HEX < 0x02040000
33 PyObject *PyMac_GetOSErrException(void);
34 #endif
36 #include <ApplicationServices/ApplicationServices.h>
39 ** Optional CFStringRef. None will pass NULL
41 static int
42 OptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec)
44 if (v == Py_None) {
45 *spec = NULL;
46 return 1;
48 return CFStringRefObj_Convert(v, spec);
51 PyObject *
52 OptCFStringRefObj_New(CFStringRef it)
54 if (it == NULL) {
55 Py_INCREF(Py_None);
56 return Py_None;
58 return CFStringRefObj_New(it);
62 ** Convert LSItemInfoRecord to Python.
64 PyObject *
65 LSItemInfoRecord_New(LSItemInfoRecord *it)
67 return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}",
68 "flags", it->flags,
69 "filetype", PyMac_BuildOSType, it->filetype,
70 "creator", PyMac_BuildOSType, it->creator,
71 "extension", OptCFStringRefObj_New, it->extension,
72 "iconFileName", OptCFStringRefObj_New, it->iconFileName,
73 "kindID", it->kindID);
75 """
77 # From here on it's basically all boiler plate...
78 execfile(string.lower(MODPREFIX) + 'typetest.py')
80 # Create the generator groups and link them
81 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
82 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
83 ##module.addobject(object)
85 # Create the generator classes used to populate the lists
86 Function = OSErrFunctionGenerator
87 ##Method = OSErrMethodGenerator
89 # Create and populate the lists
90 functions = []
91 ##methods = []
92 execfile(INPUTFILE)
94 # add the populated lists to the generator groups
95 # (in a different wordl the scan program would generate this)
96 for f in functions: module.add(f)
97 ##for f in methods: object.add(f)
99 # generate output (open the output file as late as possible)
100 SetOutputFileName(OUTPUTFILE)
101 module.generate()