blob: 4624b64938e2e7b7aa275c4cd875e5bbf7da5030 [file] [log] [blame]
Guido van Rossum22a1d361999-12-20 21:18:49 +00001/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00002Copyright (c) 2000, BeOpen.com.
3Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5All rights reserved.
Guido van Rossum22a1d361999-12-20 21:18:49 +00006
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007See the file "Misc/COPYRIGHT" for information on usage and
8redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossum22a1d361999-12-20 21:18:49 +00009******************************************************************/
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 Rossum96a8fb71999-12-22 14:09:35 +000019#if defined(__hp9000s300)
20#define FUNCNAME_PATTERN "_init%.200s"
21#else
22#define FUNCNAME_PATTERN "init%.200s"
23#endif
Guido van Rossum22a1d361999-12-20 21:18:49 +000024
25const struct filedescr _PyImport_DynLoadFiletab[] = {
26 {".sl", "rb", C_EXTENSION},
27 {"module.sl", "rb", C_EXTENSION},
28 {0, 0}
29};
30
Guido van Rossum96a8fb71999-12-22 14:09:35 +000031dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
Guido van Rossum22a1d361999-12-20 21:18:49 +000032 const char *pathname, FILE *fp)
33{
34 dl_funcptr p;
35 shl_t lib;
36 int flags;
Guido van Rossum96a8fb71999-12-22 14:09:35 +000037 char funcname[258];
Guido van Rossum22a1d361999-12-20 21:18:49 +000038
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 Rossum96a8fb71999-12-22 14:09:35 +000055 sprintf(funcname, FUNCNAME_PATTERN, shortname);
Guido van Rossum22a1d361999-12-20 21:18:49 +000056 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}