Debian Codegraph @

Modules/_sqlite/clinic/module.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_modsupport.h" // _PyArg_UnpackKeywords()
10
11 PyDoc_STRVAR(pysqlite_complete_statement__doc__,
12 "complete_statement($module, /, statement)\n"
13 "--\n"
14 "\n"
15 "Checks if a string contains a complete SQL statement.");
16
17 #define PYSQLITE_COMPLETE_STATEMENT_METHODDEF \
18 {"complete_statement", _PyCFunction_CAST(pysqlite_complete_statement), METH_FASTCALL|METH_KEYWORDS, pysqlite_complete_statement__doc__},
19
20 static PyObject *
21 pysqlite_complete_statement_impl(PyObject *module, const char *statement);
22
23 static PyObject *
24 pysqlite_complete_statement(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
25 {
26 PyObject *return_value = NULL;
27 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
28
29 #define NUM_KEYWORDS 1
30 static struct {
31 PyGC_Head _this_is_not_used;
32 PyObject_VAR_HEAD
33 Py_hash_t ob_hash;
34 PyObject *ob_item[NUM_KEYWORDS];
35 } _kwtuple = {
36 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
37 .ob_hash = -1,
38 .ob_item = { &_Py_ID(statement), },
39 };
40 #undef NUM_KEYWORDS
41 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
42
43 #else // !Py_BUILD_CORE
44 # define KWTUPLE NULL
45 #endif // !Py_BUILD_CORE
46
47 static const char * const _keywords[] = {"statement", NULL};
48 static _PyArg_Parser _parser = {
49 .keywords = _keywords,
50 .fname = "complete_statement",
51 .kwtuple = KWTUPLE,
52 };
53 #undef KWTUPLE
54 PyObject *argsbuf[1];
55 const char *statement;
56
57 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
58 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
59 if (!args) {
60 goto exit;
61 }
62 if (!PyUnicode_Check(args[0])) {
63 _PyArg_BadArgument("complete_statement", "argument 'statement'", "str", args[0]);
64 goto exit;
65 }
66 Py_ssize_t statement_length;
67 statement = PyUnicode_AsUTF8AndSize(args[0], &statement_length);
68 if (statement == NULL) {
69 goto exit;
70 }
71 if (strlen(statement) != (size_t)statement_length) {
72 PyErr_SetString(PyExc_ValueError, "embedded null character");
73 goto exit;
74 }
75 return_value = pysqlite_complete_statement_impl(module, statement);
76
77 exit:
78 return return_value;
79 }
80
81 PyDoc_STRVAR(pysqlite_register_adapter__doc__,
82 "register_adapter($module, type, adapter, /)\n"
83 "--\n"
84 "\n"
85 "Register a function to adapt Python objects to SQLite values.");
86
87 #define PYSQLITE_REGISTER_ADAPTER_METHODDEF \
88 {"register_adapter", _PyCFunction_CAST(pysqlite_register_adapter), METH_FASTCALL, pysqlite_register_adapter__doc__},
89
90 static PyObject *
91 pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type,
92 PyObject *caster);
93
94 static PyObject *
95 pysqlite_register_adapter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
96 {
97 PyObject *return_value = NULL;
98 PyTypeObject *type;
99 PyObject *caster;
100
101 if (!_PyArg_CheckPositional("register_adapter", nargs, 2, 2)) {
102 goto exit;
103 }
104 type = (PyTypeObject *)args[0];
105 caster = args[1];
106 return_value = pysqlite_register_adapter_impl(module, type, caster);
107
108 exit:
109 return return_value;
110 }
111
112 PyDoc_STRVAR(pysqlite_register_converter__doc__,
113 "register_converter($module, typename, converter, /)\n"
114 "--\n"
115 "\n"
116 "Register a function to convert SQLite values to Python objects.");
117
118 #define PYSQLITE_REGISTER_CONVERTER_METHODDEF \
119 {"register_converter", _PyCFunction_CAST(pysqlite_register_converter), METH_FASTCALL, pysqlite_register_converter__doc__},
120
121 static PyObject *
122 pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
123 PyObject *callable);
124
125 static PyObject *
126 pysqlite_register_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
127 {
128 PyObject *return_value = NULL;
129 PyObject *orig_name;
130 PyObject *callable;
131
132 if (!_PyArg_CheckPositional("register_converter", nargs, 2, 2)) {
133 goto exit;
134 }
135 if (!PyUnicode_Check(args[0])) {
136 _PyArg_BadArgument("register_converter", "argument 1", "str", args[0]);
137 goto exit;
138 }
139 orig_name = args[0];
140 callable = args[1];
141 return_value = pysqlite_register_converter_impl(module, orig_name, callable);
142
143 exit:
144 return return_value;
145 }
146
147 PyDoc_STRVAR(pysqlite_enable_callback_trace__doc__,
148 "enable_callback_tracebacks($module, enable, /)\n"
149 "--\n"
150 "\n"
151 "Enable or disable callback functions throwing errors to stderr.");
152
153 #define PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF \
154 {"enable_callback_tracebacks", (PyCFunction)pysqlite_enable_callback_trace, METH_O, pysqlite_enable_callback_trace__doc__},
155
156 static PyObject *
157 pysqlite_enable_callback_trace_impl(PyObject *module, int enable);
158
159 static PyObject *
160 pysqlite_enable_callback_trace(PyObject *module, PyObject *arg)
161 {
162 PyObject *return_value = NULL;
163 int enable;
164
165 enable = PyLong_AsInt(arg);
166 if (enable == -1 && PyErr_Occurred()) {
167 goto exit;
168 }
169 return_value = pysqlite_enable_callback_trace_impl(module, enable);
170
171 exit:
172 return return_value;
173 }
174
175 PyDoc_STRVAR(pysqlite_adapt__doc__,
176 "adapt($module, obj, proto=PrepareProtocolType, alt=<unrepresentable>, /)\n"
177 "--\n"
178 "\n"
179 "Adapt given object to given protocol.");
180
181 #define PYSQLITE_ADAPT_METHODDEF \
182 {"adapt", _PyCFunction_CAST(pysqlite_adapt), METH_FASTCALL, pysqlite_adapt__doc__},
183
184 static PyObject *
185 pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
186 PyObject *alt);
187
188 static PyObject *
189 pysqlite_adapt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
190 {
191 PyObject *return_value = NULL;
192 PyObject *obj;
193 PyObject *proto = (PyObject *)clinic_state()->PrepareProtocolType;
194 PyObject *alt = NULL;
195
196 if (!_PyArg_CheckPositional("adapt", nargs, 1, 3)) {
197 goto exit;
198 }
199 obj = args[0];
200 if (nargs < 2) {
201 goto skip_optional;
202 }
203 proto = args[1];
204 if (nargs < 3) {
205 goto skip_optional;
206 }
207 alt = args[2];
208 skip_optional:
209 return_value = pysqlite_adapt_impl(module, obj, proto, alt);
210
211 exit:
212 return return_value;
213 }
214 /*[clinic end generated code: output=17c4e031680a5168 input=a9049054013a1b77]*/