Last active
November 12, 2019 09:39
-
-
Save jun66j5/08b37b3c8bca8cea68068952ea9cc229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 0b5193e8415d0d1504e99dfa013c0886b697f5a3 | |
Author: Jun Omae <jun66j5@gmail.com> | |
Date: Tue Oct 29 13:06:55 2019 +0900 | |
Support building with SWIG 4 on Python 2 and 3 | |
diff --git a/build/ac-macros/swig.m4 b/build/ac-macros/swig.m4 | |
index 2fb5e49fb..358389bd0 100644 | |
--- a/build/ac-macros/swig.m4 | |
+++ b/build/ac-macros/swig.m4 | |
@@ -157,10 +157,13 @@ AC_DEFUN(SVN_FIND_SWIG, | |
ac_cv_python_is_py3="yes" | |
]) | |
+ SWIG_PY_OPTS="-python -nofastunpack" | |
if test "$ac_cv_python_is_py3" = "yes"; then | |
- SWIG_PY_OPTS="-python -py3" | |
+ SWIG_PY_OPTS="$SWIG_PY_OPTS -py3" | |
else | |
- SWIG_PY_OPTS="-python -classic" | |
+ if test "$SWIG_VERSION" -lt "400000"; then | |
+ SWIG_PY_OPTS="$SWIG_PY_OPTS -classic" | |
+ fi | |
fi | |
dnl SWIG Python bindings successfully configured, clear the error message | |
diff --git a/subversion/bindings/swig/include/proxy.py b/subversion/bindings/swig/include/proxy.py | |
index f97b7234a..73ff5ffda 100644 | |
--- a/subversion/bindings/swig/include/proxy.py | |
+++ b/subversion/bindings/swig/include/proxy.py | |
@@ -25,13 +25,6 @@ | |
return value | |
- # SWIG classes generated with -classic do not define this variable, | |
- # so set it to 0 when it doesn't exist | |
- try: | |
- _newclass | |
- except NameError: | |
- _newclass = 0 | |
- | |
# Attribute access must be intercepted to ensure that objects coming from | |
# read attribute access match those that are set with write attribute access. | |
# Specifically the metadata, such as the associated apr_pool object, should | |
@@ -58,13 +51,7 @@ | |
object.__getattribute__(self, 'assert_valid')() | |
- try: | |
- value = object.__getattribute__(self, name) | |
- except AttributeError: | |
- value = _swig_getattr(self, | |
- object.__getattribute__(self, '__class__'), | |
- name) | |
- | |
+ value = _get_instance_attr(self, name) | |
fn = object.__getattribute__(self, '_retrieve_swig_value') | |
return fn(name, value) | |
else: | |
@@ -85,4 +72,4 @@ | |
# SWIG-land | |
self.__dict__.setdefault("_members",{})[name] = value | |
- return _swig_setattr(self, self.__class__, name, value) | |
+ return _set_instance_attr(self, name, value) | |
diff --git a/subversion/bindings/swig/include/proxy.swg b/subversion/bindings/swig/include/proxy.swg | |
index bc9291313..1c7e3ac62 100644 | |
--- a/subversion/bindings/swig/include/proxy.swg | |
+++ b/subversion/bindings/swig/include/proxy.swg | |
@@ -64,7 +64,40 @@ | |
pass | |
else: | |
fn() | |
+ | |
+%} | |
+#if SWIG_VERSION >= 0x040000 | |
+%pythoncode %{ | |
+ # Only new-style classes feature is supported since SWIG 4, | |
+ # https://github.com/swig/swig/pull/1261 | |
+ _newclass = 1 | |
+ _set_instance_attr = _swig_setattr_nondynamic_instance_variable(object.__setattr__) | |
+ _get_instance_attr = object.__getattribute__ | |
+%} | |
+#else | |
+%pythoncode %{ | |
+ # SWIG classes generated with -classic do not define this variable, | |
+ # so set it to 0 when it doesn't exist | |
+ try: | |
+ _newclass | |
+ except NameError: | |
+ _newclass = 0 | |
+ | |
+ def _set_instance_attr(self, name, value): | |
+ return _swig_setattr(self, self.__class__, name, value) | |
+ | |
+ if _newclass: | |
+ def _get_instance_attr(self, name): | |
+ try: | |
+ return object.__getattribute__(self, name) | |
+ except AttributeError: | |
+ return _swig_getattr(self, object.__getattribute__(self, '__class__'), | |
+ name) | |
+ else: | |
+ def _get_instance_attr(self, name): | |
+ return _swig_getattr(self, self.__class__, name) | |
%} | |
+#endif | |
/* Default code for all wrapped proxy classes in Python. | |
* Inline the code from a separate file to avoid issues with |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment