Files
typthon/Modules/clinic/_struct.c.h
copilot-swe-agent[bot] 71cf7bf14f Fix more missed Py_ patterns - opcode, thread, exception
Fixed additional patterns:
- _PyOpcode_* → _TyOpcode_* (all opcode metadata)
- _PyUOpName → _TyUOpName
- _PyFunction_* → _TyFunction_*
- _PyListIterObject → _TyListIterObject
- _Py_T_OBJECT → _Ty_T_OBJECT
- Py_BEGIN_ALLOW_THREADS, Py_END_ALLOW_THREADS → Ty_*
- PyDoc_STRVAR, PyDoc_STR → TyDoc_*
- PyInterpreterState, PyThread_*, PyTime_t → Ty*
- PyStructSequence_* → TyStructSequence_*
- PyLockStatus → TyLockStatus
- PyVarObject_HEAD_INIT → TyVarObject_HEAD_INIT
- PyBaseExceptionObject → TyBaseExceptionObject
- Fixed _PyExc_ → _TyExc_ in exception macros

Build is progressing further.

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
2025-12-29 18:27:36 +00:00

462 lines
12 KiB
C
Generated

/*[clinic input]
preserve
[clinic start generated code]*/
#if defined(Ty_BUILD_CORE) && !defined(Ty_BUILD_CORE_MODULE)
# include "pycore_gc.h" // TyGC_Head
# include "pycore_runtime.h" // _Ty_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_modsupport.h" // _TyArg_UnpackKeywords()
TyDoc_STRVAR(Struct___init____doc__,
"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.");
static int
Struct___init___impl(PyStructObject *self, TyObject *format);
static int
Struct___init__(TyObject *self, TyObject *args, TyObject *kwargs)
{
int return_value = -1;
#if defined(Ty_BUILD_CORE) && !defined(Ty_BUILD_CORE_MODULE)
#define NUM_KEYWORDS 1
static struct {
TyGC_Head _this_is_not_used;
PyObject_VAR_HEAD
Ty_hash_t ob_hash;
TyObject *ob_item[NUM_KEYWORDS];
} _kwtuple = {
.ob_base = TyVarObject_HEAD_INIT(&TyTuple_Type, NUM_KEYWORDS)
.ob_hash = -1,
.ob_item = { &_Ty_ID(format), },
};
#undef NUM_KEYWORDS
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
#else // !Ty_BUILD_CORE
# define KWTUPLE NULL
#endif // !Ty_BUILD_CORE
static const char * const _keywords[] = {"format", NULL};
static _TyArg_Parser _parser = {
.keywords = _keywords,
.fname = "Struct",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
TyObject *argsbuf[1];
TyObject * const *fastargs;
Ty_ssize_t nargs = TyTuple_GET_SIZE(args);
TyObject *format;
fastargs = _TyArg_UnpackKeywords(_TyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
if (!fastargs) {
goto exit;
}
format = fastargs[0];
return_value = Struct___init___impl((PyStructObject *)self, format);
exit:
return return_value;
}
TyDoc_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 TyObject *
Struct_unpack_impl(PyStructObject *self, Ty_buffer *buffer);
static TyObject *
Struct_unpack(TyObject *self, TyObject *arg)
{
TyObject *return_value = NULL;
Ty_buffer buffer = {NULL, NULL};
if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
goto exit;
}
return_value = Struct_unpack_impl((PyStructObject *)self, &buffer);
exit:
/* Cleanup for buffer */
if (buffer.obj) {
PyBuffer_Release(&buffer);
}
return return_value;
}
TyDoc_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"
"The buffer\'s size in bytes, starting at position offset, must be\n"
"at least Struct.size.\n"
"\n"
"See help(struct) for more on format strings.");
#define STRUCT_UNPACK_FROM_METHODDEF \
{"unpack_from", _PyCFunction_CAST(Struct_unpack_from), METH_FASTCALL|METH_KEYWORDS, Struct_unpack_from__doc__},
static TyObject *
Struct_unpack_from_impl(PyStructObject *self, Ty_buffer *buffer,
Ty_ssize_t offset);
static TyObject *
Struct_unpack_from(TyObject *self, TyObject *const *args, Ty_ssize_t nargs, TyObject *kwnames)
{
TyObject *return_value = NULL;
#if defined(Ty_BUILD_CORE) && !defined(Ty_BUILD_CORE_MODULE)
#define NUM_KEYWORDS 2
static struct {
TyGC_Head _this_is_not_used;
PyObject_VAR_HEAD
Ty_hash_t ob_hash;
TyObject *ob_item[NUM_KEYWORDS];
} _kwtuple = {
.ob_base = TyVarObject_HEAD_INIT(&TyTuple_Type, NUM_KEYWORDS)
.ob_hash = -1,
.ob_item = { &_Ty_ID(buffer), &_Ty_ID(offset), },
};
#undef NUM_KEYWORDS
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
#else // !Ty_BUILD_CORE
# define KWTUPLE NULL
#endif // !Ty_BUILD_CORE
static const char * const _keywords[] = {"buffer", "offset", NULL};
static _TyArg_Parser _parser = {
.keywords = _keywords,
.fname = "unpack_from",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
TyObject *argsbuf[2];
Ty_ssize_t noptargs = nargs + (kwnames ? TyTuple_GET_SIZE(kwnames) : 0) - 1;
Ty_buffer buffer = {NULL, NULL};
Ty_ssize_t offset = 0;
args = _TyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
/*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
if (!args) {
goto exit;
}
if (PyObject_GetBuffer(args[0], &buffer, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!noptargs) {
goto skip_optional_pos;
}
{
Ty_ssize_t ival = -1;
TyObject *iobj = _PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = TyLong_AsSsize_t(iobj);
Ty_DECREF(iobj);
}
if (ival == -1 && TyErr_Occurred()) {
goto exit;
}
offset = ival;
}
skip_optional_pos:
return_value = Struct_unpack_from_impl((PyStructObject *)self, &buffer, offset);
exit:
/* Cleanup for buffer */
if (buffer.obj) {
PyBuffer_Release(&buffer);
}
return return_value;
}
TyDoc_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__},
static TyObject *
Struct_iter_unpack_impl(PyStructObject *self, TyObject *buffer);
static TyObject *
Struct_iter_unpack(TyObject *self, TyObject *buffer)
{
TyObject *return_value = NULL;
return_value = Struct_iter_unpack_impl((PyStructObject *)self, buffer);
return return_value;
}
TyDoc_STRVAR(_clearcache__doc__,
"_clearcache($module, /)\n"
"--\n"
"\n"
"Clear the internal cache.");
#define _CLEARCACHE_METHODDEF \
{"_clearcache", (PyCFunction)_clearcache, METH_NOARGS, _clearcache__doc__},
static TyObject *
_clearcache_impl(TyObject *module);
static TyObject *
_clearcache(TyObject *module, TyObject *Py_UNUSED(ignored))
{
return _clearcache_impl(module);
}
TyDoc_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__},
static Ty_ssize_t
calcsize_impl(TyObject *module, PyStructObject *s_object);
static TyObject *
calcsize(TyObject *module, TyObject *arg)
{
TyObject *return_value = NULL;
PyStructObject *s_object = NULL;
Ty_ssize_t _return_value;
if (!cache_struct_converter(module, arg, &s_object)) {
goto exit;
}
_return_value = calcsize_impl(module, s_object);
if ((_return_value == -1) && TyErr_Occurred()) {
goto exit;
}
return_value = TyLong_FromSsize_t(_return_value);
exit:
/* Cleanup for s_object */
Ty_XDECREF(s_object);
return return_value;
}
TyDoc_STRVAR(unpack__doc__,
"unpack($module, format, buffer, /)\n"
"--\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 \
{"unpack", _PyCFunction_CAST(unpack), METH_FASTCALL, unpack__doc__},
static TyObject *
unpack_impl(TyObject *module, PyStructObject *s_object, Ty_buffer *buffer);
static TyObject *
unpack(TyObject *module, TyObject *const *args, Ty_ssize_t nargs)
{
TyObject *return_value = NULL;
PyStructObject *s_object = NULL;
Ty_buffer buffer = {NULL, NULL};
if (!_TyArg_CheckPositional("unpack", nargs, 2, 2)) {
goto exit;
}
if (!cache_struct_converter(module, args[0], &s_object)) {
goto exit;
}
if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
goto exit;
}
return_value = unpack_impl(module, s_object, &buffer);
exit:
/* Cleanup for s_object */
Ty_XDECREF(s_object);
/* Cleanup for buffer */
if (buffer.obj) {
PyBuffer_Release(&buffer);
}
return return_value;
}
TyDoc_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 \
{"unpack_from", _PyCFunction_CAST(unpack_from), METH_FASTCALL|METH_KEYWORDS, unpack_from__doc__},
static TyObject *
unpack_from_impl(TyObject *module, PyStructObject *s_object,
Ty_buffer *buffer, Ty_ssize_t offset);
static TyObject *
unpack_from(TyObject *module, TyObject *const *args, Ty_ssize_t nargs, TyObject *kwnames)
{
TyObject *return_value = NULL;
#if defined(Ty_BUILD_CORE) && !defined(Ty_BUILD_CORE_MODULE)
#define NUM_KEYWORDS 2
static struct {
TyGC_Head _this_is_not_used;
PyObject_VAR_HEAD
Ty_hash_t ob_hash;
TyObject *ob_item[NUM_KEYWORDS];
} _kwtuple = {
.ob_base = TyVarObject_HEAD_INIT(&TyTuple_Type, NUM_KEYWORDS)
.ob_hash = -1,
.ob_item = { &_Ty_ID(buffer), &_Ty_ID(offset), },
};
#undef NUM_KEYWORDS
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
#else // !Ty_BUILD_CORE
# define KWTUPLE NULL
#endif // !Ty_BUILD_CORE
static const char * const _keywords[] = {"", "buffer", "offset", NULL};
static _TyArg_Parser _parser = {
.keywords = _keywords,
.fname = "unpack_from",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
TyObject *argsbuf[3];
Ty_ssize_t noptargs = nargs + (kwnames ? TyTuple_GET_SIZE(kwnames) : 0) - 2;
PyStructObject *s_object = NULL;
Ty_buffer buffer = {NULL, NULL};
Ty_ssize_t offset = 0;
args = _TyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
/*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
if (!args) {
goto exit;
}
if (!cache_struct_converter(module, args[0], &s_object)) {
goto exit;
}
if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!noptargs) {
goto skip_optional_pos;
}
{
Ty_ssize_t ival = -1;
TyObject *iobj = _PyNumber_Index(args[2]);
if (iobj != NULL) {
ival = TyLong_AsSsize_t(iobj);
Ty_DECREF(iobj);
}
if (ival == -1 && TyErr_Occurred()) {
goto exit;
}
offset = ival;
}
skip_optional_pos:
return_value = unpack_from_impl(module, s_object, &buffer, offset);
exit:
/* Cleanup for s_object */
Ty_XDECREF(s_object);
/* Cleanup for buffer */
if (buffer.obj) {
PyBuffer_Release(&buffer);
}
return return_value;
}
TyDoc_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 \
{"iter_unpack", _PyCFunction_CAST(iter_unpack), METH_FASTCALL, iter_unpack__doc__},
static TyObject *
iter_unpack_impl(TyObject *module, PyStructObject *s_object,
TyObject *buffer);
static TyObject *
iter_unpack(TyObject *module, TyObject *const *args, Ty_ssize_t nargs)
{
TyObject *return_value = NULL;
PyStructObject *s_object = NULL;
TyObject *buffer;
if (!_TyArg_CheckPositional("iter_unpack", nargs, 2, 2)) {
goto exit;
}
if (!cache_struct_converter(module, args[0], &s_object)) {
goto exit;
}
buffer = args[1];
return_value = iter_unpack_impl(module, s_object, buffer);
exit:
/* Cleanup for s_object */
Ty_XDECREF(s_object);
return return_value;
}
/*[clinic end generated code: output=caa7f36443e91cb9 input=a9049054013a1b77]*/