tdb2: fix return handling in pytdb wrapper.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 13 Sep 2011 22:43:27 +0000 (08:13 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 13 Sep 2011 22:43:27 +0000 (08:13 +0930)
tdb_close() does genuinely return non-zero, not an error code, even in tdb2.
And tdb_exists() returns true or false, not an error code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lib/tdb2/pytdb.c

index c03f00d58cbc97f67513b19c59e38bd78cf4f5b5..98ce4232a9995f16f1a3c60a9d449db3b97b43b2 100644 (file)
@@ -173,12 +173,15 @@ static PyObject *obj_unlockall_read(PyTdbObject *self)
 
 static PyObject *obj_close(PyTdbObject *self)
 {
-       enum TDB_ERROR ret;
+       int ret;
        if (self->closed)
                Py_RETURN_NONE;
        ret = tdb_close(self->ctx);
        self->closed = true;
-       PyErr_TDB_ERROR_IS_ERR_RAISE(ret);
+       if (ret != 0) {
+               PyErr_SetTDBError(TDB_ERR_IO);
+               return NULL;
+       }
        Py_RETURN_NONE;
 }
 
@@ -265,17 +268,16 @@ static PyObject *obj_delete(PyTdbObject *self, PyObject *args)
 static PyObject *obj_has_key(PyTdbObject *self, PyObject *args)
 {
        TDB_DATA key;
-       enum TDB_ERROR ret;
        PyObject *py_key;
        if (!PyArg_ParseTuple(args, "O", &py_key))
                return NULL;
 
        key = PyString_AsTDB_DATA(py_key);
-       ret = tdb_exists(self->ctx, key);
-       if (ret == TDB_ERR_NOEXIST)
-               return Py_False;
-       PyErr_TDB_ERROR_IS_ERR_RAISE(ret);
-       return Py_True;
+       if (tdb_exists(self->ctx, key))
+               return Py_True;
+       if (tdb_error(self->ctx) != TDB_ERR_NOEXIST)
+               PyErr_TDB_ERROR_IS_ERR_RAISE(tdb_error(self->ctx));
+       return Py_False;
 }
 
 static PyObject *obj_store(PyTdbObject *self, PyObject *args)