[Python-Dev] issue 9807 - a glitch in coexisting builds of different types (original) (raw)

Barry Warsaw barry at python.org
Mon Oct 4 20:28:51 CEST 2010


On Oct 02, 2010, at 10:36 AM, Georg Brandl wrote:

Am 02.10.2010 00:06, schrieb Barry Warsaw:

The reason is that the import.c logic that uses the struct filedescr tables built from PyImportDynLoadFiletab are just not smart enough to handle this case. All it knows about are suffix, and for backwards compatibility, we have dynloadshlib.c matching both .SOABI.so and bare .so. So when it's searching the directories for .cpython-32m.so files, it finds the ..cpython-32dmu.so first based on the bare .so match. I don't understand -- wouldn't "foo.sometag.so" (where sometag is not SOABI) only be found a match for a suffix of ".so" if the module name requested is "foo.sometag"? (And if not, isn't implementing that the easiest solution?)

Yep, my analysis was faulty. Python's own import machinery does exactly the right thing. I think the problem is in distribute, which writes a _foo.py file that bootstraps into loading the wrong .so file. E.g. for an extension names _stupid, you end up with this _stupid.py in the egg:

def bootstrap(): global bootstrap, loader, file import sys, pkg_resources, imp file = pkg_resources.resource_filename(name,'_stupid.cpython-32dmu.so') loader = None; del bootstrap, loader imp.load_dynamic(name,file) bootstrap()

Python's built-in import finds _stupid.py, but this is hardcoded to the build-flags of the last Python used to install the package. If instead this looked like:

def bootstrap(): global bootstrap, loader, file import sys, pkg_resources, imp, sysconfig file = pkg_resources.resource_filename(name,'_stupid.{soabi}.so'.format(soabi=sysconfig.get_config_var('SOABI'))) loader = None; del bootstrap, loader imp.load_dynamic(name,file) bootstrap()

then everything works out just fine. If you install only the 'dmu' version and try to import it with the 'm' Python, you get an ImportError as expected (i.e. not a crash!).

-Barry -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20101004/1e6c0a2a/attachment.pgp>



More information about the Python-Dev mailing list