Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 1 | |
| 2 | /* Support for dynamic loading of extension modules */ |
| 3 | |
| 4 | #include "dl.h" |
| 5 | #include <errno.h> |
| 6 | |
| 7 | #include "Python.h" |
| 8 | #include "importdl.h" |
| 9 | |
Guido van Rossum | 96a8fb7 | 1999-12-22 14:09:35 +0000 | [diff] [blame] | 10 | #if defined(__hp9000s300) |
| 11 | #define FUNCNAME_PATTERN "_init%.200s" |
| 12 | #else |
| 13 | #define FUNCNAME_PATTERN "init%.200s" |
| 14 | #endif |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 15 | |
| 16 | const struct filedescr _PyImport_DynLoadFiletab[] = { |
| 17 | {".sl", "rb", C_EXTENSION}, |
| 18 | {"module.sl", "rb", C_EXTENSION}, |
| 19 | {0, 0} |
| 20 | }; |
| 21 | |
Guido van Rossum | 96a8fb7 | 1999-12-22 14:09:35 +0000 | [diff] [blame] | 22 | dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 23 | const char *pathname, FILE *fp) |
| 24 | { |
| 25 | dl_funcptr p; |
| 26 | shl_t lib; |
| 27 | int flags; |
Guido van Rossum | 96a8fb7 | 1999-12-22 14:09:35 +0000 | [diff] [blame] | 28 | char funcname[258]; |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 29 | |
| 30 | flags = BIND_FIRST | BIND_DEFERRED; |
| 31 | if (Py_VerboseFlag) { |
| 32 | flags = DYNAMIC_PATH | BIND_FIRST | BIND_IMMEDIATE | |
| 33 | BIND_NONFATAL | BIND_VERBOSE; |
| 34 | printf("shl_load %s\n",pathname); |
| 35 | } |
| 36 | lib = shl_load(pathname, flags, 0); |
| 37 | /* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */ |
| 38 | if (lib == NULL) { |
| 39 | char buf[256]; |
| 40 | if (Py_VerboseFlag) |
| 41 | perror(pathname); |
Jeremy Hylton | 518ab1c | 2001-11-28 20:42:20 +0000 | [diff] [blame] | 42 | PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s", |
| 43 | pathname); |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 44 | PyErr_SetString(PyExc_ImportError, buf); |
| 45 | return NULL; |
| 46 | } |
Jeremy Hylton | 518ab1c | 2001-11-28 20:42:20 +0000 | [diff] [blame] | 47 | PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN, shortname); |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 48 | if (Py_VerboseFlag) |
| 49 | printf("shl_findsym %s\n", funcname); |
| 50 | shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p); |
| 51 | if (p == NULL && Py_VerboseFlag) |
| 52 | perror(funcname); |
| 53 | |
| 54 | return p; |
| 55 | } |