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

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents ba6a7a5c32e8
children 5f2dcdd09329
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 /* 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
149 *dataptr = **h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 memcpy(dataptr+1, (*h)+1, (int)*dataptr);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154 CloseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 }
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 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
160 ** 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
161 ** 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
162 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163 int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 PyMac_FindResourceModule(obj, module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
165 PyStringObject *obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
166 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 char *filename;
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 ok;
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 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
172 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 }
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 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 ** 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
177 ** 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
178 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180 PyMac_FindCodeResourceModule(obj, module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
181 PyStringObject *obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 char *filename;
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 ok;
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 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
188 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189 }
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
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 ** 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
194 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
195 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
196 PyMac_LoadCodeResourceModule(name, pathname)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
197 char *name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
198 char *pathname;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
199 {
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
200 PyObject *m, *d, *s;
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
201 char funcname[258];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
202 char *lastdot, *shortname, *packagecontext;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
203 dl_funcptr p = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
204 Str255 fragmentname;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205 CFragConnectionID connID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
206 Ptr mainAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
207 Str255 errMessage;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
208 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
209 char buf[512];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
210 Ptr symAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 CFragSymbolClass class;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
212
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
213 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
214 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
215 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
216 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
217 lastdot = strrchr(name, '.');
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
218 if (lastdot == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
219 packagecontext = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
220 shortname = name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
221 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
222 else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
223 packagecontext = name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
224 shortname = lastdot+1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
225 }
21245
ba6a7a5c32e8 Replace sprintf() with PyOS_snprintf().
Jack Jansen <jack.jansen@cwi.nl>
parents: 20876
diff changeset
226 PyOS_snprintf(funcname, sizeof(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
227 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
228 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
229 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
230 }
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 /* Load the fragment
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
233 (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
234 err = GetSharedLibrary(fragmentname, kCompiledCFragArch,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
235 kLoadCFrag, &connID, &mainAddr,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
236 errMessage);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
237 if ( err ) {
21245
ba6a7a5c32e8 Replace sprintf() with PyOS_snprintf().
Jack Jansen <jack.jansen@cwi.nl>
parents: 20876
diff changeset
238 PyOS_snprintf(buf, sizeof(buf), "%.*s: %.200s",
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
239 errMessage[0], errMessage+1,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
240 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 /* 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
245 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
246 if ( err ) {
21245
ba6a7a5c32e8 Replace sprintf() with PyOS_snprintf().
Jack Jansen <jack.jansen@cwi.nl>
parents: 20876
diff changeset
247 PyOS_snprintf(buf, sizeof(buf), "%s: %.200s",
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
248 funcname, PyMac_StrError(err));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
249 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
250 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
251 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
252 p = (dl_funcptr)symAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
253 if (p == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
254 PyErr_Format(PyExc_ImportError,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
255 "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
256 funcname);
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 _Py_PackageContext = packagecontext;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
260 (*p)();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
261 _Py_PackageContext = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
262 if (PyErr_Occurred())
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 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
265 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
266
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
267 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
268 if (m == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
269 PyErr_SetString(PyExc_SystemError,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
270 "dynamic module not initialized properly");
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 }
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
273 #if 1
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
274 /* 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
275 d = PyModule_GetDict(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
276 s = PyString_FromString(pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
277 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
278 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
279 Py_XDECREF(s);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
280 #endif
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
281 if (Py_VerboseFlag)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
282 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
283 name, fragmentname, pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
284 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
285 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 ** 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
290 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292 PyMac_LoadResourceModule(module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
296 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
297 FInfo finfo;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
298 short oldrh, filerh;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 Handle h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
300 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
301 PyObject *m, *co;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
302 long num, size;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
304 #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
305 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
306 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
307 #else
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
308 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
309 #endif
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
310 goto error;
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
311 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
312 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
313 ** 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
314 ** 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
315 ** (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
316 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
317 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
318 UseResFile(PyMac_AppRefNum);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
319 filerh = -1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
320 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
321 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
322 goto error;
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 filerh = FSpOpenResFile(&fss, fsRdPerm);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
325 if ( filerh == -1 ) {
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 UseResFile(filerh);
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 h = Get1NamedResource('PYC ', Pstring(module));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
332 if ( h == NULL ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
333 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
334 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
335 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
336 HLock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
337 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
338 ** 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
339 ** 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
340 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
341 size = GetHandleSize(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
342 if ( size < 8 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
343 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
344 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
345 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
346 num = (*h)[0] & 0xff;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
347 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
348 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
349 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
350 if ( num != PyImport_GetMagicNumber() ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
351 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
352 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
353 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
354 co = PyMarshal_ReadObjectFromString((*h)+8, size-8);
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
355 /*
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
356 ** 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
357 ** 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
358 ** 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
359 ** See also py_resource.py. (jvr)
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
360 */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
361 if ((*h)[4] & 0xff) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
362 /* it's a package */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
363 /* Set __path__ to the package name */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
364 PyObject *d, *s;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
365 int err;
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 m = PyImport_AddModule(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
368 if (m == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
369 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
370 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
371 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
372 d = PyModule_GetDict(m);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
373 s = PyString_InternFromString(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
374 if (s == 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 err = PyDict_SetItemString(d, "__path__", s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
379 Py_DECREF(s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
380 if (err != 0) {
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 }
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
385 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
386 }
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
387 packageerror:
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
388 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
389 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
390 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
391 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
392 ReleaseResource(h);
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
393 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
394 if ( co ) {
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
395 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
396 Py_DECREF(co);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
397 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
398 m = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
399 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
400 if (Py_VerboseFlag)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
401 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
402 module, filename);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
403 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
404 error:
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 char buf[512];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
407
21245
ba6a7a5c32e8 Replace sprintf() with PyOS_snprintf().
Jack Jansen <jack.jansen@cwi.nl>
parents: 20876
diff changeset
408 PyOS_snprintf(buf, sizeof(buf), "%s: %s", filename, PyMac_StrError(err));
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
409 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
410 return NULL;
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 }
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 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
415 ** 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
416 ** 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
417 ** 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
418 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
419 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
420 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
421 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
422 struct filedescr *fdp;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
423 unsigned char fnbuf[64];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
424 int modnamelen = strlen(module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
425 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
426 #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
427 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
428 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
429 short refnum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
430 long dirid;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
431
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
432 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
433 ** 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
434 ** 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
435 ** lucky and return immedeately.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
436 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
437 if ( !_PyImport_Filetab[0].suffix )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
438 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
439
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
440 strcpy(buf+*lenp, _PyImport_Filetab[0].suffix);
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9332
diff changeset
441 #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
442 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
443 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
444 return _PyImport_Filetab;
618fb830be65 Mods by Just to allow aliases in sys.path entries
Jack Jansen <jack.jansen@cwi.nl>
parents: 9007
diff changeset
445 #else
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
446 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
447 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
448 #endif
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
449 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
450 ** 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
451 ** 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
452 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
453 refnum = fss.vRefNum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
454 dirid = fss.parID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
455 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
456 return 0;
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 ** 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
459 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
460 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
461 strcpy((char *)fnbuf+1, module);
20876
27874c860268 MacPython -vv equivalent printed incorrect filenames, fixed. Also
Jack Jansen <jack.jansen@cwi.nl>
parents: 19032
diff changeset
462 buf[*lenp] = '\0';
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
463
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
464 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
465 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
466 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
467 if (Py_VerboseFlag > 1)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
468 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
469 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
470 /* Found it. */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
471 strcpy(buf+*lenp, fdp->suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
472 return fdp;
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 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
475 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
476 }