annotate Mac/Modules/launch/launchsupport.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents c3a096bfbd6b
children ac192f89c109
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 # This script generates a Python interface for an Apple Macintosh Manager.
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 # It uses the "bgen" package to generate C code.
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 # The function specifications are generated by scanning the mamager's header file,
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 # using the "scantools" package (customized for this particular manager).
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 import string
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 # Declarations that change for each manager
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
9 MODNAME = '_Launch' # The name of the module
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
10 OBJECTNAME = 'UNUSED' # The basic name of the objects used here
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
11 KIND = 'Record' # Usually 'Ptr' or 'Handle'
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 # The following is *usually* unchanged but may still require tuning
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
14 MODPREFIX = 'Launch' # The prefix for module-wide routines
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
15 OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
16 OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 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: 31160
diff changeset
18 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 from macsupport import *
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 # Create the type objects
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 LSAcceptanceFlags = Type("LSAcceptanceFlags", "l")
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 LSInitializeFlags = Type("LSInitializeFlags", "l")
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 LSRequestedInfo = Type("LSRequestedInfo", "l")
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 LSRolesMask = Type("LSRolesMask", "l")
31091
3861eb467c29 Ported to Universal Headers 3.4.2. Qd and Qt remain to be done.
Jack Jansen <jack.jansen@cwi.nl>
parents: 31075
diff changeset
27 UniCharCount = Type("UniCharCount", "l")
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 OptCFStringRef = OpaqueByValueType("CFStringRef", "OptCFStringRefObj")
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 LSItemInfoRecord = OpaqueType("LSItemInfoRecord", "LSItemInfoRecord")
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 includestuff = includestuff + """
31160
2a0782cc151f Made this module compatible with Python2.3, and added a temporary setup
Jack Jansen <jack.jansen@cwi.nl>
parents: 31091
diff changeset
32 #if PY_VERSION_HEX < 0x02040000
2a0782cc151f Made this module compatible with Python2.3, and added a temporary setup
Jack Jansen <jack.jansen@cwi.nl>
parents: 31091
diff changeset
33 PyObject *PyMac_GetOSErrException(void);
2a0782cc151f Made this module compatible with Python2.3, and added a temporary setup
Jack Jansen <jack.jansen@cwi.nl>
parents: 31091
diff changeset
34 #endif
2a0782cc151f Made this module compatible with Python2.3, and added a temporary setup
Jack Jansen <jack.jansen@cwi.nl>
parents: 31091
diff changeset
35
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 #include <ApplicationServices/ApplicationServices.h>
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 /*
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 ** Optional CFStringRef. None will pass NULL
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 */
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 static int
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 OptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
44 if (v == Py_None) {
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
45 *spec = NULL;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
46 return 1;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
47 }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
48 return CFStringRefObj_Convert(v, spec);
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 }
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 PyObject *
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 OptCFStringRefObj_New(CFStringRef it)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
54 if (it == NULL) {
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
55 Py_INCREF(Py_None);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
56 return Py_None;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
57 }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
58 return CFStringRefObj_New(it);
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 }
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 /*
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 ** Convert LSItemInfoRecord to Python.
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 */
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 PyObject *
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 LSItemInfoRecord_New(LSItemInfoRecord *it)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
67 return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}",
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
68 "flags", it->flags,
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
69 "filetype", PyMac_BuildOSType, it->filetype,
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
70 "creator", PyMac_BuildOSType, it->creator,
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
71 "extension", OptCFStringRefObj_New, it->extension,
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
72 "iconFileName", OptCFStringRefObj_New, it->iconFileName,
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31160
diff changeset
73 "kindID", it->kindID);
31075
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 }
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 """
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 # From here on it's basically all boiler plate...
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 execfile(string.lower(MODPREFIX) + 'typetest.py')
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 # Create the generator groups and link them
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 ##module.addobject(object)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 # Create the generator classes used to populate the lists
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 Function = OSErrFunctionGenerator
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 ##Method = OSErrMethodGenerator
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 # Create and populate the lists
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 functions = []
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 ##methods = []
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 execfile(INPUTFILE)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 # add the populated lists to the generator groups
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 # (in a different wordl the scan program would generate this)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 for f in functions: module.add(f)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 ##for f in methods: object.add(f)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 # generate output (open the output file as late as possible)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 SetOutputFileName(OUTPUTFILE)
5b515cc90b5a An interface to the LaunchServices API.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 module.generate()