[Python-Dev] issue 9807 - a glitch in coexisting builds of different types

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 _PyImport_DynLoadFiletab are just not smart enough
>> to handle this case.  All it knows about are suffix, and for
>> backwards compatibility, we have dynload_shlib.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