[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Win32 compile problems with "long long" datatype in Perl/Python/Ruby bindings

From: David James <james82_at_gmail.com>
Date: 2005-08-09 15:48:20 CEST

Visual C++ does not support the 'long long' datatype, so we need to
replace this datatype with portable constructs. As of r15644 on the
python-bindings-improvements branch, the Python/SWIG bindings no
longer output C files which use the "long long" datatype. Instead, we
use "PY_LONG_LONG", which should work on both Unix and Windows.

The Perl and Ruby bindings also have the same problem, but this has
not been fixed yet.

Cheers,

David

---------- Forwarded message ----------
From: djames@tigris.org <djames@tigris.org>
Date: Aug 8, 2005 10:29 PM
Subject: svn commit: r15644 - in
branches/python-bindings-improvements: build/generator
To: svn@subversion.tigris.org

Author: djames
Date: Mon Aug 8 21:29:11 2005
New Revision: 15644

Modified:
   branches/python-bindings-improvements/build/generator/gen_swig.py
   branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg

Log:
Avoid using long long directly in Python/SWIG bindings.

* build/generator/gen_swig.py:
  (_write_long_long_fix): Hide the SWIG implementation of 'long long'
  converters so that Visual C++ won't get confused by it. Python only.
  (write): If SWIG is found, run self._write_long_long_fix().
* subversion/bindings/swig/include:
  (apr_time_t, apr_int64_t, apr_uint64_t): Define python input typemaps.
  (apr_time_t, apr_int64_t, long long, __int64, apr_uint64_t,
   unsigned long long, unsigned __int64): Define python output typemaps.
  (apr_time_t, apr_int64_t, long long, __int64): Define python argout typemaps.

Modified: branches/python-bindings-improvements/build/generator/gen_swig.py
Url: http://svn.collab.net/viewcvs/svn/branches/python-bindings-improvements/build/generator/gen_swig.py?rev=15644&p1=branches/python-bindings-improvements/build/generator/gen_swig.py&p2=branches/python-bindings-improvements/build/generator/gen_swig.py&r1=15643&r2=15644
==============================================================================
--- branches/python-bindings-improvements/build/generator/gen_swig.py
 (original)
+++ branches/python-bindings-improvements/build/generator/gen_swig.py
 Mon Aug 8 21:29:11 2005
@@ -243,6 +243,25 @@
     else:
       self._cmd("%s -o %s -co %s/%s" % (self.swig_path, out, dir, file))

+ def _write_long_long_fix(self):
+ """Hide the SWIG implementation of 'long long' converters so that
+ Visual C++ won't get confused by it."""
+
+ self._checkout("python","python.swg")
+
+ python_swg_filename = "%s/python.swg" % self.swig_proxy_dir
+ python_swg = open(python_swg_filename).read()
+ file = open(python_swg_filename,"w")
+ file.write("""
+ %fragment("SWIG_AsVal_" {long long},"header") {
+ }
+ %fragment("SWIG_Check_" {long long},"header") {
+ }
+ %fragment("SWIG_From_" {long long},"header") {
+ }\n""")
+ file.write(python_swg)
+ file.close()
+
   def _write_external_runtime(self, langs):
     """Generate external runtime header files for each SWIG language"""

@@ -338,3 +357,6 @@
     langs = ["perl", "python", "ruby"]
     if self.swig_version >= 103024:
       self._write_external_runtime(langs)
+
+ # Fix SWIG's "long long" support on WIN32
+ self._write_long_long_fix()

Modified: branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg
Url: http://svn.collab.net/viewcvs/svn/branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg?rev=15644&p1=branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg&p2=branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg&r1=15643&r2=15644
==============================================================================
--- branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg
      (original)
+++ branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg
      Mon Aug 8 21:29:11 2005
@@ -82,8 +82,28 @@
 %typemap (in, parse="I") unsigned int "";
 %typemap (in, parse="l") long, ssize_t "";
 %typemap (in, parse="k") unsigned long, size_t "";
-%typemap (in, parse="L") long long, __int64 "";
-%typemap (in, parse="K") unsigned long long, unsigned __int64 "";
+%typemap (in, parse="L") apr_time_t, apr_int64_t, long long, __int64 "";
+%typemap (in, parse="K") apr_uint64_t, unsigned long long, unsigned __int64 "";
+
+/* For compatibility with Python 2.2 */
+%{
+#if defined(LONG_LONG) && !defined(PY_LONG_LONG)
+#define PY_LONG_LONG LONG_LONG
+#endif
+%}
+
+/* These typemaps use PY_LONG_LONG so that they will work on Win32 and Unix */
+%typemap (out) apr_time_t, apr_int64_t, long long, __int64
+ " $result = PyLong_FromLongLong((PY_LONG_LONG)($1)); ";
+
+%typemap (out) apr_uint64_t, unsigned long long, unsigned __int64
+ " $result = PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)($1)); ";
+
+%typemap(argout) \
+ long long *OUTPUT, apr_int64_t *OUTPUT, __int64 *OUTPUT, apr_time_t *OUTPUT
+ "$result = t_output_helper($result, ((res$argnum == SWIG_NEWOBJ) ?
+ PyLong_FromLongLong((*$1)) :
+ SWIG_NewPointerObj((void*)($1), $1_descriptor, 0)));";

 /* We assume here that Subversion functions have no more than
    20 fixed parameters. If you want to wrap a function that has

---------------------------------------------------------------------
To unsubscribe, e-mail: svn-unsubscribe@subversion.tigris.org
For additional commands, e-mail: svn-help@subversion.tigris.org

-- 
David James -- http://www.cs.toronto.edu/~james
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Aug 9 15:49:26 2005

This is an archived mail posted to the Subversion Dev mailing list.