[PATCH gpgmepy] build: Fix compiler warnings

Paul Schwabauer via Gnupg-devel <[email protected]>
Newsgroups gmane.comp.encryption.gpg.devel
Message-ID <[email protected]>
This initializes variables that could be uninitialized and removes the
usage of deprecated functions.
---
 gpgme.i   | 12 ++++++++----
 helpers.c |  3 ++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/gpgme.i b/gpgme.i
index f67c45a..0baa551 100644
--- a/gpgme.i
+++ b/gpgme.i
@@ -71,14 +71,14 @@
 
 /* Likewise for a list of strings.  */
 %typemap(in) const char *[] (void *vector = NULL,
-                             size_t size,
+                             size_t size = 0,
                              PyObject **pyVector = NULL) {
   /* Check if is a list */
   if (PyList_Check($input)) {
     size_t i, j;
     size = PyList_Size($input);
     $1 = (char **) (vector = malloc((size+1) * sizeof(char *)));
-    pyVector = calloc(sizeof *pyVector, size);
+    pyVector = calloc(size, sizeof *pyVector);
 
     for (i = 0; i < size; i++) {
       PyObject *o = PyList_GetItem($input,i);
@@ -319,8 +319,10 @@
   else if (PyInt_Check($input))
     $1 = PyInt_AsLong($input);
 #endif
-  else
+  else {
     PyErr_SetString(PyExc_TypeError, "Numeric argument expected");
+    return NULL;
+    }
 }
 
 %typemap(out) off_t {
@@ -342,8 +344,10 @@
   else if (PyInt_Check($input))
     $1 = PyInt_AsLong($input);
 #endif
-  else
+  else {
     PyErr_SetString(PyExc_TypeError, "Numeric argument expected");
+    return NULL;
+    }
 }
 
 /* Those are for gpgme_data_read() and gpgme_strerror_r().  */
diff --git a/helpers.c b/helpers.c
index 1ce7f48..50db70d 100644
--- a/helpers.c
+++ b/helpers.c
@@ -116,7 +116,8 @@ static void _gpg_stash_callback_exception(PyObject *weak_self)
     PyTuple_SetItem(excinfo, 2, Py_None);
   }
 
-  self = PyWeakref_GetObject(weak_self);
+  PyWeakref_GetRef(weak_self, &self);
+  Py_DECREF(self);
   /* self only has a borrowed reference.  */
   if (self == Py_None) {
     /* This should not happen, as even if we're called from the data
-- 
2.49.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.