]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45082: Cleanup ctypes.c_buffer alias (GH-28129)
authorVictor Stinner <vstinner@python.org>
Thu, 2 Sep 2021 17:02:03 +0000 (19:02 +0200)
committerGitHub <noreply@github.com>
Thu, 2 Sep 2021 17:02:03 +0000 (19:02 +0200)
* Remove commented deprecation of ctypes.c_buffer.
* Remove references to ctypes.c_string which doesn't exist.
* Remove StringTestCase: it only had skipped test methods.

Doc/library/ctypes.rst
Lib/ctypes/__init__.py
Lib/ctypes/test/test_strings.py
Modules/_ctypes/callproc.c

index fd6422cc8c06c5f38ba6379d49154f575ee7d30f..0c1a93cdce4dbef759560c812c598a3a0d9ef659 100644 (file)
@@ -330,10 +330,9 @@ property::
    10 b'Hi\x00lo\x00\x00\x00\x00\x00'
    >>>
 
-The :func:`create_string_buffer` function replaces the :func:`c_buffer` function
-(which is still available as an alias), as well as the :func:`c_string` function
-from earlier ctypes releases.  To create a mutable memory block containing
-unicode characters of the C type :c:type:`wchar_t` use the
+The :func:`create_string_buffer` function replaces the old :func:`c_buffer`
+function (which is still available as an alias).  To create a mutable memory
+block containing unicode characters of the C type :c:type:`wchar_t`, use the
 :func:`create_unicode_buffer` function.
 
 
index 4afa4ebd4224934904e3817d91dcbb45722a7c5a..b08629e8df4dfd0a5746a4431915d6d22b288be6 100644 (file)
@@ -65,12 +65,8 @@ def create_string_buffer(init, size=None):
         return buf
     raise TypeError(init)
 
-def c_buffer(init, size=None):
-##    "deprecated, use create_string_buffer instead"
-##    import warnings
-##    warnings.warn("c_buffer is deprecated, use create_string_buffer instead",
-##                  DeprecationWarning, stacklevel=2)
-    return create_string_buffer(init, size)
+# Alias to create_string_buffer() for backward compatibility
+c_buffer = create_string_buffer
 
 _c_functype_cache = {}
 def CFUNCTYPE(restype, *argtypes, **kw):
index 5434efda10c0572dd09de128eb880bf05be58ba0..12e208828a70db45bc5085562e0a1d41cfeb28ce 100644 (file)
@@ -85,74 +85,6 @@ class WStringArrayTestCase(unittest.TestCase):
         w = c_wchar(u)
         self.assertEqual(w.value, u)
 
-class StringTestCase(unittest.TestCase):
-    @unittest.skip('test disabled')
-    def test_basic_strings(self):
-        cs = c_string("abcdef")
-
-        # Cannot call len on a c_string any longer
-        self.assertRaises(TypeError, len, cs)
-        self.assertEqual(sizeof(cs), 7)
-
-        # The value property is the string up to the first terminating NUL.
-        self.assertEqual(cs.value, "abcdef")
-        self.assertEqual(c_string("abc\000def").value, "abc")
-
-        # The raw property is the total buffer contents:
-        self.assertEqual(cs.raw, "abcdef\000")
-        self.assertEqual(c_string("abc\000def").raw, "abc\000def\000")
-
-        # We can change the value:
-        cs.value = "ab"
-        self.assertEqual(cs.value, "ab")
-        self.assertEqual(cs.raw, "ab\000\000\000\000\000")
-
-        cs.raw = "XY"
-        self.assertEqual(cs.value, "XY")
-        self.assertEqual(cs.raw, "XY\000\000\000\000\000")
-
-        self.assertRaises(TypeError, c_string, "123")
-
-    @unittest.skip('test disabled')
-    def test_sized_strings(self):
-
-        # New in releases later than 0.4.0:
-        self.assertRaises(TypeError, c_string, None)
-
-        # New in releases later than 0.4.0:
-        # c_string(number) returns an empty string of size number
-        self.assertEqual(len(c_string(32).raw), 32)
-        self.assertRaises(ValueError, c_string, -1)
-        self.assertRaises(ValueError, c_string, 0)
-
-        # These tests fail, because it is no longer initialized
-##        self.assertEqual(c_string(2).value, "")
-##        self.assertEqual(c_string(2).raw, "\000\000")
-        self.assertEqual(c_string(2).raw[-1], "\000")
-        self.assertEqual(len(c_string(2).raw), 2)
-
-    @unittest.skip('test disabled')
-    def test_initialized_strings(self):
-
-        self.assertEqual(c_string("ab", 4).raw[:2], "ab")
-        self.assertEqual(c_string("ab", 4).raw[:2:], "ab")
-        self.assertEqual(c_string("ab", 4).raw[:2:-1], "ba")
-        self.assertEqual(c_string("ab", 4).raw[:2:2], "a")
-        self.assertEqual(c_string("ab", 4).raw[-1], "\000")
-        self.assertEqual(c_string("ab", 2).raw, "a\000")
-
-    @unittest.skip('test disabled')
-    def test_toolong(self):
-        cs = c_string("abcdef")
-        # Much too long string:
-        self.assertRaises(ValueError, setattr, cs, "value", "123456789012345")
-
-        # One char too long values:
-        self.assertRaises(ValueError, setattr, cs, "value", "1234567")
-
-    @unittest.skip('test disabled')
-    def test_perf(self):
-        check_perf()
 
 @need_symbol('c_wchar')
 class WStringTestCase(unittest.TestCase):
@@ -208,25 +140,6 @@ def run_test(rep, msg, func, arg):
     stop = clock()
     print("%20s: %.2f us" % (msg, ((stop-start)*1e6/5/rep)))
 
-def check_perf():
-    # Construct 5 objects
-
-    REP = 200000
-
-    run_test(REP, "c_string(None)", c_string, None)
-    run_test(REP, "c_string('abc')", c_string, 'abc')
-
-# Python 2.3 -OO, win2k, P4 700 MHz:
-#
-#      c_string(None): 1.75 us
-#     c_string('abc'): 2.74 us
-
-# Python 2.2 -OO, win2k, P4 700 MHz:
-#
-#      c_string(None): 2.95 us
-#     c_string('abc'): 3.67 us
-
 
 if __name__ == '__main__':
-##    check_perf()
     unittest.main()
index f8f8efa4ee879301365bbbcfa25d6d891a9e6963..17e82f90cf474032c59b434b062300a2055de6a3 100644 (file)
@@ -530,8 +530,8 @@ PyCArg_repr(PyCArgObject *self)
         }
 
 /* Hm, are these 'z' and 'Z' codes useful at all?
-   Shouldn't they be replaced by the functionality of c_string
-   and c_wstring ?
+   Shouldn't they be replaced by the functionality of create_string_buffer()
+   and c_wstring() ?
 */
     case 'z':
     case 'Z':