Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Lib/ctypes/_aix.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_ld_headers(file):
# 2. If "INDEX" in occurs in a following line - return ld_header
# 3. get info (lines starting with [0-9])
ldr_headers = []
p = Popen(["/usr/bin/dump", "-X%s" % AIX_ABI, "-H", file],
p = Popen(["/usr/bin/dump", f"-X{AIX_ABI}", "-H", file],
universal_newlines=True, stdout=PIPE, stderr=DEVNULL)
# be sure to read to the end-of-file - getting all entries
while True:
Expand Down Expand Up @@ -140,7 +140,7 @@ def get_one_match(expr, lines):
When there is a match, strip leading "[" and trailing "]"
"""
# member names in the ld_headers output are between square brackets
expr = r'\[(%s)\]' % expr
expr = rf'\[({expr})\]'
matches = list(filter(None, (re.search(expr, line) for line in lines)))
if len(matches) == 1:
return matches[0].group(1)
Expand Down Expand Up @@ -197,8 +197,8 @@ def get_version(name, members):
# any combination of additional 'dot' digits pairs are accepted
# anything more than libFOO.so.digits.digits.digits
# should be seen as a member name outside normal expectations
exprs = [r'lib%s\.so\.[0-9]+[0-9.]*' % name,
r'lib%s_?64\.so\.[0-9]+[0-9.]*' % name]
exprs = [rf'lib{name}\.so\.[0-9]+[0-9.]*',
rf'lib{name}_?64\.so\.[0-9]+[0-9.]*']
for expr in exprs:
versions = []
for line in members:
Expand All @@ -219,12 +219,12 @@ def get_member(name, members):
and finally, legacy AIX naming scheme.
"""
# look first for a generic match - prepend lib and append .so
expr = r'lib%s\.so' % name
expr = rf'lib{name}\.so'
member = get_one_match(expr, members)
if member:
return member
elif AIX_ABI == 64:
expr = r'lib%s64\.so' % name
expr = rf'lib{name}64\.so'
member = get_one_match(expr, members)
if member:
return member
Expand Down Expand Up @@ -277,7 +277,7 @@ def find_shared(paths, name):
continue
# "lib" is prefixed to emulate compiler name resolution,
# e.g., -lc to libc
base = 'lib%s.a' % name
base = f'lib{name}.a'
archive = path.join(dir, base)
if path.exists(archive):
members = get_shared(get_ld_headers(archive))
Expand Down Expand Up @@ -308,7 +308,7 @@ def find_library(name):
libpaths = get_libpaths()
(base, member) = find_shared(libpaths, name)
if base != None:
return "%s(%s)" % (base, member)
return f"{base}({member})"

# To get here, a member in an archive has not been found
# In other words, either:
Expand All @@ -319,7 +319,7 @@ def find_library(name):
# Note, the installation must prepare a link from a .so
# to a versioned file
# This is common practice by GNU libtool on other platforms
soname = "lib%s.so" % name
soname = f"lib{name}.so"
for dir in libpaths:
# /lib is a symbolic link to /usr/lib, skip it
if dir == "/lib":
Expand Down
16 changes: 8 additions & 8 deletions Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,18 @@ def test():
elif sys.platform.startswith("aix"):
from ctypes import CDLL
if sys.maxsize < 2**32:
print("Using CDLL(name, os.RTLD_MEMBER): %s" % CDLL("libc.a(shr.o)", os.RTLD_MEMBER))
print("Using cdll.LoadLibrary(): %s" % cdll.LoadLibrary("libc.a(shr.o)"))
print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr.o)', os.RTLD_MEMBER)}")
print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr.o)')}")
# librpm.so is only available as 32-bit shared library
print(find_library("rpm"))
print(cdll.LoadLibrary("librpm.so"))
else:
print("Using CDLL(name, os.RTLD_MEMBER): %s" % CDLL("libc.a(shr_64.o)", os.RTLD_MEMBER))
print("Using cdll.LoadLibrary(): %s" % cdll.LoadLibrary("libc.a(shr_64.o)"))
print("crypt\t:: %s" % find_library("crypt"))
print("crypt\t:: %s" % cdll.LoadLibrary(find_library("crypt")))
print("crypto\t:: %s" % find_library("crypto"))
print("crypto\t:: %s" % cdll.LoadLibrary(find_library("crypto")))
print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr_64.o)', os.RTLD_MEMBER)}")
print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr_64.o)')}")
print(f"crypt\t:: {find_library('crypt')}")
print(f"crypt\t:: {cdll.LoadLibrary(find_library('crypt'))}")
print(f"crypto\t:: {find_library('crypto')}")
print(f"crypto\t:: {cdll.LoadLibrary(find_library('crypto'))}")
else:
print(cdll.LoadLibrary("libm.so"))
print(cdll.LoadLibrary("libcrypt.so"))
Expand Down