diff --git a/.gitignore b/.gitignore index e94087e29..d2e6b841f 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,7 @@ CCache/ccache_swig_config.h CCache/config.h CCache/config.log CCache/config.status +CCache/config_win32.h Examples/Makefile Examples/d/example.mk Examples/guile/Makefile @@ -85,6 +86,8 @@ swig.spec # Build Artifacts .dirstamp CCache/ccache-swig +CCache/ccache-swig.1 +CCache/web/ccache-swig-man.html Lib/swigwarn.swg Source/CParse/parser.c Source/CParse/parser.h diff --git a/.travis.yml b/.travis.yml index 08b688425..6d80ba20e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,6 @@ matrix: env: SWIGLANG= sudo: required dist: trusty - - compiler: gcc - os: linux - env: SWIGLANG= - compiler: gcc os: linux env: SWIGLANG= @@ -55,15 +52,23 @@ matrix: - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=node VER=4 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=node VER=6 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=node VER=8 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=node VER=10 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=jsc @@ -164,6 +169,11 @@ matrix: env: SWIGLANG=python PY3=3 VER=3.5 sudo: required dist: trusty + - compiler: gcc + os: linux + env: SWIGLANG=python PY3=3 VER=3.6 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-builtin VER=2.6 @@ -174,6 +184,14 @@ matrix: env: SWIGLANG=python SWIG_FEATURES=-builtin sudo: required dist: trusty + - os: linux + env: SWIGLANG=python SWIG_FEATURES=-builtin SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP11=1 + sudo: required + dist: trusty + - os: linux + env: SWIGLANG=python SWIG_FEATURES=-builtin SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP11=1 PY3=3 VER=3.6 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.4 @@ -186,7 +204,12 @@ matrix: dist: trusty - compiler: gcc os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5 SWIGOPTPY3= + env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.6 + sudo: required + dist: trusty + - compiler: gcc + os: linux + env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.6 SWIGOPTPY3= sudo: required dist: trusty - compiler: gcc @@ -233,6 +256,10 @@ matrix: env: SWIGLANG=csharp SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 sudo: required dist: trusty + - os: linux + env: SWIGLANG=go SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 + sudo: required + dist: trusty - os: linux env: SWIGLANG=java SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 sudo: required @@ -241,14 +268,26 @@ matrix: env: SWIGLANG=python SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 sudo: required dist: trusty + - os: linux + env: SWIGLANG=r CPP11=1 # Note: making 'R CMD SHLIB' use a different compiler is non-trivial + sudo: required + dist: trusty - os: linux env: SWIGLANG=ruby SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 sudo: required dist: trusty + - os: linux + env: SWIGLANG=tcl SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 + sudo: required + dist: trusty - os: linux env: SWIGLANG=csharp SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP14=1 sudo: required dist: trusty + - os: linux + env: SWIGLANG=go SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP14=1 + sudo: required + dist: trusty - os: linux env: SWIGLANG=java SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP14=1 sudo: required @@ -261,6 +300,18 @@ matrix: env: SWIGLANG=ruby SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP14=1 sudo: required dist: trusty + - os: linux + env: SWIGLANG=tcl SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP14=1 + sudo: required + dist: trusty + - os: linux + env: SWIGLANG=java SWIG_CC=gcc-7 SWIG_CXX=g++-7 CPP14=1 + sudo: required + dist: trusty + - os: linux + env: SWIGLANG=python SWIG_CC=gcc-7 SWIG_CXX=g++-7 CPP14=1 + sudo: required + dist: trusty - compiler: gcc os: osx env: SWIGLANG= @@ -302,10 +353,6 @@ matrix: env: SWIGLANG=tcl allow_failures: - # Started failing after upgrade from Guile 2.0.14 to Guile 2.2.0 - - compiler: clang - os: osx - env: SWIGLANG=guile # Lots of failing tests currently - compiler: gcc os: linux @@ -331,6 +378,7 @@ install: - if test "$TRAVIS_OS_NAME" = "osx"; then source Tools/travis-osx-install.sh; fi - if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing --without-maximum-compile-warnings "CXXFLAGS=-std=c++11 -Wall -Wextra" "CFLAGS=-std=c11 -Wall -Wextra") && export CSTD=c11 && export CPPSTD=c++11; fi - if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing --without-maximum-compile-warnings "CXXFLAGS=-std=c++14 -Wall -Wextra" "CFLAGS=-std=c11 -Wall -Wextra") && export CSTD=c11 && export CPPSTD=c++14; fi + - if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing --without-maximum-compile-warnings "CXXFLAGS=-std=c++17 -Wall -Wextra" "CFLAGS=-std=c11 -Wall -Wextra") && export CSTD=c11 && export CPPSTD=c++17; fi - ls -la $(which $CC) - ls -la $(which $CXX) - $CC --version diff --git a/ANNOUNCE b/ANNOUNCE index e0bd4d0f9..109cf9216 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 3.0.13 (in progress) *** +*** ANNOUNCE: SWIG 4.0.0 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-3.0.13, the latest SWIG release. +We're pleased to announce SWIG-4.0.0, the latest SWIG release. What is SWIG? ============= @@ -27,11 +27,11 @@ Availability ============ The release is available for download on Sourceforge at - http://prdownloads.sourceforge.net/swig/swig-3.0.13.tar.gz + http://prdownloads.sourceforge.net/swig/swig-4.0.0.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-3.0.13.zip + http://prdownloads.sourceforge.net/swig/swigwin-4.0.0.zip Please report problems with this release to the swig-devel mailing list, details at http://www.swig.org/mail.html. diff --git a/CCache/Makefile.in b/CCache/Makefile.in index 67fd3f363..d1bb8c526 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -8,6 +8,7 @@ bindir=@bindir@ mandir=@mandir@ INSTALLCMD=@INSTALL@ PACKAGE_NAME=@PACKAGE_NAME@ +PROGRAM_NAME=@PROGRAM_NAME@ # Soft link test can be skipped on systems that don't support soft linking NOSOFTLINKSTEST= @@ -17,13 +18,10 @@ SWIG=swig SWIG_LIB=../$(srcdir)/../Lib EXEEXT=@EXEEXT@ -# Use standard autoconf approach to transform executable name using --program-prefix and --program-suffix -transform = @program_transform_name@ - LIBS= @LIBS@ OBJS= ccache.o mdfour.o hash.o execute.o util.o args.o stats.o \ cleanup.o snprintf.o unify.o -HEADERS = ccache.h mdfour.h +HEADERS = ccache.h mdfour.h config.h config_win32.h all: $(PACKAGE_NAME)$(EXEEXT) @@ -32,7 +30,7 @@ Makefile: $(srcdir)/Makefile.in ./config.status $(SHELL) ./config.status # Note that HTML documentation is actually generated and used from the main SWIG documentation Makefile -docs: $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/ccache-man.html +docs: $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/$(PACKAGE_NAME)-man.html $(PACKAGE_NAME)$(EXEEXT): $(OBJS) $(HEADERS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) @@ -40,40 +38,43 @@ $(PACKAGE_NAME)$(EXEEXT): $(OBJS) $(HEADERS) $(srcdir)/$(PACKAGE_NAME).1: $(srcdir)/ccache.yo -yodl2man -o $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/ccache.yo -$(srcdir)/web/ccache-man.html: $(srcdir)/ccache.yo - yodl2html -o $(srcdir)/web/ccache-man.html $(srcdir)/ccache.yo +$(srcdir)/web/$(PACKAGE_NAME)-man.html: $(srcdir)/ccache.yo + yodl2html -o $(srcdir)/web/$(PACKAGE_NAME)-man.html $(srcdir)/ccache.yo install: $(PACKAGE_NAME)$(EXEEXT) @echo "Installing $(PACKAGE_NAME)" - @echo "Installing $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT)" + @echo "Installing $(DESTDIR)${bindir}/$(PROGRAM_NAME)$(EXEEXT)" ${INSTALLCMD} -d $(DESTDIR)${bindir} - ${INSTALLCMD} -m 755 $(PACKAGE_NAME)$(EXEEXT) $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT) + ${INSTALLCMD} -m 755 $(PACKAGE_NAME)$(EXEEXT) $(DESTDIR)${bindir}/$(PROGRAM_NAME)$(EXEEXT) install-docs: $(srcdir)/$(PACKAGE_NAME).1 - @echo "Installing $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1" + @echo "Installing $(DESTDIR)${mandir}/man1/$(PROGRAM_NAME).1" ${INSTALLCMD} -d $(DESTDIR)${mandir}/man1 - ${INSTALLCMD} -m 644 $(srcdir)/$(PACKAGE_NAME).1 $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1 + ${INSTALLCMD} -m 644 $(srcdir)/$(PACKAGE_NAME).1 $(DESTDIR)${mandir}/man1/$(PROGRAM_NAME).1 uninstall: $(PACKAGE_NAME)$(EXEEXT) - rm -f $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT) + rm -f $(DESTDIR)${bindir}/$(PROGRAM_NAME)$(EXEEXT) uninstall-docs: $(srcdir)/$(PACKAGE_NAME).1 - rm -f $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1 + rm -f $(DESTDIR)${mandir}/man1/$(PROGRAM_NAME).1 -clean: +clean: clean-docs /bin/rm -f $(OBJS) *~ $(PACKAGE_NAME)$(EXEEXT) +clean-docs: + rm -f $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/$(PACKAGE_NAME)-man.html + test: test.sh - SWIG_LIB='$(SWIG_LIB)' PATH=../..:$$PATH SWIG='$(SWIG)' CC='$(CC)' NOSOFTLINKSTEST='$(NOSOFTLINKSTEST)' $(srcdir)/test.sh + SWIG_LIB='$(SWIG_LIB)' PATH=../..:$$PATH SWIG='$(SWIG)' CC='$(CC)' NOSOFTLINKSTEST='$(NOSOFTLINKSTEST)' CCACHE='../$(PACKAGE_NAME)' CCACHE_PROG=$(PROGRAM_NAME) $(srcdir)/test.sh check: test distclean: clean - /bin/rm -f Makefile config.h config.sub config.log build-stamp config.status ccache_swig_config.h + /bin/rm -f Makefile config.h config.sub config.log build-stamp config.status ccache_swig_config.h config_win32.h /bin/rm -rf autom4te.cache maintainer-clean: distclean - /bin/rm -f $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/ccache-man.html + /bin/rm -f $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/$(PACKAGE_NAME)-man.html # FIXME: To fix this, test.sh needs to be able to take ccache from the diff --git a/CCache/ccache.h b/CCache/ccache.h index a79d88322..25e786496 100644 --- a/CCache/ccache.h +++ b/CCache/ccache.h @@ -6,7 +6,7 @@ #include "config.h" #else #include -#define PACKAGE_NAME "ccache-swig.exe" +#include "config_win32.h" #endif #include @@ -51,7 +51,7 @@ #define STATUS_FATAL 4 #define STATUS_NOCACHE 5 -#define MYNAME PACKAGE_NAME +#define MYNAME PROGRAM_NAME #define LIMIT_MULTIPLE 0.8 diff --git a/CCache/config_win32.h.in b/CCache/config_win32.h.in new file mode 100644 index 000000000..2d5ab97e3 --- /dev/null +++ b/CCache/config_win32.h.in @@ -0,0 +1,3 @@ +#if !defined(PROGRAM_NAME) +#define PROGRAM_NAME "@PROGRAM_NAME@.exe" +#endif diff --git a/CCache/configure.ac b/CCache/configure.ac index dfbf86dbc..e1c761860 100644 --- a/CCache/configure.ac +++ b/CCache/configure.ac @@ -7,6 +7,7 @@ AC_CONFIG_SRCDIR([ccache.h]) AC_MSG_NOTICE([Configuring ccache]) AC_CONFIG_HEADER(config.h) +AC_CONFIG_FILES([config_win32.h]) dnl Checks for programs. AC_PROG_CC @@ -14,6 +15,20 @@ AC_PROG_CPP AC_PROG_INSTALL AC_ARG_PROGRAM # for program_transform_name +AC_SUBST(PROGRAM_NAME) +if test "x$program_prefix" != "xNONE" -a "x$program_prefix" != "x" +then + PROGRAM_NAME="$program_prefix$PACKAGE_NAME" +else + PROGRAM_NAME="$PACKAGE_NAME" +fi +if test "x$program_suffix" != "xNONE" -a "x$program_suffix" != "x" +then + PROGRAM_NAME="$PROGRAM_NAME$program_suffix" +fi + +AC_DEFINE_UNQUOTED(PROGRAM_NAME, "$PROGRAM_NAME", [Define my program name]) + AC_DEFINE([_GNU_SOURCE], 1, [Define _GNU_SOURCE so that we get all necessary prototypes]) diff --git a/CCache/snprintf.c b/CCache/snprintf.c index 32187c1a5..9bf8a817b 100644 --- a/CCache/snprintf.c +++ b/CCache/snprintf.c @@ -292,6 +292,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args break; case 'X': flags |= DP_F_UP; + /* FALLTHROUGH */ case 'x': flags |= DP_F_UNSIGNED; if (cflags == DP_C_SHORT) @@ -314,6 +315,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args break; case 'E': flags |= DP_F_UP; + /* FALLTHROUGH */ case 'e': if (cflags == DP_C_LDOUBLE) fvalue = va_arg (args, LDOUBLE); @@ -322,6 +324,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args break; case 'G': flags |= DP_F_UP; + /* FALLTHROUGH */ case 'g': if (cflags == DP_C_LDOUBLE) fvalue = va_arg (args, LDOUBLE); diff --git a/CCache/test.sh b/CCache/test.sh index 438e782cd..5b6f92a35 100755 --- a/CCache/test.sh +++ b/CCache/test.sh @@ -20,7 +20,12 @@ fi PATH="`echo $PATH | \ sed -e 's!:/usr\(/local\)*/lib\([0-9]\)*/ccache\(/\)*!!g'`" -CCACHE=../ccache-swig +if test -n "$CCACHE"; then + CCACHE="$CCACHE" +else + CCACHE=../ccache-swig +fi + TESTDIR=test.$$ test_failed() { @@ -406,6 +411,10 @@ swigtests() { # main program rm -rf $TESTDIR mkdir $TESTDIR +if test -n "$CCACHE_PROG"; then + ln -s $CCACHE $TESTDIR/$CCACHE_PROG + CCACHE=./$CCACHE_PROG +fi cd $TESTDIR || exit 1 unset CCACHE_DIR diff --git a/CHANGES b/CHANGES index 836bf4b9c..d18a11bb6 100644 --- a/CHANGES +++ b/CHANGES @@ -11813,7 +11813,7 @@ Version 1.3.23 (November 11, 2004) ie, no additional pointer elements are created, and the original 'foo' and 'A.bar' can be used as parameters. - In the case of member fucntion however, still you need + In the case of member function however, still you need to use the special variable Class::_cb_ptr, ie: foobarm(3, a, A.barm_cb_ptr) @@ -21116,7 +21116,7 @@ Version 1.3.7 (September 3, 2001) typedef __name vector; %enddef - An a specific instantiation is created in exactly the same way: + A specific instantiation is created in exactly the same way: %template(intvec) vector; diff --git a/CHANGES.current b/CHANGES.current index 2d5e841ea..f15c99e90 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,21 +4,630 @@ See the RELEASENOTES file for a summary of changes in each release. Issue # numbers mentioned below can be found on Github. For more details, add the issue number to the end of the URL: https://github.com/swig/swig/issues/ -Version 3.0.13 (in progress) -============================ +Version 4.0.0 (in progress) +=========================== + +2018-04-18: olly + [Python] Suppress new pycodestyle warning: + E252 missing whitespace around parameter equals + +2018-04-07: goatshriek + [Ruby] #1213 Fix ruby %alias directive for global C/C++ functions. + +2018-04-03: olly + [Ruby] Fix to pass Qnil instead of NULL to rb_funcall(), which silences GCC + -Wconversion-null warning (on by default with recent GCC). + +2018-03-09: fultonwi + [Java] #1184 Fix swigReleaseOwnership() and swigTakeOwnership() regression + for non-director classes. Restores a dynamic_cast which was previously removed. + +2018-03-07: llongi + Github PR #1166 - Fix preprocessor handling of macros with commas + in a // comment. + +2018-02-18: JPEWdev + Patch #1164 - Add support for a command-line options file, also sometimes + called a response file. This is useful if the command-line options exceed + the system command-line length limit. To use, put the command-line options + into a file, then provide the file name prefixed with @, for example using + a file called args.txt: + + swig @args.txt + +2018-02-11: wsfulton + [Javascript] #1187 Fix compilation error wrapping std::complex via + std_complex.i. + +2018-01-30: smarchetto + [Scilab] add type name argument in SWIG_ptr() function to cast from pointer adress to typed pointers + +2018-01-16: wsfulton + Expressions following a preprocessor directive must now be separated by whitespace + or non-numeric characters. This syntax change makes the SWIG preprocessor work like + the C preprocessor in this area. + + For example, the following code used be accepted as valid syntax: + #if1 + #define ABC 123 + #endif + + Now you get an error: + example.h:1: Error: Unknown SWIG preprocessor directive: if1 (if this is a block of + target language code, delimit it with %{ and %}) + example.h:3: Error: Extraneous #endif. + + The following is the correct syntax: + #if 1 + #define ABC 123 + #endif + + The following of course also works: + #if(1) + #define ABC 123 + #endif + +2018-01-15: wsfulton + Fix issue #1183. Floating point exception evaluating preprocessor expressions + resulting in division by zero. + +2018-01-14: wsfulton + Fix issue #1172. Seg fault parsing invalid exponents in the preprocessor. + +2018-01-12: Liryna + [C#] Patch #1128. Add ToArray function to std::vector wrappers. + +2018-01-12: wsfulton + [Java] Fix issue #1156. Add missing throws clause for interfaces when using the + %interface family of macros. + +2018-01-05: wsfulton + Fix default arguments using expressions containing -> syntax error. Problem reported on + swig-user mailing list. + +2017-12-30: wsfulton + [Python] Replace pep8 with pycodestyle for checking the Python code style when + running Python tests. + +2017-12-30: davedissian + Fixed a symbol lookup issue when encountering a typedef of a symbol from the tag + namespace to the global namespace when the names are identical, such as 'typedef + struct Foo Foo;'. + +2017-12-13: wsfulton + [Perl] add missing support for directorfree typemaps. + +2017-12-13: wsfulton + Issue #1167 Fix directorout typemaps which were causing undefined behaviour when + returning pointers by reference. + +2017-12-08: olly + [PHP] Use ZEND_MODULE_GLOBALS_ACCESSOR to access globals - this + should make the generated code work with PHP 7.2.0. + +2017-12-04: wsfulton + [Python] Add missing checks for failures in calls to PyUnicode_AsUTF8String. Previously a + seg fault could occur when passing invalid UTF8 strings (low surrogates), eg passing + u"\udcff" to the C layer (Python 3). + +2017-11-24: joequant + Fix #1124 and return R_NilValue for null pointers + +2017-11-29: wsfulton + [Java] director exception handling improvements. + + When a director method throws an exception and it is caught by DirectorException + and passed back to Java using Swig::DirectorException::throwException, the Java + stack trace now contains the original source line that threw the exception. + + Deprecate Swig::DirectorException::raiseJavaException, please replace usage with + Swig::DirectorException::throwException. + +2017-10-26: wsfulton + Add support for C++11 ref-qualifiers when using directors. + +2017-10-26: wsfulton + Fix generated code when using directors and methods returning const ref pointers. + +2017-10-26: wsfulton + [C#, D, Java, Octave, R, Scilab] Port director typemaps to these additional languages. + Issue #700. + +2017-10-26: radarsat1 + [Ruby Python] Patch #1029 - Correct handling of null using directors and shared_ptr. + +2017-10-10: joequant + [R] pass enum expressions to R. This will generate + incorrect files when there is an arithmetic expression + in the enum, but this is better than silently generating + incorrect code + +2017-10-09: olly + [PHP] Fix incorrect wrapper code generated when there's a + combination of overloading, parameters with a default value + and %newobject. Fixes https://sourceforge.net/p/swig/bugs/1350/ + +2017-10-09: olly + Remove GCJ support. It isn't in a good state and doesn't seem to + be used, and GCC7 dropped GCJ. Closes + https://sourceforge.net/p/swig/bugs/823/ + +2017-10-07: olly + Fix preprocessor handling of empty macro arguments to match that of + C/C++ compilers. Fixes https://github.com/swig/swig/pull/1111 and + https://sourceforge.net/p/swig/bugs/826/ + +2017-10-06: wsfulton + [Python] Issue #1108. Fix platform inconsistency in Python default argument handling. + 32 bit and 64 bit compiled versions of SWIG generated different Python files + when default arguments were outside the range of 32 bit signed integers. + The default arguments specified in Python are now only those that are in the + range of a 32 bit signed integer, otherwise the default is obtained from C/C++ code. + +2017-10-02: wsfulton + [C#] Fix std::complex types passed by value. + +2017-10-02: wsfulton + [Javascript, Python, Ruby] Issue #732 - Missing type information for std::complex + in std_complex.i meant that previously std::complex always had to be fully qualified + in order to be wrapped with the appropriate typemaps. + +2017-10-01: joequant + allow R package names with docs + allowing mulitple get accessors in R + fix smrt-pointer and NAMESPACE support + constructors now returning smart pointers (if class + declared as such) + smart-pointer classes deriving from parent smart-pointers + +2017-09-29: wsfulton + Issue #1100 - Allow an instantiated template to have the same name in the target + language as the C++ template name, for example, this is now possible: + + template struct X { ... }; + %template(X) X; + +2017-09-23: wsfulton + Issue #1098. Fix overloading of shared_ptr with underlying pointer types, eg: + + void m(std::shared_ptr p); + void m(T &p); + void m(T *p); + + Only the first method is wrapped and the others are ignored/shadowed. + The implementation is done via a new attribute in the 'typecheck' typemap called + 'equivalent'. If specified, it must contain the equivalent pointer type for overloading + and can only be used for the special SWIG_TYPECHECK_POINTER precedence level. + The shared_ptr 'typecheck' typemaps have been modified accordingly. + Here is a simplified version: + + %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="T *") + T, + T CONST &, + T CONST *, + T *CONST&, + std::shared_ptr< T >, + std::shared_ptr< T > &, + std::shared_ptr< T > *, + std::shared_ptr< T > *& + { ... } + + Overloading with any of these types will result in SWIG ignoring all but the first + overloaded method by default. Without the 'equivalent' attribute, wrapping the overloaded + methods resulted in types being shadowed (scripting languages) or code that did not + compile (statically typed languages). + +2017-09-19: futatuki + [Python] #1003 Add --with-2to3=/path/to/2to3 option to configure. + +2017-09-18: wsfulton + Fix type promotion wrapping constant expressions of the form: + # define EXPR_MIXED1 (0x80 + 11.1) - 1 + This was previously an integral type instead of a floating point type. + +2017-09-17: wsfulton + Fix generated code for constant expressions containing wchar_t L literals such as: + # define __WCHAR_MAX (0x7fffffff + L'\0') + # define __WCHAR_MIN (-__WCHAR_MAX - 1) + +2017-09-10: mlamarre + [Python] Patch #1083. Define_DEBUG to 1 to do exactly like Visual Studio + /LDd, /MDd or /MTd compiler options. + +2017-08-25: wsfulton + Issue #1059. Add support for C++11 ref-qualifiers on non-static member functions. + Members with lvalue ref-qualifiers such as: + + struct RQ { + void m1(int x) &; + void m2(int x) const &; + }; + + are wrapped like any other member function. Member functions with rvalue ref-qualifiers + are ignored by default, such as: + + struct RQ { + void m3(int x) &&; + void m4(int x) const &&; + }; + + example.i:7: Warning 405: Method with rvalue ref-qualifier m3(int) && ignored. + example.i:8: Warning 405: Method with rvalue ref-qualifier m4(int) const && ignored. + + These can be unignored and exposed to the target language, see further documentation in + CPlusPlus11.html. + +2017-08-16: wsfulton + Fix #1063. Add using declarations to templates into typedef table. + + Using declarations to templates were missing in SWIG's internal typedef tables. + This led to a few problems, such as, templates that did not instantiate and generated + C++ code that did not compile as SWIG did not know what scope the template was + in. This happened mostly when a using declaration was used on a template type in a + completely unrelated namespace. + +2017-08-16: wsfulton + Fix type lookup in the presence of using directives and using declarations. + + Fix some cases of type lookup failure via a combination of both using directives and + using declarations resulting in C++ code that did not compile as the generated type was + not fully qualified for use in the global namespace. Example below: + + namespace Space5 { + namespace SubSpace5 { + namespace SubSubSpace5 { + struct F {}; + } + } + using namespace SubSpace5; + using SubSubSpace5::F; + void func(SubSubSpace5::F f); + } + +2017-08-16: wsfulton + Issue #1051. %template scope enforcement and class definition fixes. + + The scoping rules around %template have been specified and enforced. + The %template directive for a class template is the equivalent to an + explicit instantiation of a C++ class template. The scope for a valid + %template instantiation is now the same as the scope required for a + valid explicit instantiation of a C++ template. A definition of the + template for the explicit instantiation must be in scope where the + instantiation is declared and must not be enclosed within a different + namespace. + + For example, a few %template and C++ explicit instantiations of std::vector + are shown below: + + // valid + namespace std { + %template(vin) vector; + template class vector; + } + + // valid + using namespace std; + %template(vin) vector; + template class vector; + + // valid + using std::vector; + %template(vin) vector; + template class vector; + + // ill-formed + namespace unrelated { + using std::vector; + %template(vin) vector; + template class vector; + } + + // ill-formed + namespace unrelated { + using namespace std; + %template(vin) vector; + template class vector; + } + + // ill-formed + namespace unrelated { + namespace std { + %template(vin) vector; + template class vector; + } + } + + // ill-formed + namespace unrelated { + %template(vin) std::vector; + template class std::vector; + } + + When the scope is incorrect, an error now occurs such as: + + cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and + was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'. + + Previously SWIG accepted the ill-formed examples above but this led to + numerous subtle template scope problems especially in the presence of + using declarations and using directives as well as with %feature and %typemap. + + Actually, a valid instantiation is one which conforms to the C++03 + standard as C++11 made a change to disallow using declarations and + using directives to find a template. + + // valid C++03, ill-formed C++11 + using std::vector; + template class vector; + + Similar fixes for defining classes using forward class references have + also been put in place. For example: + + namespace Space1 { + struct A; + } + namespace Space2 { + struct Space1::A { + void x(); + } + } + + will now error out with: + + cpp_class_definition.i:5: Error: 'Space1::A' resolves to 'Space1::A' and + was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'. + + Previously some symbols would have been instantiated in the wrong scope and led + to lots of scope problems involving SWIG typemaps, features, renames etc. + You will need to correct the scope used in other SWIG directives which do not + support 'using declarations' and 'using directives'. For example, if you previously had: + + %rename(Zap) vector::clear; + using namespace std; + %template(VectorInt) vector; + + Prior versions of SWIG incorrectly instantiated vector in the global namespace + and so the %rename matched. Now the template is instantiated in the correct namespace, + so is fully qualified as std::vector. The other SWIG directives need correcting as + they do not follow 'using declarations' and 'using directives'. Change it to: + + %rename(Zap) std::vector::clear; + using namespace std; + %template(vin) vector; + + + *** POTENTIAL INCOMPATIBILITY *** + +2017-08-16: wsfulton + Fix scope lookup for template parameters containing unary scope operators. + + Fixes cases like: + + namespace Alloc { + template struct Rebind { + typedef int Integer; + }; + } + %template(RebindBucket) Alloc::Rebind< Bucket >; + OR + %template(RebindBucket) Alloc::Rebind< ::Bucket >; + + Alloc::Rebind< Bucket >::Integer Bucket1(); + Alloc::Rebind< ::Bucket >::Integer Bucket2(); + Alloc::Rebind<::template TemplateBucket>::Integer Bucket3(); + +2017-08-16: wsfulton + For templates only, the template parameters are fully resolved when + handling typemaps. Without this, it is too hard to have decent rules + to apply typemaps when parameter types are typedef'd and template + parameters have default values. + + Fixes %clear for typedefs in templates, eg: + + %typemap("in") XXX::Long "..." + template typename struct XXX { + typedef long Long; + }; + %clear XXX::Long; + + as the typemap was previously incorrectly stored as a typemap for long + instead of XXX::Long. + +2017-08-05: olly + [C++11] Allow static_assert at the top level (and disallow it right + after template). Fixes https://github.com/swig/swig/issues/1031 + reported by Artem V L. + +2017-08-02: wsfulton + Fix incorrectly shown warning when an empty template instantiation was used on a + class used as a base class and that base class was explicitly ignored with %ignore. + Example of the warning which will no longer appear: + + Warning 401: Base class 'Functor< int,int >' has no name as it is an empty + template instantiated with '%template()'. Ignored. + +2017-07-17: fflexo + [Java] #674 Add std_list.i to add support for std::list containers. The Java proxy + extends java.util.AbstractSequentialList and makes the C++ std::list container look + and feel much like a java.util.LinkedList from Java. + +2017-07-07: wsfulton + [Python] Fix display of documented template types when using the autodoc + feature. For example when wrapping: + + %feature("autodoc"); + template struct T {}; + %template(TInteger) T; + + the generated documentation contains: + """Proxy of C++ T< int > class.""" + instead of: + """Proxy of C++ T<(int)> class.""" + and + """__init__(TInteger self) -> TInteger""" + instead of + """__init__(T<(int)> self) -> TInteger""" + +2017-06-27: nihaln + [PHP] Update the OUTPUT Typemap to add return statement to the + PHP Wrapper. + +2017-06-27: nihaln + [PHP] Update the enum and value examples to use the OO wrappers + rather than the flat functions produced with -noproxy. There's + not been a good reason to use -noproxy for since PHP5 OO wrapping + was fixed back in 2005. + +2017-06-23: m7thon + [Python] fix and improve default argument handling: + + 1. Fix negative octals. Currently not handled correctly by `-py3` + (unusual case, but incorrect). + 2. Fix arguments of type "octal + something" (e.g. `0640 | 04`). + Currently drops everything after the first octal. Nasty! + 3. Fix bool arguments "0 + something" (e.g. `0 | 1`) are always + "False" (unusual case, but incorrect). + 4. Remove special handling of "TRUE" and "FALSE" from + `convertValue` since there's no reason these have to match + "true" and "false". + 5. Remove the Python 2 vs. Python 3 distinction based on the + `-py3` flag. Now the same python code is produced for default + arguments for Python 2 and Python 3. For this, octal default + arguments, e.g. 0644, are now wrapped as `int('644', 8)`. This + is required, as Python 2 and Python 3 have incompatible syntax + for octal literals. + + Fixes #707 + +2017-06-21: futatuki + #1004 - Fix ccache-swig executable name to respect configure's --program-prefix and + --program-suffix values if used. + +2017-06-21: tamuratak + [Ruby] #911 - Add std::wstring support. + +2017-06-19: wsfulton + [Python] Fix handling of rich comparisons when wrapping overloaded operators: + + operator< operator<= operator> operator>= operator== operator!= + + Previously a TypeError was always thrown if the type was not correct. NotImplemented + is now returned from these wrapped functions if the type being compared with is + not correct. The subsequent behaviour varies between different versions of Python + and the comparison function being used, but is now consistent with normal Python + behaviour. For example, for the first 4 operator overloads above, a TypeError + 'unorderable types' is thrown in Python 3, but Python 2 will return True or False. + NotImplemented should be returned when the comparison cannot be done, see PEP 207 and + https://docs.python.org/3/library/constants.html#NotImplemented + + Note that the bug was only present when overloaded operators did not also have a + function overload. + + Fixes SF bug #1208 (3441262) and SF patch #303. + + *** POTENTIAL INCOMPATIBILITY *** + +2017-06-17: fabrice102 + [Go] Fix Go callback example. Fixes github #600, #955, #1000. + +2017-06-16: wsfulton + Make sure warning and error messages are not split up by other processes writing to + stdout at the same time. + +2017-06-16: wsfulton + [R] Fix wrapping function pointers containing rvalue and lvalue reference parameters. + +2017-06-13: olly + [Perl] Fix testsuite to work without . in @INC - it was removed in + Perl 5.26 for security reasons, and has also been removed from + older versions in some distros. Fixes + https://github.com/swig/swig/issues/997 reported by lfam. + +2017-06-03: wsfulton + Fix %import on a file containing a file scope %fragment forced inclusion to not + generate the fragment contents as %import should not result in code being generated. + The behaviour is now the same as importing code insertion blocks. + Wrapping FileC.i in the following example will result in no generated code, whereas + previously "#include " was generated: + + // FileA.i + %fragment("", "header") %{ + #include + %} + + %{ + #include + %} + %fragment(""); + + // FileC.i + %import "FileA.i" + + *** POTENTIAL INCOMPATIBILITY *** + +2017-05-26: Volker Diels-Grabsch, vadz + [Java] #842 Extend from java.util.AbstractList<> and implement java.util.RandomAccess for + std::vector wrappers. This notably allows to iterate over wrapped vectors in a natural way. +2017-05-30: davidcl + [Scilab] #994 Undefined symbol error when loading in Scilab 6 + +2017-05-25: asibross + [Java] #370 #417 Missing smart pointer handling in Java director extra methods + swigReleaseOwnership() and swigTakeOwnership(). + +2017-05-23: wsfulton + [Java] #230 #759 Fix Java shared_ptr and directors for derived classes java compilation + error. + + For shared_ptr proxy proxy classes, add a protected method swigSetCMemOwn for modifying + the swigCMemOwn and swigCMemOwnDerived member variables which are used by various other + methods for controlling memory ownership. + +2017-05-21: Sghirate + [Java, C#, D] #449 Remove unnecessary use of dynamic_cast in directors to enable + non-RTTI compilation. + +2017-05-21: wsfulton + [Python] #993 Fix handling of default -ve unsigned values, such as: + void f(unsigned = -1U); + +2017-05-20: jschueller + [Python] #991 Fix E731 PEP8 warning: do not assign a lambda expression + +2017-05-16: nihal95 + [PHP] Add %pragma version directive to allow the version of the + extension to be set. Patch #970, fixes #360. + +2017-05-13: yag00 + Patch #975 - Add support for noexcept on director methods. + +2017-04-27: redbrain + Issue #974, Patch #976 - Fix preprocessor handling of macros with commas in a comment. + +2017-04-25: jleveque + [Lua] #959 - Fix Visual Studio C4244 conversion warnings in Lua wrappers. + +2017-04-21: tamuratak + [Ruby] #964 - Add shared_ptr director typemaps. + +2017-04-20: wsfulton + [Ruby] #586, #935 Add assert for invalid NULL type parameter when calling SWIG_Ruby_NewPointerObj. + +2017-04-20: tamuratak + [Ruby] #930, #937 - Fix containers of std::shared_ptr. + Upcasting, const types (eg vector>) and NULL/nullptr support added. 2017-04-12: smarchetto [Scilab] New parameter targetversion to specify the Scilab target version (5, 6, ..) for code generation With Scilab 6 target specified, identifier names truncation is disabled (no longer necessary) -2017-02-29: tamuratak - [Ruby] #917 - Add Enumerable module to all container class wrappers. It was missing - for std::list, std::multiset, std::unordered_multiset and std::unordered_map. - 2017-03-24: tamuratak [Ruby] Fix #939 - Wrapping std::vector fix due to incorrect null checks on VALUE obj. +2017-03-17: vadz + [C#] #947 Add support for std::complex + 2017-03-17: wsfulton [Go] Fix handling of typedef'd function pointers and typedef'd member function pointers such as: @@ -43,6 +652,10 @@ Version 3.0.13 (in progress) auto sum1(int x, int y) const -> int { return x + y; } auto sum2(int x, int y) noexcept -> int { return x + y; } +2017-02-29: tamuratak + [Ruby] #917 - Add Enumerable module to all container class wrappers. It was missing + for std::list, std::multiset, std::unordered_multiset and std::unordered_map. + 2017-02-27: assambar [C++11] Extend parser to support throw specifier in combination with override and/or final. diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html index ddb6fba55..c4d898130 100644 --- a/Doc/Manual/Allegrocl.html +++ b/Doc/Manual/Allegrocl.html @@ -155,7 +155,7 @@ SWIG directives. SWIG can be furnished with a header file, but an interface can also be generated without library headers by supplying a simple text file--called the interface file, which is typically named with a .i extension--containing any foreign declarations of -identifiers you wish to use. The most common approach is to use a an +identifiers you wish to use. The most common approach is to use an interface file with directives to parse the needed headers. A straight parse of library headers will result in usable code, but SWIG directives provides much freedom in how a user might tailor the diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html index b295b5e04..726314228 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -409,7 +409,7 @@ All the steps required to compile and use a simple hierarchy of classes for shap

First create an Android project called SwigClass in a subdirectory called class. -The steps below create and build a the JNI C++ app. +The steps below create and build the JNI C++ app. Adjust the --target id as mentioned earlier in the Examples introduction.

diff --git a/Doc/Manual/CCache.html b/Doc/Manual/CCache.html index d23b0cb2f..521184ff0 100644 --- a/Doc/Manual/CCache.html +++ b/Doc/Manual/CCache.html @@ -411,7 +411,7 @@ following conditions need to be met:

-ccache was inspired by the compilercache shell script script written +ccache was inspired by the compilercache shell script written by Erik Thiele and I would like to thank him for an excellent piece of work. See http://www.erikyyy.de/compilercache/ diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index d3494455b..f9281bd56 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -42,6 +42,7 @@

  • Exception specifications and noexcept
  • Control and query object alignment
  • Attributes +
  • Methods with ref-qualifiers
  • Standard library changes
      @@ -877,7 +878,8 @@ so in this case it is entirely possible to pass an int instead of a double to -SWIG correctly parses the new static_assert declarations. +SWIG correctly parses the new static_assert declarations (though 3.0.12 and earlier +had a bug which meant this wasn't accepted at file scope). This is a C++ compile time directive so there isn't anything useful that SWIG can do with it.

      @@ -970,6 +972,104 @@ int [[attr1]] i [[attr2, attr3]]; [[noreturn, nothrow]] void f [[noreturn]] (); + +

      7.2.29 Methods with ref-qualifiers

      + + +

      +C++11 non-static member functions can be declared with ref-qualifiers. +Member functions declared with a & lvalue ref-qualifiers are wrapped like any other function without ref-qualifiers. +Member functions declared with a && rvalue ref-qualifiers are ignored by default +as they are unlikely to be required from non-C++ languages where the concept of rvalue-ness +for the implied *this pointer does not apply. +The warning is hidden by default, but can be displayed as described in the section on Enabling extra warnings. +

      + +

      +Consider: +

      + +
      +struct RQ {
      +  void m1(int x) &;
      +  void m2(int x) &&;
      +};
      +
      + +

      +The only wrapped method will be the lvalue ref-qualified method m1 +and if SWIG is run with the -Wextra command-line option, the following warning will be issued indicating m2 is not wrapped: +

      + +
      +
      +example.i:7: Warning 405: Method with rvalue ref-qualifier m2(int) && ignored.
      +
      +
      + +

      +If you unignore the method as follows, wrappers for m2 will be generated: +

      + +
      +%feature("ignore", "0") RQ::m2(int x) &&;
      +struct RQ {
      +  void m1(int x) &;
      +  void m2(int x) &&;
      +};
      +
      + +

      +Inspection of the generated C++ code, will show that std::move is used on the instance +of the RQ * class: +

      + +
      +  RQ *arg1 = (RQ *) 0 ;
      +  int arg2 ;
      +
      +  arg1 = ...marshalled from target language...
      +  arg2 = ...marshalled from target language...
      +
      +  std::move(*arg1).m2(arg2);
      +
      + +

      +This will compile but when run, the move effects may not be what you want. +As stated earlier, rvalue ref-qualifiers aren't really applicable outside the world of C++. +However, if you really know what you are doing, full control over the call to the method is +possible via the low-level "action" feature. +This feature completely replaces the call to the underlying function, that is, the last line in the snippet of code above. +

      + +
      +%feature("ignore", "0") RQ::m2(int x) &&;
      +%feature("action") RQ::m2(int x) && %{
      +  RQ().m2(arg2);
      +%}
      +struct RQ {
      +  void m1(int x) &;
      +  void m2(int x) &&;
      +};
      +
      + +

      +resulting in: +

      + +
      +  RQ *arg1 = (RQ *) 0 ;
      +  int arg2 ;
      +
      +  arg1 = ...marshalled from target language...
      +  arg2 = ...marshalled from target language...
      +
      +  RQ().m2(arg2);
      +
      + +

      +Compatibility note: SWIG-4.0.0 was the first version to support ref-qualifiers. +

      7.3 Standard library changes

      @@ -1176,5 +1276,6 @@ Phew, that is a lot of hard work to get a callback working. You could just go with the more attractive option of just using double as the return type in the function declaration instead of result_of!

      + diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 5be63a340..13b6e4997 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -677,7 +677,7 @@ As a result, we get the following method in the module class:
       public static void myArrayCopy(int[] sourceArray, int[] targetArray, int nitems) {
      -    examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems);
      +  examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems);
       }
       
      @@ -997,9 +997,9 @@ When the following C# code is executed:
       public class runme {
      -    static void Main() {
      -      example.positivesonly(-1);
      -    }
      +  static void Main() {
      +    example.positivesonly(-1);
      +  }
       }
       
      @@ -1772,7 +1772,7 @@ should pass the call on to CSharpDefaults.DefaultMethod(int)using the C

      -When using multiple modules it is is possible to compile each SWIG generated wrapper +When using multiple modules it is possible to compile each SWIG generated wrapper into a different assembly. However, by default the generated code may not compile if generated classes in one assembly use generated classes in another assembly. @@ -1846,12 +1846,12 @@ and the following usage from C# after running the code through SWIG:

      -      Wheel wheel = new Bike(10).getWheel();
      -      Console.WriteLine("wheel size: " + wheel.size);
      -      // Simulate a garbage collection
      -      global::System.GC.Collect();
      -      global::System.GC.WaitForPendingFinalizers();
      -      global::System.Console.WriteLine("wheel size: " + wheel.size);
      +  Wheel wheel = new Bike(10).getWheel();
      +  Console.WriteLine("wheel size: " + wheel.size);
      +  // Simulate a garbage collection
      +  global::System.GC.Collect();
      +  global::System.GC.WaitForPendingFinalizers();
      +  global::System.Console.WriteLine("wheel size: " + wheel.size);
       
      @@ -1980,9 +1980,9 @@ and more or less equivalent usage from C#
      -      Container container = new Container();
      -      Element element = new Element(20);
      -      container.setElement(element);
      +  Container container = new Container();
      +  Element element = new Element(20);
      +  container.setElement(element);
       
      @@ -1993,14 +1993,14 @@ In order to understand why, consider a garbage collection occuring...
      -      Container container = new Container();
      -      Element element = new Element(20);
      -      container.setElement(element);
      -      Console.WriteLine("element.value: " + container.getElement().value);
      -      // Simulate a garbage collection
      -      global::System.GC.Collect();
      -      global::System.GC.WaitForPendingFinalizers();
      -      global::System.Console.WriteLine("element.value: " + container.getElement().value);
      +  Container container = new Container();
      +  Element element = new Element(20);
      +  container.setElement(element);
      +  Console.WriteLine("element.value: " + container.getElement().value);
      +  // Simulate a garbage collection
      +  global::System.GC.Collect();
      +  global::System.GC.WaitForPendingFinalizers();
      +  global::System.Console.WriteLine("element.value: " + container.getElement().value);
       
      @@ -2019,37 +2019,50 @@ public class Container : global::System.IDisposable { // Ensure that the GC doesn't collect any Element set from C# // as the underlying C++ class stores a shallow copy private Element elementReference; - private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) { - elementReference = element; - return Element.getCPtr(element); - } public void setElement(Element e) { - examplePINVOKE.Container_setElement(swigCPtr, getCPtrAndAddReference(e)); + examplePINVOKE.Container_setElement(swigCPtr, Element.getCPtr(e)); + elementReference = e; } }

      -The following typemaps will generate the desired code. -The 'csin' typemap matches the input parameter type for the setElement method. -The 'cscode' typemap simply adds in the specified code into the C# proxy class. +The following typemaps can be used to generate this code:

      -%typemap(csin) Element *e "getCPtrAndAddReference($csinput)"
      -
       %typemap(cscode) Container %{
         // Ensure that the GC doesn't collect any Element set from C#
         // as the underlying C++ class stores a shallow copy
         private Element elementReference;
      -  private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
      -    elementReference = element;
      -    return Element.getCPtr(element);
      -  }
       %}
      +
      +%typemap(csin,
      +         post="      elementReference = $csinput;"
      +         ) Element *e "Element.getCPtr($csinput)"
      +
      +
      + +

      +The 'cscode' typemap simply adds in the specified code into the C# proxy class. +The 'csin' typemap matches the input parameter type and name for the setElement method and +the 'post' typemap attribute allows adding code after the PInvoke call. +The 'post' code is generated into a finally block after the PInvoke call so the resulting code isn't quite +as mentioned earlier, setElement is actually: +

      + +
      +
      +  public void setElement(Element e) {
      +    try {
      +      examplePINVOKE.Container_setElement(swigCPtr, Element.getCPtr(e));
      +    } finally {
      +      elementReference = e;
      +    }
      +  }
       
      diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 56afca857..5cc796c8d 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -228,7 +228,6 @@
    • Static members
    • Member data
    -
  • Default arguments
  • Protection
  • Enums and constants
  • Friends @@ -236,16 +235,27 @@
  • Pass and return by value
  • Inheritance
  • A brief discussion of multiple inheritance, pointers, and type checking -
  • Wrapping Overloaded Functions and Methods +
  • Default arguments +
  • Overloaded functions and methods -
  • Wrapping overloaded operators +
  • Overloaded operators
  • Class extension
  • Templates +
  • Namespaces @@ -300,6 +315,7 @@
  • Exception specifications and noexcept
  • Control and query object alignment
  • Attributes +
  • Methods with ref-qualifiers
  • Standard library changes
  • Accessing protected members
  • Common customization features diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index 0e5fb2869..269e659e0 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -356,7 +356,7 @@ In this case, the exception handler is only attached to declarations named "allocate". This would include both global and member functions. The names supplied to %exception follow the same rules as for %rename described in the section on -Ambiguity resolution and renaming. +Renaming and ambiguity resolution. For example, if you wanted to define an exception handler for a specific class, you might write this:

    @@ -516,7 +516,7 @@ The special variables are often used in situations where method calls are logged $action } catch (MemoryError) { - croak("Out of memory in $decl"); + croak("Out of memory in $decl"); } } void log(const char *message); @@ -796,7 +796,7 @@ involving %feature:

    -The name matching rules outlined in the Ambiguity resolution and renaming +The name matching rules outlined in the Renaming and ambiguity resolution section applies to all %feature directives. In fact the %rename directive is just a special form of %feature. The matching rules mean that features are very flexible and can be applied with diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html index 45b57e18b..1a317a005 100644 --- a/Doc/Manual/D.html +++ b/Doc/Manual/D.html @@ -280,7 +280,7 @@ class SomeClass : AnInterface, AnotherInterface { ... } -

    For this to work, AnInterface and AnotherInterface have to be in scope. If SWIG is not in split proxy mode, this is already the case, but it it is, they have to be added to the import list via the dimports typemap. Additionally, the import statement depends on the package SWIG is configured to emit the modules to.

    +

    For this to work, AnInterface and AnotherInterface have to be in scope. If SWIG is not in split proxy mode, this is already the case, but if it is, they have to be added to the import list via the dimports typemap. Additionally, the import statement depends on the package SWIG is configured to emit the modules to.

    The $importtype macro helps you to elegantly solve this problem:

     %typemap(dimports) RemoteMpe %{
    diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html
    index bf70b69ac..b56657847 100644
    --- a/Doc/Manual/Extending.html
    +++ b/Doc/Manual/Extending.html
    @@ -1576,7 +1576,7 @@ return the node for the first class member.
     
     
    Returns the last child node. You might use this if you wanted to append a new -node to the of a class. +node to the children of a class.

    @@ -2592,36 +2592,36 @@ command line options, simply use code similar to this:

     void Language::main(int argc, char *argv[]) {
       for (int i = 1; i < argc; i++) {
    -      if (argv[i]) {
    -          if (strcmp(argv[i], "-interface") == 0) {
    -            if (argv[i+1]) {
    -              interface = NewString(argv[i+1]);
    -              Swig_mark_arg(i);
    -              Swig_mark_arg(i+1);
    -              i++;
    -            } else {
    -              Swig_arg_error();
    -            }
    -          } else if (strcmp(argv[i], "-globals") == 0) {
    -            if (argv[i+1]) {
    -              global_name = NewString(argv[i+1]);
    -              Swig_mark_arg(i);
    -              Swig_mark_arg(i+1);
    -              i++;
    -            } else {
    -              Swig_arg_error();
    -            }
    -          } else if ((strcmp(argv[i], "-proxy") == 0)) {
    -            proxy_flag = 1;
    -            Swig_mark_arg(i);
    -          } else if (strcmp(argv[i], "-keyword") == 0) {
    -            use_kw = 1;
    -            Swig_mark_arg(i);
    -          } else if (strcmp(argv[i], "-help") == 0) {
    -            fputs(usage, stderr);
    -          }
    -          ...
    +    if (argv[i]) {
    +      if (strcmp(argv[i], "-interface") == 0) {
    +        if (argv[i+1]) {
    +          interface = NewString(argv[i+1]);
    +          Swig_mark_arg(i);
    +          Swig_mark_arg(i+1);
    +          i++;
    +        } else {
    +          Swig_arg_error();
    +        }
    +      } else if (strcmp(argv[i], "-globals") == 0) {
    +        if (argv[i+1]) {
    +          global_name = NewString(argv[i+1]);
    +          Swig_mark_arg(i);
    +          Swig_mark_arg(i+1);
    +          i++;
    +        } else {
    +          Swig_arg_error();
    +        }
    +      } else if ((strcmp(argv[i], "-proxy") == 0)) {
    +        proxy_flag = 1;
    +        Swig_mark_arg(i);
    +      } else if (strcmp(argv[i], "-keyword") == 0) {
    +        use_kw = 1;
    +        Swig_mark_arg(i);
    +      } else if (strcmp(argv[i], "-help") == 0) {
    +        fputs(usage, stderr);
           }
    +      ...
    +    }
       }
     }
     
    @@ -3164,7 +3164,7 @@ these kinds of problems.

    Examples/Makefile.in -
    Nothing special here; see comments at top the of this file +
    Nothing special here; see comments at the top of this file and look to the existing languages for examples.
    Examples/qux99/check.list diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index f25e9850b..820921bd5 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -639,12 +639,12 @@ public: virtual ~FooBarAbstract() {}; std::string FooBar() { - return this->Foo() + ", " + this->Bar(); + return this->Foo() + ", " + this->Bar(); }; protected: virtual std::string Foo() { - return "Foo"; + return "Foo"; }; virtual std::string Bar() = 0; diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index bd259e60d..3b6cb3a05 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -94,6 +94,9 @@
  • Director threading issues
  • Director performance tuning
  • Java exceptions from directors +
  • Accessing protected members
  • Common customization features @@ -3746,12 +3749,10 @@ Naturally, the SWIG generated C++ code and the generated Java intermediary class
    -public class DirectorDerived extends DirectorBase {
    -  public DirectorDerived() {
    -  }
    -
    +class DirectorDerived extends DirectorBase {
    +  @Override
       public void upcall_method() {
    -    System.out.println("DirectorDerived::upcall_method() invoked.");
    +    System.out.println("DirectorDerived.upcall_method() invoked.");
       }
     }
     
    @@ -3774,7 +3775,7 @@ will result in the following being output:
    -DirectorDerived::upcall_method() invoked.
    +DirectorDerived.upcall_method() invoked.
     
    @@ -3825,45 +3826,186 @@ The disadvantage is that invocation of director methods from C++ when Java doesn

    With directors routing method calls to Java, and proxies routing them to C++, the handling of exceptions is an important concern. -The default behavior from SWIG 3.0 -onwards is to convert the thrown Java exception into a SWIG defined -DirectorException C++ exception. -SWIG 2.0 and earlier versions didn't provide any mechanism to handle the Java director method exceptions in C++. +The default behavior for Java exceptions thrown in a director method overridden in Java is +to store the thrown Java exception into a SWIG defined +Swig::DirectorException C++ class exception in the C++ layer and then throw this C++ exception.

    -Converting Java exceptions into C++ exceptions can be done in two different ways using -the director:except feature. -In the simplest approach, a code block is attached to each director method to -handle the mapping of Java exceptions into C++ exceptions. +Of course, should this exception be thrown, your C++ code must catch it and handle it before returning back to Java. +The default generated code does not attempt to handle the C++ exception, but there is a simple way +to make this all work by catching the C++ exception and extracting the original Java exception by using %catches for Swig::DirectorException. +Consider the example shown earlier with a modification to the upcall_method Java method to throw a Java exception:

    -%feature("director:except") MyClass::method(int x) {
    -  jthrowable $error = jenv->ExceptionOccurred();
    -  if ($error) {
    -    jenv->ExceptionClear();
    -    if (Swig::ExceptionMatches(jenv, $error, "java/lang/IndexOutOfBoundsException"))
    -      throw std::out_of_range(Swig::JavaExceptionMessage(jenv, $error).message());
    -    if (Swig::ExceptionMatches(jenv, $error, "$packagepath/MyJavaException"))
    -      throw MyCppException(Swig::JavaExceptionMessage(jenv, $error).message());
    -    throw std::runtime_error("Unexpected exception thrown in MyClass::method");
    +class DirectorDerived extends DirectorBase {
    +  @Override
    +  public void upcall_method() {
    +    System.out.println("DirectorDerived.upcall_method() invoked.");
    +    throw new RuntimeException("There was a problem!");
       }
     }
    -
    -class MyClass {
    -  /** Throws either a std::out_of_range or MyCppException on error */
    -  void method(int x);
    -}
     

    -This approach allows a flexible mapping of Java exceptions thrown by director methods into -C++ exceptions expected by a C++ caller. There -need not be any C++ exception specifications on the C++ method. The -utility function Swig::ExceptionMatches +Now, by default, the JVM will abort when example.callup(director) is called as the C++ +Swig::DirectorException (storing the Java exception) is thrown and not handled by the callup method. +Needless to say this is not very user friendly and so the recommendation is to add the following +simple %catches directive before SWIG parses the callup function: +

    + +
    +
    +%catches(Swig::DirectorException) callup;
    +
    +
    + +

    +Or target all wrapped methods using: +

    + +
    +
    +%catches(Swig::DirectorException);
    +
    +
    + +

    +This tells SWIG to generate a C++ catch handler using some code from the throws typemap for Swig::DirectorException that SWIG supplies by default, see Exception handling with %catches. +This typemap code is written to simply catch the C++ Swig::DirectorException class and immediately +return to Java throwing the original Java exception that it has stored. +The net result is a stack trace containing the original Java exception including the location that the exception was thown from. +

    + +
    +
    +DirectorDerived.upcall_method() invoked.
    +Exception in thread "main" java.lang.RuntimeException: There was a problem!
    +    at DirectorDerived.upcall_method(runme.java:4)
    +    at exampleJNI.SwigDirector_DirectorBase_upcall_method(exampleJNI.java:20)
    +    at exampleJNI.callup(Native Method)
    +    at example.callup(example.java:12)
    +    at runme.main(runme.java:21)
    +
    +
    + +

    +More on the Swig::DirectorException class can be found in the next section which details how to customize the handling of director exceptions. +

    + +

    25.5.7.1 Customizing director exceptions

    + + +

    +This section is for advanced customization of director exceptions. +The recommendation for most users is to use the simple %catches directive described above as it should be sufficient for most users needs. +

    + +

    +The conversion of Java exceptions into C++ exceptions can be customized in two different ways using +the director:except feature. +In the first approach, a code block is attached to each director method to +handle the mapping of Java exceptions into C++ exceptions. +The code block is generated just after the call up from the C++ director method into the overloaded method in Java. Its primary function is to check if a Java exception has been thrown and then handle it in C++. +The example below converts a +java.lang.IndexOutOfBoundsException into a C++ std::out_of_range exception and converts a +user's Java MyJavaException into a C++ MyCppException exception. +If the Java exception doesn't match either of these, a fallback std::runtime_error C++ exception is thrown. +

    + +
    +
    +%feature("director:except") MyClass::dirmethod(int x) {
    +  jthrowable $error = jenv->ExceptionOccurred();
    +  if ($error) {
    +    if (Swig::ExceptionMatches(jenv, $error, "java/lang/IndexOutOfBoundsException"))
    +      throw std::out_of_range(Swig::JavaExceptionMessage(jenv, $error).message());
    +    if (Swig::ExceptionMatches(jenv, $error, "$packagepath/MyJavaException"))
    +      throw MyCppException(Swig::JavaExceptionMessage(jenv, $error).message());
    +    throw std::runtime_error("Unexpected exception thrown in MyClass::dirmethod");
    +  }
    +}
    +
    +class MyClass {
    +public:
    +  /** Throws either a std::out_of_range or MyCppException on error */
    +  virtual void dirmethod(int x);
    +  virtual ~MyClass();
    +};
    +
    +
    + +

    +A few special variables are expanded within the director:except feature. +

    +
      +
    • The special variable $error is expanded into a unique variable name (swigerror) + and should be used for the assignment of the jthrowable exception that occurred.
    • +
    • The special variable $packagepath is + replaced by the outer package provided for SWIG generation by the -package option.
    • +
    • The special variable $directorthrowshandlers is not shown above, but is replaced + by applicable "directorthrows" typemap contents (covered later in this section).
    • +
    • The special variable $null is not shown above, but is replaced + by a suitable default constructed object for returning from the director method (or nothing if + the director method has a void return). +
    • +
    + +

    +Utility functions/classes in director.swg are provided to aid the exception conversion as follows: +

    + +
    +
    +namespace Swig {
    +
    +  // Helper method to determine if a Java throwable matches a particular Java class type
    +  // Note side effect of clearing any pending exceptions
    +  bool ExceptionMatches(JNIEnv *jenv, jthrowable throwable, const char *classname);
    +
    +  // Helper class to extract the exception message from a Java throwable
    +  class JavaExceptionMessage {
    +  public:
    +    JavaExceptionMessage(JNIEnv *jenv, jthrowable throwable);
    +
    +    // Return a C string of the exception message in the jthrowable passed in the constructor
    +    // If no message is available, null_string is return instead
    +    const char *message(const char *null_string = 
    +                        "Could not get exception message in JavaExceptionMessage") const;
    +  };
    +
    +  // C++ Exception class for handling Java exceptions thrown during a director method Java upcall
    +  class DirectorException : public std::exception {
    +  public:
    +
    +    // Construct exception from a Java throwable
    +    DirectorException(JNIEnv *jenv, jthrowable throwable);
    +
    +    // More general constructor for handling as a java.lang.RuntimeException
    +    DirectorException(const char *msg);
    +
    +    // Return exception message extracted from the Java throwable
    +    const char *what() const throw();
    +
    +    // Reconstruct and raise/throw the Java Exception that caused the DirectorException
    +    // Note that any error in the JNI exception handling results in a Java RuntimeException
    +    void throwException(JNIEnv *jenv) const;
    +
    +    // Create and throw the DirectorException
    +    static void raise(JNIEnv *jenv, jthrowable throwable) {
    +      throw DirectorException(jenv, throwable);
    +    }
    +  };
    +
    +}
    +
    +
    + +

    +The utility function Swig::ExceptionMatches and class Swig::JavaExceptionMessage are provided to simplify writing code for wrappers that use the director:except feature. The function Swig::ExceptionMatches matches the type of the @@ -3871,13 +4013,10 @@ function Swig::ExceptionMatches matches the type of the name, such as "java/lang/IOError". If the throwable class is the same type, or derives from the given type, Swig::ExceptionMatches will return true. Care must be taken to provide the correct fully qualified name, since for wrapped exceptions the -generated proxy class will have additional package qualification, depending on +generated proxy class will have an additional package qualification, depending on the '-package' argument and use of the nspace - feature. The special variable $error is expanded by SWIG into a unique variable name and -should be used for the -assignment of the exception that occurred. The special variable $packagepath is -replaced by the outer package provided for SWIG generation by the -package -option. The utility class Swig::JavaExceptionMessage is a holder + feature. +The utility class Swig::JavaExceptionMessage is a holder providing access to the message from the thrown Java exception. The message() method returns the exception message as a const char *, which is only valid during the lifetime of the holder. Any code using this message @@ -3885,20 +4024,27 @@ needs to copy it, for example into a std::string or a newly constructed C++ exce

    -Using the above approach to +Using the first approach above to write handlers for a large number of methods will require -repetitive duplication of the director:except feature code. -To mitigate this, an alternative approach is provided via typemaps in a +repetitive duplication of the director:except feature code +for each director method. +To mitigate this, a second approach is provided via typemaps in a fashion analagous to -the "throws" typemap. The -"throws" typemap provides an approach to automatically map all the C++ +the "throws" typemap. +The "throws" typemap provides a way to map all the C++ exceptions listed in a method's defined exceptions (either from a C++ exception specification or a %catches feature) into Java exceptions. The "directorthrows" typemap provides the inverse mapping and should contain code to convert a suitably matching Java exception into a C++ exception. +Only use this typemap if you wish to write custom conversions of Java exceptions into C++ exceptions +and apply them to many different methods. +The default handling which uses the Swig::DirectorException class should otherwise meet your needs. +

    + +

    The example below converts a Java java.lang.IndexOutOfBoundsException exception -to the typemap's type, that is std::out_of_range: +to the typemap's type, that is a std::out_of_range C++ exception:

    @@ -3913,7 +4059,7 @@ to the typemap's type, that is std::out_of_range:
     

    The "directorthrows" typemap is then used in conjunction with the director:except feature if the $directorthrowshandlers special variable -is used in the feature code. Consider the following, which also happens to be the default: +is used in the code block. Consider the following, which also happens to be the default:

    @@ -3921,31 +4067,41 @@ is used in the feature code. Consider the following, which also happens to be th %feature("director:except") %{ jthrowable $error = jenv->ExceptionOccurred(); if ($error) { - jenv->ExceptionClear(); $directorthrowshandlers - throw Swig::DirectorException(jenv, $error); + Swig::DirectorException::raise(jenv, $error); } %}
    -

    The code generated using the director:except feature -replaces the $directorthrowshandlers special variable with the code in -the "directorthrows" typemaps, for each and every exception defined for the method. -The possible exceptions can be defined either with a C++ exception +

    +where Swig::DirectorException::raise is the helper method to throw a C++ Swig::DirectorException, see above. +The code generated from the director:except feature +has the $directorthrowshandlers special variable replaced with the code in +the relevant "directorthrows" typemaps, for each and every exception defined for the method. +The relevant exceptions can be defined either with a C++ exception specification or %catches as described for the "throws" typemap.

    -Consider the following director method: +Let's try and put all this together by considering the following director method:

    -  ...
    +struct X {
       virtual void doSomething(int index) throw (std::out_of_range);
       ...
    +};
    +
    +OR
    +
    +%catches(std::out_of_range) X::doSomething;
    +struct X {
    +  virtual void doSomething(int index);
    +  ...
    +};
     
    @@ -3958,12 +4114,10 @@ the resulting code generated in the director method after calling up to Java wil
     jthrowable swigerror = jenv->ExceptionOccurred();
     if (swigerror) {
    -  jenv->ExceptionClear();
       if (Swig::ExceptionMatches(jenv, swigerror, "java/lang/IndexOutOfBoundsException")) {
         throw std::out_of_range(Swig::JavaExceptionMessage(jenv, swigerror).message());
       }
    -  
    -  throw Swig::DirectorException(jenv, swigerror);
    +  Swig::DirectorException::raise(jenv, swigerror);
     }
     
    @@ -3971,7 +4125,7 @@ if (swigerror) {

    Note: Beware of using exception specifications as the SWIG director methods will be generated with the same exception specifications and if the -director method throws an exception that is not specified it is likely +director method throws an exception that is not specified in the exception specifications list it is likely to terminate your program. See the C++ standard for more details. Using the %catches feature instead to define the handled exceptions does not suffer this potential fate. @@ -3979,8 +4133,9 @@ this potential fate.

    Because the default code generation maps any unhandled Java exceptions to Swig::DirectorException, any director methods that have exception -specifications may cause program termination. To simply ignore -unexpected exceptions, the default handling can be changed with: +specifications may cause program termination as this exception class won't be in the exception specifications list. +You can avoid throwing Swig::DirectorException by changing the default handling for all methods by adding a director:except feature without any method name. +For example, you can just ignore them:

    @@ -3988,8 +4143,8 @@ unexpected exceptions, the default handling can be changed with: %feature("director:except") %{ jthrowable $error = jenv->ExceptionOccurred(); if ($error) { - jenv->ExceptionClear(); $directorthrowshandlers + jenv->ExceptionClear(); return $null; // exception is ignored } %} @@ -3999,7 +4154,7 @@ unexpected exceptions, the default handling can be changed with:

    Alternatively an exception compatible with the existing director method exception specifications can be thrown. Assuming that all methods allow std::runtime_error to be thrown, -the return $null; could be changed to: +the return $null line above could be changed to:

    @@ -4009,124 +4164,296 @@ the return $null; could be changed to:

    In more complex situations, a separate director:except feature -may need to be attached to specific methods. +may need to be attached to specific methods by providing a method name to the director:except feature.

    -

    Below is a complete example demonstrating the use -of the "directorthrows" typemaps. In this example, a -generic "directorthrows" typemap is appropriate for all three exceptions - all -take single string constructors. If the exceptions had different constructors, -it would be necessary to have separate typemaps for each exception type. +

    This is all no doubt quite hard to follow without seeing a full example and some code. +Below is a complete example demonstrating the use +of most of the exception customizations one can use, that is, +"directorthrows" and "throws" typemaps, %exception and %catches. +See the Exception handling with %exception and %javaexception +section for more on converting C++ exceptions to Java exceptions. +The example also has a user defined C++ exception class called MyNS::MyException and this is wrapped as a Java exception. +The director class being wrapped is MyClass and the director method is called MyClass::dirmethod. +A number of std::cout calls have been added to help understand code flow. +You can copy the code below into an interface file and run SWIG on it and examine the generated code. -

     %module(directors="1") example
     
     %{
    -  #include <string>
       #include <stdexcept>
    +  #include <iostream>
     %}
     
    -// Define exceptions in header section using std::runtime_error
    -%define DEFINE_EXCEPTION(NAME)
    -%{
    -  namespace MyNS {
    -    struct NAME : public std::runtime_error { NAME(const std::string &what) : runtime_error(what) {} };
    +// Generic catch handler for all wrapped methods
    +%exception %{
    +  try {
    +    $action
    +  } catch (const std::exception &e) {
    +    std::cout << "Generic std::exception catch handler" << std::endl;
    +    jclass clazz = jenv->FindClass("java/lang/RuntimeException");
    +    jenv->ThrowNew(clazz, e.what()); 
    +    return $null;
       }
     %}
    -%enddef
     
    -// Expose C++ exceptions as Java Exceptions by changing the Java base class and providing a getMessage()
    -%define DECLARE_EXCEPTION(NAME)
    -%typemap(javabase) MyNS::NAME "java.lang.Exception";
    -%rename(getMessage) MyNS::NAME::what;
    +// Expose C++ exception as a Java Exception by changing the Java base class and providing a getMessage()
    +%typemap(javabase) MyNS::MyException "java.lang.RuntimeException";
    +%rename(getMessage) MyNS::MyException::whatsup;
    +
    +%inline %{
     namespace MyNS {
    -  struct NAME {
    -    NAME(const std::string& what);
    -    const char * what();
    +  class MyException {
    +    std::string msg;
    +  public:
    +    MyException(const char *msg) : msg(msg) {}
    +    const char * whatsup() const { return msg.c_str(); }
       };
     }
    -%enddef
    -
    -DEFINE_EXCEPTION(ExceptionA)
    -DEFINE_EXCEPTION(ExceptionB)
    -DEFINE_EXCEPTION(Unexpected)
    -
    -// Mark three methods to map director thrown exceptions.
    -%feature("director:except") MyClass::meth1(int);
    -%feature("director:except") MyClass::meth2;
    -%feature("director:except") meth3;
    -
    -%typemap(directorthrows) MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected %{
    -  if (Swig::ExceptionMatches(jenv, $error, "$packagepath/$javaclassname"))
    -    throw $1_type(Swig::JavaExceptionMessage(jenv, $error).message());
     %}
     
    -DECLARE_EXCEPTION(ExceptionA)
    -DECLARE_EXCEPTION(ExceptionB)
    -DECLARE_EXCEPTION(Unexpected)
    +%typemap(directorthrows) MyNS::MyException %{
    +  if (Swig::ExceptionMatches(jenv, $error, "$packagepath/MyException")) {
    +    std::cout << "$1_type exception matched (directorthrows typemap)" << std::endl;
    +    throw $1_type(Swig::JavaExceptionMessage(jenv, $error).message());
    +  }
    +%}
     
    -%catches(MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected) MyClass::meth2();
    +%typemap(throws) MyNS::MyException %{
    +  std::cout << "$1_type caught (throws typemap)" << std::endl;
    +  jclass excep = jenv->FindClass("MyException");
    +  if (excep) {
    +    std::cout << "$1_type class found (throws typemap)" << std::endl;
    +    jenv->ThrowNew(excep, $1.whatsup());
    +  }
    +  return $null;
    +%}
     
    -%inline {
    -  class MyClass {
    -  public:
    -    virtual void meth1(int x) throw(MyNS::ExceptionA, MyNS::ExceptionB) = 0;
    -    virtual void meth2() = 0;   /* throws MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected */
    -    virtual void meth3(float x) throw(MyNS::Unexpected) = 0;
    -    virtual ~MyClass() {}
    -  };
    +// These are the exceptions that the director method MyClass::dirmethod will have catch handlers for.
    +// Note that this is also a virtual method / director method and the C++ exceptions listed can be
    +// thrown after converting them from Java exceptions.
    +%catches(MyNS::MyException, Swig::DirectorException) MyClass::dirmethod;
    +
    +// These are the exceptions that call_dirmethod C++ wrapper will have catch handlers for.
    +// Note that this is not a virtual method, hence not a director method.
    +%catches(MyNS::MyException, Swig::DirectorException) call_dirmethod;
    +
    +%feature("director") MyClass;
    +
    +%feature("director:except") MyClass::dirmethod(int x) {
    +  jthrowable $error = jenv->ExceptionOccurred();
    +  if ($error) {
    +    std::cout << "Upcall finished, an exception was thrown in Java" << std::endl;
    +    $directorthrowshandlers
    +    std::cout << "Upcall finished, no exception conversion, throwing DirectorException" << std::endl;
    +    Swig::DirectorException::raise(jenv, $error);
    +  }
     }
    +
    +%inline %{
    +class MyClass {
    +public:
    +  /** Throws either a std::out_of_range or MyException on error */
    +  virtual void dirmethod(int x) {
    +    if (x <= 0)
    +      throw std::out_of_range("MyClass::dirmethod index is out of range");
    +    else if (x == 1)
    +      throw MyNS::MyException("MyClass::dirmethod some problem!");
    +  }
    +  virtual ~MyClass() {}
    +  static void call_dirmethod(MyClass& c, int x) {
    +    return c.dirmethod(x);
    +  }
    +};
    +%}
     

    -In this case the three different "directorthrows" typemaps will be used -to generate the three different exception handlers for -meth1, meth2 and meth3. The generated -handlers will have "if" blocks for each exception type specified, in -the exception specification or %catches feature. -

    - -

    Note that the "directorthrows" typemaps are important -only if it is important for the the exceptions passed through the C++ -layer to be mapped to distinct C++ exceptions. If director methods -are being called by C++ code that is itself wrapped in a -SWIG generated Java wrapper and access is always through this wrapper, -the default Swig::DirectorException class provides enough information -to reconstruct the original exception. In this case removing the -$directorthrowshandlers special variable from the -default director:except feature and simply always -throwing a Swig::DirectorException will achieve the desired result. -Along with this a generic exception feature is added to convert any -caught Swig::DirectorExceptions back into the underlying -Java exceptions via the Swig::DirectorException::raiseJavaException method, -as demonstrated with %javaexception below: +The generated code for the call_dirmethod wrapper contains the various exception handlers. +The outer exception handler is from the %exception directive and the others +are from the "throws" typemaps.

    -%javaexception("Exception") MyClass::myMethod %{
    +SWIGEXPORT void JNICALL Java_exampleJNI_MyClass_1call_1dirmethod(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
    +  ...
       try {
    -    $action
    -  } catch (Swig::DirectorException &e) {
    -    // raise/throw the Java exception that originally caused the DirectorException
    -    e.raiseJavaException(jenv);
    -    return $null;
    +    try {
    +      MyClass::call_dirmethod(*arg1,arg2);
    +    } catch(MyNS::MyException &_e) {
    +      std::cout << "MyNS::MyException caught (throws typemap)" << std::endl;
    +      jclass excep = jenv->FindClass("MyException");
    +      if (excep) {
    +        std::cout << "MyNS::MyException class found (throws typemap)" << std::endl;
    +        jenv->ThrowNew(excep, (&_e)->whatsup());
    +      }
    +      return ;
    +      
    +    } catch(Swig::DirectorException &_e) {
    +      (&_e)->throwException(jenv);
    +      return ; 
    +    }
    +  } catch (const std::exception &e) {
    +    std::cout << "Generic std::exception catch handler" << std::endl;
    +    jclass clazz = jenv->FindClass("java/lang/RuntimeException");
    +    jenv->ThrowNew(clazz, e.what()); 
    +    return ;
       }
    -%}
     

    -See the Exception handling with %exception and %javaexception -section for more on converting C++ exceptions to Java exceptions. +The director method calling up to Java contains the exception handling code from the "directorthrows" typemaps and director:except feature.

    +
    +
    +void SwigDirector_MyClass::dirmethod(int x) {
    +      ... [call up to Java using CallStaticVoidMethod]
    +      jthrowable swigerror = jenv->ExceptionOccurred();
    +      if (swigerror) {
    +        std::cout << "Upcall finished, an exception was thrown in Java" << std::endl;
    +        
    +        if (Swig::ExceptionMatches(jenv, swigerror, "MyException")) {
    +          std::cout << "MyNS::MyException exception matched (directorthrows typemap)" << std::endl;
    +          throw MyNS::MyException(Swig::JavaExceptionMessage(jenv, swigerror).message());
    +        }
    +        
    +        std::cout << "Upcall finished, no exception conversion, throwing DirectorException" << std::endl;
    +        Swig::DirectorException::raise(jenv, swigerror);
    +      }
    +
    +
    + +

    +Let's use the following Java class to override the director method. +

    + +
    +
    +class DerivedClass extends MyClass {
    +  @Override
    +  public void dirmethod(int x) {
    +    if (x < 0)
    +      throw new IndexOutOfBoundsException("Index is negative");
    +    else if (x == 0)
    +      throw new MyException("MyException: bad dirmethod");
    +  }
    +}
    +public class runme {
    +  public static void main(String argv[]) {
    +    System.loadLibrary("example");
    +    ... code snippets shown below ...
    +  }
    +}
    +
    +
    + +

    +Consider the output using the Java code in the four slightly different scenarios below. +

    + +

    +1. Non-director C++ class is used, thus, no upcall to a Java director method is made. +A std::out_of_range exception is thrown, which is derived from std::exception, +and hence caught by the generic exception handler in the call_dirmethod wrapper. +The Java code snippet and resulting output is: +

    + + +
    +
    +MyClass.call_dirmethod(new MyClass(), 0);
    +
    +
    + +
    +
    +Generic std::exception catch handler
    +Exception in thread "main" java.lang.RuntimeException: MyClass::dirmethod index is out of range
    +        at exampleJNI.MyClass_call_dirmethod(Native Method)
    +        at MyClass.call_dirmethod(MyClass.java:57)
    +        at runme.main(runme.java:14)
    +
    +
    + +

    +2. Non-director C++ class again but this time the MyNS::MyException class is thrown and caught: +

    + +
    +
    +MyClass.call_dirmethod(new MyClass(), 1);
    +
    +
    + +
    +
    +MyNS::MyException caught (throws typemap)
    +MyNS::MyException class found (throws typemap)
    +Exception in thread "main" MyException: MyClass::dirmethod some problem!
    +        at exampleJNI.MyClass_call_dirmethod(Native Method)
    +        at MyClass.call_dirmethod(MyClass.java:57)
    +        at runme.main(runme.java:15)
    +
    +
    + +

    +3. The DerivedClass director class is used so the upcall to Java occurs, but it throws +a Java MyException, which gets converted into a C++ MyNS::MyException, then caught and converted back +into a Java MyException: +

    + +
    +
    +MyClass.call_dirmethod(new DerivedClass(), 0);
    +
    +
    + +
    +
    +Upcall finished, an exception was thrown in Java
    +MyNS::MyException exception matched (directorthrows typemap)
    +MyNS::MyException caught (throws typemap)
    +MyNS::MyException class found (throws typemap)
    +Exception in thread "main" MyException: MyException: bad dirmethod
    +        at exampleJNI.MyClass_call_dirmethod(Native Method)
    +        at MyClass.call_dirmethod(MyClass.java:57)
    +        at runme.main(runme.java:16)
    +
    +
    + +

    +4. The director class is used again, but this time the director method throws a Java IndexOutOfBoundsException exception which is converted into a C++ Swig::DirectorException, thrown and caught again. +This time the original Java exception is extracted from the Swig::DirectorException and rethrown. +Note that this approach keeps the stack trace information of the original exception, so it has the exact location of where the IndexOutOfBoundsException exception was thrown. +This is arguably an improvement over the approach above that converts from a Java excepton to C++ exception and then back to a new Java exception, losing the location of the original exception. +

    + +
    +
    +MyClass.call_dirmethod(new DerivedClass(), -1);
    +
    +
    + +
    +
    +Upcall finished, an exception was thrown in Java
    +Upcall finished, no exception conversion, throwing DirectorException
    +Exception in thread "main" java.lang.IndexOutOfBoundsException: Index is negative
    +        at DerivedClass.dirmethod(runme.java:5)
    +        at exampleJNI.SwigDirector_MyClass_dirmethod(exampleJNI.java:23)
    +        at exampleJNI.MyClass_call_dirmethod(Native Method)
    +        at MyClass.call_dirmethod(MyClass.java:57)
    +        at runme.main(runme.java:17)
    +
    +
    +

    25.6 Accessing protected members

    @@ -4323,16 +4650,16 @@ struct Vector { %extend Vector { char *toString() { - static char tmp[1024]; - sprintf(tmp, "Vector(%g, %g, %g)", $self->x, $self->y, $self->z); - return tmp; + static char tmp[1024]; + sprintf(tmp, "Vector(%g, %g, %g)", $self->x, $self->y, $self->z); + return tmp; } Vector(double x, double y, double z) { - Vector *v = (Vector *) malloc(sizeof(Vector)); - v->x = x; - v->y = y; - v->z = z; - return v; + Vector *v = (Vector *) malloc(sizeof(Vector)); + v->x = x; + v->y = y; + v->z = z; + return v; } };
  • @@ -5266,7 +5593,7 @@ void * operator new(size_t t) { throw bad_alloc(); pJalloc->ref = 0; return static_cast<void *>( - static_cast<char *>(static_cast<void *>(pJalloc)) + sizeof(Jalloc)); + static_cast<char *>(static_cast<void *>(pJalloc)) + sizeof(Jalloc)); } } @@ -5681,6 +6008,17 @@ The most important of these implement the mapping of C/C++ types to Java types: In other words the typemap provides the conversion from the native method call return type. + +jboxtype +Java boxed type. + These are Java code typemaps to provide the Java boxed type, such as, Integer for C type int. + As autoboxing is only relevant to the Java primitive types, these are only provided for the + C types that map to Java primitive types. + This typemap is usually only used by C++ STL container wrappers that are wrapped by Java generic + types as the boxed type must be used instead of the unboxed/primitive type when declaring a Java generic type. + + + javadirectorin Conversion from jtype to jstype for director methods. @@ -7217,7 +7555,7 @@ public class runme { example.print_args(animals); String args[] = example.get_args(); for (int i=0; i<args.length; i++) - System.out.println(i + ":" + args[i]); + System.out.println(i + ":" + args[i]); } }
    @@ -8142,40 +8480,52 @@ public class Container { // Ensure that the GC doesn't collect any Element set from Java // as the underlying C++ class stores a shallow copy private Element elementReference; - private long getCPtrAndAddReference(Element element) { - elementReference = element; - return Element.getCPtr(element); - } public void setElement(Element e) { - exampleJNI.Container_setElement(swigCPtr, this, getCPtrAndAddReference(e), e); + exampleJNI.Container_setElement(swigCPtr, this, Element.getCPtr(e), e); + elementReference = e; } }

    -The following typemaps will generate the desired code. -The 'javain' typemap matches the input parameter type for the setElement method. -The 'javacode' typemap simply adds in the specified code into the Java proxy class. +The following typemaps can be used to generate this code:

    -%typemap(javain) Element *e "getCPtrAndAddReference($javainput)"
    -
     %typemap(javacode) Container %{
       // Ensure that the GC doesn't collect any element set from Java
       // as the underlying C++ class stores a shallow copy
       private Element elementReference;
    -  private long getCPtrAndAddReference(Element element) {
    -    elementReference = element;
    -    return Element.getCPtr(element);
    -  }
     %}
    +
    +%typemap(javain, 
    +         post="      elementReference = $javainput;"
    +         ) Element *e "Element.getCPtr($javainput)"
     
    +

    +The 'javacode' typemap simply adds in the specified code into the Java proxy class. +The 'javain' typemap matches the input parameter type and name for the setElement method and +the 'post' typemap attribute allows adding code after the JNI call. +The 'post' code is generated into a finally block after the JNI call so the resulting code isn't quite +as mentioned earlier, setElement is actually: +

    + +
    +
    +  public void setElement(Element e) {
    +    try {
    +      exampleJNI.Container_setElement(swigCPtr, this, Element.getCPtr(e), e);
    +    } finally {
    +      elementReference = e;
    +    }
    +  }
    +
    +

    25.10.13 Date marshalling using the javain typemap and associated attributes

    diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 4bad9a03e..8a9053917 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -12,26 +12,33 @@
    -

    9.4 STL/C++ Library

    +

    9.4 STL/C++ library

    @@ -1385,16 +1393,24 @@ The following table shows which C++ classes are supported and the equivalent SWI SWIG Interface library file + std::array (C++11) array std_array.i std::auto_ptr memory std_auto_ptr.i + std::complex complex std_complex.i std::deque deque std_deque.i std::list list std_list.i std::map map std_map.i + std::multimap (C++11) multimap std_multimap.i + std::multiset (C++11) multiset std_multiset.i std::pair utility std_pair.i std::set set std_set.i std::string string std_string.i + std::unordered_map (C++11) unordered_map std_unordered_map.i + std::unordered_multimap (C++11) unordered_multimap std_unordered_multimap.i + std::unordered_multiset (C++11) unordered_multiset std_unordered_multiset.i + std::unordered_set (C++11) unordered_set std_unordered_set.i std::vector vector std_vector.i - std::array array (C++11) std_array.i - std::shared_ptr shared_ptr (C++11) std_shared_ptr.i + std::wstring wstring std_wstring.i + std::shared_ptr (C++11) shared_ptr std_shared_ptr.i @@ -1460,7 +1476,7 @@ In the target language:

     x = my_struct();
    -x.foo="Hello World";      # assign with string
    +x.foo = "Hello World";    # assign with string
     print x.foo;              # print as string
     
    @@ -1720,6 +1736,9 @@ Any thrown STL exceptions will then be gracefully handled instead of causing a c

    9.4.4 shared_ptr smart pointer

    +

    9.4.4.1 shared_ptr basics

    + +

    Some target languages have support for handling the shared_ptr reference counted smart pointer. This smart pointer is available in the standard C++11 library as std::shared_ptr. @@ -1813,8 +1832,11 @@ System.out.println(val1 + " " + val2);

    +

    9.4.4.2 shared_ptr and inheritance

    + +

    -This shared_ptr library works quite differently to SWIG's normal, but somewhat limited, +The shared_ptr library works quite differently to SWIG's normal, but somewhat limited, smart pointer handling. The shared_ptr library does not generate extra wrappers, just for smart pointer handling, in addition to the proxy class. The normal proxy class including inheritance relationships is generated as usual. @@ -1892,7 +1914,7 @@ Adding the missing %shared_ptr macros will fix this:

    -%include "boost_shared_ptr.i"
    +%include <boost_shared_ptr.i>
     %shared_ptr(GrandParent);
     %shared_ptr(Parent);
     %shared_ptr(Child);
    @@ -1901,10 +1923,75 @@ Adding the missing %shared_ptr macros will fix this:
     
    +

    9.4.4.3 shared_ptr and method overloading

    + +

    -Note: There is somewhat limited support for %shared_ptr and the director feature -and the degrees of success varies among the different target languages. -Please help to improve this support by providing patches with improvements. +A C++ compiler can disambiguate a method overloaded by a shared_ptr and one using the raw underlying type. +For example, either one of these methods can be called in C++: +

    + +
    +
    +int age(std::shared_ptr<GrandParent> num);
    +int age(GrandParent& num);
    +
    +
    + +

    +When wrapped by SWIG, disambiguation is not possible using the overloaded names as there is just one equivalent type (GrandParent) in the target language. +SWIG will choose to wrap just the first method by default. +Ambiguity in overloading discusses ways to control which method(s) gets wrapped using %ignore or %rename. +For the interested reader, SWIG detects that they are equivalent types via the typecheck typemaps in the shared_ptr library. +

    + +

    9.4.4.4 shared_ptr and templates

    + + +

    +The %shared_ptr macro should be used for all the required instantiations +of the template before each of the %template instantiations. +For example, consider number.h containing the following illustrative template: +

    + +
    +
    +#include <memory>
    +
    +template<int N> struct Number {
    +  int num;
    +  Number() : num(N) {}
    +  static std::shared_ptr<Number<N>> make() { return std::make_shared<Number<N>>(); }
    +};
    +
    +
    + +

    +The SWIG code below shows the required ordering: +

    + +
    +
    +%include <std_shared_ptr.i>
    +
    +%shared_ptr(Number<10>);
    +%shared_ptr(Number<42>);
    +
    +%{
    +  #include "number.h"
    +%}
    +%include "number.h"
    +
    +%template(Number10) Number<10>;
    +%template(Number42) Number<42>;
    +
    +
    + +

    9.4.4.5 shared_ptr and directors

    + + +

    +The languages that support shared_ptr also have support for using shared_ptr with directors.

    diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index ba42f735c..7bf8562c5 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -122,9 +122,12 @@ swig -cffi -help

    27.2.2 Generating CFFI bindings

    +

    + As we mentioned earlier the ideal way to use SWIG is to use interface files. To illustrate the use of it, let's assume that we have a file named test.h with the following C code: +

     #define y 5
    @@ -155,7 +158,10 @@ void lispsort_double (int n, double * array);
     enum color { RED, BLUE, GREEN};
     
    +

    Corresponding to this we will write a simple interface file: +

    +
     %module test
     
    @@ -163,7 +169,9 @@ Corresponding to this we will write a simple interface file:
     
     
    +

    The generated SWIG Code will be: +

     ;;;SWIG wrapper code starts here
    @@ -430,8 +438,10 @@ Also, while parsing the C++ file and generating C wrapper code SWIG
     %include "target/header.h"
     
     
    +

    Various features which were available for C headers can also be used here. The target header which we are going to use here is: +

     namespace OpenDemo {
       class Test
    @@ -478,8 +488,10 @@ namespace OpenDemo {
     %include "test.cpp"
     
    +

    SWIG generates 3 files, the first one is a C wrap which we don't show, the second is the plain CFFI wrapper which is as shown below: +

     (cffi:defcfun ("_wrap_Test_x_set" Test_x_set) :void
       (self :pointer)
    @@ -528,11 +540,13 @@ SWIG generates 3 files, the first one is a C wrap which we don't show,
     (cffi:defcfun ("_wrap_RandomUnitVectorOnXZPlane" RandomUnitVectorOnXZPlane) :pointer)
     
    +

    The output is pretty good but it fails in disambiguating overloaded functions such as the constructor, in this case. One way of resolving this problem is to make the interface use the rename directiv, but hopefully there are better solutions. In addition SWIG also generates, a CLOS file +

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html
    index c94fe31dc..c5c944225 100644
    --- a/Doc/Manual/Lua.html
    +++ b/Doc/Manual/Lua.html
    @@ -1008,11 +1008,10 @@ The following operators cannot be overloaded (mainly because they are not suppor
     

    SWIG also accepts the __str__() member function which converts an object to a string. This function should return a const char*, preferably to static memory. This will be used for the print() and tostring() functions in Lua. Assuming the complex class has a function

    -
    const char* __str__()
    -{
    -        static char buffer[255];
    -        sprintf(buffer, "Complex(%g, %g)", this->re(), this->im());
    -        return buffer;
    +
    const char* __str__() {
    +  static char buffer[255];
    +  sprintf(buffer, "Complex(%g, %g)", this->re(), this->im());
    +  return buffer;
     }
     

    @@ -1031,11 +1030,10 @@ Complex(10, 12)

    It is also possible to overload the operator[], but currently this cannot be automatically performed. To overload the operator[] you need to provide two functions, __getitem__() and __setitem__()

    -
    class Complex
    -{
    -        //....
    -        double __getitem__(int i)const; // i is the index, returns the data
    -        void __setitem__(int i, double d); // i is the index, d is the data
    +
    class Complex {
    +  //....
    +  double __getitem__(int i)const; // i is the index, returns the data
    +  void __setitem__(int i, double d); // i is the index, d is the data
     };
     

    diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 96e9f7517..8ea43ad6b 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -949,7 +949,7 @@ Foo *BarToFoo(Bar *b) { } Foo *IncrFoo(Foo *f, int i) { - return f+i; + return f+i; } %}

    @@ -1057,7 +1057,7 @@ produces a single accessor function like this:
     int *Foo_x_get(Foo *self) {
    -    return self->x;
    +  return self->x;
     };
     
    @@ -1092,11 +1092,11 @@ generates accessor functions such as this:
     Foo *Bar_f_get(Bar *b) {
    -    return &b->f;
    +  return &b->f;
     }
     
     void Bar_f_set(Bar *b, Foo *val) {
    -    b->f = *val;
    +  b->f = *val;
     }
     
    @@ -1633,9 +1633,8 @@ class DoubleArray { void setitem(int i, double val) { if ((i >= 0) && (i < n)) ptr[i] = val; - else { + else throw RangeError(); - } } };
    @@ -1888,9 +1887,9 @@ like this:
     %typemap(out) int {
    -    $result = sv_newmortal();
    -    set_setiv($result, (IV) $1);
    -    argvi++;
    +  $result = sv_newmortal();
    +  set_setiv($result, (IV) $1);
    +  argvi++;
     }
     
    @@ -2313,8 +2312,8 @@ Consider the following data structure:
     #define SIZE  8
     typedef struct {
    -    int   values[SIZE];
    -    ...
    +  int   values[SIZE];
    +  ...
     } Foo;
     
     
    @@ -2328,10 +2327,10 @@ To make the member writable, a "memberin" typemap can be used.
     %typemap(memberin) int [SIZE] {
    -    int i;
    -    for (i = 0; i < SIZE; i++) {
    -        $1[i] = $input[i];
    -    }
    +  int i;
    +  for (i = 0; i < SIZE; i++) {
    +    $1[i] = $input[i];
    +  }
     }
     
     
    @@ -2600,48 +2599,48 @@ package example::Vector; %BLESSEDMEMBERS = (); sub new () { - my $self = shift; - my @args = @_; - $self = vectorc::new_Vector(@args); - return undef if (!defined($self)); - bless $self, "example::Vector"; - $OWNER{$self} = 1; - my %retval; - tie %retval, "example::Vector", $self; - return bless \%retval, "Vector"; + my $self = shift; + my @args = @_; + $self = vectorc::new_Vector(@args); + return undef if (!defined($self)); + bless $self, "example::Vector"; + $OWNER{$self} = 1; + my %retval; + tie %retval, "example::Vector", $self; + return bless \%retval, "Vector"; } sub DESTROY { - return unless $_[0]->isa('HASH'); - my $self = tied(%{$_[0]}); - delete $ITERATORS{$self}; - if (exists $OWNER{$self}) { - examplec::delete_Vector($self)); - delete $OWNER{$self}; - } + return unless $_[0]->isa('HASH'); + my $self = tied(%{$_[0]}); + delete $ITERATORS{$self}; + if (exists $OWNER{$self}) { + examplec::delete_Vector($self)); + delete $OWNER{$self}; + } } sub FETCH { - my ($self, $field) = @_; - my $member_func = "vectorc::Vector_${field}_get"; - my $val = &$member_func($self); - if (exists $BLESSEDMEMBERS{$field}) { - return undef if (!defined($val)); - my %retval; - tie %retval, $BLESSEDMEMBERS{$field}, $val; - return bless \%retval, $BLESSEDMEMBERS{$field}; - } - return $val; + my ($self, $field) = @_; + my $member_func = "vectorc::Vector_${field}_get"; + my $val = &$member_func($self); + if (exists $BLESSEDMEMBERS{$field}) { + return undef if (!defined($val)); + my %retval; + tie %retval, $BLESSEDMEMBERS{$field}, $val; + return bless \%retval, $BLESSEDMEMBERS{$field}; + } + return $val; } sub STORE { - my ($self, $field, $newval) = @_; - my $member_func = "vectorc::Vector_${field}_set"; - if (exists $BLESSEDMEMBERS{$field}) { - &$member_func($self, tied(%{$newval})); - } else { - &$member_func($self, $newval); - } + my ($self, $field, $newval) = @_; + my $member_func = "vectorc::Vector_${field}_set"; + if (exists $BLESSEDMEMBERS{$field}) { + &$member_func($self, tied(%{$newval})); + } else { + &$member_func($self, $newval); + } }
    @@ -2842,11 +2841,11 @@ this:
     sub dot_product {
    -    my @args = @_;
    -    $args[0] = tied(%{$args[0]});         # Get the real pointer values
    -    $args[1] = tied(%{$args[1]});
    -    my $result = vectorc::dot_product(@args);
    -    return $result;
    +  my @args = @_;
    +  $args[0] = tied(%{$args[0]});         # Get the real pointer values
    +  $args[1] = tied(%{$args[1]});
    +  my $result = vectorc::dot_product(@args);
    +  return $result;
     }
     
    @@ -2985,7 +2984,7 @@ sub set_transform for (my $j = 0; $j < 4, $j++) { mat44_set($a, $i, $j, $x->[i][j]) - } + } } example.set_transform($im, $a); free_mat44($a); @@ -3104,14 +3103,14 @@ the methods one() and two() (but not three()): %feature("director") Foo; class Foo { public: - Foo(int foo); - virtual void one(); - virtual void two(); + Foo(int foo); + virtual void one(); + virtual void two(); }; class Bar: public Foo { public: - virtual void three(); + virtual void three(); }; @@ -3279,9 +3278,9 @@ suffice in most cases:
     %feature("director:except") {
    -    if ($error != NULL) {
    -        throw Swig::DirectorMethodException();
    -    }
    +  if ($error != NULL) {
    +    throw Swig::DirectorMethodException();
    +  }
     }
     
    @@ -3305,8 +3304,8 @@ suitable exception handler:
     %exception {
    -    try { $action }
    -    catch (Swig::DirectorException &e) { SWIG_fail; }
    +  try { $action }
    +  catch (Swig::DirectorException &e) { SWIG_fail; }
     }
     
    diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 52bedf87f..9fbfd75c0 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -163,7 +163,7 @@ If the module is in PHP's default extension directory, you can omit the path.

    For some SAPIs (for example, the CLI SAPI) you can instead use the dl() function to load -an extension at run time, by adding a like like this to the start of each +an extension at run time, by adding a line like this to the start of each PHP script which uses your extension:

    @@ -390,8 +390,7 @@ Although PHP does not support overloading functions natively, swig will generate dispatch functions which will use %typecheck typemaps to allow overloading. This dispatch function's operation and precedence is described in Wrapping -Overloaded Functions and Methods. +href="SWIGPlus.html#SWIGPlus_overloaded_methods">Overloaded functions and methods.

    a(40).p.p.A (B --> A) * ---> a(40).p.p.int (A --> int) * + * + * Using declarations are stored in the "typetab" hash table. For example, + * + * namespace NN { + * struct SS {}; + * } + * namespace N { + * struct S {}; + * using NN::SS; + * } + * using N::S; + * + * typetab in scope '' contains: + * "S" : "N::S" + * + * and typetab in scope 'N' contains: + * "SS" : "NN::SS" + * "S" : "S" + * + * * For inheritance, SWIG tries to resolve types back to the base class. For instance, if * you have this: * - * class Foo { - * public: - * typedef int Integer; - * }; + * class Foo { + * public: + * typedef int Integer; + * }; + * struct Bar : public Foo { + * void blah(Integer x); + * }; * - * class Bar : public Foo { - * void blah(Integer x); - * }; + * In this case typetab in scope '' contains: + * "Foo" : "Foo" + * "Bar" : "Bar" + * and scope 'Foo' contains: + * "Integer" : "int" + * and scope 'Bar' inherits from 'Foo' but is empty (observe that blah is not a scope or typedef) * * The argument type of Bar::blah will be set to Foo::Integer. * + * + * The scope-inheritance mechanism is used to manage C++ using directives. + * + * namespace XX { + * class CC {}; + * } + * namespace X { + * class C {}; + * using namespace XX; + * } + * using namespace X; + * + * typetab in scope '' inherits from 'X' + * typetab in scope 'X' inherits from 'XX' and contains: + * "C" : "C" + * typetab in scope 'XX' contains: + * "CC" : "CC" + * + * * The scope-inheritance mechanism is used to manage C++ namespace aliases. * For example, if you have this: * - * namespace Foo { - * typedef int Integer; - * } + * namespace Foo { + * typedef int Integer; + * } * - * namespace F = Foo; + * namespace F = Foo; * - * In this case, "F::" is defined as a scope that "inherits" from Foo. Internally, - * "F::" will merely be an empty scope that refers to Foo. SWIG will never + * In this case, F is defined as a scope that "inherits" from Foo. Internally, + * F will merely be an empty scope that points to Foo. SWIG will never * place new type information into a namespace alias---attempts to do so * will generate a warning message (in the parser) and will place information into * Foo instead. @@ -166,6 +215,7 @@ void SwigType_typesystem_init() { * ----------------------------------------------------------------------------- */ int SwigType_typedef(const SwigType *type, const_String_or_char_ptr name) { + /* Printf(stdout, "typedef %s %s\n", type, name); */ if (Getattr(current_typetab, name)) return -1; /* Already defined */ if (Strcmp(type, name) == 0) { /* Can't typedef a name to itself */ @@ -248,10 +298,26 @@ void SwigType_new_scope(const_String_or_char_ptr name) { ttab = NewHash(); Setattr(s, "typetab", ttab); - /* Build fully qualified name and */ + /* Build fully qualified name */ qname = SwigType_scope_name(s); +#if 1 + { + /* TODO: only do with templates? What happens with non-templates with code below? */ + String *stripped_qname; + stripped_qname = SwigType_remove_global_scope_prefix(qname); + /* Use fully qualified name for hash key without unary scope prefix, qname may contain unary scope */ + Setattr(scopes, stripped_qname, s); + Setattr(s, "qname", qname); + /* + Printf(stdout, "SwigType_new_scope stripped %s %s\n", qname, stripped_qname); + */ + Delete(stripped_qname); + } +#else + Printf(stdout, "SwigType_new_scope %s\n", qname); Setattr(scopes, qname, s); Setattr(s, "qname", qname); +#endif Delete(qname); current_scope = s; @@ -418,12 +484,14 @@ static Typetab *SwigType_find_scope(Typetab *s, const SwigType *nameprefix) { Typetab *s_orig = s; String *nnameprefix = 0; static int check_parent = 1; + int is_template = 0; if (Getmark(s)) return 0; Setmark(s, 1); - if (SwigType_istemplate(nameprefix)) { + is_template = SwigType_istemplate(nameprefix); + if (is_template) { nnameprefix = SwigType_typedef_resolve_all(nameprefix); nameprefix = nnameprefix; } @@ -437,10 +505,12 @@ static Typetab *SwigType_find_scope(Typetab *s, const SwigType *nameprefix) { } else { full = NewString(nameprefix); } - if (Getattr(scopes, full)) { - s = Getattr(scopes, full); - } else { - s = 0; + s = Getattr(scopes, full); + if (!s && is_template) { + /* try look up scope with all the unary scope operators within the template parameter list removed */ + SwigType *full_stripped = SwigType_remove_global_scope_prefix(full); + s = Getattr(scopes, full_stripped); + Delete(full_stripped); } Delete(full); if (s) { @@ -541,8 +611,11 @@ static SwigType *_typedef_resolve(Typetab *s, String *base, int look_parent) { /* ----------------------------------------------------------------------------- * template_parameters_resolve() * - * For use with templates only. The template parameters are resolved. If none - * of the parameters can be resolved, zero is returned. + * For use with templates only. Attempts to resolve one template parameter. + * + * If one of the template parameters can be resolved, the type is returned with + * just the one parameter resolved and the remaining parameters left as is. + * If none of the template parameters can be resolved, zero is returned. * ----------------------------------------------------------------------------- */ static String *template_parameters_resolve(const String *base) { @@ -574,14 +647,15 @@ static String *template_parameters_resolve(const String *base) { if ((i + 1) < sz) Append(type, ","); } - Append(type, ")>"); - Append(type, suffix); - Delete(suffix); - Delete(tparms); - if (!rep) { + if (rep) { + Append(type, ")>"); + Append(type, suffix); + } else { Delete(type); type = 0; } + Delete(suffix); + Delete(tparms); return type; } @@ -592,6 +666,17 @@ static SwigType *typedef_resolve(Typetab *s, String *base) { /* ----------------------------------------------------------------------------- * SwigType_typedef_resolve() + * + * Given a type declaration, this function looks to reduce/resolve the type via a + * typedef (including via C++ using declarations). + * + * If it is able to find a typedef, the resolved type is returned. If no typedef + * is found NULL is returned. The type name is resolved in the current scope. + * The type returned is not always fully qualified for the global scope, it is + * valid for use in the current scope. If the current scope is global scope, a + * fully qualified type should be returned. + * + * Some additional notes are in Doc/Manual/Extending.html. * ----------------------------------------------------------------------------- */ /* #define SWIG_DEBUG */ @@ -718,6 +803,25 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) { } } + if (!type && SwigType_istemplate(base)) { + String *tprefix = SwigType_templateprefix(base); + String *rtprefix = SwigType_typedef_resolve(tprefix); + /* We're looking for a using declaration on the template prefix to resolve the template prefix + * in another scope. Using declaration do not have template parameters. */ + if (rtprefix && !SwigType_istemplate(rtprefix)) { + String *tsuffix = SwigType_templatesuffix(base); + String *targs = SwigType_templateargs(base); + type = NewString(rtprefix); + newtype = 1; + Append(type, targs); + Append(type, tsuffix); + Delete(targs); + Delete(tsuffix); + Delete(rtprefix); + } + Delete(tprefix); + } + if (type && (Equal(base, type))) { if (newtype) Delete(type); @@ -911,6 +1015,9 @@ SwigType *SwigType_typedef_resolve_all(const SwigType *t) { return Copy(r); } +#ifdef SWIG_DEBUG + Printf(stdout, "SwigType_typedef_resolve_all start ... %s\n", t); +#endif /* Recursively resolve the typedef */ r = NewString(t); while ((n = SwigType_typedef_resolve(r))) { @@ -931,6 +1038,9 @@ SwigType *SwigType_typedef_resolve_all(const SwigType *t) { Delete(key); Delete(rr); } +#ifdef SWIG_DEBUG + Printf(stdout, "SwigType_typedef_resolve_all end === %s => %s\n", t, r); +#endif return r; } @@ -938,8 +1048,17 @@ SwigType *SwigType_typedef_resolve_all(const SwigType *t) { /* ----------------------------------------------------------------------------- * SwigType_typedef_qualified() * - * Given a type declaration, this function tries to fully qualify it according to - * typedef scope rules. + * Given a type declaration, this function tries to fully qualify it so that the + * resulting type can be used in the global scope. The type name is resolved in + * the current scope. + * + * It provides a fully qualified name, not necessarily a fully expanded name. + * When a using declaration or using directive is found the type may not be fully + * expanded, but it will be resolved and fully qualified for use in the global scope. + * + * This function is for looking up scopes to qualify a type. It does not resolve + * C typedefs, it just qualifies them. See SwigType_typedef_resolve for resolving. + * * If the unary scope operator (::) is used as a prefix to the type to denote global * scope, it is left in place. * ----------------------------------------------------------------------------- */ @@ -1000,20 +1119,14 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) { out of the current scope */ Typetab *cs = current_scope; - while (cs) { - String *qs = SwigType_scope_name(cs); - if (Len(qs)) { - Append(qs, "::"); - } - Append(qs, e); - if (Getattr(scopes, qs)) { + if (cs) { + Typetab *found_scope = SwigType_find_scope(cs, e); + if (found_scope) { + String *qs = SwigType_scope_name(found_scope); Clear(e); Append(e, qs); Delete(qs); - break; } - Delete(qs); - cs = Getattr(cs, "parent"); } } } @@ -1029,10 +1142,6 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) { Parm *p; List *parms; ty = Swig_symbol_template_deftype(e, current_symtab); - /* - String *dt = Swig_symbol_template_deftype(e, current_symtab); - ty = Swig_symbol_type_qualify(dt, 0); - */ e = ty; parms = SwigType_parmlist(e); tprefix = SwigType_templateprefix(e); @@ -1099,9 +1208,6 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) { Delete(tprefix); Delete(qprefix); Delete(parms); - /* - Delete(dt); - */ } Append(result, e); Delete(ty); @@ -1181,7 +1287,7 @@ int SwigType_typedef_using(const_String_or_char_ptr name) { String *defined_name = 0; - /* Printf(stdout,"using %s\n", name); */ + /* Printf(stdout, "using %s\n", name); */ if (!Swig_scopename_check(name)) return -1; /* Not properly qualified */ @@ -1436,7 +1542,7 @@ SwigType *SwigType_alttype(const SwigType *t, int local_tmap) { } } else { if (SwigType_issimple(td) && SwigType_istemplate(td)) { - use_wrapper = !n || !GetFlag(n, "feature:novaluewrapper"); + use_wrapper = 1; } } } diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh index 57f97b604..cec76d812 100755 --- a/Tools/travis-linux-install.sh +++ b/Tools/travis-linux-install.sh @@ -13,6 +13,10 @@ elif [[ "$CC" == gcc-6 ]]; then travis_retry sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test travis_retry sudo apt-get -qq update travis_retry sudo apt-get install -qq g++-6 +elif [[ "$CC" == gcc-7 ]]; then + travis_retry sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + travis_retry sudo apt-get -qq update + travis_retry sudo apt-get install -qq g++-7 fi travis_retry sudo apt-get -qq install libboost-dev @@ -86,13 +90,13 @@ case "$SWIGLANG" in travis_retry sudo apt-get -qq install php$VER-cli php$VER-dev ;; "python") - pip install pep8 + pip install --user pycodestyle if [[ "$PY3" ]]; then travis_retry sudo apt-get install -qq python3-dev fi WITHLANG=$SWIGLANG$PY3 if [[ "$VER" ]]; then - travis_retry sudo add-apt-repository -y ppa:fkrull/deadsnakes + travis_retry sudo add-apt-repository -y ppa:deadsnakes/ppa travis_retry sudo apt-get -qq update travis_retry sudo apt-get -qq install python${VER}-dev WITHLANG=$SWIGLANG$PY3=$SWIGLANG$VER diff --git a/Tools/travis-osx-install.sh b/Tools/travis-osx-install.sh index 42cc33bb2..6bfb2276a 100755 --- a/Tools/travis-osx-install.sh +++ b/Tools/travis-osx-install.sh @@ -23,8 +23,7 @@ case "$SWIGLANG" in "python") WITHLANG=$SWIGLANG$PY3 if [[ "$PY3" ]]; then - travis_retry brew install python3 - travis_retry brew list -v python3 + travis_retry brew upgrade python fi ;; esac diff --git a/appveyor.yml b/appveyor.yml index ea01db0f8..e2f6a6b32 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,8 +22,7 @@ environment: PY3: 1 - SWIGLANG: python OSVARIANT: cygwin - - SWIGLANG: python - OSVARIANT: mingw + - OSVARIANT: mingw install: - date /T & time /T @@ -79,14 +78,12 @@ install: - if "%OSVARIANT%"=="" bash -c "cl.exe /? 2>&1 | head -n 1" - if "%OSVARIANT%"=="" bash -c "which csc.exe" - if "%OSVARIANT%"=="" bash -c "csc.exe /? | head -n 1" -- if "%OSVARIANT%"=="cygwin" %CYGWINSETUP% --quiet-mode --packages libpcre-devel,libboost-devel > cygwin-install.txt || bash -c "cat cygwin-install.txt" +- if "%OSVARIANT%"=="cygwin" %CYGWINSETUP% --quiet-mode --packages python-devel,libpcre-devel,libboost-devel > cygwin-install.txt || bash -c "cat cygwin-install.txt" - if "%OSVARIANT%"=="mingw" bash -c "pacman --noconfirm --sync mingw%MBITS%/mingw-w64-%MARCH%-pcre mingw%MBITS%/mingw-w64-%MARCH%-boost" - bash -c "which $CC" - bash -c "which $CXX" - bash -c "$CC --version | head -n 1" - bash -c "$CXX --version | head -n 1" -- bash -c "which python" -- bash -c "python -V" - bash -c "make --version | head -n 2" - pwd - echo MAKEJOBS=%MAKEJOBS% @@ -105,9 +102,9 @@ test_script: - .\swig.exe -version - if not "%OSVARIANT%"=="" CCache\ccache-swig -V - bash -c "file ./swig.exe" -- bash -c "make check-%SWIGLANG%-version" -- bash -c "time make -k check-%SWIGLANG%-examples %CHECK_OPTIONS%" -- bash -c "time make -k check-%SWIGLANG%-test-suite -j%MAKEJOBS% %CHECK_OPTIONS%" +- if not "%SWIGLANG%"=="" bash -c "make check-%SWIGLANG%-version %CHECK_OPTIONS%" +- if not "%SWIGLANG%"=="" bash -c "time make -k check-%SWIGLANG%-examples %CHECK_OPTIONS%" +- if not "%SWIGLANG%"=="" bash -c "time make -k check-%SWIGLANG%-test-suite -j%MAKEJOBS% %CHECK_OPTIONS%" # Do not build on tags (GitHub only) skip_tags: true diff --git a/configure.ac b/configure.ac index 4d9355cd0..0161e2778 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl The macros which aren't shipped with the autotools are stored in the dnl Tools/config directory in .m4 files. -AC_INIT([swig],[3.0.13],[http://www.swig.org]) +AC_INIT([swig],[4.0.0],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed @@ -28,8 +28,6 @@ AH_BOTTOM([ dnl Check for programs that a user requires to build SWIG AC_PROG_CC AC_PROG_CXX -AC_EXEEXT -AC_OBJEXT AM_PROG_CC_C_O # Needed for subdir-objects in AUTOMAKE_OPTIONS AC_COMPILE_WARNINGS # Increase warning levels @@ -280,7 +278,7 @@ fi AC_MSG_RESULT($RPATH) # LINKFORSHARED are the flags passed to the $(CC) command that links -# the a few executables -- this is only needed for a few systems +# a few executables -- this is only needed for a few systems AC_MSG_CHECKING(LINKFORSHARED) if test -z "$LINKFORSHARED" @@ -895,11 +893,23 @@ else fi if test -n "$PYINCLUDE" || test -n "$PY3INCLUDE" ; then - AC_CHECK_PROGS(PEP8, pep8) - if test -n "$PEP8"; then - AC_MSG_CHECKING(pep8 version) - pep8_version=`$PEP8 --version 2>/dev/null` - AC_MSG_RESULT($pep8_version) + AC_CHECK_PROGS(PYCODESTYLE, pycodestyle) + if test -n "$PYCODESTYLE"; then + AC_MSG_CHECKING(pycodestyle version) + pycodestyle_version=`$PYCODESTYLE --version 2>/dev/null` + AC_MSG_RESULT($pycodestyle_version) + fi +fi + +AC_ARG_WITH(2to3, AS_HELP_STRING([--with-2to3=path], [Set location of Python 2to3 tool]), [PY2TO3BIN="$withval"], [PY2TO3BIN="yes"]) +if test -n "$PYTHON3"; then + if test "x$PY2TO3BIN" = xyes; then + AC_CHECK_PROGS(PY2TO3, 2to3) + else + PY2TO3="$PY2TO3BIN" + fi + if test -z "$PY2TO3"; then + PYTHON3= fi fi @@ -1482,7 +1492,7 @@ else # check for include files AC_MSG_CHECKING(for JavaScriptCore/JavaScript.h) - AC_ARG_WITH(jscoreinc, [ --with-jscinc=path Set location of Javascript include directory], [JSCOREINCDIR="$withval"], [JSCOREINCDIR=]) + AC_ARG_WITH(jscoreinc, [ --with-jscoreinc=path Set location of Javascript include directory], [JSCOREINCDIR="$withval"], [JSCOREINCDIR=]) JSCOREVERSION= @@ -1516,7 +1526,7 @@ else fi # check for JavaScriptCore/Webkit libraries - AC_ARG_WITH(jscorelib,[ --with-jsclib=path Set location of the JavaScriptCore/Webkit library directory],[JSCORELIB="-L$withval"], [JSCORELIB=]) + AC_ARG_WITH(jscorelib,[ --with-jscorelib=path Set location of the JavaScriptCore/Webkit library directory],[JSCORELIB="-L$withval"], [JSCORELIB=]) if test -z "$JSCORELIB" -a -n "$PKGCONFIG"; then AC_MSG_CHECKING(for JavaScriptCore/Webkit library) @@ -1540,7 +1550,7 @@ else # check for include files AC_MSG_CHECKING(for V8 Javascript v8.h) - AC_ARG_WITH(jsv8inc, [ --with-jsv8inc=path Set location of Javascript v8 include directory], [JSV8INCDIR="$withval"]) + AC_ARG_WITH(jsv8inc, [ --with-jsv8inc=path Set location of Javascript v8 include directory], [JSV8INCDIR="$withval"], [JSV8INCDIR=]) # if not include dir is specified we try to find if test -z "$JSV8INCDIR"; then @@ -1623,34 +1633,6 @@ AC_SUBST(JSV8ENABLED) AC_SUBST(NODEJS) AC_SUBST(NODEGYP) -#---------------------------------------------------------------- -# Look for gcj -#---------------------------------------------------------------- - -AC_ARG_WITH(gcj, AS_HELP_STRING([--without-gcj], [Disable GCJ]) -AS_HELP_STRING([--with-gcj=path], [Set location of gcj executable]),[GCJBIN="$withval"], [GCJBIN="$alllang_default"]) -AC_ARG_WITH(gcjh, [ --with-gcjh=path Set location of gcjh executable],[GCJHBIN="$withval"], [GCJHBIN=]) - -# First, check for "--without-gcj" or "--with-gcj=no". -if test x"${GCJBIN}" = xno; then - AC_MSG_NOTICE([Disabling GCJ]) -else - if test "x$GCJBIN" = xyes; then - AC_CHECK_PROGS(GCJ, gcj) - else - GCJ="$GCJBIN" - fi - - if test -z "$GCJCBIN"; then - AC_CHECK_PROGS(GCJH, gcjh) - else - GCJH="$GCJHBIN" - fi -fi - -AC_SUBST(GCJ) -AC_SUBST(GCJH) - #---------------------------------------------------------------- # Look for Android #---------------------------------------------------------------- @@ -1722,17 +1704,28 @@ else fi if test -n "$GUILE_CONFIG" ; then if test x"$GUILE" = xyes; then - AC_MSG_CHECKING([for guile bindir]) - guile_bindir="`$GUILE_CONFIG info bindir`" - AC_MSG_RESULT([$guile_bindir]) - GUILE=$guile_bindir/guile + AC_MSG_CHECKING([for guile executable]) + # Try extracting it via guile-config first. If it's defined there it's the most reliable result + GUILE="`$GUILE_CONFIG info guile 2>/dev/null`" + if test -n "$GUILE"; then + AC_MSG_RESULT([$GUILE]) + else + AC_MSG_RESULT([not found via guile-config - constructing path]) + AC_MSG_CHECKING([for guile bindir]) + guile_bindir="`$GUILE_CONFIG info bindir`" + AC_MSG_RESULT([$guile_bindir]) + GUILE="$guile_bindir/guile" + fi if ! test -f "$GUILE" ; then - GUILE= + GUILE= AC_PATH_PROG(GUILE, guile) fi + if test -z "$GUILE" ; then + AC_MSG_WARN([no suitable guile executable found. Disabling Guile]) + fi fi - if test -f "$GUILE" ; then + if test -n "$GUILE" ; then AC_MSG_CHECKING([for guile version]) guile_version=`$GUILE -c '(display (effective-version))'` AC_MSG_RESULT([$guile_version]) @@ -1740,20 +1733,33 @@ else guile_good_version=`$GUILE -c '(if (>= (string->number (effective-version)) 1.8) (display "yes") (display "no"))'` AC_MSG_RESULT([$guile_good_version]) if test x"$guile_good_version" != xyes ; then + AC_MSG_WARN([at least guile version 1.8 is required. Disabling Guile]) GUILE= fi fi - if test -z "$GUILE_CFLAGS" ; then - AC_MSG_CHECKING([for guile compile flags]) - GUILE_CFLAGS="`$GUILE_CONFIG compile`" # Note that this can sometimes be empty - AC_MSG_RESULT([$GUILE_CFLAGS]) + if test -n "$GUILE" ; then + # Test if guile-config and guile versions match. They should. + gc_version="`$GUILE_CONFIG --version 2>&1 | sed '1 s/.* //;q'`" + g_version="`$GUILE --version | sed '1 s/.* //;q'`" + if test "$gc_version" != "$g_version"; then + AC_MSG_WARN([different versions reported by $GUILE_CONFIG ($gc_version) and $GUILE ($g_version). Disabling Guile]) + GUILE= + fi fi - if test -z "$GUILE_LIBS" ; then - AC_MSG_CHECKING([for guile link flags]) - GUILE_LIBS="`$GUILE_CONFIG link`" - AC_MSG_RESULT([$GUILE_LIBS]) + if test -n "$GUILE" ; then + if test -z "$GUILE_CFLAGS" ; then + AC_MSG_CHECKING([for guile compile flags]) + GUILE_CFLAGS="`$GUILE_CONFIG compile`" # Note that this can sometimes be empty + AC_MSG_RESULT([$GUILE_CFLAGS]) + fi + + if test -z "$GUILE_LIBS" ; then + AC_MSG_CHECKING([for guile link flags]) + GUILE_LIBS="`$GUILE_CONFIG link`" + AC_MSG_RESULT([$GUILE_LIBS]) + fi fi fi fi @@ -2267,14 +2273,14 @@ else if test -z "$CSHARPCOMPILERBIN" ; then case $host in *-*-cygwin* | *-*-mingw*) - # prefer Mono gmcs (.NET 2.0) over mcs (.NET 1.1) - note mcs-1.2.3 has major pinvoke bug - AC_CHECK_PROGS(CSHARPCOMPILER, csc mono-csc gmcs mcs cscc) + # prefer unified Mono mcs compiler (not to be confused with the ancient .NET 1 mcs) over older/alternative names. + AC_CHECK_PROGS(CSHARPCOMPILER, csc mcs mono-csc gmcs cscc) if test -n "$CSHARPCOMPILER" && test "$CSHARPCOMPILER" = "csc" ; then AC_MSG_CHECKING(whether csc is the Microsoft CSharp compiler) csc 2>/dev/null | grep "C#" > /dev/null || CSHARPCOMPILER="" if test -z "$CSHARPCOMPILER" ; then AC_MSG_RESULT(no) - AC_CHECK_PROGS(CSHARPCOMPILER, mono-csc gmcs mcs cscc) + AC_CHECK_PROGS(CSHARPCOMPILER, mcs mono-csc gmcs cscc) else AC_MSG_RESULT(yes) fi @@ -2602,7 +2608,7 @@ else GOVERSIONOPTION=version go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //') case "$go_version" in - go1 | go1.[[01234]]*) + go1 | go1.[[01234]] | go1.[[01234]].*) GOC=$(sh -c "$(go env) && echo \$GOCHAR")c ;; *) @@ -2611,7 +2617,7 @@ else esac AC_MSG_CHECKING([whether go version is too old]) case $go_version in - go1.1* | go1.0* | go1 ) + go1.1.* | go1.1 | go1.0 | go1.0.* | go1 ) AC_MSG_RESULT([yes - minimum version is 1.2]) GO= GOOPT="-intgosize 32" @@ -2629,13 +2635,13 @@ else ;; esac case $go_version in - go1.0* | go1 | go1.1*) + go1.0 | go1.0.* | go1 | go1.1 | go1.1.*) GOOPT="$GOOPT -use-shlib" ;; - go1.2*) + go1.2 | go1.2.*) GO12=true ;; - go1.3* | go1.4*) + go1.3 | go1.3.* | go1.4 | go1.4.*) GO13=true ;; *) @@ -2946,16 +2952,6 @@ AC_SUBST(SKIP_D) #---------------------------------------------------------------- # Additional language dependencies #---------------------------------------------------------------- -SKIP_GCJ= -if test -z "$GCJ" || test -z "$GCJH" ; then - SKIP_GCJ="1" -else - if test "$GCC" != yes; then - SKIP_GCJ="1" - fi -fi -AC_SUBST(SKIP_GCJ) - SKIP_ANDROID= if test -z "$ANDROID" || test -z "$ADB" || test -z "$ANT" || test -z "$NDKBUILD" ; then