annotate Mac/Python/macimport.c @ 24012:e8a263db1be0 legacy-trunk

Changed some prototypes to match the exact definition in some faraway Apple header files. If we're building with precompiled headers these are in scope.
author Jack Jansen <jack.jansen@cwi.nl>
date Wed, 26 Jun 2002 20:37:40 +0000
parents 5f2dcdd09329
children 808b4fe5184f
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 #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
39 #include <StringCompare.h>
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 typedef void (*dl_funcptr)();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 #define FUNCNAME_PATTERN "init%.200s"
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
44 static int
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
45 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
46 {
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
47 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
48 return 0;
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
49 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
50 }
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 ** 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
53 ** 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
54 ** 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
55 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 static int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 findnamedresource(
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 PyStringObject *obj,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 char *module,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 char *filename,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 OSType restype,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 StringPtr dataptr)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 FInfo finfo;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 short oldrh, filerh;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 int ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 Handle h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69
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 ** 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
72 ** 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
73 ** 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
74 ** 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
75 ** as resource files again.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 #define MAXPATHCOMPONENTS 32
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 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
79 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
80 int i;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 if (obj && obj->ob_sinterned ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 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
84 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
85 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 }
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
87 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
88 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
89 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
90 /* 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
91 return 0;
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
92 }
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
93 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
94 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 ** 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
96 ** 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
97 ** (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
98 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 UseResFile(PyMac_AppRefNum);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 filerh = -1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 } else {
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
103 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
104 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
105 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
106 /* 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
107 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 filerh = FSpOpenResFile(&fss, fsRdPerm);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 if ( filerh == -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 UseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 if ( dataptr == NULL )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 SetResLoad(0);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 h = Get1NamedResource(restype, Pstring(module));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 SetResLoad(1);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 ok = (h != NULL);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 if ( ok && dataptr != NULL ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 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
122 /* 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
123 /* 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
124 *dataptr = **h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 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
126 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 CloseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135 ** 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
136 ** 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
137 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 PyMac_FindResourceModule(obj, module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140 PyStringObject *obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 int ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 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
147 return ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
148 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 ** 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
152 ** 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
153 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154 int
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 PyMac_FindCodeResourceModule(obj, module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 PyStringObject *obj;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158 char *filename;
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 int ok;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
162 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
163 return ok;
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
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168 ** 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
169 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171 PyMac_LoadCodeResourceModule(name, pathname)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172 char *name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 char *pathname;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174 {
8789
d32dbc202613 The PYD resource should now contain 2 strings: one for the ppc
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
175 PyObject *m, *d, *s;
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 char funcname[258];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
177 char *lastdot, *shortname, *packagecontext;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
178 dl_funcptr p = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 Str255 fragmentname;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180 CFragConnectionID connID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
181 Ptr mainAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182 Str255 errMessage;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184 char buf[512];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185 Ptr symAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186 CFragSymbolClass class;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
188 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
189 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190 return m;
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 lastdot = strrchr(name, '.');
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193 if (lastdot == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
194 packagecontext = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
195 shortname = name;
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 else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
198 packagecontext = name;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
199 shortname = lastdot+1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
200 }
21245
ba6a7a5c32e8 Replace sprintf() with PyOS_snprintf().
Jack Jansen <jack.jansen@cwi.nl>
parents: 20876
diff changeset
201 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
202 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
203 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
204 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
206
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
207 /* Load the fragment
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
208 (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
209 err = GetSharedLibrary(fragmentname, kCompiledCFragArch,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
210 kLoadCFrag, &connID, &mainAddr,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 errMessage);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
212 if ( err ) {
21245
ba6a7a5c32e8 Replace sprintf() with PyOS_snprintf().
Jack Jansen <jack.jansen@cwi.nl>
parents: 20876
diff changeset
213 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
214 errMessage[0], errMessage+1,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
215 PyMac_StrError(err));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
216 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
217 return NULL;
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 /* 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
220 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
221 if ( err ) {
21245
ba6a7a5c32e8 Replace sprintf() with PyOS_snprintf().
Jack Jansen <jack.jansen@cwi.nl>
parents: 20876
diff changeset
222 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
223 funcname, PyMac_StrError(err));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
224 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
225 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
226 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
227 p = (dl_funcptr)symAddr;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
228 if (p == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
229 PyErr_Format(PyExc_ImportError,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
230 "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
231 funcname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
232 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
233 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
234 _Py_PackageContext = packagecontext;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
235 (*p)();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
236 _Py_PackageContext = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
237 if (PyErr_Occurred())
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
238 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
239 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
240 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
241
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
242 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
243 if (m == NULL) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244 PyErr_SetString(PyExc_SystemError,
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
245 "dynamic module not initialized properly");
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
246 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
247 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
248 /* 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
249 d = PyModule_GetDict(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
250 s = PyString_FromString(pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
251 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
252 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
253 Py_XDECREF(s);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
254 if (Py_VerboseFlag)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
255 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
256 name, fragmentname, pathname);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
257 Py_INCREF(m);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
258 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
259 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
260
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
261 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
262 ** 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
263 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
264 PyObject *
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
265 PyMac_LoadResourceModule(module, filename)
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
266 char *module;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
267 char *filename;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
268 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
269 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
270 FInfo finfo;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
271 short oldrh, filerh;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
272 Handle h;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
273 OSErr err;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
274 PyObject *m, *co;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
275 long num, size;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
276
17898
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
277 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
278 goto error;
5d50d1fae078 Fixed a nasty slowdown in imports in frozen applications: the shortcut
Jack Jansen <jack.jansen@cwi.nl>
parents: 16727
diff changeset
279 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
280 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
281 ** 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
282 ** 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
283 ** (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
284 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
285 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286 UseResFile(PyMac_AppRefNum);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287 filerh = -1;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 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
290 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 oldrh = CurResFile();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292 filerh = FSpOpenResFile(&fss, fsRdPerm);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293 if ( filerh == -1 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295 goto error;
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 UseResFile(filerh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
298 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 h = Get1NamedResource('PYC ', Pstring(module));
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
300 if ( h == NULL ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
301 err = ResError();
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
302 goto error;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
304 HLock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
305 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
306 ** 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
307 ** 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
308 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
309 size = GetHandleSize(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
310 if ( size < 8 ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
311 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
312 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
313 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
314 num = (*h)[0] & 0xff;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
315 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
316 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
317 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
318 if ( num != PyImport_GetMagicNumber() ) {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
319 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
320 co = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
321 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
322 co = PyMarshal_ReadObjectFromString((*h)+8, size-8);
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
323 /*
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
324 ** 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
325 ** 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
326 ** 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
327 ** See also py_resource.py. (jvr)
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
328 */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
329 if ((*h)[4] & 0xff) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
330 /* it's a package */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
331 /* Set __path__ to the package name */
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
332 PyObject *d, *s;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
333 int err;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
334
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
335 m = PyImport_AddModule(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
336 if (m == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
337 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
338 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
339 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
340 d = PyModule_GetDict(m);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
341 s = PyString_InternFromString(module);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
342 if (s == NULL) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
343 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
344 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
345 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
346 err = PyDict_SetItemString(d, "__path__", s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
347 Py_DECREF(s);
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
348 if (err != 0) {
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
349 co = NULL;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
350 goto packageerror;
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
351 }
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
352 }
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
353 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
354 }
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
355 packageerror:
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
356 HUnlock(h);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
357 if ( filerh != -1 )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
358 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
359 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
360 ReleaseResource(h);
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
361 UseResFile(oldrh);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
362 if ( co ) {
9007
ff1a8a38f8c1 Support for freezing packages (Just).
Jack Jansen <jack.jansen@cwi.nl>
parents: 8789
diff changeset
363 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
364 Py_DECREF(co);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
365 } else {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
366 m = NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
367 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
368 if (Py_VerboseFlag)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
369 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
370 module, filename);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
371 return m;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
372 error:
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
373 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
374 char buf[512];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
375
21245
ba6a7a5c32e8 Replace sprintf() with PyOS_snprintf().
Jack Jansen <jack.jansen@cwi.nl>
parents: 20876
diff changeset
376 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
377 PyErr_SetString(PyExc_ImportError, buf);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
378 return NULL;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
379 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
380 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
381
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
382 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
383 ** 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
384 ** 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
385 ** 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
386 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
387 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
388 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
389 {
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
390 struct filedescr *fdp;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
391 unsigned char fnbuf[64];
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
392 int modnamelen = strlen(module);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
393 FSSpec fss;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
394 short refnum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
395 long dirid;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
396
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
397 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
398 ** 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
399 ** 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
400 ** lucky and return immedeately.
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
401 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
402 if ( !_PyImport_Filetab[0].suffix )
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
403 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
404
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
405 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
406 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
407 return _PyImport_Filetab;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
408 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
409 ** 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
410 ** 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
411 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
412 refnum = fss.vRefNum;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
413 dirid = fss.parID;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
414 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
415 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
416 /*
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
417 ** 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
418 */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
419 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
420 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
421 buf[*lenp] = '\0';
8665
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
422
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
423 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
424 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
425 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
426 if (Py_VerboseFlag > 1)
9332
462ccd0bbe50 Replaced fprintf(stderr,...) with PySys_WriteStderr(...) where appropriate.
Jack Jansen <jack.jansen@cwi.nl>
parents: 9073
diff changeset
427 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
428 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
429 /* Found it. */
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
430 strcpy(buf+*lenp, fdp->suffix);
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
431 return fdp;
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 }
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
434 return 0;
f594778a56af All import-related code has moved to macimport.c.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
435 }