Skip to content

Commit

Permalink
Issue #16421: allow to load multiple modules from the same shared obj…
Browse files Browse the repository at this point in the history
…ect.

Patch by Václav Šmilauer.
  • Loading branch information
asvetlov committed Dec 14, 2012
1 parent f76f0ee commit 6b2cbeb
Show file tree
Hide file tree
Showing 12 changed files with 887 additions and 10 deletions.
14 changes: 14 additions & 0 deletions Lib/test/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ def test_issue15828_load_extensions(self):
mod = imp.load_module(example, *x)
self.assertEqual(mod.__name__, example)

def test_issue16421_multiple_modules_in_one_dll(self):
# Issue 16421: loading several modules from the same compiled file fails
m = '_testimportmultiple'
fileobj, pathname, description = imp.find_module(m)
fileobj.close()
mod0 = imp.load_dynamic(m, pathname)
mod1 = imp.load_dynamic('foo', pathname)
mod2 = imp.load_dynamic('bar', pathname)
self.assertEqual(mod0.__name__, m)
self.assertEqual(mod1.__name__, 'foo')
self.assertEqual(mod2.__name__, 'bar')
with self.assertRaises(ImportError):
imp.load_dynamic('nonexistent', pathname)

def test_load_dynamic_ImportError_path(self):
# Issue #1559549 added `name` and `path` attributes to ImportError
# in order to provide better detail. Issue #10854 implemented those
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ George Sipe
J. Sipprell
Kragen Sitaker
Michael Sloan
Václav Šmilauer
Christopher Smith
Eric V. Smith
Gregory P. Smith
Expand Down
4 changes: 4 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ What's New in Python 3.4.0 Alpha 1?
Core and Builtins
-----------------

- Issue #16421: loading multiple modules from one shared object is now
handled correctly (previously, the first module loaded from that file
was silently returned). Patch by Václav Šmilauer.

- Issue #16602: When a weakref's target was part of a long deallocation
chain, the object could remain reachable through its weakref even though
its refcount had dropped to zero.
Expand Down
57 changes: 57 additions & 0 deletions Modules/_testimportmultiple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* C extensions module to test importing multiple modules from one compiled
* file (issue16421). This file defines 3 modules (_testimportmodule,
* foo, bar), only the first one is called the same as the compiled file.
*/
#include<Python.h>

static struct PyModuleDef _testimportmultiple = {
PyModuleDef_HEAD_INIT,
"_testimportmultiple",
"_testimportmultiple doc",
-1,
NULL,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC PyInit__testimportmultiple()
{
return PyModule_Create(&_testimportmultiple);
}

static struct PyModuleDef _foomodule = {
PyModuleDef_HEAD_INIT,
"foo",
"foo doc",
-1,
NULL,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC PyInit_foo()
{
return PyModule_Create(&_foomodule);
}

static struct PyModuleDef _barmodule = {
PyModuleDef_HEAD_INIT,
"bar",
"bar doc",
-1,
NULL,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC PyInit_bar(){
return PyModule_Create(&_barmodule);
}

Loading

0 comments on commit 6b2cbeb

Please sign in to comment.