annotate Mac/Python/macimport.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 5d50d1fae078
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 /***********************************************************
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 The Netherlands.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 All Rights Reserved
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 ******************************************************************/
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 #include "Python.h"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 #include "macglue.h"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 #include "marshal.h"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 #include "import.h"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 #include "importdl.h"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 #include "pythonresources.h"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 #include <Types.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 #include <Files.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 #include <Resources.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 #if 0
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 #include <OSUtils.h> /* for Set(Current)A5 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 #include <StandardFile.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 #include <Memory.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 #include <Windows.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 #include <Traps.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 #include <Processes.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 #include <Fonts.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 #include <Menus.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 #include <TextUtils.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 #endif
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 #include <CodeFragments.h>
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9332
diff changeset
51 #ifdef USE_GUSI1
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
52 #include "TFileSpec.h" /* for Path2FSSpec() */
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
53 #endif
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
54
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 typedef void (*dl_funcptr)();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 #define FUNCNAME_PATTERN "init%.200s"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 ** findnamedresource - Common code for the various *ResourceModule functions.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 ** Check whether a file contains a resource of the correct name and type, and
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 ** optionally return the value in it.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 static int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 findnamedresource(
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 PyStringObject *obj,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 char *module,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 char *filename,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 OSType restype,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69 StringPtr dataptr)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 FInfo finfo;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 short oldrh, filerh;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 int ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 Handle h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 #ifdef INTERN_STRINGS
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 ** If we have interning find_module takes care of interning all
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 ** sys.path components. We then keep a record of all sys.path
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 ** components for which GetFInfo has failed (usually because the
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 ** component in question is a folder), and we don't try opening these
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 ** as resource files again.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 #define MAXPATHCOMPONENTS 32
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 static PyStringObject *not_a_file[MAXPATHCOMPONENTS];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 static int max_not_a_file = 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 int i;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 if (obj && obj->ob_sinterned ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 for( i=0; i< max_not_a_file; i++ )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 if ( obj == not_a_file[i] )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 #endif /* INTERN_STRINGS */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 ** Special case: the application itself. Use a shortcut to
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 ** forestall opening and closing the application numerous times
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 ** (which is dead slow when running from CDROM)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 UseResFile(PyMac_AppRefNum);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 filerh = -1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 } else {
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9332
diff changeset
107 #ifdef USE_GUSI1
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
108 if ( Path2FSSpec(filename, &fss) != noErr ||
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
109 #else
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr ||
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
111 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 FSpGetFInfo(&fss, &finfo) != noErr ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 #ifdef INTERN_STRINGS
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 if ( obj && max_not_a_file < MAXPATHCOMPONENTS && obj->ob_sinterned )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 not_a_file[max_not_a_file++] = obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 #endif /* INTERN_STRINGS */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 /* doesn't exist or is folder */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 filerh = FSpOpenResFile(&fss, fsRdPerm);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 if ( filerh == -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 UseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 if ( dataptr == NULL )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 SetResLoad(0);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 h = Get1NamedResource(restype, Pstring(module));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 SetResLoad(1);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 ok = (h != NULL);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 if ( ok && dataptr != NULL ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 HLock(h);
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
133 /* XXXX Unsafe if resource not correctly formatted! */
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
134 #ifdef __CFM68K__
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
135 /* for cfm68k we take the second pstring */
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
136 *dataptr = *((*h)+(**h)+1);
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
137 memcpy(dataptr+1, (*h)+(**h)+2, (int)*dataptr);
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
138 #else
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
139 /* for ppc we take the first pstring */
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140 *dataptr = **h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 memcpy(dataptr+1, (*h)+1, (int)*dataptr);
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
142 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 CloseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
147 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
148 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 ** Returns true if the argument has a resource fork, and it contains
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 ** a 'PYC ' resource of the correct name
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 PyMac_FindResourceModule(obj, module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 PyStringObject *obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
159 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
160 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161 int ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
162
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163 ok = findnamedresource(obj, module, filename, 'PYC ', (StringPtr)0);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
165 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
166
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168 ** Returns true if the argument has a resource fork, and it contains
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 ** a 'PYD ' resource of the correct name
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171 int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172 PyMac_FindCodeResourceModule(obj, module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 PyStringObject *obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
177 int ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
178
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 ok = findnamedresource(obj, module, filename, 'PYD ', (StringPtr)0);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
181 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185 ** Load the specified module from a code resource
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
188 PyMac_LoadCodeResourceModule(name, pathname)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189 char *name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190 char *pathname;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
191 {
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
192 PyObject *m, *d, *s;
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193 char funcname[258];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
194 char *lastdot, *shortname, *packagecontext;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
195 dl_funcptr p = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
196 Str255 fragmentname;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
197 CFragConnectionID connID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
198 Ptr mainAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
199 Str255 errMessage;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
200 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
201 char buf[512];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
202 Ptr symAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
203 CFragSymbolClass class;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
204
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205 if ((m = _PyImport_FindExtension(name, name)) != NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
206 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
207 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
208 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
209 lastdot = strrchr(name, '.');
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
210 if (lastdot == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 packagecontext = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
212 shortname = name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
213 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
214 else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
215 packagecontext = name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
216 shortname = lastdot+1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
217 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
218 sprintf(funcname, FUNCNAME_PATTERN, shortname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
219 if( !findnamedresource((PyStringObject *)0, shortname, pathname, 'PYD ', fragmentname)) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
220 PyErr_SetString(PyExc_ImportError, "PYD resource not found");
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
221 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
222 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
223
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
224 /* Load the fragment
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
225 (or return the connID if it is already loaded */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
226 err = GetSharedLibrary(fragmentname, kCompiledCFragArch,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
227 kLoadCFrag, &connID, &mainAddr,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
228 errMessage);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
229 if ( err ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
230 sprintf(buf, "%.*s: %.200s",
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
231 errMessage[0], errMessage+1,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
232 PyMac_StrError(err));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
233 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
234 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
235 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
236 /* Locate the address of the correct init function */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
237 err = FindSymbol(connID, Pstring(funcname), &symAddr, &class);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
238 if ( err ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
239 sprintf(buf, "%s: %.200s",
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
240 funcname, PyMac_StrError(err));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
241 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
242 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
243 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244 p = (dl_funcptr)symAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
245 if (p == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
246 PyErr_Format(PyExc_ImportError,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
247 "dynamic module does not define init function (%.200s)",
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
248 funcname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
249 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
250 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
251 _Py_PackageContext = packagecontext;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
252 (*p)();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
253 _Py_PackageContext = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
254 if (PyErr_Occurred())
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
255 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
256 if (_PyImport_FixupExtension(name, name) == NULL)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
257 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
258
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
259 m = PyDict_GetItemString(PyImport_GetModuleDict(), name);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
260 if (m == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
261 PyErr_SetString(PyExc_SystemError,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
262 "dynamic module not initialized properly");
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
263 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
264 }
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
265 #if 1
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
266 /* Remember the filename as the __file__ attribute */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
267 d = PyModule_GetDict(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
268 s = PyString_FromString(pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
269 if (s == NULL || PyDict_SetItemString(d, "__file__", s) != 0)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
270 PyErr_Clear(); /* Not important enough to report */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
271 Py_XDECREF(s);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
272 #endif
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
273 if (Py_VerboseFlag)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
274 PySys_WriteStderr("import %s # pyd fragment %#s loaded from %s\n",
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
275 name, fragmentname, pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
276 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
277 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
278 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
279
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
280 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
281 ** Load the specified module from a resource
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
282 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
283 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
284 PyMac_LoadResourceModule(module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
285 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 FInfo finfo;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
290 short oldrh, filerh;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 Handle h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293 PyObject *m, *co;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 long num, size;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
296 if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
297 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
298 ** Special case: the application itself. Use a shortcut to
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 ** forestall opening and closing the application numerous times
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
300 ** (which is dead slow when running from CDROM)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
301 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
302 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303 UseResFile(PyMac_AppRefNum);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
304 filerh = -1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
305 } else {
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9332
diff changeset
306 #ifdef USE_GUSI1
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
307 if ( (err=Path2FSSpec(filename, &fss)) != noErr ||
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
308 FSpGetFInfo(&fss, &finfo) != noErr )
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
309 #else
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
310 if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr )
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
311 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
312 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
313 if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
314 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
315 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
316 filerh = FSpOpenResFile(&fss, fsRdPerm);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
317 if ( filerh == -1 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
318 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
319 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
320 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
321 UseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
322 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
323 h = Get1NamedResource('PYC ', Pstring(module));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
324 if ( h == NULL ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
325 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
326 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
327 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
328 HLock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
329 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
330 ** XXXX The next few lines are intimately tied to the format of pyc
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
331 ** files. I'm not sure whether this code should be here or in import.c -- Jack
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
332 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
333 size = GetHandleSize(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
334 if ( size < 8 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
335 PyErr_SetString(PyExc_ImportError, "Resource too small");
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
336 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
337 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
338 num = (*h)[0] & 0xff;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
339 num = num | (((*h)[1] & 0xff) << 8);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
340 num = num | (((*h)[2] & 0xff) << 16);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
341 num = num | (((*h)[3] & 0xff) << 24);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
342 if ( num != PyImport_GetMagicNumber() ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
343 PyErr_SetString(PyExc_ImportError, "Bad MAGIC in resource");
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
344 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
345 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
346 co = PyMarshal_ReadObjectFromString((*h)+8, size-8);
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
347 /*
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
348 ** Normally, byte 4-7 are the time stamp, but that is not used
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
349 ** for 'PYC ' resources. We abuse byte 4 as a flag to indicate
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
350 ** that it is a package rather than an ordinary module.
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
351 ** See also py_resource.py. (jvr)
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
352 */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
353 if ((*h)[4] & 0xff) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
354 /* it's a package */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
355 /* Set __path__ to the package name */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
356 PyObject *d, *s;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
357 int err;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
358
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
359 m = PyImport_AddModule(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
360 if (m == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
361 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
362 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
363 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
364 d = PyModule_GetDict(m);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
365 s = PyString_InternFromString(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
366 if (s == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
367 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
368 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
369 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
370 err = PyDict_SetItemString(d, "__path__", s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
371 Py_DECREF(s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
372 if (err != 0) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
373 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
374 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
375 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
376 }
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
377 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
378 }
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
379 packageerror:
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
380 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
381 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
382 CloseResFile(filerh);
16727
800b004acc71 Release a PYC resource after reading it. No need to keep it incore.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13547
diff changeset
383 else
800b004acc71 Release a PYC resource after reading it. No need to keep it incore.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13547
diff changeset
384 ReleaseResource(h);
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
385 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
386 if ( co ) {
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
387 m = PyImport_ExecCodeModuleEx(module, co, "<pyc resource>");
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
388 Py_DECREF(co);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
389 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
390 m = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
391 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
392 if (Py_VerboseFlag)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
393 PySys_WriteStderr("import %s # pyc resource from %s\n",
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
394 module, filename);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
395 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
396 error:
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
397 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
398 char buf[512];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
399
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
400 sprintf(buf, "%s: %s", filename, PyMac_StrError(err));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
401 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
402 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
403 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
404 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
405
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
406 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
407 ** Look for a module in a single folder. Upon entry buf and len
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
408 ** point to the folder to search, upon exit they refer to the full
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
409 ** pathname of the module found (if any).
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
410 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
411 struct filedescr *
13333
89e47eba2771 PyMac_FindModuleExtension now uses a size_t as its size parameter for compatibility.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
412 PyMac_FindModuleExtension(char *buf, size_t *lenp, char *module)
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
413 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
414 struct filedescr *fdp;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
415 unsigned char fnbuf[64];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
416 int modnamelen = strlen(module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
417 FSSpec fss;
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13333
diff changeset
418 #ifdef USE_GUSI1
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
419 FInfo finfo;
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13333
diff changeset
420 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
421 short refnum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
422 long dirid;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
423
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
424 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
425 ** Copy the module name to the buffer (already :-terminated)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
426 ** We also copy the first suffix, if this matches immedeately we're
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
427 ** lucky and return immedeately.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
428 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
429 if ( !_PyImport_Filetab[0].suffix )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
430 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
431
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
432 #if 0
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
433 /* Pre 1.5a4 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
434 strcpy(buf+*lenp, module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
435 strcpy(buf+*lenp+modnamelen, _PyImport_Filetab[0].suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
436 #else
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
437 strcpy(buf+*lenp, _PyImport_Filetab[0].suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
438 #endif
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9332
diff changeset
439 #ifdef USE_GUSI1
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
440 if ( Path2FSSpec(buf, &fss) == noErr &&
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
441 FSpGetFInfo(&fss, &finfo) == noErr)
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
442 return _PyImport_Filetab;
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
443 #else
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
444 if ( FSMakeFSSpec(0, 0, Pstring(buf), &fss) == noErr )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
445 return _PyImport_Filetab;
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
446 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
447 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
448 ** We cannot check for fnfErr (unfortunately), it can mean either that
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
449 ** the file doesn't exist (fine, we try others) or the path leading to it.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
450 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
451 refnum = fss.vRefNum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
452 dirid = fss.parID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
453 if ( refnum == 0 || dirid == 0 ) /* Fail on nonexistent dir */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
454 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
455 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
456 ** We now have the folder parameters. Setup the field for the filename
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
457 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
458 if ( modnamelen > 54 ) return 0; /* Leave room for extension */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
459 strcpy((char *)fnbuf+1, module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
460
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
461 for( fdp = _PyImport_Filetab+1; fdp->suffix; fdp++ ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
462 strcpy((char *)fnbuf+1+modnamelen, fdp->suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
463 fnbuf[0] = strlen((char *)fnbuf+1);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
464 if (Py_VerboseFlag > 1)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
465 PySys_WriteStderr("# trying %s%s\n", buf, fdp->suffix);
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
466 if ( FSMakeFSSpec(refnum, dirid, fnbuf, &fss) == noErr ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
467 /* Found it. */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
468 #if 0
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
469 strcpy(buf+*lenp+modnamelen, fdp->suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
470 #else
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
471 strcpy(buf+*lenp, fdp->suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
472 #endif
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
473 *lenp = strlen(buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
474 return fdp;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
475 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
476 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
477 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
478 }