summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-07-11 19:49:17 +0300
committerGitHub <noreply@github.com>2018-07-11 19:49:17 +0300
commitef19fd200d0768919f1658466f8b6080b191fba0 (patch)
treecb396ceee187b10b4e55a7468a834a798611fcca /Modules
parent6f036bb67d5a20c86c29ea5aeace563e3751baab (diff)
downloadcpython-git-ef19fd200d0768919f1658466f8b6080b191fba0.tar.gz
[2.7] bpo-23927: Make getargs.c skipitem() skipping 'w*'. (GH-8192). (GH-8255)
(cherry picked from commit 504373c59b48f1ea12132d515459022730db6047) Also backport tests for skipitem() and handling errors.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index d87acc171c..f57176d632 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1559,6 +1559,66 @@ getargs_et_hash(PyObject *self, PyObject *args)
return result;
}
+static PyObject *
+parse_tuple_and_keywords(PyObject *self, PyObject *args)
+{
+ PyObject *sub_args;
+ PyObject *sub_kwargs;
+ const char *sub_format;
+ PyObject *sub_keywords;
+
+ Py_ssize_t i, size;
+ char *keywords[8 + 1]; /* space for NULL at end */
+ PyObject *o;
+
+ int result;
+ PyObject *return_value = NULL;
+
+ double buffers[8][4]; /* double ensures alignment where necessary */
+
+ if (!PyArg_ParseTuple(args, "OOsO:parse_tuple_and_keywords",
+ &sub_args, &sub_kwargs,
+ &sub_format, &sub_keywords))
+ return NULL;
+
+ if (!(PyList_CheckExact(sub_keywords) || PyTuple_CheckExact(sub_keywords))) {
+ PyErr_SetString(PyExc_ValueError,
+ "parse_tuple_and_keywords: sub_keywords must be either list or tuple");
+ return NULL;
+ }
+
+ memset(buffers, 0, sizeof(buffers));
+ memset(keywords, 0, sizeof(keywords));
+
+ size = PySequence_Fast_GET_SIZE(sub_keywords);
+ if (size > 8) {
+ PyErr_SetString(PyExc_ValueError,
+ "parse_tuple_and_keywords: too many keywords in sub_keywords");
+ goto exit;
+ }
+
+ for (i = 0; i < size; i++) {
+ o = PySequence_Fast_GET_ITEM(sub_keywords, i);
+ keywords[i] = PyString_AsString(o);
+ if (keywords[i] == NULL) {
+ goto exit;
+ }
+ }
+
+ result = PyArg_ParseTupleAndKeywords(sub_args, sub_kwargs,
+ sub_format, keywords,
+ buffers + 0, buffers + 1, buffers + 2, buffers + 3,
+ buffers + 4, buffers + 5, buffers + 6, buffers + 7);
+
+ if (result) {
+ return_value = Py_None;
+ Py_INCREF(Py_None);
+ }
+
+exit:
+ return return_value;
+}
+
#ifdef Py_USING_UNICODE
static volatile int x;
@@ -2604,6 +2664,7 @@ static PyMethodDef TestMethods[] = {
#ifdef Py_USING_UNICODE
{"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS},
#endif
+ {"parse_tuple_and_keywords", parse_tuple_and_keywords, METH_VARARGS},
{"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS},
{"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS},
{"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS,