summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-12-14 15:04:59 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-12-14 15:04:59 (GMT)
commit6b2cbeba58aeb0755bdefd02fb51a80ec66d6144 (patch)
tree2634f036965fc3ebf737ef3ce1b830437de9a04f /Python
parentf76f0eea5c00ea20ac62d9a8437a19f23fd455c5 (diff)
downloadcpython-6b2cbeba58aeb0755bdefd02fb51a80ec66d6144.zip
cpython-6b2cbeba58aeb0755bdefd02fb51a80ec66d6144.tar.gz
cpython-6b2cbeba58aeb0755bdefd02fb51a80ec66d6144.tar.bz2
Issue #16421: allow to load multiple modules from the same shared object.
Patch by Václav Šmilauer.
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/Python/import.c b/Python/import.c
index 6882b57..8e7482a 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -452,12 +452,12 @@ PyImport_GetMagicTag(void)
/* Magic for extension modules (built-in as well as dynamically
loaded). To prevent initializing an extension module more than
- once, we keep a static dictionary 'extensions' keyed by module name
- (for built-in modules) or by filename (for dynamically loaded
- modules), containing these modules. A copy of the module's
- dictionary is stored by calling _PyImport_FixupExtensionObject()
- immediately after the module initialization function succeeds. A
- copy can be retrieved from there by calling
+ once, we keep a static dictionary 'extensions' keyed by the tuple
+ (module name, module name) (for built-in modules) or by
+ (filename, module name) (for dynamically loaded modules), containing these
+ modules. A copy of the module's dictionary is stored by calling
+ _PyImport_FixupExtensionObject() immediately after the module initialization
+ function succeeds. A copy can be retrieved from there by calling
_PyImport_FindExtensionObject().
Modules which do support multiple initialization set their m_size
@@ -470,7 +470,7 @@ int
_PyImport_FixupExtensionObject(PyObject *mod, PyObject *name,
PyObject *filename)
{
- PyObject *modules, *dict;
+ PyObject *modules, *dict, *filename_name;
struct PyModuleDef *def;
if (extensions == NULL) {
extensions = PyDict_New();
@@ -508,7 +508,11 @@ _PyImport_FixupExtensionObject(PyObject *mod, PyObject *name,
if (def->m_base.m_copy == NULL)
return -1;
}
- PyDict_SetItem(extensions, filename, (PyObject*)def);
+ filename_name = PyTuple_Pack(2,filename, name);
+ if (filename_name == NULL)
+ return -1;
+ if (PyDict_SetItem(extensions, filename_name, (PyObject*)def) < 0)
+ return -1;
return 0;
}
@@ -528,11 +532,14 @@ _PyImport_FixupBuiltin(PyObject *mod, char *name)
PyObject *
_PyImport_FindExtensionObject(PyObject *name, PyObject *filename)
{
- PyObject *mod, *mdict;
+ PyObject *mod, *mdict, *filename_name;
PyModuleDef* def;
if (extensions == NULL)
return NULL;
- def = (PyModuleDef*)PyDict_GetItem(extensions, filename);
+ filename_name = PyTuple_Pack(2,filename, name);
+ if (filename_name == NULL)
+ return NULL;
+ def = (PyModuleDef*)PyDict_GetItem(extensions, filename_name);
if (def == NULL)
return NULL;
if (def->m_size == -1) {