[Pkg-gnupg-commit] [gpgme] 125/412: python: Translate list of strings.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:30 UTC 2016


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

dkg pushed a commit to branch master
in repository gpgme.

commit c9cc0412e940c78c3e9bacb6ff1459b5bb5bb9ad
Author: Justus Winter <justus at gnupg.org>
Date:   Mon May 23 15:41:06 2016 +0200

    python: Translate list of strings.
    
    * lang/python/gpgme.i: Add typemap translating list of strings.
    
    Signed-off-by: Justus Winter <justus at gnupg.org>
---
 lang/python/gpgme.i | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index 4809fd6..fb882c8 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -42,6 +42,40 @@
 }
 %typemap(freearg) const char * "";
 
+/* Likewise for a list of strings.  */
+%typemap(in) const char *[] {
+  /* Check if is a list */
+  if (PyList_Check($input)) {
+    size_t i, size = PyList_Size($input);
+    $1 = (char **) malloc((size+1) * sizeof(char *));
+
+    for (i = 0; i < size; i++) {
+      PyObject *o = PyList_GetItem($input,i);
+      if (PyUnicode_Check(o))
+        $1[i] = PyUnicode_AsUTF8(o);
+      else if (PyString_Check(o))
+	$1[i] = PyString_AsString(o);
+      else {
+	PyErr_Format(PyExc_TypeError,
+                     "arg %d: list must contain only str or bytes, got %s "
+                     "at position %d",
+                     $argnum, o->ob_type->tp_name, i);
+	free($1);
+	return NULL;
+      }
+    }
+    $1[i] = NULL;
+  } else {
+    PyErr_Format(PyExc_TypeError,
+                 "arg %d: expected a list of str or bytes, got %s",
+                 $argnum, $input->ob_type->tp_name);
+    return NULL;
+  }
+}
+%typemap(freearg) const char *[] {
+  free((char *) $1);
+}
+
 // Release returned buffers as necessary.
 %typemap(newfree) char * "free($1);";
 %newobject gpgme_data_release_and_get_mem;

-- 
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