2 /* Support for dynamic loading of extension modules */
8 #include <CodeFragments.h>
10 #include "TFileSpec.h" /* for Path2FSSpec() */
13 #include <TextUtils.h>
18 const struct filedescr _PyImport_DynLoadFiletab
[] = {
19 {".slb", "rb", C_EXTENSION
},
21 {".CFM68K.slb", "rb", C_EXTENSION
},
23 #if TARGET_API_MAC_CARBON
24 {".carbon.slb", "rb", C_EXTENSION
},
26 {".ppc.slb", "rb", C_EXTENSION
},
33 dl_funcptr
_PyImport_GetDynLoadFunc(const char *fqname
, const char *shortname
,
34 const char *pathname
, FILE *fp
)
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".
48 CFragConnectionID connID
;
53 Boolean isfolder
, didsomething
;
58 CFragSymbolClass
class;
60 /* First resolve any aliases to find the real file */
62 err
= Path2FSSpec(pathname
, &libspec
);
64 c2pstrcpy((unsigned char *)buf
, pathname
);
65 (void)FSMakeFSSpec(0, 0, (unsigned char *)buf
, &libspec
);
66 err
= ResolveAliasFile(&libspec
, 1, &isfolder
, &didsomething
);
69 PyOS_snprintf(buf
, sizeof(buf
),
70 "%.200s: %.200s", pathname
, PyMac_StrError(err
));
71 PyErr_SetString(PyExc_ImportError
, buf
);
74 /* Next, determine the fragment name,
75 by stripping '.slb' and 'module' */
76 memcpy(fragname
+1, libspec
.name
+1, libspec
.name
[0]);
77 fragname
[0] = libspec
.name
[0];
78 if( strncmp((char *)(fragname
+1+fragname
[0]-4),
81 if ( strncmp((char *)(fragname
+1+fragname
[0]-6),
85 (or return the connID if it is already loaded */
86 err
= GetDiskFragment(&libspec
, 0, 0, fragname
,
87 kLoadCFrag
, &connID
, &mainAddr
,
89 if ( err
== cfragImportTooOldErr
|| err
== cfragImportTooNewErr
) {
91 ** Special-case code: if PythonCore is too old or too new this means
92 ** the dynamic module was meant for a different Python.
94 if (errMessage
[0] == 10 && strncmp((char *)errMessage
+1, "PythonCore", 10) == 0 ) {
95 PyOS_snprintf(buf
, sizeof(buf
),
96 "Dynamic module was built for %s version of MacPython",
97 (err
== cfragImportTooOldErr
? "a newer" : "an older"));
98 PyErr_SetString(PyExc_ImportError
, buf
);
103 PyOS_snprintf(buf
, sizeof(buf
), "%.*s: %.200s",
104 errMessage
[0], errMessage
+1,
105 PyMac_StrError(err
));
106 PyErr_SetString(PyExc_ImportError
, buf
);
109 /* Locate the address of the correct init function */
110 PyOS_snprintf(funcname
, sizeof(funcname
), "init%.200s", shortname
);
111 err
= FindSymbol(connID
, Pstring(funcname
), &symAddr
, &class);
113 PyOS_snprintf(buf
, sizeof(buf
), "%s: %.200s",
114 funcname
, PyMac_StrError(err
));
115 PyErr_SetString(PyExc_ImportError
, buf
);
118 p
= (dl_funcptr
)symAddr
;