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
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
dl_funcptr p;
|
|
|
|
shl_t lib;
|
|
|
|
int flags;
|
|
|
|
char funcname[258];
|
|
|
|
|
|
|
|
flags = BIND_FIRST | BIND_DEFERRED;
|
|
|
|
if (Py_VerboseFlag) {
|
|
|
|
flags = BIND_FIRST | BIND_IMMEDIATE |
|
|
|
|
BIND_NONFATAL | BIND_VERBOSE;
|
|
|
|
printf("shl_load %s\n",pathname);
|
|
|
|
}
|
|
|
|
lib = shl_load(pathname, flags, 0);
|
|
|
|
/* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */
|
|
|
|
if (lib == NULL) {
|
|
|
|
char buf[256];
|
2012-04-20 16:31:11 -03:00
|
|
|
PyObject *pathname_ob = NULL;
|
|
|
|
PyObject *buf_ob = NULL;
|
|
|
|
PyObject *shortname_ob = NULL;
|
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
if (Py_VerboseFlag)
|
|
|
|
perror(pathname);
|
|
|
|
PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s",
|
|
|
|
pathname);
|
2012-04-20 16:31:11 -03:00
|
|
|
buf_ob = PyUnicode_FromString(buf);
|
|
|
|
shortname_ob = PyUnicode_FromString(shortname);
|
|
|
|
pathname_ob = PyUnicode_FromString(pathname);
|
|
|
|
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;
|
|
|
|
}
|
2015-05-23 09:24:10 -03:00
|
|
|
PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN,
|
|
|
|
prefix, shortname);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (Py_VerboseFlag)
|
|
|
|
printf("shl_findsym %s\n", funcname);
|
|
|
|
if (shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p) == -1) {
|
|
|
|
shl_unload(lib);
|
|
|
|
p = NULL;
|
|
|
|
}
|
|
|
|
if (p == NULL && Py_VerboseFlag)
|
|
|
|
perror(funcname);
|
|
|
|
|
|
|
|
return p;
|
1999-12-20 17:18:49 -04:00
|
|
|
}
|