Apparently the code to forestall Tk eating events was too aggressive (Tk user input...
[python/dscho.git] / Python / dynload_mac.c
blobc8c9646bd89c1a4a626adddc683a849c6db70ae8
2 /* Support for dynamic loading of extension modules */
4 #include "Python.h"
5 #include "importdl.h"
7 #include <Aliases.h>
8 #include <CodeFragments.h>
9 #ifdef USE_GUSI1
10 #include "TFileSpec.h" /* for Path2FSSpec() */
11 #endif
12 #include <Files.h>
13 #include <TextUtils.h>
14 #include "macdefs.h"
15 #include "macglue.h"
18 const struct filedescr _PyImport_DynLoadFiletab[] = {
19 {".slb", "rb", C_EXTENSION},
20 #ifdef __CFM68K__
21 {".CFM68K.slb", "rb", C_EXTENSION},
22 #else
23 #if TARGET_API_MAC_CARBON
24 {".carbon.slb", "rb", C_EXTENSION},
25 #else
26 {".ppc.slb", "rb", C_EXTENSION},
27 #endif
28 #endif
29 {0, 0}
33 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
34 const char *pathname, FILE *fp)
36 dl_funcptr p;
37 char funcname[258];
40 ** Dynamic loading of CFM shared libraries on the Mac. The
41 ** code has become more convoluted than it was, because we
42 ** want to be able to put multiple modules in a single
43 ** file. For this reason, we have to determine the fragment
44 ** name, and we cannot use the library entry point but we have
45 ** to locate the correct init routine "by hand".
47 FSSpec libspec;
48 CFragConnectionID connID;
49 Ptr mainAddr;
50 Str255 errMessage;
51 OSErr err;
52 #ifndef USE_GUSI1
53 Boolean isfolder, didsomething;
54 #endif
55 char buf[512];
56 Str63 fragname;
57 Ptr symAddr;
58 CFragSymbolClass class;
60 /* First resolve any aliases to find the real file */
61 #ifdef USE_GUSI1
62 err = Path2FSSpec(pathname, &libspec);
63 #else
64 c2pstrcpy((unsigned char *)buf, pathname);
65 (void)FSMakeFSSpec(0, 0, (unsigned char *)buf, &libspec);
66 err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething);
67 #endif
68 if ( err ) {
69 sprintf(buf, "%.200s: %.200s", pathname, PyMac_StrError(err));
70 PyErr_SetString(PyExc_ImportError, buf);
71 return NULL;
73 /* Next, determine the fragment name,
74 by stripping '.slb' and 'module' */
75 memcpy(fragname+1, libspec.name+1, libspec.name[0]);
76 fragname[0] = libspec.name[0];
77 if( strncmp((char *)(fragname+1+fragname[0]-4),
78 ".slb", 4) == 0 )
79 fragname[0] -= 4;
80 if ( strncmp((char *)(fragname+1+fragname[0]-6),
81 "module", 6) == 0 )
82 fragname[0] -= 6;
83 /* Load the fragment
84 (or return the connID if it is already loaded */
85 err = GetDiskFragment(&libspec, 0, 0, fragname,
86 kLoadCFrag, &connID, &mainAddr,
87 errMessage);
88 if ( err == cfragImportTooOldErr || err == cfragImportTooNewErr ) {
90 ** Special-case code: if PythonCore is too old or too new this means
91 ** the dynamic module was meant for a different Python.
93 if (errMessage[0] == 10 && strncmp((char *)errMessage+1, "PythonCore", 10) == 0 ) {
94 sprintf(buf, "Dynamic module was built for %s version of MacPython",
95 (err == cfragImportTooOldErr ? "a newer" : "an older"));
96 PyErr_SetString(PyExc_ImportError, buf);
97 return NULL;
100 if ( err ) {
101 sprintf(buf, "%.*s: %.200s",
102 errMessage[0], errMessage+1,
103 PyMac_StrError(err));
104 PyErr_SetString(PyExc_ImportError, buf);
105 return NULL;
107 /* Locate the address of the correct init function */
108 sprintf(funcname, "init%.200s", shortname);
109 err = FindSymbol(connID, Pstring(funcname), &symAddr, &class);
110 if ( err ) {
111 sprintf(buf, "%s: %.200s",
112 funcname, PyMac_StrError(err));
113 PyErr_SetString(PyExc_ImportError, buf);
114 return NULL;
116 p = (dl_funcptr)symAddr;
118 return p;