Update ctypes to 3.14.5 (#7899)

This commit is contained in:
Shahar Naveh authored and GitHub committed 2026-05-17 20:54:56 +09:00
1 parent 2c558fa749
commit bc1b442e19
8 files changed
+74 -23

No files matched your search

+2
View File
@@ -470,6 +470,8 @@ class CDLL(object):
if name and name.endswith(")") and ".a(" in name:
mode |= _os.RTLD_MEMBER | _os.RTLD_NOW
self._name = name
if handle is not None:
return handle
return _dlopen(name, mode)
def __repr__(self):
+16 -10
View File
@@ -85,15 +85,10 @@ if os.name == "nt":
wintypes.DWORD,
)
_psapi = ctypes.WinDLL('psapi', use_last_error=True)
_enum_process_modules = _psapi["EnumProcessModules"]
_enum_process_modules.restype = wintypes.BOOL
_enum_process_modules.argtypes = (
wintypes.HANDLE,
ctypes.POINTER(wintypes.HMODULE),
wintypes.DWORD,
wintypes.LPDWORD,
)
# gh-145307: We defer loading psapi.dll until _get_module_handles is called.
# Loading additional DLLs at startup for functionality that may never be
# used is wasteful.
_enum_process_modules = None
def _get_module_filename(module: wintypes.HMODULE):
name = (wintypes.WCHAR * 32767)() # UNICODE_STRING_MAX_CHARS
@@ -101,8 +96,19 @@ if os.name == "nt":
return name.value
return None
def _get_module_handles():
global _enum_process_modules
if _enum_process_modules is None:
_psapi = ctypes.WinDLL('psapi', use_last_error=True)
_enum_process_modules = _psapi["EnumProcessModules"]
_enum_process_modules.restype = wintypes.BOOL
_enum_process_modules.argtypes = (
wintypes.HANDLE,
ctypes.POINTER(wintypes.HMODULE),
wintypes.DWORD,
wintypes.LPDWORD,
)
process = _get_current_process()
space_needed = wintypes.DWORD()
n = 1024
+42
View File
@@ -166,6 +166,48 @@ class Test(unittest.TestCase, StructCheckMixin):
self.assertEqual(s.value, math.pi)
self.assertEqual(bin(struct.pack(">d", math.pi)), bin(s))
@unittest.skipUnless(hasattr(ctypes, 'c_float_complex'), "No complex types")
def test_endian_float_complex(self):
c_float_complex = ctypes.c_float_complex
if sys.byteorder == "little":
self.assertIs(c_float_complex.__ctype_le__, c_float_complex)
self.assertIs(c_float_complex.__ctype_be__.__ctype_le__,
c_float_complex)
else:
self.assertIs(c_float_complex.__ctype_be__, c_float_complex)
self.assertIs(c_float_complex.__ctype_le__.__ctype_be__,
c_float_complex)
s = c_float_complex(math.pi+1j)
self.assertEqual(bin(struct.pack("F", math.pi+1j)), bin(s))
self.assertAlmostEqual(s.value, math.pi+1j, places=6)
s = c_float_complex.__ctype_le__(math.pi+1j)
self.assertAlmostEqual(s.value, math.pi+1j, places=6)
self.assertEqual(bin(struct.pack("<F", math.pi+1j)), bin(s))
s = c_float_complex.__ctype_be__(math.pi+1j)
self.assertAlmostEqual(s.value, math.pi+1j, places=6)
self.assertEqual(bin(struct.pack(">F", math.pi+1j)), bin(s))
@unittest.skipUnless(hasattr(ctypes, 'c_double_complex'), "No complex types")
def test_endian_double_complex(self):
c_double_complex = ctypes.c_double_complex
if sys.byteorder == "little":
self.assertIs(c_double_complex.__ctype_le__, c_double_complex)
self.assertIs(c_double_complex.__ctype_be__.__ctype_le__,
c_double_complex)
else:
self.assertIs(c_double_complex.__ctype_be__, c_double_complex)
self.assertIs(c_double_complex.__ctype_le__.__ctype_be__,
c_double_complex)
s = c_double_complex(math.pi+1j)
self.assertEqual(bin(struct.pack("D", math.pi+1j)), bin(s))
self.assertAlmostEqual(s.value, math.pi+1j, places=6)
s = c_double_complex.__ctype_le__(math.pi+1j)
self.assertAlmostEqual(s.value, math.pi+1j, places=6)
self.assertEqual(bin(struct.pack("<D", math.pi+1j)), bin(s))
s = c_double_complex.__ctype_be__(math.pi+1j)
self.assertAlmostEqual(s.value, math.pi+1j, places=6)
self.assertEqual(bin(struct.pack(">D", math.pi+1j)), bin(s))
def test_endian_other(self):
self.assertIs(c_byte.__ctype_le__, c_byte)
self.assertIs(c_byte.__ctype_be__, c_byte)
+1 -3
View File
@@ -26,7 +26,6 @@ else:
)
class ListSharedLibraries(unittest.TestCase):
# TODO: RUSTPYTHON
@unittest.skipIf(not APPLE, "TODO: RUSTPYTHON")
def test_lists_system(self):
dlls = ctypes.util.dllist()
@@ -36,8 +35,7 @@ class ListSharedLibraries(unittest.TestCase):
any(lib in dll for dll in dlls for lib in KNOWN_LIBRARIES), f"loaded={dlls}"
)
# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_lists_updates(self):
dlls = ctypes.util.dllist()
+8
View File
@@ -106,6 +106,14 @@ class LoaderTest(unittest.TestCase):
lib = ctypes.WinDLL(name=None, handle=handle)
self.assertIs(handle, lib._handle)
@unittest.skipIf(os.name == "nt", 'POSIX-specific test')
@unittest.skipIf(libc_name is None, 'could not find libc')
def test_load_without_name_and_with_handle_posix(self):
lib1 = CDLL(libc_name)
handle = lib1._handle
lib2 = CDLL(name=None, handle=handle)
self.assertIs(lib2._handle, handle)
@unittest.skipUnless(os.name == "nt", 'Windows-specific test')
def test_1703286_A(self):
# On winXP 64-bit, advapi32 loads at an address that does
+2 -4
View File
@@ -7,8 +7,7 @@ from ctypes import (pythonapi, POINTER, create_string_buffer, sizeof,
class PythonAPITestCase(unittest.TestCase):
# TODO: RUSTPYTHON - requires pythonapi (Python C API)
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; - requires pythonapi (Python C API)
def test_PyBytes_FromStringAndSize(self):
PyBytes_FromStringAndSize = pythonapi.PyBytes_FromStringAndSize
@@ -59,8 +58,7 @@ class PythonAPITestCase(unittest.TestCase):
del pyobj
self.assertEqual(sys.getrefcount(s), ref)
# TODO: RUSTPYTHON - requires pythonapi (Python C API)
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; - requires pythonapi (Python C API)
def test_PyOS_snprintf(self):
PyOS_snprintf = pythonapi.PyOS_snprintf
PyOS_snprintf.argtypes = POINTER(c_char), c_size_t, c_char_p
+2 -4
View File
@@ -39,8 +39,7 @@ class ValuesTestCase(unittest.TestCase):
class PythonValuesTestCase(unittest.TestCase):
"""This test only works when python itself is a dll/shared library"""
# TODO: RUSTPYTHON - requires pythonapi (Python C API)
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; - requires pythonapi (Python C API)
def test_optimizeflag(self):
# This test accesses the Py_OptimizeFlag integer, which is
# exported by the Python dll and should match the sys.flags value
@@ -48,8 +47,7 @@ class PythonValuesTestCase(unittest.TestCase):
opt = c_int.in_dll(pythonapi, "Py_OptimizeFlag").value
self.assertEqual(opt, sys.flags.optimize)
# TODO: RUSTPYTHON - requires pythonapi (Python C API)
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; - requires pythonapi (Python C API)
@thread_unsafe('overrides frozen modules')
def test_frozentable(self):
# Python exports a PyImport_FrozenModules symbol. This is a
+1 -2
View File
@@ -13,8 +13,7 @@ from ._support import Py_TPFLAGS_DISALLOW_INSTANTIATION, Py_TPFLAGS_IMMUTABLETYP
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
class FunctionCallTestCase(unittest.TestCase):
# TODO: RUSTPYTHON: SEH not implemented, crashes with STATUS_ACCESS_VIOLATION
@unittest.skip("TODO: RUSTPYTHON")
@unittest.skip("TODO: RUSTPYTHON; SEH not implemented, crashes with STATUS_ACCESS_VIOLATION")
@unittest.skipUnless('MSC' in sys.version, "SEH only supported by MSC")
@unittest.skipIf(sys.executable.lower().endswith('_d.exe'),
"SEH not enabled in debug builds")