Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 4 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 5 | All rights reserved. |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | See the file "Misc/COPYRIGHT" for information on usage and |
| 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 9 | ******************************************************************/ |
| 10 | |
| 11 | /* Support for dynamic loading of extension modules */ |
| 12 | |
| 13 | #include "dl.h" |
| 14 | #include <errno.h> |
| 15 | |
| 16 | #include "Python.h" |
| 17 | #include "importdl.h" |
| 18 | |
Guido van Rossum | 96a8fb7 | 1999-12-22 14:09:35 +0000 | [diff] [blame] | 19 | #if defined(__hp9000s300) |
| 20 | #define FUNCNAME_PATTERN "_init%.200s" |
| 21 | #else |
| 22 | #define FUNCNAME_PATTERN "init%.200s" |
| 23 | #endif |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 24 | |
| 25 | const struct filedescr _PyImport_DynLoadFiletab[] = { |
| 26 | {".sl", "rb", C_EXTENSION}, |
| 27 | {"module.sl", "rb", C_EXTENSION}, |
| 28 | {0, 0} |
| 29 | }; |
| 30 | |
Guido van Rossum | 96a8fb7 | 1999-12-22 14:09:35 +0000 | [diff] [blame] | 31 | dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 32 | const char *pathname, FILE *fp) |
| 33 | { |
| 34 | dl_funcptr p; |
| 35 | shl_t lib; |
| 36 | int flags; |
Guido van Rossum | 96a8fb7 | 1999-12-22 14:09:35 +0000 | [diff] [blame] | 37 | char funcname[258]; |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 38 | |
| 39 | flags = BIND_FIRST | BIND_DEFERRED; |
| 40 | if (Py_VerboseFlag) { |
| 41 | flags = DYNAMIC_PATH | BIND_FIRST | BIND_IMMEDIATE | |
| 42 | BIND_NONFATAL | BIND_VERBOSE; |
| 43 | printf("shl_load %s\n",pathname); |
| 44 | } |
| 45 | lib = shl_load(pathname, flags, 0); |
| 46 | /* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */ |
| 47 | if (lib == NULL) { |
| 48 | char buf[256]; |
| 49 | if (Py_VerboseFlag) |
| 50 | perror(pathname); |
| 51 | sprintf(buf, "Failed to load %.200s", pathname); |
| 52 | PyErr_SetString(PyExc_ImportError, buf); |
| 53 | return NULL; |
| 54 | } |
Guido van Rossum | 96a8fb7 | 1999-12-22 14:09:35 +0000 | [diff] [blame] | 55 | sprintf(funcname, FUNCNAME_PATTERN, shortname); |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 56 | if (Py_VerboseFlag) |
| 57 | printf("shl_findsym %s\n", funcname); |
| 58 | shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p); |
| 59 | if (p == NULL && Py_VerboseFlag) |
| 60 | perror(funcname); |
| 61 | |
| 62 | return p; |
| 63 | } |