Debian Codegraph @

Modules/_ctypes/clinic/callproc.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #include "pycore_abstract.h" // _PyNumber_Index()
6 #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
7 #include "pycore_modsupport.h" // _PyArg_CheckPositional()
8
9 PyDoc_STRVAR(_ctypes_sizeof__doc__,
10 "sizeof($module, obj, /)\n"
11 "--\n"
12 "\n"
13 "Return the size in bytes of a C instance.");
14
15 #define _CTYPES_SIZEOF_METHODDEF \
16 {"sizeof", (PyCFunction)_ctypes_sizeof, METH_O, _ctypes_sizeof__doc__},
17
18 PyDoc_STRVAR(_ctypes_byref__doc__,
19 "byref($module, obj, offset=0, /)\n"
20 "--\n"
21 "\n"
22 "Return a pointer lookalike to a C instance, only usable as function argument.");
23
24 #define _CTYPES_BYREF_METHODDEF \
25 {"byref", _PyCFunction_CAST(_ctypes_byref), METH_FASTCALL, _ctypes_byref__doc__},
26
27 static PyObject *
28 _ctypes_byref_impl(PyObject *module, PyObject *obj, Py_ssize_t offset);
29
30 static PyObject *
31 _ctypes_byref(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
32 {
33 PyObject *return_value = NULL;
34 PyObject *obj;
35 Py_ssize_t offset = 0;
36
37 if (!_PyArg_CheckPositional("byref", nargs, 1, 2)) {
38 goto exit;
39 }
40 if (!PyObject_TypeCheck(args[0], clinic_state()->PyCData_Type)) {
41 _PyArg_BadArgument("byref", "argument 1", (clinic_state()->PyCData_Type)->tp_name, args[0]);
42 goto exit;
43 }
44 obj = args[0];
45 if (nargs < 2) {
46 goto skip_optional;
47 }
48 {
49 Py_ssize_t ival = -1;
50 PyObject *iobj = _PyNumber_Index(args[1]);
51 if (iobj != NULL) {
52 ival = PyLong_AsSsize_t(iobj);
53 Py_DECREF(iobj);
54 }
55 if (ival == -1 && PyErr_Occurred()) {
56 goto exit;
57 }
58 offset = ival;
59 }
60 skip_optional:
61 Py_BEGIN_CRITICAL_SECTION(obj);
62 return_value = _ctypes_byref_impl(module, obj, offset);
63 Py_END_CRITICAL_SECTION();
64
65 exit:
66 return return_value;
67 }
68
69 PyDoc_STRVAR(_ctypes_addressof__doc__,
70 "addressof($module, obj, /)\n"
71 "--\n"
72 "\n"
73 "Return the address of the C instance internal buffer");
74
75 #define _CTYPES_ADDRESSOF_METHODDEF \
76 {"addressof", (PyCFunction)_ctypes_addressof, METH_O, _ctypes_addressof__doc__},
77
78 static PyObject *
79 _ctypes_addressof_impl(PyObject *module, PyObject *obj);
80
81 static PyObject *
82 _ctypes_addressof(PyObject *module, PyObject *arg)
83 {
84 PyObject *return_value = NULL;
85 PyObject *obj;
86
87 if (!PyObject_TypeCheck(arg, clinic_state()->PyCData_Type)) {
88 _PyArg_BadArgument("addressof", "argument", (clinic_state()->PyCData_Type)->tp_name, arg);
89 goto exit;
90 }
91 obj = arg;
92 Py_BEGIN_CRITICAL_SECTION(obj);
93 return_value = _ctypes_addressof_impl(module, obj);
94 Py_END_CRITICAL_SECTION();
95
96 exit:
97 return return_value;
98 }
99
100 PyDoc_STRVAR(_ctypes_resize__doc__,
101 "resize($module, obj, size, /)\n"
102 "--\n"
103 "\n");
104
105 #define _CTYPES_RESIZE_METHODDEF \
106 {"resize", _PyCFunction_CAST(_ctypes_resize), METH_FASTCALL, _ctypes_resize__doc__},
107
108 static PyObject *
109 _ctypes_resize_impl(PyObject *module, CDataObject *obj, Py_ssize_t size);
110
111 static PyObject *
112 _ctypes_resize(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
113 {
114 PyObject *return_value = NULL;
115 CDataObject *obj;
116 Py_ssize_t size;
117
118 if (!_PyArg_CheckPositional("resize", nargs, 2, 2)) {
119 goto exit;
120 }
121 if (!PyObject_TypeCheck(args[0], clinic_state()->PyCData_Type)) {
122 _PyArg_BadArgument("resize", "argument 1", (clinic_state()->PyCData_Type)->tp_name, args[0]);
123 goto exit;
124 }
125 obj = (CDataObject *)args[0];
126 {
127 Py_ssize_t ival = -1;
128 PyObject *iobj = _PyNumber_Index(args[1]);
129 if (iobj != NULL) {
130 ival = PyLong_AsSsize_t(iobj);
131 Py_DECREF(iobj);
132 }
133 if (ival == -1 && PyErr_Occurred()) {
134 goto exit;
135 }
136 size = ival;
137 }
138 Py_BEGIN_CRITICAL_SECTION(obj);
139 return_value = _ctypes_resize_impl(module, obj, size);
140 Py_END_CRITICAL_SECTION();
141
142 exit:
143 return return_value;
144 }
145 /*[clinic end generated code: output=23c74aced603977d input=a9049054013a1b77]*/