Skip to content

Commit 6e1a726

Browse files
author
Erlend E. Aasland
committed
Convert Row
1 parent 2557de5 commit 6e1a726

File tree

2 files changed

+86
-21
lines changed

2 files changed

+86
-21
lines changed

Modules/_sqlite/clinic/row.c.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*[clinic input]
2+
preserve
3+
[clinic start generated code]*/
4+
5+
static PyObject *
6+
pysqlite_row_new_impl(PyTypeObject *type, pysqlite_Cursor *cursor,
7+
PyObject *data);
8+
9+
static PyObject *
10+
pysqlite_row_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
11+
{
12+
PyObject *return_value = NULL;
13+
pysqlite_Cursor *cursor;
14+
PyObject *data;
15+
16+
if ((type == &pysqlite_RowType) &&
17+
!_PyArg_NoKeywords("Row", kwargs)) {
18+
goto exit;
19+
}
20+
if (!_PyArg_CheckPositional("Row", PyTuple_GET_SIZE(args), 2, 2)) {
21+
goto exit;
22+
}
23+
if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), &pysqlite_CursorType)) {
24+
_PyArg_BadArgument("Row", "argument 1", (&pysqlite_CursorType)->tp_name, PyTuple_GET_ITEM(args, 0));
25+
goto exit;
26+
}
27+
cursor = (pysqlite_Cursor *)PyTuple_GET_ITEM(args, 0);
28+
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 1))) {
29+
_PyArg_BadArgument("Row", "argument 2", "tuple", PyTuple_GET_ITEM(args, 1));
30+
goto exit;
31+
}
32+
data = PyTuple_GET_ITEM(args, 1);
33+
return_value = pysqlite_row_new_impl(type, cursor, data);
34+
35+
exit:
36+
return return_value;
37+
}
38+
39+
PyDoc_STRVAR(pysqlite_row_keys__doc__,
40+
"keys($self, /)\n"
41+
"--\n"
42+
"\n"
43+
"Returns the keys of the row.");
44+
45+
#define PYSQLITE_ROW_KEYS_METHODDEF \
46+
{"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS, pysqlite_row_keys__doc__},
47+
48+
static PyObject *
49+
pysqlite_row_keys_impl(pysqlite_Row *self);
50+
51+
static PyObject *
52+
pysqlite_row_keys(pysqlite_Row *self, PyObject *Py_UNUSED(ignored))
53+
{
54+
return pysqlite_row_keys_impl(self);
55+
}
56+
/*[clinic end generated code: output=64c70362f4bfe669 input=a9049054013a1b77]*/

Modules/_sqlite/row.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323

2424
#include "row.h"
2525
#include "cursor.h"
26+
#include "clinic/row.c.h"
27+
28+
/*[clinic input]
29+
module _sqlite3
30+
class _sqlite3.Row "pysqlite_Row *" "&pysqlite_RowType"
31+
[clinic start generated code]*/
32+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5fe72209a8a6e40c]*/
2633

2734
void pysqlite_row_dealloc(pysqlite_Row* self)
2835
{
@@ -32,30 +39,25 @@ void pysqlite_row_dealloc(pysqlite_Row* self)
3239
Py_TYPE(self)->tp_free((PyObject*)self);
3340
}
3441

42+
/*[clinic input]
43+
@classmethod
44+
_sqlite3.Row.__new__ as pysqlite_row_new
45+
46+
cursor: object(type='pysqlite_Cursor *', subclass_of='&pysqlite_CursorType')
47+
data: object(subclass_of='&PyTuple_Type')
48+
/
49+
50+
[clinic start generated code]*/
51+
3552
static PyObject *
36-
pysqlite_row_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
53+
pysqlite_row_new_impl(PyTypeObject *type, pysqlite_Cursor *cursor,
54+
PyObject *data)
55+
/*[clinic end generated code: output=10d58b09a819a4c1 input=3bb62e4657f18d81]*/
3756
{
3857
pysqlite_Row *self;
39-
PyObject* data;
40-
pysqlite_Cursor* cursor;
4158

4259
assert(type != NULL && type->tp_alloc != NULL);
4360

44-
if (!_PyArg_NoKeywords("Row", kwargs))
45-
return NULL;
46-
if (!PyArg_ParseTuple(args, "OO", &cursor, &data))
47-
return NULL;
48-
49-
if (!PyObject_TypeCheck((PyObject*)cursor, &pysqlite_CursorType)) {
50-
PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument");
51-
return NULL;
52-
}
53-
54-
if (!PyTuple_Check(data)) {
55-
PyErr_SetString(PyExc_TypeError, "tuple required for second argument");
56-
return NULL;
57-
}
58-
5961
self = (pysqlite_Row *) type->tp_alloc(type, 0);
6062
if (self == NULL)
6163
return NULL;
@@ -156,7 +158,15 @@ pysqlite_row_length(pysqlite_Row* self)
156158
return PyTuple_GET_SIZE(self->data);
157159
}
158160

159-
PyObject* pysqlite_row_keys(pysqlite_Row* self, PyObject *Py_UNUSED(ignored))
161+
/*[clinic input]
162+
_sqlite3.Row.keys as pysqlite_row_keys
163+
164+
Returns the keys of the row.
165+
[clinic start generated code]*/
166+
167+
static PyObject *
168+
pysqlite_row_keys_impl(pysqlite_Row *self)
169+
/*[clinic end generated code: output=efe3dfb3af6edc07 input=7549a122827c5563]*/
160170
{
161171
PyObject* list;
162172
Py_ssize_t nitems, i;
@@ -221,8 +231,7 @@ static PySequenceMethods pysqlite_row_as_sequence = {
221231

222232

223233
static PyMethodDef pysqlite_row_methods[] = {
224-
{"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS,
225-
PyDoc_STR("Returns the keys of the row.")},
234+
PYSQLITE_ROW_KEYS_METHODDEF
226235
{NULL, NULL}
227236
};
228237

0 commit comments

Comments
 (0)