Mercurial > cpython-lru_cache-weakref
annotate Mac/Modules/cm/cmsupport.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | c3a096bfbd6b |
| children | ac192f89c109 |
| rev | line source |
|---|---|
| 3282 | 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). | |
| 5 | |
| 6 import string | |
| 7 | |
| 8 # Declarations that change for each manager | |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
9 MACHEADERFILE = 'Components.h' # The Apple header file |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
10 MODNAME = '_Cm' # The name of the module |
| 3282 | 11 |
| 12 # The following is *usually* unchanged but may still require tuning | |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
13 MODPREFIX = 'Cm' # The prefix for module-wide routines |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
14 C_OBJECTPREFIX = 'CmpObj' # The prefix for object methods |
| 3282 | 15 CI_OBJECTPREFIX = 'CmpInstObj' |
| 16 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner | |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
17 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
| 3282 | 18 |
| 19 from macsupport import * | |
| 20 | |
| 21 # Create the type objects | |
| 22 | |
| 23 includestuff = includestuff + """ | |
|
17924
474e3de00b05
Lots more Carbon/Carbon.h includes, new UPP routine names, function prototypes. Most toolbox modules now compile, link and import in MacOSX-MachO python.
Jack Jansen <jack.jansen@cwi.nl>
parents:
17848
diff
changeset
|
24 #include <Carbon/Carbon.h> |
|
474e3de00b05
Lots more Carbon/Carbon.h includes, new UPP routine names, function prototypes. Most toolbox modules now compile, link and import in MacOSX-MachO python.
Jack Jansen <jack.jansen@cwi.nl>
parents:
17848
diff
changeset
|
25 |
|
17848
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
26 #ifdef USE_TOOLBOX_OBJECT_GLUE |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
27 extern PyObject *_CmpObj_New(Component); |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
28 extern int _CmpObj_Convert(PyObject *, Component *); |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
29 extern PyObject *_CmpInstObj_New(ComponentInstance); |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
30 extern int _CmpInstObj_Convert(PyObject *, ComponentInstance *); |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
31 |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
32 #define CmpObj_New _CmpObj_New |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
33 #define CmpObj_Convert _CmpObj_Convert |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
34 #define CmpInstObj_New _CmpInstObj_New |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
35 #define CmpInstObj_Convert _CmpInstObj_Convert |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
36 #endif |
| 3282 | 37 |
| 38 /* | |
| 39 ** Parse/generate ComponentDescriptor records | |
| 40 */ | |
|
13606
c9a4a1316170
pymactoolbox.h contains protoypes for all externally visible toolbox module
Jack Jansen <jack.jansen@cwi.nl>
parents:
3282
diff
changeset
|
41 static PyObject * |
|
17924
474e3de00b05
Lots more Carbon/Carbon.h includes, new UPP routine names, function prototypes. Most toolbox modules now compile, link and import in MacOSX-MachO python.
Jack Jansen <jack.jansen@cwi.nl>
parents:
17848
diff
changeset
|
42 CmpDesc_New(ComponentDescription *itself) |
| 3282 | 43 { |
| 44 | |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
45 return Py_BuildValue("O&O&O&ll", |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
46 PyMac_BuildOSType, itself->componentType, |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
47 PyMac_BuildOSType, itself->componentSubType, |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
48 PyMac_BuildOSType, itself->componentManufacturer, |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
49 itself->componentFlags, itself->componentFlagsMask); |
| 3282 | 50 } |
| 51 | |
|
13606
c9a4a1316170
pymactoolbox.h contains protoypes for all externally visible toolbox module
Jack Jansen <jack.jansen@cwi.nl>
parents:
3282
diff
changeset
|
52 static int |
|
17924
474e3de00b05
Lots more Carbon/Carbon.h includes, new UPP routine names, function prototypes. Most toolbox modules now compile, link and import in MacOSX-MachO python.
Jack Jansen <jack.jansen@cwi.nl>
parents:
17848
diff
changeset
|
53 CmpDesc_Convert(PyObject *v, ComponentDescription *p_itself) |
| 3282 | 54 { |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
55 return PyArg_ParseTuple(v, "O&O&O&ll", |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
56 PyMac_GetOSType, &p_itself->componentType, |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
57 PyMac_GetOSType, &p_itself->componentSubType, |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
58 PyMac_GetOSType, &p_itself->componentManufacturer, |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
59 &p_itself->componentFlags, &p_itself->componentFlagsMask); |
| 3282 | 60 } |
| 61 | |
| 62 """ | |
| 63 | |
|
17848
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
64 initstuff = initstuff + """ |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
65 PyMac_INIT_TOOLBOX_OBJECT_NEW(Component, CmpObj_New); |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
66 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Component, CmpObj_Convert); |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
67 PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, CmpInstObj_New); |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
68 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, CmpInstObj_Convert); |
|
17848
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
69 """ |
|
6960b2bbbfca
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
Jack Jansen <jack.jansen@cwi.nl>
parents:
13606
diff
changeset
|
70 |
| 3282 | 71 ComponentDescription = OpaqueType('ComponentDescription', 'CmpDesc') |
| 72 Component = OpaqueByValueType('Component', C_OBJECTPREFIX) | |
| 73 ComponentInstance = OpaqueByValueType('ComponentInstance', CI_OBJECTPREFIX) | |
| 74 ComponentResult = Type("ComponentResult", "l") | |
| 75 | |
| 76 ComponentResourceHandle = OpaqueByValueType("ComponentResourceHandle", "ResObj") | |
| 77 | |
|
26524
7aba859cee54
Added PEP253 support to most Carbon modules. This isn't complete yet:
Jack Jansen <jack.jansen@cwi.nl>
parents:
26464
diff
changeset
|
78 class MyCIObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
79 def outputCheckNewArg(self): |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
80 Output("""if (itself == NULL) { |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
81 PyErr_SetString(Cm_Error,"NULL ComponentInstance"); |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
82 return NULL; |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
83 }""") |
| 3282 | 84 |
|
26524
7aba859cee54
Added PEP253 support to most Carbon modules. This isn't complete yet:
Jack Jansen <jack.jansen@cwi.nl>
parents:
26464
diff
changeset
|
85 class MyCObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
86 def outputCheckNewArg(self): |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
87 Output("""if (itself == NULL) { |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
88 /* XXXX Or should we return None? */ |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
89 PyErr_SetString(Cm_Error,"No such component"); |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
90 return NULL; |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
91 }""") |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
92 |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
93 def outputCheckConvertArg(self): |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
94 Output("""if ( v == Py_None ) { |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
95 *p_itself = 0; |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
96 return 1; |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
97 }""") |
| 3282 | 98 |
| 99 # Create the generator groups and link them | |
| 100 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) | |
| 101 ci_object = MyCIObjectDefinition('ComponentInstance', CI_OBJECTPREFIX, | |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
30973
diff
changeset
|
102 'ComponentInstance') |
| 3282 | 103 c_object = MyCObjectDefinition('Component', C_OBJECTPREFIX, 'Component') |
| 104 module.addobject(ci_object) | |
| 105 module.addobject(c_object) | |
| 106 | |
| 107 # Create the generator classes used to populate the lists | |
|
22525
4ff37c58ab89
Backport of _Cmmodule.c 1.8 and cmsupport.py 1.6:
Jack Jansen <jack.jansen@cwi.nl>
parents:
19441
diff
changeset
|
108 Function = OSErrWeakLinkFunctionGenerator |
|
4ff37c58ab89
Backport of _Cmmodule.c 1.8 and cmsupport.py 1.6:
Jack Jansen <jack.jansen@cwi.nl>
parents:
19441
diff
changeset
|
109 Method = OSErrWeakLinkMethodGenerator |
| 3282 | 110 |
| 111 # Create and populate the lists | |
| 112 functions = [] | |
| 113 c_methods = [] | |
| 114 ci_methods = [] | |
| 115 execfile(INPUTFILE) | |
| 116 | |
| 117 # add the populated lists to the generator groups | |
| 118 # (in a different wordl the scan program would generate this) | |
| 119 for f in functions: module.add(f) | |
| 120 for f in c_methods: c_object.add(f) | |
| 121 for f in ci_methods: ci_object.add(f) | |
| 122 | |
| 123 # generate output (open the output file as late as possible) | |
| 124 SetOutputFileName(OUTPUTFILE) | |
| 125 module.generate() |
