subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From troycurti...@apache.org
Subject svn commit: r1813665 - in /subversion/branches/swig-py3: ./ build/ac-macros/ subversion/bindings/swig/ subversion/bindings/swig/include/ subversion/bindings/swig/python/libsvn_swig_py/
Date Sun, 29 Oct 2017 03:37:38 GMT
Author: troycurtisjr
Date: Sun Oct 29 03:37:37 2017
New Revision: 1813665

URL: http://svn.apache.org/viewvc?rev=1813665&view=rev
Log:
On branch swig-py3: Use py3c library in Python swig bindings.

Add the py3c Python compatibility library and update the python swig bindings
to use the compatibility functions that it provides. This is the first step to
getting the swig bindings to support Python 3.

* ac-macros/py3c.m4:
  Create a new ac-macro for the py3c library.

* aclocal.m4:
  Include the new py3c.m4 file.

* ac-macros/swig.m4:
  (SVN_FIND_SWIG): Call the new SVN_PY3C macro to add py3c to the build.

[in subversion/bindings/swig]

* include/svn_string.swg
  (python typemaps: RET_STRING): Replace PyString_FromStringAndSize with
     PyStr_FromStringAndSize.
  (python typemaps: (in) svn_stringbuf_t *,
   (in) const svn_string_t * (svn_string_t value)): 
     Replace PyString_Check with PyStr_Check and
     PyString_AS_STRING/PyString_GET_SIZE with PyStr_AsUTF8AndSize.
  (python typemaps: (out) svn_stringbuf_t *, 
                    (out) svn_string_t *):
     Replace PyString_FromStringAndSize with PyStr_FromStringAndSize.
  (python typemaps: (argout) const char **OUTPUT):
     Replace PyString_FromString with PyStr_FromString.

* include/svn_types.swg
  (python typemaps: (in) (const char *PTR, apr_size_t LEN)): 
    Replace PyString_Check with PyStr_Check and
    PyStr_AS_STRING/PyString_GET_SIZE with PyStr_AsUTF8AndSize.
  (python typemaps: (argout) unsigned char digest[ANY]): 
    Replace PyString_FromStringAndSize with PyStr_FromStringAndSize.
  (python typemaps: (in) const unsigned char *digest): 
    Replace PyString_AsString with PyStr_AsString.

* include/libsvn_swig_py/swigutil_py.h,
  include/libsvn_swig_py/swigutil_py.c
  Include py3c.h to pick up Python 2/3 compatibility defines.
  (svn_swig_py_as_file): Add new compatibility function.
  (svn_swig_py_unwrap_string): Add clarifying note to function.
  (svn_swig_py_svn_exception,
   svn_swig_py_propinheriteditemarray_to_dict,
   svn_swig_py_proparray_to_dict,
   svn_swig_py_locationhash_to_dict,
   svn_swig_py_c_strings_to_list,
   svn_swig_py_array_to_list,
   cstring_to_pystring,
   convert_string): 
     Replace PyString_FromString with PyStr_FromString.
  (make_string_from_ob,
   make_svn_string_from_ob,
   svn_swig_py_unwrap_string,
   ra_callbacks_get_client_string,
   exeception_to_error):
     Replace PyString_AsString with PyStr_AsString.
  (make_string_from_ob, make_svn_string_from_ob):
     Replace PyString_Check with PyStr_Check.
  (convert_svn_string_t,
   svn_swig_py_proparray_to_dict,
   ra_callbacks_push_or_set_wc_prop):
     Replace PyString_FromStringAndSize with PyStr_FromStringAndSize.
  (svn_swig_py_make_file):
     Replace PyFile_Check/PyFile_AsFile with svn_swig_py_as_file.
  (read_handler_pyio, ra_callbacks_get_wc_prop):
     Replace PyString_GET_SIZE/PyString_AS_STRING with PyStr_AsUTF8AndSize.
  (svn_swig_py_get_commit_log_func):
     Replace PyString_AS_STRING with PyStr_AsString and PyString_Check with
     PyStr_Check.

* core.i
  (python typemap: 
   (char *buffer, apr_size_t *len)): 
     Replace PyString_FromStringAndSize with PyStr_FromStringAndSize.
  (python typemap: 
   (const char *data, apr_size_t *len)): 
     Replace PyString_Check with PyStr_Check, and PyString_AS_STRING/
     PyString_GET_SIZE with PyStr_AsUTF8AndSize.
  (python typemap: 
   const void *value (apr_pool_t *_global_pool, PyObject *_global_py_pool)):
     Replace PyString_Check with PyStr_Check and PyString_AS_STRING with
     PyStr_AsString.
  (python typemap: FILE *): Replace PyFile_AsFile with svn_swig_py_as_file.

* svn_client.i
  Include py3c.h to pick up Python 2/3 compatibility defines.
  (python typemap: (argout) apr_array_header_t **props):
    Replace PyString_FromStringAndSize with PyStr_FromStringAndSize.

* svn_delta.i,
  svn_diff.i,
  svn_fs.i,
  svn_ra.i,
  svn_repos.i,
  svn_wc.i
  Include py3c.h to pick up Python 2/3 compatibility defines.


Added:
    subversion/branches/swig-py3/build/ac-macros/py3c.m4
Modified:
    subversion/branches/swig-py3/aclocal.m4
    subversion/branches/swig-py3/build/ac-macros/swig.m4
    subversion/branches/swig-py3/subversion/bindings/swig/core.i
    subversion/branches/swig-py3/subversion/bindings/swig/include/svn_string.swg
    subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg
    subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
    subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h
    subversion/branches/swig-py3/subversion/bindings/swig/svn_client.i
    subversion/branches/swig-py3/subversion/bindings/swig/svn_delta.i
    subversion/branches/swig-py3/subversion/bindings/swig/svn_diff.i
    subversion/branches/swig-py3/subversion/bindings/swig/svn_fs.i
    subversion/branches/swig-py3/subversion/bindings/swig/svn_ra.i
    subversion/branches/swig-py3/subversion/bindings/swig/svn_repos.i
    subversion/branches/swig-py3/subversion/bindings/swig/svn_wc.i

Modified: subversion/branches/swig-py3/aclocal.m4
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/aclocal.m4?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/aclocal.m4 (original)
+++ subversion/branches/swig-py3/aclocal.m4 Sun Oct 29 03:37:37 2017
@@ -42,6 +42,7 @@ sinclude(build/ac-macros/java.m4)
 sinclude(build/ac-macros/sasl.m4)
 sinclude(build/ac-macros/serf.m4)
 sinclude(build/ac-macros/sqlite.m4)
+sinclude(build/ac-macros/py3c.m4)
 sinclude(build/ac-macros/swig.m4)
 sinclude(build/ac-macros/zlib.m4)
 sinclude(build/ac-macros/lz4.m4)

Added: subversion/branches/swig-py3/build/ac-macros/py3c.m4
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/build/ac-macros/py3c.m4?rev=1813665&view=auto
==============================================================================
--- subversion/branches/swig-py3/build/ac-macros/py3c.m4 (added)
+++ subversion/branches/swig-py3/build/ac-macros/py3c.m4 Sun Oct 29 03:37:37 2017
@@ -0,0 +1,90 @@
+dnl ===================================================================
+dnl   Licensed to the Apache Software Foundation (ASF) under one
+dnl   or more contributor license agreements.  See the NOTICE file
+dnl   distributed with this work for additional information
+dnl   regarding copyright ownership.  The ASF licenses this file
+dnl   to you under the Apache License, Version 2.0 (the
+dnl   "License"); you may not use this file except in compliance
+dnl   with the License.  You may obtain a copy of the License at
+dnl
+dnl     http://www.apache.org/licenses/LICENSE-2.0
+dnl
+dnl   Unless required by applicable law or agreed to in writing,
+dnl   software distributed under the License is distributed on an
+dnl   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+dnl   KIND, either express or implied.  See the License for the
+dnl   specific language governing permissions and limitations
+dnl   under the License.
+dnl ===================================================================
+dnl
+dnl  SVN_PY3C
+dnl
+dnl  Check configure options and assign variables related to
+dnl  the py3c library.
+dnl
+
+AC_DEFUN(SVN_PY3C,
+[
+  py3c_found=no
+  py3c_skip=no
+
+  AC_ARG_WITH(py3c,AS_HELP_STRING([--with-py3c=PREFIX],
+                                  [py3c python extension compatibility library]),
+  [
+    if test "$withval" = "yes"; then
+      py3c_skip=no
+    elif test "$withval" = "no"; then
+      py3c_skip=yes
+    else
+      py3c_skip=no
+      py3c_prefix="$withval"
+    fi
+  ])
+
+  if test "$py3c_skip" = "yes"; then
+    AC_MSG_ERROR([subversion swig python bindings require py3c])
+  fi
+
+  if test -n "$py3c_prefix"; then
+    AC_MSG_NOTICE([py3c library configuration via prefix])
+    save_cppflags="$CPPFLAGS"
+    CPPFLAGS="$CPPFLAGS -I$py3c_prefix/include"
+    AC_CHECK_HEADERS(py3c.h,[
+        py3c_found="yes"
+        SVN_PY3C_INCLUDES="-I$py3c_prefix/include"
+    ])
+    CPPFLAGS="$save_cppflags"
+  else
+    SVN_PY3C_PKG_CONFIG()
+
+    if test "$py3c_found" = "no"; then
+      AC_MSG_NOTICE([py3c library configuration])
+      AC_CHECK_HEADER(py3c.h, [
+        py3c_found="yes"
+      ])
+    fi
+  fi
+
+  if test "$py3c_found" = "no"; then
+    AC_MSG_ERROR([subversion swig python bindings require py3c])
+  fi
+
+  AC_SUBST(SVN_PY3C_INCLUDES)
+])
+
+dnl SVN_PY3C_PKG_CONFIG()
+dnl Use pkg-config to try and detect and configure py3c
+AC_DEFUN(SVN_PY3C_PKG_CONFIG,
+[
+  AC_MSG_NOTICE([py3c library configuration via pkg-config])
+  if test -n "$PKG_CONFIG"; then
+    AC_MSG_CHECKING([for py3c library])
+    if $PKG_CONFIG py3c --exists; then
+      AC_MSG_RESULT([yes])
+      py3c_found=yes
+      SVN_PY3C_INCLUDES=`$PKG_CONFIG py3c --cflags`
+    else
+      AC_MSG_RESULT([no])
+    fi
+  fi
+])

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=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/build/ac-macros/swig.m4 (original)
+++ subversion/branches/swig-py3/build/ac-macros/swig.m4 Sun Oct 29 03:37:37 2017
@@ -162,6 +162,8 @@ AC_DEFUN(SVN_FIND_SWIG,
                          ["$svn_cv_pycfmt_apr_int64_t"],
                          [Define to the Python/C API format character suitable]
                          [ for apr_int64_t])
+
+      SVN_PY3C()
     fi
 
     if test "$PERL" != "none"; then

Modified: subversion/branches/swig-py3/subversion/bindings/swig/core.i
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/core.i?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/core.i (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/core.i Sun Oct 29 03:37:37 2017
@@ -49,6 +49,12 @@
 %}
 #endif
 
+#ifdef SWIGPYTHON
+%{
+#include <py3c.h>
+%}
+#endif
+
 /* ### for now, let's ignore this thing. */
 %ignore svn_prop_t;
 
@@ -418,7 +424,7 @@
 
 #ifdef SWIGPYTHON
 %typemap(argout) (char *buffer, apr_size_t *len) {
-  %append_output(PyString_FromStringAndSize($1, *$2));
+  %append_output(PyStr_FromStringAndSize($1, *$2));
   free($1);
 }
 #endif
@@ -440,13 +446,12 @@
 */
 #ifdef SWIGPYTHON
 %typemap(in) (const char *data, apr_size_t *len) ($*2_type temp) {
-    if (!PyString_Check($input)) {
+    if (!PyStr_Check($input)) {
         PyErr_SetString(PyExc_TypeError,
                         "expecting a string for the buffer");
         SWIG_fail;
     }
-    $1 = PyString_AS_STRING($input);
-    temp = PyString_GET_SIZE($input);
+    $1 = PyStr_AsUTF8AndSize($input, &temp);
     $2 = ($2_ltype)&temp;
 }
 #endif
@@ -499,8 +504,8 @@
        SWIG_fail;
     }
 
-    if (PyString_Check($input)) {
-        char *value = PyString_AS_STRING($input);
+    if (PyStr_Check($input)) {
+        char *value = PyStr_AsString($input);
         $1 = apr_pstrdup(_global_pool, value);
     }
     else if (PyLong_Check($input)) {
@@ -605,7 +610,7 @@
 */
 #ifdef SWIGPYTHON
 %typemap(in) FILE * {
-    $1 = PyFile_AsFile($input);
+    $1 = svn_swig_py_as_file($input);
     if ($1 == NULL) {
         PyErr_SetString(PyExc_ValueError, "Must pass in a valid file object");
         SWIG_fail;

Modified: subversion/branches/swig-py3/subversion/bindings/swig/include/svn_string.swg
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/include/svn_string.swg?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/include/svn_string.swg (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/include/svn_string.swg Sun Oct 29
03:37:37 2017
@@ -31,6 +31,9 @@ typedef struct svn_string_t svn_string_t
    because we only refer to the ->data and ->len values.
 */
 #ifdef SWIGPYTHON
+
+#include <py3c.h>
+
 %typemap(argout) RET_STRING {
     PyObject *s;
     if (*$1 == NULL) {
@@ -38,7 +41,7 @@ typedef struct svn_string_t svn_string_t
         s = Py_None;
     }
     else {
-        s = PyString_FromStringAndSize((*$1)->data, (*$1)->len);
+        s = PyStr_FromStringAndSize((*$1)->data, (*$1)->len);
         if (s == NULL)
             SWIG_fail;
     }
@@ -75,14 +78,17 @@ typedef struct svn_string_t svn_string_t
 
 #ifdef SWIGPYTHON
 %typemap(in) svn_stringbuf_t * {
-    if (!PyString_Check($input)) {
+    if (!PyStr_Check($input)) {
         PyErr_SetString(PyExc_TypeError, "not a string");
         SWIG_fail;
     }
-    $1 = svn_stringbuf_ncreate(PyString_AS_STRING($input),
-                               PyString_GET_SIZE($input),
-                               /* ### gah... what pool to use? */
-                               _global_pool);
+    {
+      Py_ssize_t strBufLen;
+      const char *strBufChar = PyStr_AsUTF8AndSize($input, &strBufLen);
+      $1 = svn_stringbuf_ncreate(strBufChar, strBufLen,
+                                 /* ### gah... what pool to use? */
+                                 _global_pool);
+    }
 }
 #endif
 
@@ -139,7 +145,7 @@ typedef struct svn_string_t svn_string_t
 
 #ifdef SWIGPYTHON
 %typemap(out) svn_stringbuf_t * {
-    $result = PyString_FromStringAndSize($1->data, $1->len);
+    $result = PyStr_FromStringAndSize($1->data, $1->len);
 }
 #endif
 
@@ -174,12 +180,13 @@ typedef struct svn_string_t svn_string_t
     if ($input == Py_None)
         $1 = NULL;
     else {
-        if (!PyString_Check($input)) {
+        Py_ssize_t pyStrLen;
+        if (!PyStr_Check($input)) {
             PyErr_SetString(PyExc_TypeError, "not a string");
             SWIG_fail;
         }
-        value.data = PyString_AS_STRING($input);
-        value.len = PyString_GET_SIZE($input);
+        value.data = PyStr_AsUTF8AndSize($input, &pyStrLen);
+        value.len = pyStrLen;
         $1 = &value;
     }
 }
@@ -223,7 +230,7 @@ typedef struct svn_string_t svn_string_t
 
 #ifdef SWIGPYTHON
 %typemap(out) svn_string_t * {
-    $result = PyString_FromStringAndSize($1->data, $1->len);
+    $result = PyStr_FromStringAndSize($1->data, $1->len);
 }
 #endif
 #ifdef SWIGPERL
@@ -253,7 +260,7 @@ typedef struct svn_string_t svn_string_t
         s = Py_None;
     }
     else {
-        s = PyString_FromString(*$1);
+        s = PyStr_FromString(*$1);
         if (s == NULL)
             SWIG_fail;
     }

Modified: subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg Sun Oct 29
03:37:37 2017
@@ -28,6 +28,10 @@
 %include svn_string.swg
 %include svn_containers.swg
 
+#ifdef SWIGPYTHON
+#include <py3c.h>
+#endif
+
 /* -----------------------------------------------------------------------
    Generic handling for "type **" parameters.  Almost all such parameters
    are OUTPUT parameters.  Handling is as follows:
@@ -463,12 +467,13 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
 */
 #ifdef SWIGPYTHON
 %typemap(in) (const char *PTR, apr_size_t LEN) {
-    if (!PyString_Check($input)) {
+    Py_ssize_t pyStrLen;
+    if (!PyStr_Check($input)) {
         PyErr_SetString(PyExc_TypeError, "expecting a string");
         SWIG_fail;
     }
-    $1 = PyString_AS_STRING($input);
-    $2 = PyString_GET_SIZE($input);
+    $1 = PyStr_AsUTF8AndSize($input, &pyStrLen);
+    $2 = pyStrLen;
 }
 #endif
 
@@ -1093,7 +1098,7 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
 #ifdef SWIGPYTHON
 %typemap(argout) unsigned char digest[ANY]
 {
-  %append_output(PyString_FromStringAndSize((char *)$1, APR_MD5_DIGESTSIZE));
+  %append_output(PyStr_FromStringAndSize((const char *)$1, APR_MD5_DIGESTSIZE));
 }
 #endif
 
@@ -1166,7 +1171,7 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
     if ($input == Py_None) {
         $1 = NULL;
     } else {
-        $1 = (unsigned char *) PyString_AsString($input);
+        $1 = (unsigned char *) PyStr_AsString($input);
         if ($1 == NULL) SWIG_fail;
     }
 }

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=1813665&r1=1813664&r2=1813665&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
Sun Oct 29 03:37:37 2017
@@ -26,6 +26,8 @@
 
 #include <Python.h>
 
+#include <py3c.h>
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -142,6 +144,30 @@ apr_status_t svn_swig_py_initialize(void
   return APR_SUCCESS;
 }
 
+FILE *svn_swig_py_as_file(PyObject *pyfile)
+{
+#if IS_PY3
+  FILE *fp = NULL;
+  int fd = PyFile_AsFileDescriptor(pyfile);
+  if (fd >= 0)
+    {
+      PyObject *mode_obj = PyObject_GetAttrString(pyfile, "mode");
+      PyObject *mode_byte_obj = PyUnicode_AsUTF8String(mode_obj);
+      char *mode = PyBytes_AsString(mode_byte_obj);
+
+      if (mode)
+        fp = fdopen(fd, mode);
+
+      Py_DECREF(mode_obj);
+      Py_DECREF(mode_byte_obj);
+    }
+
+  return fp;
+#else
+  return PyFile_AsFile(pyfile);
+#endif
+}
+
 int svn_swig_py_get_pool_arg(PyObject *args, swig_type_info *type,
     PyObject **py_pool, apr_pool_t **pool)
 {
@@ -370,14 +396,14 @@ void svn_swig_py_svn_exception(svn_error
           Py_INCREF(Py_None);
           message_ob = Py_None;
         }
-      else if ((message_ob = PyString_FromString(err->message)) == NULL)
+      else if ((message_ob = PyStr_FromString(err->message)) == NULL)
         goto finished;
       if (err->file == NULL)
         {
           Py_INCREF(Py_None);
           file_ob = Py_None;
         }
-      else if ((file_ob = PyString_FromString(err->file)) == NULL)
+      else if ((file_ob = PyStr_FromString(err->file)) == NULL)
         goto finished;
       if ((line_ob = PyInt_FromLong(err->line)) == NULL)
         goto finished;
@@ -476,23 +502,23 @@ static char *make_string_from_ob(PyObjec
 {
   if (ob == Py_None)
     return NULL;
-  if (! PyString_Check(ob))
+  if (! PyStr_Check(ob))
     {
       PyErr_SetString(PyExc_TypeError, "not a string");
       return NULL;
     }
-  return apr_pstrdup(pool, PyString_AS_STRING(ob));
+  return apr_pstrdup(pool, PyStr_AsString(ob));
 }
 static svn_string_t *make_svn_string_from_ob(PyObject *ob, apr_pool_t *pool)
 {
   if (ob == Py_None)
     return NULL;
-  if (! PyString_Check(ob))
+  if (! PyStr_Check(ob))
     {
       PyErr_SetString(PyExc_TypeError, "not a string");
       return NULL;
     }
-  return svn_string_create(PyString_AS_STRING(ob), pool);
+  return svn_string_create(PyStr_AsString(ob), pool);
 }
 
 
@@ -552,8 +578,7 @@ static PyObject *convert_svn_string_t(vo
 
   const svn_string_t *s = value;
 
-  /* ### gotta cast this thing cuz Python doesn't use "const" */
-  return PyString_FromStringAndSize((void *)s->data, s->len);
+  return PyStr_FromStringAndSize(s->data, s->len);
 }
 
 /* Convert a C string into a Python String object (or a reference to
@@ -566,7 +591,7 @@ static PyObject *cstring_to_pystring(con
       Py_INCREF(Py_None);
       return retval;
     }
-  return PyString_FromString(cstring);
+  return PyStr_FromString(cstring);
 }
 
 static PyObject *convert_svn_client_commit_item3_t(void *value, void *ctx)
@@ -642,8 +667,7 @@ PyObject *svn_swig_py_prophash_to_dict(a
 static PyObject *convert_string(void *value, void *ctx,
                                 PyObject *py_pool)
 {
-  /* ### gotta cast this thing cuz Python doesn't use "const" */
-  return PyString_FromString((const char *)value);
+  return PyStr_FromString((const char *)value);
 }
 
 PyObject *svn_swig_py_stringhash_to_dict(apr_hash_t *hash)
@@ -725,7 +749,7 @@ svn_swig_py_propinheriteditemarray_to_di
         apr_hash_t *prop_hash = prop_inherited_item->prop_hash;
         PyObject *py_key, *py_value;
 
-        py_key = PyString_FromString(prop_inherited_item->path_or_url);
+        py_key = PyStr_FromString(prop_inherited_item->path_or_url);
         if (py_key == NULL)
           goto error;
 
@@ -769,7 +793,7 @@ PyObject *svn_swig_py_proparray_to_dict(
 
         prop = APR_ARRAY_IDX(array, i, svn_prop_t);
 
-        py_key = PyString_FromString(prop.name);
+        py_key = PyStr_FromString(prop.name);
         if (py_key == NULL)
           goto error;
 
@@ -780,8 +804,8 @@ PyObject *svn_swig_py_proparray_to_dict(
           }
         else
           {
-             py_value = PyString_FromStringAndSize((void *)prop.value->data,
-                                                   prop.value->len);
+             py_value = PyStr_FromStringAndSize(prop.value->data,
+                                                prop.value->len);
              if (py_value == NULL)
                {
                  Py_DECREF(py_key);
@@ -831,7 +855,7 @@ PyObject *svn_swig_py_locationhash_to_di
             Py_DECREF(dict);
             return NULL;
           }
-        value = PyString_FromString((char *)v);
+        value = PyStr_FromString((const char *)v);
         if (value == NULL)
           {
             Py_DECREF(key);
@@ -895,7 +919,7 @@ PyObject *svn_swig_py_c_strings_to_list(
 
     while ((s = *strings++) != NULL)
       {
-        PyObject *ob = PyString_FromString(s);
+        PyObject *ob = PyStr_FromString(s);
 
         if (ob == NULL)
             goto error;
@@ -1252,7 +1276,7 @@ svn_swig_py_unwrap_string(PyObject *sour
                           void *baton)
 {
     const char **ptr_dest = destination;
-    *ptr_dest = PyString_AsString(source);
+    *ptr_dest = PyStr_AsString(source);
 
     if (*ptr_dest != NULL)
         return 0;
@@ -1371,7 +1395,7 @@ PyObject *svn_swig_py_array_to_list(cons
     for (i = 0; i < array->nelts; ++i)
       {
         PyObject *ob =
-          PyString_FromString(APR_ARRAY_IDX(array, i, const char *));
+          PyStr_FromString(APR_ARRAY_IDX(array, i, const char *));
         if (ob == NULL)
           goto error;
         PyList_SET_ITEM(list, i, ob);
@@ -1446,13 +1470,13 @@ static svn_error_t *exception_to_error(P
 
     if ((message_ob = PyObject_GetAttrString(exc, "message")) == NULL)
         goto finished;
-    message = PyString_AsString(message_ob);
+    message = PyStr_AsString(message_ob);
     if (PyErr_Occurred()) goto finished;
 
     if ((file_ob = PyObject_GetAttrString(exc, "file")) == NULL)
         goto finished;
     if (file_ob != Py_None)
-        file = PyString_AsString(file_ob);
+        file = PyStr_AsString(file_ob);
     if (PyErr_Occurred()) goto finished;
 
     if ((line_ob = PyObject_GetAttrString(exc, "line")) == NULL)
@@ -2436,10 +2460,10 @@ apr_file_t *svn_swig_py_make_file(PyObje
   if (py_file == NULL || py_file == Py_None)
     return NULL;
 
-  if (PyString_Check(py_file))
+  if (PyStr_Check(py_file))
     {
       /* input is a path -- just open an apr_file_t */
-      char* fname = PyString_AS_STRING(py_file);
+      char* fname = PyStr_AsString(py_file);
       apr_err = apr_file_open(&apr_file, fname,
                               APR_CREATE | APR_READ | APR_WRITE,
                               APR_OS_DEFAULT, pool);
@@ -2452,25 +2476,26 @@ apr_file_t *svn_swig_py_make_file(PyObje
           return NULL;
         }
     }
-  else if (PyFile_Check(py_file))
+  else
     {
-      FILE *file;
-      apr_os_file_t osfile;
+      FILE *file = svn_swig_py_as_file(py_file);
 
       /* input is a file object -- convert to apr_file_t */
-      file = PyFile_AsFile(py_file);
+      if (file != NULL)
+        {
 #ifdef WIN32
-      osfile = (apr_os_file_t)_get_osfhandle(_fileno(file));
+          apr_os_file_t osfile = (apr_os_file_t)_get_osfhandle(_fileno(file));
 #else
-      osfile = (apr_os_file_t)fileno(file);
+          apr_os_file_t osfile = (apr_os_file_t)fileno(file);
 #endif
-      apr_err = apr_os_file_put(&apr_file, &osfile, O_CREAT | O_WRONLY, pool);
-      if (apr_err)
-        {
-          char buf[256];
-          apr_strerror(apr_err, buf, sizeof(buf));
-          PyErr_Format(PyExc_IOError, "apr_os_file_put failed: %s", buf);
-          return NULL;
+          apr_err = apr_os_file_put(&apr_file, &osfile, O_CREAT | O_WRONLY, pool);
+          if (apr_err)
+            {
+              char buf[256];
+              apr_strerror(apr_err, buf, sizeof(buf));
+              PyErr_Format(PyExc_IOError, "apr_os_file_put failed: %s", buf);
+              return NULL;
+            }
         }
     }
   return apr_file;
@@ -2482,7 +2507,6 @@ read_handler_pyio(void *baton, char *buf
 {
   PyObject *result;
   PyObject *py_io = baton;
-  apr_size_t bytes;
   svn_error_t *err = SVN_NO_ERROR;
 
   if (py_io == Py_None)
@@ -2499,10 +2523,16 @@ read_handler_pyio(void *baton, char *buf
     {
       err = callback_exception_error();
     }
-  else if (PyString_Check(result))
+  else if (PyStr_Check(result))
     {
-      bytes = PyString_GET_SIZE(result);
-      if (bytes > *len)
+      Py_ssize_t bytes;
+      const char *result_str = PyStr_AsUTF8AndSize(result, &bytes);
+
+      if (result_str == NULL)
+        {
+          err = callback_exception_error();
+        }
+      else if (bytes > *len)
         {
           err = callback_bad_return_error("Too many bytes");
         }
@@ -2510,7 +2540,7 @@ read_handler_pyio(void *baton, char *buf
         {
           /* Writeback, in case this was a short read, indicating EOF */
           *len = bytes;
-          memcpy(buffer, PyString_AS_STRING(result), *len);
+          memcpy(buffer, result_str, *len);
         }
     }
   else
@@ -2948,9 +2978,9 @@ svn_error_t *svn_swig_py_get_commit_log_
       *log_msg = NULL;
       err = SVN_NO_ERROR;
     }
-  else if (PyString_Check(result))
+  else if (PyStr_Check(result))
     {
-      *log_msg = apr_pstrdup(pool, PyString_AS_STRING(result));
+      *log_msg = apr_pstrdup(pool, PyStr_AsString(result));
       Py_DECREF(result);
       err = SVN_NO_ERROR;
     }
@@ -3852,9 +3882,9 @@ ra_callbacks_get_wc_prop(void *baton,
     }
   else if (result != Py_None)
     {
-      char *buf;
       Py_ssize_t len;
-      if (PyString_AsStringAndSize(result, &buf, &len) == -1)
+      const char *buf = PyStr_AsUTF8AndSize(result, &len);
+      if (buf == NULL)
         {
           err = callback_exception_error();
         }
@@ -3897,7 +3927,7 @@ ra_callbacks_push_or_set_wc_prop(const c
       goto finished;
     }
 
-  if ((py_value = PyString_FromStringAndSize(value->data, value->len)) == NULL)
+  if ((py_value = PyStr_FromStringAndSize(value->data, value->len)) == NULL)
     {
       err = callback_exception_error();
       goto finished;
@@ -4096,7 +4126,7 @@ ra_callbacks_get_client_string(void *bat
     }
   else if (result != Py_None)
     {
-      if ((*name = PyString_AsString(result)) == NULL)
+      if ((*name = PyStr_AsString(result)) == NULL)
         {
           err = callback_exception_error();
         }

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h
(original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h
Sun Oct 29 03:37:37 2017
@@ -50,6 +50,12 @@ extern "C" {
 apr_status_t svn_swig_py_initialize(void);
 
 
+/* Returns the provided python object as a FILE *object.
+ * Return the underlying FILE or NULL if the object is not a File instance.
+ */
+FILE *svn_swig_py_as_file(PyObject *pyfile);
+
+
 
 /* Functions to manage python's global interpreter lock */
 void svn_swig_py_release_py_lock(void);
@@ -226,7 +232,10 @@ svn_swig_py_seq_to_array(PyObject *seq,
                          apr_pool_t *pool);
 
 /* An svn_swig_py_object_unwrap_t that extracts a char pointer from a Python
-   string. */
+   string.
+
+   Note the lifetime of the returned string is tied to the provided Python
+   object. */
 int
 svn_swig_py_unwrap_string(PyObject *source,
                           void *destination,

Modified: subversion/branches/swig-py3/subversion/bindings/swig/svn_client.i
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/svn_client.i?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/svn_client.i (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/svn_client.i Sun Oct 29 03:37:37
2017
@@ -34,6 +34,11 @@
 %import svn_delta.i
 %import svn_wc.i
 
+#ifdef SWIGPYTHON
+%{
+#include <py3c.h>
+%}
+#endif
 /* Ignore platform-specific auth functions */
 %ignore svn_client_get_windows_simple_provider;
 
@@ -119,7 +124,7 @@
     ppitem = (svn_client_proplist_item_t **)(*$1)->elts;
     for (i = 0; i < nelts; ++i, ++ppitem) {
         PyObject *item = PyTuple_New(2);
-        PyObject *name = PyString_FromStringAndSize((*ppitem)->node_name->data,
+        PyObject *name = PyStr_FromStringAndSize((*ppitem)->node_name->data,
                                                     (*ppitem)->node_name->len);
         PyObject *hash = svn_swig_py_prophash_to_dict((*ppitem)->prop_hash);
 

Modified: subversion/branches/swig-py3/subversion/bindings/swig/svn_delta.i
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/svn_delta.i?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/svn_delta.i (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/svn_delta.i Sun Oct 29 03:37:37
2017
@@ -32,6 +32,12 @@
 %include svn_global.swg
 %import core.i
 
+#ifdef SWIGPYTHON
+%{
+#include <py3c.h>
+%}
+#endif
+
 #ifdef SWIGRUBY
 %ignore svn_compat_wrap_file_rev_handler;
 #endif

Modified: subversion/branches/swig-py3/subversion/bindings/swig/svn_diff.i
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/svn_diff.i?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/svn_diff.i (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/svn_diff.i Sun Oct 29 03:37:37 2017
@@ -32,6 +32,12 @@
 %include svn_global.swg
 %import core.i
 
+#ifdef SWIGPYTHON
+%{
+#include <py3c.h>
+%}
+#endif
+
 /* -----------------------------------------------------------------------
    %apply-ing of typemaps defined elsewhere
 */

Modified: subversion/branches/swig-py3/subversion/bindings/swig/svn_fs.i
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/svn_fs.i?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/svn_fs.i (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/svn_fs.i Sun Oct 29 03:37:37 2017
@@ -33,6 +33,12 @@
 %import core.i
 %import svn_delta.i
 
+#ifdef SWIGPYTHON
+%{
+#include <py3c.h>
+%}
+#endif
+
 /* -----------------------------------------------------------------------
    do not generate any constructors or destructors (of structures) -- all
    structures are going to come /out/ of the FS (so we don't need to

Modified: subversion/branches/swig-py3/subversion/bindings/swig/svn_ra.i
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/svn_ra.i?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/svn_ra.i (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/svn_ra.i Sun Oct 29 03:37:37 2017
@@ -33,6 +33,12 @@
 %import core.i
 %import svn_delta.i
 
+#ifdef SWIGPYTHON
+%{
+#include <py3c.h>
+%}
+#endif
+
 /* Bad pool convention, also these are not public interfaces, they were
    simply placed in the public header by mistake. */
 %ignore svn_ra_svn_init;

Modified: subversion/branches/swig-py3/subversion/bindings/swig/svn_repos.i
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/svn_repos.i?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/svn_repos.i (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/svn_repos.i Sun Oct 29 03:37:37
2017
@@ -34,6 +34,12 @@
 %import svn_delta.i
 %import svn_fs.i
 
+#ifdef SWIGPYTHON
+%{
+#include <py3c.h>
+%}
+#endif
+
 /* -----------------------------------------------------------------------
    %apply-ing of typemaps defined elsewhere
 */

Modified: subversion/branches/swig-py3/subversion/bindings/swig/svn_wc.i
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/svn_wc.i?rev=1813665&r1=1813664&r2=1813665&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/svn_wc.i (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/svn_wc.i Sun Oct 29 03:37:37 2017
@@ -34,6 +34,12 @@
 %import svn_delta.i
 %import svn_ra.i
 
+#ifdef SWIGPYTHON
+%{
+#include <py3c.h>
+%}
+#endif
+
 /* -----------------------------------------------------------------------
    ### these functions require a pool, which we don't have immediately
    ### handy. just eliminate these funcs for now.



Mime
View raw message