[git] GPGME - branch, master, updated. gpgme-1.6.0-166-g77d149e

by Justus Winter cvs at cvs.gnupg.org
Wed Jun 8 19:22:02 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, master has been updated
       via  77d149e8614c381458e07808a7930ce3fb92cdc3 (commit)
       via  5ebc205439cac266685d2532466df8b3457dea23 (commit)
      from  8426304b67a0b0a5630db500abf740b0e0b9e43c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 77d149e8614c381458e07808a7930ce3fb92cdc3
Author: Justus Winter <justus at g10code.com>
Date:   Wed Jun 8 18:06:24 2016 +0200

    python: Improve error handling.
    
    * lang/python/helpers.c (pyPassphraseCb): Handle write errors.
    (pyEditCb): Likewise.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 5c620e6..0033ef0 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;

commit 5ebc205439cac266685d2532466df8b3457dea23
Author: Justus Winter <justus at g10code.com>
Date:   Wed Jun 8 17:54:45 2016 +0200

    python: Add function to raise exceptions from c.
    
    * lang/python/helpers.c (pygpgme_raise_exception): New function.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 7e1c1c3..5c620e6 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -1,4 +1,5 @@
 /*
+# Copyright (C) 2016 g10 Code GmbH
 # Copyright (C) 2004 Igor Belyi <belyi at users.sourceforge.net>
 # Copyright (C) 2002 John Goerzen <jgoerzen at complete.org>
 #
@@ -41,6 +42,25 @@ void pygpgme_exception_init(void) {
   }
 }
 
+static PyObject *
+pygpgme_raise_exception(gpgme_error_t err)
+{
+  PyObject *e;
+
+  pygpgme_exception_init();
+  if (GPGMEError == NULL)
+    return PyErr_Format(PyExc_RuntimeError, "Got gpgme_error_t %d", err);
+
+  e = PyObject_CallFunction(GPGMEError, "l", (long) err);
+  if (e == NULL)
+    return NULL;
+
+  PyErr_SetObject(GPGMEError, e);
+  Py_DECREF(e);
+
+  return NULL;	/* raise */
+}
+
 gpgme_error_t pygpgme_exception2code(void) {
   gpgme_error_t err_status = gpg_error(GPG_ERR_GENERAL);
   if (GPGMEError && PyErr_ExceptionMatches(GPGMEError)) {

-----------------------------------------------------------------------

Summary of changes:
 lang/python/helpers.c | 49 +++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list