1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
32 /* Support for dynamic loading of extension modules */
38 #include <CodeFragments.h>
39 #ifdef SYMANTEC__CFM68K__ /* Really an older version of Universal Headers */
40 #define CFragConnectionID ConnectionID
41 #define kLoadCFrag 0x01
44 #include "TFileSpec.h" /* for Path2FSSpec() */
51 const struct filedescr _PyImport_DynLoadFiletab
[] = {
52 {".slb", "rb", C_EXTENSION
},
54 {".CFM68K.slb", "rb", C_EXTENSION
},
56 {".ppc.slb", "rb", C_EXTENSION
},
62 dl_funcptr
_PyImport_GetDynLoadFunc(const char *fqname
, const char *shortname
,
63 const char *pathname
, FILE *fp
)
69 ** Dynamic loading of CFM shared libraries on the Mac. The
70 ** code has become more convoluted than it was, because we
71 ** want to be able to put multiple modules in a single
72 ** file. For this reason, we have to determine the fragment
73 ** name, and we cannot use the library entry point but we have
74 ** to locate the correct init routine "by hand".
77 CFragConnectionID connID
;
82 Boolean isfolder
, didsomething
;
87 CFragSymbolClass
class;
89 /* First resolve any aliases to find the real file */
91 err
= Path2FSSpec(pathname
, &libspec
);
93 (void)FSMakeFSSpec(0, 0, Pstring(pathname
), &libspec
);
94 err
= ResolveAliasFile(&libspec
, 1, &isfolder
, &didsomething
);
97 sprintf(buf
, "%.255s: %.200s",
98 pathname
, PyMac_StrError(err
));
99 PyErr_SetString(PyExc_ImportError
, buf
);
102 /* Next, determine the fragment name,
103 by stripping '.slb' and 'module' */
104 memcpy(fragname
+1, libspec
.name
+1, libspec
.name
[0]);
105 fragname
[0] = libspec
.name
[0];
106 if( strncmp((char *)(fragname
+1+fragname
[0]-4),
109 if ( strncmp((char *)(fragname
+1+fragname
[0]-6),
113 (or return the connID if it is already loaded */
114 err
= GetDiskFragment(&libspec
, 0, 0, fragname
,
115 kLoadCFrag
, &connID
, &mainAddr
,
117 if ( err
== cfragImportTooOldErr
|| err
== cfragImportTooNewErr
) {
119 ** Special-case code: if PythonCore is too old or too new this means
120 ** the dynamic module was meant for a different Python.
122 if (errMessage
[0] == 10 && strncmp((char *)errMessage
+1, "PythonCore", 10) == 0 ) {
123 sprintf(buf
, "Dynamic module was built for %s version of MacPython",
124 (err
== cfragImportTooOldErr
? "a newer" : "an older"));
125 PyErr_SetString(PyExc_ImportError
, buf
);
130 sprintf(buf
, "%.*s: %.200s",
131 errMessage
[0], errMessage
+1,
132 PyMac_StrError(err
));
133 PyErr_SetString(PyExc_ImportError
, buf
);
136 /* Locate the address of the correct init function */
137 sprintf(funcname
, "init%.200s", shortname
);
138 err
= FindSymbol(connID
, Pstring(funcname
), &symAddr
, &class);
140 sprintf(buf
, "%s: %.200s",
141 funcname
, PyMac_StrError(err
));
142 PyErr_SetString(PyExc_ImportError
, buf
);
145 p
= (dl_funcptr
)symAddr
;