[Pkg-gnupg-commit] [gpgme] 06/53: python: Correctly translate off_t.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Oct 24 19:26:47 UTC 2016


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

dkg pushed a commit to branch experimental
in repository gpgme.

commit 1d80e7374aa3150306c86afe7acdc8e8eb05143f
Author: Justus Winter <justus at g10code.com>
Date:   Mon Sep 26 13:04:35 2016 +0200

    python: Correctly translate off_t.
    
    * lang/python/gpgme.i: Improve int/long translations, correctly handle
    off_t with large file support.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 lang/python/gpgme.i | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index a4672e1..934ebea 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -291,13 +291,42 @@
 
 /* SWIG has problems interpreting ssize_t, off_t or gpgme_error_t in
    gpgme.h.  */
-/* XXX: This is wrong at least for off_t if compiled with LFS.  */
-%typemap(out) ssize_t, off_t, gpgme_error_t, gpgme_err_code_t, gpgme_err_source_t, gpg_error_t {
+%typemap(out) ssize_t, gpgme_error_t, gpgme_err_code_t, gpgme_err_source_t, gpg_error_t {
   $result = PyLong_FromLong($1);
 }
-/* XXX: This is wrong at least for off_t if compiled with LFS.  */
-%typemap(in) ssize_t, off_t, gpgme_error_t, gpgme_err_code_t, gpgme_err_source_t, gpg_error_t {
-  $1 = PyLong_AsLong($input);
+
+%typemap(in) ssize_t, gpgme_error_t, gpgme_err_code_t, gpgme_err_source_t, gpg_error_t {
+  if (PyLong_Check($input))
+    $1 = PyLong_AsLong($input);
+#if PY_MAJOR_VERSION < 3
+  else if (PyInt_Check($input))
+    $1 = PyInt_AsLong($input);
+#endif
+  else
+    PyErr_SetString(PyExc_TypeError, "Numeric argument expected");
+}
+
+%typemap(out) off_t {
+#if _FILE_OFFSET_BITS == 64
+  $result = PyLong_FromLongLong($1);
+#else
+  $result = PyLong_FromLong($1);
+#endif
+}
+
+%typemap(in) off_t {
+  if (PyLong_Check($input))
+#if _FILE_OFFSET_BITS == 64
+    $1 = PyLong_AsLongLong($input);
+#else
+    $1 = PyLong_AsLong($input);
+#endif
+#if PY_MAJOR_VERSION < 3
+  else if (PyInt_Check($input))
+    $1 = PyInt_AsLong($input);
+#endif
+  else
+    PyErr_SetString(PyExc_TypeError, "Numeric argument expected");
 }
 
 // Those are for gpgme_data_read() and gpgme_strerror_r()

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