Message261012
The following demonstrates the basics.
cdll.LoadLibrary will load a .so file if it can be located (you will have to believe me as I forgot to include the test in this last batch)
Further, when given the AIX format for loading a member of an archive
(e.g., libc.a(shr.o) or libcrypto.a(libcrypto.so), the dlload occurs as expected.
in ctypes/utils.py
This looks in the standard directories (as the example, but not complete, see below) to demonstrate how to respond.
Note: it is also looking for a .so file, and if it finds one, it returns the .so name, otherwise it looks for a .a file - and when it finds it, just appends the libNAME.so in the correct format.
What is not done, and probably different from ldconfig behavior!
1. The complete path is not returned (so cdll.LoadLibrary will still follow default search - which I hope includes, read uses, the default for the python executable
2. The member name is not verified for existence (e.g., libconv.a(libiconv.so) is not expected to find libiconv.a(libiconv.so.2)
3. Since member verification is not being performed, shr.o, shr4.o, shr*_64.o
And many many thanks for the strip -e/-E info. Hard to find!
root@x064:[/data/prj/aixtools/src]diff -u python-2.7.11/Lib/ctypes/__init__.py /opt/lib/python2.7/ctypes/__init__.py
--- python-2.7.11/Lib/ctypes/__init__.py 2015-12-05 19:46:56 +0000
+++ /opt/lib/python2.7/ctypes/__init__.py 2016-02-29 17:36:43 +0000
@@ -11,6 +11,7 @@
from _ctypes import _Pointer
from _ctypes import CFuncPtr as _CFuncPtr
from _ctypes import __version__ as _ctypes_version
+# from _ctypes import RTLD_LOCAL, RTLD_GLOBAL, RTLD_NOW ## fails
from _ctypes import RTLD_LOCAL, RTLD_GLOBAL
from _ctypes import ArgumentError
@@ -356,6 +357,14 @@
if use_last_error:
flags |= _FUNCFLAG_USE_LASTERROR
+ if _sys.platform.startswith("aix"):
+ RTLD_NOW = 0x00000002
+ RTLD_MEMBER = 0x00040000
+ mode |= RTLD_NOW
+ if name is not None:
+ if name[-1] == ')':
+ mode |= RTLD_MEMBER
+
class _FuncPtr(_CFuncPtr):
_flags_ = flags
_restype_ = self._func_restype_
root@x064:[/data/prj/aixtools/src]diff -u python-2.7.11/Lib/ctypes/util.py /opt/lib/python2.7/ctypes/util.py
--- python-2.7.11/Lib/ctypes/util.py 2015-12-05 19:46:56 +0000
+++ /opt/lib/python2.7/ctypes/util.py 2016-02-29 17:42:41 +0000
@@ -84,6 +84,23 @@
continue
return None
+if os.name == "posix" and sys.platform.startswith("aix"):
+ def _findLib_aix(name):
+ paths='/usr/lib:/lib:/usr/lpp/xlC/lib'
+ for dir in paths.split(":"):
+ shlib = os.path.join(dir, "lib%s.so" % name)
+ if os.path.exists(shlib):
+ return shlib
+ libfile = os.path.join(dir, "lib%s.a" % name)
+ if os.path.exists(libfile):
+ shlib = "lib%s.a(lib%s.so)" % (name, name)
+ return shlib
+
+ return None
+
+ def find_library(name):
+ return _findLib_aix(name)
+
elif os.name == "posix":
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
import re, tempfile, errno
@@ -267,7 +284,16 @@
print cdll.LoadLibrary("libcrypto.dylib")
print cdll.LoadLibrary("libSystem.dylib")
print cdll.LoadLibrary("System.framework/System")
+ elif sys.platform.startswith("aix"):
+ print find_library("crypto")
+ x = find_library("crypto")
+ print cdll.LoadLibrary(x)
+ print cdll.LoadLibrary("libcrypto.a(libcrypto.so)")
+ print cdll.LoadLibrary("libc.a(shr.o)")
+ print find_library("crypt")
+ print cdll.LoadLibrary("libcrypt.a(shr.o)")
else:
+ print cdll.LoadLibrary("libc.a")
print cdll.LoadLibrary("libm.so")
print cdll.LoadLibrary("libcrypt.so")
print find_library("crypt")
p.s. Anyone know what flag to set in vi so that tabs are never inserted and/or spaces converted to tabs. Python seems to hate tab indents. |
|
Date |
User |
Action |
Args |
2016-02-29 17:58:07 | Michael.Felt | set | recipients:
+ Michael.Felt, David.Edelsohn |
2016-02-29 17:58:07 | Michael.Felt | set | messageid: <1456768687.4.0.877556004396.issue26439@psf.upfronthosting.co.za> |
2016-02-29 17:58:07 | Michael.Felt | link | issue26439 messages |
2016-02-29 17:58:04 | Michael.Felt | create | |
|