8000 bpo-23927: Make getargs.c skipitem() skipping 'w*'. (GH-8192) · python/cpython@48d2aeb · GitHub
[go: up one dir, main page]

Skip to content

Commit 48d2aeb

Browse files
bpo-23927: Make getargs.c skipitem() skipping 'w*'. (GH-8192)
(cherry picked from commit 504373c) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 020f5ab commit 48d2aeb

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Lib/test/test_capi.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pickle
77
import random
88
import re
9+
import string
910
import subprocess
1011
import sys
1112
import sysconfig
@@ -489,6 +490,37 @@ def test_skipitem(self):
489490
c, i, when_skipped, when_not_skipped))
490491
self.assertIs(when_skipped, when_not_skipped, message)
491492

493+
def test_skipitem_with_suffix(self):
494+
parse = _testcapi.parse_tuple_and_keywords
495+
empty_tuple = ()
496+
tuple_1 = (0,)
497+
dict_b = {'b':1}
498+
keywords = ["a", "b"]
499+
500+
supported = ('s#', 's*', 'z#', 'z*', 'u#', 'Z#', 'y#', 'y*', 'w#', 'w*')
501+
for c in string.ascii_letters:
502+
for c2 in '#*':
503+
f = c + c2
504+
with self.subTest(format=f):
505+
optional_format = "|" + f + "i"
506+
if f in supported:
507+
parse(empty_tuple, dict_b, optional_format, keywords)
508+
else:
509+
with self.assertRaisesRegex(SystemError,
510+
'impossible<bad format char>'):
511+
parse(empty_tuple, dict_b, optional_format, keywords)
512+
513+
for c in map(chr, range(32, 128)):
514+
f = 'e' + c
515+
optional_format = "|" + f + "i"
516+
with self.subTest(format=f):
517+
if c in 'st':
518+
parse(empty_tuple, dict_b, optional_format, keywords)
519+
else:
520+
with self.assertRaisesRegex(SystemError,
521+
'impossible<bad format char>'):
522+
parse(empty_tuple, dict_b, optional_format, keywords)
523+
492524
def test_parse_tuple_and_keywords(self):
493525
# Test handling errors in the parse_tuple_and_keywords helper itself
494526
self.assertRaises(TypeError, _testcapi.parse_tuple_and_keywords,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed :exc:`SystemError` in :c:func:`PyArg_ParseTupleAndKeywords` when the
2+
``w*`` format unit is used for optional parameter.

Python/getargs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,9 @@ skipitem(const char **p_format, va_list *p_va, int flags)
23332333
(void) va_arg(*p_va, int *);
23342334
}
23352335
format++;
2336-
} else if ((c == 's' || c == 'z' || c == 'y') && *format == '*') {
2336+
} else if ((c == 's' || c == 'z' || c == 'y' || c == 'w')
2337+
&& *format == '*')
2338+
{
23372339
format++;
23382340
}
23392341
break;

0 commit comments

Comments
 (0)
0