Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.7] bpo-23927: Make getargs.c skipitem() skipping 'w*'. (GH-8192) #8251

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pickle
import random
import re
import string
import subprocess
import sys
import sysconfig
Expand Down Expand Up @@ -489,6 +490,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<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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed :exc:`SystemError` in :c:func:`PyArg_ParseTupleAndKeywords` when the
``w*`` format unit is used for optional parameter.
4 changes: 3 additions & 1 deletion Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down