mirror of
https://github.com/yann64/haikuports.git
synced 2026-04-10 22:00:09 +02:00
[python-2.7 & 3.6] Implement CTypes's find_library() for Haiku. (#1363)
Should fix #1120 for python v2.7.13 and v3.6.1.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
From 4f5d1b027f1e5b1bba2155aec103cec7233f9d7c Mon Sep 17 00:00:00 2001
|
||||
From 0172d4c19e066892e3009ae5fe41e7aa2a9bcff7 Mon Sep 17 00:00:00 2001
|
||||
From: Jerome Duval <jerome.duval@gmail.com>
|
||||
Date: Thu, 10 Apr 2014 16:03:33 +0000
|
||||
Subject: initial Haiku patch
|
||||
@@ -536,10 +536,10 @@ index f04bf22..718c03a 100644
|
||||
if (self.compiler.find_library_file(lib_dirs, 'nsl')):
|
||||
libs = ['nsl']
|
||||
--
|
||||
2.11.0
|
||||
2.12.2
|
||||
|
||||
|
||||
From 7133afd2665e636cd11daadbaa672f1a45ed031e Mon Sep 17 00:00:00 2001
|
||||
From 98f3a8c3e3d810181523691d2f340aba0a35f538 Mon Sep 17 00:00:00 2001
|
||||
From: Jerome Duval <jerome.duval@gmail.com>
|
||||
Date: Sun, 16 Apr 2017 10:05:42 +0200
|
||||
Subject: fix for negative errnos
|
||||
@@ -574,5 +574,89 @@ index 5007a39..625c507 100644
|
||||
*--cur = Py_hexdigits[saved_errno % 16];
|
||||
saved_errno /= 16;
|
||||
--
|
||||
2.11.0
|
||||
2.12.2
|
||||
|
||||
|
||||
From 253ba23338ad0d16d6b0df8811d26fe8cd9f7bc0 Mon Sep 17 00:00:00 2001
|
||||
From: Philippe Houdoin <philippe.houdoin@gmail.com>
|
||||
Date: Wed, 24 May 2017 11:09:43 +0000
|
||||
Subject: Implement CTypes's find_library for Haiku
|
||||
|
||||
|
||||
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
|
||||
index 339ae8a..d537963 100644
|
||||
--- a/Lib/ctypes/util.py
|
||||
+++ b/Lib/ctypes/util.py
|
||||
@@ -243,6 +243,56 @@ elif os.name == "posix":
|
||||
def find_library(name, is64 = False):
|
||||
return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))
|
||||
|
||||
+ elif sys.platform.startswith("haiku"):
|
||||
+
|
||||
+ def _num_version(libname):
|
||||
+ # "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ]
|
||||
+ parts = libname.split('.')
|
||||
+ nums = []
|
||||
+ try:
|
||||
+ while parts:
|
||||
+ nums.insert(0, int(parts.pop()))
|
||||
+ except ValueError:
|
||||
+ pass
|
||||
+ return nums or [sys.maxint]
|
||||
+
|
||||
+ def find_library(name):
|
||||
+ if name in ('c', 'm'):
|
||||
+ return find_library('root')
|
||||
+ for directory in os.environ['LIBRARY_PATH'].split(os.pathsep):
|
||||
+ if directory.startswith("%A/"):
|
||||
+ directory = directory.replace('%A',
|
||||
+ os.path.dirname(os.path.abspath(sys.argv[0] or os.getcwd())))
|
||||
+
|
||||
+ if not os.path.isdir(directory):
|
||||
+ continue
|
||||
+
|
||||
+ # try direct match
|
||||
+ fname = os.path.join(directory, name)
|
||||
+ if os.path.isfile(fname):
|
||||
+ return fname
|
||||
+
|
||||
+ fname = os.path.join(directory, 'lib%s.so' % name)
|
||||
+ if os.path.isfile(fname):
|
||||
+ return fname
|
||||
+
|
||||
+ # no exact matching in this directroy
|
||||
+ # collect versioned candidates, if any
|
||||
+ candidates = []
|
||||
+ pattern = re.compile(r'lib%s\.so\.\S+' % re.escape(name))
|
||||
+ for entry in os.listdir(directory):
|
||||
+ if not os.path.isfile(os.path.join(directory, entry)):
|
||||
+ continue
|
||||
+
|
||||
+ if re.match(pattern, entry):
|
||||
+ candidates.append(os.path.join(directory, entry))
|
||||
+
|
||||
+ if candidates:
|
||||
+ # return latest version found
|
||||
+ candidates.sort(key=_num_version)
|
||||
+ return candidates[-1]
|
||||
+
|
||||
+ return None
|
||||
else:
|
||||
|
||||
def _findSoname_ldconfig(name):
|
||||
@@ -328,6 +378,12 @@ def test():
|
||||
print(cdll.LoadLibrary("libcrypto.dylib"))
|
||||
print(cdll.LoadLibrary("libSystem.dylib"))
|
||||
print(cdll.LoadLibrary("System.framework/System"))
|
||||
+ elif sys.platform.startswith("haiku"):
|
||||
+ print(find_library("libbz2.so.1.0"))
|
||||
+ print(find_library("tracker"))
|
||||
+ print(find_library("media"))
|
||||
+ print(cdll.LoadLibrary(find_library("tracker")))
|
||||
+ print(cdll.LoadLibrary("libmedia.so"))
|
||||
else:
|
||||
print(cdll.LoadLibrary("libm.so"))
|
||||
print(cdll.LoadLibrary("libcrypt.so"))
|
||||
--
|
||||
2.12.2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user