Author: troycurtisjr
Date: Mon Nov  6 02:33:27 2017
New Revision: 1814387

URL: http://svn.apache.org/viewvc?rev=1814387&view=rev
Log:
On branch swig-py3: Get swig bindings compiling with Python 3.

Add the necessary build tool support for choosing Python 3 or Python 2 to build
against, and get the bindings building under Python 3.

* BRANCH-README
  Add a note about current known runtime issues under Python 3.

* Makefile.in
  (SWIG_PY_OPTS): New configuration variable.

* build.conf
  (swig-python-opts): Use the new SWIG_PY_OPTS variable for the swig python
    arguments.

* configure.ac
  Add PYTHON to the influential environment variable list.
  
* build/ac-macros/swig.m4
  (SVN_FIND_SWIG): Choose appropriate SWIG_PY_OPTS based on the Python version
    detected.

* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
  Move the py3c.h include such that selected conflicting macros from swig can be
  undefined for use with this file.
  (svn_swig_py_as_file): Use correct PyObject_AsFileDescriptor instead of Python
    2's PyFile_AsFileDescriptor.

Modified:
    subversion/branches/swig-py3/BRANCH-README
    subversion/branches/swig-py3/Makefile.in
    subversion/branches/swig-py3/build.conf
    subversion/branches/swig-py3/build/ac-macros/swig.m4
    subversion/branches/swig-py3/configure.ac
    
subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c

Modified: subversion/branches/swig-py3/BRANCH-README
URL: 
http://svn.apache.org/viewvc/subversion/branches/swig-py3/BRANCH-README?rev=1814387&r1=1814386&r2=1814387&view=diff
==============================================================================
--- subversion/branches/swig-py3/BRANCH-README (original)
+++ subversion/branches/swig-py3/BRANCH-README Mon Nov  6 02:33:27 2017
@@ -16,6 +16,8 @@ TODO
 * Make the error more meaningful if the user attempts to build python swig
   bindings, even if py3c was disabled or not found. Currently the error on
   makefile builds is "none: command not found", which isn't very descriptive.
+* While the bindings compile and correctly link with Python 3, there are still 
runtime
+  issues to work through. Notably several Bytes versus Strings issues.
 
 
 References:

Modified: subversion/branches/swig-py3/Makefile.in
URL: 
http://svn.apache.org/viewvc/subversion/branches/swig-py3/Makefile.in?rev=1814387&r1=1814386&r2=1814387&view=diff
==============================================================================
--- subversion/branches/swig-py3/Makefile.in (original)
+++ subversion/branches/swig-py3/Makefile.in Mon Nov  6 02:33:27 2017
@@ -191,6 +191,7 @@ CPPFLAGS = @CPPFLAGS@ $(EXTRA_CPPFLAGS)
 LDFLAGS = @LDFLAGS@ $(EXTRA_LDFLAGS)
 SWIG_LDFLAGS = @SWIG_LDFLAGS@ $(EXTRA_SWIG_LDFLAGS)
 SWIG_CPPFLAGS = @SWIG_CPPFLAGS@ $(EXTRA_CPPFLAGS)
+SWIG_PY_OPTS = @SWIG_PY_OPTS@
 
 COMPILE = $(CC) $(CMODEFLAGS) $(CPPFLAGS) $(CMAINTAINERFLAGS) $(CFLAGS) 
$(INCLUDES)
 COMPILE_NOWARN = $(CC) $(CMODEFLAGS) $(CPPFLAGS) $(CNOWARNFLAGS) $(CFLAGS) 
$(INCLUDES)

Modified: subversion/branches/swig-py3/build.conf
URL: 
http://svn.apache.org/viewvc/subversion/branches/swig-py3/build.conf?rev=1814387&r1=1814386&r2=1814387&view=diff
==============================================================================
--- subversion/branches/swig-py3/build.conf (original)
+++ subversion/branches/swig-py3/build.conf Mon Nov  6 02:33:27 2017
@@ -98,7 +98,7 @@ test-scripts =
 
 bdb-test-scripts =
 
-swig-python-opts = $(SWIG_CPPFLAGS) -python -classic
+swig-python-opts = $(SWIG_CPPFLAGS) $(SWIG_PY_OPTS)
 swig-perl-opts = $(SWIG_CPPFLAGS) -perl -nopm -noproxy
 swig-ruby-opts = $(SWIG_CPPFLAGS) -ruby
 swig-languages = python perl ruby

Modified: subversion/branches/swig-py3/build/ac-macros/swig.m4
URL: 
http://svn.apache.org/viewvc/subversion/branches/swig-py3/build/ac-macros/swig.m4?rev=1814387&r1=1814386&r2=1814387&view=diff
==============================================================================
--- subversion/branches/swig-py3/build/ac-macros/swig.m4 (original)
+++ subversion/branches/swig-py3/build/ac-macros/swig.m4 Mon Nov  6 02:33:27 
2017
@@ -101,6 +101,7 @@ AC_DEFUN(SVN_FIND_SWIG,
 
     SWIG_PY_COMPILE="none"
     SWIG_PY_LINK="none"
+    SWIG_PY_OPTS="none"
     if test "$PYTHON" != "none"; then
       AC_MSG_NOTICE([Configuring python swig binding])
 
@@ -133,6 +134,18 @@ AC_DEFUN(SVN_FIND_SWIG,
         ])
         SWIG_PY_LIBS="`SVN_REMOVE_STANDARD_LIB_DIRS($ac_cv_python_libs)`"
 
+        AC_CACHE_CHECK([for Python >= 3], [ac_cv_python_is_py3],[
+          ac_cv_python_is_py3="no"
+          $PYTHON -c 'import sys; sys.exit(0x3000000 >= sys.hexversion)' && \
+             ac_cv_python_is_py3="yes"
+        ])
+
+        if test "$ac_cv_python_is_py3" = "yes"; then
+           SWIG_PY_OPTS="-python -py3"
+        else
+           SWIG_PY_OPTS="-python -classic"
+        fi
+
         dnl Sun Forte adds an extra space before substituting APR_INT64_T_FMT
         dnl gcc-2.95 adds an extra space after substituting APR_INT64_T_FMT
         dnl thus the egrep patterns have a + in them.
@@ -306,6 +319,7 @@ int main()
   AC_SUBST(SWIG_PY_COMPILE)
   AC_SUBST(SWIG_PY_LINK)
   AC_SUBST(SWIG_PY_LIBS)
+  AC_SUBST(SWIG_PY_OPTS)
   AC_SUBST(SWIG_PL_INCLUDES)
   AC_SUBST(SWIG_PL_LINK)
   AC_SUBST(SWIG_RB_LINK)

Modified: subversion/branches/swig-py3/configure.ac
URL: 
http://svn.apache.org/viewvc/subversion/branches/swig-py3/configure.ac?rev=1814387&r1=1814386&r2=1814387&view=diff
==============================================================================
--- subversion/branches/swig-py3/configure.ac (original)
+++ subversion/branches/swig-py3/configure.ac Mon Nov  6 02:33:27 2017
@@ -1289,7 +1289,7 @@ AS_HELP_STRING([--enable-gprof],
 # Scripting and Bindings languages
 
 # Python: Used for testsuite, and bindings
-
+AC_ARG_VAR([PYTHON], [Python interpreter command])
 
 PYTHON="`$abs_srcdir/build/find_python.sh`"
 if test -z "$PYTHON"; then

Modified: 
subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c?rev=1814387&r1=1814386&r2=1814387&view=diff
==============================================================================
--- 
subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
 (original)
+++ 
subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
 Mon Nov  6 02:33:27 2017
@@ -26,7 +26,6 @@
 
 #include <Python.h>
 
-#include <py3c.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -53,6 +52,17 @@
 #include "swig_python_external_runtime.swg"
 #include "swigutil_py.h"
 
+/* This py3c include needs to be after the swig includes. */
+#if PY_VERSION_HEX >= 0x03000000
+/* SWIG and py3c both define a few compat defines, so need to undef
+   here to give preference to the py3c versions. */
+#undef PyLong_FromSize_t
+#undef PyLong_AsLong
+#undef PyInt_Check
+#endif
+
+#include <py3c.h>
+
 /* Py_ssize_t for old Pythons */
 /* This code is as recommended by: */
 /* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */
@@ -148,7 +158,7 @@ FILE *svn_swig_py_as_file(PyObject *pyfi
 {
 #if IS_PY3
   FILE *fp = NULL;
-  int fd = PyFile_AsFileDescriptor(pyfile);
+  int fd = PyObject_AsFileDescriptor(pyfile);
   if (fd >= 0)
     {
       PyObject *mode_obj = PyObject_GetAttrString(pyfile, "mode");


Reply via email to