Mercurial > cpython-lru_cache-weakref
annotate Python/dynload_shlib.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | a5681f50bae2 |
| children |
| 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> |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 #endif |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
20510
bdc486c66df0
Patch to bug #472202: Correctly recognize NetBSD before 199712.
Martin v. Löwis <martin@v.loewis.de>
parents:
19728
diff
changeset
|
23 #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
|
24 #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
|
25 #else |
|
bbc991ab6d32
Patch 102114, Bug 11725. On OpenBSD (but apparently not on the other
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
26 #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
|
27 #endif |
|
bbc991ab6d32
Patch 102114, Bug 11725. On OpenBSD (but apparently not on the other
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
28 |
| 64399 | 29 /* The .so extension module ABI tag, supplied by the Makefile via |
| 30 Makefile.pre.in and configure. This is used to discriminate between | |
| 31 incompatible .so files so that extensions for different Python builds can | |
| 32 live in the same directory. E.g. foomodule.cpython-32.so | |
| 33 */ | |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76434
diff
changeset
|
35 const char *_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
|
36 #ifdef __CYGWIN__ |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76434
diff
changeset
|
37 ".dll", |
| 64399 | 38 #else /* !__CYGWIN__ */ |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
22054
diff
changeset
|
39 #ifdef __VMS |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76434
diff
changeset
|
40 ".exe", |
|
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76434
diff
changeset
|
41 ".EXE", |
| 64399 | 42 #else /* !__VMS */ |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76434
diff
changeset
|
43 "." SOABI ".so", |
|
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76434
diff
changeset
|
44 ".abi" PYTHON_ABI_STRING ".so", |
|
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76434
diff
changeset
|
45 ".so", |
| 64399 | 46 #endif /* __VMS */ |
| 47 #endif /* __CYGWIN__ */ | |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76434
diff
changeset
|
48 NULL, |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 }; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 static struct { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
52 dev_t dev; |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
22054
diff
changeset
|
53 #ifdef __VMS |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
54 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
|
55 #else |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
56 ino_t ino; |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
22054
diff
changeset
|
57 #endif |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
58 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
|
59 } handles[128]; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 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
|
61 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
68108
0874698b1201
Issue #3080: Remove unused argument of _PyImport_GetDynLoadFunc()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66664
diff
changeset
|
63 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
|
64 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
|
65 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
66 dl_funcptr p; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
67 void *handle; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
68 char funcname[258]; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
69 char pathbuf[260]; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
70 int dlopenflags=0; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
71 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
72 if (strchr(pathname, '/') == NULL) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
73 /* Prefix bare filename with "./" */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
74 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
|
75 pathname = pathbuf; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
76 } |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
77 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
78 PyOS_snprintf(funcname, sizeof(funcname), |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
79 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
|
80 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
81 if (fp != NULL) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
82 int i; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
83 struct stat statb; |
|
84741
654268ff29b5
Check return value of fstat() in _PyImport_GetDynLoadFunc()
Christian Heimes <christian@cheimes.de>
parents:
78705
diff
changeset
|
84 if (fstat(fileno(fp), &statb) == -1) { |
| 84804 | 85 PyErr_SetFromErrno(PyExc_IOError); |
| 86 return NULL; | |
|
84741
654268ff29b5
Check return value of fstat() in _PyImport_GetDynLoadFunc()
Christian Heimes <christian@cheimes.de>
parents:
78705
diff
changeset
|
87 } |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
88 for (i = 0; i < nhandles; i++) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
89 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
|
90 statb.st_ino == handles[i].ino) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
91 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
|
92 funcname); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
93 return p; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
94 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
95 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
96 if (nhandles < 128) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
97 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
|
98 #ifdef __VMS |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 #else |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
103 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
|
104 #endif |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
105 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
106 } |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
108 dlopenflags = PyThreadState_GET()->interp->dlopenflags; |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
15806
diff
changeset
|
109 |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
22054
diff
changeset
|
110 #ifdef __VMS |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
111 /* 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
|
112 /* Concatenate 'python_module_' and shortname */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
113 /* 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
|
114 /* 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
|
115 /* important limitation */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
116 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
|
117 shortname); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
118 pathname = pathbuf; |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
22054
diff
changeset
|
119 #endif |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
22054
diff
changeset
|
120 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
121 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
|
122 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
123 if (handle == NULL) { |
|
79393
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
124 PyObject *mod_name; |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
125 PyObject *path; |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
126 PyObject *error_ob; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
127 const char *error = dlerror(); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
128 if (error == NULL) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
129 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
|
130 error_ob = PyUnicode_FromString(error); |
|
79393
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
131 if (error_ob == NULL) |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
132 return NULL; |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
133 mod_name = PyUnicode_FromString(shortname); |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
134 if (mod_name == NULL) { |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
135 Py_DECREF(error_ob); |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
136 return NULL; |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
137 } |
|
76434
573010778eed
Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents:
76303
diff
changeset
|
138 path = PyUnicode_FromString(pathname); |
|
79393
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
139 if (path == NULL) { |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
140 Py_DECREF(error_ob); |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
141 Py_DECREF(mod_name); |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
142 return NULL; |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
143 } |
|
76434
573010778eed
Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents:
76303
diff
changeset
|
144 PyErr_SetImportError(error_ob, mod_name, path); |
|
79393
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
145 Py_DECREF(error_ob); |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
146 Py_DECREF(mod_name); |
|
f3ed5e211fcc
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
Victor Stinner <victor.stinner@gmail.com>
parents:
78705
diff
changeset
|
147 Py_DECREF(path); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
148 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
149 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
150 if (fp != NULL && nhandles < 128) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
151 handles[nhandles++].handle = handle; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
152 p = (dl_funcptr) dlsym(handle, funcname); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
153 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
|
154 } |
