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