Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/library/struct.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The module defines the following exception and functions:
Pack the values *v1*, *v2*, ... according to the format string *format* and
write the packed bytes into the writable buffer *buffer* starting at
position *offset*. Note that *offset* is a required argument.
A negative *offset* counts from the end of *buffer*.


.. function:: unpack(format, buffer)
Expand All @@ -84,6 +85,7 @@ The module defines the following exception and functions:
string *format*. The result is a tuple even if it contains exactly one
item. The buffer's size in bytes, starting at position *offset*, must be at
least the size required by the format, as reflected by :func:`calcsize`.
A negative *offset* counts from the end of *buffer*.


.. function:: iter_unpack(format, buffer)
Expand Down
17 changes: 10 additions & 7 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -1960,15 +1960,16 @@ Return a tuple containing unpacked values.
Values are unpacked according to the format string Struct.format.

The buffer's size in bytes, starting at position offset, must be
at least Struct.size.
at least Struct.size. A negative offset counts from the end of the
buffer.

See help(struct) for more on format strings.
[clinic start generated code]*/

static PyObject *
Struct_unpack_from_impl(PyStructObject *self, Py_buffer *buffer,
Py_ssize_t offset)
/*[clinic end generated code: output=57fac875e0977316 input=cafd4851d473c894]*/
/*[clinic end generated code: output=57fac875e0977316 input=3451f778ed8a5345]*/
{
_structmodulestate *state = get_struct_state_structinst(self);
ENSURE_STRUCT_IS_READY(self);
Expand Down Expand Up @@ -2296,8 +2297,9 @@ PyDoc_STRVAR(s_pack_into__doc__,
\n\
Pack the values v1, v2, ... according to the format string S.format\n\
and write the packed bytes into the writable buffer buf starting at\n\
offset. Note that the offset is a required argument. See\n\
help(struct) for more on format strings.");
offset. Note that the offset is a required argument. A negative\n\
offset counts from the end of the buffer. See help(struct) for more\n\
on format strings.");

static PyObject *
s_pack_into(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Expand Down Expand Up @@ -2593,8 +2595,8 @@ PyDoc_STRVAR(pack_into_doc,
\n\
Pack the values v1, v2, ... according to the format string and write\n\
the packed bytes into the writable buffer buf starting at offset. Note\n\
that the offset is a required argument. See help(struct) for more\n\
on format strings.");
that the offset is a required argument. A negative offset counts from\n\
the end of the buffer. See help(struct) for more on format strings.");

static PyObject *
pack_into(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Expand Down Expand Up @@ -2648,14 +2650,15 @@ unpack_from
Return a tuple containing values unpacked according to the format string.

The buffer's size, minus offset, must be at least calcsize(format).
A negative offset counts from the end of the buffer.

See help(struct) for more on format strings.
[clinic start generated code]*/

static PyObject *
unpack_from_impl(PyObject *module, PyStructObject *s_object,
Py_buffer *buffer, Py_ssize_t offset)
/*[clinic end generated code: output=1042631674c6e0d3 input=6e80a5398e985025]*/
/*[clinic end generated code: output=1042631674c6e0d3 input=e383ecb97728be2b]*/
{
return Struct_unpack_from_impl(s_object, buffer, offset);
}
Expand Down
6 changes: 4 additions & 2 deletions Modules/clinic/_struct.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading