annotate Mac/Python/macimport.c @ 9073:618fb830be65 legacy-trunk

Mods by Just to allow aliases in sys.path entries
author Jack Jansen <jack.jansen@cwi.nl>
date Mon, 07 Sep 1998 11:36:17 +0000
parents ff1a8a38f8c1
children 462ccd0bbe50
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
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
51 #ifdef USE_GUSI
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 {
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
107 #ifdef USE_GUSI
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)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
274 fprintf(stderr,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
275 "import %s # pyd fragment %#s loaded from %s\n",
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
276 name, fragmentname, pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
277 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
278 return m;
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 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
282 ** 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
283 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
284 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
285 PyMac_LoadResourceModule(module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
290 FInfo finfo;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 short oldrh, filerh;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292 Handle h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 PyObject *m, *co;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295 long num, size;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
296
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
297 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
298 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 ** 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
300 ** 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
301 ** (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
302 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
304 UseResFile(PyMac_AppRefNum);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
305 filerh = -1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
306 } else {
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
307 #ifdef USE_GUSI
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
308 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
309 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
310 #else
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
311 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
312 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
313 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
314 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
315 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
316 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
317 filerh = FSpOpenResFile(&fss, fsRdPerm);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
318 if ( filerh == -1 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
319 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
320 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
321 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
322 UseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
323 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
324 h = Get1NamedResource('PYC ', Pstring(module));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
325 if ( h == NULL ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
326 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
327 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
328 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
329 HLock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
330 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
331 ** 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
332 ** 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
333 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
334 size = GetHandleSize(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
335 if ( size < 8 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
336 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
337 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
338 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
339 num = (*h)[0] & 0xff;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
340 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
341 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
342 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
343 if ( num != PyImport_GetMagicNumber() ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
344 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
345 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
346 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
347 co = PyMarshal_ReadObjectFromString((*h)+8, size-8);
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
348 /*
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
349 ** 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
350 ** 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
351 ** 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
352 ** See also py_resource.py. (jvr)
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
353 */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
354 if ((*h)[4] & 0xff) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
355 /* it's a package */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
356 /* Set __path__ to the package name */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
357 PyObject *d, *s;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
358 int err;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
359
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
360 m = PyImport_AddModule(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
361 if (m == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
362 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
363 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
364 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
365 d = PyModule_GetDict(m);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
366 s = PyString_InternFromString(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
367 if (s == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
368 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
369 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
370 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
371 err = PyDict_SetItemString(d, "__path__", s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
372 Py_DECREF(s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
373 if (err != 0) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
374 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
375 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
376 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
377 }
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
378 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
379 }
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
380 packageerror:
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
381 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
382 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
383 CloseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
384 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
385 if ( co ) {
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
386 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
387 Py_DECREF(co);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
388 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
389 m = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
390 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
391 if (Py_VerboseFlag)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
392 fprintf(stderr, "import %s # pyc resource from %s\n",
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
393 module, filename);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
394 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
395 error:
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
396 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
397 char buf[512];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
398
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
399 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
400 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
401 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
402 }
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 ** 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
407 ** 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
408 ** 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
409 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
410 struct filedescr *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
411 PyMac_FindModuleExtension(char *buf, int *lenp, char *module)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
412 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
413 struct filedescr *fdp;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
414 unsigned char fnbuf[64];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
415 int modnamelen = strlen(module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
416 FSSpec fss;
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
417 FInfo finfo;
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
418 short refnum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
419 long dirid;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
420
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
421 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
422 ** 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
423 ** 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
424 ** lucky and return immedeately.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
425 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
426 if ( !_PyImport_Filetab[0].suffix )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
427 return 0;
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 0
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
430 /* Pre 1.5a4 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
431 strcpy(buf+*lenp, module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
432 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
433 #else
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
434 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
435 #endif
9073
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
436 #ifdef USE_GUSI
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
437 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
438 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
439 return _PyImport_Filetab;
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
440 #else
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
441 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
442 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
443 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
444 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
445 ** 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
446 ** 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
447 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
448 refnum = fss.vRefNum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
449 dirid = fss.parID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
450 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
451 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
452 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
453 ** 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
454 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
455 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
456 strcpy((char *)fnbuf+1, module);
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 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
459 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
460 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
461 if (Py_VerboseFlag > 1)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
462 fprintf(stderr, "# trying %s%s\n", buf, fdp->suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
463 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
464 /* Found it. */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
465 #if 0
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
466 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
467 #else
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
468 strcpy(buf+*lenp, fdp->suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
469 #endif
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
470 *lenp = strlen(buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
471 return fdp;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
472 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
473 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
474 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
475 }