annotate Python/dynload_mac.c @ 29199:cd1c826c98a2 legacy-trunk

Fix for SF [ 734869 ] Lambda functions in list comprehensions The compiler was reseting the list comprehension tmpname counter for each function, but the symtable was using the same counter for the entire module. Repair by move tmpname into the symtable entry. Bugfix candidate.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Wed, 21 May 2003 17:34:50 +0000
parents ed28b9752f8d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Support for dynamic loading of extension modules */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #include "Python.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #include "importdl.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #include <Aliases.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #include <CodeFragments.h>
12476
3500c4350f62 Jack Jansen: The new version of the GUSI i/o library on the Macintosh
Guido van Rossum <guido@python.org>
parents: 11756
diff changeset
9 #ifdef USE_GUSI1
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 #include "TFileSpec.h" /* for Path2FSSpec() */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #include <Files.h>
15537
50358d64dc43 Use c2pstr() in stead of Pstring() to convert C-strings to
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
13 #include <TextUtils.h>
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 #include "macdefs.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #include "macglue.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 const struct filedescr _PyImport_DynLoadFiletab[] = {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 {".slb", "rb", C_EXTENSION},
15879
90992c82d46e Added a separate extension (.carbon.slb) for Carbon dynamic modules.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15537
diff changeset
20 {".carbon.slb", "rb", C_EXTENSION},
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 {0, 0}
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 };
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
25 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 const char *pathname, FILE *fp)
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 dl_funcptr p;
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
29 char funcname[258];
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 /*
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 ** Dynamic loading of CFM shared libraries on the Mac. The
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 ** code has become more convoluted than it was, because we
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 ** want to be able to put multiple modules in a single
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 ** file. For this reason, we have to determine the fragment
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 ** name, and we cannot use the library entry point but we have
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 ** to locate the correct init routine "by hand".
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 FSSpec libspec;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 CFragConnectionID connID;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 Ptr mainAddr;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 Str255 errMessage;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 OSErr err;
12476
3500c4350f62 Jack Jansen: The new version of the GUSI i/o library on the Macintosh
Guido van Rossum <guido@python.org>
parents: 11756
diff changeset
44 #ifndef USE_GUSI1
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 Boolean isfolder, didsomething;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 char buf[512];
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 Str63 fragname;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 Ptr symAddr;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 CFragSymbolClass class;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 /* First resolve any aliases to find the real file */
12476
3500c4350f62 Jack Jansen: The new version of the GUSI i/o library on the Macintosh
Guido van Rossum <guido@python.org>
parents: 11756
diff changeset
53 #ifdef USE_GUSI1
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 err = Path2FSSpec(pathname, &libspec);
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 #else
15537
50358d64dc43 Use c2pstr() in stead of Pstring() to convert C-strings to
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
56 c2pstrcpy((unsigned char *)buf, pathname);
50358d64dc43 Use c2pstr() in stead of Pstring() to convert C-strings to
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
57 (void)FSMakeFSSpec(0, 0, (unsigned char *)buf, &libspec);
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething);
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 if ( err ) {
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
61 PyOS_snprintf(buf, sizeof(buf),
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
62 "%.200s: %.200s", pathname, PyMac_StrError(err));
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 PyErr_SetString(PyExc_ImportError, buf);
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 return NULL;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 /* Next, determine the fragment name,
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 by stripping '.slb' and 'module' */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 memcpy(fragname+1, libspec.name+1, libspec.name[0]);
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 fragname[0] = libspec.name[0];
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 if( strncmp((char *)(fragname+1+fragname[0]-4),
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 ".slb", 4) == 0 )
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 fragname[0] -= 4;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 if ( strncmp((char *)(fragname+1+fragname[0]-6),
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 "module", 6) == 0 )
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 fragname[0] -= 6;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 /* Load the fragment
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 (or return the connID if it is already loaded */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 err = GetDiskFragment(&libspec, 0, 0, fragname,
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 kLoadCFrag, &connID, &mainAddr,
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 errMessage);
11756
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
81 if ( err == cfragImportTooOldErr || err == cfragImportTooNewErr ) {
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
82 /*
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
83 ** Special-case code: if PythonCore is too old or too new this means
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
84 ** the dynamic module was meant for a different Python.
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
85 */
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
86 if (errMessage[0] == 10 && strncmp((char *)errMessage+1, "PythonCore", 10) == 0 ) {
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
87 PyOS_snprintf(buf, sizeof(buf),
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
88 "Dynamic module was built for %s version of MacPython",
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
89 (err == cfragImportTooOldErr ? "a newer" : "an older"));
11756
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
90 PyErr_SetString(PyExc_ImportError, buf);
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
91 return NULL;
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
92 }
6367d829f36b Patch by Jack Jansen:
Guido van Rossum <guido@python.org>
parents: 11618
diff changeset
93 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 if ( err ) {
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
95 PyOS_snprintf(buf, sizeof(buf), "%.*s: %.200s",
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 errMessage[0], errMessage+1,
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 PyMac_StrError(err));
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 PyErr_SetString(PyExc_ImportError, buf);
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 return NULL;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 /* Locate the address of the correct init function */
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
102 PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname);
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 err = FindSymbol(connID, Pstring(funcname), &symAddr, &class);
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 if ( err ) {
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
105 PyOS_snprintf(buf, sizeof(buf), "%s: %.200s",
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16055
diff changeset
106 funcname, PyMac_StrError(err));
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 PyErr_SetString(PyExc_ImportError, buf);
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 return NULL;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 p = (dl_funcptr)symAddr;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
111
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 return p;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 }