git » libjio » commit 9b6ee79

In Python bindings, check return values and raise exceptions accordingly

author Alberto Bertogli
2009-02-25 07:48:31 UTC
committer Alberto Bertogli
2009-02-25 07:50:27 UTC
parent 95a4c5d5372cd43244c132c80cbef8c4e5956045

In Python bindings, check return values and raise exceptions accordingly

UPGRADING +3 -2
bindings/python/libjio.c +14 -0

diff --git a/UPGRADING b/UPGRADING
index 452594b..cbc02d3 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -13,8 +13,9 @@ If you want to see what motivated the changes, see the changelog or just ask.
 
 0.22 -> 0.23
 * The return values of jfsck() have changed, so applications using it need to
-	be recompiled. The Python version now raises IOError on failures, and
-	no longer returns None.
+	be recompiled.
+* Python bindings' jfsck(), jfsck_cleanup(), jsync(), jwrite() and jpwrite()
+	now raise an IOError on failures.
 
 0.21 -> 0.22
 * Applications need to be recompiled due to a change in the jfs structure.
diff --git a/bindings/python/libjio.c b/bindings/python/libjio.c
index fcd61a3..8ea6093 100644
--- a/bindings/python/libjio.c
+++ b/bindings/python/libjio.c
@@ -175,6 +175,9 @@ static PyObject *jf_write(jfileobject *fp, PyObject *args)
 	rv = jwrite(fp->fs, buf, len);
 	Py_END_ALLOW_THREADS
 
+	if (rv < 0)
+		return PyErr_SetFromErrno(PyExc_IOError);
+
 	return PyLong_FromLong(rv);
 }
 
@@ -200,6 +203,9 @@ static PyObject *jf_pwrite(jfileobject *fp, PyObject *args)
 	rv = jpwrite(fp->fs, buf, len, offset);
 	Py_END_ALLOW_THREADS
 
+	if (rv < 0)
+		return PyErr_SetFromErrno(PyExc_IOError);
+
 	return PyLong_FromLong(rv);
 }
 
@@ -280,6 +286,9 @@ static PyObject *jf_jsync(jfileobject *fp, PyObject *args)
 	rv = jsync(fp->fs);
 	Py_END_ALLOW_THREADS
 
+	if (rv < 0)
+		return PyErr_SetFromErrno(PyExc_IOError);
+
 	return PyLong_FromLong(rv);
 }
 
@@ -608,6 +617,11 @@ static PyObject *jf_jfsck_cleanup(PyObject *self, PyObject *args)
 	rv = jfsck_cleanup(name, jdir);
 	Py_END_ALLOW_THREADS
 
+	if (rv != 1) {
+		PyErr_SetObject(PyExc_IOError, PyInt_FromLong(rv));
+		return NULL;
+	}
+
 	return PyInt_FromLong(rv);
 }