* Move imports at top level and sort imports.
* Replace c_buffer() with create_string_buffer(): c_buffer is a
deprecated alias.
* PEP 8: Add empty lines for readability between imports and classes.
import test.support
from ctypes import c_int, Union, Structure, sizeof
+
class AnonTest(unittest.TestCase):
def test_anon(self):
self.assertEqual(Y._.offset, sizeof(c_int))
self.assertEqual(Y.y.offset, sizeof(c_int) * 2)
+
if __name__ == "__main__":
unittest.main()
+import binascii
+import re
import unittest
from ctypes import c_byte, Structure, POINTER, cast
-from binascii import hexlify
-import re
+
def dump(obj):
# helper function to dump memory contents in hex, with a hyphen
# between the bytes.
- h = hexlify(memoryview(obj)).decode()
+ h = binascii.hexlify(memoryview(obj)).decode()
return re.sub(r"(..)", r"\1-", h)[:-1]
class Value(Structure):
_fields_ = [("val", c_byte)]
+
class Container(Structure):
_fields_ = [("pvalues", POINTER(Value))]
+
class Test(unittest.TestCase):
def test(self):
# create an array of 4 values
([1, 2, 3, 4], "01-02-03-04")
)
+
if __name__ == "__main__":
unittest.main()
# fake to enable this test on Linux
CALLBACK_FUNCTYPE = CFUNCTYPE
+
class POINT(Structure):
_fields_ = [("x", c_int), ("y", c_int)]
+
class BasicWrapTestCase(unittest.TestCase):
def wrap(self, param):
return param
f(self.wrap(2**18), self.wrap(cb))
self.assertEqual(args, expected)
- ################################################################
-
def test_callbacks(self):
f = dll._testfunc_callback_i_if
f.restype = c_int
(9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))
def test_recursive_as_param(self):
- from ctypes import c_int
-
class A(object):
pass
c_int.from_param(a)
-#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
class AsParamWrapper(object):
def __init__(self, param):
self._as_parameter_ = param
class AsParamWrapperTestCase(BasicWrapTestCase):
wrap = AsParamWrapper
-#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class AsParamPropertyWrapper(object):
def __init__(self, param):
class AsParamPropertyWrapperTestCase(BasicWrapTestCase):
wrap = AsParamPropertyWrapper
-#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if __name__ == '__main__':
unittest.main()
+import _ctypes_test
+import os
+import unittest
from ctypes import (CDLL, Structure, sizeof, POINTER, byref, alignment,
LittleEndianStructure, BigEndianStructure,
c_byte, c_ubyte, c_char, c_char_p, c_void_p, c_wchar,
c_uint32, c_uint64,
c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong)
from test import support
-import unittest
-import os
-import _ctypes_test
class BITS(Structure):
_fields_ = [("A", c_int, 1),
setattr(b, name, i)
self.assertEqual(getattr(b, name), func(byref(b), name.encode('ascii')))
+
signed_int_types = (c_byte, c_short, c_int, c_long, c_longlong)
unsigned_int_types = (c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong)
int_types = unsigned_int_types + signed_int_types
x.a, x.b = 0, -1
self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 7, 0))
-
def fail_fields(self, *fields):
return self.get_except(type(Structure), "X", (),
{"_fields_": fields})
self.assertEqual(X.b.offset, sizeof(c_short)*1)
self.assertEqual(X.c.offset, sizeof(c_short)*2)
-
def get_except(self, func, *args, **kw):
try:
func(*args, **kw)
x.c = 2
self.assertEqual(b, b'\xab\xcd\xef\x12')
+
if __name__ == "__main__":
unittest.main()
+import unittest
from ctypes import (create_string_buffer, create_unicode_buffer, sizeof,
c_char, c_wchar)
-import unittest
-class StringBufferTestCase(unittest.TestCase):
+class StringBufferTestCase(unittest.TestCase):
def test_buffer(self):
b = create_string_buffer(32)
self.assertEqual(len(b), 32)
"""Test where byte objects are accepted"""
import sys
import unittest
+from _ctypes import _SimpleCData
from ctypes import Structure, c_char, c_char_p, c_wchar, c_wchar_p
+
class BytesTest(unittest.TestCase):
def test_c_char(self):
x = c_char(b"x")
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
def test_BSTR(self):
- from _ctypes import _SimpleCData
class BSTR(_SimpleCData):
_type_ = "X"
-import sys, unittest, struct, math, ctypes
-from binascii import hexlify
-
+import binascii
+import ctypes
+import math
+import struct
+import sys
+import unittest
from ctypes import (Structure, Union, LittleEndianUnion, BigEndianUnion,
BigEndianStructure, LittleEndianStructure,
POINTER, sizeof, cast,
c_long, c_ulong, c_longlong, c_ulonglong,
c_uint32, c_float, c_double)
+
def bin(s):
- return hexlify(memoryview(s)).decode().upper()
+ return binascii.hexlify(memoryview(s)).decode().upper()
+
# Each *simple* type that supports different byte orders has an
# __ctype_be__ attribute that specifies the same type in BIG ENDIAN
self.assertEqual(s.point.x, 1)
self.assertEqual(s.point.y, 2)
+
if __name__ == "__main__":
unittest.main()
+import _ctypes_test
+import ctypes
import functools
+import gc
+import math
import sys
import unittest
-from test import support
-
-import ctypes
+from _ctypes import CTYPES_MAX_ARGCOUNT
from ctypes import (CDLL, cdll, Structure, CFUNCTYPE,
ArgumentError, POINTER, sizeof,
c_byte, c_ubyte, c_char, c_char_p,
c_short, c_ushort, c_int, c_uint,
c_long, c_longlong, c_ulonglong, c_ulong,
c_float, c_double, c_longdouble, py_object)
-from _ctypes import CTYPES_MAX_ARGCOUNT
-import _ctypes_test
+from ctypes.util import find_library
+from test import support
class Callbacks(unittest.TestCase):
functype = CFUNCTYPE
## def tearDown(self):
-## import gc
## gc.collect()
def callback(self, *args):
def test_float(self):
# only almost equal: double -> float -> double
- import math
self.check_type(c_float, math.e)
self.check_type(c_float, -math.e)
def __init__(self):
self.v = proto(self.func)
- import gc
for i in range(32):
X()
gc.collect()
self.assertEqual(len(live), 0)
def test_issue12483(self):
- import gc
class Nasty:
def __del__(self):
gc.collect()
functype = ctypes.WINFUNCTYPE
-################################################################
-
class SampleCallbacksTestCase(unittest.TestCase):
def test_integrate(self):
self.assertLess(diff, 0.01, "%s not less than 0.01" % diff)
def test_issue_8959_a(self):
- from ctypes.util import find_library
libc_path = find_library("c")
if not libc_path:
self.skipTest('could not find libc')
c_void_p, c_char_p, c_wchar_p,
c_byte, c_short, c_int)
-class Test(unittest.TestCase):
+class Test(unittest.TestCase):
def test_array2pointer(self):
array = (c_int * 3)(42, 17, 2)
def test_wchar_p(self):
s = c_wchar_p("hiho")
self.assertEqual(cast(cast(s, c_void_p), c_wchar_p).value,
- "hiho")
+ "hiho")
def test_bad_type_arg(self):
# The type argument must be a ctypes pointer type.
_fields_ = [("a", c_int)]
self.assertRaises(TypeError, cast, array, MyUnion)
+
if __name__ == "__main__":
unittest.main()
-import unittest
+import _ctypes_test
import ctypes
+import unittest
from ctypes import (CDLL,
c_byte, c_ubyte, c_char,
c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong,
c_float, c_double, c_longdouble)
-import _ctypes_test
class CFunctions(unittest.TestCase):
self.assertEqual(self._dll.tv_i(-42), None)
self.assertEqual(self.S(), -42)
+
# The following repeats the above tests with stdcall functions (where
# they are available)
if hasattr(ctypes, 'WinDLL'):
+import _ctypes_test
import ctypes
import unittest
from ctypes import CDLL, c_int
class Test(unittest.TestCase):
-
def test_checkretval(self):
-
- import _ctypes_test
dll = CDLL(_ctypes_test.__file__)
self.assertEqual(42, dll._testfunc_p_p(42))
self.assertRaises(OSError, oleaut32.CreateTypeLib2, 0, None, None)
-
if __name__ == "__main__":
unittest.main()
-import unittest, os, errno
-import threading
-
import ctypes
+import errno
+import os
+import threading
+import unittest
from ctypes import CDLL, c_int, c_char_p, c_wchar_p, get_errno, set_errno
from ctypes.util import find_library
+
class Test(unittest.TestCase):
def test_open(self):
libc_name = find_library("c")
import array
import gc
import unittest
-from ctypes import Structure, Union, Array, sizeof, c_char, c_int
+from ctypes import (Structure, Union, Array, sizeof,
+ _Pointer, _SimpleCData, _CFuncPtr,
+ c_char, c_int)
+
class X(Structure):
_fields_ = [("c_int", c_int)]
def __init__(self):
self._init_called = True
+
class Test(unittest.TestCase):
def test_from_buffer(self):
a = array.array("i", range(16))
(c_int * 1).from_buffer_copy(a, 16 * sizeof(c_int))
def test_abstract(self):
- from ctypes import _Pointer, _SimpleCData, _CFuncPtr
-
self.assertRaises(TypeError, Array.from_buffer, bytearray(10))
self.assertRaises(TypeError, Structure.from_buffer, bytearray(10))
self.assertRaises(TypeError, Union.from_buffer, bytearray(10))
self.assertRaises(TypeError, _Pointer.from_buffer_copy, b"123")
self.assertRaises(TypeError, _SimpleCData.from_buffer_copy, b"123")
+
if __name__ == '__main__':
unittest.main()
import _ctypes_test
import ctypes
import unittest
-from ctypes import (CDLL, Structure, CFUNCTYPE, sizeof,
+from ctypes import (CDLL, Structure, CFUNCTYPE, sizeof, _CFuncPtr,
c_void_p, c_char_p, c_char, c_int, c_uint, c_long)
+
try:
WINFUNCTYPE = ctypes.WINFUNCTYPE
except AttributeError:
self.assertEqual(strtok(None, b"\n"), None)
def test_abstract(self):
- from ctypes import _CFuncPtr
-
self.assertRaises(TypeError, _CFuncPtr, 13, "name", 42, "iid")
-"""
-Here is probably the place to write the docs, since the test-cases
-show how the type behave.
-
-Later...
-"""
-
+import _ctypes_test
import ctypes
+import sys
+import unittest
from ctypes import (CDLL, Structure, Array, CFUNCTYPE,
byref, POINTER, pointer, ArgumentError,
c_char, c_wchar, c_byte, c_char_p,
c_short, c_int, c_long, c_longlong,
c_float, c_double, c_longdouble)
-import sys, unittest
+from _ctypes import _Pointer, _SimpleCData
+
try:
WINFUNCTYPE = ctypes.WINFUNCTYPE
# fake to enable this test on Linux
WINFUNCTYPE = CFUNCTYPE
-import _ctypes_test
dll = CDLL(_ctypes_test.__file__)
if sys.platform == "win32":
windll = ctypes.WinDLL(_ctypes_test.__file__)
+
class POINT(Structure):
_fields_ = [("x", c_int), ("y", c_int)]
+
+
class RECT(Structure):
_fields_ = [("left", c_int), ("top", c_int),
("right", c_int), ("bottom", c_int)]
+
+
class FunctionTestCase(unittest.TestCase):
def test_mro(self):
_length_ = 5
_type_ = "i"
- from _ctypes import _Pointer
with self.assertRaises(TypeError):
class X(object, _Pointer):
pass
- from _ctypes import _SimpleCData
with self.assertRaises(TypeError):
class X(object, _SimpleCData):
_type_ = "i"
callback = proto(callback)
self.assertRaises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT()))
+
if __name__ == '__main__':
unittest.main()
import warnings
from ctypes import Structure, POINTER, pointer, c_char_p
-################################################################
-#
-# The incomplete pointer example from the tutorial
-#
+# The incomplete pointer example from the tutorial
class TestSetPointerType(unittest.TestCase):
-
def tearDown(self):
# to not leak references, we must clean _pointer_type_cache
ctypes._reset_cache()
with self.assertWarns(DeprecationWarning):
ctypes.SetPointerType(lpcell, cell)
-################################################################
if __name__ == '__main__':
unittest.main()
# This tests the internal _objects attribute
-import sys
-import unittest
-from ctypes import Structure, POINTER, c_char_p, c_int
# XXX This test must be reviewed for correctness!!!
#
# What about pointers?
+import sys
+import unittest
+from ctypes import Structure, POINTER, c_char_p, c_int
+
+
class ObjectsTestCase(unittest.TestCase):
def assertSame(self, a, b):
self.assertEqual(id(a), id(b))
##XXX print x.data[0]
##XXX print x.data._objects
+
if __name__ == '__main__':
unittest.main()
+import gc
import sys
import unittest
-from ctypes import Structure, POINTER, pointer, c_char_p, c_int
+from ctypes import (Structure, POINTER, pointer, _pointer_type_cache,
+ c_char_p, c_int)
class SimpleTestCase(unittest.TestCase):
x = c_char_p(b"spam")
self.assertEqual(x._objects, b"spam")
+
class StructureTestCase(unittest.TestCase):
def test_cint_struct(self):
class X(Structure):
r.lr = POINT()
self.assertEqual(r._objects, {'0': {}, '1': {}})
+
class ArrayTestCase(unittest.TestCase):
def test_cint_array(self):
INTARR = c_int * 3
x.a = ia
self.assertEqual(x._objects, {'1': {}})
+
class PointerTestCase(unittest.TestCase):
def test_p_cint(self):
i = c_int(42)
x = pointer(i)
self.assertEqual(x._objects, {'1': i})
+
class DeletePointerTestCase(unittest.TestCase):
@unittest.skip('test disabled')
def test_X(self):
## del x
## print "2?", sys.getrefcount(i)
## del i
- import gc
gc.collect()
for i in range(320):
c_int(99)
print("+" * 42)
print(x._objects)
+
class PointerToStructure(unittest.TestCase):
def test(self):
class POINT(Structure):
# to avoid leaking when tests are run several times
# clean up the types left in the cache.
- from ctypes import _pointer_type_cache
del _pointer_type_cache[POINT]
+
if __name__ == "__main__":
unittest.main()
+import _ctypes_test
+import math
import unittest
-
from ctypes import (CDLL, CFUNCTYPE, POINTER, create_string_buffer, sizeof,
c_void_p, c_char, c_int, c_double, c_size_t)
-import _ctypes_test
lib = CDLL(_ctypes_test.__file__)
"""Return -1 if x < y, 0 if x == y and 1 if x > y"""
return (x > y) - (x < y)
+
class LibTest(unittest.TestCase):
def test_sqrt(self):
lib.my_sqrt.argtypes = c_double,
lib.my_sqrt.restype = c_double
self.assertEqual(lib.my_sqrt(4.0), 2.0)
- import math
self.assertEqual(lib.my_sqrt(2.0), math.sqrt(2.0))
def test_qsort(self):
lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort))
self.assertEqual(chars.raw, b" ,,aaaadmmmnpppsss\x00")
+
if __name__ == "__main__":
unittest.main()
+import _ctypes
+import _ctypes_test
import ctypes
import os
import shutil
import sys
import test.support
import unittest
-from test.support import import_helper, os_helper
from ctypes import CDLL, cdll, addressof, c_void_p, c_char_p
from ctypes.util import find_library
+from test.support import import_helper, os_helper
libc_name = None
+
def setUpModule():
global libc_name
if os.name == "nt":
if test.support.verbose:
print("libc_name is", libc_name)
+
class LoaderTest(unittest.TestCase):
unknowndll = "xxrandomnamexx"
test_lib = libc_name
else:
if os.name == "nt":
- import _ctypes_test
test_lib = _ctypes_test.__file__
else:
self.skipTest('could not find library to load')
@unittest.skipUnless(os.name == "nt",
'test specific to Windows')
def test_load_ordinal_functions(self):
- import _ctypes_test
dll = ctypes.WinDLL(_ctypes_test.__file__)
# We load the same function both via ordinal and name
func_ord = dll[2]
@unittest.skipUnless(os.name == "nt", 'Windows-specific test')
def test_1703286_A(self):
- from _ctypes import LoadLibrary, FreeLibrary
# On winXP 64-bit, advapi32 loads at an address that does
# NOT fit into a 32-bit integer. FreeLibrary must be able
# to accept this address.
# These are tests for https://bugs.python.org/issue1703286
- handle = LoadLibrary("advapi32")
- FreeLibrary(handle)
+ handle = _ctypes.LoadLibrary("advapi32")
+ _ctypes.FreeLibrary(handle)
@unittest.skipUnless(os.name == "nt", 'Windows-specific test')
def test_1703286_B(self):
# above, the (arbitrarily selected) CloseEventLog function
# also has a high address. 'call_function' should accept
# addresses so large.
- from _ctypes import call_function
advapi32 = ctypes.windll.advapi32
# Calling CloseEventLog with a NULL argument should fail,
self.assertTrue(proc)
# This is the real test: call the function via 'call_function'
- self.assertEqual(0, call_function(proc, (None,)))
+ self.assertEqual(0, _ctypes.call_function(proc, (None,)))
@unittest.skipUnless(os.name == "nt",
'test specific to Windows')
-import os
-import sys
-import unittest
-
# Bob Ippolito:
#
# Ok.. the code to find the filename for __getattr__ should look
#
# -bob
+import os
+import sys
+import unittest
+
from ctypes.macholib.dyld import dyld_find
from ctypes.macholib.dylib import dylib_info
from ctypes.macholib.framework import framework_info
+
def find_lib(name):
possible = ['lib'+name+'.dylib', name+'.dylib', name+'.framework/'+name]
for dylib in possible:
self.assertEqual(framework_info('P/F.framework/Versions/A/F_debug'),
d('P', 'F.framework/Versions/A/F_debug', 'F', 'A', 'debug'))
+
if __name__ == "__main__":
unittest.main()
import sys
-from test import support
import unittest
+from test import support
from ctypes import (POINTER, sizeof, cast,
create_string_buffer, string_at,
create_unicode_buffer, wstring_at,
memmove, memset,
c_char_p, c_byte, c_ubyte, c_wchar)
+
class MemFunctionsTest(unittest.TestCase):
@unittest.skip('test disabled')
def test_overflow(self):
self.assertEqual(wstring_at(a, 16), "Hello, World\0\0\0\0")
self.assertEqual(wstring_at(a, 0), "")
+
if __name__ == "__main__":
unittest.main()
+import array
import struct
import sys
import unittest
-from array import array
from operator import truth
from ctypes import (byref, sizeof, alignment, _SimpleCData,
c_char, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong,
c_float, c_double, c_longdouble, c_bool)
+
def valid_ranges(*types):
# given a sequence of numeric types, collect their _type_
# attribute, which is a single format character compatible with
result.append((min(a, b, c, d), max(a, b, c, d)))
return result
+
ArgType = type(byref(c_int(0)))
unsigned_types = [c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong]
signed_ranges = valid_ranges(*signed_types)
bool_values = [True, False, 0, 1, -1, 5000, 'test', [], [1]]
-################################################################
class NumberTestCase(unittest.TestCase):
# the array module doesn't support all format codes
# (no 'q' or 'Q')
try:
- array(t._type_)
+ array.array(t._type_)
except ValueError:
continue
- a = array(t._type_, [100])
+ a = array.array(t._type_, [100])
# v now is an integer at an 'external' memory location
v = t.from_address(a.buffer_info()[0])
def test_float_from_address(self):
for t in float_types:
- a = array(t._type_, [3.14])
+ a = array.array(t._type_, [3.14])
v = t.from_address(a.buffer_info()[0])
self.assertEqual(v.value, a[0])
self.assertIs(type(v), t)
self.assertIs(type(v), t)
def test_char_from_address(self):
- a = array('b', [0])
+ a = array.array('b', [0])
a[0] = ord('x')
v = c_char.from_address(a.buffer_info()[0])
self.assertEqual(v.value, b'x')
# array does not support c_bool / 't'
@unittest.skip('test disabled')
def test_bool_from_address(self):
- a = array(c_bool._type_, [True])
+ a = array.array(c_bool._type_, [True])
v = t.from_address(a.buffer_info()[0])
self.assertEqual(v.value, a[0])
self.assertEqual(type(v) is t)
def test_perf(self):
check_perf()
+
class c_int_S(_SimpleCData):
_type_ = "i"
__slots__ = []
+
def run_test(rep, msg, func, arg=None):
## items = [None] * rep
items = range(rep)
stop = clock()
print("%15s: %.2f us" % (msg, ((stop-start)*1e6/5/rep)))
+
def check_perf():
# Construct 5 objects
from ctypes import c_int
# c_int_S(): 9.87 us
# c_int_S(999): 9.85 us
+
if __name__ == '__main__':
## check_perf()
unittest.main()
>>> x.array._b_base_._objects
{'0:2': b'spam spam spam'}
>>>
-
'''
-import unittest, doctest
-
+import doctest
+import unittest
import test.test_ctypes.test_objects
+
class TestCase(unittest.TestCase):
def test(self):
failures, tests = doctest.testmod(test.test_ctypes.test_objects)
self.assertFalse(failures, 'doctests failed, see output above')
+
if __name__ == '__main__':
doctest.testmod(test.test_ctypes.test_objects)
+import _ctypes_test
import unittest
import test.support
+from ctypes import (CDLL, PyDLL, ArgumentError,
+ Structure, Array, Union,
+ _Pointer, _SimpleCData, _CFuncPtr,
+ POINTER, pointer, byref,
+ c_void_p, c_char_p, c_wchar_p, py_object,
+ c_bool,
+ c_char, c_wchar,
+ c_byte, c_ubyte,
+ c_short, c_ushort,
+ c_int, c_uint,
+ c_long, c_ulong,
+ c_longlong, c_ulonglong,
+ c_float, c_double, c_longdouble)
-class SimpleTypesTestCase(unittest.TestCase):
+class SimpleTypesTestCase(unittest.TestCase):
def setUp(self):
try:
from _ctypes import set_conversion_mode
set_conversion_mode(*self.prev_conv_mode)
def test_subclasses(self):
- from ctypes import c_void_p, c_char_p
# ctypes 0.9.5 and before did overwrite from_param in SimpleType_new
class CVOIDP(c_void_p):
def from_param(cls, value):
self.assertEqual(CCHARP.from_param("abc"), "abcabcabcabc")
def test_subclasses_c_wchar_p(self):
- from ctypes import c_wchar_p
-
class CWCHARP(c_wchar_p):
def from_param(cls, value):
return value * 3
# XXX Replace by c_char_p tests
def test_cstrings(self):
- from ctypes import c_char_p
-
# c_char_p.from_param on a Python String packs the string
# into a cparam object
s = b"123"
self.assertIs(c_char_p.from_param(a), a)
def test_cw_strings(self):
- from ctypes import c_wchar_p
-
c_wchar_p.from_param("123")
self.assertRaises(TypeError, c_wchar_p.from_param, 42)
self.assertEqual(type(pa), c_wchar_p)
def test_c_char(self):
- from ctypes import c_char
-
with self.assertRaises(TypeError) as cm:
c_char.from_param(b"abc")
self.assertEqual(str(cm.exception),
"one character bytes, bytearray or integer expected")
def test_c_wchar(self):
- from ctypes import c_wchar
-
with self.assertRaises(TypeError) as cm:
c_wchar.from_param("abc")
self.assertEqual(str(cm.exception),
"unicode string expected instead of int instance")
def test_int_pointers(self):
- from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
LPINT = POINTER(c_int)
## p = pointer(c_int(42))
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
- from ctypes import c_short, c_uint, c_int, c_long, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
def test_byref_pointerpointer(self):
# See above
- from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPLPINT = POINTER(POINTER(c_int))
LPLPINT.from_param(byref(pointer(c_int(42))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
def test_array_pointers(self):
- from ctypes import c_short, c_uint, c_int, c_long, POINTER
INTARRAY = c_int * 3
ia = INTARRAY()
self.assertEqual(len(ia), 3)
self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
def test_noctypes_argtype(self):
- import _ctypes_test
- from ctypes import CDLL, c_void_p, ArgumentError
-
func = CDLL(_ctypes_test.__file__)._testfunc_p_p
func.restype = c_void_p
# TypeError: has no from_param method
self.assertRaises(ArgumentError, func, 99)
def test_abstract(self):
- from ctypes import (Array, Structure, Union, _Pointer,
- _SimpleCData, _CFuncPtr)
-
self.assertRaises(TypeError, Array.from_param, 42)
self.assertRaises(TypeError, Structure.from_param, 42)
self.assertRaises(TypeError, Union.from_param, 42)
def test_issue31311(self):
# __setstate__ should neither raise a SystemError nor crash in case
# of a bad __dict__.
- from ctypes import Structure
class BadStruct(Structure):
@property
WorseStruct().__setstate__({}, b'foo')
def test_parameter_repr(self):
- from ctypes import (
- c_bool,
- c_char,
- c_wchar,
- c_byte,
- c_ubyte,
- c_short,
- c_ushort,
- c_int,
- c_uint,
- c_long,
- c_ulong,
- c_longlong,
- c_ulonglong,
- c_float,
- c_double,
- c_longdouble,
- c_char_p,
- c_wchar_p,
- c_void_p,
- )
self.assertRegex(repr(c_bool.from_param(True)), r"^<cparam '\?' at 0x[A-Fa-f0-9]+>$")
self.assertEqual(repr(c_char.from_param(97)), "<cparam 'c' ('a')>")
self.assertRegex(repr(c_wchar.from_param('a')), r"^<cparam 'u' at 0x[A-Fa-f0-9]+>$")
@test.support.cpython_only
def test_from_param_result_refcount(self):
# Issue #99952
- import _ctypes_test
- from ctypes import PyDLL, c_int, c_void_p, py_object, Structure
-
class X(Structure):
"""This struct size is <= sizeof(void*)."""
_fields_ = [("a", c_void_p)]
self.assertEqual(trace, [1, 2, 3, 4, 5])
-################################################################
if __name__ == '__main__':
unittest.main()
+import re
+import sys
import unittest
from ctypes import (CFUNCTYPE, POINTER, sizeof, Union,
Structure, LittleEndianStructure, BigEndianStructure,
c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong, c_uint64,
c_bool, c_float, c_double, c_longdouble, py_object)
-import re, sys
+
if sys.byteorder == "little":
THIS_ENDIAN = "<"
THIS_ENDIAN = ">"
OTHER_ENDIAN = "<"
+
def normalize(format):
# Remove current endian specifier and white space from a format
# string
format = format.replace(OTHER_ENDIAN, THIS_ENDIAN)
return re.sub(r"\s", "", format)
-class Test(unittest.TestCase):
+class Test(unittest.TestCase):
def test_native_types(self):
for tp, fmt, shape, itemtp in native_types:
ob = tp()
print(tp)
raise
+
# define some structure classes
class Point(Structure):
PComplete = POINTER(Complete)
Complete._fields_ = [("a", c_long)]
+
################################################################
#
# This table contains format strings as they look on little endian
]
+
class BEPoint(BigEndianStructure):
_fields_ = [("x", c_long), ("y", c_long)]
class LEPoint(LittleEndianStructure):
_fields_ = [("x", c_long), ("y", c_long)]
-################################################################
-#
+
# This table contains format strings as they really look, on both big
# and little endian machines.
-#
endian_types = [
(BEPoint, "T{>l:x:>l:y:}".replace('l', s_long), (), BEPoint),
(LEPoint * 1, "T{<l:x:<l:y:}".replace('l', s_long), (1,), LEPoint),
(POINTER(LEPoint), "&T{<l:x:<l:y:}".replace('l', s_long), (), POINTER(LEPoint)),
]
+
if __name__ == "__main__":
unittest.main()
-import unittest
+import _ctypes_test
import pickle
+import unittest
from ctypes import (CDLL, Structure, CFUNCTYPE, pointer,
- c_void_p, c_char_p, c_wchar_p, c_char, c_wchar, c_int, c_double)
+ c_void_p, c_char_p, c_wchar_p,
+ c_char, c_wchar, c_int, c_double)
-import _ctypes_test
dll = CDLL(_ctypes_test.__file__)
X.init_called += 1
self.x = 42
+
class Y(X):
_fields_ = [("str", c_char_p)]
+
class PickleTest:
def dumps(self, item):
return pickle.dumps(item, self.proto)
# Issue 5049
self.dumps(c_wchar("x"))
+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
name = 'PickleTest_%s' % proto
globals()[name] = type(name,
(PickleTest, unittest.TestCase),
{'proto': proto})
+
if __name__ == "__main__":
unittest.main()
import _ctypes_test
+import array
import ctypes
import sys
import unittest
-from ctypes import (CDLL, CFUNCTYPE, Structure, POINTER, pointer, byref, sizeof,
+from ctypes import (CDLL, CFUNCTYPE, Structure,
+ POINTER, pointer, _Pointer, _pointer_type_cache,
+ byref, sizeof,
c_void_p, c_char_p,
c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
- c_long, c_ulong, c_longlong, c_ulonglong, c_float, c_double)
+ c_long, c_ulong, c_longlong, c_ulonglong,
+ c_float, c_double)
+
ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_float]
python_types = [int, int, int, int, int, int,
int, int, int, int, float, float]
-class PointersTestCase(unittest.TestCase):
+class PointersTestCase(unittest.TestCase):
def test_pointer_crash(self):
class A(POINTER(c_ulong)):
del p[0]
def test_from_address(self):
- from array import array
- a = array('i', [100, 200, 300, 400, 500])
+ a = array.array('i', [100, 200, 300, 400, 500])
addr = a.buffer_info()[0]
p = POINTER(POINTER(c_int))
pt.contents.c = 33
- from ctypes import _pointer_type_cache
del _pointer_type_cache[Table]
def test_basic(self):
self.assertTrue(POINTER(LargeNamedType))
# to not leak references, we must clean _pointer_type_cache
- from ctypes import _pointer_type_cache
del _pointer_type_cache[LargeNamedType]
def test_pointer_type_str_name(self):
self.assertTrue(P)
# to not leak references, we must clean _pointer_type_cache
- from ctypes import _pointer_type_cache
del _pointer_type_cache[id(P)]
def test_abstract(self):
- from ctypes import _Pointer
-
self.assertRaises(TypeError, _Pointer.set_type, 42)
-from ctypes import (CDLL, CFUNCTYPE, POINTER, ArgumentError,
- pointer, byref, sizeof, addressof,
- c_void_p, c_char_p, c_wchar_p, c_char, c_wchar, c_buffer,
- c_short, c_int, c_long, c_longlong, c_double)
-import unittest
-
# IMPORTANT INFO:
#
# Consider this call:
# In this case, there would have to be an additional reference to the argument...
import _ctypes_test
+import unittest
+from ctypes import (CDLL, CFUNCTYPE, POINTER, ArgumentError,
+ pointer, byref, sizeof, addressof, create_string_buffer,
+ c_void_p, c_char_p, c_wchar_p, c_char, c_wchar,
+ c_short, c_int, c_long, c_longlong, c_double)
+
+
testdll = CDLL(_ctypes_test.__file__)
+
# Return machine address `a` as a (possibly long) non-negative integer.
# Starting with Python 2.5, id(anything) is always non-negative, and
# the ctypes addressof() inherits that via PyLong_FromVoidPtr().
assert a >= 0
return a
+
def c_wbuffer(init):
n = len(init) + 1
return (c_wchar * n)(*init)
-class CharPointersTestCase(unittest.TestCase):
+class CharPointersTestCase(unittest.TestCase):
def setUp(self):
func = testdll._testfunc_p_p
func.restype = c_long
self.assertEqual(None, func(c_char_p(None)))
self.assertEqual(b"123", func(c_char_p(b"123")))
- self.assertEqual(b"123", func(c_buffer(b"123")))
+ self.assertEqual(b"123", func(create_string_buffer(b"123")))
ca = c_char(b"a")
self.assertEqual(ord(b"a"), func(pointer(ca))[0])
self.assertEqual(ord(b"a"), func(byref(ca))[0])
self.assertEqual(None, func(c_char_p(None)))
self.assertEqual(b"123", func(c_char_p(b"123")))
- self.assertEqual(b"123", func(c_buffer(b"123")))
+ self.assertEqual(b"123", func(create_string_buffer(b"123")))
ca = c_char(b"a")
self.assertEqual(ord(b"a"), func(pointer(ca))[0])
self.assertEqual(ord(b"a"), func(byref(ca))[0])
self.assertEqual(b"123", func(c_char_p(b"123")))
self.assertEqual(None, func(c_char_p(None)))
- self.assertEqual(b"123", func(c_buffer(b"123")))
+ self.assertEqual(b"123", func(create_string_buffer(b"123")))
ca = c_char(b"a")
self.assertEqual(ord(b"a"), func(pointer(ca))[0])
self.assertEqual(ord(b"a"), func(byref(ca))[0])
func.argtypes = None
self.assertEqual(None, func(X()))
-class WCharPointersTestCase(unittest.TestCase):
+class WCharPointersTestCase(unittest.TestCase):
def setUp(self):
func = testdll._testfunc_p_p
func.restype = c_int
self.assertEqual("a", func(pointer(ca))[0])
self.assertEqual("a", func(byref(ca))[0])
+
class ArrayTest(unittest.TestCase):
def test(self):
func = testdll._testfunc_ai8
def func(): pass
CFUNCTYPE(None, c_int * 3)(func)
-################################################################
if __name__ == '__main__':
unittest.main()
-import unittest
+import _ctypes
import sys
+import unittest
from test import support
-from ctypes import (pythonapi, POINTER, c_buffer, sizeof,
+from ctypes import (pythonapi, POINTER, create_string_buffer, sizeof,
py_object, c_char_p, c_char, c_long, c_size_t)
-################################################################
-# This section should be moved into ctypes\__init__.py, when it's ready.
-
-from _ctypes import PyObj_FromPtr
-
-################################################################
-
-
class PythonAPITestCase(unittest.TestCase):
-
def test_PyBytes_FromStringAndSize(self):
PyBytes_FromStringAndSize = pythonapi.PyBytes_FromStringAndSize
s = "abc def ghi jkl"
ref = sys.getrefcount(s)
# id(python-object) is the address
- pyobj = PyObj_FromPtr(id(s))
+ pyobj = _ctypes.PyObj_FromPtr(id(s))
self.assertIs(s, pyobj)
self.assertEqual(sys.getrefcount(s), ref + 1)
PyOS_snprintf = pythonapi.PyOS_snprintf
PyOS_snprintf.argtypes = POINTER(c_char), c_size_t, c_char_p
- buf = c_buffer(256)
+ buf = create_string_buffer(256)
PyOS_snprintf(buf, sizeof(buf), b"Hello from %s", b"ctypes")
self.assertEqual(buf.value, b"Hello from ctypes")
+import _ctypes
import contextlib
import ctypes
import sys
42 / arg
raise ValueError(arg)
+
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
class call_function_TestCase(unittest.TestCase):
# _ctypes.call_function is deprecated and private, but used by
# Gary Bishp's readline module. If we have it, we must test it as well.
def test(self):
- from _ctypes import call_function
-
kernel32 = ctypes.windll.kernel32
kernel32.LoadLibraryA.restype = c_void_p
kernel32.GetProcAddress.argtypes = c_void_p, c_char_p
hdll = kernel32.LoadLibraryA(b"kernel32")
funcaddr = kernel32.GetProcAddress(hdll, b"GetModuleHandleA")
- self.assertEqual(call_function(funcaddr, (None,)),
+ self.assertEqual(_ctypes.call_function(funcaddr, (None,)),
kernel32.GetModuleHandleA(None))
+
class CallbackTracbackTestCase(unittest.TestCase):
# When an exception is raised in a ctypes callback function, the C
# code prints a traceback.
+import _ctypes_test
import ctypes
import gc
import sys
import unittest
from test import support
+
MyCallback = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int)
OtherCallback = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_ulonglong)
-import _ctypes_test
dll = ctypes.CDLL(_ctypes_test.__file__)
-class RefcountTestCase(unittest.TestCase):
+class RefcountTestCase(unittest.TestCase):
@support.refcount_test
def test_1(self):
f = dll._testfunc_callback_i_if
self.assertEqual(sys.getrefcount(callback), 2)
-
@support.refcount_test
def test_refcount(self):
def func(*args):
gc.collect()
self.assertEqual(sys.getrefcount(func), 2)
+
class AnotherLeak(unittest.TestCase):
def test_callback(self):
- import sys
-
proto = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_int)
def func(a, b):
return a * b * 2
for _ in range(10000):
func()
+
if __name__ == '__main__':
unittest.main()
+import unittest
from ctypes import (c_byte, c_short, c_int, c_long, c_longlong,
c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong,
c_float, c_double, c_longdouble, c_bool, c_char)
-import unittest
+
subclasses = []
for base in [c_byte, c_short, c_int, c_long, c_longlong,
pass
subclasses.append(X)
+
class X(c_char):
pass
-# This test checks if the __repr__ is correct for subclasses of simple types
+# This test checks if the __repr__ is correct for subclasses of simple types
class ReprTest(unittest.TestCase):
def test_numbers(self):
for typ in subclasses:
+import _ctypes_test
import unittest
from ctypes import CDLL, CFUNCTYPE, ArgumentError, c_char_p, c_void_p, c_char
-import _ctypes_test
class ReturnFuncPtrTestCase(unittest.TestCase):
-
def test_with_prototype(self):
# The _ctypes_test shared lib/dll exports quite some functions for testing.
# The get_strchr function returns a *pointer* to the C strchr function.
+import _ctypes_test
import unittest
from ctypes import (CDLL, POINTER, sizeof,
c_byte, c_short, c_int, c_long, c_char, c_wchar, c_char_p)
-import _ctypes_test
class SlicesTestCase(unittest.TestCase):
def test_getslice_cint(self):
self.assertEqual(res[len(s)-2:5:-7], tmpl[:5:-7])
dll.my_free(res)
-################################################################
if __name__ == "__main__":
unittest.main()
-import unittest
+import _ctypes_test
import sys
+import unittest
from test import support
-from ctypes import CDLL, Structure, POINTER, c_buffer, c_char, c_char_p
+from ctypes import (CDLL, Structure, POINTER, create_string_buffer,
+ c_char, c_char_p)
-import _ctypes_test
lib = CDLL(_ctypes_test.__file__)
-class StringPtrTestCase(unittest.TestCase):
+class StringPtrTestCase(unittest.TestCase):
@support.refcount_test
def test__POINTER_c_char(self):
class X(Structure):
# NULL pointer access
self.assertRaises(ValueError, getattr, x.str, "contents")
- b = c_buffer(b"Hello, World")
+ b = create_string_buffer(b"Hello, World")
self.assertEqual(sys.getrefcount(b), 2)
x.str = b
self.assertEqual(sys.getrefcount(b), 3)
# POINTER(c_char) and Python string is NOT compatible
- # POINTER(c_char) and c_buffer() is compatible
+ # POINTER(c_char) and create_string_buffer() is compatible
for i in range(len(b)):
self.assertEqual(b[i], x.str[i])
x = X()
# c_char_p and Python string is compatible
- # c_char_p and c_buffer is NOT compatible
+ # c_char_p and create_string_buffer is NOT compatible
self.assertEqual(x.str, None)
x.str = b"Hello, World"
self.assertEqual(x.str, b"Hello, World")
- b = c_buffer(b"Hello, World")
+ b = create_string_buffer(b"Hello, World")
self.assertRaises(TypeError, setattr, x, b"str", b)
strchr.restype = c_char_p
# c_char_p and Python string is compatible
- # c_char_p and c_buffer are now compatible
+ # c_char_p and create_string_buffer are now compatible
strchr.argtypes = c_char_p, c_char
self.assertEqual(strchr(b"abcdef", b"c"), b"cdef")
- self.assertEqual(strchr(c_buffer(b"abcdef"), b"c"), b"cdef")
+ self.assertEqual(strchr(create_string_buffer(b"abcdef"), b"c"),
+ b"cdef")
# POINTER(c_char) and Python string is NOT compatible
- # POINTER(c_char) and c_buffer() is compatible
+ # POINTER(c_char) and create_string_buffer() is compatible
strchr.argtypes = POINTER(c_char), c_char
- buf = c_buffer(b"abcdef")
+ buf = create_string_buffer(b"abcdef")
self.assertEqual(strchr(buf, b"c"), b"cdef")
self.assertEqual(strchr(b"abcdef", b"c"), b"cdef")
# So we must keep a reference to buf separately
strchr.restype = POINTER(c_char)
- buf = c_buffer(b"abcdef")
+ buf = create_string_buffer(b"abcdef")
r = strchr(buf, b"c")
x = r[0], r[1], r[2], r[3], r[4]
self.assertEqual(x, (b"c", b"d", b"e", b"f", b"\000"))
# Because r is a pointer to memory that is freed after deleting buf,
# the pointer is hanging and using it would reference freed memory.
+
if __name__ == '__main__':
unittest.main()
import unittest
-from ctypes import c_buffer, sizeof, byref, c_char, c_wchar
+from ctypes import create_string_buffer, sizeof, byref, c_char, c_wchar
+
class StringArrayTestCase(unittest.TestCase):
def test(self):
self.assertRaises(ValueError, setattr, buf, "value", b"aaaaaaaa")
self.assertRaises(TypeError, setattr, buf, "value", 42)
- def test_c_buffer_value(self):
- buf = c_buffer(32)
+ def test_create_string_buffer_value(self):
+ buf = create_string_buffer(32)
buf.value = b"Hello, World"
self.assertEqual(buf.value, b"Hello, World")
self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc"))
self.assertRaises(ValueError, setattr, buf, "raw", memoryview(b"x" * 100))
- def test_c_buffer_raw(self):
- buf = c_buffer(32)
+ def test_create_string_buffer_raw(self):
+ buf = create_string_buffer(32)
buf.raw = memoryview(b"Hello, World")
self.assertEqual(buf.value, b"Hello, World")
repr(byref(c_wchar("x")))
c_wchar("x")
-
@unittest.skip('test disabled')
def test_basic_wstrings(self):
cs = c_wstring("abcdef")
import unittest
from ctypes import Structure, Union, sizeof, c_char, c_int
+
class StructFieldsTestCase(unittest.TestCase):
# Structure/Union classes must get 'finalized' sooner or
# later, when one of these things happen:
self.assertRaises(TypeError,
MyCUnion.field.__get__, 'wrong type self', 42)
+
if __name__ == "__main__":
unittest.main()
+import _ctypes_test
import platform
+import struct
import sys
import unittest
from ctypes import (CDLL, Structure, Union, POINTER, sizeof, byref, alignment,
c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong, c_float, c_double)
from struct import calcsize
-import _ctypes_test
from test import support
+
# The following definition is meant to be used from time to time to assist
# temporarily disabling tests on specific architectures while investigations
# are in progress, to keep buildbots happy.
MACHINE = platform.machine()
+
class SubclassesTest(unittest.TestCase):
def test_subclass(self):
class X(Structure):
self.assertEqual(Y._fields_, [("b", c_int)])
self.assertEqual(Z._fields_, [("a", c_int)])
+
class StructureTestCase(unittest.TestCase):
formats = {"c": c_char,
"b": c_byte,
self.assertEqual(sizeof(X), 10)
self.assertEqual(X.b.offset, 2)
- import struct
longlong_size = struct.calcsize("q")
longlong_align = struct.calcsize("bq") - longlong_size
self.assertEqual(ctx.exception.args[0], 'item 1 in _argtypes_ passes '
'a union by value, which is unsupported.')
+
class PointerMemberTestCase(unittest.TestCase):
def test(self):
s.p = None
self.assertEqual(s.x, 12345678)
+
class TestRecursiveStructure(unittest.TestCase):
def test_contains_itself(self):
class Recursive(Structure):
else:
self.fail("AttributeError not raised")
+
if __name__ == '__main__':
unittest.main()
c_float, c_double,
c_ushort, c_uint, c_ulong, c_ulonglong)
+
structures = []
byteswapped_structures = []
structures.append(X)
byteswapped_structures.append(Y)
+
class TestStructures(unittest.TestCase):
def test_native(self):
for typ in structures:
o.value = 4
self.assertEqual(o.value, 4)
+
if __name__ == '__main__':
unittest.main()
-import unittest
+import _ctypes_test
import ctypes
+import unittest
-import _ctypes_test
class UnicodeTestCase(unittest.TestCase):
def test_wcslen(self):
A testcase which accesses *values* in a dll.
"""
+import _ctypes_test
import _imp
import importlib.util
-import unittest
import sys
-from ctypes import Structure, CDLL, POINTER, pythonapi, c_ubyte, c_char_p, c_int
+import unittest
+from ctypes import (Structure, CDLL, POINTER, pythonapi,
+ _pointer_type_cache,
+ c_ubyte, c_char_p, c_int)
from test.support import import_helper
-import _ctypes_test
class ValuesTestCase(unittest.TestCase):
ctdll = CDLL(_ctypes_test.__file__)
self.assertRaises(ValueError, c_int.in_dll, ctdll, "Undefined_Symbol")
+
class PythonValuesTestCase(unittest.TestCase):
"""This test only works when python itself is a dll/shared library"""
"_PyImport_FrozenBootstrap example "
"in Doc/library/ctypes.rst may be out of date")
- from ctypes import _pointer_type_cache
del _pointer_type_cache[struct_frozen]
def test_undefined(self):
self.assertRaises(ValueError, c_int.in_dll, pythonapi,
"Undefined_Symbol")
+
if __name__ == '__main__':
unittest.main()
-from ctypes import Structure, sizeof, resize, c_int
import unittest
+from ctypes import Structure, sizeof, resize, c_int
+
class VarSizeTest(unittest.TestCase):
def test_resize(self):
self.assertRaises(IndexError, array.__setitem__, -1, None)
self.assertRaises(IndexError, array.__getitem__, -1)
+
if __name__ == "__main__":
unittest.main()
import _ctypes_test
import ctypes
+import errno
import sys
import unittest
from ctypes import (CDLL, Structure, POINTER, pointer, sizeof, byref,
+ _pointer_type_cache,
c_void_p, c_char, c_int, c_long)
from test import support
self.assertEqual(value, expected)
-
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
class TestWintypes(unittest.TestCase):
def test_HWND(self):
self.assertEqual(ex.text, "text")
self.assertEqual(ex.details, ("details",))
+
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
class TestWinError(unittest.TestCase):
def test_winerror(self):
# see Issue 16169
- import errno
ERROR_INVALID_PARAMETER = 87
msg = ctypes.FormatError(ERROR_INVALID_PARAMETER).strip()
args = (errno.EINVAL, msg, None, ERROR_INVALID_PARAMETER)
self.assertEqual(ret.bottom, bottom.value)
# to not leak references, we must clean _pointer_type_cache
- from ctypes import _pointer_type_cache
del _pointer_type_cache[RECT]
# See <https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types>
# for reference.
+#
+# Tests also work on POSIX
import unittest
-
-# also work on POSIX
-
from ctypes import POINTER, cast, c_int16
from ctypes import wintypes