2017-02-02 07:09:30 -04:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2022-08-11 18:25:49 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2023-08-31 18:42:34 -03:00
|
|
|
# include "pycore_gc.h" // PyGC_Head
|
|
|
|
# include "pycore_runtime.h" // _Py_ID()
|
2022-08-11 18:25:49 -03:00
|
|
|
#endif
|
2023-08-31 18:42:34 -03:00
|
|
|
#include "pycore_abstract.h" // _PyNumber_Index()
|
2023-10-17 09:30:31 -03:00
|
|
|
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2023-11-26 10:29:52 -04:00
|
|
|
PyDoc_STRVAR(Struct___init____doc__,
|
2017-02-02 07:09:30 -04:00
|
|
|
"Struct(format)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Create a compiled struct object.\n"
|
|
|
|
"\n"
|
|
|
|
"Return a new Struct object which writes and reads binary data according to\n"
|
|
|
|
"the format string.\n"
|
|
|
|
"\n"
|
|
|
|
"See help(struct) for more on format strings.");
|
|
|
|
|
2023-11-26 10:29:52 -04:00
|
|
|
static int
|
|
|
|
Struct___init___impl(PyStructObject *self, PyObject *format);
|
2017-02-02 07:09:30 -04:00
|
|
|
|
2023-11-26 10:29:52 -04:00
|
|
|
static int
|
|
|
|
Struct___init__(PyObject *self, PyObject *args, PyObject *kwargs)
|
2017-02-02 07:09:30 -04:00
|
|
|
{
|
2023-11-26 10:29:52 -04:00
|
|
|
int return_value = -1;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 1
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(format), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2017-02-02 07:09:30 -04:00
|
|
|
static const char * const _keywords[] = {"format", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "Struct",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2019-03-14 05:32:22 -03:00
|
|
|
PyObject *argsbuf[1];
|
|
|
|
PyObject * const *fastargs;
|
|
|
|
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
|
2017-02-02 07:09:30 -04:00
|
|
|
PyObject *format;
|
|
|
|
|
2019-03-14 05:32:22 -03:00
|
|
|
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
|
|
|
|
if (!fastargs) {
|
2017-02-02 07:09:30 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-03-14 05:32:22 -03:00
|
|
|
format = fastargs[0];
|
2023-11-26 10:29:52 -04:00
|
|
|
return_value = Struct___init___impl((PyStructObject *)self, format);
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(Struct_unpack__doc__,
|
|
|
|
"unpack($self, buffer, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a tuple containing unpacked values.\n"
|
|
|
|
"\n"
|
|
|
|
"Unpack according to the format string Struct.format. The buffer\'s size\n"
|
|
|
|
"in bytes must be Struct.size.\n"
|
|
|
|
"\n"
|
|
|
|
"See help(struct) for more on format strings.");
|
|
|
|
|
|
|
|
#define STRUCT_UNPACK_METHODDEF \
|
|
|
|
{"unpack", (PyCFunction)Struct_unpack, METH_O, Struct_unpack__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
Struct_unpack_impl(PyStructObject *self, Py_buffer *buffer);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
Struct_unpack(PyStructObject *self, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
Py_buffer buffer = {NULL, NULL};
|
|
|
|
|
2018-12-25 07:23:47 -04:00
|
|
|
if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2017-02-02 07:09:30 -04:00
|
|
|
return_value = Struct_unpack_impl(self, &buffer);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for buffer */
|
|
|
|
if (buffer.obj) {
|
|
|
|
PyBuffer_Release(&buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(Struct_unpack_from__doc__,
|
|
|
|
"unpack_from($self, /, buffer, offset=0)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a tuple containing unpacked values.\n"
|
|
|
|
"\n"
|
|
|
|
"Values are unpacked according to the format string Struct.format.\n"
|
|
|
|
"\n"
|
2018-03-10 14:58:52 -04:00
|
|
|
"The buffer\'s size in bytes, starting at position offset, must be\n"
|
|
|
|
"at least Struct.size.\n"
|
2017-02-02 07:09:30 -04:00
|
|
|
"\n"
|
|
|
|
"See help(struct) for more on format strings.");
|
|
|
|
|
|
|
|
#define STRUCT_UNPACK_FROM_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"unpack_from", _PyCFunction_CAST(Struct_unpack_from), METH_FASTCALL|METH_KEYWORDS, Struct_unpack_from__doc__},
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
Struct_unpack_from_impl(PyStructObject *self, Py_buffer *buffer,
|
|
|
|
Py_ssize_t offset);
|
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
Struct_unpack_from(PyStructObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
2017-02-02 07:09:30 -04:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 2
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(buffer), &_Py_ID(offset), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2017-02-02 07:09:30 -04:00
|
|
|
static const char * const _keywords[] = {"buffer", "offset", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "unpack_from",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2019-03-14 05:32:22 -03:00
|
|
|
PyObject *argsbuf[2];
|
|
|
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
2017-02-02 07:09:30 -04:00
|
|
|
Py_buffer buffer = {NULL, NULL};
|
|
|
|
Py_ssize_t offset = 0;
|
|
|
|
|
2019-03-14 05:32:22 -03:00
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
|
|
|
|
if (!args) {
|
2017-02-02 07:09:30 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-03-14 05:32:22 -03:00
|
|
|
if (PyObject_GetBuffer(args[0], &buffer, PyBUF_SIMPLE) != 0) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!noptargs) {
|
|
|
|
goto skip_optional_pos;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Py_ssize_t ival = -1;
|
2020-05-28 04:33:45 -03:00
|
|
|
PyObject *iobj = _PyNumber_Index(args[1]);
|
2019-03-14 05:32:22 -03:00
|
|
|
if (iobj != NULL) {
|
|
|
|
ival = PyLong_AsSsize_t(iobj);
|
|
|
|
Py_DECREF(iobj);
|
|
|
|
}
|
|
|
|
if (ival == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
offset = ival;
|
|
|
|
}
|
|
|
|
skip_optional_pos:
|
2017-02-02 07:09:30 -04:00
|
|
|
return_value = Struct_unpack_from_impl(self, &buffer, offset);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for buffer */
|
|
|
|
if (buffer.obj) {
|
|
|
|
PyBuffer_Release(&buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(Struct_iter_unpack__doc__,
|
|
|
|
"iter_unpack($self, buffer, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return an iterator yielding tuples.\n"
|
|
|
|
"\n"
|
|
|
|
"Tuples are unpacked from the given bytes source, like a repeated\n"
|
|
|
|
"invocation of unpack_from().\n"
|
|
|
|
"\n"
|
|
|
|
"Requires that the bytes length be a multiple of the struct size.");
|
|
|
|
|
|
|
|
#define STRUCT_ITER_UNPACK_METHODDEF \
|
|
|
|
{"iter_unpack", (PyCFunction)Struct_iter_unpack, METH_O, Struct_iter_unpack__doc__},
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_clearcache__doc__,
|
|
|
|
"_clearcache($module, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Clear the internal cache.");
|
|
|
|
|
|
|
|
#define _CLEARCACHE_METHODDEF \
|
|
|
|
{"_clearcache", (PyCFunction)_clearcache, METH_NOARGS, _clearcache__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_clearcache_impl(PyObject *module);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_clearcache(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return _clearcache_impl(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(calcsize__doc__,
|
|
|
|
"calcsize($module, format, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return size in bytes of the struct described by the format string.");
|
|
|
|
|
|
|
|
#define CALCSIZE_METHODDEF \
|
|
|
|
{"calcsize", (PyCFunction)calcsize, METH_O, calcsize__doc__},
|
|
|
|
|
2017-02-04 05:14:52 -04:00
|
|
|
static Py_ssize_t
|
|
|
|
calcsize_impl(PyObject *module, PyStructObject *s_object);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
calcsize(PyObject *module, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyStructObject *s_object = NULL;
|
|
|
|
Py_ssize_t _return_value;
|
|
|
|
|
2020-11-19 09:36:23 -04:00
|
|
|
if (!cache_struct_converter(module, arg, &s_object)) {
|
2017-02-04 05:14:52 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = calcsize_impl(module, s_object);
|
|
|
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = PyLong_FromSsize_t(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for s_object */
|
|
|
|
Py_XDECREF(s_object);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2017-02-02 07:09:30 -04:00
|
|
|
PyDoc_STRVAR(unpack__doc__,
|
2017-02-02 09:24:16 -04:00
|
|
|
"unpack($module, format, buffer, /)\n"
|
2017-02-02 07:09:30 -04:00
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a tuple containing values unpacked according to the format string.\n"
|
|
|
|
"\n"
|
|
|
|
"The buffer\'s size in bytes must be calcsize(format).\n"
|
|
|
|
"\n"
|
|
|
|
"See help(struct) for more on format strings.");
|
|
|
|
|
|
|
|
#define UNPACK_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"unpack", _PyCFunction_CAST(unpack), METH_FASTCALL, unpack__doc__},
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-02-04 05:14:52 -04:00
|
|
|
unpack_impl(PyObject *module, PyStructObject *s_object, Py_buffer *buffer);
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2017-02-02 07:09:30 -04:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2017-02-04 05:14:52 -04:00
|
|
|
PyStructObject *s_object = NULL;
|
2017-02-02 09:24:16 -04:00
|
|
|
Py_buffer buffer = {NULL, NULL};
|
2017-02-02 07:09:30 -04:00
|
|
|
|
2019-01-11 10:01:14 -04:00
|
|
|
if (!_PyArg_CheckPositional("unpack", nargs, 2, 2)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2020-11-19 09:36:23 -04:00
|
|
|
if (!cache_struct_converter(module, args[0], &s_object)) {
|
2019-01-11 10:01:14 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2017-02-04 05:14:52 -04:00
|
|
|
return_value = unpack_impl(module, s_object, &buffer);
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
exit:
|
2017-02-04 05:14:52 -04:00
|
|
|
/* Cleanup for s_object */
|
|
|
|
Py_XDECREF(s_object);
|
2017-02-02 09:24:16 -04:00
|
|
|
/* Cleanup for buffer */
|
|
|
|
if (buffer.obj) {
|
|
|
|
PyBuffer_Release(&buffer);
|
|
|
|
}
|
|
|
|
|
2017-02-02 07:09:30 -04:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(unpack_from__doc__,
|
|
|
|
"unpack_from($module, format, /, buffer, offset=0)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a tuple containing values unpacked according to the format string.\n"
|
|
|
|
"\n"
|
|
|
|
"The buffer\'s size, minus offset, must be at least calcsize(format).\n"
|
|
|
|
"\n"
|
|
|
|
"See help(struct) for more on format strings.");
|
|
|
|
|
|
|
|
#define UNPACK_FROM_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"unpack_from", _PyCFunction_CAST(unpack_from), METH_FASTCALL|METH_KEYWORDS, unpack_from__doc__},
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-02-04 05:14:52 -04:00
|
|
|
unpack_from_impl(PyObject *module, PyStructObject *s_object,
|
|
|
|
Py_buffer *buffer, Py_ssize_t offset);
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
unpack_from(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
2017-02-02 07:09:30 -04:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 2
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(buffer), &_Py_ID(offset), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2017-02-02 07:09:30 -04:00
|
|
|
static const char * const _keywords[] = {"", "buffer", "offset", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "unpack_from",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2019-03-14 05:32:22 -03:00
|
|
|
PyObject *argsbuf[3];
|
|
|
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
2017-02-04 05:14:52 -04:00
|
|
|
PyStructObject *s_object = NULL;
|
2017-02-02 07:09:30 -04:00
|
|
|
Py_buffer buffer = {NULL, NULL};
|
|
|
|
Py_ssize_t offset = 0;
|
|
|
|
|
2019-03-14 05:32:22 -03:00
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
|
|
|
|
if (!args) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2020-11-19 09:36:23 -04:00
|
|
|
if (!cache_struct_converter(module, args[0], &s_object)) {
|
2019-03-14 05:32:22 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
|
2017-02-02 07:09:30 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-03-14 05:32:22 -03:00
|
|
|
if (!noptargs) {
|
|
|
|
goto skip_optional_pos;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Py_ssize_t ival = -1;
|
2020-05-28 04:33:45 -03:00
|
|
|
PyObject *iobj = _PyNumber_Index(args[2]);
|
2019-03-14 05:32:22 -03:00
|
|
|
if (iobj != NULL) {
|
|
|
|
ival = PyLong_AsSsize_t(iobj);
|
|
|
|
Py_DECREF(iobj);
|
|
|
|
}
|
|
|
|
if (ival == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
offset = ival;
|
|
|
|
}
|
|
|
|
skip_optional_pos:
|
2017-02-04 05:14:52 -04:00
|
|
|
return_value = unpack_from_impl(module, s_object, &buffer, offset);
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
exit:
|
2017-02-04 05:14:52 -04:00
|
|
|
/* Cleanup for s_object */
|
|
|
|
Py_XDECREF(s_object);
|
2017-02-02 07:09:30 -04:00
|
|
|
/* Cleanup for buffer */
|
|
|
|
if (buffer.obj) {
|
|
|
|
PyBuffer_Release(&buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(iter_unpack__doc__,
|
|
|
|
"iter_unpack($module, format, buffer, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return an iterator yielding tuples unpacked from the given bytes.\n"
|
|
|
|
"\n"
|
|
|
|
"The bytes are unpacked according to the format string, like\n"
|
|
|
|
"a repeated invocation of unpack_from().\n"
|
|
|
|
"\n"
|
|
|
|
"Requires that the bytes length be a multiple of the format struct size.");
|
|
|
|
|
|
|
|
#define ITER_UNPACK_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"iter_unpack", _PyCFunction_CAST(iter_unpack), METH_FASTCALL, iter_unpack__doc__},
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-02-04 05:14:52 -04:00
|
|
|
iter_unpack_impl(PyObject *module, PyStructObject *s_object,
|
|
|
|
PyObject *buffer);
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
iter_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2017-02-02 07:09:30 -04:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2017-02-04 05:14:52 -04:00
|
|
|
PyStructObject *s_object = NULL;
|
2017-02-02 07:09:30 -04:00
|
|
|
PyObject *buffer;
|
|
|
|
|
2019-01-11 10:01:14 -04:00
|
|
|
if (!_PyArg_CheckPositional("iter_unpack", nargs, 2, 2)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2020-11-19 09:36:23 -04:00
|
|
|
if (!cache_struct_converter(module, args[0], &s_object)) {
|
2017-02-02 07:09:30 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-11 10:01:14 -04:00
|
|
|
buffer = args[1];
|
2017-02-04 05:14:52 -04:00
|
|
|
return_value = iter_unpack_impl(module, s_object, buffer);
|
2017-02-02 07:09:30 -04:00
|
|
|
|
|
|
|
exit:
|
2017-02-04 05:14:52 -04:00
|
|
|
/* Cleanup for s_object */
|
|
|
|
Py_XDECREF(s_object);
|
|
|
|
|
2017-02-02 07:09:30 -04:00
|
|
|
return return_value;
|
|
|
|
}
|
2023-11-26 10:29:52 -04:00
|
|
|
/*[clinic end generated code: output=67bd299e5d72fee0 input=a9049054013a1b77]*/
|