mirror of https://github.com/swig/swig
Support JDK 21 and std::list
Fixes removeFirst() and removeLast() incompatibilities with methods of the same name in the Java base class java.util.AbstractSequentialList which were added in JDK 21 as part of JEP-431. configure.ac has been modified to detect the version of JDK/Java for use in testing the test-suite via the JAVA_VERSION_MAJOR variable. Needed to continue testing removeFirst(), removeLast(), addFirst(), addLast(). Closes #3156
This commit is contained in:
parent
83be871eec
commit
ef0d38bffd
|
@ -7,6 +7,26 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.4.0 (in progress)
|
||||
===========================
|
||||
|
||||
2025-04-02: wsfulton
|
||||
[Java] #3156 Support JDK 21 and std::list. Fixes removeFirst() and removeLast()
|
||||
incompatibilities with methods of the same name in the base class,
|
||||
AbstractSequentialList, which were added in JDK 21 with a different
|
||||
return type. The addFirst() and addLast() methods were also added, all part
|
||||
of JEP-431 Sequenced Collections, see https://openjdk.org/jeps/431.
|
||||
|
||||
If these 4 methods are needed, as SWIG previously generated them, then add
|
||||
the following to your interface file after %include <std_list.i>:
|
||||
|
||||
%extend std::list {
|
||||
void removeLast() { $self->pop_back(); }
|
||||
void removeFirst() { $self->pop_front(); }
|
||||
void addLast(const T &value) { $self->push_back(value); }
|
||||
void addFirst(const T &value) { $self->push_front(value); }
|
||||
}
|
||||
|
||||
But note that this will give javac compiler errors when using JDK 21 and
|
||||
later for removeFirst() and removeLast().
|
||||
|
||||
2025-04-02: wsfulton
|
||||
[Java] Fix javac -Xlint warning (JDK 21):
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ JAVA = @JAVA@
|
|||
JAVAC = @JAVAC@
|
||||
JAVAFLAGS = @JAVAFLAGS@
|
||||
JAVAC_OPTIONS = @JAVAC_OPTIONS@
|
||||
JAVA_VERSION_MAJOR = @JAVA_VERSION_MAJOR@
|
||||
JAVA_CLASSPATH_SEP = @JAVA_CLASSPATH_SEP@
|
||||
SCRIPTSUFFIX = _runme.java
|
||||
SKIP_DOXYGEN_TEST_CASES = @JAVA_SKIP_DOXYGEN_TEST_CASES@
|
||||
|
@ -77,6 +78,7 @@ SRCDIR = ../$(srcdir)/
|
|||
JAVA_PACKAGE = $*
|
||||
JAVA_PACKAGEOPT = -package $(JAVA_PACKAGE)
|
||||
SWIGOPT += $(JAVA_PACKAGEOPT)
|
||||
SWIGOPT += -DJAVA_VERSION_MAJOR=$(JAVA_VERSION_MAJOR)
|
||||
|
||||
# Ensure testsuite remains free from SWIG warnings.
|
||||
SWIGOPT += -Werror
|
||||
|
|
|
@ -9,6 +9,18 @@
|
|||
#include <numeric>
|
||||
%}
|
||||
|
||||
#if defined(SWIGJAVA) && JAVA_VERSION_MAJOR < 21
|
||||
// Test these methods which were removed in swig-4.0 as JDK added the same methods
|
||||
// in the java.util.AbstractSequentialList base but unfortunately two of them use
|
||||
// a different return type.
|
||||
%extend std::list {
|
||||
void removeLast() { $self->pop_back(); }
|
||||
void removeFirst() { $self->pop_front(); }
|
||||
void addLast(const T &value) { $self->push_back(value); }
|
||||
void addFirst(const T &value) { $self->push_front(value); }
|
||||
}
|
||||
#endif
|
||||
|
||||
%template(BoolList) std::list<bool>;
|
||||
%template(CharList) std::list<char>;
|
||||
%template(ShortList) std::list<short>;
|
||||
|
|
|
@ -22,6 +22,7 @@ SWIGINTERN jint SWIG_ListSize(size_t size) {
|
|||
}
|
||||
}
|
||||
|
||||
%javamethodmodifiers std::list::push_back "private";
|
||||
%javamethodmodifiers std::list::begin "private";
|
||||
%javamethodmodifiers std::list::insert "private";
|
||||
%javamethodmodifiers std::list::doSize "private";
|
||||
|
@ -54,7 +55,7 @@ namespace std {
|
|||
}
|
||||
|
||||
public boolean add($typemap(jboxtype, T) value) {
|
||||
addLast(value);
|
||||
push_back(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -185,14 +186,7 @@ namespace std {
|
|||
void clear();
|
||||
%rename(remove) erase;
|
||||
iterator erase(iterator pos);
|
||||
%rename(removeLast) pop_back;
|
||||
void pop_back();
|
||||
%rename(removeFirst) pop_front;
|
||||
void pop_front();
|
||||
%rename(addLast) push_back;
|
||||
void push_back(const T &value);
|
||||
%rename(addFirst) push_front;
|
||||
void push_front(const T &value);
|
||||
iterator begin();
|
||||
iterator end();
|
||||
iterator insert(iterator pos, const T &value);
|
||||
|
|
38
configure.ac
38
configure.ac
|
@ -1017,31 +1017,25 @@ else
|
|||
JAVAC="$JAVACBIN"
|
||||
fi
|
||||
|
||||
# Check Java version: we require Java 9 or later for Doxygen tests.
|
||||
if test -n "$JAVAC"; then
|
||||
AC_MSG_CHECKING(if java version is 9 or greater)
|
||||
javac_version=`"$JAVAC" -version 2>&1`
|
||||
java_version_num=`echo $javac_version | sed -n 's/^javac //p'`
|
||||
if test -z "$java_version_num"; then
|
||||
AC_MSG_WARN([unknown format for Java version returned by "$JAVAC" ($javac_version)])
|
||||
JAVA_SKIP_DOXYGEN_TEST_CASES=1
|
||||
AC_MSG_RESULT(unknown)
|
||||
else
|
||||
dnl Until Java 8 version number was in format "1.x", starting from
|
||||
dnl Java 9 it's just "x".
|
||||
case $java_version_num in
|
||||
1.*)
|
||||
JAVA_SKIP_DOXYGEN_TEST_CASES=1
|
||||
AC_MSG_RESULT([no, disabling Doxygen tests])
|
||||
;;
|
||||
AC_MSG_CHECKING(java major version)
|
||||
javac_version=`"$JAVAC" -version 2>&1`
|
||||
java_version_num=`echo $javac_version | sed -n 's/^javac //p'`
|
||||
JAVA_VERSION_MAJOR="1"
|
||||
if test -n "$java_version_num"; then
|
||||
dnl Until Java 8 version number was in format "1.x.y_z", starting from Java 9 it's "x.y.z".
|
||||
JAVA_VERSION_MAJOR=[$(echo "$java_version_num" | sed -e "s/^1\.//" | sed -e "s/^\([0-9]\+\)\..*/\1/")]
|
||||
fi
|
||||
AC_MSG_RESULT([$JAVA_VERSION_MAJOR])
|
||||
|
||||
*)
|
||||
AC_MSG_RESULT(yes)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
# Check Java version: we require Java 9 or later for Doxygen tests.
|
||||
JAVA_SKIP_DOXYGEN_TEST_CASES=
|
||||
if test "$JAVA_VERSION_MAJOR" -le "8"; then
|
||||
JAVA_SKIP_DOXYGEN_TEST_CASES="1"
|
||||
fi
|
||||
|
||||
AC_SUBST(JAVA_SKIP_DOXYGEN_TEST_CASES)
|
||||
AC_SUBST(JAVA_VERSION_MAJOR)
|
||||
AC_SUBST(JAVA_SKIP_DOXYGEN_TEST_CASES)
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(for java include file jni.h)
|
||||
|
|
Loading…
Reference in New Issue