From c5c0a4d3315d10921f2d4514724da045edbda296 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2011 08:13:27 +0930 Subject: tdb2: fix return handling in pytdb wrapper. 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 --- lib/tdb2/pytdb.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/tdb2/pytdb.c') diff --git a/lib/tdb2/pytdb.c b/lib/tdb2/pytdb.c index c03f00d58c..98ce4232a9 100644 --- a/lib/tdb2/pytdb.c +++ b/lib/tdb2/pytdb.c @@ -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) -- cgit