diff options
| author | Justus Winter <[email protected]> | 2016-05-23 13:41:06 +0000 | 
|---|---|---|
| committer | Justus Winter <[email protected]> | 2016-05-23 13:41:06 +0000 | 
| commit | c9cc0412e940c78c3e9bacb6ff1459b5bb5bb9ad (patch) | |
| tree | a94c3024f5bca8d400696a82515aea5fa4cab362 /lang/python | |
| parent | api: Return Tofu info for signatures. (diff) | |
| download | gpgme-c9cc0412e940c78c3e9bacb6ff1459b5bb5bb9ad.tar.gz gpgme-c9cc0412e940c78c3e9bacb6ff1459b5bb5bb9ad.zip | |
python: Translate list of strings.
* lang/python/gpgme.i: Add typemap translating list of strings.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to '')
| -rw-r--r-- | lang/python/gpgme.i | 34 | 
1 files changed, 34 insertions, 0 deletions
| diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i index 4809fd6c..fb882c85 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; | 
