From: Mark Wooding Date: Fri, 14 Jul 2017 22:19:41 +0000 (+0100) Subject: catacomb/__init__.py: Awful bodge for symbol conflict. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/8854bd74bdb76307df1d695b6820ab4e25b7088f catacomb/__init__.py: Awful bodge for symbol conflict. It seems that, in Debian jessie and later, the main Python binary now exports `md5_init' and friends. Unfortunately, this overrides Catacomb's existing `md5_init' with a rather different version, and the result is a segfault (on i386) or wrong answers (on amd64). So, as an unpleasant bodge (while this broken thing makes its way through Debian, see bug #868366), try to force the `RTLD_DEEPBIND' flag when loading the module. This is unfortunate, because Python doesn't actually advertise this flag, at least in my version. (cherry picked from commit a3ae4a9f590ef84d8e6eac0bc94873a9fd943073) --- diff --git a/catacomb/__init__.py b/catacomb/__init__.py index 53d7cea..eb3344a 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -27,6 +27,9 @@ from __future__ import with_statement from binascii import hexlify as _hexify, unhexlify as _unhexify from contextlib import contextmanager as _ctxmgr +try: import DLFCN as _dlfcn +except ImportError: _dlfcn = None +import os as _os from struct import pack as _pack import sys as _sys import types as _types @@ -34,8 +37,31 @@ import types as _types ###-------------------------------------------------------------------------- ### Import the main C extension module. +try: + _dlflags = _odlflags = _sys.getdlopenflags() +except AttributeError: + _dlflags = _odlflags = -1 + +## Set the `deep binding' flag. Python has its own different MD5 +## implementation, and some distributions export `md5_init' and friends so +## they override our versions, which doesn't end well. Figure out how to +## turn this flag on so we don't have the problem. +if _dlflags >= 0: + try: _dlflags |= _dlfcn.RTLD_DEEPBIND + except AttributeError: + try: _dlflags |= _os.RTLD_DEEPBIND + except AttributeError: + if _os.uname()[0] == 'Linux': _dlflags |= 8 # magic knowledge + else: pass # can't do this. + _sys.setdlopenflags(_dlflags) + import _base +if _odlflags >= 0: + _sys.setdlopenflags(_odlflags) + +del _dlflags, _odlflags + ###-------------------------------------------------------------------------- ### Basic stuff.