1999-12-20 17:18:49 -04:00
|
|
|
|
|
|
|
/* Support for dynamic loading of extension modules */
|
|
|
|
|
|
|
|
#include "dl.h"
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "Python.h"
|
|
|
|
#include "importdl.h"
|
|
|
|
|
1999-12-22 10:09:35 -04:00
|
|
|
#if defined(__hp9000s300)
|
2015-05-23 18:13:41 -03:00
|
|
|
#define FUNCNAME_PATTERN "_%.20s_%.200s"
|
1999-12-22 10:09:35 -04:00
|
|
|
#else
|
2015-05-23 18:13:41 -03:00
|
|
|
#define FUNCNAME_PATTERN "%.20s_%.200s"
|
1999-12-22 10:09:35 -04:00
|
|
|
#endif
|
1999-12-20 17:18:49 -04:00
|
|
|
|
2012-05-04 16:20:40 -03:00
|
|
|
const char *_PyImport_DynLoadFiletab[] = {SHLIB_EXT, NULL};
|
1999-12-20 17:18:49 -04:00
|
|
|
|
2015-05-23 09:24:10 -03:00
|
|
|
dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
|
|
|
|
const char *shortname,
|
|
|
|
const char *pathname, FILE *fp)
|
1999-12-20 17:18:49 -04:00
|
|
|
{
|
2019-05-14 12:34:56 -03:00
|
|
|
int flags = BIND_FIRST | BIND_DEFERRED;
|
|
|
|
int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose;
|
|
|
|
if (verbose) {
|
2010-05-09 12:52:27 -03:00
|
|
|
flags = BIND_FIRST | BIND_IMMEDIATE |
|
|
|
|
BIND_NONFATAL | BIND_VERBOSE;
|
|
|
|
printf("shl_load %s\n",pathname);
|
|
|
|
}
|
2019-05-14 12:34:56 -03:00
|
|
|
|
|
|
|
shl_t lib = shl_load(pathname, flags, 0);
|
2010-05-09 12:52:27 -03:00
|
|
|
/* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */
|
|
|
|
if (lib == NULL) {
|
2019-05-14 12:34:56 -03:00
|
|
|
if (verbose) {
|
2010-05-09 12:52:27 -03:00
|
|
|
perror(pathname);
|
2019-05-14 12:34:56 -03:00
|
|
|
}
|
|
|
|
char buf[256];
|
2010-05-09 12:52:27 -03:00
|
|
|
PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s",
|
|
|
|
pathname);
|
2019-05-14 12:34:56 -03:00
|
|
|
PyObject *buf_ob = PyUnicode_FromString(buf);
|
|
|
|
PyObject *shortname_ob = PyUnicode_FromString(shortname);
|
|
|
|
PyObject *pathname_ob = PyUnicode_FromString(pathname);
|
2012-04-20 16:31:11 -03:00
|
|
|
PyErr_SetImportError(buf_ob, shortname_ob, pathname_ob);
|
|
|
|
Py_DECREF(buf_ob);
|
|
|
|
Py_DECREF(shortname_ob);
|
|
|
|
Py_DECREF(pathname_ob);
|
2010-05-09 12:52:27 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-05-14 12:34:56 -03:00
|
|
|
|
|
|
|
char funcname[258];
|
2015-05-23 09:24:10 -03:00
|
|
|
PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN,
|
|
|
|
prefix, shortname);
|
2019-05-14 12:34:56 -03:00
|
|
|
if (verbose) {
|
2010-05-09 12:52:27 -03:00
|
|
|
printf("shl_findsym %s\n", funcname);
|
2019-05-14 12:34:56 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
dl_funcptr p;
|
2010-05-09 12:52:27 -03:00
|
|
|
if (shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p) == -1) {
|
|
|
|
shl_unload(lib);
|
|
|
|
p = NULL;
|
|
|
|
}
|
2019-05-14 12:34:56 -03:00
|
|
|
if (p == NULL && verbose) {
|
2010-05-09 12:52:27 -03:00
|
|
|
perror(funcname);
|
2019-05-14 12:34:56 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
return p;
|
1999-12-20 17:18:49 -04:00
|
|
|
}
|