diff options
author | Thomas Heller <theller@ctypes.org> | 2006-04-05 17:36:45 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2006-04-05 17:36:45 (GMT) |
commit | 726dcf34a6cfa95e083d9e020752be4cab29672d (patch) | |
tree | ffe2fa6cc7cc1099b7712f44b5480402ed4be500 /Lib | |
parent | a2a26b9e1f00692c01ea6a731eef7d150088a5bd (diff) | |
download | cpython-726dcf34a6cfa95e083d9e020752be4cab29672d.zip cpython-726dcf34a6cfa95e083d9e020752be4cab29672d.tar.gz cpython-726dcf34a6cfa95e083d9e020752be4cab29672d.tar.bz2 |
Use 'ldd' to find the libc library to load. Based on an idea from Matthias Klose.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/test/test_loading.py | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py index dd2886c..dec296b 100644 --- a/Lib/ctypes/test/test_loading.py +++ b/Lib/ctypes/test/test_loading.py @@ -2,59 +2,59 @@ from ctypes import * import sys, unittest import os, StringIO +libc_name = None +if os.name == "nt": + libc_name = "msvcrt" +elif os.name == "ce": + libc_name = "coredll" +elif sys.platform == "darwin": + libc_name = "libc.dylib" +elif sys.platform == "cygwin": + libc_name = "cygwin1.dll" +else: + for line in os.popen("ldd %s" % sys.executable): + if "libc.so" in line: + if sys.platform == "openbsd3": + libc_name = line.split()[4] + else: + libc_name = line.split()[2] +## print "libc_name is", libc_name + break + class LoaderTest(unittest.TestCase): unknowndll = "xxrandomnamexx" - def test_load(self): - if os.name == "nt": - name = "msvcrt" - elif os.name == "ce": - name = "coredll" - elif sys.platform == "darwin": - name = "libc.dylib" - elif sys.platform.startswith("freebsd"): - name = "libc.so" - elif sys.platform in ("sunos5", "osf1V5"): - name = "libc.so" - elif sys.platform.startswith("netbsd") or sys.platform.startswith("openbsd"): - name = "libc.so" - else: - name = "libc.so.6" -## print (sys.platform, os.name) - try: - cdll.load(name) - except Exception, details: - self.fail((str(details), name, (os.name, sys.platform))) - self.assertRaises(OSError, cdll.load, self.unknowndll) + if libc_name is not None: + def test_load(self): + cdll.load(libc_name) + cdll.load(os.path.basename(libc_name)) + self.assertRaises(OSError, cdll.load, self.unknowndll) - def test_load_version(self): - version = "6" - name = "c" - if sys.platform == "linux2": - cdll.load_version(name, version) + if libc_name is not None and "libc.so.6" in libc_name: + def test_load_version(self): + cdll.load_version("c", "6") # linux uses version, libc 9 should not exist - self.assertRaises(OSError, cdll.load_version, name, "9") - self.assertRaises(OSError, cdll.load_version, self.unknowndll, "") + self.assertRaises(OSError, cdll.load_version, "c", "9") + self.assertRaises(OSError, cdll.load_version, self.unknowndll, "") - if os.name == "posix" and sys.platform != "sunos5": def test_find(self): name = "c" cdll.find(name) self.assertRaises(OSError, cdll.find, self.unknowndll) - def test_load_library(self): - if os.name == "nt": - windll.load_library("kernel32").GetModuleHandleW - windll.LoadLibrary("kernel32").GetModuleHandleW - WinDLL("kernel32").GetModuleHandleW - elif os.name == "ce": - windll.load_library("coredll").GetModuleHandleW - windll.LoadLibrary("coredll").GetModuleHandleW - WinDLL("coredll").GetModuleHandleW + if os.name in ("nt", "ce"): + def test_load_library(self): + if os.name == "nt": + windll.load_library("kernel32").GetModuleHandleW + windll.LoadLibrary("kernel32").GetModuleHandleW + WinDLL("kernel32").GetModuleHandleW + elif os.name == "ce": + windll.load_library("coredll").GetModuleHandleW + windll.LoadLibrary("coredll").GetModuleHandleW + WinDLL("coredll").GetModuleHandleW - def test_load_ordinal_functions(self): - if os.name in ("nt", "ce"): + def test_load_ordinal_functions(self): import _ctypes_test dll = WinDLL(_ctypes_test.__file__) # We load the same function both via ordinal and name |