Mercurial > cpython-lru_cache-weakref
annotate Mac/Modules/ctl/ctlsupport.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 852ca23c80cc |
| children | 4e53746e51af |
| rev | line source |
|---|---|
|
2267
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 # This script generates a Python interface for an Apple Macintosh Manager. |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 # It uses the "bgen" package to generate C code. |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 # The function specifications are generated by scanning the mamager's header file, |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 # using the "scantools" package (customized for this particular manager). |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 import string |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
2720
abf116db523f
Trying again to check it in. Changes to:
Jack Jansen <jack.jansen@cwi.nl>
parents:
2267
diff
changeset
|
8 import addpack |
|
abf116db523f
Trying again to check it in. Changes to:
Jack Jansen <jack.jansen@cwi.nl>
parents:
2267
diff
changeset
|
9 addpack.addpack(':Tools:bgen:bgen') |
|
abf116db523f
Trying again to check it in. Changes to:
Jack Jansen <jack.jansen@cwi.nl>
parents:
2267
diff
changeset
|
10 |
|
2267
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 # Declarations that change for each manager |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 MACHEADERFILE = 'Controls.h' # The Apple header file |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 MODNAME = 'Ctl' # The name of the module |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 OBJECTNAME = 'Control' # The basic name of the objects used here |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 # The following is *usually* unchanged but may still require tuning |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 MODPREFIX = MODNAME # The prefix for module-wide routines |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 from macsupport import * |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 # Create the type objects |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 ControlHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) |
|
2720
abf116db523f
Trying again to check it in. Changes to:
Jack Jansen <jack.jansen@cwi.nl>
parents:
2267
diff
changeset
|
28 ControlRef = ControlHandle |
|
2267
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 ExistingControlHandle = OpaqueByValueType(OBJECTTYPE, "CtlObj_WhichControl", "BUG") |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
3499
5f25040fd63e
Replaced various dummy updateRegions by real arguments
Jack Jansen <jack.jansen@cwi.nl>
parents:
2751
diff
changeset
|
31 RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") |
|
2723
a0fc94b3bb21
Ported to Universal Header 2.0.1f (i.e. CW6)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2720
diff
changeset
|
32 ControlPartCode = Type("ControlPartCode", "h") |
|
a0fc94b3bb21
Ported to Universal Header 2.0.1f (i.e. CW6)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2720
diff
changeset
|
33 DragConstraint = Type("DragConstraint", "h") |
|
2267
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 includestuff = includestuff + """ |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 #include <%s>""" % MACHEADERFILE + """ |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */ |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 #ifdef THINK_C |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 #define ControlActionUPP ProcPtr |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 #endif |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 """ |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 finalstuff = finalstuff + """ |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 PyObject * |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 CtlObj_WhichControl(ControlHandle c) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 { |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 PyObject *it; |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 /* XXX What if we find a control belonging to some other package? */ |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 if (c == NULL) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 it = NULL; |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 else |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 it = (PyObject *) GetCRefCon(c); |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 if (it == NULL || ((ControlObject *)it)->ob_itself != c) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 it = Py_None; |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 Py_INCREF(it); |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 return it; |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 } |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 """ |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 class MyObjectDefinition(GlobalObjectDefinition): |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 def outputCheckNewArg(self): |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 def outputInitStructMembers(self): |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 GlobalObjectDefinition.outputInitStructMembers(self) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 Output("SetCRefCon(itself, (long)it);") |
|
3516
7879f3b39606
Fixed a nasty bug where FindControl could return a reference to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
3499
diff
changeset
|
71 def outputCleanupStructMembers(self): |
|
4348
852ca23c80cc
Fixed very nasty null-dereferencing bug in DisposeControl/destroy
Jack Jansen <jack.jansen@cwi.nl>
parents:
3516
diff
changeset
|
72 Output("if (self->ob_itself) SetCRefCon(self->ob_itself, (long)0); /* Make it forget about us */") |
|
3516
7879f3b39606
Fixed a nasty bug where FindControl could return a reference to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
3499
diff
changeset
|
73 |
|
2267
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 # Create the generator groups and link them |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 module.addobject(object) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 # Create the generator classes used to populate the lists |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 Function = OSErrFunctionGenerator |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 Method = OSErrMethodGenerator |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 # Create and populate the lists |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 functions = [] |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 methods = [] |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 execfile(INPUTFILE) |
|
2751
ae64003b2a75
Added as_Resource() method to convert ctl object to res object
Jack Jansen <jack.jansen@cwi.nl>
parents:
2723
diff
changeset
|
87 execfile('ctledit.py') |
|
2267
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 # add the populated lists to the generator groups |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 for f in functions: module.add(f) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 for f in methods: object.add(f) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 # generate output (open the output file as late as possible) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 SetOutputFileName(OUTPUTFILE) |
|
7411b6a06920
Committed a more or less working version.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 module.generate() |
