Debian Codegraph @

Modules/_ctypes/clinic/cfield.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_abstract.h" // _PyNumber_Index()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 static PyObject *
13 PyCField_new_impl(PyTypeObject *type, PyObject *name, PyObject *proto,
14 Py_ssize_t byte_size, Py_ssize_t byte_offset,
15 Py_ssize_t index, int _internal_use,
16 PyObject *bit_size_obj, PyObject *bit_offset_obj);
17
18 static PyObject *
19 PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
20 {
21 PyObject *return_value = NULL;
22 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
23
24 #define NUM_KEYWORDS 8
25 static struct {
26 PyGC_Head _this_is_not_used;
27 PyObject_VAR_HEAD
28 Py_hash_t ob_hash;
29 PyObject *ob_item[NUM_KEYWORDS];
30 } _kwtuple = {
31 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
32 .ob_hash = -1,
33 .ob_item = { &_Py_ID(name), &_Py_ID(type), &_Py_ID(byte_size), &_Py_ID(byte_offset), &_Py_ID(index), &_Py_ID(_internal_use), &_Py_ID(bit_size), &_Py_ID(bit_offset), },
34 };
35 #undef NUM_KEYWORDS
36 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
37
38 #else // !Py_BUILD_CORE
39 # define KWTUPLE NULL
40 #endif // !Py_BUILD_CORE
41
42 static const char * const _keywords[] = {"name", "type", "byte_size", "byte_offset", "index", "_internal_use", "bit_size", "bit_offset", NULL};
43 static _PyArg_Parser _parser = {
44 .keywords = _keywords,
45 .fname = "CField",
46 .kwtuple = KWTUPLE,
47 };
48 #undef KWTUPLE
49 PyObject *argsbuf[8];
50 PyObject * const *fastargs;
51 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
52 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 6;
53 PyObject *name;
54 PyObject *proto;
55 Py_ssize_t byte_size;
56 Py_ssize_t byte_offset;
57 Py_ssize_t index;
58 int _internal_use;
59 PyObject *bit_size_obj = Py_None;
60 PyObject *bit_offset_obj = Py_None;
61
62 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
63 /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 6, /*varpos*/ 0, argsbuf);
64 if (!fastargs) {
65 goto exit;
66 }
67 if (!PyUnicode_Check(fastargs[0])) {
68 _PyArg_BadArgument("CField", "argument 'name'", "str", fastargs[0]);
69 goto exit;
70 }
71 name = fastargs[0];
72 proto = fastargs[1];
73 {
74 Py_ssize_t ival = -1;
75 PyObject *iobj = _PyNumber_Index(fastargs[2]);
76 if (iobj != NULL) {
77 ival = PyLong_AsSsize_t(iobj);
78 Py_DECREF(iobj);
79 }
80 if (ival == -1 && PyErr_Occurred()) {
81 goto exit;
82 }
83 byte_size = ival;
84 }
85 {
86 Py_ssize_t ival = -1;
87 PyObject *iobj = _PyNumber_Index(fastargs[3]);
88 if (iobj != NULL) {
89 ival = PyLong_AsSsize_t(iobj);
90 Py_DECREF(iobj);
91 }
92 if (ival == -1 && PyErr_Occurred()) {
93 goto exit;
94 }
95 byte_offset = ival;
96 }
97 {
98 Py_ssize_t ival = -1;
99 PyObject *iobj = _PyNumber_Index(fastargs[4]);
100 if (iobj != NULL) {
101 ival = PyLong_AsSsize_t(iobj);
102 Py_DECREF(iobj);
103 }
104 if (ival == -1 && PyErr_Occurred()) {
105 goto exit;
106 }
107 index = ival;
108 }
109 _internal_use = PyObject_IsTrue(fastargs[5]);
110 if (_internal_use < 0) {
111 goto exit;
112 }
113 if (!noptargs) {
114 goto skip_optional_kwonly;
115 }
116 if (fastargs[6]) {
117 bit_size_obj = fastargs[6];
118 if (!--noptargs) {
119 goto skip_optional_kwonly;
120 }
121 }
122 bit_offset_obj = fastargs[7];
123 skip_optional_kwonly:
124 return_value = PyCField_new_impl(type, name, proto, byte_size, byte_offset, index, _internal_use, bit_size_obj, bit_offset_obj);
125
126 exit:
127 return return_value;
128 }
129 /*[clinic end generated code: output=7eb1621e22ea2e05 input=a9049054013a1b77]*/