]> granicus.if.org Git - python/commitdiff
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
authorBenjamin Peterson <benjamin@python.org>
Mon, 22 Dec 2008 20:51:15 +0000 (20:51 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 22 Dec 2008 20:51:15 +0000 (20:51 +0000)
Modules/_testcapimodule.c
Python/getargs.c

index adb04c0bb8757366fdcacc9e4306c48a83e72b4f..d7ec73031db02232899b899dc40515e7d232832d 100644 (file)
@@ -518,6 +518,32 @@ test_u_code(PyObject *self)
        return Py_None;
 }
 
+static PyObject *
+test_empty_argparse(PyObject *self)
+{
+       /* Test that formats can begin with '|'. See issue #4720. */
+       PyObject *tuple, *dict = NULL;
+       static char *kwlist[] = {NULL};
+       int result;
+       tuple = PyTuple_New(0);
+       if (!tuple)
+               return NULL;
+       if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0)
+               goto done;
+       dict = PyDict_New();
+       if (!dict)
+               goto done;
+       result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist);
+  done:
+       Py_DECREF(tuple);
+       Py_XDECREF(dict);
+       if (result < 0)
+               return NULL;
+       else {
+               Py_RETURN_NONE;
+       }
+}
+
 static PyObject *
 codec_incrementalencoder(PyObject *self, PyObject *args)
 {
@@ -780,6 +806,7 @@ static PyMethodDef TestMethods[] = {
        {"test_long_api",       (PyCFunction)test_long_api,      METH_NOARGS},
        {"test_long_numbits",   (PyCFunction)test_long_numbits,  METH_NOARGS},
        {"test_k_code",         (PyCFunction)test_k_code,        METH_NOARGS},
+       {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS},
        {"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,
index 9d1f0b218ba5ce2211bf3dc5a1024b287476e42e..544948b928510c605e1fe37298990fb442d010f2 100644 (file)
@@ -1601,7 +1601,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
                }
        }
 
-       if (!IS_END_OF_FORMAT(*format)) {
+       if (!IS_END_OF_FORMAT(*format) && *format != '|') {
                PyErr_Format(PyExc_RuntimeError,
                        "more argument specifiers than keyword list entries "
                        "(remaining format:'%s')", format);