diff options
author | Sylvain <sylvain.desodt+github@gmail.com> | 2017-06-15 15:05:23 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-06-15 15:05:23 (GMT) |
commit | 96c7c0685045b739fdc5145018cddfd252155713 (patch) | |
tree | 8c99f9484c33d59c49b45146e50f7d6c7b08a4a7 /Modules/_struct.c | |
parent | 8acb4cf2b3436652568d7a70228b166316181466 (diff) | |
download | cpython-96c7c0685045b739fdc5145018cddfd252155713.zip cpython-96c7c0685045b739fdc5145018cddfd252155713.tar.gz cpython-96c7c0685045b739fdc5145018cddfd252155713.tar.bz2 |
bpo-20627: Fix error message when keyword arguments are used (#2115)
Diffstat (limited to 'Modules/_struct.c')
-rw-r--r-- | Modules/_struct.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c index 5b74ec5..46e7b40 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1823,6 +1823,9 @@ s_pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) PyObject *result; /* Validate arguments. */ + if (!_PyArg_NoStackKeywords("pack", kwnames)) { + return NULL; + } soself = (PyStructObject *)self; assert(PyStruct_Check(self)); assert(soself->s_codes != NULL); @@ -1832,9 +1835,6 @@ s_pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) "pack expected %zd items for packing (got %zd)", soself->s_len, nargs); return NULL; } - if (!_PyArg_NoStackKeywords("pack", kwnames)) { - return NULL; - } /* Allocate a new buffer */ result = PyBytes_FromStringAndSize((char *)NULL, soself->s_size); @@ -1866,6 +1866,9 @@ s_pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames Py_ssize_t offset; /* Validate arguments. +1 is for the first arg as buffer. */ + if (!_PyArg_NoStackKeywords("pack_into", kwnames)) { + return NULL; + } soself = (PyStructObject *)self; assert(PyStruct_Check(self)); assert(soself->s_codes != NULL); @@ -1886,9 +1889,6 @@ s_pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames } return NULL; } - if (!_PyArg_NoStackKeywords("pack_into", kwnames)) { - return NULL; - } /* Extract a writable memory buffer from the first argument */ if (!PyArg_Parse(args[0], "w*", &buffer)) @@ -2131,6 +2131,10 @@ pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) PyObject *s_object = NULL; PyObject *format, *result; + if (!_PyArg_NoStackKeywords("pack", kwnames)) { + return NULL; + } + if (nargs == 0) { PyErr_SetString(PyExc_TypeError, "missing format argument"); return NULL; @@ -2159,6 +2163,10 @@ pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) PyObject *s_object = NULL; PyObject *format, *result; + if (!_PyArg_NoStackKeywords("pack_into", kwnames)) { + return NULL; + } + if (nargs == 0) { PyErr_SetString(PyExc_TypeError, "missing format argument"); return NULL; |