[Pkg-gnupg-commit] [gpgme] 08/132: python: Define a macro for wrapping fragile result objects.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Apr 26 01:00:46 UTC 2017


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

dkg pushed a commit to branch experimental
in repository gpgme.

commit fb7f4cb973abc9f5eb05eb240607be35c1be986c
Author: Tobias Mueller <muelli at cryptobitch.de>
Date:   Thu Dec 1 21:15:12 2016 +0100

    python: Define a macro for wrapping fragile result objects.
    
    * lang/python/gpgme.i (wrapresult): New Macro.
    --
    
    This reduces the amount of copy and pasted code at the expense of a
    slightly more complicated logic with a macro.
    
    Signed-off-by: Tobias Mueller <muelli at cryptobitch.de>
---
 lang/python/gpgme.i | 69 ++++++++++-------------------------------------------
 1 file changed, 12 insertions(+), 57 deletions(-)

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index 783531f..73533d0 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -424,69 +424,24 @@
 

 
 /* Wrap the fragile result objects into robust Python ones.  */
-%typemap(out) gpgme_encrypt_result_t {
+%define wrapresult(cls, name)
+%typemap(out) cls {
   PyObject *fragile;
   fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
                                %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "EncryptResult");
+  $result = _gpg_wrap_result(fragile, name);
   Py_DECREF(fragile);
 }
+%enddef
 
-%typemap(out) gpgme_decrypt_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "DecryptResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_sign_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "SignResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_verify_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "VerifyResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_import_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "ImportResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_genkey_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "GenkeyResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_keylist_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "KeylistResult");
-  Py_DECREF(fragile);
-}
-
-%typemap(out) gpgme_vfs_mount_result_t {
-  PyObject *fragile;
-  fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor,
-                               %newpointer_flags);
-  $result = _gpg_wrap_result(fragile, "VFSMountResult");
-  Py_DECREF(fragile);
-}
+wrapresult(gpgme_encrypt_result_t, "EncryptResult")
+wrapresult(gpgme_decrypt_result_t, "DecryptResult")
+wrapresult(gpgme_sign_result_t, "SignResult")
+wrapresult(gpgme_verify_result_t, "VerifyResult")
+wrapresult(gpgme_import_result_t, "ImportResult")
+wrapresult(gpgme_genkey_result_t, "GenkeyResult")
+wrapresult(gpgme_keylist_result_t, "KeylistResult")
+wrapresult(gpgme_vfs_mount_result_t, "VFSMountResult")
 
 %typemap(out) gpgme_engine_info_t {
   int i;

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