chiark / gitweb /
catacomb/__init__.py: Awful bodge for symbol conflict.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 14 Jul 2017 22:19:41 +0000 (23:19 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 15 Jul 2017 14:07:09 +0000 (15:07 +0100)
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.

catacomb/__init__.py

index 0ce4d0494fd9232d96662b293c42d5a95bd4e784..42b765bd4053d1b8b8a9dbb3a648dfa45df2c11f 100644 (file)
@@ -27,6 +27,8 @@ from __future__ import with_statement
 
 from binascii import hexlify as _hexify, unhexlify as _unhexify
 from contextlib import contextmanager as _ctxmgr
+import DLFCN as _dlfcn
+import os as _os
 from struct import pack as _pack
 import sys as _sys
 import types as _types
@@ -34,8 +36,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.