annotate Mac/Python/macapplication.c @ 16727:800b004acc71 legacy-trunk

Release a PYC resource after reading it. No need to keep it incore.
author Jack Jansen <jack.jansen@cwi.nl>
date Wed, 21 Feb 2001 15:48:19 +0000
parents db963a615bc9
children d3268d62e462
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2426
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 /***********************************************************
5079
d6b292a33cfe Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents: 4021
diff changeset
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
2426
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 The Netherlands.
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 All Rights Reserved
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 ******************************************************************/
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24
10171
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
25 /* Macintosh Python main program for both applets and interpreter */
2426
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26
10171
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
27 #include <Resources.h>
11643
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
28 #include <CodeFragments.h>
10171
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
29
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
30 #ifdef __CFM68K__
2426
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 #pragma lib_export on
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 #endif
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 11643
diff changeset
34 extern void PyMac_InitApplication(void);
10174
744db86e0311 Put the applet code inside USE_MAC_APPLET_SUPPORT ifdefs, to make 68k standalone Python compile.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10171
diff changeset
35 #ifdef USE_MAC_APPLET_SUPPORT
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 11643
diff changeset
36 extern void PyMac_InitApplet(void);
10174
744db86e0311 Put the applet code inside USE_MAC_APPLET_SUPPORT ifdefs, to make 68k standalone Python compile.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10171
diff changeset
37 #endif /* USE_MAC_APPLET_SUPPORT */
2426
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 11643
diff changeset
39 /* From the MSL runtime: */
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 11643
diff changeset
40 extern void __initialize(void);
11643
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
41
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
42 /*
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
43 ** Alternative initialization entry point for some very special cases.
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
44 ** Use this in stead of __initialize in the PEF settings to remember (and
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
45 ** re-open as resource file) the application. This is needed if we link against
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
46 ** a dynamic library that, in its own __initialize routine, opens a resource
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
47 ** file. This would mess up our finding of override preferences.
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
48 ** Only set this entrypoint in your apps if you notice sys.path or some such is
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
49 ** messed up.
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
50 */
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
51 static int application_fss_valid;
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
52 static FSSpec application_fss;
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
53
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
54 OSErr pascal
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
55 __initialize_remember_app_fsspec(CFragInitBlockPtr data)
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
56 {
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
57 /* Call the MW runtime's initialization routine */
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
58 __initialize();
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
59 if ( data == nil ) return noErr;
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
60 if ( data->fragLocator.where == kDataForkCFragLocator ) {
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
61 application_fss = *data->fragLocator.u.onDisk.fileSpec;
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
62 application_fss_valid = 1;
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
63 } else if ( data->fragLocator.where == kResourceCFragLocator ) {
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
64 application_fss = *data->fragLocator.u.inSegs.fileSpec;
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
65 application_fss_valid = 1;
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
66 }
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
67 return noErr;
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
68 }
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
69
4021
cf2630a41f87 Removed debug printf
Jack Jansen <jack.jansen@cwi.nl>
parents: 3422
diff changeset
70 void
2426
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 main() {
11643
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
72 if ( application_fss_valid )
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
73 (void)FSpOpenResFile(&application_fss, fsRdPerm);
10174
744db86e0311 Put the applet code inside USE_MAC_APPLET_SUPPORT ifdefs, to make 68k standalone Python compile.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10171
diff changeset
74 #ifdef USE_MAC_APPLET_SUPPORT
11643
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
75 {
10171
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
76 Handle mainpyc;
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
77
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
78 mainpyc = Get1NamedResource('PYC ', "\p__main__");
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
79 if (mainpyc != NULL)
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
80 PyMac_InitApplet();
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
81 else
73e5e3f51b87 (finally) unified the interpreter and the applet as Just suggested ages ago. The
Jack Jansen <jack.jansen@cwi.nl>
parents: 5079
diff changeset
82 PyMac_InitApplication();
11643
86890c073c3b Added initializer routine optionally to be used as PEF fragment initialization routine, which allows us to get at our own resource fork even if some shared library init routine opens other resource files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10174
diff changeset
83 }
10174
744db86e0311 Put the applet code inside USE_MAC_APPLET_SUPPORT ifdefs, to make 68k standalone Python compile.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10171
diff changeset
84 #else
744db86e0311 Put the applet code inside USE_MAC_APPLET_SUPPORT ifdefs, to make 68k standalone Python compile.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10171
diff changeset
85 PyMac_InitApplication();
744db86e0311 Put the applet code inside USE_MAC_APPLET_SUPPORT ifdefs, to make 68k standalone Python compile.
Jack Jansen <jack.jansen@cwi.nl>
parents: 10171
diff changeset
86 #endif /* USE_MAC_APPLET_SUPPORT */
2426
9bf18996eed8 MAde a few things more orthogonal and did some cleanups:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 }