Author: jun66j5
Date: Wed Oct 23 10:36:30 2024
New Revision: 1921505
URL: http://svn.apache.org/viewvc?rev=1921505&view=rev
Log:
Make swig-py compatible with SWIG 4.3.0.
* subversion/bindings/swig/include/svn_types.swg
(%typemap(out) svn_error_t *):
Initialize `$result` with an empty list for the workaround to
`%append_output` incorrectly handling for None and a list in Python.
(%typemap(ret) svn_error_t *):
Use first entry for `$result` when the size of the `$result` list is 1.
(%typemap(ret) svn_error_t * SVN_ERR_WITH_ATTRS):
Ditto.
* subversion/bindings/swig/python/svn/fs.py
(svn_fs_commit_txn):
Removed because multiple values are correctly retrieved from SWIG methods
now.
* subversion/bindings/swig/python/tests/client.py
(test_checkout, test_update4):
Check `TypeError` when a NULL pointer passed since SWIG 4.3.0.
* subversion/bindings/swig/python/tests/core.py
(test_svn_rangelist_diff):
Added tests for the workaround for `%append_output` incorrectly handling.
Modified:
subversion/trunk/subversion/bindings/swig/include/svn_types.swg
subversion/trunk/subversion/bindings/swig/python/svn/fs.py
subversion/trunk/subversion/bindings/swig/python/tests/client.py
subversion/trunk/subversion/bindings/swig/python/tests/core.py
Modified: subversion/trunk/subversion/bindings/swig/include/svn_types.swg
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/include/svn_types.swg?rev=1921505&r1=1921504&r2=1921505&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/include/svn_types.swg (original)
+++ subversion/trunk/subversion/bindings/swig/include/svn_types.swg Wed Oct 23
10:36:30 2024
@@ -435,8 +435,8 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
svn_error_clear($1);
SWIG_fail;
}
- Py_INCREF(Py_None);
- $result = Py_None;
+ Py_XDECREF($result);
+ $result = PyList_New(0);
}
%typemap(out) svn_error_t * SVN_ERR_WITH_ATTRS (apr_status_t apr_err,
@@ -470,11 +470,31 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
SWIG_fail;
}
}
- else
- {
- Py_INCREF(Py_None);
- $result = Py_None;
+ Py_XDECREF($result);
+ $result = PyList_New(0);
+}
+
+%typemap(ret) svn_error_t * {
+ if ($result == NULL) {
+ $result = Py_None;
+ Py_INCREF($result);
+ }
+ else {
+ switch (PyList_Size($result)) {
+ case 0:
+ $result = Py_None;
+ Py_INCREF($result);
+ break;
+ case 1:
+ {
+ PyObject *tmp = $result;
+ $result = PyList_GetItem(tmp, 0);
+ Py_INCREF($result);
+ Py_DECREF(tmp);
+ }
+ break;
}
+ }
}
%typemap(ret) svn_error_t * SVN_ERR_WITH_ATTRS {
@@ -486,6 +506,7 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
Py_XDECREF($result);
SWIG_fail;
}
+ $typemap(ret, svn_error_t *);
}
#endif
Modified: subversion/trunk/subversion/bindings/swig/python/svn/fs.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/svn/fs.py?rev=1921505&r1=1921504&r2=1921505&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/svn/fs.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/svn/fs.py Wed Oct 23
10:36:30 2024
@@ -25,34 +25,6 @@
import errno
from libsvn.fs import *
-
-######################################################################
-# Any adjustment of SWIG generated wrapper functions on svn.fs module
-# should be placed before adding alternative names for them.
-
-# fs.commit_txn() should return a 2-tupple of conflict_p and new_rev.
-# However if conflict_p is None, SWIG generated wrapper function
-# libsvn.fs.svn_fs_commit_txn returns an integer value of new_rev.
-# This is a bug of SWIG generated wrapper function, so we fix it here.
-#
-# (There was discussion about this behavior because C API
-# svn_fs_commit_txn() always set NULL to conflict_p if it returns
-# SVN_NO_ERROR and so it seems to be reasonable that fs.commit_txn()
-# returns only rev_new value. However for compatibility, we decided
-# that fs.commit_txn always returns 2-tuple if it does not raises
-# an exception.)
-
-_svn_fs_commit_txn = svn_fs_commit_txn
-
-def svn_fs_commit_txn(*args):
- r"""svn_fs_commit_txn(svn_fs_txn_t txn, apr_pool_t pool) -> svn_error_t"""
- ret = _svn_fs_commit_txn(*args)
- if not isinstance(ret, tuple):
- ret = (None, ret)
- return ret
-
-######################################################################
-
from svn.core import _unprefix_names, Pool, _as_list
_unprefix_names(locals(), 'svn_fs_')
_unprefix_names(locals(), 'SVN_FS_')
Modified: subversion/trunk/subversion/bindings/swig/python/tests/client.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/client.py?rev=1921505&r1=1921504&r2=1921505&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/client.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/client.py Wed Oct 23
10:36:30 2024
@@ -172,7 +172,9 @@ class SubversionClientTestCase(unittest.
path = self.temper.alloc_empty_dir('-checkout')
- self.assertRaises(ValueError, client.checkout2,
+ # TypeError is raised since SWIG 4.3.0
+ self.assertRaises((ValueError, TypeError), r'Received a NULL pointer',
+ client.checkout2,
self.repos_uri, path, None, None, True, True,
self.client_ctx)
@@ -579,7 +581,9 @@ class SubversionClientTestCase(unittest.
path = self.temper.alloc_empty_dir('-update')
- self.assertRaises(ValueError, client.checkout2,
+ # TypeError is raised since SWIG 4.3.0
+ self.assertRaises((ValueError, TypeError), r'Received a NULL pointer',
+ client.checkout2,
self.repos_uri, path, None, None, True, True,
self.client_ctx)
Modified: subversion/trunk/subversion/bindings/swig/python/tests/core.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/core.py?rev=1921505&r1=1921504&r2=1921505&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/core.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/core.py Wed Oct 23
10:36:30 2024
@@ -348,6 +348,35 @@ class SubversionCoreTestCase(unittest.Te
finally:
svn.core.svn_stream_close(stream)
+ def test_svn_rangelist_diff(self):
+ """
+ SWIG incorrectly handles return values when the first %append_output() is
+ invoked with a list instance. svn.core.svn_rangelist_diff() is in the case.
+ We test whether the workaround for it is working.
+ """
+
+ def from_args(start, end, inheritable):
+ instance = svn.core.svn_merge_range_t()
+ instance.start = start
+ instance.end = end
+ instance.inheritable = inheritable
+ return instance
+
+ def to_args(instance):
+ return [instance.start, instance.end, instance.inheritable]
+
+ def map_list(f, iterator):
+ return list(map(f, iterator))
+
+ from_ = [from_args(4, 5, True), from_args(9, 13, True)]
+ to = [from_args(7, 11, True)]
+ rv = svn.core.svn_rangelist_diff(from_, to, True)
+ self.assertIsInstance(rv, (list, tuple))
+ deleted, added = rv
+ self.assertEqual([[7, 9, True]], map_list(to_args, added))
+ self.assertEqual([[4, 5, True], [11, 13, True]],
+ map_list(to_args, deleted))
+
def suite():
return unittest.defaultTestLoader.loadTestsFromTestCase(