Mercurial > cpython-lru_cache-weakref
annotate Python/importdl.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 | 479af6ca3a3c |
| children |
| rev | line source |
|---|---|
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* Support for dynamic loading of extension modules */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
4 #include "Python.h" |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
5 |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
6 /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
7 supported on this platform. configure will then compile and link in one |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
8 of the dynload_*.c files, as appropriate. We will call a function in |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
9 those modules to get a function pointer to the module's init function. |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
10 */ |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
11 #ifdef HAVE_DYNAMIC_LOADING |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
12 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 #include "importdl.h" |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
15 #ifdef MS_WINDOWS |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
16 extern dl_funcptr _PyImport_GetDynLoadWindows(const char *shortname, |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
17 PyObject *pathname, FILE *fp); |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
18 #else |
|
68108
0874698b1201
Issue #3080: Remove unused argument of _PyImport_GetDynLoadFunc()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65418
diff
changeset
|
19 extern 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
|
20 const char *pathname, FILE *fp); |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
21 #endif |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5314
diff
changeset
|
23 PyObject * |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
24 _PyImport_LoadDynamicModule(PyObject *name, PyObject *path, FILE *fp) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 { |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
26 PyObject *m = NULL; |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
27 #ifndef MS_WINDOWS |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
28 PyObject *pathbytes; |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
29 #endif |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
30 PyObject *nameascii; |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
31 char *namestr, *lastdot, *shortname, *packagecontext, *oldcontext; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
32 dl_funcptr p0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
33 PyObject* (*p)(void); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
34 struct PyModuleDef *def; |
|
11600
14561e8395bb
Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents:
11469
diff
changeset
|
35 |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
36 m = _PyImport_FindExtensionObject(name, path); |
|
68712
2425717c6430
Issue #3080: Import builtins using Unicode strings
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
37 if (m != NULL) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
38 Py_INCREF(m); |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
39 return m; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
40 } |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
41 |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
42 /* name must be encodable to ASCII because dynamic module must have a |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
43 function called "PyInit_NAME", they are written in C, and the C language |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
44 doesn't accept non-ASCII identifiers. */ |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
45 nameascii = PyUnicode_AsEncodedString(name, "ascii", NULL); |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
46 if (nameascii == NULL) |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
47 return NULL; |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
48 |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
49 namestr = PyBytes_AS_STRING(nameascii); |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
50 if (namestr == NULL) |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
51 goto error; |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
52 |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
53 lastdot = strrchr(namestr, '.'); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
54 if (lastdot == NULL) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
55 packagecontext = NULL; |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
56 shortname = namestr; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
57 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
58 else { |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
59 packagecontext = namestr; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
60 shortname = lastdot+1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
61 } |
|
3907
ac1d5abfd78e
Changes for AIX sharedlibs.
Guido van Rossum <guido@python.org>
parents:
3898
diff
changeset
|
62 |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
63 #ifdef MS_WINDOWS |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
64 p0 = _PyImport_GetDynLoadWindows(shortname, path, fp); |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
65 #else |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
66 pathbytes = PyUnicode_EncodeFSDefault(path); |
|
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
67 if (pathbytes == NULL) |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
68 goto error; |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
69 p0 = _PyImport_GetDynLoadFunc(shortname, |
|
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
70 PyBytes_AS_STRING(pathbytes), fp); |
|
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
71 Py_DECREF(pathbytes); |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68716
diff
changeset
|
72 #endif |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
73 p = (PyObject*(*)(void))p0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
74 if (PyErr_Occurred()) |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
75 goto error; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
76 if (p == NULL) { |
|
76434
573010778eed
Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents:
76303
diff
changeset
|
77 PyObject *msg = PyUnicode_FromFormat("dynamic module does not define " |
|
573010778eed
Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents:
76303
diff
changeset
|
78 "init function (PyInit_%s)", |
|
573010778eed
Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents:
76303
diff
changeset
|
79 shortname); |
|
84693
479af6ca3a3c
Issue #18408: Fix _PyImport_LoadDynamicModule(), handle PyUnicode_FromFormat() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84538
diff
changeset
|
80 if (msg == NULL) |
|
479af6ca3a3c
Issue #18408: Fix _PyImport_LoadDynamicModule(), handle PyUnicode_FromFormat() failure
Victor Stinner <victor.stinner@gmail.com>
parents:
84538
diff
changeset
|
81 goto error; |
|
76434
573010778eed
Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents:
76303
diff
changeset
|
82 PyErr_SetImportError(msg, name, path); |
|
573010778eed
Issue #14599: Generalize a test for ImportError.path and add support
Brett Cannon <brett@python.org>
parents:
76303
diff
changeset
|
83 Py_DECREF(msg); |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
84 goto error; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
85 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
86 oldcontext = _Py_PackageContext; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
87 _Py_PackageContext = packagecontext; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
88 m = (*p)(); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
89 _Py_PackageContext = oldcontext; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
90 if (m == NULL) |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
91 goto error; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
93 if (PyErr_Occurred()) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
94 PyErr_Format(PyExc_SystemError, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
95 "initialization of %s raised unreported exception", |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
96 shortname); |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
97 goto error; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
98 } |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
43573
diff
changeset
|
99 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
100 /* Remember pointer to module init function. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
101 def = PyModule_GetDef(m); |
|
84538
fce581643cb6
Issue #18426: improve exception message. Courtesy of Amaury
Christian Heimes <christian@cheimes.de>
parents:
84536
diff
changeset
|
102 if (def == NULL) { |
|
fce581643cb6
Issue #18426: improve exception message. Courtesy of Amaury
Christian Heimes <christian@cheimes.de>
parents:
84536
diff
changeset
|
103 PyErr_Format(PyExc_SystemError, |
|
fce581643cb6
Issue #18426: improve exception message. Courtesy of Amaury
Christian Heimes <christian@cheimes.de>
parents:
84536
diff
changeset
|
104 "initialization of %s did not return an extension " |
|
fce581643cb6
Issue #18426: improve exception message. Courtesy of Amaury
Christian Heimes <christian@cheimes.de>
parents:
84536
diff
changeset
|
105 "module", shortname); |
|
84536
4343dfaca8e2
Issue #18426: Fix NULL pointer dereference in C extension import when
Christian Heimes <christian@cheimes.de>
parents:
76434
diff
changeset
|
106 goto error; |
|
84538
fce581643cb6
Issue #18426: improve exception message. Courtesy of Amaury
Christian Heimes <christian@cheimes.de>
parents:
84536
diff
changeset
|
107 } |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
108 def->m_base.m_init = p; |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
43573
diff
changeset
|
109 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
110 /* Remember the filename as the __file__ attribute */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
111 if (PyModule_AddObject(m, "__file__", path) < 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47580
diff
changeset
|
112 PyErr_Clear(); /* Not important enough to report */ |
|
65418
fd5135cbd928
_PyImport_FixupExtension() and _PyImport_FindExtension() uses FS encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
113 else |
|
fd5135cbd928
_PyImport_FixupExtension() and _PyImport_FindExtension() uses FS encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
114 Py_INCREF(path); |
|
30316
19611d101d23
Patch #794826: Add __file__ in dynamically loaded modules for multiple
Martin v. Löwis <martin@v.loewis.de>
parents:
25040
diff
changeset
|
115 |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
116 if (_PyImport_FixupExtensionObject(m, name, path) < 0) |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
117 goto error; |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
118 Py_DECREF(nameascii); |
|
68716
ef2b6305d395
Issue #3080: _PyImport_LoadDynamicModule() uses Unicode for name and path
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68712
diff
changeset
|
119 return m; |
|
69889
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
120 |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
121 error: |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
122 Py_DECREF(nameascii); |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
123 Py_XDECREF(m); |
|
eb003c3d1770
_PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII
Victor Stinner <victor.stinner@haypocalc.com>
parents:
69145
diff
changeset
|
124 return NULL; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
125 } |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11600
diff
changeset
|
126 |
|
11600
14561e8395bb
Moved most of the platform-specific code to dynload_<platform>.c files.
Guido van Rossum <guido@python.org>
parents:
11469
diff
changeset
|
127 #endif /* HAVE_DYNAMIC_LOADING */ |
