blob: 14b54b8ecb528c28712e409e256578fe3782c180 [file] [log] [blame]
Guido van Rossum22a1d361999-12-20 21:18:49 +00001/***********************************************************
2Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
4
5 All Rights Reserved
6
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007Copyright (c) 2000, BeOpen.com.
8Copyright (c) 1995-2000, Corporation for National Research Initiatives.
9Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
10All rights reserved.
Guido van Rossum22a1d361999-12-20 21:18:49 +000011
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000012See the file "Misc/COPYRIGHT" for information on usage and
13redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossum22a1d361999-12-20 21:18:49 +000014
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 Rossum96a8fb71999-12-22 14:09:35 +000025#if defined(__hp9000s300)
26#define FUNCNAME_PATTERN "_init%.200s"
27#else
28#define FUNCNAME_PATTERN "init%.200s"
29#endif
Guido van Rossum22a1d361999-12-20 21:18:49 +000030
31const struct filedescr _PyImport_DynLoadFiletab[] = {
32 {".sl", "rb", C_EXTENSION},
33 {"module.sl", "rb", C_EXTENSION},
34 {0, 0}
35};
36
Guido van Rossum96a8fb71999-12-22 14:09:35 +000037dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
Guido van Rossum22a1d361999-12-20 21:18:49 +000038 const char *pathname, FILE *fp)
39{
40 dl_funcptr p;
41 shl_t lib;
42 int flags;
Guido van Rossum96a8fb71999-12-22 14:09:35 +000043 char funcname[258];
Guido van Rossum22a1d361999-12-20 21:18:49 +000044
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 Rossum96a8fb71999-12-22 14:09:35 +000061 sprintf(funcname, FUNCNAME_PATTERN, shortname);
Guido van Rossum22a1d361999-12-20 21:18:49 +000062 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}