[Numpy-svn] r4876 - in trunk/numpy: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Mar 16 12:37:25 EDT 2008


Author: stefan
Date: 2008-03-16 11:37:08 -0500 (Sun, 16 Mar 2008)
New Revision: 4876

Modified:
   trunk/numpy/ctypeslib.py
   trunk/numpy/tests/test_ctypeslib.py
Log:
In ctypes.load_library, also attempt to load .so files on failure.
Build processes sometimes produce libraries with incorrect suffixes on
non-linux platforms.


Modified: trunk/numpy/ctypeslib.py
===================================================================
--- trunk/numpy/ctypeslib.py	2008-03-16 03:57:00 UTC (rev 4875)
+++ trunk/numpy/ctypeslib.py	2008-03-16 16:37:08 UTC (rev 4876)
@@ -30,20 +30,30 @@
             warnings.warn("All features of ctypes interface may not work " \
                           "with ctypes < 1.0.1")
         if '.' not in libname:
+            # Try to load library with platform-specific name, otherwise
+            # default to libname.so.  Sometimes, .so files are built
+            # erroneously on non-linux platforms.
+            libname_ext = ['%s.so' % libname]
             if sys.platform == 'win32':
-                libname = '%s.dll' % libname
+                libname_ext.insert(0, '%s.dll' % libname)
             elif sys.platform == 'darwin':
-                libname = '%s.dylib' % libname
-            else:
-                libname = '%s.so' % libname
+                libname_ext.insert(0, '%s.dylib' % libname)
+
         loader_path = os.path.abspath(loader_path)
         if not os.path.isdir(loader_path):
             libdir = os.path.dirname(loader_path)
         else:
             libdir = loader_path
-        libpath = os.path.join(libdir, libname)
-        return ctypes.cdll[libpath]
 
+        for ln in libname_ext:
+            try:
+                libpath = os.path.join(libdir, ln)
+                return ctypes.cdll[libpath]
+            except OSError, e:
+                pass
+
+        raise e
+
     ctypes_load_library = deprecate(load_library, 'ctypes_load_library',
                                     'load_library')
 

Modified: trunk/numpy/tests/test_ctypeslib.py
===================================================================
--- trunk/numpy/tests/test_ctypeslib.py	2008-03-16 03:57:00 UTC (rev 4875)
+++ trunk/numpy/tests/test_ctypeslib.py	2008-03-16 16:37:08 UTC (rev 4876)
@@ -1,7 +1,12 @@
 import numpy as np
-from numpy.ctypeslib import ndpointer
+from numpy.ctypeslib import ndpointer, load_library
 from numpy.testing import *
 
+class TestLoadLibrary(NumpyTestCase):
+    def check_basic(self):
+        cdll = load_library('multiarray',
+                            np.core.multiarray.__file__)
+
 class TestNdpointer(NumpyTestCase):
     def check_dtype(self):
         dt = np.intc




More information about the Numpy-svn mailing list