Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32f2eb4

Browse files
committed
Issue #21042: Revert Linux find_library() to return just filename
This reverts most of revision 3092cf163eb4. The change worked on x86 architectures, but did not work on ARM, probably due to extra ABI flags in the ldconfig output.
1 parent ec195fb commit 32f2eb4

4 files changed

Lines changed: 21 additions & 35 deletions

File tree

Doc/library/ctypes.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,15 +1258,15 @@ The exact functionality is system dependent.
12581258

12591259
On Linux, :func:`find_library` tries to run external programs
12601260
(``/sbin/ldconfig``, ``gcc``, and ``objdump``) to find the library file. It
1261-
returns the absolute path of the library file. Here are some examples::
1261+
returns the filename of the library file. Here are some examples::
12621262

12631263
>>> from ctypes.util import find_library
12641264
>>> find_library("m")
1265-
'/lib/x86_64-linux-gnu/libm.so.6'
1265+
'libm.so.6'
12661266
>>> find_library("c")
1267-
'/lib/x86_64-linux-gnu/libc.so.6'
1267+
'libc.so.6'
12681268
>>> find_library("bz2")
1269-
'/lib/x86_64-linux-gnu/libbz2.so.1.0'
1269+
'libbz2.so.1.0'
12701270
>>>
12711271

12721272
On OS X, :func:`find_library` tries several predefined naming schemes and paths
@@ -1835,9 +1835,6 @@ Utility functions
18351835

18361836
The exact functionality is system dependent.
18371837

1838-
.. versionchanged:: 3.6
1839-
On Linux it returns an absolute path.
1840-
18411838

18421839
.. function:: find_msvcrt()
18431840
:module: ctypes.util

Lib/ctypes/test/test_find.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,39 @@
99
class Test_OpenGL_libs(unittest.TestCase):
1010
@classmethod
1111
def setUpClass(cls):
12-
cls.lib_gl = cls.lib_glu = cls.lib_gle = None
12+
lib_gl = lib_glu = lib_gle = None
1313
if sys.platform == "win32":
14-
cls.lib_gl = find_library("OpenGL32")
15-
cls.lib_glu = find_library("Glu32")
14+
lib_gl = find_library("OpenGL32")
15+
lib_glu = find_library("Glu32")
1616
elif sys.platform == "darwin":
17-
cls.lib_gl = cls.lib_glu = find_library("OpenGL")
17+
lib_gl = lib_glu = find_library("OpenGL")
1818
else:
19-
cls.lib_gl = find_library("GL")
20-
cls.lib_glu = find_library("GLU")
21-
cls.lib_gle = find_library("gle")
19+
lib_gl = find_library("GL")
20+
lib_glu = find_library("GLU")
21+
lib_gle = find_library("gle")
2222

2323
## print, for debugging
2424
if test.support.verbose:
2525
print("OpenGL libraries:")
26-
for item in (("GL", cls.lib_gl),
27-
("GLU", cls.lib_glu),
28-
("gle", cls.lib_gle)):
26+
for item in (("GL", lib_gl),
27+
("GLU", lib_glu),
28+
("gle", lib_gle)):
2929
print("\t", item)
3030

3131
cls.gl = cls.glu = cls.gle = None
32-
if cls.lib_gl:
32+
if lib_gl:
3333
try:
34-
cls.gl = CDLL(cls.lib_gl, mode=RTLD_GLOBAL)
34+
cls.gl = CDLL(lib_gl, mode=RTLD_GLOBAL)
3535
except OSError:
3636
pass
37-
if cls.lib_glu:
37+
if lib_glu:
3838
try:
39-
cls.glu = CDLL(cls.lib_glu, RTLD_GLOBAL)
39+
cls.glu = CDLL(lib_glu, RTLD_GLOBAL)
4040
except OSError:
4141
pass
42-
if cls.lib_gle:
42+
if lib_gle:
4343
try:
44-
cls.gle = CDLL(cls.lib_gle)
44+
cls.gle = CDLL(lib_gle)
4545
except OSError:
4646
pass
4747

@@ -64,14 +64,6 @@ def test_gle(self):
6464
self.skipTest('lib_gle not available')
6565
self.gle.gleGetJoinStyle
6666

67-
def test_abspath(self):
68-
if self.lib_gl:
69-
self.assertTrue(os.path.isabs(self.lib_gl))
70-
if self.lib_glu:
71-
self.assertTrue(os.path.isabs(self.lib_glu))
72-
if self.lib_gle:
73-
self.assertTrue(os.path.isabs(self.lib_gle))
74-
7567
# On platforms where the default shared library suffix is '.so',
7668
# at least some libraries can be loaded as attributes of the cdll
7769
# object, since ctypes now tries loading the lib again

Lib/ctypes/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def _findSoname_ldconfig(name):
221221
abi_type = mach_map.get(machine, 'libc6')
222222

223223
# XXX assuming GLIBC's ldconfig (with option -p)
224-
regex = r'lib%s\.[^\s]+\s\(%s(?:,\s.*)?\)\s=>\s(.*)'
224+
regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
225225
regex = os.fsencode(regex % (re.escape(name), abi_type))
226226
try:
227227
with subprocess.Popen(['/sbin/ldconfig', '-p'],

Misc/NEWS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ Library
245245

246246
- Issue #26177: Fixed the keys() method for Canvas and Scrollbar widgets.
247247

248-
- Issue #21042: Make ctypes.util.find_library() return the full path on
249-
Linux, similar to other platforms. Patch by Tamás Bence Gedai.
250-
251248
- Issue #15068: Got rid of excessive buffering in fileinput.
252249
The bufsize parameter is now deprecated and ignored.
253250

0 commit comments

Comments
 (0)