1999-12-20 22:18:49 +01:00
|
|
|
|
|
|
|
/* Support for dynamic loading of extension modules */
|
|
|
|
|
|
|
|
#include "dl.h"
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "Python.h"
|
|
|
|
#include "importdl.h"
|
|
|
|
|
1999-12-22 15:09:35 +01:00
|
|
|
#if defined(__hp9000s300)
|
2008-06-11 07:26:20 +02:00
|
|
|
#define FUNCNAME_PATTERN "_PyInit_%.200s"
|
1999-12-22 15:09:35 +01:00
|
|
|
#else
|
2008-06-11 07:26:20 +02:00
|
|
|
#define FUNCNAME_PATTERN "PyInit_%.200s"
|
1999-12-22 15:09:35 +01:00
|
|
|
#endif
|
1999-12-20 22:18:49 +01:00
|
|
|
|
2012-05-04 21:20:40 +02:00
|
|
|
const char *_PyImport_DynLoadFiletab[] = {SHLIB_EXT, NULL};
|
1999-12-20 22:18:49 +01:00
|
|
|
|
2011-02-23 00:16:19 +01:00
|
|
|
dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
|
2010-05-09 17:52:27 +02:00
|
|
|
const char *pathname, FILE *fp)
|
1999-12-20 22:18:49 +01:00
|
|
|
{
|
2010-05-09 17:52:27 +02: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 21:31:11 +02:00
|
|
|
PyObject *pathname_ob = NULL;
|
|
|
|
PyObject *buf_ob = NULL;
|
|
|
|
PyObject *shortname_ob = NULL;
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
if (Py_VerboseFlag)
|
|
|
|
perror(pathname);
|
|
|
|
PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s",
|
|
|
|
pathname);
|
2012-04-20 21:31:11 +02: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 17:52:27 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN, shortname);
|
|
|
|
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 22:18:49 +01:00
|
|
|
}
|