annotate Mac/Python/macshlglue.c @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents f840bf6a3351
children e8a263db1be0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5079
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
1 /***********************************************************
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
3 The Netherlands.
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
4
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
5 All Rights Reserved
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
6
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
8 documentation for any purpose and without fee is hereby granted,
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
9 provided that the above copyright notice appear in all copies and that
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
10 both that copyright notice and this permission notice appear in
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
14 distribution of the software without specific, written prior
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
15 permission.
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
16
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
17 While CWI is the initial source for this software, a modified version
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
18 is made available by the Corporation for National Research Initiatives
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
20
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
29
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
30 ******************************************************************/
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4120
diff changeset
31
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 /*
4120
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
33 ** Shared library initialization code.
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
34 **
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
35 ** This code calls the MetroWerks shared-library initialization code
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
36 ** and performs one extra step: it remembers the FSSpec of the file
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
37 ** we are loaded from, so we can later call PyMac_AddLibResources to
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
38 ** add the file to our resource file chain.
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
39 **
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
40 ** This file is needed for PythonCore and for any dynamically loaded
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
41 ** module that has interesting resources in its .slb file.
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
42 ** Use by replacing __initialize in the "CFM preferences" init field
650031e1e419 Always call __initialize(), also on PPC
Jack Jansen <jack.jansen@cwi.nl>
parents: 4023
diff changeset
43 ** by __initialize_with_resources.
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 */
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45
5430
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
46 #include <Types.h>
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 #include <Quickdraw.h>
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 #include <SegLoad.h>
5153
1ae7e2ebc2f3 - Changed GestaltEqu.h to Gestalt.h
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
49 #include <CodeFragments.h>
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 #include <Files.h>
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 #include <Resources.h>
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52
13702
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 8791
diff changeset
53 /* Defined in the MSL runtime: */
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 8791
diff changeset
54 extern void __initialize(void);
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 8791
diff changeset
55
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 8791
diff changeset
56 /* Defined either in macglue.c or in a MPW library: */
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 8791
diff changeset
57 extern pascal int PLstrcmp(unsigned char *, unsigned char *);
f840bf6a3351 Added more prototypes.
Jack Jansen <jack.jansen@cwi.nl>
parents: 8791
diff changeset
58
2410
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
59 /*
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
60 ** Variables passed from shared lib initialization to PyMac_AddLibResources.
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
61 */
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
62 static int library_fss_valid;
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
63 static FSSpec library_fss;
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
64
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 /*
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 ** Routine called upon fragment load. We attempt to save the FSSpec from which we're
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 ** loaded. We always return noErr (we just continue without the resources).
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 */
2410
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
69 OSErr pascal
5430
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
70 __initialize_with_resources(CFragInitBlockPtr data)
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 {
4016
938918ff3537 Guido: changed __sinit to __initialize for CFM68K.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3424
diff changeset
72 /* Call the MW runtime's initialization routine */
938918ff3537 Guido: changed __sinit to __initialize for CFM68K.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3424
diff changeset
73 __initialize();
3424
24bee3783b35 Added __sinit() call, so C++ initializations in shared library work
Jack Jansen <jack.jansen@cwi.nl>
parents: 3401
diff changeset
74
2410
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
75 if ( data == nil ) return noErr;
5430
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
76 if ( data->fragLocator.where == kDataForkCFragLocator ) {
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 library_fss = *data->fragLocator.u.onDisk.fileSpec;
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 library_fss_valid = 1;
5430
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
79 } else if ( data->fragLocator.where == kResourceCFragLocator ) {
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 library_fss = *data->fragLocator.u.inSegs.fileSpec;
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 library_fss_valid = 1;
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 }
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 return noErr;
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84 }
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 /*
8791
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
87 ** compare two FSSpecs, return true if equal, false if different
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
88 ** XXX where could this function live? (jvr)
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
89 */
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
90
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
91 static int
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
92 FSpCompare(FSSpec *fss1, FSSpec *fss2) {
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
93 if (fss1->vRefNum != fss2->vRefNum)
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
94 return 0;
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
95 if (fss1->parID != fss2->parID)
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
96 return 0;
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
97 return !PLstrcmp(fss1->name, fss2->name);
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
98 }
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
99
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
100 /* XXX can't include "macglue.h" somehow (jvr) */
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
101 extern FSSpec PyMac_ApplicationFSSpec; /* Application location (from macargv.c) */
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
102
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
103 /*
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 ** Insert the library resources into the search path. Put them after
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 ** the resources from the application (which we assume is the current
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 ** resource file). Again, we ignore errors.
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 */
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 void
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109 PyMac_AddLibResources()
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 {
8791
33d59336e7e6 Don't add the library file to the resource file chain if it is the
Jack Jansen <jack.jansen@cwi.nl>
parents: 5430
diff changeset
111 if ( !library_fss_valid || FSpCompare(&library_fss, &PyMac_ApplicationFSSpec))
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 return;
3189
02c8f74d08dc Removed unused variables
Jack Jansen <jack.jansen@cwi.nl>
parents: 2727
diff changeset
113 (void)FSpOpenResFile(&library_fss, fsRdPerm);
2316
ed821a99ba39 Glue for the python shared library: an init routine that remembers
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 }
2410
403a5631214b ported to CFM-68K
Guido van Rossum <guido@python.org>
parents: 2332
diff changeset
115
5430
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
116 /*
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
117 ** Dummy main() program to keep linker happy: we want to
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
118 ** use the MW AppRuntime in our shared library (better than building
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
119 ** custom runtime libraries as we did before) but AppRuntime
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
120 ** expects a main program. Note that it
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
121 */
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
122
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
123 #pragma export off
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
124 int
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
125 main(int argc, char **argv) {
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
126 DebugStr("\pCannot happen: PythonCore dummy main called!");
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
127 }
2329ccf0e581 - Various names in CodeFragments.h have changed
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
128 #pragma export reset