aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-06-08 16:06:24 +0000
committerJustus Winter <[email protected]>2016-06-08 16:12:35 +0000
commit77d149e8614c381458e07808a7930ce3fb92cdc3 (patch)
tree77a810d3c86df0ec5aef417946e8782c2e6d18f8 /lang/python
parentpython: Add function to raise exceptions from c. (diff)
downloadgpgme-77d149e8614c381458e07808a7930ce3fb92cdc3.tar.gz
gpgme-77d149e8614c381458e07808a7930ce3fb92cdc3.zip
python: Improve error handling.
* lang/python/helpers.c (pyPassphraseCb): Handle write errors. (pyEditCb): Likewise. Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang/python')
-rw-r--r--lang/python/helpers.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 5c620e6b..0033ef02 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -320,7 +320,10 @@ static gpgme_error_t pyPassphraseCb(void *hook,
err_status = pygpgme_exception2code();
} else {
if (!retval) {
- write(fd, "\n", 1);
+ if (write(fd, "\n", 1) < 0) {
+ err_status = gpgme_error_from_syserror ();
+ pygpgme_raise_exception (err_status);
+ }
} else {
char *buf;
size_t len;
@@ -342,8 +345,15 @@ static gpgme_error_t pyPassphraseCb(void *hook,
goto leave;
}
- write(fd, buf, len);
- write(fd, "\n", 1);
+ if (write(fd, buf, len) < 0) {
+ err_status = gpgme_error_from_syserror ();
+ pygpgme_raise_exception (err_status);
+ }
+ if (! err_status && write(fd, "\n", 1) < 0) {
+ err_status = gpgme_error_from_syserror ();
+ pygpgme_raise_exception (err_status);
+ }
+
Py_DECREF(retval);
}
}
@@ -512,17 +522,24 @@ gpgme_error_t pyEditCb(void *opaque, gpgme_status_code_t status,
Py_DECREF(pyargs);
if (PyErr_Occurred()) {
err_status = pygpgme_exception2code();
- pygpgme_stash_callback_exception(self);
} else {
if (fd>=0 && retval && PyUnicode_Check(retval)) {
const char *buffer;
Py_ssize_t size;
buffer = PyUnicode_AsUTF8AndSize(retval, &size);
- write(fd, buffer, size);
- write(fd, "\n", 1);
+ if (write(fd, buffer, size) < 0) {
+ err_status = gpgme_error_from_syserror ();
+ pygpgme_raise_exception (err_status);
+ }
+ if (! err_status && write(fd, "\n", 1) < 0) {
+ err_status = gpgme_error_from_syserror ();
+ pygpgme_raise_exception (err_status);
+ }
}
}
+ if (err_status)
+ pygpgme_stash_callback_exception(self);
Py_XDECREF(retval);
return err_status;