subversion-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yasuhito FUTATSUKI <futat...@poem.co.jp>
Subject Re: [swig-py3][patch] interfacing bytes object instead of str
Date Thu, 22 Nov 2018 11:16:16 GMT
Thank you to respond to me.

It seems svn_stream_readline() works as I expected, eol argment accept
bytes, and returns bytes. (the patch below contains fix for
svn_stream_write() which is incomplete in my previous patch)

On 11/22/18 9:57 AM, Daniel Shahaf wrote:
> Yasuhito FUTATSUKI wrote on Thu, 22 Nov 2018 08:05 +0900:

>> Even with this patch, svn_stream_readline() doesn't work well.
>> It claims 2nd argment is not bytes object, and returns str object.
>>
>> I think it is better that svn_stream_readlin() returns bytes too.
>>
> 
> +1.  That function should return bytes, and as no swig-py consumers are
> written in py3 there are no compatibility concerns preventing us from
> making it so.

Now ViewVC (un-official branch) works with swig-py on py3 :-)
(https://github.com/futatuki/viewvc/tree/python3_support_with_altsvn)


By the way, while I've read headers, I found some other APIs handle
'eol' argment, in svn_subst.h and svn_diff.h. I think some of them
might need to handle some argment as bytes, because str on py3 normalize
eol style.


diff --git a/subversion/bindings/swig/core.i b/subversion/bindings/swig/core.i
index be5434dc20..0af5faa4ee 100644
--- a/subversion/bindings/swig/core.i
+++ b/subversion/bindings/swig/core.i
@@ -444,9 +444,9 @@
  */
  #ifdef SWIGPYTHON
  %typemap(in) (const char *data, apr_size_t *len) ($*2_type temp) {
-    if (!PyStr_Check($input)) {
+    if (!PyBytes_Check($input)) {
          PyErr_SetString(PyExc_TypeError,
-                        "expecting a string for the buffer");
+                        "expecting a bytes for the buffer");
          SWIG_fail;
      }
      if (PyBytes_AsStringAndSize($input, &$1, &temp) == -1) {
@@ -488,6 +488,39 @@
  }
  #endif
  
+/* -----------------------------------------------------------------------
+   fix up the svn_stream_readline() eol argument
+*/
+#ifdef SWIGPYTHON
+%typemap(in) (const char *eol) {
+    if (!PyBytes_Check($input)) {
+        PyErr_SetString(PyExc_TypeError,
+                        "expecting a bytes for the eol");
+        SWIG_fail;
+    }
+    $1 = PyBytes_AsString($input);
+}
+#endif
+
+/* -----------------------------------------------------------------------
+   fix up the svn_stream_readline() return value
+*/
+#ifdef SWIGPYTHON
+%typemap(argout) (svn_stringbuf_t **stringbuf, const char *eol) {
+    PyObject *s;
+    if (*$1 == NULL) {
+        Py_INCREF(Py_None);
+        s = Py_None;
+    }
+    else {
+        s = PyBytes_FromStringAndSize((*$1)->data, (*$1)->len);
+        if (s == NULL)
+            SWIG_fail;
+    }
+    %append_output(s);
+}
+#endif
+
  /* -----------------------------------------------------------------------
     auth parameter set/get
  */

-- 
Yasuhito FUTATSUKI

Mime
View raw message