Use the ``'w'`` format code instead.
(contributed by Hugo van Kemenade in :gh:`80480`)
+* :mod:`ctypes`: Deprecate undocumented :func:`!ctypes.SetPointerType`
+ and :func:`!ctypes.ARRAY` functions.
+ Replace ``ctypes.SetPointerType(item_type, size)`` with ``item_type * size``.
+ (Contributed by Victor Stinner in :gh:`105733`.)
+
+
Removed
=======
raise TypeError(init)
-# XXX Deprecated
def SetPointerType(pointer, cls):
+ import warnings
+ warnings._deprecated("ctypes.SetPointerType", remove=(3, 15))
if _pointer_type_cache.get(cls, None) is not None:
raise RuntimeError("This type already exists in the cache")
if id(pointer) not in _pointer_type_cache:
_pointer_type_cache[cls] = pointer
del _pointer_type_cache[id(pointer)]
-# XXX Deprecated
def ARRAY(typ, len):
+ import warnings
+ warnings._deprecated("ctypes.ARRAY", remove=(3, 15))
return typ * len
################################################################
-import unittest
-from test.support import bigmemtest, _2G
+import ctypes
import sys
+import unittest
+import warnings
from ctypes import *
+from test.support import bigmemtest, _2G
from test.test_ctypes import need_symbol
formats = c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, \
c_long, c_ulonglong, c_float, c_double, c_longdouble
+
+def ARRAY(*args):
+ # ignore DeprecationWarning in tests
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ return ctypes.ARRAY(*args)
+
+
class ArrayTestCase(unittest.TestCase):
def test_simple(self):
# create classes holding simple numeric types, and check
def test_large_array(self, size):
c_char * size
+ def test_deprecation(self):
+ with self.assertWarns(DeprecationWarning):
+ CharArray = ctypes.ARRAY(c_char, 3)
+
+
if __name__ == '__main__':
unittest.main()
+import ctypes
import unittest
+import warnings
from ctypes import *
################################################################
# The incomplete pointer example from the tutorial
#
-class MyTestCase(unittest.TestCase):
+class TestSetPointerType(unittest.TestCase):
+
+ def tearDown(self):
+ # to not leak references, we must clean _pointer_type_cache
+ ctypes._reset_cache()
def test_incomplete_example(self):
lpcell = POINTER("cell")
_fields_ = [("name", c_char_p),
("next", lpcell)]
- SetPointerType(lpcell, cell)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ ctypes.SetPointerType(lpcell, cell)
c1 = cell()
c1.name = b"foo"
p = p.next[0]
self.assertEqual(result, [b"foo", b"bar"] * 4)
- # to not leak references, we must clean _pointer_type_cache
- from ctypes import _pointer_type_cache
- del _pointer_type_cache[cell]
+ def test_deprecation(self):
+ lpcell = POINTER("cell")
+ class cell(Structure):
+ _fields_ = [("name", c_char_p),
+ ("next", lpcell)]
+
+ with self.assertWarns(DeprecationWarning):
+ ctypes.SetPointerType(lpcell, cell)
################################################################
--- /dev/null
+:mod:`ctypes`: Deprecate undocumented :func:`!ctypes.SetPointerType` and
+:func:`!ctypes.ARRAY` functions. Patch by Victor Stinner.