1 | n/a | |
---|
2 | n/a | /* Support for dynamic loading of extension modules */ |
---|
3 | n/a | |
---|
4 | n/a | #include "dl.h" |
---|
5 | n/a | #include <errno.h> |
---|
6 | n/a | |
---|
7 | n/a | #include "Python.h" |
---|
8 | n/a | #include "importdl.h" |
---|
9 | n/a | |
---|
10 | n/a | #if defined(__hp9000s300) |
---|
11 | n/a | #define FUNCNAME_PATTERN "_%.20s_%.200s" |
---|
12 | n/a | #else |
---|
13 | n/a | #define FUNCNAME_PATTERN "%.20s_%.200s" |
---|
14 | n/a | #endif |
---|
15 | n/a | |
---|
16 | n/a | const char *_PyImport_DynLoadFiletab[] = {SHLIB_EXT, NULL}; |
---|
17 | n/a | |
---|
18 | n/a | dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix, |
---|
19 | n/a | const char *shortname, |
---|
20 | n/a | const char *pathname, FILE *fp) |
---|
21 | n/a | { |
---|
22 | n/a | dl_funcptr p; |
---|
23 | n/a | shl_t lib; |
---|
24 | n/a | int flags; |
---|
25 | n/a | char funcname[258]; |
---|
26 | n/a | |
---|
27 | n/a | flags = BIND_FIRST | BIND_DEFERRED; |
---|
28 | n/a | if (Py_VerboseFlag) { |
---|
29 | n/a | flags = BIND_FIRST | BIND_IMMEDIATE | |
---|
30 | n/a | BIND_NONFATAL | BIND_VERBOSE; |
---|
31 | n/a | printf("shl_load %s\n",pathname); |
---|
32 | n/a | } |
---|
33 | n/a | lib = shl_load(pathname, flags, 0); |
---|
34 | n/a | /* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */ |
---|
35 | n/a | if (lib == NULL) { |
---|
36 | n/a | char buf[256]; |
---|
37 | n/a | PyObject *pathname_ob = NULL; |
---|
38 | n/a | PyObject *buf_ob = NULL; |
---|
39 | n/a | PyObject *shortname_ob = NULL; |
---|
40 | n/a | |
---|
41 | n/a | if (Py_VerboseFlag) |
---|
42 | n/a | perror(pathname); |
---|
43 | n/a | PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s", |
---|
44 | n/a | pathname); |
---|
45 | n/a | buf_ob = PyUnicode_FromString(buf); |
---|
46 | n/a | shortname_ob = PyUnicode_FromString(shortname); |
---|
47 | n/a | pathname_ob = PyUnicode_FromString(pathname); |
---|
48 | n/a | PyErr_SetImportError(buf_ob, shortname_ob, pathname_ob); |
---|
49 | n/a | Py_DECREF(buf_ob); |
---|
50 | n/a | Py_DECREF(shortname_ob); |
---|
51 | n/a | Py_DECREF(pathname_ob); |
---|
52 | n/a | return NULL; |
---|
53 | n/a | } |
---|
54 | n/a | PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN, |
---|
55 | n/a | prefix, shortname); |
---|
56 | n/a | if (Py_VerboseFlag) |
---|
57 | n/a | printf("shl_findsym %s\n", funcname); |
---|
58 | n/a | if (shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p) == -1) { |
---|
59 | n/a | shl_unload(lib); |
---|
60 | n/a | p = NULL; |
---|
61 | n/a | } |
---|
62 | n/a | if (p == NULL && Py_VerboseFlag) |
---|
63 | n/a | perror(funcname); |
---|
64 | n/a | |
---|
65 | n/a | return p; |
---|
66 | n/a | } |
---|