#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE …
#endif
#include "Python.h"
#include "pycore_bytesobject.h"
#include "pycore_long.h"
#include "pycore_moduleobject.h"
#ifdef Py_HAVE_C_COMPLEX
# include "_complex.h"
#endif
#include <stddef.h>
_structmodulestate;
static inline _structmodulestate*
get_struct_state(PyObject *module)
{ … }
static struct PyModuleDef _structmodule;
#define get_struct_state_structinst(self) …
#define get_struct_state_iterinst(self) …
formatdef;
formatcode;
PyStructObject;
#define PyStruct_Check(op, state) …
st_short;
st_int;
st_long;
st_float;
st_double;
#ifdef Py_HAVE_C_COMPLEX
st_float_complex;
st_double_complex;
#endif
st_void_p;
st_size_t;
st_bool;
#define SHORT_ALIGN …
#define INT_ALIGN …
#define LONG_ALIGN …
#define FLOAT_ALIGN …
#define DOUBLE_ALIGN …
#ifdef Py_HAVE_C_COMPLEX
#define FLOAT_COMPLEX_ALIGN …
#define DOUBLE_COMPLEX_ALIGN …
#endif
#define VOID_P_ALIGN …
#define SIZE_T_ALIGN …
#define BOOL_ALIGN …
s_long_long;
#define LONG_LONG_ALIGN …
#ifdef __powerc
#pragma options align=reset
#endif
static int cache_struct_converter(PyObject *, PyObject *, PyStructObject **);
#include "clinic/_struct.c.h"
static PyObject *
get_pylong(_structmodulestate *state, PyObject *v)
{ … }
static int
get_long(_structmodulestate *state, PyObject *v, long *p)
{ … }
static int
get_ulong(_structmodulestate *state, PyObject *v, unsigned long *p)
{ … }
static int
get_longlong(_structmodulestate *state, PyObject *v, long long *p)
{ … }
static int
get_ulonglong(_structmodulestate *state, PyObject *v, unsigned long long *p)
{ … }
static int
get_ssize_t(_structmodulestate *state, PyObject *v, Py_ssize_t *p)
{ … }
static int
get_size_t(_structmodulestate *state, PyObject *v, size_t *p)
{ … }
#define RANGE_ERROR(state, f, flag) …
static PyObject *
unpack_halffloat(const char *p,
int le)
{ … }
static int
pack_halffloat(_structmodulestate *state,
char *p,
PyObject *v,
int le)
{ … }
static PyObject *
unpack_float(const char *p,
int le)
{ … }
static PyObject *
unpack_double(const char *p,
int le)
{ … }
static int
_range_error(_structmodulestate *state, const formatdef *f, int is_unsigned)
{ … }
static PyObject *
nu_char(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_byte(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_ubyte(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_short(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_ushort(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_int(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_uint(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_long(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_ulong(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_ssize_t(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_size_t(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_bool(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_halffloat(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_float(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_double(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
#ifdef Py_HAVE_C_COMPLEX
static PyObject *
nu_float_complex(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
nu_double_complex(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
#endif
static PyObject *
nu_void_p(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static int
np_byte(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_ubyte(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_char(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_short(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_ushort(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_int(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_uint(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_long(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_ulong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_ssize_t(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_size_t(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_longlong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_ulonglong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_bool(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_halffloat(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_float(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
np_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
#ifdef Py_HAVE_C_COMPLEX
static int
np_float_complex(_structmodulestate *state, char *p, PyObject *v,
const formatdef *f)
{ … }
static int
np_double_complex(_structmodulestate *state, char *p, PyObject *v,
const formatdef *f)
{ … }
#else
static int
np_complex_stub(_structmodulestate *state, char *p, PyObject *v,
const formatdef *f)
{
PyErr_Format(state->StructError,
"'%c' format not supported on this system",
f->format);
return -1;
}
static PyObject *
nu_complex_stub(_structmodulestate *state, const char *p, const formatdef *f)
{
PyErr_Format(state->StructError,
"'%c' format not supported on this system",
f->format);
return NULL;
}
#endif
static int
np_void_p(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static const formatdef native_table[] = …;
static PyObject *
bu_short(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
bu_int(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
bu_uint(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
bu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
bu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
bu_halffloat(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
bu_float(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
bu_double(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
#ifdef Py_HAVE_C_COMPLEX
static PyObject *
bu_float_complex(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
bu_double_complex(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
#endif
static PyObject *
bu_bool(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static int
bp_int(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
bp_uint(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
bp_longlong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
bp_ulonglong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
bp_halffloat(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
bp_float(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
bp_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
#ifdef Py_HAVE_C_COMPLEX
static int
bp_float_complex(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
bp_double_complex(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
#endif
static int
bp_bool(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static formatdef bigendian_table[] = …;
static PyObject *
lu_short(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
lu_int(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
lu_uint(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
lu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
lu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
lu_halffloat(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
lu_float(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
lu_double(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
#ifdef Py_HAVE_C_COMPLEX
static PyObject *
lu_float_complex(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
static PyObject *
lu_double_complex(_structmodulestate *state, const char *p, const formatdef *f)
{ … }
#endif
static int
lp_int(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
lp_uint(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
lp_longlong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
lp_ulonglong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
lp_halffloat(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
lp_float(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
lp_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
#ifdef Py_HAVE_C_COMPLEX
static int
lp_float_complex(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
static int
lp_double_complex(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{ … }
#endif
static formatdef lilendian_table[] = …;
static const formatdef *
whichtable(const char **pfmt)
{ … }
static const formatdef *
getentry(_structmodulestate *state, int c, const formatdef *f)
{ … }
static Py_ssize_t
align(Py_ssize_t size, char c, const formatdef *e)
{ … }
static int
prepare_s(PyStructObject *self)
{ … }
static PyObject *
s_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ … }
static int
Struct___init___impl(PyStructObject *self, PyObject *format)
{ … }
static int
s_clear(PyStructObject *s)
{ … }
static int
s_traverse(PyStructObject *s, visitproc visit, void *arg)
{ … }
static void
s_dealloc(PyStructObject *s)
{ … }
static PyObject *
s_unpack_internal(PyStructObject *soself, const char *startfrom,
_structmodulestate *state) { … }
static PyObject *
Struct_unpack_impl(PyStructObject *self, Py_buffer *buffer)
{ … }
static PyObject *
Struct_unpack_from_impl(PyStructObject *self, Py_buffer *buffer,
Py_ssize_t offset)
{ … }
unpackiterobject;
static void
unpackiter_dealloc(unpackiterobject *self)
{ … }
static int
unpackiter_traverse(unpackiterobject *self, visitproc visit, void *arg)
{ … }
static PyObject *
unpackiter_len(unpackiterobject *self, PyObject *Py_UNUSED(ignored))
{ … }
static PyMethodDef unpackiter_methods[] = …;
static PyObject *
unpackiter_iternext(unpackiterobject *self)
{ … }
static PyType_Slot unpackiter_type_slots[] = …;
static PyType_Spec unpackiter_type_spec = …;
static PyObject *
Struct_iter_unpack(PyStructObject *self, PyObject *buffer)
{ … }
static int
s_pack_internal(PyStructObject *soself, PyObject *const *args, int offset,
char* buf, _structmodulestate *state)
{ … }
PyDoc_STRVAR(s_pack__doc__,
"S.pack(v1, v2, ...) -> bytes\n\
\n\
Return a bytes object containing values v1, v2, ... packed according\n\
to the format string S.format. See help(struct) for more on format\n\
strings.");
static PyObject *
s_pack(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{ … }
PyDoc_STRVAR(s_pack_into__doc__,
"S.pack_into(buffer, offset, v1, v2, ...)\n\
\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.");
static PyObject *
s_pack_into(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{ … }
static PyObject *
s_get_format(PyStructObject *self, void *unused)
{ … }
static PyObject *
s_get_size(PyStructObject *self, void *unused)
{ … }
PyDoc_STRVAR(s_sizeof__doc__,
"S.__sizeof__() -> size of S in memory, in bytes");
static PyObject *
s_sizeof(PyStructObject *self, void *unused)
{ … }
static PyObject *
s_repr(PyStructObject *self)
{ … }
static struct PyMethodDef s_methods[] = …;
static PyMemberDef s_members[] = …;
static PyGetSetDef s_getsetlist[] = …;
PyDoc_STRVAR(s__doc__,
"Struct(fmt) --> compiled struct object\n"
"\n"
);
static PyType_Slot PyStructType_slots[] = …;
static PyType_Spec PyStructType_spec = …;
#define MAXCACHE …
static int
cache_struct_converter(PyObject *module, PyObject *fmt, PyStructObject **ptr)
{ … }
static PyObject *
_clearcache_impl(PyObject *module)
{ … }
static Py_ssize_t
calcsize_impl(PyObject *module, PyStructObject *s_object)
{ … }
PyDoc_STRVAR(pack_doc,
"pack(format, v1, v2, ...) -> bytes\n\
\n\
Return a bytes object containing the values v1, v2, ... packed according\n\
to the format string. See help(struct) for more on format strings.");
static PyObject *
pack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
{ … }
PyDoc_STRVAR(pack_into_doc,
"pack_into(format, buffer, offset, v1, v2, ...)\n\
\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.");
static PyObject *
pack_into(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
{ … }
static PyObject *
unpack_impl(PyObject *module, PyStructObject *s_object, Py_buffer *buffer)
{ … }
static PyObject *
unpack_from_impl(PyObject *module, PyStructObject *s_object,
Py_buffer *buffer, Py_ssize_t offset)
{ … }
static PyObject *
iter_unpack_impl(PyObject *module, PyStructObject *s_object,
PyObject *buffer)
{ … }
static struct PyMethodDef module_functions[] = …;
PyDoc_STRVAR(module_doc,
"Functions to convert between Python values and C structs.\n\
Python bytes objects are used to hold the data representing the C struct\n\
and also as format strings (explained below) to describe the layout of data\n\
in the C struct.\n\
\n\
The optional first format char indicates byte order, size and alignment:\n\
@: native order, size & alignment (default)\n\
=: native order, std. size & alignment\n\
<: little-endian, std. size & alignment\n\
>: big-endian, std. size & alignment\n\
!: same as >\n\
\n\
The remaining chars indicate types of args and must match exactly;\n\
these can be preceded by a decimal repeat count:\n\
x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;\n\
?: _Bool (requires C99; if not available, char is used instead)\n\
h:short; H:unsigned short; i:int; I:unsigned int;\n\
l:long; L:unsigned long; f:float; d:double; e:half-float.\n\
Special cases (preceding decimal count indicates length):\n\
s:string (array of char); p: pascal string (with count byte).\n\
Special cases (only available in native format):\n\
n:ssize_t; N:size_t;\n\
P:an integer type that is wide enough to hold a pointer.\n\
Special case (not in native mode unless 'long long' in platform C):\n\
q:long long; Q:unsigned long long\n\
Whitespace between formats is ignored.\n\
\n\
The variable struct.error is an exception raised on errors.\n");
static int
_structmodule_traverse(PyObject *module, visitproc visit, void *arg)
{ … }
static int
_structmodule_clear(PyObject *module)
{ … }
static void
_structmodule_free(void *module)
{ … }
static int
_structmodule_exec(PyObject *m)
{ … }
static PyModuleDef_Slot _structmodule_slots[] = …;
static struct PyModuleDef _structmodule = …;
PyMODINIT_FUNC
PyInit__struct(void)
{ … }