Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0ed0db

Browse files
committed
Merged revisions 76646 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r76646 | mark.dickinson | 2009-12-03 10:59:46 +0000 (Thu, 03 Dec 2009) | 6 lines Issue #7414: Add missing 'case 'C'' to skipitem() in getargs.c. This was causing PyArg_ParseTupleAndKeywords(args, kwargs, "|CC", ...) to fail with a RuntimeError. Thanks Case Van Horsen for tracking down the source of this error. ........
1 parent a9566d0 commit d0ed0db

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ Core and Builtins
270270
C-API
271271
-----
272272

273+
- Issue #7414: 'C' code wasn't being skipped properly (for keyword arguments)
274+
in PyArg_ParseTupleAndKeywords.
275+
273276
- Issue #6624: yArg_ParseTuple with "s" format when parsing argument with
274277
NUL: Bogus TypeError detail string.
275278

Modules/_testcapimodule.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,52 @@ test_s_code(PyObject *self)
616616
Py_RETURN_NONE;
617617
}
618618

619+
static PyObject *
620+
test_bug_7414(PyObject *self)
621+
{
622+
/* Issue #7414: for PyArg_ParseTupleAndKeywords, 'C' code wasn't being
623+
skipped properly in skipitem() */
624+
int a = 0, b = 0, result;
625+
char *kwlist[] = {"a", "b", NULL};
626+
PyObject *tuple = NULL, *dict = NULL, *b_str;
627+
628+
tuple = PyTuple_New(0);
629+
if (tuple == NULL)
630+
goto failure;
631+
dict = PyDict_New();
632+
if (dict == NULL)
633+
goto failure;
634+
b_str = PyUnicode_FromString("b");
635+
if (b_str == NULL)
636+
goto failure;
637+
result = PyDict_SetItemString(dict, "b", b_str);
638+
Py_DECREF(b_str);
639+
if (result < 0)
640+
goto failure;
641+
642+
result = PyArg_ParseTupleAndKeywords(tuple, dict, "|CC",
643+
kwlist, &a, &b);
644+
if (!result)
645+
goto failure;
646+
647+
if (a != 0)
648+
return raiseTestError("test_bug_7414",
649+
"C format code not skipped properly");
650+
if (b != 'b')
651+
return raiseTestError("test_bug_7414",
652+
"C format code returned wrong value");
653+
654+
Py_DECREF(dict);
655+
Py_DECREF(tuple);
656+
Py_RETURN_NONE;
657+
658+
failure:
659+
Py_XDECREF(dict);
660+
Py_XDECREF(tuple);
661+
return NULL;
662+
}
663+
664+
619665
static volatile int x;
620666

621667
/* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
@@ -1457,6 +1503,7 @@ static PyMethodDef TestMethods[] = {
14571503
{"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS},
14581504
{"test_k_code", (PyCFunction)test_k_code, METH_NOARGS},
14591505
{"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS},
1506+
{"test_bug_7414", (PyCFunction)test_bug_7414, METH_NOARGS},
14601507
{"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS},
14611508
{"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS},
14621509
{"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS,

Python/getargs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,7 @@ skipitem(const char **p_format, va_list *p_va, int flags)
17761776
case 'D': /* complex double */
17771777
#endif
17781778
case 'c': /* char */
1779+
case 'C': /* unicode char */
17791780
{
17801781
(void) va_arg(*p_va, void *);
17811782
break;

0 commit comments

Comments
 (0)