annotate Python/dynload_shlib.c @ 76451:ea46ebba8a0f

Issue #13959: Re-implement imp.source_from_cache() in Lib/imp.py.
author Brett Cannon <brett@python.org>
date Sat, 21 Apr 2012 18:52:52 -0400
parents 573010778eed
children 257cbd2fac38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Support for dynamic loading of extension modules */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #include "Python.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #include "importdl.h"
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #include <sys/types.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #include <sys/stat.h>
20546
73a1395a2351 Move dlfcn.h block out of NetBSD block, assuming that NetBSD before
Martin v. Löwis <martin@v.loewis.de>
parents: 20510
diff changeset
9
20510
bdc486c66df0 Patch to bug #472202: Correctly recognize NetBSD before 199712.
Martin v. Löwis <martin@v.loewis.de>
parents: 19728
diff changeset
10 #if defined(__NetBSD__)
bdc486c66df0 Patch to bug #472202: Correctly recognize NetBSD before 199712.
Martin v. Löwis <martin@v.loewis.de>
parents: 19728
diff changeset
11 #include <sys/param.h>
bdc486c66df0 Patch to bug #472202: Correctly recognize NetBSD before 199712.
Martin v. Löwis <martin@v.loewis.de>
parents: 19728
diff changeset
12 #if (NetBSD < 199712)
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 #include <nlist.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 #include <link.h>
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #define dlerror() "error in dynamic linking"
20546
73a1395a2351 Move dlfcn.h block out of NetBSD block, assuming that NetBSD before
Martin v. Löwis <martin@v.loewis.de>
parents: 20510
diff changeset
16 #endif
73a1395a2351 Move dlfcn.h block out of NetBSD block, assuming that NetBSD before
Martin v. Löwis <martin@v.loewis.de>
parents: 20510
diff changeset
17 #endif /* NetBSD */
73a1395a2351 Move dlfcn.h block out of NetBSD block, assuming that NetBSD before
Martin v. Löwis <martin@v.loewis.de>
parents: 20510
diff changeset
18
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 #ifdef HAVE_DLFCN_H
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 #include <dlfcn.h>
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21077
diff changeset
21 #else
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21077
diff changeset
22 #if defined(PYOS_OS2) && defined(PYCC_GCC)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21077
diff changeset
23 #include "dlfcn.h"
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21077
diff changeset
24 #endif
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
20510
bdc486c66df0 Patch to bug #472202: Correctly recognize NetBSD before 199712.
Martin v. Löwis <martin@v.loewis.de>
parents: 19728
diff changeset
27 #if (defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__)
15336
bbc991ab6d32 Patch 102114, Bug 11725. On OpenBSD (but apparently not on the other
Guido van Rossum <guido@python.org>
parents: 15036
diff changeset
28 #define LEAD_UNDERSCORE "_"
bbc991ab6d32 Patch 102114, Bug 11725. On OpenBSD (but apparently not on the other
Guido van Rossum <guido@python.org>
parents: 15036
diff changeset
29 #else
bbc991ab6d32 Patch 102114, Bug 11725. On OpenBSD (but apparently not on the other
Guido van Rossum <guido@python.org>
parents: 15036
diff changeset
30 #define LEAD_UNDERSCORE ""
bbc991ab6d32 Patch 102114, Bug 11725. On OpenBSD (but apparently not on the other
Guido van Rossum <guido@python.org>
parents: 15036
diff changeset
31 #endif
bbc991ab6d32 Patch 102114, Bug 11725. On OpenBSD (but apparently not on the other
Guido van Rossum <guido@python.org>
parents: 15036
diff changeset
32
64399
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
33 /* The .so extension module ABI tag, supplied by the Makefile via
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
34 Makefile.pre.in and configure. This is used to discriminate between
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
35 incompatible .so files so that extensions for different Python builds can
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
36 live in the same directory. E.g. foomodule.cpython-32.so
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
37 */
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 const struct filedescr _PyImport_DynLoadFiletab[] = {
15036
6e9ff060a728 SF "bug" 115973: patches from Norman Vine so that shared libraries and
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
40 #ifdef __CYGWIN__
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
41 {".dll", "rb", C_EXTENSION},
64399
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
42 #else /* !__CYGWIN__ */
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21077
diff changeset
43 #if defined(PYOS_OS2) && defined(PYCC_GCC)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
44 {".pyd", "rb", C_EXTENSION},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
45 {".dll", "rb", C_EXTENSION},
64399
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
46 #else /* !(defined(PYOS_OS2) && defined(PYCC_GCC)) */
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
47 #ifdef __VMS
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
48 {".exe", "rb", C_EXTENSION},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
49 {".EXE", "rb", C_EXTENSION},
64399
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
50 #else /* !__VMS */
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
51 {"." SOABI ".so", "rb", C_EXTENSION},
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 64566
diff changeset
52 {".abi" PYTHON_ABI_STRING ".so", "rb", C_EXTENSION},
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
53 {".so", "rb", C_EXTENSION},
64399
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
54 #endif /* __VMS */
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
55 #endif /* defined(PYOS_OS2) && defined(PYCC_GCC) */
5e33b27c71a8 PEP 3149 is accepted.
Barry Warsaw <barry@python.org>
parents: 61466
diff changeset
56 #endif /* __CYGWIN__ */
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
57 {0, 0}
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 };
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 static struct {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
61 dev_t dev;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
62 #ifdef __VMS
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
63 ino_t ino[3];
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
64 #else
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
65 ino_t ino;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
66 #endif
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
67 void *handle;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 } handles[128];
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 static int nhandles = 0;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
68108
0874698b1201 Issue #3080: Remove unused argument of _PyImport_GetDynLoadFunc()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 66664
diff changeset
72 dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
73 const char *pathname, FILE *fp)
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
75 dl_funcptr p;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
76 void *handle;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
77 char funcname[258];
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
78 char pathbuf[260];
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
79 int dlopenflags=0;
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
80
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
81 if (strchr(pathname, '/') == NULL) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
82 /* Prefix bare filename with "./" */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
83 PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
84 pathname = pathbuf;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
85 }
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
86
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
87 PyOS_snprintf(funcname, sizeof(funcname),
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
88 LEAD_UNDERSCORE "PyInit_%.200s", shortname);
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
90 if (fp != NULL) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
91 int i;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
92 struct stat statb;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
93 fstat(fileno(fp), &statb);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
94 for (i = 0; i < nhandles; i++) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
95 if (statb.st_dev == handles[i].dev &&
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
96 statb.st_ino == handles[i].ino) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
97 p = (dl_funcptr) dlsym(handles[i].handle,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
98 funcname);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
99 return p;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
100 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
101 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
102 if (nhandles < 128) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
103 handles[nhandles].dev = statb.st_dev;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
104 #ifdef __VMS
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
105 handles[nhandles].ino[0] = statb.st_ino[0];
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
106 handles[nhandles].ino[1] = statb.st_ino[1];
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
107 handles[nhandles].ino[2] = statb.st_ino[2];
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
108 #else
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
109 handles[nhandles].ino = statb.st_ino;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
110 #endif
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
111 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
112 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21077
diff changeset
114 #if !(defined(PYOS_OS2) && defined(PYCC_GCC))
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
115 dlopenflags = PyThreadState_GET()->interp->dlopenflags;
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21077
diff changeset
116 #endif
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 15806
diff changeset
117
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
118 #ifdef __VMS
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
119 /* VMS currently don't allow a pathname, use a logical name instead */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
120 /* Concatenate 'python_module_' and shortname */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
121 /* so "import vms.bar" will use the logical python_module_bar */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
122 /* As C module use only one name space this is probably not a */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
123 /* important limitation */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
124 PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s",
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
125 shortname);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
126 pathname = pathbuf;
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
127 #endif
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 22054
diff changeset
128
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
129 handle = dlopen(pathname, dlopenflags);
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 15806
diff changeset
130
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
131 if (handle == NULL) {
76434
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
132 PyObject *mod_name = NULL;
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
133 PyObject *path = NULL;
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
134 PyObject *error_ob = NULL;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
135 const char *error = dlerror();
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
136 if (error == NULL)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
137 error = "unknown dlopen() error";
76434
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
138 error_ob = PyUnicode_FromString(error);
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
139 path = PyUnicode_FromString(pathname);
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
140 mod_name = PyUnicode_FromString(shortname);
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
141 PyErr_SetImportError(error_ob, mod_name, path);
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
142 Py_DECREF(error_ob);
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
143 Py_DECREF(path);
573010778eed Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
144 Py_DECREF(mod_name);
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
145 return NULL;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
146 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
147 if (fp != NULL && nhandles < 128)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
148 handles[nhandles++].handle = handle;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
149 p = (dl_funcptr) dlsym(handle, funcname);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47580
diff changeset
150 return p;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 }