From 2cefe0526cc1e0eeda4e8eb29623956f35c624d8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 11 Jul 2018 17:41:43 +0300 Subject: [PATCH] bpo-23927: Make getargs.c skipitem() skipping 'w*'. (GH-8192) (cherry picked from commit 504373c59b48f1ea12132d515459022730db6047) Co-authored-by: Serhiy Storchaka --- Lib/test/test_capi.py | 32 +++++++++++++++++++ .../2018-07-09-11-39-54.bpo-23927.pDFkxb.rst | 2 ++ Python/getargs.c | 4 ++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/C API/2018-07-09-11-39-54.bpo-23927.pDFkxb.rst diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index b36a2ce585ce3e..2725333e7e96c2 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -5,6 +5,7 @@ import pickle import random import re +import string import subprocess import sys import sysconfig @@ -565,6 +566,37 @@ def test_skipitem(self): 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'): + 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'): + 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 index 00000000000000..3e2ac6c91837e1 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2018-07-09-11-39-54.bpo-23927.pDFkxb.rst @@ -0,0 +1,2 @@ +Fixed :exc:`SystemError` in :c:func:`PyArg_ParseTupleAndKeywords` when the +``w*`` format unit is used for optional parameter. diff --git a/Python/getargs.c b/Python/getargs.c index 4d27418a84ba07..594b150deeb1f0 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2281,7 +2281,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; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy