FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-71052: Implement `ctypes.util.find_library` on Android by mhsmith · Pull Request #116379 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 3 additions & 2 deletions Doc/library/ctypes.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,9 @@ Here are some examples::
'libbz2.so.1.0'
>>>

On macOS, :func:`~ctypes.util.find_library` tries several predefined naming schemes and paths
to locate the library, and returns a full pathname if successful::
On macOS and Android, :func:`~ctypes.util.find_library` uses the system's
standard naming schemes and paths to locate the library, and returns a full
pathname if successful::

>>> from ctypes.util import find_library
>>> find_library("c")
Expand Down
9 changes: 9 additions & 0 deletions Lib/ctypes/util.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def find_library(name):

from ctypes._aix import find_library

elif sys.platform == "android":
def find_library(name):
directory = "/system/lib"
if "64" in os.uname().machine:
directory += "64"

fname = f"{directory}/lib{name}.so"
return fname if os.path.isfile(fname) else None

elif os.name == "posix":
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
import re, tempfile
Expand Down
23 changes: 23 additions & 0 deletions Lib/test/test_ctypes/test_find.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,28 @@ def test_gh114257(self):
self.assertIsNone(find_library("libc"))


@unittest.skipUnless(sys.platform == 'android', 'Test only valid for Android')
class FindLibraryAndroid(unittest.TestCase):
def test_find(self):
for name in [
"c", "m", # POSIX
"z", # Non-POSIX, but present on Linux
"log", # Not present on Linux
]:
with self.subTest(name=name):
path = find_library(name)
self.assertIsInstance(path, str)
self.assertEqual(
os.path.dirname(path),
"/system/lib64" if "64" in os.uname().machine
else "/system/lib")
self.assertEqual(os.path.basename(path), f"lib{name}.so")
self.assertTrue(os.path.isfile(path), path)

for name in ["libc", "nonexistent"]:
with self.subTest(name=name):
self.assertIsNone(find_library(name))


if __name__ == "__main__":
unittest.main()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement :func:`ctypes.util.find_library` on Android.

Back | FazBrowse Home | New Git URL