]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- made the C version of RowProxy accept any sequence for the row, instead of
authorGaëtan de Menten <gdementen@gmail.com>
Fri, 2 Apr 2010 18:29:37 +0000 (20:29 +0200)
committerGaëtan de Menten <gdementen@gmail.com>
Fri, 2 Apr 2010 18:29:37 +0000 (20:29 +0200)
  only tuples

lib/sqlalchemy/cextension/resultproxy.c

index b530b65f7eac3a2c3022d432c360b01ccb550dd6..45149bebd5a477390ad44b2f81ef226da3f179a4 100644 (file)
@@ -69,8 +69,8 @@ BaseRowProxy_init(BaseRowProxy *self, PyObject *args, PyObject *kwds)
     Py_INCREF(parent);
     self->parent = parent;
 
-    if (!PyTuple_CheckExact(row)) {
-        PyErr_SetString(PyExc_TypeError, "row must be a tuple");
+    if (!PySequence_Check(row)) {
+        PyErr_SetString(PyExc_TypeError, "row must be a sequence");
         return -1;
     }
     Py_INCREF(row);
@@ -148,13 +148,15 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple)
 {
     Py_ssize_t num_values, num_processors;
     PyObject **valueptr, **funcptr, **resultptr;
-    PyObject *func, *result, *processed_value;
+    PyObject *func, *result, *processed_value, *values_fastseq;
 
     num_values = Py_SIZE(values);
     num_processors = Py_SIZE(processors);
     if (num_values != num_processors) {
-        PyErr_SetString(PyExc_RuntimeError,
-            "number of values in row differ from number of column processors");
+        PyErr_Format(PyExc_RuntimeError,
+            "number of values in row (%d) differ from number of column "
+            "processors (%d)",
+            num_values, num_processors);
         return NULL;
     }
 
@@ -166,9 +168,11 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple)
     if (result == NULL)
         return NULL;
 
-    /* we don't need to use PySequence_Fast as long as values, processors and
-     * result are simple tuple or lists. */
-    valueptr = PySequence_Fast_ITEMS(values);
+    values_fastseq = PySequence_Fast(values, "row must be a sequence");
+    if (values_fastseq == NULL)
+        return NULL;
+
+    valueptr = PySequence_Fast_ITEMS(values_fastseq);
     funcptr = PySequence_Fast_ITEMS(processors);
     resultptr = PySequence_Fast_ITEMS(result);
     while (--num_values >= 0) {
@@ -177,6 +181,7 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple)
             processed_value = PyObject_CallFunctionObjArgs(func, *valueptr,
                                                            NULL);
             if (processed_value == NULL) {
+                Py_DECREF(values_fastseq);
                 Py_DECREF(result);
                 return NULL;
             }
@@ -189,6 +194,7 @@ BaseRowProxy_processvalues(PyObject *values, PyObject *processors, int astuple)
         funcptr++;
         resultptr++;
     }
+    Py_DECREF(values_fastseq);
     return result;
 }
 
@@ -199,19 +205,12 @@ BaseRowProxy_values(BaseRowProxy *self)
                                                       self->processors, 0);
 }
 
-static PyTupleObject *
-BaseRowProxy_tuplevalues(BaseRowProxy *self)
-{
-    return (PyTupleObject *)BaseRowProxy_processvalues(self->row,
-                                                       self->processors, 1);
-}
-
 static PyObject *
 BaseRowProxy_iter(BaseRowProxy *self)
 {
     PyObject *values, *result;
 
-    values = (PyObject *)BaseRowProxy_tuplevalues(self);
+    values = BaseRowProxy_processvalues(self->row, self->processors, 1);
     if (values == NULL)
         return NULL;
 
@@ -395,7 +394,7 @@ BaseRowProxy_setrow(BaseRowProxy *self, PyObject *value, void *closure)
 
     if (!PyTuple_CheckExact(value)) {
         PyErr_SetString(PyExc_TypeError,
-                        "The 'row' attribute value must be a tuple");
+                        "The 'row' attribute value must be a sequence");
         return -1;
     }