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

Unified Diff: Modules/_sqlite/row.c

Issue 13583: sqlite3.Row doesn't support slice indexes
Patch Set: Created 5 years, 10 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 Sat Apr 26 19:01:47 2014 -0400
+++ b/Modules/_sqlite/row.c Sun Apr 27 22:47:32 2014 -0700
@@ -125,8 +125,34 @@
return NULL;
}
else if (PySlice_Check(idx)) {
- PyErr_SetString(PyExc_ValueError, "slices not implemented, yet");
- return NULL;
+ Py_ssize_t start, stop, step, slicelength, cur, i;
+ PyObject* result;
+ PyObject* it;
+ PyObject **src, **dest;
+ if (PySlice_GetIndicesEx((PyObject *)idx,
+ PyTuple_GET_SIZE(self->data),
+ &start, &stop, &step, &slicelength) < 0) {
+ return NULL;
+ }
+
+ if (step == 1) {
+ return PyTuple_GetSlice(self->data, start, stop);
+ }
+ else {
+ result = PyTuple_New(slicelength);
+ if (!result) return NULL;
+
+ src = ((PyTupleObject *)self->data)->ob_item;
+ dest = ((PyTupleObject *)result)->ob_item;
+ for (cur = start, i = 0; i < slicelength;
+ cur += step, i++) {
+ it = src[cur];
AntoinePitrou 2014/04/28 13:26:54 Why not simply use PyTuple_SET_ITEM and PyTuple_GE
+ Py_INCREF(it);
+ dest[i] = it;
+ }
+
+ return result;
+ }
}
else {
PyErr_SetString(PyExc_IndexError, "Index must be int or string");
« 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+