annotate Mac/Python/macimport.c @ 18386:8cdff545cbde legacy-trunk

Set the default 8-bit encoding based on the system script and language.
author unknown <tools@python.org>
date Wed, 04 Jul 2001 22:37:19 +0000
parents 9734f895f4fb
children d3268d62e462
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>
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
50 #include <StringCompare.h>
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9332
diff changeset
52 #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
53 #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
54 #endif
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
55
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 typedef void (*dl_funcptr)();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 #define FUNCNAME_PATTERN "init%.200s"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
59 static int
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
60 fssequal(FSSpec *fs1, FSSpec *fs2)
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
61 {
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
62 if ( fs1->vRefNum != fs2->vRefNum || fs1->parID != fs2->parID )
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
63 return 0;
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
64 return EqualString(fs1->name, fs2->name, false, true);
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
65 }
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 ** 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
68 ** 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
69 ** 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
70 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 static int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 findnamedresource(
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 PyStringObject *obj,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 char *module,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 char *filename,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 OSType restype,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 StringPtr dataptr)
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 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 FInfo finfo;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 short oldrh, filerh;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 int ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 Handle h;
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 #ifdef INTERN_STRINGS
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 ** 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
88 ** 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
89 ** 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
90 ** 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
91 ** as resource files again.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 #define MAXPATHCOMPONENTS 32
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 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
95 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
96 int i;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 if (obj && obj->ob_sinterned ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 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
100 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
101 return 0;
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 #endif /* INTERN_STRINGS */
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
104 #ifdef USE_GUSI1
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
105 if ( Path2FSSpec(filename, &fss) != noErr ) {
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
106 #else
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
107 if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr ) {
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
108 #endif
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
109 #ifdef INTERN_STRINGS
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
110 if ( obj && max_not_a_file < MAXPATHCOMPONENTS && obj->ob_sinterned )
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
111 not_a_file[max_not_a_file++] = obj;
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
112 #endif /* INTERN_STRINGS */
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
113 /* doesn't exist or is folder */
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
114 return 0;
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
115 }
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
116 if ( fssequal(&fss, &PyMac_ApplicationFSSpec) ) {
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 ** 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
119 ** 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
120 ** (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
121 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 UseResFile(PyMac_AppRefNum);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 filerh = -1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 #ifdef INTERN_STRINGS
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
127 if ( FSpGetFInfo(&fss, &finfo) != noErr ) {
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 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
129 not_a_file[max_not_a_file++] = obj;
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
130 /* doesn't exist or is folder */
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 }
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
133 #endif /* INTERN_STRINGS */
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135 filerh = FSpOpenResFile(&fss, fsRdPerm);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 if ( filerh == -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
137 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 UseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140 if ( dataptr == NULL )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 SetResLoad(0);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 h = Get1NamedResource(restype, Pstring(module));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 SetResLoad(1);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 ok = (h != NULL);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145 if ( ok && dataptr != NULL ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 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
147 /* 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
148 #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
149 /* 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
150 *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
151 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
152 #else
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
153 /* 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
154 *dataptr = **h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 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
156 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
159 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
160 CloseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
162 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164
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 ** 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
167 ** 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
168 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 PyMac_FindResourceModule(obj, module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171 PyStringObject *obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175 int ok;
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 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
178 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180
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 ** 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
183 ** 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
184 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185 int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186 PyMac_FindCodeResourceModule(obj, module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187 PyStringObject *obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
188 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
191 int ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
192
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193 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
194 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
195 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
196
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
197
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
198 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
199 ** 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
200 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
201 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
202 PyMac_LoadCodeResourceModule(name, pathname)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
203 char *name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
204 char *pathname;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205 {
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
206 PyObject *m, *d, *s;
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
207 char funcname[258];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
208 char *lastdot, *shortname, *packagecontext;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
209 dl_funcptr p = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
210 Str255 fragmentname;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 CFragConnectionID connID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
212 Ptr mainAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
213 Str255 errMessage;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
214 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
215 char buf[512];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
216 Ptr symAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
217 CFragSymbolClass class;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
218
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
219 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
220 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
221 return m;
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 lastdot = strrchr(name, '.');
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
224 if (lastdot == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
225 packagecontext = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
226 shortname = name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
227 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
228 else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
229 packagecontext = name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
230 shortname = lastdot+1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
231 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
232 sprintf(funcname, FUNCNAME_PATTERN, shortname);
18275
9734f895f4fb Fixed bug that prevented shared libs that are submodules of a
Just van Rossum <just@letterror.com>
parents: 17898
diff changeset
233 if( !findnamedresource((PyStringObject *)0, name, pathname, 'PYD ', fragmentname)) {
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
234 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
235 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
236 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
237
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
238 /* Load the fragment
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
239 (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
240 err = GetSharedLibrary(fragmentname, kCompiledCFragArch,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
241 kLoadCFrag, &connID, &mainAddr,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
242 errMessage);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
243 if ( err ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244 sprintf(buf, "%.*s: %.200s",
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
245 errMessage[0], errMessage+1,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
246 PyMac_StrError(err));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
247 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
248 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
249 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
250 /* 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
251 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
252 if ( err ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
253 sprintf(buf, "%s: %.200s",
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
254 funcname, PyMac_StrError(err));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
255 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
256 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
257 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
258 p = (dl_funcptr)symAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
259 if (p == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
260 PyErr_Format(PyExc_ImportError,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
261 "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
262 funcname);
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 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
265 _Py_PackageContext = packagecontext;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
266 (*p)();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
267 _Py_PackageContext = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
268 if (PyErr_Occurred())
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
269 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
270 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
271 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
272
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
273 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
274 if (m == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
275 PyErr_SetString(PyExc_SystemError,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
276 "dynamic module not initialized properly");
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
277 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
278 }
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
279 #if 1
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
280 /* 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
281 d = PyModule_GetDict(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
282 s = PyString_FromString(pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
283 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
284 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
285 Py_XDECREF(s);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286 #endif
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287 if (Py_VerboseFlag)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
288 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
289 name, fragmentname, pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
290 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295 ** 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
296 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
297 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
298 PyMac_LoadResourceModule(module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
300 char *filename;
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 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303 FInfo finfo;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
304 short oldrh, filerh;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
305 Handle h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
306 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
307 PyObject *m, *co;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
308 long num, size;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
309
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
310 #ifdef USE_GUSI1
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
311 if ( (err=Path2FSSpec(filename, &fss)) != noErr ||
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
312 FSpGetFInfo(&fss, &finfo) != noErr )
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
313 #else
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
314 if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr )
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
315 #endif
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
316 goto error;
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
317 if ( fssequal(&fss, &PyMac_ApplicationFSSpec) ) {
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
318 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
319 ** 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
320 ** 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
321 ** (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
322 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
323 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
324 UseResFile(PyMac_AppRefNum);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
325 filerh = -1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
326 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
327 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
328 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
329 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
330 filerh = FSpOpenResFile(&fss, fsRdPerm);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
331 if ( filerh == -1 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
332 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
333 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
334 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
335 UseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
336 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
337 h = Get1NamedResource('PYC ', Pstring(module));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
338 if ( h == NULL ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
339 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
340 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
341 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
342 HLock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
343 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
344 ** 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
345 ** 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
346 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
347 size = GetHandleSize(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
348 if ( size < 8 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
349 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
350 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
351 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
352 num = (*h)[0] & 0xff;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
353 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
354 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
355 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
356 if ( num != PyImport_GetMagicNumber() ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
357 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
358 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
359 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
360 co = PyMarshal_ReadObjectFromString((*h)+8, size-8);
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
361 /*
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
362 ** 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
363 ** 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
364 ** 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
365 ** See also py_resource.py. (jvr)
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
366 */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
367 if ((*h)[4] & 0xff) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
368 /* it's a package */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
369 /* Set __path__ to the package name */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
370 PyObject *d, *s;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
371 int err;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
372
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
373 m = PyImport_AddModule(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
374 if (m == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
375 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
376 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
377 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
378 d = PyModule_GetDict(m);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
379 s = PyString_InternFromString(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
380 if (s == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
381 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
382 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
383 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
384 err = PyDict_SetItemString(d, "__path__", s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
385 Py_DECREF(s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
386 if (err != 0) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
387 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
388 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
389 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
390 }
8665
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 }
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
393 packageerror:
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
394 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
395 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
396 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
397 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
398 ReleaseResource(h);
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
399 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
400 if ( co ) {
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
401 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
402 Py_DECREF(co);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
403 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
404 m = NULL;
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 if (Py_VerboseFlag)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
407 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
408 module, filename);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
409 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
410 error:
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
411 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
412 char buf[512];
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 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
415 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
416 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
417 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
418 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
419
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 ** 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
422 ** 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
423 ** 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
424 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
425 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
426 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
427 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
428 struct filedescr *fdp;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
429 unsigned char fnbuf[64];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
430 int modnamelen = strlen(module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
431 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
432 #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
433 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
434 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
435 short refnum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
436 long dirid;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
437
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
438 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
439 ** 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
440 ** 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
441 ** lucky and return immedeately.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
442 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
443 if ( !_PyImport_Filetab[0].suffix )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
444 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
445
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
446 #if 0
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
447 /* Pre 1.5a4 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
448 strcpy(buf+*lenp, module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
449 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
450 #else
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
451 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
452 #endif
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9332
diff changeset
453 #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
454 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
455 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
456 return _PyImport_Filetab;
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
457 #else
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
458 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
459 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
460 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
461 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
462 ** 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
463 ** 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
464 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
465 refnum = fss.vRefNum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
466 dirid = fss.parID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
467 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
468 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
469 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
470 ** 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
471 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
472 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
473 strcpy((char *)fnbuf+1, module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
474
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
475 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
476 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
477 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
478 if (Py_VerboseFlag > 1)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
479 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
480 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
481 /* Found it. */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
482 #if 0
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
483 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
484 #else
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
485 strcpy(buf+*lenp, fdp->suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
486 #endif
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
487 *lenp = strlen(buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
488 return fdp;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
489 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
490 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
491 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
492 }