Commit 5c89c19e authored by Petri Lehtinen's avatar Petri Lehtinen

#14897: Enhance error messages of struct.pack and struct.pack_into

Patch by Matti Mäki.
parent 64c0b2ca
...@@ -655,6 +655,7 @@ Brian Merrell ...@@ -655,6 +655,7 @@ Brian Merrell
Luke Mewburn Luke Mewburn
Carl Meyer Carl Meyer
Mike Meyer Mike Meyer
Piotr Meyer
Steven Miale Steven Miale
Trent Mick Trent Mick
Tom Middleton Tom Middleton
...@@ -685,7 +686,7 @@ Sape Mullender ...@@ -685,7 +686,7 @@ Sape Mullender
Michael Muller Michael Muller
Neil Muller Neil Muller
R. David Murray R. David Murray
Piotr Meyer Matti Mäki
Dale Nagata Dale Nagata
John Nagle John Nagle
Takahiro Nakayama Takahiro Nakayama
......
...@@ -125,6 +125,9 @@ Core and Builtins ...@@ -125,6 +125,9 @@ Core and Builtins
Library Library
------- -------
- Issue #14897: Enhance error messages of struct.pack and
struct.pack_into. Patch by Matti Mäki.
- Issue #12890: cgitb no longer prints spurious <p> tags in text - Issue #12890: cgitb no longer prints spurious <p> tags in text
mode when the logdir option is specified. mode when the logdir option is specified.
......
...@@ -1603,7 +1603,7 @@ s_pack(PyObject *self, PyObject *args) ...@@ -1603,7 +1603,7 @@ s_pack(PyObject *self, PyObject *args)
if (PyTuple_GET_SIZE(args) != soself->s_len) if (PyTuple_GET_SIZE(args) != soself->s_len)
{ {
PyErr_Format(StructError, PyErr_Format(StructError,
"pack requires exactly %zd arguments", soself->s_len); "pack expected %zd items for packing (got %zd)", soself->s_len, PyTuple_GET_SIZE(args));
return NULL; return NULL;
} }
...@@ -1642,9 +1642,19 @@ s_pack_into(PyObject *self, PyObject *args) ...@@ -1642,9 +1642,19 @@ s_pack_into(PyObject *self, PyObject *args)
assert(soself->s_codes != NULL); assert(soself->s_codes != NULL);
if (PyTuple_GET_SIZE(args) != (soself->s_len + 2)) if (PyTuple_GET_SIZE(args) != (soself->s_len + 2))
{ {
PyErr_Format(StructError, if (PyTuple_GET_SIZE(args) == 0) {
"pack_into requires exactly %zd arguments", PyErr_Format(StructError,
(soself->s_len + 2)); "pack_into expected buffer argument");
}
else if (PyTuple_GET_SIZE(args) == 1) {
PyErr_Format(StructError,
"pack_into expected offset argument");
}
else {
PyErr_Format(StructError,
"pack_into expected %zd items for packing (got %zd)",
soself->s_len, (PyTuple_GET_SIZE(args) - 2));
}
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment