From 8196edf9ca5c8f2f02553e7f22d9c79dbd229882 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 6 Jun 2016 13:11:15 +0200 Subject: python: Wrap file-like objects on demand. * lang/python/gpgme.i (gpgme_data_t): Use new function to create wrapper objects if necessary, and deallocate them after the function call. * lang/python/helpers.c (object_to_gpgme_data_t): New function. * lang/python/helpers.h (object_to_gpgme_data_t): New prototype. * lang/python/tests/Makefile.am (pytests): Add new test. * lang/python/tests/t-idiomatic.py: New file. Signed-off-by: Justus Winter --- lang/python/gpgme.i | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lang/python/gpgme.i') diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i index e3c761d4..e3695823 100644 --- a/lang/python/gpgme.i +++ b/lang/python/gpgme.i @@ -113,13 +113,17 @@ } // Special handling for references to our objects. -%typemap(in) gpgme_data_t DATAIN { +%typemap(in) gpgme_data_t DATAIN (PyObject *wrapper) { + /* If we create a temporary wrapper object, we will store it in + wrapperN, where N is $argnum. Here in this fragment, SWIG will + automatically append $argnum. */ + wrapper = NULL; if ($input == Py_None) $1 = NULL; else { PyObject *pypointer = NULL; - if((pypointer=object_to_gpgme_t($input, "$1_ltype", $argnum)) == NULL) + if((pypointer=object_to_gpgme_data_t($input, $argnum, &wrapper)) == NULL) return NULL; /* input = $input, 1 = $1, 1_descriptor = $1_descriptor */ @@ -135,6 +139,11 @@ } } +%typemap(freearg) gpgme_data_t DATAIN { + /* Free the temporary wrapper, if any. */ + Py_XDECREF(wrapper$argnum); +} + %apply gpgme_data_t DATAIN {gpgme_data_t plain, gpgme_data_t cipher, gpgme_data_t sig, gpgme_data_t signed_text, gpgme_data_t plaintext, gpgme_data_t keydata, -- cgit v1.2.3