diff options
author | Justus Winter <[email protected]> | 2016-06-06 11:11:15 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2016-06-06 12:16:04 +0000 |
commit | 8196edf9ca5c8f2f02553e7f22d9c79dbd229882 (patch) | |
tree | d3bacbbbe7f72ba90bbe2715b5a87acac6871445 /lang/python/gpgme.i | |
parent | python: Move helper function. (diff) | |
download | gpgme-8196edf9ca5c8f2f02553e7f22d9c79dbd229882.tar.gz gpgme-8196edf9ca5c8f2f02553e7f22d9c79dbd229882.zip |
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 <[email protected]>
Diffstat (limited to '')
-rw-r--r-- | lang/python/gpgme.i | 13 |
1 files changed, 11 insertions, 2 deletions
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, |