[liblouis-liblouisxml] LoadLibrary and ABI

  • From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Fri, 26 Jun 2009 02:10:45 +0200

Hello,

The python bindings of liblouis uses LoadLibrary then ctypes to access
liblouis' functions. However, this does not handle the case when the
library ABI changes (e.g. if length parameters were turned into size_t)
and both new versions of the library and old versions of the library
co-exist. Also, some systems do not use the .so extension, but .dylib,
etc. The attached subversion patch extracts the precise name of the
library that the python bindings was built with, to make sure to load
the correct file. It assumes that you have run

svn mv __init__.py __init__.py.in

Samuel
Index: python/louis/Makefile.am
===================================================================
--- python/louis/Makefile.am    (révision 182)
+++ python/louis/Makefile.am    (copie de travail)
@@ -1,2 +1,10 @@
-EXTRA_DIST = __init__.py
+EXTRA_DIST = __init__.py.in
+CLEANFILES = __init__.py
 
+LIBLOUIS_SONAME = $(shell source ../../liblouis/liblouis.la ; echo $$dlname)
+
+all:
+       source ../../liblouis/liblouis.la ; \
+       sed "s/###LIBLOUIS_SONAME###/$$dlname/" \
+               < $(srcdir)/__init__.py.in \
+               > __init__.py
Index: python/louis/__init__.py.in
===================================================================
--- python/louis/__init__.py.in (révision 182)
+++ python/louis/__init__.py.in (copie de travail)
@@ -38,7 +38,7 @@
         liblouis = cdll.liblouis
 except OSError:
     # Unix
-    liblouis = cdll.LoadLibrary("liblouis.so")
+    liblouis = cdll.LoadLibrary("###LIBLOUIS_SONAME###")
 
 atexit.register(liblouis.lou_free)
 

Other related posts: