[Pkg-gnupg-commit] [gpgme] 07/53: python: Correctly translate to size_t.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Oct 24 19:26:47 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gpgme.

commit c38fabfea0601ed5f61e27e0bf43f8e74c67ce2a
Author: Justus Winter <justus at g10code.com>
Date:   Mon Sep 26 13:16:59 2016 +0200

    python: Correctly translate to size_t.
    
    * lang/python/gpgme.i: Correctly translate Python number to size_t.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 lang/python/gpgme.i | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index 934ebea..04257fd 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -329,14 +329,29 @@
     PyErr_SetString(PyExc_TypeError, "Numeric argument expected");
 }
 
-// Those are for gpgme_data_read() and gpgme_strerror_r()
+/* Those are for gpgme_data_read() and gpgme_strerror_r().  */
 %typemap(in) (void *buffer, size_t size), (char *buf, size_t buflen) {
-   $2 = PyLong_AsLong($input);
-   if ($2 < 0) {
-     PyErr_SetString(PyExc_ValueError, "Positive integer expected");
-     return NULL;
-   }
-   $1 = ($1_ltype) malloc($2+1);
+  {
+    long tmp$argnum;
+    if (PyLong_Check($input))
+      tmp$argnum = PyLong_AsLong($input);
+#if PY_MAJOR_VERSION < 3
+    else if (PyInt_Check($input))
+      tmp$argnum = PyInt_AsLong($input);
+#endif
+    else
+      {
+        PyErr_SetString(PyExc_TypeError, "Numeric argument expected");
+        return NULL;
+      }
+
+    if (tmp$argnum < 0) {
+      PyErr_SetString(PyExc_ValueError, "Positive integer expected");
+      return NULL;
+    }
+    $2 = (size_t) tmp$argnum;
+    $1 = ($1_ltype) malloc($2+1);
+  }
 }
 %typemap(argout) (void *buffer, size_t size), (char *buf, size_t buflen) {
   Py_XDECREF($result);   /* Blow away any previous result */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list