[3.13] gh-140041: Fix import of ctypes on Android and Cygwin when ABI flags are present (GH-140178) (#140181)

Use sysconfig to determine the full name of libpython, rather than hardcoding
a library name that doesn't have ABI flags.
(cherry picked from commit 7f371ed84b)

Co-authored-by: Malcolm Smith <smith@chaquo.com>
This commit is contained in:
Miss Islington (bot) 2025-10-16 00:03:25 +02:00 committed by GitHub
parent 77976761ba
commit f09a6a2fc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 9 deletions

View file

@ -47,7 +47,7 @@ for ((i, prefix) in prefixes.withIndex()) {
val libDir = file("$prefix/lib") val libDir = file("$prefix/lib")
val version = run { val version = run {
for (filename in libDir.list()!!) { for (filename in libDir.list()!!) {
"""python(\d+\.\d+)""".toRegex().matchEntire(filename)?.let { """python(\d+\.\d+[a-z]*)""".toRegex().matchEntire(filename)?.let {
return@run it.groupValues[1] return@run it.groupValues[1]
} }
} }
@ -64,9 +64,10 @@ for ((i, prefix) in prefixes.withIndex()) {
val libPythonDir = file("$libDir/python$pythonVersion") val libPythonDir = file("$libDir/python$pythonVersion")
val triplet = run { val triplet = run {
for (filename in libPythonDir.list()!!) { for (filename in libPythonDir.list()!!) {
"""_sysconfigdata__android_(.+).py""".toRegex().matchEntire(filename)?.let { """_sysconfigdata_[a-z]*_android_(.+).py""".toRegex()
return@run it.groupValues[1] .matchEntire(filename)?.let {
} return@run it.groupValues[1]
}
} }
throw GradleException("Failed to find Python triplet in $libPythonDir") throw GradleException("Failed to find Python triplet in $libPythonDir")
} }

View file

@ -1,6 +1,8 @@
"""create and manipulate C data types in Python""" """create and manipulate C data types in Python"""
import os as _os, sys as _sys import os as _os
import sys as _sys
import sysconfig as _sysconfig
import types as _types import types as _types
__version__ = "1.1.0" __version__ = "1.1.0"
@ -484,10 +486,9 @@ def LoadLibrary(self, name):
if _os.name == "nt": if _os.name == "nt":
pythonapi = PyDLL("python dll", None, _sys.dllhandle) pythonapi = PyDLL("python dll", None, _sys.dllhandle)
elif _sys.platform == "android": elif _sys.platform in ["android", "cygwin"]:
pythonapi = PyDLL("libpython%d.%d.so" % _sys.version_info[:2]) # These are Unix-like platforms which use a dynamically-linked libpython.
elif _sys.platform == "cygwin": pythonapi = PyDLL(_sysconfig.get_config_var("LDLIBRARY"))
pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2])
else: else:
pythonapi = PyDLL(None) pythonapi = PyDLL(None)

View file

@ -0,0 +1 @@
Fix import of :mod:`ctypes` on Android and Cygwin when ABI flags are present.