]> granicus.if.org Git - python/commitdiff
bpo-23927: Make getargs.c skipitem() skipping 'w*'. (GH-8192)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 11 Jul 2018 14:41:43 +0000 (17:41 +0300)
committerGitHub <noreply@github.com>
Wed, 11 Jul 2018 14:41:43 +0000 (17:41 +0300)
Lib/test/test_capi.py
Misc/NEWS.d/next/C API/2018-07-09-11-39-54.bpo-23927.pDFkxb.rst [new file with mode: 0644]
Python/getargs.c

index 2a6de3c5aa9780c735e72c9a34cc7e7c7082ac6c..bb2570a8e094389109621276403af3e6b9a665a2 100644 (file)
@@ -6,6 +6,7 @@ import os
 import pickle
 import random
 import re
+import string
 import subprocess
 import sys
 import sysconfig
@@ -489,6 +490,37 @@ class SkipitemTest(unittest.TestCase):
                     c, i, when_skipped, when_not_skipped))
             self.assertIs(when_skipped, when_not_skipped, message)
 
+    def test_skipitem_with_suffix(self):
+        parse = _testcapi.parse_tuple_and_keywords
+        empty_tuple = ()
+        tuple_1 = (0,)
+        dict_b = {'b':1}
+        keywords = ["a", "b"]
+
+        supported = ('s#', 's*', 'z#', 'z*', 'u#', 'Z#', 'y#', 'y*', 'w#', 'w*')
+        for c in string.ascii_letters:
+            for c2 in '#*':
+                f = c + c2
+                with self.subTest(format=f):
+                    optional_format = "|" + f + "i"
+                    if f in supported:
+                        parse(empty_tuple, dict_b, optional_format, keywords)
+                    else:
+                        with self.assertRaisesRegex(SystemError,
+                                    'impossible<bad format char>'):
+                            parse(empty_tuple, dict_b, optional_format, keywords)
+
+        for c in map(chr, range(32, 128)):
+            f = 'e' + c
+            optional_format = "|" + f + "i"
+            with self.subTest(format=f):
+                if c in 'st':
+                    parse(empty_tuple, dict_b, optional_format, keywords)
+                else:
+                    with self.assertRaisesRegex(SystemError,
+                                'impossible<bad format char>'):
+                        parse(empty_tuple, dict_b, optional_format, keywords)
+
     def test_parse_tuple_and_keywords(self):
         # Test handling errors in the parse_tuple_and_keywords helper itself
         self.assertRaises(TypeError, _testcapi.parse_tuple_and_keywords,
diff --git a/Misc/NEWS.d/next/C API/2018-07-09-11-39-54.bpo-23927.pDFkxb.rst b/Misc/NEWS.d/next/C API/2018-07-09-11-39-54.bpo-23927.pDFkxb.rst
new file mode 100644 (file)
index 0000000..3e2ac6c
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed :exc:`SystemError` in :c:func:`PyArg_ParseTupleAndKeywords` when the
+``w*`` format unit is used for optional parameter.
index 97c1fe8f4c9da9d21fb76e7b5cdd672db2660f8b..992cb216c257f978d0c9439e8136cd0da7ae98c1 100644 (file)
@@ -2333,7 +2333,9 @@ skipitem(const char **p_format, va_list *p_va, int flags)
                         (void) va_arg(*p_va, int *);
                 }
                 format++;
-            } else if ((c == 's' || c == 'z' || c == 'y') && *format == '*') {
+            } else if ((c == 's' || c == 'z' || c == 'y' || c == 'w')
+                       && *format == '*')
+            {
                 format++;
             }
             break;