Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(34318)

Unified Diff: Modules/_sqlite/row.c

Issue 10203: sqlite3.Row doesn't support sequence protocol
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/sqlite3/test/factory.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/_sqlite/row.c Wed May 21 17:12:21 2014 +0300
+++ b/Modules/_sqlite/row.c Tue May 27 10:47:37 2014 +0300
@@ -63,9 +63,17 @@
return 0;
}
+PyObject* pysqlite_row_item(pysqlite_Row* self, Py_ssize_t idx)
+{
+ PyObject* item = PyTuple_GetItem(self->data, idx);
+ Py_XINCREF(item);
+ return item;
+}
+
PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
{
long _idx;
+ int long_overflow;
char* key;
Py_ssize_t nitems, i;
char* compare_key;
@@ -75,8 +83,16 @@
PyObject* item;
- if (PyLong_Check(idx)) {
- _idx = PyLong_AsLong(idx);
+ if (PyLong_Check(idx)) {
+ _idx = PyLong_AsLongAndOverflow(idx, &long_overflow);
+ if (long_overflow) {
+ PyErr_Format(PyExc_IndexError,
+ "cannot fit '%.200s' into an index-sized integer",
+ idx->ob_type->tp_name);
+ return NULL;
+ }
+ if (_idx < 0)
+ _idx += PyTuple_GET_SIZE(self->data);
item = PyTuple_GetItem(self->data, _idx);
Py_XINCREF(item);
return item;
@@ -198,6 +214,14 @@
/* mp_ass_subscript */ (objobjargproc)0,
};
+static PySequenceMethods pysqlite_row_as_sequence = {
+ /* sq_length */ (lenfunc)pysqlite_row_length,
+ /* sq_concat */ 0,
+ /* sq_repeat */ 0,
+ /* sq_item */ (ssizeargfunc)pysqlite_row_item,
+};
+
+
static PyMethodDef pysqlite_row_methods[] = {
{"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS,
PyDoc_STR("Returns the keys of the row.")},
@@ -251,5 +275,6 @@
{
pysqlite_RowType.tp_new = PyType_GenericNew;
pysqlite_RowType.tp_as_mapping = &pysqlite_row_as_mapping;
+ pysqlite_RowType.tp_as_sequence = &pysqlite_row_as_sequence;
return PyType_Ready(&pysqlite_RowType);
}
« no previous file with comments | « Lib/sqlite3/test/factory.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+