diff --git a/.gitignore b/.gitignore index c29287f6caa..bd8a875355c 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ CCache/autom4te.cache/ CCache/config.h.in CCache/configure Source/Include/swigconfig.h.in -Source/Include/swigconfig.h.in~ Source/Makefile.in Tools/config/compile Tools/config/config.guess @@ -85,8 +84,6 @@ swig.spec # Build Artifacts .dirstamp CCache/ccache-swig -CCache/ccache-swig.1 -CCache/web/ccache-man.html Lib/swigwarn.swg Source/CParse/parser.c Source/CParse/parser.h @@ -96,46 +93,67 @@ swig Tools/javascript/javascript # Generated documentation -Doc/Manual/CCache.html Doc/Manual/SWIGDocumentation.html Doc/Manual/SWIGDocumentation.pdf Doc/Manual/*.book -# Test Suite Generated Files -Examples/test-suite/allegrocl/*/ -Examples/test-suite/cffi/*/ -Examples/test-suite/chicken/*/ -Examples/test-suite/clisp/*/ -Examples/test-suite/csharp/*/ -Examples/test-suite/d/*/ -Examples/test-suite/go/*/ -Examples/test-suite/guile/*/ -Examples/test-suite/java/*/ -Examples/test-suite/javascript/*/ -Examples/test-suite/lua/*/ -Examples/test-suite/mzscheme/*/ -Examples/test-suite/ocaml/*/ -Examples/test-suite/octave/*/ -Examples/test-suite/perl5/*/ -Examples/test-suite/php/*/ -Examples/test-suite/pike/*/ -Examples/test-suite/python/*/ -Examples/test-suite/r/*/ -Examples/test-suite/ruby/*/ -Examples/test-suite/tcl/*/ -Examples/test-suite/uffi/*/ +# SWIG common generated files *_wrap.c +*_wrap.cpp *_wrap.cxx +*_wrap.h *-gypcopy.cxx -# C# generated files -*_runme.exe.mdb -*_runme.exe +# Scratch directories +Examples/scratch + +# Out of source tree build directories +*build*/ + +# errors test-suite +Examples/test-suite/errors/*.newerr +Examples/test-suite/errors/*.py + +########## Language specific files ########## + +# C# +Examples/test-suite/csharp/*/ +*runme.exe.mdb +*runme.exe +Examples/csharp/*/*.cs +!Examples/csharp/*/runme.cs + +# D +Examples/test-suite/d/*/ +Examples/d/**/example.d +Examples/d/**/example_im.d +Examples/d/**/runme + +# Go +*.[5689] +*_gc.c +Examples/test-suite/go/*.go +!Examples/test-suite/go/*runme.go +Examples/test-suite/go/*runme +Examples/test-suite/go/gopath +Examples/test-suite/go/testdir +Examples/go/*/gopath +Examples/go/*/example.go +Examples/go/*/runme + +# Guile +Examples/guile/*/my-guile + +# Java +Examples/test-suite/java/*/ +Examples/java/*/*.java +!Examples/java/*/runme.java -# Javascript generated files +# Javascript +Examples/test-suite/javascript/*/ *.gyp -# Matlab generated files +# Matlab *.mex* # module directories [+]*/ @@ -143,22 +161,44 @@ Examples/test-suite/uffi/*/ SwigRef.m SwigMem.m -# Octave generated files +# Octave swigexample*.oct Examples/test-suite/octave/*.oct -# Python generated files, based on: -# https://github.com/github/gitignore/blob/master/Python.gitignore +# Perl5 +Examples/test-suite/perl5/*.pm +Examples/perl5/*/*.pm + +# PHP +Examples/test-suite/php/php_*.h +Examples/test-suite/php/*.php +!Examples/test-suite/php/*runme.php +!Examples/test-suite/php/skel.php +Examples/php/*/php_*.h +Examples/php/*/example.php + +# Python +# Based on https://github.com/github/gitignore/blob/master/Python.gitignore *.py[cod] */__pycache__/ /__pycache__/ +Examples/test-suite/python/*.py +!Examples/test-suite/python/*runme.py +Examples/python/*/example.py +Examples/python/**/bar.py +Examples/python/**/base.py +Examples/python/**/foo.py +Examples/python/**/spam.py + +# R +Examples/test-suite/r/*.R +Examples/test-suite/r/*.Rout +!Examples/test-suite/r/*runme.R +Examples/r/*/example.R +Examples/r/*/*.Rout +Examples/r/*/.RData + +# Scilab +Examples/test-suite/scilab/*/ +loader.sce -# Go generated files -*.[5689] -*_gc.c - -# Scratch directories -Examples/scratch - -# Out of source tree build directories -*build*/ diff --git a/.travis.yml b/.travis.yml index 3a726db3e77..6bf3e3c372c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,121 +1,188 @@ language: cpp -compiler: - - clang - - gcc -env: - - SWIGLANG= matrix: include: - - compiler: gcc + - compiler: clang + os: linux + env: SWIGLANG= + - compiler: gcc + os: linux + env: SWIGLANG= + - os: linux + env: SWIGLANG= SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 + - os: linux + env: SWIGLANG= SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP14=1 + - compiler: gcc + os: linux env: SWIGLANG=csharp - compiler: gcc + os: linux env: SWIGLANG=d - compiler: gcc + os: linux env: SWIGLANG=go - compiler: gcc + os: linux env: SWIGLANG=guile - compiler: gcc + os: linux env: SWIGLANG=java - compiler: gcc + os: linux env: SWIGLANG=javascript ENGINE=node - compiler: gcc + os: linux env: SWIGLANG=javascript ENGINE=jsc - compiler: gcc + os: linux env: SWIGLANG=javascript ENGINE=v8 - compiler: gcc + os: linux env: SWIGLANG=lua - compiler: gcc - env: SWIGLANG=octave SWIGJOBS=-j3 # 3.2 + os: linux + env: SWIGLANG=octave SWIGJOBS=-j2 # 3.2 + - compiler: gcc + os: linux + env: SWIGLANG=octave SWIGJOBS=-j2 VER=3.8 - compiler: gcc - env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8 + os: linux + env: SWIGLANG=octave SWIGJOBS=-j2 VER=4.0 - compiler: gcc + os: linux env: SWIGLANG=perl5 - compiler: gcc + os: linux env: SWIGLANG=php - compiler: gcc + os: linux env: SWIGLANG=python VER=2.4 - compiler: gcc + os: linux env: SWIGLANG=python VER=2.5 - compiler: gcc + os: linux env: SWIGLANG=python VER=2.6 - compiler: gcc + os: linux env: SWIGLANG=python # 2.7 - compiler: gcc + os: linux env: SWIGLANG=python PY3=3 # 3.2 - compiler: gcc + os: linux env: SWIGLANG=python PY3=3 VER=3.3 - compiler: gcc + os: linux env: SWIGLANG=python PY3=3 VER=3.4 - compiler: gcc + os: linux + env: SWIGLANG=python PY3=3 VER=3.5 + - compiler: gcc + os: linux env: SWIGLANG=python SWIG_FEATURES=-builtin - compiler: gcc + os: linux env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 - compiler: gcc + os: linux + env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5 + - compiler: gcc + os: linux + env: SWIGLANG=python SWIG_FEATURES=-O + - compiler: gcc + os: linux + env: SWIGLANG=python SWIG_FEATURES=-classic + - compiler: gcc + os: linux + env: SWIGLANG=r + - compiler: gcc + os: linux env: SWIGLANG=ruby - compiler: gcc + os: linux + env: SWIGLANG=ruby VER=2.3.0 + - compiler: gcc + os: linux + env: SWIGLANG=scilab + - compiler: gcc + os: linux env: SWIGLANG=tcl + - os: linux + env: SWIGLANG=csharp SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 + - os: linux + env: SWIGLANG=java SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 + - os: linux + env: SWIGLANG=python SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 + - os: osx + env: SWIGLANG= SWIG_CC=gcc-4.2 SWIG_CXX=g++-4.2 + - compiler: clang + os: osx + env: SWIGLANG= + - compiler: clang + os: osx + env: SWIGLANG=csharp + - compiler: clang + os: osx + env: SWIGLANG=go + - compiler: clang + os: osx + env: SWIGLANG=guile + - compiler: clang + os: osx + env: SWIGLANG=java + - compiler: clang + os: osx + env: SWIGLANG=lua + - compiler: clang + os: osx + env: SWIGLANG=perl5 + - compiler: clang + os: osx + env: SWIGLANG=php + - compiler: clang + os: osx + env: SWIGLANG=python + - compiler: clang + os: osx + env: SWIGLANG=python PY3=3 + - compiler: clang + os: osx + env: SWIGLANG=ruby + - compiler: clang + os: osx + env: SWIGLANG=tcl + allow_failures: - # Occasional gcc internal compiler error + # Lots of failing tests currently + - compiler: gcc + os: linux + env: SWIGLANG=ocaml + # Not quite working yet - compiler: gcc - env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8 + os: linux + env: SWIGLANG=python SWIG_FEATURES=-O before_install: - date -u - uname -a - - lsb_release -a - - sudo apt-get -qq update - - time sudo apt-get -qq install libboost-dev - - if test -z "$SWIGLANG"; then sudo apt-get -qq install yodl; fi - - if test "$SWIGLANG" = "csharp"; then sudo apt-get -qq install mono-devel; fi - - if test "$SWIGLANG" = "d"; then wget http://downloads.dlang.org/releases/2014/dmd_2.066.0-0_amd64.deb; sudo dpkg -i dmd_2.066.0-0_amd64.deb; fi - - if test "$SWIGLANG" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed - - if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "node"; then sudo apt-get install -qq rlwrap python-software-properties && echo 'yes' | sudo add-apt-repository ppa:chris-lea/node.js && sudo apt-get -qq update && sudo apt-get install -qq nodejs && sudo npm install -g node-gyp; fi - - if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "jsc"; then sudo apt-get install -qq libwebkitgtk-dev; fi - - if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "v8"; then sudo apt-get install -qq libv8-dev; fi - - if test "$SWIGLANG" = "guile"; then sudo apt-get -qq install guile-2.0-dev; fi - - if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi - - if test "$SWIGLANG" = "octave" -a -z "$VER"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi - - if test "$SWIGLANG" = "octave" -a "$VER"; then sudo add-apt-repository -y ppa:kwwette/octaves && sudo apt-get -qq update && sudo apt-get -qq install liboctave${VER}-dev; fi - - if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi - - if test "$SWIGLANG" = "python"; then git clone https://github.com/jcrocholl/pep8.git && pushd pep8 && git checkout tags/1.5.7 && python ./setup.py build && sudo python ./setup.py install && popd; fi - - if test "$SWIGLANG" = "python" -a "$PY3" -a -z "$VER"; then sudo apt-get install -qq python3-dev; fi - - if test "$SWIGLANG" = "python" -a "$VER"; then sudo add-apt-repository -y ppa:fkrull/deadsnakes && sudo apt-get -qq update && sudo apt-get -qq install python${VER}-dev && export CONFIGOPTS="--with-python${PY3}=python${VER}"; fi - - if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi - # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. - - declare -A CFLAGS_EXAMPLES && CFLAGS_EXAMPLES=( - ["csharp"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["d"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["go"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["guile"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["java"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["javascript"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["lua"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["octave"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["perl5"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["php"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["python"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["ruby"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["tcl"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ) - - declare -A CXXFLAGS_EXAMPLES && CXXFLAGS_EXAMPLES=( - ["csharp"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["d"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["go"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["guile"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["java"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["javascript"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["lua"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["octave"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["perl5"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ["php"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["python"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["ruby"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" - ["tcl"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" - ) + - if test "$TRAVIS_OS_NAME" = "linux"; then lscpu && cat /proc/cpuinfo | grep "model name" && cat /proc/meminfo | grep MemTotal; fi + - if test "$TRAVIS_OS_NAME" = "osx"; then sysctl -a | grep brand_string; fi + # Travis overrides CC environment with compiler predefined values + - if test -n "$SWIG_CC"; then export CC="$SWIG_CC"; fi + - if test -n "$SWIG_CXX"; then export CXX="$SWIG_CXX"; fi +install: + - if test "$TRAVIS_OS_NAME" = "linux"; then source Tools/travis-linux-install.sh; fi + - 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 + - ls -la $(which $CC) + - ls -la $(which $CXX) - $CC --version - $CXX --version script: - echo 'Configuring...' && echo -en 'travis_fold:start:script.1\\r' - - ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure $CONFIGOPTS + - if test -n "$SWIGLANG"; then CONFIGOPTS+=(--without-alllang --with-$WITHLANG); fi + - echo "${CONFIGOPTS[@]}" + - ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure "${CONFIGOPTS[@]}" - echo -en 'travis_fold:end:script.1\\r' - make -s $SWIGJOBS - ./swig -version && ./swig -pcreversion @@ -124,9 +191,13 @@ script: - echo 'Installing...' && echo -en 'travis_fold:start:script.2\\r' - if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi - echo -en 'travis_fold:end:script.2\\r' + # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. + - if test -n "$SWIGLANG"; then cflags=$($TRAVIS_BUILD_DIR/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags; fi + - if test -n "$SWIGLANG"; then cxxflags=$($TRAVIS_BUILD_DIR/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags; fi - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi - - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-examples CFLAGS="${CFLAGS_EXAMPLES[$SWIGLANG]}" CXXFLAGS="${CXXFLAGS_EXAMPLES[$SWIGLANG]}"; fi - - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-test-suite; fi + - if test -n "$SWIGLANG"; then make check-$SWIGLANG-enabled; fi + - if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi + - if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi - echo 'Cleaning...' && echo -en 'travis_fold:start:script.3\\r' - make check-maintainer-clean && ../../configure $CONFIGOPTS - echo -en 'travis_fold:end:script.3\\r' diff --git a/ANNOUNCE b/ANNOUNCE index e3792cc95ce..b06aa53d283 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 3.0.5 (in progress) *** +*** ANNOUNCE: SWIG 3.0.9 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-3.0.5, the latest SWIG release. +We're pleased to announce SWIG-3.0.9, the latest SWIG release. What is SWIG? ============= @@ -11,21 +11,27 @@ SWIG is a software development tool that reads C/C++ header files and generates the wrapper code needed to make C and C++ code accessible from other programming languages including Perl, Python, Tcl, Ruby, PHP, C#, Go, Java, Javascript, Lua, Scheme (Guile, MzScheme, CHICKEN), -D, Ocaml, Pike, Modula-3, Octave, R, Common Lisp (CLISP, Allegro CL, -CFFI, UFFI). SWIG can also export its parse tree in the form of XML -and Lisp s-expressions. Major applications of SWIG include generation -of scripting language extension modules, rapid prototyping, testing, -and user interface development for large C/C++ systems. +D, Ocaml, Pike, Modula-3, Octave, R, Scilab, Common Lisp (CLISP, +Allegro CL, CFFI, UFFI). SWIG can also export its parse tree in +the form of XML and Lisp s-expressions. Major applications of SWIG +include generation of scripting language extension modules, rapid +prototyping, testing, and user interface development for large +C/C++ systems. + +Release Notes +============= +Detailed release notes are available with the release and are also +published on the SWIG web site at http://swig.org/release.html. Availability ============ The release is available for download on Sourceforge at - http://prdownloads.sourceforge.net/swig/swig-3.0.5.tar.gz + http://prdownloads.sourceforge.net/swig/swig-3.0.9.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-3.0.5.zip + http://prdownloads.sourceforge.net/swig/swigwin-3.0.9.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 6cded08d4bd..67fd3f36384 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -43,17 +43,21 @@ $(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 -install: $(PACKAGE_NAME)$(EXEEXT) $(srcdir)/$(PACKAGE_NAME).1 +install: $(PACKAGE_NAME)$(EXEEXT) @echo "Installing $(PACKAGE_NAME)" @echo "Installing $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT)" ${INSTALLCMD} -d $(DESTDIR)${bindir} ${INSTALLCMD} -m 755 $(PACKAGE_NAME)$(EXEEXT) $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT) + +install-docs: $(srcdir)/$(PACKAGE_NAME).1 @echo "Installing $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1" ${INSTALLCMD} -d $(DESTDIR)${mandir}/man1 ${INSTALLCMD} -m 644 $(srcdir)/$(PACKAGE_NAME).1 $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1 -uninstall: $(PACKAGE_NAME)$(EXEEXT) $(srcdir)/$(PACKAGE_NAME).1 +uninstall: $(PACKAGE_NAME)$(EXEEXT) rm -f $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT) + +uninstall-docs: $(srcdir)/$(PACKAGE_NAME).1 rm -f $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1 clean: diff --git a/CCache/test.sh b/CCache/test.sh index f64c3e3de6c..438e782cd84 100755 --- a/CCache/test.sh +++ b/CCache/test.sh @@ -15,6 +15,11 @@ else SWIG=swig fi +# fix: Remove ccache from $PATH if it exists +# as it will influence the unit tests +PATH="`echo $PATH | \ + sed -e 's!:/usr\(/local\)*/lib\([0-9]\)*/ccache\(/\)*!!g'`" + CCACHE=../ccache-swig TESTDIR=test.$$ @@ -402,6 +407,29 @@ swigtests() { rm -rf $TESTDIR mkdir $TESTDIR cd $TESTDIR || exit 1 + +unset CCACHE_DIR +unset CCACHE_TEMPDIR +unset CCACHE_LOGFILE +unset CCACHE_VERBOSE +unset CCACHE_PATH +unset CCACHE_CC +unset CCACHE_PREFIX +unset CCACHE_DISABLE +unset CCACHE_READONLY +unset CCACHE_CPP2 +unset CCACHE_NOCOMPRESS +unset CCACHE_NOSTATS +unset CCACHE_NLEVELS +unset CCACHE_HARDLINK +unset CCACHE_RECACHE +unset CCACHE_UMASK +unset CCACHE_HASHDIR +unset CCACHE_UNIFY +unset CCACHE_EXTENSION +unset CCACHE_STRIPC +unset CCACHE_SWIG + CCACHE_DIR="ccache dir" # with space in directory name (like Windows default) mkdir "$CCACHE_DIR" export CCACHE_DIR diff --git a/CHANGES b/CHANGES index 9c64f9c75e8..1982307756f 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,514 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 3.0.8 (31 Dec 2015) +=========================== + +2015-12-30: wsfulton + The pdf documentation is now generated by wkhtmltopdf and has colour + for the code snippets just like the html documentation! + +2015-12-23: ahnolds + [Python] Fixes for conversion of signed and unsigned integer types: + + No longer check for PyInt objects in Python3. Because PyInt_Check + and friends are #defined to the corresponding PyLong methods, this + had caused errors in Python3 where values greater than what could be + stored in a long were incorrectly interpreted as the value -1 with + the Python error indicator set to OverflowError. This applies to + both the conversions PyLong->long and PyLong->double. + + Conversion from PyLong to long, unsigned long, long long, and + unsigned long long now raise OverflowError instead of TypeError in + both Python2 and Python3 for PyLong values outside the range + expressible by the corresponding C type. This matches the existing + behavior for other integral types (signed and unsigned ints, shorts, + and chars), as well as the conversion for PyInt to all numeric + types. This also indirectly applies to the size_t and ptrdiff_t + types, which depend on the conversions for unsigned long and long. + +2015-12-19: wsfulton + [Python] Python 2 Unicode UTF-8 strings can be used as inputs to char * or + std::string types if the generated C/C++ code has SWIG_PYTHON_2_UNICODE defined. + +2015-12-17: wsfulton + Issues #286, #128 + Remove ccache-swig.1 man page - please use the CCache.html docs instead. + The yodl2man and yodl2html tools are no longer used and so SWIG no + longer has a dependency on these packages which were required when + building from git. + +2015-12-16: zturner/coleb + [Python] Fix Python3.5 interpreter assertions when objects are being + deleted due to an existing exception. Most notably in generators + which terminate using a StopIteration exception. Fixes #559 #560 #573. + If a further exception is raised during an object destruction, + PyErr_WriteUnraisable is used on this second exception and the + original exception bubbles through. + +2015-12-14: ahnolds/wsfulton + [Python] Add in missing initializers for tp_finalize, + nb_matrix_multiply, nb_inplace_matrix_multiply, ht_qualname + ht_cached_keys and tp_prev. + +2015-12-12: wsfulton + Fix STL wrappers to not generate <: digraphs. + For example std::vector<::X::Y> was sometimes generated, now + corrected to std::vector< ::X::Y >. + +2015-11-25: wsfulton + [Ruby] STL ranges and slices fixes. + + Ruby STL container setting slices fixes: + + Setting an STL container wrapper slice better matches the way Ruby + arrays work. The behaviour is now the same as Ruby arrays. The only + exception is the default value used when expanding a container + cannot be nil as this is not a valid type/value for C++ container + elements. + + Obtaining a Ruby STL container ranges and slices fixes: + + Access via ranges and slices now behave identically to Ruby arrays. + The fixes are mostly for out of range indices and lengths. + - Zero length slice requests return an empty container instead of nil. + - Slices which request a length greater than the size of the container + no longer chop off the last element. + - Ranges which used to return nil now return an empty array when the + the start element is a valid index. + + Ruby STL container negative indexing support improved. + + Using negative indexes to set values works the same as Ruby arrays, eg + + %template(IntVector) std::vector; + + iv = IntVector.new([1,2,3,4]) + iv[-4] = 9 # => [1,2,3,9] + iv[-5] = 9 # => IndexError + +2015-11-21: wsfulton + [Ruby, Python] Add std::array container wrappers. + + These work much like any of the other STL containers except Python/Ruby slicing + is somewhat limited because the array is a fixed size. Only slices of + the full size are supported. + +2015-10-10: wsfulton + [Python] #539 - Support Python 3.5 and -builtin. PyAsyncMethods is a new + member in PyHeapTypeObject. + +2015-10-06: ianlancetaylor + [Go] Don't emit a constructor function for a director + class with an abstract method, since the function will + always panic. + +2015-10-01: wsfulton + Fix %shared_ptr support for private and protected inheritance. + - Remove unnecessary Warning 520: Derived class 'Derived' of 'Base' + is not similarly marked as a smart pointer + - Do not generate code that attempts to cast up the inheritance chain in the + type system runtime in such cases as it doesn't compile and can't be used. + Remove unnecessary warning 520 for %shared_ptr when the base class is ignored. + +2015-10-01: vkalinin + Fix #508: Fix segfault parsing anonymous typedef nested classes. + +2015-09-26: wsfulton + [Ruby] Add shared_ptr support + +2015-09-13: kkaempf + [Ruby] Resolve tracking bug - issue #225. + The bug is that the tracking code uses a ruby hash and thus may + allocate objects (Bignum) while running the GC. This was tolerated in + 1.8 but is invalid (raises an exception) in 1.9. + The patch uses a C hash (also used by ruby) instead. + +2015-09-09: lyze + [CFFI] Extend the "export" feature in the CFFI module to support + exporting to a specified package. + +2015-09-04: olly + [Python] Fix docstrings for %callback functions. + +2015-09-03: demi-rluddy + [Go] Removed golang stringing for signed/unsigned char + + Changed default handling of signed char* and unsigned char* to be + opaque pointers rather than strings, similarly to how other + languages work. + + Any existing code relying on treating signed char* or unsigned + char* as a string can restore the old behavior with typemaps.i by + using %apply to copy the [unchanged] char* behavior. + + *** POTENTIAL INCOMPATIBILITY *** + +2015-08-07: talby + [Perl] tidy -Wtautological-constant-out-of-range-compare warnings when building generated code under clang + +2015-08-07: xantares + [Python] pep257 & numpydoc conforming docstrings: + - Mono-line module docsstring + - Rewrite autodoc parameters section in numpydoc style: + https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt + - One line summary should end with "." + - Adds a blank line after class docstring + +2015-08-05: vadz + [Java] Make (char* STRING, size_t LENGTH) typemaps usable for + strings of other types, e.g. "unsigned char*". + +Version 3.0.7 (3 Aug 2015) +========================== + +2015-08-02: wsfulton + [Java] Fix potential security exploit in generated Java classes. + The swigCPtr and swigCMemOwn member variables in the generated Java + classes are now declared 'transient' by default. Further details of the exploit + in Android is being published in an academic paper as part of USENIX WOOT '15: + https://www.usenix.org/conference/woot15/workshop-program/presentation/peles. + + In the unlikely event that you are relying on these members being serializable, + then you will need to override the default javabody and javabody_derived typemaps + to generate the old generated code. The relevant typemaps are in the Lib directory + in the java.swg, boost_shared_ptr.i and boost_intrusive_ptr.i files. Copy the + relevant default typemaps into your interface file and remove the 'transient' keyword. + + *** POTENTIAL INCOMPATIBILITY *** + +2015-08-01: vadz + Make configure --without-alllang option more useful: it can now be overridden by the following + --with-xxx options, allowing to easily enable just one or two languages. + +2015-07-30: wsfulton + Fix #440 - Initialise all newly created arrays when using %array_functions and %array_class + in the carrays.i library - bug is only relevant when using C++. + +2015-07-29: wsfulton + [Python] Improve indentation warning and error messages for code in the following directives: + + %pythonprepend + %pythonappend + %pythoncode + %pythonbegin + %feature("shadow") + + Old error example: + Error: Line indented less than expected (line 3 of pythoncode) + + New error example: + Error: Line indented less than expected (line 3 of %pythoncode or %insert("python") block) + as no line should be indented less than the indentation in line 1 + + Old warning example: + Warning 740: Whitespace prefix doesn't match (line 2 of %pythoncode or %insert("python") block) + + New warning example: + Warning 740: Whitespace indentation is inconsistent compared to earlier lines (line 3 of + %pythoncode or %insert("python") block) + + +2015-07-28: wsfulton + [Python] Fix #475. Improve docstring indentation handling. + + SWIG-3.0.5 and earlier sometimes truncated text provided in the docstring feature. + This occurred when the indentation (whitespace) in the docstring was less in the + second or later lines when compared to the first line. + SWIG-3.0.6 gave a 'Line indented less than expected' error instead of truncating + the docstring text. + Now the indentation for the 'docstring' feature is smarter and is appropriately + adjusted so that no truncation occurs. + +2015-07-22: wsfulton + Support for special variable expansion in typemap attributes. Example usage expansion + in the 'out' attribute (C# specific): + + %typemap(ctype, out="$*1_ltype") unsigned int& "$*1_ltype" + + is equivalent to the following as $*1_ltype expands to 'unsigned int': + + %typemap(ctype, out="unsigned int") unsigned int& "unsigned int" + + Special variables can be used within special variable macros too. Example usage expansion: + + %typemap(cstype) unsigned int "uint" + %typemap(cstype, out="$typemap(cstype, $*1_ltype)") unsigned int& "$typemap(cstype, $*1_ltype)" + + Special variables are expanded first and hence the above is equivalent to: + + %typemap(cstype, out="$typemap(cstype, unsigned int)") unsigned int& "$typemap(cstype, unsigned int)" + + which then expands to: + + %typemap(cstype, out="uint") unsigned int& "uint" + +2015-07-22: lindleyf + Apply patch #439 - support for $typemap() (aka embedded typemaps or special variable + macros) in typemap attributes. A simple example where $typemap() is expanded in the + 'out' attribute (C# specific): + + %typemap(cstype) unsigned int "uint" + %typemap(cstype, out="$typemap(cstype, unsigned int)") unsigned int& "$typemap(cstype, unsigned int)" + + is equivalent to: + + %typemap(cstype, out="uint") unsigned int& "uint" + +2015-07-18: m7thon + [Python] Docstrings provided via %feature("docstring") are now quoted and added to + the tp_doc slot when using python builtin classes (-builtin). When no docstring is + provided, the tp_doc slot is set to the fully qualified C/C++ class name. + Github issues #445 and #461. + +2015-07-17: kwwette + [octave] Support Octave version 4.0.0 (thanks to patches from Orion Poplawski). + +2015-07-07: wsfulton + SWIG no longer generates a wrapper for a class' constructor if that class has + any base class with a private destructor. This is because your compiler should + not allow a class to be instantiated if a base has a private destructor. Some + compilers do, so if you need the old behaviour, use the "notabstract" feature, eg: + + %feature("notabstract") Derived; + class Base { + ~Base() {} + }; + struct Derived : Base {}; + +Version 3.0.6 (5 Jul 2015) +========================== + +2015-07-02: wsfulton + Fix syntax error when the template keyword is used in types, eg: + + std::template vector v; + +2015-07-02: ngladitz + [Lua] Push characters as unformatted 1-character strings to avoid + unprintable characters such as (char)127 being converted to + "<\127>" with Lua 5.3 and later. (github PR #452) + +2015-06-29: olly + [Python] Improve handling of whitespace in %pythoncode. + + Previously SWIG looked at the indentation of the first line and + removed that many characters from each subsequent line, regardless + of what those characters were. This was made worse because SWIG's + preprocessor removes any whitespace before a '#'. Fixes github + issue #379, reported by Joe Orton. + +2015-06-12: wsfulton + [R] Fix #430 - call to SWIG_createNewRef in copyToC was incorrectly named. + +2015-06-11: sghirate + [C#] Patch #427 adds in new command line option -outfile to combine all the + generated C# code into a single file. + +2015-06-09: wsfulton + Fix seg fault processing C++11 type aliasing. Issue #424. + +2015-05-28: wsfulton + [Python] Add new feature "python:cdefaultargs" to control default argument + code generation. By default, SWIG attempts to convert C/C++ default argument values + into Python values and generates code into the Python layer with these values. + Recent versions of SWIG are able to convert more of these values, however, the + new behaviour can be circumvented if desired via this new feature, such that + the default argument values are obtained from the C layer and not the Python layer. + For example: + + struct CDA { + int fff(int a = 1, bool b = false); + }; + + The default code generation in the Python layer is: + + class CDA(_object): + ... + def fff(self, a=1, b=False): + return _default_args.CDA_fff(self, a, b) + + Adding the feature: + + %feature("python:cdefaultargs") CDA::fff; + + Results in: + + class CDA(_object): + ... + def fff(self, *args): + return _default_args.CDA_fff(self, *args) + + Some code generation modes, eg -builtin and -fastproxy, are unaffected by this as + the default values are always obtained from the C layer. + +2015-05-27: wsfulton + [Python] Deal with an integer as the default value of a typedef to bool + parameter in the C++ prototype. See #327. Regression from 3.0.0 onwards. + +2015-05-19: olly + [Python] Fix warning when compiling generated code with MSVC. + (Fixes https://sourceforge.net/p/swig/patches/351/ reported by + Mateusz Szyma¿ski). + +2015-05-14: wsfulton + Fix seg fault wrapping shared_ptr of classes with private constructors and destructors. + This also fixes the "unref" feature when used on classes with private destructors. + +2015-05-10: wsfulton + [Java] Fix multi-argument typemaps (char *STRING, size_t LENGTH) + so that they can be applied to a wider range of types. Fixes #385. + +2015-05-07: olly + [Python] Deal with an integer as the default value of a bool + parameter in the C++ prototype. Fixes github #327, reported by + Greg Allen. + +2015-05-07: LindleyF + [Java] Allow feature("director") and feature("ref") to be used + together. Github PR#403. + +2015-05-05: olly + Suppress warning 325 "Nested class not currently supported (Foo + ignored)" when Foo has already been explicitly ignored with "%ignore". + +2015-05-04: wsfulton + Add support for friend templates, including operator overloading - fixes #196. Considering + the example below, previously the operator gave a syntax error and friendfunc incorrectly + warned with: + + "Warning 503: Can't wrap 'friendfunc<(Type)>' unless renamed to a valid identifier." + + template class MyClass { + friend int friendfunc (double is, MyClass & x); + friend int operator<< (double un, const MyClass &x); + }; + + The following also previously incorrectly warned with: + + "Warning 302: Identifier 'template_friend' redefined (ignored)," + + template T template_friend(T); + struct MyTemplate { + template friend T template_friend(T); + }; + +2015-05-01: wsfulton + Fix handling of conversion operators where the operator is split over multiple + lines or has comments within the operator type. Fixes #401. + + Also fix similar problem with normal operators which gave a syntax error if split over + multiple lines or had a comment within the operator declaration. + +2015-04-30: olly + Ignore unknown preprocessor directives which are inside an inactive + conditional (github issue #394, reported by Dan Wilcox). + Regression introduced in 3.0.3. + +2015-04-27: vadz + [Python] Fix "default" typemap used after an argument with "numinputs=0" (#377). + +2015-04-24: wsfulton + [Python] Fix #256. Code generated with '-builtin -modernargs' segfaults for any + method taking zero arguments. + + Also fixes: "SystemError: error return without exception set" during error checking + when using just -builtin and the incorrect number of arguments is passed to a class + method expecting zero arguments. + +2015-04-23: wsfulton + [Java] Bug #386 - Memory leak fix in (char *STRING, size_t LENGTH) typemaps. + +2015-04-23: vadz + [Python] Make "default" typemap work again (#330, #377). + +2015-04-23: vadz + [Python] Fix the use of default values for the pointer types (#365, #376). + +2015-04-23: wsfulton + Fix 'make check-ccache' which is part of 'make check' when one of the CCACHE_ + environment variables, for example CCACHE_DISABLE, is set. + +2015-04-14: wsfulton + Clearer warning message for badly constructed typecheck typemaps. For example, was: + + example.i:3: Warning 467: Overloaded foo(int) not supported (no type checking + rule for 'int'). + + Now: + + example.i:3: Warning 467: Overloaded foo(int) not supported (incomplete type checking + rule - no precedence level in typecheck typemap for 'int'). + +2015-04-11: wsfulton + [Java] Fix #353 - Linker multiple definition of 'ExceptionMatches' when + using directors and multiple modules. + +2015-04-11: wsfulton + Merge #320 - Make __dict__ accessible for Python builtin classes. + +2015-04-07: wsfulton + Fix #375 - parsing of extern "C" and typedef for example: + extern "C" typedef void (*Hook2_t)(int, const char *); + extern "C" typedef int Integer; + +2015-03-12: olly + -DSWIG_DIRECTOR_STATIC is now supported for all languages with + director support, not only Python and PHP. + +2015-03-02: ianlancetaylor + [Go] Add -cgo option, required for Go versions 1.5 and + later. + +2015-02-26: olly + Fix segmentation fault when top==NULL, introduced by nested class + handling (reported in issue#346 by Pawe¿ Tomulik). + +2015-02-09: wsfulton + [Guile] Fix generated code for static const char member variables when + defined and declared inline. + +2015-02-09: mishas + [Go] Fix %import of files in sub directories. + +2015-02-05: ianlancetaylor + [Go] Ignore Go specific type maps (goin, goout, etc.) if they are empty. + +2015-02-05: ianlancetaylor + [Go] Generated Go code no longer calls _swig_goallocate or + _swig_makegostring, as they will no longer work as of Go 1.5. + +Version 3.0.5 (31 Jan 2015) +=========================== + +2015-01-30: wsfulton + [Python] Fix Python -classic and property setting. Setting properties on classic classes + was broken in swig-3.0.3 by attempting to use __setattr__. This regression is fixed now + by using __dict__ again when using -classic. + Fixes patch #232. + +2015-01-27: smarchetto + [Scilab] Support for the Scilab language has been added + +2015-01-23: olly + [PHP] When wrapping a returned resource as an object, check if all + cases wrap it in the same class, and if so eliminate the pointless + switch statement wrapper we previously generated. + +2015-01-22: wsfulton + [Octave] Merge patch #297 for SF bug #1277 - Octave shared_ptr support + +2015-01-15: wsfulton + [Python] Merge patch #250 - Fixes for using %constant and objects (non-primitive types) + +2015-01-15: wsfulton + [C# Go] Merge patch #308 and fix #307 - C++11 strongly typed enum support + in directors + +2015-01-15: wsfulton + [Python] Second fix for #294 #296 - Regression introduced in SWIG-3.0.3 when + wrapping functions with default arguments, this time when using kwargs. + Version 3.0.4 (14 Jan 2015) =========================== @@ -69,6 +577,10 @@ Version 3.0.3 (30 Dec 2014) [Python] Patch #201 The generated .py file no longer uses *args for all Python parameters. Instead, the parameters are named using the C++ parameter names. + "compactdefaultargs" feature can be enabled to restore the old behaviour. + + *** POTENTIAL INCOMPATIBILITY *** + 2014-10-24: timotheecour [D] Patch #204 Use core.atomic.atomicOp to mutate shared variables @@ -1489,7 +2001,7 @@ Version 2.0.6 (30 April 2012) [Lua] Fix uninitialised variable in SWIGTYPE **OUTPUT typemaps as reported by Jim Anderson. 2012-04-28: wsfulton - [Python] Fix compilation errors when wrapping STL containers on Mac OSX and possibly other systems. + [Python] Fix compilation errors when wrapping STL containers on Mac OS X and possibly other systems. 2012-04-28: wsfulton [Java] Patch 3521811 from Leo Davis - char **STRING_ARRAY typemaps fixed to handle @@ -2184,7 +2696,7 @@ Version 2.0.2 (20 February 2011) Update chapter name to MzScheme/Racket accounting for the rename of MzScheme to Racket. 2011-02-05: wsfulton - [C#] SF #3085906 - Possible fix running test-suite on Mac OSX. + [C#] SF #3085906 - Possible fix running test-suite on Mac OS X. 2011-02-05: wsfulton SF #3173367 Better information during configure about Boost prerequisite for running @@ -3837,7 +4349,7 @@ Version 1.3.37 (13 January 2009) in Allegro CL 2008-07-19: wsfulton - Fix building of Tcl examples/test-suite on Mac OSX reported by Gideon Simpson. + Fix building of Tcl examples/test-suite on Mac OS X reported by Gideon Simpson. 2008-07-17: wsfulton Fix SF #2019156 Configuring with --without-octave or --without-alllang @@ -7341,7 +7853,7 @@ Version 1.3.28 (February 12, 2006) 12/10/2005: mmatus [UTF] - - Fix unneccessary calls to SWIG_TypeQuery for 'char *' + - Fix unnecessary calls to SWIG_TypeQuery for 'char *' and 'wchar_t *', problem found by Clay Culver while profiling the PyOgre project. @@ -10676,7 +11188,7 @@ Version 1.3.23 (November 11, 2004) now if you have - %pythonnondynamic(1) A; + %pythonnondynamic A; struct A { int a; @@ -10694,11 +11206,11 @@ Version 1.3.23 (November 11, 2004) Since this is a feature, you can use - %pythonnondynamic(1); + %pythonnondynamic; or - %pythondynamic(0); [ Note: %pythondynamic since deprecated ] + %pythondynamic; [ Note: %pythondynamic since deprecated ] to force all the wrapped classes to be "nondynamic" ones. @@ -12658,7 +13170,7 @@ Version 1.3.20 (December 17, 2003) Suggested by Kerim Borchaev. 11/11/2003: beazley - Configuration changes to make SWIG work on Mac OSX 10.3.x (Panther). + Configuration changes to make SWIG work on Mac OS X 10.3.x (Panther). Tested with Python, Tcl, Perl, and Ruby---all of which seem to work. 11/08/2003: cheetah (William Fulton) @@ -23064,7 +23576,7 @@ Version 1.1b5 (March 12, 1997) 2/23/97 : Modified Python module to be better behaved under Windows - Module initialization function is now properly exported. - It should not be neccessary to explicitly export this function + It should not be necessary to explicitly export this function yourself. - Bizarre compilation problems when compiling the SWIG wrapper diff --git a/CHANGES.current b/CHANGES.current index 084711f9f4a..4c5ef680e19 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,12 +2,71 @@ Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 3.0.5 (in progress) +Version 3.0.9 (in progress) =========================== -2015-01-15: wsfulton - [Python] Merge patch #250 - Fixes for using %constant and objects (non-primitive types) +2016-03-01: olly + [Python] Fix isfinite() check to work with GCC6. Fixes + https://github.com/swig/swig/issues/615 reported by jplesnik. -2015-01-15: wsfulton - [C# Go] Merge patch #308 and fix #307 - C++11 strongly typed enum support - in directors +2016-02-17: olly + [Python] Add missing keywords 'as' and 'with' to pythonkw.swg. + +2016-02-07: kwwette + [Octave] recognise various unary functions + * Use __float__() for numeric conversions, e.g. when calling double() + * Map various unary functions, e.g. abs() to __abs__(), see full list + in section 32.3.10 of manual; only available in Octave 3.8.0 or later + +2016-02-07: kwwette + [Octave] export function swig_octave_prereq() for testing Octave version + +2016-02-06: pjohangustavsson + [C#] Fix duplicate symbol problems when linking the source generated + from multiple SWIG modules into one shared library for the -namespace + option. The namespace is now mangled into the global PInvoke function + names. + + *** POTENTIAL INCOMPATIBILITY *** + +2016-01-27: ahnolds + [Python] Added support for differentiating between Python Bytes + and Unicode objects using by defining SWIG_PYTHON_STRICT_BYTE_CHAR + and SWIG_PYTHON_STRICT_UNICODE_WCHAR. + +2016-01-27: steeve + [Go] Ensure structs are properly packed between gc and GCC/clang. + +2016-01-25: ahnolds + [Python] Support the full Python test suite in -classic mode + * Convert long/unsigned long/long long/unsigned long long to PyInt + rather than PyLong when possible. Certain python functions like + len() require a PyInt when operating on old-style classes. + * Add support for static methods in classic mode, including support + for pythonappend, pythonprepend, and docstrings. + * Removing the use of __swig_getmethods__ for static member methods + since they will always be found by the standard argument lookup + * Fix a bug where the wrong type of exception was caught when + checking for new-style class support + +2016-01-23: ahnolds + [Go] Enable support for the Go test-suite on OSX: + * The linker on OSX requires that all symbols (even weak symbols) + are defined at link time. Because the function _cgo_topofstack is + only defined starting in Go version 1.4, we explicitly mark it as + undefined for older versions of Go on OSX. + * Avoid writing empty swigargs structs, since empty structs are not + allowed in extern "C" blocks. + +2016-01-12: olly + [Javascript] Look for "nodejs" as well as "node", as it's packaged + as the former on Debian. + +2016-01-12: olly + [Javascript] For v8 >= 4.3.0, use V8_MAJOR_VERSION. + Fixes https://github.com/swig/swig/issues/561. + +2016-01-10: ahnolds + Improved size_t and ptrdiff_t typemaps to support large values + on platforms where sizeof(size_t) > sizeof(unsigned long) and + sizeof(ptrdiff_t) > sizeof(long). diff --git a/COPYRIGHT b/COPYRIGHT index 1344630bbc0..c3fbbdebdeb 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -11,57 +11,62 @@ Portions also copyrighted by: Information-technology Promotion Agency, Japan Active SWIG Developers: - William Fulton (wsf@fultondesigns.co.uk) (SWIG core, Java, C#, Windows, Cygwin) - Olly Betts (olly@survex.com) (PHP) - Joseph Wang (joequant@gmail.com) (R) - Xavier Delacour (xavier.delacour@gmail.com) (Octave) - David Nadlinger (code@klickverbot.at) (D) - Oliver Buchtala (oliver.buchtala@gmail.com) (Javascript) - Neha Narang (narangneha03@gmail.com) (Javascript) + William Fulton (wsf@fultondesigns.co.uk) (SWIG core, Java, C#, Windows, Cygwin) + Olly Betts (olly@survex.com) (PHP) + Joseph Wang (joequant@gmail.com) (R) + Xavier Delacour (xavier.delacour@gmail.com) (Octave) + David Nadlinger (code@klickverbot.at) (D) + Oliver Buchtala (oliver.buchtala@gmail.com) (Javascript) + Neha Narang (narangneha03@gmail.com) (Javascript) + Simon Marchetto (simon.marchetto@scilab-enterprises.com) (Scilab) Past SWIG developers and major contributors include: - Dave Beazley (dave-swig@dabeaz.com) (SWIG core, Python, Tcl, Perl) - Henning Thielemann (swig@henning-thielemann.de) (Modula3) - Matthias Köppe (mkoeppe@mail.math.uni-magdeburg.de) (Guile, MzScheme) - Luigi Ballabio (luigi.ballabio@fastwebnet.it) (STL wrapping) - Mikel Bancroft (mikel@franz.com) (Allegro CL) - Surendra Singhi (efuzzyone@netscape.net) (CLISP, CFFI) - Marcelo Matus (mmatus@acms.arizona.edu) (SWIG core, Python, UTL[python,perl,tcl,ruby]) - Art Yerkes (ayerkes@speakeasy.net) (Ocaml) - Lyle Johnson (lyle@users.sourceforge.net) (Ruby) - Charlie Savage (cfis@interserv.com) (Ruby) - Thien-Thi Nguyen (ttn@glug.org) (build/test/misc) - Richard Palmer (richard@magicality.org) (PHP) - Sam Liddicott - Ananova Ltd (saml@liddicott.com) (PHP) - Tim Hockin - Sun Microsystems (thockin@sun.com) (PHP) - Kevin Ruland (PHP) - Shibukawa Yoshiki (Japanese Translation) - Jason Stewart (jason@openinformatics.com) (Perl5) - Loic Dachary (Perl5) - David Fletcher (Perl5) - Gary Holt (Perl5) - Masaki Fukushima (Ruby) - Scott Michel (scottm@cs.ucla.edu) (Java directors) - Tiger Feng (songyanf@cs.uchicago.edu) (SWIG core) - Mark Rose (mrose@stm.lbl.gov) (Directors) - Jonah Beckford (beckford@usermail.com) (CHICKEN) - Ahmon Dancy (dancy@franz.com) (Allegro CL) - Dirk Gerrits (Allegro CL) - Neil Cawse (C#) - Harco de Hilster (Java) - Alexey Dyachenko (dyachenko@fromru.com) (Tcl) - Bob Techentin (Tcl) - Martin Froehlich (Guile) - Marcio Luis Teixeira (Guile) - Duncan Temple Lang (R) - Miklos Vajna (PHP directors) - Mark Gossage (mark@gossage.cjb.net) (Lua) - Raman Gopalan (ramangopalan@gmail.com) (eLua) - Gonzalo Garramuno (ggarra@advancedsl.com.ar) (Ruby, Ruby's UTL) - John Lenz (Guile, MzScheme updates, Chicken module, runtime system) - Ian Lance Taylor (Go) - Vadim Zeitlin (PCRE) - Stefan Zager (szager@gmail.com) (Python) + Dave Beazley (dave-swig@dabeaz.com) (SWIG core, Python, Tcl, Perl) + Henning Thielemann (swig@henning-thielemann.de) (Modula3) + Matthias Köppe (mkoeppe@mail.math.uni-magdeburg.de) (Guile, MzScheme) + Luigi Ballabio (luigi.ballabio@fastwebnet.it) (STL wrapping) + Mikel Bancroft (mikel@franz.com) (Allegro CL) + Surendra Singhi (efuzzyone@netscape.net) (CLISP, CFFI) + Marcelo Matus (mmatus@acms.arizona.edu) (SWIG core, Python, UTL[python,perl,tcl,ruby]) + Art Yerkes (ayerkes@speakeasy.net) (Ocaml) + Lyle Johnson (lyle@users.sourceforge.net) (Ruby) + Charlie Savage (cfis@interserv.com) (Ruby) + Thien-Thi Nguyen (ttn@glug.org) (build/test/misc) + Richard Palmer (richard@magicality.org) (PHP) + Sam Liddicott - Ananova Ltd (saml@liddicott.com) (PHP) + Tim Hockin - Sun Microsystems (thockin@sun.com) (PHP) + Kevin Ruland (PHP) + Shibukawa Yoshiki (Japanese Translation) + Jason Stewart (jason@openinformatics.com) (Perl5) + Loic Dachary (Perl5) + David Fletcher (Perl5) + Gary Holt (Perl5) + Masaki Fukushima (Ruby) + Scott Michel (scottm@cs.ucla.edu) (Java directors) + Tiger Feng (songyanf@cs.uchicago.edu) (SWIG core) + Mark Rose (mrose@stm.lbl.gov) (Directors) + Jonah Beckford (beckford@usermail.com) (CHICKEN) + Ahmon Dancy (dancy@franz.com) (Allegro CL) + Dirk Gerrits (Allegro CL) + Neil Cawse (C#) + Harco de Hilster (Java) + Alexey Dyachenko (dyachenko@fromru.com) (Tcl) + Bob Techentin (Tcl) + Martin Froehlich (Guile) + Marcio Luis Teixeira (Guile) + Duncan Temple Lang (R) + Miklos Vajna (PHP directors) + Mark Gossage (mark@gossage.cjb.net) (Lua) + Raman Gopalan (ramangopalan@gmail.com) (eLua) + Gonzalo Garramuno (ggarra@advancedsl.com.ar) (Ruby, Ruby's UTL) + John Lenz (Guile, MzScheme updates, Chicken module, runtime system) + Baozeng Ding (Scilab) + Ian Lance Taylor (Go) + Vadim Zeitlin (PCRE, Python) + Stefan Zager (szager@gmail.com) (Python) + Vincent Couvert (Scilab) + Sylvestre Ledru (Scilab) + Wolfgang Frisch (Scilab) Past contributors include: James Michael DuPont, Clark McGrew, Dustin Mitchell, Ian Cooke, Catalin Dumitrescu, Baran diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html index 8295bad1c0a..4b6bad42151 100644 --- a/Doc/Manual/Allegrocl.html +++ b/Doc/Manual/Allegrocl.html @@ -1,14 +1,14 @@ - - + SWIG and Allegro Common Lisp + -

18 SWIG and Allegro Common Lisp

+

18 SWIG and Allegro Common Lisp

    @@ -135,10 +135,10 @@

    18 SWIG and Allegro Common Lisp

    to it.

    -

    18.1 Basics

    +

    18.1 Basics

    -

    18.1.1 Running SWIG

    +

    18.1.1 Running SWIG

    @@ -360,7 +360,7 @@

    18.1.1 Running SWIG

    the C++ wrapper will be what you then load into Allegro CL.

    -

    18.1.2 Command Line Options

    +

    18.1.2 Command Line Options

    @@ -373,21 +373,21 @@

    18.1.2 Command Line Options

    -identifier-converter [name] - Binds the variable swig:*swig-identifier-convert* in the generated .cl file to name. - This function is used to generate symbols - for the lisp side of the interface. + This function is used to generate symbols + for the lisp side of the interface. -cwrap - [default] Generate a .cxx file containing C wrapper function when wrapping C code. The interface generated is similar to what is - done for C++ code. + done for C++ code. -nocwrap - Explicitly turn off generation of .cxx wrappers for C code. Reasonable for modules with simple interfaces. Can not handle all legal enum - and constant constructs, or take advantage of SWIG customization features. + and constant constructs, or take advantage of SWIG customization features. -isolate - With this command-line argument, all lisp helper functions are defined in a unique package named swig.<module-name> rather than - swig. This prevents conflicts when the module is - intended to be used with other swig generated interfaces that may, - for instance, make use of different identifier converters. + swig. This prevents conflicts when the module is + intended to be used with other swig generated interfaces that may, + for instance, make use of different identifier converters.
@@ -396,7 +396,7 @@

18.1.2 Command Line Options

functions for more details.

-

18.1.3 Inserting user code into generated files

+

18.1.3 Inserting user code into generated files

@@ -436,7 +436,7 @@

18.1.3 Inserting user code into generated files<

-

18.2 Wrapping Overview

+

18.2 Wrapping Overview

@@ -446,7 +446,7 @@

18.2 Wrapping Overview

interested in generating an interface to C++.

-

18.2.1 Function Wrapping

+

18.2.1 Function Wrapping

@@ -472,7 +472,7 @@

18.2.1 Function Wrapping

| Foreign Code | What we're generating an interface to. |______________| | - | + | _______v______ | | (foreign side) | Wrapper code | extern "C" wrappers calling C++ @@ -484,22 +484,22 @@

18.2.1 Function Wrapping

| FFI Layer | Low level lisp interface. ff:def-foreign-call, |______________| ff:def-foreign-variable | - +---------------------------- + +---------------------------- _______v______ _______v______ | | | | (lisp side) | Defuns | | Defmethods | wrapper for overloaded |______________| |______________| functions or those with (lisp side) | defaulted arguments - Wrapper for non-overloaded | - functions and methods _______v______ - | | (lisp side) - | Defuns | dispatch function - |______________| to overloads based - on arity + Wrapper for non-overloaded | + functions and methods _______v______ + | | (lisp side) + | Defuns | dispatch function + |______________| to overloads based + on arity -

18.2.2 Foreign Wrappers

+

18.2.2 Foreign Wrappers

@@ -512,7 +512,7 @@

18.2.2 Foreign Wrappers

typemap.

-

18.2.3 FFI Wrappers

+

18.2.3 FFI Wrappers

@@ -593,7 +593,7 @@

18.2.3 FFI Wrappers

ff:def-foreign-call's.

-

18.2.4 Non-overloaded Defuns

+

18.2.4 Non-overloaded Defuns

@@ -606,7 +606,7 @@

18.2.4 Non-overloaded Defuns

this function can be manipulated via the lout typemap.

-

18.2.5 Overloaded Defuns

+

18.2.5 Overloaded Defuns

@@ -622,7 +622,7 @@

18.2.5 Overloaded Defuns

can be manipulated via the lout typemap.

-

18.2.6 What about constant and variable access?

+

18.2.6 What about constant and variable access?

@@ -635,7 +635,7 @@

18.2.6 What about constant and variable access? into the foreign module.

-

18.2.7 Object Wrapping

+

18.2.7 Object Wrapping

@@ -657,7 +657,7 @@

18.2.7 Object Wrapping

foreign function interface.

-

18.3 Wrapping Details

+

18.3 Wrapping Details

@@ -665,7 +665,7 @@

18.3 Wrapping Details

translated into lisp.

-

18.3.1 Namespaces

+

18.3.1 Namespaces

@@ -742,7 +742,7 @@

18.3.1 Namespaces

function such as (car '(1 2 3).

-

18.3.2 Constants

+

18.3.2 Constants

@@ -799,11 +799,11 @@

18.3.2 Constants

- Users are cautioned to get to know their constants before use, or - not use the -nocwrap command-line option. + Users are cautioned to get to know their constants before use, or + not use the -nocwrap command-line option.

-

18.3.3 Variables

+

18.3.3 Variables

@@ -881,7 +881,7 @@

18.3.3 Variables

-

18.3.4 Enumerations

+

18.3.4 Enumerations

@@ -907,7 +907,7 @@

18.3.4 Enumerations

For example, the following header file

enum.h:
-enum COL { RED, GREEN, BLUE };	
+enum COL { RED, GREEN, BLUE };
 enum FOO { FOO1 = 10, FOO2, FOO3 };
       
@@ -957,7 +957,7 @@

18.3.4 Enumerations

-

18.3.5 Arrays

+

18.3.5 Arrays

@@ -1105,10 +1105,10 @@

18.3.5 Arrays

-

18.3.6 Classes and Structs and Unions (oh my!)

+

18.3.6 Classes and Structs and Unions (oh my!)

-

18.3.6.1 CLOS wrapping of

+

18.3.6.1 CLOS wrapping of

@@ -1123,7 +1123,7 @@

18.3.6.1 CLOS wrapping of

integer values.

-

18.3.6.2 CLOS Inheritance

+

18.3.6.2 CLOS Inheritance

@@ -1136,7 +1136,7 @@

18.3.6.2 CLOS Inheritance

parameter.

-

18.3.6.3 Member fields and functions

+

18.3.6.3 Member fields and functions

@@ -1152,7 +1152,7 @@

18.3.6.3 Member fields and functions

the interface does nothing for friend directives,

-

18.3.6.4 Why not directly access C++ classes using foreign types?

+

18.3.6.4 Why not directly access C++ classes using foreign types?

@@ -1170,34 +1170,34 @@

18.3.6.4 Why not directly access C++ classes us use the more robust wrapper functions.

-

18.3.7 Templates

+

18.3.7 Templates

-

18.3.7.1 Generating wrapper code for templates

+

18.3.7.1 Generating wrapper code for templates

-

- SWIG provides support for dealing with templates, but by - default, it will not generate any member variable or function - wrappers for templated classes. In order to create these - wrappers, you need to explicitly tell SWIG to instantiate - them. This is done via the - %template - directive. -

+

+SWIG provides support for dealing with templates, but by +default, it will not generate any member variable or function +wrappers for templated classes. In order to create these +wrappers, you need to explicitly tell SWIG to instantiate +them. This is done via the +%template +directive. +

-

18.3.7.2 Implicit Template instantiation

+

18.3.7.2 Implicit Template instantiation

-

- While no wrapper code is generated for accessing member - variables, or calling member functions, type code is generated - to include these templated classes in the foreign-type and CLOS - class schema. -

+

+While no wrapper code is generated for accessing member +variables, or calling member functions, type code is generated +to include these templated classes in the foreign-type and CLOS +class schema. +

-

18.3.8 Typedef, Templates, and Synonym Types

+

18.3.8 Typedef, Templates, and Synonym Types

@@ -1243,7 +1243,7 @@

18.3.8 Typedef, Templates, and Synonym Types
- (setf (find-class <synonym>) <primary>) + (setf (find-class <synonym>) <primary>)

The result is that all references to synonym types in foreign @@ -1277,7 +1277,7 @@

18.3.8 Typedef, Templates, and Synonym Types -

18.3.8.1 Choosing a primary type

+

18.3.8.1 Choosing a primary type

@@ -1285,20 +1285,20 @@

18.3.8.1 Choosing a primary type

criteria from a set of synonym types.

    -
  • - If a synonym type has a class definition, it is the primary type. -
  • -
  • - If a synonym type is a class template and has been explicitly - instantiated via %template, it is the primary type. -
  • -
  • - For all other sets of synonymous types, the synonym which is - parsed first becomes the primary type. -
  • +
  • + If a synonym type has a class definition, it is the primary type. +
  • +
  • + If a synonym type is a class template and has been explicitly + instantiated via %template, it is the primary type. +
  • +
  • + For all other sets of synonymous types, the synonym which is + parsed first becomes the primary type. +
-

18.3.9 Function overloading/Parameter defaulting

+

18.3.9 Function overloading/Parameter defaulting

@@ -1461,7 +1461,7 @@

18.3.9 Function overloading/Parameter defaultin -

18.3.10 Operator wrapping and Operator overloading

+

18.3.10 Operator wrapping and Operator overloading

@@ -1472,68 +1472,68 @@

18.3.10 Operator wrapping and Operator overload
 /* name conversion for overloaded operators. */
 #ifdef __cplusplus
-%rename(__add__)	     *::operator+;
-%rename(__pos__)	     *::operator+();
-%rename(__pos__)	     *::operator+() const;
+%rename(__add__)             *::operator+;
+%rename(__pos__)             *::operator+();
+%rename(__pos__)             *::operator+() const;
 
-%rename(__sub__)	     *::operator-;
-%rename(__neg__)	     *::operator-() const;
-%rename(__neg__)	     *::operator-();
+%rename(__sub__)             *::operator-;
+%rename(__neg__)             *::operator-() const;
+%rename(__neg__)             *::operator-();
 
-%rename(__mul__)	     *::operator*;
-%rename(__deref__)	     *::operator*();
-%rename(__deref__)	     *::operator*() const;
+%rename(__mul__)             *::operator*;
+%rename(__deref__)           *::operator*();
+%rename(__deref__)           *::operator*() const;
 
-%rename(__div__)	     *::operator/;
-%rename(__mod__)	     *::operator%;
-%rename(__logxor__)	     *::operator^;
-%rename(__logand__)	     *::operator&;
-%rename(__logior__)	     *::operator|;
-%rename(__lognot__)	     *::operator~();
-%rename(__lognot__)	     *::operator~() const;
+%rename(__div__)             *::operator/;
+%rename(__mod__)             *::operator%;
+%rename(__logxor__)          *::operator^;
+%rename(__logand__)          *::operator&;
+%rename(__logior__)          *::operator|;
+%rename(__lognot__)          *::operator~();
+%rename(__lognot__)          *::operator~() const;
 
-%rename(__not__)	     *::operator!();
-%rename(__not__)	     *::operator!() const;
+%rename(__not__)             *::operator!();
+%rename(__not__)             *::operator!() const;
 
-%rename(__assign__)	     *::operator=;
+%rename(__assign__)          *::operator=;
 
 %rename(__add_assign__)      *::operator+=;
-%rename(__sub_assign__)	     *::operator-=;
-%rename(__mul_assign__)	     *::operator*=;
-%rename(__div_assign__)	     *::operator/=;
-%rename(__mod_assign__)	     *::operator%=;
+%rename(__sub_assign__)      *::operator-=;
+%rename(__mul_assign__)      *::operator*=;
+%rename(__div_assign__)      *::operator/=;
+%rename(__mod_assign__)      *::operator%=;
 %rename(__logxor_assign__)   *::operator^=;
 %rename(__logand_assign__)   *::operator&=;
 %rename(__logior_assign__)   *::operator|=;
 
-%rename(__lshift__)	     *::operator<<;
+%rename(__lshift__)          *::operator<<;
 %rename(__lshift_assign__)   *::operator<<=;
-%rename(__rshift__)	     *::operator>>;
+%rename(__rshift__)          *::operator>>;
 %rename(__rshift_assign__)   *::operator>>=;
 
-%rename(__eq__)		     *::operator==;
-%rename(__ne__)		     *::operator!=;
-%rename(__lt__)		     *::operator<;
-%rename(__gt__)		     *::operator>;
-%rename(__lte__)	     *::operator<=;
-%rename(__gte__)	     *::operator>=;
+%rename(__eq__)              *::operator==;
+%rename(__ne__)              *::operator!=;
+%rename(__lt__)              *::operator<;
+%rename(__gt__)              *::operator>;
+%rename(__lte__)             *::operator<=;
+%rename(__gte__)             *::operator>=;
 
-%rename(__and__)	     *::operator&&;
-%rename(__or__)		     *::operator||;
+%rename(__and__)             *::operator&&;
+%rename(__or__)              *::operator||;
 
-%rename(__preincr__)	     *::operator++();
-%rename(__postincr__)	     *::operator++(int);
-%rename(__predecr__)	     *::operator--();
-%rename(__postdecr__)	     *::operator--(int);
+%rename(__preincr__)         *::operator++();
+%rename(__postincr__)        *::operator++(int);
+%rename(__predecr__)         *::operator--();
+%rename(__postdecr__)        *::operator--(int);
 
-%rename(__comma__)	     *::operator,();
-%rename(__comma__)	     *::operator,() const;
+%rename(__comma__)           *::operator,();
+%rename(__comma__)           *::operator,() const;
 
 %rename(__member_ref__)      *::operator->;
 %rename(__member_func_ref__) *::operator->*;
 
-%rename(__funcall__)	     *::operator();
-%rename(__aref__)	     *::operator[];
+%rename(__funcall__)         *::operator();
+%rename(__aref__)            *::operator[];
     
@@ -1607,7 +1607,7 @@

18.3.10 Operator wrapping and Operator overload -

18.3.11 Varargs

+

18.3.11 Varargs

@@ -1628,7 +1628,7 @@

18.3.11 Varargs

with other ways such functions can be wrapped.

-

18.3.12 C++ Exceptions

+

18.3.12 C++ Exceptions

@@ -1640,7 +1640,7 @@

18.3.12 C++ Exceptions

implemented.

-

18.3.13 Pass by value, pass by reference

+

18.3.13 Pass by value, pass by reference

@@ -1652,7 +1652,7 @@

18.3.13 Pass by value, pass by reference

newly defined types.

-

18.4 Typemaps

+

18.4 Typemaps

@@ -1663,7 +1663,7 @@

18.4 Typemaps

on Typemaps for more information.

-

18.4.1 Code Generation in the C++ Wrapper

+

18.4.1 Code Generation in the C++ Wrapper

@@ -1693,7 +1693,7 @@

18.4.1 Code Generation in the C++ Wrapper

-

18.4.1.1 IN Typemap

+

18.4.1.1 IN Typemap

@@ -1728,7 +1728,7 @@

18.4.1.1 IN Typemap

-

18.4.1.2 OUT Typemap

+

18.4.1.2 OUT Typemap

@@ -1752,7 +1752,7 @@

18.4.1.2 OUT Typemap

-

18.4.1.3 CTYPE Typemap

+

18.4.1.3 CTYPE Typemap

@@ -1784,7 +1784,7 @@

18.4.1.3 CTYPE Typemap

these common typemaps here.

-

18.4.2 Code generation in Lisp wrappers

+

18.4.2 Code generation in Lisp wrappers

@@ -1803,7 +1803,7 @@

18.4.2 Code generation in Lisp wrappers

16.3.1 Namespaces for details.

-

18.4.2.1 LIN Typemap

+

18.4.2.1 LIN Typemap

@@ -1821,32 +1821,32 @@

18.4.2.1 LIN Typemap

The LIN typemap accepts the following $variable references.

    -
  • $in - expands to the name of the parameter being - applied to this typemap -
  • -
  • $out - expands to the name of the local variable - assigned to this typemap -
  • -
  • $in_fftype - the foreign function type of the C type.
  • -
  • $*in_fftype - the foreign function type of the C type - with one pointer removed. If there is no pointer, then $*in_fftype - is the same as $in_fftype. -
  • -
  • $body - very important. Instructs SWIG where - subsequent code generation steps should be inserted into the - current typemap. Leaving out a $body reference - will result in lisp wrappers that do very little by way of - calling into foreign code. Not recommended. -
  • +
  • $in - expands to the name of the parameter being + applied to this typemap +
  • +
  • $out - expands to the name of the local variable + assigned to this typemap +
  • +
  • $in_fftype - the foreign function type of the C type.
  • +
  • $*in_fftype - the foreign function type of the C type + with one pointer removed. If there is no pointer, then $*in_fftype + is the same as $in_fftype. +
  • +
  • $body - very important. Instructs SWIG where + subsequent code generation steps should be inserted into the + current typemap. Leaving out a $body reference + will result in lisp wrappers that do very little by way of + calling into foreign code. Not recommended. +
-%typemap(lin)	SWIGTYPE 	"(cl:let (($out $in))\n  $body)";
+%typemap(lin) SWIGTYPE "(cl:let (($out $in))\n  $body)";
     
-

18.4.2.2 LOUT Typemap

+

18.4.2.2 LOUT Typemap

@@ -1858,17 +1858,17 @@

18.4.2.2 LOUT Typemap

The LOUT typemap uses the following $variable

    -
  • $lclass - Expands to the CLOS class that - represents foreign-objects of the return type matching this - typemap. -
  • -
  • $body - Same as for the LIN map. Place this - variable where you want the foreign-function call to occur. -
  • -
  • $ldestructor - Expands to the symbol naming the destructor for this - class ($lclass) of object. Allows you to insert finalization or automatic garbage - collection into the wrapper code (see default mappings below). -
  • +
  • $lclass - Expands to the CLOS class that + represents foreign-objects of the return type matching this + typemap. +
  • +
  • $body - Same as for the LIN map. Place this + variable where you want the foreign-function call to occur. +
  • +
  • $ldestructor - Expands to the symbol naming the destructor for this + class ($lclass) of object. Allows you to insert finalization or automatic garbage + collection into the wrapper code (see default mappings below). +
@@ -1889,7 +1889,7 @@

18.4.2.2 LOUT Typemap

-

18.4.2.3 FFITYPE Typemap

+

18.4.2.3 FFITYPE Typemap

@@ -1939,7 +1939,7 @@

18.4.2.3 FFITYPE Typemap

-

18.4.2.4 LISPTYPE Typemap

+

18.4.2.4 LISPTYPE Typemap

@@ -1959,7 +1959,7 @@

18.4.2.4 LISPTYPE Typemap

-

18.4.2.5 LISPCLASS Typemap

+

18.4.2.5 LISPCLASS Typemap

@@ -1983,7 +1983,7 @@

18.4.2.5 LISPCLASS Typemap

-

18.4.3 Modifying SWIG behavior using typemaps

+

18.4.3 Modifying SWIG behavior using typemaps

@@ -2017,10 +2017,10 @@

18.4.3 Modifying SWIG behavior using typemaps -

18.5 Identifier Converter functions

+

18.5 Identifier Converter functions

-

18.5.1 Creating symbols in the lisp environment

+

18.5.1 Creating symbols in the lisp environment

@@ -2041,11 +2041,11 @@

18.5.1 Creating symbols in the lisp environment of arguments.

-

18.5.2 Existing identifier-converter functions

+

18.5.2 Existing identifier-converter functions

Two basic identifier routines have been defined. -

18.5.2.1 identifier-convert-null

+

18.5.2.1 identifier-convert-null

@@ -2054,7 +2054,7 @@

18.5.2.1 identifier-convert-null

strings, from which a symbol will be created.

-

18.5.2.2 identifier-convert-lispify

+

18.5.2.2 identifier-convert-lispify

@@ -2063,7 +2063,7 @@

18.5.2.2 identifier-convert-lispify

same symbol transformations.

-

18.5.2.3 Default identifier to symbol conversions

+

18.5.2.3 Default identifier to symbol conversions

@@ -2072,7 +2072,7 @@

18.5.2.3 Default identifier to symbol conversio default naming conventions.

-

18.5.3 Defining your own identifier-converter

+

18.5.3 Defining your own identifier-converter

@@ -2128,7 +2128,7 @@

18.5.3 Defining your own identifier-converter -

18.5.4 Instructing SWIG to use a particular identifier-converter

+

18.5.4 Instructing SWIG to use a particular identifier-converter

diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html index 2890e241519..8838e67a9fd 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -1,11 +1,12 @@ - + SWIG and Android + -

19 SWIG and Android

+

19 SWIG and Android

    @@ -30,24 +31,24 @@

    19 SWIG and Android

    -

    19.1 Overview

    +

    19.1 Overview

    The Android chapter is fairly short as support for Android is the same as for Java, where the Java Native Interface (JNI) is used to call from Android Java into C or C++ compiled code. -Everything in the Java chapter applies to generating code for access from Android Java code. +Everything in the Java chapter applies to generating code for access from Android Java code. This chapter contains a few Android specific notes and examples.

    -

    19.2 Android examples

    +

    19.2 Android examples

    -

    19.2.1 Examples introduction

    +

    19.2.1 Examples introduction

    -The examples require the Android SDK and Android NDK which can be installed as per instructions in the links. +The examples require the Android SDK and Android NDK which can be installed as per instructions in the links. The Eclipse version is not required for these examples as just the command line tools are used (shown for Linux as the host, but Windows will be very similar, if not identical in most places). Add the SDK tools and NDK tools to your path and create a directory somewhere for your Android projects (adjust PATH as necessary to where you installed the tools):

    @@ -76,7 +77,7 @@

    19.2.1 Examples introduction

    The following examples are shipped with SWIG under the Examples/android directory and include a Makefile to build and install each example.

    -

    19.2.2 Simple C example

    +

    19.2.2 Simple C example

    @@ -209,7 +210,7 @@

    19.2.2 Simple C example

     $ adb devices
     List of devices attached 
    -A32-6DBE0001-9FF80000-015D62C3-02018028	device
    +A32-6DBE0001-9FF80000-015D62C3-02018028 device
     
@@ -221,7 +222,7 @@

19.2.2 Simple C example

 $ adb install bin/SwigSimple-debug.apk 
 95 KB/s (4834 bytes in 0.049s)
-	pkg: /data/local/tmp/SwigSimple-debug.apk
+        pkg: /data/local/tmp/SwigSimple-debug.apk
 Success
 
@@ -398,7 +399,7 @@

19.2.2 Simple C example

Android screenshot of SwigSimple example
-

19.2.3 C++ class example

+

19.2.3 C++ class example

@@ -746,7 +747,7 @@

19.2.3 C++ class example

Android screenshot of SwigClass example
-

19.2.4 Other examples

+

19.2.4 Other examples

@@ -758,7 +759,7 @@

19.2.4 Other examples

Normally C++ exception handling and the STL is not available by default in the version of g++ shipped with Android, but this example turns these features on as described in the next section.

-

19.3 C++ STL

+

19.3 C++ STL

diff --git a/Doc/Manual/Arguments.html b/Doc/Manual/Arguments.html index 3b77136862b..48ec5c629b0 100644 --- a/Doc/Manual/Arguments.html +++ b/Doc/Manual/Arguments.html @@ -1,12 +1,13 @@ - + Argument Handling + -

10 Argument Handling

+

10 Argument Handling

    @@ -42,7 +43,7 @@

    10 Argument Handling

    describes some of the techniques for doing this.

    -

    10.1 The typemaps.i library

    +

    10.1 The typemaps.i library

    @@ -50,7 +51,7 @@

    10.1 The typemaps.i library

    change certain properties of argument conversion.

    -

    10.1.1 Introduction

    +

    10.1.1 Introduction

    @@ -59,7 +60,7 @@

    10.1.1 Introduction

     void add(double a, double b, double *result) {
    -	*result = a + b;
    +  *result = a + b;
     }
     
    @@ -194,7 +195,7 @@

    10.1.1 Introduction

-

10.1.2 Input parameters

+

10.1.2 Input parameters

@@ -203,7 +204,7 @@

10.1.2 Input parameters

-int *INPUT		
+int *INPUT
 short *INPUT
 long *INPUT
 unsigned int *INPUT
@@ -220,7 +221,7 @@ 

10.1.2 Input parameters

 double add(double *a, double *b) {
-	return *a+*b;
+  return *a+*b;
 }
 
@@ -247,7 +248,7 @@

10.1.2 Input parameters

result = add(3,4)
-

10.1.3 Output parameters

+

10.1.3 Output parameters

@@ -272,7 +273,7 @@

10.1.3 Output parameters

 void add(double a, double b, double *c) {
-	*c = a+b;
+  *c = a+b;
 }
 
@@ -314,7 +315,7 @@

10.1.3 Output parameters

-

10.1.4 Input/Output parameters

+

10.1.4 Input/Output parameters

@@ -338,7 +339,7 @@

10.1.4 Input/Output parameters

 void negate(double *x) {
-	*x = -(*x);
+  *x = -(*x);
 }
 
 
@@ -379,7 +380,7 @@

10.1.4 Input/Output parameters

SWIG. Backwards compatibility is preserved, but deprecated.

-

10.1.5 Using different names

+

10.1.5 Using different names

@@ -413,7 +414,7 @@

10.1.5 Using different names

file or a matching %clear declaration.

-

10.2 Applying constraints to input values

+

10.2 Applying constraints to input values

@@ -423,7 +424,7 @@

10.2 Applying constraints to input values

can be accomplished including the constraints.i library file.

-

10.2.1 Simple constraint example

+

10.2.1 Simple constraint example

@@ -449,7 +450,7 @@

10.2.1 Simple constraint example

exception will be raised. As a result, it is possible to catch bad values, prevent mysterious program crashes and so on.

-

10.2.2 Constraint methods

+

10.2.2 Constraint methods

@@ -465,7 +466,7 @@

10.2.2 Constraint methods

-

10.2.3 Applying constraints to new datatypes

+

10.2.3 Applying constraints to new datatypes

diff --git a/Doc/Manual/CCache.html b/Doc/Manual/CCache.html new file mode 100644 index 00000000000..d23b0cb2f2d --- /dev/null +++ b/Doc/Manual/CCache.html @@ -0,0 +1,474 @@ + + + +ccache-swig(1) manpage + + + + + +

17 Using SWIG with ccache - ccache-swig(1) manpage

+ + + + + + +

+

17.1 NAME

+ + +

+ +ccache-swig - a fast compiler cache + +

+

17.2 SYNOPSIS

+ + +

+ccache-swig [OPTION] +

+ccache-swig <compiler> [COMPILER OPTIONS] +

+<compiler> [COMPILER OPTIONS] +

+

17.3 DESCRIPTION

+ + +

+ccache-swig is a compiler cache. It speeds up re-compilation of C/C++/SWIG code +by caching previous compiles and detecting when the same compile is +being done again. ccache-swig is ccache plus support for SWIG. ccache +and ccache-swig are used interchangeably in this document. +

+

17.4 OPTIONS SUMMARY

+ + +

+Here is a summary of the options to ccache-swig. +

+

+
+-s                      show statistics summary
+-z                      zero statistics
+-c                      run a cache cleanup
+-C                      clear the cache completely
+-F <n>                  set maximum files in cache
+-M <n>                  set maximum size of cache (use G, M or K)
+-h                      this help page
+-V                      print version number
+
+
+ +

+

17.5 OPTIONS

+ + +

+These options only apply when you invoke ccache as "ccache-swig". When +invoked as a compiler none of these options apply. In that case your +normal compiler options apply and you should refer to your compilers +documentation. +

+

+

-h
Print a options summary page +

+

-s
Print the current statistics summary for the cache. The +statistics are stored spread across the subdirectories of the +cache. Using "ccache-swig -s" adds up the statistics across all +subdirectories and prints the totals. +

+

-z
Zero the cache statistics. +

+

-V
Print the ccache version number +

+

-c
Clean the cache and re-calculate the cache file count and +size totals. Normally the -c option should not be necessary as ccache +keeps the cache below the specified limits at runtime and keeps +statistics up to date on each compile. This option is mostly useful +if you manually modify the cache contents or believe that the cache +size statistics may be inaccurate. +

+

-C
Clear the entire cache, removing all cached files. +

+

-F <maxfiles>
This sets the maximum number of files allowed in +the cache. The value is stored inside the cache directory and applies +to all future compiles. Due to the way the value is stored the actual +value used is always rounded down to the nearest multiple of 16. +

+

-M <maxsize>
This sets the maximum cache size. You can specify +a value in gigabytes, megabytes or kilobytes by appending a G, M or K +to the value. The default is gigabytes. The actual value stored is +rounded down to the nearest multiple of 16 kilobytes. +

+

+

+

17.6 INSTALLATION

+ + +

+There are two ways to use ccache. You can either prefix your compile +commands with "ccache-swig" or you can create a symbolic link between +ccache-swig and the names of your compilers. The first method is most +convenient if you just want to try out ccache or wish to use it for +some specific projects. The second method is most useful for when you +wish to use ccache for all your compiles. +

+To install for usage by the first method just copy ccache-swig to somewhere +in your path. +

+To install for the second method do something like this: +

+
+  cp ccache-swig /usr/local/bin/
+  ln -s /usr/local/bin/ccache-swig /usr/local/bin/gcc
+  ln -s /usr/local/bin/ccache-swig /usr/local/bin/g++
+  ln -s /usr/local/bin/ccache-swig /usr/local/bin/cc
+  ln -s /usr/local/bin/ccache-swig /usr/local/bin/swig
+
+
+ +This will work as long as /usr/local/bin comes before the path to gcc +(which is usually in /usr/bin). After installing you may wish to run +"which gcc" to make sure that the correct link is being used. +

+Note! Do not use a hard link, use a symbolic link. A hardlink will +cause "interesting" problems. +

+

17.7 EXTRA OPTIONS

+ + +

+When run as a compiler front end ccache usually just takes the same +command line options as the compiler you are using. The only exception +to this is the option '--ccache-skip'. That option can be used to tell +ccache that the next option is definitely not a input filename, and +should be passed along to the compiler as-is. +

+The reason this can be important is that ccache does need to parse the +command line and determine what is an input filename and what is a +compiler option, as it needs the input filename to determine the name +of the resulting object file (among other things). The heuristic +ccache uses in this parse is that any string on the command line that +exists as a file is treated as an input file name (usually a C +file). By using --ccache-skip you can force an option to not be +treated as an input file name and instead be passed along to the +compiler as a command line option. +

+

17.8 ENVIRONMENT VARIABLES

+ + +

+ccache uses a number of environment variables to control operation. In +most cases you won't need any of these as the defaults will be fine. +

+

+

+

CCACHE_DIR
the CCACHE_DIR environment variable specifies +where ccache will keep its cached compiler output. The default is +"$HOME/.ccache". +

+

CCACHE_TEMPDIR
the CCACHE_TEMPDIR environment variable specifies +where ccache will put temporary files. The default is the same as +CCACHE_DIR. Note that the CCACHE_TEMPDIR path must be on the same +filesystem as the CCACHE_DIR path, so that renames of files between +the two directories can work. +

+

CCACHE_LOGFILE
If you set the CCACHE_LOGFILE environment +variable then ccache will write some log information on cache hits +and misses in that file. This is useful for tracking down problems. +

+

CCACHE_VERBOSE
If you set the CCACHE_VERBOSE environment +variable then ccache will display on stdout all the compiler invocations +that it makes. This can useful for debugging unexpected problems. +

+

CCACHE_PATH
You can optionally set CCACHE_PATH to a colon +separated path where ccache will look for the real compilers. If you +don't do this then ccache will look for the first executable matching +the compiler name in the normal PATH that isn't a symbolic link to +ccache itself. +

+

CCACHE_CC
You can optionally set CCACHE_CC to force the name +of the compiler to use. If you don't do this then ccache works it out +from the command line. +

+

CCACHE_PREFIX
This option adds a prefix to the command line +that ccache runs when invoking the compiler. Also see the section +below on using ccache with distcc. +

+

CCACHE_DISABLE
If you set the environment variable +CCACHE_DISABLE then ccache will just call the real compiler, +bypassing the cache completely. +

+

CCACHE_READONLY
the CCACHE_READONLY environment variable +tells ccache to attempt to use existing cached object files, but not +to try to add anything new to the cache. If you are using this because +your CCACHE_DIR is read-only, then you may find that you also need to +set CCACHE_TEMPDIR as otherwise ccache will fail to create the +temporary files. +

+

CCACHE_CPP2
If you set the environment variable CCACHE_CPP2 +then ccache will not use the optimisation of avoiding the 2nd call to +the pre-processor by compiling the pre-processed output that was used +for finding the hash in the case of a cache miss. This is primarily a +debugging option, although it is possible that some unusual compilers +will have problems with the intermediate filename extensions used in +this optimisation, in which case this option could allow ccache to be +used. +

+

CCACHE_NOCOMPRESS
If you set the environment variable +CCACHE_NOCOMPRESS then there is no compression used on files that go +into the cache. However, this setting has no effect on how files are +retrieved from the cache, compressed results will still be usable. +

+

CCACHE_NOSTATS
If you set the environment variable +CCACHE_NOSTATS then ccache will not update the statistics files on +each compile. +

+

CCACHE_NLEVELS
The environment variable CCACHE_NLEVELS allows +you to choose the number of levels of hash in the cache directory. The +default is 2. The minimum is 1 and the maximum is 8. +

+

CCACHE_HARDLINK
If you set the environment variable +CCACHE_HARDLINK then ccache will attempt to use hard links from the +cache directory when creating the compiler output rather than using a +file copy. Using hard links is faster, but can confuse programs like +'make' that rely on modification times. Hard links are never made for +compressed cache files. +

+

CCACHE_RECACHE
This forces ccache to not use any cached +results, even if it finds them. New results are still cached, but +existing cache entries are ignored. +

+

CCACHE_UMASK
This sets the umask for ccache and all child +processes (such as the compiler). This is mostly useful when you wish +to share your cache with other users. Note that this also affects the +file permissions set on the object files created from your +compilations. +

+

CCACHE_HASHDIR
This tells ccache to hash the current working +directory when calculating the hash that is used to distinguish two +compiles. This prevents a problem with the storage of the current +working directory in the debug info of a object file, which can lead +ccache to give a cached object file that has the working directory in +the debug info set incorrectly. This option is off by default as the +incorrect setting of this debug info rarely causes problems. If you +strike problems with gdb not using the correct directory then enable +this option. +

+

CCACHE_UNIFY
If you set the environment variable CCACHE_UNIFY +then ccache will use the C/C++ unifier when hashing the pre-processor +output if -g is not used in the compile. The unifier is slower than a +normal hash, so setting this environment variable loses a little bit +of speed, but it means that ccache can take advantage of not +recompiling when the changes to the source code consist of +reformatting only. Note that using CCACHE_UNIFY changes the hash, so +cached compiles with CCACHE_UNIFY set cannot be used when +CCACHE_UNIFY is not set and vice versa. The reason the unifier is off +by default is that it can give incorrect line number information in +compiler warning messages. +

+

CCACHE_EXTENSION
Normally ccache tries to automatically +determine the extension to use for intermediate C pre-processor files +based on the type of file being compiled. Unfortunately this sometimes +doesn't work, for example when using the aCC compiler on HP-UX. On +systems like this you can use the CCACHE_EXTENSION option to override +the default. On HP-UX set this environment variable to "i" if you use +the aCC compiler. +

+

CCACHE_STRIPC
If you set the environment variable +CCACHE_STRIPC then ccache will strip the -c option when invoking +the preprocessor. This option is primarily for the Sun Workshop +C++ compiler as without this option an unwarranted warning is displayed: +CC: Warning: "-E" redefines product from "object" to "source (stdout)" +when -E and -c is used together. +

+

CCACHE_SWIG
When using SWIG as the compiler and it does not +have 'swig' in the executable name, then the CCACHE_SWIG environment +variable needs to be set in order for ccache to work correctly with +SWIG. The use of CCACHE_CPP2 is also recommended for SWIG due to some +preprocessor quirks, however, use of CCACHE_CPP2 can often be skipped +-- check your generated code with and without this option set. Known +problems are using preprocessor directives within %inline blocks and +the use of '#pragma SWIG'. +

+

+

+

17.9 CACHE SIZE MANAGEMENT

+ + +

+By default ccache has a one gigabyte limit on the cache size and no +maximum number of files. You can set a different limit using the +"ccache -M" and "ccache -F" options, which set the size and number of +files limits. +

+When these limits are reached ccache will reduce the cache to 20% +below the numbers you specified in order to avoid doing the cache +clean operation too often. +

+

17.10 CACHE COMPRESSION

+ + +

+By default on most platforms ccache will compress all files it puts +into the cache +using the zlib compression. While this involves a negligible +performance slowdown, it significantly increases the number of files +that fit in the cache. You can turn off compression setting the +CCACHE_NOCOMPRESS environment variable. +

+

17.11 HOW IT WORKS

+ + +

+The basic idea is to detect when you are compiling exactly the same +code a 2nd time and use the previously compiled output. You detect +that it is the same code by forming a hash of: +

+

    +
  • the pre-processor output from running the compiler with -E +
  • the command line options +
  • the real compilers size and modification time +
  • any stderr output generated by the compiler +
+

+These are hashed using md4 (a strong hash) and a cache file is formed +based on that hash result. When the same compilation is done a second +time ccache is able to supply the correct compiler output (including +all warnings etc) from the cache. +

+ccache has been carefully written to always produce exactly the same +compiler output that you would get without the cache. If you ever +discover a case where ccache changes the output of your compiler then +please let me know. +

+

17.12 USING CCACHE WITH DISTCC

+ + +

+distcc is a very useful program for distributing compilation across a +range of compiler servers. It is often useful to combine distcc with +ccache, so that compiles that are done are sped up by distcc, but that +ccache avoids the compile completely where possible. +

+To use distcc with ccache I recommend using the CCACHE_PREFIX +option. You just need to set the environment variable CCACHE_PREFIX to +'distcc' and ccache will prefix the command line used with the +compiler with the command 'distcc'. +

+

17.13 SHARING A CACHE

+ + +

+A group of developers can increase the cache hit rate by sharing a +cache directory. The hard links however cause unwanted side effects, +as all links to a cached file share the file's modification timestamp. +This results in false dependencies to be triggered by timestamp-based +build systems whenever another user links to an existing +file. Typically, users will see that their libraries and binaries are +relinked without reason. To share a cache without side effects, the +following conditions need to be met: +

+

    +
  • Use the same CCACHE_DIR environment variable setting +
  • Unset the CCACHE_HARDLINK environment variable +
  • Make sure everyone sets the CCACHE_UMASK environment variable + to 002, this ensures that cached files are accessible to everyone in + the group. +
  • Make sure that all users have write permission in the entire + cache directory (and that you trust all users of the shared cache). +
  • Make sure that the setgid bit is set on all directories in the + cache. This tells the filesystem to inherit group ownership for new + directories. The command "chmod g+s `find $CCACHE_DIR -type d`" might + be useful for this. +
  • Set CCACHE_NOCOMPRESS for all users, if there are users with + versions of ccache that do not support compression. +
+

+

17.14 HISTORY

+ + +

+ccache was inspired by the compilercache shell script script written +by Erik Thiele and I would like to thank him for an excellent piece of +work. See +http://www.erikyyy.de/compilercache/ +for the Erik's scripts. +ccache-swig is a port of the original ccache with support added for use +with SWIG. +

+I wrote ccache because I wanted to get a bit more speed out of a +compiler cache and I wanted to remove some of the limitations of the +shell-script version. +

+

17.15 DIFFERENCES FROM COMPILERCACHE

+ + +

+The biggest differences between Erik's compilercache script and ccache +are: +

    +
  • ccache is written in C, which makes it a bit faster (calling out to + external programs is mostly what slowed down the scripts). +
  • ccache can automatically find the real compiler +
  • ccache keeps statistics on hits/misses +
  • ccache can do automatic cache management +
  • ccache can cache compiler output that includes warnings. In many + cases this gives ccache a much higher cache hit rate. +
  • ccache can handle a much wider ranger of compiler options +
  • ccache avoids a double call to cpp on a cache miss +
+

+

17.16 CREDITS

+ + +

+Thanks to the following people for their contributions to ccache +

    +
  • Erik Thiele for the original compilercache script +
  • Luciano Rocha for the idea of compiling the pre-processor output + to avoid a 2nd cpp pass +
  • Paul Russell for many suggestions and the debian packaging +
+

+

17.17 AUTHOR

+ + +

+ccache was written by Andrew Tridgell +http://samba.org/~tridge/. +ccache was adapted to create ccache-swig for use with SWIG by William Fulton. +

+If you wish to report a problem or make a suggestion then please email +the SWIG developers on the swig-devel mailing list, see +http://www.swig.org/mail.html +

+ccache is released under the GNU General Public License version 2 or +later. Please see the file COPYING for license details. +

+ + + + diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index b7e1d638ce3..714845bbab3 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -1,12 +1,13 @@ - + SWIG and C++11 + -

7 SWIG and C++11

+

7 SWIG and C++11

-

7.2.2 Generalized constant expressions

+

7.2.2 Generalized constant expressions

SWIG parses and identifies the keyword constexpr, but cannot fully utilise it. @@ -138,7 +139,7 @@

7.2.2 Generalized When either of these is used from a target language, a runtime call is made to obtain the underlying constant.

-

7.2.3 Extern template

+

7.2.3 Extern template

SWIG correctly parses the keywords extern template. @@ -151,7 +152,7 @@

7.2.3 Extern template

%template(VectorInt) std::vector<int>; // SWIG instantiation -

7.2.4 Initializer lists

+

7.2.4 Initializer lists

@@ -283,7 +284,7 @@

7.2.4 Initializer lists

and hence any user supplied typemaps will override it and suppress the warning.

-

7.2.5 Uniform initialization

+

7.2.5 Uniform initialization

The curly brackets {} for member initialization are fully @@ -316,7 +317,7 @@

7.2.5 Uniform initializatio 142.15 -

7.2.6 Type inference

+

7.2.6 Type inference

SWIG supports decltype() with some limitations. Single @@ -333,13 +334,13 @@

7.2.6 Type inference

decltype(i+j) k; // syntax error -

7.2.7 Range-based for-loop

+

7.2.7 Range-based for-loop

This feature is part of the implementation block only. SWIG ignores it.

-

7.2.8 Lambda functions and expressions

+

7.2.8 Lambda functions and expressions

SWIG correctly parses most of the Lambda functions syntax. For example:

@@ -365,7 +366,7 @@

7.2.8 Lambda func Better support should be available in a later release.

-

7.2.9 Alternate function syntax

+

7.2.9 Alternate function syntax

SWIG fully supports the new definition of functions. For example:

@@ -400,7 +401,7 @@

7.2.9 Alternate function auto square(float a, float b) -> decltype(a); -

7.2.10 Object construction improvement

+

7.2.10 Object construction improvement

@@ -463,7 +464,7 @@

7.2.10 Object cons }; -

7.2.11 Explicit overrides and final

+

7.2.11 Explicit overrides and final

@@ -487,12 +488,12 @@

7.2.11 Explicit overrides -

7.2.12 Null pointer constant

+

7.2.12 Null pointer constant

The nullptr constant is mostly unimportant in wrappers. In the few places it has an effect, it is treated like NULL.

-

7.2.13 Strongly typed enumerations

+

7.2.13 Strongly typed enumerations

SWIG supports strongly typed enumerations and parses the new enum class syntax and forward declarator for the enums, such as:

@@ -548,7 +549,7 @@

7.2.13 Strongly typed System.out.println(Color.RainbowColors.Red.swigValue() + " " + Color.WarmColors.Red.swigValue() + " " + Color.PrimeColors.Red.swigValue()); -

7.2.14 Double angle brackets

+

7.2.14 Double angle brackets

SWIG correctly parses the symbols >> as closing the @@ -559,7 +560,7 @@

7.2.14 Double angle brackets std::vector<std::vector<int>> myIntTable; -

7.2.15 Explicit conversion operators

+

7.2.15 Explicit conversion operators

SWIG correctly parses the keyword explicit for operators in addition to constructors now. @@ -602,7 +603,7 @@

7.2.15 Explicit conv them available as a normal proxy method.

-

7.2.16 Alias templates

+

7.2.16 Alias templates

@@ -656,7 +657,7 @@

7.2.16 Alias templates

typedef void (*PFD)(double); // The old style -

7.2.17 Unrestricted unions

+

7.2.17 Unrestricted unions

SWIG fully supports any type inside a union even if it does not @@ -682,7 +683,7 @@

7.2.17 Unrestricted unions

-

7.2.18 Variadic templates

+

7.2.18 Variadic templates

SWIG supports the variadic templates syntax (inside the <> @@ -717,7 +718,7 @@

7.2.18 Variadic templates

In the above example SIZE is of course wrapped as a constant.

-

7.2.19 New string literals

+

7.2.19 New string literals

SWIG supports wide string and Unicode string constants and raw string literals.

@@ -747,7 +748,7 @@

7.2.19 New string literals

-

7.2.20 User-defined literals

+

7.2.20 User-defined literals

@@ -814,7 +815,7 @@

7.2.20 User-defined literals OutputType var3 = 3.1416_suffix; -

7.2.21 Thread-local storage

+

7.2.21 Thread-local storage

SWIG correctly parses the thread_local keyword. For example, variables @@ -834,7 +835,7 @@

7.2.21 Thread-local storage -

7.2.22 Explicitly defaulted functions and deleted functions

+

7.2.22 Explicitly defaulted functions and deleted functions

SWIG handles explicitly defaulted functions, that is, = default added to a function declaration. Deleted definitions, which are also called deleted functions, have = delete added to the function declaration. @@ -872,12 +873,12 @@

7.2.22 Explicitly defaulted func so in this case it is entirely possible to pass an int instead of a double to f from Java, Python etc.

-

7.2.23 Type long long int

+

7.2.23 Type long long int

SWIG correctly parses and uses the new long long type already introduced in C99 some time ago.

-

7.2.24 Static assertions

+

7.2.24 Static assertions

@@ -892,7 +893,7 @@

7.2.24 Static assertions

}; -

7.2.25 Allow sizeof to work on members of classes without an explicit object

+

7.2.25 Allow sizeof to work on members of classes without an explicit object

@@ -913,7 +914,7 @@

7.2.25 Allow sizeof to work on members of c 8 -

7.2.26 Exception specifications and noexcept

+

7.2.26 Exception specifications and noexcept

@@ -929,7 +930,7 @@

7.2.26 Exception specifications and noexc int noex3(int, bool) noexcept(false); -

7.2.27 Control and query object alignment

+

7.2.27 Control and query object alignment

@@ -961,7 +962,7 @@

7.2.27 Control and query object alignmen -

7.2.28 Attributes

+

7.2.28 Attributes

@@ -974,10 +975,10 @@

7.2.28 Attributes

[[noreturn, nothrow]] void f [[noreturn]] (); -

7.3 Standard library changes

+

7.3 Standard library changes

-

7.3.1 Threading facilities

+

7.3.1 Threading facilities

SWIG does not currently wrap or use any of the new threading @@ -985,7 +986,7 @@

7.3.1 Threading facilities -

7.3.2 Tuple types

+

7.3.2 Tuple types

@@ -993,7 +994,7 @@

7.3.2 Tuple types

Variadic template support requires further work to provide substantial tuple wrappers.

-

7.3.3 Hash tables

+

7.3.3 Hash tables

@@ -1001,14 +1002,14 @@

7.3.3 Hash tables

These are not available in SWIG, but in principle should be easily implemented by adapting the current STL containers.

-

7.3.4 Regular expressions

+

7.3.4 Regular expressions

While SWIG could provide wrappers for the new C++11 regular expressions classes, there is little need as the target languages have their own regular expression facilities.

-

7.3.5 General-purpose smart pointers

+

7.3.5 General-purpose smart pointers

@@ -1017,12 +1018,12 @@

7.3.5 General-purpo There is no special smart pointer handling available for std::weak_ptr and std::unique_ptr yet.

-

7.3.6 Extensible random number facility

+

7.3.6 Extensible random number facility

This feature extends and standardizes the standard library only and does not effect the C++ language nor SWIG.

-

7.3.7 Wrapper reference

+

7.3.7 Wrapper reference

@@ -1033,7 +1034,7 @@

7.3.7 Wrapper reference

-

7.3.8 Polymorphous wrappers for function objects

+

7.3.8 Polymorphous wrappers for function objects

@@ -1064,7 +1065,7 @@

7.3.8 P b = t(1,2) # invoke C++ function object -

7.3.9 Type traits for metaprogramming

+

7.3.9 Type traits for metaprogramming

The type_traits functions to support C++ metaprogramming is useful at compile time and is aimed specifically at C++ development:

@@ -1114,7 +1115,7 @@

7.3.9 Type traits 2 -

7.3.10 Uniform method for computing return type of function objects

+

7.3.10 Uniform method for computing return type of function objects

diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index ba49fa00434..0cbc9ec2404 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -1,17 +1,19 @@ - + SWIG and C# + -

20 SWIG and C#

+

20 SWIG and C#

-
  • Multiples modules +
  • Multiple modules
  • C# Typemap examples
    • Memory management when returning references to member variables @@ -52,7 +54,7 @@

      20 SWIG and C#

      -

      20.1 Introduction

      +

      20.1 Introduction

      @@ -69,17 +71,70 @@

      20.1 Introduction

      To get the most out of this chapter an understanding of interop is required. The Microsoft Developer Network (MSDN) has a good reference guide in a section titled "Interop Marshaling". -Monodoc, available from the Mono project, has a very useful section titled Interop with native libraries. +Monodoc, available from the Mono project, has a very useful section titled Interop with native libraries.

      -

      20.1.1 SWIG 2 Compatibility

      +

      20.1.1 SWIG 2 Compatibility

      In order to minimize name collisions between names generated based on input to SWIG and names used in the generated code from the .NET framework, SWIG 3 fully qualifies the use of all .NET types. Furthermore, SWIG 3 avoids using directives in generated code. This breaks backwards compatibility with typemaps, pragmas, etc written for use with SWIG 2 that assume the presence of using System; or using System.Runtime.InteropServices; directives in the intermediate class imports, module imports, or proxy imports. SWIG 3 supports backwards compatibility though the use of the SWIG2_CSHARP macro. If SWIG2_CSHARP is defined, SWIG 3 generates using directives in the intermediate class, module class, and proxy class code similar to those generated by SWIG 2. This can be done without modifying any of the input code by passing the -DSWIG2_CSHARP commandline parameter when executing swig.

      -

      20.2 Differences to the Java module

      + +

      20.1.2 Additional command line options

      + + +

      +The following table lists the additional commandline options available for the C# module. They can also be seen by using: +

      + +
      +swig -csharp -help 
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      C# specific options
      -dllimport <dl>Override DllImport attribute name to <dl>
      -namespace <nm>Generate wrappers into C# namespace <nm>
      -noproxyGenerate the low-level functional interface instead of proxy classes
      -oldvarnamesOld intermediary method names for variable wrappers
      -outfile <file>Write all C# into a single <file> located in the output directory +
      + +

      +The -outfile option combines all the generated C# code into a single output file instead of creating multiple C# files. +The default, when this option is not provided, is to generate separate .cs files for the module class, +intermediary class and each of the generated proxy and type wrapper classes. +Note that the file extension (.cs) will not be automatically added and needs to be provided. +Due to possible compiler limits it is not advisable to use -outfile for large projects. +

      + +

      20.2 Differences to the Java module

      @@ -492,7 +547,7 @@

      20.2 Differences to the Java moduleCygwin or MinGW environment for automatic configuration of the example makefiles. Any one of the three C# compilers (Portable.NET, Mono or Microsoft) can be detected from within a Cygwin or Mingw environment if installed in your path. -

      20.3 Void pointers

      +

      20.3 Void pointers

      @@ -510,7 +565,7 @@

      20.3 Void pointers

  • -

    20.4 C# Arrays

    +

    20.4 C# Arrays

    @@ -522,7 +577,7 @@

    20.4 C# Arrays

    pinned arrays.

    -

    20.4.1 The SWIG C arrays library

    +

    20.4.1 The SWIG C arrays library

    @@ -559,7 +614,7 @@

    20.4.1 The SWIG C arrays library -

    20.4.2 Managed arrays using P/Invoke default array marshalling

    +

    20.4.2 Managed arrays using P/Invoke default array marshalling

    @@ -686,7 +741,7 @@

    20.4.2 Managed -

    20.4.3 Managed arrays using pinning

    +

    20.4.3 Managed arrays using pinning

    @@ -781,7 +836,7 @@

    20.4.3 Managed arrays using pinning

    -

    20.5 C# Exceptions

    +

    20.5 C# Exceptions

    @@ -878,7 +933,7 @@

    20.5 C# Exceptions

    -

    20.5.1 C# exception example using "check" typemap

    +

    20.5.1 C# exception example using "check" typemap

    @@ -1060,7 +1115,7 @@

    20.5.1 C# exception exa Actually it will issue this warning for any function beginning with SWIG_CSharpSetPendingException.

    -

    20.5.2 C# exception example using %exception

    +

    20.5.2 C# exception example using %exception

    @@ -1126,7 +1181,7 @@

    20.5.2 C# exception -

    20.5.3 C# exception example using exception specifications

    +

    20.5.3 C# exception example using exception specifications

    @@ -1183,7 +1238,7 @@

    20.5.3 C# ex Multiple catch handlers are generated should there be more than one exception specifications declared.

    -

    20.5.4 Custom C# ApplicationException example

    +

    20.5.4 Custom C# ApplicationException example

    @@ -1317,7 +1372,7 @@

    20.5.4 Custom C# Applicati -

    20.6 C# Directors

    +

    20.6 C# Directors

    @@ -1330,7 +1385,7 @@

    20.6 C# Directors

    However, the Java directors section should also be read in order to gain more insight into directors.

    -

    20.6.1 Directors example

    +

    20.6.1 Directors example

    @@ -1451,7 +1506,7 @@

    20.6.1 Directors example

    -

    20.6.2 Directors implementation

    +

    20.6.2 Directors implementation

    @@ -1634,7 +1689,7 @@

    20.6.2 Directors implementatio -

    20.6.3 Director caveats

    +

    20.6.3 Director caveats

    @@ -1682,11 +1737,11 @@

    20.6.3 Director caveats

    should pass the call on to CSharpDefaults.DefaultMethod(int)using the C++ default value, as shown above.

    -

    20.7 Multiples modules

    +

    20.7 Multiple modules

    -When using multiple modules it is is possible to compile each SWIG generated wrapper +When using multiple modules it is 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. @@ -1717,7 +1772,7 @@

    20.7 Multiples modules

    if you don't want users to easily stumble upon these so called 'internal workings' of the wrappers.

    -

    20.8 C# Typemap examples

    +

    20.8 C# Typemap examples

    This section includes a few examples of typemaps. For more examples, you @@ -1725,7 +1780,7 @@

    20.8 C# Typemap examples

    the SWIG library. -

    20.8.1 Memory management when returning references to member variables

    +

    20.8.1 Memory management when returning references to member variables

    @@ -1849,7 +1904,7 @@

    20.8.1 Memory manage Note the addReference call.

    -

    20.8.2 Memory management for objects passed to the C++ layer

    +

    20.8.2 Memory management for objects passed to the C++ layer

    @@ -1968,7 +2023,7 @@

    20.8.2 Memory management for -

    20.8.3 Date marshalling using the csin typemap and associated attributes

    +

    20.8.3 Date marshalling using the csin typemap and associated attributes

    @@ -2254,7 +2309,7 @@

    20.8.3 Date marshalling using the csin -

    20.8.4 A date example demonstrating marshalling of C# properties

    +

    20.8.4 A date example demonstrating marshalling of C# properties

    @@ -2354,7 +2409,7 @@

    20.8.4 A date example demonstrating mar
  • The 'csin' typemap has 'pre', 'post' and 'cshin' attributes, and these are all ignored in the property set. The code in these attributes must instead be replicated within the 'csvarin' typemap. The line creating the temp$csinput variable is such an example; it is identical to what is in the 'pre' attribute. -

    20.8.5 Date example demonstrating the 'pre' and 'post' typemap attributes for directors

    +

    20.8.5 Date example demonstrating the 'pre' and 'post' typemap attributes for directors

    @@ -2416,7 +2471,7 @@

    20.8.5 Date example demonstrati

    -

    20.8.6 Turning wrapped classes into partial classes

    +

    20.8.6 Turning wrapped classes into partial classes

    @@ -2516,7 +2571,7 @@

    20.8.6 Turning wrapped classes into par The following example is an alternative approach to adding managed code to the generated proxy class.

    -

    20.8.7 Extending proxy classes with additional C# code

    +

    20.8.7 Extending proxy classes with additional C# code

    @@ -2555,7 +2610,7 @@

    20.8.7 Extending proxy classes wi -

    20.8.8 Underlying type for enums

    +

    20.8.8 Underlying type for enums

    diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html index 82861c31c74..820d01fde14 100644 --- a/Doc/Manual/Chicken.html +++ b/Doc/Manual/Chicken.html @@ -1,14 +1,14 @@ - - + SWIG and Chicken + -

    21 SWIG and Chicken

    +

    21 SWIG and Chicken

      @@ -55,10 +55,10 @@

      21 SWIG and Chicken

        -
      1. generates portable C code
      2. -
      3. includes a customizable interpreter
      4. -
      5. links to C libraries with a simple Foreign Function Interface
      6. -
      7. supports full tail-recursion and first-class continuations
      8. +
      9. generates portable C code
      10. +
      11. includes a customizable interpreter
      12. +
      13. links to C libraries with a simple Foreign Function Interface
      14. +
      15. supports full tail-recursion and first-class continuations

      @@ -72,7 +72,7 @@

      21 SWIG and Chicken

      -

      21.1 Preliminaries

      +

      21.1 Preliminaries

      @@ -89,7 +89,7 @@

      21.1 Preliminaries

      directory for the basic steps to run SWIG CHICKEN.

      -

      21.1.1 Running SWIG in C mode

      +

      21.1.1 Running SWIG in C mode

      @@ -98,7 +98,7 @@

      21.1.1 Running SWIG in C mode

      -
      % swig -chicken example.i
      +
      % swig -chicken example.i

      @@ -122,7 +122,7 @@

      21.1.1 Running SWIG in C mode

      object files and linked into your project.

      -

      21.1.2 Running SWIG in C++ mode

      +

      21.1.2 Running SWIG in C++ mode

      @@ -131,7 +131,7 @@

      21.1.2 Running SWIG in C++ mode

      -
      % swig -chicken -c++ example.i
      +
      % swig -chicken -c++ example.i

      @@ -142,7 +142,7 @@

      21.1.2 Running SWIG in C++ mode

      -
      % chicken example.scm -output-file oexample.c
      +
      % chicken example.scm -output-file oexample.c

      @@ -151,10 +151,10 @@

      21.1.2 Running SWIG in C++ mode

      object files and linked into your project.

      -

      21.2 Code Generation

      +

      21.2 Code Generation

      -

      21.2.1 Naming Conventions

      +

      21.2.1 Naming Conventions

      @@ -170,16 +170,16 @@

      21.2.1 Naming Conventions

      %rename SWIG directive in the SWIG interface file.

      -

      21.2.2 Modules

      +

      21.2.2 Modules

      The name of the module must be declared one of two ways:

        -
      • Placing %module example in the SWIG interface - file.
      • -
      • Using -module example on the SWIG command - line.
      • +
      • Placing %module example in the SWIG interface + file.
      • +
      • Using -module example on the SWIG command + line.

      @@ -189,10 +189,10 @@

      21.2.2 Modules

      CHICKEN will be able to access the module using the (declare - (uses modulename)) CHICKEN Scheme form. + (uses modulename)) CHICKEN Scheme form.

      -

      21.2.3 Constants and Variables

      +

      21.2.3 Constants and Variables

      @@ -200,10 +200,10 @@

      21.2.3 Constants and Variables

      the interface file:

        -
      1. #define MYCONSTANT1 ...
      2. -
      3. %constant int MYCONSTANT2 = ...
      4. -
      5. const int MYCONSTANT3 = ...
      6. -
      7. enum { MYCONSTANT4 = ... };
      8. +
      9. #define MYCONSTANT1 ...
      10. +
      11. %constant int MYCONSTANT2 = ...
      12. +
      13. const int MYCONSTANT3 = ...
      14. +
      15. enum { MYCONSTANT4 = ... };

      @@ -229,7 +229,7 @@

      21.2.3 Constants and Variables

      for info on how to apply the %feature.

      -

      21.2.4 Functions

      +

      21.2.4 Functions

      @@ -248,7 +248,7 @@

      21.2.4 Functions

      parameters). The return values can then be accessed with (call-with-values).

      -

      21.2.5 Exceptions

      +

      21.2.5 Exceptions

      The SWIG chicken module has support for exceptions thrown from @@ -290,16 +290,16 @@

      21.2.5 Exceptions

    -

    21.3 TinyCLOS

    +

    21.3 TinyCLOS

    The author of TinyCLOS, Gregor Kiczales, describes TinyCLOS as: - "Tiny CLOS is a Scheme implementation of a `kernelized' CLOS, with a - metaobject protocol. The implementation is even simpler than - the simple CLOS found in `The Art of the Metaobject Protocol,' - weighing in at around 850 lines of code, including (some) - comments and documentation." + "Tiny CLOS is a Scheme implementation of a `kernelized' CLOS, with a + metaobject protocol. The implementation is even simpler than + the simple CLOS found in `The Art of the Metaobject Protocol,' + weighing in at around 850 lines of code, including (some) + comments and documentation."

    @@ -333,7 +333,7 @@

    21.3 TinyCLOS

    -

    21.4 Linkage

    +

    21.4 Linkage

    @@ -354,7 +354,7 @@

    21.4 Linkage

    -

    21.4.1 Static binary or shared library linked at compile time

    +

    21.4.1 Static binary or shared library linked at compile time

    We can easily use csc to build a static binary.

    @@ -395,7 +395,7 @@

    21.4.1 Static binary or shared library linked at be run with csi.

    -

    21.4.2 Building chicken extension libraries

    +

    21.4.2 Building chicken extension libraries

    Building a shared library like in the above section only works if the library @@ -453,7 +453,7 @@

    21.4.2 Building chicken extension libraries

    See the Examples/chicken/egg directory in the SWIG source for an example that builds two eggs, one using the first method and one using the second method.

    -

    21.4.3 Linking multiple SWIG modules with TinyCLOS

    +

    21.4.3 Linking multiple SWIG modules with TinyCLOS

    Linking together multiple modules that share type information using the %import @@ -477,7 +477,7 @@

    21.4.3 Linking multiple SWIG modules with TinyCLO To create an extension library or an egg, just create a module_load.scm file that (declare (uses ...)) all the modules.

    -

    21.5 Typemaps

    +

    21.5 Typemaps

    @@ -486,7 +486,7 @@

    21.5 Typemaps

    Lib/chicken/chicken.swg.

    -

    21.6 Pointers

    +

    21.6 Pointers

    @@ -519,7 +519,7 @@

    21.6 Pointers

    type. flags is either zero or SWIG_POINTER_DISOWN (see below).

    -

    21.6.1 Garbage collection

    +

    21.6.1 Garbage collection

    If the owner flag passed to SWIG_NewPointerObj is 1, NewPointerObj will add a @@ -550,7 +550,7 @@

    21.6.1 Garbage collection

    must be called manually.

    -

    21.7 Unsupported features and known problems

    +

    21.7 Unsupported features and known problems

    -

    21.7.1 TinyCLOS problems with Chicken version <= 1.92

    +

    21.7.1 TinyCLOS problems with Chicken version <= 1.92

    In Chicken versions equal to or below 1.92, TinyCLOS has a limitation such that generic methods do not properly work on methods diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 51d4edaa444..55d16ee1a13 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -1,10 +1,12 @@ - + SWIG Users Manual + +

    SWIG Users Manual

    @@ -142,8 +144,8 @@

    5 SWIG Basics

  • Basic Type Handling
  • Global Variables
  • Constants -
  • A brief word about const -
  • A cautionary tale of char * +
  • A brief word about const +
  • A cautionary tale of char *
  • Pointers and complex objects +
  • Special variables and typemap attributes +
  • Special variables combined with special variable macros
  • Common typemap methods
  • Typemaps and overloading -
  • More about %apply and %clear +
  • More about %apply and %clear
  • Passing data between typemaps
  • C++ "this" pointer
  • Where to go for more information? @@ -725,6 +729,7 @@

    20 SWIG and C#

  • Introduction
  • Differences to the Java module
  • Void pointers @@ -747,7 +752,7 @@

    20 SWIG and C#

  • Directors implementation
  • Director caveats -
  • Multiples modules +
  • Multiple modules
  • C# Typemap examples -
  • %features +
  • D and %feature
  • Pragmas
  • D Exceptions
  • D Directors
  • Other features
  • Further details on the generated Java classes
  • Embedded Webkit
  • Creating Applications with node-webkit -
  • Examples +
  • Examples
  • Exceptions @@ -1309,6 +1328,10 @@

    32 SWIG and Octave

  • Class extension with %extend
  • C++ templates
  • C++ Smart Pointers +
  • Directors (calling Octave from C++ code)
  • Threads
  • Memory management @@ -1414,7 +1437,7 @@

    34 SWIG and PHP

  • Pointers and References
  • Structures and C++ classes
  • Further details on the Python class interface @@ -1529,6 +1556,7 @@

    36 SWIG and Python

  • Simple pointers
  • Unbounded C Arrays
  • String handling +
  • Default arguments
  • Typemaps @@ -1629,6 +1658,10 @@

    38 SWIG and Ruby

  • C++ STL Functors
  • C++ STL Iterators
  • C++ Smart Pointers +
  • Cross-Language Polymorphism
    • Exception Unrolling @@ -1727,7 +1760,76 @@

      38 SWIG and Ruby

      -

      39 SWIG and Tcl

      +

      39 SWIG and Scilab

      + + + + + +

      40 SWIG and Tcl

      @@ -1793,7 +1895,7 @@

      39 SWIG and Tcl

      -

      40 Extending SWIG to support new languages

      +

      41 Extending SWIG to support new languages

      diff --git a/Doc/Manual/Contract.html b/Doc/Manual/Contract.html index 35bc874ef06..4b4995819a3 100644 --- a/Doc/Manual/Contract.html +++ b/Doc/Manual/Contract.html @@ -1,12 +1,13 @@ - + Contract Checking + -

      13 Contracts

      +

      13 Contracts

        @@ -38,7 +39,7 @@

        13 Contracts

        generated rather than having the program continue to execute.

        -

        13.1 The %contract directive

        +

        13.1 The %contract directive

        @@ -94,7 +95,7 @@

        13.1 The %contract directive

      -

      13.2 %contract and classes

      +

      13.2 %contract and classes

      @@ -173,7 +174,7 @@

      13.2 %contract and classes

      this means that both the arguments to Spam::bar must be positive.

      -

      13.3 Constant aggregation and %aggregate_check

      +

      13.3 Constant aggregation and %aggregate_check

      @@ -262,7 +263,7 @@

      13.3 Constant aggregation and %aggregate_check -

      13.4 Notes

      +

      13.4 Notes

      diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index 8e26a7e8a0d..8705534f9dd 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -1,12 +1,13 @@ - + Customization Features + -

      12 Customization Features

      +

      12 Customization Features

        @@ -45,7 +46,7 @@

        12 Customization Features

        customization mechanism known as "features" is described.

        -

        12.1 Exception handling with %exception

        +

        12.1 Exception handling with %exception

        @@ -100,7 +101,7 @@

        12.1 Exception handling with %exceptio provides the same functionality, but is substantially more flexible.

        -

        12.1.1 Handling exceptions in C code

        +

        12.1.1 Handling exceptions in C code

        @@ -115,16 +116,18 @@

        12.1.1 Handling exceptions in C code

        static int error_status = 0; void throw_exception(char *msg) { - strncpy(error_message,msg,256); - error_status = 1; + strncpy(error_message,msg,256); + error_status = 1; } void clear_exception() { - error_status = 0; + error_status = 0; } char *check_exception() { - if (error_status) return error_message; - else return NULL; + if (error_status) + return error_message; + else + return NULL; }
      @@ -136,13 +139,13 @@

      12.1.1 Handling exceptions in C code

       double inv(double x) {
      -	if (x != 0) return 1.0/x;
      -	else {
      -		throw_exception("Division by zero");
      -		return 0;
      -	}
      +  if (x != 0)
      +    return 1.0/x;
      +  else {
      +    throw_exception("Division by zero");
      +    return 0;
      +  }
       }
      -
       

      @@ -151,12 +154,12 @@

      12.1.1 Handling exceptions in C code

       %exception {
      -    char *err;
      -    clear_exception();
      -    $action
      -    if ((err = check_exception())) {
      -       croak(err);
      -    }
      +  char *err;
      +  clear_exception();
      +  $action
      +  if ((err = check_exception())) {
      +    croak(err);
      +  }
       }
       
      @@ -166,7 +169,7 @@

      12.1.1 Handling exceptions in C code

      and for Perl it is the croak method shown above.

      -

      12.1.2 Exception handling with longjmp()

      +

      12.1.2 Exception handling with longjmp()

      @@ -206,8 +209,10 @@

      12.1.2 Exception handling with longjmp()

       double inv(double x) {
      -	if (x) return 1.0/x;
      -	else throw(DivisionByZero);
      +  if (x)
      +    return 1.0/x;
      +  else
      +    throw(DivisionByZero);
       }
       
       
      @@ -221,17 +226,17 @@

      12.1.2 Exception handling with longjmp()

      @@ -240,7 +245,7 @@

      12.1.2 Exception handling with longjmp()

      try declarations.

      -

      12.1.3 Handling C++ exceptions

      +

      12.1.3 Handling C++ exceptions

      @@ -249,17 +254,17 @@

      12.1.3 Handling C++ exceptions

       %exception {
      -	try {
      -		$action
      -	} catch(RangeError) {
      -		croak("Range Error");
      -	} catch(DivisionByZero) {
      -		croak("Division by zero");
      -	} catch(OutOfMemory) {
      -		croak("Out of memory");
      -	} catch(...) {
      -		croak("Unknown exception");
      -	}
      +  try {
      +    $action
      +  } catch(RangeError) {
      +    croak("Range Error");
      +  } catch(DivisionByZero) {
      +    croak("Division by zero");
      +  } catch(OutOfMemory) {
      +    croak("Out of memory");
      +  } catch(...) {
      +    croak("Unknown exception");
      +  }
       }
       
       
      @@ -275,7 +280,7 @@

      12.1.3 Handling C++ exceptions

      -

      12.1.4 Exception handlers for variables

      +

      12.1.4 Exception handlers for variables

      @@ -300,7 +305,7 @@

      12.1.4 Exception handlers for variab -

      12.1.5 Defining different exception handlers

      +

      12.1.5 Defining different exception handlers

      @@ -319,7 +324,7 @@

      12.1.5 Defining different exception handlers
       %exception {
      -	... your exception handler ...
      +  ... your exception handler ...
       }
       /* Define critical operations that can throw exceptions here */
       
      @@ -437,7 +442,7 @@ 

      12.1.5 Defining different exception handlers %exception directive is much better.

      -

      12.1.6 Special variables for %exception

      +

      12.1.6 Special variables for %exception

      @@ -540,7 +545,7 @@

      12.1.6 Special varia

      -

      12.1.7 Using The SWIG exception library

      +

      12.1.7 Using The SWIG exception library

      @@ -595,7 +600,7 @@

      12.1.7 Using The SWIG exception library

      The SWIG_exception() function can also be used in typemaps.

      -

      12.2 Object ownership and %newobject

      +

      12.2 Object ownership and %newobject

      @@ -752,7 +757,7 @@

      12.2 Object ownership and %newobject -

      12.3 Features and the %feature directive

      +

      12.3 Features and the %feature directive

      @@ -834,7 +839,7 @@

      12.3 Features and the %feature directiv The syntax in the first variation will generate the { } delimiters used whereas the other variations will not.

      -

      12.3.1 Feature attributes

      +

      12.3.1 Feature attributes

      @@ -875,7 +880,7 @@

      12.3.1 Feature attributes

      Java exception handling section.

      -

      12.3.2 Feature flags

      +

      12.3.2 Feature flags

      @@ -973,7 +978,7 @@

      12.3.2 Feature flags

      The concept of clearing features is discussed next.

      -

      12.3.3 Clearing features

      +

      12.3.3 Clearing features

      @@ -1066,7 +1071,7 @@

      12.3.3 Clearing features

      -

      12.3.4 Features and default arguments

      +

      12.3.4 Features and default arguments

      @@ -1141,7 +1146,7 @@

      12.3.4 Features and defaul in SWIG-1.3.23 when the approach to wrapping methods with default arguments was changed.

      -

      12.3.5 Feature example

      +

      12.3.5 Feature example

      diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html index 47dab50f17d..9e8e6535897 100644 --- a/Doc/Manual/D.html +++ b/Doc/Manual/D.html @@ -1,4 +1,4 @@ - + SWIG and D @@ -6,7 +6,7 @@ -

      22 SWIG and D

      +

      22 SWIG and D

      -
    • %features +
    • D and %feature
    • Pragmas
    • D Exceptions
    • D Directors
    • Other features
        -
      • Extended namespace support (nspace) +
      • Extended namespace support (nspace)
      • Native pointer support
      • Operator overloading
      • Running the test-suite @@ -41,7 +41,7 @@

        22 SWIG and D

        -

        22.1 Introduction

        +

        22.1 Introduction

        From the D Programming Language web site: D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. [...] The D language is statically typed and compiles directly to machine code. As such, it is not very surprising that D is able to directly interface with C libraries. Why would a SWIG module for D be needed then in the first place?

        @@ -50,10 +50,10 @@

        22.1 Introduction

        While these issues can be worked around relatively easy by hand-coding a thin wrapper layer around the C library in question, there is another issue where writing wrapper code per hand is not feasible: C++ libraries. D did not support interfacing to C++ in version 1 at all, and even if extern(C++) has been added to D2, the support is still very limited, and a custom wrapper layer is still required in many cases.

        -

        To help addressing these issues, the SWIG C# module has been forked to support D. Is has evolved quite a lot since then, but there are still many similarities, so if you do not find what you are looking for on this page, it might be worth having a look at the chapter on C# (and also on Java, since the C# module was in turn forked from it).

        +

        To help addressing these issues, the SWIG C# module has been forked to support D. Is has evolved quite a lot since then, but there are still many similarities, so if you do not find what you are looking for on this page, it might be worth having a look at the chapter on C# (and also on Java, since the C# module was in turn forked from it).

        -

        22.2 Command line invocation

        +

        22.2 Command line invocation

        To activate the D module, pass the -d option to SWIG at the command line. The same standard command line switches as with any other language module are available, plus the following D specific ones:

        @@ -64,7 +64,7 @@

        22.2 Command line invocation

        By default, SWIG generates code for D1/Tango. Use the -d2 flag to target D2/Phobos instead.

        -
        -splitproxy
        +
        -splitproxy

        By default, SWIG generates two D modules: the proxy module, named like the source module (either specified via the %module directive or via the module command line switch), which contains all the proxy classes, functions, enums, etc., and the intermediary module (named like the proxy module, but suffixed with _im), which contains all the extern(C) function declarations and other private parts only used internally by the proxy module.

        If the split proxy mode is enabled by passing this switch at the command line, all proxy classes and enums are emitted to their own D module instead. The main proxy module only contains free functions and constants in this case.

        @@ -83,10 +83,10 @@

        22.2 Command line invocation

        -

        22.3 Typemaps

        +

        22.3 Typemaps

        -

        22.3.1 C# <-> D name comparison

        +

        22.3.1 C# <-> D name comparison

        If you already know the SWIG C# module, you might find the following name comparison table useful:

        @@ -112,7 +112,7 @@

        22.3.1 C# <-> D name compariso -

        22.3.2 ctype, imtype, dtype

        +

        22.3.2 ctype, imtype, dtype

        Mapping of types between the C/C++ library, the C/C++ library wrapper exposing the C functions, the D wrapper module importing these functions and the D proxy code.

        @@ -120,26 +120,26 @@

        22.3.2 ctype, imtype, dtype

        The ctype typemap is used to determine the types to use in the C wrapper functions. The types from the imtype typemap are used in the extern(C) declarations of these functions in the intermediary D module. The dtype typemap contains the D types used in the D proxy module/class.

        -

        22.3.3 in, out, directorin, directorout

        +

        22.3.3 in, out, directorin, directorout

        Used for converting between the types for C/C++ and D when generating the code for the wrapper functions (on the C++ side).

        -

        The code from the in typemap is used to convert arguments to the C wrapper function to the type used in the wrapped code (ctype->original C++ type), the out typemap is utilized to convert values from the wrapped code to wrapper function return types (original C++ type->ctype).

        +

        The code from the in typemap is used to convert arguments to the C wrapper function to the type used in the wrapped code (ctype->original C++ type), the out typemap is utilized to convert values from the wrapped code to wrapper function return types (original C++ type->ctype).

        The directorin typemap is used to convert parameters to the type used in the D director callback function, its return value is processed by directorout (see below).

        -

        22.3.4 din, dout, ddirectorin, ddirectorout

        +

        22.3.4 din, dout, ddirectorin, ddirectorout

        Typemaps for code generation in D proxy and type wrapper classes.

        -

        The din typemap is used for converting function parameter types from the type used in the proxy module or class to the type used in the intermediary D module (the $dinput macro is replaced). To inject further parameter processing code before or after the call to the intermediary layer, the pre, post and terminator attributes can be used (please refer to the C# date marshalling example for more information on these).

        +

        The din typemap is used for converting function parameter types from the type used in the proxy module or class to the type used in the intermediary D module (the $dinput macro is replaced). To inject further parameter processing code before or after the call to the intermediary layer, the pre, post and terminator attributes can be used (please refer to the C# date marshalling example for more information on these).

        -

        The dout typemap is used for converting function return values from the return type used in the intermediary D module to the type returned by the proxy function. The $excode special variable in dout typemaps is replaced by the excode typemap attribute code if the method can throw any exceptions from unmanaged code, otherwise by nothing (the $imcall and $owner macros are replaced).

        +

        The dout typemap is used for converting function return values from the return type used in the intermediary D module to the type returned by the proxy function. The $excode special variable in dout typemaps is replaced by the excode typemap attribute code if the method can throw any exceptions from unmanaged code, otherwise by nothing (the $imcall and $owner macros are replaced).

        -

        The code from the ddirectorin and ddirectorout typemaps is used for conversion in director callback functions. Arguments are converted to the type used in the proxy class method they are calling by using the code from ddirectorin, the proxy class method return value is converted to the type the C++ code expects via the ddirectorout typemap (the $dcall and $winput macros are replaced).

        +

        The code from the ddirectorin and ddirectorout typemaps is used for conversion in director callback functions. Arguments are converted to the type used in the proxy class method they are calling by using the code from ddirectorin, the proxy class method return value is converted to the type the C++ code expects via the ddirectorout typemap (the $dcall and $winput macros are replaced).

        The full chain of type conversions when a director callback is invoked looks like this:

        @@ -157,13 +157,13 @@

        22.3.4 din, dout, ddirecto dtype DClass.method(dtype a) -

        22.3.5 typecheck typemaps

        +

        22.3.5 typecheck typemaps

        Because, unlike many scripting languages supported by SWIG, D does not need any dynamic dispatch helper to access an overloaded function, the purpose of these is merely to issue a warning for overloaded C++ functions that cannot be overloaded in D (as more than one C++ type maps to a single D type).

        -

        22.3.6 Code injection typemaps

        +

        22.3.6 Code injection typemaps

        These typemaps are used for generating the skeleton of proxy classes for C++ types.

        @@ -172,10 +172,10 @@

        22.3.6 Code injection typemaps

        Using dcode and dimports, you can specify additional D code which will be emitted into the class body respectively the imports section of the D module the class is written to.

        -

        dconstructor, ddestructor, ddispose and ddispose_derived are used to generate the class constructor, destructor and dispose() method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in dbody and dbody_derived. You can override them for specific types.

        +

        dconstructor, ddestructor, ddispose and ddispose_derived are used to generate the class constructor, destructor and dispose() method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in dbody and dbody_derived. You can override them for specific types.

        -

        22.3.7 Special variable macros

        +

        22.3.7 Special variable macros

        The standard SWIG special variables are available for use within typemaps as described in the Typemaps documentation, for example $1, $input, $result etc.

        @@ -197,7 +197,7 @@

        22.3.7 Special variable macros

        $null

        In code inserted into the generated C/C++ wrapper functions, this variable is replaced by either 0 or nothing at all, depending on whether the function has a return value or not. It can be used to bail out early e.g. in case of errors (return $null;).

        -
        $dinput (C#: $csinput)
        +
        $dinput (C#: $csinput)

        This variable is used in din typemaps and is replaced by the expression which is to be passed to C/C++.

        For example, this input

        @@ -214,7 +214,7 @@

        22.3.7 Special variable macros

        example_im.foo(SomeClass.getCPointer(arg)); }
        -
        $imcall and $owner (C#: $imcall)
        +
        $imcall and $owner (C#: $imcall)

        These variables are used in dout typemaps. $imcall contains the call to the intermediary module which provides the value to be used, and $owner signals if the caller is responsible for managing the object lifetime (that is, if the called method is a constructor or has been marked via %newobject).

        Consider the following example:

        @@ -243,7 +243,7 @@

        22.3.7 Special variable macros

        $dcall and $winput (C#: $cscall, $iminput)
        -

        These variables are used in the director-specific typemaps ddirectorin and ddirectorout. They are more or less the reverse of the $imcall and $dinput macros: $dcall contains the invocation of the D proxy method of which the return value is to be passed back to C++, $winput contains the parameter value from C++.

        +

        These variables are used in the director-specific typemaps ddirectorin and ddirectorout. They are more or less the reverse of the $imcall and $dinput macros: $dcall contains the invocation of the D proxy method of which the return value is to be passed back to C++, $winput contains the parameter value from C++.

        $excode

        This variable is used in dout and dconstructor typemaps and is filled with the contents of the excode typemap attribute if an exception could be thrown from the C++ side. See the C# documentation for details.

        @@ -263,7 +263,7 @@

        22.3.7 Special variable macros

        -
        $importtype(SomeDType)
        +
        $importtype(SomeDType)

        This macro is used in the dimports typemap if a dependency on another D type generated by SWIG is added by a custom typemap.

        Consider the following code snippet:

        @@ -295,7 +295,7 @@

        22.3.7 Special variable macros

        -

        22.4 %features

        +

        22.4 D and %feature

        The D module defines a number of directives which modify the SWIG features set globally or for a specific declaration:

        @@ -325,7 +325,7 @@

        22.4 %features

        -

        22.5 Pragmas

        +

        22.5 Pragmas

        There are a few SWIG pragmas specific to the D module, which you can use to influence the D code SWIG generates:

        @@ -364,7 +364,7 @@

        22.5 Pragmas

        -

        22.6 D Exceptions

        +

        22.6 D Exceptions

        Out of the box, C++ exceptions are fundamentally incompatible to their equivalent in the D world and cannot simply be propagated to a calling D method. There is, however, an easy way to solve this problem: Just catch the exception in the C/C++ wrapper layer, pass the contents to D, and make the wrapper code rethrow the exception in the D world.

        @@ -374,7 +374,7 @@

        22.6 D Exceptions

        As this feature is implemented in exactly the same way it is for C#, please see the C# documentation for a more detailed explanation.

        -

        22.7 D Directors

        +

        22.7 D Directors

        When the directors feature is activated, SWIG generates extra code on both the C++ and the D side to enable cross-language polymorphism. Essentially, this means that if you subclass a proxy class in D, C++ code can access any overridden virtual methods just as if you created a derived class in C++.

        @@ -383,16 +383,16 @@

        22.7 D Directors

        -

        22.8 Other features

        +

        22.8 Other features

        -

        22.8.1 Extended namespace support (nspace)

        +

        22.8.1 Extended namespace support (nspace)

        By default, SWIG flattens all C++ namespaces into a single target language namespace, but as for Java and C#, the nspace feature is supported for D. If it is active, C++ namespaces are mapped to D packages/modules. Note, however, that like for the other languages, free variables and functions are not supported yet; currently, they are all allows written to the main proxy D module.

        -

        22.8.2 Native pointer support

        +

        22.8.2 Native pointer support

        Contrary to many of the scripting languages supported by SWIG, D fully supports C-style pointers. The D module thus includes a custom mechanism to wrap C pointers directly as D pointers where applicable, that is, if the type that is pointed to is represented the same in C and D (on the bit-level), dubbed a primitive type below.

        @@ -404,7 +404,7 @@

        22.8.2 Native pointer support

        To determine if a type should be considered primitive, the cprimitive attribute on its dtype attribute is used. For example, the dtype typemap for float has cprimitive="1", so the code from the nativepointer attribute is taken into account e.g. for float ** or the function pointer float (*)(float *).

        -

        22.8.3 Operator overloading

        +

        22.8.3 Operator overloading

        The D module comes with basic operator overloading support for both D1 and D2. There are, however, a few limitations arising from conceptual differences between C++ and D:

        @@ -416,7 +416,7 @@

        22.8.3 Operator overloading

        There are also some cases where the operators can be translated to D, but the differences in the implementation details are big enough that a rather involved scheme would be required for automatic wrapping them, which has not been implemented yet. This affects, for example, the array subscript operator, [], in combination with assignments - while operator [] in C++ simply returns a reference which is then written to, D resorts to a separate opIndexAssign method -, or implicit casting (which was introduced in D2 via alias this). Despite the lack of automatic support, manually handling these cases should be perfectly possible.

        -

        22.8.4 Running the test-suite

        +

        22.8.4 Running the test-suite

        As with any other language, the SWIG test-suite can be built for D using the *-d-test-suite targets of the top-level Makefile. By default, D1 is targeted, to build it with D2, use the optional D_VERSION variable, e.g. make check-d-test-suite D_VERSION=2.

        @@ -424,14 +424,14 @@

        22.8.4 Running the test-suite

        Note: If you want to use GDC on Linux or another platform which requires you to link libdl for dynamically loading the shared library, you might have to add -ldl manually to the d_compile target in Examples/Makefile, because GDC does not currently honor the pragma(lib,...) statement.

        -

        22.9 D Typemap examples

        +

        22.9 D Typemap examples

        There are no D-specific typemap examples yet. However, with the above name comparison table, you should be able to get an idea what can be done by looking at the corresponding C# section.

        -

        22.10 Work in progress and planned features

        +

        22.10 Work in progress and planned features

        There are a couple of features which are not implemented yet, but would be very useful and might be added in the near future:

        diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 00302d7b5c8..14dcbdccdf6 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -1,12 +1,13 @@ - + Extending SWIG to support new languages + -

        40 Extending SWIG to support new languages

        +

        41 Extending SWIG to support new languages

          @@ -75,7 +76,7 @@

          40 Extending SWIG to support new languages

          -

          40.1 Introduction

          +

          41.1 Introduction

          @@ -91,7 +92,7 @@

          40.1 Introduction

          you should probably look at one of SWIG's existing modules.

          -

          40.2 Prerequisites

          +

          41.2 Prerequisites

          @@ -121,7 +122,7 @@

          40.2 Prerequisites

          wrapper code are driven by C++ datatypes.

          -

          40.3 The Big Picture

          +

          41.3 The Big Picture

          @@ -158,7 +159,7 @@

          40.3 The Big Picture

          based on pattern matching and interact heavily with the underlying type system.

          -

          40.4 Execution Model

          +

          41.4 Execution Model

          @@ -203,7 +204,7 @@

          40.4 Execution Model

          The next few sections briefly describe some of these stages.

          -

          40.4.1 Preprocessing

          +

          41.4.1 Preprocessing

          @@ -284,7 +285,7 @@

          40.4.1 Preprocessing

          construction of the wrapper code.

          -

          40.4.2 Parsing

          +

          41.4.2 Parsing

          @@ -385,7 +386,7 @@

          40.4.2 Parsing

          arguments).

          -

          40.4.3 Parse Trees

          +

          41.4.3 Parse Trees

          @@ -640,7 +641,7 @@

          40.4.3 Parse Trees

        -

        40.4.4 Attribute namespaces

        +

        41.4.4 Attribute namespaces

        @@ -659,7 +660,7 @@

        40.4.4 Attribute namespaces

        perl:foo.

        -

        40.4.5 Symbol Tables

        +

        41.4.5 Symbol Tables

        @@ -750,7 +751,7 @@

        40.4.5 Symbol Tables

        -

        40.4.6 The %feature directive

        +

        41.4.6 The %feature directive

        @@ -806,7 +807,7 @@

        40.4.6 The %feature directive

        stored without any modifications.

        -

        40.4.7 Code Generation

        +

        41.4.7 Code Generation

        @@ -928,7 +929,7 @@

        40.4.7 Code Generation

        The role of these functions is described shortly.

        -

        40.4.8 SWIG and XML

        +

        41.4.8 SWIG and XML

        @@ -941,7 +942,7 @@

        40.4.8 SWIG and XML

        your mind as a model.

        -

        40.5 Primitive Data Structures

        +

        41.5 Primitive Data Structures

        @@ -987,7 +988,7 @@

        40.5 Primitive Data Structures

        -

        40.5.1 Strings

        +

        41.5.1 Strings

        @@ -1128,7 +1129,7 @@

        40.5.1 Strings

        -

        40.5.2 Hashes

        +

        41.5.2 Hashes

        @@ -1205,7 +1206,7 @@

        40.5.2 Hashes

        -

        40.5.3 Lists

        +

        41.5.3 Lists

        @@ -1294,7 +1295,7 @@

        40.5.3 Lists

        and is used to create a String object. -

        40.5.4 Common operations

        +

        41.5.4 Common operations

        The following operations are applicable to all datatypes. @@ -1349,7 +1350,7 @@

        40.5.4 Common operations

        Gets the line number associated with x. -

        40.5.5 Iterating over Lists and Hashes

        +

        41.5.5 Iterating over Lists and Hashes

        To iterate over the elements of a list or a hash table, the following functions are used: @@ -1394,7 +1395,7 @@

        40.5.5 Iterating over Lists and Hashes

        -

        40.5.6 I/O

        +

        41.5.6 I/O

        Special I/O functions are used for all internal I/O. These operations @@ -1528,7 +1529,7 @@

        40.5.6 I/O

        Similarly, the preprocessor and parser all operate on string-files.

        -

        40.6 Navigating and manipulating parse trees

        +

        41.6 Navigating and manipulating parse trees

        Parse trees are built as collections of hash tables. Each node is a hash table in which @@ -1662,7 +1663,7 @@

        40.6 Navigating and manipulating parse trees -

        40.7 Working with attributes

        +

        41.7 Working with attributes

        @@ -1779,7 +1780,7 @@

        40.7 Working with attributes

        function. -

        40.8 Type system

        +

        41.8 Type system

        @@ -1788,7 +1789,7 @@

        40.8 Type system

        type theory is impossible here. However, let's cover the highlights.

        -

        40.8.1 String encoding of types

        +

        41.8.1 String encoding of types

        @@ -1889,7 +1890,7 @@

        40.8.1 String encoding of types

        string concatenation.

        -

        40.8.2 Type construction

        +

        41.8.2 Type construction

        @@ -2058,7 +2059,7 @@

        40.8.2 Type construction

        ty is unmodified. -

        40.8.3 Type tests

        +

        41.8.3 Type tests

        @@ -2145,7 +2146,7 @@

        40.8.3 Type tests

        Checks if ty is a templatized type. -

        40.8.4 Typedef and inheritance

        +

        41.8.4 Typedef and inheritance

        @@ -2247,7 +2248,7 @@

        40.8.4 Typedef and inheritance

        will consist only of primitive typenames. -

        40.8.5 Lvalues

        +

        41.8.5 Lvalues

        @@ -2284,7 +2285,7 @@

        40.8.5 Lvalues

        -

        40.8.6 Output functions

        +

        41.8.6 Output functions

        @@ -2346,7 +2347,7 @@

        40.8.6 Output functions

        that appear in wrappers (e.g., SWIGTYPE_p_double). -

        40.9 Parameters

        +

        41.9 Parameters

        @@ -2445,7 +2446,7 @@

        40.9 Parameters

        Returns the number of required (non-optional) arguments in p. -

        40.10 Writing a Language Module

        +

        41.10 Writing a Language Module

        @@ -2460,7 +2461,7 @@

        40.10 Writing a Language Module

        this to other languages.

        -

        40.10.1 Execution model

        +

        41.10.1 Execution model

        @@ -2470,7 +2471,7 @@

        40.10.1 Execution model

        different methods of the Language that must be defined by your module.

        -

        40.10.2 Starting out

        +

        41.10.2 Starting out

        @@ -2578,7 +2579,7 @@

        40.10.2 Starting out

        messages from your new module should appear.

        -

        40.10.3 Command line options

        +

        41.10.3 Command line options

        @@ -2637,7 +2638,7 @@

        40.10.3 Command line options

        unrecognized command line option error.

        -

        40.10.4 Configuration and preprocessing

        +

        41.10.4 Configuration and preprocessing

        @@ -2686,7 +2687,7 @@

        40.10.4 Configuration and preprocessing

        python.swg.

        -

        40.10.5 Entry point to code generation

        +

        41.10.5 Entry point to code generation

        @@ -2744,7 +2745,7 @@

        40.10.5 Entry point to code generation

        -

        40.10.6 Module I/O and wrapper skeleton

        +

        41.10.6 Module I/O and wrapper skeleton

        @@ -2892,7 +2893,7 @@

        40.10.6 Module I/O and wrapper skeleton

        -

        40.10.7 Low-level code generators

        +

        41.10.7 Low-level code generators

        @@ -3046,7 +3047,7 @@

        40.10.7 Low-level code generators

        -

        40.10.8 Configuration files

        +

        41.10.8 Configuration files

        @@ -3190,7 +3191,7 @@

        40.10.8 Configuration files

        -

        40.10.9 Runtime support

        +

        41.10.9 Runtime support

        @@ -3199,7 +3200,7 @@

        40.10.9 Runtime support

        the SWIG files that implement those functions.

        -

        40.10.10 Standard library files

        +

        41.10.10 Standard library files

        @@ -3218,7 +3219,7 @@

        40.10.10 Standard library files

        Please copy these and modify for any new language.

        -

        40.10.11 User examples

        +

        41.10.11 User examples

        @@ -3247,7 +3248,7 @@

        40.10.11 User examples

        files.

        -

        40.10.12 Test driven development and the test-suite

        +

        41.10.12 Test driven development and the test-suite

        @@ -3306,7 +3307,7 @@

        40.10.12 Test driven development and the but error/exception out with an error message on stderr on failure.

        -

        40.10.12.1 Running the test-suite

        +

        41.10.12.1 Running the test-suite

        @@ -3498,7 +3499,7 @@

        40.10.12.1 Running the test-suite The test cases used and the way it works is described in Examples/test-suite/errors/Makefile.in.

        -

        40.10.13 Documentation

        +

        41.10.13 Documentation

        @@ -3530,7 +3531,7 @@

        40.10.13 Documentation

        if available.
      -

      40.10.14 Prerequisites for adding a new language module to the SWIG distribution

      +

      41.10.14 Prerequisites for adding a new language module to the SWIG distribution

      @@ -3587,7 +3588,7 @@

      40.10.14 Prerequisites for adding a ne the existing tests.

      -

      40.10.15 Coding style guidelines

      +

      41.10.15 Coding style guidelines

      @@ -3611,7 +3612,7 @@

      40.10.15 Coding style guidel should be avoided as unlike the SWIG developers, users will never have consistent tab settings.

      -

      40.11 Debugging Options

      +

      41.11 Debugging Options

      @@ -3638,7 +3639,7 @@

      40.11 Debugging Options

      The complete list of command line options for SWIG are available by running swig -help.

      -

      40.12 Guide to parse tree nodes

      +

      41.12 Guide to parse tree nodes

      @@ -4046,7 +4047,7 @@

      40.12 Guide to parse tree nodes

      -

      40.13 Further Development Information

      +

      41.13 Further Development Information

      diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 9a6de95982f..ced046c6661 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -1,11 +1,12 @@ - + SWIG and Go + -

      23 SWIG and Go

      +

      23 SWIG and Go

        @@ -13,8 +14,8 @@

        23 SWIG and Go

      • Examples
      • Running SWIG with Go
      • A tour of basic C/C++ wrapping
          @@ -29,6 +30,16 @@

          23 SWIG and Go

      • Go Templates
      • Go Director Classes +
      • Default Go primitive type mappings
      • Output arguments
      • Adding additional go code @@ -46,55 +57,131 @@

        23 SWIG and Go

        see golang.org.

        -

        23.1 Overview

        +

        23.1 Overview

        -Go is a compiled language, not a scripting language. However, it does -not support direct calling of functions written in C/C++. The cgo -program may be used to generate wrappers to call C code from Go, but -there is no convenient way to call C++ code. SWIG fills this gap. +Go does not support direct calling of functions written in C/C++. The +cgo program may be used to generate +wrappers to call C code from Go, but there is no convenient way to call C++ +code. SWIG fills this gap.

        -There are (at least) two different Go compilers. One is the gc -compiler, normally invoked via the go tool. The other -is the gccgo compiler, which is a frontend to the gcc compiler suite. -The interface to C/C++ code is completely different for the two Go -compilers. SWIG supports both, selected by a command line option. +There are (at least) two different Go compilers. The first is the gc compiler +of the Go distribution, normally +invoked via the go tool. +The second Go compiler is the +gccgo compiler, which is a frontend to the GCC compiler suite. +The interface to C/C++ code is completely different for the two Go compilers. +SWIG supports both Go compilers, selected by the -gccgo command line +option.

        -Because Go is a type-safe compiled language, SWIG's runtime type -checking and runtime library are not used with Go. This should be -borne in mind when reading the rest of the SWIG documentation. +Go is a type-safe compiled language and the wrapper code generated by SWIG is +type-safe as well. In case of type issues the build will fail and hence SWIG's +runtime library and +runtime type checking +are not used.

        -

        23.2 Examples

        +

        23.2 Examples

        -Working examples can be found here: +Working examples can be found in the +SWIG source tree +.

        - +

        -The examples in the 2nd link are shipped with the SWIG distribution under the Examples/go directory. +Please note that the examples in the SWIG source tree use makefiles with the .i +SWIG interface file extension for backwards compatibility with Go 1.

        -

        23.3 Running SWIG with Go

        +

        23.3 Running SWIG with Go

        + +

        +Most Go programs are built using the go +tool. Since Go 1.1 the go tool has support for SWIG. To use it, give your +SWIG interface file the extension .swig (for C code) or .swigcxx (for C++ code). +Put that file in a GOPATH/src directory as usual for Go sources. Put other +C/C++ code in the same directory with extensions of .c and .cxx. The +go build and go install commands will automatically run SWIG +for you and compile the generated wrapper code. To check the SWIG command line +options the go tool uses run go build -x. To access the automatically +generated files run go build -work. You'll find the files under the +temporary WORK directory. +

        -To generate Go code, use the -go option with SWIG. By -default SWIG will generate code for the gc compilers. To generate -code for gccgo, you should also use the -gccgo option. +To manually generate and compile C/C++ wrapper code for Go, use the -go +option with SWIG. By default SWIG will generate code for the Go compiler of the +Go distribution. To generate code for gccgo, you should also use the +-gccgo option.

        -

        23.3.1 Additional Commandline Options

        +

        +When using the -cgo option, SWIG will generate files that can be used +directly by go build. Starting with the Go 1.5 distribution the +-cgo option has to be given. Put your SWIG interface file in a +directory under GOPATH/src, and give it a name that does not end in the +.swig or .swigcxx extension. Typically the SWIG interface file extension is .i +in this case. +

        + +
        +% swig -go -cgo example.i
        +% go install
        +
        + +

        +You will now have a Go package that you can import from other Go packages as +usual. +

        + +

        +To use SWIG without the -cgo option, more steps are required. Recall +that this only works with Go versions before 1.5. When using Go version 1.2 or +later, or when using gccgo, the code generated by SWIG can be linked directly +into the Go program. A typical command sequence when using the Go compiler of +the Go distribution would look like this: +

        + +
        +% swig -go example.i
        +% gcc -c code.c    # The C library being wrapped.
        +% gcc -c example_wrap.c
        +% go tool 6g example.go
        +% go tool 6c example_gc.c
        +% go tool pack grc example.a example.6 example_gc.6 code.o example_wrap.o
        +% go tool 6g main.go
        +% go tool 6l main.6
        +
        + +

        +You can also put the wrapped code into a shared library, and when using the Go +versions before 1.2 this is the only supported option. A typical command +sequence for this approach would look like this: +

        + +
        +% swig -go -use-shlib example.i
        +% gcc -c -fpic example.c
        +% gcc -c -fpic example_wrap.c
        +% gcc -shared example.o example_wrap.o -o example.so
        +% go tool 6g example.go
        +% go tool 6c example_gc.c
        +% go tool pack grc example.a example.6 example_gc.6
        +% go tool 6g main.go  # your code, not generated by SWIG
        +% go tool 6l main.6
        +
        + + +

        23.3.1 Go-specific Commandline Options

        @@ -106,9 +193,17 @@

        23.3.1 Additional Commandline Options

        swig -go -help
      - +
      + + + + - + + @@ -126,7 +221,7 @@

      23.3.1 Additional Commandline Options

      + the Go compiler of the Go distribution. @@ -138,8 +233,8 @@

      23.3.1 Additional Commandline Options

      + meaningful for the Go compiler of the Go distribution, which needs to know at + compile time whether a shared library will be used. @@ -147,9 +242,9 @@

      23.3.1 Additional Commandline Options

      + the Go compiler of the Go distribution; when using gccgo, the equivalent name + will be taken from the -soname option passed to the linker. + Using this option implies the -use-shlib option. @@ -168,11 +263,17 @@

      23.3.1 Additional Commandline Options

      Go-specific options
      Go specific options-cgoGenerate files to be used as input for the Go cgo tool. This + option is required for Go 1.5 and later, and works for Go 1.2 and + later. In the future this option will likely become the + default.
      -gccgo Generate code for gccgo. The default is to generate code for - the gc compiler.
      -use-shlib Tell SWIG to emit code that uses a shared library. This is only - meaningful for the gc compiler, which needs to know at compile time - whether a shared library will be used.
      Set the runtime name of the shared library that the dynamic linker should include at runtime. The default is the package name with ".so" appended. This is only used when generating code for - the gc compiler; when using gccgo, the equivalent name will be taken from - the -soname option passed to the linker. Using this - option implies the -use-shlib option.
      -

      23.3.2 Go Output Files

      +

      23.3.2 Generated Wrapper Files

      + + +

      There are two different approaches to generating wrapper files, + controlled by SWIG's -cgo option. The -cgo option + works with Go version 1.2 or later. It is required when using Go + version 1.5 or later.

      -

      When generating Go code, SWIG will generate the following - files:

      +

      With or without the -cgo option, SWIG will generate the + following files when generating wrapper code:

      • @@ -180,71 +281,34 @@

        23.3.2 Go Output Files

        These functions will be wrappers for the C++ functions defined by your module. This file should, of course, be compiled with the Go compiler. +
      • MODULE_wrap.c or MODULE_wrap.cxx will contain C/C++ functions will be invoked by the Go wrapper code. This file should be compiled with the -usual C or C++ compiler and linked into a shared library. +usual C or C++ compiler. +
      • MODULE_wrap.h will be generated if you use the directors feature. It provides a definition of the generated C++ director classes. It is generally not necessary to use this file, but in some special cases it may be helpful to include it in your code, compiled with the usual C or C++ compiler. -
      • -If using the gc compiler, MODULE_gc.c will contain C code which should -be compiled with the C compiler distributed as part of the gc -compiler. It should then be combined with the compiled MODULE.go -using gopack. This file will not be generated when using gccgo. +
      -

      -Most Go programs are built using the go tool. The go tool has limited -support for SWIG. To use it, put your SWIG interface into a file with -the extension .swig, or, if you are wrapping C++ code, .swigcxx. Put -that file in a GOPATH/src directory as usual for Go sources. Put -other interface code in the same directory with extensions of .c and -.cxx. The go build command and go install commands will automatically -run SWIG for you and will build the interface code. -

      - -

      -You can also use SWIG directly yourself. When using the gc compiler -version 1.2 or later, or when using gccgo, the code generated by SWIG -can be linked directly into the Go program. A typical command -sequence when using the gc compiler would look like this: -

      - -
      -% swig -go example.i
      -% gcc -c code.c	   # The C library being wrapped.
      -% gcc -c example_wrap.c
      -% go tool 6g example.go
      -% go tool 6c example_gc.c
      -% go tool pack grc example.a example.6 example_gc.6 code.o example_wrap.o
      -% go tool 6g main.go
      -% go tool 6l main.6
      -
      +

      When neither the -cgo nor the -gccgo option is + used, SWIG will also generate an additional file:

      -

      -You can also put the wrapped code into a shared library, and when -using the gc compiler before version 1.2 this is the only supported -option. A typical command sequence for this approach would look like -this: -

      +
        +
      • +MODULE_gc.c will contain C code which should be compiled with the C +compiler distributed as part of the gc compiler. It should then be +combined with the compiled MODULE.go using go tool pack. +
      • +
      -
      -% swig -go -use-shlib example.i
      -% gcc -c -fpic example.c
      -% gcc -c -fpic example_wrap.c
      -% gcc -shared example.o example_wrap.o -o example.so
      -% go tool 6g example.go
      -% go tool 6c example_gc.c
      -% go tool pack grc example.a example.6 example_gc.6
      -% go tool 6g main.go  # your code, not generated by SWIG
      -% go tool 6l main.6
      -
      -

      23.4 A tour of basic C/C++ wrapping

      +

      23.4 A tour of basic C/C++ wrapping

      @@ -254,7 +318,7 @@

      23.4 A tour of basic C/C++ wrapping

      essential aspects of this wrapping.

      -

      23.4.1 Go Package Name

      +

      23.4.1 Go Package Name

      @@ -264,7 +328,7 @@

      23.4.1 Go Package Name

      command line option.

      -

      23.4.2 Go Names

      +

      23.4.2 Go Names

      @@ -296,7 +360,7 @@

      23.4.2 Go Names

      named Delete followed by that name.

      -

      23.4.3 Go Constants

      +

      23.4.3 Go Constants

      @@ -304,7 +368,7 @@

      23.4.3 Go Constants

      directive become Go constants, declared with a const declaration. -

      23.4.4 Go Enumerations

      +

      23.4.4 Go Enumerations

      @@ -314,7 +378,7 @@

      23.4.4 Go Enumerations

      code should avoid modifying those variables.

      -

      23.4.5 Go Classes

      +

      23.4.5 Go Classes

      @@ -392,43 +456,129 @@

      23.4.5 Go Classes

      for this by calling the Swigcptr() method.

      -

      23.4.5.1 Go Class Memory Management

      +

      23.4.5.1 Go Class Memory Management

      -Calling NewClassName for some C++ class ClassName -will allocate memory using the C++ memory allocator. This memory will -not be automatically freed by Go's garbage collector as the object ownership is -not tracked. When you are done with the C++ object you must free it manually -using DeleteClassName. +Calling NewClassName for a C++ class ClassName will allocate +memory using the C++ memory allocator. This memory will not be automatically +freed by Go's garbage collector as the object ownership is not tracked. When +you are done with the C++ object you must free it using +DeleteClassName.
      +
      +The most Go idiomatic way to manage the memory for some C++ class is to call +NewClassName followed by a +defer of +the DeleteClassName call. Using defer ensures that the memory +of the C++ object is freed as soon as the function containing the defer +statement returns. Furthemore defer works great for short-lived +objects and fits nicely C++'s RAII idiom. Example:

      +
      +
      +func UseClassName(...) ... {
      +  o := NewClassName(...)
      +  defer DeleteClassName(o)
      +  // Use the ClassName object
      +  return ...
      +}
      +
      +

      -A common technique is to store the C++ object into a Go object, and -use the Go function runtime.SetFinalizer to free the C++ object when -the Go object is freed. It is strongly recommended to read the -runtime.SetFinalizer -documentation before using this technique to understand its limitations. -For example, if the SWIG package is imported as "wrap": +With increasing complexity, especially complex C++ object hierarchies, the +correct placement of defer statements becomes harder and harder as C++ +objects need to be freed in the correct order. This problem can be eased by +keeping a C++ object function local so that it is only available to the function +that creates a C++ object and functions called by this function. Example:

      +func WithClassName(constructor args, f func(ClassName, ...interface{}) error, data ...interface{}) error {
      +  o := NewClassName(constructor args)
      +  defer DeleteClassName(o)
      +  return f(o, data...)
      +}
      +
      +func UseClassName(o ClassName, data ...interface{}) (err error) {
      +  // Use the ClassName object and additional data and return error.
      +}
      +
      +func main() {
      +  WithClassName(constructor args, UseClassName, additional data)
      +}
      +
      +
      + +

      +Using defer has limitations though, especially when it comes to +long-lived C++ objects whichs lifetimes are hard to predict. For such C++ +objects a common technique is to store the C++ object into a Go object, and to +use the Go function runtime.SetFinalizer to add a finalizer which frees +the C++ object when the Go object is freed. It is strongly recommended to read +the runtime.SetFinalizer + documentation before using this technique to understand the +runtime.SetFinalizer limitations.
      +

      +

      +Common pitfalls with runtime.SetFinalizer are: +

      +
        +
      • +If a hierarchy of C++ objects will be automatically freed by Go finalizers then +the Go objects that store the C++ objects need to replicate the hierarchy of the +C++ objects to prevent that C++ objects are freed prematurely while other C++ +objects still rely on them. +
      • +
      • +The usage of Go finalizers is problematic with C++'s RAII idiom as it isn't +predictable when the finalizer will run and this might require a Close or Delete +method to be added the Go object that stores a C++ object to mitigate. +
      • +
      • +The Go finalizer function typically runs in a different OS thread which can be +problematic with C++ code that uses thread-local storage. +
      • +
      + +

      +runtime.SetFinalizer Example: +

      +
      +
      +import (
      +  "runtime"
      +  "wrap" // SWIG generated wrapper code
      +)
      +
       type GoClassName struct {
      -	w wrap.ClassName
      +  wcn wrap.ClassName
       }
       
       func NewGoClassName() *GoClassName {
      -	r := &GoClassName{wrap.NewClassName()}
      -	runtime.SetFinalizer(r,
      -		func(r *GoClassName) {
      -			wrap.DeleteClassName(r.w)
      -		})
      -	return r
      +  o := &GoClassName{wcn: wrap.NewClassName()}
      +  runtime.SetFinalizer(o, deleteGoClassName)
      +  return o
      +}
      +
      +func deleteGoClassName(o *GoClassName) {
      +  // Runs typically in a different OS thread!
      +  wrap.DeleteClassName(o.wcn)
      +  o.wcn = nil
      +}
      +
      +func (o *GoClassName) Close() {
      +  // If the C++ object has a Close method.
      +  o.wcn.Close()
      +
      +  // If the GoClassName object is no longer in an usable state.
      +  runtime.SetFinalizer(o, nil) // Remove finalizer.
      +  deleteGoClassName() // Free the C++ object.
       }
       
      -

      23.4.5.2 Go Class Inheritance

      +

      23.4.5.2 Go Class Inheritance

      @@ -440,7 +590,7 @@

      23.4.5.2 Go Class Inheritance

      be checked dynamically.

      -

      23.4.6 Go Templates

      +

      23.4.6 Go Templates

      @@ -448,50 +598,551 @@

      23.4.6 Go Templates

      wrappers for a particular template instantation. To do this, use the %template directive. -

      23.4.7 Go Director Classes

      + +

      23.4.7 Go Director Classes

      + + +

      +SWIG's director feature permits a Go type to act as the subclass of a C++ class. +This is complicated by the fact that C++ and Go define inheritance differently. +SWIG normally represents the C++ class inheritance automatically in Go via +interfaces but with a Go type representing a subclass of a C++ class some manual +work is necessary. +

      + +

      +This subchapter gives a step by step guide how to properly sublass a C++ class +with a Go type. In general it is strongly recommended to follow this guide +completely to avoid common pitfalls with directors in Go. +

      + + +

      23.4.7.1 Example C++ code

      + + +

      +The step by step guide is based on two example C++ classes. FooBarAbstract is +an abstract C++ class and the FooBarCpp class inherits from it. This guide +explains how to implement a FooBarGo class similar to the FooBarCpp class. +

      + +

      +FooBarAbstract abstract C++ class: +

      + +
      +
      +class FooBarAbstract
      +{
      +public:
      +  FooBarAbstract() {};
      +  virtual ~FooBarAbstract() {};
      +
      +  std::string FooBar() {
      +          return this->Foo() + ", " + this->Bar();
      +  };
      +
      +protected:
      +  virtual std::string Foo() {
      +          return "Foo";
      +  };
      +
      +  virtual std::string Bar() = 0;
      +};
      +
      +
      + +

      +FooBarCpp C++ class: +

      + +
      +
      +class FooBarCpp : public FooBarAbstract
      +{
      +protected:
      +  virtual std::string Foo() {
      +    return "C++ " + FooBarAbstract::Foo();
      +  }
      +
      +  virtual std::string Bar() {
      +    return "C++ Bar";
      +  }
      +};
      +
      +
      + +

      +Returned string by the FooBarCpp::FooBar method is: +

      + +
      +
      +C++ Foo, C++ Bar
      +
      +
      + + +

      +The complete example, including the FooBarGoo class implementation, can +be found in the end of the guide. +

      + + +

      23.4.7.2 Enable director feature

      + + +

      +The director feature is disabled by default. To use directors you must make two +changes to the interface file. First, add the "directors" option to the %module +directive, like this: +

      + +
      +
      +%module(directors="1") modulename
      +
      +
      + +

      +Second, you must use the %feature("director") directive to tell SWIG which +classes should get directors. In the example the FooBarAbstract class needs the +director feature enabled so that the FooBarGo class can inherit from it, like +this: +

      + +
      +
      +%feature("director") FooBarAbstract;
      +
      +
      + +

      +For a more detailed documentation of the director feature and how to enable or +disable it for specific classes and virtual methods see SWIG's Java +documentation on directors. +

      + + +

      23.4.7.3 Constructor and destructor

      -SWIG's director feature permits a Go type to act as the subclass of a -C++ class with virtual methods. This is complicated by the fact that -C++ and Go define inheritance differently. In Go, structs can inherit -methods via anonymous field embedding. However, when a method is -called for an embedded struct, if that method calls any other methods, -they are called for the embedded struct, not for the original type. -Therefore, SWIG must use Go interfaces to represent C++ inheritance. +SWIG creates an additional set of constructor and destructor functions once the +director feature has been enabled for a C++ class. +NewDirectorClassName allows overriding virtual methods on the new +object instance and DeleteDirectorClassName needs to be used to free a +director object instance created with NewDirectorClassName. +More on overriding virtual methods follows later in this guide under +overriding virtual methods.

      -In order to use the director feature in Go, you must define a type in -your Go code. You must then add methods for the type. Define a -method in Go for each C++ virtual function that you want to override. -You must then create a value of your new type, and pass a pointer to -it to the function NewDirectorClassName, -where ClassName is the name of the C++ class. That will -return a value of type ClassName. +The default constructor and destructor functions NewClassName and +DeleteClassName can still be used as before so that existing code +doesn't break just because the director feature has been enabled for a C++ +class. The behavior is undefined if the default and director constructor and +destructor functions get mixed and so great care needs to be taken that only one +of the constructor and destructor function pairs is used for any object +instance. Both constructor functions, the default and the director one, return +the same interface type. This makes it potentially hard to know which +destructor function, the default or the director one, needs to be called to +delete an object instance.

      -For example: +In theory the DirectorInterface method could be used to +determine if an object instance was created via NewDirectorClassName:

      -type GoClass struct { }
      -func (p *GoClass) VirtualFunction() { }
      -func MakeClass() ClassName {
      -	return NewDirectorClassName(&GoClass{})
      +if o.DirectorInterface() != nil {
      +  DeleteDirectorClassName(o)
      +} else {
      +  DeleteClassName(o)
       }
       

      -Any call in C++ code to the virtual function will wind up calling the -method defined in Go. The Go code may of course call other methods on -itself, and those methods may be defined either in Go or in C++. +In practice it is strongly recommended to embed a director object +instance in a Go struct so that a director object instance will be represented +as a distinct Go type that subclasses a C++ class. For this Go type custom +constructor and destructor functions take care of the director constructor and +destructor function calls and the resulting Go class will appear to the user as +any other SWIG wrapped C++ class. More on properly subclassing a C++ class +follows later in this guide under subclass via +embedding.

      -

      23.4.8 Default Go primitive type mappings

      + +

      23.4.7.4 Override virtual methods

      + + +

      +In order to override virtual methods on a C++ class with Go methods the +NewDirectorClassName constructor functions receives a +DirectorInterface argument. The methods in the +DirectorInterface are a subset of the public and protected virtual methods +of the C++ class. If the DirectorInterface contains a method with a +matching signature to a virtual method of the C++ class then the virtual C++ +method will be overwritten with the Go method. As Go doesn't support protected +methods all overriden protected virtual C++ methods will be public in Go. +

      + +

      +As an example see part of the FooBarGo class: +

      + +
      +
      +type overwrittenMethodsOnFooBarAbstract struct {
      +  fb FooBarAbstract
      +}
      +
      +func (om *overwrittenMethodsOnFooBarAbstract) Foo() string {
      +  ...
      +}
      +
      +func (om *overwrittenMethodsOnFooBarAbstract) Bar() string {
      +  ...
      +}
      +
      +func NewFooBarGo() FooBarGo {
      +  om := &overwrittenMethodsOnFooBarAbstract{}
      +  fb := NewDirectorFooBarAbstract(om)
      +  om.fb = fb
      +  ...
      +}
      +
      +
      + +

      +The complete example, including the FooBarGoo class implementation, can +be found in the end of the guide. In +this part of the example the virtual methods FooBarAbstract::Foo and +FooBarAbstract::Bar have been overwritten with Go methods similarly to +how the FooBarAbstract virtual methods are overwritten by the +FooBarCpp class. +

      + +

      +The DirectorInterface in the example is implemented by the +overwrittenMethodsOnFooBarAbstract Go struct type. A pointer to a +overwrittenMethodsOnFooBarAbstract struct instance will be given to the +NewDirectorFooBarAbstract constructor function. The constructor return +value implements the FooBarAbstract interface. +overwrittenMethodsOnFooBarAbstract could in theory be any Go type but +in practice a struct is used as it typically contains at least a value of the +C++ class interface so that the overwritten methods can use the rest of the +C++ class. If the FooBarGo class would receive additional constructor +arguments then these would also typically be stored in the +overwrittenMethodsOnFooBarAbstract struct so that they can be used by +the Go methods. +

      + + +

      23.4.7.5 Call base methods

      + + +

      +Often a virtual method will be overwritten to extend the original behavior of +the method in the base class. This is also the case for the +FooBarCpp::Foo method of the example code: +

      + +
      +
      +virtual std::string Foo() {
      +  return "C++ " + FooBarAbstract::Foo();
      +}
      +
      +
      + +

      +To use base methods the DirectorClassNameMethodName wrapper functions +are automatically generated by SWIG for public and protected virtual methods. +The FooBarGo.Foo implementation in the example looks like this: +

      + +
      +
      +func (om *overwrittenMethodsOnFooBarAbstract) Foo() string {
      +  return "Go " + DirectorFooBarAbstractFoo(om.fb)
      +}
      +
      +
      + +

      +The complete example, including the FooBarGoo class implementation, can +be found in the end of the guide. +

      + + +

      23.4.7.6 Subclass via embedding

      + + +

      +As previously mentioned in this guide the +default and director constructor functions return the same interface type. To +properly subclass a C++ class with a Go type the director object instance +returned by the NewDirectorClassName constructor function should be +embedded into a Go struct so that it represents a distinct but compatible type +in Go's type system. This Go struct should be private and the constructor and +destructor functions should instead work with a public interface type so that +the Go class that subclasses a C++ class can be used as a compatible drop in. +

      + +

      +The subclassing part of the FooBarGo class for an example looks like +this: +

      + +
      +
      +type FooBarGo interface {
      +  FooBarAbstract
      +  deleteFooBarAbstract()
      +  IsFooBarGo()
      +}
      +
      +type fooBarGo struct {
      +  FooBarAbstract
      +}
      +
      +func (fbgs *fooBarGo) deleteFooBarAbstract() {
      +  DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract)
      +}
      +
      +func (fbgs *fooBarGo) IsFooBarGo() {}
      +
      +func NewFooBarGo() FooBarGo {
      +  om := &overwrittenMethodsOnFooBarAbstract{}
      +  fb := NewDirectorFooBarAbstract(om)
      +  om.fb = fb
      +
      +  return &fooBarGo{FooBarAbstract: fb}
      +}
      +
      +func DeleteFooBarGo(fbg FooBarGo) {
      +  fbg.deleteFooBarAbstract()
      +}
      +
      +
      + + +

      +The complete example, including the FooBarGoo class implementation, can +be found in the end of the guide. In +this part of the example the private fooBarGo struct embeds +FooBarAbstract which lets the fooBarGo Go type "inherit" all the +methods of the FooBarAbstract C++ class by means of embedding. The +public FooBarGo interface type includes the FooBarAbstract +interface and hence FooBarGo can be used as a drop in replacement for +FooBarAbstract while the reverse isn't possible and would raise a +compile time error. Furthemore the constructor and destructor functions +NewFooBarGo and DeleteFooBarGo take care of all the director +specifics and to the user the class appears as any other SWIG wrapped C++ +class. +

      + + +

      23.4.7.7 Memory management with runtime.SetFinalizer

      + + +

      +In general all guidelines for C++ class memory +management apply as well to director classes. One often overlooked +limitation with runtime.SetFinalizer is that a finalizer doesn't run +in case of a cycle and director classes typically have a cycle. The cycle +in the FooBarGo class is here: +

      + +
      +
      +type overwrittenMethodsOnFooBarAbstract struct {
      +  fb FooBarAbstract
      +}
      +
      +func NewFooBarGo() FooBarGo {
      +  om := &overwrittenMethodsOnFooBarAbstract{}
      +  fb := NewDirectorFooBarAbstract(om) // fb.v = om
      +  om.fb = fb // Backlink causes cycle as fb.v = om!
      +  ...
      +}
      +
      +
      + +

      +In order to be able to use runtime.SetFinalizer nevertheless the +finalizer needs to be set on something that isn't in a cycle and that references +the director object instance. In the FooBarGo class example the +FooBarAbstract director instance can be automatically deleted by setting +the finalizer on fooBarGo: +

      + +
      +
      +type fooBarGo struct {
      +  FooBarAbstract
      +}
      +
      +type overwrittenMethodsOnFooBarAbstract struct {
      +  fb FooBarAbstract
      +}
      +
      +func NewFooBarGo() FooBarGo {
      +  om := &overwrittenMethodsOnFooBarAbstract{}
      +  fb := NewDirectorFooBarAbstract(om)
      +  om.fb = fb // Backlink causes cycle as fb.v = om!
      +
      +  fbgs := &fooBarGo{FooBarAbstract: fb}
      +  runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract)
      +  return fbgs
      +}
      +
      +
      + +

      +Furthermore if runtime.SetFinalizer is in use either the +DeleteClassName destructor function needs to be removed or the +fooBarGo struct needs additional data to prevent double deletion. Please +read the C++ class memory management subchapter +before using runtime.SetFinalizer to know all of its gotchas. +

      + + +

      23.4.7.8 Complete FooBarGo example class

      + + +

      +The complete and annotated FooBarGo class looks like this: +

      + +
      +
      +// FooBarGo is a superset of FooBarAbstract and hence FooBarGo can be used as a
      +// drop in replacement for FooBarAbstract but the reverse causes a compile time
      +// error.
      +type FooBarGo interface {
      +  FooBarAbstract
      +  deleteFooBarAbstract()
      +  IsFooBarGo()
      +}
      +
      +// Via embedding fooBarGo "inherits" all methods of FooBarAbstract.
      +type fooBarGo struct {
      +  FooBarAbstract
      +}
      +
      +func (fbgs *fooBarGo) deleteFooBarAbstract() {
      +  DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract)
      +}
      +
      +// The IsFooBarGo method ensures that FooBarGo is a superset of FooBarAbstract.
      +// This is also how the class hierarchy gets represented by the SWIG generated
      +// wrapper code.  For an instance FooBarCpp has the IsFooBarAbstract and
      +// IsFooBarCpp methods.
      +func (fbgs *fooBarGo) IsFooBarGo() {}
      +
      +// Go type that defines the DirectorInterface. It contains the Foo and Bar
      +// methods that overwrite the respective virtual C++ methods on FooBarAbstract.
      +type overwrittenMethodsOnFooBarAbstract struct {
      +  // Backlink to FooBarAbstract so that the rest of the class can be used by
      +  // the overridden methods.
      +  fb FooBarAbstract
      +
      +  // If additional constructor arguments have been given they are typically
      +  // stored here so that the overriden methods can use them.
      +}
      +
      +func (om *overwrittenMethodsOnFooBarAbstract) Foo() string {
      +  // DirectorFooBarAbstractFoo calls the base method FooBarAbstract::Foo.
      +  return "Go " + DirectorFooBarAbstractFoo(om.fb)
      +}
      +
      +func (om *overwrittenMethodsOnFooBarAbstract) Bar() string {
      +  return "Go Bar"
      +}
      +
      +func NewFooBarGo() FooBarGo {
      +  // Instantiate FooBarAbstract with selected methods overridden.  The methods
      +  // that will be overwritten are defined on
      +  // overwrittenMethodsOnFooBarAbstract and have a compatible signature to the
      +  // respective virtual C++ methods. Furthermore additional constructor
      +  // arguments will be typically stored in the
      +  // overwrittenMethodsOnFooBarAbstract struct.
      +  om := &overwrittenMethodsOnFooBarAbstract{}
      +  fb := NewDirectorFooBarAbstract(om)
      +  om.fb = fb // Backlink causes cycle as fb.v = om!
      +
      +  fbgs := &fooBarGo{FooBarAbstract: fb}
      +  // The memory of the FooBarAbstract director object instance can be
      +  // automatically freed once the FooBarGo instance is garbage collected by
      +  // uncommenting the following line.  Please make sure to understand the
      +  // runtime.SetFinalizer specific gotchas before doing this.  Furthemore
      +  // DeleteFooBarGo should be deleted if a finalizer is in use or the fooBarGo
      +  // struct needs additional data to prevent double deletion.
      +  // runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract)
      +  return fbgs
      +}
      +
      +// Recommended to be removed if runtime.SetFinalizer is in use.
      +func DeleteFooBarGo(fbg FooBarGo) {
      +  fbg.deleteFooBarAbstract()
      +}
      +
      +
      + +

      +Returned string by the FooBarGo.FooBar method is: +

      + +
      +
      +Go Foo, Go Bar
      +
      +
      + +

      +For comparison the FooBarCpp class looks like this: +

      + +
      +
      +class FooBarCpp : public FooBarAbstract
      +{
      +protected:
      +  virtual std::string Foo() {
      +    return "C++ " + FooBarAbstract::Foo();
      +  }
      +
      +  virtual std::string Bar() {
      +    return "C++ Bar";
      +  }
      +};
      +
      +
      + +

      +For comparison the returned string by the FooBarCpp::FooBar method is: +

      + +
      +
      +C++ Foo, C++ Bar
      +
      +
      + +

      +The complete source of this example can be found under + +SWIG/Examples/go/director/. +

      + + +

      23.4.8 Default Go primitive type mappings

      @@ -598,7 +1249,7 @@

      23.4.8 Default Go primitive type ma into Go types.

      -

      23.4.9 Output arguments

      +

      23.4.9 Output arguments

      Because of limitations in the way output arguments are processed in swig, @@ -651,7 +1302,7 @@

      23.4.9 Output arguments

      -

      23.4.10 Adding additional go code

      +

      23.4.10 Adding additional go code

      Often the APIs generated by swig are not very natural in go, especially if @@ -746,7 +1397,7 @@

      23.4.10 Adding additional go code -

      23.4.11 Go typemaps

      +

      23.4.11 Go typemaps

      @@ -795,7 +1446,8 @@

      23.4.11 Go typemaps

      Go code to convert from gotype to imtype when calling a C/C++ function. SWIG will then internally convert imtype to a C/C++ type -and pass it down. If this is not defined no conversion is done. +and pass it down. If this is not defined, or is the empty string, no +conversion is done. @@ -822,7 +1474,8 @@

      23.4.11 Go typemaps

      goout Go code to convert a value returned from a C/C++ function from imtype -to gotype. If this is not defined no conversion is done. +to gotype. If this is not defined, or is the empty string, no +conversion is done. @@ -843,7 +1496,7 @@

      23.4.11 Go typemaps

      Go code to adjust an argument value when returning from a function. This is called after the real C/C++ function has run. The value will be in imtype. This is only useful for a pointer type of some sort. -If this is not defined nothing will be done. +If this is not defined, or is the empty string, nothing will be done. @@ -861,7 +1514,8 @@

      23.4.11 Go typemaps

      godirectorin Go code to convert a value used to call a director method from imtype -to gotype. If this is not defined no conversion is done. +to gotype. If this is not defined, or is the empty string, no +conversion is done. @@ -869,7 +1523,8 @@

      23.4.11 Go typemaps

      godirectorout Go code to convert a value returned from a director method from gotype -to imtype. If this is not defined no conversion is done. +to imtype. If this is not defined, or is the empty string, no +conversion is done. diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 4c1126c7fed..f30e139e590 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -1,14 +1,14 @@ - - + SWIG and Guile + -

      24 SWIG and Guile

      +

      24 SWIG and Guile

        @@ -47,7 +47,7 @@

        24 SWIG and Guile

        This section details guile-specific support in SWIG. -

        24.1 Supported Guile Versions

        +

        24.1 Supported Guile Versions

        @@ -61,7 +61,7 @@

        24.1 Supported Guile Versions

        so your mileage may vary. To be safe set environment variable GUILE_AUTO_COMPILE to 0 when using swig generated guile code. -

        24.2 Meaning of "Module"

        +

        24.2 Meaning of "Module"

        @@ -69,7 +69,7 @@

        24.2 Meaning of "Module"

        separately for SWIG, Guile, and Libtool. To avoid horrible confusion, we explicitly prefix the context, e.g., "guile-module". -

        24.3 Old GH Guile API

        +

        24.3 Old GH Guile API

        Guile 1.8 and older could be interfaced using two different api's, the SCM @@ -80,7 +80,7 @@

        24.3 Old GH Guile API

        version of SWIG that can still generate guile GH wrapper code is 2.0.9. Please use that version if you really need the GH wrapper code. -

        24.4 Linkage

        +

        24.4 Linkage

        @@ -88,7 +88,7 @@

        24.4 Linkage

        which manifests in multiple shared-library usage conventions. A set of policies implementing a usage convention is called a linkage. -

        24.4.1 Simple Linkage

        +

        24.4.1 Simple Linkage

        @@ -158,8 +158,8 @@

        24.4.1 Simple Linkage

         (module-map (lambda (sym var)
        -	      (module-export! (current-module) (list sym)))
        -	    (current-module))
        +              (module-export! (current-module) (list sym)))
        +            (current-module))
         
        @@ -193,7 +193,7 @@

        24.4.1 Simple Linkage

        SWIG_init via a preprocessor define to avoid symbol clashes. For this case, however, passive linkage is available. -

        24.4.2 Passive Linkage

        +

        24.4.2 Passive Linkage

        Passive linkage is just like simple linkage, but it generates an @@ -203,7 +203,7 @@

        24.4.2 Passive Linkage

        You should use passive linkage rather than simple linkage when you are using multiple modules. -

        24.4.3 Native Guile Module Linkage

        +

        24.4.3 Native Guile Module Linkage

        SWIG can also generate wrapper code that does all the Guile module @@ -244,7 +244,7 @@

        24.4.3 Native Guile Module Linkage

    -

    24.4.4 Old Auto-Loading Guile Module Linkage

    +

    24.4.4 Old Auto-Loading Guile Module Linkage

    Guile used to support an autoloading facility for object-code @@ -270,7 +270,7 @@

    24.4.4 Old Auto-Loading Guile Module Linkage

    an appropriate name. -

    24.4.5 Hobbit4D Linkage

    +

    24.4.5 Hobbit4D Linkage

    @@ -295,7 +295,7 @@

    24.4.5 Hobbit4D Linkage

    experimental; the (hobbit4d link) conventions are not well understood.

    -

    24.5 Underscore Folding

    +

    24.5 Underscore Folding

    @@ -307,7 +307,7 @@

    24.5 Underscore Folding

    %rename to specify the Guile name of the wrapped functions and variables (see CHANGES). -

    24.6 Typemaps

    +

    24.6 Typemaps

    @@ -399,7 +399,7 @@

    24.6 Typemaps

    Features and the %feature directive for info on how to apply the %feature.

    -

    24.7 Representation of pointers as smobs

    +

    24.7 Representation of pointers as smobs

    @@ -420,7 +420,7 @@

    24.7 Representation of pointers as smobs

    If the Scheme object passed was not a SWIG smob representing a compatible pointer, a wrong-type-arg exception is raised. -

    24.7.1 Smobs

    +

    24.7.1 Smobs

    @@ -439,7 +439,7 @@

    24.7.1 Smobs

    the corresponding GOOPS class.

    -

    24.7.2 Garbage Collection

    +

    24.7.2 Garbage Collection

    Garbage collection is a feature of Guile since version 1.6. As SWIG now requires Guile > 1.8, @@ -453,7 +453,7 @@

    24.7.2 Garbage Collection

    Object ownership and %newobject in the SWIG manual. All typemaps use an $owner var, and the guile module replaces $owner with 0 or 1 depending on feature:new.

    -

    24.8 Exception Handling

    +

    24.8 Exception Handling

    @@ -462,16 +462,16 @@

    24.8 Exception Handling

    -      MAP(SWIG_MemoryError,	"swig-memory-error");
    -      MAP(SWIG_IOError,		"swig-io-error");
    -      MAP(SWIG_RuntimeError,	"swig-runtime-error");
    -      MAP(SWIG_IndexError,	"swig-index-error");
    -      MAP(SWIG_TypeError,	"swig-type-error");
    -      MAP(SWIG_DivisionByZero,	"swig-division-by-zero");
    -      MAP(SWIG_OverflowError,	"swig-overflow-error");
    -      MAP(SWIG_SyntaxError,	"swig-syntax-error");
    -      MAP(SWIG_ValueError,	"swig-value-error");
    -      MAP(SWIG_SystemError,	"swig-system-error");
    +      MAP(SWIG_MemoryError,     "swig-memory-error");
    +      MAP(SWIG_IOError,         "swig-io-error");
    +      MAP(SWIG_RuntimeError,    "swig-runtime-error");
    +      MAP(SWIG_IndexError,      "swig-index-error");
    +      MAP(SWIG_TypeError,       "swig-type-error");
    +      MAP(SWIG_DivisionByZero,  "swig-division-by-zero");
    +      MAP(SWIG_OverflowError,   "swig-overflow-error");
    +      MAP(SWIG_SyntaxError,     "swig-syntax-error");
    +      MAP(SWIG_ValueError,      "swig-value-error");
    +      MAP(SWIG_SystemError,     "swig-system-error");
     
    @@ -479,7 +479,7 @@

    24.8 Exception Handling

    The default when not specified here is to use "swig-error". See Lib/exception.i for details. -

    24.9 Procedure documentation

    +

    24.9 Procedure documentation

    If invoked with the command-line option -procdoc @@ -514,7 +514,7 @@

    24.9 Procedure documentation

    typemap argument doc. See Lib/guile/typemaps.i for details. -

    24.10 Procedures with setters

    +

    24.10 Procedures with setters

    For global variables, SWIG creates a single wrapper procedure @@ -542,7 +542,7 @@

    24.10 Procedures with setters

    pointer)
    and (struct-member-set pointer value) are not generated. -

    24.11 GOOPS Proxy Classes

    +

    24.11 GOOPS Proxy Classes

    SWIG can also generate classes and generic functions for use with @@ -688,7 +688,7 @@

    24.11 GOOPS Proxy Classes

    %import "foo.h" before the %inline block.

    -

    24.11.1 Naming Issues

    +

    24.11.1 Naming Issues

    As you can see in the example above, there are potential naming conflicts. The default exported @@ -725,7 +725,7 @@

    24.11.1 Naming Issues

    (use-modules ((Test) #:renamer (symbol-prefix-proc 'goops:))) -

    24.11.2 Linking

    +

    24.11.2 Linking

    The guile-modules generated above all need to be linked together. GOOPS support requires diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html index 19d59a4df85..1c29f476038 100644 --- a/Doc/Manual/Introduction.html +++ b/Doc/Manual/Introduction.html @@ -1,12 +1,13 @@ - + Introduction + -

    2 Introduction

    +

    2 Introduction

      @@ -31,7 +32,7 @@

      2 Introduction

      -

      2.1 What is SWIG?

      +

      2.1 What is SWIG?

      @@ -71,7 +72,7 @@

      2.1 What is SWIG?

      in scientific and engineering projects. However, nowadays SWIG is known to be used in many large open source and commercial projects. -

      2.2 Why use SWIG?

      +

      2.2 Why use SWIG?

      @@ -143,7 +144,7 @@

      2.2 Why use SWIG?

      every aspect of the language bindings. This is the main reason why SWIG has such a large user manual ;-). -

      2.3 A SWIG example

      +

      2.3 A SWIG example

      @@ -157,14 +158,16 @@

      2.3 A SWIG example

      double My_variable = 3.0; /* Compute factorial of n */ -int fact(int n) { - if (n <= 1) return 1; - else return n*fact(n-1); +int fact(int n) { + if (n <= 1) + return 1; + else + return n*fact(n-1); } /* Compute n mod m */ int my_mod(int n, int m) { - return(n % m); + return(n % m); }
    @@ -174,7 +177,7 @@

    2.3 A SWIG example

    interface file as shown below (by convention, these files carry a .i suffix) : -

    2.3.1 SWIG interface file

    +

    2.3.1 SWIG interface file

    @@ -199,7 +202,7 @@ 

    2.3.1 SWIG interface file

    provides a location for inserting additional code, such as C header files or additional C declarations, into the generated C wrapper code. -

    2.3.2 The swig command

    +

    2.3.2 The swig command

    @@ -221,8 +224,7 @@

    2.3.2 The swig command

    7.5 %
    -

    - +

    The swig command produced a new file called example_wrap.c that should be compiled along with the example.c file. Most operating systems and scripting @@ -233,7 +235,7 @@

    2.3.2 The swig command

    example_wrap.c reveals a hideous mess. However, you almost never need to worry about it. -

    2.3.3 Building a Perl5 module

    +

    2.3.3 Building a Perl5 module

    @@ -244,8 +246,8 @@

    2.3.3 Building a Perl5 module

     unix > swig -perl5 example.i
     unix > gcc -c example.c example_wrap.c \
    -	-I/usr/local/lib/perl5/sun4-solaris/5.003/CORE
    -unix > ld -G example.o example_wrap.o -o example.so		# This is for Solaris
    +        -I/usr/local/lib/perl5/sun4-solaris/5.003/CORE
    +unix > ld -G example.o example_wrap.o -o example.so # This is for Solaris
     unix > perl5.003
     use example;
     print example::fact(4), "\n";
    @@ -259,7 +261,7 @@ 

    2.3.3 Building a Perl5 module

    -

    2.3.4 Building a Python module

    +

    2.3.4 Building a Python module

    @@ -283,7 +285,7 @@

    2.3.4 Building a Python module

    7.5 -

    2.3.5 Shortcuts

    +

    2.3.5 Shortcuts

    @@ -296,7 +298,7 @@

    2.3.5 Shortcuts

     unix > swig -perl5 -module example example.h
     unix > gcc -c example.c example_wrap.c \
    -	-I/usr/local/lib/perl5/sun4-solaris/5.003/CORE
    +        -I/usr/local/lib/perl5/sun4-solaris/5.003/CORE
     unix > ld -G example.o example_wrap.o -o example.so
     unix > perl5.003
     use example;
    @@ -309,7 +311,7 @@ 

    2.3.5 Shortcuts

    7.5
    -

    2.4 Supported C/C++ language features

    +

    2.4 Supported C/C++ language features

    @@ -334,8 +336,7 @@

    2.4 Supported C/C++ language features

    -Currently, the only major C++ feature not supported is nested classes--a limitation -that should be removed in a future release, but has some workarounds for the moment. +Most of C++11 is also supported. Details are in the C++11 section.

    @@ -349,7 +350,7 @@

    2.4 Supported C/C++ language features

    stresses the very limits of many C++ compilers. -

    2.5 Non-intrusive interface building

    +

    2.5 Non-intrusive interface building

    @@ -361,7 +362,7 @@

    2.5 Non-intrusive interface building

    possible to support different types of interfaces depending on the application.

    -

    2.6 Incorporating SWIG into a build system

    +

    2.6 Incorporating SWIG into a build system

    @@ -384,7 +385,7 @@

    2.6 Incorporating SWIG into a build

    -There is growing support for SWIG in some build tools, for example CMake +There is growing support for SWIG in some build tools, for example CMake is a cross-platform, open-source build manager with built in support for SWIG. CMake can detect the SWIG executable and many of the target language libraries for linking against. CMake knows how to build shared libraries and loadable modules on many different operating systems. @@ -419,7 +420,7 @@

    2.6 Incorporating SWIG into a build For other target languages on Windows a dll, instead of a .pyd file, is usually generated.

    -

    2.7 Hands off code generation

    +

    2.7 Hands off code generation

    @@ -432,7 +433,7 @@

    2.7 Hands off code generation

    details.

    -

    2.8 SWIG and freedom

    +

    2.8 SWIG and freedom

    @@ -458,6 +459,12 @@

    2.8 SWIG and freedom

    of the programmer's way----the last thing any developer wants to do is to spend their time debugging the output of a tool that relies on non-portable or unreliable programming features. +Dependencies are often a source of incompatibilities and problems and so +additional third party libraries are not used in the generated code. +SWIG will also generally avoid generating code that introduces a dependency +on the C++ Standard Template Library (STL). +SWIG will generate code that depends on the C libraries though. +

    diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 3a4f7ee5d3a..dae6edc01ca 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -1,11 +1,12 @@ - + SWIG and Java + -

    25 SWIG and Java

    +

    25 SWIG and Java

  • Further details on the generated Java classes
      @@ -157,7 +162,7 @@

      25 SWIG and Java

      -

      25.1 Overview

      +

      25.1 Overview

      @@ -192,7 +197,7 @@

      25.1 Overview

      The latter sections cover the advanced techniques of using typemaps for complete control of the wrapping process.

      -

      25.2 Preliminaries

      +

      25.2 Preliminaries

      @@ -209,10 +214,10 @@

      25.2 Preliminaries

      This is the commonly used method to load JNI code so your system will more than likely support this.

      -Android uses Java JNI and also works with SWIG. Please read the Android chapter in conjunction with this one if you are targeting Android. +Android uses Java JNI and also works with SWIG. Please read the Android chapter in conjunction with this one if you are targeting Android.

      -

      25.2.1 Running SWIG

      +

      25.2.1 Running SWIG

      @@ -271,7 +276,7 @@

      25.2.1 Running SWIG

      compiling and using the generated files.

      -

      25.2.2 Additional Commandline Options

      +

      25.2.2 Additional Commandline Options

      @@ -308,7 +313,7 @@

      25.2.2 Additional Commandline Options

      Their use will become clearer by the time you have finished reading this section on SWIG and Java.

      -

      25.2.3 Getting the right header files

      +

      25.2.3 Getting the right header files

      @@ -323,7 +328,7 @@

      25.2.3 Getting the right header fil

      The exact location may vary on your machine, but the above locations are typical.

      -

      25.2.4 Compiling a dynamic module

      +

      25.2.4 Compiling a dynamic module

      @@ -345,8 +350,6 @@

      25.2.4 Compiling a dynamic module

      your compiler and linker to get the right set of options. You might also check the SWIG Wiki for additional information. -JNI compilation -is a useful reference for compiling on different platforms.

      @@ -360,7 +363,7 @@

      25.2.4 Compiling a dynamic module

      If the name of your SWIG module is "example", the name of the corresponding shared library file should be "libexample.so" (or equivalent depending on your machine, see Dynamic linking problems for more information). The name of the module is specified using the %module directive or -module command line option.

      -

      25.2.5 Using your module

      +

      25.2.5 Using your module

      @@ -395,7 +398,7 @@

      25.2.5 Using your module

      If it doesn't work have a look at the following section which discusses problems loading the shared library.

      -

      25.2.6 Dynamic linking problems

      +

      25.2.6 Dynamic linking problems

      @@ -461,9 +464,9 @@

      25.2.6 Dynamic linking problems<
       $ java runme
       Exception in thread "main" java.lang.UnsatisfiedLinkError: exampleJNI.gcd(II)I
      -	at exampleJNI.gcd(Native Method)
      -	at example.gcd(example.java:12)
      -	at runme.main(runme.java:18)
      +        at exampleJNI.gcd(Native Method)
      +        at example.gcd(example.java:12)
      +        at runme.main(runme.java:18)
       

      @@ -482,7 +485,7 @@

      25.2.6 Dynamic linking problems<

      -

      25.2.7 Compilation problems and compiling with C++

      +

      25.2.7 Compilation problems and compiling with C++

      @@ -534,7 +537,7 @@

      25.2.7 Compilation problems and

      -

      25.2.8 Building on Windows

      +

      25.2.8 Building on Windows

      @@ -543,7 +546,7 @@

      25.2.8 Building on Windows

      This section covers the process of using SWIG with Microsoft Visual C++ 6 although the procedure may be similar with other compilers. In order for everything to work, you will need to have a JDK installed on your machine in order to read the JNI header files.

      -

      25.2.8.1 Running SWIG from Visual Studio

      +

      25.2.8.1 Running SWIG from Visual Studio

      @@ -582,7 +585,7 @@

      25.2.8.1 Running SWIG from Visual StudioDynamic linking problems.

      -

      25.2.8.2 Using NMAKE

      +

      25.2.8.2 Using NMAKE

      @@ -627,11 +630,11 @@

      25.2.8.2 Using NMAKE

      JAVA_INCLUDE = -ID:\jdk1.3\include -ID:\jdk1.3\include\win32 java:: - swig -java -o $(WRAPFILE) $(INTERFACE) - $(CC) $(CFLAGS) $(JAVA_INCLUDE) $(SRCS) $(WRAPFILE) - set LIB=$(TOOLS)\lib - $(LINK) $(LOPT) -out:example.dll $(LIBS) example.obj example_wrap.obj - javac *.java + swig -java -o $(WRAPFILE) $(INTERFACE) + $(CC) $(CFLAGS) $(JAVA_INCLUDE) $(SRCS) $(WRAPFILE) + set LIB=$(TOOLS)\lib + $(LINK) $(LOPT) -out:example.dll $(LIBS) example.obj example_wrap.obj + javac *.java

      @@ -641,7 +644,7 @@

      25.2.8.2 Using NMAKE

      -

      25.3 A tour of basic C/C++ wrapping

      +

      25.3 A tour of basic C/C++ wrapping

      @@ -651,7 +654,7 @@

      25.3 A tour of basic C/C++ wrapping

      This section briefly covers the essential aspects of this wrapping.

      -

      25.3.1 Modules, packages and generated Java classes

      +

      25.3.1 Modules, packages and generated Java classes

      @@ -687,7 +690,7 @@

      25.3.1 Modules, packages and gene SWIG won't create the directory, so make sure it exists beforehand.

      -

      25.3.2 Functions

      +

      25.3.2 Functions

      @@ -721,7 +724,7 @@

      25.3.2 Functions

      -

      25.3.3 Global variables

      +

      25.3.3 Global variables

      @@ -808,7 +811,7 @@

      25.3.3 Global variables

      -

      25.3.4 Constants

      +

      25.3.4 Constants

      @@ -948,7 +951,7 @@

      25.3.4 Constants

      -

      25.3.5 Enumerations

      +

      25.3.5 Enumerations

      @@ -962,7 +965,7 @@

      25.3.5 Enumerations

      Before looking at the various approaches for wrapping named C/C++ enums, anonymous enums are considered.

      -

      25.3.5.1 Anonymous enums

      +

      25.3.5.1 Anonymous enums

      @@ -1025,7 +1028,7 @@

      25.3.5.1 Anonymous enums

      -

      25.3.5.2 Typesafe enums

      +

      25.3.5.2 Typesafe enums

      @@ -1119,7 +1122,7 @@

      25.3.5.2 Typesafe enums

      The following section details proper Java enum generation.

      -

      25.3.5.3 Proper Java enums

      +

      25.3.5.3 Proper Java enums

      @@ -1172,7 +1175,7 @@

      25.3.5.3 Proper Java enums

      Simpler Java enums for enums without initializers section.

      -

      25.3.5.4 Type unsafe enums

      +

      25.3.5.4 Type unsafe enums

      @@ -1220,7 +1223,7 @@

      25.3.5.4 Type unsafe enums

      Thus the upgrade path to proper enums provided in JDK 1.5 is more painful.

      -

      25.3.5.5 Simple enums

      +

      25.3.5.5 Simple enums

      @@ -1239,7 +1242,7 @@

      25.3.5.5 Simple enums

      The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.

      -

      25.3.6 Pointers

      +

      25.3.6 Pointers

      @@ -1327,7 +1330,7 @@

      25.3.6 Pointers

      a NULL pointer if the conversion can't be performed.

      -

      25.3.7 Structures

      +

      25.3.7 Structures

      @@ -1337,7 +1340,7 @@

      25.3.7 Structures

       struct Vector {
      -	double x,y,z;
      +  double x,y,z;
       };
       
       
      @@ -1495,7 +1498,7 @@

      25.3.7 Structures

      -

      25.3.8 C++ classes

      +

      25.3.8 C++ classes

      @@ -1558,7 +1561,7 @@

      25.3.8 C++ classes

      -

      25.3.9 C++ inheritance

      +

      25.3.9 C++ inheritance

      @@ -1619,7 +1622,7 @@

      25.3.9 C++ inheritance

      A warning is given when multiple inheritance is detected and only the first base class is used.

      -

      25.3.10 Pointers, references, arrays and pass by value

      +

      25.3.10 Pointers, references, arrays and pass by value

      @@ -1674,7 +1677,7 @@

      25.3.10 Pointers, references, arrays when the returned object's finalizer is run by the garbage collector).

      -

      25.3.10.1 Null pointers

      +

      25.3.10.1 Null pointers

      @@ -1698,7 +1701,7 @@

      25.3.10.1 Null pointers

      The converse also occurs, that is, NULL pointers are translated into null Java objects when returned from a C/C++ function.

      -

      25.3.11 C++ overloaded functions

      +

      25.3.11 C++ overloaded functions

      @@ -1813,7 +1816,7 @@

      25.3.11 C++ overloaded functions

      -

      25.3.12 C++ default arguments

      +

      25.3.12 C++ default arguments

      @@ -1856,7 +1859,7 @@

      25.3.12 C++ default arguments

      -

      25.3.13 C++ namespaces

      +

      25.3.13 C++ namespaces

      @@ -1946,7 +1949,7 @@

      25.3.13 C++ namespaces

      you will need to open up the visibility for the pointer constructor and getCPtr method from the default 'protected' to 'public' with the SWIG_JAVABODY_PROXY macro. See Java code typemaps.

      -

      25.3.14 C++ templates

      +

      25.3.14 C++ templates

      @@ -1995,7 +1998,21 @@

      25.3.14 C++ templates

      More details can be found in the SWIG and C++ chapter.

      -

      25.3.15 C++ Smart Pointers

      +

      25.3.15 C++ Smart Pointers

      + + +

      25.3.15.1 The shared_ptr Smart Pointer

      + + +

      +The C++11 standard provides std::shared_ptr which was derived from the Boost +implementation, boost::shared_ptr. +Both of these are available for Java in the SWIG library and usage is outlined +in the shared_ptr smart pointer library section. +

      + + +

      25.3.15.2 Generic Smart Pointers

      @@ -2079,7 +2096,7 @@

      25.3.15 C++ Smart Pointers

      -

      25.4 Further details on the generated Java classes

      +

      25.4 Further details on the generated Java classes

      @@ -2094,7 +2111,7 @@

      25.4 Further details on the generated Jav First, the crucial intermediary JNI class is considered.

      -

      25.4.1 The intermediary JNI class

      +

      25.4.1 The intermediary JNI class

      @@ -2214,7 +2231,7 @@

      25.4.1 The intermediary JNI class

      from modulename to modulenameModule.

      -

      25.4.1.1 The intermediary JNI class pragmas

      +

      25.4.1.1 The intermediary JNI class pragmas

      @@ -2296,7 +2313,7 @@

      25.4.1.1 The intermediary JNI class pragm All the methods in the intermediary JNI class will then not be callable outside of the package as the method modifiers have been changed from public access to default access. This is useful if you want to prevent users calling these low level functions.

      -

      25.4.2 The Java module class

      +

      25.4.2 The Java module class

      @@ -2327,7 +2344,7 @@

      25.4.2 The Java module class

      The primary reason for having the module class wrapping the calls in the intermediary JNI class is to implement static type checking. In this case only a Foo can be passed to the egg function, whereas any long can be passed to the egg function in the intermediary JNI class.

      -

      25.4.2.1 The Java module class pragmas

      +

      25.4.2.1 The Java module class pragmas

      @@ -2378,7 +2395,7 @@

      25.4.2.1 The Java module class pragm

      -

      25.4.3 Java proxy classes

      +

      25.4.3 Java proxy classes

      @@ -2390,8 +2407,8 @@

      25.4.3 Java proxy classes

       public class Foo {
      -  private long swigCPtr;
      -  protected boolean swigCMemOwn;
      +  private transient long swigCPtr;
      +  protected transient boolean swigCMemOwn;
       
         protected Foo(long cPtr, boolean cMemoryOwn) {
           swigCMemOwn = cMemoryOwn;
      @@ -2454,7 +2471,7 @@ 

      25.4.3 Java proxy classes

      -

      25.4.3.1 Memory management

      +

      25.4.3.1 Memory management

      @@ -2616,7 +2633,7 @@

      25.4.3.1 Memory management

      -

      25.4.3.2 Inheritance

      +

      25.4.3.2 Inheritance

      @@ -2641,8 +2658,8 @@

      25.4.3.2 Inheritance

       public class Base {
      -  private long swigCPtr;
      -  protected boolean swigCMemOwn;
      +  private transient long swigCPtr;
      +  protected transient boolean swigCMemOwn;
       
         protected Base(long cPtr, boolean cMemoryOwn) {
           swigCMemOwn = cMemoryOwn;
      @@ -2682,7 +2699,7 @@ 

      25.4.3.2 Inheritance

       public class Derived extends Base {
      -  private long swigCPtr;
      +  private transient long swigCPtr;
       
         protected Derived(long cPtr, boolean cMemoryOwn) {
           super(exampleJNI.SWIGDerivedUpcast(cPtr), cMemoryOwn);
      @@ -2732,7 +2749,7 @@ 

      25.4.3.2 Inheritance

      -

      25.4.3.3 Proxy classes and garbage collection

      +

      25.4.3.3 Proxy classes and garbage collection

      @@ -2815,7 +2832,7 @@

      25.4.3.3 Proxy classes and garbage colle See the How to Handle Java Finalization's Memory-Retention Issues article for alternative approaches to managing memory by avoiding finalizers altogether.

      -

      25.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

      +

      25.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

      @@ -2937,7 +2954,7 @@

      25.4.3.4 The premature garbage collection preventio Compatibility note: The generation of this additional parameter did not occur in versions prior to SWIG-1.3.30.

      -

      25.4.3.5 Single threaded applications and thread safety

      +

      25.4.3.5 Single threaded applications and thread safety

      @@ -2960,8 +2977,8 @@

      25.4.3.5 Single threaded applicatio
       public class Test {
      -  private long swigCPtr;
      -  protected boolean swigCMemOwn;
      +  private transient long swigCPtr;
      +  protected transient boolean swigCMemOwn;
       
         protected Test(long cPtr, boolean cMemoryOwn) {
           swigCMemOwn = cMemoryOwn;
      @@ -3025,7 +3042,7 @@ 

      25.4.3.5 Single threaded applicatio

      -

      25.4.4 Type wrapper classes

      +

      25.4.4 Type wrapper classes

      @@ -3034,7 +3051,7 @@

      25.4.4 Type wrapper classes

       public class SWIGTYPE_p_int {
      -  private long swigCPtr;
      +  private transient long swigCPtr;
       
         protected SWIGTYPE_p_int(long cPtr, boolean bFutureUse) {
           swigCPtr = cPtr;
      @@ -3112,7 +3129,7 @@ 

      25.4.4 Type wrapper classes

      -

      25.4.5 Enum classes

      +

      25.4.5 Enum classes

      @@ -3121,7 +3138,7 @@

      25.4.5 Enum classes

      The following sub-sections detail the various types of enum classes that can be generated.

      -

      25.4.5.1 Typesafe enum classes

      +

      25.4.5.1 Typesafe enum classes

      @@ -3205,7 +3222,7 @@

      25.4.5.1 Typesafe enum classes

      toString method is overridden so that the enum name is available.

      -

      25.4.5.2 Proper Java enum classes

      +

      25.4.5.2 Proper Java enum classes

      @@ -3283,7 +3300,7 @@

      25.4.5.2 Proper Java enum classesSimpler Java enums for enums without initializers section describes how typemaps can be used to achieve this.

      -

      25.4.5.3 Type unsafe enum classes

      +

      25.4.5.3 Type unsafe enum classes

      @@ -3314,7 +3331,7 @@

      25.4.5.3 Type unsafe enum classe

      -

      25.5 Cross language polymorphism using directors

      +

      25.5 Cross language polymorphism using directors

      @@ -3336,7 +3353,7 @@

      25.5 Cross language polymorphism using director Neither C++ code nor Java code needs to know where a particular method is implemented: the combination of proxy classes, director classes, and C wrapper functions transparently takes care of all the cross-language method routing.

      -

      25.5.1 Enabling directors

      +

      25.5.1 Enabling directors

      @@ -3404,7 +3421,7 @@

      25.5.1 Enabling directors

      -

      25.5.2 Director classes

      +

      25.5.2 Director classes

      @@ -3431,7 +3448,7 @@

      25.5.2 Director classes

      -

      25.5.3 Overhead and code bloat

      +

      25.5.3 Overhead and code bloat

      @@ -3449,7 +3466,7 @@

      25.5.3 Overhead and code bloat

      -

      25.5.4 Simple directors example

      +

      25.5.4 Simple directors example

      @@ -3514,7 +3531,7 @@

      25.5.4 Simple directors example

      -

      25.5.5 Director threading issues

      +

      25.5.5 Director threading issues

      @@ -3534,7 +3551,7 @@

      25.5.5 Director threading issues

      -

      25.5.6 Director performance tuning

      +

      25.5.6 Director performance tuning

      @@ -3555,7 +3572,7 @@

      25.5.6 Director performance tuning< The disadvantage is that invocation of director methods from C++ when Java doesn't actually override the method will require an additional call up into Java and back to C++. As such, this option is only useful when overrides are extremely common and instantiation is frequent enough that its performance is critical.

      -

      25.5.7 Java exceptions from directors

      +

      25.5.7 Java exceptions from directors

      @@ -3752,7 +3769,7 @@

      25.5.7 Java exceptions from dir 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 neccessary to have separate typemaps for each exception type. +it would be necessary to have separate typemaps for each exception type.
        @@ -25,12 +26,12 @@

        26 SWIG and Javascript

    • Embedded Webkit
    • Creating Applications with node-webkit
    -
  • Examples +
  • Examples
    • Simple
    • Class @@ -51,7 +52,7 @@

      26 SWIG and Javascript

      This chapter describes SWIG's support of Javascript. It does not cover SWIG basics, but only information that is specific to this module.

      -

      26.1 Overview

      +

      26.1 Overview

      Javascript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. Its arguably the most popular language for web development. @@ -62,10 +63,10 @@

      26.1 Overview

      With node-webkit there is a platform which uses Google's Chromium as Web-Browser widget and node.js for javascript extensions.

      -

      26.2 Preliminaries

      +

      26.2 Preliminaries

      -

      26.2.1 Running SWIG

      +

      26.2.1 Running SWIG

      Suppose that you defined a SWIG module such as the following:

      @@ -89,11 +90,22 @@

      26.2.1 Running SWIG

      $ swig -c++ -javascript -jsc example.i

      The V8 code that SWIG generates should work with most versions from 3.11.10 up to 3.29.14 and later.

      -

      Specify the V8 version when running SWIG (e.g. 3.25.30)

      +

      The API headers for V8 >= 4.3.0 define constants which SWIG can use to +determine the V8 version it is compiling for. For versions < 4.3.0, you +need to specify the V8 version when running SWIG. This is specified as a hex +constant, but the constant is read as pairs of decimal digits, so for V8 +3.25.30 use constant 0x032530. This scheme can't represent components > 99, +but this constant is only useful for V8 < 4.3.0, and no V8 versions from +that era had a component > 99. For example:

       $ swig -c++ -javascript -v8 -DV8_VERSION=0x032530 example.i
      +

      If you're targetting V8 >= 4.3.0, you would just run swig like so:

      +

      +
      +$ swig -c++ -javascript -v8 example.i
      +

      This creates a C/C++ source file example_wrap.c or example_wrap.cxx. The generated C source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application to create an extension module.

      The name of the wrapper file is derived from the name of the input file. For example, if the input file is example.i, the name of the wrapper file is example_wrap.c. To change this, you can use the -o option. The wrapped module will export one function which must be called to register the module with the Javascript interpreter. For example, if your module is named example the corresponding initializer for JavascriptCore would be

      @@ -109,7 +121,7 @@

      26.2.1 Running SWIG

      Note: be aware that v8 has a C++ API, and thus, the generated modules must be compiled as C++.

      -

      26.2.2 Running Tests and Examples

      +

      26.2.2 Running Tests and Examples

      The configuration for tests and examples currently supports Linux and Mac only and not MinGW (Windows) yet.

      @@ -141,7 +153,7 @@

      26.2.2 Running Tests and Exa $ make check-javascript-examples V8_VERSION=0x032530 ENGINE=v8

      -

      26.2.3 Known Issues

      +

      26.2.3 Known Issues

      At the moment, the Javascript generators pass all tests syntactically, i.e., the generated source code compiles. However, there are still remaining runtime issues.

      @@ -156,17 +168,17 @@

      26.2.3 Known Issues

    • instanceOf does not work under JSC

    -

    The primary development environment has been Linux (Ubuntu 12.04). Windows and OSX have been tested sporadically. Therefore, the generators might have more issues on those platforms. Please report back any problem you observe to help us improving this module quickly.

    +

    The primary development environment has been Linux (Ubuntu 12.04). Windows and Mac OS X have been tested sporadically. Therefore, the generators might have more issues on those platforms. Please report back any problem you observe to help us improving this module quickly.

    -

    26.3 Integration

    +

    26.3 Integration

    This chapter gives a short introduction how to use a native Javascript extension: as a node.js module, and as an extension for an embedded Webkit.

    -

    26.3.1 Creating node.js Extensions

    +

    26.3.1 Creating node.js Extensions

    -

    To install node.js you can download an installer from their web-site for OSX and Windows. For Linux you can either build the source yourself and run sudo checkinstall or keep to the (probably stone-age) packaged version. For Ubuntu there is a PPA available.

    +

    To install node.js you can download an installer from their web-site for Mac OS X and Windows. For Linux you can either build the source yourself and run sudo checkinstall or keep to the (probably stone-age) packaged version. For Ubuntu there is a PPA available.

     $ sudo add-apt-repository ppa:chris-lea/node.js
    @@ -197,10 +209,10 @@ 

    26.3.1 Creating node.js Extensions<
     $ swig -javascript -node -c++ example.i

    -

    Then run node-gyp

    +

    Then run node-gyp build to actually create the module:

    -$ node-gyp
    +$ node-gyp build

    This will create a build folder containing the native module. To use the extension you need to 'require' it in your Javascript source file:

    @@ -209,7 +221,7 @@

    26.3.1 Creating node.js Extensions<

    A more detailed explanation is given in the Examples section.

    -

    26.3.1.1 Troubleshooting

    +

    26.3.1.1 Troubleshooting

      @@ -221,12 +233,12 @@

      26.3.1.1 Troubleshooting

      $ sudo apt-get remove gyp -

      26.3.2 Embedded Webkit

      +

      26.3.2 Embedded Webkit

      -

      Webkit is pre-installed on OSX and available as a library for GTK.

      +

      Webkit is pre-installed on Mac OS X and available as a library for GTK.

      -

      26.3.2.1 OSX

      +

      26.3.2.1 Mac OS X

      There is general information about programming with WebKit on Apple Developer Documentation. Details about Cocoa programming are not covered here.

      @@ -274,7 +286,7 @@

      26.3.2.1 OSX

      @end -

      26.3.2.2 GTK

      +

      26.3.2.2 GTK

      There is general information about programming GTK at GTK documentation and in the GTK tutorial, and for Webkit there is a Webkit GTK+ API Reference.

      @@ -319,7 +331,7 @@

      26.3.2.2 GTK

      } -

      26.3.3 Creating Applications with node-webkit

      +

      26.3.3 Creating Applications with node-webkit

      To get started with node-webkit there is a very informative set of wiki pages.

      @@ -348,7 +360,7 @@

      26.3.3 Creating Applications wi

      - package.json: +package.json:

      @@ -368,7 +380,7 @@ 

      26.3.3 Creating Applications wi the main window.

      - app.html: +app.html:

      @@ -395,7 +407,7 @@

      26.3.3 Creating Applications wi

      - app.js: +app.js:

      @@ -410,12 +422,12 @@

      26.3.3 Creating Applications wi };

      -

      26.4 Examples

      +

      26.4 Examples

      Some basic examples are shown here in more detail.

      -

      26.4.1 Simple

      +

      26.4.1 Simple

      The common example simple looks like this:

      @@ -465,7 +477,7 @@

      26.4.1 Simple

      Note: ECMAScript 5, the currently implemented Javascript standard, does not have modules. node.js and other implementations provide this mechanism defined by the CommonJS group. For browsers this is provided by Browserify, for instance.

      -

      26.4.2 Class

      +

      26.4.2 Class

      The common example class defines three classes, Shape, Circle, and Square:

      @@ -595,12 +607,12 @@

      26.4.2 Class

      Note: In ECMAScript 5 there is no concept for classes. Instead each function can be used as a constructor function which is executed by the 'new' operator. Furthermore, during construction the key property prototype of the constructor function is used to attach a prototype instance to the created object. A prototype is essentially an object itself that is the first-class delegate of a class used whenever the access to a property of an object fails. The very same prototype instance is shared among all instances of one type. Prototypal inheritance is explained in more detail on in Inheritance and the prototype chain, for instance.

      -

      26.5 Implementation

      +

      26.5 Implementation

      The Javascript Module implementation has taken a very different approach compared to other language modules in order to support different Javascript interpreters.

      -

      26.5.1 Source Code

      +

      26.5.1 Source Code

      The Javascript module is implemented in Source/Modules/javascript.cxx. It dispatches the code generation to a JSEmitter instance, V8Emitter or JSCEmitter. Additionally there are some helpers: Template, for templated code generation, and JSEmitterState, which is used to manage state information during AST traversal. This rough map shall make it easier to find a way through this huge source file:

      @@ -701,7 +713,7 @@

      26.5.1 Source Code

      ... -

      26.5.2 Code Templates

      +

      26.5.2 Code Templates

      All generated code is created on the basis of code templates. The templates for JavascriptCore can be found in Lib/javascript/jsc/javascriptcode.swg, for v8 in Lib/javascript/v8/javascriptcode.swg.

      @@ -740,7 +752,7 @@

      26.5.2 Code Templates

      Template creates a copy of that string and Template::replace uses Swig's Replaceall to replace variables in the template. Template::trim can be used to eliminate leading and trailing whitespaces. Template::print is used to write the final template string to a Swig DOH (based on Printv). All methods allow chaining.

      -

      26.5.3 Emitter

      +

      26.5.3 Emitter

      The Javascript module delegates code generation to a JSEmitter instance. The following extract shows the essential interface:

      @@ -859,7 +871,7 @@

      26.5.3 Emitter

      In enterClass the emitter stores state information that is necessary when processing class members. In exitClass the wrapper code for the whole class is generated.

      -

      26.5.4 Emitter states

      +

      26.5.4 Emitter states

      For storing information during the AST traversal the emitter provides a JSEmitterState with different slots to store data representing the scopes global, class, function, and variable.

      @@ -903,7 +915,7 @@

      26.5.4 Emitter states

      State information can be retrieved using state.clazz(NAME) or with Getattr on state.clazz() which actually returns a Hash instance.

      -

      26.5.5 Handling Exceptions in JavascriptCore

      +

      26.5.5 Handling Exceptions in JavascriptCore

      Applications with an embedded JavascriptCore should be able to present detailed exception messages that occur in the Javascript engine. Below is an example derived from code provided by Brian Barnes on how these exception details can be extracted.

      diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 740988e71eb..954de54f7a0 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -1,12 +1,13 @@ - + SWIG Library + -

      9 SWIG library

      +

      9 SWIG library

        @@ -59,7 +60,7 @@

        9 SWIG library

        carefully if you used the old libraries.

        -

        9.1 The %include directive and library search path

        +

        9.1 The %include directive and library search path

        @@ -91,7 +92,7 @@

        9.1 The %include directive and library search path The directories that are searched are displayed when using -verbose commandline option.

        -

        9.2 C Arrays and Pointers

        +

        9.2 C Arrays and Pointers

        @@ -103,7 +104,7 @@

        9.2 C Arrays and Pointers

        memory, their use is potentially unsafe and you should exercise caution.

        -

        9.2.1 cpointer.i

        +

        9.2.1 cpointer.i

        @@ -319,7 +320,7 @@

        9.2.1 cpointer.i

        Note: When working with simple pointers, typemaps can often be used to provide more seamless operation.

        -

        9.2.2 carrays.i

        +

        9.2.2 carrays.i

        @@ -497,7 +498,7 @@

        9.2.2 carrays.i

        used with types of char or char *.

        -

        9.2.3 cmalloc.i

        +

        9.2.3 cmalloc.i

        @@ -658,7 +659,7 @@

        9.2.3 cmalloc.i

      -

      9.2.4 cdata.i

      +

      9.2.4 cdata.i

      @@ -760,7 +761,7 @@

      9.2.4 cdata.i

      Clearly they are unsafe.

      -

      9.3 C String Handling

      +

      9.3 C String Handling

      @@ -780,7 +781,7 @@

      9.3 C String Handling

      for manipulating raw C strings.

      -

      9.3.1 Default string handling

      +

      9.3.1 Default string handling

      @@ -821,7 +822,7 @@

      9.3.1 Default string handling

      not work well with binary data. Instead, strings are assumed to be NULL-terminated.

      -

      9.3.2 Passing binary data

      +

      9.3.2 Passing binary data

      @@ -863,7 +864,7 @@

      9.3.2 Passing binary data

      The (char *STRING, int LENGTH) multi-argument typemap is also available in addition to (char *STRING, size_t LENGTH).

      -

      9.3.3 Using %newobject to release memory

      +

      9.3.3 Using %newobject to release memory

      @@ -904,7 +905,7 @@

      9.3.3 Using %newobject to release memory

      See Object ownership and %newobject for more details.

      -

      9.3.4 cstring.i

      +

      9.3.4 cstring.i

      @@ -1364,7 +1365,7 @@

      9.3.4 cstring.i

    -

    9.4 STL/C++ Library

    +

    9.4 STL/C++ Library

    @@ -1392,7 +1393,8 @@

    9.4 STL/C++ Library

    std::set set std_set.i std::string string std_string.i std::vector vector std_vector.i - std::shared_ptr shared_ptr std_shared_ptr.i + std::array array (C++11) std_array.i + std::shared_ptr shared_ptr (C++11) std_shared_ptr.i @@ -1402,7 +1404,7 @@

    9.4 STL/C++ Library

    -

    9.4.1 std::string

    +

    9.4.1 std::string

    @@ -1486,7 +1488,7 @@

    9.4.1 std::string

    -

    9.4.2 std::vector

    +

    9.4.2 std::vector

    @@ -1665,7 +1667,7 @@

    9.4.2 std::vector

    details and the public API exposed to the interpreter vary.

    -

    9.4.3 STL exceptions

    +

    9.4.3 STL exceptions

    @@ -1715,7 +1717,7 @@

    9.4.3 STL exceptions

    Any thrown STL exceptions will then be gracefully handled instead of causing a crash.

    -

    9.4.4 shared_ptr smart pointer

    +

    9.4.4 shared_ptr smart pointer

    @@ -1900,11 +1902,13 @@

    9.4.4 shared_ptr smart pointer

    -Note: There is currently no support for %shared_ptr and the director feature. +Note: There is somewhat limited support for %shared_ptr and the director feature +and the degress of success varies among the different target languages. +Please help to improve this support by providing patches with improvements.

    -

    9.4.5 auto_ptr smart pointer

    +

    9.4.5 auto_ptr smart pointer

    @@ -1953,10 +1957,10 @@

    9.4.5 auto_ptr smart pointer

    -

    9.5 Utility Libraries

    +

    9.5 Utility Libraries

    -

    9.5.1 exception.i

    +

    9.5.1 exception.i

    diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 0b8d47846b1..0867ba926b2 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -1,12 +1,13 @@ - + SWIG and Common Lisp + -

    27 SWIG and Common Lisp

    +

    27 SWIG and Common Lisp

      @@ -41,7 +42,7 @@

      27 SWIG and Common Lisp

      Lisp, Common Foreign Function Interface(CFFI), CLisp and UFFI foreign function interfaces.

      -

      27.1 Allegro Common Lisp

      +

      27.1 Allegro Common Lisp

      @@ -50,7 +51,7 @@

      27.1 Allegro Common Lisp

      here

      -

      27.2 Common Foreign Function Interface(CFFI)

      +

      27.2 Common Foreign Function Interface(CFFI)

      @@ -77,7 +78,7 @@

      27.2 Common Foreign Function Interface(CFFI)

      files and the various things which you can do with them.

      -

      27.2.1 Additional Commandline Options

      +

      27.2.1 Additional Commandline Options

      @@ -118,7 +119,7 @@

      27.2.1 Additional Commandline Options

      -

      27.2.2 Generating CFFI bindings

      +

      27.2.2 Generating CFFI bindings

      As we mentioned earlier the ideal way to use SWIG is to use interface @@ -219,19 +220,19 @@

      27.2.2 Generating CFFI bindings

      (cl:defconstant x (cl:ash 5 -1)) (cffi:defcstruct bar - (p :short) - (q :short) - (a :char) - (b :char) - (z :pointer) - (n :pointer)) + (p :short) + (q :short) + (a :char) + (b :char) + (z :pointer) + (n :pointer)) (cffi:defcvar ("my_struct" my_struct) :pointer) (cffi:defcstruct foo - (a :int) - (b :pointer)) + (a :int) + (b :pointer)) (cffi:defcfun ("pointer_func" pointer_func) :int (ClosureFun :pointer) @@ -247,9 +248,9 @@

      27.2.2 Generating CFFI bindings

      (array :pointer)) (cffi:defcenum color - :RED - :BLUE - :GREEN) + :RED + :BLUE + :GREEN)

    @@ -284,9 +285,11 @@

    27.2.2 Generating CFFI bindings

    %feature("export"); %feature("inline") lispsort_double; - %feature("intern_function", "my-lispify") lispsort_double; +%feature("export", package="'some-other-package") lispsort_double; + %rename func123 renamed_cool_func; + %ignore "pointer_func"; %include "test.h" @@ -310,12 +313,13 @@

    27.2.2 Generating CFFI bindings

    lispsort_double;, here we are using an additional feature which allows us to use our lispify function.

    -

    The export feature allows us to export the symbols. The inline - feature declaims the declared function as inline. The rename - directive allows us to change the name(it is useful when - generating C wrapper code for handling overloaded - functions). The ignore directive ignores a certain - declaration. +

    The export feature allows us to export the symbols. If + the package argument is given, then the symbol will be exported to + the specified Lisp package. The inline feature declaims the + declared function as inline. The rename directive allows us to + change the name(it is useful when generating C wrapper code for handling + overloaded functions). The ignore directive ignores a certain + declaration.

    There are several other things which are possible, to see some example of usage of SWIG look at the Lispbuilder and wxCL @@ -332,12 +336,12 @@

    27.2.2 Generating CFFI bindings

    (cl:export '#.(swig-lispify "x" 'constant)) (cffi:defcstruct #.(swig-lispify "bar" 'classname) - (#.(swig-lispify "p" 'slotname) :short) - (#.(swig-lispify "q" 'slotname) :short) - (#.(swig-lispify "a" 'slotname) :char) - (#.(swig-lispify "b" 'slotname) :char) - (#.(swig-lispify "z" 'slotname) :pointer) - (#.(swig-lispify "n" 'slotname) :pointer)) + (#.(swig-lispify "p" 'slotname) :short) + (#.(swig-lispify "q" 'slotname) :short) + (#.(swig-lispify "a" 'slotname) :char) + (#.(swig-lispify "b" 'slotname) :char) + (#.(swig-lispify "z" 'slotname) :pointer) + (#.(swig-lispify "n" 'slotname) :pointer)) (cl:export '#.(swig-lispify "bar" 'classname)) @@ -359,8 +363,8 @@

    27.2.2 Generating CFFI bindings

    (cl:export '#.(swig-lispify "my_struct" 'variable)) (cffi:defcstruct #.(swig-lispify "foo" 'classname) - (#.(swig-lispify "a" 'slotname) :int) - (#.(swig-lispify "b" 'slotname) :pointer)) + (#.(swig-lispify "a" 'slotname) :int) + (#.(swig-lispify "b" 'slotname) :pointer)) (cl:export '#.(swig-lispify "foo" 'classname)) @@ -381,18 +385,18 @@

    27.2.2 Generating CFFI bindings

    (n :int) (array :pointer)) -(cl:export '#.(my-lispify "lispsort_double" 'function)) +(cl:export '#.(my-lispify "lispsort_double" 'function) 'some-other-package) (cffi:defcenum #.(swig-lispify "color" 'enumname) - #.(swig-lispify "RED" 'enumvalue :keyword) - #.(swig-lispify "BLUE" 'enumvalue :keyword) - #.(swig-lispify "GREEN" 'enumvalue :keyword)) + #.(swig-lispify "RED" 'enumvalue :keyword) + #.(swig-lispify "BLUE" 'enumvalue :keyword) + #.(swig-lispify "GREEN" 'enumvalue :keyword)) (cl:export '#.(swig-lispify "color" 'enumname)) -

    27.2.3 Generating CFFI bindings for C++ code

    +

    27.2.3 Generating CFFI bindings for C++ code

    This feature to SWIG (for CFFI) is very new and still far from @@ -568,7 +572,7 @@

    27.2.3 Generating CFFI bindings for C++ code

    module feel free to contact us on the SWIG mailing list, and also please add a "[CFFI]" tag in the subject line. -

    27.2.4 Inserting user code into generated files

    +

    27.2.4 Inserting user code into generated files

    @@ -608,7 +612,7 @@

    27.2.4 Inserting user code into generated files

    -

    27.3 CLISP

    +

    27.3 CLISP

    @@ -638,7 +642,7 @@

    27.3 CLISP

    interface file for the CLISP module. The CLISP module tries to produce code which is both human readable and easily modifyable.

    -

    27.3.1 Additional Commandline Options

    +

    27.3.1 Additional Commandline Options

    @@ -658,33 +662,33 @@

    27.3.1 Additional Commandline Options

    -extern-all If this option is given then clisp definitions for all the functions
    and global variables will be created otherwise only definitions for
    - externed functions and variables are created. +externed functions and variables are created. -generate-typedef If this option is given then def-c-type will be used to generate
    - shortcuts according to the typedefs in the input. +shortcuts according to the typedefs in the input. -

    27.3.2 Details on CLISP bindings

    +

    27.3.2 Details on CLISP bindings

    As mentioned earlier the CLISP bindings generated by SWIG may need - some modifications. The clisp module creates a lisp file with - the same name as the module name. This - lisp file contains a 'defpackage' declaration, with the - package name same as the module name. This package uses the - 'common-lisp' and 'ffi' packages. Also, package exports all - the functions, structures and variables for which an ffi - binding was generated.
    - After generating the defpackage statement, the clisp module also - sets the default language. +some modifications. The clisp module creates a lisp file with +the same name as the module name. This +lisp file contains a 'defpackage' declaration, with the +package name same as the module name. This package uses the +'common-lisp' and 'ffi' packages. Also, package exports all +the functions, structures and variables for which an ffi +binding was generated.
    +After generating the defpackage statement, the clisp module also +sets the default language.

     (defpackage :test
    @@ -734,18 +738,18 @@ 

    27.3.2 Details on CLISP bindings

    (ffi:def-call-out pointer_func (:name "pointer_func") (:arguments (ClosureFun (ffi:c-function (:arguments (arg0 (ffi:c-pointer NIL)) - (arg1 (ffi:c-pointer NIL)) - (arg2 (ffi:c-pointer NIL))) - (:return-type NIL))) - (y ffi:int)) + (arg1 (ffi:c-pointer NIL)) + (arg2 (ffi:c-pointer NIL))) + (:return-type NIL))) + (y ffi:int)) (:return-type ffi:int) (:library +library-name+)) (ffi:def-call-out func123 (:name "func123") (:arguments (x (ffi:c-pointer div_t)) - (z (ffi:c-ptr (ffi:c-array (ffi:c-ptr (ffi:c-ptr ffi:int)) 100))) - (y (ffi:c-ptr (ffi:c-ptr (ffi:c-array ffi:int (1000 10)))))) + (z (ffi:c-ptr (ffi:c-array (ffi:c-ptr (ffi:c-ptr ffi:int)) 100))) + (y (ffi:c-ptr (ffi:c-ptr (ffi:c-array ffi:int (1000 10)))))) (:return-type ffi:int) (:library +library-name+)) @@ -753,14 +757,14 @@

    27.3.2 Details on CLISP bindings

    (ffi:def-call-out lispsort_double (:name "lispsort_double") (:arguments (n ffi:int) - (array (ffi:c-ptr DOUBLE-FLOAT))) + (array (ffi:c-ptr DOUBLE-FLOAT))) (:return-type NIL) (:library +library-name+)) (ffi:def-call-out test123 (:name "test") (:arguments (x SINGLE-FLOAT) - (y DOUBLE-FLOAT)) + (y DOUBLE-FLOAT)) (:return-type NIL) (:library +library-name+)) @@ -795,7 +799,7 @@

    27.3.2 Details on CLISP bindings

    -

    27.4 UFFI

    +

    27.4 UFFI

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 61f19be6849..004ca6f2b08 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -1,12 +1,13 @@ - + SWIG and Lua + -

    28 SWIG and Lua

    +

    28 SWIG and Lua

      @@ -82,14 +83,14 @@

      28 SWIG and Lua

      eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers the full implementation of the Lua programming language to the embedded world, extending it with specific features for efficient and portable software embedded development. eLua runs on smaller devices like microcontrollers and provides the full features of the regular Lua desktop version. More information on eLua can be found here: http://www.eluaproject.net

      -

      28.1 Preliminaries

      +

      28.1 Preliminaries

      The current SWIG implementation is designed to work with Lua 5.0.x, 5.1.x and 5.2.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also has support for eLua starting from eLua 0.8. Due to substantial changes between SWIG 2.x and SWIG 3.0 and unavailability of testing platform, eLua status was downgraded to 'experimental'.

      -

      28.2 Running SWIG

      +

      28.2 Running SWIG

      @@ -137,7 +138,7 @@

      28.2 Running SWIG

      The -elua option puts all the C function wrappers and variable get/set wrappers in rotables. It also generates a metatable which will control the access to these variables from eLua. It also offers a significant amount of module size compression. On the other hand, the -eluac option puts all the wrappers in a single rotable. With this option, no matter how huge the module, it will consume no additional microcontroller SRAM (crass compression). There is a catch though: Metatables are not generated with -eluac. To access any value from eLua, one must directly call the wrapper function associated with that value.

      -

      28.2.1 Additional command line options

      +

      28.2.1 Additional command line options

      @@ -178,7 +179,7 @@

      28.2.1 Additional command line options

      -

      28.2.2 Compiling and Linking and Interpreter

      +

      28.2.2 Compiling and Linking and Interpreter

      @@ -201,8 +202,8 @@

      28.2.2 Compiling and Linking and Interpreter

      return 0; } L=lua_open(); - luaopen_base(L); // load basic libs (eg. print) - luaopen_example(L); // load the wrapped module + luaopen_base(L); // load basic libs (eg. print) + luaopen_example(L); // load the wrapped module if (luaL_loadfile(L,argv[1])==0) // load and run the file lua_pcall(L,0,0,0); else @@ -249,7 +250,7 @@

      28.2.2 Compiling and Linking and Interpreter

      More information on building and configuring eLua can be found here: http://www.eluaproject.net/doc/v0.8/en_building.html

      -

      28.2.3 Compiling a dynamic module

      +

      28.2.3 Compiling a dynamic module

      @@ -317,7 +318,7 @@

      28.2.3 Compiling a dynamic module

      -

      28.2.4 Using your module

      +

      28.2.4 Using your module

      @@ -335,19 +336,19 @@

      28.2.4 Using your module

      >
    -

    28.3 A tour of basic C/C++ wrapping

    +

    28.3 A tour of basic C/C++ wrapping

    By default, SWIG tries to build a very natural Lua interface to your C/C++ code. This section briefly covers the essential aspects of this wrapping.

    -

    28.3.1 Modules

    +

    28.3.1 Modules

    The SWIG module directive specifies the name of the Lua module. If you specify `module example', then everything is wrapped into a Lua table 'example' containing all the functions and variables. When choosing a module name, make sure you don't use the same name as a built-in Lua command or standard module name.

    -

    28.3.2 Functions

    +

    28.3.2 Functions

    @@ -388,7 +389,7 @@

    28.3.2 Functions

    24 -

    28.3.3 Global variables

    +

    28.3.3 Global variables

    @@ -476,7 +477,7 @@

    28.3.3 Global variables

    In general, functions of the form "variable_get()" and "variable_set()" are automatically generated by SWIG for use with -eluac.

    -

    28.3.4 Constants and enums

    +

    28.3.4 Constants and enums

    @@ -511,7 +512,7 @@

    28.3.4 Constants and enums

    Hello World -

    28.3.4.1 Constants/enums and classes/structures

    +

    28.3.4.1 Constants/enums and classes/structures

    @@ -567,7 +568,7 @@

    28.3.4.1 Constants/enums and classes/structures

    It is worth mentioning, that example.Test.TEST1 and example.Test_TEST1 are different entities and changing one does not change the other. Given the fact that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.

    -

    28.3.5 Pointers

    +

    28.3.5 Pointers

    @@ -605,7 +606,7 @@

    28.3.5 Pointers

    nil -

    28.3.6 Structures

    +

    28.3.6 Structures

    @@ -709,7 +710,7 @@

    28.3.6 Structures

    In general, functions of the form "new_struct()", "struct_member_get()", "struct_member_set()" and "free_struct()" are automatically generated by SWIG for each structure defined in C. (Please note: This doesn't apply for modules generated with the -elua option)

    -

    28.3.7 C++ classes

    +

    28.3.7 C++ classes

    @@ -784,7 +785,7 @@

    28.3.7 C++ classes

    However, if the -no-old-metatable-bindings option is used, then the backward compatible names are not generated in addition to ordinary ones.

    -

    28.3.8 C++ inheritance

    +

    28.3.8 C++ inheritance

    @@ -809,7 +810,7 @@

    28.3.8 C++ inheritance

    It is safe to use multiple inheritance with SWIG.

    -

    28.3.9 Pointers, references, values, and arrays

    +

    28.3.9 Pointers, references, values, and arrays

    @@ -840,7 +841,7 @@

    28.3.9 Pointers, references, values, and arrays

    then all three functions will return a pointer to some Foo object. Since the third function (spam7) returns a value, newly allocated memory is used to hold the result and a pointer is returned (Lua will release this memory when the return value is garbage collected). The other two are pointers which are assumed to be managed by the C code and so will not be garbage collected.

    -

    28.3.10 C++ overloaded functions

    +

    28.3.10 C++ overloaded functions

    @@ -891,7 +892,7 @@

    28.3.10 C++ overloaded functions

    or

    -
    VOID FOO(bAR *B);
    +
    void foo(Bar *b);
     void foo(Bar &b);
     

    @@ -926,7 +927,7 @@

    28.3.10 C++ overloaded functions

    Dealing with the Lua coercion mechanism, the priority is roughly (integers, floats, strings, userdata). But it is better to rename the functions rather than rely upon the ordering.

    -

    28.3.11 C++ operators

    +

    28.3.11 C++ operators

    @@ -1060,7 +1061,7 @@

    28.3.11 C++ operators

    No other lua metafunction is inherited. For example, __gc is not inherited and must be redefined in every class. __tostring is subject to a special handling. If absent in class and in class bases, a default one will be provided by SWIG.

    -

    28.3.12 Class extension with %extend

    +

    28.3.12 Class extension with %extend

    @@ -1116,7 +1117,7 @@

    28.3.12 Class extension with %extend

    Extend works with both C and C++ code, on classes and structs. It does not modify the underlying object in any way---the extensions only show up in the Lua interface. The only item to take note of is the code has to use the '$self' instead of 'this', and that you cannot access protected/private members of the code (as you are not officially part of the class).

    -

    28.3.13 Using %newobject to release memory

    +

    28.3.13 Using %newobject to release memory

    If you have a function that allocates memory like this,

    @@ -1140,7 +1141,7 @@

    28.3.13 Using %newobject to release memory

    This will release the allocated memory.

    -

    28.3.14 C++ templates

    +

    28.3.14 C++ templates

    @@ -1175,7 +1176,7 @@

    28.3.14 C++ templates

    Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter. Some more complicated examples will appear later.

    -

    28.3.15 C++ Smart Pointers

    +

    28.3.15 C++ Smart Pointers

    @@ -1227,7 +1228,7 @@

    28.3.15 C++ Smart Pointers

    > f = p:__deref__() -- Returns underlying Foo * -

    28.3.16 C++ Exceptions

    +

    28.3.16 C++ Exceptions

    @@ -1370,7 +1371,7 @@

    28.3.16 C++ Exceptions

    add exception specification to functions or globally (respectively).

    -

    28.3.17 Namespaces

    +

    28.3.17 Namespaces

    @@ -1421,7 +1422,7 @@

    28.3.17 Namespaces

    19 > -

    28.3.17.1 Compatibility Note

    +

    28.3.17.1 Compatibility Note

    @@ -1437,7 +1438,7 @@

    28.3.17.1 Compatibility Note

    -

    28.3.17.2 Names

    +

    28.3.17.2 Names

    If SWIG is launched without -no-old-metatable-bindings option, then it enters backward-compatible mode. While in this mode, it tries @@ -1481,7 +1482,7 @@

    28.3.17.2 Names

    > -

    28.3.17.3 Inheritance

    +

    28.3.17.3 Inheritance

    The internal organization of inheritance has changed. @@ -1522,12 +1523,12 @@

    28.3.17.3 Inheritance

    > -

    28.4 Typemaps

    +

    28.4 Typemaps

    This section explains what typemaps are and how to use them. The default wrapping behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrapping. This section will be explaining how to use typemaps to best effect

    -

    28.4.1 What is a typemap?

    +

    28.4.1 What is a typemap?

    A typemap is nothing more than a code generation rule that is attached to a specific C datatype. For example, to convert integers from Lua to C, you might define a typemap like this:

    @@ -1535,8 +1536,8 @@

    28.4.1 What is a typemap?

    %module example
     
     %typemap(in) int {
    -	$1 = (int) lua_tonumber(L,$input);
    -	printf("Received an integer : %d\n",$1);
    +  $1 = (int) lua_tonumber(L,$input);
    +  printf("Received an integer : %d\n",$1);
     }
     %inline %{
     extern int fact(int n);
    @@ -1555,7 +1556,7 @@ 

    28.4.1 What is a typemap?

    720
    -

    28.4.2 Using typemaps

    +

    28.4.2 Using typemaps

    There are many ready written typemaps built into SWIG for all common types (int, float, short, long, char*, enum and more), which SWIG uses automatically, with no effort required on your part.

    @@ -1608,7 +1609,7 @@

    28.4.2 Using typemaps

    Note: C++ references must be handled exactly the same way. However SWIG will automatically wrap a const int& as an input parameter (since that it obviously input).

    -

    28.4.3 Typemaps and arrays

    +

    28.4.3 Typemaps and arrays

    Arrays present a challenge for SWIG, because like pointers SWIG does not know whether these are input or output values, nor @@ -1672,7 +1673,7 @@

    28.4.3 Typemaps and arrays

    Note: SWIG also can support arrays of pointers in a similar manner.

    -

    28.4.4 Typemaps and pointer-pointer functions

    +

    28.4.4 Typemaps and pointer-pointer functions

    Several C++ libraries use a pointer-pointer functions to create its objects. These functions require a pointer to a pointer which is then filled with the pointer to the new object. Microsoft's COM and DirectX as well as many other libraries have this kind of function. An example is given below:

    @@ -1706,7 +1707,7 @@

    28.4.4 Typemaps and pointer-poi ptr=nil -- the iMath* will be GC'ed as normal -

    28.5 Writing typemaps

    +

    28.5 Writing typemaps

    This section describes how you can modify SWIG's default wrapping behavior for various C/C++ datatypes using the %typemap directive. This is an advanced topic that assumes familiarity with the Lua C API as well as the material in the "Typemaps" chapter.

    @@ -1715,7 +1716,7 @@

    28.5 Writing typemaps

    Before proceeding, you should read the previous section on using typemaps, and look at the existing typemaps found in luatypemaps.swg and typemaps.i. These are both well documented and fairly easy to read. You should not attempt to write your own typemaps until you have read and can understand both of these files (they may well also give you an idea to base your work on).

    -

    28.5.1 Typemaps you can write

    +

    28.5.1 Typemaps you can write

    There are many different types of typemap that can be written, the full list can be found in the "Typemaps" chapter. However the following are the most commonly used ones.

    @@ -1728,7 +1729,7 @@

    28.5.1 Typemaps you can write

    (the syntax for the typecheck is different from the typemap, see typemaps for details).
  • -

    28.5.2 SWIG's Lua-C API

    +

    28.5.2 SWIG's Lua-C API

    This section explains the SWIG specific Lua-C API. It does not cover the main Lua-C api, as this is well documented and not worth covering.

    @@ -1777,7 +1778,7 @@

    28.5.2 SWIG's Lua-C API

    Similar to SWIG_fail_arg, except that it will display the swig_type_info information instead.
    -

    28.6 Customization of your Bindings

    +

    28.6 Customization of your Bindings

    @@ -1786,7 +1787,7 @@

    28.6 Customization of your Bindings

    -

    28.6.1 Writing your own custom wrappers

    +

    28.6.1 Writing your own custom wrappers

    @@ -1805,7 +1806,7 @@

    28.6.1 Writing your own custom wrappers

    The %native directive in the above example, tells SWIG that there is a function int native_function(lua_State*L); which is to be added into the module under the name 'my_func'. SWIG will not add any wrapper for this function, beyond adding it into the function table. How you write your code is entirely up to you.

    -

    28.6.2 Adding additional Lua code

    +

    28.6.2 Adding additional Lua code

    @@ -1843,7 +1844,7 @@

    28.6.2 Adding additional Lua code

    See Examples/lua/arrays for an example of this code.

    -

    28.7 Details on the Lua binding

    +

    28.7 Details on the Lua binding

    @@ -1854,7 +1855,7 @@

    28.7 Details on the Lua binding

    -

    28.7.1 Binding global data into the module.

    +

    28.7.1 Binding global data into the module.

    @@ -1914,7 +1915,7 @@

    28.7.1 Binding global data into the module.

    That way when you call 'a=example.Foo', the interpreter looks at the table 'example' sees that there is no field 'Foo' and calls __index. This will in turn check in '.get' table and find the existence of 'Foo' and then return the value of the C function call 'Foo_get()'. Similarly for the code 'example.Foo=10', the interpreter will check the table, then call the __newindex which will then check the '.set' table and call the C function 'Foo_set(10)'.

    -

    28.7.2 Userdata and Metatables

    +

    28.7.2 Userdata and Metatables

    @@ -1994,7 +1995,7 @@

    28.7.2 Userdata and Metatables

    Note: Operator overloads are basically done in the same way, by adding functions such as '__add' & '__call' to the class' metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.

    -

    28.7.3 Memory management

    +

    28.7.3 Memory management

    diff --git a/Doc/Manual/Makefile b/Doc/Manual/Makefile index 5112afa3318..c7769dc9763 100644 --- a/Doc/Manual/Makefile +++ b/Doc/Manual/Makefile @@ -9,7 +9,7 @@ # validation. # # Additional html validation can be done using the validate target. -# Additional link checking can be done using the linkchecker target. +# Additional link checking can be done using the linkchecker1 and linkchecker2 target. # # Note the # and " are escaped @@ -19,31 +19,34 @@ HTMLDOC_OPTIONS = "--book --toclevels 4 --no-numbered --toctitle \"Table of Cont all: maketoc check generate -maketoc: CCache.html +maketoc: python maketoc.py +# Use this to regenerate CCache.html should this ever be needed CCache.html: ../../CCache/ccache.yo yodl2html -o CCache.html ../../CCache/ccache.yo +# Tabs in the html files will stop the build as wkhtmltopdf does not expand them correctly - replace them with the appropriate number of tabs # Use htmltidy to warn about some HTML errors. Note that it is not used to clean/tidy the HTML, # it is just used as a primitive HTML checker. # CCache.html is generated by yodl2html and has a few insignificant problems, so we don't put it through tidy check: - tidy -errors --gnu-emacs yes -quiet index.html - tidy -errors --gnu-emacs yes -quiet Sections.html - all=`sed '/^#/d' chapters | grep -v CCache.html`; for a in $$all; do tidy -errors --gnu-emacs yes -quiet $$a; done; + all="index.html Sections.html `sed '/^#/d' chapters | grep -v CCache.html`" && for a in $$all; do echo "Check for tabs $$a" && if grep -P '\t' $$a; then echo "Please delete the tabs from the lines above" && exit 1; fi; done && for a in $$all; do echo "HTML tidy check $$a" && tidy -errors --gnu-emacs yes -quiet $$a; done; -generate: swightml.book swigpdf.book +# Note wkhtmltopdf limitations for generating pdf docs: +# 1)

    Text

    style links don't work and need changing to +#

    Text

    +# 2) Tabs in
     elements should be expanded to 8 spaces by default, but
    +#     are expanded to just one space and css tab-size is not working.
    +#  3) 
       elements do not always select a fixed-width font - try installing the
    +#     Courier font to fix - these have been added to style.css.
    +generate: SWIGDocumentation.html
    +	wkhtmltopdf --margin-top 20mm --margin-bottom 20mm --margin-left 10mm --margin-right 10mm --header-font-size 6 --footer-font-size 6 --header-spacing 6 --footer-spacing 6 --header-center '[doctitle]' --footer-left '[subsection]' --footer-right '[page]' SWIGDocumentation.html SWIGDocumentation.pdf
    +
    +SWIGDocumentation.html: swightml.book
     	htmldoc --batch swightml.book || true
    -	htmldoc --batch swigpdf.book || true
     	python fixstyle.py SWIGDocumentation.html
     
    -swigpdf.book: chapters Sections.html
    -	echo "#HTMLDOC 1.8.24" > swigpdf.book
    -	echo -t pdf13 -f SWIGDocumentation.pdf $(HTMLDOC_OPTIONS) --stylesheet style.css >> swigpdf.book
    -	echo "Sections.html" >> swigpdf.book
    -	cat chapters >> swigpdf.book
    -
     swightml.book: chapters Sections.html
     	echo "#HTMLDOC 1.8.24" > swightml.book
     	echo -t html -f SWIGDocumentation.html $(HTMLDOC_OPTIONS) >> swightml.book
    @@ -52,10 +55,9 @@ swightml.book: chapters Sections.html
     
     maintainer-clean: clean-baks
     	rm -f swightml.book
    -	rm -f swigpdf.book
    -	rm -f CCache.html
     	rm -f SWIGDocumentation.html
     	rm -f SWIGDocumentation.pdf
    +	rm -rf linkchecker-tmp
     
     clean-baks:
     	rm -f *.bak
    @@ -69,9 +71,18 @@ test:
     validate:
     	all=`sed '/^#/d' chapters`; for a in $$all; do validate --emacs $$a; done;
     
    -# Link checking using linkchecker
    -linkchecker:
    +# Link checking using linkchecker of the index.html only file (including anchors)
    +linkchecker1:
     	@echo -----------------------------------------------------------------------
     	@echo Note linkchecker versions prior to 6.1 do not work properly wrt anchors
     	@echo -----------------------------------------------------------------------
    -	linkchecker --config=./linkchecker.config index.html
    +	linkchecker --config=./linkchecker.config --anchors index.html
    +
    +# Check for links which don't work including those generated from the individual .html files into SWIGDocumentation.html
    +linkchecker2:
    +	rm -rf linkchecker-tmp
    +	mkdir linkchecker-tmp
    +	cp SWIGDocumentation.html linkchecker-tmp
    +	cp *.png linkchecker-tmp
    +	(cd linkchecker-tmp && linkchecker --config=../linkchecker.config -F text --no-warnings SWIGDocumentation.html)
    +
    diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html
    index ffbf6132dc4..f324495a39b 100644
    --- a/Doc/Manual/Modula3.html
    +++ b/Doc/Manual/Modula3.html
    @@ -1,11 +1,12 @@
    -
    +
     
     
     SWIG and Modula-3
     
    +
     
     
    -

    29 SWIG and Modula-3

    +

    29 SWIG and Modula-3

    -

    29.4.5 Exceptions

    +

    29.4.5 Exceptions

    @@ -816,7 +817,7 @@

    29.4.5 Exceptions

    %typemap("m3wrapinconv:throws") blah * %{OSError.E%}.

    -

    29.4.6 Example

    +

    29.4.6 Example

    @@ -863,10 +864,10 @@

    29.4.6 Example

    -

    29.5 More hints to the generator

    +

    29.5 More hints to the generator

    -

    29.5.1 Features

    +

    29.5.1 Features

    @@ -903,7 +904,7 @@

    29.5.1 Features

    -

    29.5.2 Pragmas

    +

    29.5.2 Pragmas

    @@ -926,7 +927,7 @@

    29.5.2 Pragmas

    -

    29.6 Remarks

    +

    29.6 Remarks

      diff --git a/Doc/Manual/Modules.html b/Doc/Manual/Modules.html index 551fd075040..089b1a4adf9 100644 --- a/Doc/Manual/Modules.html +++ b/Doc/Manual/Modules.html @@ -1,12 +1,13 @@ - + Working with Modules + -

      16 Working with Modules

      +

      16 Working with Modules

        @@ -23,7 +24,7 @@

        16 Working with Modules

        -

        16.1 Modules Introduction

        +

        16.1 Modules Introduction

        @@ -77,7 +78,7 @@

        16.1 Modules Introduction

        Each module in the collection is created via separate invocations of SWIG.

        -

        16.2 Basics

        +

        16.2 Basics

        @@ -176,7 +177,7 @@

        16.2 Basics

        issue, read on.

        -

        16.3 The SWIG runtime code

        +

        16.3 The SWIG runtime code

        @@ -242,7 +243,7 @@

        16.3 The SWIG runtime code

        is empty. Only modules compiled with the same pair will share type information.

        -

        16.4 External access to the runtime

        +

        16.4 External access to the runtime

        As described in The run-time type checker, @@ -250,7 +251,9 @@

        16.4 External access to the runtime< to be called. Calling these functions from a typemap is supported, since the typemap code is embedded into the _wrap.c file, which has those declarations available. If you need to call the SWIG run-time functions from another C file, there is one header you need -to include. To generate the header that needs to be included, run the following command: +to include. To generate the header that needs to be included, SWIG can be run in a different +mode via -external-runtime to generate the run-time instead of the normal mode of +processing an input interface file. For example:
         $ swig -python -external-runtime <filename>
        @@ -279,7 +282,7 @@ 

        16.4 External access to the runtime< access.

        -

        16.5 A word of caution about static libraries

        +

        16.5 A word of caution about static libraries

        @@ -290,7 +293,7 @@

        16.5 A word of caution about static libraries

        behavior. When working with dynamically loadable modules, you should try to work exclusively with shared libraries.

        -

        16.6 References

        +

        16.6 References

        @@ -298,7 +301,7 @@

        16.6 References

        an outside reference. John Levine's "Linkers and Loaders" is highly recommended.

        -

        16.7 Reducing the wrapper file size

        +

        16.7 Reducing the wrapper file size

        diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html index fadda5fc989..c5c199262ea 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -1,14 +1,14 @@ - - + SWIG and MzScheme/Racket + -

        30 SWIG and MzScheme/Racket

        +

        30 SWIG and MzScheme/Racket

          @@ -24,7 +24,7 @@

          30 SWIG and MzScheme/Racket

          This section contains information on SWIG's support of Racket, formally known as MzScheme. -

          30.1 Creating native structures

          +

          30.1 Creating native structures

          @@ -56,16 +56,16 @@

          30.1 Creating native structures

          -	; suppose a function created a struct foo as 
          -	; (define foo (make-diag-cntrs (#x1 #x2 #x3) (make-inspector))
          -	; Then you can do
          -	(format "0x~x" (diag-cntrs-field1 foo))
          -	(format "0x~x" (diag-cntrs-field2 foo))
          -	;etc...
          +        ; suppose a function created a struct foo as
          +        ; (define foo (make-diag-cntrs (#x1 #x2 #x3) (make-inspector))
          +        ; Then you can do
          +        (format "0x~x" (diag-cntrs-field1 foo))
          +        (format "0x~x" (diag-cntrs-field2 foo))
          +        ;etc...
           
          -

          30.2 Simple example

          +

          30.2 Simple example

          @@ -166,7 +166,7 @@

          30.2 Simple example

        • The above requests mzc to create an extension using the CGC garbage-collector. The alternative -- the 3m collector -- has generally better performance, but work is still required for SWIG to emit code which is compatible with it.
        -

        30.3 External documentation

        +

        30.3 External documentation

        diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index aa6679f9aa6..e489c41470d 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -1,12 +1,13 @@ - + - SWIG and Ocaml +SWIG and Ocaml + - - -

        31 SWIG and Ocaml

        + + +

        31 SWIG and Ocaml

      @@ -59,74 +60,76 @@

      31 SWIG and Ocaml

      - This chapter describes SWIG's -support of Ocaml. Ocaml is a relatively recent addition to the ML family, -and is a recent addition to SWIG. It's the second compiled, typed -language to be added. Ocaml has widely acknowledged benefits for engineers, -mostly derived from a sophisticated type system, compile-time checking -which eliminates several classes of common programming errors, and good -native performance. While all of this is wonderful, there are well-written -C and C++ libraries that Ocaml users will want to take advantage of as -part of their arsenal (such as SSL and gdbm), as well as their own mature -C and C++ code. SWIG allows this code to be used in a natural, type-safe -way with Ocaml, by providing the necessary, but repetitive glue code -which creates and uses Ocaml values to communicate with C and C++ code. - In addition, SWIG also produces the needed Ocaml source that binds -variants, functions, classes, etc. +This chapter describes SWIG's support of Ocaml. +

      + +

      +Ocaml is a relatively recent addition to the ML family, +and is a recent addition to SWIG. It's the second compiled, typed +language to be added. Ocaml has widely acknowledged benefits for engineers, +mostly derived from a sophisticated type system, compile-time checking +which eliminates several classes of common programming errors, and good +native performance. While all of this is wonderful, there are well-written +C and C++ libraries that Ocaml users will want to take advantage of as +part of their arsenal (such as SSL and gdbm), as well as their own mature +C and C++ code. SWIG allows this code to be used in a natural, type-safe +way with Ocaml, by providing the necessary, but repetitive glue code +which creates and uses Ocaml values to communicate with C and C++ code. +In addition, SWIG also produces the needed Ocaml source that binds +variants, functions, classes, etc.

      If you're not familiar with the Objective Caml language, you can visit -The Ocaml Website. +The Ocaml Website.

      -

      31.1 Preliminaries

      +

      31.1 Preliminaries

      - SWIG 1.3 works with Ocaml 3.04 and above. Given the choice, - you should use the latest stable release. The SWIG Ocaml module has -been tested on Linux (x86,PPC,Sparc) and Cygwin on Windows. The -best way to determine whether your system will work is to compile the -examples and test-suite which come with SWIG. You can do this by running -make check from the SWIG root directory after installing SWIG. - The Ocaml module has been tested using the system's dynamic linking (the -usual -lxxx against libxxx.so, as well as with Gerd Stolpmann's -Dl package -. The ocaml_dynamic and ocaml_dynamic_cpp targets in the +SWIG 3.0 works with Ocaml 3.08.3 and above. Given the choice, +you should use the latest stable release. The SWIG Ocaml module has +been tested on Linux (x86,PPC,Sparc) and Cygwin on Windows. The +best way to determine whether your system will work is to compile the +examples and test-suite which come with SWIG. You can do this by running +make check from the SWIG root directory after installing SWIG. +The Ocaml module has been tested using the system's dynamic linking (the +usual -lxxx against libxxx.so, as well as with Gerd Stolpmann's +Dl package. +The ocaml_dynamic and ocaml_dynamic_cpp targets in the file Examples/Makefile illustrate how to compile and link SWIG modules that will be loaded dynamically. This has only been tested on Linux so far.

      -

      31.1.1 Running SWIG

      +

      31.1.1 Running SWIG

      - The basics of getting a SWIG Ocaml module up and running - can be seen from one of SWIG's example Makefiles, but is also described - here. To build an Ocaml module, run SWIG using the -ocaml -option. +The basics of getting a SWIG Ocaml module up and running +can be seen from one of SWIG's example Makefiles, but is also described +here. To build an Ocaml module, run SWIG using the -ocaml +option.

      -
      -
      +
      +
       %swig -ocaml example.i
      -  
      +
      - -

      This will produce 3 files. The file example_wrap.c contains + +

      This will produce 3 files. The file example_wrap.c contains all of the C code needed to build an Ocaml module. To build the module, -you will compile the file example_wrap.c with ocamlc or +you will compile the file example_wrap.c with ocamlc or ocamlopt to create the needed .o file. You will need to compile the resulting .ml and .mli files as well, and do the final link with -custom -(not needed for native link).

      - -

      31.1.2 Compiling the code

      +(not needed for native link).

      + +

      31.1.2 Compiling the code

      -The OCaml SWIG module now requires you to compile a module (Swig) +The OCaml SWIG module now requires you to compile a module (Swig) separately. In addition to aggregating common SWIG functionality, the Swig module contains the data structure that represents C/C++ values. This allows easier data sharing between modules if two or more are combined, because @@ -134,39 +137,40 @@

      31.1.2 Compiling the code

      also allows SWIG to acquire new conversions painlessly, as well as giving the user more freedom with respect to custom typing. - Use ocamlc or ocamlopt to compile your - SWIG interface like: +Use ocamlc or ocamlopt to compile your SWIG interface like:

      - -
      -
      +
      +
      +
       % swig -ocaml -co swig.mli ; swig -ocaml co swig.ml
       % ocamlc -c swig.mli ; ocamlc -c swig.ml
       % ocamlc -c -ccopt "-I/usr/include/foo" example_wrap.c
       % ocamlc -c example.mli
       % ocamlc -c example.ml
      -  
      +
      - -

      ocamlc is aware of .c files and knows how to handle them. Unfortunately, - it does not know about .cxx, .cc, or .cpp files, so when SWIG is invoked - in C++ mode, you must:

      - -
      -
      -% cp example_wrap.cxx example_wrap.cxx.c
      % ocamlc -c ... -ccopt -xc++ example_wrap.cxx.c
      % ...
      -
      + +

      ocamlc is aware of .c files and knows how to handle them. Unfortunately, +it does not know about .cxx, .cc, or .cpp files, so when SWIG is invoked +in C++ mode, you must:

      + +
      +
      +% cp example_wrap.cxx example_wrap.cxx.c
      +% ocamlc -c ... -ccopt -xc++ example_wrap.cxx.c
      +% ...
      +
      -

      31.1.3 The camlp4 module

      +

      31.1.3 The camlp4 module

      The camlp4 module (swigp4.ml -> swigp4.cmo) contains a simple rewriter which makes C++ code blend more seamlessly with objective caml code. Its use is optional, but encouraged. The source file is included in the Lib/ocaml -directory of the SWIG source distribution. You can checkout this file with -"swig -ocaml -co swigp4.ml". You should compile the file with +directory of the SWIG source distribution. You can checkout this file with +"swig -ocaml -co swigp4.ml". You should compile the file with "ocamlc -I `camlp4 -where` -pp 'camlp4o pa_extend.cmo q_MLast.cmo' -c swigp4.ml"

      @@ -192,7 +196,7 @@

      31.1.3 The camlp4 module

      (invoke object) "+=" argument as in
      (invoke a) "+=" b -Note that because camlp4 always recognizes << +Note that because camlp4 always recognizes << and >>, they are replaced by lsl and lsr in operator names. 'unop object as in
      @@ -234,21 +238,21 @@

      31.1.3 The camlp4 module

      -

      31.1.4 Using your module

      +

      31.1.4 Using your module

      You can test-drive your module by building a toplevel ocaml interpreter. Consult the ocaml manual for details.

      - +

      When linking any ocaml bytecode with your module, use the -custom - option to build your functions into the primitive list. This - option is not needed when you build native code. +option to build your functions into the primitive list. This +option is not needed when you build native code.

      -

      31.1.5 Compilation problems and compiling with C++

      +

      31.1.5 Compilation problems and compiling with C++

      @@ -259,7 +263,7 @@

      31.1.5 Compilation problems and compiling with C++ -

      31.2 The low-level Ocaml/C interface

      +

      31.2 The low-level Ocaml/C interface

      @@ -273,9 +277,9 @@

      31.2 The low-level Ocaml/C interface

      writer, there is a value, swig_result, that always contains the current return data. It is a list, and must be appended with the caml_list_append function, or with functions and macros provided by -objective caml.
      +objective caml.

      - +
       type c_obj =
           C_void
      @@ -299,68 +303,67 @@ 

      31.2 The low-level Ocaml/C interface

      - A few functions exist which generate and return these: +A few functions exist which generate and return these:

      - +
        -
      • caml_ptr_val receives a c_obj and returns a void *.  This - should be used for all pointer purposes.
      • -
      • caml_long_val receives a c_obj and returns a long.  This - should be used for most integral purposes.
        -
      • -
      • caml_val_ptr receives a void * and returns a c_obj.
      • -
      • caml_val_bool receives a C int and returns a c_obj representing - its bool value.
      • -
      • caml_val_(u)?(char|short|int|long|float|double) receives an -appropriate C value and returns a c_obj representing it.
      • -
      • caml_val_string receives a char * and returns a string value.
      • -
      • caml_val_string_len receives a char * and a length and returns - a string value.
      • -
      • caml_val_obj receives a void * and an object type and returns - a C_obj, which contains a closure giving method access.
      • - +
      • caml_ptr_val receives a c_obj and returns a void *. This + should be used for all pointer purposes.
      • +
      • caml_long_val receives a c_obj and returns a long. This + should be used for most integral purposes.
      • +
      • caml_val_ptr receives a void * and returns a c_obj.
      • +
      • caml_val_bool receives a C int and returns a c_obj representing + its bool value.
      • +
      • caml_val_(u)?(char|short|int|long|float|double) receives an + appropriate C value and returns a c_obj representing it.
      • +
      • caml_val_string receives a char * and returns a string value.
      • +
      • caml_val_string_len receives a char * and a length and returns + a string value.
      • +
      • caml_val_obj receives a void * and an object type and returns + a C_obj, which contains a closure giving method access.

      Because of this style, a typemap can return any kind of value it -wants from a function.  This enables out typemaps and inout typemaps -to work well.  The one thing to remember about outputting values -is that you must append them to the return list with swig_result = caml_list_append(swig_result,v). -

      - -

      - This function will return a new list that has your element - appended. Upon return to caml space, the fnhelper function - beautifies the result. A list containing a single item degrades to - only that item (i.e. [ C_int 3 ] -> C_int 3), and a list - containing more than one item is wrapped in C_list (i.e. [ C_char - 'a' ; C_char 'b' -> C_list [ C_char 'a' ; C_char b - ]).  This is in order to make return values easier to handle - when functions have only one return value, such as constructors, - and operators.  In addition, string, pointer, and object - values are interchangeable with respect to caml_ptr_val, so you can - allocate memory as caml strings and still use the resulting - pointers for C purposes, even using them to construct simple objects - on. Note, though, that foreign C++ code does not respect the garbage - collector, although the SWIG interface does.

      - -

      - The wild card type that you can use in lots of different ways is - C_obj. It allows you to wrap any type of thing you like as an - object using the same mechanism that the ocaml module - does.  When evaluated in caml_ptr_val, the returned value is - the result of a call to the object's "&" operator, taken as a pointer. -

      -

      - You should only construct values using objective caml, or using the - functions caml_val_* functions provided as static functions to a SWIG - ocaml module, as well as the caml_list_* functions. These functions - provide everything a typemap needs to produce values. In addition, - value items pass through directly, but you must make your own type - signature for a function that uses value in this way. -

      - -

      31.2.1 The generated module

      +wants from a function. This enables out typemaps and inout typemaps +to work well. The one thing to remember about outputting values +is that you must append them to the return list with swig_result = caml_list_append(swig_result,v). +

      + +

      +This function will return a new list that has your element +appended. Upon return to caml space, the fnhelper function +beautifies the result. A list containing a single item degrades to +only that item (i.e. [ C_int 3 ] -> C_int 3), and a list +containing more than one item is wrapped in C_list (i.e. [ C_char +'a' ; C_char 'b' -> C_list [ C_char 'a' ; C_char b +]). This is in order to make return values easier to handle +when functions have only one return value, such as constructors, +and operators. In addition, string, pointer, and object +values are interchangeable with respect to caml_ptr_val, so you can +allocate memory as caml strings and still use the resulting +pointers for C purposes, even using them to construct simple objects +on. Note, though, that foreign C++ code does not respect the garbage +collector, although the SWIG interface does.

      + +

      +The wild card type that you can use in lots of different ways is +C_obj. It allows you to wrap any type of thing you like as an +object using the same mechanism that the ocaml module +does. When evaluated in caml_ptr_val, the returned value is +the result of a call to the object's "&" operator, taken as a pointer. +

      + +

      +You should only construct values using objective caml, or using the +functions caml_val_* functions provided as static functions to a SWIG +ocaml module, as well as the caml_list_* functions. These functions +provide everything a typemap needs to produce values. In addition, +value items pass through directly, but you must make your own type +signature for a function that uses value in this way. +

      + +

      31.2.1 The generated module

      @@ -376,7 +379,7 @@

      31.2.1 The generated module

      You can introduce extra code into the output wherever you like with SWIG. These are the places you can introduce code: - @@ -385,25 +388,25 @@

      31.2.1 The generated module

      - +
      "header"This code is inserted near the beginning of the +
      "header"This code is inserted near the beginning of the C wrapper file, before any function definitions.
      "wrapper"This code is inserted in the function definition section.
      "mli"This code is inserted into the caml interface file. Special signatures should be inserted here.
      "ml"This code is inserted in the caml code defining the +
      "ml"This code is inserted in the caml code defining the interface to your C code. Special caml code, as well as any initialization which should run when the module is loaded may be inserted here. -
      "classtemplate"The "classtemplate" place is special because it describes the output SWIG will generate for class definitions.
      - -

      31.2.2 Enums

      + +

      31.2.2 Enums

      SWIG will wrap enumerations as polymorphic variants in the output -Ocaml code, as above in C_enum.  In order to support all +Ocaml code, as above in C_enum. In order to support all C++-style uses of enums, the function int_to_enum and enum_to_int are provided for ocaml code to produce and consume these values as -integers.  Other than that, correct uses of enums will not have -a problem.  Since enum labels may overlap between enums, the +integers. Other than that, correct uses of enums will not have +a problem. Since enum labels may overlap between enums, the enum_to_int and int_to_enum functions take an enum type label as an argument. Example:

      @@ -416,9 +419,9 @@

      31.2.2 Enums

      enum c_enum_type { a = 1, b, c = 4, d = 8 };
      -

      +

      The output mli contains: -

      +

       type c_enum_type = [
      @@ -435,16 +438,16 @@ 

      31.2.2 Enums

      val int_to_enum c_enum_type -> int -> c_obj val enum_to_int c_enum_type -> c_obj -> c_obj
      -
      +

      - So it's possible to do this: +So it's possible to do this:

      -
      -
      +
      +
       bash-2.05a$ ocamlmktop -custom enum_test_wrap.o enum_test.cmo -o enum_test_top
      -bash-2.05a$ ./enum_test_top 
      +bash-2.05a$ ./enum_test_top
               Objective Caml version 3.04
       
       # open Enum_test ;;
      @@ -455,9 +458,9 @@ 

      31.2.2 Enums

      # int_to_enum `c_enum_type 4 ;; - : Enum_test.c_obj = C_enum `c
      -
      +
      -

      31.2.2.1 Enum typing in Ocaml

      +

      31.2.2.1 Enum typing in Ocaml

      @@ -470,10 +473,10 @@

      31.2.2.1 Enum typing in Ocaml

      values using the swig_val function before sharing them with another module.

      -

      31.2.3 Arrays

      +

      31.2.3 Arrays

      -

      31.2.3.1 Simple types of bounded arrays

      +

      31.2.3.1 Simple types of bounded arrays

      @@ -485,7 +488,7 @@

      31.2.3.1 Simple types of bounded arrays

      By including "carray.i", you will get access to some macros that help you -create typemaps for array types fairly easily. +create typemaps for array types fairly easily.

      @@ -494,7 +497,7 @@

      31.2.3.1 Simple types of bounded arrays

      for arrays whose bounds are completely specified.

      -

      31.2.3.2 Complex and unbounded arrays

      +

      31.2.3.2 Complex and unbounded arrays

      @@ -507,7 +510,7 @@

      31.2.3.2 Complex and unbounded arrays

      so you have to specify it for yourself in the form of a typemap.

      -

      31.2.3.3 Using an object

      +

      31.2.3.3 Using an object

      @@ -521,7 +524,7 @@

      31.2.3.3 Using an object

      such as using a required sentinel, etc.

      -

      31.2.3.4 Example typemap for a function taking float * and int

      +

      31.2.3.4 Example typemap for a function taking float * and int

      @@ -541,24 +544,24 @@

      31.2.3.4 Example typemap for a function taking floa #include <stdio.h> void printfloats( float *tab, int len ) { - int i; + int i; - for( i = 0; i < len; i++ ) { - printf( "%f ", tab[i] ); - } + for( i = 0; i < len; i++ ) { + printf( "%f ", tab[i] ); + } - printf( "\n" ); + printf( "\n" ); } %} %typemap(in) (float *tab, int len) { - int i; - /* $*1_type */ - $2 = caml_array_len($input); - $1 = ($*1_type *)malloc( $2 * sizeof( float ) ); - for( i = 0; i < $2; i++ ) { - $1[i] = caml_double_val(caml_array_nth($input,i)); - } + int i; + /* $*1_type */ + $2 = caml_array_len($input); + $1 = ($*1_type *)malloc( $2 * sizeof( float ) ); + for( i = 0; i < $2; i++ ) { + $1[i] = caml_double_val(caml_array_nth($input,i)); + } } void printfloats( float *tab, int len ); @@ -572,30 +575,30 @@

      31.2.3.4 Example typemap for a function taking floa -

      31.2.4 C++ Classes

      +

      31.2.4 C++ Classes

      C++ classes, along with structs and unions are represented by C_obj -(string -> c_obj -> c_obj) wrapped closures.  These objects +(string -> c_obj -> c_obj) wrapped closures. These objects contain a method list, and a type, which allow them to be used like C++ objects. When passed into typemaps that use pointers, they -degrade to pointers through their "&" method.  Every method +degrade to pointers through their "&" method. Every method an object has is represented as a string in the object's method table, -and each method table exists in memory only once.  In addition +and each method table exists in memory only once. In addition to any other operators an object might have, certain builtin ones are -provided by SWIG: (all of these take no arguments (C_void)) +provided by SWIG: (all of these take no arguments (C_void))

      - - @@ -603,8 +606,8 @@

      31.2.4 C++ Classes

      indicated parent class. This is mainly used internally by the SWIG module, but may be useful to client programs.
      "~"Delete this object
      "&"Return an ordinary C_ptr value representing this +
      "&"Return an ordinary C_ptr value representing this object's address
      "sizeof"If enabled with ("sizeof"="1") on the module node, return the object's size in char.
      ":methods"Returns a list of strings containing the names of the methods this object contains
      ":classof"Returns the name of the class this object belongs +
      ":classof"Returns the name of the class this object belongs to.
      ":parents"Returns a list of all direct parent classes which have been wrapped by SWIG.
      "[member-variable]"Each member variable is wrapped as a -method with an optional parameter. -Called with one argument, the member variable is set to the value of the +method with an optional parameter. +Called with one argument, the member variable is set to the value of the argument. With zero arguments, the value is returned.
      @@ -615,7 +618,7 @@

      31.2.4 C++ Classes

      returned value for the same object.

      -

      31.2.4.1 STL vector and string Example

      +

      31.2.4.1 STL vector and string Example

      @@ -637,7 +640,7 @@

      31.2.4.1 STL vector and string Example

      %include <stl.i> namespace std { - %template(StringVector) std::vector < string >; + %template(StringVector) std::vector < string >; }; %include "example.h" @@ -652,12 +655,12 @@

      31.2.4.1 STL vector and string Example

      Here's a sample transcript of an interactive session using a string vector -after making a toplevel (make toplevel). This example uses the camlp4 +after making a toplevel (make toplevel). This example uses the camlp4 module.

      -bash-2.05a$ ./example_top 
      +bash-2.05a$ ./example_top
               Objective Caml version 3.06
       
               Camlp4 Parsing version 3.06
      @@ -685,17 +688,17 @@ 

      31.2.4.1 STL vector and string Example

      - : Example.c_obj = C_void # x '[1] ;; - : Example.c_obj = C_string "spam" -# for i = 0 to (x -> size() as int) - 1 do - print_endline ((x '[i to int]) as string) +# for i = 0 to (x -> size() as int) - 1 do + print_endline ((x '[i to int]) as string) done ;; foo bar baz - : unit = () -# +#
      -

      31.2.4.2 C++ Class Example

      +

      31.2.4.2 C++ Class Example

      @@ -703,7 +706,7 @@

      31.2.4.2 C++ Class Example

      - +
      qt.i
      qt.i
       %module qt
       %{
      @@ -712,20 +715,20 @@ 

      31.2.4.2 C++ Class Example

      %} class QApplication { public: - QApplication( int argc, char **argv ); - void setMainWidget( QWidget *widget ); - void exec(); + QApplication( int argc, char **argv ); + void setMainWidget( QWidget *widget ); + void exec(); }; class QPushButton { public: - QPushButton( char *str, QWidget *w ); - void resize( int x, int y ); - void show(); + QPushButton( char *str, QWidget *w ); + void resize( int x, int y ); + void show(); };
      -

      31.2.4.3 Compiling the example

      +

      31.2.4.3 Compiling the example

      @@ -733,9 +736,9 @@ 

      31.2.4.3 Compiling the example

      bash-2.05a$ for file in swig.mli swig.ml swigp4.ml ; do swig -ocaml -co $file ; done bash-2.05a$ ocamlc -c swig.mli ; ocamlc -c swig.ml bash-2.05a$ ocamlc -I `camlp4 -where` -pp "camlp4o pa_extend.cmo q_MLast.cmo" -c swigp4.ml -bash-2.05a$ swig -ocaml -c++ -I$QTPATH/include qt.i +bash-2.05a$ swig -ocaml -c++ -I$QTPATH/include qt.i bash-2.05a$ mv qt_wrap.cxx qt_wrap.c -bash-2.05a$ ocamlc -c -ccopt -xc++ -ccopt -g -g -ccopt -I$QTPATH/include qt_wrap.c +bash-2.05a$ ocamlc -c -ccopt -xc++ -ccopt -g -g -ccopt -I$QTPATH/include qt_wrap.c bash-2.05a$ ocamlc -c qt.mli bash-2.05a$ ocamlc -c qt.ml bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \ @@ -743,11 +746,11 @@

      31.2.4.3 Compiling the example

      -L$QTPATH/lib -cclib -lqt
      -

      31.2.4.4 Sample Session

      +

      31.2.4.4 Sample Session

      -bash-2.05a$ ./qt_top 
      +bash-2.05a$ ./qt_top
               Objective Caml version 3.06
       
               Camlp4 Parsing version 3.06
      @@ -767,13 +770,13 @@ 

      31.2.4.4 Sample Session

      Assuming you have a working installation of QT, you will see a window -containing the string "hi" in a button. +containing the string "hi" in a button.

      -

      31.2.5 Director Classes

      +

      31.2.5 Director Classes

      -

      31.2.5.1 Director Introduction

      +

      31.2.5.1 Director Introduction

      @@ -800,7 +803,7 @@

      31.2.5.1 Director Introduction

      };
      -

      31.2.5.2 Overriding Methods in Ocaml

      +

      31.2.5.2 Overriding Methods in Ocaml

      @@ -828,7 +831,7 @@

      31.2.5.2 Overriding Methods in Ocaml

      an overloaded class. This example is contained in Examples/ocaml/shapes.

      -

      31.2.5.3 Director Usage Example

      +

      31.2.5.3 Director Usage Example

      @@ -845,14 +848,14 @@

      31.2.5.3 Director Usage Example

      "cover" -> (match args with C_list [ x_arg ; y_arg ] -> - let xa = x_arg as float - and ya = y_arg as float in - (point_in_triangle pts xa ya) to bool + let xa = x_arg as float + and ya = y_arg as float in + (point_in_triangle pts xa ya) to bool | _ -> raise (Failure "cover needs two double arguments.")) | _ -> (invoke ob) meth args ;; let triangle = - new_derived_object + new_derived_object new_shape (triangle_class ((0.0,0.0),(0.5,1.0),(1.0,0.0))) '() ;; @@ -887,7 +890,7 @@

      31.2.5.3 Director Usage Example

      program in C++.

      -

      31.2.5.4 Creating director objects

      +

      31.2.5.4 Creating director objects

      @@ -896,7 +899,7 @@

      31.2.5.4 Creating director objects

       let triangle =
      -  new_derived_object 
      +  new_derived_object
           new_shape
           (triangle_class ((0.0,0.0),(0.5,1.0),(1.0,0.0)))
           '()
      @@ -904,13 +907,13 @@ 

      31.2.5.4 Creating director objects

      The first argument to new_derived_object, new_shape is the method -which returns a shape instance. This function will be invoked with the +which returns a shape instance. This function will be invoked with the third argument will be appended to the argument list [ C_void ]. In the example, the actual argument list is sent as (C_list [ C_void ; C_void ]). The augmented constructor for a director class needs the first argument to determine whether it is being constructed as a derived object, or as an object of the indicated type only (in this case shape). The -Second argument is a closure that will be added to the final C_obj. +Second argument is a closure that will be added to the final C_obj.

      @@ -928,7 +931,7 @@

      31.2.5.4 Creating director objects

      properly.

      -

      31.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      +

      31.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      @@ -939,7 +942,7 @@

      31.2.5.5 Typemaps for directors, directorin, di and to receive arguments the same way you normally receive function returns.

      -

      31.2.5.6 directorin typemap

      +

      31.2.5.6 typemap

      @@ -950,7 +953,7 @@

      31.2.5.6 directorin typemap

      can use the same body as a simple out typemap.

      -

      31.2.5.7 directorout typemap

      +

      31.2.5.7 directorout typemap

      @@ -961,7 +964,7 @@

      31.2.5.7 directorout typemap

      ownership, etc.

      -

      31.2.5.8 directorargout typemap

      +

      31.2.5.8 directorargout typemap

      @@ -978,7 +981,7 @@

      31.2.5.8 directorargout typemap

      values will read zero, and struct or object returns have undefined results.

      -

      31.2.6 Exceptions

      +

      31.2.6 Exceptions

      diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 46a8941c2e9..9b9744f658c 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -1,14 +1,15 @@ - + SWIG and Octave + -

      32 SWIG and Octave

      +

      32 SWIG and Octave

        @@ -33,6 +34,10 @@

        32 SWIG and Octave

      • Class extension with %extend
      • C++ templates
      • C++ Smart Pointers +
      • Directors (calling Octave from C++ code)
      • Threads
      • Memory management @@ -55,15 +60,16 @@

        32 SWIG and Octave

        Also, there are a dozen or so examples in the Examples/octave directory, and hundreds in the test suite (Examples/test-suite and Examples/test-suite/octave).

        -

        32.1 Preliminaries

        +

        32.1 Preliminaries

        -As of SWIG 3.0.3, the Octave module has been tested with Octave versions 3.2.4, 3.4.3, 3.6.4, and 3.8.1. +As of SWIG 3.0.7, the Octave module is regularly tested with Octave versions 3.2.4, 3.8.1, and 4.0.0. Use of older Octave versions is not recommended, as these versions are no longer tested with SWIG. +The SWIG runtime exports the function swig_octave_prereq() for checking the version of Octave.

        -

        32.2 Running SWIG

        +

        32.2 Running SWIG

        @@ -95,7 +101,7 @@

        32.2 Running SWIG

        This creates a C++ source file "example_wrap.cpp". A C++ file is generated even when wrapping C code as Octave is itself written in C++ and requires wrapper code to be in the same language. The generated C++ source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application (in this case, the gcd implementation) to create an extension module.

        -

        32.2.1 Command-line options

        +

        32.2.1 Command-line options

        @@ -118,7 +124,7 @@

        32.2.1 Command-line options

        The -opprefix options sets the prefix of the names of global/friend operator functions.

        -

        32.2.2 Compiling a dynamic module

        +

        32.2.2 Compiling a dynamic module

        @@ -145,7 +151,7 @@

        32.2.2 Compiling a dynamic module

        octave:1> swigexample
        -

        32.2.3 Using your module

        +

        32.2.3 Using your module

        @@ -163,10 +169,10 @@

        32.2.3 Using your module

        octave:5> swigexample.cvar.Foo ans = 4

      -

      32.3 A tour of basic C/C++ wrapping

      +

      32.3 A tour of basic C/C++ wrapping

      -

      32.3.1 Modules

      +

      32.3.1 Modules

      @@ -211,7 +217,7 @@

      32.3.1 Modules

      ans = 2 -

      32.3.2 Functions

      +

      32.3.2 Functions

      @@ -228,7 +234,7 @@

      32.3.2 Functions

      octave:1> swigexample.fact(4)
       24 
      -

      32.3.3 Global variables

      +

      32.3.3 Global variables

      @@ -281,7 +287,7 @@

      32.3.3 Global variables

      octave:3> swigexample.PI ans = 3.1420 -

      32.3.4 Constants and enums

      +

      32.3.4 Constants and enums

      @@ -303,7 +309,7 @@

      32.3.4 Constants and enums

      swigexample.SUNDAY=0 .... -

      32.3.5 Pointers

      +

      32.3.5 Pointers

      @@ -350,7 +356,7 @@

      32.3.5 Pointers

      error: value on right hand side of assignment is undefined error: evaluating assignment expression near line 2, column 2 -

      32.3.6 Structures and C++ classes

      +

      32.3.6 Structures and C++ classes

      @@ -485,7 +491,7 @@

      32.3.6 Structures and C++ classes

      Depending on the ownership setting of a swig_ref, it may call C++ destructors when its reference count goes to zero. See the section on memory management below for details.

      -

      32.3.7 C++ inheritance

      +

      32.3.7 C++ inheritance

      @@ -494,7 +500,7 @@

      32.3.7 C++ inheritance

      the tree is walked to find a match in the current class as well as any of its bases. The lookup is then cached in the swig_ref.

      -

      32.3.8 C++ overloaded functions

      +

      32.3.8 C++ overloaded functions

      @@ -504,7 +510,7 @@

      32.3.8 C++ overloaded functions

      typecheck typemaps are used to analyze each argument, as well as assign precedence. See the chapter on typemaps for details.

      -

      32.3.9 C++ operators

      +

      32.3.9 C++ operators

      @@ -512,7 +518,7 @@

      32.3.9 C++ operators

      The swig_ref type supports all unary and binary operators between itself and all other types that exist in the system at module load time. When an operator is used (where one of the operands is a swig_ref), the runtime routes the call to either a member function of the given object, or to a global function whose named is derived from the types of the operands (either both or just the lhs or rhs).

      -For example, if a and b are SWIG variables in Octave, a+b becomes a.__add(b). The wrapper is then free to implement __add to do whatever it wants. A wrapper may define the __add function manually, %rename some other function to it, or %rename a C++ operator to it. +For example, if a and b are SWIG variables in Octave, a+b becomes a.__add__(b). The wrapper is then free to implement __add__ to do whatever it wants. A wrapper may define the __add__ function manually, %rename some other function to it, or %rename a C++ operator to it.

      By default the C++ operators are renamed to their corresponding Octave operators. So without doing any work, the following interface @@ -539,87 +545,87 @@

      32.3.9 C++ operators

      Octave operators are mapped in the following way:

      -__brace      a{args}
      -__brace_asgn a{args} = rhs
      -__paren      a(args)
      -__paren_asgn a(args) = rhs
      -__str        generates string rep
      -__not        !a
      -__uplus      +a
      -__uminus     -a
      -__transpose  a.'
      -__hermitian  a'
      -__incr       a++
      -__decr       a--
      -__add        a + b
      -__sub        a - b
      -__mul        a * b
      -__div        a / b
      -__pow        a ^ b
      -__ldiv       a \ b
      -__lshift     a << b
      -__rshift     a >> b
      -__lt         a < b
      -__le         a <= b
      -__eq         a == b
      -__ge         a >= b
      -__gt         a > b
      -__ne         a != b
      -__el_mul     a .* b
      -__el_div     a ./ b
      -__el_pow     a .^ b
      -__el_ldiv    a .\ b
      -__el_and     a & b
      -__el_or      a | b
      +__brace__      a{args}
      +__brace_asgn__ a{args} = rhs
      +__paren__      a(args)
      +__paren_asgn__ a(args) = rhs
      +__str__        generates string rep
      +__not__        !a
      +__uplus__      +a
      +__uminus__     -a
      +__transpose__  a.'
      +__hermitian__  a'
      +__incr__       a++
      +__decr__       a--
      +__add__        a + b
      +__sub__        a - b
      +__mul__        a * b
      +__div__        a / b
      +__pow__        a ^ b
      +__ldiv__       a \ b
      +__lshift__     a << b
      +__rshift__     a >> b
      +__lt__         a < b
      +__le__         a <= b
      +__eq__         a == b
      +__ge__         a >= b
      +__gt__         a > b
      +__ne__         a != b
      +__el_mul__     a .* b
      +__el_div__     a ./ b
      +__el_pow__     a .^ b
      +__el_ldiv__    a .\ b
      +__el_and__     a & b
      +__el_or__      a | b
       

      On the C++ side, the default mappings are as follows:

      -%rename(__add)       *::operator+;
      -%rename(__add)       *::operator+();
      -%rename(__add)       *::operator+() const;
      -%rename(__sub)       *::operator-;
      -%rename(__uminus)    *::operator-();
      -%rename(__uminus)    *::operator-() const;
      -%rename(__mul)       *::operator*;
      -%rename(__div)       *::operator/;
      -%rename(__mod)       *::operator%;
      -%rename(__lshift)    *::operator<<;
      -%rename(__rshift)    *::operator>>;
      -%rename(__el_and)    *::operator&&;
      -%rename(__el_or)     *::operator||;
      -%rename(__xor)       *::operator^;
      -%rename(__invert)    *::operator~;
      -%rename(__lt)        *::operator<;
      -%rename(__le)        *::operator<=;
      -%rename(__gt)        *::operator>;
      -%rename(__ge)        *::operator>=;
      -%rename(__eq)        *::operator==;
      -%rename(__ne)        *::operator!=;
      -%rename(__not)       *::operator!;
      -%rename(__incr)      *::operator++;
      -%rename(__decr)      *::operator--;
      -%rename(__paren)     *::operator();
      -%rename(__brace)     *::operator[];
      +%rename(__add__)       *::operator+;
      +%rename(__add__)       *::operator+();
      +%rename(__add__)       *::operator+() const;
      +%rename(__sub__)       *::operator-;
      +%rename(__uminus__)    *::operator-();
      +%rename(__uminus__)    *::operator-() const;
      +%rename(__mul__)       *::operator*;
      +%rename(__div__)       *::operator/;
      +%rename(__mod__)       *::operator%;
      +%rename(__lshift__)    *::operator<<;
      +%rename(__rshift__)    *::operator>>;
      +%rename(__el_and__)    *::operator&&;
      +%rename(__el_or__)     *::operator||;
      +%rename(__xor__)       *::operator^;
      +%rename(__invert__)    *::operator~;
      +%rename(__lt__)        *::operator<;
      +%rename(__le__)        *::operator<=;
      +%rename(__gt__)        *::operator>;
      +%rename(__ge__)        *::operator>=;
      +%rename(__eq__)        *::operator==;
      +%rename(__ne__)        *::operator!=;
      +%rename(__not__)       *::operator!;
      +%rename(__incr__)      *::operator++;
      +%rename(__decr__)      *::operator--;
      +%rename(__paren__)     *::operator();
      +%rename(__brace__)     *::operator[];
       

      Octave can also utilise friend (i.e. non-member) operators with a simple %rename: see the example in the Examples/octave/operator directory.

      -

      32.3.10 Class extension with %extend

      +

      32.3.10 Class extension with %extend

      The %extend directive works the same as in other modules.

      -You can use it to define special behavior, like for example defining Octave operators not mapped to C++ operators, or defining certain Octave mechanisms such as how an object prints. For example, the octave_value::{is_string,string_value,print} functions are routed to a special method __str that can be defined inside an %extend. +You can use it to define special behavior, like for example defining Octave operators not mapped to C++ operators, or defining certain Octave mechanisms such as how an object prints. For example, the octave_value::{is_string,string_value,print} functions are routed to a special method __str__ that can be defined inside an %extend.

       %extend A {
      -string __str() {
      +string __str__() {
         stringstream sout;
         sout<<$self->value;
         return sout.str();
      @@ -635,10 +641,19 @@ 

      32.3.10 Class extension with %extend

      a = 4 octave:3> printf("%s\n",a); 4 -octave:4> a.__str() +octave:4> a.__str__() 4
      -

      32.3.11 C++ templates

      + +

      +Similarly, Octave can use the __float__ method to convert an object to a numeric value. +

      + +

      +Octave 3.8.0 and later versions will also map unary functions X() to the corresponding __X__ method, where X includes: abs(), acos(), acosh(), angle(), arg(), asin(), asinh(), atan(), atanh(), cbrt(), ceil(), conj(), cos(), cosh(), dawson(), erf(), erfc(), erfcinv(), erfcx(), erfi(), erfinv(), exp(), expm1(), finite(), fix(), floor(), gamma(), imag(), isalnum(), isalpha(), isascii(), iscntrl(), isdigit(), isgraph(), isinf(), islower(), isna(), isnan(), isprint(), ispunct(), isspace(), isupper(), isxdigit(), lgamma(), log(), log10(), log1p(), log2(), real(), round(), roundb(), signbit(), signum(), sin(), sinh(), sqrt(), tan(), tanh(), toascii(), tolower(), toupper() +

      + +

      32.3.11 C++ templates

      @@ -687,7 +702,7 @@

      32.3.11 C++ templates

      s+=_s; return *this; } - std::string __str() const { + std::string __str__() const { std::stringstream sout; sout<<s; return sout.str(); @@ -715,14 +730,28 @@

      32.3.11 C++ templates

      -

      32.3.12 C++ Smart Pointers

      +

      32.3.12 C++ Smart Pointers

      + + +

      32.3.12.1 The shared_ptr Smart Pointer

      + + +

      +The C++11 standard provides std::shared_ptr which was derived from the Boost +implementation, boost::shared_ptr. +Both of these are available for Octave in the SWIG library and usage is outlined +in the shared_ptr smart pointer library section. +

      + + +

      32.3.12.2 Generic Smart Pointers

      C++ smart pointers are fully supported as in other modules.

      -

      32.3.13 Directors (calling Octave from C++ code)

      +

      32.3.13 Directors (calling Octave from C++ code)

      @@ -803,14 +832,14 @@

      32.3.13 Directors (calling Octave from C++ code) -

      32.3.14 Threads

      +

      32.3.14 Threads

      The use of threads in wrapped Director code is not supported; i.e., an Octave-side implementation of a C++ class must be called from the Octave interpreter's thread. Anything fancier (apartment/queue model, whatever) is left to the user. Without anything fancier, this amounts to the limitation that Octave must drive the module... like, for example, an optimization package that calls Octave to evaluate an objective function.

      -

      32.3.15 Memory management

      +

      32.3.15 Memory management

      @@ -844,14 +873,14 @@

      32.3.15 Memory management

      In the case where one wishes for the C++ side to own an object that was created in Octave (especially a Director object), one can use the __disown() method to invert this logic. Then letting the Octave reference count go to zero will not destroy the object, but destroying the object will invalidate the Octave-side object if it still exists (and call destructors of other C++ bases in the case of multiple inheritance/subclass()'ing).

      -

      32.3.16 STL support

      +

      32.3.16 STL support

      Various STL library files are provided for wrapping STL containers.

      -

      32.3.17 Matrix typemaps

      +

      32.3.17 Matrix typemaps

      diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 8bc7cbfd3dc..8d7b866d61e 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -1,12 +1,13 @@ - + SWIG and Perl5 + -

      33 SWIG and Perl5

      +

      33 SWIG and Perl5

        @@ -96,7 +97,7 @@

        33 SWIG and Perl5

        Perl 5.6 seems to mostly work, while older versions don't.

        -

        33.1 Overview

        +

        33.1 Overview

        @@ -117,7 +118,7 @@

        33.1 Overview

        options are found near the end of the chapter.

        -

        33.2 Preliminaries

        +

        33.2 Preliminaries

        @@ -142,7 +143,7 @@

        33.2 Preliminaries

        example_wrap.c and link it with the rest of your program.

        -

        33.2.1 Getting the right header files

        +

        33.2.1 Getting the right header files

        @@ -174,7 +175,7 @@

        33.2.1 Getting the right header files

      -

      33.2.2 Compiling a dynamic module

      +

      33.2.2 Compiling a dynamic module

      @@ -207,7 +208,7 @@

      33.2.2 Compiling a dynamic module

      `example.sl', or the appropriate dynamic module name on your system.

      -

      33.2.3 Building a dynamic module with MakeMaker

      +

      33.2.3 Building a dynamic module with MakeMaker

      @@ -219,9 +220,9 @@

      33.2.3 Building a dynamic module with MakeMaker

      # File : Makefile.PL use ExtUtils::MakeMaker; WriteMakefile( - `NAME' => `example', # Name of package - `LIBS' => [`-lm'], # Name of custom libraries - `OBJECT' => `example.o example_wrap.o' # Object files + `NAME' => `example', # Name of package + `LIBS' => [`-lm'], # Name of custom libraries + `OBJECT' => `example.o example_wrap.o' # Object files ); @@ -241,7 +242,7 @@

      33.2.3 Building a dynamic module with MakeMaker

      found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen, and Randal Schwartz.

      -

      33.2.4 Building a static version of Perl

      +

      33.2.4 Building a static version of Perl

      @@ -300,7 +301,7 @@

      33.2.4 Building a static version of Perl

       $ gcc example.o example_wrap.o -L/usr/lib/perl/5.14/CORE \
      -	-lperl -lsocket -lnsl -lm -o myperl
      +        -lperl -lsocket -lnsl -lm -o myperl
       

      @@ -310,7 +311,7 @@

      33.2.4 Building a static version of Perl

      additional libraries such as -lsocket, -lnsl, -ldl, etc.

      -

      33.2.5 Using the module

      +

      33.2.5 Using the module

      @@ -463,7 +464,7 @@

      33.2.5 Using the module

      read the man pages).

      -

      33.2.6 Compilation problems and compiling with C++

      +

      33.2.6 Compilation problems and compiling with C++

      @@ -606,7 +607,7 @@

      33.2.6 Compilation problems and compiling with C++swig-user mailing list.

      -

      33.2.7 Compiling for 64-bit platforms

      +

      33.2.7 Compiling for 64-bit platforms

      @@ -633,7 +634,7 @@

      33.2.7 Compiling for 64-bit platforms

      linking standard (e.g., -o32 and -n32 on Irix).

      -

      33.3 Building Perl Extensions under Windows

      +

      33.3 Building Perl Extensions under Windows

      @@ -644,7 +645,7 @@

      33.3 Building Perl Extensions under Windows

      although the procedure may be similar with other compilers.

      -

      33.3.1 Running SWIG from Developer Studio

      +

      33.3.1 Running SWIG from Developer Studio

      @@ -707,7 +708,7 @@

      33.3.1 Running SWIG from Developer Studio

      -

      33.3.2 Using other compilers

      +

      33.3.2 Using other compilers

      @@ -715,7 +716,7 @@

      33.3.2 Using other compilers

      For general hints and suggestions refer to the Windows chapter.

      -

      33.4 The low-level interface

      +

      33.4 The low-level interface

      @@ -725,7 +726,7 @@

      33.4 The low-level interface

      construct more user-friendly proxy classes as described in the next section.

      -

      33.4.1 Functions

      +

      33.4.1 Functions

      @@ -748,7 +749,7 @@

      33.4.1 Functions

      $a = &example::fact(2); -

      33.4.2 Global variables

      +

      33.4.2 Global variables

      @@ -818,7 +819,7 @@

      33.4.2 Global variables

      -

      33.4.3 Constants

      +

      33.4.3 Constants

      @@ -858,7 +859,7 @@

      33.4.3 Constants

      -

      33.4.4 Pointers

      +

      33.4.4 Pointers

      @@ -891,9 +892,9 @@

      33.4.4 Pointers

       if (defined($ptr)) {
      -	print "Not a NULL pointer.";
      +  print "Not a NULL pointer.";
       } else {
      -	print "Is a NULL pointer.";
      +  print "Is a NULL pointer.";
       }
       
       
      @@ -916,9 +917,9 @@

      33.4.4 Pointers

       if ($$a == $$b) {
      -	print "a and b point to the same thing in C";
      +  print "a and b point to the same thing in C";
       } else {
      -	print "a and b point to different objects.";
      +  print "a and b point to different objects.";
       }
       
       
      @@ -967,7 +968,7 @@

      33.4.4 Pointers

      SWIG and XS, this is no longer supported.

      -

      33.4.5 Structures

      +

      33.4.5 Structures

      @@ -977,7 +978,7 @@

      33.4.5 Structures

       struct Vector {
      -	double x,y,z;
      +  double x,y,z;
       };
       
      @@ -1101,7 +1102,7 @@

      33.4.5 Structures

      -

      33.4.6 C++ classes

      +

      33.4.6 C++ classes

      @@ -1166,7 +1167,7 @@

      33.4.6 C++ classes

      can be built using these low-level accessors. This is described shortly.

      -

      33.4.7 C++ classes and type-checking

      +

      33.4.7 C++ classes and type-checking

      @@ -1202,7 +1203,7 @@

      33.4.7 C++ classes and type-checking

      multiple inheritance is used).

      -

      33.4.8 C++ overloaded functions

      +

      33.4.8 C++ overloaded functions

      @@ -1246,7 +1247,7 @@

      33.4.8 C++ overloaded functions

      Please refer to the "SWIG Basics" chapter for more information.

      -

      33.4.9 Operators

      +

      33.4.9 Operators

      @@ -1258,22 +1259,22 @@

      33.4.9 Operators

        -
      • operator++
      • -
      • operator--
      • -
      • operator+
      • -
      • operator-
      • -
      • operator*
      • -
      • operator/
      • -
      • operator==
      • -
      • operator!=
      • -
      • operator%
      • -
      • operator>
      • -
      • operator<
      • +
      • operator++
      • +
      • operator--
      • +
      • operator+
      • +
      • operator-
      • +
      • operator*
      • +
      • operator/
      • +
      • operator==
      • +
      • operator!=
      • +
      • operator%
      • +
      • operator>
      • +
      • operator<
      • operator and
      • operator or
      -

      33.4.10 Modules and packages

      +

      33.4.10 Modules and packages

      @@ -1368,7 +1369,7 @@

      33.4.10 Modules and packages

      --> -

      33.5 Input and output parameters

      +

      33.5 Input and output parameters

      @@ -1587,7 +1588,7 @@

      33.5 Input and output parameters

      Note: The REFERENCE feature is only currently supported for numeric types (integers and floating point).

      -

      33.6 Exception handling

      +

      33.6 Exception handling

      @@ -1752,7 +1753,7 @@

      33.6 Exception handling

      functionality, but it has additional capabilities that make it more powerful.

      -

      33.7 Remapping datatypes with typemaps

      +

      33.7 Remapping datatypes with typemaps

      @@ -1769,7 +1770,7 @@

      33.7 Remapping datatypes with typemaps

      C-Perl interface.

      -

      33.7.1 A simple typemap example

      +

      33.7.1 A simple typemap example

      @@ -1782,8 +1783,8 @@

      33.7.1 A simple typemap example

      %module example %typemap(in) int { - $1 = (int) SvIV($input); - printf("Received an integer : %d\n", $1); + $1 = (int) SvIV($input); + printf("Received an integer : %d\n", $1); } ... %inline %{ @@ -1828,8 +1829,8 @@

      33.7.1 A simple typemap example

       %typemap(in) int n {
      -	$1 = (int) SvIV($input);
      -	printf("n = %d\n",$1);
      +  $1 = (int) SvIV($input);
      +  printf("n = %d\n",$1);
       }
       %inline %{
       typedef int Integer;
      @@ -1873,7 +1874,7 @@ 

      33.7.1 A simple typemap example

      -

      33.7.2 Perl5 typemaps

      +

      33.7.2 Perl5 typemaps

      @@ -1978,7 +1979,7 @@

      33.7.2 Perl5 typemaps

      Check value of input parameter. -

      33.7.3 Typemap variables

      +

      33.7.3 Typemap variables

      @@ -2049,7 +2050,7 @@

      33.7.3 Typemap variables

      The Perl name of the wrapper function being created. -

      33.7.4 Useful functions

      +

      33.7.4 Useful functions

      @@ -2118,7 +2119,7 @@

      33.7.4 Useful functions

      -

      33.8 Typemap Examples

      +

      33.8 Typemap Examples

      @@ -2127,7 +2128,7 @@

      33.8 Typemap Examples

      the SWIG library.

      -

      33.8.1 Converting a Perl5 array to a char **

      +

      33.8.1 Converting a Perl5 array to a char **

      @@ -2142,47 +2143,47 @@

      33.8.1 Converting a Perl5 array to a char **

      // This tells SWIG to treat char ** as a special case %typemap(in) char ** { - AV *tempav; - I32 len; - int i; - SV **tv; - if (!SvROK($input)) - croak("Argument $argnum is not a reference."); - if (SvTYPE(SvRV($input)) != SVt_PVAV) - croak("Argument $argnum is not an array."); - tempav = (AV*)SvRV($input); - len = av_len(tempav); - $1 = (char **) malloc((len+2)*sizeof(char *)); - for (i = 0; i <= len; i++) { - tv = av_fetch(tempav, i, 0); - $1[i] = (char *) SvPV(*tv,PL_na); - } - $1[i] = NULL; + AV *tempav; + I32 len; + int i; + SV **tv; + if (!SvROK($input)) + croak("Argument $argnum is not a reference."); + if (SvTYPE(SvRV($input)) != SVt_PVAV) + croak("Argument $argnum is not an array."); + tempav = (AV*)SvRV($input); + len = av_len(tempav); + $1 = (char **) malloc((len+2)*sizeof(char *)); + for (i = 0; i <= len; i++) { + tv = av_fetch(tempav, i, 0); + $1[i] = (char *) SvPV(*tv,PL_na); + } + $1[i] = NULL; }; // This cleans up the char ** array after the function call %typemap(freearg) char ** { - free($1); + free($1); } // Creates a new Perl array and places a NULL-terminated char ** into it %typemap(out) char ** { - AV *myav; - SV **svs; - int i = 0,len = 0; - /* Figure out how many elements we have */ - while ($1[len]) - len++; - svs = (SV **) malloc(len*sizeof(SV *)); - for (i = 0; i < len ; i++) { - svs[i] = sv_newmortal(); - sv_setpv((SV*)svs[i],$1[i]); - }; - myav = av_make(len,svs); - free(svs); - $result = newRV_noinc((SV*)myav); - sv_2mortal($result); - argvi++; + AV *myav; + SV **svs; + int i = 0,len = 0; + /* Figure out how many elements we have */ + while ($1[len]) + len++; + svs = (SV **) malloc(len*sizeof(SV *)); + for (i = 0; i < len ; i++) { + svs[i] = sv_newmortal(); + sv_setpv((SV*)svs[i],$1[i]); + }; + myav = av_make(len,svs); + free(svs); + $result = newRV_noinc((SV*)myav); + sv_2mortal($result); + argvi++; } // Now a few test functions @@ -2219,7 +2220,7 @@

      33.8.1 Converting a Perl5 array to a char **

      -

      33.8.2 Return values

      +

      33.8.2 Return values

      @@ -2239,16 +2240,16 @@

      33.8.2 Return values

       %typemap(argout) int *OUTPUT {
      -	if (argvi >= items) {            
      -		EXTEND(sp,1);              /* Extend the stack by 1 object */
      -	}
      -	$result = sv_newmortal();
      -	sv_setiv($target,(IV) *($1));
      -	argvi++;
      +  if (argvi >= items) {
      +    EXTEND(sp,1);              /* Extend the stack by 1 object */
      +  }
      +  $result = sv_newmortal();
      +  sv_setiv($target,(IV) *($1));
      +  argvi++;
       }
       
      -

      33.8.3 Returning values from arguments

      +

      33.8.3 Returning values from arguments

      @@ -2263,24 +2264,24 @@

      33.8.3 Returning values from arguments

      // an output value. %typemap(argout) double *OUTPUT { - $result = sv_newmortal(); - sv_setnv($result, *$input); - argvi++; /* Increment return count -- important! */ + $result = sv_newmortal(); + sv_setnv($result, *$input); + argvi++; /* Increment return count -- important! */ } // We don't care what the input value is. Ignore, but set to a temporary variable %typemap(in,numinputs=0) double *OUTPUT(double junk) { - $1 = &junk; + $1 = &junk; } // Now a function to test it %{ /* Returns the first two input arguments */ int multout(double a, double b, double *out1, double *out2) { - *out1 = a; - *out2 = b; - return 0; + *out1 = a; + *out2 = b; + return 0; }; %} @@ -2302,7 +2303,7 @@

      33.8.3 Returning values from arguments

      ($x,$y) = multout(7,13); -

      33.8.4 Accessing array structure members

      +

      33.8.4 Accessing array structure members

      @@ -2365,7 +2366,7 @@

      33.8.4 Accessing array structure members

      to copy the converted array into a C data structure.

      -

      33.8.5 Turning Perl references into C pointers

      +

      33.8.5 Turning Perl references into C pointers

      @@ -2376,7 +2377,7 @@

      33.8.5 Turning Perl references into C pointers

       void add(double a, double b, double *c) {
      -	*c = a + b;
      +  *c = a + b;
       }
       
      @@ -2430,7 +2431,7 @@

      33.8.5 Turning Perl references into C pointers

      -

      33.8.6 Pointer handling

      +

      33.8.6 Pointer handling

      @@ -2509,7 +2510,7 @@

      33.8.6 Pointer handling

      -

      33.9 Proxy classes

      +

      33.9 Proxy classes

      @@ -2525,7 +2526,7 @@

      33.9 Proxy classes

      details of the proxy interface.

      -

      33.9.1 Preliminaries

      +

      33.9.1 Preliminaries

      @@ -2547,7 +2548,7 @@

      33.9.1 Preliminaries

      high level wrappers. The wrappers, in turn, interact with the low-level procedural module.

      -

      33.9.2 Structure and class wrappers

      +

      33.9.2 Structure and class wrappers

      @@ -2557,9 +2558,9 @@

      33.9.2 Structure and class wrappers

       %module example
       struct Vector {
      -	Vector(double x, double y, double z);
      -	~Vector();
      -	double x,y,z;
      +  Vector(double x, double y, double z);
      +  ~Vector();
      +  double x,y,z;
       };
       
       
      @@ -2609,8 +2610,9 @@

      33.9.2 Structure and class wrappers

      my $self = tied(%{$_[0]}); delete $ITERATORS{$self}; if (exists $OWNER{$self}) { - examplec::delete_Vector($self)); - delete $OWNER{$self}; + examplec::delete_Vector($self)); + delete $OWNER{$self}; + } } sub FETCH { @@ -2662,8 +2664,8 @@

      33.9.2 Structure and class wrappers

      # Assignment of all members %$v = ( x=>3, - y=>9, - z=>-2); + y=>9, + z=>-2); # Reading members $x = $v->{x}; @@ -2673,7 +2675,7 @@

      33.9.2 Structure and class wrappers

      -

      33.9.3 Object Ownership

      +

      33.9.3 Object Ownership

      @@ -2684,7 +2686,7 @@

      33.9.3 Object Ownership

       Vector *Vector_get(Vector *v, int index) {
      -	return &v[i];
      +  return &v[i];
       }
       
      @@ -2697,9 +2699,9 @@

      33.9.3 Object Ownership

       Vector *new_Vector(double x, double y, double z) {
      -	Vector *v;
      -	v = new Vector(x,y,z);        // Call C++ constructor
      -	return v;
      +  Vector *v;
      +  v = new Vector(x,y,z);        // Call C++ constructor
      +  return v;
       }
       
      @@ -2760,7 +2762,7 @@

      33.9.3 Object Ownership

      sophisticated languages.

      -

      33.9.4 Nested Objects

      +

      33.9.4 Nested Objects

      @@ -2769,10 +2771,10 @@

      33.9.4 Nested Objects

       struct Particle {
      -	Vector r;
      -	Vector v;
      -	Vector f;
      -	int	type;
      +  Vector r;
      +  Vector v;
      +  Vector f;
      +  int type;
       }
       
       
      @@ -2788,9 +2790,9 @@

      33.9.4 Nested Objects

      package Particle; ... %BLESSEDMEMBERS = ( - r => `Vector', - v => `Vector', - f => `Vector', + r => `Vector', + v => `Vector', + f => `Vector', ); @@ -2813,7 +2815,7 @@

      33.9.4 Nested Objects

      %${$p->{v}} = ( x=>0, y=>0, z=>0); -

      33.9.5 Proxy Functions

      +

      33.9.5 Proxy Functions

      @@ -2847,7 +2849,7 @@

      33.9.5 Proxy Functions

      identical manner.

      -

      33.9.6 Inheritance

      +

      33.9.6 Inheritance

      @@ -2866,23 +2868,23 @@

      33.9.6 Inheritance

      class Shape { public: - virtual double area() = 0; - virtual double perimeter() = 0; - void set_location(double x, double y); + virtual double area() = 0; + virtual double perimeter() = 0; + void set_location(double x, double y); }; class Circle : public Shape { public: - Circle(double radius); - ~Circle(); - double area(); - double perimeter(); + Circle(double radius); + ~Circle(); + double area(); + double perimeter(); }; class Square : public Shape { public: - Square(double size); - ~Square(); - double area(); - double perimeter(); + Square(double size); + ~Square(); + double area(); + double perimeter(); } @@ -2923,7 +2925,7 @@

      33.9.6 Inheritance

      not even sure if it really works).

      -

      33.9.7 Modifying the proxy methods

      +

      33.9.7 Modifying the proxy methods

      @@ -2951,7 +2953,7 @@

      33.9.7 Modifying the proxy methods

      }; -

      33.10 Adding additional Perl code

      +

      33.10 Adding additional Perl code

      @@ -3002,7 +3004,7 @@

      33.10 Adding additional Perl code

      -

      33.11 Cross language polymorphism

      +

      33.11 Cross language polymorphism

      @@ -3036,7 +3038,7 @@

      33.11 Cross language polymorphism

      all the cross-language method routing transparently.

      -

      33.11.1 Enabling directors

      +

      33.11.1 Enabling directors

      @@ -3126,7 +3128,7 @@

      33.11.1 Enabling directors

      -

      33.11.2 Director classes

      +

      33.11.2 Director classes

      @@ -3206,7 +3208,7 @@

      33.11.2 Director classes

      calls through Perl.

      -

      33.11.3 Ownership and object destruction

      +

      33.11.3 Ownership and object destruction

      @@ -3255,7 +3257,7 @@

      33.11.3 Ownership and object destruction

      -

      33.11.4 Exception unrolling

      +

      33.11.4 Exception unrolling

      @@ -3311,7 +3313,7 @@

      33.11.4 Exception unrolling

      exception as soon as the C wrapper function returns.

      -

      33.11.5 Overhead and code bloat

      +

      33.11.5 Overhead and code bloat

      @@ -3345,7 +3347,7 @@

      33.11.5 Overhead and code bloat

      Perl.

      -

      33.11.6 Typemaps

      +

      33.11.6 Typemaps

      diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 623adb68ad0..8c483b7a076 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -1,13 +1,13 @@ - - + SWIG and PHP + -

      34 SWIG and PHP

      +

      34 SWIG and PHP

        @@ -25,7 +25,7 @@

        34 SWIG and PHP

      • Pointers and References
      • Structures and C++ classes
          -
        • Using -noproxy +
        • Using -noproxy
        • Constructors and Destructors
        • Static Member Variables
        • Static Member Functions @@ -80,7 +80,7 @@

          34 SWIG and PHP

          available.

          -

          34.1 Generating PHP Extensions

          +

          34.1 Generating PHP Extensions

          @@ -125,7 +125,7 @@

          34.1 Generating PHP Extensions

          this approach, or provide explicit support for it.

          -

          34.1.1 Building a loadable extension

          +

          34.1.1 Building a loadable extension

          @@ -136,11 +136,11 @@

          34.1.1 Building a loadable extension

          -	gcc `php-config --includes` -fpic -c example_wrap.c example.c
          -	gcc -shared example_wrap.o example.o -o example.so
          +        gcc `php-config --includes` -fpic -c example_wrap.c example.c
          +        gcc -shared example_wrap.o example.o -o example.so
           
          -

          34.1.2 Using PHP Extensions

          +

          34.1.2 Using PHP Extensions

          @@ -150,7 +150,7 @@

          34.1.2 Using PHP Extensions

          -	extension=/path/to/modulename.so
          +        extension=/path/to/modulename.so
           

          @@ -165,7 +165,7 @@

          34.1.2 Using PHP Extensions

          -	dl("/path/to/modulename.so");	// Load the module
          +        dl("/path/to/modulename.so"); // Load the module
           

          @@ -180,7 +180,7 @@

          34.1.2 Using PHP Extensions

          -	include("example.php");
          +        include("example.php");
           

          @@ -188,7 +188,7 @@

          34.1.2 Using PHP Extensions

          almost certainly want to include it anyway.

          -

          34.2 Basic PHP interface

          +

          34.2 Basic PHP interface

          @@ -199,7 +199,7 @@

          34.2 Basic PHP interface

          SWIG doesn't have support for the namespace feature added in PHP 5.3.

          -

          34.2.1 Constants

          +

          34.2.1 Constants

          @@ -249,7 +249,7 @@

          34.2.1 Constants

           %module example
           
          -#define EASY_TO_MISPELL	0
          +#define EASY_TO_MISPELL 0
           
          @@ -262,9 +262,9 @@

          34.2.1 Constants

          include("example.php"); if(EASY_TO_MISPEL) { - .... + ... } else { - .... + ... } @@ -276,7 +276,7 @@

          34.2.1 Constants

          would be treated as false!

          -

          34.2.2 Global Variables

          +

          34.2.2 Global Variables

          @@ -303,7 +303,7 @@

          34.2.2 Global Variables

           include("example.php");
           print seki_get();
          -seki_set( seki_get() * 2);	# The C variable is now 4.
          +seki_set( seki_get() * 2); # The C variable is now 4.
           print seki_get();
           
          @@ -325,7 +325,7 @@

          34.2.2 Global Variables

          At this time SWIG does not support custom accessor methods.

          -

          34.2.3 Functions

          +

          34.2.3 Functions

          @@ -348,7 +348,7 @@

          34.2.3 Functions

          include("example.php"); $a = foo(2); $b = bar(3.5, -1.5); -$c = bar(3.5); # Use default argument for 2nd parameter +$c = bar(3.5); # Use default argument for 2nd parameter
      @@ -378,7 +378,7 @@

      34.2.3 Functions

      --> -

      34.2.4 Overloading

      +

      34.2.4 Overloading

      @@ -434,7 +434,7 @@

      34.2.4 Overloading

      --> -

      34.2.5 Pointers and References

      +

      34.2.5 Pointers and References

      @@ -579,7 +579,7 @@

      34.2.5 Pointers and References

      variable, or assigning NULL to a variable.

      -

      34.2.6 Structures and C++ classes

      +

      34.2.6 Structures and C++ classes

      @@ -599,10 +599,10 @@

      34.2.6 Structures and C++ classes

      class Vector { public: - double x,y,z; - Vector(); - ~Vector(); - double magnitude(); + double x,y,z; + Vector(); + ~Vector(); + double magnitude(); }; struct Complex { @@ -640,7 +640,7 @@

      34.2.6 Structures and C++ classes

      Member variables and methods are accessed using the -> operator.

      -

      34.2.6.1 Using -noproxy

      +

      34.2.6.1 Using -noproxy

      @@ -666,7 +666,7 @@

      34.2.6.1 Using -noproxy

      Complex_im_get($obj); -

      34.2.6.2 Constructors and Destructors

      +

      34.2.6.2 Constructors and Destructors

      @@ -707,7 +707,7 @@

      34.2.6.2 Constructors and Destructors

      unset($v)

      -

      34.2.6.3 Static Member Variables

      +

      34.2.6.3 Static Member Variables

      @@ -722,7 +722,7 @@

      34.2.6.3 Static Member Variables

      %module example class Ko { - static int threats; + static int threats; }; @@ -750,7 +750,7 @@

      34.2.6.3 Static Member Variables

      echo "There have now been " . Ko::threats() . " threats\n"; -

      34.2.6.4 Static Member Functions

      +

      34.2.6.4 Static Member Functions

      @@ -772,7 +772,7 @@

      34.2.6.4 Static Member Functions

      -

      34.2.6.5 Specifying Implemented Interfaces

      +

      34.2.6.5 Specifying Implemented Interfaces

      @@ -790,7 +790,7 @@

      34.2.6.5 Specifying Implemented Interfaces

      If there are multiple interfaces, just list them separated by commas.

      -

      34.2.7 PHP Pragmas, Startup and Shutdown code

      +

      34.2.7 PHP Pragmas, Startup and Shutdown code

      @@ -878,7 +878,7 @@

      34.2.7 PHP Pragmas, Startup and Shutdown code

      into the request init (PHP_RINIT_FUNCTION) and request shutdown (PHP_RSHUTDOWN_FUNCTION) code respectively.

      -

      34.3 Cross language polymorphism

      +

      34.3 Cross language polymorphism

      @@ -913,7 +913,7 @@

      34.3 Cross language polymorphism

      transparently.

      -

      34.3.1 Enabling directors

      +

      34.3.1 Enabling directors

      @@ -1002,7 +1002,7 @@

      34.3.1 Enabling directors

      -

      34.3.2 Director classes

      +

      34.3.2 Director classes

      @@ -1082,7 +1082,7 @@

      34.3.2 Director classes

      calls through PHP.

      -

      34.3.3 Ownership and object destruction

      +

      34.3.3 Ownership and object destruction

      @@ -1138,7 +1138,7 @@

      34.3.3 Ownership and object destruction

      deleting all the Foo pointers it contains at some point.

      -

      34.3.4 Exception unrolling

      +

      34.3.4 Exception unrolling

      @@ -1197,7 +1197,7 @@

      34.3.4 Exception unrolling

      as soon as the C wrapper function returns.

      -

      34.3.5 Overhead and code bloat

      +

      34.3.5 Overhead and code bloat

      @@ -1230,7 +1230,7 @@

      34.3.5 Overhead and code bloat

      directive) for only those methods that are likely to be extended in PHP.

      -

      34.3.6 Typemaps

      +

      34.3.6 Typemaps

      @@ -1244,7 +1244,7 @@

      34.3.6 Typemaps

      -

      34.3.7 Miscellaneous

      +

      34.3.7 Miscellaneous

      Director typemaps for STL classes are mostly in place, and hence you diff --git a/Doc/Manual/Pike.html b/Doc/Manual/Pike.html index 44c6930f876..22ab4e2a2b1 100644 --- a/Doc/Manual/Pike.html +++ b/Doc/Manual/Pike.html @@ -1,12 +1,13 @@ - + SWIG and Pike + -

      35 SWIG and Pike

      +

      35 SWIG and Pike

      -

      35.2 Basic C/C++ Mapping

      +

      35.2 Basic C/C++ Mapping

      -

      35.2.1 Modules

      +

      35.2.1 Modules

      @@ -143,7 +144,7 @@

      35.2.1 Modules

      significance.

      -

      35.2.2 Functions

      +

      35.2.2 Functions

      @@ -168,7 +169,7 @@

      35.2.2 Functions

      (1) Result: 24 -

      35.2.3 Global variables

      +

      35.2.3 Global variables

      @@ -197,7 +198,7 @@

      35.2.3 Global variables

      (3) Result: 3.141590 -

      35.2.4 Constants and enumerated types

      +

      35.2.4 Constants and enumerated types

      @@ -205,7 +206,7 @@

      35.2.4 Constants and enumerated types

      not as Pike enums.

      -

      35.2.5 Constructors and Destructors

      +

      35.2.5 Constructors and Destructors

      @@ -213,7 +214,7 @@

      35.2.5 Constructors and Destructors

      wrapped as destroy() methods, for Pike classes.

      -

      35.2.6 Static Members

      +

      35.2.6 Static Members

      diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index d17dc229c91..4a9ad5ba9c4 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -1,12 +1,13 @@ - + Preface + -

      1 Preface

      +

      1 Preface

        @@ -35,7 +36,7 @@

        1 Preface

        -

        1.1 Introduction

        +

        1.1 Introduction

        @@ -58,7 +59,7 @@

        1.1 Introduction

        variety of applications--in fact almost anything where C/C++ programming is involved. -

        1.2 SWIG Versions

        +

        1.2 SWIG Versions

        @@ -70,7 +71,7 @@

        1.2 SWIG Versions

        license changes and this gave rise to version 2.0.0 in 2010.

        -

        1.3 SWIG License

        +

        1.3 SWIG License

        @@ -86,7 +87,7 @@

        1.3 SWIG License

        source was placed under the GNU General Public License version 3.

        -

        1.4 SWIG resources

        +

        1.4 SWIG resources

        @@ -126,7 +127,7 @@

        1.4 SWIG resources

        -

        1.5 Prerequisites

        +

        1.5 Prerequisites

        @@ -151,7 +152,7 @@

        1.5 Prerequisites

        of the gory details, you will almost certainly want to consult a good C++ reference. If you don't program in C++, you may just want to skip those parts of the manual. -

        1.6 Organization of this manual

        +

        1.6 Organization of this manual

        @@ -163,7 +164,7 @@

        1.6 Organization of this manual

        to know.

        -

        1.7 How to avoid reading the manual

        +

        1.7 How to avoid reading the manual

        @@ -175,7 +176,7 @@

        1.7 How to avoid reading the manual

        examples that illustrate different topics.

        -

        1.8 Backwards compatibility

        +

        1.8 Backwards compatibility

        @@ -211,7 +212,7 @@

        1.8 Backwards compatibility

        wrapper file. The SWIG preprocessor has defined SWIG_VERSION since SWIG-1.3.11.

        -

        1.9 Release notes

        +

        1.9 Release notes

        @@ -220,7 +221,7 @@

        1.9 Release notes

        detailed release notes for previous releases and summary release notes from SWIG-1.3.22 onwards.

        -

        1.10 Credits

        +

        1.10 Credits

        @@ -233,7 +234,7 @@

        1.10 Credits

        are mentioned either in the COPYRIGHT file or CHANGES files shipped with SWIG or in submitted bugs.

        -

        1.11 Bug reports

        +

        1.11 Bug reports

        @@ -248,21 +249,21 @@

        1.11 Bug reports

        can only fix bugs if we know about them.

        -

        1.12 Installation

        +

        1.12 Installation

        -

        1.12.1 Windows installation

        +

        1.12.1 Windows installation

        -Please see the dedicated Windows chapter for instructions on installing +Please see the dedicated Windows chapter for instructions on installing SWIG on Windows and running the examples. The Windows distribution is called swigwin and includes a prebuilt SWIG executable, swig.exe, included in the top level directory. Otherwise it is exactly the same as the main SWIG distribution. There is no need to download anything else.

        -

        1.12.2 Unix installation

        +

        1.12.2 Unix installation

        @@ -332,7 +333,7 @@

        1.12.2 Unix installation

        SWIG used to include a set of runtime libraries for some languages for working with multiple modules. These are no longer built during the installation stage. However, users can build them just like any wrapper module as described in -the Modules chapter. +the Modules chapter. The CHANGES file shipped with SWIG in the top level directory also lists some examples which build the runtime library.

        @@ -350,7 +351,7 @@

        1.12.2 Unix installation

      -

      1.12.3 Macintosh OS X installation

      +

      1.12.3 Macintosh OS X installation

      @@ -370,7 +371,7 @@

      1.12.3 Macintosh OS X installationhttp://developer.apple.com/documentation/ReleaseNotes/DeveloperTools/TwoLevelNamespaces.html. +Understanding Two-Level Namespaces.

      @@ -378,7 +379,7 @@

      1.12.3 Macintosh OS X installation -

      1.12.4 Testing

      +

      1.12.4 Testing

      @@ -432,7 +433,7 @@

      1.12.4 Testing

      might take more than an hour to run the test-suite.

      -

      1.12.5 Examples

      +

      1.12.5 Examples

      diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html index 745570ca466..2538f8f18de 100644 --- a/Doc/Manual/Preprocessor.html +++ b/Doc/Manual/Preprocessor.html @@ -1,12 +1,13 @@ - + SWIG Preprocessor + -

      8 Preprocessing

      +

      8 Preprocessing

        @@ -37,7 +38,7 @@

        8 Preprocessing

        chapter describes some of these modifications.

        -

        8.1 File inclusion

        +

        8.1 File inclusion

        @@ -63,7 +64,7 @@

        8.1 File inclusion

        is that you often don't want SWIG to try and wrap everything included in standard header system headers and auxiliary files. -

        8.2 File imports

        +

        8.2 File imports

        @@ -92,7 +93,7 @@

        8.2 File imports

        as imports. This might be useful if you want to extract type definitions from system header files without generating any wrappers. -

        8.3 Conditional Compilation

        +

        8.3 Conditional Compilation

        @@ -120,7 +121,7 @@

        8.3 Conditional Compilation SWIG_JAVASCRIPT_V8 Defined when using Javascript for v8 or node.js SWIGLUA Defined when using Lua SWIGMODULA3 Defined when using Modula-3 -SWIGMZSCHEME Defined when using Mzscheme +SWIGMZSCHEME Defined when using Mzscheme SWIGOCAML Defined when using Ocaml SWIGOCTAVE Defined when using Octave SWIGPERL Defined when using Perl @@ -129,6 +130,7 @@

        8.3 Conditional Compilation SWIGPYTHON Defined when using Python SWIGR Defined when using R SWIGRUBY Defined when using Ruby +SWIGSCILAB Defined when using Scilab SWIGSEXP Defined when using S-expressions SWIGTCL Defined when using Tcl SWIGXML Defined when using XML @@ -155,7 +157,7 @@

        8.3 Conditional Compilation within the SWIG compiler).

        -

        8.4 Macro Expansion

        +

        8.4 Macro Expansion

        @@ -210,7 +212,7 @@

        8.4 Macro Expansion

      -

      8.5 SWIG Macros

      +

      8.5 SWIG Macros

      @@ -256,7 +258,7 @@

      8.5 SWIG Macros

      support).

      -

      8.6 C99 and GNU Extensions

      +

      8.6 C99 and GNU Extensions

      @@ -312,14 +314,14 @@

      8.6 C99 and GNU Extensions

      SWIG directives and are provided to make SWIG more compatible with C99 code.

      -

      8.7 Preprocessing and delimiters

      +

      8.7 Preprocessing and delimiters

      The preprocessor handles { }, " " and %{ %} delimiters differently.

      -

      8.7.1 Preprocessing and %{ ... %} & " ... " delimiters

      +

      8.7.1 Preprocessing and %{ ... %} & " ... " delimiters

      @@ -344,7 +346,7 @@

      8.7.1 Preprocessing and %{ ... %} & " ... modification to the output (including all preprocessor directives).

      -

      8.7.2 Preprocessing and { ... } delimiters

      +

      8.7.2 Preprocessing and { ... } delimiters

      @@ -386,7 +388,7 @@

      8.7.2 Preprocessing and { ... } delimiters% and leave the preprocessor directive in the code.

      -

      8.8 Preprocessor and Typemaps

      +

      8.8 Preprocessor and Typemaps

      @@ -457,7 +459,7 @@

      8.8 Preprocessor and Typemaps<

      -

      8.9 Viewing preprocessor output

      +

      8.9 Viewing preprocessor output

      @@ -467,7 +469,7 @@

      8.9 Viewing preprocessor output

      This might be useful as an aid to debugging and viewing the results of macro expansions.

      -

      8.10 The #error and #warning directives

      +

      8.10 The #error and #warning directives

      diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index eb102aa3e13..1dce1806c5a 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -1,12 +1,13 @@ - + SWIG and Python + -

      36 SWIG and Python

      +

      36 SWIG and Python

      @@ -142,7 +149,7 @@

      36 SWIG and Python

      Basics" chapter.

      -

      36.1 Overview

      +

      36.1 Overview

      @@ -169,10 +176,10 @@

      36.1 Overview

      details.

      -

      36.2 Preliminaries

      +

      36.2 Preliminaries

      -

      36.2.1 Running SWIG

      +

      36.2.1 Running SWIG

      @@ -270,13 +277,13 @@

      36.2.1 Running SWIG

      how you might go about compiling and using the generated files.

      -

      36.2.2 Using distutils

      +

      36.2.2 Using distutils

      The preferred approach to building an extension module for python is to compile it with distutils, which comes with all recent versions of python -(Distutils Docs). +(Distutils Docs).

      @@ -362,7 +369,7 @@

      36.2.2 Using distutils

      can even build extensions to the standard Windows Python using MingGW)

      -

      36.2.3 Hand compiling a dynamic module

      +

      36.2.3 Hand compiling a dynamic module

      @@ -410,7 +417,7 @@

      36.2.3 Hand compiling a dynamic module

      -

      36.2.4 Static linking

      +

      36.2.4 Static linking

      @@ -455,14 +462,14 @@

      36.2.4 Static linking

      -$ swig -python example.i
      +$ swig -python -lembed.i example.i
       $ gcc example.c example_wrap.c \
               -Xlinker -export-dynamic \
      -        -DHAVE_CONFIG_H -I/usr/local/include/python2.1 \
      -	-I/usr/local/lib/python2.1/config \
      -	-L/usr/local/lib/python2.1/config -lpython2.1 -lm -ldl \
      -	-o mypython
      -
      +        -DHAVE_CONFIG_H -I/usr/include/python2.7 \
      +        -I/usr/lib/python2.7/config-x86_64-linux-gnu \
      +        -I/usr/lib/python2.7/config \
      +        -L/usr/lib/python2.7/config -lpython2.7 -lm -ldl \
      +        -o mypython
       

      You will need to supply the same libraries that were used to build Python the first @@ -483,13 +490,13 @@

      36.2.4 Static linking

      Compatibility note: The embed.i library file is -deprecated and has not been maintained for several years. Even though it -appears to "work" with Python 2.1, no future support is guaranteed. +deprecated and has not been actively maintained for many years. Even though it +appears to "work" with Python 2.7, no future support is guaranteed. If using static linking, you might want to rely on a different approach (perhaps using distutils).

      -

      36.2.5 Using your module

      +

      36.2.5 Using your module

      @@ -646,7 +653,7 @@

      36.2.5 Using your module

      read the man pages).

      -

      36.2.6 Compilation of C++ extensions

      +

      36.2.6 Compilation of C++ extensions

      @@ -738,7 +745,7 @@

      36.2.6 Compilation of C++ extensions

      might want to investigate using a more formal standard such as COM.

      -

      36.2.7 Compiling for 64-bit platforms

      +

      36.2.7 Compiling for 64-bit platforms

      @@ -775,7 +782,7 @@

      36.2.7 Compiling for 64-bit platforms

      extension.

      -

      36.2.8 Building Python Extensions under Windows

      +

      36.2.8 Building Python Extensions under Windows

      @@ -904,7 +911,7 @@

      36.2.8 Building Python Extensions under Windows -

      36.3 A tour of basic C/C++ wrapping

      +

      36.3 A tour of basic C/C++ wrapping

      @@ -913,7 +920,7 @@

      36.3 A tour of basic C/C++ wrapping

      This section briefly covers the essential aspects of this wrapping.

      -

      36.3.1 Modules

      +

      36.3.1 Modules

      @@ -926,7 +933,7 @@

      36.3.1 Modules

      Python command or standard module name.

      -

      36.3.2 Functions

      +

      36.3.2 Functions

      @@ -950,7 +957,7 @@

      36.3.2 Functions

      >>>
      -

      36.3.3 Global variables

      +

      36.3.3 Global variables

      @@ -1088,7 +1095,7 @@

      36.3.3 Global variables

      if there are no global variables in a module.

      -

      36.3.4 Constants and enums

      +

      36.3.4 Constants and enums

      @@ -1128,7 +1135,7 @@

      36.3.4 Constants and enums

      generate code that prevents this. You will just have to be careful.

      -

      36.3.5 Pointers

      +

      36.3.5 Pointers

      @@ -1269,7 +1276,7 @@

      36.3.5 Pointers

      None if the conversion can't be performed.

      -

      36.3.6 Structures

      +

      36.3.6 Structures

      @@ -1279,7 +1286,7 @@

      36.3.6 Structures

       struct Vector {
      -	double x,y,z;
      +  double x,y,z;
       };
       
       
      @@ -1458,7 +1465,7 @@

      36.3.6 Structures

      -

      36.3.7 C++ classes

      +

      36.3.7 C++ classes

      @@ -1547,7 +1554,7 @@

      36.3.7 C++ classes

      -

      36.3.8 C++ inheritance

      +

      36.3.8 C++ inheritance

      @@ -1602,7 +1609,7 @@

      36.3.8 C++ inheritance

      It is safe to use multiple inheritance with SWIG.

      -

      36.3.9 Pointers, references, values, and arrays

      +

      36.3.9 Pointers, references, values, and arrays

      @@ -1663,7 +1670,7 @@

      36.3.9 Pointers, references, values, and arrays -

      36.3.10 C++ overloaded functions

      +

      36.3.10 C++ overloaded functions

      @@ -1786,7 +1793,7 @@

      36.3.10 C++ overloaded functions

      Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      36.3.11 C++ operators

      +

      36.3.11 C++ operators

      @@ -1875,7 +1882,7 @@

      36.3.11 C++ operators

      overloaded assignment operators don't map to Python semantics and will be ignored.

      -

      36.3.12 C++ namespaces

      +

      36.3.12 C++ namespaces

      @@ -1942,7 +1949,7 @@

      36.3.12 C++ namespaces

      identical symbol names, well, then you get what you deserve.

      -

      36.3.13 C++ templates

      +

      36.3.13 C++ templates

      @@ -1996,7 +2003,21 @@

      36.3.13 C++ templates

      examples will appear later.

      -

      36.3.14 C++ Smart Pointers

      +

      36.3.14 C++ Smart Pointers

      + + +

      36.3.14.1 The shared_ptr Smart Pointer

      + + +

      +The C++11 standard provides std::shared_ptr which was derived from the Boost +implementation, boost::shared_ptr. +Both of these are available for Python in the SWIG library and usage is outlined +in the shared_ptr smart pointer library section. +

      + + +

      36.3.14.2 Generic Smart Pointers

      @@ -2080,7 +2101,7 @@

      36.3.14 C++ Smart Pointers

      -

      36.3.15 C++ reference counted objects

      +

      36.3.15 C++ reference counted objects

      @@ -2089,7 +2110,7 @@

      36.3.15 C++ reference counted objects

      -

      36.4 Further details on the Python class interface

      +

      36.4 Further details on the Python class interface

      @@ -2112,7 +2133,7 @@

      36.4 Further details on the Python class interface section.

      -

      36.4.1 Proxy classes

      +

      36.4.1 Proxy classes

      @@ -2169,15 +2190,15 @@

      36.4.1 Proxy classes

      import _example class Foo(object): - def __init__(self): - self.this = _example.new_Foo() - self.thisown = 1 - def __del__(self): - if self.thisown: - _example.delete_Foo(self.this) - def spam(self,arg1): - return _example.Foo_spam(self.this,arg1) - x = property(_example.Foo_x_get, _example.Foo_x_set) + def __init__(self): + self.this = _example.new_Foo() + self.thisown = 1 + def __del__(self): + if self.thisown: + _example.delete_Foo(self.this) + def spam(self,arg1): + return _example.Foo_spam(self.this,arg1) + x = property(_example.Foo_x_get, _example.Foo_x_set) @@ -2201,7 +2222,7 @@

      36.4.1 Proxy classes

      by Python built-in types until Python 2.2).

      -

      36.4.2 Built-in Types

      +

      36.4.2 Built-in Types

      @@ -2219,9 +2240,9 @@

      36.4.2 Built-in Types

       class Foo(object):
      -     def __init__(self):
      -         self.this = _example.new_Foo()
      -         self.thisown = 1
      +    def __init__(self):
      +        self.this = _example.new_Foo()
      +        self.thisown = 1
       
      @@ -2245,7 +2266,7 @@

      36.4.2 Built-in Types

      http://docs.python.org/extending/newtypes.html

      -

      36.4.2.1 Limitations

      +

      36.4.2.1 Limitations

      Use of the -builtin option implies a couple of limitations: @@ -2313,11 +2334,11 @@

      36.4.2.1 Limitations

      -class MyPyException (Exception) :
      -    def __init__(self, msg, *args) :
      +class MyPyException(Exception):
      +    def __init__(self, msg, *args):
               Exception.__init__(self, *args)
               self.myexc = MyException(msg)
      -    def what (self) :
      +    def what(self):
               return self.myexc.what()
       
      @@ -2413,7 +2434,7 @@

      36.4.2.1 Limitations

      -

      36.4.2.2 Operator overloads -- use them!

      +

      36.4.2.2 Operator overloads -- use them!

      The entire justification for the -builtin option is improved @@ -2514,7 +2535,7 @@

      36.4.2.2 Operator overloads -- use th

      -

      36.4.3 Memory management

      +

      36.4.3 Memory management

      NOTE: Although this section refers to proxy objects, everything here also applies @@ -2709,7 +2730,7 @@

      36.4.3 Memory management

      typemaps--an advanced topic discussed later.

      -

      36.4.4 Python 2.2 and classic classes

      +

      36.4.4 Python 2.2 and classic classes

      @@ -2719,7 +2740,7 @@

      36.4.4 Python 2.2 and classic classes

      This new-style class system offers many enhancements including static member functions, properties (managed attributes), and class methods. Details about all of these changes can be found on www.python.org and is not repeated here. +href="https://www.python.org">www.python.org and is not repeated here.

      @@ -2734,7 +2755,7 @@

      36.4.4 Python 2.2 and classic classes

      This dual-nature of the wrapper code means that you can create extension modules with SWIG and those modules will work with all versions of Python -ranging from Python-1.4 to the very latest release. Moreover, the wrappers take +ranging from Python-2.0 to the very latest release. Moreover, the wrappers take advantage of Python-2.2 features when available.

      @@ -2746,7 +2767,7 @@

      36.4.4 Python 2.2 and classic classes

      function or through an instance (see the earlier section).

      -

      36.5 Cross language polymorphism

      +

      36.5 Cross language polymorphism

      @@ -2780,7 +2801,7 @@

      36.5 Cross language polymorphism

      all the cross-language method routing transparently.

      -

      36.5.1 Enabling directors

      +

      36.5.1 Enabling directors

      @@ -2841,6 +2862,7 @@

      36.5.1 Enabling directors

      class Foo { public: Foo(int foo); + virtual ~Foo(); virtual void one(); virtual void two(); }; @@ -2861,16 +2883,17 @@

      36.5.1 Enabling directors

      import mymodule class MyFoo(mymodule.Foo): - def __init__(self, foo): - mymodule.Foo(self, foo) + def __init__(self, foo): + mymodule.Foo.__init__(self, foo) +# super().__init__(foo) # Alternative construction for Python3 - def one(self): - print "one from python" + def one(self): + print "one from python" -

      36.5.2 Director classes

      +

      36.5.2 Director classes

      @@ -2952,7 +2975,7 @@

      36.5.2 Director classes

      calls through Python.

      -

      36.5.3 Ownership and object destruction

      +

      36.5.3 Ownership and object destruction

      @@ -3019,7 +3042,7 @@

      36.5.3 Ownership and object destruction

      references to the Foo objects remain in Python.

      -

      36.5.4 Exception unrolling

      +

      36.5.4 Exception unrolling

      @@ -3078,7 +3101,7 @@

      36.5.4 Exception unrolling

      exception as soon as the C wrapper function returns.

      -

      36.5.5 Overhead and code bloat

      +

      36.5.5 Overhead and code bloat

      @@ -3112,7 +3135,7 @@

      36.5.5 Overhead and code bloat

      Python.

      -

      36.5.6 Typemaps

      +

      36.5.6 Typemaps

      @@ -3126,7 +3149,7 @@

      36.5.6 Typemaps

      -

      36.5.7 Miscellaneous

      +

      36.5.7 Miscellaneous

      @@ -3173,7 +3196,7 @@

      36.5.7 Miscellaneous

      -

      36.6 Common customization features

      +

      36.6 Common customization features

      @@ -3186,7 +3209,7 @@

      36.6 Common customization features

      improve your the interface to an extension module.

      -

      36.6.1 C/C++ helper functions

      +

      36.6.1 C/C++ helper functions

      @@ -3267,7 +3290,7 @@

      36.6.1 C/C++ helper functions

      customization features as covered in later sections.

      -

      36.6.2 Adding additional Python code

      +

      36.6.2 Adding additional Python code

      @@ -3380,6 +3403,18 @@

      36.6.2 Adding additional Python code

      an error for invalid preprocessor directives, so you may have to update existing interface files to delimit blocks of Python code correctly.

      +

      As an alternative to providing a block containing Python code, you can +include python code from a file. The code is inserted exactly as in the +file, so this avoids any issues with the SWIG preprocessor. It's a good +approach if you have a non-trivial chunk of Python code to insert. To +use this feature you specify a filename in double quotes, for example:

      + +
      +
      +%pythoncode "somecode.py"
      +
      +
      +

      Sometimes you may want to replace or modify the wrapper function that SWIG creates in the proxy .py file. The Python module in SWIG provides some features that enable you to do this. First, to @@ -3402,7 +3437,7 @@

      36.6.2 Adding additional Python code

      class Foo { public: int bar(int x); -} +}; @@ -3439,7 +3474,7 @@

      36.6.2 Adding additional Python code

      class Foo { public: int bar(int x); -} +}; @@ -3468,7 +3503,7 @@

      36.6.2 Adding additional Python code

      class Foo { public: int bar(int x); -} +}; @@ -3498,7 +3533,7 @@

      36.6.2 Adding additional Python code

      public: int bar(int x); int bar(); -} +}; @@ -3507,7 +3542,7 @@

      36.6.2 Adding additional Python code

      -

      36.6.3 Class extension with %extend

      +

      36.6.3 Class extension with %extend

      @@ -3596,7 +3631,7 @@

      36.6.3 Class extension with %extend

      in any way---the extensions only show up in the Python interface.

      -

      36.6.4 Exception handling with %exception

      +

      36.6.4 Exception handling with %exception

      @@ -3722,7 +3757,7 @@

      36.6.4 Exception handling with %exception

      to raise exceptions. See the SWIG Library chapter.

      -

      36.7 Tips and techniques

      +

      36.7 Tips and techniques

      @@ -3732,7 +3767,7 @@

      36.7 Tips and techniques

      solving these problems.

      -

      36.7.1 Input and output parameters

      +

      36.7.1 Input and output parameters

      @@ -3945,7 +3980,7 @@

      36.7.1 Input and output parameters

      may not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

      -

      36.7.2 Simple pointers

      +

      36.7.2 Simple pointers

      @@ -4014,7 +4049,7 @@

      36.7.2 Simple pointers

      See the SWIG Library chapter for further details.

      -

      36.7.3 Unbounded C Arrays

      +

      36.7.3 Unbounded C Arrays

      @@ -4076,7 +4111,7 @@

      36.7.3 Unbounded C Arrays

      package binary data, etc.

      -

      36.7.4 String handling

      +

      36.7.4 String handling

      @@ -4145,7 +4180,107 @@

      36.7.4 String handling

      also be used to extra binary data from arbitrary pointers.

      -

      36.8 Typemaps

      + +

      36.7.5 Default arguments

      + + +

      +C++ default argument code generation is documented in the main +Default arguments section. +There is also an optional Python specific feature that can be used called the python:cdefaultargs +feature flag. +By default, SWIG attempts to convert C++ default argument values +into Python values and generates code into the Python layer containing these values. +For example: +

      + +
      +
      +struct CDA {
      +  int fff(int a = 1, bool b = false);
      +};
      +
      +
      + +

      +From Python this can be called as follows: +

      + +
      +
      +>>> CDA().fff()        # C++ layer receives a=1 and b=false
      +>>> CDA().fff(2)       # C++ layer receives a=2 and b=false
      +>>> CDA().fff(3, True) # C++ layer receives a=3 and b=true
      +
      +
      + +

      +The default code generation in the Python layer is: +

      + +
      +
      +class CDA(object):
      +    ...
      +    def fff(self, a=1, b=False):
      +        return _default_args.CDA_fff(self, a, b)
      +
      +
      + +

      +Adding the feature: +

      + +
      +
      +%feature("python:cdefaultargs") CDA::fff;
      +struct CDA {
      +  int fff(int a = 1, bool b = false);
      +
      +
      + +

      +results in identical behaviour when called from Python, however, it results in different code generation: +

      + +
      +
      +class CDA(object):
      +    ...
      +    def fff(self, *args):
      +        return _default_args.CDA_fff(self, *args)
      +
      +
      + +

      +The default arguments are obtained in the C++ wrapper layer instead of the Python layer. +Some code generation modes are quite different, eg -builtin and -fastproxy, +and are unaffected by python:cdefaultargs as the default values are always obtained from the C++ layer. +

      + +

      +Note that not all default arguments can be converted into a Python equivalent. +When SWIG does not convert them, it will generate code to obtain them from the C++ layer as if +python:cdefaultargs was specified. +This will happen if just one argument cannot be converted into a Python equivalent. +This occurs typically when the argument is not fully numeric, such as int(1): +

      + +
      +
      +struct CDA {
      +  int fff(int a = int(1), bool b = false);
      +};
      +
      +
      + +

      +Compatibility Note: SWIG-3.0.6 introduced the python:cdefaultargs feature. +Versions of SWIG prior to this varied in their ability to convert C++ default values into +equivalent Python default argument values. +

      + +

      36.8 Typemaps

      @@ -4162,7 +4297,7 @@

      36.8 Typemaps

      C-Python interface or if you want to elevate your guru status.

      -

      36.8.1 What is a typemap?

      +

      36.8.1 What is a typemap?

      @@ -4175,8 +4310,8 @@

      36.8.1 What is a typemap?

      %module example %typemap(in) int { - $1 = (int) PyLong_AsLong($input); - printf("Received an integer : %d\n",$1); + $1 = (int) PyLong_AsLong($input); + printf("Received an integer : %d\n",$1); } %inline %{ extern int fact(int n); @@ -4213,11 +4348,11 @@

      36.8.1 What is a typemap?

      %module example %typemap(in) int nonnegative { - $1 = (int) PyLong_AsLong($input); - if ($1 < 0) { - PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value."); - return NULL; - } + $1 = (int) PyLong_AsLong($input); + if ($1 < 0) { + PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value."); + return NULL; + } } %inline %{ extern int fact(int nonnegative); @@ -4239,8 +4374,8 @@

      36.8.1 What is a typemap?

       %typemap(in) int n {
      -	$1 = (int) PyLong_AsLong($input);
      -	printf("n = %d\n",$1);
      +  $1 = (int) PyLong_AsLong($input);
      +  printf("n = %d\n",$1);
       }
       %inline %{
       typedef int Integer;
      @@ -4278,7 +4413,7 @@ 

      36.8.1 What is a typemap?

      -

      36.8.2 Python typemaps

      +

      36.8.2 Python typemaps

      @@ -4319,7 +4454,7 @@

      36.8.2 Python typemaps

      -

      36.8.3 Typemap variables

      +

      36.8.3 Typemap variables

      @@ -4390,7 +4525,7 @@

      36.8.3 Typemap variables

      The Python name of the wrapper function being created. -

      36.8.4 Useful Python Functions

      +

      36.8.4 Useful Python Functions

      @@ -4518,7 +4653,7 @@

      36.8.4 Useful Python Functions

      -

      36.9 Typemap Examples

      +

      36.9 Typemap Examples

      @@ -4527,7 +4662,7 @@

      36.9 Typemap Examples

      the SWIG library.

      -

      36.9.1 Converting Python list to a char **

      +

      36.9.1 Converting Python list to a char **

      @@ -4550,11 +4685,11 @@

      36.9.1 Converting Python list to a char **

      for (i = 0; i < size; i++) { PyObject *o = PyList_GetItem($input,i); if (PyString_Check(o)) - $1[i] = PyString_AsString(PyList_GetItem($input,i)); + $1[i] = PyString_AsString(PyList_GetItem($input,i)); else { - PyErr_SetString(PyExc_TypeError,"list must contain strings"); - free($1); - return NULL; + PyErr_SetString(PyExc_TypeError,"list must contain strings"); + free($1); + return NULL; } } $1[i] = 0; @@ -4607,7 +4742,7 @@

      36.9.1 Converting Python list to a char **

      the C function.

      -

      36.9.2 Expanding a Python object into multiple arguments

      +

      36.9.2 Expanding a Python object into multiple arguments

      @@ -4649,11 +4784,11 @@

      36.9.2 Expanding a Python object into multiple arg for (i = 0; i < $1; i++) { PyObject *o = PyList_GetItem($input,i); if (PyString_Check(o)) - $2[i] = PyString_AsString(PyList_GetItem($input,i)); + $2[i] = PyString_AsString(PyList_GetItem($input,i)); else { - PyErr_SetString(PyExc_TypeError,"list must contain strings"); - free($2); - return NULL; + PyErr_SetString(PyExc_TypeError,"list must contain strings"); + free($2); + return NULL; } } $2[i] = 0; @@ -4686,7 +4821,7 @@

      36.9.2 Expanding a Python object into multiple arg -

      36.9.3 Using typemaps to return arguments

      +

      36.9.3 Using typemaps to return arguments

      @@ -4697,10 +4832,10 @@

      36.9.3 Using typemaps to return arguments

       /* Returns a status value and two values in out1 and out2 */
       int spam(double a, double b, double *out1, double *out2) {
      -	... Do a bunch of stuff ...
      -	*out1 = result1;
      -	*out2 = result2;
      -	return status;
      +  ... Do a bunch of stuff ...
      +  *out1 = result1;
      +  *out2 = result2;
      +  return status;
       }
       
      @@ -4774,7 +4909,7 @@

      36.9.3 Using typemaps to return arguments

      >>> -

      36.9.4 Mapping Python tuples into small arrays

      +

      36.9.4 Mapping Python tuples into small arrays

      @@ -4823,7 +4958,7 @@

      36.9.4 Mapping Python tuples into small arrays

      -

      36.9.5 Mapping sequences to C arrays

      +

      36.9.5 Mapping sequences to C arrays

      @@ -4912,7 +5047,7 @@

      36.9.5 Mapping sequences to C arrays

      -

      36.9.6 Pointer handling

      +

      36.9.6 Pointer handling

      @@ -5009,7 +5144,7 @@

      36.9.6 Pointer handling

      -

      36.10 Docstring Features

      +

      36.10 Docstring Features

      @@ -5037,7 +5172,7 @@

      36.10 Docstring Features

      -

      36.10.1 Module docstring

      +

      36.10.1 Module docstring

      @@ -5071,7 +5206,7 @@

      36.10.1 Module docstring

      -

      36.10.2 %feature("autodoc")

      +

      36.10.2 %feature("autodoc")

      @@ -5099,7 +5234,7 @@

      36.10.2 %feature("autodoc")

      feature, %feature("autodoc", "level"). The four values for level are covered in the following sub-sections. -

      36.10.2.1 %feature("autodoc", "0")

      +

      36.10.2.1 %feature("autodoc", "0")

      @@ -5128,7 +5263,7 @@

      36.10.2.1 %feature("autodoc", "0")

      -

      36.10.2.2 %feature("autodoc", "1")

      +

      36.10.2.2 %feature("autodoc", "1")

      @@ -5153,13 +5288,13 @@

      36.10.2.2 %feature("autodoc", "1")

      -

      36.10.2.3 %feature("autodoc", "2")

      +

      36.10.2.3 %feature("autodoc", "2")

      Level "2" results in the function prototype as per level "0". In addition, a line of -documentation is generated for each parameter. Using the previous example, the generated -code will be: +documentation is generated for each parameter using numpydoc style. +Using the previous example, the generated code will be:

      @@ -5168,11 +5303,12 @@

      36.10.2.3 %feature("autodoc", "2")

      """ function_name(x, y, foo=None, bar=None) -> bool - Parameters: - x: int - y: int - foo: Foo * - bar: Bar * + Parameters + ---------- + x: int + y: int + foo: Foo * + bar: Bar * """ ... @@ -5203,17 +5339,18 @@

      36.10.2.3 %feature("autodoc", "2")

      """ function_name(x, y, foo=None, bar=None) -> bool - Parameters: - x (C++ type: int) -- Input x dimension - y: int - foo: Foo * - bar: Bar * + Parameters + ---------- + x (C++ type: int) -- Input x dimension + y: int + foo: Foo * + bar: Bar * """
      -

      36.10.2.4 %feature("autodoc", "3")

      +

      36.10.2.4 %feature("autodoc", "3")

      @@ -5226,11 +5363,12 @@

      36.10.2.4 %feature("autodoc", "3")

      """ function_name(int x, int y, Foo foo=None, Bar bar=None) -> bool - Parameters: - x: int - y: int - foo: Foo * - bar: Bar * + Parameters + ---------- + x: int + y: int + foo: Foo * + bar: Bar * """ ... @@ -5238,7 +5376,7 @@

      36.10.2.4 %feature("autodoc", "3")

      -

      36.10.2.5 %feature("autodoc", "docstring")

      +

      36.10.2.5 %feature("autodoc", "docstring")

      @@ -5257,7 +5395,7 @@

      36.10.2.5 %feature("autodoc", "docstring")

      -

      36.10.3 %feature("docstring")

      +

      36.10.3 %feature("docstring")

      @@ -5289,7 +5427,7 @@

      36.10.3 %feature("docstring")

      -

      36.11 Python Packages

      +

      36.11 Python Packages

      Python has concepts of modules and packages. Modules are separate units of @@ -5347,7 +5485,7 @@

      36.11 Python Packages

      %module directive or import related command line options. These are explained in the following sections.

      -

      36.11.1 Setting the Python package

      +

      36.11.1 Setting the Python package

      @@ -5401,7 +5539,7 @@

      36.11.1 Setting the Python package

      -

      36.11.2 Absolute and relative imports

      +

      36.11.2 Absolute and relative imports

      Suppose, we have the following hierarchy of files:

      @@ -5540,7 +5678,7 @@

      36.11.2 Absolute and relative imports

      __init__.py to import symbols from submodules or subpackages and the submodule depends on other submodules (discussed later).

      -

      36.11.3 Enforcing absolute import semantics

      +

      36.11.3 Enforcing absolute import semantics

      As you may know, there is an incompatibility in import semantics (for the @@ -5554,7 +5692,7 @@

      36.11.3 Enforcing absolute import semantics

      refers to a top-level module or to another module inside the current package. In Python 3 it always refers to a top-level module -(see PEP 328). +(see PEP 328). To instruct Python 2.5 through 2.7 to use new semantics (that is import foo is interpreted as absolute import), one has to put the following line @@ -5577,7 +5715,7 @@

      36.11.3 Enforcing absolute import semantics -

      36.11.4 Importing from __init__.py

      +

      36.11.4 Importing from __init__.py

      Imports in __init__.py are handy when you want to populate a @@ -5688,7 +5826,7 @@

      36.11.4 Importing from __init__.py

      workaround).

      -

      36.12 Python 3 Support

      +

      36.12 Python 3 Support

      @@ -5715,7 +5853,7 @@

      36.12 Python 3 Support

      SWIG.

      -

      36.12.1 Function annotation

      +

      36.12.1 Function annotation

      @@ -5745,10 +5883,10 @@

      36.12.1 Function annotation

      For detailed usage of function annotation, see -PEP 3107. +PEP 3107.

      -

      36.12.2 Buffer interface

      +

      36.12.2 Buffer interface

      @@ -5900,7 +6038,7 @@

      36.12.2 Buffer interface

      -

      36.12.3 Abstract base classes

      +

      36.12.3 Abstract base classes

      @@ -5938,10 +6076,10 @@

      36.12.3 Abstract base classes

      For details of abstract base class, please see -PEP 3119. +PEP 3119.

      -

      36.12.4 Byte string output conversion

      +

      36.12.4 Byte string output conversion

      @@ -6024,7 +6162,157 @@

      36.12.4 Byte string output conversion

      For more details about the surrogateescape error handler, please see -PEP 383. +PEP 383. +

      + +

      +In some cases, users may wish to instead handle all byte strings as bytes +objects in Python 3. This can be accomplished by adding +SWIG_PYTHON_STRICT_BYTE_CHAR to the generated code: +

      + +
      +%module char_to_bytes
      +%begin %{
      +#define SWIG_PYTHON_STRICT_BYTE_CHAR
      +%}
      +
      +char *charstring(char *s) {
      +  return s;
      +}
      +
      + +

      +This will modify the behavior so that only Python 3 bytes objects will be +accepted and converted to a C/C++ string, and any string returned from C/C++ +will be converted to a bytes object in Python 3: +

      + +
      +>>> from char_to_bytes import *
      +>>> charstring(b"hi") # Byte string
      +b'hi'
      +>>> charstring("hi")  # Unicode string
      +Traceback (most recent call last):
      +  File "<stdin>", line 1, in ?
      +TypeError: in method 'charstring', argument 1 of type 'char *'
      +
      + +

      +Note that in Python 2, defining SWIG_PYTHON_STRICT_BYTE_CHAR has no +effect, since strings in Python 2 are equivalent to Python 3 bytes objects. +However, there is a similar capability to force unicode-only handling for +wide characters C/C++ strings (wchar_t * or std::wstring +types) in Python 2. By default, in Python 2 both strings and unicode strings +are converted to C/C++ wide strings, and returned wide strings are converted +to a Python unicode string. To instead only convert unicode strings to wide +strings, users can add SWIG_PYTHON_STRICT_UNICODE_WCHAR to the +generated code: +

      + +
      +%module wchar_to_unicode
      +%begin %{
      +#define SWIG_PYTHON_STRICT_UNICODE_WCHAR
      +%}
      +
      +wchar_t *wcharstring(wchar_t *s) {
      +  return s;
      +}
      +
      + +

      +This ensures that only unicode strings are accepted by wcharstring in both +Python 2 and Python 3: +

      + +
      +>>> from wchar_to_unicode import *
      +>>> wcharstring(u"hi") # Unicode string
      +u'hi'
      +>>> wcharstring(b"hi") # Byte string
      +Traceback (most recent call last):
      +  File "<stdin>", line 1, in ?
      +TypeError: in method 'charstring', argument 1 of type 'wchar_t *'
      +
      + +

      +By defining both SWIG_PYTHON_STRICT_BYTE_CHAR and +SWIG_PYTHON_STRICT_UNICODE_WCHAR, Python wrapper code can support +overloads taking both std::string (as Python bytes) and std::wstring +(as Python unicode). +

      + +

      36.12.5 Python 2 Unicode

      + + +

      +A Python 3 string is a Unicode string so by default a Python 3 string that contains Unicode +characters passed to C/C++ will be accepted and converted to a C/C++ string +(char * or std::string types). +A Python 2 string is not a unicode string by default and should a Unicode string be +passed to C/C++ it will fail to convert to a C/C++ string +(char * or std::string types). +The Python 2 behavior can be made more like Python 3 by defining +SWIG_PYTHON_2_UNICODE when compiling the generated C/C++ code. +By default when the following is wrapped: +

      + +
      +%module unicode_strings
      +char *charstring(char *s) {
      +  return s;
      +}
      +
      + +

      +An error will occur when using Unicode strings in Python 2: +

      + +
      +>>> from unicode_strings import *
      +>>> charstring("hi")
      +'hi'
      +>>> charstring(u"hi")
      +Traceback (most recent call last):
      +  File "<stdin>", line 1, in ?
      +TypeError: in method 'charstring', argument 1 of type 'char *'
      +
      + +

      +When the SWIG_PYTHON_2_UNICODE macro is added to the generated code: +

      + +
      +%module unicode_strings
      +%begin %{
      +#define SWIG_PYTHON_2_UNICODE
      +%}
      +
      +char *charstring(char *s) {
      +  return s;
      +}
      +
      + +

      +Unicode strings will be successfully accepted and converted from UTF-8, +but note that they are returned as a normal Python 2 string: +

      + +
      +>>> from unicode_strings import *
      +>>> charstring("hi")
      +'hi'
      +>>> charstring(u"hi")
      +'hi'
      +>>>
      +
      + +

      +Note that defining both SWIG_PYTHON_2_UNICODE and +SWIG_PYTHON_STRICT_BYTE_CHAR at the same time is not allowed, since +the first is allowing unicode conversion and the second is explicitly +prohibiting it.

      diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html index 5de390eab7c..9b5993bff0b 100644 --- a/Doc/Manual/R.html +++ b/Doc/Manual/R.html @@ -1,12 +1,13 @@ - +SWIG and R + -

      37 SWIG and R

      +

      37 SWIG and R

        @@ -33,7 +34,7 @@

        37 SWIG and R

        with gcc. The R bindings also work on Microsoft Windows using Visual C++.

        -

        37.1 Bugs

        +

        37.1 Bugs

        @@ -45,7 +46,7 @@

        37.1 Bugs

      • C Array wrappings
      -

      37.2 Using R and SWIG

      +

      37.2 Using R and SWIG

      @@ -119,7 +120,24 @@

      37.2 Using R and SWIG

      These two files can be loaded in any order

      -

      37.3 Precompiling large R files

      +

      + If you are compiling code yourself (not using R itself), there are a few things to watch out for: +

      + +
        +
      • The output shared library name (to the left of the file extension) MUST match the module name, or alternatively, you can also set the -package NAME command line argument. See swig -r -help for more information +
      • If you do not set the output file name appropriately, you might see errors like +
        +
        +> fact(4)
        +Error in .Call("R_swig_fact", s_arg1, as.logical(.copy), PACKAGE = "example") :
        +  "R_swig_fact" not available for .Call() for package "example"
        +
        +
        +
      • Make sure the architecture of the shared library(x64 for instance), matches the architecture of the R program you want to load your shared library into +
      + +

      37.3 Precompiling large R files

      In cases where the R file is large, one make save a lot of loading @@ -137,7 +155,7 @@

      37.3 Precompiling large R files

      -

      37.4 General policy

      +

      37.4 General policy

      @@ -146,7 +164,7 @@

      37.4 General policy

      to provide R syntax.

      -

      37.5 Language conventions

      +

      37.5 Language conventions

      @@ -155,7 +173,7 @@

      37.5 Language conventions

      slices)

      -

      37.6 C++ classes

      +

      37.6 C++ classes

      @@ -167,7 +185,7 @@

      37.6 C++ classes

      of the proxy class baggage you see in other languages.

      -

      37.7 Enumerations

      +

      37.7 Enumerations

      diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index e78447b92c1..cfb99e792b8 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -1,13 +1,14 @@ - + - SWIG and Ruby - +SWIG and Ruby + + -

      38 SWIG and Ruby

      +

      38 SWIG and Ruby

      -

      38.1.3 Compiling a dynamic module

      +

      38.1.3 Compiling a dynamic module

      Ruby extension modules are typically compiled into shared @@ -285,7 +290,7 @@

      38.1.3 Compiling a dynamic module

      of options. You might also check the SWIG Wiki for additional information.

      -

      38.1.4 Using your module

      +

      38.1.4 Using your module

      Ruby module names must be capitalized, @@ -315,7 +320,7 @@

      38.1.4 Using your module

      will result in an extension module using the feature name "example" and Ruby module name "Example".

      -

      38.1.5 Static linking

      +

      38.1.5 Static linking

      An alternative approach to dynamic linking is to rebuild the @@ -330,7 +335,7 @@

      38.1.5 Static linking

      file, adding your directory to the list of extensions in the file, and finally rebuilding Ruby.

      -

      38.1.6 Compilation of C++ extensions

      +

      38.1.6 Compilation of C++ extensions

      On most machines, C++ extension modules should be linked @@ -362,7 +367,7 @@

      38.1.6 Compilation of C++ extensions

      create_makefile('example')
      -

      38.2 Building Ruby Extensions under Windows 95/NT

      +

      38.2 Building Ruby Extensions under Windows 95/NT

      Building a SWIG extension to Ruby under Windows 95/NT is @@ -387,7 +392,7 @@

      38.2 Building Ruby Extensions under Windows 95/NT

      -

      38.2.1 Running SWIG from Developer Studio

      +

      38.2.1 Running SWIG from Developer Studio

      If you are developing your application within Microsoft @@ -451,13 +456,13 @@

      38.2.1 Running SWIG from Developer Studio

      -

      38.3 The Ruby-to-C/C++ Mapping

      +

      38.3 The Ruby-to-C/C++ Mapping

      This section describes the basics of how SWIG maps C or C++ declarations in your SWIG interface files to Ruby constructs.

      -

      38.3.1 Modules

      +

      38.3.1 Modules

      The SWIG %module directive specifies @@ -529,7 +534,7 @@

      38.3.1 Modules

      names of your constants, classes and methods don't conflict with any of Ruby's built-in names.

      -

      38.3.2 Functions

      +

      38.3.2 Functions

      Global functions are wrapped as Ruby module methods. For @@ -563,7 +568,7 @@

      38.3.2 Functions

      24 -

      38.3.3 Variable Linking

      +

      38.3.3 Variable Linking

      C/C++ global variables are wrapped as a pair of singleton @@ -625,7 +630,7 @@

      38.3.3 Variable Linking

      effect until it is explicitly disabled using %mutable.

      -

      38.3.4 Constants

      +

      38.3.4 Constants

      C/C++ constants are wrapped as module constants initialized @@ -653,7 +658,7 @@

      38.3.4 Constants

      3.14159 -

      38.3.5 Pointers

      +

      38.3.5 Pointers

      "Opaque" pointers to arbitrary C/C++ types (i.e. types that @@ -677,7 +682,7 @@

      38.3.5 Pointers

      A NULL pointer is always represented by the Ruby nil object.

      -

      38.3.6 Structures

      +

      38.3.6 Structures

      C/C++ structs are wrapped as Ruby classes, with accessor @@ -782,7 +787,7 @@

      38.3.6 Structures

      } -

      38.3.7 C++ classes

      +

      38.3.7 C++ classes

      Like structs, C++ classes are wrapped by creating a new Ruby @@ -837,7 +842,7 @@

      38.3.7 C++ classes

      3 -

      38.3.8 C++ Inheritance

      +

      38.3.8 C++ Inheritance

      The SWIG type-checker is fully aware of C++ inheritance. @@ -990,7 +995,7 @@

      38.3.8 C++ Inheritance

      (i.e. they exhibit "Duck Typing").

      -

      38.3.9 C++ Overloaded Functions

      +

      38.3.9 C++ Overloaded Functions

      C++ overloaded functions, methods, and constructors are @@ -1080,7 +1085,7 @@

      38.3.9 C++ Overloaded Functions

      Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      38.3.10 C++ Operators

      +

      38.3.10 C++ Operators

      For the most part, overloaded operators are handled @@ -1122,7 +1127,7 @@

      38.3.10 C++ Operators

      is discussed in the section on operator overloading.

      -

      38.3.11 C++ namespaces

      +

      38.3.11 C++ namespaces

      SWIG is aware of C++ namespaces, but namespace names do not @@ -1179,7 +1184,7 @@

      38.3.11 C++ namespaces

      program utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      38.3.12 C++ templates

      +

      38.3.12 C++ templates

      C++ templates don't present a huge problem for SWIG. However, @@ -1221,7 +1226,7 @@

      38.3.12 C++ templates

      4 -

      38.3.13 C++ Standard Template Library (STL)

      +

      38.3.13 C++ Standard Template Library (STL)

      On a related note, the standard SWIG library contains a @@ -1314,7 +1319,7 @@

      38.3.13 C++ Standard Template Library (STL)

      shown in these examples. More details can be found in the SWIG and C++ chapter.

      -

      38.3.14 C++ STL Functors

      +

      38.3.14 C++ STL Functors

      Some containers in the STL allow you to modify their default @@ -1347,7 +1352,7 @@

      38.3.14 C++ STL Functors

      %include <std_set.i> -%typemap(IntSet) std::set< int, swig::BinaryPredicate >; +%template(IntSet) std::set< int, swig::BinaryPredicate >;

      You can then use the set from Ruby with or without a proc @@ -1375,7 +1380,7 @@

      38.3.14 C++ STL Functors

      -

      38.3.15 C++ STL Iterators

      +

      38.3.15 C++ STL Iterators

      The STL is well known for the use of iterators. There @@ -1458,7 +1463,21 @@

      38.3.15 C++ STL Iterators

      If you'd rather have STL classes without any iterators, you should define -DSWIG_NO_EXPORT_ITERATOR_METHODS when running swig.

      -

      38.3.16 C++ Smart Pointers

      +

      38.3.16 C++ Smart Pointers

      + + +

      38.3.16.1 The shared_ptr Smart Pointer

      + + +

      +The C++11 standard provides std::shared_ptr which was derived from the Boost +implementation, boost::shared_ptr. +Both of these are available for Ruby in the SWIG library and usage is outlined +in the shared_ptr smart pointer library section. +

      + + +

      38.3.16.2 Generic Smart Pointers

      In certain C++ programs, it is common to use classes that @@ -1523,7 +1542,7 @@

      38.3.16 C++ Smart Pointers

      irb(main):004:0> f = p.__deref__() # Returns underlying Foo *
      -

      38.3.17 Cross-Language Polymorphism

      +

      38.3.17 Cross-Language Polymorphism

      SWIG's Ruby module supports cross-language polymorphism @@ -1532,7 +1551,7 @@

      38.3.17 Cross-Language Polymorphism

      section just notes the differences that you need to be aware of when using this feature with Ruby.

      -

      38.3.17.1 Exception Unrolling

      +

      38.3.17.1 Exception Unrolling

      Whenever a C++ director class routes one of its virtual @@ -1555,7 +1574,7 @@

      38.3.17.1 Exception Unrolling

      function from Ruby's C API. If any Ruby exception is raised, it will be caught here and a C++ exception is raised in its place.

      -

      38.4 Naming

      +

      38.4 Naming

      Ruby has several common naming conventions. Constants are @@ -1593,7 +1612,7 @@

      38.4 Naming

      by SWIG, it is turned off by default in SWIG 1.3.28. However, it is planned to become the default option in future releases.

      -

      38.4.1 Defining Aliases

      +

      38.4.1 Defining Aliases

      It's a fairly common practice in the Ruby built-ins and @@ -1663,7 +1682,7 @@

      38.4.1 Defining Aliases

      on "Customization Features") for more details).

      -

      38.4.2 Predicate Methods

      +

      38.4.2 Predicate Methods

      Ruby methods that return a boolean value and end in a @@ -1712,7 +1731,7 @@

      38.4.2 Predicate Methods

      used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      38.4.3 Bang Methods

      +

      38.4.3 Bang Methods

      Ruby methods that modify an object in-place and end in an @@ -1744,7 +1763,7 @@

      38.4.3 Bang Methods

      used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      38.4.4 Getters and Setters

      +

      38.4.4 Getters and Setters

      Often times a C++ library will expose properties through @@ -1779,7 +1798,7 @@

      38.4.4 Getters and Setters

      %rename("value=") Foo::setValue(int value); -

      38.5 Input and output parameters

      +

      38.5 Input and output parameters

      A common problem in some C programs is handling parameters @@ -1918,10 +1937,10 @@

      38.5 Input and output parameters

      r, c = Example.get_dimensions(m)
      -

      38.6 Exception handling

      +

      38.6 Exception handling

      -

      38.6.1 Using the %exception directive

      +

      38.6.1 Using the %exception directive

      The SWIG %exception directive can be @@ -2030,7 +2049,7 @@

      38.6.1 Using the %exception directive

      limited to C++ exception handling. See the chapter on Customization Features for more examples.

      -

      38.6.2 Handling Ruby Blocks

      +

      38.6.2 Handling Ruby Blocks

      One of the highlights of Ruby and most of its standard library @@ -2097,7 +2116,7 @@

      38.6.2 Handling Ruby Blocks

      For more information on typemaps, see Typemaps.

      -

      38.6.3 Raising exceptions

      +

      38.6.3 Raising exceptions

      There are three ways to raise exceptions from C++ code to @@ -2254,7 +2273,7 @@

      38.6.3 Raising exceptions

      is the exception type. You can raise a custom exception type or one of the built-in Ruby exception types.

      -

      38.6.4 Exception classes

      +

      38.6.4 Exception classes

      Starting with SWIG 1.3.28, the Ruby module supports the %exceptionclass @@ -2291,7 +2310,7 @@

      38.6.4 Exception classes

      For another example look at swig/Examples/ruby/exception_class.

      -

      38.7 Typemaps

      +

      38.7 Typemaps

      This section describes how you can modify SWIG's default @@ -2306,7 +2325,7 @@

      38.7 Typemaps

      in most cases. Typemaps are only used if you want to change some aspect of the primitive C-Ruby interface.

      -

      38.7.1 What is a typemap?

      +

      38.7.1 What is a typemap?

      A typemap is nothing more than a code generation rule that is @@ -2463,7 +2482,7 @@

      38.7.1 What is a typemap?

      2 -

      38.7.2 Typemap scope

      +

      38.7.2 Typemap scope

      Once defined, a typemap remains in effect for all of the @@ -2509,7 +2528,7 @@

      38.7.2 Typemap scope

      }; -

      38.7.3 Copying a typemap

      +

      38.7.3 Copying a typemap

      A typemap is copied by using assignment. For example:

      @@ -2551,7 +2570,7 @@

      38.7.3 Copying a typemap

      %apply (char *buf, int len) { (char *buffer, int size) }; // Multiple arguments -

      38.7.4 Deleting a typemap

      +

      38.7.4 Deleting a typemap

      A typemap can be deleted by simply defining no code. For @@ -2576,7 +2595,7 @@

      38.7.4 Deleting a typemap

      will make that type unusable unless you also define a new set of typemaps immediately after the clear operation.

      -

      38.7.5 Placement of typemaps

      +

      38.7.5 Placement of typemaps

      Typemap declarations can be declared in the global scope, @@ -2647,13 +2666,13 @@

      38.7.5 Placement of typemaps

      string .

      -

      38.7.6 Ruby typemaps

      +

      38.7.6 Ruby typemaps

      The following list details all of the typemap methods that can be used by the Ruby module:

      -

      38.7.6.1 "in" typemap

      +

      38.7.6.1 "in" typemap

      Converts Ruby objects to input @@ -2720,7 +2739,7 @@

      38.7.6.1 "in" typemap

      At this time, only zero or one arguments may be converted.

      -

      38.7.6.2 "typecheck" typemap

      +

      38.7.6.2 "typecheck" typemap

      The "typecheck" typemap is used to support overloaded @@ -2742,7 +2761,7 @@

      38.7.6.2 "typecheck" typemap

      "typecheck" typemaps. More details about this follow in a later section on "Typemaps and Overloading."

      -

      38.7.6.3 "out" typemap

      +

      38.7.6.3 "out" typemap

      Converts return value of a C function @@ -2793,7 +2812,7 @@

      38.7.6.3 "out" typemap

      -

      38.7.6.4 "arginit" typemap

      +

      38.7.6.4 "arginit" typemap

      The "arginit" typemap is used to set the initial value of a @@ -2808,7 +2827,7 @@

      38.7.6.4 "arginit" typemap

      } -

      38.7.6.5 "default" typemap

      +

      38.7.6.5 "default" typemap

      The "default" typemap is used to turn an argument into a @@ -2833,7 +2852,7 @@

      38.7.6.5 "default" typemap

      Default/optional arguments section for further information on default argument wrapping.

      -

      38.7.6.6 "check" typemap

      +

      38.7.6.6 "check" typemap

      The "check" typemap is used to supply value checking code @@ -2848,7 +2867,7 @@

      38.7.6.6 "check" typemap

      } -

      38.7.6.7 "argout" typemap

      +

      38.7.6.7 "argout" typemap

      The "argout" typemap is used to return values from arguments. @@ -2902,7 +2921,7 @@

      38.7.6.7 "argout" typemap

      See the typemaps.i library for examples.

      -

      38.7.6.8 "freearg" typemap

      +

      38.7.6.8 "freearg" typemap

      The "freearg" typemap is used to cleanup argument data. It is @@ -2929,7 +2948,7 @@

      38.7.6.8 "freearg" typemap

      that may be used in other typemaps whenever a wrapper function needs to abort prematurely.

      -

      38.7.6.9 "newfree" typemap

      +

      38.7.6.9 "newfree" typemap

      The "newfree" typemap is used in conjunction with the %newobject @@ -2953,7 +2972,7 @@

      38.7.6.9 "newfree" typemap

      See Object ownership and %newobject for further details.

      -

      38.7.6.10 "memberin" typemap

      +

      38.7.6.10 "memberin" typemap

      The "memberin" typemap is used to copy data from an @@ -2971,21 +2990,21 @@

      38.7.6.10 "memberin" typemap

      already provides a default implementation for arrays, strings, and other objects.

      -

      38.7.6.11 "varin" typemap

      +

      38.7.6.11 "varin" typemap

      The "varin" typemap is used to convert objects in the target language to C for the purposes of assigning to a C/C++ global variable. This is implementation specific.

      -

      38.7.6.12 "varout" typemap

      +

      38.7.6.12 "varout" typemap

      The "varout" typemap is used to convert a C/C++ object to an object in the target language when reading a C/C++ global variable. This is implementation specific.

      -

      38.7.6.13 "throws" typemap

      +

      38.7.6.13 "throws" typemap

      The "throws" typemap is only used when SWIG parses a C++ @@ -3026,7 +3045,7 @@

      38.7.6.13 "throws" typemap

      deal with them. For a neat way to handle these, see the Exception handling with %exception section.

      -

      38.7.6.14 directorin typemap

      +

      38.7.6.14 directorin typemap

      Converts C++ objects in director @@ -3085,7 +3104,7 @@

      38.7.6.14 directorin typemap

      -

      38.7.6.15 directorout typemap

      +

      38.7.6.15 directorout typemap

      Converts Ruby objects in director @@ -3158,7 +3177,7 @@

      38.7.6.15 directorout typemap

      -

      38.7.6.16 directorargout typemap

      +

      38.7.6.16 directorargout typemap

      Output argument processing in director @@ -3216,19 +3235,19 @@

      38.7.6.16 directorargout typemap -

      38.7.6.17 ret typemap

      +

      38.7.6.17 ret typemap

      Cleanup of function return values

      -

      38.7.6.18 globalin typemap

      +

      38.7.6.18 globalin typemap

      Setting of C global variables

      -

      38.7.7 Typemap variables

      +

      38.7.7 Typemap variables

      @@ -3278,7 +3297,7 @@

      38.7.7 Typemap variables

      The Ruby name of the wrapper function being created.
      -

      38.7.8 Useful Functions

      +

      38.7.8 Useful Functions

      When you write a typemap, you usually have to work directly @@ -3293,7 +3312,7 @@

      38.7.8 Useful Functions

      That should help you avoid having to rewrite a lot of typemaps across multiple languages.

      -

      38.7.8.1 C Datatypes to Ruby Objects

      +

      38.7.8.1 C Datatypes to Ruby Objects

      @@ -3335,7 +3354,7 @@

      38.7.8.1 C Datatypes to Ruby Objects

      -

      38.7.8.2 Ruby Objects to C Datatypes

      +

      38.7.8.2 Ruby Objects to C Datatypes

      Here, while the Ruby versions return the value directly, the SWIG @@ -3403,7 +3422,7 @@

      38.7.8.2 Ruby Objects to C Datatypes

      -

      38.7.8.3 Macros for VALUE

      +

      38.7.8.3 Macros for VALUE

      RSTRING_LEN(str)

      @@ -3426,7 +3445,7 @@

      38.7.8.3 Macros for VALUE

      pointer to array storage
      -

      38.7.8.4 Exceptions

      +

      38.7.8.4 Exceptions

      void rb_raise(VALUE exception, const char *fmt, @@ -3505,7 +3524,7 @@

      38.7.8.4 Exceptions

      flag. The given format string fmt and remaining arguments are interpreted as with printf(). -

      38.7.8.5 Iterators

      +

      38.7.8.5 Iterators

      void rb_iter_break()

      @@ -3551,14 +3570,14 @@

      38.7.8.5 Iterators

      Equivalent to Ruby's throw.
      -

      38.7.9 Typemap Examples

      +

      38.7.9 Typemap Examples

      This section includes a few examples of typemaps. For more examples, you might look at the examples in the Example/ruby directory.

      -

      38.7.10 Converting a Ruby array to a char **

      +

      38.7.10 Converting a Ruby array to a char **

      A common problem in many C programs is the processing of @@ -3623,7 +3642,7 @@

      38.7.10 Converting a Ruby array to a char **

      the array, the "freearg" typemap is used to later release this memory after the execution of the C function.

      -

      38.7.11 Collecting arguments in a hash

      +

      38.7.11 Collecting arguments in a hash

      Ruby's solution to the "keyword arguments" capability of some @@ -3837,7 +3856,7 @@

      38.7.11 Collecting arguments in a hash

      program that uses the extension, can be found in the Examples/ruby/hashargs directory of the SWIG distribution.

      -

      38.7.12 Pointer handling

      +

      38.7.12 Pointer handling

      Occasionally, it might be necessary to convert pointer values @@ -3896,7 +3915,7 @@

      38.7.12 Pointer handling

      } -

      38.7.12.1 Ruby Datatype Wrapping

      +

      38.7.12.1 Ruby Datatype Wrapping

      VALUE Data_Wrap_Struct(VALUE class, void @@ -3923,7 +3942,7 @@

      38.7.12.1 Ruby Datatype Wrapping

      type c-type from the data object obj and assigns that pointer to ptr. -

      38.7.13 Example: STL Vector to Ruby Array

      +

      38.7.13 Example: STL Vector to Ruby Array

      Another use for macros and type maps is to create a Ruby array @@ -4015,7 +4034,7 @@

      38.7.13 Example: STL Vector to Ruby Array

      which does much more than this. Refer to the section called the C++ Standard Template Library. -

      38.8 Docstring Features

      +

      38.8 Docstring Features

      @@ -4049,7 +4068,7 @@

      38.8 Docstring Features

      $ rdoc -r file_wrap.c -

      38.8.1 Module docstring

      +

      38.8.1 Module docstring

      @@ -4079,7 +4098,7 @@

      38.8.1 Module docstring

      %module(docstring=DOCSTRING) xrc -

      38.8.2 %feature("autodoc")

      +

      38.8.2 %feature("autodoc")

      Since SWIG does know everything about the function it wraps, @@ -4100,7 +4119,7 @@

      38.8.2 %feature("autodoc")

      feature, described below.

      -

      38.8.2.1 %feature("autodoc", "0")

      +

      38.8.2.1 %feature("autodoc", "0")

      @@ -4124,7 +4143,7 @@

      38.8.2.1 %feature("autodoc", "0")

      ... -

      38.8.2.2 %feature("autodoc", "1")

      +

      38.8.2.2 %feature("autodoc", "1")

      @@ -4144,7 +4163,7 @@

      38.8.2.2 %feature("autodoc", "1")

      ... -

      38.8.2.3 %feature("autodoc", "2")

      +

      38.8.2.3 %feature("autodoc", "2")

      @@ -4156,7 +4175,7 @@

      38.8.2.3 %feature("autodoc", "2")

      this:

      -

      38.8.2.4 %feature("autodoc", "3")

      +

      38.8.2.4 %feature("autodoc", "3")

      @@ -4171,13 +4190,13 @@

      38.8.2.4 %feature("autodoc", "3")

      function_name(int x, int y, Foo foo=nil, Bar bar=nil) -> bool
       
       Parameters:
      -	x - int
      -	y - int
      -	foo - Foo
      -	bar - Bar
      + x - int + y - int + foo - Foo + bar - Bar -

      38.8.2.5 %feature("autodoc", "docstring")

      +

      38.8.2.5 %feature("autodoc", "docstring")

      @@ -4193,7 +4212,7 @@

      38.8.2.5 %feature("autodoc", "docstring")

      void GetPosition(int* OUTPUT, int* OUTPUT); -

      38.8.3 %feature("docstring")

      +

      38.8.3 %feature("docstring")

      @@ -4204,10 +4223,10 @@

      38.8.3 %feature("docstring")

      If an item already has an autodoc string then it is combined with the docstring and they are output together.

      -

      38.9 Advanced Topics

      +

      38.9 Advanced Topics

      -

      38.9.1 Operator overloading

      +

      38.9.1 Operator overloading

      SWIG allows operator overloading with, by using the %extend @@ -4388,7 +4407,7 @@

      38.9.1 Operator overloading

      parses the expression a != b as !(a == b).

      -

      38.9.2 Creating Multi-Module Packages

      +

      38.9.2 Creating Multi-Module Packages

      The chapter on Working @@ -4514,7 +4533,7 @@

      38.9.2 Creating Multi-Module Packages

      5.0 -

      38.9.3 Specifying Mixin Modules

      +

      38.9.3 Specifying Mixin Modules

      The Ruby language doesn't support multiple inheritance, but @@ -4581,7 +4600,7 @@

      38.9.3 Specifying Mixin Modules

      on "Customization Features") for more details).

      -

      38.10 Memory Management

      +

      38.10 Memory Management

      One of the most common issues in generating SWIG bindings for @@ -4604,7 +4623,7 @@

      38.10 Memory Management

      invoked. Clearly, developing a SWIG wrapper requires a thorough understanding of how the underlying library manages memory.

      -

      38.10.1 Mark and Sweep Garbage Collector

      +

      38.10.1 Mark and Sweep Garbage Collector

      Ruby uses a mark and sweep garbage collector. When the garbage @@ -4618,8 +4637,7 @@

      38.10.1 Mark and Sweep Garbage Collector

      reference other objects. This process will continue until all active objects have been "marked." After the mark phase comes the sweep phase. In the sweep phase, all objects that have not been marked will be -garbage collected. For more information about the Ruby garbage -collector please refer to http://rubygarden.org/ruby/ruby?GCAndExtensions.

      +garbage collected.

      The Ruby C/API provides extension developers two hooks into the garbage collector - a "mark" function and a "sweep" function. By @@ -4636,7 +4654,7 @@

      38.10.1 Mark and Sweep Garbage Collector

      C++ struct, then a "free" function must be defined that deallocates this memory.

      -

      38.10.2 Object Ownership

      +

      38.10.2 Object Ownership

      As described above, memory management depends on clearly @@ -4781,7 +4799,7 @@

      38.10.2 Object Ownership

      This code can be seen in swig/examples/ruby/tracking.

      -

      38.10.3 Object Tracking

      +

      38.10.3 Object Tracking

      The remaining parts of this section will use the class library @@ -4818,7 +4836,7 @@

      38.10.3 Object Tracking

      class Zoo { protected: - std::vector<animal *=""> animals; + std::vector<Animal *> animals; public: // Construct an empty zoo @@ -4941,7 +4959,8 @@

      38.10.3 Object Tracking

      /* Tell SWIG that create_animal creates a new object */ %newobject Zoo::create_animal; -/* Tell SWIG to keep track of mappings between C/C++ structs/classes. */%trackobjects; +/* Tell SWIG to keep track of mappings between C/C++ structs/classes. */ +%trackobjects; %include "example.h" @@ -5006,7 +5025,7 @@

      38.10.3 Object Tracking

      also have to call the SWIG_RubyRemoveTracking and RubyUnlinkObjects methods.

      -

      38.10.4 Mark Functions

      +

      38.10.4 Mark Functions

      With a bit more testing, we see that our class library still @@ -5101,7 +5120,7 @@

      38.10.4 Mark Functions

      Note the mark function is dependent on the SWIG_RUBY_InstanceFor method, and thus requires that %trackobjects is enabled. For more -information, please refer to the track_object.i test case in the SWIG +information, please refer to the ruby_track_objects.i test case in the SWIG test suite.

      When this code is compiled we now see:

      @@ -5135,7 +5154,7 @@

      38.10.4 Mark Functions

      This code can be seen in swig/examples/ruby/mark_function.

      -

      38.10.5 Free Functions

      +

      38.10.5 Free Functions

      By default, SWIG creates a "free" function that is called when @@ -5168,21 +5187,23 @@

      38.10.5 Free Functions

      To show how to use the %freefunc directive, let's slightly change our example. Assume that the zoo -object is responsible for freeing animal that it contains. This means +object is responsible for freeing any animal that it contains. This means that the Zoo::add_animal function should be marked with a DISOWN typemap and the destructor should be updated as below:

      -
      Zoo::~Zoo() {
      - IterType iter = this->animals.begin();
      - IterType end = this->animals.end();
      -
      - for(iter; iter != end; ++iter) {
      - Animal* animal = *iter;
      - delete animal;
      - }
      -}
      +
      +Zoo::~Zoo() {
      +  IterType iter = this->animals.begin();
      +  IterType end = this->animals.end();
      + 
      +  for(iter; iter != end; ++iter) {
      +    Animal* animal = *iter;
      +    delete animal;
      +  }
      +}
      +

      When we use these objects in IRB we see:

      @@ -5230,8 +5251,7 @@

      38.10.5 Free Functions

      #include "example.h" %} -/* Specify that ownership is transferred to the zoo - when calling add_animal */ +/* Specify that ownership is transferred to the zoo when calling add_animal */ %apply SWIGTYPE *DISOWN { Animal* animal }; /* Track objects */ @@ -5302,7 +5322,7 @@

      38.10.5 Free Functions

      This code can be seen in swig/examples/ruby/free_function.

      -

      38.10.6 Embedded Ruby and the C++ Stack

      +

      38.10.6 Embedded Ruby and the C++ Stack

      As has been said, the Ruby GC runs and marks objects before diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 4c33aeab8f2..178247e4218 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1,12 +1,13 @@ - + SWIG Basics + -

      5 SWIG Basics

      +

      5 SWIG Basics

    • Pointers and complex objects
        @@ -40,7 +41,7 @@

        5 SWIG Basics

      • Passing structures by value
      • Return by value
      • Linking to structure variables -
      • Linking to char * +
      • Linking to char *
      • Arrays
      • Creating read-only variables
      • Renaming and ignoring declarations @@ -94,7 +95,7 @@

        5 SWIG Basics

        chapters.

        -

        5.1 Running SWIG

        +

        5.1 Running SWIG

        @@ -110,7 +111,7 @@

        5.1 Running SWIG

        Below is a subset of options that can be used. Additional options are also defined for each target language. A full list can be obtained by typing swig -help or swig --lang -help. +-<lang> -help
        for language <lang> specific options.

        @@ -119,26 +120,31 @@ 

        5.1 Running SWIG

        -clisp Generate CLISP wrappers -cffi Generate CFFI wrappers -csharp Generate C# wrappers +-d Generate D wrappers -go Generate Go wrappers -guile Generate Guile wrappers -java Generate Java wrappers +-javascript Generate Javascript wrappers -lua Generate Lua wrappers -modula3 Generate Modula 3 wrappers -mzscheme Generate Mzscheme wrappers -ocaml Generate Ocaml wrappers +-octave Generate Octave wrappers -perl Generate Perl wrappers -php Generate PHP wrappers -pike Generate Pike wrappers -python Generate Python wrappers -r Generate R (aka GNU S) wrappers -ruby Generate Ruby wrappers +-scilab Generate Scilab wrappers -sexp Generate Lisp S-Expressions wrappers -tcl Generate Tcl wrappers -uffi Generate Common Lisp / UFFI wrappers -xml Generate XML wrappers -c++ Enable C++ parsing --cppext ext Change file extension of C++ generated files to ext (default is cxx, except for PHP which uses cpp) +-cppext ext Change file extension of C++ generated files to ext + (default is cxx, except for PHP which uses cpp) -Dsymbol Define a preprocessor symbol -Fstandard Display error/warning messages in commonly used format -Fmicrosoft Display error/warning messages in Microsoft format @@ -146,7 +152,8 @@

        5.1 Running SWIG

        -Idir Add a directory to the file include path -lfile Include a SWIG library file. -module name Set the name of the SWIG module --o outfile Name of output file +-o outfile Set name of C/C++ output file to <outfile> +-oh headfile Set name of C++ output header file for directors to <headfile> -outcurrentdir Set default output dir to current dir instead of input file's path -outdir dir Set language specific files output directory -pcreversion Display PCRE version information @@ -155,7 +162,7 @@

        5.1 Running SWIG

        -

        5.1.1 Input format

        +

        5.1.1 Input format

        @@ -202,7 +209,7 @@

        5.1.1 Input format

        used in input files to parser generation tools such as yacc or bison.

        -

        5.1.2 SWIG Output

        +

        5.1.2 SWIG Output

        @@ -212,7 +219,7 @@

        5.1.2 SWIG Output

        with the name file.i is transformed into a file file_wrap.c or file_wrap.cxx (depending on whether or not the -c++ option has been used). The name of the -output file can be changed using the -o option. In certain +output C/C++ file can be changed using the -o option. In certain cases, file suffixes are used by the compiler to determine the source language (C, C++, etc.). Therefore, you have to use the -o option to change the suffix of the SWIG-generated wrapper @@ -262,7 +269,7 @@

        5.1.2 SWIG Output

        generated C/C++ file if not overridden with -outdir.

        -

        5.1.3 Comments

        +

        5.1.3 Comments

        @@ -272,7 +279,7 @@

        5.1.3 Comments

        and will reappear in a later SWIG release.

        -

        5.1.4 C Preprocessor

        +

        5.1.4 C Preprocessor

        @@ -296,7 +303,7 @@

        5.1.4 C Preprocessor

        extensions are described in the "Preprocessor" chapter.

        -

        5.1.5 SWIG Directives

        +

        5.1.5 SWIG Directives

        @@ -327,7 +334,7 @@

        5.1.5 SWIG Directives

        it is parsing an input file.

        -

        5.1.6 Parser Limitations

        +

        5.1.6 Parser Limitations

        @@ -425,7 +432,7 @@

        5.1.6 Parser Limitations

        described on p. 234 of K&R).

        -

        5.2 Wrapping Simple C Declarations

        +

        5.2 Wrapping Simple C Declarations

        @@ -488,7 +495,7 @@

        5.2 Wrapping Simple C Declarations

        next few sections describe various aspects of this mapping.

        -

        5.2.1 Basic Type Handling

        +

        5.2.1 Basic Type Handling

        @@ -613,7 +620,7 @@

        5.2.1 Basic Type Handling

        You may need to write some special conversion functions.

        -

        5.2.2 Global Variables

        +

        5.2.2 Global Variables

        @@ -668,7 +675,7 @@

        5.2.2 Global Variables

        constants instead.

        -

        5.2.3 Constants

        +

        5.2.3 Constants

        @@ -757,7 +764,7 @@

        5.2.3 Constants

        interface that are not defined in the original header file.

        -

        5.2.4 A brief word about const

        +

        5.2.4 A brief word about const

        @@ -859,7 +866,7 @@

        5.2.4 A brief word about const

    • -

      5.2.5 A cautionary tale of char *

      +

      5.2.5 A cautionary tale of char *

      @@ -898,7 +905,7 @@

      5.2.5 A cautionary tale of char *

      using typemaps.

      -

      5.3 Pointers and complex objects

      +

      5.3 Pointers and complex objects

      @@ -906,7 +913,7 @@

      5.3 Pointers and complex objects

      discusses the handling of these datatypes.

      -

      5.3.1 Simple pointers

      +

      5.3.1 Simple pointers

      @@ -972,7 +979,7 @@

      5.3.1 Simple pointers

    -

    5.3.2 Run time pointer type checking

    +

    5.3.2 Run time pointer type checking

    @@ -994,7 +1001,7 @@

    5.3.2 Run time pointer type checking

    SWIG leaves NULL pointer checking up to the application.

    -

    5.3.3 Derived types, structs, and classes

    +

    5.3.3 Derived types, structs, and classes

    @@ -1035,15 +1042,14 @@

    5.3.3 Derived types, structs, and classes

     # Copy a file 
     def filecopy(source,target):
    -	f1 = fopen(source,"r")
    -	f2 = fopen(target,"w")
    -	buffer = malloc(8192)
    -	nbytes = fread(buffer,8192,1,f1)
    -	while (nbytes > 0):
    -		fwrite(buffer,8192,1,f2)
    -		nbytes = fread(buffer,8192,1,f1)
    -	free(buffer)
    -
    +  f1 = fopen(source,"r")
    +  f2 = fopen(target,"w")
    +  buffer = malloc(8192)
    +  nbytes = fread(buffer,8192,1,f1)
    +  while (nbytes > 0):
    +    fwrite(buffer,8192,1,f2)
    +          nbytes = fread(buffer,8192,1,f1)
    +  free(buffer)
     

    @@ -1051,7 +1057,7 @@

    5.3.3 Derived types, structs, and classes

    opaque objects containing C pointers. It doesn't matter what value they contain--our program works just fine without this knowledge.

    -

    5.3.4 Undefined datatypes

    +

    5.3.4 Undefined datatypes

    @@ -1111,7 +1117,7 @@

    5.3.4 Undefined datatypes

    -

    5.3.5 Typedef

    +

    5.3.5 Typedef

    @@ -1200,7 +1206,7 @@

    5.3.5 Typedef

    type unsigned int * or size_t *.

    -

    5.4 Other Practicalities

    +

    5.4 Other Practicalities

    @@ -1210,7 +1216,7 @@

    5.4 Other Practicalities

    some of these issues.

    -

    5.4.1 Passing structures by value

    +

    5.4.1 Passing structures by value

    @@ -1241,7 +1247,7 @@

    5.4.1 Passing structures by value

    is transparent so you might not notice.

    -

    5.4.2 Return by value

    +

    5.4.2 Return by value

    @@ -1296,7 +1302,7 @@

    5.4.2 Return by value

    constructor. The section on SWIG and C++ has more information about this case.

    -

    5.4.3 Linking to structure variables

    +

    5.4.3 Linking to structure variables

    @@ -1313,10 +1319,10 @@

    5.4.3 Linking to structure variables

     Vector *unit_i_get() {
    -	return &unit_i;
    +  return &unit_i;
     }
     void unit_i_set(Vector *value) {
    -	unit_i = *value;
    +  unit_i = *value;
     }
     
    @@ -1328,7 +1334,7 @@

    5.4.3 Linking to structure variables

    assignment to work correctly.

    -

    5.4.4 Linking to char *

    +

    5.4.4 Linking to char *

    @@ -1457,7 +1463,7 @@

    5.4.4 Linking to char *

    -

    5.4.5 Arrays

    +

    5.4.5 Arrays

    @@ -1593,7 +1599,7 @@

    5.4.5 Arrays

    In the target language, the value can be set like a normal variable.

    -

    5.4.6 Creating read-only variables

    +

    5.4.6 Creating read-only variables

    @@ -1603,11 +1609,11 @@

    5.4.6 Creating read-only variables

     // File : interface.i
     
    -int 	a; 			// Can read/write
    +int a;       // Can read/write
     %immutable;
    -int	b,c,d			// Read only variables
    +int b,c,d;   // Read only variables
     %mutable;
    -double	x,y			// read/write
    +double x,y;  // read/write
     

    @@ -1667,10 +1673,10 @@

    5.4.6 Creating read-only variables

    %mutable;
    to silence the warning. Don't forget the extra semicolon!

    -

    5.4.7 Renaming and ignoring declarations

    +

    5.4.7 Renaming and ignoring declarations

    -

    5.4.7.1 Simple renaming of specific identifiers

    +

    5.4.7.1 Simple renaming of specific identifiers

    @@ -1768,7 +1774,7 @@

    5.4.7.1 Simple renaming of specific identifiers

    directive is more powerful and better supports wrapping of raw header file information.

    -

    5.4.7.2 Advanced renaming support

    +

    5.4.7.2 Advanced renaming support

    @@ -1970,7 +1976,7 @@

    5.4.7.2 Advanced renaming support

    multiple declarations using the previously described matching possibilities.

    -

    5.4.7.3 Limiting global renaming rules

    +

    5.4.7.3 Limiting global renaming rules

    @@ -2068,7 +2074,7 @@

    5.4.7.3 Limiting global renaming rules<

    -

    5.4.7.4 Ignoring everything then wrapping a few selected symbols

    +

    5.4.7.4 Ignoring everything then wrapping a few selected symbols

    @@ -2110,7 +2116,7 @@

    5.4.7.4 Ignoring everything then wrapping -

    5.4.8 Default/optional arguments

    +

    5.4.8 Default/optional arguments

    @@ -2127,8 +2133,8 @@

    5.4.8 Default/optional arguments

    used in Tcl as follows :

    -% plot -3.4 7.5 				# Use default value
    -% plot -3.4 7.5 10				# set color to 10 instead
    +% plot -3.4 7.5    # Use default value
    +% plot -3.4 7.5 10 # set color to 10 instead
     
     
    @@ -2147,7 +2153,7 @@

    5.4.8 Default/optional arguments

    in the C++ chapter for further details.

    -

    5.4.9 Pointers to functions and callbacks

    +

    5.4.9 Pointers to functions and callbacks

    @@ -2300,7 +2306,7 @@

    5.4.9 Pointers to functions and callbacks

    and individual target language chapters for more on callbacks and the 'director' feature.

    -

    5.5 Structures and unions

    +

    5.5 Structures and unions

    @@ -2318,7 +2324,7 @@

    5.5 Structures and unions

     struct Vector {
    -	double x,y,z;
    +  double x,y,z;
     }
     
     
    @@ -2328,22 +2334,22 @@

    5.5 Structures and unions

     double Vector_x_get(struct Vector *obj) {
    -	return obj->x;
    +  return obj->x;
     }
     double Vector_y_get(struct Vector *obj) { 
    -	return obj->y;
    +  return obj->y;
     }
     double Vector_z_get(struct Vector *obj) { 
    -	return obj->z;
    +  return obj->z;
     }
     void Vector_x_set(struct Vector *obj, double value) {
    -	obj->x = value;
    +  obj->x = value;
     }
     void Vector_y_set(struct Vector *obj, double value) {
    -	obj->y = value;
    +  obj->y = value;
     }
     void Vector_z_set(struct Vector *obj, double value) {
    -	obj->z = value;
    +  obj->z = value;
     }
     
    @@ -2382,7 +2388,7 @@

    5.5 Structures and unions

    However, most of SWIG's language modules also provide a high-level interface that is more convenient. Keep reading.

    -

    5.5.1 Typedef and structures

    +

    5.5.1 Typedef and structures

    @@ -2391,7 +2397,7 @@

    5.5.1 Typedef and structures

     typedef struct {
    -	double x,y,z;
    +  double x,y,z;
     } Vector;
     
     
    @@ -2406,7 +2412,7 @@

    5.5.1 Typedef and structures

     double Vector_x_get(Vector *obj) {
    -	return obj->x;
    +  return obj->x;
     }
     
    @@ -2416,7 +2422,7 @@

    5.5.1 Typedef and structures

     typedef struct vector_struct {
    -	double x,y,z;
    +  double x,y,z;
     } Vector;
     
     
    @@ -2428,7 +2434,7 @@

    5.5.1 Typedef and structures

    Vector and it generates the appropriate type-checking code.

    -

    5.5.2 Character strings and structures

    +

    5.5.2 Character strings and structures

    @@ -2442,8 +2448,8 @@

    5.5.2 Character strings and structures

    %module mymodule ... struct Foo { - char *name; - ... + char *name; + ... } @@ -2453,14 +2459,15 @@

    5.5.2 Character strings and structures

     char *Foo_name_get(Foo *obj) {
    -	return Foo->name;
    +  return Foo->name;
     }
     
     char *Foo_name_set(Foo *obj, char *c) {
    -	if (obj->name) free(obj->name);
    -	obj->name = (char *) malloc(strlen(c)+1);
    -	strcpy(obj->name,c);
    -	return obj->name;
    +  if (obj->name)
    +    free(obj->name);
    +  obj->name = (char *) malloc(strlen(c)+1);
    +  strcpy(obj->name,c);
    +  return obj->name;
     }
     
    @@ -2475,7 +2482,7 @@

    5.5.2 Character strings and structures

    perform memory allocation.

    -

    5.5.3 Array members

    +

    5.5.3 Array members

    @@ -2497,7 +2504,7 @@

    5.5.3 Array members

    harmless.

    -

    5.5.4 Structure data members

    +

    5.5.4 Structure data members

    @@ -2603,7 +2610,7 @@

    5.5.4 Structure data members

    datatype is really a struct, simply use a forward struct declaration such as "struct Foo;".

    -

    5.5.5 C constructors and destructors

    +

    5.5.5 C constructors and destructors

    @@ -2692,7 +2699,7 @@

    5.5.5 C constructors and destructors

    -

    5.5.6 Adding member functions to C structures

    +

    5.5.6 Adding member functions to C structures

    @@ -2712,7 +2719,7 @@

    5.5.6 Adding member functions to /* file : vector.h */ ... typedef struct Vector { - double x,y,z; + double x,y,z; } Vector; @@ -2730,23 +2737,23 @@

    5.5.6 Adding member functions to %include "vector.h" // Just grab original C header file %extend Vector { // Attach these functions to struct Vector - Vector(double x, double y, double z) { - Vector *v; - v = (Vector *) malloc(sizeof(Vector)); - v->x = x; - v->y = y; - v->z = z; - return v; - } - ~Vector() { - free($self); - } - double magnitude() { - return sqrt($self->x*$self->x+$self->y*$self->y+$self->z*$self->z); - } - void print() { - printf("Vector [%g, %g, %g]\n", $self->x,$self->y,$self->z); - } + Vector(double x, double y, double z) { + Vector *v; + v = (Vector *) malloc(sizeof(Vector)); + v->x = x; + v->y = y; + v->z = z; + return v; + } + ~Vector() { + free($self); + } + double magnitude() { + return sqrt($self->x*$self->x+$self->y*$self->y+$self->z*$self->z); + } + void print() { + printf("Vector [%g, %g, %g]\n", $self->x,$self->y,$self->z); + } }; @@ -2785,12 +2792,12 @@

    5.5.6 Adding member functions to %} typedef struct Vector { - double x,y,z; - %extend { - Vector(double x, double y, double z) { ... } - ~Vector() { ... } - ... - } + double x,y,z; + %extend { + Vector(double x, double y, double z) { ... } + ~Vector() { ... } + ... + } } Vector; @@ -2804,19 +2811,19 @@

    5.5.6 Adding member functions to /* Vector methods */ #include "vector.h" Vector *new_Vector(double x, double y, double z) { - Vector *v; - v = (Vector *) malloc(sizeof(Vector)); - v->x = x; - v->y = y; - v->z = z; - return v; + Vector *v; + v = (Vector *) malloc(sizeof(Vector)); + v->x = x; + v->y = y; + v->z = z; + return v; } void delete_Vector(Vector *v) { - free(v); + free(v); } double Vector_magnitude(Vector *v) { - return sqrt(v->x*v->x+v->y*v->y+v->z*v->z); + return sqrt(v->x*v->x+v->y*v->y+v->z*v->z); } // File : vector.i @@ -2827,13 +2834,13 @@

    5.5.6 Adding member functions to %} typedef struct Vector { - double x,y,z; - %extend { - Vector(int,int,int); // This calls new_Vector() - ~Vector(); // This calls delete_Vector() - double magnitude(); // This will call Vector_magnitude() - ... - } + double x,y,z; + %extend { + Vector(int,int,int); // This calls new_Vector() + ~Vector(); // This calls delete_Vector() + double magnitude(); // This will call Vector_magnitude() + ... + } } Vector; @@ -2845,13 +2852,13 @@

    5.5.6 Adding member functions to
     typedef struct Integer {
    -	int value;
    +  int value;
     } Int;
     %extend Integer { ...  } /* Correct name */
     %extend Int { ...  } /* Incorrect name */
     
     struct Float {
    -	float value;
    +  float value;
     };
     typedef struct Float FloatValue;
     %extend Float { ...  } /* Correct name */
    @@ -2864,7 +2871,7 @@ 

    5.5.6 Adding member functions to
     typedef struct {
    -	double value;
    +  double value;
     } Double;
     %extend Double { ...  } /* Okay */
     
    @@ -2965,7 +2972,7 @@

    5.5.6 Adding member functions to directive name has been chosen.

    -

    5.5.7 Nested structures

    +

    5.5.7 Nested structures

    @@ -2973,13 +2980,13 @@

    5.5.7 Nested structures

     typedef struct Object {
    -	int objtype;
    -	union {
    -		int 	ivalue;
    -		double	dvalue;
    -		char	*strvalue;
    -		void	*ptrvalue;
    -	} intRep;
    +  int objtype;
    +  union {
    +    int ivalue;
    +    double dvalue;
    +    char *strvalue;
    +    void *ptrvalue;
    +  } intRep;
     } Object;
     
     
    @@ -2991,15 +2998,15 @@

    5.5.7 Nested structures

     typedef union {
    -	int 		ivalue;
    -	double		dvalue;
    -	char		*strvalue;
    -	void		*ptrvalue;
    +  int ivalue;
    +  double dvalue;
    +  char *strvalue;
    +  void *ptrvalue;
     } Object_intRep;
     
     typedef struct Object {
    -	int objType;
    -	Object_intRep intRep;
    +  int objType;
    +  Object_intRep intRep;
     } Object;
     
     
    @@ -3011,16 +3018,16 @@

    5.5.7 Nested structures

     Object_intRep *Object_intRep_get(Object *o) {
    -	return (Object_intRep *) &o->intRep;
    +  return (Object_intRep *) &o->intRep;
     }
     int Object_intRep_ivalue_get(Object_intRep *o) {
    -	return o->ivalue;
    +  return o->ivalue;
     }
     int Object_intRep_ivalue_set(Object_intRep *o, int value) {
    -	return (o->ivalue = value);
    +  return (o->ivalue = value);
     }
     double Object_intRep_dvalue_get(Object_intRep *o) {
    -	return o->dvalue;
    +  return o->dvalue;
     }
     ... etc ...
     
    @@ -3049,7 +3056,7 @@ 

    5.5.7 Nested structures

    see Nested classes.

    -

    5.5.8 Other things to note about structure wrapping

    +

    5.5.8 Other things to note about structure wrapping

    @@ -3111,7 +3118,7 @@

    5.5.8 Other things to note about structure wrapping< some way or another.

    -

    5.6 Code Insertion

    +

    5.6 Code Insertion

    @@ -3121,7 +3128,7 @@

    5.6 Code Insertion

    There are four common ways to insert code, but it's useful to know how the output of SWIG is structured first.

    -

    5.6.1 The output of SWIG

    +

    5.6.1 The output of SWIG

    @@ -3157,7 +3164,7 @@

    5.6.1 The output of SWIG

    -

    5.6.2 Code insertion blocks

    +

    5.6.2 Code insertion blocks

    @@ -3227,7 +3234,7 @@

    5.6.2 Code insertion blocks

    %{ /* Create a new vector */ static Vector *new_Vector() { - return (Vector *) malloc(sizeof(Vector)); + return (Vector *) malloc(sizeof(Vector)); } %} @@ -3235,7 +3242,7 @@

    5.6.2 Code insertion blocks

    Vector *new_Vector();
    -

    5.6.3 Inlined code blocks

    +

    5.6.3 Inlined code blocks

    @@ -3247,7 +3254,7 @@

    5.6.3 Inlined code blocks

    %inline %{ /* Create a new vector */ Vector *new_Vector() { - return (Vector *) malloc(sizeof(Vector)); + return (Vector *) malloc(sizeof(Vector)); } %} @@ -3262,7 +3269,7 @@

    5.6.3 Inlined code blocks

    is given to both the C compiler and SWIG, it is illegal to include any SWIG directives inside a %{ ... %} block.

    -

    5.6.4 Initialization blocks

    +

    5.6.4 Initialization blocks

    @@ -3273,11 +3280,11 @@

    5.6.4 Initialization blocks

     %init %{
    -	init_variables();
    +  init_variables();
     %}
     
    -

    5.7 An Interface Building Strategy

    +

    5.7 An Interface Building Strategy

    @@ -3285,7 +3292,7 @@

    5.7 An Interface Building Strategy

    with SWIG. The specifics related to a particular scripting language are found in later chapters.

    -

    5.7.1 Preparing a C program for SWIG

    +

    5.7.1 Preparing a C program for SWIG

    @@ -3339,7 +3346,7 @@

    5.7.1 Preparing a C program for SWIG

    SWIG bug tracker.

    -

    5.7.2 The SWIG interface file

    +

    5.7.2 The SWIG interface file

    @@ -3392,7 +3399,7 @@

    5.7.2 The SWIG interface file

    In more complex projects, an interface file containing numerous %include and #include statements like this is one of the most common approaches to interface file design due to lower maintenance overhead.

    -

    5.7.3 Why use separate interface files?

    +

    5.7.3 Why use separate interface files?

    @@ -3421,7 +3428,7 @@

    5.7.3 Why use separate interface files?

    header files. -

    5.7.4 Getting the right header files

    +

    5.7.4 Getting the right header files

    @@ -3441,7 +3448,7 @@

    5.7.4 Getting the right header files

    ...
    -

    5.7.5 What to do with main()

    +

    5.7.5 What to do with main()

    diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 62c0e8d1e04..73b242fa37d 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -1,12 +1,13 @@ - + SWIG and C++ + -

    6 SWIG and C++

    +

    6 SWIG and C++

      @@ -75,7 +76,7 @@

      6 SWIG and C++

      wrapping and that material will be useful in understanding this chapter.

      -

      6.1 Comments on C++ Wrapping

      +

      6.1 Comments on C++ Wrapping

      @@ -117,7 +118,7 @@

      6.1 Comments on C++ Wrapping

      yourself in the foot. You will just have to be careful.

      -

      6.2 Approach

      +

      6.2 Approach

      @@ -158,7 +159,7 @@

      6.2 Approach

      for each target language.

      -

      6.3 Supported C++ features

      +

      6.3 Supported C++ features

      @@ -197,7 +198,7 @@

      6.3 Supported C++ features

      good way to get problems fixed (wink).

      -

      6.4 Command line options and compilation

      +

      6.4 Command line options and compilation

      @@ -231,7 +232,7 @@

      6.4 Command line options and compilation

      The -noproxy commandline option is recognised by many target languages and will generate just this interface as in earlier versions. -

      6.5 Proxy classes

      +

      6.5 Proxy classes

      @@ -243,7 +244,7 @@

      6.5 Proxy classes

      C++ class is wrapped by a Java proxy class.

      -

      6.5.1 Construction of proxy classes

      +

      6.5.1 Construction of proxy classes

      @@ -325,7 +326,7 @@

      6.5.1 Construction of proxy classes

      might include operator overloading, exception handling, and other features.

      -

      6.5.2 Resource management in proxies

      +

      6.5.2 Resource management in proxies

      @@ -479,7 +480,7 @@

      6.5.2 Resource management in proxies

      can be used (if necessary) to address some of the more tricky memory management problems.

      -

      6.5.3 Language specific details

      +

      6.5.3 Language specific details

      @@ -487,7 +488,7 @@

      6.5.3 Language specific details

      chapter has merely introduced the topic in a very general way.

      -

      6.6 Simple C++ wrapping

      +

      6.6 Simple C++ wrapping

      @@ -520,7 +521,7 @@

      6.6 Simple C++ wrapping

      accessor functions which are then used by the proxy classes.

      -

      6.6.1 Constructors and destructors

      +

      6.6.1 Constructors and destructors

      @@ -529,15 +530,15 @@

      6.6.1 Constructors and destructors

       List * new_List(void) {
      -	return new List;
      +  return new List;
       }
       void delete_List(List *l) {
      -	delete l;
      +  delete l;
       }
       
       
      -

      6.6.2 Default constructors, copy constructors and implicit destructors

      +

      6.6.2 Default constructors, copy constructors and implicit destructors

      @@ -686,7 +687,7 @@

      6.6.2 Default constructors, copy constructors and

      -

      6.6.3 When constructor wrappers aren't created

      +

      6.6.3 When constructor wrappers aren't created

      @@ -763,7 +764,7 @@

      6.6.3 When constructor wrappers aren't created%feature can be found in the Customization features chapter.

      -

      6.6.4 Copy constructors

      +

      6.6.4 Copy constructors

      @@ -865,7 +866,7 @@

      6.6.4 Copy constructors

      older versions.

      -

      6.6.5 Member functions

      +

      6.6.5 Member functions

      @@ -873,7 +874,7 @@

      6.6.5 Member functions

       int List_search(List *obj, char *value) {
      -	return obj->search(value);
      +  return obj->search(value);
       }
       
       
      @@ -891,7 +892,7 @@

      6.6.5 Member functions

      low-level procedural wrappers match the accessor function prototype described above.

      -

      6.6.6 Static members

      +

      6.6.6 Static members

      @@ -901,7 +902,7 @@

      6.6.6 Static members

      in the generated wrapper code.

      -

      6.6.7 Member data

      +

      6.6.7 Member data

      @@ -911,11 +912,11 @@

      6.6.7 Member data

       int List_length_get(List *obj) {
      -	return obj->length;
      +  return obj->length;
       }
       int List_length_set(List *obj, int value) {
      -	obj->length = value;
      -	return value;
      +  obj->length = value;
      +  return value;
       }
       
       
      @@ -932,7 +933,7 @@

      6.6.7 Member data

      public: ... %immutable; - int length; + int length; %mutable; ... }; @@ -1093,7 +1094,7 @@

      6.6.7 Member data

      customization features.

      -

      6.7 Default arguments

      +

      6.7 Default arguments

      @@ -1199,7 +1200,7 @@

      6.7 Default arguments

      SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used.

      -

      6.8 Protection

      +

      6.8 Protection

      @@ -1219,7 +1220,7 @@

      6.8 Protection

      the same convention used by C++).

      -

      6.9 Enums and constants

      +

      6.9 Enums and constants

      @@ -1230,7 +1231,7 @@

      6.9 Enums and constants

       class Swig {
       public:
      -	enum {ALE, LAGER, PORTER, STOUT};
      +  enum {ALE, LAGER, PORTER, STOUT};
       };
       
       
      @@ -1249,7 +1250,7 @@

      6.9 Enums and constants

      Members declared as const are wrapped as read-only members and do not create constants.

      -

      6.10 Friends

      +

      6.10 Friends

      @@ -1310,7 +1311,7 @@

      6.10 Friends

      and a wrapper for the method 'blah' will not be generated.

      -

      6.11 References and pointers

      +

      6.11 References and pointers

      @@ -1320,7 +1321,7 @@

      6.11 References and pointers

       class Foo {
       public:
      -	double bar(double &a);
      +  double bar(double &a);
       }
       
      @@ -1330,7 +1331,7 @@

      6.11 References and pointers

       double Foo_bar(Foo *obj, double *a) {
      -	obj->bar(*a);
      +  obj->bar(*a);
       }
       
      @@ -1410,7 +1411,7 @@

      6.11 References and pointers

      -

      6.12 Pass and return by value

      +

      6.12 Pass and return by value

      @@ -1514,7 +1515,7 @@

      6.12 Pass and return by value

      It is not used for C++ pointers or references.

      -

      6.13 Inheritance

      +

      6.13 Inheritance

      @@ -1549,24 +1550,24 @@

      6.13 Inheritance

      class Shape { public: - double x,y; - virtual double area() = 0; - virtual double perimeter() = 0; - void set_location(double x, double y); + double x,y; + virtual double area() = 0; + virtual double perimeter() = 0; + void set_location(double x, double y); }; class Circle : public Shape { public: - Circle(double radius); - ~Circle(); - double area(); - double perimeter(); + Circle(double radius); + ~Circle(); + double area(); + double perimeter(); }; class Square : public Shape { public: - Square(double size); - ~Square(); - double area(); - double perimeter(); + Square(double size); + ~Square(); + double area(); + double perimeter(); }
    @@ -1700,7 +1701,7 @@

    6.13 Inheritance

    class.

    -

    6.14 A brief discussion of multiple inheritance, pointers, and type checking

    +

    6.14 A brief discussion of multiple inheritance, pointers, and type checking

    @@ -1832,7 +1833,7 @@

    6.14 A brief discussion of multiple inheritance, In practice, the pointer is held as an integral number in the target language proxy class.

    -

    6.15 Wrapping Overloaded Functions and Methods

    +

    6.15 Wrapping Overloaded Functions and Methods

    @@ -1895,7 +1896,7 @@

    6.15 Wrapping Overloaded Functions -

    6.15.1 Dispatch function generation

    +

    6.15.1 Dispatch function generation

    @@ -2020,7 +2021,7 @@

    6.15.1 Dispatch function generation

    If you're still confused, don't worry about it---SWIG is probably doing the right thing.

    -

    6.15.2 Ambiguity in Overloading

    +

    6.15.2 Ambiguity in Overloading

    @@ -2101,13 +2102,13 @@

    6.15.2 Ambiguity in Overloading

    -When wrapping an overloaded function, there is a chance that you will get an error message like this: +When wrapping an overloaded function, there is a chance that you will get a warning message like this:

    -example.i:3: Warning 467: Overloaded foo(int) not supported (no type checking
    -rule for 'int').
    +example.i:3: Warning 467: Overloaded foo(int) not supported (incomplete type checking rule - 
    +no precedence level in typecheck typemap for 'int').
     
    @@ -2116,7 +2117,8 @@

    6.15.2 Ambiguity in Overloading

    but for some reason there is no type-checking rule that can be used to generate a working dispatch function. The resulting behavior is then undefined. You should report this as a bug to the -SWIG bug tracking database. +SWIG bug tracking database +if this is due to one of the typemaps supplied with SWIG.

    @@ -2137,7 +2139,7 @@

    6.15.2 Ambiguity in Overloading

    functions and methods. The only way to fix the problem is to read the next section.

    -

    6.15.3 Ambiguity resolution and renaming

    +

    6.15.3 Ambiguity resolution and renaming

    @@ -2480,6 +2482,7 @@

    6.15.3 Ambiguity resolu
  • Currently no resolution is performed in order to match function parameters. This means function parameter types must match exactly. For example, namespace qualifiers and typedefs will not work. The following usage of typedefs demonstrates this: +

    @@ -2566,7 +2569,7 @@ 

    6.15.3 Ambiguity resolu -

    6.15.4 Comments on overloading

    +

    6.15.4 Comments on overloading

    @@ -2583,7 +2586,7 @@

    6.15.4 Comments on overloading

    than dynamically typed languages like Perl, Python, Ruby, and Tcl.

    -

    6.16 Wrapping overloaded operators

    +

    6.16 Wrapping overloaded operators

    @@ -2612,7 +2615,7 @@

    6.16 Wrapping overloaded operators

    } Complex operator*(const Complex &c) const { return Complex(rpart*c.rpart - ipart*c.ipart, - rpart*c.ipart + c.rpart*ipart); + rpart*c.ipart + c.rpart*ipart); } Complex operator-() const { return Complex(-rpart, -ipart); @@ -2767,7 +2770,7 @@

    6.16 Wrapping overloaded operators

  • -

    6.17 Class extension

    +

    6.17 Class extension

    @@ -2785,17 +2788,17 @@

    6.17 Class extension

    class Vector { public: - double x,y,z; - Vector(); - ~Vector(); - ... bunch of C++ methods ... - %extend { - char *__str__() { - static char temp[256]; - sprintf(temp,"[ %g, %g, %g ]", $self->x,$self->y,$self->z); - return &temp[0]; - } - } + double x,y,z; + Vector(); + ~Vector(); + ... bunch of C++ methods ... + %extend { + char *__str__() { + static char temp[256]; + sprintf(temp,"[ %g, %g, %g ]", $self->x,$self->y,$self->z); + return &temp[0]; + } + } }; @@ -2866,7 +2869,7 @@

    6.17 Class extension

    directive name has been chosen.

    -

    6.18 Templates

    +

    6.18 Templates

    @@ -3614,18 +3617,52 @@

    6.18 Templates

    -Needless to say, SWIG's template support provides plenty of -opportunities to break the universe. That said, an important final -point is that SWIG does not perform extensive error checking of -templates! Specifically, SWIG does not perform type checking nor -does it check to see if the actual contents of the template -declaration make any sense. Since the C++ compiler will hopefully -check this when it compiles the resulting wrapper file, there is no -practical reason for SWIG to duplicate this functionality (besides, -none of the SWIG developers are masochistic enough to want to -implement this right now). +Needless to say, SWIG's template support provides plenty of opportunities to +break the universe. That said, an important final point is that SWIG does +not perform extensive error checking of templates! Specifically, SWIG does +not perform type checking nor does it check to see if the actual contents of the +template declaration make any sense. Since the C++ compiler checks this when it +compiles the resulting wrapper file, there is no practical reason for SWIG to +duplicate this functionality.

    + +

    +As SWIG's template support does not perform type checking %template +can be used as early as after a template declaration. You can, and rarely have +to, use %template before the template parameters have been declared. +For example: +

    + +
    +
    +template <class T> class OuterTemplateClass {};
    +
    +// The nested class OuterClass::InnerClass inherits from the template class
    +// OuterTemplateClass<OuterClass::InnerStruct> and thus the template needs
    +// to be expanded with %template before the OuterClass declaration.
    +%template(OuterTemplateClass_OuterClass__InnerStruct)
    +    OuterTemplateClass<OuterClass::InnerStruct>
    +
    +
    +// Don't forget to use %feature("flatnested") for OuterClass::InnerStruct and
    +// OuterClass::InnerClass if the target language doesn't support nested classes.
    +class OuterClass {
    +    public:
    +        // Forward declarations:
    +        struct InnerStruct;
    +        class InnerClass;
    +};
    +
    +struct OuterClass::InnerStruct {};
    +
    +// Expanding the template at this point with %template is too late as the
    +// OuterClass::InnerClass declaration is processed inside OuterClass.
    +
    +class OuterClass::InnerClass : public OuterTemplateClass<InnerStruct> {};
    +
    +
    +

    Compatibility Note: The first implementation of template support relied heavily on macro expansion in the preprocessor. Templates have been more tightly integrated into @@ -3666,7 +3703,7 @@

    6.18 Templates

    Similar changes apply to typemaps and other customization features.

    -

    6.19 Namespaces

    +

    6.19 Namespaces

    @@ -4115,7 +4152,7 @@

    6.19 Namespaces

    more advanced namespace support.

    -

    6.19.1 The nspace feature for namespaces

    +

    6.19.1 The nspace feature for namespaces

    @@ -4196,7 +4233,7 @@

    6.19.1 The nspace feature for namespaces

    Compatibility Note: The nspace feature was first introduced in SWIG-2.0.0.

    -

    6.20 Renaming templated types in namespaces

    +

    6.20 Renaming templated types in namespaces

    @@ -4274,7 +4311,7 @@

    6.20 Renaming tem -

    6.21 Exception specifications

    +

    6.21 Exception specifications

    @@ -4325,7 +4362,7 @@

    6.21 Exception specification The next section details a way of simulating an exception specification or replacing an existing one.

    -

    6.22 Exception handling with %catches

    +

    6.22 Exception handling with %catches

    @@ -4375,7 +4412,7 @@

    6.22 Exception handling with %catches

    -

    6.23 Pointers to Members

    +

    6.23 Pointers to Members

    @@ -4425,7 +4462,7 @@

    6.23 Pointers to Members

    for member pointers.

    -

    6.24 Smart pointers and operator->()

    +

    6.24 Smart pointers and operator->()

    @@ -4637,11 +4674,12 @@

    6.24 Smart pointers and operator->( Note: Smart pointer support was first added in SWIG-1.3.14.

    -

    6.25 C++ reference counted objects - ref/unref feature

    +

    6.25 C++ reference counted objects - ref/unref feature

    Another similar idiom in C++ is the use of reference counted objects. Consider for example: +

    @@ -4658,11 +4696,11 @@ 

    6.25 C++ reference counted objects - ref/un return add_ref(); } - int unref() const { + int unref() const { if (ref_count() == 0 || del_ref() == 0 ) { - delete this; - return 0; - } + delete this; + return 0; + } return ref_count(); } }; @@ -4809,7 +4847,7 @@

    6.25 C++ reference counted objects - ref/un -

    6.26 Using declarations and inheritance

    +

    6.26 Using declarations and inheritance

    @@ -4972,7 +5010,7 @@

    6.26 Using declarations and inheritance

    -

    6.27 Nested classes

    +

    6.27 Nested classes

    @@ -5000,6 +5038,12 @@

    6.27 Nested classes

    +

    +If a nested class, within an outer class, has to be used as a template parameter within the outer class, then the template will +have to be instantiated with %template before the beginning of the outer class. +An example can be found in the +Templates section. +

    Compatibility Note: @@ -5030,7 +5074,7 @@

    6.27 Nested classes

    -

    6.28 A brief rant about const-correctness

    +

    6.28 A brief rant about const-correctness

    @@ -5088,7 +5132,7 @@

    6.28 A brief rant about const-correctness

    of your project.

    -

    6.29 Where to go for more information

    +

    6.29 Where to go for more information

    diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html new file mode 100644 index 00000000000..3e9e1c1a206 --- /dev/null +++ b/Doc/Manual/Scilab.html @@ -0,0 +1,2052 @@ + + + +SWIG and Scilab + + + + + + + +

    39 SWIG and Scilab

    + + + + + + +

    +Scilab is a scientific software package for numerical computations providing a powerful open computing environment for engineering and scientific applications that is mostly compatible with MATLAB. More information can be found at www.scilab.org. +

    + +

    +This chapter explains how to use SWIG for Scilab. After this introduction, you should be able to generate with SWIG a Scilab external module from a C/C++ library. +

    + + +

    39.1 Preliminaries

    + + +

    +SWIG for Scilab supports Linux. Other operating sytems haven't been tested. +

    + +

    +Scilab is supported from version 5.3.3 onwards. +The forthcoming version 6, as of January 2015, is also supported. +

    + +

    +SWIG for Scilab supports C language. C++ is partially supported. See A basic tour of C/C++ wrapping for further details. +

    + + +

    39.2 Running SWIG

    + + +

    +Let's see how to use SWIG for Scilab on a small example. +
    +In this example we bind from C a function and a global variable into Scilab. The SWIG interface (stored in a file named example.i), is the following: +

    + +
    +%module example
    +
    +%inline %{
    +double Foo = 3.0;
    +
    +int fact(int n) {
    +    if (n < 0) {
    +        return 0;
    +    }
    +    else if (n == 0) {
    +        return 1;
    +    }
    +    else {
    +        return n * fact(n-1);
    +    }
    +}
    +%}
    +
    + +

    +Note: a code in an %inline section is both parsed and wrapped by SWIG, and inserted as is in the wrapper source file. +

    + + +

    39.2.1 Generating the module

    + + +

    +The module is generated using the swig executable and its -scilab option. +

    + +
    +$ swig -scilab example.i
    +
    + +

    +This command generates two files: +

    +
      +
    • example_wrap.c: a C source file containing the wrapping code and also here the wrapped code (the fact() and Foo definitions)
    • +
    • loader.sce: a Scilab script used to load the module into Scilab +
    + +

    +Note: if the following error is returned: +

    + +
    +:1: Error: Unable to find 'swig.swg'
    +:3: Error: Unable to find 'scilab.swg'
    +
    + +

    +it may be because the SWIG library is not found. Check the SWIG_LIB environment variable or your SWIG installation. +

    + +

    +Note: SWIG for Scilab can work in two modes related to the way the module is built, see the Building modes section for details. +This example uses the builder mode. +

    + + +

    +The swig executable has several other command line options you can use. See Scilab command line options for further details. +

    + + +

    39.2.2 Building the module

    + + +

    +To be loaded in Scilab, the wrapper has to be built into a dynamic module (or shared library). +

    + +

    +The commands to compile and link the wrapper (with gcc) into the shared library libexample.so are: +

    + +
    +$ gcc -fPIC -c -I/usr/local/include/scilab example_wrap.c
    +$ gcc -shared example_wrap.o -o libexample.so
    +
    + +

    +Note: we supposed in this example that the path to the Scilab include directory is /usr/local/include/scilab (which is the case in a Debian environment), this should be changed for another environment. +

    + +

    39.2.3 Loading the module

    + + +

    +Loading a module is done by running the loader script in Scilab: +

    + +
    +--> exec loader.sce
    +
    + +

    +Scilab should output the following messages: +

    + +
    +Shared archive loaded.
    +Link done.
    +
    + +

    +which means that Scilab has successfully loaded the shared library. The module functions and other symbols are now available in Scilab. +

    + +

    39.2.4 Using the module

    + + +

    +In Scilab, the function fact() is simply called as following: +

    + +
    +--> fact(5)
    +ans  =
    +
    +    120.
    +
    + +

    For the Foo global variable, the accessors need to be used: + +

    +--> Foo_get
    +ans  =
    +
    +    3.
    +
    +--> Foo_set(4);
    +
    +--> Foo_get
    +ans  =
    +
    +    4.
    +
    + +

    +Note: for conciseness, we assume in the subsequent Scilab code examples that the modules have been beforehand built and loaded in Scilab. +

    + +

    39.2.5 Scilab command line options

    + + +

    +The following table lists the Scilab specific command line options in addition to the generic SWIG options: +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    -builderGenerate the Scilab builder script
    -buildercflags <cflags>Add <cflags> to the builder compiler flags
    -builderldflags <ldflags>Add <ldlags> to the builder linker flags
    -buildersources <files>Add the (comma separated) files <files> to the builder sources
    -builderverbositylevel <level>Set the build verbosity level to <level> (default 0: off, 2: high)
    -builderflagscript <file>Use the Scilab script <file> to configure the compiler and linker flags
    -gatewayxml <gateway_id>Generate the gateway XML with the given <gateway_id>
    + +

    +These options can be displayed with: +

    + +
    +$ swig -scilab -help
    +
    + + +

    39.3 A basic tour of C/C++ wrapping

    + + +

    39.3.1 Overview

    + + +

    +SWIG for Scilab provides only a low-level C interface for Scilab (see Scripting Languages for the general approach to wrapping). +This means that functions, structs, classes, variables, etc... are interfaced through C functions. These C functions are mapped as Scilab functions. +There are a few exceptions, such as constants and enumerations, which can be wrapped directly as Scilab variables. +

    + +

    39.3.2 Identifiers

    + + +

    +In Scilab 5.x, identifier names are composed of 24 characters maximum (this limitation should disappear from Scilab 6.0 onwards). +
    Thus long function or variable names may be truncated and this can cause ambiguities. +

    +

    This happens especially when wrapping structs/classes, for which the wrapped function name is composed of the struct/class name and field names. +In these cases, the %rename directive can be used to choose a different Scilab name. +

    + +

    39.3.3 Functions

    + + +

    +Functions are wrapped as new Scilab built-in functions. For example: +

    + +
    +%module example
    +
    +%inline %{
    +int fact(int n) {
    +  if (n > 1)
    +    return n * fact(n - 1);
    +  else
    +    return 1;
    +}
    +%}
    +
    + +

    +creates a built-in function fact(n) in Scilab: +

    + +
    +--> fact(4)
    +ans  =
    +
    +    24.
    +
    + +

    39.3.3.1 Argument passing

    + + +

    +In the above example, the function parameter is a primitive type and is marshalled by value. +So this function is wrapped without any additional customization. +Argument values are converted between C types and Scilab types through type mappings. +There are several default type mappings for primitive and complex types, described later in the Scilab typemaps section. +

    + +

    +When a parameter is not passed by value, such as a pointer or reference, SWIG does not know if it is an input, output (or both) parameter. +The INPUT, OUTPUT, INOUT typemaps defined in the typemaps.i library can be used to specify this. +

    + +

    +Let's see this on two simple functions: sub() which has an output parameter, and inc(), which as input/output parameter: +

    + +
    +%module example
    +
    +%include <typemaps.i>
    +
    +extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
    +extern void inc(int *INOUT, int *INPUT);
    +
    +%{
    +void sub(int *x, int *y, int *result) {
    +  *result = *x - *y;
    +}
    +void inc(int *x, int *delta) {
    +  *x = *x + *delta;
    +}
    +%}
    +
    + +

    +In Scilab, parameters are passed by value. The output (and inout) parameters are returned as the result of the functions: +

    + +
    +--> sub(5, 3)
    + ans  =
    +
    +    2.
    +
    +--> inc(4, 3)
    + ans  =
    +
    +    7.
    +
    + +

    39.3.3.2 Multiple output arguments

    + + +

    +A C function can have several output parameters. They can all be returned as results of the wrapped function as Scilab supports multiple return values from a function +when using the typemaps.i library. +If the C function itself returns a result, this is returned first before the parameter outputs. +

    + +

    +The example below shows this for a C function returning 2 values and a result: +

    + +
    +%module example
    +
    +%include <typemaps.i>
    +
    +int divide(int n, int d, int *OUTPUT, int *OUTPUT);
    +
    +%{
    +int divide(int n, int d, int q*, int *r) {
    +   if (d != 0) {
    +     *q = n / d;
    +     *r = n % d;
    +     return 1;
    +   }
    +   else return 0;
    +}
    +%}
    +
    + +
    + +
    +--> [ret, q, r] = divide(20, 6)
    + r  =
    +
    +    2.
    + q  =
    +
    +    3.
    + ret  =
    +
    +    1.
    +
    + + +

    39.3.4 Global variables

    + + +

    +Global variables are manipulated through generated accessor functions. +For example, for a given Foo global variable, SWIG actually generates two functions: Foo_get() to get the value of Foo, and Foo_set() to set the value. +These functions are used as following: +

    + +
    +--> exec loader.sce;
    +--> c = Foo_get();
    +
    +--> Foo_set(4);
    +
    +--> c
    +c =
    +
    +    3.
    +
    +--> Foo_get()
    +ans  =
    +
    +    4.
    +
    + +

    +It works for variables of primitive type, but also for non-primitive types: arrays, and structs/classes which are described later. +For now, an example with two global primitive arrays x and y is shown: +

    + +
    +%module example
    +
    +%inline %{
    +int x[10];
    +double y[7];
    +
    +void initArrays()
    +{
    +  int i;
    +  for (i = 0; i < 10; i++)
    +    x[i] = 1;
    +  for (i = 0; i < 7; i++)
    +    y[i] = 1.0f;
    +}
    +%}
    +
    + +

    +It works the same:

    + +
    +--> exec loader.sce
    +
    +--> initArrays();
    +--> x_get()
    + ans  =
    +
    +    1.    1.    1.    1.    1.    1.    1.    1.    1.    1.
    +
    +--> y_set([0:6] / 10);
    +--> y_get()
    + ans  =
    +
    +    0.    0.1    0.2    0.3    0.4    0.5    0.6
    +
    + + +

    39.3.5 Constants and enumerations

    + + +

    39.3.5.1 Constants

    + + +

    +There is not any constant in Scilab. By default, C/C++ constants are wrapped as getter functions. For example, for the following constants: +

    + +
    +%module example
    +#define    ICONST      42
    +#define    FCONST      2.1828
    +#define    CCONST      'x'
    +#define    CCONST2     '\n'
    +#define    SCONST      "Hello World"
    +#define    SCONST2     "\"Hello World\""
    +
    + +

    +the following getter functions are generated: +

    + +
    +--> exec loader.sce;
    +--> ICONST_get();
    + ans  =
    +
    +    42.
    +
    +--> FCONST_get();
    + ans  =
    +
    +    2.1828
    +
    +--> CCONST_get();
    + ans  =
    +
    +    x
    +
    +--> CCONST2_get();
    + ans  =
    +
    +--> SCONST_get();
    + ans  =
    +
    +    Hello World
    +
    +--> SCONST2_get();
    + ans  =
    +
    +    "Hello World"
    +
    +--> EXPR_get();
    + ans  =
    +
    +    48.5484
    +
    +--> iconst_get();
    + ans  =
    +
    +    37.
    +
    +--> fconst_get();
    + ans  =
    +
    +    3.14
    +
    + +

    +There is another mode in which constants are wrapped as Scilab variables. +The variables are easier to use than functions, but the drawback is that variables are not constant and so can be modified. +

    + +

    +This mode can be enabled/disabled at any time in the interface file with %scilabconst(), which +works like all the other %feature directives. +Use the argument value "1" to enable and "0" to disable this mode. +For example in this mode the previous constants: +

    + +
    +%module example
    +
    +%scilabconst(1);
    +#define    ICONST      42
    +#define    FCONST      2.1828
    +#define    CCONST      'x'
    +#define    CCONST2     '\n'
    +#define    SCONST      "Hello World"
    +#define    SCONST2     "\"Hello World\""
    +
    + +

    +are mapped to Scilab variables, with the same name: +

    + +
    +--> exec loader.sce;
    +--> ICONST
    + ans  =
    +
    +    42
    +
    +--> FCONST
    + ans  =
    +
    +    2.1828
    +
    +--> CCONST
    + ans  =
    +
    +    x
    +
    +--> CCONST2
    + ans  =
    +
    +--> SCONST
    + ans  =
    +
    +    Hello World
    +
    +--> SCONST2
    + ans  =
    +
    +    "Hello World"
    +
    +--> EXPR
    + ans  =
    +
    +    48.5484
    +
    +--> iconst
    + ans  =
    +
    +    37
    +
    +--> fconst
    + ans  =
    +
    +    3.14
    +
    + +

    39.3.5.2 Enumerations

    + + +

    +The wrapping of enums is the same as for constants. +By default, enums are wrapped as getter functions. +For example, with the following enumeration: +

    + +
    %module example
    +typedef enum { RED, BLUE, GREEN } color;
    +
    + +

    +a getter function will be generated for each value of the enumeration: +

    + +
    +--> exec loader.sce;
    +--> RED_get()
    + ans  =
    +
    +    0.
    +
    +--> BLUE_get()
    + ans  =
    +
    +    1.
    +
    +--> GREEN_get()
    + ans  =
    +
    +    2.
    +
    + +

    +The %scilabconst() feature is also available for enumerations: +

    + +
    %module example
    +%scilabconst(1) color;
    +typedef enum { RED, BLUE, GREEN } color;
    +
    + +
    + +
    +--> exec loader.sce;
    +--> RED
    + ans  =
    +
    +    0.
    +
    +--> BLUE
    + ans  =
    +
    +    1.
    +
    +--> GREEN
    + ans  =
    +
    +    2.
    +
    +
    + +

    39.3.6 Pointers

    + + +

    +C/C++ pointers are fully supported by SWIG. They are mapped to the Scilab pointer type ("pointer", type ID: 128). +

    + +

    +Given a wrapping of some of the C file functions: +

    + +
    +%module example
    +
    +%{
    +#include <stdio.h>
    +%}
    +
    +FILE *fopen(const char *filename, const char *mode);
    +int fputs(const char *, FILE *);
    +int fclose(FILE *);
    +
    + +

    +These functions can be used in a natural way from Scilab: +

    + +
    +--> f = fopen("junk", "w");
    +--> typeof(f)
    + ans  =
    +
    +  pointer
    +
    +--> fputs("Hello World", f);
    +--> fclose(f);
    +
    + +

    +The user of a pointer is responsible for freeing it or, like in the example, closing any resources associated with it (just as is required in a C program). +

    + +

    39.3.6.1 Utility functions

    + + +

    +Most of time pointer manipulation is not needed in a scripting language such as Scilab. +However, in some cases it can be useful, such as for testing or debugging. +

    + +

    +SWIG comes with two pointer utility functions: +

    +
      +
    • SWIG_this(): returns the address value of a pointer
    • +
    • SWIG_ptr(): creates a pointer from an address value
    • +
    + +

    Following illustrates their use on the last example:

    + +
    +--> f = fopen("junk", "w");
    +--> fputs("Hello", f);
    +--> addr = SWIG_this(f)
    + ans  =
    +
    +    8219088.
    +
    +--> p = SWIG_ptr(addr);
    +--> fputs(" World", p);
    +--> fclose(f);
    +
    + +

    39.3.6.2 Null pointers

    + + +

    By default, Scilab does not provide a way to test or create null pointers. +But it is possible to have a null pointer by using the previous functions SWIG_this() and SWIG_ptr(), like this: +

    + +
    +--> p = SWIG_ptr(0);
    +--> SWIG_this(p) == 0
    + ans  =
    +
    +    T
    +
    + + +

    39.3.7 Structures

    + + +

    +Structs exist in Scilab, but C structs are not (at least in this version of SWIG) mapped to Scilab structs. +A C structure is wrapped through low-level accessor functions, i.e. functions that give access to the member variables of this structure. +In Scilab, a structure is manipulated through a pointer which is passed as an argument to the accessor functions. +

    + +

    +Let's see it on an example of a struct with two members: +

    + +
    +%module example
    +
    +%inline %{
    +
    +typedef struct {
    +    int x;
    +    int arr[4];
    +} Foo;
    +
    +%}
    +
    + +

    +Several functions are generated: +

    +
      +
    • a constructor function new_Foo() which returns a pointer to a newly created struct Foo.
    • +
    • two member getter functions Foo_x_get(), Foo_arr_get(), to get the values of x and y for the struct pointer (provided as the first parameter to these functions)
    • +
    • two member setter functions Foo_x_set(), Foo_arr_set(), to set the values of x and y for the struct pointer (provided as the first parameter to these functions).
    • +
    • a destructor function delete_Foo() to release the struct pointer.
    • +
    + +

    +Usage example: +

    + +
    +--> f = new_Foo();
    +--> Foo_x_set(f, 100);
    +--> Foo_x_get(f)
    +ans  =
    +
    +    100.
    +
    +--> Foo_arr_set(f, [0:3]);
    +--> Foo_arr_get(f)
    +ans  =
    +
    +    0.    1.    2.    3.
    +
    +--> delete_Foo(f);
    +
    + + +

    +Members of a structure that are also structures are also accepted and wrapped as a pointer: +

    + +
    +%module example
    +
    +%inline %{
    +
    +typedef struct {
    +  int x;
    +} Bar;
    +
    +typedef struct {
    +  Bar b;
    +} Foo;
    +
    +%}
    +
    + +
    + +
    +--> b = new_Bar();
    +--> Bar_x_set(b, 20.);
    +
    +--> f = new_Foo();
    +--> Foo_b_set(f, b);
    +
    +--> b2 = Foo_b_get(f);
    +--> Bar_x_get(b2);
    +ans  =
    +
    +    20.
    +
    + + +

    39.3.8 C++ classes

    + + +

    +Classes do not exist in Scilab. The classes are wrapped the same way as structs. +Low-level accessor functions are generated for class members. +Also, constructor and destructor functions are generated to create and destroy an instance of the class. +

    + +

    +For example, the following class: +

    + +
    +%module example
    +
    +%inline %{
    +
    +class Point {
    +public:
    +  int x, y;
    +  Point(int _x, int _y) : x(_x), y(_y) {}
    +  double distance(const Point& rhs) {
    +    return sqrt(pow(x-rhs.x, 2) + pow(y-rhs.y, 2));
    +  }
    +  void set(int _x, int _y) {
    +    x=_x;
    +    y=_y;
    +  }
    +};
    +
    +%}
    +
    + +

    +can be used in Scilab like this: +

    + +
    +--> p1 = Point_new(3, 5);
    +--> p2 = Point_new(1, 2);
    +--> p1.distance(p2)
    +ans  =
    +
    +    3.6056
    +
    +--> delete_Point(p1);
    +--> delete_Point(p2);
    +
    + +

    39.3.9 C++ inheritance

    + + +

    +Inheritance is supported. SWIG knows the inheritance relationship between classes. +

    + +

    +A function is only generated for the class in which it is actually declared. +But if one of its parameters is a class, any instance of a derived class is accepted as the argument. +

    + +

    +This mechanism also applies for accessor functions: they are generated only in the class in which they are defined. +But any instance of a derived class can be used as the argument to these accessor functions. +

    + +

    +For example, let's take a base class Shape and two derived classes Circle and Square: +

    + +
    +%module example
    +
    +%inline %{
    +
    +class Shape {
    +public:
    +  double x, y;
    +  void set_location(double _x, double _y) { x = _x; y = _y; }
    +  virtual double get_perimeter() { return 0; };
    +};
    +
    +class Circle : public Shape {
    +public:
    +  int radius;
    +  Circle(int _radius): radius(_radius) {};
    +  virtual double get_perimeter() { return 6.28 * radius; }
    +};
    +
    +class Square : public Shape {
    +public:
    +  int size;
    +  Square(int _size): size(_size) {};
    +  virtual double get_perimeter() { return 4 * size; }
    +};
    +
    +%}
    +
    + +

    +To set the location of the Circle, we have to use the function set_location() of the parent Shape. +But we can use either use the get_perimeter() function of the parent class or the derived class: +

    + +
    +--> c = new_Circle(3);
    +
    +--> Shape_set_location(c, 2, 3);
    +--> Shape_x_get(c)
    + ans  =
    +
    +    2.
    +
    +--> Circle_get_perimeter(c)
    + ans  =
    +
    +    18.84
    +
    +--> Shape_get_perimeter(c)
    + ans  =
    +
    +    18.84
    +
    + +

    39.3.10 Pointers, references, values, and arrays

    + + +

    +In C++ objects can be passed by value, pointer, reference, or by an array: +

    +
    +%module example
    +
    +%{
    +#include <sciprint.h>
    +%}
    +
    +%inline %{
    +
    +class Foo {
    +public:
    +  Foo(int _x) : x(_x) {}
    +  int x;
    +};
    +
    +void spam1(Foo *f)  { sciprint("%d\n", f->x); }   // Pass by pointer
    +void spam2(Foo &f)  { sciprint("%d\n", f.x); }    // Pass by reference
    +void spam3(Foo f)   { sciprint("%d\n", f.x); }    // Pass by value
    +void spam4(Foo f[]) { sciprint("%d\n", f[0].x); } // Array of objects
    +
    +%}
    +
    +

    + +In SWIG, there is no real distinction between these. +So in Scilab, it is perfectly legal to do this: +

    +
    +--> f = new_Foo()
    +--> spam1(f)
    +3
    +--> spam2(f)
    +3
    +--> spam3(f)
    +3
    +--> spam4(f)
    +3
    +
    + +

    +Similar behaviour occurs for return values. For example, if you had functions like this: +

    +
    +Foo *spam5();
    +Foo &spam6();
    +Foo  spam7();
    +
    +

    +All these functions will return a pointer to an instance of Foo. +As the function spam7 returns a value, new instance of Foo has to be allocated, and a pointer on this instance is returned. +

    + +

    39.3.11 C++ templates

    + + +

    +As in other languages, function and class templates are supported in SWIG Scilab. +

    + +

    +You have to tell SWIG to create wrappers for a particular +template instantiation. The %template directive is used for this purpose. +For example: +

    + +
    +%module example
    +
    +template<class T1, class T2, class T3>
    +struct triplet {
    +  T1 first;
    +  T2 second;
    +  T3 third;
    +  triplet(const T1& a, const T2& b, const T3& c) {
    +    third = a; second = b; third = c;
    +  }
    +};
    +
    +%template(IntTriplet) triplet<int,int,int>;
    +
    + +

    +Then in Scilab: +

    + +
    +
    +--> t = new_IntTriplet(3, 4, 1);
    +
    +--> IntTriplet_first_get(t)
    + ans  =
    +
    +    3.
    +
    +--> IntTriplet_second_get(t)
    + ans  =
    +
    +    4.
    +
    +--> IntTriplet_third_get(t)
    + ans  =
    +
    +    1.
    +
    +--> delete_IntTriplet(t);
    +
    +
    + +

    +More details on template support can be found in the templates documentation. +

    + +

    39.3.12 C++ operators

    + + +

    +C++ operators are partially supported. +Operator overloading exists in Scilab, but a C++ operator is not (in this version) wrapped by SWIG as a Scilab operator, but as a function. +It is not automatic, you have to rename each operator (with the instruction %rename) with the suitable wrapper name. +

    + +

    +Let's see it with an example of class with two operators + and double(): +

    + +
    +%module example
    +
    +%rename(plus) operator +;
    +%rename(toDouble) operator double();
    +
    +%inline %{
    +
    +class Complex {
    +public:
    +  Complex(double re, double im) : real(re), imag(im) {};
    +
    +  Complex operator+(const Complex& other) {
    +    double result_real = real + other.real;
    +    double result_imaginary = imag + other.imag;
    +    return Complex(result_real, result_imaginary);
    +  }
    +  operator double() { return real; }
    +private:
    +  double real;
    +  double imag;
    +};
    +
    +%}
    +
    + +
    + +
    +--> c1 = new_Complex(3, 7);
    +
    +--> c2 = Complex_plus(c, new_Complex(1,1));
    +
    +--> Complex_toDouble(c2)
    + ans  =
    +
    +    4.
    +
    + + +

    39.3.13 C++ namespaces

    + + +

    +SWIG is aware of C++ namespaces, but does not use it for wrappers. +The module is not broken into submodules, nor do namespace appear in functions names. +All the namespaces are all flattened in the module. +For example with one namespace Foo: +

    + +
    +
    +%module example
    +
    +%inline %{
    +
    +namespace foo {
    +  int fact(int n) {
    +    if (n > 1)
    +      return n * fact(n-1);
    +    else
    +      return 1;
    +  }
    +
    +  struct Vector {
    +    double x,y,z;
    +  };
    +};
    +
    +%}
    +
    +
    +
    + +

    +In Scilab, there is no need to the specify the Foo namespace: +

    + +
    +
    +--> fact(3)
    + ans  =
    +
    +   6.
    +
    +--> v = new_Vector();
    +--> Vector_x_set(v, 3.4);
    +--> Vector_y_get(v)
    + ans  =
    +
    +   0.
    +
    +
    + +

    +If your program has more than one namespace, name conflicts can be resolved using %rename. +For example: +

    + +
    +
    +%rename(Bar_spam) Bar::spam;
    +
    +namespace Foo {
    +  int spam();
    +}
    +
    +namespace Bar {
    +  int spam();
    +}
    +
    +
    + +

    +Note: the nspace feature is not supported. +

    + + +

    39.3.14 C++ exceptions

    + + +

    +Scilab does not natively support exceptions, but has errors. +When an exception is thrown, SWIG catches it, and sets a Scilab error. An error message is displayed in Scilab. +For example: +

    + +
    +%module example
    +
    +%inline %{
    +void throw_exception() throw(char const *) {
    +  throw "Bye world !";
    +}
    +%}
    +
    + +
    + +
    +-->throw_exception()
    +  !--error 999
    +SWIG/Scilab: Exception (char const *) occured: Bye world !
    +
    + +

    +Scilab has a try-catch mechanism (and a similar instruction execstr()) to handle exceptions. +It can be used with the lasterror() function as following: +

    + +
    +--> execstr('throw_exception()', 'errcatch');
    + ans  =
    +
    +    999.
    +
    +--> lasterror()
    + ans  =
    +
    +    SWIG/Scilab: Exception (char const *) occured: Bye world !
    +
    + +

    +If the function has a throw exception specification, SWIG can automatically map the exception type and set an appropriate Scilab error message. +It works for a few primitive types, and also for STL exceptions (the library std_except.i has to be included to get the STL exception support): +

    + +
    +%module example
    +
    +%include <std_except.i>
    +
    +%inline %{
    +void throw_int() throw(int) {
    +  throw 12;
    +}
    +
    +void throw_stl_invalid_arg(int i) throw(std::invalid_argument) {
    +  if (i < 0)
    +    throw std::invalid_argument("argument is negative.");
    +}
    +%}
    +
    + +
    + +
    +--> throw_int();
    +            !--error 999
    +SWIG/Scilab: Exception (int) occured: 12
    +
    +-->throw_stl_invalid_arg(-1);
    +                          !--error 999
    +SWIG/Scilab: ValueError: argument is negative.
    +
    + +

    +More complex or custom exception types require specific exception typemaps to be implemented in order to specifically handle a thrown type. +See the SWIG C++ documentation for more details. +

    + +

    39.3.15 C++ STL

    + + +

    +The Standard Template Library (STL) is partially supported. See STL for more details. +

    + +

    39.4 Type mappings and libraries

    + + +

    39.4.1 Default primitive type mappings

    + + +

    +The following table provides the equivalent Scilab type for C/C++ primitive types. +

    + +
    + + + + + + + + + + + + + + + + + + + + +
    C/C++ typeScilab type
    boolboolean
    charstring
    signed chardouble or int8
    unsigned chardouble or uint8
    shortdouble or int16
    unsigned shortdouble or uint16
    intdouble or int32
    unsigned intdouble or uint32
    longdouble or int32
    unsigned longdouble or uint32
    signed long longnot supported in Scilab 5.x
    unsigned long longnot supported in Scilab 5.x
    floatdouble
    doubledouble
    char * or char[]string
    +
    + +

    +Notes: +

    +
      +
    • In Scilab the double type is far more used than any integer type. +This is why integer values (int32, uint32, ...) are automatically converted to Scilab double values when marshalled from C into Scilab. +Additionally on input to a C function, Scilab double values are converted into the related integer type. +
    • +
    • +When an integer is expected, if the input is a double, the value must be an integer, i.e. it must not have any decimal part, otherwise a SWIG value error occurs. +
    • +
    • +In SWIG for Scilab 5.x, the long long type is not supported, since Scilab 5.x does not have a 64-bit integer type. +The default behaviour is for SWIG to generate code that will give a runtime error if long long type arguments are used from Scilab. +
    • +
    + + +

    39.4.2 Default type mappings for non-primitive types

    + + +

    +The default mapped type for C/C++ non-primitive types is the Scilab pointer, for example for C structs, C++ classes, etc... +

    + + +

    39.4.3 Arrays

    + + +

    +Typemaps are available by default for arrays. Primitive type arrays are automatically converted to/from Scilab matrices. +Typemaps are also provided to handle members of a struct or class that are arrays. +

    + +

    +In input, the matrix is usually one-dimensional (it can be either a row or column vector). But it can also be a two-dimensional matrix. +Warning: in Scilab, the values are column-major ordered, unlike in C, which is row-major ordered. +

    + +

    +The type mappings used for arrays is the same for primitive types, described earlier. +This means that, if needed, a Scilab double vector is converted in input into the related C integer array +and this C integer array is automatically converted on output into a Scilab double vector. +Note that unlike scalars, no control is done for arrays when a double is converted into an integer. +

    + +

    +The following example illustrates all this:

    + +
    +%module example
    +
    +%#include <stdio.h>
    +
    +%inline %{
    +
    +void printArray(int values[], int len) {
    +  int i = 0;
    +  for (i = 0; i < len; i++) {
    +    printf("%s %d %s", i==0?"[":"", values[i], i==len-1?"]\n":"");
    +  }
    +}
    +%}
    +
    + +
    + +
    +--> printArray([0 1 2 3], 4)
    +[ 0  1  2  3 ]
    +
    +--> printArray([0.2; -1.8; 2; 3.7], 4)
    +[ 0  -1  2  3 ]
    +
    +--> printArray([0 1; 2 3], 4)
    +[ 0  2  1  3 ]
    +
    +--> printArray([0; 1; 2; 3], 4)
    +[ 0  1  2  3 ]
    +
    + +

    39.4.4 Pointer-to-pointers

    + + +

    +There are no specific typemaps for pointer-to-pointers, they are are mapped as pointers in Scilab. +

    + +

    +Pointer-to-pointers are sometimes used to implement matrices in C. The following is a an example of this: +

    + + +
    +%module example
    +%inline %{
    +
    +// Returns the matrix [1 2; 3 4];
    +double **create_matrix() {
    +  double **M;
    +  int i;
    +  M = (double **) malloc(2 * sizeof(double *));
    +  for (i = 0; i < 2; i++) {
    +    M[i] = (double *) malloc(2 * sizeof(double));
    +    M[i][0] = 2 * i + 1;
    +    M[i][1] = 2 * i + 2;
    +  }
    +  return M;
    +}
    +
    +// Gets the item M(i,j) value
    +double get_matrix(double **M, int i, int j) {
    +  return M[i][j];
    +}
    +
    +// Sets the item M(i,j) value to be val
    +void set_matrix(double **M, int i, int j, double val) {
    +  M[i][j] = val;
    +}
    +
    +// Prints a matrix (2,2) to console
    +void print_matrix(double **M, int nbRows, int nbCols) {
    +  int i, j;
    +  for (i = 0; i < 2; i++) {
    +    for (j = 0; j < 2; j++) {
    +      printf("%3g ", M[i][j]);
    +    }
    +    printf("\n");
    +  }
    +}
    +
    +%}
    +
    + +

    + These functions are used like this in Scilab: +

    + +
    +--> m = create_matrix();
    +
    +--> print_matrix(m);
    +   1.   2.
    +   3.   4.
    +
    +--> set_matrix(m, 1, 1, 5.);
    +
    +--> get_matrix(m, 1, 1)
    + ans  =
    +
    +    5.
    +
    + + +

    39.4.5 Matrices

    + + +

    +The matrix.i library provides a set of typemaps which can be useful when working with one-dimensional and two-dimensional matrices. +

    + +

    +In order to use this library, just include it in the interface file: +

    + +
    +  %include <matrix.i>
    +
    + + +

    +Several typemaps are available for the common Scilab matrix types: +

    +
      +
    • double
    • +
    • int
    • +
    • char *
    • +
    • bool
    • +
    + +

    +For example: for a matrix of int, we have the typemaps, for input: +

    +
      +
    • (int *IN, int IN_ROWCOUNT, int IN_COLCOUNT)
    • +
    • (int IN_ROWCOUNT, int IN_COLCOUNT, int *IN)
    • +
    • (int *IN, int IN_SIZE)
    • +
    • (int IN_SIZE, int *IN)
    • +
    + +

    +and output: +

    +
      +
    • (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT)
    • +
    • (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, int **OUT)
    • +
    • (int **OUT, int *OUT_SIZE)
    • +
    • (int *OUT_SIZE, int **OUT)
    • +
    + +

    +They marshall a Scilab matrix type into the appropriate 2 or 3 C parameters. +The following is an example using the typemaps in this library: +

    + +
    +%module example
    +
    +%include <matrix.i>
    +
    +%apply (int *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (int *matrix, int matrixNbRow, int matrixNbCol) };
    +%apply (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (int **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) };
    +
    +%inline %{
    +
    +void absolute(int *matrix, int matrixNbRow, int matrixNbCol,
    +  int **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) {
    +  int i, j;
    +  *outMatrixNbRow = matrixNbRow;
    +  *outMatrixNbCol = matrixNbCol;
    +  *outMatrix = malloc(matrixNbRow * matrixNbCol * sizeof(int));
    +  for (i=0; i < matrixNbRow * matrixNbCol; i++) {
    +    (*outMatrix)[i] = matrix[i] > 0 ? matrix[i]:-matrix[i];
    +  }
    +}
    +
    +%}
    +
    + +
    + +
    +--> absolute([-0 1 -2; 3 4 -5])
    + ans  =
    +
    +    0.    1.    2.
    +    3.    4.    5.
    +
    + +

    +The remarks made earlier for arrays also apply here: +

    +
      +
    • The values of matrices in Scilab are column-major orderered,
    • +
    • There is no control while converting double values to integers, double values are truncated without any checking or warning.
    • +
    + +

    39.4.6 STL

    + + +

    +The STL library wraps some containers defined in the STL (Standard Template Library), so that they can be manipulated in Scilab. +This library also provides the appropriate typemaps to use the containers in functions and variables. +

    + +

    +The list of wrapped sequence containers are: +

    +
      +
    • std::vector
    • +
    • std::list
    • +
    • std::deque
    • +
    + +

    +And associative containers are: +

    +
      +
    • std::set
    • +
    • std::multiset
    • +
    + +

    +Typemaps are available for the following container types: +

    + +
      +
    • double
    • +
    • float
    • +
    • int
    • +
    • string
    • +
    • bool
    • +
    • pointer
    • +
    + +

    +Containers of other item types are not supported. Using them does not break compilation, but provokes a runtime error. +Containers of enum are not supported yet. +

    + +

    +In order to use the STL, the library must first be included in the SWIG interface file: +

    + +
    +%include <stl.i>
    +
    + +

    Then for each container used, the appropriate template must be instantiated, in the std namespace: +

    +namespace std {
    +    %template(IntVector)    vector<int>;
    +    %template(DoubleVector) vector<double>;
    +}
    +
    + +

    +Additionally, the module initialization function has to be executed first in Scilab, so that all the types are known to Scilab. +See the Module initialization section for more details. +

    + + +

    +Because in Scilab matrices exist for basic types only, a sequence container of pointers is mapped to a Scilab list. +For other item types (double, int, string...) the sequence container is mapped to a Scilab matrix. +

    + +

    +The first example below shows how to create a vector (of int) in Scilab, add some values to the vector and pass it as an argument of a function. +It also shows, thanks to the typemaps, that we can also pass a Scilab matrix of values directly into the function: +

    + +
    +%module example
    +
    +%include <stl.i>
    +
    +namespace std {
    +  %template(IntVector) vector<int>;
    +}
    +
    +%{
    +#include <numeric>
    +%}
    +
    +%inline %{
    +
    +double average(std::vector<int> v) {
    +  return std::accumulate(v.begin(), v.end(), 0.0) / v.size();
    +}
    +
    +%}
    +
    + +
    + +
    +--> example_Init();
    +
    +--> v = new_IntVector();
    +
    +--> for i = 1:4
    +-->     IntVector_push_back(v, i);
    +--> end;
    +
    +--> average(v)
    + ans  =
    +
    +    2.5
    +
    +--> average([0 1 2 3])
    + ans  =
    +
    +    2.5
    +
    +--> delete_IntVector();
    +
    + + +

    +In the second example, a set of struct (Person) is wrapped. +A function performs a search in this set, and returns a subset. As one can see, the result in Scilab is a list of pointers: +

    + +
    +%module example
    +
    +%include <stl.i>
    +
    +%{
    +#include <string>
    +%}
    +
    +%inline %{
    +
    +struct Person {
    +  Person(std::string _name, int _age) : name(_name), age(_age) {};
    +  std::string name;
    +  int age;
    +};
    +typedef Person * PersonPtr;
    +
    +%}
    +
    +namespace std {
    +  %template(PersonPtrSet) set<PersonPtr>;
    +}
    +
    +%inline %{
    +
    +std::set<PersonPtr> findPersonsByAge(std::set<PersonPtr> persons, int minAge, int maxAge) {
    +  std::set<PersonPtr> foundPersons;
    +  for (std::set<PersonPtr>::iterator it = persons.begin(); it != persons.end(); it++) {
    +    if (((*it)->age >= minAge) && ((*it)->age <= maxAge)) {
    +      foundPersons.insert(*it);
    +    }
    +  }
    +  return foundPersons;
    +}
    +
    +%}
    +
    + +
    + +
    +--> example_Init();
    +
    +--> joe = new_Person("Joe", 25);
    +--> susan = new_Person("Susan", 32);
    +--> bill = new_Person("Bill", 50);
    +
    +--> p = new_PersonPtrSet();
    +--> PersonPtrSet_insert(p, susan);
    +--> PersonPtrSet_insert(p, joe);
    +--> PersonPtrSet_insert(p, bill);
    +
    +--> l = findPersonsByAge(p, 20, 40);
    +
    +--> size(l)
    + ans  =
    +
    +    2.
    +
    +--> Person_name_get(l(1))
    +ans  =
    +
    +    Susan
    +
    +--> Person_name_get(l(2))
    + ans  =
    +
    +    Joe
    +
    +--> delete_PersonPtrSet(p);
    +
    + +

    39.5 Module initialization

    + + +

    +The wrapped module contains an initialization function to: +

    +
      +
    • initialize the SWIG runtime, which is necessary when working with the STL
    • +
    • initialize in Scilab the module constants and enumerations declared with %scilabconst()
    • +
    + +

    +This initialization function should be executed at the start of a script, before the wrapped library has to be used. +

    + +

    +The function has the name of the module suffixed by _Init. +For example, to initialize the module example: +

    + +
    +--> example_Init();
    +
    + +

    39.6 Building modes

    + + +

    +The mechanism to load an external module in Scilab is called Dynamic Link and works with dynamic modules (or shared libraries, .so files). +

    + +

    +To produce a dynamic module, when generating the wrapper, there are two possibilities, or build modes: +

    +
      +
    • the nobuilder mode, this is the default mode in SWIG. The user is responsible of the build. +
    • the builder mode. In this mode, Scilab is responsible of building. +
    + +

    39.6.1 No-builder mode

    + + +

    +In this mode, used by default, SWIG generates the wrapper sources, which have to be manually compiled and linked. +A loader script loader.sce is also produced, this one is executed further in Scilab to load the module. +

    + +

    +This mode is the best option to use when you have to integrate the module build into a larger build process. +

    + + +

    39.6.2 Builder mode

    + + +

    +In this mode, in addition to the wrapper sources, SWIG produces a builder Scilab script (builder.sce), which is executed in Scilab to build the module. +In a few words, the Scilab ilib_build() command is used, which produces the shared library file, and the loader script loader.sce (and also a cleaner script cleaner.sce). +

    + +

    +An advantage of this mode is that it hides all the complexity of the build and other platform issues. +Also it allows the module to conform to a Scilab external module convention which is that an external module should be simply built by calling a builder script. +

    + +

    +The builder mode is activated with the -builder SWIG option. +In this mode, the following SWIG options may be used to setup the build: +

    + +
      +
    • -buildersources: to add sources to the build (several files must be separated by a comma)
    • +
    • -buildercflags: to add flags to the builder compiler flags, for example to set library dependencies include paths
    • +
    • -builderldflags: to add flags to the linker flags, for example to set library dependency names and paths
    • +
    + +

    +Let's give an example how to build a module example, composed of two sources, and using a library dependency: +

    +
      +
    • the sources are baa1.c and baa2.c (and are stored in in the current directory)
    • +
    • the library is libfoo in /opt/foo (headers stored in /opt/foo/include, and shared library in /opt/foo/lib)
    • +
    + +

    +The command is: +

    + +
    +$ swig -scilab -builder -buildercflags -I/opt/foo/include -builderldflags "-L/opt/foo/lib -lfoo" -buildersources baa1.cxx,baa2.cxx example.i
    +
    + +

    39.7 Generated scripts

    + + +

    +In this part we give some details about the generated Scilab scripts. +

    + +

    39.7.1 Builder script

    + + +

    +builder.sce is the name of the builder script generated by SWIG in builder mode. It contains code like this: +

    +
    +ilib_name = "examplelib";
    +files = ["example_wrap.c"];
    +libs = [];
    +table = ["fact","_wrap_fact";"Foo_set","_wrap_Foo_set";"Foo_get","_wrap_Foo_get";];
    +ilib_build(ilib_name,table,files,libs);
    +
    + +

    +ilib_build(lib_name,table,files,libs) is used to create shared libraries, and to generate a loader file used to dynamically load the shared library into Scilab. +

    + +
      +
    • ilib_name: a character string, the generic name of the library without path and extension.
    • +
    • files: string matrix containing objects files needed for shared library creation.
    • +
    • libs: string matrix containing extra libraries needed for shared library creation.
    • +
    • table: two column string matrix containing a table of pairs of 'scilab function name', 'C function name'.
    • +
    + +

    39.7.2 Loader script

    + + +

    +The loader script is used to load in Scilab all the module functions. When loaded, these functions can be used as other Scilab functions. +

    + +

    +The loader script loader.sce contains code similar to: +

    + +
    +// ------------------------------------------------------
    +// generated by builder.sce: Please do not edit this file
    +// ------------------------------------------------------
    +
    +libexamplelib_path = get_file_path('loader.sce');
    +list_functions = [             'fact';
    +            'Foo_set';
    +            'Foo_get';
    +];
    +addinter(libexamplelib_path+'/libexamplelib.so','libexamplelib',list_functions);
    +// remove temp. variables on stack
    +clear libexamplelib_path;
    +clear list_functions;
    +clear get_file_path;
    +// ------------------------------------------------------
    +
    + +

    +addinter(files,spname,fcts) performs dynamic linking of a compiled C interface function. +

    +
      +
    • files: a character string or a vector of character strings defining the object files (containing the C interface functions) to link with.
    • +
    • spname: a character string. Name of interface routine entry point.
    • +
    • fcts: vector of character strings. The name of new Scilab function.
    • +
    + + +

    39.8 Other resources

    + + +
      +
    • Example use cases can be found in the Examples/scilab directory.
    • +
    • The test suite in the Examples/test-suite/scilab can be another source of useful use cases.
    • +
    • The Scilab API is used in the generated code and is a useful reference when examining the output.
    • +
    • This guide describes the Scilab external modules structure and files, in particular the files that are generated by SWIG for Scilab.
    • +
    + diff --git a/Doc/Manual/Scripting.html b/Doc/Manual/Scripting.html index c714fa0d7b9..18af78a6862 100644 --- a/Doc/Manual/Scripting.html +++ b/Doc/Manual/Scripting.html @@ -1,12 +1,13 @@ - + Scripting Languages + -

    4 Scripting Languages

    +

    4 Scripting Languages

      @@ -37,7 +38,7 @@

      4 Scripting Languages

      access C and C++ code.

      -

      4.1 The two language view of the world

      +

      4.1 The two language view of the world

      @@ -68,7 +69,7 @@

      4.1 The two language view of the world

      scripting, and access to high-level data structures such associative arrays.

      -

      4.2 How does a scripting language talk to C?

      +

      4.2 How does a scripting language talk to C?

      @@ -93,7 +94,7 @@

      4.2 How does a scripting language talk to C?

      -

      4.2.1 Wrapper functions

      +

      4.2.1 Wrapper functions

      @@ -101,8 +102,10 @@

      4.2.1 Wrapper functions

       int fact(int n) {
      -	if (n <= 1) return 1;
      -	else return n*fact(n-1);
      +  if (n <= 1)
      +    return 1;
      +  else
      +    return n*fact(n-1);
       }
       
      @@ -123,18 +126,17 @@

      4.2.1 Wrapper functions

      function above example might look like the following :

      -int wrap_fact(ClientData clientData, Tcl_Interp *interp,
      -		int argc, char *argv[]) {
      -	int result;
      -	int arg0;
      -	if (argc != 2) {
      -		interp->result = "wrong # args";
      -		return TCL_ERROR;
      -	}
      -	arg0 = atoi(argv[1]);
      -	result = fact(arg0);
      -	sprintf(interp->result,"%d", result);
      -	return TCL_OK;
      +int wrap_fact(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
      +  int result;
      +  int arg0;
      +  if (argc != 2) {
      +    interp->result = "wrong # args";
      +    return TCL_ERROR;
      +  }
      +  arg0 = atoi(argv[1]);
      +  result = fact(arg0);
      +  sprintf(interp->result,"%d", result);
      +  return TCL_OK;
       }
       
       
      @@ -148,9 +150,9 @@

      4.2.1 Wrapper functions

       int Wrap_Init(Tcl_Interp *interp) {
      -	Tcl_CreateCommand(interp, "fact", wrap_fact, (ClientData) NULL,
      -				(Tcl_CmdDeleteProc *) NULL);
      -	return TCL_OK;
      +  Tcl_CreateCommand(interp, "fact", wrap_fact, (ClientData) NULL,
      +                    (Tcl_CmdDeleteProc *) NULL);
      +  return TCL_OK;
       }
       
      @@ -165,7 +167,7 @@

      4.2.1 Wrapper functions

      additional initialization code. Only the specific details are different.

      -

      4.2.2 Variable linking

      +

      4.2.2 Variable linking

      @@ -201,7 +203,7 @@

      4.2.2 Variable linking

      the value.

      -

      4.2.3 Constants

      +

      4.2.3 Constants

      @@ -222,7 +224,7 @@

      4.2.3 Constants

      a trivial exercise.

      -

      4.2.4 Structures and classes

      +

      4.2.4 Structures and classes

      @@ -243,9 +245,9 @@

      4.2.4 Structures and classes

       struct Vector {
      -	Vector();
      -	~Vector();
      -	double x,y,z;
      +  Vector();
      +  ~Vector();
      +  double x,y,z;
       };
       
       
      @@ -283,7 +285,7 @@

      4.2.4 Structures and classes

      about the actual representation of a Vector.

      -

      4.2.5 Proxy classes

      +

      4.2.5 Proxy classes

      @@ -298,9 +300,9 @@

      4.2.5 Proxy classes

       class Vector {
       public:
      -	Vector();
      -	~Vector();
      -	double x,y,z;
      +  Vector();
      +  ~Vector();
      +  double x,y,z;
       };
       
      @@ -345,7 +347,7 @@

      4.2.5 Proxy classes

      as if you are simply manipulating a C/C++ object.

      -

      4.3 Building scripting language extensions

      +

      4.3 Building scripting language extensions

      @@ -358,7 +360,7 @@

      4.3 Building scripting language extensions

      added to it.

      -

      4.3.1 Shared libraries and dynamic loading

      +

      4.3.1 Shared libraries and dynamic loading

      @@ -400,7 +402,7 @@

      4.3.1 Shared libraries and dynamic loading

      c++ -shared example.o example_wrap.o -o example.so
    -

    4.3.2 Linking with shared libraries

    +

    4.3.2 Linking with shared libraries

    @@ -447,7 +449,7 @@

    4.3.2 Linking with shared libraries

    -

    4.3.3 Static linking

    +

    4.3.3 Static linking

    diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 666069264fd..bfa58f1ae79 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -1,16 +1,19 @@ - + SWIG-3.0 Documentation + -

    SWIG-3.0 Documentation

    +

    SWIG-3.0 Documentation

    -Last update : SWIG-3.0.5 (in progress) +

    +Last update : SWIG-3.0.9 (in progress) +

    -

    Sections

    +

    Sections

    -

    SWIG Core Documentation

    +

    SWIG Core Documentation

    -

    Language Module Documentation

    +

    Language Module Documentation

    -

    Developer Documentation

    +

    Developer Documentation

    • Extending SWIG
    • diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index 45218f30377..31fae0321c7 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -1,12 +1,13 @@ - + SWIG and Tcl + -

      39 SWIG and Tcl

      +

      40 SWIG and Tcl

        @@ -83,7 +84,7 @@

        39 SWIG and Tcl

        this is no longer supported.

        -

        39.1 Preliminaries

        +

        40.1 Preliminaries

        @@ -109,7 +110,7 @@

        39.1 Preliminaries

        need to compile this file and link it with the rest of your program.

        -

        39.1.1 Getting the right header files

        +

        40.1.1 Getting the right header files

        @@ -127,7 +128,7 @@

        39.1.1 Getting the right header files

        header file.

        -

        39.1.2 Compiling a dynamic module

        +

        40.1.2 Compiling a dynamic module

        @@ -163,7 +164,7 @@

        39.1.2 Compiling a dynamic module

        -module command line option.

        -

        39.1.3 Static linking

        +

        40.1.3 Static linking

        @@ -207,8 +208,8 @@

        39.1.3 Static linking

        $ gcc example.c example_wrap.c \ -Xlinker -export-dynamic \ -DHAVE_CONFIG_H -I/usr/local/include/ \ - -L/usr/local/lib -ltcl -lm -ldl \ - -o mytclsh + -L/usr/local/lib -ltcl -lm -ldl \ + -o mytclsh
      @@ -229,7 +230,7 @@

      39.1.3 Static linking

      hassle in the opinion of this author).

      -

      39.1.4 Using your module

      +

      40.1.4 Using your module

      @@ -357,7 +358,7 @@

      39.1.4 Using your module

      the man pages).

      -

      39.1.5 Compilation of C++ extensions

      +

      40.1.5 Compilation of C++ extensions

      @@ -440,7 +441,7 @@

      39.1.5 Compilation of C++ extensions

      might want to investigate using a more formal standard such as COM.

      -

      39.1.6 Compiling for 64-bit platforms

      +

      40.1.6 Compiling for 64-bit platforms

      @@ -467,7 +468,7 @@

      39.1.6 Compiling for 64-bit platforms

      linking standard (e.g., -o32 and -n32 on Irix).

      -

      39.1.7 Setting a package prefix

      +

      40.1.7 Setting a package prefix

      @@ -486,7 +487,7 @@

      39.1.7 Setting a package prefix

      call it "Foo_bar".

      -

      39.1.8 Using namespaces

      +

      40.1.8 Using namespaces

      @@ -508,7 +509,7 @@

      39.1.8 Using namespaces

      are always accessed with the namespace name such as Foo::bar.

      -

      39.2 Building Tcl/Tk Extensions under Windows 95/NT

      +

      40.2 Building Tcl/Tk Extensions under Windows 95/NT

      @@ -519,7 +520,7 @@

      39.2 Building Tcl/Tk Extensions under Windows 95/NT -

      39.2.1 Running SWIG from Developer Studio

      +

      40.2.1 Running SWIG from Developer Studio

      @@ -577,7 +578,7 @@

      39.2.1 Running SWIG from Developer Studio

      % -

      39.2.2 Using NMAKE

      +

      40.2.2 Using NMAKE

      @@ -625,11 +626,11 @@

      39.2.2 Using NMAKE

      TCL_INCLUDES = -Id:\tcl8.0a2\generic -Id:\tcl8.0a2\win TCLLIB = d:\tcl8.0a2\win\tcl80.lib -tcl:: - ..\..\swig -tcl -o $(WRAPFILE) $(INTERFACE) - $(CC) $(CFLAGS) $(TCL_INCLUDES) $(SRCS) $(WRAPFILE) - set LIB=$(TOOLS)\lib - $(LINK) $(LOPT) -out:example.dll $(LIBS) $(TCLLIB) example.obj example_wrap.obj +tcl: + ..\..\swig -tcl -o $(WRAPFILE) $(INTERFACE) + $(CC) $(CFLAGS) $(TCL_INCLUDES) $(SRCS) $(WRAPFILE) + set LIB=$(TOOLS)\lib + $(LINK) $(LOPT) -out:example.dll $(LIBS) $(TCLLIB) example.obj example_wrap.obj @@ -640,7 +641,7 @@

      39.2.2 Using NMAKE

      Tcl extensions.

      -

      39.3 A tour of basic C/C++ wrapping

      +

      40.3 A tour of basic C/C++ wrapping

      @@ -651,7 +652,7 @@

      39.3 A tour of basic C/C++ wrapping

      wrapping.

      -

      39.3.1 Modules

      +

      40.3.1 Modules

      @@ -685,7 +686,7 @@

      39.3.1 Modules

      -

      39.3.2 Functions

      +

      40.3.2 Functions

      @@ -710,7 +711,7 @@

      39.3.2 Functions

      % -

      39.3.3 Global variables

      +

      40.3.3 Global variables

      @@ -790,7 +791,7 @@

      39.3.3 Global variables

      -

      39.3.4 Constants and enums

      +

      40.3.4 Constants and enums

      @@ -874,7 +875,7 @@

      39.3.4 Constants and enums

      conversion. This allows the global statement to be omitted.

      -

      39.3.5 Pointers

      +

      40.3.5 Pointers

      @@ -970,7 +971,7 @@

      39.3.5 Pointers

      None if the conversion can't be performed.

      -

      39.3.6 Structures

      +

      40.3.6 Structures

      @@ -980,7 +981,7 @@

      39.3.6 Structures

       struct Vector {
      -	double x,y,z;
      +  double x,y,z;
       };
       
       
      @@ -1252,7 +1253,7 @@

      39.3.6 Structures

      memory management section that appears shortly.

      -

      39.3.7 C++ classes

      +

      40.3.7 C++ classes

      @@ -1319,7 +1320,7 @@

      39.3.7 C++ classes

      -

      39.3.8 C++ inheritance

      +

      40.3.8 C++ inheritance

      @@ -1368,7 +1369,7 @@

      39.3.8 C++ inheritance

      It is safe to use multiple inheritance with SWIG.

      -

      39.3.9 Pointers, references, values, and arrays

      +

      40.3.9 Pointers, references, values, and arrays

      @@ -1422,7 +1423,7 @@

      39.3.9 Pointers, references, values, and arrays

      when the return value is garbage collected).

      -

      39.3.10 C++ overloaded functions

      +

      40.3.10 C++ overloaded functions

      @@ -1545,7 +1546,7 @@

      39.3.10 C++ overloaded functions

      Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      39.3.11 C++ operators

      +

      40.3.11 C++ operators

      @@ -1647,7 +1648,7 @@

      39.3.11 C++ operators

      Keep reading.

      -

      39.3.12 C++ namespaces

      +

      40.3.12 C++ namespaces

      @@ -1711,7 +1712,7 @@

      39.3.12 C++ namespaces

      identical symbol names, well, then you get what you deserve.

      -

      39.3.13 C++ templates

      +

      40.3.13 C++ templates

      @@ -1763,7 +1764,7 @@

      39.3.13 C++ templates

      examples will appear later.

      -

      39.3.14 C++ Smart Pointers

      +

      40.3.14 C++ Smart Pointers

      @@ -1847,7 +1848,7 @@

      39.3.14 C++ Smart Pointers

      -

      39.4 Further details on the Tcl class interface

      +

      40.4 Further details on the Tcl class interface

      @@ -1860,7 +1861,7 @@

      39.4 Further details on the Tcl class interface

      of how the proxy classes work.

      -

      39.4.1 Proxy classes

      +

      40.4.1 Proxy classes

      @@ -1925,7 +1926,7 @@

      39.4.1 Proxy classes

      as shown in the last section.

      -

      39.4.2 Memory management

      +

      40.4.2 Memory management

      @@ -2113,7 +2114,7 @@

      39.4.2 Memory management

      -

      39.5 Input and output parameters

      +

      40.5 Input and output parameters

      @@ -2301,7 +2302,7 @@

      39.5 Input and output parameters

      -

      39.6 Exception handling

      +

      40.6 Exception handling

      @@ -2435,7 +2436,7 @@

      39.6 Exception handling

      See the chapter on "Customization Features" for more examples.

      -

      39.7 Typemaps

      +

      40.7 Typemaps

      @@ -2452,7 +2453,7 @@

      39.7 Typemaps

      C-Tcl interface.

      -

      39.7.1 What is a typemap?

      +

      40.7.1 What is a typemap?

      @@ -2465,8 +2466,9 @@

      39.7.1 What is a typemap?

      %module example %typemap(in) int { - if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR) return TCL_ERROR; - printf("Received an integer : %d\n",$1); + if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR) + return TCL_ERROR; + printf("Received an integer : %d\n",$1); } %inline %{ extern int fact(int n); @@ -2503,8 +2505,9 @@

      39.7.1 What is a typemap?

      %module example %typemap(in) int n { - if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR) return TCL_ERROR; - printf("n = %d\n",$1); + if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR) + return TCL_ERROR; + printf("n = %d\n",$1); } %inline %{ extern int fact(int n); @@ -2526,8 +2529,9 @@

      39.7.1 What is a typemap?

       %typemap(in) int n {
      -        if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR) return TCL_ERROR;
      -	printf("n = %d\n",$1);
      +  if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR)
      +    return TCL_ERROR;
      +  printf("n = %d\n",$1);
       }
       %inline %{
       typedef int Integer;
      @@ -2569,7 +2573,7 @@ 

      39.7.1 What is a typemap?

      -

      39.7.2 Tcl typemaps

      +

      40.7.2 Tcl typemaps

      @@ -2707,7 +2711,7 @@

      39.7.2 Tcl typemaps

      Examples of these methods will appear shortly.

      -

      39.7.3 Typemap variables

      +

      40.7.3 Typemap variables

      @@ -2778,7 +2782,7 @@

      39.7.3 Typemap variables

      The Tcl name of the wrapper function being created. -

      39.7.4 Converting a Tcl list to a char **

      +

      40.7.4 Converting a Tcl list to a char **

      @@ -2840,7 +2844,7 @@

      39.7.4 Converting a Tcl list to a char **

      3 -

      39.7.5 Returning values in arguments

      +

      40.7.5 Returning values in arguments

      @@ -2882,7 +2886,7 @@

      39.7.5 Returning values in arguments

      % -

      39.7.6 Useful functions

      +

      40.7.6 Useful functions

      @@ -2958,7 +2962,7 @@

      39.7.6 Useful functions

      -

      39.7.7 Standard typemaps

      +

      40.7.7 Standard typemaps

      @@ -2975,10 +2979,10 @@

      39.7.7 Standard typemaps

       %typemap(in) int, short, long {
      -   int temp;
      -   if (Tcl_GetIntFromObj(interp, $input, &temp) == TCL_ERROR)
      -      return TCL_ERROR;
      -   $1 = ($1_ltype) temp;
      +  int temp;
      +  if (Tcl_GetIntFromObj(interp, $input, &temp) == TCL_ERROR)
      +    return TCL_ERROR;
      +  $1 = ($1_ltype) temp;
       }
       
      @@ -3043,7 +3047,7 @@

      39.7.7 Standard typemaps

      -

      39.7.8 Pointer handling

      +

      40.7.8 Pointer handling

      @@ -3119,7 +3123,7 @@

      39.7.8 Pointer handling

      -

      39.8 Turning a SWIG module into a Tcl Package.

      +

      40.8 Turning a SWIG module into a Tcl Package.

      @@ -3153,8 +3157,8 @@

      39.8 Turning a SWIG module into a Tcl Package.

       ./example/
      -	   pkgIndex.tcl           # The file created by pkg_mkIndex
      -	   example.so             # The SWIG generated module
      +           pkgIndex.tcl           # The file created by pkg_mkIndex
      +           example.so             # The SWIG generated module
       

      @@ -3191,7 +3195,7 @@

      39.8 Turning a SWIG module into a Tcl Package.

      to use the load command instead.

      -

      39.9 Building new kinds of Tcl interfaces (in Tcl)

      +

      40.9 Building new kinds of Tcl interfaces (in Tcl)

      @@ -3264,14 +3268,14 @@

      39.9 Building new kinds of Tcl interfaces (in Tcl)
       set a [Array double 100]                   ;# Create a double [100]
       for {set i 0} {$i < 100} {incr i 1} {      ;# Clear the array
      -	$a set $i 0.0
      +        $a set $i 0.0
       }
       $a set 3 3.1455                            ;# Set an individual element
       set b [$a get 10]                          ;# Retrieve an element
       
       set ia [Array int 50]                      ;# Create an int[50]
       for {set i 0} {$i < 50} {incr i 1} {       ;# Clear it
      -	$ia set $i 0
      +        $ia set $i 0
       }
       $ia set 3 7                                ;# Set an individual element
       set ib [$ia get 10]                        ;# Get an individual element
      @@ -3290,7 +3294,7 @@ 

      39.9 Building new kinds of Tcl interfaces (in Tcl) -

      39.9.1 Proxy classes

      +

      40.9.1 Proxy classes

      @@ -3411,7 +3415,7 @@

      39.9.1 Proxy classes

      interesting things.

      -

      39.10 Tcl/Tk Stubs

      +

      40.10 Tcl/Tk Stubs

      diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 040244d45ae..0dc725a9fac 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -1,12 +1,13 @@ - + Typemaps + -

      11 Typemaps

      +

      11 Typemaps

  • Common typemap methods
      @@ -85,7 +88,7 @@

      11 Typemaps

    • Usage
  • Typemaps and overloading -
  • More about %apply and %clear +
  • More about %apply and %clear
  • Passing data between typemaps
  • C++ "this" pointer
  • Where to go for more information? @@ -95,7 +98,7 @@

    11 Typemaps

    -

    11.1 Introduction

    +

    11.1 Introduction

    @@ -112,7 +115,7 @@

    11.1 Introduction

    chapter with only a vague idea of what SWIG already does by default.

    -

    11.1.1 Type conversion

    +

    11.1.1 Type conversion

    @@ -205,7 +208,7 @@

    11.1.1 Type conversion

    how it works (an exercise left to the reader).

    -

    11.1.2 Typemaps

    +

    11.1.2 Typemaps

    @@ -306,7 +309,7 @@

    11.1.2 Typemaps

    possible to completely change the way in which values are converted.

    -

    11.1.3 Pattern matching

    +

    11.1.3 Pattern matching

    @@ -408,7 +411,7 @@

    11.1.3 Pattern matching

    provides a hint to the unusual variable naming scheme involving $1, $2, and so forth.

    -

    11.1.4 Reusing typemaps

    +

    11.1.4 Reusing typemaps

    @@ -464,7 +467,7 @@

    11.1.4 Reusing typemaps

    then SWIG already knows that the int typemaps apply. You don't have to do anything.

    -

    11.1.5 What can be done with typemaps?

    +

    11.1.5 What can be done with typemaps?

    @@ -576,7 +579,7 @@

    11.1.5 What can be done with typemaps?

    aspects of the Java bindings. Consult language specific documentation for further details.

    -

    11.1.6 What can't be done with typemaps?

    +

    11.1.6 What can't be done with typemaps?

    @@ -639,7 +642,7 @@

    11.1.6 What can't be done with typemaps?

    -

    11.1.7 Similarities to Aspect Oriented Programming

    +

    11.1.7 Similarities to Aspect Oriented Programming

    @@ -653,11 +656,11 @@

    11.1.7 Similarities to Aspect Oriented Progra
  • Aspect: Aspects are the combination of the pointcut and the advice, hence each typemap is an aspect.

    -SWIG can also be viewed as has having a second set of aspects based around %feature. +SWIG can also be viewed as has having a second set of aspects based around %feature. Features such as %exception are also cross-cutting concerns as they encapsulate code that can be used to add logging or exception handling to any function.

    -

    11.1.8 The rest of this chapter

    +

    11.1.8 The rest of this chapter

    @@ -677,14 +680,14 @@

    11.1.8 The rest of this chapter

    "The C++ Programming Language" by Stroustrup before going any further.

    -

    11.2 Typemap specifications

    +

    11.2 Typemap specifications

    This section describes the behavior of the %typemap directive itself.

    -

    11.2.1 Defining a typemap

    +

    11.2.1 Defining a typemap

    @@ -797,7 +800,7 @@

    11.2.1 Defining a typemap

    individual pieces will become clear.

    -

    11.2.2 Typemap scope

    +

    11.2.2 Typemap scope

    @@ -847,7 +850,7 @@

    11.2.2 Typemap scope

    -

    11.2.3 Copying a typemap

    +

    11.2.3 Copying a typemap

    @@ -905,7 +908,7 @@

    11.2.3 Copying a typemap

    -

    11.2.4 Deleting a typemap

    +

    11.2.4 Deleting a typemap

    @@ -938,7 +941,7 @@

    11.2.4 Deleting a typemap

    after the clear operation.

    -

    11.2.5 Placement of typemaps

    +

    11.2.5 Placement of typemaps

    @@ -1018,7 +1021,7 @@

    11.2.5 Placement of typemaps

    within a particular namespace. In this example, this is done using the forward class declaration class string.

    -

    11.3 Pattern matching rules

    +

    11.3 Pattern matching rules

    @@ -1026,7 +1029,7 @@

    11.3 Pattern matching rules

    The matching rules can be observed in practice by using the debugging options also described.

    -

    11.3.1 Basic matching rules

    +

    11.3.1 Basic matching rules

    @@ -1125,7 +1128,7 @@

    11.3.1 Basic matching rules

    stripped all qualifiers in one step.

    -

    11.3.2 Typedef reductions matching

    +

    11.3.2 Typedef reductions matching

    @@ -1300,7 +1303,7 @@

    11.3.2 Typedef reductions matching -

    11.3.3 Default typemap matching rules

    +

    11.3.3 Default typemap matching rules

    @@ -1438,7 +1441,7 @@

    11.3.3 Default typemap matching rules

    simpler scheme to match the current C++ class template partial specialization matching rules.

    -

    11.3.4 Multi-arguments typemaps

    +

    11.3.4 Multi-arguments typemaps

    @@ -1468,7 +1471,7 @@

    11.3.4 Multi-argumen

    -

    11.3.5 Matching rules compared to C++ templates

    +

    11.3.5 Matching rules compared to C++ templates

    @@ -1627,7 +1630,7 @@

    11.3.5 Matching rules co

    -

    11.3.6 Debugging typemap pattern matching

    +

    11.3.6 Debugging typemap pattern matching

    @@ -1840,7 +1843,7 @@

    11.3.6 Debugging typemap pattern mat

  • -

    11.4 Code generation rules

    +

    11.4 Code generation rules

    @@ -1848,7 +1851,7 @@

    11.4 Code generation rules

    the generated wrapper code.

    -

    11.4.1 Scope

    +

    11.4.1 Scope

    @@ -1926,7 +1929,7 @@

    11.4.1 Scope

    Note that only the third of the three typemaps have the typemap code passed through the SWIG preprocessor.

    -

    11.4.2 Declaring new local variables

    +

    11.4.2 Declaring new local variables

    @@ -2093,7 +2096,7 @@

    11.4.2 Declaring new local variables

    -

    11.4.3 Special variables

    +

    11.4.3 Special variables

    @@ -2345,7 +2348,7 @@

    11.4.3 Special variables

    -

    11.4.4 Special variable macros

    +

    11.4.4 Special variable macros

    @@ -2357,7 +2360,7 @@

    11.4.4 Special variable macro The following special variable macros are available across all language modules.

    -

    11.4.4.1 $descriptor(type)

    +

    11.4.4.1 $descriptor(type)

    @@ -2368,7 +2371,7 @@

    11.4.4.1 $descriptor(type)Run-time type checker usage section.

    -

    11.4.4.2 $typemap(method, typepattern)

    +

    11.4.4.2 $typemap(method, typepattern)

    @@ -2425,7 +2428,77 @@

    11.4.4.2 $typemap(method, typep -

    11.5 Common typemap methods

    + +

    11.4.5 Special variables and typemap attributes

    + + +

    +As of SWIG-3.0.7 typemap attributes will also expand special variables and special variable macros. +

    + +

    +Example usage showing the expansion in the 'out' attribute (C# specific) as well as the main typemap body: +

    + +
    +
    +%typemap(ctype, out="$*1_ltype") unsigned int& "$*1_ltype"
    +
    +
    + +

    +is equivalent to the following as $*1_ltype expands to unsigned int: +

    + +
    +
    +%typemap(ctype, out="unsigned int") unsigned int& "unsigned int"
    +
    +
    + +

    11.4.6 Special variables combined with special variable macros

    + + +

    +Special variables can also be used within special variable macros. +The special variables are expanded before they are used in the special variable macros. +

    + +

    +Consider the following C# typemaps: +

    + +
    +
    +%typemap(cstype) unsigned int "uint"
    +%typemap(cstype, out="$typemap(cstype, $*1_ltype)") unsigned int& "$typemap(cstype, $*1_ltype)"
    +
    +
    + +

    +Special variables are expanded first and hence the above is equivalent to: +

    + +
    +
    +%typemap(cstype) unsigned int "uint"
    +%typemap(cstype, out="$typemap(cstype, unsigned int)") unsigned int& "$typemap(cstype, unsigned int)"
    +
    +
    + +

    +which then expands to: +

    + +
    +
    +%typemap(cstype) unsigned int "uint"
    +%typemap(cstype, out="uint") unsigned int& "uint"
    +
    +
    + + +

    11.5 Common typemap methods

    @@ -2433,7 +2506,7 @@

    11.5 Common typemap methods

    the following typemap methods are nearly universal:

    -

    11.5.1 "in" typemap

    +

    11.5.1 "in" typemap

    @@ -2493,7 +2566,7 @@

    11.5.1 "in" typemap

    is the same as the old "ignore" typemap.

    -

    11.5.2 "typecheck" typemap

    +

    11.5.2 "typecheck" typemap

    @@ -2519,7 +2592,7 @@

    11.5.2 "typecheck" typemap

    "typecheck" typemaps. More details about this follow in the Typemaps and overloading section.

    -

    11.5.3 "out" typemap

    +

    11.5.3 "out" typemap

    @@ -2550,7 +2623,7 @@

    11.5.3 "out" typemap

    The "out" typemap supports an optional attribute flag called "optimal". This is for code optimisation and is detailed in the Optimal code generation when returning by value section.

    -

    11.5.4 "arginit" typemap

    +

    11.5.4 "arginit" typemap

    @@ -2569,7 +2642,7 @@

    11.5.4 "arginit" typemap

    -

    11.5.5 "default" typemap

    +

    11.5.5 "default" typemap

    @@ -2602,7 +2675,7 @@

    11.5.5 "default" typemap

    for further information on default argument wrapping.

    -

    11.5.6 "check" typemap

    +

    11.5.6 "check" typemap

    @@ -2621,7 +2694,7 @@

    11.5.6 "check" typemap

    -

    11.5.7 "argout" typemap

    +

    11.5.7 "argout" typemap

    @@ -2667,7 +2740,7 @@

    11.5.7 "argout" typemap

    See the typemaps.i library file for examples.

    -

    11.5.8 "freearg" typemap

    +

    11.5.8 "freearg" typemap

    @@ -2700,7 +2773,7 @@

    11.5.8 "freearg" typemap

    prematurely.

    -

    11.5.9 "newfree" typemap

    +

    11.5.9 "newfree" typemap

    @@ -2729,7 +2802,7 @@

    11.5.9 "newfree" typemap

    See Object ownership and %newobject for further details.

    -

    11.5.10 "memberin" typemap

    +

    11.5.10 "memberin" typemap

    @@ -2751,7 +2824,7 @@

    11.5.10 "memberin" typemap

    a default implementation for arrays, strings, and other objects.

    -

    11.5.11 "varin" typemap

    +

    11.5.11 "varin" typemap

    @@ -2759,7 +2832,7 @@

    11.5.11 "varin" typemap

    purposes of assigning to a C/C++ global variable. This is implementation specific.

    -

    11.5.12 "varout" typemap

    +

    11.5.12 "varout" typemap

    @@ -2767,7 +2840,7 @@

    11.5.12 "varout" typemap

    language when reading a C/C++ global variable. This is implementation specific.

    -

    11.5.13 "throws" typemap

    +

    11.5.13 "throws" typemap

    @@ -2813,7 +2886,7 @@

    11.5.13 "throws" typemap

    For a neat way to handle these, see the Exception handling with %exception section.

    -

    11.6 Some typemap examples

    +

    11.6 Some typemap examples

    @@ -2821,7 +2894,7 @@

    11.6 Some typemap examples

    for more examples.

    -

    11.6.1 Typemaps for arrays

    +

    11.6.1 Typemaps for arrays

    @@ -2978,8 +3051,8 @@

    11.6.1 Typemaps for arrays

     struct SomeObject {
    -	float  value[4];
    -        ...
    +  float  value[4];
    +  ...
     };
     
    @@ -3080,7 +3153,7 @@

    11.6.1 Typemaps for arrays

    useless and has since been eliminated. To return structure members, simply use the "out" typemap.

    -

    11.6.2 Implementing constraints with typemaps

    +

    11.6.2 Implementing constraints with typemaps

    @@ -3093,9 +3166,9 @@

    11.6.2 Implementing constraints with typemaps11.6.2 Implementing constraints with typemaps -

    11.7 Typemaps for multiple target languages

    +

    11.7 Typemaps for multiple target languages

    @@ -3158,7 +3231,7 @@

    11.7 Typemaps for multiple target languages

    %typemap(ruby,in) int "$1 = NUM2INT($input);".

    -

    11.8 Optimal code generation when returning by value

    +

    11.8 Optimal code generation when returning by value

    @@ -3347,7 +3420,7 @@

    11.8 Optimal code generation when returning b However, it doesn't always get it right, for example when $1 is within some commented out code.

    -

    11.9 Multi-argument typemaps

    +

    11.9 Multi-argument typemaps

    @@ -3614,7 +3687,7 @@

    11.9 Multi-argument typemaps< the arguments to make them consecutive will need to be written.

    -

    11.10 Typemap warnings

    +

    11.10 Typemap warnings

    @@ -3623,7 +3696,7 @@

    11.10 Typemap warnings

    -

    11.11 Typemap fragments

    +

    11.11 Typemap fragments

    @@ -3876,7 +3949,7 @@

    11.11 Typemap fragments

    with some powerful but tricky macro and fragment usage that is used in parts of the SWIG typemap library.

    -

    11.11.1 Fragment type specialization

    +

    11.11.1 Fragment type specialization

    @@ -3909,7 +3982,7 @@

    11.11.1 Fragment type sp -

    11.11.2 Fragments and automatic typemap specialization

    +

    11.11.2 Fragments and automatic typemap specialization

    @@ -3955,7 +4028,7 @@

    11.11.2 Fragments and automa

    -

    11.12 The run-time type checker

    +

    11.12 The run-time type checker

    @@ -3981,7 +4054,7 @@

    11.12 The run-time type checker<
  • Modules can be unloaded from the type system.
  • -

    11.12.1 Implementation

    +

    11.12.1 Implementation

    @@ -4167,7 +4240,7 @@

    11.12.1 Implementation

    structures are chained together in a circularly linked list.

    -

    11.12.2 Usage

    +

    11.12.2 Usage

    This section covers how to use these functions from typemaps. To learn how to @@ -4261,7 +4334,7 @@

    11.12.2 Usage

    managed.

    -

    11.13 Typemaps and overloading

    +

    11.13 Typemaps and overloading

    @@ -4429,7 +4502,7 @@

    11.13 Typemaps and overloading

    Using the above table as a guide, each target language defines a collection of "typecheck" typemaps. -The follow excerpt from the Python module illustrates this: +The following excerpt from the Python module illustrates this:

    @@ -4438,22 +4511,22 @@

    11.13 Typemaps and overloading

    /* Note: %typecheck(X) is a macro for %typemap(typecheck,precedence=X) */ %typecheck(SWIG_TYPECHECK_INTEGER) - int, short, long, - unsigned int, unsigned short, unsigned long, - signed char, unsigned char, - long long, unsigned long long, - const int &, const short &, const long &, - const unsigned int &, const unsigned short &, const unsigned long &, - const long long &, const unsigned long long &, - enum SWIGTYPE, - bool, const bool & + int, short, long, + unsigned int, unsigned short, unsigned long, + signed char, unsigned char, + long long, unsigned long long, + const int &, const short &, const long &, + const unsigned int &, const unsigned short &, const unsigned long &, + const long long &, const unsigned long long &, + enum SWIGTYPE, + bool, const bool & { $1 = (PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0; } %typecheck(SWIG_TYPECHECK_DOUBLE) - float, double, - const float &, const double & + float, double, + const float &, const double & { $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0; } @@ -4542,11 +4615,31 @@

    11.13 Typemaps and overloading

    The bottom line: If you are writing new typemaps and you are using overloaded methods, you will probably -have to write typecheck code or copy existing code. Since this is a relatively new SWIG feature, there are -few examples to work with. However, you might look at some of the existing library files likes 'typemaps.i' for -a guide. +have to write new typecheck code or copy and modify existing typecheck code.

    +

    +If you write a typecheck typemap and omit the precedence level, for example commenting it out as shown below: +

    + +
    +
    +%typemap(typecheck /*,precedence=SWIG_TYPECHECK_INTEGER*/) int {
    +   $1 = PyInt_Check($input) ? 1 : 0;
    +}
    +
    +
    + +

    +then the type is given a precedence higher than any other known precedence level and a warning is issued: +

    + +
    +
    +example.i:18: Warning 467: Overloaded method foo(int) not supported (incomplete type checking rule - no precedence level in typecheck typemap for 'int').
    +
    +
    +

    Notes:

    @@ -4572,7 +4665,7 @@

    11.13 Typemaps and overloading

  • -

    11.14 More about %apply and %clear

    +

    11.14 More about %apply and %clear

    @@ -4658,7 +4751,7 @@

    11.14 More about %apply and %clear< -

    11.15 Passing data between typemaps

    +

    11.15 Passing data between typemaps

    @@ -4695,7 +4788,7 @@

    11.15 Passing data between typemaps

    -

    11.16 C++ "this" pointer

    +

    11.16 C++ "this" pointer

    @@ -4755,7 +4848,7 @@

    11.16 C++ "this" pointer

    the method, but gives the argument a name other than self.

    -

    11.17 Where to go for more information?

    +

    11.17 Where to go for more information?

    diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index dac1ad7bc96..1c99804f143 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -1,12 +1,13 @@ - + Variable Length Arguments + -

    14 Variable Length Arguments

    +

    14 Variable Length Arguments

      @@ -42,7 +43,7 @@

      14 Variable Length Arguments

      wisely chosen to avoid this issue.

      -

      14.1 Introduction

      +

      14.1 Introduction

      @@ -139,7 +140,7 @@

      14.1 Introduction

    -

    14.2 The Problem

    +

    14.2 The Problem

    @@ -232,7 +233,7 @@

    14.2 The Problem

    are willing to get hands dirty. Keep reading.

    -

    14.3 Default varargs support

    +

    14.3 Default varargs support

    @@ -301,7 +302,7 @@

    14.3 Default varargs support

    -

    14.4 Argument replacement using %varargs

    +

    14.4 Argument replacement using %varargs

    @@ -412,7 +413,7 @@

    14.4 Argument replacement using %varargs

    wrappers to such functions presents special problems (covered shortly).

    -

    14.5 Varargs and typemaps

    +

    14.5 Varargs and typemaps

    @@ -589,7 +590,7 @@

    14.5 Varargs and typemaps

    security, continue to the next section.

    -

    14.6 Varargs wrapping with libffi

    +

    14.6 Varargs wrapping with libffi

    @@ -605,7 +606,7 @@

    14.6 Varargs wrapping with libffi

    One way to do this is to use a special purpose library such as libffi (http://sources.redhat.com/libffi). +href="http://www.sourceware.org/libffi/">http://www.sourceware.org/libffi/). libffi is a library that allows you to dynamically construct call-stacks and invoke procedures in a relatively platform independent manner. Details about the library can be found in the libffi @@ -635,7 +636,7 @@

    14.6 Varargs wrapping with libffi

    PyObject *o = PyTuple_GetItem(varargs,i); if (!PyString_Check(o)) { PyErr_SetString(PyExc_ValueError,"Expected a string"); - free(argv); + free(argv); return NULL; } argv[i] = PyString_AsString(o); @@ -841,7 +842,7 @@

    14.6 Varargs wrapping with libffi

    values. Please consult the chapter on each language module for more details.

    -

    14.7 Wrapping of va_list

    +

    14.7 Wrapping of va_list

    @@ -895,7 +896,7 @@

    14.7 Wrapping of va_list

    -

    14.8 C++ Issues

    +

    14.8 C++ Issues

    @@ -964,7 +965,7 @@

    14.8 C++ Issues

    fully general wrapper to a varargs C++ member function.

    -

    14.9 Discussion

    +

    14.9 Discussion

    diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 99b89c425df..3ec1af75740 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -1,12 +1,13 @@ - + Warning Messages + -

    15 Warning Messages

    +

    15 Warning Messages

    -

    15.5 Symbolic symbols

    +

    15.5 Symbolic symbols

    @@ -309,7 +310,7 @@

    15.5 Symbolic symbols

    -

    15.6 Commentary

    +

    15.6 Commentary

    @@ -326,7 +327,7 @@

    15.6 Commentary

    messages.

    -

    15.7 Warnings as errors

    +

    15.7 Warnings as errors

    @@ -335,7 +336,7 @@

    15.7 Warnings as errors

    warning is encountered.

    -

    15.8 Message output format

    +

    15.8 Message output format

    @@ -349,15 +350,15 @@

    15.8 Message output format

     $ swig -python -Fstandard example.i
    -example.i:4: Syntax error in input.
    +example.i:4: Syntax error in input(1).
     $ swig -python -Fmicrosoft example.i
    -example.i(4) : Syntax error in input.
    +example.i(4) : Syntax error in input(1).
     
    -

    15.9 Warning number reference

    +

    15.9 Warning number reference

    -

    15.9.1 Deprecated features (100-199)

    +

    15.9.1 Deprecated features (100-199)

      @@ -385,7 +386,7 @@

      15.9.1 Deprecated features (100-199)

    • 126. The 'nestedworkaround' feature is deprecated.
    -

    15.9.2 Preprocessor (200-299)

    +

    15.9.2 Preprocessor (200-299)

      @@ -397,7 +398,7 @@

      15.9.2 Preprocessor (200-299)

    • 206. Unexpected tokens after #directive directive.
    -

    15.9.3 C/C++ Parser (300-399)

    +

    15.9.3 C/C++ Parser (300-399)

      @@ -474,7 +475,7 @@

      15.9.3 C/C++ Parser (300-399)

    • 395. operator delete[] ignored.
    -

    15.9.4 Types and typemaps (400-499)

    +

    15.9.4 Types and typemaps (400-499)

      @@ -492,7 +493,7 @@

      15.9.4 Types and typemaps (400-499)

    • 464. Unsupported constant value.
    • 465. Unable to handle type type.
    • 466. Unsupported variable type type. -
    • 467. Overloaded declaration not supported (no type checking rule for 'type') +
    • 467. Overloaded declaration not supported (incomplete type checking rule - no precedence level in typecheck typemap for 'type')
    • 468. No 'throw' typemap defined for exception type type
    • 469. No or improper directorin typemap defined for type
    • 470. Thread/reentrant unsafe wrapping, consider returning by value instead. @@ -505,7 +506,7 @@

      15.9.4 Types and typemaps (400-499)

      -

      15.9.5 Code generation (500-599)

      +

      15.9.5 Code generation (500-599)

        @@ -534,7 +535,7 @@

        15.9.5 Code generation (500-599)

      • 523. Use of an illegal destructor name 'name' in %extend is deprecated, the destructor name should be 'name'.
      -

      15.9.6 Language module specific (700-899)

      +

      15.9.6 Language module specific (700-899)

        @@ -585,14 +586,14 @@

        15.9.6 Language module specific (700-899)

      • 871. Unrecognized pragma pragma. (Php).
      -

      15.9.7 User defined (900-999)

      +

      15.9.7 User defined (900-999)

      These numbers can be used by your own application.

      -

      15.10 History

      +

      15.10 History

      diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index 0685242ba8f..b95105bddb8 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -1,12 +1,13 @@ - + Getting started on Windows + -

      3 Getting started on Windows

      +

      3 Getting started on Windows

        @@ -52,7 +53,7 @@

        3 Getting started on Windows

        -

        3.1 Installation on Windows

        +

        3.1 Installation on Windows

        @@ -63,7 +64,7 @@

        3.1 Installation on Windows

      • Set environment variables as described in the SWIG Windows Examples section in order to run examples using Visual C++.
      -

      3.1.1 Windows Executable

      +

      3.1.1 Windows Executable

      @@ -72,7 +73,7 @@

      3.1.1 Windows Executable

      -

      3.2 SWIG Windows Examples

      +

      3.2 SWIG Windows Examples

      @@ -87,7 +88,7 @@

      3.2 SWIG Windows Examples

      More information on each of the examples is available with the examples distributed with SWIG (Examples/index.html). -

      3.2.1 Instructions for using the Examples with Visual Studio

      +

      3.2.1 Instructions for using the Examples with Visual Studio

      @@ -105,7 +106,7 @@

      3.2.1 Instructions for using the Example If you are interested in how the project files are set up there is explanatory information in some of the language module's documentation.

      -

      3.2.1.1 C#

      +

      3.2.1.1 C#

      @@ -115,7 +116,7 @@

      3.2.1.1 C#

      -

      3.2.1.2 Java

      +

      3.2.1.2 Java

      @@ -129,7 +130,7 @@

      3.2.1.2 Java

      -

      3.2.1.3 Perl

      +

      3.2.1.3 Perl

      @@ -143,7 +144,7 @@

      3.2.1.3 Perl

      -

      3.2.1.4 Python

      +

      3.2.1.4 Python

      @@ -157,13 +158,13 @@

      3.2.1.4 Python

      -

      3.2.1.5 TCL

      +

      3.2.1.5 TCL

      TCL_INCLUDE : Set this to the directory containing tcl.h
      TCL_LIB : Set this to the TCL library including path for linking

      -Example using ActiveTcl 8.3.3.3
      +Example using ActiveTcl 8.3.3.3
      TCL_INCLUDE: D:\tcl\include
      TCL_LIB: D:\tcl\lib\tcl83.lib
      @@ -171,7 +172,7 @@

      3.2.1.5 TCL

      -

      3.2.1.6 R

      +

      3.2.1.6 R

      @@ -185,7 +186,7 @@

      3.2.1.6 R

      -

      3.2.1.7 Ruby

      +

      3.2.1.7 Ruby

      @@ -199,21 +200,21 @@

      3.2.1.7 Ruby

      -

      3.2.2 Instructions for using the Examples with other compilers

      +

      3.2.2 Instructions for using the Examples with other compilers

      If you do not have access to Visual C++ you will have to set up project files / Makefiles for your chosen compiler. There is a section in each of the language modules detailing what needs setting up using Visual C++ which may be of some guidance. Alternatively you may want to use Cygwin as described in the following section.

      -

      3.3 SWIG on Cygwin and MinGW

      +

      3.3 SWIG on Cygwin and MinGW

      SWIG can also be compiled and run using Cygwin or MinGW which provides a Unix like front end to Windows and comes free with gcc, an ANSI C/C++ compiler. However, this is not a recommended approach as the prebuilt executable is supplied.

      -

      3.3.1 Building swig.exe on Windows

      +

      3.3.1 Building swig.exe on Windows

      @@ -223,7 +224,7 @@

      3.3.1 Building swig.exe on Windows

      Normally this is not needed, so most people will want to ignore this section.

      -

      3.3.1.1 Building swig.exe using MinGW and MSYS

      +

      3.3.1.1 Building swig.exe using MinGW and MSYS

      @@ -293,9 +294,9 @@

      3.3.1.1 Building swig.exe using MinGW and M Start the MSYS command prompt and execute:
       cd /
      -tar -jxf msys-automake-1.8.2.tar.bz2 
      +tar -jxf msys-automake-1.8.2.tar.bz2
       tar -jxf msys-autoconf-2.59.tar.bz2
      -tar -zxf bison-2.0-MSYS.tar.gz   
      +tar -zxf bison-2.0-MSYS.tar.gz
       

    • @@ -341,7 +342,7 @@

      3.3.1.1 Building swig.exe using MinGW and M -

      3.3.1.2 Building swig.exe using Cygwin

      +

      3.3.1.2 Building swig.exe using Cygwin

      @@ -352,7 +353,7 @@

      3.3.1.2 Building swig.exe using Cygwin

      These files are generated using the autogen.sh script and will only need regenerating in circumstances such as changing the build system.

      -

      3.3.1.3 Building swig.exe alternatives

      +

      3.3.1.3 Building swig.exe alternatives

      @@ -362,7 +363,7 @@

      3.3.1.3 Building swig.exe altern

      -

      3.3.2 Running the examples on Windows using Cygwin

      +

      3.3.2 Running the examples on Windows using Cygwin

      @@ -371,7 +372,7 @@

      3.3.2 Running the examples on Windows Follow the Unix instructions in the README file in the SWIG root directory to build the examples.

      -

      3.4 Microsoft extensions and other Windows quirks

      +

      3.4 Microsoft extensions and other Windows quirks

      @@ -388,6 +389,53 @@

      3.4 Microsoft extensions and other Wind __declspec(dllexport) ULONG __stdcall foo(DWORD, __int32); +

      Note that if you follow Microsoft's recommendation of wrapping the +__declspec calls in a preprocessor definition, you will need to +make sure that the definition is included by SWIG as well, by either defining it +manually or via a header. For example, if you have specified the +preprocessor definition in a header named export_lib.h and include +other headers which depend on it, you should use the %include directive +to include the definition explicitly. For example, if you had a header file, +bar.h, which depended on export_lib.h, your SWIG definition +file might look like:

      + +
      +// bar.i
      +%module bar
      +%include <windows.i>
      +%include "export_lib.h"
      +%include "bar.h"
      +
      + +

      +where export_lib.h may contain: +

      + +
      +// export_lib.h
      +#define BAR_API __declspec(dllexport)
      +
      + +

      +and bar.h may look like: +

      + +
      +// bar.h
      +#include "export_lib.h"
      +BAR_API void bar_function(int, double);
      +
      + +

      +Using the preprocessor to remove BAR_API is a popular simpler solution: +

      + +
      +// bar.i
      +%module bar
      +#define BAR_API
      +%include "bar.h"
      +
      diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index c5f6552541f..d94a8a3967d 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -36,5 +36,6 @@ Pike.html Python.html R.html Ruby.html +Scilab.html Tcl.html Extending.html diff --git a/Doc/Manual/fixstyle.py b/Doc/Manual/fixstyle.py index 1007d594985..a3609689052 100644 --- a/Doc/Manual/fixstyle.py +++ b/Doc/Manual/fixstyle.py @@ -1,6 +1,6 @@ #!/usr/bin/python -# Adds the SWIG stylesheet to the generated documentation on a single page +# Replace the inline htmldoc stylesheet with the SWIG stylesheet import sys import string @@ -14,11 +14,16 @@ lines = data.splitlines() result = [ ] +skip = False for s in lines: - if s == "": + result.append(s) + skip = False data = "\n".join(result) diff --git a/Doc/Manual/index.html b/Doc/Manual/index.html index fbe105a7ed0..26cc81ea192 100644 --- a/Doc/Manual/index.html +++ b/Doc/Manual/index.html @@ -1,10 +1,11 @@ - + SWIG-3.0 Documentation + -

      SWIG-3.0 Documentation

      +

      SWIG-3.0 Documentation

      The SWIG documentation is available in one of the following formats.
        diff --git a/Doc/Manual/linkchecker.config b/Doc/Manual/linkchecker.config index a947b278ae2..9317a8940b7 100644 --- a/Doc/Manual/linkchecker.config +++ b/Doc/Manual/linkchecker.config @@ -1,5 +1,3 @@ -[checking] -anchors=1 - [filtering] ignorewarnings=http-robots-denied +ignorewarnings=https-certificate-error diff --git a/Doc/Manual/makechap.py b/Doc/Manual/makechap.py index 8225bfc79ef..61994e2a00e 100644 --- a/Doc/Manual/makechap.py +++ b/Doc/Manual/makechap.py @@ -21,7 +21,7 @@ ############################################################################### # Regexs for -alink = re.compile(r"", re.IGNORECASE) +alink = re.compile(r".*", re.IGNORECASE) heading = re.compile(r"(_nn\d)", re.IGNORECASE) def getheadingname(m): @@ -38,6 +38,19 @@ def getheadingname(m): headingname = "%s_nn%d" % (filenamebase, nameindex) return headingname +# Return heading - 1.1. Introduction in the examples below: +# old style example:

        1.1 Introduction

        +# new style example:

        1.1 Introduction

        +def getheadingtext(m, s): + prevheadingtext_newstyle = m.group(2) + prevheadingtext_oldstyle = m.group(3) + if len(prevheadingtext_oldstyle) == 0 and len(prevheadingtext_newstyle) == 0: + raise RuntimeError("No heading text in line:\n%s" % s) + if len(prevheadingtext_oldstyle) > 0 and len(prevheadingtext_newstyle) > 0: + raise RuntimeError("Two heading texts, only one should be specified in line:\n%s" % s) + prevheadingtext = prevheadingtext_oldstyle if len(prevheadingtext_oldstyle) > 0 else prevheadingtext_newstyle + return prevheadingtext + ############################################################################### # Main program ############################################################################### @@ -59,11 +72,11 @@ def getheadingname(m): # Regexs for

        ,...

        sections -h1 = re.compile(r".*?

        ()*[\d\.\s]*(.*?)

        ", re.IGNORECASE) -h2 = re.compile(r".*?

        ()*[\d\.\s]*(.*?)

        ", re.IGNORECASE) -h3 = re.compile(r".*?

        ()*[\d\.\s]*(.*?)

        ", re.IGNORECASE) -h4 = re.compile(r".*?

        ()*[\d\.\s]*(.*?)

        ", re.IGNORECASE) -h5 = re.compile(r".*?
        ()*[\d\.\s]*(.*?)
        ", re.IGNORECASE) +h1 = re.compile(r".*?

        (\s*[\d\s]*(.*?))*[\d\s]*(.*?)

        ", re.IGNORECASE) +h2 = re.compile(r".*?

        (\s*[\d\.\s]*(.*?))*[\d\.\s]*(.*?)

        ", re.IGNORECASE) +h3 = re.compile(r".*?

        (\s*[\d\.\s]*(.*?))*[\d\.\s]*(.*?)

        ", re.IGNORECASE) +h4 = re.compile(r".*?

        (\s*[\d\.\s]*(.*?))*[\d\.\s]*(.*?)

        ", re.IGNORECASE) +h5 = re.compile(r".*?
        (\s*[\d\.\s]*(.*?))*[\d\.\s]*(.*?)
        ", re.IGNORECASE) data = open(filename).read() # Read data open(filename+".bak","w").write(data) # Make backup @@ -95,10 +108,10 @@ def getheadingname(m): m = h1.match(s) if m: - prevheadingtext = m.group(2) + prevheadingtext = getheadingtext(m, s) nameindex += 1 headingname = getheadingname(m) - result.append("""

        %d %s

        """ % (headingname,num,prevheadingtext)) + result.append("""

        %d %s

        """ % (headingname,num,prevheadingtext)) result.append("@INDEX@") section = 0 subsection = 0 @@ -109,11 +122,11 @@ def getheadingname(m): continue m = h2.match(s) if m: - prevheadingtext = m.group(2) + prevheadingtext = getheadingtext(m, s) nameindex += 1 section += 1 headingname = getheadingname(m) - result.append("""

        %d.%d %s

        """ % (headingname,num,section, prevheadingtext)) + result.append("""

        %d.%d %s

        """ % (headingname,num,section, prevheadingtext)) if subsubsubsection: index += "
      \n" @@ -132,11 +145,11 @@ def getheadingname(m): continue m = h3.match(s) if m: - prevheadingtext = m.group(2) + prevheadingtext = getheadingtext(m, s) nameindex += 1 subsection += 1 headingname = getheadingname(m) - result.append("""

      %d.%d.%d %s

      """ % (headingname,num,section, subsection, prevheadingtext)) + result.append("""

      %d.%d.%d %s

      """ % (headingname,num,section, subsection, prevheadingtext)) if subsubsubsection: index += "
    \n" @@ -151,12 +164,12 @@ def getheadingname(m): continue m = h4.match(s) if m: - prevheadingtext = m.group(2) + prevheadingtext = getheadingtext(m, s) nameindex += 1 subsubsection += 1 headingname = getheadingname(m) - result.append("""

    %d.%d.%d.%d %s

    """ % (headingname,num,section, subsection, subsubsection, prevheadingtext)) + result.append("""

    %d.%d.%d.%d %s

    """ % (headingname,num,section, subsection, subsubsection, prevheadingtext)) if subsubsubsection: index += "\n" @@ -169,11 +182,11 @@ def getheadingname(m): continue m = h5.match(s) if m: - prevheadingtext = m.group(2) + prevheadingtext = getheadingtext(m, s) nameindex += 1 subsubsubsection += 1 headingname = getheadingname(m) - result.append("""
    %d.%d.%d.%d.%d %s
    """ % (headingname,num,section, subsection, subsubsection, subsubsubsection, prevheadingtext)) + result.append("""
    %d.%d.%d.%d.%d %s
    """ % (headingname,num,section, subsection, subsubsection, subsubsubsection, prevheadingtext)) if subsubsubsection == 1: index += "
      \n" diff --git a/Doc/Manual/maketoc.py b/Doc/Manual/maketoc.py index d8c4aa759b1..dc862643475 100644 --- a/Doc/Manual/maketoc.py +++ b/Doc/Manual/maketoc.py @@ -6,12 +6,14 @@ f = open("Contents.html","w") print >>f, """ - + SWIG Users Manual + +

      SWIG Users Manual

      diff --git a/Doc/Manual/margin-left.patch b/Doc/Manual/margin-left.patch deleted file mode 100644 index 8bef6305c32..00000000000 --- a/Doc/Manual/margin-left.patch +++ /dev/null @@ -1,277 +0,0 @@ -# This patch is against htmldoc 1.8.27, and it hacks in support for -# correctly indenting the

      sections in the SWIG manual. -# This patch should only be used until the 1.9 branch of htmldoc -# stabilizes, since the 1.9 branch includes true CSS1 support. -# -# This patch only affects the PDF generation, an unpatched htmldoc -# creates the one-page html documentation just fine. -# -diff -Naur htmldoc-1.8.27/htmldoc/htmldoc.cxx htmldoc-1.8.27-margin-left/htmldoc/htmldoc.cxx ---- htmldoc-1.8.27/htmldoc/htmldoc.cxx 2006-03-30 14:01:20.000000000 +0100 -+++ htmldoc-1.8.27-margin-left/htmldoc/htmldoc.cxx 2013-05-11 10:11:47.428435647 +0100 -@@ -65,6 +65,8 @@ - const char *__XOS2RedirRoot(const char *); - } - #endif -+ -+extern void parse_style(char *); - - - /* -@@ -1115,6 +1117,7 @@ - else if (compare_strings(argv[i], "--version", 6) == 0) - { - puts(SVERSION); -+ puts("Patched with margin-left.patch"); - return (0); - } - else if (compare_strings(argv[i], "--webpage", 3) == 0) -@@ -2403,6 +2406,10 @@ - } - else if (strcmp(temp, "--cookies") == 0) - file_cookies(temp2); -+ else if (strcmp(temp, "--stylesheet") == 0) -+ { -+ parse_style(temp2); -+ } - } - } - -diff -Naur htmldoc-1.8.27/htmldoc/Makefile htmldoc-1.8.27-margin-left/htmldoc/Makefile ---- htmldoc-1.8.27/htmldoc/Makefile 2005-10-28 21:32:59.000000000 +0100 -+++ htmldoc-1.8.27-margin-left/htmldoc/Makefile 2013-05-11 09:39:04.392367869 +0100 -@@ -36,7 +36,7 @@ - OBJS = gui.o file.o html.o htmldoc.o htmllib.o htmlsep.o \ - http.o http-addr.o http-addrlist.o http-support.o image.o \ - iso8859.o license.o md5.o progress.o ps-pdf.o rc4.o \ -- snprintf.o string.o toc.o util.o -+ snprintf.o string.o toc.o util.o style.o - - - # -diff -Naur htmldoc-1.8.27/htmldoc/ps-pdf.cxx htmldoc-1.8.27-margin-left/htmldoc/ps-pdf.cxx ---- htmldoc-1.8.27/htmldoc/ps-pdf.cxx 2006-08-01 17:58:50.000000000 +0100 -+++ htmldoc-1.8.27-margin-left/htmldoc/ps-pdf.cxx 2013-05-11 09:37:40.096364957 +0100 -@@ -160,6 +160,7 @@ - # undef page_t - #endif // __hpux - -+extern int lookup_div_class(uchar *); - - /* - * Output options... -@@ -4230,9 +4231,24 @@ - para->child = para->last_child = NULL; - } - -- parse_doc(t->child, left, right, bottom, top, x, y, page, NULL, -+ { -+ int num_indent = 0; -+ uchar *cname; -+ -+ if (cname = htmlGetVariable(t, (uchar *)"class")) { -+ num_indent = lookup_div_class(cname); -+ *left += 5.0f * num_indent; -+ *x = *left; -+ } -+ -+ parse_doc(t->child, left, right, bottom, top, x, y, page, NULL, - needspace); - -+ if (num_indent > 0) { -+ *left -= 5.0f * num_indent; -+ } -+ } -+ - if (para->child != NULL) - { - parse_paragraph(para, *left, *right, *bottom, *top, x, y, page, *needspace); -diff -Naur htmldoc-1.8.27/htmldoc/style.cxx htmldoc-1.8.27-margin-left/htmldoc/style.cxx ---- htmldoc-1.8.27/htmldoc/style.cxx 1970-01-01 01:00:00.000000000 +0100 -+++ htmldoc-1.8.27-margin-left/htmldoc/style.cxx 2013-05-11 09:37:40.096364957 +0100 -@@ -0,0 +1,185 @@ -+/* Extreamly simple parsing routines for CSS style sheets. -+ * We only parse div.class { } sections, and only look -+ * for margin-left: em; -+ * -+ * Copyright (C) 2005 John Lenz -+ * -+ * Released under GNU GPL v2 or above. -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "types.h" -+ -+#define BUFF_SIZE 512 -+ -+struct div_entry { -+ uchar class_name[BUFF_SIZE]; -+ int indent; -+ struct div_entry *next; -+}; -+ -+static struct div_entry *head = 0; -+ -+/* These are the parsing states */ -+#define IGNORE_TILL_SEMI 0 -+#define IGNORE_TILL_CLOSE_BRACE 1 -+#define READING_DIV 2 -+#define READING_CLASS 3 -+#define READING_ATTRIBUTE 4 -+#define READING_NUM 5 -+#define CHECKING_ONLY_DIV 6 -+ -+static int at_eof = 0; -+ -+static int strucmp(uchar *a, uchar *b) { -+ int i; -+ for (i = 0; a[i] && b[i]; i++) { -+ if (a[i] < b[i]) return -1; -+ if (a[i] > b[i]) return 1; -+ } -+ /* This isn't right, but who cares...*/ -+ if (a[i] || b[i]) return 1; -+ return 0; -+} -+ -+static int read_word(FILE *f, const char *word) { -+ char c; -+ for (int idx = 0; word[idx]; idx++) { -+ c = getc(f); -+ if (c == EOF) { -+ at_eof = 1; -+ return 0; -+ } -+ if (c != word[idx]) -+ return 0; -+ } -+ return 1; -+} -+ -+int lookup_div_class(uchar *name) { -+ struct div_entry *node = head; -+ -+ while (node) { -+ if (strucmp(node->class_name, name) == 0) -+ return node->indent; -+ node = node->next; -+ } -+ -+ return 0; -+} -+ -+void parse_style(char *fname) { -+ FILE *f; -+ char c; -+ int state; -+ struct div_entry *cur = 0; -+ int class_idx = 0; -+ char num[BUFF_SIZE]; -+ int num_idx = 0; -+ -+ if (!fname) return; -+ -+ f = fopen(fname, "r"); -+ if (!f) { -+ fprintf(stderr, "Unable to parse style\n"); -+ return; -+ } -+ -+ state = READING_DIV; -+ while (!at_eof && (c = getc(f)) != EOF) { -+ switch (state) { -+ -+ case IGNORE_TILL_SEMI: -+ if (c == ';') -+ state = READING_ATTRIBUTE; -+ break; -+ -+ case IGNORE_TILL_CLOSE_BRACE: -+ if (c == '}') -+ state = READING_DIV; -+ break; -+ -+ case READING_DIV: -+ if (c != ' ' && c != '\t' && c != '\n') { -+ if (c == 'd' && read_word(f, "iv.")) { -+ state = READING_CLASS; -+ cur = (struct div_entry *) malloc(sizeof(struct div_entry)); -+ memset(cur, 0, sizeof(struct div_entry)); -+ class_idx = 0; -+ } else -+ state = IGNORE_TILL_CLOSE_BRACE; -+ } -+ break; -+ -+ case READING_CLASS: -+ if (isalpha(c)) { -+ if (class_idx >= BUFF_SIZE-1) { -+ fprintf(stderr, "class size %s too long\n", cur->class_name); -+ free(cur); -+ state = IGNORE_TILL_CLOSE_BRACE; -+ } else { -+ cur->class_name[class_idx++] = c; -+ } -+ } else { -+ if (c == '{') { -+ cur->next = head; -+ head = cur; -+ state = READING_ATTRIBUTE; -+ } else -+ state = CHECKING_ONLY_DIV; -+ } -+ break; -+ -+ case READING_ATTRIBUTE: -+ if (c != ' ' && c != '\t' && c != '\n') { -+ if (c == '}') -+ state = READING_DIV; -+ else { -+ if (c == 'm' && read_word(f, "argin-left:")) { -+ num_idx = 0; -+ memset(num, 0, sizeof(num)); -+ state = READING_NUM; -+ } else { -+ state = IGNORE_TILL_SEMI; -+ } -+ } -+ } -+ break; -+ -+ case READING_NUM: -+ if (isdigit(c)) { -+ if (num_idx >= BUFF_SIZE - 1) { -+ fprintf(stderr, "Number too long\n"); -+ state = IGNORE_TILL_SEMI; -+ } else { -+ num[num_idx++] = c; -+ } -+ } else if (c != ' ' && c != '\t') { -+ if (num_idx > 0 && c == 'e' && read_word(f, "m")) -+ cur->indent = atoi(num); -+ state = IGNORE_TILL_SEMI; -+ } -+ break; -+ -+ case CHECKING_ONLY_DIV: -+ if (c != ' ' && c != '\t' && c != '\n') { -+ if (c == '{') { -+ cur->next = head; -+ head = cur; -+ state = READING_ATTRIBUTE; -+ } else { -+ free(cur); -+ state = IGNORE_TILL_CLOSE_BRACE; -+ } -+ } -+ break; -+ } -+ } -+ -+ fclose(f); -+} diff --git a/Doc/Manual/style.css b/Doc/Manual/style.css index 02329e56fce..45e51e35b77 100644 --- a/Doc/Manual/style.css +++ b/Doc/Manual/style.css @@ -32,6 +32,7 @@ div.code { margin-left: 4em; margin-right: 4em; background-color: #F0FFFF; + font-family: "Courier New", Courier, "Courier 10 Pitch", monospace; } div.targetlang { @@ -41,9 +42,9 @@ div.targetlang { margin-left: 4em; margin-right: 4em; background-color: #d7f6bb; + font-family: "Courier New", Courier, "Courier 10 Pitch", monospace; } - div.shell { border-style: solid; border-width: 1px; @@ -51,6 +52,7 @@ div.shell { margin-left: 4em; margin-right: 4em; background-color: #DCDCDC; + font-family: "Courier New", Courier, "Courier 10 Pitch", monospace; } div.diagram { @@ -60,6 +62,7 @@ div.diagram { margin-left: 4em; margin-right: 4em; background-color: #FFEBCD; + font-family: "Courier New", Courier, "Courier 10 Pitch", monospace; } ul li p { @@ -82,3 +85,8 @@ div.indent p { margin-right: 0; } +pre, code, tt { + font-family: "Courier New", Courier, "Courier 10 Pitch", monospace; +} + +body { font-family: serif; } diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 2cb2d6eb564..68a1991cc8a 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -58,7 +58,13 @@ INTERFACE = INTERFACEDIR = INTERFACEPATH = $(SRCDIR)$(INTERFACEDIR)$(INTERFACE) SWIGOPT = -SWIG = swig + +# SWIG_LIB_DIR and SWIGEXE must be explicitly set by Makefiles using this Makefile +SWIG_LIB_DIR = ./Lib +SWIGEXE = swig +SWIG_LIB_SET = @SWIG_LIB_SET@ +SWIGTOOL = +SWIG = $(SWIG_LIB_SET) $(SWIGTOOL) $(SWIGEXE) LIBM = @LIBM@ LIBC = @LIBC@ @@ -133,6 +139,13 @@ distclean: rm -f d/example.mk rm -f xml/Makefile +################################################################## +# Very generic invocation of swig +################################################################## + +swiginvoke: + $(SWIG) $(SWIGOPT) + ################################################################## ##### Tcl/Tk ###### ################################################################## @@ -321,6 +334,9 @@ else SWIGPYTHON = $(SWIG) -python -py3 endif +PEP8 = @PEP8@ +PEP8_FLAGS = --ignore=E402,E501,E30,W291,W391 + # ---------------------------------------------------------------- # Build a C dynamically loadable module # ---------------------------------------------------------------- @@ -373,8 +389,10 @@ endif PY2TO3 = 2to3 `2to3 -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'` python_run: $(PYSCRIPT) - export PYTHONPATH=".:$$PYTHONPATH"; \ - $(RUNTOOL) $(PYTHON) $(PYSCRIPT) $(RUNPIPE) +ifneq (,$(PEP8)) + $(PEP8) $(PEP8_FLAGS) $(PYSCRIPT) +endif + env PYTHONPATH=$$PWD $(RUNTOOL) $(PYTHON) $(PYSCRIPT) $(RUNPIPE) ifneq (,$(SRCDIR)) $(RUNME).py: $(SRCDIR)$(RUNME).py @@ -542,11 +560,10 @@ guile: $(SRCDIR_SRCS) $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) -guile_cpp: $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) -$(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO): $(SRCDIR_SRCS) +guile_cpp: $(SRCDIR_SRCS) $(SWIG) -c++ -guile -Linkage passive $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) - $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) $(CPP_DLLIBS) -o $@ + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) guile_externalhdr: $(SWIG) -guile -external-runtime $(TARGET) @@ -653,7 +670,7 @@ java_cpp: $(SRCDIR_SRCS) # ---------------------------------------------------------------- java_compile: $(SRCDIR_SRCS) - $(COMPILETOOL) $(JAVAC) $(JAVACFLAGS) $(addprefix $(SRCDIR),$(JAVASRCS)) + $(COMPILETOOL) $(JAVAC) $(addprefix $(SRCDIR),$(JAVASRCS)) # ----------------------------------------------------------------- # Run java example @@ -941,7 +958,7 @@ OCAMLFIND=@OCAMLFIND@ OCAMLMKTOP=@OCAMLMKTOP@ $(SWIGWHERE) NOLINK ?= false OCAMLPP= -pp "camlp4o ./swigp4.cmo" -OCAMLP4WHERE=`$(COMPILETOOL) camlp4 -where` +OCAMLP4WHERE=`$(COMPILETOOL) @CAMLP4@ -where` OCAMLCORE=\ rm -rf swig.mli swig.ml swigp4.ml && \ $(SWIG) -ocaml -co swig.mli 2>/dev/null && \ @@ -1136,7 +1153,7 @@ ruby_cpp_static: $(SRCDIR_SRCS) # ----------------------------------------------------------------- ruby_run: - $(RUNTOOL) $(RUBY) -I. $(RUBY_SCRIPT) $(RUNPIPE) + $(RUNTOOL) $(RUBY) $(RUBYFLAGS) -I. $(RUBY_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -1403,6 +1420,8 @@ CSHARPCOMPILER = @CSHARPCOMPILER@ CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@ CSHARPCFLAGS = @CSHARPCFLAGS@ +CSHARPFLAGS = +CSHARPOPTIONS = CSHARPSO = @CSHARPSO@ CSHARP_RUNME = $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) ./$(RUNME).exe @@ -1435,7 +1454,7 @@ SRCDIR_CSHARPSRCS = endif csharp_compile: $(SRCDIR_SRCS) - $(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPSRCS) $(SRCDIR_CSHARPSRCS) + $(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPOPTIONS) $(CSHARPSRCS) $(SRCDIR_CSHARPSRCS) # ----------------------------------------------------------------- # Run CSharp example @@ -1498,6 +1517,12 @@ lua_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS) $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(INCLUDES) $(LUA_INCLUDE) $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(LUA_SO) +lua_externalhdr: + $(SWIG) -lua -external-runtime $(TARGET) + +lua_swig_cpp: + $(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + # ----------------------------------------------------------------- # Build statically linked Lua interpreter # ----------------------------------------------------------------- @@ -1702,7 +1727,7 @@ R = R RCXXSRCS = $(INTERFACE:.i=_wrap.cpp) #Need to use _wrap.cpp for R build system as it does not understand _wrap.cxx RRSRC = $(INTERFACE:.i=.R) R_CFLAGS=-fPIC -R_SCRIPT=$(RUNME).R +R_SCRIPT=$(SRCDIR)$(RUNME).R # need to compile .cxx files outside of R build system to make sure that # we get -fPIC @@ -1722,7 +1747,6 @@ endif # ---------------------------------------------------------------- # Build a R dynamically loadable module (C++) # ---------------------------------------------------------------- - r_cpp: $(SRCDIR_CXXSRCS) $(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) ifneq ($(SRCDIR_CXXSRCS),) @@ -1754,32 +1778,92 @@ r_clean: rm -f *.@OBJEXT@ *@SO@ NAMESPACE rm -f $(RRSRC) $(RUNME).Rout .RData +################################################################## +##### SCILAB ###### +################################################################## + +SCILAB = @SCILAB@ +SCILAB_INC= @SCILABINCLUDE@ +SCILAB_OPT = @SCILABOPT@ +SCILAB_LIBPREFIX = lib + +# ---------------------------------------------------------------- +# Build a C dynamically loadable module +# ---------------------------------------------------------------- + +scilab: + $(SWIG) -scilab $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SCILAB_INC) $(INCLUDES) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR_CSRCS) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(IOBJS) $(OBJS) $(LIBS) -o $(SCILAB_LIBPREFIX)$(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Build a C++ dynamically loadable module +# ---------------------------------------------------------------- + +scilab_cpp: + $(SWIG) -c++ -scilab $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SCILAB_INC) $(INCLUDES) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(IOBJS) $(OBJS) $(LIBS) $(CPP_DLLIBS) -o $(SCILAB_LIBPREFIX)$(TARGET)$(SO) + +# ----------------------------------------------------------------- +# Running a Scilab example +# ----------------------------------------------------------------- + +scilab_run: + env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(SCILAB) $(SCILAB_OPT) -f $(SRCDIR)$(RUNME).sci $(RUNPIPE) + +# ----------------------------------------------------------------- +# Scilab version +# ----------------------------------------------------------------- + +scilab_version: + echo `$(SCILAB) -version | head -1` + +# ----------------------------------------------------------------- +# Cleaning the scilab examples +# ----------------------------------------------------------------- + +scilab_clean: + rm -f *_wrap* *~ .~* + rm -f core @EXTRA_CLEAN@ + rm -f *.@OBJEXT@ *@SO@ + rm -f *.sce + ################################################################## ##### Go ###### ################################################################## +# TODO: The Go make targets need simplifying to use configure time +# configuration or to use Make's ifeq rather than using lots of +# runtime shell code. The output will then be a lot less verbose. + GO = @GO@ GOGCC = @GOGCC@ +GCCGO = @GCCGO@ GO1 = @GO1@ GO12 = @GO12@ GO13 = @GO13@ +GO15 = @GO15@ GOC = @GOC@ GOOPT = @GOOPT@ +GCCGOOPT = @GCCGOOPT@ GOVERSIONOPTION = @GOVERSIONOPTION@ GOSWIGARG = `if $(GOGCC) ; then echo -gccgo; fi` -GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` `if $(GO13) ; then echo -pack ; fi` +GOCOMPILEARG = `if $(GO15); then echo tool compile; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` `if $(GO13) || $(GO15); then echo -pack ; fi` GOSRCS = $(INTERFACE:.i=.go) GOCSRCS = $(INTERFACE:.i=_gc.c) -GOLD = $(GOC:c=l) +GOLD = `if $(GO15); then echo link; else echo $(GOC:c=l); fi` GOTOOL = `if $(GO1) ; then echo go tool; fi` GOPACK = `if $(GO1) ; then echo go tool pack; else echo gopack; fi` -GOPACKAGE = $(INTERFACE:.i=.a) +GOPACKAGE = $(notdir $(INTERFACE:.i=.a)) + +GOPATHDIR = gopath/src/$(INTERFACE:.i=) -GOOBJEXT = $(GOC:c=) +GOOBJEXT = `if $(GO15); then echo o; else echo $(GOC:c=); fi` GOGCOBJS = $(GOSRCS:.go=.$(GOOBJEXT)) GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@) @@ -1787,19 +1871,21 @@ GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@) # Build a Go module (C) # ---------------------------------------------------------------- -go: $(SRCDIR_SRCS) +go_nocgo: $(SRCDIR_SRCS) $(SWIG) -go $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) - if $(GO12) || $(GO13) || $(GOGCC); then \ + if $(GO12) || $(GO13) || $(GO15) || $(GOGCC); then \ $(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \ else \ $(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \ $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \ fi - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) - if ! $(GOGCC) ; then \ + if $(GOGCC) ; then \ + $(COMPILETOOL) $(GCCGO) -g -c -I . $(GOSRCS); \ + else \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS); \ $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \ rm -f $(GOPACKAGE); \ - if $(GO13); then \ + if $(GO13) || $(GO15); then \ cp $(GOGCOBJS) $(GOPACKAGE); \ $(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ elif $(GO12); then \ @@ -1809,12 +1895,54 @@ go: $(SRCDIR_SRCS) fi; \ fi if test -f $(SRCDIR)$(RUNME).go; then \ - $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \ if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \ - elif $(GO12) || $(GO13); then \ + $(COMPILETOOL) $(GCCGO) -g -c $(SRCDIR)$(RUNME).go; \ + $(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \ + elif $(GO12) || $(GO13) || $(GO15); then \ + $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CC)" -extldflags "$(CFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ else \ + $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + fi; \ + fi + +go: $(SRCDIR_SRCS) + $(SWIG) -go -cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + @mkdir gopath 2>/dev/null || true + @mkdir gopath/src 2>/dev/null || true + @mkdir gopath/src/$(INTERFACE:.i=) 2>/dev/null || true + rm -f $(GOPATHDIR)/* + cp $(ISRCS) $(GOPATHDIR)/ + if test -f $(IWRAP:.i=.h); then \ + cp $(IWRAP:.i=.h) $(GOPATHDIR)/; \ + fi + if test -n "$(SRCDIR_SRCS)"; then \ + cp $(SRCDIR_SRCS) $(GOPATHDIR)/; \ + fi + cp $(GOSRCS) $(GOPATHDIR)/ + GOPATH=`pwd`/gopath; \ + export GOPATH; \ + CGO_CPPFLAGS="$(CPPFLAGS) $(INCLUDES) -I `cd $(SRCDIR) && pwd` -I `pwd`"; \ + export CGO_CPPFLAGS; \ + CGO_CFLAGS="$(CFLAGS)"; \ + export CGO_CFLAGS; \ + CGO_LDFLAGS="$(LDFLAGS) -lm"; \ + export CGO_LDFLAGS; \ + (cd $(GOPATHDIR)/ && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o $(GOPACKAGE)) + cp $(GOPATHDIR)/$(GOPACKAGE) $(dir $(INTERFACE))/$(GOPACKAGE) + if $(GOGCC); then \ + cp $(dir $(INTERFACE))/$(GOPACKAGE) $(dir $(INTERFACE))/$(GOPACKAGE:.a=.gox); \ + fi + if test -f $(SRCDIR)$(RUNME).go; then \ + if $(GOGCC) ; then \ + $(COMPILETOOL) $(GCCGO) -c -g $(SRCDIR)$(RUNME).go; \ + $(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(dir $(INTERFACE))/$(GOPACKAGE); \ + elif $(GO12) || $(GO13) || $(GO15); then \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -o $(RUNME).$(GOOBJEXT) $(SRCDIR)$(RUNME).go; \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CC)" -extldflags "$(CFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + else \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ fi; \ fi @@ -1823,19 +1951,29 @@ go: $(SRCDIR_SRCS) # Build a Go module (C++) # ---------------------------------------------------------------- -go_cpp: $(SRCDIR_SRCS) +go_cpp_nocgo: $(SRCDIR_SRCS) $(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - if $(GO12) || $(GO13) || $(GOGCC); then \ - $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ + if $(GO12) || $(GO13) || $(GO15) || $(GOGCC); then \ + if test -n "$(SRCDIR_CXXSRCS)$(SRCDIR_SRCS)"; then \ + $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_CXXSRCS) $(SRCDIR_SRCS) $(INCLUDES); \ + fi; \ + $(foreach f,$(ICXXSRCS), \ + $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) -o $(addsuffix .@OBJEXT@,$(basename $f)) $f $(INCLUDES); \ + ) \ else \ $(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES); \ $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \ fi - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) if ! $(GOGCC) ; then \ - $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \ + $(foreach f,$(GOSRCS), \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . -o $(addsuffix .$(GOOBJEXT),$(basename $f)) $f \ + ); \ + $(foreach f,$(GOCSRCS), \ + $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} \ + -o $(addsuffix .$(GOOBJEXT),$(basename $f)) $f; \ + ) \ rm -f $(GOPACKAGE); \ - if $(GO13); then \ + if $(GO13) || $(GO15); then \ cp $(GOGCOBJS) $(GOPACKAGE); \ $(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ elif $(GO12); then \ @@ -1843,14 +1981,65 @@ go_cpp: $(SRCDIR_SRCS) else \ $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ fi; \ + else \ + $(foreach f,$(GOSRCS), \ + $(COMPILETOOL) $(GCCGO) -g -c -I . -o $(addsuffix .@OBJEXT@,$(basename $f)) $f \ + ); \ + fi + if test -f $(SRCDIR)$(RUNME).go; then \ + if $(GOGCC) ; then \ + $(COMPILETOOL) $(GCCGO) -g -c $(SRCDIR)$(RUNME).go; \ + $(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \ + elif $(GO12) || $(GO13) || $(GO15); then \ + $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CXX)" -extldflags "$(CXXFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + else \ + $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + fi; \ + fi + +go_cpp: $(SRCDIR_SRCS) + $(SWIG) -go -c++ -cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + @mkdir gopath 2>/dev/null || true + @mkdir gopath/src 2>/dev/null || true + @mkdir gopath/src/$(INTERFACE:.i=) 2>/dev/null || true + rm -f $(GOPATHDIR)/* + cp $(ICXXSRCS) $(GOPATHDIR)/ + if test -f $(IWRAP:.i=.h); then \ + cp $(IWRAP:.i=.h) $(GOPATHDIR)/; \ + fi + if test -n "$(SRCDIR_CXXSRCS)"; then \ + cp $(SRCDIR_CXXSRCS) $(GOPATHDIR)/; \ + fi + if test -n "$(SRCDIR_SRCS)"; then \ + cp $(SRCDIR_SRCS) $(GOPATHDIR)/; \ + fi + cp $(GOSRCS) $(GOPATHDIR)/ + GOPATH=`pwd`/gopath; \ + export GOPATH; \ + CGO_CPPFLAGS="$(CPPFLAGS) $(INCLUDES) -I `cd $(SRCDIR) && pwd` -I `pwd`"; \ + export CGO_CPPFLAGS; \ + CGO_CFLAGS="$(CFLAGS)"; \ + export CGO_CFLAGS; \ + CGO_CXXFLAGS="$(CXXFLAGS)"; \ + export CGO_CXXFLAGS; \ + CGO_LDFLAGS="$(LDFLAGS) -lm"; \ + export CGO_LDFLAGS; \ + (cd $(GOPATHDIR) && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o $(GOPACKAGE)) + cp $(GOPATHDIR)/$(GOPACKAGE) $(dir $(INTERFACE))/$(GOPACKAGE) + if $(GOGCC); then \ + cp $(dir $(INTERFACE))/$(GOPACKAGE) $(dir $(INTERFACE))/$(GOPACKAGE:.a=.gox); \ fi if test -f $(SRCDIR)$(RUNME).go; then \ - $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \ if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \ - elif $(GO12) || $(GO13); then \ + $(COMPILETOOL) $(GCCGO) -g -c $(SRCDIR)$(RUNME).go; \ + $(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(dir $(INTERFACE))/$(GOPACKAGE) -lstdc++; \ + elif $(GO12) || $(GO13) || $(GO15); then \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -o $(RUNME).$(GOOBJEXT) $(SRCDIR)$(RUNME).go; \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CXX)" -extldflags "$(CXXFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ else \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ fi; \ fi @@ -1860,7 +2049,7 @@ go_cpp: $(SRCDIR_SRCS) # ----------------------------------------------------------------- go_run: - env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) ./$(RUNME) $(RUNPIPE) + env $(RUNTOOL) ./$(RUNME) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -1874,7 +2063,8 @@ go_version: # ----------------------------------------------------------------- go_clean: - rm -f *_wrap* *_gc* .~* $(RUNME) $(GOSRCS) + rm -f *_wrap* *_gc* *.gox .~* $(RUNME) $(GOSRCS) + rm -rf gopath rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *.[568] *.a *@SO@ diff --git a/Examples/android/class/Makefile b/Examples/android/class/Makefile index 574566623d6..8b5a090e956 100644 --- a/Examples/android/class/Makefile +++ b/Examples/android/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = example INTERFACE = example.i INTERFACEDIR = jni/ @@ -13,8 +14,9 @@ TARGETID = 1 check: build build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android_cpp install: diff --git a/Examples/android/extend/Makefile b/Examples/android/extend/Makefile index fb974d22ccd..19d90eccafe 100644 --- a/Examples/android/extend/Makefile +++ b/Examples/android/extend/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = example INTERFACE = example.i INTERFACEDIR = jni/ @@ -13,8 +14,9 @@ TARGETID = 1 check: build build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android_cpp install: diff --git a/Examples/android/simple/Makefile b/Examples/android/simple/Makefile index 2bf41968a8d..46bcd93ca61 100644 --- a/Examples/android/simple/Makefile +++ b/Examples/android/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = example INTERFACE = example.i INTERFACEDIR = jni/ @@ -13,8 +14,9 @@ TARGETID = 1 check: build build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android install: diff --git a/Examples/chicken/class/Makefile b/Examples/chicken/class/Makefile index a37ea4a8550..ea2d8b62edf 100644 --- a/Examples/chicken/class/Makefile +++ b/Examples/chicken/class/Makefile @@ -1,17 +1,18 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -INTERFACE = example.i -SRCS = -CXXSRCS = example.cxx -TARGET = class -INCLUDE = -SWIGOPT = -VARIANT = +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +INTERFACE = example.i +SRCS = +CXXSRCS = example.cxx +TARGET = class +INCLUDE = +SWIGOPT = +VARIANT = # uncomment the following lines to build a static exe (only pick one of the CHICKEN_MAIN lines) #CHICKEN_MAIN = runme-lowlevel.scm #CHICKEN_MAIN = runme-tinyclos.scm -#VARIANT = _static +#VARIANT = _static check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CHICKEN_SCRIPT='runme-lowlevel.scm' chicken_run @@ -22,14 +23,16 @@ build: $(TARGET) $(TARGET)_proxy $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp + INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp $(TARGET)_proxy: $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT) -proxy' TARGET='$(TARGET)_proxy' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp + INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean diff --git a/Examples/chicken/constants/Makefile b/Examples/chicken/constants/Makefile index 7167e866bd3..2fdde0a58a9 100644 --- a/Examples/chicken/constants/Makefile +++ b/Examples/chicken/constants/Makefile @@ -1,12 +1,13 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -INTERFACE = example.i -SRCS = -CXXSRCS = -TARGET = constants -INCLUDE = -SWIGOPT = -VARIANT = +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +INTERFACE = example.i +SRCS = +CXXSRCS = +TARGET = constants +INCLUDE = +SWIGOPT = +VARIANT = # uncomment the following two lines to build a static exe #CHICKEN_MAIN = runme.scm @@ -20,8 +21,9 @@ build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) + INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean diff --git a/Examples/chicken/egg/Makefile b/Examples/chicken/egg/Makefile index 55aa114ebb1..0137dc0a74f 100644 --- a/Examples/chicken/egg/Makefile +++ b/Examples/chicken/egg/Makefile @@ -1,4 +1,6 @@ -SWIG = ../../../preinst-swig +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib check: build cd eggs/install && csi ../../test.scm @@ -14,7 +16,7 @@ single: single_wrap.cxx # compile the single module with -nounit single_wrap.cxx: single.i - $(SWIG) -chicken -c++ -proxy -nounit single.i + $(SWIGEXE) -chicken -c++ -proxy -nounit single.i # Now build both mod1 and mod2 into a single egg multi: mod1_wrap.cxx mod2_wrap.cxx @@ -23,10 +25,10 @@ multi: mod1_wrap.cxx mod2_wrap.cxx rm -f mod1.scm mod1_wrap.cxx mod2.scm mod2_wrap.cxx mod1_wrap.cxx: mod1.i - $(SWIG) -chicken -c++ -proxy mod1.i + $(SWIGEXE) -chicken -c++ -proxy mod1.i mod2_wrap.cxx: mod2.i - $(SWIG) -chicken -c++ -proxy mod2.i + $(SWIGEXE) -chicken -c++ -proxy mod2.i clean: rm -rf eggs diff --git a/Examples/chicken/multimap/Makefile b/Examples/chicken/multimap/Makefile index e8192e9cda0..551d1c74d0a 100644 --- a/Examples/chicken/multimap/Makefile +++ b/Examples/chicken/multimap/Makefile @@ -1,16 +1,17 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -INTERFACE = example.i -SRCS = example.c -CXXSRCS = -TARGET = multimap -INCLUDE = -SWIGOPT = -VARIANT = +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +INTERFACE = example.i +SRCS = example.c +CXXSRCS = +TARGET = multimap +INCLUDE = +SWIGOPT = +VARIANT = # uncomment the following two lines to build a static exe #CHICKEN_MAIN = runme.scm -#VARIANT = _static +#VARIANT = _static check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_run @@ -20,8 +21,9 @@ build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) + INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean diff --git a/Examples/chicken/overload/Makefile b/Examples/chicken/overload/Makefile index a9647d93e55..019390192c3 100644 --- a/Examples/chicken/overload/Makefile +++ b/Examples/chicken/overload/Makefile @@ -1,16 +1,17 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -INTERFACE = example.i -SRCS = -CXXSRCS = example.cxx -TARGET = overload -INCLUDE = -SWIGOPT = -proxy -unhideprimitive -VARIANT = +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +INTERFACE = example.i +SRCS = +CXXSRCS = example.cxx +TARGET = overload +INCLUDE = +SWIGOPT = -proxy -unhideprimitive +VARIANT = # uncomment the following lines to build a static exe #CHICKEN_MAIN = runme.scm -#VARIANT = _static +#VARIANT = _static check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_run @@ -20,8 +21,9 @@ build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp + INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean diff --git a/Examples/chicken/simple/Makefile b/Examples/chicken/simple/Makefile index c07075efae2..f5dd1a9669a 100644 --- a/Examples/chicken/simple/Makefile +++ b/Examples/chicken/simple/Makefile @@ -1,16 +1,17 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -INTERFACE = example.i -SRCS = example.c -CXXSRCS = -TARGET = simple -INCLUDE = -SWIGOPT = -VARIANT = +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +INTERFACE = example.i +SRCS = example.c +CXXSRCS = +TARGET = simple +INCLUDE = +SWIGOPT = +VARIANT = # uncomment the following two lines to build a static exe #CHICKEN_MAIN = runme.scm -#VARIANT = _static +#VARIANT = _static check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_run @@ -20,8 +21,9 @@ build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ - SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) + INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean diff --git a/Examples/csharp/arrays/Makefile b/Examples/csharp/arrays/Makefile index e5d733d356f..66b2c2171e0 100644 --- a/Examples/csharp/arrays/Makefile +++ b/Examples/csharp/arrays/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/callback/Makefile b/Examples/csharp/callback/Makefile index 4f4c84b9a34..c7f264ecc3b 100644 --- a/Examples/csharp/callback/Makefile +++ b/Examples/csharp/callback/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/callback/example.i b/Examples/csharp/callback/example.i index 90beda01af1..cf61ef9d2f8 100644 --- a/Examples/csharp/callback/example.i +++ b/Examples/csharp/callback/example.i @@ -4,8 +4,6 @@ #include "example.h" %} -%include "std_string.i" - /* turn on director wrapping Callback */ %feature("director") Callback; diff --git a/Examples/csharp/class/Makefile b/Examples/csharp/class/Makefile index 4f4c84b9a34..c7f264ecc3b 100644 --- a/Examples/csharp/class/Makefile +++ b/Examples/csharp/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/enum/Makefile b/Examples/csharp/enum/Makefile index 4f4c84b9a34..c7f264ecc3b 100644 --- a/Examples/csharp/enum/Makefile +++ b/Examples/csharp/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/extend/Makefile b/Examples/csharp/extend/Makefile index 4f4c84b9a34..c7f264ecc3b 100644 --- a/Examples/csharp/extend/Makefile +++ b/Examples/csharp/extend/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/funcptr/Makefile b/Examples/csharp/funcptr/Makefile index 99cdfa38a91..9af1d66ff12 100644 --- a/Examples/csharp/funcptr/Makefile +++ b/Examples/csharp/funcptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/nested/Makefile b/Examples/csharp/nested/Makefile index 4f4c84b9a34..c7f264ecc3b 100644 --- a/Examples/csharp/nested/Makefile +++ b/Examples/csharp/nested/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/reference/Makefile b/Examples/csharp/reference/Makefile index 4f4c84b9a34..c7f264ecc3b 100644 --- a/Examples/csharp/reference/Makefile +++ b/Examples/csharp/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/simple/Makefile b/Examples/csharp/simple/Makefile index 99cdfa38a91..9af1d66ff12 100644 --- a/Examples/csharp/simple/Makefile +++ b/Examples/csharp/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/template/Makefile b/Examples/csharp/template/Makefile index 2d0e070094c..010447fe287 100644 --- a/Examples/csharp/template/Makefile +++ b/Examples/csharp/template/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/csharp/variables/Makefile b/Examples/csharp/variables/Makefile index 99cdfa38a91..9af1d66ff12 100644 --- a/Examples/csharp/variables/Makefile +++ b/Examples/csharp/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile diff --git a/Examples/d/callback/example.i b/Examples/d/callback/example.i index 90beda01af1..cf61ef9d2f8 100644 --- a/Examples/d/callback/example.i +++ b/Examples/d/callback/example.i @@ -4,8 +4,6 @@ #include "example.h" %} -%include "std_string.i" - /* turn on director wrapping Callback */ %feature("director") Callback; diff --git a/Examples/d/example.mk.in b/Examples/d/example.mk.in index a1d9a85fce4..84b3ceb0921 100644 --- a/Examples/d/example.mk.in +++ b/Examples/d/example.mk.in @@ -23,7 +23,8 @@ endif EXAMPLES_TOP = ../../.. SWIG_TOP = ../../../.. -SWIG = $(SWIG_TOP)/preinst-swig +SWIGEXE = $(SWIG_TOP)/swig +SWIG_LIB_DIR = $(SWIG_TOP)/$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib EXTRA_CFLAGS = EXTRA_CXXFLAGS = EXTRA_LDFLAGS = @@ -44,11 +45,17 @@ check: build build: mkdir -p $(VERSION_DIR) if [ -f $(SRCDIR)example.cxx ]; then \ - $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CXXFLAGS='$(EXTRA_CXXFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' CXXSRCS='example.cxx' d_cpp; \ + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CXXFLAGS='$(EXTRA_CXXFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' CXXSRCS='example.cxx' d_cpp; \ elif [ -f $(SRCDIR)example.c ]; then \ - $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' SRCS='example.c' d; \ + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' SRCS='example.c' d; \ else \ - $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' SRCS='' d; \ + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' SRCS='' d; \ fi $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile diff --git a/Examples/go/callback/Makefile b/Examples/go/callback/Makefile index bf5275f14df..86047367c76 100644 --- a/Examples/go/callback/Makefile +++ b/Examples/go/callback/Makefile @@ -1,6 +1,8 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = callback.cxx +GOSRCS = gocallback.go TARGET = example INTERFACE = example.i SWIGOPT = @@ -9,8 +11,16 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + if [ -n '$(SRCDIR)' ]; then \ + cp $(GOSRCS:%=$(SRCDIR)/%) .; \ + fi + @# Note: example.go gets generated by SWIG + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' GOSRCS='example.go $(GOSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: + if [ -n '$(SRCDIR)' ]; then \ + rm -f $(GOSRCS); \ + fi $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/callback/example.h b/Examples/go/callback/example.h index 1a0e8c4322a..74ddad954a3 100644 --- a/Examples/go/callback/example.h +++ b/Examples/go/callback/example.h @@ -20,4 +20,3 @@ class Caller { void setCallback(Callback *cb) { delCallback(); _callback = cb; } void call() { if (_callback) _callback->run(); } }; - diff --git a/Examples/go/callback/example.i b/Examples/go/callback/example.i index 90beda01af1..cf61ef9d2f8 100644 --- a/Examples/go/callback/example.i +++ b/Examples/go/callback/example.i @@ -4,8 +4,6 @@ #include "example.h" %} -%include "std_string.i" - /* turn on director wrapping Callback */ %feature("director") Callback; diff --git a/Examples/go/callback/gocallback.go b/Examples/go/callback/gocallback.go new file mode 100644 index 00000000000..20fd0627a2b --- /dev/null +++ b/Examples/go/callback/gocallback.go @@ -0,0 +1,41 @@ +package example + +import ( + "fmt" +) + +type GoCallback interface { + Callback + deleteCallback() + IsGoCallback() +} + +type goCallback struct { + Callback +} + +func (p *goCallback) deleteCallback() { + DeleteDirectorCallback(p.Callback) +} + +func (p *goCallback) IsGoCallback() {} + +type overwrittenMethodsOnCallback struct { + p Callback +} + +func NewGoCallback() GoCallback { + om := &overwrittenMethodsOnCallback{} + p := NewDirectorCallback(om) + om.p = p + + return &goCallback{Callback: p} +} + +func DeleteGoCallback(p GoCallback) { + p.deleteCallback() +} + +func (p *goCallback) Run() { + fmt.Println("GoCallback.Run") +} diff --git a/Examples/go/callback/index.html b/Examples/go/callback/index.html index b053cf54707..9a53065b0e0 100644 --- a/Examples/go/callback/index.html +++ b/Examples/go/callback/index.html @@ -12,67 +12,17 @@

      Implementing C++ callbacks in Go

      -This example illustrates how to use directors to implement C++ -callbacks in Go. -

      - -

      -Because Go and C++ use inheritance differently, you must call a -different function to create a class which uses callbacks. Instead of -calling the usual constructor function whose name is New -followed by the capitalized name of the class, you call a function -named NewDirector followed by the capitalized name of the -class. -

      - -

      -The first argument to the NewDirector function is an instance -of a type. The NewDirector function will return an interface -value as usual. However, when calling any method on the returned -value, the program will first check whether the value passed -to NewDirector implements that method. If it does, the -method will be called in Go. This is true whether the method is -called from Go code or C++ code. -

      - -

      -Note that the Go code will be called with just the Go value, not the -C++ value. If the Go code needs to call a C++ method on itself, you -need to get a copy of the C++ object. This is typically done as -follows: - -

      -
      -type Child struct { abi Parent }
      -func (p *Child) ChildMethod() {
      -	p.abi.ParentMethod()
      -}
      -func f() {
      -	p := &Child{nil}
      -	d := NewDirectorParent(p)
      -	p.abi = d
      -	...
      -}
      -
      -
      - -In other words, we first create the Go value. We pass that to -the NewDirector function to create the C++ value; this C++ -value will be created with an association to the Go value. We then -store the C++ value in the Go value, giving us the reverse -association. That permits us to call parent methods from the child. - -

      - -

      -To delete a director object, use the function DeleteDirector -followed by the capitalized name of the class. +This example illustrates how to use directors to implement C++ callbacks in Go. +See the Go Director +Classes documentation subsection for an in-depth explanation how to use the +director feature.

      diff --git a/Examples/go/callback/runme.go b/Examples/go/callback/runme.go index 2eef77fdbe0..03ab0c5e259 100644 --- a/Examples/go/callback/runme.go +++ b/Examples/go/callback/runme.go @@ -16,26 +16,18 @@ func main() { caller.Call() caller.DelCallback() - callback = NewDirectorCallback(new(GoCallback)) + go_callback := NewGoCallback() fmt.Println() fmt.Println("Adding and calling a Go callback") - fmt.Println("------------------------------------") + fmt.Println("--------------------------------") - caller.SetCallback(callback) + caller.SetCallback(go_callback) caller.Call() caller.DelCallback() - // Test that a double delete does not occur as the object has - // already been deleted from the C++ layer. - DeleteDirectorCallback(callback) + DeleteGoCallback(go_callback) fmt.Println() fmt.Println("Go exit") } - -type GoCallback struct{} - -func (p *GoCallback) Run() { - fmt.Println("GoCallback.Run") -} diff --git a/Examples/go/check.list b/Examples/go/check.list index 5399b89794c..b3f34b30639 100644 --- a/Examples/go/check.list +++ b/Examples/go/check.list @@ -2,6 +2,7 @@ callback class constants +director enum extend funcptr diff --git a/Examples/go/class/Makefile b/Examples/go/class/Makefile index de067cdd8af..f72c067e617 100644 --- a/Examples/go/class/Makefile +++ b/Examples/go/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = class.cxx TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: diff --git a/Examples/go/constants/Makefile b/Examples/go/constants/Makefile index 8fb07fd6bea..b791fc9cfb3 100644 --- a/Examples/go/constants/Makefile +++ b/Examples/go/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: diff --git a/Examples/go/director/Makefile b/Examples/go/director/Makefile new file mode 100644 index 00000000000..430cac8341a --- /dev/null +++ b/Examples/go/director/Makefile @@ -0,0 +1,26 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +CXXSRCS = +GOSRCS = director.go +TARGET = example +INTERFACE = example.i +SWIGOPT = + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + +build: + if [ -n '$(SRCDIR)' ]; then \ + cp $(GOSRCS:%=$(SRCDIR)/%) .; \ + fi + @# Note: example.go gets generated by SWIG + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' GOSRCS='example.go $(GOSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp + +clean: + if [ -n '$(SRCDIR)' ]; then \ + rm -f $(GOSRCS); \ + fi + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/director/director.go b/Examples/go/director/director.go new file mode 100644 index 00000000000..4f99bfc6d47 --- /dev/null +++ b/Examples/go/director/director.go @@ -0,0 +1,72 @@ +package example + +// FooBarGo is a superset of FooBarAbstract and hence FooBarGo can be used as a +// drop in replacement for FooBarAbstract but the reverse causes a compile time +// error. +type FooBarGo interface { + FooBarAbstract + deleteFooBarAbstract() + IsFooBarGo() +} + +// Via embedding fooBarGo "inherits" all methods of FooBarAbstract. +type fooBarGo struct { + FooBarAbstract +} + +func (fbgs *fooBarGo) deleteFooBarAbstract() { + DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract) +} + +// The IsFooBarGo method ensures that FooBarGo is a superset of FooBarAbstract. +// This is also how the class hierarchy gets represented by the SWIG generated +// wrapper code. For an instance FooBarCpp has the IsFooBarAbstract and +// IsFooBarCpp methods. +func (fbgs *fooBarGo) IsFooBarGo() {} + +// Go type that defines the DirectorInterface. It contains the Foo and Bar +// methods that overwrite the respective virtual C++ methods on FooBarAbstract. +type overwrittenMethodsOnFooBarAbstract struct { + // Backlink to FooBarAbstract so that the rest of the class can be used by + // the overridden methods. + fb FooBarAbstract + + // If additional constructor arguments have been given they are typically + // stored here so that the overriden methods can use them. +} + +func (om *overwrittenMethodsOnFooBarAbstract) Foo() string { + // DirectorFooBarAbstractFoo calls the base method FooBarAbstract::Foo. + return "Go " + DirectorFooBarAbstractFoo(om.fb) +} + +func (om *overwrittenMethodsOnFooBarAbstract) Bar() string { + return "Go Bar" +} + +func NewFooBarGo() FooBarGo { + // Instantiate FooBarAbstract with selected methods overridden. The methods + // that will be overwritten are defined on + // overwrittenMethodsOnFooBarAbstract and have a compatible signature to the + // respective virtual C++ methods. Furthermore additional constructor + // arguments will be typically stored in the + // overwrittenMethodsOnFooBarAbstract struct. + om := &overwrittenMethodsOnFooBarAbstract{} + fb := NewDirectorFooBarAbstract(om) + om.fb = fb // Backlink causes cycle as fb.v = om! + + fbgs := &fooBarGo{FooBarAbstract: fb} + // The memory of the FooBarAbstract director object instance can be + // automatically freed once the FooBarGo instance is garbage collected by + // uncommenting the following line. Please make sure to understand the + // runtime.SetFinalizer specific gotchas before doing this. Furthemore + // DeleteFooBarGo should be deleted if a finalizer is in use or the fooBarGo + // struct needs additional data to prevent double deletion. + // runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract) + return fbgs +} + +// Recommended to be removed if runtime.SetFinalizer is in use. +func DeleteFooBarGo(fbg FooBarGo) { + fbg.deleteFooBarAbstract() +} diff --git a/Examples/go/director/director.h b/Examples/go/director/director.h new file mode 100644 index 00000000000..339a9adcd61 --- /dev/null +++ b/Examples/go/director/director.h @@ -0,0 +1,41 @@ +#ifndef DIRECTOR_H +#define DIRECTOR_H + + +#include +#include + + +class FooBarAbstract +{ +public: + FooBarAbstract() {}; + virtual ~FooBarAbstract() {}; + + std::string FooBar() { + return this->Foo() + ", " + this->Bar(); + }; + +protected: + virtual std::string Foo() { + return "Foo"; + }; + + virtual std::string Bar() = 0; +}; + + +class FooBarCpp : public FooBarAbstract +{ +protected: + virtual std::string Foo() { + return "C++ " + FooBarAbstract::Foo(); + } + + virtual std::string Bar() { + return "C++ Bar"; + } +}; + + +#endif diff --git a/Examples/go/director/example.i b/Examples/go/director/example.i new file mode 100644 index 00000000000..e832bd8c6f7 --- /dev/null +++ b/Examples/go/director/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module(directors="1") example + +%include "std_string.i" + +%header %{ +#include "director.h" +%} + +%feature("director") FooBarAbstract; +%include "director.h" diff --git a/Examples/go/director/index.html b/Examples/go/director/index.html new file mode 100644 index 00000000000..b93e780e515 --- /dev/null +++ b/Examples/go/director/index.html @@ -0,0 +1,28 @@ + + +SWIG:Examples:go:director + + + + +SWIG/Examples/go/director/ +
      + +

      How to subclass a C++ class with a Go type

      + +

      +See the Go Director +Classes documentation subsection for an explanation of this example. +

      + +

      +

        +
      • director.go. Go source with the definition of the FooBarGo class. +
      • director.h. Header with the definition of the FooBarAbstract and FooBarCpp classes. +
      • example.i. SWIG interface file. +
      • runme.go. Sample Go program. +
      + +
      + + diff --git a/Examples/go/director/runme.go b/Examples/go/director/runme.go new file mode 100644 index 00000000000..0d839bc8808 --- /dev/null +++ b/Examples/go/director/runme.go @@ -0,0 +1,39 @@ +package main + +import ( + "./example" + "fmt" + "os" +) + +func Compare(name string, got string, exp string) error { + fmt.Printf("%s; Got: '%s'; Expected: '%s'\n", name, got, exp) + if got != exp { + return fmt.Errorf("%s returned unexpected string! Got: '%s'; Expected: '%s'\n", name, got, exp) + } + return nil +} + +func TestFooBarCpp() error { + fb := example.NewFooBarCpp() + defer example.DeleteFooBarCpp(fb) + return Compare("FooBarCpp.FooBar()", fb.FooBar(), "C++ Foo, C++ Bar") +} + +func TestFooBarGo() error { + fb := example.NewFooBarGo() + defer example.DeleteFooBarGo(fb) + return Compare("FooBarGo.FooBar()", fb.FooBar(), "Go Foo, Go Bar") +} + +func main() { + fmt.Println("Test output:") + fmt.Println("------------") + err := TestFooBarCpp() + err = TestFooBarGo() + fmt.Println("------------") + if err != nil { + fmt.Fprintf(os.Stderr, "Tests failed! Last error: %s\n", err.Error()) + os.Exit(1) + } +} diff --git a/Examples/go/enum/Makefile b/Examples/go/enum/Makefile index 2e2f1b2bd87..15defe9052a 100644 --- a/Examples/go/enum/Makefile +++ b/Examples/go/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = enum.cxx TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: diff --git a/Examples/go/extend/Makefile b/Examples/go/extend/Makefile index 290694210c8..a3c520e7288 100644 --- a/Examples/go/extend/Makefile +++ b/Examples/go/extend/Makefile @@ -1,6 +1,8 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = extend.cxx +GOSRCS = ceo.go TARGET = example INTERFACE = example.i SWIGOPT = @@ -9,8 +11,16 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + if [ -n '$(SRCDIR)' ]; then \ + cp $(GOSRCS:%=$(SRCDIR)/%) .; \ + fi + @# Note: example.go gets generated by SWIG + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' GOSRCS='example.go $(GOSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: + if [ -n '$(SRCDIR)' ]; then \ + rm -f $(GOSRCS); \ + fi $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/extend/ceo.go b/Examples/go/extend/ceo.go new file mode 100644 index 00000000000..8f00c92f284 --- /dev/null +++ b/Examples/go/extend/ceo.go @@ -0,0 +1,37 @@ +package example + +type CEO interface { + Manager + deleteManager() + IsCEO() +} + +type ceo struct { + Manager +} + +func (p *ceo) deleteManager() { + DeleteDirectorManager(p.Manager) +} + +func (p *ceo) IsCEO() {} + +type overwrittenMethodsOnManager struct { + p Manager +} + +func NewCEO(name string) CEO { + om := &overwrittenMethodsOnManager{} + p := NewDirectorManager(om, name) + om.p = p + + return &ceo{Manager: p} +} + +func DeleteCEO(p CEO) { + p.deleteManager() +} + +func (p *ceo) GetPosition() string { + return "CEO" +} diff --git a/Examples/go/extend/example.h b/Examples/go/extend/example.h index ca1aed28f70..0c3b721bd21 100644 --- a/Examples/go/extend/example.h +++ b/Examples/go/extend/example.h @@ -44,7 +44,7 @@ class EmployeeList { const Employee *get_item(int i) { return list[i]; } - ~EmployeeList() { + ~EmployeeList() { std::vector::iterator i; std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; for (i=list.begin(); i!=list.end(); i++) { diff --git a/Examples/go/extend/index.html b/Examples/go/extend/index.html index 471fa9cdc35..31788b2aa52 100644 --- a/Examples/go/extend/index.html +++ b/Examples/go/extend/index.html @@ -12,13 +12,16 @@

      Extending a simple C++ class in Go

      -This example illustrates the extending of a C++ class with cross -language polymorphism. - +This example illustrates how to inherit from a C++ class in Go. +See the Go Director +Classes documentation subsection for an in-depth explanation how to use the +director feature.

      +

        -
      • example.h. Header file containing some enums. -
      • example.i. Interface file. +
      • ceo.go. Go source with the definition of the CEO class. +
      • example.h. Header with the definition of the Employee, Manager and EmployeeList classes. +
      • example.i. SWIG interface file.
      • runme.go. Sample Go program.
      diff --git a/Examples/go/extend/runme.go b/Examples/go/extend/runme.go index 770e2780275..a569689375c 100644 --- a/Examples/go/extend/runme.go +++ b/Examples/go/extend/runme.go @@ -7,19 +7,12 @@ import ( "fmt" ) -type CEO struct{} - -func (p *CEO) GetPosition() string { - return "CEO" -} - func main() { // Create an instance of CEO, a class derived from the Go // proxy of the underlying C++ class. The calls to getName() // and getPosition() are standard, the call to getTitle() uses // the director wrappers to call CEO.getPosition(). - - e := NewDirectorManager(new(CEO), "Alice") + e := NewCEO("Alice") fmt.Println(e.GetName(), " is a ", e.GetPosition()) fmt.Println("Just call her \"", e.GetTitle(), "\"") fmt.Println("----------------------") @@ -27,7 +20,6 @@ func main() { // Create a new EmployeeList instance. This class does not // have a C++ director wrapper, but can be used freely with // other classes that do. - list := NewEmployeeList() // EmployeeList owns its items, so we must surrender ownership @@ -49,15 +41,13 @@ func main() { // CEO, but now Go thinks the object is an instance of class // Employee. So the call passes through the Employee proxy // class and on to the C wrappers and C++ director, eventually - // ending up back at the Java CEO implementation of + // ending up back at the Go CEO implementation of // getPosition(). The call to GetTitle() for item 3 runs the // C++ Employee::getTitle() method, which in turn calls // GetPosition(). This virtual method call passes down - // through the C++ director class to the Java implementation + // through the C++ director class to the Go implementation // in CEO. All this routing takes place transparently. - fmt.Println("(position, title) for items 0-3:") - fmt.Println(" ", list.Get_item(0).GetPosition(), ", \"", list.Get_item(0).GetTitle(), "\"") fmt.Println(" ", list.Get_item(1).GetPosition(), ", \"", list.Get_item(1).GetTitle(), "\"") fmt.Println(" ", list.Get_item(2).GetPosition(), ", \"", list.Get_item(2).GetTitle(), "\"") @@ -66,11 +56,11 @@ func main() { // Time to delete the EmployeeList, which will delete all the // Employee* items it contains. The last item is our CEO, - // which gets destroyed as well. + // which gets destroyed as well and hence there is no need to + // call DeleteCEO. DeleteEmployeeList(list) fmt.Println("----------------------") // All done. - fmt.Println("Go exit") } diff --git a/Examples/go/funcptr/Makefile b/Examples/go/funcptr/Makefile index 82031c9d595..efeb6e86070 100644 --- a/Examples/go/funcptr/Makefile +++ b/Examples/go/funcptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = funcptr.c TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: diff --git a/Examples/go/index.html b/Examples/go/index.html index 21dda21b5e5..467f4ecb7e2 100644 --- a/Examples/go/index.html +++ b/Examples/go/index.html @@ -23,6 +23,7 @@

      SWIG Go Examples

    • template. C++ templates.
    • callback. C++ callbacks using directors.
    • extend. Polymorphism using directors. +
    • director. Example how to utilize the director feature.

    Compilation Issues

    @@ -37,20 +38,23 @@

    Compilation Issues

  • On Unix the compilation of examples is done using the -file Example/Makefile. This makefile performs a manual -module compilation which is platform specific. When using -the 6g or 8g compiler, the steps look like this +file Example/Makefile. Normally builds are done simply +using go build. For testing purposes this makefile performs +a manual module compilation that is platform specific. When using +the gc compiler, the steps look approximately like this (GNU/Linux):
    -% swig -go interface.i
    -% gcc -fpic -c interface_wrap.c
    -% gcc -shared interface_wrap.o $(OBJS) -o interfacemodule.so 
    -% 6g interface.go
    -% 6c interface_gc.c
    -% gopack grc interface.a interface.6 interface_gc.6
    -% 6l program.6
    +% swig -go -cgo interface.i
    +% mkdir -p gopath/src/interface
    +% cp interface_wrap.c interface_wrap.h interface.go gopath/src/interface
    +% GOPATH=`pwd`/gopath
    +% export GOPATH
    +% cd gopath/src/interface
    +% go build
    +% go tool compile $(SRCDIR)/runme.go
    +% go tool link -o runme runme.o
     
    @@ -58,10 +62,15 @@

    Compilation Issues

    -% swig -go interface.i
    -% gcc -c interface_wrap.c
    -% gccgo -c interface.go
    -% gccgo program.o interface.o interface_wrap.o
    +% swig -go -cgo interface.i
    +% mkdir -p gopath/src/interface
    +% cp interface_wrap.c interface_wrap.h interface.go gopath/src/interface
    +% GOPATH=`pwd`/gopath
    +% export GOPATH
    +% cd gopath/src/interface
    +% go build
    +% gccgo -c $(SRCDIR)/runme.go
    +% gccgo -o runme runme.o interface.a
     
    Compatibility
  • All of the examples were last tested with the following configuration -(10 May 2010): +(5 August 2015):
      -
    • Ubuntu Hardy -
    • gcc-4.2.4 +
    • Ubuntu Trusty +
    • gcc-4.8.4
    -Your mileage may vary. If you experience a problem, please let us know by +Your mileage may vary. If you experience a problem, please let us know by contacting us on the mailing lists. diff --git a/Examples/go/multimap/Makefile b/Examples/go/multimap/Makefile index 4d739162bee..ba172611d69 100644 --- a/Examples/go/multimap/Makefile +++ b/Examples/go/multimap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = multimap.c TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: diff --git a/Examples/go/multimap/example.i b/Examples/go/multimap/example.i index 8de6b0dc37c..30a37d3bfdf 100644 --- a/Examples/go/multimap/example.i +++ b/Examples/go/multimap/example.i @@ -74,16 +74,21 @@ extern int count(char *bytes, int len, char c); %} /* Return the mutated string as a modified element in the array. */ -%typemap(argout) (char *str, int len) +%typemap(argout,fragment="AllocateString") (char *str, int len) %{ { _gostring_ *a; a = (_gostring_*) $input.array; - a[0] = _swig_makegostring($1, $2); + a[0] = Swig_AllocateString($1, $2); } %} +%typemap(goargout,fragment="CopyString") (char *str, int len) +%{ + $input[0] = swigCopyString($input[0]) +%} + %typemap(freearg) (char *str, int len) %{ free($1); diff --git a/Examples/go/pointer/Makefile b/Examples/go/pointer/Makefile index 9f1f3fda06f..20587fd9544 100644 --- a/Examples/go/pointer/Makefile +++ b/Examples/go/pointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = pointer.c TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: diff --git a/Examples/go/reference/Makefile b/Examples/go/reference/Makefile index e136f6fae6d..d203fff6d7d 100644 --- a/Examples/go/reference/Makefile +++ b/Examples/go/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = reference.cxx TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: diff --git a/Examples/go/simple/Makefile b/Examples/go/simple/Makefile index 5bc16549d37..89b936f3d5e 100644 --- a/Examples/go/simple/Makefile +++ b/Examples/go/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = simple.c TARGET = example INTERFACE = example.i @@ -8,7 +9,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: diff --git a/Examples/go/template/Makefile b/Examples/go/template/Makefile index a1d674836a7..f79b083cbed 100644 --- a/Examples/go/template/Makefile +++ b/Examples/go/template/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: diff --git a/Examples/go/variables/Makefile b/Examples/go/variables/Makefile index d0da605e09a..cef1186af80 100644 --- a/Examples/go/variables/Makefile +++ b/Examples/go/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = variables.c TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: diff --git a/Examples/guile/class/Makefile b/Examples/guile/class/Makefile index 48426a8fb3f..84a7b43228c 100644 --- a/Examples/guile/class/Makefile +++ b/Examples/guile/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp clean: diff --git a/Examples/guile/constants/Makefile b/Examples/guile/constants/Makefile index d3f58ebdca9..abe63d4b180 100644 --- a/Examples/guile/constants/Makefile +++ b/Examples/guile/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = my-guile INTERFACE = example.i @@ -8,7 +9,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented clean: diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile index 53638c86781..cfe0c853603 100644 --- a/Examples/guile/matrix/Makefile +++ b/Examples/guile/matrix/Makefile @@ -1,14 +1,16 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = matrix.c vector.c -TARGET = matrix +TARGET = my-guile INTERFACE = example.i check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_augmented_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-lm' guile_augmented clean: diff --git a/Examples/guile/matrix/README b/Examples/guile/matrix/README index db7395b70b9..496e81bf1af 100644 --- a/Examples/guile/matrix/README +++ b/Examples/guile/matrix/README @@ -6,7 +6,7 @@ type the following : Alternatively, use the command-line: - ./matrix -e do-test -s runme.scm + ./my-guile -e do-test -s runme.scm Or, if your operating system is spiffy enough: diff --git a/Examples/guile/multimap/Makefile b/Examples/guile/multimap/Makefile index b8f5e9b5af2..f8767021932 100644 --- a/Examples/guile/multimap/Makefile +++ b/Examples/guile/multimap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static clean: diff --git a/Examples/guile/multivalue/Makefile b/Examples/guile/multivalue/Makefile index b8f5e9b5af2..f8767021932 100644 --- a/Examples/guile/multivalue/Makefile +++ b/Examples/guile/multivalue/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static clean: diff --git a/Examples/guile/port/Makefile b/Examples/guile/port/Makefile index 95a3a479f07..09ee821f5a4 100644 --- a/Examples/guile/port/Makefile +++ b/Examples/guile/port/Makefile @@ -1,14 +1,16 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c -TARGET = port +TARGET = my-guile INTERFACE = example.i check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented clean: diff --git a/Examples/guile/port/README b/Examples/guile/port/README index 784e39e5dfd..174d8767a47 100644 --- a/Examples/guile/port/README +++ b/Examples/guile/port/README @@ -1,2 +1,2 @@ This example illustrates the translation from Scheme file ports to -temporary FILE streams. Read the source and run ./port -s runme.scm +temporary FILE streams. Read the source and run ./my-guile -s runme.scm diff --git a/Examples/guile/simple/Makefile b/Examples/guile/simple/Makefile index 517e41c648f..d8fb2da8108 100644 --- a/Examples/guile/simple/Makefile +++ b/Examples/guile/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = my-guile INTERFACE = example.i @@ -8,7 +9,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented clean: diff --git a/Examples/guile/std_vector/Makefile b/Examples/guile/std_vector/Makefile index d7f5de21777..1146242c270 100644 --- a/Examples/guile/std_vector/Makefile +++ b/Examples/guile/std_vector/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp clean: diff --git a/Examples/java/callback/Makefile b/Examples/java/callback/Makefile index 13cfd1708dc..c76e0926265 100644 --- a/Examples/java/callback/Makefile +++ b/Examples/java/callback/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/callback/example.i b/Examples/java/callback/example.i index 90beda01af1..cf61ef9d2f8 100644 --- a/Examples/java/callback/example.i +++ b/Examples/java/callback/example.i @@ -4,8 +4,6 @@ #include "example.h" %} -%include "std_string.i" - /* turn on director wrapping Callback */ %feature("director") Callback; diff --git a/Examples/java/class/Makefile b/Examples/java/class/Makefile index 13cfd1708dc..c76e0926265 100644 --- a/Examples/java/class/Makefile +++ b/Examples/java/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/constants/Makefile b/Examples/java/constants/Makefile index 637ce0eaded..ddc2157a6d8 100644 --- a/Examples/java/constants/Makefile +++ b/Examples/java/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/enum/Makefile b/Examples/java/enum/Makefile index 13cfd1708dc..c76e0926265 100644 --- a/Examples/java/enum/Makefile +++ b/Examples/java/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/extend/Makefile b/Examples/java/extend/Makefile index 13cfd1708dc..c76e0926265 100644 --- a/Examples/java/extend/Makefile +++ b/Examples/java/extend/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/funcptr/Makefile b/Examples/java/funcptr/Makefile index c0b1927cae8..4babc683d39 100644 --- a/Examples/java/funcptr/Makefile +++ b/Examples/java/funcptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/multimap/Makefile b/Examples/java/multimap/Makefile index c0b1927cae8..4babc683d39 100644 --- a/Examples/java/multimap/Makefile +++ b/Examples/java/multimap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/native/Makefile b/Examples/java/native/Makefile index fa67e48a4a0..b43a7d15293 100644 --- a/Examples/java/native/Makefile +++ b/Examples/java/native/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/nested/Makefile b/Examples/java/nested/Makefile index 13cfd1708dc..c76e0926265 100644 --- a/Examples/java/nested/Makefile +++ b/Examples/java/nested/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/pointer/Makefile b/Examples/java/pointer/Makefile index c0b1927cae8..4babc683d39 100644 --- a/Examples/java/pointer/Makefile +++ b/Examples/java/pointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/pointer/example.i b/Examples/java/pointer/example.i index a8ac79499f8..ed1c2fcc37e 100644 --- a/Examples/java/pointer/example.i +++ b/Examples/java/pointer/example.i @@ -24,7 +24,3 @@ extern void sub(int *INPUT, int *INPUT, int *OUTPUT); %apply int *OUTPUT { int *r }; extern int divide(int n, int d, int *r); - - - - diff --git a/Examples/java/reference/Makefile b/Examples/java/reference/Makefile index 13cfd1708dc..c76e0926265 100644 --- a/Examples/java/reference/Makefile +++ b/Examples/java/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/simple/Makefile b/Examples/java/simple/Makefile index c0b1927cae8..4babc683d39 100644 --- a/Examples/java/simple/Makefile +++ b/Examples/java/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/template/Makefile b/Examples/java/template/Makefile index 637ce0eaded..ddc2157a6d8 100644 --- a/Examples/java/template/Makefile +++ b/Examples/java/template/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/typemap/Makefile b/Examples/java/typemap/Makefile index fa67e48a4a0..b43a7d15293 100644 --- a/Examples/java/typemap/Makefile +++ b/Examples/java/typemap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/java/variables/Makefile b/Examples/java/variables/Makefile index c0b1927cae8..4babc683d39 100644 --- a/Examples/java/variables/Makefile +++ b/Examples/java/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile diff --git a/Examples/javascript/example.mk b/Examples/javascript/example.mk index cb8a33efd54..3ef012aa824 100644 --- a/Examples/javascript/example.mk +++ b/Examples/javascript/example.mk @@ -13,20 +13,23 @@ else JSV8_VERSION=0x031110 endif -EXAMPLES_TOP=../.. -SWIG_TOP=../../.. -SWIG = $(SWIG_TOP)/preinst-swig -TARGET = example -INTERFACE = example.i -SWIGOPT=-$(JSENGINE) -DV8_VERSION=$(JSV8_VERSION) +EXAMPLES_TOP = ../.. +SWIG_TOP = ../../.. +SWIGEXE = $(SWIG_TOP)/swig +SWIG_LIB_DIR = $(SWIG_TOP)/$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +TARGET = example +INTERFACE = example.i +SWIGOPT = -$(JSENGINE) -DV8_VERSION=$(JSV8_VERSION) check: build $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' JSENGINE='$(JSENGINE)' TARGET='$(TARGET)' javascript_run build: - $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp - $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' JSENGINE='$(JSENGINE)' javascript_build_cpp clean: diff --git a/Examples/lua/arrays/Makefile b/Examples/lua/arrays/Makefile index 4191f7ec32c..70de9c453c3 100644 --- a/Examples/lua/arrays/Makefile +++ b/Examples/lua/arrays/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: diff --git a/Examples/lua/class/Makefile b/Examples/lua/class/Makefile index 96308f0dfc8..dd78fdbe90f 100644 --- a/Examples/lua/class/Makefile +++ b/Examples/lua/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: diff --git a/Examples/lua/constants/Makefile b/Examples/lua/constants/Makefile index ae33cb182cd..979dc7d4509 100644 --- a/Examples/lua/constants/Makefile +++ b/Examples/lua/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: diff --git a/Examples/lua/dual/Makefile b/Examples/lua/dual/Makefile index c86152a9701..53b28b645a9 100644 --- a/Examples/lua/dual/Makefile +++ b/Examples/lua/dual/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = dual GENCXXSRCS = example2_wrap.cxx INTERFACE = dual.i @@ -11,9 +12,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run build: - $(SWIG) -lua -external-runtime - $(SWIG) -c++ -lua $(SWIGOPT) -o $(GENCXXSRCS) $(SRCDIR)example2.i - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) GENCXXSRCS='$(GENCXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + lua_externalhdr + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-c++' INTERFACE='example2.i' lua_swig_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) GENCXXSRCS='$(GENCXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static_cpp clean: diff --git a/Examples/lua/embed/Makefile b/Examples/lua/embed/Makefile index 5e3a9189389..7f405449284 100644 --- a/Examples/lua/embed/Makefile +++ b/Examples/lua/embed/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = embed SRCS = example.c INTERFACE = example.i @@ -12,7 +13,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static clean: diff --git a/Examples/lua/embed2/Makefile b/Examples/lua/embed2/Makefile index d30ba094233..28d9682b40d 100644 --- a/Examples/lua/embed2/Makefile +++ b/Examples/lua/embed2/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = embed2 SRCS = example.c INTERFACE = example.i @@ -12,7 +13,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static clean: diff --git a/Examples/lua/embed3/Makefile b/Examples/lua/embed3/Makefile index fc002612218..d8e7c7385dc 100644 --- a/Examples/lua/embed3/Makefile +++ b/Examples/lua/embed3/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = embed3 SRCS = example.cpp INTERFACE = example.i @@ -12,8 +13,11 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run build: - $(SWIG) -c++ -lua $(SWIGOPT) -external-runtime swigluarun.h - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + lua_externalhdr + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static_cpp clean: diff --git a/Examples/lua/exception/Makefile b/Examples/lua/exception/Makefile index ac9c28b6918..a476f0b9138 100644 --- a/Examples/lua/exception/Makefile +++ b/Examples/lua/exception/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: diff --git a/Examples/lua/funcptr3/Makefile b/Examples/lua/funcptr3/Makefile index aeeaad46989..fb363cbe9a5 100644 --- a/Examples/lua/funcptr3/Makefile +++ b/Examples/lua/funcptr3/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: diff --git a/Examples/lua/functest/Makefile b/Examples/lua/functest/Makefile index aeeaad46989..fb363cbe9a5 100644 --- a/Examples/lua/functest/Makefile +++ b/Examples/lua/functest/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: diff --git a/Examples/lua/functor/Makefile b/Examples/lua/functor/Makefile index e647fb2a823..1bc860a70df 100644 --- a/Examples/lua/functor/Makefile +++ b/Examples/lua/functor/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: diff --git a/Examples/lua/import/Makefile b/Examples/lua/import/Makefile index 8d64a21c623..ff73702c46c 100644 --- a/Examples/lua/import/Makefile +++ b/Examples/lua/import/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = @@ -7,14 +8,18 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' lua_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' lua_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' lua_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' lua_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' lua_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' lua_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' lua_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' lua_cpp clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/import/README b/Examples/lua/import/README index 1a52e3c1e24..af83d29b914 100644 --- a/Examples/lua/import/README +++ b/Examples/lua/import/README @@ -1,36 +1,36 @@ -This example tests the %import directive and working with multiple modules. - -Use 'lua runme.lua' to run a test. - -Overview: ---------- - -The example defines 4 different extension modules--each wrapping -a separate C++ class. - - base.i - Base class - foo.i - Foo class derived from Base - bar.i - Bar class derived from Base - spam.i - Spam class derived from Bar - -Each module uses %import to refer to another module. For -example, the 'foo.i' module uses '%import base.i' to get -definitions for its base class. - -If everything is okay, all of the modules will load properly and -type checking will work correctly. Caveat: Some compilers, for example -gcc-3.2.x, generate broken vtables with the inline methods in this test. -This is not a SWIG problem and can usually be solved with non-inlined -destructors compiled into separate shared objects/DLLs. - -Unix: ------ -- Run make -- Run the test as described above - -Windows: +This example tests the %import directive and working with multiple modules. + +Use 'lua runme.lua' to run a test. + +Overview: +--------- + +The example defines 4 different extension modules--each wrapping +a separate C++ class. + + base.i - Base class + foo.i - Foo class derived from Base + bar.i - Bar class derived from Base + spam.i - Spam class derived from Bar + +Each module uses %import to refer to another module. For +example, the 'foo.i' module uses '%import base.i' to get +definitions for its base class. + +If everything is okay, all of the modules will load properly and +type checking will work correctly. Caveat: Some compilers, for example +gcc-3.2.x, generate broken vtables with the inline methods in this test. +This is not a SWIG problem and can usually be solved with non-inlined +destructors compiled into separate shared objects/DLLs. + +Unix: +----- +- Run make +- Run the test as described above + +Windows: -------- Sorry, no files here. -If you know how, you could copy the python or ruby example dsw & dsp and try editing that +If you know how, you could copy the python or ruby example dsw & dsp and try editing that + - diff --git a/Examples/lua/nspace/Makefile b/Examples/lua/nspace/Makefile index 17757c2ec29..fdedebca1d2 100644 --- a/Examples/lua/nspace/Makefile +++ b/Examples/lua/nspace/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: diff --git a/Examples/lua/owner/Makefile b/Examples/lua/owner/Makefile index 96308f0dfc8..dd78fdbe90f 100644 --- a/Examples/lua/owner/Makefile +++ b/Examples/lua/owner/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: diff --git a/Examples/lua/pointer/Makefile b/Examples/lua/pointer/Makefile index aeeaad46989..fb363cbe9a5 100644 --- a/Examples/lua/pointer/Makefile +++ b/Examples/lua/pointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: diff --git a/Examples/lua/simple/Makefile b/Examples/lua/simple/Makefile index 4191f7ec32c..70de9c453c3 100644 --- a/Examples/lua/simple/Makefile +++ b/Examples/lua/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: diff --git a/Examples/lua/variables/Makefile b/Examples/lua/variables/Makefile index 4191f7ec32c..70de9c453c3 100644 --- a/Examples/lua/variables/Makefile +++ b/Examples/lua/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: diff --git a/Examples/modula3/class/Makefile b/Examples/modula3/class/Makefile index 2e2f375264d..b25f636c3d7 100644 --- a/Examples/modula3/class/Makefile +++ b/Examples/modula3/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example PLATFORM = LINUXLIBC6 @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) # compilation of example_wrap.cxx is started by cm3 diff --git a/Examples/modula3/enum/Makefile b/Examples/modula3/enum/Makefile index 3915e540551..2c5c9b0a555 100644 --- a/Examples/modula3/enum/Makefile +++ b/Examples/modula3/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -11,11 +12,12 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(SWIG) -modula3 $(SWIGOPT) -module Example -generateconst $(CONSTNUMERIC) $(TARGET).h + $(SWIGEXE) -modula3 $(SWIGOPT) -module Example -generateconst $(CONSTNUMERIC) $(TARGET).h $(CXX) -Wall $(CONSTNUMERIC).c -o $(CONSTNUMERIC) $(CONSTNUMERIC) >$(CONSTNUMERIC).i - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ diff --git a/Examples/modula3/exception/Makefile b/Examples/modula3/exception/Makefile index 1dbf1a156ea..8d12ef19e24 100644 --- a/Examples/modula3/exception/Makefile +++ b/Examples/modula3/exception/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -11,7 +12,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3_cpp # $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MODULA3SRCS='$(MODULA3SRCS)' MODULA3FLAGS='$(MODULA3FLAGS)' modula3_compile m3ppinplace $(MODULA3SRCS) diff --git a/Examples/modula3/reference/Makefile b/Examples/modula3/reference/Makefile index 3b68fe822ac..eaceceb1fff 100644 --- a/Examples/modula3/reference/Makefile +++ b/Examples/modula3/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ diff --git a/Examples/modula3/simple/Makefile b/Examples/modula3/simple/Makefile index 2796b25f800..3ba35d18bca 100644 --- a/Examples/modula3/simple/Makefile +++ b/Examples/modula3/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ diff --git a/Examples/modula3/typemap/Makefile b/Examples/modula3/typemap/Makefile index 2796b25f800..3ba35d18bca 100644 --- a/Examples/modula3/typemap/Makefile +++ b/Examples/modula3/typemap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -10,7 +11,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ diff --git a/Examples/mzscheme/multimap/Makefile b/Examples/mzscheme/multimap/Makefile index ecf83fbeba2..713ee43a702 100644 --- a/Examples/mzscheme/multimap/Makefile +++ b/Examples/mzscheme/multimap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/mzscheme/simple/Makefile b/Examples/mzscheme/simple/Makefile index ecf83fbeba2..713ee43a702 100644 --- a/Examples/mzscheme/simple/Makefile +++ b/Examples/mzscheme/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/mzscheme/std_vector/Makefile b/Examples/mzscheme/std_vector/Makefile index 75918a61e59..96f5e80cf2f 100644 --- a/Examples/mzscheme/std_vector/Makefile +++ b/Examples/mzscheme/std_vector/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -12,7 +13,7 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: - $(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACE) + $(SWIGEXE) -mzscheme -c++ $(SWIGOPT) $(INTERFACE) $(MZC) --compiler $(GPP) ++ccf "-I." --cc example_wrap.cxx $(MZC) --linker $(GPP) --ld $(TARGET).so example_wrap.o diff --git a/Examples/ocaml/argout_ref/Makefile b/Examples/ocaml/argout_ref/Makefile index 09893af65ce..8b7fc959eae 100644 --- a/Examples/ocaml/argout_ref/Makefile +++ b/Examples/ocaml/argout_ref/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -13,13 +14,15 @@ check: build build: static static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp diff --git a/Examples/ocaml/contract/Makefile b/Examples/ocaml/contract/Makefile index df5d6a6f5ac..c77e6dcc417 100644 --- a/Examples/ocaml/contract/Makefile +++ b/Examples/ocaml/contract/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -13,19 +14,22 @@ check: build build: static dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static toplevel: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_toplevel diff --git a/Examples/ocaml/scoped_enum/Makefile b/Examples/ocaml/scoped_enum/Makefile index 79473397186..9655c98e6fd 100644 --- a/Examples/ocaml/scoped_enum/Makefile +++ b/Examples/ocaml/scoped_enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -13,19 +14,22 @@ check: build build: static dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp toplevel: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel diff --git a/Examples/ocaml/shapes/Makefile b/Examples/ocaml/shapes/Makefile index 69102f3b18e..b291d07e80c 100644 --- a/Examples/ocaml/shapes/Makefile +++ b/Examples/ocaml/shapes/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = SRCS = example.c TARGET = example @@ -14,19 +15,22 @@ check: build build: static static_top static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp static_top: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp diff --git a/Examples/ocaml/simple/Makefile b/Examples/ocaml/simple/Makefile index 49bf81c1eeb..88fef743554 100644 --- a/Examples/ocaml/simple/Makefile +++ b/Examples/ocaml/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -13,19 +14,22 @@ check: build build: static dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static toplevel: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_toplevel diff --git a/Examples/ocaml/std_string/Makefile b/Examples/ocaml/std_string/Makefile index 8f8b2f684ac..099b1fceee3 100644 --- a/Examples/ocaml/std_string/Makefile +++ b/Examples/ocaml/std_string/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -11,12 +12,14 @@ check: build build: static static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_dynamic_cpp diff --git a/Examples/ocaml/std_vector/Makefile b/Examples/ocaml/std_vector/Makefile index 8f8b2f684ac..099b1fceee3 100644 --- a/Examples/ocaml/std_vector/Makefile +++ b/Examples/ocaml/std_vector/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -11,12 +12,14 @@ check: build build: static static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_dynamic_cpp diff --git a/Examples/ocaml/stl/Makefile b/Examples/ocaml/stl/Makefile index e4cce48839f..912dd9f8d61 100644 --- a/Examples/ocaml/stl/Makefile +++ b/Examples/ocaml/stl/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -11,22 +12,26 @@ check: build build: static static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp director: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_director dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp toplevel: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_toplevel diff --git a/Examples/ocaml/string_from_ptr/Makefile b/Examples/ocaml/string_from_ptr/Makefile index 294bdec83c1..f9b0278029e 100644 --- a/Examples/ocaml/string_from_ptr/Makefile +++ b/Examples/ocaml/string_from_ptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = -c++ SRCS = TARGET = example @@ -14,19 +15,22 @@ check: build build: static static_top static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp static_top: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp diff --git a/Examples/ocaml/strings_test/Makefile b/Examples/ocaml/strings_test/Makefile index b6b866669e1..24e2e6cca52 100644 --- a/Examples/ocaml/strings_test/Makefile +++ b/Examples/ocaml/strings_test/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -11,17 +12,20 @@ check: build build: static top static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp dynamic: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp top: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_toplevel diff --git a/Examples/octave/callback/example.i b/Examples/octave/callback/example.i index 50ef5096d5d..333127a9db1 100644 --- a/Examples/octave/callback/example.i +++ b/Examples/octave/callback/example.i @@ -7,8 +7,6 @@ #include "example.h" %} -%include "std_string.i" - /* turn on director wrapping Callback */ %feature("director") Callback; diff --git a/Examples/octave/example.mk b/Examples/octave/example.mk index e0b1e4efb7a..1ab96f038b6 100644 --- a/Examples/octave/example.mk +++ b/Examples/octave/example.mk @@ -2,7 +2,8 @@ # These paths are relative to such an example directory TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = swigexample INTERFACE = example.i @@ -11,18 +12,22 @@ check: build build: ifneq (,$(SRCS)) - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave else - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp endif ifneq (,$(TARGET2)$(SWIGOPT2)) ifneq (,$(SRCS)) - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT2)' TARGET='$(TARGET2)' INTERFACE='$(INTERFACE)' octave else - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT2)' TARGET='$(TARGET2)' INTERFACE='$(INTERFACE)' octave_cpp endif endif diff --git a/Examples/octave/module_load/runme.m b/Examples/octave/module_load/runme.m index bc311b5e695..30b7badb282 100644 --- a/Examples/octave/module_load/runme.m +++ b/Examples/octave/module_load/runme.m @@ -61,9 +61,8 @@ testme clear all -# octave 3.0.5 randomly crashes on the remaining tests, so skip them -api_version = sscanf(octave_config_info("api_version"), "api-v%i"); -if api_version < 37 +# octave 3.0.5 randomly crashes on the remaining tests +if !swig_octave_prereq(3,2,0) exit endif diff --git a/Examples/octave/operator/example.i b/Examples/octave/operator/example.i index 7fad8e60977..937e8d39d03 100644 --- a/Examples/octave/operator/example.i +++ b/Examples/octave/operator/example.i @@ -26,4 +26,25 @@ ComplexVal __paren__(int j) { return ComplexVal($self->re()*j,$self->im()*j); } + + double __float__() { + return (double) $self->re(); + } + + double __real__() { + return $self->re(); + } + double __imag__() { + return $self->im(); + } + double __abs__() { + return sqrt($self->re()*$self->re() + $self->im()*$self->im()); + } + ComplexVal __conj__() { + return ComplexVal($self->re(), -$self->im()); + } + ComplexVal __exp__() { + return exp($self->re()) * ComplexVal(cos($self->im()), sin($self->im())); + } + }; diff --git a/Examples/octave/operator/runme.m b/Examples/octave/operator/runme.m index 9ab614ffbe7..83197b410cb 100644 --- a/Examples/octave/operator/runme.m +++ b/Examples/octave/operator/runme.m @@ -24,3 +24,16 @@ # friend operator printf("2*a = %s\n",disp(2*a)); + +# conversions +printf("single(a) = %g\n", single(a)); +printf("double(a) = %g\n", double(a)); + +# unary functions +if swig_octave_prereq(3,8,0) + printf("real(a) = %g\n", real(a)); + printf("imag(a) = %g\n", imag(a)); + printf("abs(a) = %g\n", abs(a)); + printf("conj(a) = %s\n", disp(conj(a))); + printf("exp(a) = %s\n", disp(exp(a))); +endif diff --git a/Examples/perl5/callback/Makefile b/Examples/perl5/callback/Makefile index 0d1cc574fe3..08271768c4f 100644 --- a/Examples/perl5/callback/Makefile +++ b/Examples/perl5/callback/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: diff --git a/Examples/perl5/callback/example.i b/Examples/perl5/callback/example.i index 5f9072e61bd..821a9e6b532 100644 --- a/Examples/perl5/callback/example.i +++ b/Examples/perl5/callback/example.i @@ -4,8 +4,6 @@ #include "example.h" %} -%include "std_string.i" - /* turn on director wrapping Callback */ %feature("director") Callback; diff --git a/Examples/perl5/class/Makefile b/Examples/perl5/class/Makefile index 0d1cc574fe3..08271768c4f 100644 --- a/Examples/perl5/class/Makefile +++ b/Examples/perl5/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: diff --git a/Examples/perl5/constants/Makefile b/Examples/perl5/constants/Makefile index b7b411534eb..b0dc678060b 100644 --- a/Examples/perl5/constants/Makefile +++ b/Examples/perl5/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: diff --git a/Examples/perl5/constants2/Makefile b/Examples/perl5/constants2/Makefile index 85dd13741d5..db676cc4eba 100644 --- a/Examples/perl5/constants2/Makefile +++ b/Examples/perl5/constants2/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: diff --git a/Examples/perl5/extend/Makefile b/Examples/perl5/extend/Makefile index 0d1cc574fe3..08271768c4f 100644 --- a/Examples/perl5/extend/Makefile +++ b/Examples/perl5/extend/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: diff --git a/Examples/perl5/funcptr/Makefile b/Examples/perl5/funcptr/Makefile index 3e1de1fc1ee..dfc01843e96 100644 --- a/Examples/perl5/funcptr/Makefile +++ b/Examples/perl5/funcptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: diff --git a/Examples/perl5/import/Makefile b/Examples/perl5/import/Makefile index b31ab795253..e9225af25ad 100644 --- a/Examples/perl5/import/Makefile +++ b/Examples/perl5/import/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = @@ -7,14 +8,18 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='baseclass' INTERFACE='base.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' perl5_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='baseclass' INTERFACE='base.i' perl5_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' perl5_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' perl5_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' perl5_cpp clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/java/Makefile b/Examples/perl5/java/Makefile index 5eaea321223..7c133235f62 100644 --- a/Examples/perl5/java/Makefile +++ b/Examples/perl5/java/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: Example.class Example.h - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ CXXSHARED="gcj -fpic -shared Example.class" PERL5_CCFLAGS='' PERL5_EXP='' LIBS="-lstdc++" perl5_cpp diff --git a/Examples/perl5/multimap/Makefile b/Examples/perl5/multimap/Makefile index 3e1de1fc1ee..dfc01843e96 100644 --- a/Examples/perl5/multimap/Makefile +++ b/Examples/perl5/multimap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: diff --git a/Examples/perl5/multiple_inheritance/Makefile b/Examples/perl5/multiple_inheritance/Makefile index 1fe5a51bb6a..b73356e3e03 100644 --- a/Examples/perl5/multiple_inheritance/Makefile +++ b/Examples/perl5/multiple_inheritance/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: diff --git a/Examples/perl5/pointer/Makefile b/Examples/perl5/pointer/Makefile index 3e1de1fc1ee..dfc01843e96 100644 --- a/Examples/perl5/pointer/Makefile +++ b/Examples/perl5/pointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: diff --git a/Examples/perl5/reference/Makefile b/Examples/perl5/reference/Makefile index a22f5a68d23..c4212099e5b 100644 --- a/Examples/perl5/reference/Makefile +++ b/Examples/perl5/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' SWIGOPT='$(SWIGOPT)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' SWIGOPT='$(SWIGOPT)' perl5_cpp_static clean: diff --git a/Examples/perl5/simple/Makefile b/Examples/perl5/simple/Makefile index 3e1de1fc1ee..dfc01843e96 100644 --- a/Examples/perl5/simple/Makefile +++ b/Examples/perl5/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: diff --git a/Examples/perl5/value/Makefile b/Examples/perl5/value/Makefile index 3e1de1fc1ee..dfc01843e96 100644 --- a/Examples/perl5/value/Makefile +++ b/Examples/perl5/value/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: diff --git a/Examples/perl5/variables/Makefile b/Examples/perl5/variables/Makefile index 3e1de1fc1ee..dfc01843e96 100644 --- a/Examples/perl5/variables/Makefile +++ b/Examples/perl5/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: diff --git a/Examples/perl5/xmlstring/Makefile b/Examples/perl5/xmlstring/Makefile index 4f02d3ee47a..3b4ba0ea4f7 100644 --- a/Examples/perl5/xmlstring/Makefile +++ b/Examples/perl5/xmlstring/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS=$(LIBS) CXX="g++ -g3" perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: diff --git a/Examples/php/callback/Makefile b/Examples/php/callback/Makefile index 3ad3999a5e5..cbc75774ccb 100644 --- a/Examples/php/callback/Makefile +++ b/Examples/php/callback/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static clean: diff --git a/Examples/php/callback/example.i b/Examples/php/callback/example.i index 90beda01af1..cf61ef9d2f8 100644 --- a/Examples/php/callback/example.i +++ b/Examples/php/callback/example.i @@ -4,8 +4,6 @@ #include "example.h" %} -%include "std_string.i" - /* turn on director wrapping Callback */ %feature("director") Callback; diff --git a/Examples/php/class/Makefile b/Examples/php/class/Makefile index 8b2b340e990..02a8668ac10 100644 --- a/Examples/php/class/Makefile +++ b/Examples/php/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static diff --git a/Examples/php/constants/Makefile b/Examples/php/constants/Makefile index e5b49571e19..9dbd3842d9c 100644 --- a/Examples/php/constants/Makefile +++ b/Examples/php/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static diff --git a/Examples/php/cpointer/Makefile b/Examples/php/cpointer/Makefile index f2c15c5c1a7..05679f844ed 100644 --- a/Examples/php/cpointer/Makefile +++ b/Examples/php/cpointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static diff --git a/Examples/php/disown/Makefile b/Examples/php/disown/Makefile index 8b2b340e990..02a8668ac10 100644 --- a/Examples/php/disown/Makefile +++ b/Examples/php/disown/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static diff --git a/Examples/php/enum/Makefile b/Examples/php/enum/Makefile index 2028d03c794..95ebf8fc17b 100644 --- a/Examples/php/enum/Makefile +++ b/Examples/php/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static diff --git a/Examples/php/extend/Makefile b/Examples/php/extend/Makefile index 3ad3999a5e5..cbc75774ccb 100644 --- a/Examples/php/extend/Makefile +++ b/Examples/php/extend/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static clean: diff --git a/Examples/php/funcptr/Makefile b/Examples/php/funcptr/Makefile index f2c15c5c1a7..05679f844ed 100644 --- a/Examples/php/funcptr/Makefile +++ b/Examples/php/funcptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static diff --git a/Examples/php/overloading/Makefile b/Examples/php/overloading/Makefile index 8b2b340e990..02a8668ac10 100644 --- a/Examples/php/overloading/Makefile +++ b/Examples/php/overloading/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static diff --git a/Examples/php/pointer/Makefile b/Examples/php/pointer/Makefile index f2c15c5c1a7..05679f844ed 100644 --- a/Examples/php/pointer/Makefile +++ b/Examples/php/pointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static diff --git a/Examples/php/pragmas/Makefile b/Examples/php/pragmas/Makefile index e5b49571e19..9dbd3842d9c 100644 --- a/Examples/php/pragmas/Makefile +++ b/Examples/php/pragmas/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static diff --git a/Examples/php/proxy/Makefile b/Examples/php/proxy/Makefile index 8b2b340e990..02a8668ac10 100644 --- a/Examples/php/proxy/Makefile +++ b/Examples/php/proxy/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static diff --git a/Examples/php/reference/Makefile b/Examples/php/reference/Makefile index 8b2b340e990..02a8668ac10 100644 --- a/Examples/php/reference/Makefile +++ b/Examples/php/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static diff --git a/Examples/php/simple/Makefile b/Examples/php/simple/Makefile index f2c15c5c1a7..05679f844ed 100644 --- a/Examples/php/simple/Makefile +++ b/Examples/php/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static diff --git a/Examples/php/sync/Makefile b/Examples/php/sync/Makefile index 8b2b340e990..02a8668ac10 100644 --- a/Examples/php/sync/Makefile +++ b/Examples/php/sync/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static diff --git a/Examples/php/value/Makefile b/Examples/php/value/Makefile index 3db7afec511..674e4368e1f 100644 --- a/Examples/php/value/Makefile +++ b/Examples/php/value/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static diff --git a/Examples/php/variables/Makefile b/Examples/php/variables/Makefile index f2c15c5c1a7..05679f844ed 100644 --- a/Examples/php/variables/Makefile +++ b/Examples/php/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static diff --git a/Examples/pike/class/Makefile b/Examples/pike/class/Makefile index d8cf4ea7e05..e5319dbe24e 100644 --- a/Examples/pike/class/Makefile +++ b/Examples/pike/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: diff --git a/Examples/pike/constants/Makefile b/Examples/pike/constants/Makefile index 736d30f03c0..45da7d269ca 100644 --- a/Examples/pike/constants/Makefile +++ b/Examples/pike/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static clean: diff --git a/Examples/pike/enum/Makefile b/Examples/pike/enum/Makefile index d8cf4ea7e05..e5319dbe24e 100644 --- a/Examples/pike/enum/Makefile +++ b/Examples/pike/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: diff --git a/Examples/pike/overload/Makefile b/Examples/pike/overload/Makefile index f111b113756..5e5fe669bd4 100644 --- a/Examples/pike/overload/Makefile +++ b/Examples/pike/overload/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: diff --git a/Examples/pike/simple/Makefile b/Examples/pike/simple/Makefile index d7f6b209eed..8b49b4ea5f7 100644 --- a/Examples/pike/simple/Makefile +++ b/Examples/pike/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static clean: diff --git a/Examples/pike/template/Makefile b/Examples/pike/template/Makefile index da115c1d51b..513dc3b4ba1 100644 --- a/Examples/pike/template/Makefile +++ b/Examples/pike/template/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: diff --git a/Examples/python/callback/Makefile b/Examples/python/callback/Makefile index a4c4d2a69ea..71926f397b3 100644 --- a/Examples/python/callback/Makefile +++ b/Examples/python/callback/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/callback/example.i b/Examples/python/callback/example.i index 90beda01af1..cf61ef9d2f8 100644 --- a/Examples/python/callback/example.i +++ b/Examples/python/callback/example.i @@ -4,8 +4,6 @@ #include "example.h" %} -%include "std_string.i" - /* turn on director wrapping Callback */ %feature("director") Callback; diff --git a/Examples/python/callback/runme.py b/Examples/python/callback/runme.py index ddb6684078a..345a3eb6e65 100644 --- a/Examples/python/callback/runme.py +++ b/Examples/python/callback/runme.py @@ -2,14 +2,16 @@ # This file illustrates the cross language polymorphism using directors. -import example +import example class PyCallback(example.Callback): - def __init__(self): - example.Callback.__init__(self) - def run(self): - print "PyCallback.run()" + + def __init__(self): + example.Callback.__init__(self) + + def run(self): + print "PyCallback.run()" # Create an Caller instance @@ -25,7 +27,7 @@ def run(self): callback.thisown = 0 caller.setCallback(callback) caller.call() -caller.delCallback(); +caller.delCallback() print print "Adding and calling a Python callback" @@ -53,4 +55,3 @@ def run(self): print print "python exit" - diff --git a/Examples/python/class/Makefile b/Examples/python/class/Makefile index 41cded28496..471e3907364 100644 --- a/Examples/python/class/Makefile +++ b/Examples/python/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/class/runme.py b/Examples/python/class/runme.py index 8f4f27eb9f2..34d21505c42 100644 --- a/Examples/python/class/runme.py +++ b/Examples/python/class/runme.py @@ -3,7 +3,7 @@ # This file illustrates the proxy class C++ interface generated # by SWIG. -import example +import example # ----- Object creation ----- @@ -15,7 +15,7 @@ # ----- Access a static member ----- -print "\nA total of", example.cvar.Shape_nshapes,"shapes were created" +print "\nA total of", example.cvar.Shape_nshapes, "shapes were created" # ----- Member data access ----- @@ -28,16 +28,16 @@ s.y = 5 print "\nHere is their current position:" -print " Circle = (%f, %f)" % (c.x,c.y) -print " Square = (%f, %f)" % (s.x,s.y) +print " Circle = (%f, %f)" % (c.x, c.y) +print " Square = (%f, %f)" % (s.x, s.y) # ----- Call some methods ----- print "\nHere are some properties of the shapes:" -for o in [c,s]: - print " ", o - print " area = ", o.area() - print " perimeter = ", o.perimeter() +for o in [c, s]: + print " ", o + print " area = ", o.area() + print " perimeter = ", o.perimeter() # prevent o from holding a reference to the last object looked at o = None @@ -47,5 +47,5 @@ del c del s -print example.cvar.Shape_nshapes,"shapes remain" +print example.cvar.Shape_nshapes, "shapes remain" print "Goodbye" diff --git a/Examples/python/constants/Makefile b/Examples/python/constants/Makefile index 8ec6e9cc9cb..a412cf2993a 100644 --- a/Examples/python/constants/Makefile +++ b/Examples/python/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/constants/runme.py b/Examples/python/constants/runme.py index 8d25b878bc9..415d1adc420 100644 --- a/Examples/python/constants/runme.py +++ b/Examples/python/constants/runme.py @@ -1,6 +1,6 @@ # file: runme.py -import example +import example print "ICONST =", example.ICONST, "(should be 42)" print "FCONST =", example.FCONST, "(should be 2.1828)" @@ -8,7 +8,7 @@ print "CCONST2 =", example.CCONST2, "(this should be on a new line)" print "SCONST =", example.SCONST, "(should be 'Hello World')" print "SCONST2 =", example.SCONST2, "(should be '\"Hello World\"')" -print "EXPR =", example.EXPR, "(should be 48.5484)" +print "EXPR =", example.EXPR, "(should be 48.5484)" print "iconst =", example.iconst, "(should be 37)" print "fconst =", example.fconst, "(should be 3.14)" @@ -21,7 +21,3 @@ print "FOO = ", example.FOO, "(Arg! This shouldn't print anything)" except AttributeError: print "FOO isn't defined (good)" - - - - diff --git a/Examples/python/contract/Makefile b/Examples/python/contract/Makefile index fe1d9325ecb..54817c79d55 100644 --- a/Examples/python/contract/Makefile +++ b/Examples/python/contract/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,12 +10,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - TARGET='mypython' INTERFACE='$(INTERFACE)' python_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/contract/runme.py b/Examples/python/contract/runme.py index d484ae916ed..ce01e5a1db4 100644 --- a/Examples/python/contract/runme.py +++ b/Examples/python/contract/runme.py @@ -1,13 +1,13 @@ # file: runme.py -import example +import example # Call our gcd() function x = 42 y = 105 -g = example.gcd(x,y) -print "The gcd of %d and %d is %d" % (x,y,g) +g = example.gcd(x, y) +print "The gcd of %d and %d is %d" % (x, y, g) # Manipulate the Foo global variable @@ -19,12 +19,3 @@ # See if the change took effect print "Foo = ", example.cvar.Foo - - - - - - - - - diff --git a/Examples/python/docstrings/Makefile b/Examples/python/docstrings/Makefile index f471930dd78..f1365a59975 100644 --- a/Examples/python/docstrings/Makefile +++ b/Examples/python/docstrings/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static diff --git a/Examples/python/docstrings/runme.py b/Examples/python/docstrings/runme.py index b6c95e613e6..c25d291b68c 100644 --- a/Examples/python/docstrings/runme.py +++ b/Examples/python/docstrings/runme.py @@ -1,6 +1,5 @@ # file: runme.py -import example +import example print "example.Foo.bar.__doc__ =", repr(example.Foo.bar.__doc__), "(Should be 'No comment')" - diff --git a/Examples/python/enum/Makefile b/Examples/python/enum/Makefile index 41cded28496..471e3907364 100644 --- a/Examples/python/enum/Makefile +++ b/Examples/python/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/enum/runme.py b/Examples/python/enum/runme.py index 10c4a260d07..def01b147e6 100644 --- a/Examples/python/enum/runme.py +++ b/Examples/python/enum/runme.py @@ -18,9 +18,9 @@ print "\nTesting use of enums with functions\n" example.enum_test(example.RED, example.Foo.IMPULSE) -example.enum_test(example.BLUE, example.Foo.WARP) +example.enum_test(example.BLUE, example.Foo.WARP) example.enum_test(example.GREEN, example.Foo.LUDICROUS) -example.enum_test(1234,5678) +example.enum_test(1234, 5678) print "\nTesting use of enum with class method" f = example.Foo() @@ -28,4 +28,3 @@ f.enum_test(example.Foo.IMPULSE) f.enum_test(example.Foo.WARP) f.enum_test(example.Foo.LUDICROUS) - diff --git a/Examples/python/exception/Makefile b/Examples/python/exception/Makefile index ad3d49fe1c6..8420c829768 100644 --- a/Examples/python/exception/Makefile +++ b/Examples/python/exception/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/exception/runme.py b/Examples/python/exception/runme.py index 9e924119477..7fae4903028 100644 --- a/Examples/python/exception/runme.py +++ b/Examples/python/exception/runme.py @@ -6,38 +6,37 @@ t = example.Test() try: - t.unknown() -except RuntimeError,e: - print "incomplete type", e.args[0] + t.unknown() +except RuntimeError, e: + print "incomplete type", e.args[0] try: - t.simple() -except RuntimeError,e: - print e.args[0] + t.simple() +except RuntimeError, e: + print e.args[0] try: - t.message() -except RuntimeError,e: - print e.args[0] + t.message() +except RuntimeError, e: + print e.args[0] if not example.is_python_builtin(): - try: + try: t.hosed() - except example.Exc,e: + except example.Exc, e: print e.code, e.msg else: - try: + try: t.hosed() - except BaseException,e: - # Throwing builtin classes as exceptions not supported (-builtin option) + except BaseException, e: + # Throwing builtin classes as exceptions not supported (-builtin + # option) print e -for i in range(1,4): - try: - t.multi(i) - except RuntimeError,e: - print e.args[0] - except example.Exc,e: - print e.code, e.msg - - +for i in range(1, 4): + try: + t.multi(i) + except RuntimeError, e: + print e.args[0] + except example.Exc, e: + print e.code, e.msg diff --git a/Examples/python/exceptproxy/Makefile b/Examples/python/exceptproxy/Makefile index f406dfaf480..65af5ec82cc 100644 --- a/Examples/python/exceptproxy/Makefile +++ b/Examples/python/exceptproxy/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/exceptproxy/runme.py b/Examples/python/exceptproxy/runme.py index 07e4b0a7fbb..970d6201d22 100644 --- a/Examples/python/exceptproxy/runme.py +++ b/Examples/python/exceptproxy/runme.py @@ -2,8 +2,8 @@ import example if example.is_python_builtin(): - print "Skipping example: -builtin option does not support %exceptionclass" - exit(0) + print "Skipping example: -builtin option does not support %exceptionclass" + exit(0) q = example.intQueue(10) @@ -12,18 +12,18 @@ print type(example.FullError) try: - for i in range(0,100): - q.enqueue(i) -except example.FullError,e: - print "Maxsize is", e.maxsize + for i in range(0, 100): + q.enqueue(i) +except example.FullError, e: + print "Maxsize is", e.maxsize print "Removing items" try: - while 1: - q.dequeue() -except example.EmptyError,e: - pass + while 1: + q.dequeue() +except example.EmptyError, e: + pass q = example.doubleQueue(1000) @@ -31,21 +31,15 @@ print "Inserting items into doubleQueue" try: - for i in range(0,10000): - q.enqueue(i*1.5) -except example.FullError,e: - print "Maxsize is", e.maxsize + for i in range(0, 10000): + q.enqueue(i * 1.5) +except example.FullError, e: + print "Maxsize is", e.maxsize print "Removing items" try: - while 1: - q.dequeue() -except example.EmptyError,e: - pass - - - - - - + while 1: + q.dequeue() +except example.EmptyError, e: + pass diff --git a/Examples/python/extend/Makefile b/Examples/python/extend/Makefile index a4c4d2a69ea..71926f397b3 100644 --- a/Examples/python/extend/Makefile +++ b/Examples/python/extend/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/extend/runme.py b/Examples/python/extend/runme.py index 240b098948e..2bb38fadce7 100644 --- a/Examples/python/extend/runme.py +++ b/Examples/python/extend/runme.py @@ -2,16 +2,18 @@ # This file illustrates the cross language polymorphism using directors. -import example +import example # CEO class, which overrides Employee::getPosition(). class CEO(example.Manager): - def __init__(self, name): - example.Manager.__init__(self, name) - def getPosition(self): - return "CEO" + + def __init__(self, name): + example.Manager.__init__(self, name) + + def getPosition(self): + return "CEO" # Create an instance of our employee extension class, CEO. The calls to @@ -78,4 +80,3 @@ def getPosition(self): # All done. print "python exit" - diff --git a/Examples/python/funcptr/Makefile b/Examples/python/funcptr/Makefile index 222916fa11c..26bfd946ea9 100644 --- a/Examples/python/funcptr/Makefile +++ b/Examples/python/funcptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/funcptr/runme.py b/Examples/python/funcptr/runme.py index bce06505781..bf0c6e1acff 100644 --- a/Examples/python/funcptr/runme.py +++ b/Examples/python/funcptr/runme.py @@ -1,6 +1,6 @@ # file: runme.py -import example +import example a = 37 b = 42 @@ -10,9 +10,9 @@ print "Trying some C callback functions" print " a =", a print " b =", b -print " ADD(a,b) =", example.do_op(a,b,example.ADD) -print " SUB(a,b) =", example.do_op(a,b,example.SUB) -print " MUL(a,b) =", example.do_op(a,b,example.MUL) +print " ADD(a,b) =", example.do_op(a, b, example.ADD) +print " SUB(a,b) =", example.do_op(a, b, example.SUB) +print " MUL(a,b) =", example.do_op(a, b, example.MUL) print "Here is what the C callback function objects look like in Python" print " ADD =", example.ADD diff --git a/Examples/python/funcptr2/Makefile b/Examples/python/funcptr2/Makefile index 222916fa11c..26bfd946ea9 100644 --- a/Examples/python/funcptr2/Makefile +++ b/Examples/python/funcptr2/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/funcptr2/runme.py b/Examples/python/funcptr2/runme.py index bd58fb6206a..a4405d9d9b7 100644 --- a/Examples/python/funcptr2/runme.py +++ b/Examples/python/funcptr2/runme.py @@ -1,6 +1,6 @@ # file: runme.py -import example +import example a = 37 b = 42 @@ -10,9 +10,9 @@ print "Trying some C callback functions" print " a =", a print " b =", b -print " ADD(a,b) =", example.do_op(a,b,example.ADD) -print " SUB(a,b) =", example.do_op(a,b,example.SUB) -print " MUL(a,b) =", example.do_op(a,b,example.MUL) +print " ADD(a,b) =", example.do_op(a, b, example.ADD) +print " SUB(a,b) =", example.do_op(a, b, example.SUB) +print " MUL(a,b) =", example.do_op(a, b, example.MUL) print "Here is what the C callback function objects look like in Python" print " ADD =", example.ADD @@ -20,5 +20,5 @@ print " MUL =", example.MUL print "Call the functions directly..." -print " add(a,b) =", example.add(a,b) -print " sub(a,b) =", example.sub(a,b) +print " add(a,b) =", example.add(a, b) +print " sub(a,b) =", example.sub(a, b) diff --git a/Examples/python/functor/Makefile b/Examples/python/functor/Makefile index 1234c310e01..e5de5c5b782 100644 --- a/Examples/python/functor/Makefile +++ b/Examples/python/functor/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/functor/runme.py b/Examples/python/functor/runme.py index 8fc0f2ff2f0..7f6f2b649bc 100644 --- a/Examples/python/functor/runme.py +++ b/Examples/python/functor/runme.py @@ -8,10 +8,9 @@ # Use the objects. They should be callable just like a normal # python function. -for i in range(0,100): +for i in range(0, 100): a(i) # Note: function call b(math.sqrt(i)) # Note: function call print a.result() print b.result() - diff --git a/Examples/python/import/Makefile b/Examples/python/import/Makefile index d83dfeaa8be..ad208b3e789 100644 --- a/Examples/python/import/Makefile +++ b/Examples/python/import/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = @@ -7,14 +8,18 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp clean: diff --git a/Examples/python/import/runme.py b/Examples/python/import/runme.py index 6b800ecb8b2..0e83acad0e5 100644 --- a/Examples/python/import/runme.py +++ b/Examples/python/import/runme.py @@ -81,31 +81,27 @@ print " Spam -> Base -> Foo : ", y = foo.Foo_fromBase(x) if y: - print "bad swig" + print "bad swig" else: - print "good swig" + print "good swig" print " Spam -> Base -> Bar : ", y = bar.Bar_fromBase(x) if y: - print "good swig" + print "good swig" else: - print "bad swig" - + print "bad swig" + print " Spam -> Base -> Spam : ", y = spam.Spam_fromBase(x) if y: - print "good swig" + print "good swig" else: - print "bad swig" + print "bad swig" print " Foo -> Spam : ", y = spam.Spam_fromBase(b) if y: - print "bad swig" + print "bad swig" else: - print "good swig" - - - - + print "good swig" diff --git a/Examples/python/import_packages/Makefile b/Examples/python/import_packages/Makefile index dfd46d05c5f..72b424a906f 100644 --- a/Examples/python/import_packages/Makefile +++ b/Examples/python/import_packages/Makefile @@ -1,8 +1,6 @@ TOP = ../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = -PY3 = import_packages_subdirs = \ same_modnames1 \ @@ -26,12 +24,12 @@ check: build build: for s in $(import_packages_subdirs); do \ - (cd $$s && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \ + (cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \ done static: for s in $(import_packages_subdirs); do \ - (cd $$s && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \ + (cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \ done clean: diff --git a/Examples/python/import_packages/from_init1/Makefile b/Examples/python/import_packages/from_init1/Makefile index b9d803a0e79..90c92ab1c88 100644 --- a/Examples/python/import_packages/from_init1/Makefile +++ b/Examples/python/import_packages/from_init1/Makefile @@ -1,8 +1,5 @@ TOP = ../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) -SWIGOPT = LIBS = -PY3 = ifeq (,$(PY3)) PKG1DIR = "py2" @@ -14,10 +11,10 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build static: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init1/py2/Makefile b/Examples/python/import_packages/from_init1/py2/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/from_init1/py2/Makefile +++ b/Examples/python/import_packages/from_init1/py2/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/Makefile b/Examples/python/import_packages/from_init1/py2/pkg2/Makefile index 1eb810e0566..102a8938b9f 100644 --- a/Examples/python/import_packages/from_init1/py2/pkg2/Makefile +++ b/Examples/python/import_packages/from_init1/py2/pkg2/Makefile @@ -1,19 +1,24 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static clean:: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init1/py3/Makefile b/Examples/python/import_packages/from_init1/py3/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/from_init1/py3/Makefile +++ b/Examples/python/import_packages/from_init1/py3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/Makefile b/Examples/python/import_packages/from_init1/py3/pkg2/Makefile index 1eb810e0566..102a8938b9f 100644 --- a/Examples/python/import_packages/from_init1/py3/pkg2/Makefile +++ b/Examples/python/import_packages/from_init1/py3/pkg2/Makefile @@ -1,19 +1,24 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static clean:: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init1/runme.py b/Examples/python/import_packages/from_init1/runme.py index bbe092babfd..dda397487de 100644 --- a/Examples/python/import_packages/from_init1/runme.py +++ b/Examples/python/import_packages/from_init1/runme.py @@ -5,9 +5,9 @@ testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" -if sys.version_info < (3,0): - import py2.pkg2 - print " Finished importing py2.pkg2" +if sys.version_info < (3, 0): + import py2.pkg2 + print " Finished importing py2.pkg2" else: - import py3.pkg2 - print " Finished importing py3.pkg2" + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/from_init2/Makefile b/Examples/python/import_packages/from_init2/Makefile index b9d803a0e79..90c92ab1c88 100644 --- a/Examples/python/import_packages/from_init2/Makefile +++ b/Examples/python/import_packages/from_init2/Makefile @@ -1,8 +1,5 @@ TOP = ../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) -SWIGOPT = LIBS = -PY3 = ifeq (,$(PY3)) PKG1DIR = "py2" @@ -14,10 +11,10 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build static: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init2/py2/Makefile b/Examples/python/import_packages/from_init2/py2/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/from_init2/py2/Makefile +++ b/Examples/python/import_packages/from_init2/py2/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/Makefile b/Examples/python/import_packages/from_init2/py2/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/from_init2/py2/pkg2/Makefile +++ b/Examples/python/import_packages/from_init2/py2/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile index cb20bd25f94..7a0cb18ad83 100644 --- a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init2/py3/Makefile b/Examples/python/import_packages/from_init2/py3/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/from_init2/py3/Makefile +++ b/Examples/python/import_packages/from_init2/py3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/Makefile b/Examples/python/import_packages/from_init2/py3/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/from_init2/py3/pkg2/Makefile +++ b/Examples/python/import_packages/from_init2/py3/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile index cb20bd25f94..7a0cb18ad83 100644 --- a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init2/runme.py b/Examples/python/import_packages/from_init2/runme.py index bbe092babfd..dda397487de 100644 --- a/Examples/python/import_packages/from_init2/runme.py +++ b/Examples/python/import_packages/from_init2/runme.py @@ -5,9 +5,9 @@ testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" -if sys.version_info < (3,0): - import py2.pkg2 - print " Finished importing py2.pkg2" +if sys.version_info < (3, 0): + import py2.pkg2 + print " Finished importing py2.pkg2" else: - import py3.pkg2 - print " Finished importing py3.pkg2" + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/from_init3/Makefile b/Examples/python/import_packages/from_init3/Makefile index b9d803a0e79..90c92ab1c88 100644 --- a/Examples/python/import_packages/from_init3/Makefile +++ b/Examples/python/import_packages/from_init3/Makefile @@ -1,8 +1,5 @@ TOP = ../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) -SWIGOPT = LIBS = -PY3 = ifeq (,$(PY3)) PKG1DIR = "py2" @@ -14,10 +11,10 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build static: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init3/py2/Makefile b/Examples/python/import_packages/from_init3/py2/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/from_init3/py2/Makefile +++ b/Examples/python/import_packages/from_init3/py2/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/from_init3/py2/pkg2/Makefile +++ b/Examples/python/import_packages/from_init3/py2/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile index d6ae1b2bc44..6f193fa336b 100644 --- a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile index 286d90070a5..a870607e23d 100644 --- a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init3/py3/Makefile b/Examples/python/import_packages/from_init3/py3/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/from_init3/py3/Makefile +++ b/Examples/python/import_packages/from_init3/py3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/from_init3/py3/pkg2/Makefile +++ b/Examples/python/import_packages/from_init3/py3/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile index d6ae1b2bc44..6f193fa336b 100644 --- a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile index 286d90070a5..a870607e23d 100644 --- a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init3/runme.py b/Examples/python/import_packages/from_init3/runme.py index bbe092babfd..dda397487de 100644 --- a/Examples/python/import_packages/from_init3/runme.py +++ b/Examples/python/import_packages/from_init3/runme.py @@ -5,9 +5,9 @@ testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" -if sys.version_info < (3,0): - import py2.pkg2 - print " Finished importing py2.pkg2" +if sys.version_info < (3, 0): + import py2.pkg2 + print " Finished importing py2.pkg2" else: - import py3.pkg2 - print " Finished importing py3.pkg2" + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/relativeimport1/Makefile b/Examples/python/import_packages/relativeimport1/Makefile index b9d803a0e79..90c92ab1c88 100644 --- a/Examples/python/import_packages/relativeimport1/Makefile +++ b/Examples/python/import_packages/relativeimport1/Makefile @@ -1,8 +1,5 @@ TOP = ../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) -SWIGOPT = LIBS = -PY3 = ifeq (,$(PY3)) PKG1DIR = "py2" @@ -14,10 +11,10 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build static: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py2/Makefile b/Examples/python/import_packages/relativeimport1/py2/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/relativeimport1/py2/Makefile +++ b/Examples/python/import_packages/relativeimport1/py2/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile index cb20bd25f94..7a0cb18ad83 100644 --- a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py3/Makefile b/Examples/python/import_packages/relativeimport1/py3/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/relativeimport1/py3/Makefile +++ b/Examples/python/import_packages/relativeimport1/py3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile index cb20bd25f94..7a0cb18ad83 100644 --- a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport1/runme.py b/Examples/python/import_packages/relativeimport1/runme.py index 99b6e513ec8..997476b1d19 100644 --- a/Examples/python/import_packages/relativeimport1/runme.py +++ b/Examples/python/import_packages/relativeimport1/runme.py @@ -5,9 +5,9 @@ testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) print "Testing " + testname + " - %module(package=...) with -relativeimport" -if sys.version_info < (3,0): - import py2.pkg2.bar - print " Finished importing py2.pkg2.bar" +if sys.version_info < (3, 0): + import py2.pkg2.bar + print " Finished importing py2.pkg2.bar" else: - import py3.pkg2.bar - print " Finished importing py3.pkg2.bar" + import py3.pkg2.bar + print " Finished importing py3.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/Makefile b/Examples/python/import_packages/relativeimport2/Makefile index b9d803a0e79..90c92ab1c88 100644 --- a/Examples/python/import_packages/relativeimport2/Makefile +++ b/Examples/python/import_packages/relativeimport2/Makefile @@ -1,8 +1,5 @@ TOP = ../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) -SWIGOPT = LIBS = -PY3 = ifeq (,$(PY3)) PKG1DIR = "py2" @@ -14,10 +11,10 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build static: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py2/Makefile b/Examples/python/import_packages/relativeimport2/py2/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/relativeimport2/py2/Makefile +++ b/Examples/python/import_packages/relativeimport2/py2/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile index d6ae1b2bc44..6f193fa336b 100644 --- a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile index 286d90070a5..a870607e23d 100644 --- a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py3/Makefile b/Examples/python/import_packages/relativeimport2/py3/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/relativeimport2/py3/Makefile +++ b/Examples/python/import_packages/relativeimport2/py3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile index d6ae1b2bc44..6f193fa336b 100644 --- a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile index 286d90070a5..a870607e23d 100644 --- a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport2/runme.py b/Examples/python/import_packages/relativeimport2/runme.py index f0ab6c44690..9789afc1898 100644 --- a/Examples/python/import_packages/relativeimport2/runme.py +++ b/Examples/python/import_packages/relativeimport2/runme.py @@ -5,9 +5,9 @@ testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" -if sys.version_info < (3,0): - import py2.pkg2.bar - print " Finished importing py2.pkg2.bar" +if sys.version_info < (3, 0): + import py2.pkg2.bar + print " Finished importing py2.pkg2.bar" else: - import py3.pkg2.bar - print " Finished importing py3.pkg2.bar" + import py3.pkg2.bar + print " Finished importing py3.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport3/Makefile b/Examples/python/import_packages/relativeimport3/Makefile index b9d803a0e79..90c92ab1c88 100644 --- a/Examples/python/import_packages/relativeimport3/Makefile +++ b/Examples/python/import_packages/relativeimport3/Makefile @@ -1,8 +1,5 @@ TOP = ../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) -SWIGOPT = LIBS = -PY3 = ifeq (,$(PY3)) PKG1DIR = "py2" @@ -14,10 +11,10 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build static: - cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport3/py2/Makefile b/Examples/python/import_packages/relativeimport3/py2/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/relativeimport3/py2/Makefile +++ b/Examples/python/import_packages/relativeimport3/py2/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport3/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport3/py2/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/relativeimport3/py2/pkg2/Makefile +++ b/Examples/python/import_packages/relativeimport3/py2/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/Makefile index cb20bd25f94..7a0cb18ad83 100644 --- a/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport3/py3/Makefile b/Examples/python/import_packages/relativeimport3/py3/Makefile index 9595397d81e..62962514409 100644 --- a/Examples/python/import_packages/relativeimport3/py3/Makefile +++ b/Examples/python/import_packages/relativeimport3/py3/Makefile @@ -1,13 +1,12 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) SWIGOPT = LIBS = build: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/relativeimport3/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport3/py3/pkg2/Makefile index 36e099b782a..c1f234e34dc 100644 --- a/Examples/python/import_packages/relativeimport3/py3/pkg2/Makefile +++ b/Examples/python/import_packages/relativeimport3/py3/pkg2/Makefile @@ -1,17 +1,20 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/Makefile index cb20bd25f94..7a0cb18ad83 100644 --- a/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/Makefile +++ b/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport3/runme.py b/Examples/python/import_packages/relativeimport3/runme.py index 99b6e513ec8..997476b1d19 100644 --- a/Examples/python/import_packages/relativeimport3/runme.py +++ b/Examples/python/import_packages/relativeimport3/runme.py @@ -5,9 +5,9 @@ testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) print "Testing " + testname + " - %module(package=...) with -relativeimport" -if sys.version_info < (3,0): - import py2.pkg2.bar - print " Finished importing py2.pkg2.bar" +if sys.version_info < (3, 0): + import py2.pkg2.bar + print " Finished importing py2.pkg2.bar" else: - import py3.pkg2.bar - print " Finished importing py3.pkg2.bar" + import py3.pkg2.bar + print " Finished importing py3.pkg2.bar" diff --git a/Examples/python/import_packages/same_modnames1/Makefile b/Examples/python/import_packages/same_modnames1/Makefile index e05c130178c..57148c61425 100644 --- a/Examples/python/import_packages/same_modnames1/Makefile +++ b/Examples/python/import_packages/same_modnames1/Makefile @@ -1,18 +1,16 @@ TOP = ../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) -SWIGOPT = LIBS = check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg1 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static - cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg1 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/same_modnames1/pkg1/Makefile b/Examples/python/import_packages/same_modnames1/pkg1/Makefile index df1b30321b7..3ca7fab03af 100644 --- a/Examples/python/import_packages/same_modnames1/pkg1/Makefile +++ b/Examples/python/import_packages/same_modnames1/pkg1/Makefile @@ -1,15 +1,18 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames1/pkg2/Makefile b/Examples/python/import_packages/same_modnames1/pkg2/Makefile index df1b30321b7..3ca7fab03af 100644 --- a/Examples/python/import_packages/same_modnames1/pkg2/Makefile +++ b/Examples/python/import_packages/same_modnames1/pkg2/Makefile @@ -1,15 +1,18 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames1/runme.py b/Examples/python/import_packages/same_modnames1/runme.py index 7bec1ec1e85..3c3c00c1a57 100644 --- a/Examples/python/import_packages/same_modnames1/runme.py +++ b/Examples/python/import_packages/same_modnames1/runme.py @@ -8,6 +8,12 @@ print " Finished importing pkg2.foo" var2 = pkg2.foo.Pkg2_Foo() -if str(type(var2)).find("'pkg2.foo.Pkg2_Foo'") == -1: - raise RuntimeError("failed type checking: " + str(type(var2))) + +classname = str(type(var2)) +# Check for an old-style class if swig was run in -classic mode +if classname == "": + classname = str(var2.__class__) + +if classname.find("pkg2.foo.Pkg2_Foo") == -1: + raise RuntimeError("failed type checking: " + classname) print " Successfully created object pkg2.foo.Pkg2_Foo" diff --git a/Examples/python/import_packages/same_modnames2/Makefile b/Examples/python/import_packages/same_modnames2/Makefile index 770343a800a..cf6db0c411b 100644 --- a/Examples/python/import_packages/same_modnames2/Makefile +++ b/Examples/python/import_packages/same_modnames2/Makefile @@ -1,18 +1,16 @@ TOP = ../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) -SWIGOPT = LIBS = check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build - cd pkg1/pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg1 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg1/pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build static: - cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static - cd pkg1/pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg1 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg1/pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean diff --git a/Examples/python/import_packages/same_modnames2/pkg1/Makefile b/Examples/python/import_packages/same_modnames2/pkg1/Makefile index df1b30321b7..3ca7fab03af 100644 --- a/Examples/python/import_packages/same_modnames2/pkg1/Makefile +++ b/Examples/python/import_packages/same_modnames2/pkg1/Makefile @@ -1,15 +1,18 @@ TOP = ../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile index 11e8573ad2c..921bb995167 100644 --- a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile @@ -1,15 +1,18 @@ TOP = ../../../../.. -SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames2/runme.py b/Examples/python/import_packages/same_modnames2/runme.py index eec6121ebec..38daad0a356 100644 --- a/Examples/python/import_packages/same_modnames2/runme.py +++ b/Examples/python/import_packages/same_modnames2/runme.py @@ -6,7 +6,13 @@ import pkg1.pkg2.foo print " Finished importing pkg1.pkg2.foo" -var2 = pkg1.pkg2.foo.Pkg2_Foo(); -if str(type(var2)).find("'pkg1.pkg2.foo.Pkg2_Foo'") == -1: - raise RuntimeError("failed type checking: " + str(type(var2))) +var2 = pkg1.pkg2.foo.Pkg2_Foo() + +classname = str(type(var2)) +# Check for an old-style class if swig was run in -classic mode +if classname == "": + classname = str(var2.__class__) + +if classname.find("pkg1.pkg2.foo.Pkg2_Foo") == -1: + raise RuntimeError("failed type checking: " + classname) print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo" diff --git a/Examples/python/import_template/Makefile b/Examples/python/import_template/Makefile index d83dfeaa8be..ad208b3e789 100644 --- a/Examples/python/import_template/Makefile +++ b/Examples/python/import_template/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = @@ -7,14 +8,18 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp clean: diff --git a/Examples/python/import_template/runme.py b/Examples/python/import_template/runme.py index 0d5aded1469..35f8924c123 100644 --- a/Examples/python/import_template/runme.py +++ b/Examples/python/import_template/runme.py @@ -81,31 +81,27 @@ print " Spam -> Base -> Foo : ", y = foo.intFoo_fromBase(x) if y: - print "bad swig" + print "bad swig" else: - print "good swig" + print "good swig" print " Spam -> Base -> Bar : ", y = bar.intBar_fromBase(x) if y: - print "good swig" + print "good swig" else: - print "bad swig" - + print "bad swig" + print " Spam -> Base -> Spam : ", y = spam.intSpam_fromBase(x) if y: - print "good swig" + print "good swig" else: - print "bad swig" + print "bad swig" print " Foo -> Spam : ", y = spam.intSpam_fromBase(b) if y: - print "bad swig" + print "bad swig" else: - print "good swig" - - - - + print "good swig" diff --git a/Examples/python/java/Makefile b/Examples/python/java/Makefile index 4befa38ba35..7c75e6b91c5 100644 --- a/Examples/python/java/Makefile +++ b/Examples/python/java/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: Example.class Example.h - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ CXXSHARED="gcj -fpic -shared Example.class" DEFS='' LIBS="-lstdc++" python_cpp diff --git a/Examples/python/java/runme.py b/Examples/python/java/runme.py index 0cec8a7cb3c..641ba27dd61 100644 --- a/Examples/python/java/runme.py +++ b/Examples/python/java/runme.py @@ -6,11 +6,11 @@ e1 = Example(1) e2 = Example(2) -print e1.Add(1,2) -print e1.Add(1.0,2.0) -e3 = e1.Add(e1,e2) +print e1.Add(1, 2) +print e1.Add(1.0, 2.0) +e3 = e1.Add(e1, e2) print e3.mPublicInt -print e1.Add("1","2") +print e1.Add("1", "2") JvDetachCurrentThread() diff --git a/Examples/python/libffi/Makefile b/Examples/python/libffi/Makefile index db5dfe13888..0875fdd9666 100644 --- a/Examples/python/libffi/Makefile +++ b/Examples/python/libffi/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-L/usr/local/lib -lffi' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/multimap/Makefile b/Examples/python/multimap/Makefile index 222916fa11c..26bfd946ea9 100644 --- a/Examples/python/multimap/Makefile +++ b/Examples/python/multimap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/multimap/example.i b/Examples/python/multimap/example.i index cc2482cc8b6..635f61c13d5 100644 --- a/Examples/python/multimap/example.i +++ b/Examples/python/multimap/example.i @@ -20,7 +20,7 @@ extern int gcd(int x, int y); if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "Expecting a list"); } - $1 = PyList_Size($input); + $1 = (int)PyList_Size($input); if ($1 == 0) { SWIG_exception(SWIG_ValueError, "List must contain at least 1 element"); } @@ -73,7 +73,7 @@ extern int gcdmain(int argc, char *argv[]); } utf8str = PyUnicode_AsUTF8String($input); PyBytes_AsStringAndSize(utf8str, &cstr, &len); - $1 = strndup(cstr, (size_t)len); + $1 = strncpy((char *)malloc(len+1), cstr, (size_t)len); $2 = (int)len; Py_DECREF(utf8str); %#else @@ -82,7 +82,7 @@ extern int gcdmain(int argc, char *argv[]); return NULL; } $1 = PyString_AsString($input); - $2 = PyString_Size($input); + $2 = (int)PyString_Size($input); %#endif } @@ -106,11 +106,11 @@ extern int count(char *bytes, int len, char c); Py_ssize_t len; PyObject *utf8str = PyUnicode_AsUTF8String($input); PyBytes_AsStringAndSize(utf8str, &cstr, &len); - $1 = strndup(cstr, (size_t)len); + $1 = strncpy((char *)malloc(len+1), cstr, (size_t)len); $2 = (int)len; Py_DECREF(utf8str); %#else - $2 = PyString_Size($input); + $2 = (int)PyString_Size($input); $1 = (char *) malloc($2+1); memmove($1,PyString_AsString($input),$2); %#endif diff --git a/Examples/python/multimap/runme.py b/Examples/python/multimap/runme.py index f996ab3aee8..ad693b73a3e 100644 --- a/Examples/python/multimap/runme.py +++ b/Examples/python/multimap/runme.py @@ -1,16 +1,16 @@ # file: runme.py -import example +import example # Call our gcd() function x = 42 y = 105 -g = example.gcd(x,y) -print "The gcd of %d and %d is %d" % (x,y,g) +g = example.gcd(x, y) +print "The gcd of %d and %d is %d" % (x, y, g) # Call the gcdmain() function -example.gcdmain(["gcdmain","42","105"]) +example.gcdmain(["gcdmain", "42", "105"]) # Call the count function print example.count("Hello World", "l") @@ -18,10 +18,3 @@ # Call the capitalize function print example.capitalize("hello world") - - - - - - - diff --git a/Examples/python/operator/Makefile b/Examples/python/operator/Makefile index 1234c310e01..e5de5c5b782 100644 --- a/Examples/python/operator/Makefile +++ b/Examples/python/operator/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/operator/runme.py b/Examples/python/operator/runme.py index 3687a38de6c..ac48f267604 100644 --- a/Examples/python/operator/runme.py +++ b/Examples/python/operator/runme.py @@ -1,21 +1,20 @@ # Operator overloading example import example -a = example.Complex(2,3) -b = example.Complex(-5,10) +a = example.Complex(2, 3) +b = example.Complex(-5, 10) -print "a =",a -print "b =",b +print "a =", a +print "b =", b c = a + b -print "c =",c -print "a*b =",a*b -print "a-c =",a-c +print "c =", c +print "a*b =", a * b +print "a-c =", a - c -e = example.ComplexCopy(a-c) -print "e =",e +e = example.ComplexCopy(a - c) +print "e =", e # Big expression -f = ((a+b)*(c+b*e)) + (-a) -print "f =",f - +f = ((a + b) * (c + b * e)) + (-a) +print "f =", f diff --git a/Examples/python/performance/constructor/Makefile b/Examples/python/performance/constructor/Makefile index 8e65123cf27..cbc11543ffd 100644 --- a/Examples/python/performance/constructor/Makefile +++ b/Examples/python/performance/constructor/Makefile @@ -1,19 +1,24 @@ TOP = ../../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ - TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ - TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ - TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-module Simple_baseline' TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-O -module Simple_optimized' TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-builtin -O -module Simple_builtin' TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/performance/constructor/runme.py b/Examples/python/performance/constructor/runme.py index 274cbf85e17..1771fba7b24 100644 --- a/Examples/python/performance/constructor/runme.py +++ b/Examples/python/performance/constructor/runme.py @@ -2,8 +2,9 @@ sys.path.append('..') import harness -def proc (mod) : - for i in range(1000000) : + +def proc(mod): + for i in range(1000000): x = mod.MyClass() harness.run(proc) diff --git a/Examples/python/performance/func/Makefile b/Examples/python/performance/func/Makefile index 8e65123cf27..cbc11543ffd 100644 --- a/Examples/python/performance/func/Makefile +++ b/Examples/python/performance/func/Makefile @@ -1,19 +1,24 @@ TOP = ../../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ - TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ - TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ - TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-module Simple_baseline' TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-O -module Simple_optimized' TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-builtin -O -module Simple_builtin' TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/performance/func/runme.py b/Examples/python/performance/func/runme.py index f9032b9d226..760a8ab6dd8 100644 --- a/Examples/python/performance/func/runme.py +++ b/Examples/python/performance/func/runme.py @@ -2,9 +2,10 @@ sys.path.append('..') import harness -def proc (mod) : + +def proc(mod): x = mod.MyClass() - for i in range(10000000) : + for i in range(10000000): x.func() harness.run(proc) diff --git a/Examples/python/performance/harness.py b/Examples/python/performance/harness.py index 00f48e66a7b..c3d38b4fbfb 100644 --- a/Examples/python/performance/harness.py +++ b/Examples/python/performance/harness.py @@ -3,9 +3,10 @@ import imp from subprocess import * -def run (proc) : - try : +def run(proc): + + try: mod = imp.find_module(sys.argv[1]) mod = imp.load_module(sys.argv[1], *mod) @@ -14,15 +15,18 @@ def run (proc) : t2 = time.clock() print "%s took %f seconds" % (mod.__name__, t2 - t1) - except IndexError : - proc = Popen([sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE) + except IndexError: + proc = Popen( + [sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE) (stdout, stderr) = proc.communicate() print stdout - proc = Popen([sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE) + proc = Popen( + [sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE) (stdout, stderr) = proc.communicate() print stdout - proc = Popen([sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE) + proc = Popen( + [sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE) (stdout, stderr) = proc.communicate() print stdout diff --git a/Examples/python/performance/hierarchy/Makefile b/Examples/python/performance/hierarchy/Makefile index 8e65123cf27..cbc11543ffd 100644 --- a/Examples/python/performance/hierarchy/Makefile +++ b/Examples/python/performance/hierarchy/Makefile @@ -1,19 +1,24 @@ TOP = ../../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ - TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ - TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ - TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-module Simple_baseline' TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-O -module Simple_optimized' TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-builtin -O -module Simple_builtin' TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/performance/hierarchy/runme.py b/Examples/python/performance/hierarchy/runme.py index 9b22586a1d0..8255cdc86c0 100644 --- a/Examples/python/performance/hierarchy/runme.py +++ b/Examples/python/performance/hierarchy/runme.py @@ -2,9 +2,10 @@ sys.path.append('..') import harness -def proc (mod) : + +def proc(mod): x = mod.H() - for i in range(10000000) : + for i in range(10000000): x.func() harness.run(proc) diff --git a/Examples/python/performance/hierarchy_operator/Makefile b/Examples/python/performance/hierarchy_operator/Makefile index 8e65123cf27..cbc11543ffd 100644 --- a/Examples/python/performance/hierarchy_operator/Makefile +++ b/Examples/python/performance/hierarchy_operator/Makefile @@ -1,19 +1,24 @@ TOP = ../../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ - TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ - TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ - TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-module Simple_baseline' TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-O -module Simple_optimized' TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-builtin -O -module Simple_builtin' TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/performance/hierarchy_operator/runme.py b/Examples/python/performance/hierarchy_operator/runme.py index 5a8c5255709..eabfae864cc 100644 --- a/Examples/python/performance/hierarchy_operator/runme.py +++ b/Examples/python/performance/hierarchy_operator/runme.py @@ -2,9 +2,10 @@ sys.path.append('..') import harness -def proc (mod) : + +def proc(mod): x = mod.H() - for i in range(10000000) : + for i in range(10000000): x += i harness.run(proc) diff --git a/Examples/python/performance/operator/Makefile b/Examples/python/performance/operator/Makefile index 8e65123cf27..cbc11543ffd 100644 --- a/Examples/python/performance/operator/Makefile +++ b/Examples/python/performance/operator/Makefile @@ -1,19 +1,24 @@ TOP = ../../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ - TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ - TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ - TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-module Simple_baseline' TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-O -module Simple_optimized' TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-builtin -O -module Simple_builtin' TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/performance/operator/runme.py b/Examples/python/performance/operator/runme.py index 4a6031f4865..d75ae404c33 100644 --- a/Examples/python/performance/operator/runme.py +++ b/Examples/python/performance/operator/runme.py @@ -2,9 +2,10 @@ sys.path.append('..') import harness -def proc (mod) : + +def proc(mod): x = mod.MyClass() - for i in range(10000000) : + for i in range(10000000): x = x + i harness.run(proc) diff --git a/Examples/python/pointer/Makefile b/Examples/python/pointer/Makefile index 222916fa11c..26bfd946ea9 100644 --- a/Examples/python/pointer/Makefile +++ b/Examples/python/pointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/pointer/runme.py b/Examples/python/pointer/runme.py index e38a306c178..5b5f16bc22d 100644 --- a/Examples/python/pointer/runme.py +++ b/Examples/python/pointer/runme.py @@ -1,25 +1,25 @@ # file: runme.py -import example; +import example # First create some objects using the pointer library. -print "Testing the pointer library"; -a = example.new_intp(); -b = example.new_intp(); -c = example.new_intp(); -example.intp_assign(a,37); -example.intp_assign(b,42); +print "Testing the pointer library" +a = example.new_intp() +b = example.new_intp() +c = example.new_intp() +example.intp_assign(a, 37) +example.intp_assign(b, 42) -print " a =",a -print " b =",b -print " c =",c +print " a =", a +print " b =", b +print " c =", c # Call the add() function with some pointers -example.add(a,b,c) +example.add(a, b, c) # Now get the result r = example.intp_value(c) -print " 37 + 42 =",r +print " 37 + 42 =", r # Clean up the pointers example.delete_intp(a) @@ -30,15 +30,12 @@ # This should be much easier. Now how it is no longer # necessary to manufacture pointers. -print "Trying the typemap library"; -r = example.sub(37,42) -print " 37 - 42 =",r +print "Trying the typemap library" +r = example.sub(37, 42) +print " 37 - 42 =", r # Now try the version with multiple return values -print "Testing multiple return values"; -q,r = example.divide(42,37) -print " 42/37 = %d remainder %d" % (q,r) - - - +print "Testing multiple return values" +q, r = example.divide(42, 37) +print " 42/37 = %d remainder %d" % (q, r) diff --git a/Examples/python/reference/Makefile b/Examples/python/reference/Makefile index 41cded28496..471e3907364 100644 --- a/Examples/python/reference/Makefile +++ b/Examples/python/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/reference/runme.py b/Examples/python/reference/runme.py index a1f53368e6c..0ff217b0226 100644 --- a/Examples/python/reference/runme.py +++ b/Examples/python/reference/runme.py @@ -7,22 +7,22 @@ # ----- Object creation ----- print "Creating some objects:" -a = example.Vector(3,4,5) -b = example.Vector(10,11,12) +a = example.Vector(3, 4, 5) +b = example.Vector(10, 11, 12) -print " Created",a.cprint() -print " Created",b.cprint() +print " Created", a.cprint() +print " Created", b.cprint() # ----- Call an overloaded operator ----- # This calls the wrapper we placed around # -# operator+(const Vector &a, const Vector &) +# operator+(const Vector &a, const Vector &) # # It returns a new allocated object. print "Adding a+b" -c = example.addv(a,b) +c = example.addv(a, b) print " a+b =", c.cprint() # Note: Unless we free the result, a memory leak will occur @@ -33,25 +33,25 @@ # Note: Using the high-level interface here print "Creating an array of vectors" va = example.VectorArray(10) -print " va = ",va +print " va = ", va # ----- Set some values in the array ----- # These operators copy the value of $a and $b to the vector array -va.set(0,a) -va.set(1,b) +va.set(0, a) +va.set(1, b) -va.set(2,example.addv(a,b)) +va.set(2, example.addv(a, b)) # Get some values from the array print "Getting some array values" -for i in range(0,5): +for i in range(0, 5): print " va(%d) = %s" % (i, va.get(i).cprint()) # Watch under resource meter to check on this print "Making sure we don't leak memory." -for i in xrange(0,1000000): +for i in xrange(0, 1000000): c = va.get(i % 10) # ----- Clean up ----- @@ -60,4 +60,3 @@ del va del a del b - diff --git a/Examples/python/simple/Makefile b/Examples/python/simple/Makefile index 222916fa11c..26bfd946ea9 100644 --- a/Examples/python/simple/Makefile +++ b/Examples/python/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/simple/runme.py b/Examples/python/simple/runme.py index d484ae916ed..ce01e5a1db4 100644 --- a/Examples/python/simple/runme.py +++ b/Examples/python/simple/runme.py @@ -1,13 +1,13 @@ # file: runme.py -import example +import example # Call our gcd() function x = 42 y = 105 -g = example.gcd(x,y) -print "The gcd of %d and %d is %d" % (x,y,g) +g = example.gcd(x, y) +print "The gcd of %d and %d is %d" % (x, y, g) # Manipulate the Foo global variable @@ -19,12 +19,3 @@ # See if the change took effect print "Foo = ", example.cvar.Foo - - - - - - - - - diff --git a/Examples/python/smartptr/Makefile b/Examples/python/smartptr/Makefile index 19609353d30..34edcfc40d8 100644 --- a/Examples/python/smartptr/Makefile +++ b/Examples/python/smartptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/smartptr/runme.py b/Examples/python/smartptr/runme.py index 5ea1fb9473d..5f8b7347642 100644 --- a/Examples/python/smartptr/runme.py +++ b/Examples/python/smartptr/runme.py @@ -3,7 +3,7 @@ # This file illustrates the proxy class C++ interface generated # by SWIG. -import example +import example # ----- Object creation ----- @@ -17,7 +17,7 @@ # ----- Access a static member ----- -print "\nA total of", example.cvar.Shape_nshapes,"shapes were created" +print "\nA total of", example.cvar.Shape_nshapes, "shapes were created" # ----- Member data access ----- @@ -30,16 +30,16 @@ s.y = 5 print "\nHere is their current position:" -print " Circle = (%f, %f)" % (c.x,c.y) -print " Square = (%f, %f)" % (s.x,s.y) +print " Circle = (%f, %f)" % (c.x, c.y) +print " Square = (%f, %f)" % (s.x, s.y) # ----- Call some methods ----- print "\nHere are some properties of the shapes:" -for o in [c,s]: - print " ", o - print " area = ", o.area() - print " perimeter = ", o.perimeter() +for o in [c, s]: + print " ", o + print " area = ", o.area() + print " perimeter = ", o.perimeter() print "\nGuess I'll clean up now" @@ -50,6 +50,5 @@ del ss s = 3 -print example.cvar.Shape_nshapes,"shapes remain" +print example.cvar.Shape_nshapes, "shapes remain" print "Goodbye" - diff --git a/Examples/python/std_map/Makefile b/Examples/python/std_map/Makefile index f406dfaf480..65af5ec82cc 100644 --- a/Examples/python/std_map/Makefile +++ b/Examples/python/std_map/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/std_map/runme.py b/Examples/python/std_map/runme.py index b521c9c9c90..26031f3f4d0 100644 --- a/Examples/python/std_map/runme.py +++ b/Examples/python/std_map/runme.py @@ -7,8 +7,6 @@ pmap["hello"] = 2 - - dmap = {} dmap["hello"] = 1.0 dmap["hi"] = 2.0 @@ -28,8 +26,8 @@ for i in dmap.itervalues(): print "val", i -for k,v in dmap.iteritems(): - print "item", k,v +for k, v in dmap.iteritems(): + print "item", k, v dmap = example.DoubleMap() dmap["hello"] = 1.0 @@ -41,8 +39,8 @@ for i in dmap.itervalues(): print "val", i -for k,v in dmap.iteritems(): - print "item", k,v +for k, v in dmap.iteritems(): + print "item", k, v print dmap.items() @@ -54,7 +52,6 @@ print hmap.values() - dmap = {} dmap["hello"] = 2 dmap["hi"] = 4 @@ -76,7 +73,7 @@ for i in dmap.iteritems(): print "item", i -for k,v in dmap.iteritems(): - print "item", k,v +for k, v in dmap.iteritems(): + print "item", k, v print dmap diff --git a/Examples/python/std_vector/Makefile b/Examples/python/std_vector/Makefile index f406dfaf480..65af5ec82cc 100644 --- a/Examples/python/std_vector/Makefile +++ b/Examples/python/std_vector/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/std_vector/runme.py b/Examples/python/std_vector/runme.py index d248ccbbbaf..d7d3c2ea49e 100644 --- a/Examples/python/std_vector/runme.py +++ b/Examples/python/std_vector/runme.py @@ -4,13 +4,13 @@ # Call average with a Python list... -print example.average([1,2,3,4]) +print example.average([1, 2, 3, 4]) # ... or a wrapped std::vector v = example.IntVector(4) for i in range(len(v)): - v[i] = i+1 + v[i] = i + 1 print example.average(v) @@ -22,8 +22,8 @@ # ... or a wrapped std::vector v = example.DoubleVector() -for i in [1,2,3,4]: - v.append(i) +for i in [1, 2, 3, 4]: + v.append(i) print example.half(v) @@ -31,6 +31,5 @@ example.halve_in_place(v) for i in range(len(v)): - print v[i], "; ", + print v[i], "; ", print - diff --git a/Examples/python/template/Makefile b/Examples/python/template/Makefile index f406dfaf480..65af5ec82cc 100644 --- a/Examples/python/template/Makefile +++ b/Examples/python/template/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: diff --git a/Examples/python/template/runme.py b/Examples/python/template/runme.py index 05940bc6723..e408e15f9e6 100644 --- a/Examples/python/template/runme.py +++ b/Examples/python/template/runme.py @@ -3,32 +3,30 @@ import example # Call some templated functions -print example.maxint(3,7) -print example.maxdouble(3.14,2.18) +print example.maxint(3, 7) +print example.maxdouble(3.14, 2.18) # Create some class iv = example.vecint(100) dv = example.vecdouble(1000) -for i in range(0,100): - iv.setitem(i,2*i) +for i in range(0, 100): + iv.setitem(i, 2 * i) -for i in range(0,1000): - dv.setitem(i, 1.0/(i+1)) +for i in range(0, 1000): + dv.setitem(i, 1.0 / (i + 1)) sum = 0 -for i in range(0,100): - sum = sum + iv.getitem(i) +for i in range(0, 100): + sum = sum + iv.getitem(i) print sum sum = 0.0 -for i in range(0,1000): - sum = sum + dv.getitem(i) +for i in range(0, 1000): + sum = sum + dv.getitem(i) print sum del iv del dv - - diff --git a/Examples/python/varargs/Makefile b/Examples/python/varargs/Makefile index 8ec6e9cc9cb..a412cf2993a 100644 --- a/Examples/python/varargs/Makefile +++ b/Examples/python/varargs/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/varargs/runme.py b/Examples/python/varargs/runme.py index 8eab77041ea..48e3134f3f5 100644 --- a/Examples/python/varargs/runme.py +++ b/Examples/python/varargs/runme.py @@ -1,13 +1,13 @@ # file: runme.py import sys -import example +import example # Call printf example.printf("Hello World. I'm printf\n") # Note: We call printf, but use *python* string formatting -for i in range(0,10): +for i in range(0, 10): example.printf("i is %d\n" % i) # This will probably be garbled because %d is interpreted by C @@ -15,21 +15,13 @@ stdout = example.stdout_stream() # Call fprintf -example.fprintf(stdout,"Hello World. I'm fprintf\n") -for i in range(0,10): - example.fprintf(stdout,"i is %d\n" % i) +example.fprintf(stdout, "Hello World. I'm fprintf\n") +for i in range(0, 10): + example.fprintf(stdout, "i is %d\n" % i) # This won't be garbled since %d is not interpreted -example.fprintf(stdout,"The value is %d\n") +example.fprintf(stdout, "The value is %d\n") # This function calls our NULL-terminated function -example.printv("Hello","World","this","is","a","test.") - - - - - - - - +example.printv("Hello", "World", "this", "is", "a", "test.") diff --git a/Examples/python/variables/Makefile b/Examples/python/variables/Makefile index 222916fa11c..26bfd946ea9 100644 --- a/Examples/python/variables/Makefile +++ b/Examples/python/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: diff --git a/Examples/python/variables/runme.py b/Examples/python/variables/runme.py index b635b985977..3388a0eba82 100644 --- a/Examples/python/variables/runme.py +++ b/Examples/python/variables/runme.py @@ -4,21 +4,21 @@ # Try to set the values of some global variables -example.cvar.ivar = 42 -example.cvar.svar = -31000 -example.cvar.lvar = 65537 -example.cvar.uivar = 123456 -example.cvar.usvar = 61000 -example.cvar.ulvar = 654321 -example.cvar.scvar = -13 -example.cvar.ucvar = 251 -example.cvar.cvar = "S" -example.cvar.fvar = 3.14159 -example.cvar.dvar = 2.1828 -example.cvar.strvar = "Hello World" -example.cvar.iptrvar= example.new_int(37) -example.cvar.ptptr = example.new_Point(37,42) -example.cvar.name = "Bill" +example.cvar.ivar = 42 +example.cvar.svar = -31000 +example.cvar.lvar = 65537 +example.cvar.uivar = 123456 +example.cvar.usvar = 61000 +example.cvar.ulvar = 654321 +example.cvar.scvar = -13 +example.cvar.ucvar = 251 +example.cvar.cvar = "S" +example.cvar.fvar = 3.14159 +example.cvar.dvar = 2.1828 +example.cvar.strvar = "Hello World" +example.cvar.iptrvar = example.new_int(37) +example.cvar.ptptr = example.new_Point(37, 42) +example.cvar.name = "Bill" # Now print out the values of the variables @@ -46,16 +46,16 @@ example.print_vars() -print "\nNow I'm going to try and modify some read only variables"; +print "\nNow I'm going to try and modify some read only variables" -print " Tring to set 'path'"; +print " Tring to set 'path'" try: example.cvar.path = "Whoa!" print "Hey, what's going on?!?! This shouldn't work" except: print "Good." -print " Trying to set 'status'"; +print " Trying to set 'status'" try: example.cvar.status = 0 print "Hey, what's going on?!?! This shouldn't work" @@ -70,6 +70,3 @@ print "The new value is" example.pt_print() print "You should see the value", example.Point_print(example.cvar.ptptr) - - - diff --git a/Examples/r/class/Makefile b/Examples/r/class/Makefile index 3e5d6a6ca31..6b4b306f328 100644 --- a/Examples/r/class/Makefile +++ b/Examples/r/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -8,7 +9,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' r_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r_cpp clean: diff --git a/Examples/r/simple/Makefile b/Examples/r/simple/Makefile index 5cc41530c47..add881898af 100644 --- a/Examples/r/simple/Makefile +++ b/Examples/r/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,7 +9,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' r_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r clean: diff --git a/Examples/ruby/class/Makefile b/Examples/ruby/class/Makefile index 516f842d7d8..0d469c6559d 100644 --- a/Examples/ruby/class/Makefile +++ b/Examples/ruby/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/constants/Makefile b/Examples/ruby/constants/Makefile index 561d5fd8443..24698f2b4c9 100644 --- a/Examples/ruby/constants/Makefile +++ b/Examples/ruby/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/ruby/enum/Makefile b/Examples/ruby/enum/Makefile index 516f842d7d8..0d469c6559d 100644 --- a/Examples/ruby/enum/Makefile +++ b/Examples/ruby/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/exception_class/Makefile b/Examples/ruby/exception_class/Makefile index 6723a2a7cef..2d4518e1137 100644 --- a/Examples/ruby/exception_class/Makefile +++ b/Examples/ruby/exception_class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/free_function/Makefile b/Examples/ruby/free_function/Makefile index 516f842d7d8..0d469c6559d 100644 --- a/Examples/ruby/free_function/Makefile +++ b/Examples/ruby/free_function/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/funcptr/Makefile b/Examples/ruby/funcptr/Makefile index 15b39cf0d57..d320c9a83b9 100644 --- a/Examples/ruby/funcptr/Makefile +++ b/Examples/ruby/funcptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/ruby/funcptr2/Makefile b/Examples/ruby/funcptr2/Makefile index 15b39cf0d57..d320c9a83b9 100644 --- a/Examples/ruby/funcptr2/Makefile +++ b/Examples/ruby/funcptr2/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/ruby/functor/Makefile b/Examples/ruby/functor/Makefile index 348bd66e36b..c7f998c147e 100644 --- a/Examples/ruby/functor/Makefile +++ b/Examples/ruby/functor/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = example INTERFACE = example.i LIBS = -lm @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/hashargs/Makefile b/Examples/ruby/hashargs/Makefile index 59a36c0dd27..2d0d943e1d8 100644 --- a/Examples/ruby/hashargs/Makefile +++ b/Examples/ruby/hashargs/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/ruby/import/Makefile b/Examples/ruby/import/Makefile index b5d06bdd735..586e4887089 100644 --- a/Examples/ruby/import/Makefile +++ b/Examples/ruby/import/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = @@ -7,14 +8,18 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' ruby_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' ruby_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/import_template/Makefile b/Examples/ruby/import_template/Makefile index b5d06bdd735..586e4887089 100644 --- a/Examples/ruby/import_template/Makefile +++ b/Examples/ruby/import_template/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = @@ -7,14 +8,18 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' ruby_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' ruby_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/java/Makefile b/Examples/ruby/java/Makefile index 7d611abd23b..bec5e1844ff 100644 --- a/Examples/ruby/java/Makefile +++ b/Examples/ruby/java/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: Example.class Example.h - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ CXXSHARED="gcj -fpic -shared Example.class" LIBS="-lstdc++" DEFS='' ruby_cpp diff --git a/Examples/ruby/mark_function/Makefile b/Examples/ruby/mark_function/Makefile index 516f842d7d8..0d469c6559d 100644 --- a/Examples/ruby/mark_function/Makefile +++ b/Examples/ruby/mark_function/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/mark_function/runme.rb b/Examples/ruby/mark_function/runme.rb index 6d84ee88fcf..a7c5b042e2f 100644 --- a/Examples/ruby/mark_function/runme.rb +++ b/Examples/ruby/mark_function/runme.rb @@ -9,7 +9,7 @@ zoo.add_animal(tiger1) # unset variables to force gc - tiger = nil + tiger1 = nil end GC.start @@ -20,4 +20,4 @@ # Call a method to verify the animal is still valid and not gc'ed if tiger2.get_name != "tiger1" raise RuntimeError, "Wrong animal name" -end +end diff --git a/Examples/ruby/multimap/Makefile b/Examples/ruby/multimap/Makefile index 15b39cf0d57..d320c9a83b9 100644 --- a/Examples/ruby/multimap/Makefile +++ b/Examples/ruby/multimap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/ruby/operator/Makefile b/Examples/ruby/operator/Makefile index bdcf52646a4..53241eead62 100644 --- a/Examples/ruby/operator/Makefile +++ b/Examples/ruby/operator/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/overloading/Makefile b/Examples/ruby/overloading/Makefile index 516f842d7d8..0d469c6559d 100644 --- a/Examples/ruby/overloading/Makefile +++ b/Examples/ruby/overloading/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/pointer/Makefile b/Examples/ruby/pointer/Makefile index 15b39cf0d57..d320c9a83b9 100644 --- a/Examples/ruby/pointer/Makefile +++ b/Examples/ruby/pointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/ruby/reference/Makefile b/Examples/ruby/reference/Makefile index 516f842d7d8..0d469c6559d 100644 --- a/Examples/ruby/reference/Makefile +++ b/Examples/ruby/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/simple/Makefile b/Examples/ruby/simple/Makefile index 15b39cf0d57..d320c9a83b9 100644 --- a/Examples/ruby/simple/Makefile +++ b/Examples/ruby/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/ruby/std_vector/Makefile b/Examples/ruby/std_vector/Makefile index 370bd8fb6d1..636a0f19ffe 100644 --- a/Examples/ruby/std_vector/Makefile +++ b/Examples/ruby/std_vector/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/template/Makefile b/Examples/ruby/template/Makefile index 370bd8fb6d1..636a0f19ffe 100644 --- a/Examples/ruby/template/Makefile +++ b/Examples/ruby/template/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: diff --git a/Examples/ruby/value/Makefile b/Examples/ruby/value/Makefile index 15b39cf0d57..d320c9a83b9 100644 --- a/Examples/ruby/value/Makefile +++ b/Examples/ruby/value/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/ruby/variables/Makefile b/Examples/ruby/variables/Makefile index 15b39cf0d57..d320c9a83b9 100644 --- a/Examples/ruby/variables/Makefile +++ b/Examples/ruby/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = example INTERFACE = example.i @@ -8,11 +9,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: diff --git a/Examples/s-exp/uffi.lisp b/Examples/s-exp/uffi.lisp index 253f85abae0..aea9a1405cf 100644 --- a/Examples/s-exp/uffi.lisp +++ b/Examples/s-exp/uffi.lisp @@ -15,7 +15,7 @@ (defvar *swig-source-directory* #p"/home/mkoeppe/s/swig1.3/") -(defvar *swig-program* (merge-pathnames "preinst-swig" *swig-source-directory*)) +(defvar *swig-program* (merge-pathnames "swig" *swig-source-directory*)) (defun run-swig (swig-interface-file-name &key directory-search-list module ignore-errors c++) diff --git a/Examples/scilab/check.list b/Examples/scilab/check.list new file mode 100644 index 00000000000..0bcf457c27c --- /dev/null +++ b/Examples/scilab/check.list @@ -0,0 +1,16 @@ +# see top-level Makefile.in +class +constants +contract +enum +funcptr +matrix +matrix2 +pointer +simple +std_list +std_vector +struct +template +variables + diff --git a/Examples/scilab/class/Makefile b/Examples/scilab/class/Makefile new file mode 100644 index 00000000000..40c97a5f7be --- /dev/null +++ b/Examples/scilab/class/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/class/example.cxx b/Examples/scilab/class/example.cxx new file mode 100644 index 00000000000..0463045196a --- /dev/null +++ b/Examples/scilab/class/example.cxx @@ -0,0 +1,28 @@ +/* File : example.cxx */ + +#include "example.h" +#define M_PI 3.14159265358979323846 + +/* Move the shape to a new location */ +void Shape::move(double dx, double dy) { + x += dx; + y += dy; +} + +int Shape::nshapes = 0; + +double Circle::area() { + return M_PI*radius*radius; +} + +double Circle::perimeter() { + return 2*M_PI*radius; +} + +double Square::area() { + return width*width; +} + +double Square::perimeter() { + return 4*width; +} diff --git a/Examples/scilab/class/example.h b/Examples/scilab/class/example.h new file mode 100644 index 00000000000..0dff185b265 --- /dev/null +++ b/Examples/scilab/class/example.h @@ -0,0 +1,34 @@ +/* File : example.h */ + +class Shape { +public: + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + } + double x, y; + void move(double dx, double dy); + virtual double area() = 0; + virtual double perimeter() = 0; + static int nshapes; +}; + +class Circle : public Shape { +private: + double radius; +public: + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); +}; + +class Square : public Shape { +private: + double width; +public: + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); +}; diff --git a/Examples/scilab/class/example.i b/Examples/scilab/class/example.i new file mode 100644 index 00000000000..fbdf7249fd2 --- /dev/null +++ b/Examples/scilab/class/example.i @@ -0,0 +1,9 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" diff --git a/Examples/scilab/class/runme.sci b/Examples/scilab/class/runme.sci new file mode 100644 index 00000000000..236e541107e --- /dev/null +++ b/Examples/scilab/class/runme.sci @@ -0,0 +1,52 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + +// ----- Object creation ----- + +printf("Creating some objects:\n"); +c = new_Circle(10) +s = new_Square(10) + +// ----- Access a static member ----- + +printf("\nA total of %i shapes were created\n", Shape_nshapes_get()); + +// ----- Member data access ----- + +// Set the location of the object + +Shape_x_set(c, 20); +Shape_y_set(c, 30); + +Shape_x_set(s, -10); +Shape_y_set(s, 5); + +printf("\nHere is their current position:\n"); +printf(" Circle = (%f, %f)\n", Shape_x_get(c), Shape_y_get(c)); +printf(" Square = (%f, %f)\n", Shape_x_get(s), Shape_y_get(s)); + +// ----- Call some methods ----- + +printf("\nHere are some properties of the shapes:\n"); +function print_shape(o) + printf(" area = %f\n", Shape_area(o)); + printf(" perimeter = %f\n", Shape_perimeter(o)); +endfunction +print_shape(c); +print_shape(s); + +printf("\nGuess I will clean up now\n"); + +// Note: this invokes the virtual destructor +delete_Circle(c); +delete_Square(s); + +printf("%i shapes remain\n", Shape_nshapes_get()); +printf("Goodbye\n"); + +exit diff --git a/Examples/scilab/constants/Makefile b/Examples/scilab/constants/Makefile new file mode 100644 index 00000000000..d47674b3756 --- /dev/null +++ b/Examples/scilab/constants/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/constants/example.i b/Examples/scilab/constants/example.i new file mode 100644 index 00000000000..1172a4edc62 --- /dev/null +++ b/Examples/scilab/constants/example.i @@ -0,0 +1,30 @@ +/* File : example.i */ +%module example + +/* Wraps enums and constants as Scilab variables (instead of functions) */ +%scilabconst(1); + +/* A few preprocessor macros */ + +#define ICONST 42 +#define FCONST 2.1828 +#define CCONST 'x' +#define CCONST2 '\n' +#define SCONST "Hello World" +#define SCONST2 "\"Hello World\"" + +/* This should work just fine */ +#define EXPR ICONST + 3*(FCONST) + +/* This shouldn't do anything */ +#define EXTERN extern + +/* Neither should this (BAR isn't defined) */ +#define FOO (ICONST + BAR) + +/* The following directives also produce constants */ + +%constant int iconst = 37; +%constant double fconst = 3.14; + + diff --git a/Examples/scilab/constants/runme.sci b/Examples/scilab/constants/runme.sci new file mode 100644 index 00000000000..cfb28b6b4d5 --- /dev/null +++ b/Examples/scilab/constants/runme.sci @@ -0,0 +1,18 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end +example_Init(); + +printf("\nTest constants\n"); +printf("ICONST = %i (should be 42)\n", ICONST); +printf("FCONST = %5.4f (should be 2.1828)\n", FCONST); +printf("SCONST = ''%s'' (should be ''Hello World'')\n", SCONST); +printf("EXPR = %5.4f (should be 48.5484)\n", EXPR); +printf("iconst = %i (should be 37)\n", iconst); +printf("fconst = %3.2f (should be 3.14)\n", fconst); + +exit diff --git a/Examples/scilab/contract/Makefile b/Examples/scilab/contract/Makefile new file mode 100644 index 00000000000..6604d191bea --- /dev/null +++ b/Examples/scilab/contract/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = example.c +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/contract/example.c b/Examples/scilab/contract/example.c new file mode 100644 index 00000000000..1a644543fad --- /dev/null +++ b/Examples/scilab/contract/example.c @@ -0,0 +1,23 @@ +/* File : example.c */ + +/* A global variable */ +double Foo = 3.0; + +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + +int fact(int n) { + if (n <= 0) return 1; + return n*fact(n-1); +} + + diff --git a/Examples/scilab/contract/example.i b/Examples/scilab/contract/example.i new file mode 100644 index 00000000000..8fd1a80af72 --- /dev/null +++ b/Examples/scilab/contract/example.i @@ -0,0 +1,21 @@ +/* File : example.i */ +%module example + +%contract gcd(int x, int y) { +require: + x >= 0; + y >= 0; +} + +%contract fact(int n) { +require: + n >= 0; +ensure: + fact >= 1; +} + +%inline %{ +extern int gcd(int x, int y); +extern int fact(int n); +extern double Foo; +%} diff --git a/Examples/scilab/contract/runme.sci b/Examples/scilab/contract/runme.sci new file mode 100644 index 00000000000..718424b29fd --- /dev/null +++ b/Examples/scilab/contract/runme.sci @@ -0,0 +1,46 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + + +// Call our gcd() function +x = 42; +y = 105; +g = gcd(x, y); +printf("The gcd of %d and %d is %d\n", x, y, g); + +// Call our fact() function +x = 5; +g = fact(x); +printf("The fact of %d is %d\n", x, g); + +// Manipulate the Foo global variable + +// Output its current value +printf("Foo = %f\n", Foo_get()); + +// Change its value +Foo_set(3.1415926); + +// See if the change took effect +printf("Foo = %f\n", Foo_get()); + +// Check error messages when violating contract +ierr = execstr('gcd(-42, 105)', 'errcatch'); +if ierr <> 20003 then + error("gcd(-42, 105) must provoke a RunTimeError") +end + +ierr = execstr('fact(-4)', 'errcatch'); +if ierr <> 20003 then + error("fact(-4) must provoke a RunTimeError") +end + +exit + + + diff --git a/Examples/scilab/enum/Makefile b/Examples/scilab/enum/Makefile new file mode 100644 index 00000000000..40c97a5f7be --- /dev/null +++ b/Examples/scilab/enum/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/enum/example.cxx b/Examples/scilab/enum/example.cxx new file mode 100644 index 00000000000..6785e57acd4 --- /dev/null +++ b/Examples/scilab/enum/example.cxx @@ -0,0 +1,37 @@ +/* File : example.c */ + +#include "example.h" +#include + +void Foo::enum_test(speed s) { + if (s == IMPULSE) { + printf("IMPULSE speed\n"); + } else if (s == WARP) { + printf("WARP speed\n"); + } else if (s == LUDICROUS) { + printf("LUDICROUS speed\n"); + } else { + printf("Unknown speed\n"); + } +} + +void enum_test(color c, Foo::speed s) { + if (c == RED) { + printf("color = RED, "); + } else if (c == BLUE) { + printf("color = BLUE, "); + } else if (c == GREEN) { + printf("color = GREEN, "); + } else { + printf("color = Unknown color!, "); + } + if (s == Foo::IMPULSE) { + printf("speed = IMPULSE speed\n"); + } else if (s == Foo::WARP) { + printf("speed = WARP speed\n"); + } else if (s == Foo::LUDICROUS) { + printf("speed = LUDICROUS speed\n"); + } else { + printf("speed = Unknown speed!\n"); + } +} diff --git a/Examples/scilab/enum/example.h b/Examples/scilab/enum/example.h new file mode 100644 index 00000000000..525d62afc57 --- /dev/null +++ b/Examples/scilab/enum/example.h @@ -0,0 +1,13 @@ +/* File : example.h */ + +enum color { RED, BLUE, GREEN }; + +class Foo { + public: + Foo() { } + enum speed { IMPULSE, WARP, LUDICROUS }; + void enum_test(speed s); +}; + +void enum_test(color c, Foo::speed s); + diff --git a/Examples/scilab/enum/example.i b/Examples/scilab/enum/example.i new file mode 100644 index 00000000000..a9c71c5abc7 --- /dev/null +++ b/Examples/scilab/enum/example.i @@ -0,0 +1,10 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +%include "example.h" + + diff --git a/Examples/scilab/enum/runme.sci b/Examples/scilab/enum/runme.sci new file mode 100644 index 00000000000..0895fc340ac --- /dev/null +++ b/Examples/scilab/enum/runme.sci @@ -0,0 +1,36 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end +example_Init(); + +printf("\nTest enums\n"); +printf("*** color ***\n"); +printf(" RED_get() = %i\n", RED_get()); +printf(" BLUE_get() = %i\n", BLUE_get()); +printf(" GREEN_get() = %i\n", GREEN_get()); + +printf("\n*** Foo::speed ***\n") +printf(" Foo_IMPULSE = %i\n", Foo_IMPULSE_get()); +printf(" Foo_WARP = %i\n", Foo_WARP_get()); +printf(" Foo_LUDICROUS = %i\n", Foo_LUDICROUS_get()); + +printf("\nTest enums as argument of functions\n"); + +enum_test(RED_get(), Foo_IMPULSE_get()); +enum_test(BLUE_get(), Foo_WARP_get()); +enum_test(GREEN_get(), Foo_LUDICROUS_get()); +enum_test(1234, 5678); + +printf("\nTest enums as argument of class methods\n"); + +f = new_Foo(); +Foo_enum_test(f, Foo_IMPULSE_get()); +Foo_enum_test(f, Foo_WARP_get()); +Foo_enum_test(f, Foo_LUDICROUS_get()); +delete_Foo(f); + +exit diff --git a/Examples/scilab/funcptr/Makefile b/Examples/scilab/funcptr/Makefile new file mode 100644 index 00000000000..6604d191bea --- /dev/null +++ b/Examples/scilab/funcptr/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = example.c +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/funcptr/example.c b/Examples/scilab/funcptr/example.c new file mode 100644 index 00000000000..5c4a3dabfe1 --- /dev/null +++ b/Examples/scilab/funcptr/example.c @@ -0,0 +1,19 @@ +/* File : example.c */ + +int do_op(int a, int b, int (*op)(int,int)) { + return (*op)(a,b); +} + +int add(int a, int b) { + return a+b; +} + +int sub(int a, int b) { + return a-b; +} + +int mul(int a, int b) { + return a*b; +} + +int (*funcvar)(int,int) = add; diff --git a/Examples/scilab/funcptr/example.h b/Examples/scilab/funcptr/example.h new file mode 100644 index 00000000000..9936e24fc9f --- /dev/null +++ b/Examples/scilab/funcptr/example.h @@ -0,0 +1,9 @@ +/* file: example.h */ + +extern int do_op(int,int, int (*op)(int,int)); +extern int add(int,int); +extern int sub(int,int); +extern int mul(int,int); + +extern int (*funcvar)(int,int); + diff --git a/Examples/scilab/funcptr/example.i b/Examples/scilab/funcptr/example.i new file mode 100644 index 00000000000..e8af50e6ff4 --- /dev/null +++ b/Examples/scilab/funcptr/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +/* Wrap a function taking a pointer to a function */ +extern int do_op(int a, int b, int (*op)(int, int)); + +extern int (*funcvar)(int,int); + diff --git a/Examples/scilab/funcptr/runme.sci b/Examples/scilab/funcptr/runme.sci new file mode 100644 index 00000000000..d3cbed394e9 --- /dev/null +++ b/Examples/scilab/funcptr/runme.sci @@ -0,0 +1,22 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + +a = 37 +b = 42 + +// Now call our C function with a bunch of callbacks + +printf("Trying some C callback functions\n"); +printf(" a = %i\n", a); +printf(" b = %i\n", b); +printf(" ADD(a,b) = %i\n", do_op(a,b,funcvar_get())); + +exit + + + diff --git a/Examples/scilab/matrix/Makefile b/Examples/scilab/matrix/Makefile new file mode 100644 index 00000000000..6604d191bea --- /dev/null +++ b/Examples/scilab/matrix/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = example.c +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/matrix/example.c b/Examples/scilab/matrix/example.c new file mode 100644 index 00000000000..6ce10098b59 --- /dev/null +++ b/Examples/scilab/matrix/example.c @@ -0,0 +1,61 @@ +/* FILE : matrix.c : some simple 4x4 matrix operations */ +#include +#include + +double **new_matrix() { + + int i; + double **M; + + M = (double **) malloc(4*sizeof(double *)); + M[0] = (double *) malloc(16*sizeof(double)); + + for (i = 0; i < 4; i++) { + M[i] = M[0] + 4*i; + } + return M; +} + +void destroy_matrix(double **M) { + + free(M[0]); + free(M); + +} + +void print_matrix(double **M) { + + int i,j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + printf("%10g ", M[i][j]); + } + printf("\n"); + } + +} + +void mat_mult(double **m1, double **m2, double **m3) { + + int i,j,k; + double temp[4][4]; + + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) { + temp[i][j] = 0; + for (k = 0; k < 4; k++) + temp[i][j] += m1[i][k]*m2[k][j]; + } + + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + m3[i][j] = temp[i][j]; +} + + + + + + + diff --git a/Examples/scilab/matrix/example.i b/Examples/scilab/matrix/example.i new file mode 100644 index 00000000000..c930e92f5d2 --- /dev/null +++ b/Examples/scilab/matrix/example.i @@ -0,0 +1,36 @@ +%module example +// FILE : matrix.i + +%{ + +void set_m(double **M, int i, int j, double val) { + M[i][j] = val; +} + +double get_m(double **M, int i, int j) { + return M[i][j]; +} +%} + +%inline { +/*** Matrix Operations ***/ + +extern double **new_matrix(); +/* Creates a new matrix and returns a pointer to it */ + +extern void destroy_matrix(double **M); +/* Destroys the matrix M */ + +extern void print_matrix(double **M); +/* Prints out the matrix M */ + +extern void set_m(double **M, int i, int j, double val); +/* Sets M[i][j] = val*/ + +extern double get_m(double **M, int i, int j); +/* Returns M[i][j] */ + +extern void mat_mult(double **a, double **b, double **c); +/* Multiplies matrix a by b and places the result in c*/ + +} diff --git a/Examples/scilab/matrix/runme.sci b/Examples/scilab/matrix/runme.sci new file mode 100644 index 00000000000..26943b1841d --- /dev/null +++ b/Examples/scilab/matrix/runme.sci @@ -0,0 +1,43 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + +// create a new matrix +x = new_matrix(); +for i = 0 : 3; + for j = 0 : 3; + set_m(x, i, j, i+j); + end; +end; + +// print the matrix +print_matrix(x); + +// another matrix +y = new_matrix(); + for i = 0 : 3; + for j = 0 : 3; + set_m(y, i, j, i-j); + end; + end; + +// print the matrix +print_matrix(y); + +// mat_mult the two matrix, and the result is stored in a new matrix +z = new_matrix(); + +mat_mult(x, y, z); + +print_matrix(z); + +//destroy the matrix +destroy_matrix(x); +destroy_matrix(y); +destroy_matrix(z); + +exit diff --git a/Examples/scilab/matrix2/Makefile b/Examples/scilab/matrix2/Makefile new file mode 100644 index 00000000000..6604d191bea --- /dev/null +++ b/Examples/scilab/matrix2/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = example.c +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/matrix2/example.c b/Examples/scilab/matrix2/example.c new file mode 100644 index 00000000000..476067df916 --- /dev/null +++ b/Examples/scilab/matrix2/example.c @@ -0,0 +1,118 @@ +#include +#include +#include + + +// Double matrix functions + +double sumDoubleMatrix(double *inputMatrix, int nbRow, int nbCol) +{ + int i; + double total = 0.0; + for (i=0; i myMatrix=[ 103 3 1 12;0 0 2043 1]; + * --> sumitems(myMatrix); + * 32 + */ + double B[] = {1,3,4,9,2,8,3,2}; /* Declare the matrix */ + int rowB = 2, colB = 4; + printf("sumitems: %6.2f\n",sumitems(B, rowB, colB)); + + +/** + * --> myOtherMatrix=generateValues(); + * --> size(myOtherMatrix); + */ + int numberRow, numberCol, i; + double * matrix=getValues(&numberRow, &numberCol); + printf("Matrix of size [%d,%d]",numberRow, numberCol); + for(i=0; i < numberRow*numberCol; i++) + { + printf("A[%d] = %5.2f\n",i,matrix[i]); + } +} diff --git a/Examples/scilab/matrix2/runme.sci b/Examples/scilab/matrix2/runme.sci new file mode 100644 index 00000000000..0af7df4e7c8 --- /dev/null +++ b/Examples/scilab/matrix2/runme.sci @@ -0,0 +1,51 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + +// Test lib double matrix functions +disp("Call lib function getDoubleMatrix()"); +doubleMatrix = getDoubleMatrix(); +disp(doubleMatrix); + +disp("Call lib function sumDoubleMatrix()"); +s = sumDoubleMatrix(doubleMatrix); +disp(s); + +disp("Call lib function squareDoubleMatrix()"); +sqrd = squareDoubleMatrix(doubleMatrix); +disp(sqrd); + + +// Test lib integer matrix functions + +disp("Call lib function getIntegerMatrix()"); +integerMatrix = getIntegerMatrix(); +disp(integerMatrix); + +disp("Call lib function sumIntegerMatrix()"); +s = sumIntegerMatrix(integerMatrix); +disp(s); + +disp("Call lib function squareIntegerMatrix()"); +sqri = squareIntegerMatrix(integerMatrix); +disp(sqri); + + +// Test lib string matrix functions + +disp("Call lib function getStringVector()"); +stringVector = getStringVector(); +disp(stringVector); + +disp("Call lib function concatStringVector()"); +stringVector2 = concatStringVector(stringVector); +disp(stringVector2); + +exit + + + diff --git a/Examples/scilab/pointer/Makefile b/Examples/scilab/pointer/Makefile new file mode 100644 index 00000000000..9ce2685bfc3 --- /dev/null +++ b/Examples/scilab/pointer/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = example.c +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/pointer/example.c b/Examples/scilab/pointer/example.c new file mode 100644 index 00000000000..b877d9a5bfc --- /dev/null +++ b/Examples/scilab/pointer/example.c @@ -0,0 +1,16 @@ +/* File : example.c */ + +void add(int *x, int *y, int *result) { + *result = *x + *y; +} + +void sub(int *x, int *y, int *result) { + *result = *x - *y; +} + +int divide(int n, int d, int *r) { + int q; + q = n/d; + *r = n - q*d; + return q; +} diff --git a/Examples/scilab/pointer/example.i b/Examples/scilab/pointer/example.i new file mode 100644 index 00000000000..a8ac79499f8 --- /dev/null +++ b/Examples/scilab/pointer/example.i @@ -0,0 +1,30 @@ +/* File : example.i */ +%module example + +%{ +extern void add(int *, int *, int *); +extern void sub(int *, int *, int *); +extern int divide(int, int, int *); +%} + +/* This example illustrates a couple of different techniques + for manipulating C pointers */ + +/* First we'll use the pointer library */ +extern void add(int *x, int *y, int *result); +%include cpointer.i +%pointer_functions(int, intp); + +/* Next we'll use some typemaps */ + +%include typemaps.i +extern void sub(int *INPUT, int *INPUT, int *OUTPUT); + +/* Next we'll use typemaps and the %apply directive */ + +%apply int *OUTPUT { int *r }; +extern int divide(int n, int d, int *r); + + + + diff --git a/Examples/scilab/pointer/runme.sci b/Examples/scilab/pointer/runme.sci new file mode 100644 index 00000000000..3400ab3e5d8 --- /dev/null +++ b/Examples/scilab/pointer/runme.sci @@ -0,0 +1,47 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + +// First create some objects using the pointer library. +printf("Testing the pointer library\n") +a = new_intp(); +b = new_intp(); +c = new_intp(); // Memory for result + +intp_assign(a, 37); +intp_assign(b, 42); + +printf(" a = %d\n", intp_value(a)); +printf(" b = %d\n", intp_value(b)); +printf(" c = %d\n", intp_value(c)); + +// Call the add() function with some pointers +add(a, b, c); + +// Now get the result +r = intp_value(c); +printf(" 37 + 42 = %d\n", r); + +// Clean up the pointers +delete_intp(a); +delete_intp(b); +delete_intp(c); + +// Now try the typemap library +// This should be much easier. Now how it is no longer +// necessary to manufacture pointers. +printf("Trying the typemap library\n"); +r = sub(37, 42); +printf(" 37 - 42 = %d\n", r); + +// Now try the version with multiple return values +printf("Testing multiple return values\n"); +[q, r] = divide(42, 37); +printf(" 42/37 = %d remainder %d\n", q, r); + +exit + diff --git a/Examples/scilab/simple/Makefile b/Examples/scilab/simple/Makefile new file mode 100644 index 00000000000..6604d191bea --- /dev/null +++ b/Examples/scilab/simple/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = example.c +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/simple/example.c b/Examples/scilab/simple/example.c new file mode 100644 index 00000000000..1c2af789ce3 --- /dev/null +++ b/Examples/scilab/simple/example.c @@ -0,0 +1,18 @@ +/* File : example.c */ + +/* A global variable */ +double Foo = 3.0; + +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + + diff --git a/Examples/scilab/simple/example.i b/Examples/scilab/simple/example.i new file mode 100644 index 00000000000..24093b9bf0a --- /dev/null +++ b/Examples/scilab/simple/example.i @@ -0,0 +1,7 @@ +/* File : example.i */ +%module example + +%inline %{ +extern int gcd(int x, int y); +extern double Foo; +%} diff --git a/Examples/scilab/simple/runme.sci b/Examples/scilab/simple/runme.sci new file mode 100644 index 00000000000..ed8b0f6c37a --- /dev/null +++ b/Examples/scilab/simple/runme.sci @@ -0,0 +1,29 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + +// Call our gcd() function + +x = 42; +y = 105; +g = gcd(x,y); +printf("The gcd of %d and %d is %d\n",x,y,g); + +// Manipulate the Foo global variable + +// Get its default value (see in example.c) +defaultValue = Foo_get() +if defaultValue <> 3 then pause; end + +// Change its value +Foo_set(3.1415926) + +// See if the change took effect +if Foo_get() <> 3.1415926 then pause,end + +exit + diff --git a/Examples/scilab/std_list/Makefile b/Examples/scilab/std_list/Makefile new file mode 100644 index 00000000000..40c97a5f7be --- /dev/null +++ b/Examples/scilab/std_list/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/std_list/example.cxx b/Examples/scilab/std_list/example.cxx new file mode 100644 index 00000000000..e58d6a38bad --- /dev/null +++ b/Examples/scilab/std_list/example.cxx @@ -0,0 +1,61 @@ +/* File : example.cpp */ + +#include "example.h" + +#include +#include +#include +#include +#include + + +template +std::list concat_list(const std::list list, const std::list other_list) +{ + std::list out_list(list); + out_list.insert(out_list.end(), other_list.begin(), other_list.end()); + return out_list; +} + +// int lists + +std::list create_integer_list(const int rangemin, const int rangemax) +{ + std::list out_list; + for (int i = rangemin; i <= rangemax; i++) + { + out_list.push_back(i); + } + return out_list; +} + +int sum_integer_list(const std::list& list) +{ + return std::accumulate(list.begin(), list.end(), 0); +} + +std::list concat_integer_list(const std::list list, const std::list other_list) +{ + return concat_list(list, other_list); +} + +// string lists + +std::list create_string_list(const char* svalue) +{ + std::list out_list; + std::string str(svalue); + + std::istringstream iss(str); + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::inserter >(out_list, out_list.begin())); + + return out_list; +} + +std::list concat_string_list(const std::list list, const std::list other_list) +{ + return concat_list(list, other_list); +} + diff --git a/Examples/scilab/std_list/example.h b/Examples/scilab/std_list/example.h new file mode 100644 index 00000000000..769627e080b --- /dev/null +++ b/Examples/scilab/std_list/example.h @@ -0,0 +1,14 @@ +/* File : example.h */ + +#include +#include + + +// integer lists +std::list create_integer_list(const int size, const int value); +int sum_integer_list(const std::list& list); +std::list concat_integer_list(const std::list list, const std::list other_list); + +// string lists +std::list create_string_list(const char* value); +std::list concat_string_list(const std::list list, const std::list other_list); diff --git a/Examples/scilab/std_list/example.i b/Examples/scilab/std_list/example.i new file mode 100644 index 00000000000..dbe2a73e46e --- /dev/null +++ b/Examples/scilab/std_list/example.i @@ -0,0 +1,19 @@ +/* File : example.i */ + +%module example + +%{ +#include "example.h" +%} + +%include stl.i +%include std_list.i + +/* instantiate the required template specializations */ +namespace std +{ + %template(IntList) list; + %template(StringList) list; +} + +%include "example.h" diff --git a/Examples/scilab/std_list/runme.sci b/Examples/scilab/std_list/runme.sci new file mode 100644 index 00000000000..e4c04b029f5 --- /dev/null +++ b/Examples/scilab/std_list/runme.sci @@ -0,0 +1,39 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end +example_Init(); + +// This example shows how to use C++ fonctions with STL lists arguments +// Here, STL lists are converted from/to Scilab matrices (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS is not defined) + +// integer lists + +disp("Example of passing matrices of int as list arguments of C++ functions."); +disp("get a list of int {1...4} from create_integer_list():"); +is = create_integer_list(1, 4); +disp(is); +disp("get the sum of this list elements with sum_integer_list():") +sum = sum_integer_list(is); +disp(is); +is2 = create_integer_list(3, 6); +disp("concat this list with the list of int {3...6} with concat_integer_list():"); +is3 = concat_integer_list(is, is2); +disp(is3); + +// string lists + +disp("Example of passing matrices of string as list arguments of C++ functions."); +disp("get a list of string {''aa'', ''bb'', ''cc'', ''dd''} with create_string_list():"); +ss = create_string_list("aa bb cc dd"); +disp(ss); +ss2 = create_string_list("cc dd ee ff"); +disp("concat this list with the list of string {''cc'', ''dd'', ''ee'', ''ff''} with concat_string_list():"); +ss3 = concat_string_list(ss, ss2); +disp(ss3); + +exit + diff --git a/Examples/scilab/std_vector/Makefile b/Examples/scilab/std_vector/Makefile new file mode 100644 index 00000000000..490ac73b568 --- /dev/null +++ b/Examples/scilab/std_vector/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +CXXSRCS = +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/std_vector/example.h b/Examples/scilab/std_vector/example.h new file mode 100644 index 00000000000..4f0dac70d8c --- /dev/null +++ b/Examples/scilab/std_vector/example.h @@ -0,0 +1,25 @@ +/* File : example.h */ + +#include +#include +#include +#include + +double average(std::vector v) { + return std::accumulate(v.begin(),v.end(),0.0)/v.size(); +} + +std::vector half(const std::vector& v) { + std::vector w(v); + for (unsigned int i=0; i& v) { + // would you believe this is the same as the above? + std::transform(v.begin(),v.end(),v.begin(), + std::bind2nd(std::divides(),2.0)); +} + + diff --git a/Examples/scilab/std_vector/example.i b/Examples/scilab/std_vector/example.i new file mode 100644 index 00000000000..1ba9e927e33 --- /dev/null +++ b/Examples/scilab/std_vector/example.i @@ -0,0 +1,19 @@ +/* File : example.i */ +%module example + +%warnfilter(SWIGWARN_SCILAB_TRUNCATED_NAME) std::vector::get_allocator; + +%{ +#include "example.h" +%} + +%include stl.i +/* instantiate the required template specializations */ +namespace std { + %template(IntVector) vector; + %template(DoubleVector) vector; +} + +/* Let's just grab the original header file here */ +%include "example.h" + diff --git a/Examples/scilab/std_vector/runme.sci b/Examples/scilab/std_vector/runme.sci new file mode 100644 index 00000000000..3e569454c6a --- /dev/null +++ b/Examples/scilab/std_vector/runme.sci @@ -0,0 +1,37 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end +example_Init(); + + +disp(mean([1,2,3,4])); + +// ... or a wrapped std::vector + +v = new_IntVector(); +for i = 1:4 + IntVector_push_back(v, i); +end; +disp(average(v)); + + +// half will return a Scilab matrix. +// Call it with a Scilab matrix... + +disp(half([1.0, 1.5, 2.0, 2.5, 3.0])); + + +// ... or a wrapped std::vector + +v = new_DoubleVector(); +for i = 1:4 + DoubleVector_push_back(v, i); +end; +disp(half(v)); + +exit + diff --git a/Examples/scilab/struct/Makefile b/Examples/scilab/struct/Makefile new file mode 100644 index 00000000000..9f8b7e89176 --- /dev/null +++ b/Examples/scilab/struct/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/struct/example.i b/Examples/scilab/struct/example.i new file mode 100644 index 00000000000..af2cd3f4a9b --- /dev/null +++ b/Examples/scilab/struct/example.i @@ -0,0 +1,11 @@ +%module example + +%rename(Bar) Foo; + +%inline %{ +typedef struct { + int x; +} Foo; + +%} + diff --git a/Examples/scilab/struct/runme.sci b/Examples/scilab/struct/runme.sci new file mode 100644 index 00000000000..4d47ef0dcc8 --- /dev/null +++ b/Examples/scilab/struct/runme.sci @@ -0,0 +1,18 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + +// Test use of a struct (Bar) + +a = new_Bar(); + +Bar_x_set(a, 100); +printf("a.x = %d (Should be 100)\n", Bar_x_get(a)); + +delete_Bar(a); + +exit diff --git a/Examples/scilab/template/Makefile b/Examples/scilab/template/Makefile new file mode 100644 index 00000000000..490ac73b568 --- /dev/null +++ b/Examples/scilab/template/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +CXXSRCS = +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/template/example.h b/Examples/scilab/template/example.h new file mode 100644 index 00000000000..7401df650a0 --- /dev/null +++ b/Examples/scilab/template/example.h @@ -0,0 +1,32 @@ +/* File : example.h */ + +// Some template definitions + +template T max(T a, T b) { return a>b ? a : b; } + +template class vector { + T *v; + int sz; + public: + vector(int _sz) { + v = new T[_sz]; + sz = _sz; + } + T &get(int index) { + return v[index]; + } + void set(int index, T &val) { + v[index] = val; + } +#ifdef SWIG + %extend { + T getitem(int index) { + return $self->get(index); + } + void setitem(int index, T val) { + $self->set(index,val); + } + } +#endif +}; + diff --git a/Examples/scilab/template/example.i b/Examples/scilab/template/example.i new file mode 100644 index 00000000000..8f94c4da132 --- /dev/null +++ b/Examples/scilab/template/example.i @@ -0,0 +1,17 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" + +/* Now instantiate some specific template declarations */ + +%template(maxint) max; +%template(maxdouble) max; +%template(vecint) vector; +%template(vecdouble) vector; + diff --git a/Examples/scilab/template/runme.sci b/Examples/scilab/template/runme.sci new file mode 100644 index 00000000000..35ca9d1c2f9 --- /dev/null +++ b/Examples/scilab/template/runme.sci @@ -0,0 +1,45 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end +example_Init(); + +// Call some templated functions +printf("maxint(3, 7) = %i\n", maxint(3, 7)); +printf("maxdouble(3.14, 2.18) = %3.2f\n", maxdouble(3.14, 2.18)); + +// Create some class + +iv = new_vecint(100); +dv = new_vecdouble(1000); + +for i = 0:100 + vecint_setitem(iv, i, 2*i); +end + +for i = 0:100 + vecdouble_setitem(dv, i, 1.0/(i+1)); +end + +isum = 0 +for i = 0:100 + isum = isum + vecint_getitem(iv, i); +end + +printf("isum = %i\n", isum); + +dsum = 0 +for i = 0:100 + dsum = dsum + vecdouble_getitem(dv, i); +end + +printf("dsum = %3.2f\n", dsum); + +delete_vecint(iv); +delete_vecdouble(dv); + +exit + diff --git a/Examples/scilab/variables/Makefile b/Examples/scilab/variables/Makefile new file mode 100644 index 00000000000..6604d191bea --- /dev/null +++ b/Examples/scilab/variables/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +SRCS = example.c +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean diff --git a/Examples/scilab/variables/example.c b/Examples/scilab/variables/example.c new file mode 100644 index 00000000000..9f88d90a41a --- /dev/null +++ b/Examples/scilab/variables/example.c @@ -0,0 +1,95 @@ +/* File : example.c */ + +/* I'm a file containing some C global variables */ + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +#include +#include +#include "example.h" + +int ivar = 0; +short svar = 0; +long lvar = 0; +unsigned int uivar = 0; +unsigned short usvar = 0; +unsigned long ulvar = 0; +signed char scvar = 0; +unsigned char ucvar = 0; +char cvar = 0; +float fvar = 0; +double dvar = 0; +char *strvar = 0; +const char cstrvar[] = "Goodbye"; +int *iptrvar = 0; +char name[256] = "Dave"; +char path[256] = "/home/beazley"; + + +/* Global variables involving a structure */ +Point *ptptr = 0; +Point pt = { 10, 20 }; + +/* A variable that we will make read-only in the interface */ +int status = 1; + +/* A debugging function to print out their values */ + +void print_vars() { + printf("ivar = %d\n", ivar); + printf("svar = %d\n", svar); + printf("lvar = %ld\n", lvar); + printf("uivar = %u\n", uivar); + printf("usvar = %u\n", usvar); + printf("ulvar = %lu\n", ulvar); + printf("scvar = %d\n", scvar); + printf("ucvar = %u\n", ucvar); + printf("fvar = %g\n", fvar); + printf("dvar = %g\n", dvar); + printf("cvar = %c\n", cvar); + printf("strvar = %s\n", strvar ? strvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); + printf("name = %s\n", name); + printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("pt = (%d, %d)\n", pt.x, pt.y); + printf("status = %d\n", status); +} + +/* A function to create an integer (to test iptrvar) */ + +int *new_int(int value) { + int *ip = (int *) malloc(sizeof(int)); + *ip = value; + return ip; +} + +int value_int(int *value) { + return *value; +} + +/* A function to create a point */ + +Point *new_Point(int x, int y) { + Point *p = (Point *) malloc(sizeof(Point)); + p->x = x; + p->y = y; + return p; +} + +char * Point_print(Point *p) { + static char buffer[256]; + if (p) { + sprintf(buffer,"(%d,%d)", p->x,p->y); + } else { + sprintf(buffer,"null"); + } + return buffer; +} + +void pt_print() { + printf("(%d, %d)\n", pt.x, pt.y); +} diff --git a/Examples/scilab/variables/example.h b/Examples/scilab/variables/example.h new file mode 100644 index 00000000000..0f7e8959487 --- /dev/null +++ b/Examples/scilab/variables/example.h @@ -0,0 +1,6 @@ +/* File: example.h */ + +typedef struct { + int x,y; +} Point; + diff --git a/Examples/scilab/variables/example.i b/Examples/scilab/variables/example.i new file mode 100644 index 00000000000..97ba1f0e696 --- /dev/null +++ b/Examples/scilab/variables/example.i @@ -0,0 +1,52 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +#pragma SWIG nowarn=SWIGWARN_TYPEMAP_SWIGTYPELEAK + +/* Some global variable declarations */ +%inline %{ +extern int ivar; +extern short svar; +extern long lvar; +extern unsigned int uivar; +extern unsigned short usvar; +extern unsigned long ulvar; +extern signed char scvar; +extern unsigned char ucvar; +extern char cvar; +extern float fvar; +extern double dvar; +extern char *strvar; +extern const char cstrvar[]; +extern int *iptrvar; +extern char name[256]; + +extern Point *ptptr; +extern Point pt; +%} + + +/* Some read-only variables */ + +%immutable; + +%inline %{ +extern int status; +extern char path[256]; +%} + +%mutable; + +/* Some helper functions to make it easier to test */ +%inline %{ +extern void print_vars(); +extern int *new_int(int value); +extern int value_int(int *value); +extern Point *new_Point(int x, int y); +extern char *Point_print(Point *p); +extern void pt_print(); +%} + diff --git a/Examples/scilab/variables/runme.sci b/Examples/scilab/variables/runme.sci new file mode 100644 index 00000000000..98d76cfa008 --- /dev/null +++ b/Examples/scilab/variables/runme.sci @@ -0,0 +1,73 @@ +lines(0); +ilib_verbose(0); +ierr = exec('loader.sce', 'errcatch'); +if ierr <> 0 then + disp(lasterror()); + exit(ierr); +end + +// Try to set the values of some global variables +ivar_set(42); +svar_set(-31000); +lvar_set(65537); +uivar_set(uint32(123456)); +usvar_set(uint16(61000)); +ulvar_set(654321); +scvar_set(int8(-13)); +ucvar_set(uint8(251)); +cvar_set("S"); +fvar_set(3.14159); +dvar_set(2.1828); +strvar_set("Hello World"); +iptrvar_set(new_int(37)); +ptptr_set(new_Point(37,42)); +name_set("Bill"); + +// Now print out the values of the variables +printf("Variables (values printed from Scilab)\n"); +printf("ivar = %i\n", ivar_get()); +printf("svar = %i\n", svar_get()); +printf("lvar = %i\n", lvar_get()); +printf("uivar = %i\n", uivar_get()); +printf("usvar = %i\n", usvar_get()); +printf("ulvar = %i\n", ulvar_get()); +printf("scvar = %i\n", scvar_get()); +printf("ucvar = %i\n", ucvar_get()); +printf("fvar = %f\n", fvar_get()); +printf("dvar = %f\n", dvar_get()); +printf("cvar = %s\n", cvar_get()); +printf("strvar = %s\n", strvar_get()); +printf("cstrvar = %s\n", cstrvar_get()); +printf("iptrvar = %i\n", value_int(iptrvar_get())); +printf("name = %s\n", name_get()); +printf("ptptr = %s\n", Point_print(ptptr_get())); +printf("pt = %s\n", Point_print(pt_get())); +printf("status = %d\n", status_get()); + +printf("\nVariables (values printed from C)\n"); +print_vars() + +// Immutable variables +printf("\nNow I''m going to try and modify some read only variables\n"); +printf(" Tring to set ''path''\n"); +try + path_set("Whoa!"); + printf("Hey, what''s going on?!?! This shouldn''t work\n"); +catch + printf("Good.\n"); +end +printf(" Trying to set ''status''\n"); +try + status_set(0); + printf("Hey, what''s going on?!?! This shouldn''t work\n"); +catch + printf("Good.\n"); +end + +// Structure +printf("\nI''m going to try and update a structure variable.\n"); +pt_set(ptptr_get()); +printf("The new value is %s\n", Point_print(pt_get())); + +exit + diff --git a/Examples/tcl/class/Makefile b/Examples/tcl/class/Makefile index aacf30e04a7..3fd77cff595 100644 --- a/Examples/tcl/class/Makefile +++ b/Examples/tcl/class/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static clean: diff --git a/Examples/tcl/constants/Makefile b/Examples/tcl/constants/Makefile index 17c8afa3f25..67f6567a8aa 100644 --- a/Examples/tcl/constants/Makefile +++ b/Examples/tcl/constants/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = TARGET = my_tclsh DLTARGET = example @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh clean: diff --git a/Examples/tcl/contract/Makefile b/Examples/tcl/contract/Makefile index 01fdc37b3f4..bab90552bee 100644 --- a/Examples/tcl/contract/Makefile +++ b/Examples/tcl/contract/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = my_tclsh DLTARGET = example @@ -10,12 +11,14 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_clean diff --git a/Examples/tcl/enum/Makefile b/Examples/tcl/enum/Makefile index aacf30e04a7..3fd77cff595 100644 --- a/Examples/tcl/enum/Makefile +++ b/Examples/tcl/enum/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static clean: diff --git a/Examples/tcl/funcptr/Makefile b/Examples/tcl/funcptr/Makefile index 7155bf3c3a1..8765f7ef9d8 100644 --- a/Examples/tcl/funcptr/Makefile +++ b/Examples/tcl/funcptr/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = my_tclsh DLTARGET = example @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh clean: diff --git a/Examples/tcl/import/Makefile b/Examples/tcl/import/Makefile index 6aa48e7a8ad..64ef0cdd1f8 100644 --- a/Examples/tcl/import/Makefile +++ b/Examples/tcl/import/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SWIGOPT = LIBS = @@ -7,14 +8,18 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' tcl_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' tcl_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' tcl_cpp - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ - LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' tcl_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' tcl_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' tcl_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' tcl_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' tcl_cpp clean: diff --git a/Examples/tcl/java/Makefile b/Examples/tcl/java/Makefile index 4be3764e247..e4dfc536bc7 100644 --- a/Examples/tcl/java/Makefile +++ b/Examples/tcl/java/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,7 +10,8 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: Example.class Example.h - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ TCLCXXSHARED="gcj -fpic -shared Example.class " LIBS="-lstdc++" DEFS='' tcl_cpp diff --git a/Examples/tcl/multimap/Makefile b/Examples/tcl/multimap/Makefile index 7155bf3c3a1..8765f7ef9d8 100644 --- a/Examples/tcl/multimap/Makefile +++ b/Examples/tcl/multimap/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = my_tclsh DLTARGET = example @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh clean: diff --git a/Examples/tcl/operator/Makefile b/Examples/tcl/operator/Makefile index 1c6e1be9800..73dca485a62 100644 --- a/Examples/tcl/operator/Makefile +++ b/Examples/tcl/operator/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static clean: diff --git a/Examples/tcl/pointer/Makefile b/Examples/tcl/pointer/Makefile index 7155bf3c3a1..8765f7ef9d8 100644 --- a/Examples/tcl/pointer/Makefile +++ b/Examples/tcl/pointer/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = my_tclsh DLTARGET = example @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh clean: diff --git a/Examples/tcl/reference/Makefile b/Examples/tcl/reference/Makefile index aacf30e04a7..3fd77cff595 100644 --- a/Examples/tcl/reference/Makefile +++ b/Examples/tcl/reference/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = example.cxx TARGET = example INTERFACE = example.i @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static clean: diff --git a/Examples/tcl/simple/Makefile b/Examples/tcl/simple/Makefile index 7155bf3c3a1..8765f7ef9d8 100644 --- a/Examples/tcl/simple/Makefile +++ b/Examples/tcl/simple/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = my_tclsh DLTARGET = example @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh clean: diff --git a/Examples/tcl/std_vector/Makefile b/Examples/tcl/std_vector/Makefile index f29f933ba39..3ed97f27cb9 100644 --- a/Examples/tcl/std_vector/Makefile +++ b/Examples/tcl/std_vector/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib CXXSRCS = TARGET = my_tclsh DLTARGET = example @@ -10,11 +11,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh_cpp_static clean: diff --git a/Examples/tcl/value/Makefile b/Examples/tcl/value/Makefile index 7155bf3c3a1..8765f7ef9d8 100644 --- a/Examples/tcl/value/Makefile +++ b/Examples/tcl/value/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = my_tclsh DLTARGET = example @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh clean: diff --git a/Examples/tcl/variables/Makefile b/Examples/tcl/variables/Makefile index 7155bf3c3a1..8765f7ef9d8 100644 --- a/Examples/tcl/variables/Makefile +++ b/Examples/tcl/variables/Makefile @@ -1,5 +1,6 @@ TOP = ../.. -SWIG = $(TOP)/../preinst-swig +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib SRCS = example.c TARGET = my_tclsh DLTARGET = example @@ -9,11 +10,13 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcl static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh clean: diff --git a/Examples/test-suite/allegrocl/Makefile.in b/Examples/test-suite/allegrocl/Makefile.in index 02ef8e3022c..b13d546daeb 100644 --- a/Examples/test-suite/allegrocl/Makefile.in +++ b/Examples/test-suite/allegrocl/Makefile.in @@ -35,7 +35,7 @@ CPP_TEST_BROKEN_ACL = \ dynamic_cast \ extend_variable \ # cdata.i support needed \ - li_cdata \ + li_cdata_cpp \ # warning generated. otherwise all good. \ operator_overload \ # std_common.i support \ diff --git a/Examples/test-suite/allprotected.i b/Examples/test-suite/allprotected.i index bd4dfe5c7a6..086cfb2456f 100644 --- a/Examples/test-suite/allprotected.i +++ b/Examples/test-suite/allprotected.i @@ -8,6 +8,11 @@ %include "std_string.i" +#ifdef SWIGSCILAB +%rename(ProcBase) ProtectedBase; +%rename(PubBase) PublicBase; +#endif + %feature("director") PublicBase; %feature("director") ProtectedBase; diff --git a/Examples/test-suite/apply_signed_char.i b/Examples/test-suite/apply_signed_char.i index c0fa00cfe76..d3116f02488 100644 --- a/Examples/test-suite/apply_signed_char.i +++ b/Examples/test-suite/apply_signed_char.i @@ -4,6 +4,10 @@ %warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) DirectorTest; +#if defined(SWIGSCILAB) +%rename(DirTest) DirectorTest; +#endif + %apply signed char {char, const char}; %apply const signed char & {const char &}; diff --git a/Examples/test-suite/apply_strings.i b/Examples/test-suite/apply_strings.i index 54a91f83aed..62b578bf225 100644 --- a/Examples/test-suite/apply_strings.i +++ b/Examples/test-suite/apply_strings.i @@ -1,5 +1,5 @@ -/* Test %apply for char *, signed char *, unsigned char * - This won't work in all situations, so does not necessarily have to be implemented. See +/* Test %apply for char *, signed char *, unsigned char * + This won't work in all situations, so does not necessarily have to be implemented. See http://groups.google.com.ai/group/comp.lang.c++.moderated/browse_thread/thread/ad5873ce25d49324/0ae94552452366be?lnk=raot */ %module(directors="1") apply_strings @@ -7,6 +7,11 @@ %warnfilter(SWIGWARN_TYPEMAP_VARIN_UNDEF) DigitsGlobalB; %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK) DigitsGlobalC; +#if defined(SWIGSCILAB) +%rename(TNum) TNumber; +%rename(DirTest) DirectorTest; +#endif + %apply char * {UCharPtr}; %apply char * {SCharPtr}; %apply const char * {CUCharPtr}; @@ -53,12 +58,12 @@ typedef struct { TAscii DigitsMemberA[20]; TAscii *DigitsMemberB; } TNumber; - + TAscii DigitsGlobalA[20]; TAscii DigitsGlobalB[] = {(unsigned char)'A', (unsigned char)'B', 0}; TAscii *DigitsGlobalC; -%} +%} // Director test %feature("director"); diff --git a/Examples/test-suite/array_member.i b/Examples/test-suite/array_member.i index d8e2f873ccc..845eeb72cda 100644 --- a/Examples/test-suite/array_member.i +++ b/Examples/test-suite/array_member.i @@ -1,5 +1,9 @@ %module array_member +#if defined(SWIGSCILAB) +%rename(RayPkt) RayPacketData; +#endif + %inline %{ typedef struct Foo { diff --git a/Examples/test-suite/array_typedef_memberin.i b/Examples/test-suite/array_typedef_memberin.i index ed49543a383..ad2855eed38 100644 --- a/Examples/test-suite/array_typedef_memberin.i +++ b/Examples/test-suite/array_typedef_memberin.i @@ -1,5 +1,14 @@ %module array_typedef_memberin + +#if defined(SWIGSCILAB) +%rename(ExDetail) ExampleDetail; +#endif + %inline %{ +#if defined(_MSC_VER) + #pragma warning(disable: 4351) // new behavior: elements of array 'xyz' will be default initialized +#endif + typedef short Eight[8]; typedef const short ConstEight[8]; namespace ArrayExample @@ -8,13 +17,8 @@ namespace ArrayExample { public: Eight node_list; -#ifndef _MSC_VER const Eight node_list2; ConstEight node_list3; -#else - Eight node_list2; - Eight node_list3; -#endif void fn1(Eight a) {} void fn2(const Eight a) {} @@ -27,6 +31,8 @@ namespace ArrayExample void fn7(Eight*& a) {} void fn8(ConstEight*& a) {} void fn9(const ConstEight*& a) {} + + ExampleDetail() : node_list(), node_list2(), node_list3() {} }; } diff --git a/Examples/test-suite/arrays.i b/Examples/test-suite/arrays.i index decce74153f..07162aa9049 100644 --- a/Examples/test-suite/arrays.i +++ b/Examples/test-suite/arrays.i @@ -7,6 +7,10 @@ This test case tests that various types of arrays are working. #include %} +#if defined(SWIGSCILAB) +%rename(ArrSt) ArrayStruct; +#endif + %inline %{ #define ARRAY_LEN 2 diff --git a/Examples/test-suite/autodoc.i b/Examples/test-suite/autodoc.i index d858997564e..a2d9f5b4e93 100644 --- a/Examples/test-suite/autodoc.i +++ b/Examples/test-suite/autodoc.i @@ -1,4 +1,4 @@ -%module(docstring="hello") autodoc +%module(docstring="hello.") autodoc %feature("autodoc"); @@ -27,7 +27,7 @@ %feature("autodoc","2") A::variable_c; // extended %feature("autodoc","3") A::variable_d; // extended + types -%feature("autodoc","just a string") A::funk; // names +%feature("autodoc","just a string.") A::funk; // names %inline { diff --git a/Examples/test-suite/bloody_hell.i b/Examples/test-suite/bloody_hell.i index e580f0dd439..ff296a24cd6 100644 --- a/Examples/test-suite/bloody_hell.i +++ b/Examples/test-suite/bloody_hell.i @@ -2,16 +2,20 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) kMaxIOCTLSpaceParmsSize; -#define kMaxIOCTLSpaceParmsSize 128 +#ifdef SWIGSCILAB +%rename(Parms) sm_channel_ix_dump_parms; +#endif + +#define kMaxIOCTLSpaceParmsSize 128 %{ -#define kMaxIOCTLSpaceParmsSize 128 +#define kMaxIOCTLSpaceParmsSize 128 %} %inline %{ -typedef struct sm_channel_ix_dump_parms { - unsigned data[(kMaxIOCTLSpaceParmsSize - ((4*sizeof(int)) + (2*sizeof(unsigned))))/sizeof(unsigned)]; -} SM_CHANNEL_IX_DUMP_PARMS; +typedef struct sm_channel_ix_dump_parms { + unsigned data[(kMaxIOCTLSpaceParmsSize - ((4*sizeof(int)) + (2*sizeof(unsigned))))/sizeof(unsigned)]; +} SM_CHANNEL_IX_DUMP_PARMS; %} diff --git a/Examples/test-suite/bools.i b/Examples/test-suite/bools.i index 7b94fcf884d..2ef3d93a632 100644 --- a/Examples/test-suite/bools.i +++ b/Examples/test-suite/bools.i @@ -1,5 +1,10 @@ // bool typemaps check %module bools + +#if defined(SWIGSCILAB) +%rename(BoolSt) BoolStructure; +#endif + %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) constbool; /* Ruby, wrong class name */ diff --git a/Examples/test-suite/callback.i b/Examples/test-suite/callback.i index c4d50d3fe42..4db63353ba1 100644 --- a/Examples/test-suite/callback.i +++ b/Examples/test-suite/callback.i @@ -1,10 +1,18 @@ %module callback +// Not specifying the callback name is only possible in Python. +#ifdef SWIGPYTHON %callback(1) foo; %callback(1) foof; %callback(1) A::bar; %callback(1) A::foom; -%callback("%s_Cb_Ptr") foo_T; // old style, still works. +#else +%callback("%s") foo; +%callback("%s") foof; +%callback("%s") A::bar; +%callback("%s") A::foom; +#endif +%callback("%(uppercase)s_Cb_Ptr") foo_T; // this works in Python too %inline %{ @@ -57,6 +65,22 @@ return pf(a); } +#if defined(__SUNPRO_CC) +// workaround for: Error: Could not find a match for foobar_T(int, extern "C" int(*)(int)). + extern "C" { + typedef int (*foobar_int_int)(int a); + typedef double (*foobar_double_double)(double a); + }; + template + int foobar_T(int a, foobar_int_int pf) { + return pf(a); + } + template + double foobar_T(double a, foobar_double_double pf) { + return pf(a); + } +#endif + template const T& ident(const T& x) { return x; diff --git a/Examples/test-suite/cffi/Makefile.in b/Examples/test-suite/cffi/Makefile.in index ee7e3f61e0d..6eebaa07c23 100644 --- a/Examples/test-suite/cffi/Makefile.in +++ b/Examples/test-suite/cffi/Makefile.in @@ -48,4 +48,4 @@ run_testcase = \ @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" cffi_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' cffi_clean diff --git a/Examples/test-suite/char_binary.i b/Examples/test-suite/char_binary.i index 778792946b3..394565438c2 100644 --- a/Examples/test-suite/char_binary.i +++ b/Examples/test-suite/char_binary.i @@ -5,12 +5,16 @@ A test case for testing non null terminated char pointers. %module char_binary %apply (char *STRING, size_t LENGTH) { (const char *str, size_t len) } +%apply (char *STRING, size_t LENGTH) { (const unsigned char *str, size_t len) } %inline %{ struct Test { size_t strlen(const char *str, size_t len) { return len; } + size_t ustrlen(const unsigned char *str, size_t len) { + return len; + } }; typedef char namet[5]; diff --git a/Examples/test-suite/char_strings.i b/Examples/test-suite/char_strings.i index cc59815b284..9a87df4e3d6 100644 --- a/Examples/test-suite/char_strings.i +++ b/Examples/test-suite/char_strings.i @@ -9,13 +9,9 @@ below. %warnfilter(SWIGWARN_TYPEMAP_VARIN_UNDEF) global_char_array1; // Unable to set variable of type char[] %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) global_const_char; // Setting a const char * variable may leak memory. -#ifdef SWIG_ALLEGRO_CL %{ #include -%} -#endif -%{ #define OTHERLAND_MSG "Little message from the safe world." #define CPLUSPLUS_MSG "A message from the deep dark world of C++, where anything is possible." static char *global_str = NULL; diff --git a/Examples/test-suite/chartest.i b/Examples/test-suite/chartest.i new file mode 100644 index 00000000000..e81cf54a461 --- /dev/null +++ b/Examples/test-suite/chartest.i @@ -0,0 +1,15 @@ +%module chartest + +%inline %{ +char printable_global_char = 'a'; +char unprintable_global_char = 0x7F; + +char GetPrintableChar() { + return 'a'; +} + +char GetUnprintableChar() { + return 0x7F; +} + +%} diff --git a/Examples/test-suite/chicken/Makefile.in b/Examples/test-suite/chicken/Makefile.in index 31ab311bbcf..b3dccc9c3b8 100644 --- a/Examples/test-suite/chicken/Makefile.in +++ b/Examples/test-suite/chicken/Makefile.in @@ -97,5 +97,5 @@ run_testcase = \ @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" chicken_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' chicken_clean rm -f *.scm diff --git a/Examples/test-suite/chicken/overload_extend_c_runme.ss b/Examples/test-suite/chicken/overload_extend_c_runme.ss new file mode 100644 index 00000000000..75c0ea8a85c --- /dev/null +++ b/Examples/test-suite/chicken/overload_extend_c_runme.ss @@ -0,0 +1,2 @@ +(load "overload_extend_c.so") +(include "../schemerunme/overload_extend_c.scm") diff --git a/Examples/test-suite/clisp/Makefile.in b/Examples/test-suite/clisp/Makefile.in index 6837ed60b9f..3d207178fc3 100644 --- a/Examples/test-suite/clisp/Makefile.in +++ b/Examples/test-suite/clisp/Makefile.in @@ -48,4 +48,4 @@ run_testcase = \ @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" clisp_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' clisp_clean diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 742db540b65..9f948c2ca4c 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -33,9 +33,7 @@ # can be used for memory checking of the runtime tests using: # make RUNTOOL="valgrind --leak-check=full" # and valgrind can be used when invoking SWIG using: -# make SWIGTOOL="valgrind --tool=memcheck --trace-children=yes" -# Note: trace-children needed because of preinst-swig shell wrapper -# to the swig executable. +# make SWIGTOOL="valgrind --tool=memcheck" # # An individual test run can be debugged easily: # make director_string.cpptest RUNTOOL="gdb --args" @@ -56,8 +54,8 @@ endif COMPILETOOL= SWIGTOOL = -SWIG = $(SWIGTOOL) $(top_builddir)/preinst-swig -SWIG_LIB = $(top_srcdir)/Lib +SWIGEXE = $(top_builddir)/swig +SWIG_LIB_DIR = $(top_srcdir)/Lib TEST_SUITE = test-suite EXAMPLES = Examples CXXSRCS = @@ -138,6 +136,7 @@ CPP_TEST_CASES += \ casts \ char_binary \ char_strings \ + chartest \ class_forward \ class_ignore \ class_scope_weird \ @@ -156,6 +155,7 @@ CPP_TEST_CASES += \ conversion \ conversion_namespace \ conversion_ns_template \ + conversion_operators \ cplusplus_throw \ cpp_basic \ cpp_enum \ @@ -198,6 +198,7 @@ CPP_TEST_CASES += \ director_protected \ director_protected_overloaded \ director_redefined \ + director_ref \ director_smartptr \ director_thread \ director_unroll \ @@ -217,6 +218,7 @@ CPP_TEST_CASES += \ evil_diamond \ evil_diamond_ns \ evil_diamond_prop \ + exception_classname \ exception_order \ extend \ extend_constructor_destructor \ @@ -233,6 +235,7 @@ CPP_TEST_CASES += \ features \ fragments \ friends \ + friends_template \ funcptr_cpp \ fvirtual \ global_namespace \ @@ -243,6 +246,7 @@ CPP_TEST_CASES += \ ignore_parameter \ import_nomodule \ inherit \ + inherit_member \ inherit_missing \ inherit_same_name \ inherit_target_language \ @@ -255,13 +259,14 @@ CPP_TEST_CASES += \ langobj \ li_attribute \ li_attribute_template \ + li_boost_array \ li_boost_shared_ptr \ li_boost_shared_ptr_bits \ li_boost_shared_ptr_template \ li_boost_shared_ptr_attribute \ - li_carrays \ - li_cdata \ - li_cpointer \ + li_carrays_cpp \ + li_cdata_cpp \ + li_cpointer_cpp \ li_std_auto_ptr \ li_stdint \ li_swigtype_inout \ @@ -308,6 +313,7 @@ CPP_TEST_CASES += \ operator_pointer_ref \ operbool \ ordering \ + overload_arrays \ overload_bool \ overload_copy \ overload_extend \ @@ -368,6 +374,7 @@ CPP_TEST_CASES += \ smart_pointer_templatevariables \ smart_pointer_typedef \ special_variables \ + special_variable_attributes \ special_variable_macros \ static_array_member \ static_const_member \ @@ -388,6 +395,7 @@ CPP_TEST_CASES += \ template_default \ template_default2 \ template_default_arg \ + template_default_arg_overloaded \ template_default_arg_virtual_destructor \ template_default_class_parms \ template_default_class_parms_typedef \ @@ -406,6 +414,7 @@ CPP_TEST_CASES += \ template_inherit \ template_inherit_abstract \ template_int_const \ + template_keyword_in_type \ template_methods \ template_namespace_forward_declaration \ template_using_directive_and_declaration_forward \ @@ -462,7 +471,7 @@ CPP_TEST_CASES += \ typedef_reference \ typedef_scope \ typedef_sizet \ - typedef_struct \ + typedef_struct_cpp \ typedef_typedef \ typemap_arrays \ typemap_array_qualifiers \ @@ -524,6 +533,7 @@ CPP11_TEST_CASES = \ cpp11_initializer_list \ cpp11_initializer_list_extend \ cpp11_lambda_functions \ + cpp11_li_std_array \ cpp11_noexcept \ cpp11_null_pointer_constant \ cpp11_raw_string_literals \ @@ -539,6 +549,7 @@ CPP11_TEST_CASES = \ cpp11_template_explicit \ cpp11_template_typedefs \ cpp11_type_traits \ + cpp11_type_aliasing \ cpp11_uniform_initialization \ cpp11_unrestricted_unions \ cpp11_userdefined_literals \ @@ -567,7 +578,6 @@ CPP_STD_TEST_CASES += \ li_std_vector \ li_std_vector_enum \ li_std_vector_member_var\ - naturalvar \ smart_pointer_inherit \ template_typedef_fnc \ template_type_namespace \ @@ -592,7 +602,7 @@ C_TEST_CASES += \ char_constant \ const_const \ constant_expr \ - empty \ + empty_c \ enums \ enum_forward \ enum_macro \ @@ -605,7 +615,7 @@ C_TEST_CASES += \ inctest \ infinity \ integers \ - keyword_rename \ + keyword_rename_c \ lextype \ li_carrays \ li_cdata \ @@ -620,8 +630,8 @@ C_TEST_CASES += \ nested_extend_c \ nested_structs \ newobject2 \ - overload_extend \ - overload_extendc \ + overload_extend_c \ + overload_extend2 \ preproc \ preproc_constants_c \ preproc_defined \ @@ -698,37 +708,37 @@ partialcheck: $(MAKE) check CC=true CXX=true LDSHARED=true CXXSHARED=true RUNTOOL=true COMPILETOOL=true swig_and_compile_cpp = \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS)" \ - SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \ - INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \ - TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ + TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \ $(LANGUAGE)$(VARIANT)_cpp swig_and_compile_c = \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CSRCS="$(CSRCS)" \ - SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \ - INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \ - TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CSRCS='$(CSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ + TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \ $(LANGUAGE)$(VARIANT) swig_and_compile_multi_cpp = \ for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS)" \ - SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \ - INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \ - TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$$f.i" \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + LIBS='$(LIBS)' INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ + TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR='$(INTERFACEDIR)' INTERFACE="$$f.i" \ $(LANGUAGE)$(VARIANT)_cpp; \ done swig_and_compile_external = \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" \ - SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \ - TARGET="$*_wrap_hdr.h" \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + TARGET='$*_wrap_hdr.h' \ $(LANGUAGE)$(VARIANT)_externalhdr; \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS) $*_external.cxx" \ - SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \ - INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \ - TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS) $*_external.cxx' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ + TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \ $(LANGUAGE)$(VARIANT)_cpp swig_and_compile_runtime = \ diff --git a/Examples/test-suite/constant_pointers.i b/Examples/test-suite/constant_pointers.i index 388970c4d85..9094e9dea55 100644 --- a/Examples/test-suite/constant_pointers.i +++ b/Examples/test-suite/constant_pointers.i @@ -4,6 +4,11 @@ This testcase primarily test constant pointers, eg int* const. Only a getter is %module constant_pointers +#if defined(SWIGSCILAB) +%rename(MbrVar) MemberVariablesTest; +%rename(RetVal) ReturnValuesTest; +#endif + %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */ %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG); /* Setting a pointer/reference variable may leak memory. */ diff --git a/Examples/test-suite/constructor_copy.i b/Examples/test-suite/constructor_copy.i index 8e92e7840b7..7dcd05e8b26 100644 --- a/Examples/test-suite/constructor_copy.i +++ b/Examples/test-suite/constructor_copy.i @@ -5,13 +5,13 @@ %nocopyctor Bar; %inline %{ - + struct Foo1 { int x; Foo1(int _x = 2) : x(_x) { - } + } }; struct Foo2 { @@ -25,7 +25,7 @@ struct Foo3 { struct Foo4 { Foo4() { } - + protected: Foo4(const Foo4& ) { } }; @@ -33,7 +33,7 @@ protected: struct Foo4a { Foo4a() { } - + private: Foo4a(const Foo4a& ) { } }; @@ -53,7 +53,7 @@ struct Foo8 { }; template -class Bar +class Bar { public: int x; @@ -73,7 +73,7 @@ public: %include "std_vector.i" -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGJAVASCRIPT) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGJAVASCRIPT) || defined(SWIGSCILAB) #define SWIG_GOOD_VECTOR %ignore std::vector::vector(size_type); %ignore std::vector::resize(size_type); @@ -126,7 +126,7 @@ public: template struct ModelUtils_T {}; - } + } } %} @@ -144,13 +144,13 @@ namespace Space1 { class TotalReturnSwap { public: TotalReturnSwap() {} - }; + }; template class TotalReturnSwap_T { public: TotalReturnSwap_T() {} - }; + }; } } diff --git a/Examples/test-suite/constructor_exception.i b/Examples/test-suite/constructor_exception.i index 4c867c14428..e3cdc47afaf 100644 --- a/Examples/test-suite/constructor_exception.i +++ b/Examples/test-suite/constructor_exception.i @@ -1,14 +1,14 @@ %module constructor_exception %inline %{ -class Error { +class MyError { }; class SomeClass { public: SomeClass(int x) { if (x < 0) { - throw Error(); + throw MyError(); } } }; @@ -17,7 +17,7 @@ class Test { SomeClass o; public: Test(int x) try : o(x) { } - catch (Error &) { + catch (MyError &) { } catch (int) { } diff --git a/Examples/test-suite/conversion_ns_template.i b/Examples/test-suite/conversion_ns_template.i index 0814f2a18e6..bddda5e7b62 100644 --- a/Examples/test-suite/conversion_ns_template.i +++ b/Examples/test-suite/conversion_ns_template.i @@ -20,9 +20,13 @@ Bar(){ } Bar(int){ } +#if !defined(__SUNPRO_CC) operator int() { return 0; } +#endif operator int&() { static int num = 0; return num; } +#if !defined(__SUNPRO_CC) operator Foo() { return Foo(); } +#endif operator Foo&() { return *(new Foo()); } }; } diff --git a/Examples/test-suite/conversion_operators.i b/Examples/test-suite/conversion_operators.i new file mode 100644 index 00000000000..fa9e52cac47 --- /dev/null +++ b/Examples/test-suite/conversion_operators.i @@ -0,0 +1,55 @@ +%module conversion_operators + +// Test bug #401 where the conversion operator name incorrectly included the newline character +// Also test comments around conversion operators due to special handling in the scanner for conversion operators + +// These one line ignores should match the conversion operator names to suppress Warning 503 - SWIGWARN_LANG_IDENTIFIER +%ignore operator const EcReal; +%ignore operator EcImaginary const; +%ignore operator EcComplex const; + +%inline %{ + +struct EcReal {}; +struct EcImaginary {}; +struct EcComplex {}; + +struct EcAngle { + operator const EcReal + ( + ) const; + operator EcImaginary +const ( + ) const; + operator +EcComplex + const ( + ) const; +}; + +struct EcAngle2 { + operator const EcReal/* C comment */ + ( + ) const; + operator EcImaginary/* C comment */ +const ( + ) const; + operator/* C comment */ +EcComplex + const ( + ) const; +}; + +struct EcAngle3 { + operator const EcReal // C++ comment + ( + ) const; + operator EcImaginary // C++ comment +const ( + ) const; + operator // C++ comment +EcComplex + const ( + ) const; +}; +%} diff --git a/Examples/test-suite/cpp11_lambda_functions.i b/Examples/test-suite/cpp11_lambda_functions.i index 87c7196d8bb..161e08c65ff 100644 --- a/Examples/test-suite/cpp11_lambda_functions.i +++ b/Examples/test-suite/cpp11_lambda_functions.i @@ -100,9 +100,6 @@ int runLambdaInline() { %{ // TODO -struct LambdaStruct { - static constexpr auto lambda_struct1 = [=]() { return thing; }; -}; int(*lambda101notauto)(int, int) = [] (int a, int b) { return a + b; }; int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2); void lambda_init(int = ([=]{ return 0; })()); diff --git a/Examples/test-suite/cpp11_li_std_array.i b/Examples/test-suite/cpp11_li_std_array.i new file mode 100644 index 00000000000..74e34370c97 --- /dev/null +++ b/Examples/test-suite/cpp11_li_std_array.i @@ -0,0 +1,62 @@ +%module cpp11_li_std_array + +#if defined(SWIGPYTHON) || defined(SWIGRUBY) + +%{ +#include +%} + +%include + +%template(ArrayInt6) std::array; + +%inline %{ +std::array arrayOutVal() { + return { -2, -1, 0, 0, 1, 2 }; +} + +std::array & arrayOutRef() { + static std::array a = { -2, -1, 0, 0, 1, 2 }; + return a; +} + +const std::array & arrayOutConstRef() { + static std::array a = { -2, -1, 0, 0, 1, 2 }; + return a; +} + +std::array * arrayOutPtr() { + static std::array a = { -2, -1, 0, 0, 1, 2 }; + return &a; +} + +std::array arrayInVal(std::array myarray) { + std::array a = myarray; + for (auto& val : a) { + val *= 10; + } + return a; +} + +const std::array & arrayInConstRef(const std::array & myarray) { + static std::array a = myarray; + for (auto& val : a) { + val *= 10; + } + return a; +} + +void arrayInRef(std::array & myarray) { + for (auto& val : myarray) { + val *= 10; + } +} + +void arrayInPtr(std::array * myarray) { + for (auto& val : *myarray) { + val *= 10; + } +} +%} + +#endif diff --git a/Examples/test-suite/cpp11_noexcept.i b/Examples/test-suite/cpp11_noexcept.i index 6fed5b8dfce..ef96fd8a779 100644 --- a/Examples/test-suite/cpp11_noexcept.i +++ b/Examples/test-suite/cpp11_noexcept.i @@ -13,7 +13,7 @@ struct NoExceptClass { NoExceptClass() noexcept {} NoExceptClass(const NoExceptClass&) noexcept {} NoExceptClass(NoExceptClass&&) noexcept {} - NoExceptClass& operator=(const NoExceptClass&) noexcept {} + NoExceptClass& operator=(const NoExceptClass&) noexcept { return *this; } ~NoExceptClass() noexcept {} void noex0() noexcept {} diff --git a/Examples/test-suite/cpp11_rvalue_reference2.i b/Examples/test-suite/cpp11_rvalue_reference2.i index 4ef871c632b..6718a394140 100644 --- a/Examples/test-suite/cpp11_rvalue_reference2.i +++ b/Examples/test-suite/cpp11_rvalue_reference2.i @@ -31,14 +31,17 @@ struct Thingy { // test both primitive and user defined rvalue reference default arguments and compactdefaultargs void compactDefaultArgs(const bool &&b = (const bool &&)PublicGlobalTrue, const UserDef &&u = (const UserDef &&)PublicUserDef) {} void privateDefaultArgs(const bool &&b = (const bool &&)PrivateTrue) {} - operator int &&() {} + operator int &&() { return std::move(0); } + Thingy(const Thingy& rhs) : val(rhs.val), lvalref(rhs.lvalref), rvalref(copy_int(rhs.rvalref)) {} Thingy& operator=(const Thingy& rhs) { val = rhs.val; lvalref = rhs.lvalref; rvalref = rhs.rvalref; + return *this; } private: static const bool PrivateTrue; + int copy_int(int& i) { return i; } Thingy(); }; const bool Thingy::PrivateTrue = true; diff --git a/Examples/test-suite/cpp11_template_typedefs.i b/Examples/test-suite/cpp11_template_typedefs.i index d6a1a3c8557..97a1da7ed6d 100644 --- a/Examples/test-suite/cpp11_template_typedefs.i +++ b/Examples/test-suite/cpp11_template_typedefs.i @@ -2,8 +2,14 @@ %module cpp11_template_typedefs %warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefName; +%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefNamePtr; %warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) MyIntKeyClass; %warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) PF; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) BucketAllocator1; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) BucketAllocator2; + +// This warning should go away when type aliasing is supported +#pragma SWIG nowarn=SWIGWARN_PARSE_USING_UNDEF // Nothing known about 'p.SomeType< char *,T2,4 >'. %inline %{ template< typename T1, typename T2, int > @@ -16,6 +22,8 @@ class SomeType { // template aliasing template< typename T2 > using TypedefName = SomeType; +template< typename T2 > +using TypedefNamePtr = SomeType*; // type aliasing typedef void (*PFD)(double); // Old style @@ -28,5 +36,21 @@ class MyCPP11Class { }; template using MyIntKeyClass = MyCPP11Class; MyIntKeyClass intchar; + +TypedefName alias1(TypedefName a) { return a; } +TypedefNamePtr alias1(TypedefNamePtr a = nullptr) { return a; } %} +%inline %{ +typedef double Val; +template struct ListBucket { +}; +namespace Alloc { + template struct rebind { + typedef int other; + }; +} + +using BucketAllocator1 = typename Alloc::template rebind>::other; +using BucketAllocator2 = typename Alloc::template rebind<::template ListBucket>::other; +%} diff --git a/Examples/test-suite/cpp11_type_aliasing.i b/Examples/test-suite/cpp11_type_aliasing.i new file mode 100644 index 00000000000..87443633a59 --- /dev/null +++ b/Examples/test-suite/cpp11_type_aliasing.i @@ -0,0 +1,66 @@ +%module cpp11_type_aliasing + +// Type aliasing seg fault : Github issue #424 + +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Target; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Int; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntRef; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntPtrRef; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntRValueRef; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntArray; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) HalideTargetPtr1; +%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) HalideTargetPtr2; + +%inline %{ +namespace Halide { + +struct Target { + int bits; + Target(int bits=32) : bits(bits) {} +}; + +class NamesInterface { +public: + using Target = Halide::Target; +}; + +Target get_host_target() { + return Target(); +} + +namespace Internal { + +template class GeneratorParam { + T value; +public: + GeneratorParam(const char *name, const T &v) : value(v) {} + + T getValue() { + return value; + } +}; + +class GeneratorBase : public NamesInterface { +public: + GeneratorParam target{ "target", Halide::get_host_target() }; +}; + +} +} +%} + +%template(Halide_Target) Halide::Internal::GeneratorParam; + + +%inline %{ +using Int = int; +using IntRef = int&; +using IntPtrRef = int*&; +using IntRValueRef = int&&; +using IntArray = int[]; + +using HalideTargetPtr1 = Halide::Target*; +namespace Halide { + using HalideTargetPtr2 = Target*; +} +%} diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 292c751e465..0c799c7d9e1 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -6,8 +6,7 @@ LANGUAGE = csharp SCRIPTSUFFIX = _runme.cs CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@ -CSHARPPATHSEPARATOR = "@CSHARPPATHSEPARATOR@" -CSHARPCYGPATH_W = @CSHARPCYGPATH_W@ +CSHARPCONVERTPATH = @top_srcdir@/@CSHARPCONVERTPATH@ srcdir = @srcdir@ top_srcdir = ../@top_srcdir@ @@ -74,18 +73,18 @@ setup = \ # Compiles C# files then runs the testcase. A testcase is only run if # a file is found which has _runme.cs appended after the testcase name. # Note C# uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows and SHLIB_PATH on HPUX. -# DYLD_FALLBACK_LIBRARY_PATH is cleared for MacOSX. +# DYLD_FALLBACK_LIBRARY_PATH is cleared for Mac OS X. run_testcase = \ if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo -debug+ $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ - CSHARPSRCS='`$(CSHARPCYGPATH_W) $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \ + CSHARPSRCS='`$(CSHARPCONVERTPATH) $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCONVERTPATH) "{}" \+`' csharp_compile && \ env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_FALLBACK_LIBRARY_PATH= $(RUNTOOL) $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) ./$*_runme.exe; \ else \ cd $* && \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo -debug+ $(CSHARPFLAGSSPECIAL) -t:module -out:$*.netmodule' \ - CSHARPSRCS='`find . -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile; \ + CSHARPSRCS='`find . -name "*.cs" -exec ../$(CSHARPCONVERTPATH) "{}" \+`' csharp_compile; \ fi # Clean: remove testcase directories diff --git a/Examples/test-suite/csharp/default_constructor_runme.cs b/Examples/test-suite/csharp/default_constructor_runme.cs index acd62dc3d95..9fc8d754bd9 100644 --- a/Examples/test-suite/csharp/default_constructor_runme.cs +++ b/Examples/test-suite/csharp/default_constructor_runme.cs @@ -12,13 +12,5 @@ static void Main() throw new Exception("Protected destructor exception should have been thrown"); } catch (MethodAccessException) { } - - // calling private destructor test - try { - using (FFF f = new FFF()) { - } - throw new Exception("Private destructor exception should have been thrown"); - } catch (MethodAccessException) { - } } } diff --git a/Examples/test-suite/csharp/director_smartptr_runme.cs b/Examples/test-suite/csharp/director_smartptr_runme.cs index ad33c4d3420..559dff7a0c7 100644 --- a/Examples/test-suite/csharp/director_smartptr_runme.cs +++ b/Examples/test-suite/csharp/director_smartptr_runme.cs @@ -1,13 +1,13 @@ using director_smartptrNamespace; +using System; public class runme { - private class director_smartptr_MyBarFoo : Foo { public override string ping() { - return "director_smartptr_MyBarFoo.ping();"; + return "director_smartptr_MyBarFoo.ping()"; } public override string pong() @@ -15,27 +15,39 @@ public override string pong() return "director_smartptr_MyBarFoo.pong();" + ping(); } - public override string fooBar(FooBar fooBar) + public override string upcall(FooBar fooBarPtr) { - return fooBar.FooBarDo(); + return "override;" + fooBarPtr.FooBarDo(); } public override Foo makeFoo() { return new Foo(); } + } - public override FooBar makeFooBar() - { - return new FooBar(); - } + private static void check(string got, string expected) + { + if (got != expected) + throw new ApplicationException("Failed, got: " + got + " expected: " + expected); } static void Main() { - director_smartptr_MyBarFoo myBarFoo = - new director_smartptr_MyBarFoo(); + FooBar fooBar = new FooBar(); + + Foo myBarFoo = new director_smartptr_MyBarFoo(); + check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()"); + check(Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()"); + check(Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()"); + + Foo myFoo = myBarFoo.makeFoo(); + check(myFoo.pong(), "Foo::pong();Foo::ping()"); + check(Foo.callPong(myFoo), "Foo::pong();Foo::ping()"); + check(myFoo.upcall(new FooBar()), "Bar::Foo2::Foo2Bar()"); - myBarFoo.ping(); + Foo myFoo2 = new Foo().makeFoo(); + check(myFoo2.pong(), "Foo::pong();Foo::ping()"); + check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()"); } } diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs index b4ec47f023d..38f71f97842 100644 --- a/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs +++ b/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs @@ -16,5 +16,12 @@ static void Main() HiddenDestructor hidden = HiddenDestructor.create(); hidden.Dispose(); + + HiddenPrivateDestructor hiddenPrivate = HiddenPrivateDestructor.create(); + if (HiddenPrivateDestructor.DeleteCount != 0) + throw new ApplicationException("Count should be zero"); + hiddenPrivate.Dispose(); + if (HiddenPrivateDestructor.DeleteCount != 1) + throw new ApplicationException("Count should be one"); } } diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs index 62554275122..445c4d74bc2 100644 --- a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs +++ b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs @@ -46,7 +46,7 @@ static void Main() } int actualCount = Klass.getTotal_count(); if (actualCount != expectedCount) - throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount); + Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't } int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count(); diff --git a/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs b/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs index 387d504001a..1f66042a6d1 100644 --- a/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs +++ b/Examples/test-suite/csharp/li_std_auto_ptr_runme.cs @@ -32,7 +32,7 @@ public static void Main() }; int actualCount = Klass.getTotal_count(); if (actualCount != expectedCount) - throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount); + Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't } if (k2.getLabel() != "second") @@ -51,7 +51,7 @@ public static void Main() } int actualCount = Klass.getTotal_count(); if (actualCount != expectedCount) - throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount); + Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't } } } diff --git a/Examples/test-suite/csharp/special_variable_attributes_runme.cs b/Examples/test-suite/csharp/special_variable_attributes_runme.cs new file mode 100644 index 00000000000..eca1abfa37f --- /dev/null +++ b/Examples/test-suite/csharp/special_variable_attributes_runme.cs @@ -0,0 +1,30 @@ + +using System; +using special_variable_attributesNamespace; + +public class special_variable_attributes_runme { + + public static void Main() { + if (special_variable_attributes.getNumber1() != 111) + throw new ApplicationException("getNumber1 failed"); + if (special_variable_attributes.getNumber2() != 222) + throw new ApplicationException("getNumber2 failed"); + if (special_variable_attributes.getNumber3() != 333) + throw new ApplicationException("getNumber3 failed"); + + if (special_variable_attributes.bounceNumber1(10) != 110) + throw new ApplicationException("bounceNumber1 failed"); + if (special_variable_attributes.bounceNumber2(10) != 220) + throw new ApplicationException("bounceNumber2 failed"); + if (special_variable_attributes.bounceNumber3(10) != 330) + throw new ApplicationException("bounceNumber3 failed"); + + if (special_variable_attributes.multi1(12.34) != 12+34) + throw new ApplicationException("multi1 failed"); + if (special_variable_attributes.multi2(12.34) != 12+34+55) + throw new ApplicationException("multi2 failed"); + if (special_variable_attributes.multi3(12.34) != 12+34+77) + throw new ApplicationException("multi3 failed"); + } + +} diff --git a/Examples/test-suite/csharp_exceptions.i b/Examples/test-suite/csharp_exceptions.i index 0f11e7d69d4..e5b4d495b86 100644 --- a/Examples/test-suite/csharp_exceptions.i +++ b/Examples/test-suite/csharp_exceptions.i @@ -198,7 +198,7 @@ enum UnmanagedExceptions { UnmanagedSystemException, UnmanagedArgumentException, UnmanagedArgumentNullException, - UnmanagedArgumentOutOfRangeException, + UnmanagedArgumentOutOfRangeException }; void check_exception(UnmanagedExceptions e) { diff --git a/Examples/test-suite/csharp_typemaps.i b/Examples/test-suite/csharp_typemaps.i index 32e735ca753..dc5b40c0273 100644 --- a/Examples/test-suite/csharp_typemaps.i +++ b/Examples/test-suite/csharp_typemaps.i @@ -77,17 +77,17 @@ public: Number quadruple(Number n) { n.Value *= 4; return n; -}; +} Number times8(const Number& num) { Number n(num); n.Value *= 8; return n; -}; +} Number times12(const Number* num) { Number n(*num); n.Value *= 12; return n; -}; +} %} // Test $csinput expansion diff --git a/Examples/test-suite/d/default_constructor_runme.1.d b/Examples/test-suite/d/default_constructor_runme.1.d index 3640218aeaf..bd79cdf9925 100644 --- a/Examples/test-suite/d/default_constructor_runme.1.d +++ b/Examples/test-suite/d/default_constructor_runme.1.d @@ -1,6 +1,5 @@ module default_constructor_runme; -import default_constructor.FFF; import default_constructor.G; void main() { @@ -15,16 +14,4 @@ void main() { throw e; } } - - // Private destructor test. - try { - { - scope f = new FFF(); - } - throw new Exception("Private destructor exception should have been thrown"); - } catch (Exception e) { - if (e.msg != "C++ destructor does not have public access") { - throw e; - } - } } diff --git a/Examples/test-suite/d/default_constructor_runme.2.d b/Examples/test-suite/d/default_constructor_runme.2.d index 22f5bffd2f3..991b4186a9b 100644 --- a/Examples/test-suite/d/default_constructor_runme.2.d +++ b/Examples/test-suite/d/default_constructor_runme.2.d @@ -1,6 +1,5 @@ module default_constructor_runme; -import default_constructor.FFF; import default_constructor.G; void main() { @@ -8,7 +7,6 @@ void main() { // destruction yet. // enforceThrows((){ scope g = new G(); }, "Protected destructor exception should have been thrown"); - // enforceThrows((){ scope f = new FFF(); }, "Private destructor exception should have been thrown"); } private void enforceThrows(void delegate() dg, string errorMessage) { diff --git a/Examples/test-suite/default_arg_values.i b/Examples/test-suite/default_arg_values.i index 47ca2d12f09..f2fc57c9b5e 100644 --- a/Examples/test-suite/default_arg_values.i +++ b/Examples/test-suite/default_arg_values.i @@ -6,6 +6,12 @@ struct Display { // Bad Python wrappers were being generated when NULL used for primitive type float draw1(float v = 0) { return v; } float draw2(float *v = 0) { return v ? *v : 0; } + bool bool0(bool x = 0) { return x; } + bool bool1(bool x = 1) { return x; } + + typedef bool mybool; + bool mybool0(mybool x = 0) { return x; } + bool mybool1(mybool x = 1) { return x; } }; float* createPtr(float v) { static float val; val = v; return &val; } %} @@ -14,5 +20,11 @@ struct Display { // Bad Python wrappers were being generated when NULL used for primitive type float draw1(float v = NULL) { return v; } float draw2(float *v = NULL) { return v ? *v : 0; } + bool bool0(bool x = 0) { return x; } + bool bool1(bool x = 1) { return x; } + + typedef bool mybool; + bool mybool0(mybool x = 0) { return x; } + bool mybool1(mybool x = 1) { return x; } }; float* createPtr(float v) { static float val; val = v; return &val; } diff --git a/Examples/test-suite/default_args.i b/Examples/test-suite/default_args.i index bcb8766a86c..d3014d3861e 100644 --- a/Examples/test-suite/default_args.i +++ b/Examples/test-suite/default_args.i @@ -114,7 +114,10 @@ %rename(renamed2arg) Foo::renameme(int x) const; %rename(renamed1arg) Foo::renameme() const; +%typemap(default) double* null_by_default "$1=0;"; + %inline %{ + typedef void* MyHandle; // Define a class class Foo { @@ -139,6 +142,12 @@ // test the method itself being renamed void oldname(int x = 1234) {} void renameme(int x = 1234, double d=123.4) const {} + + // test default values for pointer arguments + int double_if_void_ptr_is_null(int n, void* p = NULL) { return p ? n : 2*n; } + int double_if_handle_is_null(int n, MyHandle h = 0) { return h ? n : 2*n; } + int double_if_dbl_ptr_is_null(int n, double* null_by_default) + { return null_by_default ? n : 2*n; } }; int Foo::bar = 1; int Foo::spam = 2; @@ -269,3 +278,26 @@ struct ConstMethods { } Pointf; } %} + +// Default arguments after ignored ones. +%typemap(in, numinputs=0) int square_error { $1 = 2; }; +%typemap(default, noblock=1) int def17 { $1 = 17; }; + +// Enabling autodoc feature has a side effect of disabling the generation of +// aliases for functions that can hide problems with default arguments at +// Python level. +%feature("autodoc","0") slightly_off_square; + +%inline %{ + inline int slightly_off_square(int square_error, int def17) { return def17*def17 + square_error; } +%} + +// Python C default args +%feature("python:cdefaultargs") CDA::cdefaultargs_test1; +%inline %{ +struct CDA { + int cdefaultargs_test1(int a = 1) { return a; } + int cdefaultargs_test2(int a = 1) { return a; } +}; +%} + diff --git a/Examples/test-suite/default_constructor.i b/Examples/test-suite/default_constructor.i index f7fc8cfa6d5..40a088cc9da 100644 --- a/Examples/test-suite/default_constructor.i +++ b/Examples/test-suite/default_constructor.i @@ -13,6 +13,16 @@ SWIGWARN_D_MULTIPLE_INHERITANCE, SWIGWARN_PHP_MULTIPLE_INHERITANCE) AD; /* C#, D, Java, PHP multiple inheritance */ +%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, + SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) GGG; /* C#, D, Java, PHP multiple inheritance */ + +%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, + SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) HHH; /* C#, D, Java, PHP multiple inheritance */ + %warnfilter(SWIGWARN_LANG_FRIEND_IGNORE) F; /* friend function */ %delobject F::destroy; @@ -104,12 +114,21 @@ public: void bar(F *) { } #if defined(_MSC_VER) - #pragma warning(disable: 4624) // : destructor could not be generated because a base class destructor is inaccessible + #pragma warning(disable: 4624) // destructor could not be generated because a base class destructor is inaccessible or deleted #endif + +// Single inheritance, base has private destructor class FFF : public F { }; + +// Multiple inheritance, one base has private destructor +class GGG : public A, public F { +}; +class HHH : public F, public A { +}; + #if defined(_MSC_VER) - #pragma warning(default: 4624) // : destructor could not be generated because a base class destructor is inaccessible + #pragma warning(default: 4624) // destructor could not be generated because a base class destructor is inaccessible or deleted #endif /* A class with a protected destructor */ diff --git a/Examples/test-suite/director_binary_string.i b/Examples/test-suite/director_binary_string.i index f842dc2c706..17bdc1b64df 100644 --- a/Examples/test-suite/director_binary_string.i +++ b/Examples/test-suite/director_binary_string.i @@ -4,6 +4,7 @@ %apply (char *STRING, size_t LENGTH) { (char *dataBufferAA, int sizeAA) }; %apply (char *STRING, size_t LENGTH) { (char *dataBufferBB, int sizeBB) }; +%apply (char* STRING, size_t LENGTH) { (const void* data, size_t datalen) }; %inline %{ #include @@ -20,6 +21,7 @@ public: if (dataBufferBB) memset(dataBufferBB, -1, sizeBB); } + virtual void writeData(const void* data, size_t datalen) = 0; }; class Caller { @@ -50,6 +52,17 @@ public: void call_null() { _callback->run(NULL, 0, NULL, 0); } + int callWriteData() { + int sum = 0; + if (_callback) { + char* aa = (char*)malloc(BUFFER_SIZE_AA); + memset(aa, 9, BUFFER_SIZE_AA); + _callback->writeData(aa, BUFFER_SIZE_AA); + for (int i = 0; i < BUFFER_SIZE_AA; i++) + sum += aa[i]; + } + return sum; + } }; %} diff --git a/Examples/test-suite/director_frob.i b/Examples/test-suite/director_frob.i index cf555eb6631..f1d502dc23b 100644 --- a/Examples/test-suite/director_frob.i +++ b/Examples/test-suite/director_frob.i @@ -1,6 +1,12 @@ %module(directors="1") director_frob; #pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR +#ifdef SWIGSCILAB +%rename(cb) coreCallbacks; +%rename(On3dEngRedrawn) coreCallbacksOn3dEngineRedrawnData; +%rename (_On3dEngRedrawn) coreCallbacks_On3dEngineRedrawnData; +#endif + %header %{ #include %} @@ -17,7 +23,7 @@ virtual ~Alpha() { }; virtual const char* abs_method() = 0; }; - + struct Bravo : Alpha { const char* abs_method() @@ -26,14 +32,14 @@ } }; - struct Charlie : Bravo + struct Charlie : Bravo { const char* abs_method() { return "Charlie::abs_method()"; } }; - + struct Delta : Charlie { }; @@ -50,7 +56,9 @@ public: Ops() : num(0) {} virtual ~Ops() {} +#if !defined(__SUNPRO_CC) virtual operator int() { return 0; } +#endif virtual operator int **() const { return (int **) 0; } diff --git a/Examples/test-suite/director_ignore.i b/Examples/test-suite/director_ignore.i index 57cbc13d870..edb65732062 100644 --- a/Examples/test-suite/director_ignore.i +++ b/Examples/test-suite/director_ignore.i @@ -10,6 +10,7 @@ %ignore OverloadedProtectedMethod(int n, int xoffset = 0, int yoffset = 0); %ignore DIgnoreConstructor(bool b); %ignore DIgnoreOnlyConstructor(bool b); +%ignore DIgnoreDestructor::~DIgnoreDestructor; %ignore Pointers; %ignore References; %ignore PublicMethod1; @@ -101,6 +102,13 @@ class DIgnoreOnlyConstructor DIgnoreOnlyConstructor(bool b) {} }; +class DIgnoreDestructor +{ + public: + DIgnoreDestructor() {} + virtual ~DIgnoreDestructor() {} +}; + %{ class DIgnoreConstructor { @@ -118,5 +126,12 @@ class DIgnoreOnlyConstructor private: // Hide constructor DIgnoreOnlyConstructor(bool b) {} }; -%} +class DIgnoreDestructor +{ + public: + DIgnoreDestructor() {} + virtual ~DIgnoreDestructor() {} +}; + +%} diff --git a/Examples/test-suite/director_overload2.i b/Examples/test-suite/director_overload2.i index 0f3238149d2..e467c18cea6 100644 --- a/Examples/test-suite/director_overload2.i +++ b/Examples/test-suite/director_overload2.i @@ -12,10 +12,14 @@ struct OverloadBase { }; struct OverloadDerived1 : OverloadBase { virtual void nnn(int vvv) {} -// virtual void nnn() {} +#if defined(__SUNPRO_CC) + virtual void nnn() {} +#endif }; struct OverloadDerived2 : OverloadBase { -// virtual void nnn(int vvv) {} +#if defined(__SUNPRO_CC) + virtual void nnn(int vvv) {} +#endif virtual void nnn() {} }; %} diff --git a/Examples/test-suite/director_property.i b/Examples/test-suite/director_property.i index 3363c3c4f27..da37ca4ae1e 100644 --- a/Examples/test-suite/director_property.i +++ b/Examples/test-suite/director_property.i @@ -7,13 +7,13 @@ class Foo { private: - std::string a; + std::string a_; public: virtual ~Foo() {} virtual std::string ping() { return "Foo::ping()"; } virtual std::string pong() { return "Foo::pong();" + ping(); } - virtual std::string getA() { return this->a; } - virtual void setA(std::string a) { this->a = a; } + virtual std::string getA() { return this->a_; } + virtual void setA(std::string a) { this->a_ = a; } static Foo* get_self(Foo *slf) {return slf;} diff --git a/Examples/test-suite/director_ref.i b/Examples/test-suite/director_ref.i new file mode 100644 index 00000000000..8bb8a9b631d --- /dev/null +++ b/Examples/test-suite/director_ref.i @@ -0,0 +1,82 @@ +%module(directors="1") director_ref + +%{ +#include + +class Foo { +public: + Foo(int i = -1) : count(0) {} + virtual void OnDelete() {} + virtual ~Foo() {} + virtual std::string Msg(std::string msg = "default") { return "Foo-" + msg; } + + std::string GetMsg() { return Msg(); } + std::string GetMsg(std::string msg) { return Msg(msg); } + + void Ref() { ++count; } + void Unref() { --count; if (count == 0) { OnDelete(); delete this; } } + int GetRefCount() { return count; } +private: + int count; +}; + +class FooPtr { +public: + FooPtr(Foo* f = NULL) : my_f(f) { if (my_f) { my_f->Ref(); } } + ~FooPtr() { if (my_f) { my_f->Unref(); } } + void Reset(Foo* f = NULL) { + if (f) { f->Ref(); } + if (my_f) { my_f->Unref(); } + my_f = f; + } + int GetOwnedRefCount() { + if (my_f) { return my_f->GetRefCount(); } + return 0; + } + +private: + Foo* my_f; +}; + +%} + +%include + +%feature("director") Foo; +%feature("ref") Foo "$this->Ref();" +%feature("unref") Foo "$this->Unref();" + +class Foo { +public: + Foo(int i = -1) : count(0) {} + virtual void OnDelete() {} + virtual ~Foo() {} + virtual std::string Msg(std::string msg = "default") { return "Foo-" + msg; } + + std::string GetMsg() { return Msg(); } + std::string GetMsg(std::string msg) { return Msg(msg); } + + void Ref() { ++count; } + void Unref() { --count; if (count == 0) { OnDelete(); delete this; } } + int GetRefCount() { return count; } +private: + int count; +}; + +class FooPtr { +public: + FooPtr(Foo* f = NULL) : my_f(f) { if (my_f) { my_f->Ref(); } } + ~FooPtr() { if (my_f) { my_f->Unref(); } } + void Reset(Foo* f = NULL) { + if (f) { f->Ref(); } + if (my_f) { my_f->Unref(); } + my_f = f; + } + int GetOwnedRefCount() { + if (my_f) { return my_f->GetRefCount(); } + return 0; + } + +private: + Foo* my_f; +}; diff --git a/Examples/test-suite/director_smartptr.i b/Examples/test-suite/director_smartptr.i index 13eb745b635..9d0be80f0fa 100644 --- a/Examples/test-suite/director_smartptr.i +++ b/Examples/test-suite/director_smartptr.i @@ -23,16 +23,18 @@ public: virtual ~Foo() {} virtual std::string ping() { return "Foo::ping()"; } virtual std::string pong() { return "Foo::pong();" + ping(); } - virtual std::string fooBar(FooBar* fooBarPtr) { return fooBarPtr->FooBarDo(); } + virtual std::string upcall(FooBar* fooBarPtr) { return fooBarPtr->FooBarDo(); } virtual Foo makeFoo() { return Foo(); } virtual FooBar makeFooBar() { return FooBar(); } + static std::string callPong(Foo &foo) { return foo.pong(); } + static std::string callUpcall(Foo &foo, FooBar* fooBarPtr) { return foo.upcall(fooBarPtr); } static Foo* get_self(Foo *self_) {return self_;} }; %} -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif @@ -61,10 +63,12 @@ public: virtual ~Foo(); virtual std::string ping(); virtual std::string pong(); - virtual std::string fooBar(FooBar* fooBarPtr); + virtual std::string upcall(FooBar* fooBarPtr); virtual Foo makeFoo(); virtual FooBar makeFooBar(); + static std::string callPong(Foo &foo); + static std::string callUpcall(Foo &foo, FooBar* fooBarPtr); static Foo* get_self(Foo *self_); }; diff --git a/Examples/test-suite/empty_c.i b/Examples/test-suite/empty_c.i new file mode 100644 index 00000000000..f5d27ec19f0 --- /dev/null +++ b/Examples/test-suite/empty_c.i @@ -0,0 +1 @@ +%module empty_c diff --git a/Examples/test-suite/enum_forward.i b/Examples/test-suite/enum_forward.i index c82e17be717..784f4fb029a 100644 --- a/Examples/test-suite/enum_forward.i +++ b/Examples/test-suite/enum_forward.i @@ -8,7 +8,20 @@ enum ForwardEnum2 { CCC, DDD }; %} %inline %{ +#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) +/* ISO C forbids forward references to ‘enum’ types [-Werror=pedantic] */ +#pragma GCC diagnostic ignored "-Wpedantic" +#endif + +#if !defined(__SUNPRO_C) enum ForwardEnum1; +enum ForwardEnum2; +enum ForwardEnum2; +enum ForwardEnum3; +#endif +%} + +%inline %{ enum ForwardEnum1 get_enum1() { return AAA; } enum ForwardEnum1 test_function1(enum ForwardEnum1 e) { return e; @@ -16,22 +29,25 @@ enum ForwardEnum1 test_function1(enum ForwardEnum1 e) { %} %inline %{ -enum ForwardEnum2; -enum ForwardEnum2; enum ForwardEnum2 get_enum2() { return CCC; } enum ForwardEnum2 test_function2(enum ForwardEnum2 e) { return e; } -enum ForwardEnum2; %} %inline %{ -enum ForwardEnum3; enum ForwardEnum3 { EEE, FFF }; enum ForwardEnum3 get_enum3() { return EEE; } enum ForwardEnum3 test_function3(enum ForwardEnum3 e) { return e; } +%} + +%inline %{ +#if !defined(__SUNPRO_C) +enum ForwardEnum2; enum ForwardEnum3; +#endif %} + #endif diff --git a/Examples/test-suite/enum_macro.i b/Examples/test-suite/enum_macro.i index b18e02a847f..c058cdf7211 100644 --- a/Examples/test-suite/enum_macro.i +++ b/Examples/test-suite/enum_macro.i @@ -1,6 +1,13 @@ %module enum_macro %inline %{ + +#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) +/* comma at end of enumerator list [-Werror=pedantic] */ +#pragma GCC diagnostic ignored "-Wpedantic" +#endif + + enum Greeks1 { #define GREEK1 -1 diff --git a/Examples/test-suite/enum_missing.i b/Examples/test-suite/enum_missing.i index de71952e712..8a436ba3695 100644 --- a/Examples/test-suite/enum_missing.i +++ b/Examples/test-suite/enum_missing.i @@ -14,10 +14,10 @@ enum AVPixelFormat2 { %} %inline %{ -typedef struct AVCodecContext { +typedef struct AVCodecCtx { enum AVPixelFormat pix_fmt; enum AVPixelFormat2 pix_fmt2; -} AVCodecContext; +} AVCodecCtx; enum AVPixelFormat global_fmt; enum AVPixelFormat2 global_fmt2; @@ -29,7 +29,7 @@ enum AVPixelFormat * use_pixel_format_ptr(enum AVPixelFormat *px) { return px; } -const enum AVPixelFormat2 use_pixel_format2(const enum AVPixelFormat2 px) { +enum AVPixelFormat2 use_pixel_format2(const enum AVPixelFormat2 px) { return px; } const enum AVPixelFormat2 * use_pixel_format_ptr2(const enum AVPixelFormat2 *px) { diff --git a/Examples/test-suite/errors/.gitignore b/Examples/test-suite/errors/.gitignore deleted file mode 100644 index 22ca119479d..00000000000 --- a/Examples/test-suite/errors/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.newerr -cpp_recursive_typedef.py -cpp_shared_ptr.py -xxx.py diff --git a/Examples/test-suite/errors/Makefile.in b/Examples/test-suite/errors/Makefile.in index 4c61001e71e..cf7889a1d4b 100644 --- a/Examples/test-suite/errors/Makefile.in +++ b/Examples/test-suite/errors/Makefile.in @@ -20,6 +20,9 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ +SWIG_LIB_SET = @SWIG_LIB_SET@ +SWIGINVOKE = $(SWIG_LIB_SET) $(SWIGTOOL) $(SWIGEXE) + # All .i files with prefix 'cpp_' will be treated as C++ input and remaining .i files as C input ALL_ERROR_TEST_CASES := $(patsubst %.i,%, $(notdir $(wildcard $(srcdir)/*.i))) CPP_ERROR_TEST_CASES := $(filter cpp_%, $(ALL_ERROR_TEST_CASES)) @@ -32,7 +35,7 @@ include $(srcdir)/../common.mk # Portable dos2unix / todos for stripping CR TODOS = tr -d '\r' -#TODOS = sed -e 's/\r$$//' # On OSX behaves as if written 's/r$$//' +#TODOS = sed -e 's/\r$$//' # On Mac OS X behaves as if written 's/r$$//' # strip source directory from output, so that diffs compare STRIP_SRCDIR = sed -e 's|\\|/|g' -e 's|^$(SRCDIR)||' @@ -40,17 +43,17 @@ STRIP_SRCDIR = sed -e 's|\\|/|g' -e 's|^$(SRCDIR)||' # Rules for the different types of tests %.cpptest: echo "$(ACTION)ing errors testcase $*" - -$(SWIG) -c++ -python -Wall -Fstandard $(SWIGOPT) $(SRCDIR)$*.i 2>&1 | $(TODOS) | $(STRIP_SRCDIR) > $*.$(ERROR_EXT) + -$(SWIGINVOKE) -c++ -python -Wall -Fstandard $(SWIGOPT) $(SRCDIR)$*.i 2>&1 | $(TODOS) | $(STRIP_SRCDIR) > $*.$(ERROR_EXT) $(COMPILETOOL) diff -c $(SRCDIR)$*.stderr $*.$(ERROR_EXT) %.ctest: echo "$(ACTION)ing errors testcase $*" - -$(SWIG) -python -Wall -Fstandard $(SWIGOPT) $(SRCDIR)$*.i 2>&1 | $(TODOS) | $(STRIP_SRCDIR) > $*.$(ERROR_EXT) + -$(SWIGINVOKE) -python -Wall -Fstandard $(SWIGOPT) $(SRCDIR)$*.i 2>&1 | $(TODOS) | $(STRIP_SRCDIR) > $*.$(ERROR_EXT) $(COMPILETOOL) diff -c $(SRCDIR)$*.stderr $*.$(ERROR_EXT) %.clean: @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" python_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' python_clean @rm -f *.$(ERROR_EXT) *.py diff --git a/Examples/test-suite/errors/cpp_macro_locator.i b/Examples/test-suite/errors/cpp_macro_locator.i index bd441a1212a..e00caf00d42 100644 --- a/Examples/test-suite/errors/cpp_macro_locator.i +++ b/Examples/test-suite/errors/cpp_macro_locator.i @@ -100,4 +100,9 @@ void overloadinline2(const int *) {} void overload5(int *) {} void overload5(const int *) {} - +%ignore Outer2::QuietInner; +struct Outer2 { + struct QuietInner { + VARIABLEMACRO(MyInnerVar) + }; +}; diff --git a/Examples/test-suite/errors/cpp_template_friend.i b/Examples/test-suite/errors/cpp_template_friend.i new file mode 100644 index 00000000000..c9d1c9d5d13 --- /dev/null +++ b/Examples/test-suite/errors/cpp_template_friend.i @@ -0,0 +1,26 @@ +%module cpp_template_friend + +template T template_friend1(T); +template T template_friend1(T); +struct MyTemplate1 { + template friend T template_friend1(T); +}; + +template T template_friend2(T); +struct MyTemplate2 { + template friend T template_friend2(T); +}; +template T template_friend2(T); + + +int normal_friend1(int); +int normal_friend1(int); +struct MyClass1 { + friend int normal_friend1(int); +}; + +int normal_friend2(int); +struct MyClass2 { + friend int normal_friend2(int); +}; +int normal_friend2(int); diff --git a/Examples/test-suite/errors/cpp_template_friend.stderr b/Examples/test-suite/errors/cpp_template_friend.stderr new file mode 100644 index 00000000000..8dea195dc0a --- /dev/null +++ b/Examples/test-suite/errors/cpp_template_friend.stderr @@ -0,0 +1,8 @@ +cpp_template_friend.i:4: Warning 302: Identifier 'template_friend1' redefined (ignored), +cpp_template_friend.i:3: Warning 302: previous definition of 'template_friend1'. +cpp_template_friend.i:13: Warning 302: Identifier 'template_friend2' redefined (ignored), +cpp_template_friend.i:9: Warning 302: previous definition of 'template_friend2'. +cpp_template_friend.i:17: Warning 322: Redundant redeclaration of 'normal_friend1', +cpp_template_friend.i:16: Warning 322: previous declaration of 'normal_friend1'. +cpp_template_friend.i:26: Warning 322: Redundant redeclaration of 'normal_friend2', +cpp_template_friend.i:22: Warning 322: previous declaration of 'normal_friend2'. diff --git a/Examples/test-suite/errors/cpp_using_type_aliasing.i b/Examples/test-suite/errors/cpp_using_type_aliasing.i new file mode 100644 index 00000000000..df65dbd3d61 --- /dev/null +++ b/Examples/test-suite/errors/cpp_using_type_aliasing.i @@ -0,0 +1,13 @@ +%module cpp_using_type_aliasing + +namespace Space { + template struct Okay { + }; + struct User { + protected: + using OkayInt = Okay; + }; + struct Derived : User { + Okay ff(); + }; +}; diff --git a/Examples/test-suite/errors/cpp_using_type_aliasing.stderr b/Examples/test-suite/errors/cpp_using_type_aliasing.stderr new file mode 100644 index 00000000000..3f256652f91 --- /dev/null +++ b/Examples/test-suite/errors/cpp_using_type_aliasing.stderr @@ -0,0 +1,3 @@ +cpp_using_type_aliasing.i:8: Warning 341: The 'using' keyword in type aliasing is not fully supported yet. +cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'. +cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'. diff --git a/Examples/test-suite/errors/pp_unknowndirective.i b/Examples/test-suite/errors/pp_unknowndirective.i index 659a997d3bb..b4e608b343f 100644 --- a/Examples/test-suite/errors/pp_unknowndirective.i +++ b/Examples/test-suite/errors/pp_unknowndirective.i @@ -1,5 +1,10 @@ %module xxx +/* Regression test for bug introduced in 3.0.4 and fixed in 3.0.6 - the '%std' + * here led to SWIG calling abort(). + */ +%typemap(jstype) std::vector, const %std::vector&, std::vector& "List" + /* This used to give the rather cryptic "Syntax error in input(1)." prior to * SWIG 3.0.4. This testcase checks that the improved message is actually * issued. diff --git a/Examples/test-suite/errors/pp_unknowndirective.stderr b/Examples/test-suite/errors/pp_unknowndirective.stderr index d0d5e249f4d..2cc2377c791 100644 --- a/Examples/test-suite/errors/pp_unknowndirective.stderr +++ b/Examples/test-suite/errors/pp_unknowndirective.stderr @@ -1 +1 @@ -pp_unknowndirective.i:7: Error: Unknown directive '%remane'. +pp_unknowndirective.i:12: Error: Unknown directive '%remane'. diff --git a/Examples/test-suite/errors/pp_unknowndirective2.i b/Examples/test-suite/errors/pp_unknowndirective2.i index 889e6c5b217..5c914e5078e 100644 --- a/Examples/test-suite/errors/pp_unknowndirective2.i +++ b/Examples/test-suite/errors/pp_unknowndirective2.i @@ -1,6 +1,6 @@ %module xxx -#ifdef FOO +#ifndef FOO long long i; /* Check we get an error for an unknown directive (this should be #elif). * Unknown directives were silently ignored by SWIG < 3.0.3. */ diff --git a/Examples/test-suite/errors/swig_pythoncode_bad.i b/Examples/test-suite/errors/swig_pythoncode_bad.i new file mode 100644 index 00000000000..f1d497618d6 --- /dev/null +++ b/Examples/test-suite/errors/swig_pythoncode_bad.i @@ -0,0 +1,7 @@ +%module xxx + +%pythoncode %{ + def foo(): + a = 1 # This line starts with a tab instead of 8 spaces. + return 2 +%} diff --git a/Examples/test-suite/errors/swig_pythoncode_bad.stderr b/Examples/test-suite/errors/swig_pythoncode_bad.stderr new file mode 100644 index 00000000000..4bded567799 --- /dev/null +++ b/Examples/test-suite/errors/swig_pythoncode_bad.stderr @@ -0,0 +1 @@ +swig_pythoncode_bad.i:7: Error: Line indented less than expected (line 2 of %pythoncode or %insert("python") block) as no line should be indented less than the indentation in line 1 diff --git a/Examples/test-suite/errors/swig_pythoncode_bad2.i b/Examples/test-suite/errors/swig_pythoncode_bad2.i new file mode 100644 index 00000000000..f80f1be8602 --- /dev/null +++ b/Examples/test-suite/errors/swig_pythoncode_bad2.i @@ -0,0 +1,13 @@ +%module xxx + +%pythoncode %{ + def one(): + print "in one" +%} + +%pythoncode %{ + print "still in one" + + def two(): + print "in two" +%} diff --git a/Examples/test-suite/errors/swig_pythoncode_bad2.stderr b/Examples/test-suite/errors/swig_pythoncode_bad2.stderr new file mode 100644 index 00000000000..4fce404442f --- /dev/null +++ b/Examples/test-suite/errors/swig_pythoncode_bad2.stderr @@ -0,0 +1 @@ +swig_pythoncode_bad2.i:13: Error: Line indented less than expected (line 3 of %pythoncode or %insert("python") block) as no line should be indented less than the indentation in line 1 diff --git a/Examples/test-suite/errors/swig_pythoncode_bad3.i b/Examples/test-suite/errors/swig_pythoncode_bad3.i new file mode 100644 index 00000000000..5759158d963 --- /dev/null +++ b/Examples/test-suite/errors/swig_pythoncode_bad3.i @@ -0,0 +1,7 @@ +%module xxx + +%pythoncode %{ + def extra(): + print "extra a" # indentation is 2 spaces then tab + print "extra b" # indentation is tab then 2 spaces +%} diff --git a/Examples/test-suite/errors/swig_pythoncode_bad3.stderr b/Examples/test-suite/errors/swig_pythoncode_bad3.stderr new file mode 100644 index 00000000000..2de4e7d05ff --- /dev/null +++ b/Examples/test-suite/errors/swig_pythoncode_bad3.stderr @@ -0,0 +1 @@ +swig_pythoncode_bad3.i:7: Warning 740: Whitespace indentation is inconsistent compared to earlier lines (line 3 of %pythoncode or %insert("python") block) diff --git a/Examples/test-suite/exception_classname.i b/Examples/test-suite/exception_classname.i new file mode 100644 index 00000000000..a5a76e24de2 --- /dev/null +++ b/Examples/test-suite/exception_classname.i @@ -0,0 +1,10 @@ +%module exception_classname + +%warnfilter(SWIGWARN_RUBY_WRONG_NAME); + +%inline %{ +class Exception { +public: + int testfunc() { return 42; } +}; +%} diff --git a/Examples/test-suite/extend.i b/Examples/test-suite/extend.i index 2a2a472ea2f..29e258f5b94 100644 --- a/Examples/test-suite/extend.i +++ b/Examples/test-suite/extend.i @@ -23,6 +23,9 @@ struct Base { virtual int method(int v) { return v; } +#if !defined(SWIG) + virtual ~Base() {} +#endif }; struct Derived : Base { double actualval; diff --git a/Examples/test-suite/extern_c.i b/Examples/test-suite/extern_c.i index 9c17d18fb77..e56d9f128c9 100644 --- a/Examples/test-suite/extern_c.i +++ b/Examples/test-suite/extern_c.i @@ -14,3 +14,18 @@ typedef int Integer2; void RealFunction(int value) {} %} + +%inline %{ +extern "C" { + typedef void (*Hook1_t)(int, const char *); +} +extern "C" typedef void (*Hook2_t)(int, const char *); +void funcy1(Hook1_t) {} +void funcy2(Hook2_t) {} +Hook1_t hook1; +Hook2_t hook2; + +extern "C" typedef int Integer; +Integer int1; +%} + diff --git a/Examples/test-suite/friends_template.i b/Examples/test-suite/friends_template.i new file mode 100644 index 00000000000..48623f2ca38 --- /dev/null +++ b/Examples/test-suite/friends_template.i @@ -0,0 +1,46 @@ +%module friends_template + +%{ +template class MyClass; + +template int operator<<(double un, const MyClass & x) { return 0; } +template int funk_hidden(double is, MyClass & x) { return 2; } + +template T template_friend_hidden(T t) { return t + 1; } +%} + +%inline %{ +template int operator>>(double is, MyClass & x) { return 1; } +template int funk_seen(double is, MyClass & x) { return 2; } +template T template_friend_seen(T t1, T t2) { return t1 + t2; } +int friend_plain_seen(int i) { return i; } + +template class MyClass +{ + friend int operator<< (double un, const MyClass & x); + friend int operator>> (double is, MyClass & x); + friend int funk_hidden (double is, MyClass & x); + friend int funk_seen (double is, MyClass & x); +}; + +struct MyTemplate { + template friend T template_friend_hidden(T); + template friend T template_friend_seen(T, T); + friend int friend_plain_seen(int i); +}; + +MyClass makeMyClassInt() { return MyClass(); } +%} + +// Although the friends in MyClass are automatically instantiated via %template(MyClassDouble) MyClass, +// the operator friends are not valid and hence %rename is needed. +%rename(OperatorInputDouble) operator>> ; +%rename(OperatorOutputDouble) operator<< ; +%template(MyClassDouble) MyClass; + +%template(TemplateFriendHiddenInt) template_friend_hidden; +%template(TemplateFriendSeenInt) template_friend_seen; + +// These have no %template(XX) MyClass to instantiate, but they can be instantiated separately... +%template(OperatorInputInt) operator>> ; +%template(OperatorFunkSeenInt) funk_seen ; diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 4480ecf1fcb..01989b0d378 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -5,31 +5,43 @@ LANGUAGE = go GO = @GO@ GOGCC = @GOGCC@ +GCCGO = @GCCGO@ GO1 = @GO1@ GO12 = @GO12@ GO13 = @GO13@ +GO15 = @GO15@ GOC = @GOC@ +GOVERSIONOPTION = @GOVERSIONOPTION@ +host = @host@ SCRIPTSUFFIX = _runme.go -GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` -GOLD = $(GOC:c=l) +GOCOMPILEARG = `if $(GO15); then echo tool compile; elif $(GO1); then echo tool $(GOC:c=g); fi` +GOLD = `if $(GO15); then echo link; else echo $(GOC:c=l); fi` GOTOOL = `if $(GO1) ; then echo go tool; fi` GOPACK = `if $(GO1) ; then echo go tool pack; else echo gopack; fi` -GOOBJEXT = $(GOC:c=) +GOOBJEXT = `if $(GO15); then echo o; else echo $(GOC:c=); fi` + +OSXOLDGOLINKFLAGS = `if [ -n "\`$(GO) $(GOVERSIONOPTION) | grep -E 'go1($|.0|.1|.2|.3)'\`" ] && [ -n "\`echo $(host) | grep darwin\`" ]; then echo "-Wl,-U,__cgo_topofstack"; fi` SO = @SO@ -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -top_builddir = @top_builddir@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ CPP_TEST_CASES = \ go_inout \ go_director_inout +MULTI_CPP_TEST_CASES = \ + go_subdir_import + include $(srcdir)/../common.mk +INCLUDES = -I$(abs_top_srcdir)/$(EXAMPLES)/$(TEST_SUITE) + .SUFFIXES: .cpptest .ctest .multicpptest # Rules for the different types of tests @@ -37,37 +49,85 @@ include $(srcdir)/../common.mk $(setup) +$(swig_and_compile_cpp) $(run_testcase_cpp) + if ! $(GO15); then \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ + TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \ + $(LANGUAGE)$(VARIANT)_cpp_nocgo && \ + $(run_testcase_cpp); \ + fi %.ctest: $(setup) +$(swig_and_compile_c) $(run_testcase) + if ! $(GO15); then \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CSRCS='$(CSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ + TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \ + $(LANGUAGE)$(VARIANT)_nocgo && \ + $(run_testcase); \ + fi %.multicpptest: $(setup) +$(swig_and_compile_multi_cpp) $(run_multi_testcase) +li_windows.cpptest: + # Does not work because go build won't build li_windows.go, + # because file names with "windows" are only built on Windows. + multi_import.multicpptest: $(setup) for f in multi_import_b multi_import_a; do \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS)" \ - SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \ - INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \ - TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$$f.i" \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + LIBS='$(LIBS)' INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ + TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR='$(INTERFACEDIR)' INTERFACE="$$f.i" \ $(LANGUAGE)$(VARIANT)_cpp; \ done $(run_multi_testcase) +go_subdir_import.multicpptest: + $(setup) + mkdir -p testdir/go_subdir_import/ + mkdir -p gopath/src/testdir/go_subdir_import/ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + LIBS='$(LIBS)' INTERFACEPATH='$(SRCDIR)$(INTERFACEDIR)go_subdir_import_b.i' \ + INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT) -outdir .' NOLINK=true \ + TARGET='$(TARGETPREFIX)go_subdir_import_b$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' \ + INTERFACE='testdir/go_subdir_import/go_subdir_import_b.i' \ + $(LANGUAGE)$(VARIANT)_cpp; + for f in testdir/go_subdir_import/go_subdir_import_c go_subdir_import_a ; do \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + LIBS='$(LIBS)' INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ + TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR='$(INTERFACEDIR)' INTERFACE="$$f.i" \ + $(LANGUAGE)$(VARIANT)_cpp; \ + done + if $(GOGCC); then \ + cp gopath/src/testdir/go_subdir_import/go_subdir_import_b/go_subdir_import_b.a gopath/src/testdir/go_subdir_import/go_subdir_import_b.gox; \ + cp gopath/src/testdir/go_subdir_import/go_subdir_import_b/go_subdir_import_b.a .; \ + cp gopath/src/testdir/go_subdir_import/go_subdir_import_c/go_subdir_import_c.a gopath/src/testdir/go_subdir_import/go_subdir_import_c.gox; \ + cp gopath/src/testdir/go_subdir_import/go_subdir_import_c/go_subdir_import_c.a testdir/go_subdir_import/; \ + fi + $(run_multi_testcase) + # Runs the testcase. run_testcase = \ if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*_wrap.@OBJEXT@; \ - elif $(GO12) || $(GO13); then \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GCCGO) -c -g -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + $(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.a; \ + elif $(GO12) || $(GO13) || $(GO15); then \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ @@ -75,12 +135,14 @@ run_testcase = \ run_testcase_cpp = \ if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*_wrap.@OBJEXT@ -lstdc++; \ - elif $(GO12) || $(GO13); then \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GCCGO) -c -g -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + $(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.a -lstdc++; \ + elif $(GO12) || $(GO13) || $(GO15); then \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ @@ -88,28 +150,38 @@ run_testcase_cpp = \ run_multi_testcase = \ if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ + $(COMPILETOOL) $(GCCGO) -c -g -I . -I gopath/src $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ files=`cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; \ - $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.@OBJEXT@ $${f}_wrap.@OBJEXT@; done` -lstdc++; \ - elif $(GO12) || $(GO13); then \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.a; done` -lstdc++; \ + elif $(GO12) || $(GO13) || $(GO15); then \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ else \ + $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ $(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi %.clean: - @rm -f $*.go $*_gc.c $*_wrap.* $*_runme + @rm -rf $*.go $*_gc.c $*_wrap.* $*_runme $*.gox $*.a clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" go_clean - rm -f mod_a.go mod_b.go imports_a.go imports_b.go - rm -f clientdata_prop_a.go clientdata_prop_b.go - rm -f multi_import_a.go multi_import_b.go - rm -f packageoption_a.go packageoption_b.go packageoption_c.go - rm -f import_stl_a.go import_stl_b.go + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' go_clean + rm -f mod_a.go mod_a.gox mod_b.go mod_b.gox + rm -f imports_a.go imports_a.gox imports_b.go imports_b.gox + rm -f clientdata_prop_a.go clientdata_prop_a.gox + rm -f clientdata_prop_b.go clientdata_prop_b.gox + rm -f multi_import_a.go multi_import_a.gox + rm -f multi_import_b.go multi_import_b.gox + rm -rf go_subdir_import_a.go go_subdir_import_a.gox testdir + rm -f packageoption_a.go packageoption_a.gox + rm -f packageoption_b.go packageoption_b.gox + rm -f packageoption_c.go packageoption_c.gox + rm -f import_stl_a.go import_stl_a.gox + rm -f import_stl_b.go import_stl_b.gox + rm -rf gopath cvsignore: @echo '*_gc.c *_wrap.* *.so *.dll *.exp *.lib' diff --git a/Examples/test-suite/go/contract_runme.go b/Examples/test-suite/go/contract_runme.go index d86110be2c4..b20a1a64fdc 100644 --- a/Examples/test-suite/go/contract_runme.go +++ b/Examples/test-suite/go/contract_runme.go @@ -196,13 +196,13 @@ func main() { }() //Namespace - my := contract.NewMyClass(1) + contract.NewMyClass(1) func() { defer func() { if recover() == nil { panic("Failed! constructor preassertion") } }() - my = contract.NewMyClass(0) + contract.NewMyClass(0) }() } diff --git a/Examples/test-suite/go/default_constructor_runme.go b/Examples/test-suite/go/default_constructor_runme.go index e5e32547521..40a5a6e49ff 100644 --- a/Examples/test-suite/go/default_constructor_runme.go +++ b/Examples/test-suite/go/default_constructor_runme.go @@ -21,9 +21,6 @@ func main() { f := dc.NewF() f.Destroy() - ff := dc.NewFFF() - ff.Destroy() - g := dc.NewG() dc.GDestroy(g) diff --git a/Examples/test-suite/go/empty_c_runme.go b/Examples/test-suite/go/empty_c_runme.go new file mode 100644 index 00000000000..831a56118c8 --- /dev/null +++ b/Examples/test-suite/go/empty_c_runme.go @@ -0,0 +1,6 @@ +package main + +import _ "./empty_c" + +func main() { +} diff --git a/Examples/test-suite/go/go_subdir_import_runme.go b/Examples/test-suite/go/go_subdir_import_runme.go new file mode 100644 index 00000000000..f90a6eb5464 --- /dev/null +++ b/Examples/test-suite/go/go_subdir_import_runme.go @@ -0,0 +1,16 @@ +package main + +import ( + "go_subdir_import_a" + "testdir/go_subdir_import/go_subdir_import_b" + "testdir/go_subdir_import/go_subdir_import_c" +) + +func main() { + b := go_subdir_import_b.NewObjB(); + c := go_subdir_import_c.NewObjC(); + v := go_subdir_import_a.AddFive(b, c) + if v != 50 { + panic(0) + } +} diff --git a/Examples/test-suite/go/inherit_member_runme.go b/Examples/test-suite/go/inherit_member_runme.go new file mode 100644 index 00000000000..599a0eb5694 --- /dev/null +++ b/Examples/test-suite/go/inherit_member_runme.go @@ -0,0 +1,15 @@ +package main + +import wrap "./inherit_member" + +func main() { + s := wrap.NewChild() + s.SetPvar("p") + s.SetCvar("c") + if s.GetPvar() != "p" { + panic(s.GetPvar()) + } + if s.GetCvar() != "c" { + panic(s.GetCvar()) + } +} diff --git a/Examples/test-suite/go/keyword_rename_c_runme.go b/Examples/test-suite/go/keyword_rename_c_runme.go new file mode 100644 index 00000000000..425e38a267d --- /dev/null +++ b/Examples/test-suite/go/keyword_rename_c_runme.go @@ -0,0 +1,8 @@ +package main + +import "./keyword_rename_c" + +func main() { + keyword_rename_c.Xgo(1) + keyword_rename_c.Xchan(1) +} diff --git a/Examples/test-suite/go/li_carrays_cpp_runme.go b/Examples/test-suite/go/li_carrays_cpp_runme.go new file mode 100644 index 00000000000..7ee0a410373 --- /dev/null +++ b/Examples/test-suite/go/li_carrays_cpp_runme.go @@ -0,0 +1,14 @@ +package main + +import . "./li_carrays_cpp" + +func main() { + d := NewDoubleArray(10) + + d.Setitem(0, 7) + d.Setitem(5, d.Getitem(0)+3) + + if d.Getitem(5)+d.Getitem(0) != 17 { + panic(0) + } +} diff --git a/Examples/test-suite/go/li_cdata_cpp_runme.go b/Examples/test-suite/go/li_cdata_cpp_runme.go new file mode 100644 index 00000000000..42a0ebd0829 --- /dev/null +++ b/Examples/test-suite/go/li_cdata_cpp_runme.go @@ -0,0 +1,13 @@ +package main + +import . "./li_cdata_cpp" + +func main() { + s := "ABC abc" + m := Malloc(256) + Memmove(m, s, len(s)) + ss := Cdata(m, 7) + if string(ss) != "ABC abc" { + panic("failed") + } +} diff --git a/Examples/test-suite/go/li_cpointer_cpp_runme.go b/Examples/test-suite/go/li_cpointer_cpp_runme.go new file mode 100644 index 00000000000..e2f5a59d12a --- /dev/null +++ b/Examples/test-suite/go/li_cpointer_cpp_runme.go @@ -0,0 +1,14 @@ +package main + +import . "./li_cpointer_cpp" + +func main() { + p := New_intp() + Intp_assign(p, 3) + + if Intp_value(p) != 3 { + panic(0) + } + + Delete_intp(p) +} diff --git a/Examples/test-suite/go/overload_extendc_runme.go b/Examples/test-suite/go/overload_extend2_runme.go similarity index 86% rename from Examples/test-suite/go/overload_extendc_runme.go rename to Examples/test-suite/go/overload_extend2_runme.go index 1bdba750938..121506734bc 100644 --- a/Examples/test-suite/go/overload_extendc_runme.go +++ b/Examples/test-suite/go/overload_extend2_runme.go @@ -1,9 +1,9 @@ package main -import "./overload_extendc" +import "./overload_extend2" func main() { - f := overload_extendc.NewFoo() + f := overload_extend2.NewFoo() if f.Test(3) != 1 { panic(0) } diff --git a/Examples/test-suite/go/overload_extend_c_runme.go b/Examples/test-suite/go/overload_extend_c_runme.go new file mode 100644 index 00000000000..e00f0b94531 --- /dev/null +++ b/Examples/test-suite/go/overload_extend_c_runme.go @@ -0,0 +1,22 @@ +package main + +import "./overload_extend_c" + +func main() { + f := overload_extend_c.NewFoo() + if f.Test().(int) != 0 { + panic(0) + } + if f.Test(3).(int) != 1 { + panic(0) + } + if f.Test("hello").(int) != 2 { + panic(0) + } + if f.Test(float64(3), float64(2)).(float64) != 5 { + panic(0) + } + if f.Test(3.0).(float64) != 1003 { + panic(0) + } +} diff --git a/Examples/test-suite/go/overload_polymorphic_runme.go b/Examples/test-suite/go/overload_polymorphic_runme.go index 1720e1a4d57..46f837f49de 100644 --- a/Examples/test-suite/go/overload_polymorphic_runme.go +++ b/Examples/test-suite/go/overload_polymorphic_runme.go @@ -6,6 +6,10 @@ func main(){ t := overload_polymorphic.NewDerived() if overload_polymorphic.Test(t) != 0 { - panic("failed") + panic("failed 1") + } + + if overload_polymorphic.Test2(t) != 1 { + panic("failed 2") } } diff --git a/Examples/test-suite/go_director_inout.i b/Examples/test-suite/go_director_inout.i index af59e313ca3..5a7fbdf89b6 100644 --- a/Examples/test-suite/go_director_inout.i +++ b/Examples/test-suite/go_director_inout.i @@ -44,14 +44,14 @@ type GoRetStruct struct { $result.str.assign($input.p, $input.n); %} -%typemap(out) RetStruct +%typemap(out,fragment="AllocateString") RetStruct %{ - $result = _swig_makegostring($1.str.data(), $1.str.length()); + $result = Swig_AllocateString($1.str.data(), $1.str.length()); %} -%typemap(goout) RetStruct +%typemap(goout,fragment="CopyString") RetStruct %{ - $result = GoRetStruct{Str: $input} + $result = GoRetStruct{Str: swigCopyString($input)} %} %typemap(godirectorout) RetStruct @@ -81,21 +81,26 @@ type GoRetStruct struct { } %} -%typemap(directorin) MyStruct +%typemap(directorin,fragment="AllocateString") MyStruct %{ - $input = _swig_makegostring($1.str.data(), $1.str.length()); + $input = Swig_AllocateString($1.str.data(), $1.str.length()); %} -%typemap(out) MyStruct +%typemap(godirectorin,fragment="CopyString") MyStruct %{ - $result = _swig_makegostring($1.str.data(), $1.str.length()); + if err := json.Unmarshal([]byte(swigCopyString($input)), &$result); err != nil { + panic(err) + } %} -%typemap(godirectorin) MyStruct +%typemap(out,fragment="AllocateString") MyStruct %{ - if err := json.Unmarshal([]byte($input), &$result); err != nil { - panic(err) - } + $result = Swig_AllocateString($1.str.data(), $1.str.length()); +%} + +%typemap(goout,fragment="CopyString") MyStruct +%{ + $result = swigCopyString($input) %} %typemap(in) MyStruct diff --git a/Examples/test-suite/go_inout.i b/Examples/test-suite/go_inout.i index 510ed68e0e6..57e7bf2fb6a 100644 --- a/Examples/test-suite/go_inout.i +++ b/Examples/test-suite/go_inout.i @@ -56,14 +56,14 @@ type In json.Marshaler %typemap(imtype) RetStruct "string" -%typemap(out) RetStruct +%typemap(out,fragment="AllocateString") RetStruct %{ - $result = _swig_makegostring($1.str.data(), $1.str.length()); + $result = Swig_AllocateString($1.str.data(), $1.str.length()); %} -%typemap(goout) RetStruct +%typemap(goout,fragment="CopyString") RetStruct %{ - if err := json.Unmarshal([]byte($1), &$result); err != nil { + if err := json.Unmarshal([]byte(swigCopyString($1)), &$result); err != nil { panic(err) } %} @@ -146,7 +146,7 @@ static void putuint64(std::string *s, size_t off, uint64_t v) { %} // Pack the vector into a string. -%typemap(argout) MyArray* +%typemap(argout,fragment="AllocateString") MyArray* %{ { size_t tot = 8; @@ -164,15 +164,15 @@ static void putuint64(std::string *s, size_t off, uint64_t v) { str.replace(off, p->size(), *p); off += p->size(); } - *$input = _swig_makegostring(str.data(), str.size()); + *$input = Swig_AllocateString(str.data(), str.size()); } %} // Unpack the string into a []string. -%typemap(goargout) MyArray* +%typemap(goargout,fragment="CopyString") MyArray* %{ { - str := *$input + str := swigCopyString(*$input) bin := binary.LittleEndian size := bin.Uint64([]byte(str[:8])) str = str[8:] diff --git a/Examples/test-suite/go_subdir_import.list b/Examples/test-suite/go_subdir_import.list new file mode 100644 index 00000000000..e117d32fa27 --- /dev/null +++ b/Examples/test-suite/go_subdir_import.list @@ -0,0 +1,3 @@ +testdir/go_subdir_import/go_subdir_import_c +go_subdir_import_b +go_subdir_import_a diff --git a/Examples/test-suite/go_subdir_import_a.i b/Examples/test-suite/go_subdir_import_a.i new file mode 100644 index 00000000000..3fc36e6f9bc --- /dev/null +++ b/Examples/test-suite/go_subdir_import_a.i @@ -0,0 +1,37 @@ +/* File : go_subdir_import_a.i */ + +/* + * This files helps check the case where the SWIG-generated .go file needs to + * import another, SWIG-generated, module that is in a relative subdirectory. + * This case might happen for two different reasons: + * 1) Importing a module for which the .i file is in a subdirectory relatively + * to this file (this is tested here with go_subdir_import_c). + * 2) Importing a module whos module name is a path (this is tested here with + * go_subdir_import_b). + * + * This file is the "root" file that imports the two modules which will be + * generated (by swig) in a relative subdirectory. + */ +%module go_subdir_import_a + +%import(module="testdir/go_subdir_import/go_subdir_import_c") "testdir/go_subdir_import/go_subdir_import_c.i" +%import "go_subdir_import_b.i" + +%{ +class ObjC { + public: + virtual int getInt() const; +}; + +class ObjB { + public: + virtual int getInt() const; +}; +%} + +%inline %{ +int AddFive(const ObjB& b, const ObjC& c) { + return b.getInt() + c.getInt() + 5; +} +%} + diff --git a/Examples/test-suite/go_subdir_import_b.i b/Examples/test-suite/go_subdir_import_b.i new file mode 100644 index 00000000000..42544822e9e --- /dev/null +++ b/Examples/test-suite/go_subdir_import_b.i @@ -0,0 +1,12 @@ +/* File : go_subdir_import_b.i */ +%module "testdir/go_subdir_import/go_subdir_import_b" + +%inline %{ +class ObjB { + public: + virtual int getInt() const { + return 27; + } +}; +%} + diff --git a/Examples/test-suite/guile/Makefile.in b/Examples/test-suite/guile/Makefile.in index 9050d76f57a..55885fc2979 100644 --- a/Examples/test-suite/guile/Makefile.in +++ b/Examples/test-suite/guile/Makefile.in @@ -62,4 +62,4 @@ run_testcase = \ @rm -f $*-guile clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" guile_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' guile_clean diff --git a/Examples/test-suite/guile/li_std_string_runme.scm b/Examples/test-suite/guile/li_std_string_runme.scm index 83fc2b5e705..fcf2f58d2be 100644 --- a/Examples/test-suite/guile/li_std_string_runme.scm +++ b/Examples/test-suite/guile/li_std_string_runme.scm @@ -25,7 +25,7 @@ (if (not (try-set-locale "C.UTF-8")) ; Linux (if (not (try-set-locale "en_US.utf8")) ; Linux -(if (not (try-set-locale "en_US.UTF-8")) ; Mac OSX +(if (not (try-set-locale "en_US.UTF-8")) ; Mac OS X (error "Failed to set any UTF-8 locale") ))) diff --git a/Examples/test-suite/guile/overload_extend_c_runme.scm b/Examples/test-suite/guile/overload_extend_c_runme.scm new file mode 100644 index 00000000000..a26b8a95cba --- /dev/null +++ b/Examples/test-suite/guile/overload_extend_c_runme.scm @@ -0,0 +1,2 @@ +(dynamic-call "scm_init_overload_extend_c_module" (dynamic-link "./liboverload_extend_c")) +(load "../schemerunme/overload_extend_c.scm") diff --git a/Examples/test-suite/inherit_member.i b/Examples/test-suite/inherit_member.i new file mode 100644 index 00000000000..c26da6151a0 --- /dev/null +++ b/Examples/test-suite/inherit_member.i @@ -0,0 +1,17 @@ +// Based on https://github.com/swig/swig/issues/339 . + +%module inherit_member + +%include + +%inline %{ + +struct parent_class { + std::string pvar; +}; + + struct child : public parent_class { + std::string cvar; +}; + +%} diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 310f1a77369..3dc6555eff0 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -27,6 +27,7 @@ CPP_TEST_CASES = \ java_director_assumeoverride \ java_director_exception_feature \ java_director_exception_feature_nspace \ + java_director_ptrclass \ java_enums \ java_jnitypes \ java_lib_arrays_dimensionless \ diff --git a/Examples/test-suite/java/char_binary_runme.java b/Examples/test-suite/java/char_binary_runme.java index 9227f86173a..bc811ef5d08 100644 --- a/Examples/test-suite/java/char_binary_runme.java +++ b/Examples/test-suite/java/char_binary_runme.java @@ -20,5 +20,11 @@ public static void main(String argv[]) { if (t.strlen(hil0) != 4) throw new RuntimeException("bad multi-arg typemap"); + + if (t.ustrlen(hile) != 4) + throw new RuntimeException("bad multi-arg typemap"); + + if (t.ustrlen(hil0) != 4) + throw new RuntimeException("bad multi-arg typemap"); } } diff --git a/Examples/test-suite/java/cpp11_constexpr_runme.java b/Examples/test-suite/java/cpp11_constexpr_runme.java index c774e82f857..de1ae8cc32b 100644 --- a/Examples/test-suite/java/cpp11_constexpr_runme.java +++ b/Examples/test-suite/java/cpp11_constexpr_runme.java @@ -23,7 +23,7 @@ public static void main(String argv[]) check(cpp11_constexpr.CCC(), 30); check(cpp11_constexpr.DDD(), 40); - ConstExpressions ce = new ConstExpressions(); + ConstExpressions ce = new ConstExpressions(0); check(ce.JJJ, 100); check(ce.KKK, 200); check(ce.LLL, 300); diff --git a/Examples/test-suite/java/cpp11_type_aliasing_runme.java b/Examples/test-suite/java/cpp11_type_aliasing_runme.java new file mode 100644 index 00000000000..0db1df372d3 --- /dev/null +++ b/Examples/test-suite/java/cpp11_type_aliasing_runme.java @@ -0,0 +1,20 @@ +import cpp11_type_aliasing.*; + +public class cpp11_type_aliasing_runme { + + static { + try { + System.loadLibrary("cpp11_type_aliasing"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + Halide_Target ht = new GeneratorBase().getTarget(); + Target x = ht.getValue(); + if (x.getBits() != 32) + throw new RuntimeException("Incorrect bits"); + } +} diff --git a/Examples/test-suite/java/default_constructor_runme.java b/Examples/test-suite/java/default_constructor_runme.java index 6473c4099b9..eb6a2df535b 100644 --- a/Examples/test-suite/java/default_constructor_runme.java +++ b/Examples/test-suite/java/default_constructor_runme.java @@ -20,13 +20,5 @@ public static void main(String argv[]) throw new RuntimeException("Protected destructor exception should have been thrown"); } catch (UnsupportedOperationException e) { } - - // calling private destructor test - try { - FFF f = new FFF(); - f.delete(); - throw new RuntimeException("Private destructor exception should have been thrown"); - } catch (UnsupportedOperationException e) { - } } } diff --git a/Examples/test-suite/java/director_binary_string_runme.java b/Examples/test-suite/java/director_binary_string_runme.java index 96207336702..14982efc2d7 100644 --- a/Examples/test-suite/java/director_binary_string_runme.java +++ b/Examples/test-suite/java/director_binary_string_runme.java @@ -17,11 +17,15 @@ public static void main(String argv[]) { Callback callback = new DirectorBinaryStringCallback(); caller.setCallback(callback); int sum = caller.call(); + int sumData = caller.callWriteData(); caller.delCallback(); if (sum != 9*2*8 + 13*3*5) throw new RuntimeException("Unexpected sum: " + sum); + if (sumData != 9*2*8) + throw new RuntimeException("Unexpected sum: " + sum); + new Callback().run(null, null); callback = new DirectorBinaryStringCallback(); caller.setCallback(callback); @@ -45,5 +49,13 @@ public void run(byte[] dataBufferAA, byte[] dataBufferBB) for (int i = 0; i < dataBufferBB.length; i++) dataBufferBB[i] = (byte)(dataBufferBB[i] * 3); } + + @Override + public void writeData(byte[] dataBufferAA) + { + if (dataBufferAA != null) + for (int i = 0; i < dataBufferAA.length; i++) + dataBufferAA[i] = (byte)(dataBufferAA[i] * 2); + } } diff --git a/Examples/test-suite/java/director_ref_runme.java b/Examples/test-suite/java/director_ref_runme.java new file mode 100644 index 00000000000..1f85a669800 --- /dev/null +++ b/Examples/test-suite/java/director_ref_runme.java @@ -0,0 +1,71 @@ + +import director_ref.*; + +public class director_ref_runme { + + static { + try { + System.loadLibrary("director_ref"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + director_ref_MyFoo a = new director_ref_MyFoo(); + if (a.GetRefCount() != 1) { + throw new RuntimeException ( "Refcount test 1 failed." ); + } + + // Make sure director logic still works. + if (!a.GetMsg().equals("director_ref_MyFoo-default")) { + throw new RuntimeException ( "Test 1 failed" ); + } + if (!a.GetMsg("boo").equals("director_ref_MyFoo-boo")) { + throw new RuntimeException ( "Test 2 failed" ); + } + + a.delete(); // should delete the object. + if (a.cppDeleted != true) { + throw new RuntimeException ( "Unref test 1 failed." ); + } + + a = new director_ref_MyFoo(); + FooPtr p = new FooPtr(a); + if (a.GetRefCount() != 2) { + throw new RuntimeException ( "Refcount test 2 failed." ); + } + a.delete(); // Shouldn't actually delete the underlying object + if (a.cppDeleted) { + throw new RuntimeException ( "Unref test 2 failed." ); + } + if (p.GetOwnedRefCount() != 1) { + throw new RuntimeException ( "Unref test 3 failed." ); + } + p.Reset(); // Now it should be deleted on the cpp side. + // We can't check cppDeleted because the director will stop + // working after a delete() call. + if (p.GetOwnedRefCount() != 0) { + throw new RuntimeException ( "Unref test 4 failed." ); + } + } +} + +class director_ref_MyFoo extends Foo { + public director_ref_MyFoo() { + super(); + } + public director_ref_MyFoo(int i) { + super(i); + } + public String Msg(String msg) { + return "director_ref_MyFoo-" + msg; + } + public void OnDelete() { + cppDeleted = true; + } + + public boolean cppDeleted = false; +} + diff --git a/Examples/test-suite/java/director_smartptr_runme.java b/Examples/test-suite/java/director_smartptr_runme.java index 8c4ddc5d3af..710ece7107b 100644 --- a/Examples/test-suite/java/director_smartptr_runme.java +++ b/Examples/test-suite/java/director_smartptr_runme.java @@ -12,18 +12,35 @@ public class director_smartptr_runme { } } - public static void main(String argv[]) { - director_smartptr_MyBarFoo myBarFoo = - new director_smartptr_MyBarFoo(); + private static void check(String got, String expected) { + if (!got.equals(expected)) + throw new RuntimeException("Failed, got: " + got + " expected: " + expected); } + public static void main(String argv[]) { + director_smartptr.FooBar fooBar = new director_smartptr.FooBar(); + + director_smartptr.Foo myBarFoo = new director_smartptr_MyBarFoo(); + check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()"); + check(director_smartptr.Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()"); + check(director_smartptr.Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()"); + + director_smartptr.Foo myFoo = myBarFoo.makeFoo(); + check(myFoo.pong(), "Foo::pong();Foo::ping()"); + check(director_smartptr.Foo.callPong(myFoo), "Foo::pong();Foo::ping()"); + check(myFoo.upcall(fooBar), "Bar::Foo2::Foo2Bar()"); + + director_smartptr.Foo myFoo2 = new director_smartptr.Foo().makeFoo(); + check(myFoo2.pong(), "Foo::pong();Foo::ping()"); + check(director_smartptr.Foo.callPong(myFoo2), "Foo::pong();Foo::ping()"); + } } class director_smartptr_MyBarFoo extends director_smartptr.Foo { @Override public String ping() { - return "director_smartptr_MyBarFoo.ping();"; + return "director_smartptr_MyBarFoo.ping()"; } @Override @@ -32,17 +49,12 @@ public String pong() { } @Override - public String fooBar(director_smartptr.FooBar fooBar) { - return fooBar.FooBarDo(); + public String upcall(director_smartptr.FooBar fooBarPtr) { + return "override;" + fooBarPtr.FooBarDo(); } @Override public director_smartptr.Foo makeFoo() { return new director_smartptr.Foo(); } - - @Override - public director_smartptr.FooBar makeFooBar() { - return new director_smartptr.FooBar(); - } -} \ No newline at end of file +} diff --git a/Examples/test-suite/java/friends_template_runme.java b/Examples/test-suite/java/friends_template_runme.java new file mode 100644 index 00000000000..eb66cd5cbea --- /dev/null +++ b/Examples/test-suite/java/friends_template_runme.java @@ -0,0 +1,28 @@ + +import friends_template.*; + +public class friends_template_runme { + + static { + try { + System.loadLibrary("friends_template"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + friends_template.OperatorOutputDouble(1.1, new MyClassDouble()); + friends_template.OperatorInputDouble(1.1, new MyClassDouble()); + friends_template.funk_hidden(1.1, new MyClassDouble()); + friends_template.funk_seen(1.1, new MyClassDouble()); + + friends_template.TemplateFriendHiddenInt(0); + friends_template.TemplateFriendSeenInt(0, 0); + + SWIGTYPE_p_MyClassT_int_t myClassInt = friends_template.makeMyClassInt(); + friends_template.OperatorInputInt(1, myClassInt); + friends_template.OperatorFunkSeenInt(1.1, myClassInt); + } +} diff --git a/Examples/test-suite/java/java_director_ptrclass_runme.java b/Examples/test-suite/java/java_director_ptrclass_runme.java new file mode 100644 index 00000000000..2d78a8f2e68 --- /dev/null +++ b/Examples/test-suite/java/java_director_ptrclass_runme.java @@ -0,0 +1,47 @@ + +import java_director_ptrclass.*; + +public class java_director_ptrclass_runme { + + static { + try { + System.loadLibrary("java_director_ptrclass"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + Foo f = new Foo(); + Foo ft = new TouchingFoo(); + Baz b = new Baz(); + if (b.GetTouched()) { + throw new RuntimeException ( "Baz should not have been touched yet." ); + } + + Baz b2 = f.FinalMaybeTouch(b); + + if (b2.GetTouched() || b.GetTouched()) { + throw new RuntimeException ( "Baz should not have been touched by Foo." ); + } + + Baz b3 = ft.FinalMaybeTouch(b); + + if (!b.GetTouched() || !b3.GetTouched() || !b2.GetTouched()) { + throw new RuntimeException ( "Baz was not touched by TouchingFoo. This" + + " might mean the directorin typemap is not" + + " parsing the typemap(jstype, Bar) in its" + + " 'descriptor' kwarg correctly." ); + } + } +} + +class TouchingFoo extends Foo { + @Override + public Baz MaybeTouch(Baz baz_ptr) { + baz_ptr.SetTouched(); + return baz_ptr; + } +} + diff --git a/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java index d1489edf4d3..aefa81182a2 100644 --- a/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java +++ b/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java @@ -23,5 +23,12 @@ public static void main(String argv[]) HiddenDestructor hidden = HiddenDestructor.create(); hidden.delete(); + + HiddenPrivateDestructor hiddenPrivate = HiddenPrivateDestructor.create(); + if (HiddenPrivateDestructor.getDeleteCount() != 0) + throw new RuntimeException("Count should be zero"); + hiddenPrivate.delete(); + if (HiddenPrivateDestructor.getDeleteCount() != 1) + throw new RuntimeException("Count should be one"); } } diff --git a/Examples/test-suite/java/li_carrays_cpp_runme.java b/Examples/test-suite/java/li_carrays_cpp_runme.java new file mode 100644 index 00000000000..c339a6f561a --- /dev/null +++ b/Examples/test-suite/java/li_carrays_cpp_runme.java @@ -0,0 +1,88 @@ +import li_carrays_cpp.*; + +public class li_carrays_cpp_runme { + + static { + try { + System.loadLibrary("li_carrays_cpp"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) throws Throwable + { + // array_class + { + int length = 5; + XYArray xyArray = new XYArray(length); + for (int i=0; i +class Ptr { +public: + Ptr(T* b) : b_(b) {} + T* Get() const { return b_; } +private: + T* b_; +}; + +class Foo { +public: + // Calling FinalMaybeTouch from Java unambiguously goes through C++ to + // reach MaybeTouch. + Ptr< bar::Baz > FinalMaybeTouch(Baz* b) { + return MaybeTouch(Ptr< bar::Baz >(b)); + } + virtual Ptr< bar::Baz > MaybeTouch(Ptr< bar::Baz > f) { + return f; /* Don't touch */ + } + virtual ~Foo() {} +}; +} +%} + +%feature("director") Foo; + +%typemap(jni) bar::Ptr< bar::Baz > "jlong" +%typemap(jtype) bar::Ptr< bar::Baz > "long" +%typemap(jstype) bar::Ptr< bar::Baz > "Baz" +%typemap(in) bar::Ptr< bar::Baz > { + $1 = bar::Ptr< bar::Baz >(*( bar::Baz**)&$input); +} +%typemap(out) bar::Ptr< bar::Baz > { + const bar::Ptr< bar::Baz >& ptr = $1; + if (ptr.Get()) { + $result = ($typemap(jni, bar::Baz))ptr.Get(); + } else { + $result = 0; + } +} +%typemap(javain) bar::Ptr< bar::Baz > "$typemap(jstype, bar::Baz).getCPtr($javainput)" +%typemap(javaout) bar::Ptr< bar::Baz > { + long cPtr = $jnicall; + return (cPtr == 0) ? null : new $typemap(jstype, bar::Baz)(cPtr, false); +} +%typemap(directorin, descriptor="L$packagepath/$typemap(jstype, bar::Baz);") bar::Ptr< bar::Baz > +%{ *((bar::Baz**)&$input) = ((bar::Ptr< bar::Baz >&)$1).Get(); %} +%typemap(directorout) bar::Ptr< bar::Baz > { + $result = bar::Ptr< bar::Baz >(*( bar::Baz**)&$input); +} +%typemap(javadirectorin) bar::Ptr< bar::Baz > %{ + ((long)$jniinput == 0) ? null : new $typemap(jstype, bar::Baz)($jniinput, false) +%} +%typemap(javadirectorout) bar::Ptr< bar::Baz > "$typemap(jstype, bar::Baz).getCPtr($javacall)" + +namespace bar { +class Baz { +public: + Baz() : touched(false) {} + void SetTouched() { touched = true; } + bool GetTouched() { return touched; } +private: + bool touched; +}; + +template +class Ptr { +public: + Ptr(T* b) : b_(b) {} + T* Get() { return b_; } +private: + T* b_; +}; + +class Foo { +public: + // Calling FinalMaybeTouch from Java unambiguously goes through C++ to + // reach MaybeTouch. + Ptr< bar::Baz > FinalMaybeTouch(Baz* b) { + return MaybeTouch(Ptr< bar::Baz >(b)); + } + virtual Ptr< bar::Baz > MaybeTouch(Ptr< bar::Baz > f) { + return f; /* Don't touch */ + } + virtual ~Foo() {} +}; +} + diff --git a/Examples/test-suite/java_typemaps_proxy.i b/Examples/test-suite/java_typemaps_proxy.i index e315a36b504..3e9b1833578 100644 --- a/Examples/test-suite/java_typemaps_proxy.i +++ b/Examples/test-suite/java_typemaps_proxy.i @@ -31,8 +31,8 @@ import java.lang.*; // for Exception // Create a new getCPtr() function which takes Java null and is public %typemap(javabody) NS::Greeting %{ - private long swigCPtr; - protected boolean swigCMemOwn; + private transient long swigCPtr; + protected transient boolean swigCMemOwn; protected $javaclassname(long cPtr, boolean cMemoryOwn) { swigCMemOwn = cMemoryOwn; @@ -46,8 +46,8 @@ import java.lang.*; // for Exception // Make the pointer constructor public %typemap(javabody) NS::Farewell %{ - private long swigCPtr; - protected boolean swigCMemOwn; + private transient long swigCPtr; + protected transient boolean swigCMemOwn; public $javaclassname(long cPtr, boolean cMemoryOwn) { swigCMemOwn = cMemoryOwn; diff --git a/Examples/test-suite/java_typemaps_typewrapper.i b/Examples/test-suite/java_typemaps_typewrapper.i index a99ca7b6581..b7bf847ef51 100644 --- a/Examples/test-suite/java_typemaps_typewrapper.i +++ b/Examples/test-suite/java_typemaps_typewrapper.i @@ -39,7 +39,7 @@ import java.lang.*; // for Exception // Create a new getCPtr() function which takes Java null and is public // Make the pointer constructor public %typemap(javabody) Farewell * %{ - private long swigCPtr; + private transient long swigCPtr; public $javaclassname(long cPtr, boolean bFutureUse) { swigCPtr = cPtr; diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index 83b15f82282..c68dd22b25a 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -13,7 +13,8 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ -SWIG = $(top_builddir)/preinst_swig +SWIGEXE = $(top_builddir)/swig +SWIG_LIB_DIR = $(top_srcdir)/Lib ifneq (, $(ENGINE)) JSENGINE=$(ENGINE) @@ -53,21 +54,25 @@ ifeq (node,$(JSENGINE)) enum_thorough.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" setup_node = \ - test -d $* || mkdir $*; \ + test -d $* || mkdir $* && \ sed -e 's|$$testcase|$*|g; s|$$cflags|$(GYP_CFLAGS)|g; s|$$srcdir|$(srcdir)|g' \ - $(srcdir)/node_template/binding.gyp.in > $*/binding.gyp; \ + $(srcdir)/node_template/binding.gyp.in > $*/binding.gyp && \ sed -e 's|$$testcase|$*|g;' \ $(srcdir)/node_template/index.js.in > $*/index.js # Note: we need to use swig in C parse mode, but make node-gyp believe it is c++ (via file extension) swig_and_compile_c = \ - $(setup_node); \ - $(SWIG) -javascript $(SWIGOPT) -o $*_wrap.cxx $(srcdir)/../$*.i; \ + $(setup_node) && \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-javascript $(SWIGOPT) -o $*_wrap.cxx $(srcdir)/../$*.i' swiginvoke && \ $(NODEGYP) --loglevel=silent --directory $* configure build 1>>/dev/null swig_and_compile_cpp = \ - $(setup_node); \ - $(SWIG) -c++ -javascript $(SWIGOPT) $(srcdir)/../$*.i; \ + $(setup_node) && \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='-c++ -javascript $(SWIGOPT) $(srcdir)/../$*.i' swiginvoke && \ $(NODEGYP) --loglevel=silent --directory $* configure build 1>>/dev/null run_testcase = \ diff --git a/Examples/test-suite/javascript/char_binary_runme.js b/Examples/test-suite/javascript/char_binary_runme.js index b2aac920caa..01b72ebe14d 100644 --- a/Examples/test-suite/javascript/char_binary_runme.js +++ b/Examples/test-suite/javascript/char_binary_runme.js @@ -5,10 +5,17 @@ if (t.strlen('hile') != 4) { print(t.strlen('hile')); throw("bad multi-arg typemap 1"); } +if (t.ustrlen('hile') != 4) { + print(t.ustrlen('hile')); + throw("bad multi-arg typemap 1"); +} if (t.strlen('hil\0') != 4) { throw("bad multi-arg typemap 2"); } +if (t.ustrlen('hil\0') != 4) { + throw("bad multi-arg typemap 2"); +} /* * creating a raw char* @@ -24,6 +31,9 @@ char_binary.pchar_setitem(pc, 4, 0); if (t.strlen(pc) != 4) { throw("bad multi-arg typemap (3)"); } +if (t.ustrlen(pc) != 4) { + throw("bad multi-arg typemap (3)"); +} char_binary.var_pchar = pc; if (char_binary.var_pchar != "hola") { diff --git a/Examples/test-suite/javascript/empty_c_runme.js b/Examples/test-suite/javascript/empty_c_runme.js new file mode 100644 index 00000000000..1cc22e4ce76 --- /dev/null +++ b/Examples/test-suite/javascript/empty_c_runme.js @@ -0,0 +1 @@ +var empty_c = require("empty_c"); diff --git a/Examples/test-suite/keyword_rename_c.i b/Examples/test-suite/keyword_rename_c.i new file mode 100644 index 00000000000..9c32942712a --- /dev/null +++ b/Examples/test-suite/keyword_rename_c.i @@ -0,0 +1,7 @@ +/* + * Test reserved keyword renaming + */ + +%module keyword_rename_c + +%include "keyword_rename.i" diff --git a/Examples/test-suite/li_attribute_template.i b/Examples/test-suite/li_attribute_template.i index 3d4c108efcc..28551c2cfc0 100644 --- a/Examples/test-suite/li_attribute_template.i +++ b/Examples/test-suite/li_attribute_template.i @@ -27,38 +27,38 @@ struct C { C(int a, int b, int c) : - _a(a), _b(b), _c(c), _d(a), _e(b), + a(a), b(b), c(c), d(a), _e(b), _f(a,b), _g(b,c) { /* - _f.first = _a; - _f.second = _b; + _f.first = a; + _f.second = b; - _g.first = _b; - _g.second = _c; + _g.first = b; + _g.second = c; */ } int get_value() const { - return _a; + return a; } void set_value(int aa) { - _a = aa; + a = aa; } /* only one ref method */ int& get_ref() { - return _b; + return b; } - Foo get_class_value() const { return _d; } - void set_class_value( Foo foo) { _d = foo; } + Foo get_class_value() const { return d; } + void set_class_value( Foo foo) { d = foo; } const Foo& get_class_ref() const { return _e; } void set_class_ref( const Foo& foo ) { _e = foo; } @@ -73,10 +73,10 @@ void set_string(std::string other) { str = other; } private: - int _a; - int _b; - int _c; - Foo _d; + int a; + int b; + int c; + Foo d; Foo _e; pair _f; pair _g; diff --git a/Examples/test-suite/li_boost_array.i b/Examples/test-suite/li_boost_array.i new file mode 100644 index 00000000000..be51d15e081 --- /dev/null +++ b/Examples/test-suite/li_boost_array.i @@ -0,0 +1,85 @@ +%module li_boost_array + +#if defined(SWIGPYTHON) || defined(SWIGRUBY) + +// Hack to use the std::array support for boost::array. +// Is limited as it currently exposes some 'using' bugs in SWIG though. +// For example, the type system fails to see that pointers to std::array +// and pointers to boost::array are the same. + +%{ +#if __cplusplus >= 201103 || (defined(_MSC_VER) && _MSC_VER >= 1900) +// Use C++11 array as this is unfortunately sometimes included by +#include +namespace boost { + using std::array; +} +#else +#include +namespace std { + using boost::array; +} +#endif +%} +namespace boost { + using std::array; +} + +%include + +%template(ArrayInt6) std::array; + +%inline %{ +boost::array arrayOutVal() { + const signed char carray[] = { -2, -1, 0, 0, 1, 2 }; + boost::array myarray; + for (size_t i=0; i<6; ++i) { + myarray[i] = carray[i]; + } + return myarray; +} + +boost::array & arrayOutRef() { + static boost::array a = { -2, -1, 0, 0, 1, 2 }; + return a; +} + +const boost::array & arrayOutConstRef() { + static boost::array a = { -2, -1, 0, 0, 1, 2 }; + return a; +} + +boost::array * arrayOutPtr() { + static boost::array a = { -2, -1, 0, 0, 1, 2 }; + return &a; +} + +boost::array arrayInVal(boost::array myarray) { + for (boost::array::iterator it = myarray.begin(); it!=myarray.end(); ++it) { + *it *= 10; + } + return myarray; +} + +const boost::array & arrayInConstRef(const boost::array & myarray) { + static boost::array a = myarray; + for (boost::array::iterator it = a.begin(); it!=a.end(); ++it) { + *it *= 10; + } + return a; +} + +void arrayInRef(boost::array & myarray) { + for (boost::array::iterator it = myarray.begin(); it!=myarray.end(); ++it) { + *it *= 10; + } +} + +void arrayInPtr(boost::array * myarray) { + for (boost::array::iterator it = myarray->begin(); it!=myarray->end(); ++it) { + *it *= 10; + } +} +%} + +#endif diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index 3d474ec0034..b64197be1ab 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -1,7 +1,7 @@ // This tests shared_ptr is working okay. It also checks that there are no memory leaks in the // class that shared_ptr is pointing via a counting mechanism in the constructors and destructor of Klass. // In order to test that there are no leaks of the shared_ptr class itself (as it is created on the heap) -// the runtime tests can be run for a long time to monitor memory leaks using memory monitor tools +// the runtime tests can be run for a long time to monitor memory leaks using memory monitor tools // like 'top'. There is a wrapper for shared_ptr in shared_ptr_wrapper.h which enables one to // count the instances of shared_ptr. Uncomment the SHARED_PTR_WRAPPER macro to turn this on. // @@ -11,6 +11,16 @@ %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); +#if defined(SWIGSCILAB) +%rename(MbrVar) MemberVariables; +%rename(MbrVal) MemberVariables::MemberValue; +%rename(MbrPtr) MemberVariables::MemberPointer; +%rename(MbrRef) MemberVariables::MemberReference; +%rename(SmartMbrVal) MemberVariables::SmartMemberValue; +%rename(SmartMbrPtr) MemberVariables::SmartMemberPointer; +%rename(SmartMbrRef) MemberVariables::SmartMemberReference; +#endif + %inline %{ #include "boost/shared_ptr.hpp" #include "swig_examples_lock.h" @@ -34,7 +44,7 @@ # define SWIG_SHARED_PTR_NAMESPACE SwigBoost #endif -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif @@ -93,7 +103,7 @@ struct Klass { static int getTotal_count() { return total_count; } private: - // lock increment and decrement as a destructor could be called at the same time as a + // lock increment and decrement as a destructor could be called at the same time as a // new object is being created - C# / Java, at least, have finalizers run in a separate thread static SwigExamples::CriticalSection critical_section; static void increment() { SwigExamples::Lock lock(critical_section); total_count++; if (debug_shared) cout << " ++xxxxx Klass::increment tot: " << total_count << endl;} @@ -104,15 +114,15 @@ private: }; SwigExamples::CriticalSection Space::Klass::critical_section; -struct IgnoredMultipleInheritBase { +struct IgnoredMultipleInheritBase { IgnoredMultipleInheritBase() : d(0.0), e(0.0) {} - virtual ~IgnoredMultipleInheritBase() {} - double d; + virtual ~IgnoredMultipleInheritBase() {} + double d; double e; - virtual void AVirtualMethod() {} + virtual void AVirtualMethod() {} }; -// For most compilers, this use of multiple inheritance results in different derived and base class +// For most compilers, this use of multiple inheritance results in different derived and base class // pointer values ... for some more challenging tests :) struct KlassDerived : IgnoredMultipleInheritBase, Klass { KlassDerived() : Klass() {} @@ -254,7 +264,7 @@ long use_count(const SwigBoost::shared_ptr& sptr) { long use_count(const SwigBoost::shared_ptr& sptr) { return sptr.use_count(); } -const SwigBoost::shared_ptr& ref_1() { +const SwigBoost::shared_ptr& ref_1() { static SwigBoost::shared_ptr sptr; return sptr; } @@ -331,10 +341,15 @@ template struct Base { T2 baseVal2; Base(T1 t1, T2 t2) : baseVal1(t1*2), baseVal2(t2*2) {} virtual std::string getValue() const { return "Base<>"; }; + virtual ~Base() {} }; %} +#if !defined(SWIGSCILAB) %template(BaseIntDouble) Base; +#else +%template(BaseIDbl) Base; +#endif %inline %{ template struct Pair : Base { @@ -356,9 +371,9 @@ SwigBoost::shared_ptr< Pair > pair_id1(SwigBoost::shared_ptr< Pair< %inline %{ namespace SwigBoost { const int NOT_COUNTING = -123456; - int shared_ptr_wrapper_count() { + int shared_ptr_wrapper_count() { #ifdef SHARED_PTR_WRAPPER - return SwigBoost::SharedPtrWrapper::getTotalCount(); + return SwigBoost::SharedPtrWrapper::getTotalCount(); #else return NOT_COUNTING; #endif diff --git a/Examples/test-suite/li_boost_shared_ptr_attribute.i b/Examples/test-suite/li_boost_shared_ptr_attribute.i index c4d3dca360e..f15baa69373 100644 --- a/Examples/test-suite/li_boost_shared_ptr_attribute.i +++ b/Examples/test-suite/li_boost_shared_ptr_attribute.i @@ -1,6 +1,6 @@ %module li_boost_shared_ptr_attribute -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i index 2232b6cf6e3..b61fd2aa60f 100644 --- a/Examples/test-suite/li_boost_shared_ptr_bits.i +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -1,6 +1,6 @@ %module li_boost_shared_ptr_bits -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif @@ -128,5 +128,91 @@ HiddenDestructor::~HiddenDestructor() delete impl_; } %} + +//////////////////////////// +// As above but private instead of protected destructor //////////////////////////// +#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) + +%shared_ptr(HiddenPrivateDestructor) + +#endif + + +%inline %{ +class HiddenPrivateDestructor { +private: + HiddenPrivateDestructor() {} + virtual ~HiddenPrivateDestructor() { + DeleteCount++; + } + + class Deleter { + public: + void operator()(HiddenPrivateDestructor *hidden) { + delete hidden; + } + }; + +public: + static boost::shared_ptr create() { + boost::shared_ptr hidden( new HiddenPrivateDestructor(), HiddenPrivateDestructor::Deleter() ); + return hidden; + } + static int DeleteCount; +}; + +int HiddenPrivateDestructor::DeleteCount = 0; +%} + +///////////////////////////////////////////////// +// Non-public inheritance and shared_ptr +///////////////////////////////////////////////// + +#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) +%shared_ptr(Base) +// No %shared_ptr(DerivedPrivate1) to check Warning 520 does not appear +// No %shared_ptr(DerivedProtected1) to check Warning 520 does not appear +%shared_ptr(DerivedPrivate2) +%shared_ptr(DerivedProtected2) + +%ignore Base2; +%shared_ptr(DerivedPublic) +#endif + +%inline %{ +class Base { +public: + virtual int b() = 0; + virtual ~Base() {} +}; + +class DerivedProtected1 : protected Base { +public: + virtual int b() { return 20; } +}; +class DerivedPrivate1 : private Base { +public: + virtual int b() { return 20; } +}; + +class DerivedProtected2 : protected Base { +public: + virtual int b() { return 20; } +}; +class DerivedPrivate2 : private Base { +public: + virtual int b() { return 20; } +}; + +class Base2 { +public: + virtual int b2() = 0; + virtual ~Base2() {} +}; +class DerivedPublic : public Base2 { +public: + virtual int b2() { return 20; } +}; +%} diff --git a/Examples/test-suite/li_boost_shared_ptr_template.i b/Examples/test-suite/li_boost_shared_ptr_template.i index c1cd32ec623..e3b735c2421 100644 --- a/Examples/test-suite/li_boost_shared_ptr_template.i +++ b/Examples/test-suite/li_boost_shared_ptr_template.i @@ -15,6 +15,7 @@ class Base { public: virtual T bar() {return 1;} + virtual ~Base() {} }; template @@ -29,7 +30,7 @@ %} -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif @@ -79,6 +80,7 @@ template class BaseDefault { public: virtual T bar2() {return 3;} + virtual ~BaseDefault() {} }; template diff --git a/Examples/test-suite/li_carrays_cpp.i b/Examples/test-suite/li_carrays_cpp.i new file mode 100644 index 00000000000..c4743420ef2 --- /dev/null +++ b/Examples/test-suite/li_carrays_cpp.i @@ -0,0 +1,28 @@ +%module li_carrays_cpp + +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) doubleArray; /* Ruby, wrong class name */ + +%include + +%array_functions(int,intArray); +%array_class(double, doubleArray); + +%inline %{ +typedef struct { + int x; + int y; +} XY; +XY globalXYArray[3]; + +typedef struct { + int a; + int b; +} AB; + +AB globalABArray[3]; +%} + +// Note that struct XY { ... }; gives compiler error for C when using %array_class or %array_functions, but is okay in C++ +%array_class(XY, XYArray) +%array_functions(AB, ABArray) + diff --git a/Examples/test-suite/li_cdata_carrays_cpp.i b/Examples/test-suite/li_cdata_carrays_cpp.i new file mode 100644 index 00000000000..9a88b84807d --- /dev/null +++ b/Examples/test-suite/li_cdata_carrays_cpp.i @@ -0,0 +1,8 @@ +%module li_cdata_carrays_cpp + +%include +%array_class(int, intArray); + +%include + +%cdata(int); diff --git a/Examples/test-suite/li_cdata_cpp.i b/Examples/test-suite/li_cdata_cpp.i new file mode 100644 index 00000000000..2d7d300e421 --- /dev/null +++ b/Examples/test-suite/li_cdata_cpp.i @@ -0,0 +1,8 @@ +%module li_cdata_cpp + +%include + +%cdata(int); +%cdata(double); + +void *malloc(size_t size); diff --git a/Examples/test-suite/li_cpointer_cpp.i b/Examples/test-suite/li_cpointer_cpp.i new file mode 100644 index 00000000000..869ce6e6969 --- /dev/null +++ b/Examples/test-suite/li_cpointer_cpp.i @@ -0,0 +1,10 @@ +%module li_cpointer_cpp + +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) doublep; /* Ruby, wrong class name */ + +%include "cpointer.i" + +%pointer_functions(int,intp); +%pointer_class(double,doublep); +%pointer_cast(int, unsigned int, int_to_uint); + diff --git a/Examples/test-suite/li_std_auto_ptr.i b/Examples/test-suite/li_std_auto_ptr.i index 627572d5cb7..5fdc5fa3577 100644 --- a/Examples/test-suite/li_std_auto_ptr.i +++ b/Examples/test-suite/li_std_auto_ptr.i @@ -1,7 +1,7 @@ %module li_std_auto_ptr %{ -#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) +#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // auto_ptr deprecation #endif %} diff --git a/Examples/test-suite/li_std_combinations.i b/Examples/test-suite/li_std_combinations.i index 57f945bcd1e..e28950835f0 100644 --- a/Examples/test-suite/li_std_combinations.i +++ b/Examples/test-suite/li_std_combinations.i @@ -9,15 +9,23 @@ %template(PairIntString) std::pair; %template(VectorPairIntString) std::vector< std::pair >; -%template(PairIntVectorString) std::pair< int, std::vector >; - %template(VectorVectorString) std::vector< std::vector >; + +#if !defined(SWIGSCILAB) +%template(PairIntVectorString) std::pair< int, std::vector >; %template(PairIntPairIntString) std::pair< int, std::pair >; +#else +%template(PairIntVecStr) std::pair< int, std::vector >; +%template(PairIntPairIntStr) std::pair< int, std::pair >; +#endif + #if defined(SWIGCSHARP) || defined(SWIGD) // Checks macro containing a type with a comma SWIG_STD_VECTOR_ENHANCED(std::pair< double, std::string >) #endif + %template(PairDoubleString) std::pair< double, std::string >; %template(VectorPairDoubleString) std::vector< std::pair >; + diff --git a/Examples/test-suite/li_std_container_typemaps.i b/Examples/test-suite/li_std_container_typemaps.i new file mode 100644 index 00000000000..9da32ef8d6e --- /dev/null +++ b/Examples/test-suite/li_std_container_typemaps.i @@ -0,0 +1,132 @@ +%module li_std_container_typemaps + +%include stl.i +%include std_list.i +%include std_deque.i +%include std_set.i +%include std_multiset.i + +%{ +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; +%} + +%inline %{ +class ClassA +{ +public: + ClassA() : a(0) {} + ClassA(int _a) : a(_a) {} + ClassA(const ClassA& c) : a(c.a) {} + int a; +}; + +typedef ClassA* ClassAPtr; + +enum _Color { RED=1, GREEN=10, YELLOW=11, BLUE=100, MAGENTA=101, CYAN=111 }; +typedef enum _Color Color; + +namespace std { + template T binaryOperation(T x, T y) { + return static_cast(x + y); + } + + template<> bool binaryOperation(bool x, bool y) { + return x | y; + } + + template<> ClassAPtr binaryOperation(ClassAPtr x, ClassAPtr y) { + if (x) + y->a += x->a; + return y; + } + + template + struct sequence_container { + typedef typename SeqCont::value_type value_type; + + static SeqCont ret_container(const value_type value1, const value_type value2) { + SeqCont s; + s.insert(s.end(), value1); + s.insert(s.end(), value2); + return s; + } + + static value_type val_container(const SeqCont container) { + return std::accumulate(container.begin(), container.end(), value_type(), + binaryOperation); + } + + static value_type ref_container(const SeqCont& container) { + return std::accumulate(container.begin(), container.end(), value_type(), + binaryOperation); + } + }; + + template + Container ret_container(const T value1, const T value2) { + return sequence_container::ret_container(value1, value2); + } + template + T val_container(const Container container) { + return sequence_container::val_container(container); + } + template + T ref_container(const Container& container) { + return sequence_container::ref_container(container); + } +} +%} + +%define %instantiate_containers_templates(TYPE...) +namespace std +{ + %template(TYPE ## _vector) std::vector; + %template(TYPE ## _list) std::list; + %template(TYPE ## _deque) std::deque; + %template(TYPE ## _set) std::set; + %template(TYPE ## _multiset) std::multiset; +} +%enddef + +%define %instantiate_containers_functions(TYPE...) +namespace std +{ + %template(ret_ ## TYPE ## _vector) ret_container >; + %template(val_ ## TYPE ## _vector) val_container >; + %template(ref_ ## TYPE ## _vector) ref_container >; + %template(ret_ ## TYPE ## _list) ret_container >; + %template(val_ ## TYPE ## _list) val_container >; + %template(ref_ ## TYPE ## _list) ref_container >; + %template(ret_ ## TYPE ## _deque) ret_container >; + %template(val_ ## TYPE ## _deque) val_container >; + %template(ref_ ## TYPE ## _deque) ref_container >; + %template(ret_ ## TYPE ## _set) ret_container >; + %template(val_ ## TYPE ## _set) val_container >; + %template(ref_ ## TYPE ## _set) ref_container >; + %template(ret_ ## TYPE ## _multiset) ret_container >; + %template(val_ ## TYPE ## _multiset) val_container >; + %template(ref_ ## TYPE ## _multiset) ref_container >; +} +%enddef + +%define %instantiate_containers_templates_and_functions(TYPE...) + %instantiate_containers_templates(TYPE); + %instantiate_containers_functions(TYPE); +%enddef + +%instantiate_containers_templates_and_functions(int); +%instantiate_containers_templates_and_functions(double); +%instantiate_containers_templates_and_functions(float); +%instantiate_containers_templates_and_functions(bool); +%instantiate_containers_templates_and_functions(string); +%instantiate_containers_templates_and_functions(ClassAPtr); diff --git a/Examples/test-suite/li_std_pair.i b/Examples/test-suite/li_std_pair.i index 9dea1d814ea..49ccb4aa4a1 100644 --- a/Examples/test-suite/li_std_pair.i +++ b/Examples/test-suite/li_std_pair.i @@ -60,3 +60,20 @@ int product3(const std::pair *p) { %} +// Test that the digraph <::aa::Holder> is not generated for stl containers +%include + +%inline %{ +namespace aa { + struct Holder { + Holder(int n = 0) : number(n) {} + int number; + }; +} +%} + +%template(PairTest) std::pair< ::aa::Holder, int >; + +%inline %{ +std::pair< ::aa::Holder, int > pair1(std::pair< ::aa::Holder, int > x) { return x; } +%} diff --git a/Examples/test-suite/li_std_string.i b/Examples/test-suite/li_std_string.i index 2d0b7503d5e..a1a55ed85c6 100644 --- a/Examples/test-suite/li_std_string.i +++ b/Examples/test-suite/li_std_string.i @@ -83,6 +83,16 @@ void test_const_pointer_throw() throw(const std::string *) { std::string *Structure::StaticMemberString2 }; */ +#ifdef SWIGSCILAB +%rename(St) MemberString; +%rename(Str) MemberString; +%rename(Str2) MemberString2; +%rename(StaticStr) StaticMemberString; +%rename(StaticStr2) StaticMemberString2; +%rename(ConstStr) ConstMemberString; +%rename(ConstStaticStr) ConstStaticMemberString; +#endif + %inline %{ std::string GlobalString; std::string GlobalString2 = "global string 2"; diff --git a/Examples/test-suite/li_std_vector.i b/Examples/test-suite/li_std_vector.i index 55e0f4f6dbe..99fb88a523d 100644 --- a/Examples/test-suite/li_std_vector.i +++ b/Examples/test-suite/li_std_vector.i @@ -108,3 +108,25 @@ const std::vector & vecstructconstptr(const std::vector LanguageVector; } #endif + + +// Test that the digraph <::aa::Holder> is not generated +%include + +%inline %{ +namespace aa { + struct Holder { + Holder(int n = 0) : number(n) {} + int number; + }; +} +%} + +#if !defined(SWIGOCTAVE) +// To fix: something different in Octave is preventing this from working +%template(VectorTest) std::vector< ::aa::Holder >; + +%inline %{ +std::vector< ::aa::Holder > vec1(std::vector< ::aa::Holder > x) { return x; } +%} +#endif diff --git a/Examples/test-suite/li_std_vector_extra.i b/Examples/test-suite/li_std_vector_extra.i index 114de3f11e2..531898a0e17 100644 --- a/Examples/test-suite/li_std_vector_extra.i +++ b/Examples/test-suite/li_std_vector_extra.i @@ -12,6 +12,17 @@ #include #include #include + + +#if defined(__clang__) +// Suppress: +// warning: destination for this 'memset' call is a pointer to dynamic class +// 'Test::B'; vtable pointer will be overwritten [-Wdynamic-class-memaccess] +// memset(v_def,0,sizeof(Type)); +// Better generated code is probably needed though +#pragma clang diagnostic ignored "-Wdynamic-class-memaccess" +#endif + %} namespace std { diff --git a/Examples/test-suite/li_stdint.i b/Examples/test-suite/li_stdint.i index 5186799347f..91017aa2923 100644 --- a/Examples/test-suite/li_stdint.i +++ b/Examples/test-suite/li_stdint.i @@ -3,7 +3,7 @@ %include %inline %{ - struct StdInts { + struct StdI { int8_t int8_member; int16_t int16_member; int32_t int32_member; @@ -23,7 +23,7 @@ uint32_t uint32_td(int32_t i) { return i; } uint64_t uint64_td(int64_t i) { return i; } - struct StdIntFasts { + struct StdIf { int_fast8_t int_fast8_member; int_fast16_t int_fast16_member; int_fast32_t int_fast32_member; @@ -43,7 +43,7 @@ uint_fast32_t uint_fast32_td(int_fast32_t i) { return i; } uint_fast64_t uint_fast64_td(int_fast64_t i) { return i; } - struct StdIntLeasts { + struct StdIl { int_least8_t int_least8_member; int_least16_t int_least16_member; int_least32_t int_least32_member; diff --git a/Examples/test-suite/lua/Makefile.in b/Examples/test-suite/lua/Makefile.in index c562f09df50..7be59214b04 100644 --- a/Examples/test-suite/lua/Makefile.in +++ b/Examples/test-suite/lua/Makefile.in @@ -56,7 +56,7 @@ run_testcase = \ @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" lua_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' lua_clean cvsignore: @echo '*wrap* *.so *.dll *.exp *.lib' diff --git a/Examples/test-suite/lua/chartest_runme.lua b/Examples/test-suite/lua/chartest_runme.lua new file mode 100644 index 00000000000..e15f3dc6b5c --- /dev/null +++ b/Examples/test-suite/lua/chartest_runme.lua @@ -0,0 +1,14 @@ +require("import") -- the import fn +import("chartest") -- import code + +function char_assert(char, code) + assert(type(char) == 'string') + assert(char:len() == 1) + assert(char:byte() == code) +end + +char_assert(chartest.GetPrintableChar(), 0x61) +char_assert(chartest.GetUnprintableChar(), 0x7F) + +char_assert(chartest.printable_global_char, 0x61) +char_assert(chartest.unprintable_global_char, 0x7F) diff --git a/Examples/test-suite/lua/keyword_rename_c_runme.lua b/Examples/test-suite/lua/keyword_rename_c_runme.lua new file mode 100644 index 00000000000..ca4f73cf9da --- /dev/null +++ b/Examples/test-suite/lua/keyword_rename_c_runme.lua @@ -0,0 +1,12 @@ +require("import") -- the import fn +import("keyword_rename_c") -- import lib into global +kn=keyword_rename_c--alias + +-- catching undefined variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +-- Check renaming of Lua keywords +assert(kn.c_end(5) == 5) +assert(kn.c_nil(7) == 7) diff --git a/Examples/test-suite/lua/li_carrays_cpp_runme.lua b/Examples/test-suite/lua/li_carrays_cpp_runme.lua new file mode 100644 index 00000000000..3ead3545764 --- /dev/null +++ b/Examples/test-suite/lua/li_carrays_cpp_runme.lua @@ -0,0 +1,29 @@ +require("import") -- the import fn +import("li_carrays_cpp") -- import code +lc = li_carrays_cpp + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +-- Testing for %array_functions(int,intArray) +ary = lc.new_intArray(2) +lc.intArray_setitem(ary, 0, 0) +lc.intArray_setitem(ary, 1, 1) +assert(lc.intArray_getitem(ary, 0)==0) +assert(lc.intArray_getitem(ary, 1)==1) +lc.delete_intArray(ary) + +-- Testing for %array_class(double, doubleArray) +d = lc.doubleArray(10) +d[0] = 7 +d[5] = d[0] + 3 +assert(d[5] + d[0] == 17) +--print(d[5] + d[0]) + +ptr = d:cast() -- to ptr +d2 = lc.doubleArray_frompointer(ptr) -- and back to array +assert(d2[5] + d2[0] == 17) +--print(d2[5] + d2[0]) + diff --git a/Examples/test-suite/member_funcptr_galore.i b/Examples/test-suite/member_funcptr_galore.i index 962a8bd0e36..9a012f3069b 100644 --- a/Examples/test-suite/member_funcptr_galore.i +++ b/Examples/test-suite/member_funcptr_galore.i @@ -28,6 +28,7 @@ public: void move(double dx, double dy); virtual double area(Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int)) { return 0.0; } virtual double abc(Thing ts, Thing< const Space::Shape * > tda[]) { return 0.0; } + virtual ~Shape() {} }; } diff --git a/Examples/test-suite/mzscheme/Makefile.in b/Examples/test-suite/mzscheme/Makefile.in index da92f76fd0c..3e15f86105a 100644 --- a/Examples/test-suite/mzscheme/Makefile.in +++ b/Examples/test-suite/mzscheme/Makefile.in @@ -46,4 +46,4 @@ run_testcase = \ @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" mzscheme_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/test-suite/nested.i b/Examples/test-suite/nested.i index 004cb4814a4..1d471012839 100644 --- a/Examples/test-suite/nested.i +++ b/Examples/test-suite/nested.i @@ -1,4 +1,4 @@ -/* +/* This testcase tests that nested structs/unions work. Named structs/unions declared within a struct produced redefinition errors in SWIG 1.3.6 as reported by SF bug #447488. Also tests reported error when a #define placed in a deeply embedded struct/union. @@ -6,6 +6,13 @@ Also tests reported error when a #define placed in a deeply embedded struct/unio %module nested + +#if defined(SWIGSCILAB) +%rename(OutStNamed) OuterStructNamed; +%rename(InStNamed) OuterStructNamed::InnerStructNamed; +%rename(InUnNamed) OuterStructNamed::Inner_union_named; +#endif + %inline %{ struct TestStruct { @@ -22,6 +29,13 @@ struct OuterStructNamed { } inner_union_named; }; +%} + + +#if !defined(SWIGSCILAB) + +%inline %{ + struct OuterStructUnnamed { struct { double xx; @@ -32,7 +46,6 @@ struct OuterStructUnnamed { } inner_union_unnamed; }; - typedef struct OuterStruct { union { @@ -52,3 +65,41 @@ typedef struct OuterStruct { } OuterStruct; %} + +#else + +%inline %{ + +struct OutStUnnamed { + struct { + double xx; + } inSt; + union { + double yy; + int zz; + } inUn; +}; + +typedef struct OutSt { + union { + + struct nst_st { + union in_un { +#define BAD_STYLE 1 + int red; + struct TestStruct green; + } InUn; + + struct in_st { + int blue; + } InSt; + } NstdSt; + + } EmbedUn; +} OutSt; + +%} + +#endif + + diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index fe405479c72..b10c339493e 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -1,5 +1,33 @@ %module nested_class + +#if defined(SWIGSCILAB) +%rename(Out) Outer; +%rename(InSt1) InnerStruct1; +%rename(InCls1) InnerClass1; +%rename(InCls2) InnerClass2; +%rename(InClas3Inst) InnerClass3Instance; +%rename(InSt3Inst) InnerStruct3Instance; +%rename(InCls4Type) InnerClass4Typedef; +%rename(InSt4Type) InnerStruct4Typedef; +%rename(InCls5Type) InnerClass5Typedef; +%rename(InSt5Type) InnerStruct5Typedef; +%rename(InMul) InnerMultiple; +%rename(InMulDrv) InnerMultipleDerived; +%rename(MulInst1) MultipleInstance1; +%rename(MulInst2) MultipleInstance2; +%rename(MulInst3) MultipleInstance3; +%rename(MulInst4) MultipleInstance4; +%rename(MulDrvInst1) MultipleDerivedInstance1; +%rename(MulDrvInst2) MultipleDerivedInstance2; +%rename(MulDrvInst3) MultipleDerivedInstance3; +%rename(MulDrvInst4) MultipleDerivedInstance4; +%rename(MulInstAnnDrv1) MultipleInstanceAnonDerived1; +%rename(MulInstAnnDrv2) MultipleInstanceAnonDerived2; +%rename(MulInstAnnDrv3) MultipleInstanceAnonDerived3; +%rename(MulInstAnnDrv4) MultipleInstanceAnonDerived4; +#endif + #pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct1; %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass1; @@ -21,6 +49,16 @@ %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe; %inline %{ + +#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) +/* ISO C++ prohibits anonymous structs [-Werror=pedantic] */ +#pragma GCC diagnostic ignored "-Wpedantic" +#endif + +namespace bar { + int foo() { return 0; } +} + struct Outer { typedef int Integer; /////////////////////////////////////////// @@ -95,10 +133,16 @@ struct Outer { Integer x; } InnerClass4Typedef; +#ifdef _MSC_VER + int Outer::foo(){ return 1; } // should correctly ignore qualification here (#508) +#endif + typedef struct { Integer x; } InnerStruct4Typedef; + friend int bar::foo(); // should parse correctly (#508) + typedef union { Integer x; double y; diff --git a/Examples/test-suite/nested_extend_c.i b/Examples/test-suite/nested_extend_c.i index 64727b9eabf..8fde075a474 100644 --- a/Examples/test-suite/nested_extend_c.i +++ b/Examples/test-suite/nested_extend_c.i @@ -95,7 +95,7 @@ typedef struct { } bar; } FOO; -struct { +static struct { int i; } THING; %} diff --git a/Examples/test-suite/ocaml/Makefile.in b/Examples/test-suite/ocaml/Makefile.in index 9a4e008b992..ecdf32e9f9f 100644 --- a/Examples/test-suite/ocaml/Makefile.in +++ b/Examples/test-suite/ocaml/Makefile.in @@ -3,7 +3,7 @@ ####################################################################### LANGUAGE = ocaml -OCAMLC = ocamlc +OCAMLC = @OCAMLC@ VARIANT = _static SCRIPTSUFFIX = _runme.ml @@ -25,18 +25,11 @@ run_testcase = \ fi ; check_quant: - cat /dev/null > testing - cat /dev/null > success - cat /dev/null > results + : > testing + : > success $(MAKE) check - echo "Failed:" >> results - for element in `cat testing` ; do \ - if grep $$element success >/dev/null 2>/dev/null ; then \ - : ; \ - else \ - echo $$element >> results ; \ - fi ; \ - done + echo "Failed:" > results + diff testing success | sed 's/^< //p;d' >> results echo "Success:" >> results cat success >> results @@ -81,4 +74,4 @@ include $(srcdir)/../common.mk @rm -f $*.ml $*.mli; clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" ocaml_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' ocaml_clean diff --git a/Examples/test-suite/octave/Makefile.in b/Examples/test-suite/octave/Makefile.in index fbffd240cef..be47904e25f 100644 --- a/Examples/test-suite/octave/Makefile.in +++ b/Examples/test-suite/octave/Makefile.in @@ -68,7 +68,7 @@ run_testcase = \ @rm -f $*.m; clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" octave_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' octave_clean cvsignore: @echo '*wrap* *.mc *.so *.dll *.exp *.lib' diff --git a/Examples/test-suite/octave/default_constructor_runme.m b/Examples/test-suite/octave/default_constructor_runme.m index 41d0f3f1e85..ebe553b20f2 100644 --- a/Examples/test-suite/octave/default_constructor_runme.m +++ b/Examples/test-suite/octave/default_constructor_runme.m @@ -14,24 +14,18 @@ catch end_try_catch -del_b = dc.delete_B; - try bb = dc.new_BB(); error("Whoa. new_BB created.") catch end_try_catch -del_bb = dc.delete_BB; - try c = dc.new_C(); error("Whoa. new_C created.") catch end_try_catch -del_c = dc.delete_C; - cc = dc.new_CC(); dc.delete_CC(cc); @@ -41,24 +35,18 @@ catch end_try_catch -del_d = dc.delete_D; - try dd = dc.new_DD(); error("Whoa. new_DD created") catch end_try_catch -dd = dc.delete_DD; - try ad = dc.new_AD(); error("Whoa. new_AD created") catch end_try_catch -del_ad = dc.delete_AD; - e = dc.new_E(); dc.delete_E(e); @@ -71,31 +59,20 @@ catch end_try_catch -del_eb = dc.delete_EB; - f = dc.new_F(); try - del_f = dc.delete_F; + del_f = dc.delete_F(f); error("Whoa. delete_F created") catch end_try_catch dc.F_destroy(f); -ff = dc.new_FFF(); -try - del_ff = dc.delete_FFF; - error("Whoa. delete_FFF created") -catch -end_try_catch - -dc.F_destroy(ff); - g = dc.new_G(); try - del_g = dc.delete_G; + del_g = dc.delete_G(g); error("Whoa. delete_G created") catch end_try_catch diff --git a/Examples/test-suite/octave/empty_c_runme.m b/Examples/test-suite/octave/empty_c_runme.m new file mode 100644 index 00000000000..81264deb17b --- /dev/null +++ b/Examples/test-suite/octave/empty_c_runme.m @@ -0,0 +1,2 @@ +empty_c + diff --git a/Examples/test-suite/octave/li_boost_shared_ptr_runme.m b/Examples/test-suite/octave/li_boost_shared_ptr_runme.m new file mode 100644 index 00000000000..1da0a5725a1 --- /dev/null +++ b/Examples/test-suite/octave/li_boost_shared_ptr_runme.m @@ -0,0 +1,565 @@ +1; +li_boost_shared_ptr; + +function verifyValue(expected, got) + if (expected ~= got) + error("verify value failed.");% Expected: ", expected, " Got: ", got) + end +endfunction + +function verifyCount(expected, k) + got = use_count(k); + if (expected ~= got) + error("verify use_count failed. Expected: %d Got: %d ", expected, got); + end +endfunction + +function runtest() + li_boost_shared_ptr; # KTTODO this needs to be here at present. Global module failure? + # simple shared_ptr usage - created in C++ + k = Klass("me oh my"); + val = k.getValue(); + verifyValue("me oh my", val) + verifyCount(1, k) + + # simple shared_ptr usage - not created in C++ + k = factorycreate(); + val = k.getValue(); + verifyValue("factorycreate", val) + verifyCount(1, k) + + # pass by shared_ptr + k = Klass("me oh my"); + kret = smartpointertest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointertest", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr pointer + k = Klass("me oh my"); + kret = smartpointerpointertest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerpointertest", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr reference + k = Klass("me oh my"); + kret = smartpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerreftest", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr pointer reference + k = Klass("me oh my"); + kret = smartpointerpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerpointerreftest", val) + verifyCount(2, k) + verifyCount(2, kret) + + # const pass by shared_ptr + k = Klass("me oh my"); + kret = constsmartpointertest(k); + val = kret.getValue(); + verifyValue("me oh my", val) + verifyCount(2, k) + verifyCount(2, kret) + + # const pass by shared_ptr pointer + k = Klass("me oh my"); + kret = constsmartpointerpointertest(k); + val = kret.getValue(); + verifyValue("me oh my", val) + verifyCount(2, k) + verifyCount(2, kret) + + # const pass by shared_ptr reference + k = Klass("me oh my"); + kret = constsmartpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by value + k = Klass("me oh my"); + kret = valuetest(k); + val = kret.getValue(); + verifyValue("me oh my valuetest", val) + verifyCount(1, k) + verifyCount(1, kret) + + # pass by pointer + k = Klass("me oh my"); + kret = pointertest(k); + val = kret.getValue(); + verifyValue("me oh my pointertest", val) + verifyCount(1, k) + verifyCount(1, kret) + + # pass by reference + k = Klass("me oh my"); + kret = reftest(k); + val = kret.getValue(); + verifyValue("me oh my reftest", val) + verifyCount(1, k) + verifyCount(1, kret) + + # pass by pointer reference + k = Klass("me oh my"); + kret = pointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my pointerreftest", val) + verifyCount(1, k) + verifyCount(1, kret) + + # null tests + #KTODO None not defined + # k = None; + + # if (smartpointertest(k) ~= None) + # error("return was not null") + # end + + # if (smartpointerpointertest(k) ~= None) + # error("return was not null") + # end + + # if (smartpointerreftest(k) ~= None) + # error("return was not null") + # end + + # if (smartpointerpointerreftest(k) ~= None) + # error("return was not null") + # end + + # if (nullsmartpointerpointertest(None) ~= "null pointer") + # error("not null smartpointer pointer") + # end + + # # try: + # # valuetest(k) + # # error("Failed to catch null pointer") + # # except ValueError: + # # pass + + # if (pointertest(k) ~= None) + # error("return was not null") + # end + + # # try: + # # reftest(k) + # # error("Failed to catch null pointer") + # # except ValueError: + # # pass + + # $owner + k = pointerownertest(); + val = k.getValue(); + verifyValue("pointerownertest", val) + verifyCount(1, k) + k = smartpointerpointerownertest(); + val = k.getValue(); + verifyValue("smartpointerpointerownertest", val) + verifyCount(1, k) + + # //////////////////////////////// Derived class //////////////////////////////////////// + # derived pass by shared_ptr + k = KlassDerived("me oh my"); + kret = derivedsmartptrtest(k); + val = kret.getValue(); + verifyValue("me oh my derivedsmartptrtest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # derived pass by shared_ptr pointer + k = KlassDerived("me oh my"); + kret = derivedsmartptrpointertest(k); + val = kret.getValue(); + verifyValue("me oh my derivedsmartptrpointertest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # derived pass by shared_ptr ref + k = KlassDerived("me oh my"); + kret = derivedsmartptrreftest(k); + val = kret.getValue(); + verifyValue("me oh my derivedsmartptrreftest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # derived pass by shared_ptr pointer ref + k = KlassDerived("me oh my"); + kret = derivedsmartptrpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # derived pass by pointer + k = KlassDerived("me oh my"); + kret = derivedpointertest(k); + val = kret.getValue(); + verifyValue("me oh my derivedpointertest-Derived", val) + verifyCount(1, k) + verifyCount(1, kret) + + # derived pass by ref + k = KlassDerived("me oh my"); + kret = derivedreftest(k); + val = kret.getValue(); + verifyValue("me oh my derivedreftest-Derived", val) + verifyCount(1, k) + verifyCount(1, kret) + + # //////////////////////////////// Derived and base class mixed //////////////////////////////////////// + # pass by shared_ptr (mixed) + k = KlassDerived("me oh my"); + kret = smartpointertest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointertest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr pointer (mixed) + k = KlassDerived("me oh my"); + kret = smartpointerpointertest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerpointertest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr reference (mixed) + k = KlassDerived("me oh my"); + kret = smartpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerreftest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr pointer reference (mixed) + k = KlassDerived("me oh my"); + kret = smartpointerpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerpointerreftest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by value (mixed) + k = KlassDerived("me oh my"); + kret = valuetest(k); + val = kret.getValue(); + verifyValue("me oh my valuetest", val) # note slicing + verifyCount(1, k) + verifyCount(1, kret) + + # pass by pointer (mixed) + k = KlassDerived("me oh my"); + kret = pointertest(k); + val = kret.getValue(); + verifyValue("me oh my pointertest-Derived", val) + verifyCount(1, k) + verifyCount(1, kret) + # pass by ref (mixed) + k = KlassDerived("me oh my"); + kret = reftest(k); + val = kret.getValue(); + verifyValue("me oh my reftest-Derived", val) + verifyCount(1, k) + verifyCount(1, kret) + + # //////////////////////////////// Overloading tests //////////////////////////////////////// + # Base class + k = Klass("me oh my"); + verifyValue(overload_rawbyval(k), "rawbyval") + verifyValue(overload_rawbyref(k), "rawbyref") + verifyValue(overload_rawbyptr(k), "rawbyptr") + verifyValue(overload_rawbyptrref(k), "rawbyptrref") + + verifyValue(overload_smartbyval(k), "smartbyval") + verifyValue(overload_smartbyref(k), "smartbyref") + verifyValue(overload_smartbyptr(k), "smartbyptr") + verifyValue(overload_smartbyptrref(k), "smartbyptrref") + + # Derived class + k = KlassDerived("me oh my"); + verifyValue(overload_rawbyval(k), "rawbyval") + verifyValue(overload_rawbyref(k), "rawbyref") + verifyValue(overload_rawbyptr(k), "rawbyptr") + verifyValue(overload_rawbyptrref(k), "rawbyptrref") + + verifyValue(overload_smartbyval(k), "smartbyval") + verifyValue(overload_smartbyref(k), "smartbyref") + verifyValue(overload_smartbyptr(k), "smartbyptr") + verifyValue(overload_smartbyptrref(k), "smartbyptrref") + + # 3rd derived class + k = Klass3rdDerived("me oh my"); + val = k.getValue(); + verifyValue("me oh my-3rdDerived", val) + verifyCount(1, k) + + val = test3rdupcast(k); + verifyValue("me oh my-3rdDerived", val) + verifyCount(1, k) + + # //////////////////////////////// Member variables //////////////////////////////////////// + # smart pointer by value + m = MemberVariables(); + k = Klass("smart member value"); + m.SmartMemberValue = k; + val = k.getValue(); + verifyValue("smart member value", val) + verifyCount(2, k) + + kmember = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member value", val) + verifyCount(3, kmember) + verifyCount(3, k) + + clear m + verifyCount(2, kmember) + verifyCount(2, k) + + # smart pointer by pointer + m = MemberVariables(); + k = Klass("smart member pointer"); + m.SmartMemberPointer = k; + val = k.getValue(); + verifyValue("smart member pointer", val) + verifyCount(1, k) + + kmember = m.SmartMemberPointer; + val = kmember.getValue(); + verifyValue("smart member pointer", val) + verifyCount(2, kmember) + verifyCount(2, k) + + clear m + verifyCount(2, kmember) + verifyCount(2, k) + + # smart pointer by reference + m = MemberVariables(); + k = Klass("smart member reference"); + m.SmartMemberReference = k; + val = k.getValue(); + verifyValue("smart member reference", val) + verifyCount(2, k) + + kmember = m.SmartMemberReference; + val = kmember.getValue(); + verifyValue("smart member reference", val) + verifyCount(3, kmember) + verifyCount(3, k) + + # The C++ reference refers to SmartMemberValue... + kmemberVal = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member reference", val) + verifyCount(4, kmemberVal) + verifyCount(4, kmember) + verifyCount(4, k) + + clear m + verifyCount(3, kmemberVal) + verifyCount(3, kmember) + verifyCount(3, k) + + # plain by value + m = MemberVariables(); + k = Klass("plain member value"); + m.MemberValue = k; + val = k.getValue(); + verifyValue("plain member value", val) + verifyCount(1, k) + + kmember = m.MemberValue; + val = kmember.getValue(); + verifyValue("plain member value", val) + verifyCount(1, kmember) + verifyCount(1, k) + + clear m + verifyCount(1, kmember) + verifyCount(1, k) + + # plain by pointer + m = MemberVariables(); + k = Klass("plain member pointer"); + m.MemberPointer = k; + val = k.getValue(); + verifyValue("plain member pointer", val) + verifyCount(1, k) + + kmember = m.MemberPointer; + val = kmember.getValue(); + verifyValue("plain member pointer", val) + verifyCount(1, kmember) + verifyCount(1, k) + + clear m + verifyCount(1, kmember) + verifyCount(1, k) + + # plain by reference + m = MemberVariables(); + k = Klass("plain member reference"); + m.MemberReference = k; + val = k.getValue(); + verifyValue("plain member reference", val) + verifyCount(1, k) + + kmember = m.MemberReference; + val = kmember.getValue(); + verifyValue("plain member reference", val) + verifyCount(1, kmember) + verifyCount(1, k) + + clear m + verifyCount(1, kmember) + verifyCount(1, k) + + # null member variables + m = MemberVariables(); + + # shared_ptr by value + k = m.SmartMemberValue; + #KTODO None not defined + # if (k ~= None) + # error("expected null") + # end + + # m.SmartMemberValue = None + # k = m.SmartMemberValue + # if (k ~= None) + # error("expected null") + # end + # verifyCount(0, k) + + # # plain by value + # # try: + # # m.MemberValue = None + # # error("Failed to catch null pointer") + # # except ValueError: + # # pass + + # # ////////////////////////////////// Global variables //////////////////////////////////////// + # # smart pointer + # kglobal = cvar.GlobalSmartValue + # if (kglobal ~= None) + # error("expected null") + # end + + k = Klass("smart global value"); + cvar.GlobalSmartValue = k; + verifyCount(2, k) + + kglobal = cvar.GlobalSmartValue; + val = kglobal.getValue(); + verifyValue("smart global value", val) + verifyCount(3, kglobal) + verifyCount(3, k) + verifyValue("smart global value", cvar.GlobalSmartValue.getValue()) + #KTTODO cvar.GlobalSmartValue = None + + # plain value + k = Klass("global value"); + cvar.GlobalValue = k; + verifyCount(1, k) + + kglobal = cvar.GlobalValue; + val = kglobal.getValue(); + verifyValue("global value", val) + verifyCount(1, kglobal) + verifyCount(1, k) + verifyValue("global value", cvar.GlobalValue.getValue()) + + # try: + # cvar.GlobalValue = None + # error("Failed to catch null pointer") + # except ValueError: + # pass + + # plain pointer + kglobal = cvar.GlobalPointer; + #KTODO if (kglobal ~= None) + #KTODO error("expected null") + #KTODO end + + k = Klass("global pointer"); + cvar.GlobalPointer = k; + verifyCount(1, k) + + kglobal = cvar.GlobalPointer; + val = kglobal.getValue(); + verifyValue("global pointer", val) + verifyCount(1, kglobal) + verifyCount(1, k) + #KTODO cvar.GlobalPointer = None + + # plain reference + k = Klass("global reference"); + cvar.GlobalReference = k; + verifyCount(1, k) + + kglobal = cvar.GlobalReference; + val = kglobal.getValue(); + verifyValue("global reference", val) + verifyCount(1, kglobal) + verifyCount(1, k) + + # try: + # cvar.GlobalReference = None + # error("Failed to catch null pointer") + # except ValueError: + # pass + + # ////////////////////////////////// Templates //////////////////////////////////////// + pid = PairIntDouble(10, 20.2); + if (pid.baseVal1 ~= 20 || pid.baseVal2 ~= 40.4) + error("Base values wrong") + end + if (pid.val1 ~= 10 || pid.val2 ~= 20.2) + error("Derived Values wrong") + end + +endfunction + +debug = false;%true; + + if (debug) + fprintf( "Started\n" ) + end + + cvar.debug_shared = debug; + + # Change loop count to run for a long time to monitor memory + loopCount = 1; #5000 + for i=0:loopCount + runtest() + end + + # Expect 1 instance - the one global variable (GlobalValue) + #KTTODO next fails, possibly because we commented GlobalSmartValue=None + #if (Klass.getTotal_count() ~= 1) + # error("Klass.total_count=%d", Klass.getTotal_count()) + #end + + wrapper_count = shared_ptr_wrapper_count() ; + #KTTODO next fails as NOT_COUNTING not in octave name space, so we hard-wire it here + #if (wrapper_count ~= NOT_COUNTING) + if (wrapper_count ~= -123456) + # Expect 1 instance - the one global variable (GlobalSmartValue) + if (wrapper_count ~= 1) + error("shared_ptr wrapper count=%s", wrapper_count) + end + end + + if (debug) + fprintf( "Finished\n" ) + end diff --git a/Examples/test-suite/octave/li_carrays_cpp_runme.m b/Examples/test-suite/octave/li_carrays_cpp_runme.m new file mode 100644 index 00000000000..d5b92139ecb --- /dev/null +++ b/Examples/test-suite/octave/li_carrays_cpp_runme.m @@ -0,0 +1,10 @@ +li_carrays_cpp + +d = doubleArray(10); + +d(0) = 7; +d(5) = d(0) + 3; + +if (d(5) + d(0) != 17) + error +endif diff --git a/Examples/test-suite/octave/li_cpointer_cpp_runme.m b/Examples/test-suite/octave/li_cpointer_cpp_runme.m new file mode 100644 index 00000000000..463cf44f855 --- /dev/null +++ b/Examples/test-suite/octave/li_cpointer_cpp_runme.m @@ -0,0 +1,12 @@ +li_cpointer_cpp + + +p = new_intp(); +intp_assign(p,3); + +if (intp_value(p) != 3) + error +endif + +delete_intp(p); + diff --git a/Examples/test-suite/octave/overload_extendc_runme.m b/Examples/test-suite/octave/overload_extend2_runme.m similarity index 88% rename from Examples/test-suite/octave/overload_extendc_runme.m rename to Examples/test-suite/octave/overload_extend2_runme.m index fec586d4f2c..6db6b66bbd4 100644 --- a/Examples/test-suite/octave/overload_extendc_runme.m +++ b/Examples/test-suite/octave/overload_extend2_runme.m @@ -1,6 +1,6 @@ -overload_extendc +overload_extend2 -f = overload_extendc.Foo(); +f = overload_extend2.Foo(); if (f.test(3) != 1) error endif diff --git a/Examples/test-suite/octave/overload_extend_c_runme.m b/Examples/test-suite/octave/overload_extend_c_runme.m new file mode 100644 index 00000000000..aa6bb5b5bed --- /dev/null +++ b/Examples/test-suite/octave/overload_extend_c_runme.m @@ -0,0 +1,19 @@ +overload_extend_c + +f = overload_extend_c.Foo(); +if (f.test() != 0) + error +endif +if (f.test(3) != 1) + error +endif +if (f.test("hello") != 2) + error +endif +if (f.test(3,2) != 5) + error +endif +if (f.test(3.1)-.1 != 1003) # :) + error +endif + diff --git a/Examples/test-suite/operator_overload.i b/Examples/test-suite/operator_overload.i index 061e7024c13..90f767a847f 100644 --- a/Examples/test-suite/operator_overload.i +++ b/Examples/test-suite/operator_overload.i @@ -73,12 +73,6 @@ see bottom for a set of possible tests %rename(OrOperator) operator ||; #endif -#ifdef SWIG_ALLEGRO_CL -%{ -#include -%} -#endif - #ifdef SWIGD // Due to the way operator overloading is implemented in D1 and D2, the prefix // increment/decrement operators (D1) resp. the postfix ones (D2) are ignored. @@ -89,6 +83,7 @@ see bottom for a set of possible tests %rename(DoubleCast) operator double(); %inline %{ +#include #if defined(_MSC_VER) #include /* for named logical operator, eg 'operator or' */ diff --git a/Examples/test-suite/operator_overload_break.i b/Examples/test-suite/operator_overload_break.i index f5f3c1a4630..a948f2d492f 100644 --- a/Examples/test-suite/operator_overload_break.i +++ b/Examples/test-suite/operator_overload_break.i @@ -12,6 +12,10 @@ %rename(PlusPlusPostfix) operator++(int); #endif +%ignore operator new (size_t); +%ignore operator delete (void *); +%ignore operator delete[] (void *); + %{ #include using namespace std; @@ -60,4 +64,16 @@ public: int k; }; +struct Op2 { + void *operator new + (size_t); // definition split over two lines was giving syntax error + void operator delete /* comment here did not work */ (void *); + void operator + delete[] (void *); +}; + +void *Op2::operator new(size_t) { return malloc(sizeof(Op)); } +void Op2::operator delete(void *p) { free(p); } +void Op2::operator delete[] (void *) {} + %} diff --git a/Examples/test-suite/overload_arrays.i b/Examples/test-suite/overload_arrays.i new file mode 100644 index 00000000000..42c08390a63 --- /dev/null +++ b/Examples/test-suite/overload_arrays.i @@ -0,0 +1,148 @@ +// Tests of overloaded functions of arrays +// Based on overload_simple testcase +%module overload_arrays + +#ifdef SWIGCHICKEN +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fbool; +#endif + +#ifdef SWIGLUA +// lua only has one numeric type, so most of the overloads shadow each other creating warnings +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) foo; +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) bar; +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Spam; +#endif + +#ifdef SWIGGO +%warnfilter(SWIGWARN_PARSE_KEYWORD) type; // 'type' is a Go keyword, renamed as 'Xtype' +%rename(Foos) Foo; +#endif + + + +#ifndef SWIG_NO_OVERLOAD +%immutable Spam::type; + +%inline %{ + +#define SIZE 3 + +struct Foo { +}; + +class Bar { +public: + Bar(int i = 0) { num = i; } + + static int foo(int a=0, int b=0) {return 0;} + + int num; +}; + +char *foo() { + return (char *) "foo:"; +} +char *foo(int[SIZE]) { + return (char*) "foo:int[SIZE]"; +} + +char *foo(double[SIZE]) { + return (char*) "foo:double[SIZE]"; +} + +char *foo(char *[SIZE]) { + return (char*) "foo:char *[SIZE]"; +} + +char *foo(Foo *[SIZE]) { + return (char*) "foo:Foo *[SIZE]"; +} +char *foo(Bar *[SIZE]) { + return (char *) "foo:Bar *[SIZE]"; +} +char *foo(void *[SIZE]) { + return (char *) "foo:void *[SIZE]"; +} +char *foo(Foo *[SIZE], int[SIZE]) { + return (char *) "foo:Foo *[SIZE],int[SIZE]"; +} +char *foo(double[SIZE], Bar *[SIZE]) { + return (char *) "foo:double[SIZE],Bar *[SIZE]"; +} + +char *blah(double[SIZE]) { + return (char *) "blah:double[SIZE]"; +} + +char *blah(char *[SIZE]) { + return (char *) "blah:char *[SIZE]"; +} + +class Spam { +public: + Spam() { type = "none"; } + Spam(int[SIZE]) { type = "int[SIZE]"; } + Spam(double[SIZE]) { type = "double[SIZE]"; } + Spam(char *[SIZE]) { type = "char *[SIZE]"; } + Spam(Foo *[SIZE]) { type = "Foo *[SIZE]"; } + Spam(Bar *[SIZE]) { type = "Bar *[SIZE]"; } + Spam(void *[SIZE]) { type = "void *[SIZE]"; } + const char *type; + +char *foo(int[SIZE]) { + return (char*) "foo:int[SIZE]"; +} +char *foo(double[SIZE]) { + return (char*) "foo:double[SIZE]"; +} +char *foo(char *[SIZE]) { + return (char*) "foo:char *[SIZE]"; +} +char *foo(Foo *[SIZE]) { + return (char*) "foo:Foo *[SIZE]"; +} +char *foo(Bar *[SIZE]) { + return (char *) "foo:Bar *[SIZE]"; +} +char *foo(void *[SIZE]) { + return (char *) "foo:void *[SIZE]"; +} + +static char *bar(int[SIZE]) { + return (char*) "bar:int[SIZE]"; +} +static char *bar(double[SIZE]) { + return (char*) "bar:double[SIZE]"; +} +static char *bar(char *[SIZE]) { + return (char*) "bar:char *[SIZE]"; +} +static char *bar(Foo *[SIZE]) { + return (char*) "bar:Foo *[SIZE]"; +} +static char *bar(Bar *[SIZE]) { + return (char *) "bar:Bar *[SIZE]"; +} +static char *bar(void *[SIZE]) { + return (char *) "bar:void *[SIZE]"; +} +}; + +%} + +#endif + + +%inline { + class ClassA + { + public: + ClassA() {} + int method1( ) {return 0;} + int method1( int arg1[SIZE] ) {return arg1[0];} + protected: + int method1( int arg1[SIZE], int arg2[SIZE] ) {return arg1[0] + arg2[0];} + + }; +} + diff --git a/Examples/test-suite/overload_extendc.i b/Examples/test-suite/overload_extend2.i similarity index 94% rename from Examples/test-suite/overload_extendc.i rename to Examples/test-suite/overload_extend2.i index 1c1dd00b65c..f9173860780 100644 --- a/Examples/test-suite/overload_extendc.i +++ b/Examples/test-suite/overload_extend2.i @@ -1,4 +1,4 @@ -%module overload_extendc +%module overload_extend2 %typemap(default) int int2 "$1=1000;"; diff --git a/Examples/test-suite/overload_extend_c.i b/Examples/test-suite/overload_extend_c.i new file mode 100644 index 00000000000..77a9287a27a --- /dev/null +++ b/Examples/test-suite/overload_extend_c.i @@ -0,0 +1,3 @@ +%module overload_extend_c + +%include "overload_extend.i" diff --git a/Examples/test-suite/overload_polymorphic.i b/Examples/test-suite/overload_polymorphic.i index a1f123b9da8..ac004f94869 100644 --- a/Examples/test-suite/overload_polymorphic.i +++ b/Examples/test-suite/overload_polymorphic.i @@ -19,4 +19,8 @@ public: int test(Base* base){ return 0;} int test(int hello){ return 1; } +class Unknown; +int test2(Unknown* unknown) { return 0; } +int test2(Base* base) { return 1; } + %} diff --git a/Examples/test-suite/perl5/Makefile.in b/Examples/test-suite/perl5/Makefile.in index ccd12d6e40a..48d5fa5d122 100644 --- a/Examples/test-suite/perl5/Makefile.in +++ b/Examples/test-suite/perl5/Makefile.in @@ -13,14 +13,12 @@ top_builddir = @top_builddir@ CPP_TEST_CASES += \ primitive_types \ - li_cdata \ li_cstring \ - li_cdata_carrays \ + li_cdata_carrays_cpp \ li_reference \ director_nestedmodule \ C_TEST_CASES += \ - li_cdata \ li_cstring \ li_cdata_carrays \ @@ -60,4 +58,4 @@ run_testcase = \ @rm -f $*.pm; clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" perl5_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/test-suite/perl5/char_binary_runme.pl b/Examples/test-suite/perl5/char_binary_runme.pl index 4c50ee700ed..f97d740a692 100644 --- a/Examples/test-suite/perl5/char_binary_runme.pl +++ b/Examples/test-suite/perl5/char_binary_runme.pl @@ -1,14 +1,16 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 10; BEGIN { use_ok('char_binary') } require_ok('char_binary'); my $t = char_binary::Test->new(); is($t->strlen('hile'), 4, "string typemap"); +is($t->ustrlen('hile'), 4, "unsigned string typemap"); is($t->strlen("hil\0"), 4, "string typemap"); +is($t->ustrlen("hil\0"), 4, "unsigned string typemap"); # # creating a raw char* @@ -22,6 +24,7 @@ is($t->strlen($pc), 4, "string typemap"); +is($t->ustrlen($pc), 4, "unsigned string typemap"); $char_binary::var_pchar = $pc; is($char_binary::var_pchar, "hola", "pointer case"); diff --git a/Examples/test-suite/perl5/li_carrays_cpp_runme.pl b/Examples/test-suite/perl5/li_carrays_cpp_runme.pl new file mode 100644 index 00000000000..17019253ec1 --- /dev/null +++ b/Examples/test-suite/perl5/li_carrays_cpp_runme.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More tests => 34; +BEGIN { use_ok('li_carrays_cpp') } +require_ok('li_carrays_cpp'); + +# array_class +{ + my $length = 5; + my $xyArray = new li_carrays_cpp::XYArray($length); + for (my $i=0; $i<$length; $i++) { + my $xy = $xyArray->getitem($i); + $xy->{x} = $i*10; + $xy->{y} = $i*100; + $xyArray->setitem($i, $xy); + } + for (my $i=0; $i<$length; $i++) { + is($xyArray->getitem($i)->{x}, $i*10); + is($xyArray->getitem($i)->{y}, $i*100); + } +} + +{ + # global array variable + my $length = 3; + my $xyArrayPointer = $li_carrays_cpp::globalXYArray; + my $xyArray = li_carrays_cpp::XYArray::frompointer($xyArrayPointer); + for (my $i=0; $i<$length; $i++) { + my $xy = $xyArray->getitem($i); + $xy->{x} = $i*10; + $xy->{y} = $i*100; + $xyArray->setitem($i, $xy); + } + for (my $i=0; $i<$length; $i++) { + is($xyArray->getitem($i)->{x}, $i*10); + is($xyArray->getitem($i)->{y}, $i*100); + } +} + +# array_functions +{ + my $length = 5; + my $abArray = li_carrays_cpp::new_ABArray($length); + for (my $i=0; $i<$length; $i++) { + my $ab = li_carrays_cpp::ABArray_getitem($abArray, $i); + $ab->{a} = $i*10; + $ab->{b} = $i*100; + li_carrays_cpp::ABArray_setitem($abArray, $i, $ab); + } + for (my $i=0; $i<$length; $i++) { + is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{a}, $i*10); + is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{b}, $i*100); + } + li_carrays_cpp::delete_ABArray($abArray); +} + +{ + # global array variable + my $length = 3; + my $abArray = $li_carrays_cpp::globalABArray; + for (my $i=0; $i<$length; $i++) { + my $ab = li_carrays_cpp::ABArray_getitem($abArray, $i); + $ab->{a} = $i*10; + $ab->{b} = $i*100; + li_carrays_cpp::ABArray_setitem($abArray, $i, $ab); + } + for (my $i=0; $i<$length; $i++) { + is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{a}, $i*10); + is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{b}, $i*100); + } +} diff --git a/Examples/test-suite/perl5/li_carrays_runme.pl b/Examples/test-suite/perl5/li_carrays_runme.pl index 00d12cd1b92..51c813403a6 100644 --- a/Examples/test-suite/perl5/li_carrays_runme.pl +++ b/Examples/test-suite/perl5/li_carrays_runme.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; use warnings; -use Test::More tests => 38; +use Test::More tests => 34; BEGIN { use_ok('li_carrays') } require_ok('li_carrays'); @@ -23,7 +23,7 @@ { # global array variable - my $length = 5; + my $length = 3; my $xyArrayPointer = $li_carrays::globalXYArray; my $xyArray = li_carrays::XYArray::frompointer($xyArrayPointer); for (my $i=0; $i<$length; $i++) { diff --git a/Examples/test-suite/perl5/li_cdata_carrays_cpp_runme.pl b/Examples/test-suite/perl5/li_cdata_carrays_cpp_runme.pl new file mode 100644 index 00000000000..34b5e19b484 --- /dev/null +++ b/Examples/test-suite/perl5/li_cdata_carrays_cpp_runme.pl @@ -0,0 +1,14 @@ +use strict; +use warnings; +use Test::More tests => 4; +BEGIN { use_ok('li_cdata_carrays_cpp') } +require_ok('li_cdata_carrays_cpp'); + +my $ia = li_cdata_carrays_cpp::intArray->new(5); +for (0..4) { + $ia->setitem($_, $_**2); +} +ok(1, "setitems"); +my $x = pack q{I5}, map $_**2, (0..4); +my $y = li_cdata_carrays_cpp::cdata_int($ia->cast, 5); +is($x, $y, "carrays"); diff --git a/Examples/test-suite/perl5/overload_simple_runme.pl b/Examples/test-suite/perl5/overload_simple_runme.pl index 624d428c637..57a585a22b8 100644 --- a/Examples/test-suite/perl5/overload_simple_runme.pl +++ b/Examples/test-suite/perl5/overload_simple_runme.pl @@ -2,7 +2,7 @@ use overload_simple; use vars qw/$DOWARN/; use strict; -use Test::More tests => 75; +use Test::More tests => 97; pass("loaded"); @@ -196,3 +196,40 @@ is(overload_simple::int_object(0), 0, "int_object(0)"); is(overload_simple::int_object(undef), 999, "int_object(Spam*)"); is(overload_simple::int_object($s), 999, "int_object(Spam*)"); + +# some of this section is duplication of above tests, but I want to see +# parity with the coverage in wrapmacro_runme.pl. + +sub check { + my($args, $want) = @_; + my($s, $rslt) = defined $want ? ($want, "bar:$want") : ('*boom*', undef); + is(eval("overload_simple::Spam::bar($args)"), $rslt, "bar($args) => $s"); +} + +# normal use patterns +check("11", 'int'); +check("11.0", 'double'); +check("'11'", 'char *'); +check("'11.0'", 'char *'); +check("-13", 'int'); +check("-13.0", 'double'); +check("'-13'", 'char *'); +check("'-13.0'", 'char *'); + +check("' '", 'char *'); +check("' 11 '", 'char *'); +# TypeError explosions +check("\\*STDIN", undef); +check("[]", undef); +check("{}", undef); +check("sub {}", undef); + +# regression cases +check("''", 'char *'); +check("' 11'", 'char *'); +check("' 11.0'", 'char *'); +check("' -11.0'", 'char *'); +check("\"11\x{0}\"", 'char *'); +check("\"\x{0}\"", 'char *'); +check("\"\x{9}11\x{0}this is not eleven.\"", 'char *'); +check("\"\x{9}11.0\x{0}this is also not eleven.\"", 'char *'); diff --git a/Examples/test-suite/perl5/wrapmacro_runme.pl b/Examples/test-suite/perl5/wrapmacro_runme.pl index 8e01540574a..f2478b51bcb 100644 --- a/Examples/test-suite/perl5/wrapmacro_runme.pl +++ b/Examples/test-suite/perl5/wrapmacro_runme.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 27; BEGIN { use_ok('wrapmacro') } require_ok('wrapmacro'); @@ -12,3 +12,44 @@ is(wrapmacro::maximum($a,$b), 2); is(wrapmacro::maximum($a/7.0, -$b*256), 256); is(wrapmacro::GUINT16_SWAP_LE_BE_CONSTANT(1), 256); + +# some of this section is duplication of above tests, but I want to see +# parity with the coverage in overload_simple_runme.pl. + +sub check { + my($args, $rslt) = @_; + my $s = defined $rslt ? $rslt : '*boom*'; + is(eval("wrapmacro::maximum($args)"), $rslt, "max($args) => $s"); +} + +# normal use patterns +check("0, 11", 11); +check("0, 11.0", 11); +check("0, '11'", 11); +check("0, '11.0'", 11); +check("11, -13", 11); +check("11, -13.0", 11); +{ local $TODO = 'strtoull() handles /^\s*-\d+$/ amusingly'; +check("11, '-13'", 11); +} +check("11, '-13.0'", 11); + +# TypeError explosions +check("0, ' '", undef); +check("0, ' 11 '", undef); +check("0, \\*STDIN", undef); +check("0, []", undef); +check("0, {}", undef); +check("0, sub {}", undef); + +# regression cases +{ local $TODO = 'strtol() and friends have edge cases we should guard against'; +check("-11, ''", undef); +check("0, ' 11'", undef); +check("0, ' 11.0'", undef); +check("-13, ' -11.0'", undef); +check("0, \"11\x{0}\"", undef); +check("0, \"\x{0}\"", undef); +check("0, \"\x{9}11\x{0}this is not eleven.\"", undef); +check("0, \"\x{9}11.0\x{0}this is also not eleven.\"", undef); +} diff --git a/Examples/test-suite/php/Makefile.in b/Examples/test-suite/php/Makefile.in index c3f8af5cbc1..811eade364f 100644 --- a/Examples/test-suite/php/Makefile.in +++ b/Examples/test-suite/php/Makefile.in @@ -10,6 +10,7 @@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ CPP_TEST_CASES += \ + callback \ php_iterator \ php_namewarn_rename \ @@ -59,9 +60,9 @@ missingtests: missingcpptests missingctests # found, runs testcase.php, except for multicpptests. run_testcase = \ if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL="$(RUNTOOL)" php_run; \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL='$(RUNTOOL)' php_run; \ elif [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*.php -a ! -f $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list ]; then \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*.php RUNTOOL="$(RUNTOOL)" php_run; \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*.php RUNTOOL='$(RUNTOOL)' php_run; \ fi # Clean: remove the generated .php file @@ -69,7 +70,7 @@ run_testcase = \ @rm -f $*.php php_$*.h clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" php_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' php_clean rm -f clientdata_prop_a.php clientdata_prop_b.php php_clientdata_prop_a.h php_clientdata_prop_b.h rm -f import_stl_a.php import_stl_b.php php_import_stl_a.h php_import_stl_b.h rm -f imports_a.php imports_b.php php_imports_a.h php_imports_b.h diff --git a/Examples/test-suite/php/autodoc_runme.php b/Examples/test-suite/php/autodoc_runme.php deleted file mode 100644 index f2e19d3cb1f..00000000000 --- a/Examples/test-suite/php/autodoc_runme.php +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/Examples/test-suite/php/callback_runme.php b/Examples/test-suite/php/callback_runme.php new file mode 100644 index 00000000000..fefa32502e9 --- /dev/null +++ b/Examples/test-suite/php/callback_runme.php @@ -0,0 +1,9 @@ + diff --git a/Examples/test-suite/php/li_carrays_cpp_runme.php b/Examples/test-suite/php/li_carrays_cpp_runme.php new file mode 100644 index 00000000000..3be09ca8cc1 --- /dev/null +++ b/Examples/test-suite/php/li_carrays_cpp_runme.php @@ -0,0 +1,22 @@ +setitem(0, 7); +$d->setitem(5, $d->getitem(0) + 3); +check::equal($d->getitem(0) + $d->getitem(5), 17., "7+10==17"); + +check::done(); +?> diff --git a/Examples/test-suite/pike/Makefile.in b/Examples/test-suite/pike/Makefile.in index 92054dd9d5e..6e1bdfbffbf 100644 --- a/Examples/test-suite/pike/Makefile.in +++ b/Examples/test-suite/pike/Makefile.in @@ -46,4 +46,4 @@ run_testcase = \ @rm -f $*.pike; clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" pike_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/test-suite/preproc.i b/Examples/test-suite/preproc.i index 779c41e972c..f236bfdff04 100644 --- a/Examples/test-suite/preproc.i +++ b/Examples/test-suite/preproc.i @@ -11,6 +11,13 @@ #pragma SWIG nowarn=890 /* lots of Go name conflicts */ #pragma SWIG nowarn=206 /* Unexpected tokens after #endif directive. */ +%{ +#if defined(__clang__) +//Suppress: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] +#pragma clang diagnostic ignored "-Wconstant-logical-operand" +#endif +%} + /* check __cplusplus case */ %header %{ @@ -225,8 +232,8 @@ This testcase tests operators for defines #define A7 13 & 14 #define A8 15 | 16 #define A9 17 ^ 18 -#define A10 19 && 20 -#define A11 21 || 21 +#define A10 1 && 0 +#define A11 1 || 0 #define A12 ~22 #define A13 !23 diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i index ef5c35e1237..db71bd2d7cc 100644 --- a/Examples/test-suite/preproc_constants.i +++ b/Examples/test-suite/preproc_constants.i @@ -1,5 +1,12 @@ %module preproc_constants +%{ +#if defined(__clang__) +//Suppress: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] +#pragma clang diagnostic ignored "-Wconstant-logical-operand" +#endif +%} + // Note: C types are slightly different to C++ types as (a && b) is int in C and bool in C++ // Simple constants @@ -102,3 +109,4 @@ enum MyEnum { enum MyEnum { kValue = BIT(2) }; + diff --git a/Examples/test-suite/preproc_defined.i b/Examples/test-suite/preproc_defined.i index 617e84f61f9..0a91bd98aec 100644 --- a/Examples/test-suite/preproc_defined.i +++ b/Examples/test-suite/preproc_defined.i @@ -107,3 +107,18 @@ void another_macro_checking(void) { bumpf(10); } %} + +/* Check that unknown preprocessor directives are ignored inside an inactive + * conditional (github issue #394). + */ +#ifdef APPLE_OPENGL +# import +#endif +#ifdef AAA +# define B +#else +# wibble wibble +#endif +#if 0 +# wobble wobble +#endif diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index b221b772800..cd30b1dc12f 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -2,7 +2,7 @@ // Test __LINE__ and __FILE__ (don't change line numbering in here else runtime tests will need modifying) #define MYLINE __LINE__ -#define MYLINE_ADJUSTED __LINE__ + 100 +#define MYLINE_ADJUSTED __LINE__ + 100 #define MYFILE __FILE__ #define MYFILE_ADJUSTED __FILE__ ".bak" @@ -78,7 +78,7 @@ struct NAME { \ int num; \ }; #endif -KLASS(SillyMultipleMacroStruct) +KLASS(SillyMulMacroStruc) %} %inline %{ diff --git a/Examples/test-suite/primitive_types.i b/Examples/test-suite/primitive_types.i index 5e3ce3eed2e..8eb2a13f229 100644 --- a/Examples/test-suite/primitive_types.i +++ b/Examples/test-suite/primitive_types.i @@ -1,6 +1,11 @@ // Massive primitive datatype test. %module(directors="1") primitive_types +#if defined(SWIGSCILAB) +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) ovr_val; +%rename(TestDir) TestDirector; +#endif + %{ #if defined(_MSC_VER) #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) @@ -322,10 +327,19 @@ macro(size_t, pfx, sizet) if (a.str() != b.str()) { std::cout << "failing in pfx""_""name : " << a.str() << " : " << b.str() << std::endl; - // return 0; } } %enddef +/* check variables (arrays can't be compared so compare as strings) */ +%define var_array_check(type, pfx, name) + std::ostringstream a; std::ostringstream b; + a << pfx##_##name; + b << def_##name; + if (a.str() != b.str()) { + std::cout << "failing in pfx""_""name : " + << a.str() << " : " << b.str() << std::endl; + } +%enddef /* check a function call */ %define call_check(type, pfx, name) @@ -337,7 +351,6 @@ macro(size_t, pfx, sizet) if (a.str() != b.str()) { std::cout << "failing in pfx""_""name : " << a.str() << " : " << b.str() << std::endl; - // return 0; } } %enddef @@ -352,8 +365,24 @@ macro(size_t, pfx, sizet) %define ovr_decl(type, pfx, name) virtual int pfx##_##val(type x) { return 1; } virtual int pfx##_##ref(const type& x) { return 1; } + virtual const char* pfx##_##str(type x) { return "name"; } %enddef +/* checking size_t and ptrdiff_t typemaps */ +%begin %{ +// Must be defined before Python.h is included, since this may indirectly include stdint.h +#define __STDC_LIMIT_MACROS +%} +%include "stdint.i" +%inline { + size_t get_size_min() { return 0; } + size_t get_size_max() { return SIZE_MAX; } + ptrdiff_t get_ptrdiff_min() { return PTRDIFF_MIN; } + ptrdiff_t get_ptrdiff_max() { return PTRDIFF_MAX; } + + size_t size_echo (size_t val) { return val; } + ptrdiff_t ptrdiff_echo(ptrdiff_t val) { return val; } +} %inline { struct Foo @@ -456,7 +485,7 @@ macro(size_t, pfx, sizet) { %test_prim_types_stc(var_check, stc) %test_prim_types(var_check, var) - var_check(namet, var, namet); + var_array_check(namet, var, namet); return 1; } @@ -540,7 +569,7 @@ macro(size_t, pfx, sizet) { %test_prim_types(var_check, cct) %test_prim_types(var_check, var) - var_check(namet, var, namet); + var_array_check(namet, var, namet); return 1; } diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 82a0e9db1b7..0c47d19ce4f 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -11,7 +11,7 @@ endif LANGUAGE = python PYTHON = $(PYBIN) PEP8 = @PEP8@ -PEP8_FLAGS = --ignore=E402,E501,E30,W291,W391 +PEP8_FLAGS = --ignore=E30,E402,E501,E731,W291,W391 #*_runme.py for Python 2.x, *_runme3.py for Python 3.x PY2SCRIPTSUFFIX = _runme.py @@ -58,10 +58,14 @@ CPP_TEST_CASES += \ primitive_types \ python_abstractbase \ python_append \ + python_destructor_exception \ python_director \ + python_docstring \ python_nondynamic \ python_overload_simple_cast \ + python_pythoncode \ python_richcompare \ + python_strict_unicode \ simutry \ std_containers \ swigobject \ @@ -125,17 +129,14 @@ py_runme = $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) py2_runme = $(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX) py3_runme = $(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX) -check_pep8 = \ - if [ -n "$(PEP8)" ]; then \ - $(PEP8) $(PEP8_FLAGS) $(SCRIPTPREFIX)$*.py;\ - fi +ifneq (,$(PEP8)) +check_pep8 = $(PEP8) $(PEP8_FLAGS) $(SCRIPTPREFIX)$*.py check_pep8_multi_cpp = \ - if [ -n "$(PEP8)" ]; then \ - for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \ + for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \ $(PEP8) $(PEP8_FLAGS) $$f.py; \ - done \ - fi + done +endif run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(py_runme) @@ -168,7 +169,7 @@ endif @if test "x$(SCRIPTDIR)" != "x$(srcdir)"; then rm -f $(SCRIPTDIR)/$(py2_runme); fi clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" python_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' python_clean rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py rm -f clientdata_prop_a.py clientdata_prop_b.py import_stl_a.py import_stl_b.py rm -f imports_a.py imports_b.py mod_a.py mod_b.py multi_import_a.py diff --git a/Examples/test-suite/python/abstract_access_runme.py b/Examples/test-suite/python/abstract_access_runme.py index 55638e40e04..8abce98ae6a 100644 --- a/Examples/test-suite/python/abstract_access_runme.py +++ b/Examples/test-suite/python/abstract_access_runme.py @@ -2,5 +2,4 @@ d = abstract_access.D() if d.do_x() != 1: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/abstract_typedef2_runme.py b/Examples/test-suite/python/abstract_typedef2_runme.py index 2a11d194428..ef6f415dd51 100644 --- a/Examples/test-suite/python/abstract_typedef2_runme.py +++ b/Examples/test-suite/python/abstract_typedef2_runme.py @@ -1,8 +1,3 @@ -from abstract_typedef2 import * +from abstract_typedef2 import * a = A_UF() - - - - - diff --git a/Examples/test-suite/python/abstract_typedef_runme.py b/Examples/test-suite/python/abstract_typedef_runme.py index 15d70aa428c..d69134f2ec5 100644 --- a/Examples/test-suite/python/abstract_typedef_runme.py +++ b/Examples/test-suite/python/abstract_typedef_runme.py @@ -1,11 +1,8 @@ -from abstract_typedef import * +from abstract_typedef import * e = Engine() a = A() - - -if a.write(e) != 1: - raise RuntimeError - +if a.write(e) != 1: + raise RuntimeError diff --git a/Examples/test-suite/python/argcargvtest_runme.py b/Examples/test-suite/python/argcargvtest_runme.py index 047ea95514a..38843b93286 100644 --- a/Examples/test-suite/python/argcargvtest_runme.py +++ b/Examples/test-suite/python/argcargvtest_runme.py @@ -1,27 +1,26 @@ from argcargvtest import * -largs=['hi','hola','hello'] +largs = ['hi', 'hola', 'hello'] if mainc(largs) != 3: - raise RuntimeError("bad main typemap") + raise RuntimeError("bad main typemap") -targs=('hi','hola') -if mainv(targs,1) != 'hola': - print(mainv(targs,1)) - raise RuntimeError("bad main typemap") +targs = ('hi', 'hola') +if mainv(targs, 1) != 'hola': + print(mainv(targs, 1)) + raise RuntimeError("bad main typemap") -targs=('hi', 'hola') -if mainv(targs,1) != 'hola': - raise RuntimeError("bad main typemap") +targs = ('hi', 'hola') +if mainv(targs, 1) != 'hola': + raise RuntimeError("bad main typemap") try: - error = 0 - mainv('hello',1) - error = 1 + error = 0 + mainv('hello', 1) + error = 1 except TypeError: - pass + pass if error: - raise RuntimeError("bad main typemap") - + raise RuntimeError("bad main typemap") initializeApp(largs) diff --git a/Examples/test-suite/python/array_member_runme.py b/Examples/test-suite/python/array_member_runme.py index 95cf03b442c..de6e0f3e766 100644 --- a/Examples/test-suite/python/array_member_runme.py +++ b/Examples/test-suite/python/array_member_runme.py @@ -3,19 +3,16 @@ f = Foo() f.data = cvar.global_data -for i in range(0,8): - if get_value(f.data,i) != get_value(cvar.global_data,i): +for i in range(0, 8): + if get_value(f.data, i) != get_value(cvar.global_data, i): raise RuntimeError, "Bad array assignment" -for i in range(0,8): - set_value(f.data,i,-i) +for i in range(0, 8): + set_value(f.data, i, -i) cvar.global_data = f.data -for i in range(0,8): - if get_value(f.data,i) != get_value(cvar.global_data,i): +for i in range(0, 8): + if get_value(f.data, i) != get_value(cvar.global_data, i): raise RuntimeError, "Bad array assignment" - - - diff --git a/Examples/test-suite/python/arrays_global_runme.py b/Examples/test-suite/python/arrays_global_runme.py index ab7fd6a41cc..fa3b9f2ec2c 100644 --- a/Examples/test-suite/python/arrays_global_runme.py +++ b/Examples/test-suite/python/arrays_global_runme.py @@ -2,19 +2,19 @@ arrays_global.cvar.array_i = arrays_global.cvar.array_const_i -from arrays_global import * +from arrays_global import * BeginString_FIX44a cvar.BeginString_FIX44b BeginString_FIX44c cvar.BeginString_FIX44d cvar.BeginString_FIX44d -cvar.BeginString_FIX44b ="12"'\0'"45" +cvar.BeginString_FIX44b = "12"'\0'"45" cvar.BeginString_FIX44b cvar.BeginString_FIX44d cvar.BeginString_FIX44e BeginString_FIX44f -test_a("hello","hi","chello","chi") +test_a("hello", "hi", "chello", "chi") -test_b("1234567","hi") +test_b("1234567", "hi") diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index 756b8590405..ce0aae0eb69 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -1,336 +1,359 @@ from autodoc import * import sys -def check(got, expected, expected_builtin = None, skip = False): - if not skip: - expect = expected - if is_python_builtin() and expected_builtin != None: - expect = expected_builtin - if expect != got: - raise RuntimeError("\n" + "Expected: [" + str(expect) + "]\n" + "Got : [" + str(got) + "]") -skip = True # skip builtin check - the autodoc is missing, but it probably should not be +def check(got, expected, expected_builtin=None, skip=False): + if not skip: + expect = expected + if is_python_builtin() and expected_builtin != None: + expect = expected_builtin + if expect != got: + raise RuntimeError( + "\n" + "Expected: [" + str(expect) + "]\n" + "Got : [" + str(got) + "]") -check(A.__doc__, "Proxy of C++ A class", "::A") -check(A.funk.__doc__, "just a string") + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + +if not is_new_style_class(A): + # Missing static methods make this hard to test... skip if -classic is + # used! + sys.exit(0) + +# skip builtin check - the autodoc is missing, but it probably should not be +skip = True + +check(A.__doc__, "Proxy of C++ A class.", "::A") +check(A.funk.__doc__, "just a string.") check(A.func0.__doc__, -"func0(self, arg2, hello) -> int", -"func0(arg2, hello) -> int") + "func0(self, arg2, hello) -> int", + "func0(arg2, hello) -> int") check(A.func1.__doc__, -"func1(A self, short arg2, Tuple hello) -> int", -"func1(short arg2, Tuple hello) -> int") + "func1(A self, short arg2, Tuple hello) -> int", + "func1(short arg2, Tuple hello) -> int") check(A.func2.__doc__, -"\n" -" func2(self, arg2, hello) -> int\n" -"\n" -" Parameters:\n" -" arg2: short\n" -" hello: int tuple[2]\n" -"\n" -" " -, -"\n" -"func2(arg2, hello) -> int\n" -"\n" -"Parameters:\n" -" arg2: short\n" -" hello: int tuple[2]\n" -"\n" -"" -) + "\n" + " func2(self, arg2, hello) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " arg2: short\n" + " hello: int tuple[2]\n" + "\n" + " ", + "\n" + "func2(arg2, hello) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "arg2: short\n" + "hello: int tuple[2]\n" + "\n" + "" + ) check(A.func3.__doc__, -"\n" -" func3(A self, short arg2, Tuple hello) -> int\n" -"\n" -" Parameters:\n" -" arg2: short\n" -" hello: int tuple[2]\n" -"\n" -" " -, -"\n" -"func3(short arg2, Tuple hello) -> int\n" -"\n" -"Parameters:\n" -" arg2: short\n" -" hello: int tuple[2]\n" -"\n" -"" -) + "\n" + " func3(A self, short arg2, Tuple hello) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " arg2: short\n" + " hello: int tuple[2]\n" + "\n" + " ", + "\n" + "func3(short arg2, Tuple hello) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "arg2: short\n" + "hello: int tuple[2]\n" + "\n" + "" + ) check(A.func0default.__doc__, -"\n" -" func0default(self, e, arg3, hello, f=2) -> int\n" -" func0default(self, e, arg3, hello) -> int\n" -" " -, -"\n" -"func0default(e, arg3, hello, f=2) -> int\n" -"func0default(e, arg3, hello) -> int\n" -"" -) + "\n" + " func0default(self, e, arg3, hello, f=2) -> int\n" + " func0default(self, e, arg3, hello) -> int\n" + " ", + "\n" + "func0default(e, arg3, hello, f=2) -> int\n" + "func0default(e, arg3, hello) -> int\n" + "" + ) check(A.func1default.__doc__, -"\n" -" func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" -" func1default(A self, A e, short arg3, Tuple hello) -> int\n" -" " -, -"\n" -"func1default(A e, short arg3, Tuple hello, double f=2) -> int\n" -"func1default(A e, short arg3, Tuple hello) -> int\n" -"" -) + "\n" + " func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" + " func1default(A self, A e, short arg3, Tuple hello) -> int\n" + " ", + "\n" + "func1default(A e, short arg3, Tuple hello, double f=2) -> int\n" + "func1default(A e, short arg3, Tuple hello) -> int\n" + "" + ) check(A.func2default.__doc__, -"\n" -" func2default(self, e, arg3, hello, f=2) -> int\n" -"\n" -" Parameters:\n" -" e: A *\n" -" arg3: short\n" -" hello: int tuple[2]\n" -" f: double\n" -"\n" -" func2default(self, e, arg3, hello) -> int\n" -"\n" -" Parameters:\n" -" e: A *\n" -" arg3: short\n" -" hello: int tuple[2]\n" -"\n" -" " -, -"\n" -"func2default(e, arg3, hello, f=2) -> int\n" -"\n" -"Parameters:\n" -" e: A *\n" -" arg3: short\n" -" hello: int tuple[2]\n" -" f: double\n" -"\n" -"func2default(e, arg3, hello) -> int\n" -"\n" -"Parameters:\n" -" e: A *\n" -" arg3: short\n" -" hello: int tuple[2]\n" -"\n" -"" -) + "\n" + " func2default(self, e, arg3, hello, f=2) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " e: A *\n" + " arg3: short\n" + " hello: int tuple[2]\n" + " f: double\n" + "\n" + " func2default(self, e, arg3, hello) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " e: A *\n" + " arg3: short\n" + " hello: int tuple[2]\n" + "\n" + " ", + "\n" + "func2default(e, arg3, hello, f=2) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "e: A *\n" + "arg3: short\n" + "hello: int tuple[2]\n" + "f: double\n" + "\n" + "func2default(e, arg3, hello) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "e: A *\n" + "arg3: short\n" + "hello: int tuple[2]\n" + "\n" + "" + ) check(A.func3default.__doc__, -"\n" -" func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" -"\n" -" Parameters:\n" -" e: A *\n" -" arg3: short\n" -" hello: int tuple[2]\n" -" f: double\n" -"\n" -" func3default(A self, A e, short arg3, Tuple hello) -> int\n" -"\n" -" Parameters:\n" -" e: A *\n" -" arg3: short\n" -" hello: int tuple[2]\n" -"\n" -" " -, -"\n" -"func3default(A e, short arg3, Tuple hello, double f=2) -> int\n" -"\n" -"Parameters:\n" -" e: A *\n" -" arg3: short\n" -" hello: int tuple[2]\n" -" f: double\n" -"\n" -"func3default(A e, short arg3, Tuple hello) -> int\n" -"\n" -"Parameters:\n" -" e: A *\n" -" arg3: short\n" -" hello: int tuple[2]\n" -"\n" -"" -) + "\n" + " func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " e: A *\n" + " arg3: short\n" + " hello: int tuple[2]\n" + " f: double\n" + "\n" + " func3default(A self, A e, short arg3, Tuple hello) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " e: A *\n" + " arg3: short\n" + " hello: int tuple[2]\n" + "\n" + " ", + "\n" + "func3default(A e, short arg3, Tuple hello, double f=2) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "e: A *\n" + "arg3: short\n" + "hello: int tuple[2]\n" + "f: double\n" + "\n" + "func3default(A e, short arg3, Tuple hello) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "e: A *\n" + "arg3: short\n" + "hello: int tuple[2]\n" + "\n" + "" + ) check(A.func0static.__doc__, -"\n" -" func0static(e, arg2, hello, f=2) -> int\n" -" func0static(e, arg2, hello) -> int\n" -" " -, -"\n" -"func0static(e, arg2, hello, f=2) -> int\n" -"func0static(e, arg2, hello) -> int\n" -"" -) + "\n" + " func0static(e, arg2, hello, f=2) -> int\n" + " func0static(e, arg2, hello) -> int\n" + " ", + "\n" + "func0static(e, arg2, hello, f=2) -> int\n" + "func0static(e, arg2, hello) -> int\n" + "" + ) check(A.func1static.__doc__, -"\n" -" func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" -" func1static(A e, short arg2, Tuple hello) -> int\n" -" " -, -"\n" -"func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" -"func1static(A e, short arg2, Tuple hello) -> int\n" -"" -) + "\n" + " func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" + " func1static(A e, short arg2, Tuple hello) -> int\n" + " ", + "\n" + "func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" + "func1static(A e, short arg2, Tuple hello) -> int\n" + "" + ) check(A.func2static.__doc__, -"\n" -" func2static(e, arg2, hello, f=2) -> int\n" -"\n" -" Parameters:\n" -" e: A *\n" -" arg2: short\n" -" hello: int tuple[2]\n" -" f: double\n" -"\n" -" func2static(e, arg2, hello) -> int\n" -"\n" -" Parameters:\n" -" e: A *\n" -" arg2: short\n" -" hello: int tuple[2]\n" -"\n" -" " -, -"\n" -"func2static(e, arg2, hello, f=2) -> int\n" -"\n" -"Parameters:\n" -" e: A *\n" -" arg2: short\n" -" hello: int tuple[2]\n" -" f: double\n" -"\n" -"func2static(e, arg2, hello) -> int\n" -"\n" -"Parameters:\n" -" e: A *\n" -" arg2: short\n" -" hello: int tuple[2]\n" -"\n" -"" -) + "\n" + " func2static(e, arg2, hello, f=2) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " e: A *\n" + " arg2: short\n" + " hello: int tuple[2]\n" + " f: double\n" + "\n" + " func2static(e, arg2, hello) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " e: A *\n" + " arg2: short\n" + " hello: int tuple[2]\n" + "\n" + " ", + "\n" + "func2static(e, arg2, hello, f=2) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "e: A *\n" + "arg2: short\n" + "hello: int tuple[2]\n" + "f: double\n" + "\n" + "func2static(e, arg2, hello) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "e: A *\n" + "arg2: short\n" + "hello: int tuple[2]\n" + "\n" + "" + ) check(A.func3static.__doc__, -"\n" -" func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" -"\n" -" Parameters:\n" -" e: A *\n" -" arg2: short\n" -" hello: int tuple[2]\n" -" f: double\n" -"\n" -" func3static(A e, short arg2, Tuple hello) -> int\n" -"\n" -" Parameters:\n" -" e: A *\n" -" arg2: short\n" -" hello: int tuple[2]\n" -"\n" -" " -, -"\n" -"func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" -"\n" -"Parameters:\n" -" e: A *\n" -" arg2: short\n" -" hello: int tuple[2]\n" -" f: double\n" -"\n" -"func3static(A e, short arg2, Tuple hello) -> int\n" -"\n" -"Parameters:\n" -" e: A *\n" -" arg2: short\n" -" hello: int tuple[2]\n" -"\n" -"" -) + "\n" + " func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " e: A *\n" + " arg2: short\n" + " hello: int tuple[2]\n" + " f: double\n" + "\n" + " func3static(A e, short arg2, Tuple hello) -> int\n" + "\n" + " Parameters\n" + " ----------\n" + " e: A *\n" + " arg2: short\n" + " hello: int tuple[2]\n" + "\n" + " ", + "\n" + "func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "e: A *\n" + "arg2: short\n" + "hello: int tuple[2]\n" + "f: double\n" + "\n" + "func3static(A e, short arg2, Tuple hello) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "e: A *\n" + "arg2: short\n" + "hello: int tuple[2]\n" + "\n" + "" + ) if sys.version_info[0:2] > (2, 4): - # Python 2.4 does not seem to work - check(A.variable_a.__doc__, - "A_variable_a_get(self) -> int", - "A.variable_a" - ) - check(A.variable_b.__doc__, - "A_variable_b_get(A self) -> int", - "A.variable_b" - ) - check(A.variable_c.__doc__, - "\n" - "A_variable_c_get(self) -> int\n" - "\n" - "Parameters:\n" - " self: A *\n" - "\n" - , - "A.variable_c" - ) - check(A.variable_d.__doc__, - "\n" - "A_variable_d_get(A self) -> int\n" - "\n" - "Parameters:\n" - " self: A *\n" - "\n" - , - "A.variable_d" - ) + # Python 2.4 does not seem to work + check(A.variable_a.__doc__, + "A_variable_a_get(self) -> int", + "A.variable_a" + ) + check(A.variable_b.__doc__, + "A_variable_b_get(A self) -> int", + "A.variable_b" + ) + check(A.variable_c.__doc__, + "\n" + "A_variable_c_get(self) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "self: A *\n" + "\n", + "A.variable_c" + ) + check(A.variable_d.__doc__, + "\n" + "A_variable_d_get(A self) -> int\n" + "\n" + "Parameters\n" + "----------\n" + "self: A *\n" + "\n", + "A.variable_d" + ) check(B.__doc__, -"Proxy of C++ B class", -"::B" -) + "Proxy of C++ B class.", + "::B" + ) check(C.__init__.__doc__, "__init__(self, a, b, h) -> C", None, skip) -check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D", None, skip) +check(D.__init__.__doc__, + "__init__(D self, int a, int b, Hola h) -> D", None, skip) check(E.__init__.__doc__, -"\n" -" __init__(self, a, b, h) -> E\n" -"\n" -" Parameters:\n" -" a: special comment for parameter a\n" -" b: another special comment for parameter b\n" -" h: enum Hola\n" -"\n" -" " -, None, skip -) + "\n" + " __init__(self, a, b, h) -> E\n" + "\n" + " Parameters\n" + " ----------\n" + " a: special comment for parameter a\n" + " b: another special comment for parameter b\n" + " h: enum Hola\n" + "\n" + " ", None, skip + ) check(F.__init__.__doc__, -"\n" -" __init__(F self, int a, int b, Hola h) -> F\n" -"\n" -" Parameters:\n" -" a: special comment for parameter a\n" -" b: another special comment for parameter b\n" -" h: enum Hola\n" -"\n" -" " -, None, skip -) + "\n" + " __init__(F self, int a, int b, Hola h) -> F\n" + "\n" + " Parameters\n" + " ----------\n" + " a: special comment for parameter a\n" + " b: another special comment for parameter b\n" + " h: enum Hola\n" + "\n" + " ", None, skip + ) check(B.funk.__doc__, -"funk(B self, int c, int d) -> int", -"funk(int c, int d) -> int") + "funk(B self, int c, int d) -> int", + "funk(int c, int d) -> int") check(funk.__doc__, "funk(A e, short arg2, int c, int d) -> int") check(funkdefaults.__doc__, -"\n" -" funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" -" funkdefaults(A e, short arg2, int c, int d) -> int\n" -" " -, -"\n" -"funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" -"funkdefaults(A e, short arg2, int c, int d) -> int\n" -"" -) + "\n" + " funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" + " funkdefaults(A e, short arg2, int c, int d) -> int\n" + " ", + "\n" + "funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" + "funkdefaults(A e, short arg2, int c, int d) -> int\n" + "" + ) check(func_input.__doc__, "func_input(int * INPUT) -> int") check(func_output.__doc__, "func_output() -> int") check(func_inout.__doc__, "func_inout(int * INOUT) -> int") +check(func_cb.__doc__, "func_cb(int c, int d) -> int") check(banana.__doc__, "banana(S a, S b, int c, Integer d)") diff --git a/Examples/test-suite/python/callback_runme.py b/Examples/test-suite/python/callback_runme.py index b2bbb2d0f93..ef7baad4e25 100644 --- a/Examples/test-suite/python/callback_runme.py +++ b/Examples/test-suite/python/callback_runme.py @@ -2,30 +2,30 @@ from callback import * if foo(2) != 2: - raise RuntimeError + raise RuntimeError if A_bar(2) != 4: - raise RuntimeError + raise RuntimeError if foobar(3, _callback.foo) != foo(3): - raise RuntimeError + raise RuntimeError if foobar(3, foo) != foo(3): - raise RuntimeError + raise RuntimeError if foobar(3, A_bar) != A_bar(3): - raise RuntimeError + raise RuntimeError if foobar(3, foof) != foof(3): - raise RuntimeError + raise RuntimeError if foobar_i(3, foo_i) != foo_i(3): - raise RuntimeError + raise RuntimeError if foobar_d(3.5, foo_d) != foo_d(3.5): - raise RuntimeError + raise RuntimeError a = A() if foobarm(3, a, A.foom_cb_ptr) != a.foom(3): - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/char_binary_runme.py b/Examples/test-suite/python/char_binary_runme.py index b6d9c81c8de..34caa320870 100644 --- a/Examples/test-suite/python/char_binary_runme.py +++ b/Examples/test-suite/python/char_binary_runme.py @@ -2,11 +2,16 @@ t = Test() if t.strlen('hile') != 4: - print t.strlen('hile') - raise RuntimeError, "bad multi-arg typemap" + print t.strlen('hile') + raise RuntimeError, "bad multi-arg typemap" +if t.ustrlen('hile') != 4: + print t.ustrlen('hile') + raise RuntimeError, "bad multi-arg typemap" if t.strlen('hil\0') != 4: - raise RuntimeError, "bad multi-arg typemap" + raise RuntimeError, "bad multi-arg typemap" +if t.ustrlen('hil\0') != 4: + raise RuntimeError, "bad multi-arg typemap" # # creating a raw char* @@ -20,17 +25,18 @@ if t.strlen(pc) != 4: - raise RuntimeError, "bad multi-arg typemap" + raise RuntimeError, "bad multi-arg typemap" +if t.ustrlen(pc) != 4: + raise RuntimeError, "bad multi-arg typemap" cvar.var_pchar = pc if cvar.var_pchar != "hola": - print cvar.var_pchar - raise RuntimeError, "bad pointer case" + print cvar.var_pchar + raise RuntimeError, "bad pointer case" cvar.var_namet = pc -#if cvar.var_namet != "hola\0": +# if cvar.var_namet != "hola\0": if cvar.var_namet != "hola": - raise RuntimeError, "bad pointer case" + raise RuntimeError, "bad pointer case" delete_pchar(pc) - diff --git a/Examples/test-suite/python/compactdefaultargs_runme.py b/Examples/test-suite/python/compactdefaultargs_runme.py index ff865714c26..e81c8d17376 100644 --- a/Examples/test-suite/python/compactdefaultargs_runme.py +++ b/Examples/test-suite/python/compactdefaultargs_runme.py @@ -4,17 +4,16 @@ defaults1 = Defaults1() if defaults1.ret(10.0) != 10.0: - raise RuntimeError + raise RuntimeError if defaults1.ret() != -1.0: - raise RuntimeError + raise RuntimeError defaults2 = Defaults2(1000) defaults2 = Defaults2() if defaults2.ret(10.0) != 10.0: - raise RuntimeError + raise RuntimeError if defaults2.ret() != -1.0: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/complextest_runme.py b/Examples/test-suite/python/complextest_runme.py index cc2463a39b4..7dd7f5a3bbd 100644 --- a/Examples/test-suite/python/complextest_runme.py +++ b/Examples/test-suite/python/complextest_runme.py @@ -1,17 +1,17 @@ import complextest -a = complex(-1,2) +a = complex(-1, 2) if complextest.Conj(a) != a.conjugate(): - raise RuntimeError, "bad complex mapping" + raise RuntimeError, "bad complex mapping" if complextest.Conjf(a) != a.conjugate(): - raise RuntimeError, "bad complex mapping" + raise RuntimeError, "bad complex mapping" -v = (complex(1,2), complex(2,3), complex(4,3), 1) +v = (complex(1, 2), complex(2, 3), complex(4, 3), 1) try: - complextest.Copy_h(v) + complextest.Copy_h(v) except: - pass + pass diff --git a/Examples/test-suite/python/constant_directive_runme.py b/Examples/test-suite/python/constant_directive_runme.py index 48f85ce8a05..a7ed82b8b7f 100644 --- a/Examples/test-suite/python/constant_directive_runme.py +++ b/Examples/test-suite/python/constant_directive_runme.py @@ -1,15 +1,20 @@ import constant_directive -if not isinstance(constant_directive.TYPE1_CONSTANT1,constant_directive.Type1): - raise RuntimeError("Failure: TYPE1_CONSTANT1 type: {}".format(type(constant_directive.TYPE1_CONSTANT1))) -if not isinstance(constant_directive.getType1Instance(),constant_directive.Type1): - raise RuntimeError("Failure: getType1Instance() type: {}".format(type(constant_directive.getType1Instance()))) +if not isinstance(constant_directive.TYPE1_CONSTANT1, constant_directive.Type1): + raise RuntimeError("Failure: TYPE1_CONSTANT1 type: {}".format( + type(constant_directive.TYPE1_CONSTANT1))) +if not isinstance(constant_directive.getType1Instance(), constant_directive.Type1): + raise RuntimeError("Failure: getType1Instance() type: {}".format( + type(constant_directive.getType1Instance()))) if constant_directive.TYPE1_CONSTANT1.val != 1: - raise RuntimeError("constant_directive.TYPE1_CONSTANT1.val is %r (should be 1)" % constant_directive.TYPE1_CONSTANT1.val) + raise RuntimeError("constant_directive.TYPE1_CONSTANT1.val is %r (should be 1)" % + constant_directive.TYPE1_CONSTANT1.val) if constant_directive.TYPE1_CONSTANT2.val != 2: - raise RuntimeError("constant_directive.TYPE1_CONSTANT2.val is %r (should be 2)" % constant_directive.TYPE1_CONSTANT2.val) + raise RuntimeError("constant_directive.TYPE1_CONSTANT2.val is %r (should be 2)" % + constant_directive.TYPE1_CONSTANT2.val) if constant_directive.TYPE1_CONSTANT3.val != 3: - raise RuntimeError("constant_directive.TYPE1_CONSTANT3.val is %r (should be 3)" % constant_directive.TYPE1_CONSTANT3.val) + raise RuntimeError("constant_directive.TYPE1_CONSTANT3.val is %r (should be 3)" % + constant_directive.TYPE1_CONSTANT3.val) diff --git a/Examples/test-suite/python/constover_runme.py b/Examples/test-suite/python/constover_runme.py index 5c5419706b5..2d28a55cc9e 100644 --- a/Examples/test-suite/python/constover_runme.py +++ b/Examples/test-suite/python/constover_runme.py @@ -11,7 +11,7 @@ if p != "test_pconst": print "test_pconst failed!" error = 1 - + f = constover.Foo() p = f.test("test") if p != "test": @@ -32,7 +32,5 @@ if p != "test_pconstmethod": print "member-test_pconstm failed!" error = 1 - -sys.exit(error) - +sys.exit(error) diff --git a/Examples/test-suite/python/constructor_copy_runme.py b/Examples/test-suite/python/constructor_copy_runme.py index 431d3232fcb..a54bc106f77 100644 --- a/Examples/test-suite/python/constructor_copy_runme.py +++ b/Examples/test-suite/python/constructor_copy_runme.py @@ -1,7 +1,7 @@ from constructor_copy import * -f1 = Foo1(3); -f11 = Foo1(f1); +f1 = Foo1(3) +f11 = Foo1(f1) if f1.x != f11.x: @@ -24,7 +24,7 @@ if (bi.x != bc.x): raise RuntimeError - + bd = Bard(5) try: @@ -35,4 +35,3 @@ if not good: raise RuntimeError - diff --git a/Examples/test-suite/python/contract_runme.py b/Examples/test-suite/python/contract_runme.py index 905bf1196c8..cd75a51d26d 100644 --- a/Examples/test-suite/python/contract_runme.py +++ b/Examples/test-suite/python/contract_runme.py @@ -1,143 +1,142 @@ import contract -contract.test_preassert(1,2) +contract.test_preassert(1, 2) try: - contract.test_preassert(-1) - print "Failed! Preassertions are broken" + contract.test_preassert(-1) + print "Failed! Preassertions are broken" except: - pass + pass contract.test_postassert(3) try: - contract.test_postassert(-3) - print "Failed! Postassertions are broken" + contract.test_postassert(-3) + print "Failed! Postassertions are broken" except: - pass + pass -contract.test_prepost(2,3) -contract.test_prepost(5,-4) +contract.test_prepost(2, 3) +contract.test_prepost(5, -4) try: - contract.test_prepost(-3,4) - print "Failed! Preassertions are broken" + contract.test_prepost(-3, 4) + print "Failed! Preassertions are broken" except: - pass + pass try: - contract.test_prepost(4,-10) - print "Failed! Postassertions are broken" + contract.test_prepost(4, -10) + print "Failed! Postassertions are broken" except: - pass + pass f = contract.Foo() -f.test_preassert(4,5) +f.test_preassert(4, 5) try: - f.test_preassert(-2,3) - print "Failed! Method preassertion." + f.test_preassert(-2, 3) + print "Failed! Method preassertion." except: - pass + pass f.test_postassert(4) try: - f.test_postassert(-4) - print "Failed! Method postassertion" + f.test_postassert(-4) + print "Failed! Method postassertion" except: - pass + pass -f.test_prepost(3,4) -f.test_prepost(4,-3) +f.test_prepost(3, 4) +f.test_prepost(4, -3) try: - f.test_prepost(-4,2) - print "Failed! Method preassertion." + f.test_prepost(-4, 2) + print "Failed! Method preassertion." except: - pass + pass try: - f.test_prepost(4,-10) - print "Failed! Method postassertion." + f.test_prepost(4, -10) + print "Failed! Method postassertion." except: - pass + pass -contract.Foo_stest_prepost(4,0) +contract.Foo_stest_prepost(4, 0) try: - contract.Foo_stest_prepost(-4,2) - print "Failed! Static method preassertion" + contract.Foo_stest_prepost(-4, 2) + print "Failed! Static method preassertion" except: - pass + pass try: - contract.Foo_stest_prepost(4,-10) - print "Failed! Static method posteassertion" + contract.Foo_stest_prepost(4, -10) + print "Failed! Static method posteassertion" except: - pass - + pass + b = contract.Bar() try: - b.test_prepost(2,-4) - print "Failed! Inherited preassertion." + b.test_prepost(2, -4) + print "Failed! Inherited preassertion." except: - pass + pass d = contract.D() try: - d.foo(-1,1,1,1,1) - print "Failed! Inherited preassertion (D)." + d.foo(-1, 1, 1, 1, 1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.foo(1,-1,1,1,1) - print "Failed! Inherited preassertion (D)." + d.foo(1, -1, 1, 1, 1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.foo(1,1,-1,1,1) - print "Failed! Inherited preassertion (D)." + d.foo(1, 1, -1, 1, 1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.foo(1,1,1,-1,1) - print "Failed! Inherited preassertion (D)." + d.foo(1, 1, 1, -1, 1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.foo(1,1,1,1,-1) - print "Failed! Inherited preassertion (D)." + d.foo(1, 1, 1, 1, -1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.bar(-1,1,1,1,1) - print "Failed! Inherited preassertion (D)." + d.bar(-1, 1, 1, 1, 1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.bar(1,-1,1,1,1) - print "Failed! Inherited preassertion (D)." + d.bar(1, -1, 1, 1, 1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.bar(1,1,-1,1,1) - print "Failed! Inherited preassertion (D)." + d.bar(1, 1, -1, 1, 1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.bar(1,1,1,-1,1) - print "Failed! Inherited preassertion (D)." + d.bar(1, 1, 1, -1, 1) + print "Failed! Inherited preassertion (D)." except: - pass + pass try: - d.bar(1,1,1,1,-1) - print "Failed! Inherited preassertion (D)." + d.bar(1, 1, 1, 1, -1) + print "Failed! Inherited preassertion (D)." except: - pass + pass -#Namespace +# Namespace my = contract.myClass(1) try: - my = contract.myClass(0) - print "Failed! constructor preassertion" + my = contract.myClass(0) + print "Failed! constructor preassertion" except: - pass - + pass diff --git a/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py b/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py index 0a1c45716dc..363736a84ef 100644 --- a/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py +++ b/Examples/test-suite/python/cpp11_alternate_function_syntax_runme.py @@ -2,12 +2,13 @@ a = cpp11_alternate_function_syntax.SomeStruct() -res = a.addNormal(4,5) +res = a.addNormal(4, 5) if res != 9: - raise RuntimeError, ("SomeStruct::addNormal(4,5) returns ", res, " should be 9.") + raise RuntimeError, ("SomeStruct::addNormal(4,5) returns ", + res, " should be 9.") -res = a.addAlternate(4,5) +res = a.addAlternate(4, 5) if res != 9: - raise RuntimeError, ("SomeStruct::addAlternate(4,5) returns ", res, " should be 9.") - + raise RuntimeError, ("SomeStruct::addAlternate(4,5) returns ", + res, " should be 9.") diff --git a/Examples/test-suite/python/cpp11_decltype_runme.py b/Examples/test-suite/python/cpp11_decltype_runme.py index bfcbbec793a..1650d9004e9 100644 --- a/Examples/test-suite/python/cpp11_decltype_runme.py +++ b/Examples/test-suite/python/cpp11_decltype_runme.py @@ -3,17 +3,16 @@ a = cpp11_decltype.A() a.i = 5 if a.i != 5: - raise RuntimeError, "Assignment to a.i failed." + raise RuntimeError, "Assignment to a.i failed." a.j = 10 if a.j != 10: - raise RuntimeError, "Assignment to a.j failed." + raise RuntimeError, "Assignment to a.j failed." b = a.foo(5) if b != 10: - raise RuntimeError, "foo(5) should return 10." + raise RuntimeError, "foo(5) should return 10." b = a.foo(6) if b != 0: - raise RuntimeError, "foo(6) should return 0." - + raise RuntimeError, "foo(6) should return 0." diff --git a/Examples/test-suite/python/cpp11_function_objects_runme.py b/Examples/test-suite/python/cpp11_function_objects_runme.py index 5a63b632b78..d1515c16ce2 100644 --- a/Examples/test-suite/python/cpp11_function_objects_runme.py +++ b/Examples/test-suite/python/cpp11_function_objects_runme.py @@ -1,7 +1,9 @@ import cpp11_function_objects import sys + class Test1(cpp11_function_objects.Test): + def __init__(self): cpp11_function_objects.Test.__init__(self) @@ -10,14 +12,17 @@ def __call__(self, a, b): t = cpp11_function_objects.Test() if t.value != 0: - raise RuntimeError("Runtime cpp11_function_objects failed. t.value should be 0, but is " + str(t.value)) + raise RuntimeError( + "Runtime cpp11_function_objects failed. t.value should be 0, but is " + str(t.value)) -t(1,2) # adds numbers and sets value +t(1, 2) # adds numbers and sets value if t.value != 3: - raise RuntimeError("Runtime cpp11_function_objects failed. t.value not changed - should be 3, but is " + str(t.value)) - + raise RuntimeError( + "Runtime cpp11_function_objects failed. t.value not changed - should be 3, but is " + str(t.value)) + t2 = Test1() -a = cpp11_function_objects.testit1(t2, 4,3) +a = cpp11_function_objects.testit1(t2, 4, 3) if a != 12: - raise RuntimeError("Runtime cpp11_function_objects failed. t.value not changed - should be 12, but is " + str(a)) + raise RuntimeError( + "Runtime cpp11_function_objects failed. t.value not changed - should be 12, but is " + str(a)) diff --git a/Examples/test-suite/python/cpp11_initializer_list_extend_runme.py b/Examples/test-suite/python/cpp11_initializer_list_extend_runme.py index eedf8f148cb..285273efaab 100644 --- a/Examples/test-suite/python/cpp11_initializer_list_extend_runme.py +++ b/Examples/test-suite/python/cpp11_initializer_list_extend_runme.py @@ -1,4 +1,3 @@ import cpp11_initializer_list_extend -c = cpp11_initializer_list_extend.Container( [10, 20, 30, 40] ) - +c = cpp11_initializer_list_extend.Container([10, 20, 30, 40]) diff --git a/Examples/test-suite/python/cpp11_initializer_list_runme.py b/Examples/test-suite/python/cpp11_initializer_list_runme.py index 395cd610d85..84f955f6324 100644 --- a/Examples/test-suite/python/cpp11_initializer_list_runme.py +++ b/Examples/test-suite/python/cpp11_initializer_list_runme.py @@ -2,4 +2,3 @@ a = cpp11_initializer_list.A() a = cpp11_initializer_list.A(11.1) - diff --git a/Examples/test-suite/python/cpp11_li_std_array_runme.py b/Examples/test-suite/python/cpp11_li_std_array_runme.py new file mode 100644 index 00000000000..3b1ceb2f82e --- /dev/null +++ b/Examples/test-suite/python/cpp11_li_std_array_runme.py @@ -0,0 +1,163 @@ +from cpp11_li_std_array import * +import sys + + +def failed(a, b, msg): + raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) + + +def compare_sequences(a, b): + if len(a) != len(b): + failed(a, b, "different sizes") + for i in range(len(a)): + if a[i] != b[i]: + failed(a, b, "elements are different") + +def compare_containers(pythonlist, swigarray): + compare_sequences(pythonlist, swigarray) + +def steps_exception(swigarray, i, j, step): + try: + if i == None and j == None: + a = swigarray[::step] + elif i == None: + a = swigarray[:j:step] + elif j == None: + a = swigarray[i::step] + else: + a = swigarray[i:j:step] + raise RuntimeError, "swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed steps exception for " + str(list(swigarray)) + except ValueError, e: +# print("exception: {}".format(e)) + pass + +def del_exception(swigarray, i, j, step): + try: + if i == None and j == None: + del swigarray[::step] + elif j == None and step == None: + del swigarray[i] + elif i == None: + del swigarray[:j:step] + elif j == None: + del swigarray[i::step] + else: + del swigarray[i:j:step] + raise RuntimeError, "swigarray[" + str(i) + ":" + str(j) + ":" + str(step) + "] missed del exception for " + str(list(swigarray)) + except ValueError, e: +# print("exception: {}".format(e)) + pass + +def setslice_exception(swigarray, newval): + try: + swigarray[::] = newval + raise RuntimeError, "swigarray[::] = " + str(newval) + " missed set exception for swigarray:" + str(list(swigarray)) + except TypeError, e: +# print("exception: {}".format(e)) + pass + + +# Check std::array has similar behaviour to a Python list +# except it is not resizable + +ps = [0, 1, 2, 3, 4, 5] + +ai = ArrayInt6(ps) + +compare_containers(ps, ai) + +# slices +compare_containers(ps[0:6], ai[0:6]) +compare_containers(ps[0:10], ai[0:10]) +compare_containers(ps[-10:6], ai[-10:6]) +compare_containers(ps[-10:10], ai[-10:10]) + +compare_containers(ps[0:6:1], ai[0:6:1]) +compare_containers(ps[::], ai[::]) +compare_containers(ps[::1], ai[::1]) + +compare_containers([x for x in ps], [x for x in ai]) + +# Reverse +compare_containers(ps[::-1], ai[::-1]) +compare_containers(ps[5::-1], ai[5::-1]) +compare_containers(ps[10::-1], ai[10::-1]) + +# Steps other than +1 and -1 not supported +steps_exception(ai, 0, 6, 3) +steps_exception(ai, None, None, 0) +steps_exception(ai, None, None, 2) +steps_exception(ai, None, None, -2) +steps_exception(ai, 1, 3, 1) +steps_exception(ai, 3, 1, -1) + +# Modify content +for i in range(len(ps)): + ps[i] = (ps[i] + 1) * 10 + ai[i] = (ai[i] + 1) * 10 +compare_containers(ps, ai) + +# Delete +del_exception(ai, 0, 6, 3) +del_exception(ai, None, None, 0) +del_exception(ai, None, None, 2) +del_exception(ai, None, None, -2) +del_exception(ai, 1, 3, 1) +del_exception(ai, 3, 1, -1) + +del_exception(ai, 0, None, None) +del_exception(ai, 5, None, None) + +# Empty +ai = ArrayInt6() +compare_containers([0, 0, 0, 0, 0, 0], ai) + +# Set slice +newvals = [10, 20, 30, 40, 50, 60] +ai[::] = newvals +compare_containers(ai, newvals) + +newvals = [100, 200, 300, 400, 500, 600] +ai[0:6:1] = newvals +compare_containers(ai, newvals) + +newvals = [1000, 2000, 3000, 4000, 5000, 6000] +ai[::-1] = newvals +compare_containers(ai, newvals[::-1]) + +newvals = [10000, 20000, 30000, 40000, 50000, 60000] +ai[-10:100:1] = newvals +compare_containers(ai, newvals[-10:100:1]) + +setslice_exception(ai, [1, 2, 3, 4, 5, 6, 7]) +setslice_exception(ai, [1, 2, 3, 4, 5]) +setslice_exception(ai, [1, 2, 3, 4]) +setslice_exception(ai, [1, 2, 3]) +setslice_exception(ai, [1, 2]) +setslice_exception(ai, [1]) +setslice_exception(ai, []) + +# Check return +compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2]) +compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2]) +compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2]) +compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2]) + +# Check passing arguments +ai = arrayInVal([9, 8, 7, 6, 5, 4]) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +ai = arrayInConstRef([9, 8, 7, 6, 5, 4]) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +ai = ArrayInt6([9, 8, 7, 6, 5, 4]) +arrayInRef(ai) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +ai = ArrayInt6([9, 8, 7, 6, 5, 4]) +arrayInPtr(ai) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +# fill +ai.fill(111) +compare_containers(ai, [111, 111, 111, 111, 111, 111]) diff --git a/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py b/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py index d304c139da9..54a8fe0ebb7 100644 --- a/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py +++ b/Examples/test-suite/python/cpp11_null_pointer_constant_runme.py @@ -3,13 +3,15 @@ a = cpp11_null_pointer_constant.A() if a._myA != None: - raise RuntimeError, ("cpp11_null_pointer_constant: _myA should be None, but is ", a._myA) + raise RuntimeError, ( + "cpp11_null_pointer_constant: _myA should be None, but is ", a._myA) b = cpp11_null_pointer_constant.A() if a._myA != b._myA: - raise RuntimeError, ("cpp11_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA) + raise RuntimeError, ( + "cpp11_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA) a._myA = cpp11_null_pointer_constant.A() if a._myA == None: - raise RuntimeError, ("cpp11_null_pointer_constant: _myA should be object, but is None") - + raise RuntimeError, ( + "cpp11_null_pointer_constant: _myA should be object, but is None") diff --git a/Examples/test-suite/python/cpp11_raw_string_literals_runme.py b/Examples/test-suite/python/cpp11_raw_string_literals_runme.py index 32282d8d81d..29e53c6a7dc 100644 --- a/Examples/test-suite/python/cpp11_raw_string_literals_runme.py +++ b/Examples/test-suite/python/cpp11_raw_string_literals_runme.py @@ -1,50 +1,48 @@ from cpp11_raw_string_literals import * if cvar.L != 100: - raise RuntimeError + raise RuntimeError if cvar.u8 != 100: - raise RuntimeError + raise RuntimeError if cvar.u != 100: - raise RuntimeError + raise RuntimeError if UStruct.U != 100: - raise RuntimeError + raise RuntimeError if cvar.R != 100: - raise RuntimeError + raise RuntimeError if cvar.LR != 100: - raise RuntimeError + raise RuntimeError if cvar.u8R != 100: - raise RuntimeError + raise RuntimeError if cvar.uR != 100: - raise RuntimeError + raise RuntimeError if URStruct.UR != 100: - raise RuntimeError + raise RuntimeError if cvar.aa != "Wide string": - raise RuntimeError + raise RuntimeError if cvar.bb != "UTF-8 string": - raise RuntimeError, cvar.wide + raise RuntimeError, cvar.wide if cvar.xx != ")I'm an \"ascii\" \\ string.": - raise RuntimeError, cvar.xx + raise RuntimeError, cvar.xx if cvar.ee != ")I'm an \"ascii\" \\ string.": - raise RuntimeError, cvar.ee + raise RuntimeError, cvar.ee if cvar.ff != "I'm a \"raw wide\" \\ string.": - raise RuntimeError, cvar.ff + raise RuntimeError, cvar.ff if cvar.gg != "I'm a \"raw UTF-8\" \\ string.": - raise RuntimeError, cvar.gg - - + raise RuntimeError, cvar.gg diff --git a/Examples/test-suite/python/cpp11_result_of_runme.py b/Examples/test-suite/python/cpp11_result_of_runme.py index 4dc39fcdfb3..4469efd81f0 100644 --- a/Examples/test-suite/python/cpp11_result_of_runme.py +++ b/Examples/test-suite/python/cpp11_result_of_runme.py @@ -2,8 +2,10 @@ result = cpp11_result_of.test_result(cpp11_result_of.SQUARE, 3.0) if result != 9.0: - raise RuntimeError, "test_result(square, 3.0) is not 9.0. Got: " + str(result) + raise RuntimeError, "test_result(square, 3.0) is not 9.0. Got: " + str( + result) result = cpp11_result_of.test_result_alternative1(cpp11_result_of.SQUARE, 3.0) if result != 9.0: - raise RuntimeError, "test_result_alternative1(square, 3.0) is not 9.0. Got: " + str(result) + raise RuntimeError, "test_result_alternative1(square, 3.0) is not 9.0. Got: " + str( + result) diff --git a/Examples/test-suite/python/cpp11_rvalue_reference_runme.py b/Examples/test-suite/python/cpp11_rvalue_reference_runme.py index a72a3e63b0c..c1cd3bf2600 100644 --- a/Examples/test-suite/python/cpp11_rvalue_reference_runme.py +++ b/Examples/test-suite/python/cpp11_rvalue_reference_runme.py @@ -4,21 +4,24 @@ a.setAcopy(5) if a.getAcopy() != 5: - raise RunTimeError, ("int A::getAcopy() value is ", a.getAcopy(), " should be 5") + raise RunTimeError, ("int A::getAcopy() value is ", + a.getAcopy(), " should be 5") ptr = a.getAptr() a.setAptr(ptr) if a.getAcopy() != 5: - raise RunTimeError, ("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(), " should be 5") + raise RunTimeError, ("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy( + ), " should be 5") a.setAref(ptr) if a.getAcopy() != 5: - raise RunTimeError, ("after A::setAref(): int A::getAcopy() value is ", a.getAcopy(), " should be 5") + raise RunTimeError, ("after A::setAref(): int A::getAcopy() value is ", a.getAcopy( + ), " should be 5") rvalueref = a.getAmove() a.setAmove(rvalueref) if a.getAcopy() != 5: - raise RunTimeError, ("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(), " should be 5") - + raise RunTimeError, ("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy( + ), " should be 5") diff --git a/Examples/test-suite/python/cpp11_strongly_typed_enumerations_runme.py b/Examples/test-suite/python/cpp11_strongly_typed_enumerations_runme.py index 6509ba873e1..21b4f63f5d1 100644 --- a/Examples/test-suite/python/cpp11_strongly_typed_enumerations_runme.py +++ b/Examples/test-suite/python/cpp11_strongly_typed_enumerations_runme.py @@ -1,9 +1,11 @@ from cpp11_strongly_typed_enumerations import * + def enumCheck(actual, expected): - if actual != expected: - raise RuntimeError("Enum value mismatch. Expected " + str(expected) + " Actual: " + str(actual)) - return expected + 1 + if actual != expected: + raise RuntimeError( + "Enum value mismatch. Expected " + str(expected) + " Actual: " + str(actual)) + return expected + 1 val = 0 val = enumCheck(Enum1_Val1, val) @@ -161,4 +163,3 @@ def enumCheck(actual, expected): enumCheck(globalTest1(Enum1_Val5a), 13) enumCheck(globalTest2(Class1.Enum12_Val5c), 1121) #enumCheck(globalTest3(Class1.Struct1.Enum12_Val5f), 3121) - diff --git a/Examples/test-suite/python/cpp11_thread_local_runme.py b/Examples/test-suite/python/cpp11_thread_local_runme.py index 59a657488d9..83f2390ecf0 100644 --- a/Examples/test-suite/python/cpp11_thread_local_runme.py +++ b/Examples/test-suite/python/cpp11_thread_local_runme.py @@ -2,37 +2,36 @@ t = ThreadLocals() if t.stval != 11: - raise RuntimeError + raise RuntimeError if t.tsval != 22: - raise RuntimeError + raise RuntimeError if t.tscval99 != 99: - raise RuntimeError + raise RuntimeError cvar.etval = -11 if cvar.etval != -11: - raise RuntimeError + raise RuntimeError cvar.stval = -22 if cvar.stval != -22: - raise RuntimeError + raise RuntimeError cvar.tsval = -33 if cvar.tsval != -33: - raise RuntimeError + raise RuntimeError cvar.etval = -44 if cvar.etval != -44: - raise RuntimeError + raise RuntimeError cvar.teval = -55 if cvar.teval != -55: - raise RuntimeError + raise RuntimeError cvar.ectval = -66 if cvar.ectval != -66: - raise RuntimeError + raise RuntimeError cvar.ecpptval = -66 if cvar.ecpptval != -66: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/cpp11_type_traits_runme.py b/Examples/test-suite/python/cpp11_type_traits_runme.py index cb58656a6fe..d0dfb23d78d 100644 --- a/Examples/test-suite/python/cpp11_type_traits_runme.py +++ b/Examples/test-suite/python/cpp11_type_traits_runme.py @@ -1,7 +1,7 @@ from cpp11_type_traits import * if Elaborate(0, 0) != 1: - raise RuntimeError("Elaborate should have returned 1") + raise RuntimeError("Elaborate should have returned 1") if Elaborate(0, 0.0) != 2: - raise RuntimeError("Elaborate should have returned 2") + raise RuntimeError("Elaborate should have returned 2") diff --git a/Examples/test-suite/python/cpp11_uniform_initialization_runme.py b/Examples/test-suite/python/cpp11_uniform_initialization_runme.py index 85c3b2478c9..ecb468ccbab 100644 --- a/Examples/test-suite/python/cpp11_uniform_initialization_runme.py +++ b/Examples/test-suite/python/cpp11_uniform_initialization_runme.py @@ -2,20 +2,20 @@ var1 = cpp11_uniform_initialization.cvar.var1 if var1.x != 5: - raise RuntimeError + raise RuntimeError var2 = cpp11_uniform_initialization.cvar.var2 if var2.getX() != 2: - raise RuntimeError + raise RuntimeError m = cpp11_uniform_initialization.MoreInit() if m.charptr != None: - raise RuntimeError, m.charptr + raise RuntimeError, m.charptr m.charptr = "hello sir" if m.charptr != "hello sir": - raise RuntimeError, m.charptr + raise RuntimeError, m.charptr if m.more1(m.vi) != 15: - raise RuntimeError, m.vi -if m.more1( [-1,1,2] ) != 2: - raise RuntimeError, m.vi + raise RuntimeError, m.vi +if m.more1([-1, 1, 2]) != 2: + raise RuntimeError, m.vi if m.more1() != 10: - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/cpp_enum_runme.py b/Examples/test-suite/python/cpp_enum_runme.py index 0054ae2810a..5f1e91c9728 100644 --- a/Examples/test-suite/python/cpp_enum_runme.py +++ b/Examples/test-suite/python/cpp_enum_runme.py @@ -3,21 +3,21 @@ f = cpp_enum.Foo() if f.hola != f.Hello: - print f.hola - raise RuntimeError + print f.hola + raise RuntimeError f.hola = f.Hi if f.hola != f.Hi: - print f.hola - raise RuntimeError + print f.hola + raise RuntimeError f.hola = f.Hello if f.hola != f.Hello: - print f.hola - raise RuntimeError + print f.hola + raise RuntimeError cpp_enum.cvar.hi = cpp_enum.Hello if cpp_enum.cvar.hi != cpp_enum.Hello: - print cpp_enum.cvar.hi - raise RuntimeError + print cpp_enum.cvar.hi + raise RuntimeError diff --git a/Examples/test-suite/python/cpp_namespace_runme.py b/Examples/test-suite/python/cpp_namespace_runme.py index a454774f5d8..2ab959aea8b 100644 --- a/Examples/test-suite/python/cpp_namespace_runme.py +++ b/Examples/test-suite/python/cpp_namespace_runme.py @@ -17,7 +17,7 @@ if cpp_namespace.do_method2(t) != "Test::method": raise RuntimeError("Bad return value!") - + cpp_namespace.weird("hello", 4) del t @@ -30,16 +30,14 @@ if cpp_namespace.foo3(42) != 42: raise RuntimeError("Bad return value!") -if cpp_namespace.do_method3(t2,40) != "Test2::method": +if cpp_namespace.do_method3(t2, 40) != "Test2::method": raise RuntimeError("Bad return value!") -if cpp_namespace.do_method3(t3,40) != "Test3::method": +if cpp_namespace.do_method3(t3, 40) != "Test3::method": raise RuntimeError("Bad return value!") -if cpp_namespace.do_method3(t4,40) != "Test4::method": +if cpp_namespace.do_method3(t4, 40) != "Test4::method": raise RuntimeError("Bad return value!") -if cpp_namespace.do_method3(t5,40) != "Test5::method": +if cpp_namespace.do_method3(t5, 40) != "Test5::method": raise RuntimeError("Bad return value!") - - diff --git a/Examples/test-suite/python/cpp_static_runme.py b/Examples/test-suite/python/cpp_static_runme.py index ef862335967..b742de285d4 100644 --- a/Examples/test-suite/python/cpp_static_runme.py +++ b/Examples/test-suite/python/cpp_static_runme.py @@ -1,7 +1,17 @@ #!/usr/bin/evn python from cpp_static import * -StaticFunctionTest.static_func() -StaticFunctionTest.static_func_2(1) -StaticFunctionTest.static_func_3(1,2) + + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + +if is_new_style_class(StaticFunctionTest): + StaticFunctionTest.static_func() + StaticFunctionTest.static_func_2(1) + StaticFunctionTest.static_func_3(1, 2) +else: + StaticFunctionTest().static_func() + StaticFunctionTest().static_func_2(1) + StaticFunctionTest().static_func_3(1, 2) StaticMemberTest.static_int = 10 assert StaticMemberTest.static_int == 10 diff --git a/Examples/test-suite/python/default_arg_values_runme.py b/Examples/test-suite/python/default_arg_values_runme.py index 44e9a3b5e3d..73a73886635 100644 --- a/Examples/test-suite/python/default_arg_values_runme.py +++ b/Examples/test-suite/python/default_arg_values_runme.py @@ -3,15 +3,26 @@ d = Display() if d.draw1() != 0: - raise RuntimeError + raise RuntimeError if d.draw1(12) != 12: - raise RuntimeError + raise RuntimeError -p = createPtr(123); +p = createPtr(123) if d.draw2() != 0: - raise RuntimeError + raise RuntimeError if d.draw2(p) != 123: - raise RuntimeError + raise RuntimeError +if d.bool0() != False or type(d.bool0()) != type(False): + raise RuntimeError + +if d.bool1() != True or type(d.bool1()) != type(True): + raise RuntimeError + +if d.mybool0() != False or type(d.mybool0()) != type(False): + raise RuntimeError + +if d.mybool1() != True or type(d.mybool1()) != type(True): + raise RuntimeError diff --git a/Examples/test-suite/python/default_args_runme.py b/Examples/test-suite/python/default_args_runme.py index f24e825ad1c..6610a4ec4a2 100644 --- a/Examples/test-suite/python/default_args_runme.py +++ b/Examples/test-suite/python/default_args_runme.py @@ -1,90 +1,140 @@ -# Note that this test is also used by python_default_args_runme.py hence the use of __main__ and the run function - -def run(module_name): - default_args = __import__(module_name) - ec = default_args.EnumClass() - if not ec.blah(): - raise RuntimeError("EnumClass::blah() default arguments don't work") - - de = default_args.DerivedEnumClass() - de.accelerate() - de.accelerate(default_args.EnumClass.SLOW) - - if default_args.Statics_staticMethod() != 60: - raise RuntimeError - - if default_args.cfunc1(1) != 2: - raise RuntimeError - - if default_args.cfunc2(1) != 3: - raise RuntimeError - - if default_args.cfunc3(1) != 4: - raise RuntimeError - - - f = default_args.Foo() - - f.newname() - f.newname(1) +# Note that this test is also used by python_default_args_runme.py hence +# the use of __main__ and the run function - try: - f = default_args.Foo(1) - error = 1 - except: - error = 0 - if error: raise RuntimeError("Foo::Foo ignore is not working") +def is_new_style_class(cls): + return hasattr(cls, "__class__") - try: - f = default_args.Foo(1,2) - error = 1 - except: - error = 0 - if error: raise RuntimeError("Foo::Foo ignore is not working") - - try: - f = default_args.Foo(1,2,3) - error = 1 - except: - error = 0 - if error: raise RuntimeError("Foo::Foo ignore is not working") - - try: - m = f.meth(1) - error = 1 - except: - error = 0 - if error: raise RuntimeError("Foo::meth ignore is not working") - - try: - m = f.meth(1,2) - error = 1 - except: - error = 0 - if error: raise RuntimeError("Foo::meth ignore is not working") - - try: - m = f.meth(1,2,3) - error = 1 - except: - error = 0 - if error: raise RuntimeError("Foo::meth ignore is not working") - - if default_args.Klass.inc(100, default_args.Klass(22)).val != 122: - raise RuntimeError("Klass::inc failed") - - if default_args.Klass.inc(100).val != 99: - raise RuntimeError("Klass::inc failed") - - if default_args.Klass.inc().val != 0: - raise RuntimeError("Klass::inc failed") - - default_args.trickyvalue1(10); default_args.trickyvalue1(10, 10) - default_args.trickyvalue2(10); default_args.trickyvalue2(10, 10) - default_args.trickyvalue3(10); default_args.trickyvalue3(10, 10) - default_args.seek(); default_args.seek(10) - -if __name__=="__main__": - run('default_args') +def run(module_name): + default_args = __import__(module_name) + ec = default_args.EnumClass() + if not ec.blah(): + raise RuntimeError("EnumClass::blah() default arguments don't work") + + de = default_args.DerivedEnumClass() + de.accelerate() + de.accelerate(default_args.EnumClass.SLOW) + + if default_args.Statics_staticMethod() != 60: + raise RuntimeError + + if default_args.cfunc1(1) != 2: + raise RuntimeError + + if default_args.cfunc2(1) != 3: + raise RuntimeError + + if default_args.cfunc3(1) != 4: + raise RuntimeError + + f = default_args.Foo() + + f.newname() + f.newname(1) + + if f.double_if_void_ptr_is_null(2, None) != 4: + raise RuntimeError + + if f.double_if_void_ptr_is_null(3) != 6: + raise RuntimeError + + if f.double_if_handle_is_null(4, None) != 8: + raise RuntimeError + + if f.double_if_handle_is_null(5) != 10: + raise RuntimeError + + if f.double_if_dbl_ptr_is_null(6, None) != 12: + raise RuntimeError + + if f.double_if_dbl_ptr_is_null(7) != 14: + raise RuntimeError + + try: + f = default_args.Foo(1) + error = 1 + except: + error = 0 + if error: + raise RuntimeError("Foo::Foo ignore is not working") + + try: + f = default_args.Foo(1, 2) + error = 1 + except: + error = 0 + if error: + raise RuntimeError("Foo::Foo ignore is not working") + + try: + f = default_args.Foo(1, 2, 3) + error = 1 + except: + error = 0 + if error: + raise RuntimeError("Foo::Foo ignore is not working") + + try: + m = f.meth(1) + error = 1 + except: + error = 0 + if error: + raise RuntimeError("Foo::meth ignore is not working") + + try: + m = f.meth(1, 2) + error = 1 + except: + error = 0 + if error: + raise RuntimeError("Foo::meth ignore is not working") + + try: + m = f.meth(1, 2, 3) + error = 1 + except: + error = 0 + if error: + raise RuntimeError("Foo::meth ignore is not working") + + if is_new_style_class(default_args.Klass): + Klass_inc = default_args.Klass.inc + else: + Klass_inc = default_args.Klass_inc + + if Klass_inc(100, default_args.Klass(22)).val != 122: + raise RuntimeError("Klass::inc failed") + + if Klass_inc(100).val != 99: + raise RuntimeError("Klass::inc failed") + + if Klass_inc().val != 0: + raise RuntimeError("Klass::inc failed") + + default_args.trickyvalue1(10) + default_args.trickyvalue1(10, 10) + default_args.trickyvalue2(10) + default_args.trickyvalue2(10, 10) + default_args.trickyvalue3(10) + default_args.trickyvalue3(10, 10) + default_args.seek() + default_args.seek(10) + + if default_args.slightly_off_square(10) != 102: + raise RuntimeError + + if default_args.slightly_off_square() != 291: + raise RuntimeError + + # It is difficult to test the python:cdefaultargs feature properly as -builtin + # and -fastproxy do not use the Python layer for default args + if default_args.CDA().cdefaultargs_test1() != 1: + raise RuntimeError + + if default_args.CDA().cdefaultargs_test2() != 1: + raise RuntimeError + +if __name__ == "__main__": + run('default_args') diff --git a/Examples/test-suite/python/default_constructor_runme.py b/Examples/test-suite/python/default_constructor_runme.py index e6532031b42..1e877addad6 100644 --- a/Examples/test-suite/python/default_constructor_runme.py +++ b/Examples/test-suite/python/default_constructor_runme.py @@ -4,7 +4,7 @@ # It uses the old static syntax (e.g., dc.new_A() rather than dc.A()), # which is not provided with the -builtin option. if _default_constructor.is_python_builtin(): - exit(0) + exit(0) dc = _default_constructor @@ -23,7 +23,7 @@ del_b = dc.delete_B try: - bb = dc.new_BB(); + bb = dc.new_BB() print "Whoa. new_BB created." except: pass @@ -42,7 +42,7 @@ dc.delete_CC(cc) try: - d = dc.new_D(); + d = dc.new_D() print "Whoa. new_D created" except: pass @@ -89,15 +89,6 @@ dc.F_destroy(f) -ff = dc.new_FFF() -try: - del_ff = dc.delete_FFF - print "Whoa. delete_FFF created" -except AttributeError: - pass - -dc.F_destroy(ff) - g = dc.new_G() try: @@ -113,5 +104,4 @@ import default_constructor -hh = default_constructor.HH(1,1) - +hh = default_constructor.HH(1, 1) diff --git a/Examples/test-suite/python/director_abstract_runme.py b/Examples/test-suite/python/director_abstract_runme.py index 7d92d10ff3a..031c476d86f 100644 --- a/Examples/test-suite/python/director_abstract_runme.py +++ b/Examples/test-suite/python/director_abstract_runme.py @@ -1,68 +1,91 @@ import director_abstract + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + + class MyFoo(director_abstract.Foo): - def __init__(self): - director_abstract.Foo.__init__(self) - def ping(self): - return "MyFoo::ping()" + + def __init__(self): + director_abstract.Foo.__init__(self) + + def ping(self): + return "MyFoo::ping()" a = MyFoo() if a.ping() != "MyFoo::ping()": - raise RuntimeError, a.ping() + raise RuntimeError, a.ping() if a.pong() != "Foo::pong();MyFoo::ping()": - raise RuntimeError, a.pong() + raise RuntimeError, a.pong() class MyExample1(director_abstract.Example1): - def Color(self, r, g, b): - return r + + def Color(self, r, g, b): + return r + class MyExample2(director_abstract.Example2): - def Color(self, r, g, b): - return g -class MyExample3(director_abstract.Example3_i): - def Color(self, r, g, b): - return b + def Color(self, r, g, b): + return g -me1 = MyExample1() -if director_abstract.Example1_get_color(me1, 1,2,3) != 1: - raise RuntimeError -me2 = MyExample2(1,2) -if MyExample2.get_color(me2, 1,2,3) != 2: - raise RuntimeError +class MyExample3(director_abstract.Example3_i): + + def Color(self, r, g, b): + return b +me1 = MyExample1() +if director_abstract.Example1_get_color(me1, 1, 2, 3) != 1: + raise RuntimeError + +if is_new_style_class(MyExample2): + MyExample2_static = MyExample2 +else: + MyExample2_static = MyExample2(0, 0) +me2 = MyExample2(1, 2) +if MyExample2_static.get_color(me2, 1, 2, 3) != 2: + raise RuntimeError + +if is_new_style_class(MyExample3): + MyExample3_static = MyExample3 +else: + MyExample3_static = MyExample3() me3 = MyExample3() -if MyExample3.get_color(me3, 1,2,3) != 3: - raise RuntimeError +if MyExample3_static.get_color(me3, 1, 2, 3) != 3: + raise RuntimeError error = 1 try: - me1 = director_abstract.Example1() + me1 = director_abstract.Example1() except: - error = 0 -if (error): raise RuntimeError + error = 0 +if (error): + raise RuntimeError error = 1 try: - me2 = director_abstract.Example2() + me2 = director_abstract.Example2() except: - error = 0 -if (error): raise RuntimeError + error = 0 +if (error): + raise RuntimeError error = 1 try: - me3 = director_abstract.Example3_i() + me3 = director_abstract.Example3_i() except: - error = 0 -if (error): raise RuntimeError + error = 0 +if (error): + raise RuntimeError try: - f = director_abstract.A.f + f = director_abstract.A.f except: - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/director_alternating_runme.py b/Examples/test-suite/python/director_alternating_runme.py index a92ae1c5ce6..a93ffec34b9 100644 --- a/Examples/test-suite/python/director_alternating_runme.py +++ b/Examples/test-suite/python/director_alternating_runme.py @@ -2,4 +2,4 @@ id = getBar().id() if id != idFromGetBar(): - raise RuntimeError, "Got wrong id: " + str(id) + raise RuntimeError, "Got wrong id: " + str(id) diff --git a/Examples/test-suite/python/director_basic_runme.py b/Examples/test-suite/python/director_basic_runme.py index 5411398145a..6564c95a2c1 100644 --- a/Examples/test-suite/python/director_basic_runme.py +++ b/Examples/test-suite/python/director_basic_runme.py @@ -1,41 +1,43 @@ import director_basic + class PyFoo(director_basic.Foo): - def ping(self): - return "PyFoo::ping()" + + def ping(self): + return "PyFoo::ping()" a = PyFoo() if a.ping() != "PyFoo::ping()": - raise RuntimeError, a.ping() + raise RuntimeError, a.ping() if a.pong() != "Foo::pong();PyFoo::ping()": - raise RuntimeError, a.pong() + raise RuntimeError, a.pong() b = director_basic.Foo() if b.ping() != "Foo::ping()": - raise RuntimeError, b.ping() + raise RuntimeError, b.ping() if b.pong() != "Foo::pong();Foo::ping()": - raise RuntimeError, b.pong() + raise RuntimeError, b.pong() a = director_basic.A1(1) if a.rg(2) != 2: - raise RuntimeError - + raise RuntimeError class PyClass(director_basic.MyClass): - def method(self, vptr): - self.cmethod = 7 - pass - - def vmethod(self, b): - b.x = b.x + 31 - return b + + def method(self, vptr): + self.cmethod = 7 + pass + + def vmethod(self, b): + b.x = b.x + 31 + return b b = director_basic.Bar(3) @@ -50,49 +52,42 @@ def vmethod(self, b): cc.method(b) if c.cmethod != 7: - raise RuntimeError + raise RuntimeError if bc.x != 34: - raise RuntimeError + raise RuntimeError if bd.x != 16: - raise RuntimeError - + raise RuntimeError class PyMulti(director_basic.Foo, director_basic.MyClass): - def __init__(self): - director_basic.Foo.__init__(self) - director_basic.MyClass.__init__(self) - pass - - def vmethod(self, b): - b.x = b.x + 31 - return b + def __init__(self): + director_basic.Foo.__init__(self) + director_basic.MyClass.__init__(self) + pass - - def ping(self): - return "PyFoo::ping()" + def vmethod(self, b): + b.x = b.x + 31 + return b + + def ping(self): + return "PyFoo::ping()" a = 0 -for i in range(0,100): +for i in range(0, 100): pymult = PyMulti() pymult.pong() - del pymult - + del pymult pymult = PyMulti() - - p1 = director_basic.Foo_get_self(pymult) p2 = director_basic.MyClass_get_self(pymult) p1.ping() p2.vmethod(bc) - - diff --git a/Examples/test-suite/python/director_classic_runme.py b/Examples/test-suite/python/director_classic_runme.py index 7e18a9a614f..a4d78f19c64 100644 --- a/Examples/test-suite/python/director_classic_runme.py +++ b/Examples/test-suite/python/director_classic_runme.py @@ -1,53 +1,76 @@ from director_classic import * + class TargetLangPerson(Person): + def __init__(self): Person.__init__(self) + def id(self): identifier = "TargetLangPerson" return identifier + class TargetLangChild(Child): + def __init__(self): Child.__init__(self) + def id(self): identifier = "TargetLangChild" return identifier + class TargetLangGrandChild(GrandChild): + def __init__(self): GrandChild.__init__(self) + def id(self): identifier = "TargetLangGrandChild" return identifier # Semis - don't override id() in target language + + class TargetLangSemiPerson(Person): + def __init__(self): Person.__init__(self) # No id() override + class TargetLangSemiChild(Child): + def __init__(self): Child.__init__(self) # No id() override + class TargetLangSemiGrandChild(GrandChild): + def __init__(self): GrandChild.__init__(self) # No id() override # Orphans - don't override id() in C++ + + class TargetLangOrphanPerson(OrphanPerson): + def __init__(self): OrphanPerson.__init__(self) + def id(self): identifier = "TargetLangOrphanPerson" return identifier + class TargetLangOrphanChild(OrphanChild): + def __init__(self): - Child.__init__(self) + OrphanChild.__init__(self) + def id(self): identifier = "TargetLangOrphanChild" return identifier @@ -55,88 +78,90 @@ def id(self): def check(person, expected): - debug = 0 - # Normal target language polymorphic call - ret = person.id() - if (debug): - print(ret) - if (ret != expected): - raise RuntimeError("Failed. Received: " + str(ret) + " Expected: " + expected) - - # Polymorphic call from C++ - caller = Caller() - caller.setCallback(person) - ret = caller.call() - if (debug): - print(ret) - if (ret != expected): - raise RuntimeError("Failed. Received: " + str(ret) + " Expected: " + expected) - - # Polymorphic call of object created in target language and passed to C++ and back again - baseclass = caller.baseClass() - ret = baseclass.id() - if (debug): - print(ret) - if (ret != expected): - raise RuntimeError("Failed. Received: " + str(ret)+ " Expected: " + expected) - - caller.resetCallback() - if (debug): - print("----------------------------------------") - - - -person = Person(); -check(person, "Person"); + debug = 0 + # Normal target language polymorphic call + ret = person.id() + if (debug): + print(ret) + if (ret != expected): + raise RuntimeError( + "Failed. Received: " + str(ret) + " Expected: " + expected) + + # Polymorphic call from C++ + caller = Caller() + caller.setCallback(person) + ret = caller.call() + if (debug): + print(ret) + if (ret != expected): + raise RuntimeError( + "Failed. Received: " + str(ret) + " Expected: " + expected) + + # Polymorphic call of object created in target language and passed to C++ + # and back again + baseclass = caller.baseClass() + ret = baseclass.id() + if (debug): + print(ret) + if (ret != expected): + raise RuntimeError( + "Failed. Received: " + str(ret) + " Expected: " + expected) + + caller.resetCallback() + if (debug): + print("----------------------------------------") + + +person = Person() +check(person, "Person") del person -person = Child(); -check(person, "Child"); +person = Child() +check(person, "Child") del person -person = GrandChild(); -check(person, "GrandChild"); +person = GrandChild() +check(person, "GrandChild") del person -person = TargetLangPerson(); -check(person, "TargetLangPerson"); +person = TargetLangPerson() +check(person, "TargetLangPerson") del person -person = TargetLangChild(); -check(person, "TargetLangChild"); +person = TargetLangChild() +check(person, "TargetLangChild") del person -person = TargetLangGrandChild(); -check(person, "TargetLangGrandChild"); +person = TargetLangGrandChild() +check(person, "TargetLangGrandChild") del person # Semis - don't override id() in target language -person = TargetLangSemiPerson(); -check(person, "Person"); +person = TargetLangSemiPerson() +check(person, "Person") del person -person = TargetLangSemiChild(); -check(person, "Child"); +person = TargetLangSemiChild() +check(person, "Child") del person -person = TargetLangSemiGrandChild(); -check(person, "GrandChild"); +person = TargetLangSemiGrandChild() +check(person, "GrandChild") del person # Orphans - don't override id() in C++ -person = OrphanPerson(); -check(person, "Person"); +person = OrphanPerson() +check(person, "Person") del person -person = OrphanChild(); -check(person, "Child"); +person = OrphanChild() +check(person, "Child") del person -person = TargetLangOrphanPerson(); -check(person, "TargetLangOrphanPerson"); +person = TargetLangOrphanPerson() +check(person, "TargetLangOrphanPerson") del person -person = TargetLangOrphanChild(); -check(person, "TargetLangOrphanChild"); +person = TargetLangOrphanChild() +check(person, "TargetLangOrphanChild") del person - diff --git a/Examples/test-suite/python/director_detect_runme.py b/Examples/test-suite/python/director_detect_runme.py index a90cfe8b464..3450519826a 100644 --- a/Examples/test-suite/python/director_detect_runme.py +++ b/Examples/test-suite/python/director_detect_runme.py @@ -1,24 +1,26 @@ -import director_detect +import director_detect + class MyBar(director_detect.Bar): - def __init__(self, val = 2): - director_detect.Bar.__init__(self) - self.val = val - def get_value(self): - self.val = self.val + 1 - return self.val - - def get_class(self): - self.val = self.val + 1 - return director_detect.A() + def __init__(self, val=2): + director_detect.Bar.__init__(self) + self.val = val + + def get_value(self): + self.val = self.val + 1 + return self.val + + def get_class(self): + self.val = self.val + 1 + return director_detect.A() - def just_do_it(self): - self.val = self.val + 1 + def just_do_it(self): + self.val = self.val + 1 - def clone(self): - return MyBar(self.val) - pass + def clone(self): + return MyBar(self.val) + pass b = MyBar() @@ -33,4 +35,4 @@ def clone(self): vc = c.get_value() if (v != 3) or (b.val != 5) or (vc != 6): - raise RuntimeError,"Bad virtual detection" + raise RuntimeError, "Bad virtual detection" diff --git a/Examples/test-suite/python/director_enum_runme.py b/Examples/test-suite/python/director_enum_runme.py index 5692c88b83d..faa2d82df12 100644 --- a/Examples/test-suite/python/director_enum_runme.py +++ b/Examples/test-suite/python/director_enum_runme.py @@ -1,12 +1,14 @@ import director_enum + class MyFoo(director_enum.Foo): - def say_hi(self, val): - return val + + def say_hi(self, val): + return val b = director_enum.Foo() a = MyFoo() if a.say_hi(director_enum.hello) != b.say_hello(director_enum.hi): - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/director_exception_runme.py b/Examples/test-suite/python/director_exception_runme.py index de3ef22a5f5..892c7e6538d 100644 --- a/Examples/test-suite/python/director_exception_runme.py +++ b/Examples/test-suite/python/director_exception_runme.py @@ -1,21 +1,29 @@ from director_exception import * + class MyException(Exception): - def __init__(self, a, b): - self.msg = a + b + + def __init__(self, a, b): + self.msg = a + b + class MyFoo(Foo): - def ping(self): - raise NotImplementedError, "MyFoo::ping() EXCEPTION" + + def ping(self): + raise NotImplementedError, "MyFoo::ping() EXCEPTION" + class MyFoo2(Foo): - def ping(self): - return True - pass # error: should return a string + + def ping(self): + return True + pass # error: should return a string + class MyFoo3(Foo): - def ping(self): - raise MyException("foo", "bar") + + def ping(self): + raise MyException("foo", "bar") # Check that the NotImplementedError raised by MyFoo.ping() is returned by # MyFoo.pong(). @@ -23,16 +31,16 @@ def ping(self): a = MyFoo() b = launder(a) try: - b.pong() + b.pong() except NotImplementedError, e: - if str(e) == "MyFoo::ping() EXCEPTION": - ok = 1 - else: - print "Unexpected error message: %s" % str(e) + if str(e) == "MyFoo::ping() EXCEPTION": + ok = 1 + else: + print "Unexpected error message: %s" % str(e) except: - pass + pass if not ok: - raise RuntimeError + raise RuntimeError # Check that the director returns the appropriate TypeError if the return type @@ -41,14 +49,14 @@ def ping(self): a = MyFoo2() b = launder(a) try: - b.pong() + b.pong() except TypeError, e: - if str(e) == "SWIG director type mismatch in output value of type 'std::string'": - ok = 1 - else: - print "Unexpected error message: %s" % str(e) + if str(e) == "SWIG director type mismatch in output value of type 'std::string'": + ok = 1 + else: + print "Unexpected error message: %s" % str(e) if not ok: - raise RuntimeError + raise RuntimeError # Check that the director can return an exception which requires two arguments @@ -57,24 +65,24 @@ def ping(self): a = MyFoo3() b = launder(a) try: - b.pong() + b.pong() except MyException, e: - if e.msg == 'foobar': - ok = 1 - else: - print "Unexpected error message: %s" % str(e) + if e.msg == 'foobar': + ok = 1 + else: + print "Unexpected error message: %s" % str(e) if not ok: - raise RuntimeError + raise RuntimeError # This is expected to fail with -builtin option # Throwing builtin classes as exceptions not supported if not is_python_builtin(): - try: - raise Exception2() - except Exception2: - pass - - try: - raise Exception1() - except Exception1: - pass + try: + raise Exception2() + except Exception2: + pass + + try: + raise Exception1() + except Exception1: + pass diff --git a/Examples/test-suite/python/director_extend_runme.py b/Examples/test-suite/python/director_extend_runme.py index 1ab58676ad4..a5aad824518 100644 --- a/Examples/test-suite/python/director_extend_runme.py +++ b/Examples/test-suite/python/director_extend_runme.py @@ -1,20 +1,22 @@ # Test case from bug #1506850 #"When threading is enabled, the interpreter will infinitely wait on a mutex the second -#time this type of extended method is called. Attached is an example -#program that waits on the mutex to be unlocked." +# time this type of extended method is called. Attached is an example +# program that waits on the mutex to be unlocked." from director_extend import * + class MyObject(SpObject): + def __init__(self): SpObject.__init__(self) return def getFoo(self): return 123 - + m = MyObject() if m.dummy() != 666: - raise RuntimeError, "1st call" + raise RuntimeError, "1st call" if m.dummy() != 666: # Locked system - raise RuntimeError, "2nd call" + raise RuntimeError, "2nd call" diff --git a/Examples/test-suite/python/director_finalizer_runme.py b/Examples/test-suite/python/director_finalizer_runme.py index 4cd1f573e2b..9c9eed6935b 100644 --- a/Examples/test-suite/python/director_finalizer_runme.py +++ b/Examples/test-suite/python/director_finalizer_runme.py @@ -1,10 +1,14 @@ from director_finalizer import * + class MyFoo(Foo): - def __del__(self): - self.orStatus(2) - try: Foo.__del__(self) - except: pass + + def __del__(self): + self.orStatus(2) + try: + Foo.__del__(self) + except: + pass resetStatus() @@ -13,7 +17,7 @@ def __del__(self): del a if getStatus() != 3: - raise RuntimeError + raise RuntimeError resetStatus() @@ -21,12 +25,12 @@ def __del__(self): launder(a) if getStatus() != 0: - raise RuntimeError + raise RuntimeError del a if getStatus() != 3: - raise RuntimeError + raise RuntimeError resetStatus() @@ -34,15 +38,14 @@ def __del__(self): deleteFoo(a) if getStatus() != 3: - raise RuntimeError - + raise RuntimeError + resetStatus() a = MyFoo().__disown__() deleteFoo(launder(a)) if getStatus() != 3: - raise RuntimeError - -resetStatus() + raise RuntimeError +resetStatus() diff --git a/Examples/test-suite/python/director_frob_runme.py b/Examples/test-suite/python/director_frob_runme.py index c2dd734cf4a..0ef4ad9009e 100644 --- a/Examples/test-suite/python/director_frob_runme.py +++ b/Examples/test-suite/python/director_frob_runme.py @@ -1,7 +1,7 @@ from director_frob import * -foo = Bravo(); -s = foo.abs_method(); +foo = Bravo() +s = foo.abs_method() if s != "Bravo::abs_method()": - raise RuntimeError, s + raise RuntimeError, s diff --git a/Examples/test-suite/python/director_keywords_runme.py b/Examples/test-suite/python/director_keywords_runme.py index 03a50206a2b..495d9375ee4 100644 --- a/Examples/test-suite/python/director_keywords_runme.py +++ b/Examples/test-suite/python/director_keywords_runme.py @@ -2,4 +2,3 @@ f = Foo() f.check_self(20) - diff --git a/Examples/test-suite/python/director_nested_runme.py b/Examples/test-suite/python/director_nested_runme.py index cff82f55ba2..f3d973630fd 100644 --- a/Examples/test-suite/python/director_nested_runme.py +++ b/Examples/test-suite/python/director_nested_runme.py @@ -2,62 +2,63 @@ class A(FooBar_int): - def do_step(self): - return "A::do_step;" - - def get_value(self): - return "A::get_value" - pass + def do_step(self): + return "A::do_step;" + + def get_value(self): + return "A::get_value" + + pass a = A() if a.step() != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;": - raise RuntimeError,"Bad A virtual resolution" + raise RuntimeError, "Bad A virtual resolution" class B(FooBar_int): - def do_advance(self): - return "B::do_advance;" + self.do_step() - def do_step(self): - return "B::do_step;" - - def get_value(self): - return 1 + def do_advance(self): + return "B::do_advance;" + self.do_step() + + def do_step(self): + return "B::do_step;" + + def get_value(self): + return 1 - pass + pass b = B() if b.step() != "Bar::step;Foo::advance;B::do_advance;B::do_step;": - raise RuntimeError,"Bad B virtual resolution" - + raise RuntimeError, "Bad B virtual resolution" class C(FooBar_int): - def do_advance(self): - return "C::do_advance;" + FooBar_int.do_advance(self) - def do_step(self): - return "C::do_step;" - - def get_value(self): - return 2 + def do_advance(self): + return "C::do_advance;" + FooBar_int.do_advance(self) + + def do_step(self): + return "C::do_step;" + + def get_value(self): + return 2 - def get_name(self): - return FooBar_int.get_name(self) + " hello" + def get_name(self): + return FooBar_int.get_name(self) + " hello" - - pass + pass cc = C() c = FooBar_int_get_self(cc) c.advance() if c.get_name() != "FooBar::get_name hello": - raise RuntimeError + raise RuntimeError if c.name() != "FooBar::get_name hello": - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/director_profile_runme.py b/Examples/test-suite/python/director_profile_runme.py index 2f67481f584..035007c6102 100644 --- a/Examples/test-suite/python/director_profile_runme.py +++ b/Examples/test-suite/python/director_profile_runme.py @@ -1,9 +1,10 @@ import director_profile + class MyB(director_profile.B): - def vfi(self, a): - return a+3 + def vfi(self, a): + return a + 3 a = director_profile.A() @@ -15,27 +16,26 @@ def vfi(self, a): i = 50000 a = 1 while i: - a = fi(a) #1 - a = fi(a) #2 - a = fi(a) #3 - a = fi(a) #4 - a = fi(a) #5 - a = fi(a) #6 - a = fi(a) #7 - a = fi(a) #8 - a = fi(a) #9 - a = fi(a) #10 - a = fi(a) #1 - a = fi(a) #2 - a = fi(a) #3 - a = fi(a) #4 - a = fi(a) #5 - a = fi(a) #6 - a = fi(a) #7 - a = fi(a) #8 - a = fi(a) #9 - a = fi(a) #20 - i -= 1 + a = fi(a) # 1 + a = fi(a) # 2 + a = fi(a) # 3 + a = fi(a) # 4 + a = fi(a) # 5 + a = fi(a) # 6 + a = fi(a) # 7 + a = fi(a) # 8 + a = fi(a) # 9 + a = fi(a) # 10 + a = fi(a) # 1 + a = fi(a) # 2 + a = fi(a) # 3 + a = fi(a) # 4 + a = fi(a) # 5 + a = fi(a) # 6 + a = fi(a) # 7 + a = fi(a) # 8 + a = fi(a) # 9 + a = fi(a) # 20 + i -= 1 print a - diff --git a/Examples/test-suite/python/director_property_runme.py b/Examples/test-suite/python/director_property_runme.py index 303e53b6779..5d713c27f73 100644 --- a/Examples/test-suite/python/director_property_runme.py +++ b/Examples/test-suite/python/director_property_runme.py @@ -1,18 +1,19 @@ import director_property + class PyFoo(director_property.Foo): - a = property(director_property.Foo.getA, director_property.Foo.setA) + a = property(director_property.Foo.getA, director_property.Foo.setA) - def ping(self): - return "PyFoo::ping()" + def ping(self): + return "PyFoo::ping()" foo = PyFoo() foo.setA("BLABLA") if foo.getA() != "BLABLA": - raise RuntimeError + raise RuntimeError foo.a = "BIBI" if foo.a != "BIBI": - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/director_protected_runme.py b/Examples/test-suite/python/director_protected_runme.py index fd3c868a1f5..c3118a7c03b 100644 --- a/Examples/test-suite/python/director_protected_runme.py +++ b/Examples/test-suite/python/director_protected_runme.py @@ -1,129 +1,132 @@ from director_protected import * - class FooBar(Bar): - def ping(self): - return "FooBar::ping();" + + def ping(self): + return "FooBar::ping();" + class FooBar2(Bar): - def ping(self): - return "FooBar2::ping();" - def pang(self): - return "FooBar2::pang();" + + def ping(self): + return "FooBar2::ping();" + + def pang(self): + return "FooBar2::pang();" + class FooBar3(Bar): - def cheer(self): - return "FooBar3::cheer();" + def cheer(self): + return "FooBar3::cheer();" -b = Bar() -f = b.create() + +b = Bar() +f = b.create() fb = FooBar() fb2 = FooBar2() fb3 = FooBar3() try: - s = fb.used() - if s != "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();": - raise RuntimeError - pass + s = fb.used() + if s != "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();": + raise RuntimeError + pass except: - raise RuntimeError, "bad FooBar::used" + raise RuntimeError, "bad FooBar::used" try: - s = fb2.used() - if s != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();": - raise RuntimeError - pass + s = fb2.used() + if s != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();": + raise RuntimeError + pass except: - raise RuntimeError, "bad FooBar2::used" + raise RuntimeError, "bad FooBar2::used" try: - s = b.pong() - if s != "Bar::pong();Foo::pong();Bar::ping();": - raise RuntimeError - pass + s = b.pong() + if s != "Bar::pong();Foo::pong();Bar::ping();": + raise RuntimeError + pass except: - raise RuntimeError, "bad Bar::pong" + raise RuntimeError, "bad Bar::pong" try: - s = f.pong() - if s != "Bar::pong();Foo::pong();Bar::ping();": - raise RuntimeError - pass + s = f.pong() + if s != "Bar::pong();Foo::pong();Bar::ping();": + raise RuntimeError + pass except: - raise RuntimeError," bad Foo::pong" - + raise RuntimeError, " bad Foo::pong" + try: - s = fb.pong() - if s != "Bar::pong();Foo::pong();FooBar::ping();": - raise RuntimeError - pass + s = fb.pong() + if s != "Bar::pong();Foo::pong();FooBar::ping();": + raise RuntimeError + pass except: - raise RuntimeError," bad FooBar::pong" + raise RuntimeError, " bad FooBar::pong" -protected=1 +protected = 1 try: - b.ping() - protected=0 + b.ping() + protected = 0 except: - pass + pass if not protected: - raise RuntimeError,"Foo::ping is protected" - -protected=1 + raise RuntimeError, "Foo::ping is protected" + +protected = 1 try: - f.ping() - protected=0 + f.ping() + protected = 0 except: - pass + pass if not protected: - raise RuntimeError,"Foo::ping is protected" + raise RuntimeError, "Foo::ping is protected" -protected=1 +protected = 1 try: - f.pang() - protected=0 + f.pang() + protected = 0 except: - pass + pass if not protected: - raise RuntimeError,"FooBar::pang is protected" + raise RuntimeError, "FooBar::pang is protected" -protected=1 +protected = 1 try: - b.cheer() - protected=0 + b.cheer() + protected = 0 except: - pass + pass if not protected: - raise RuntimeError,"Bar::cheer is protected" + raise RuntimeError, "Bar::cheer is protected" -protected=1 +protected = 1 try: - f.cheer() - protected=0 + f.cheer() + protected = 0 except: - pass + pass if not protected: - raise RuntimeError,"Foo::cheer is protected" + raise RuntimeError, "Foo::cheer is protected" if fb3.cheer() != "FooBar3::cheer();": - raise RuntimeError, "bad fb3::cheer" + raise RuntimeError, "bad fb3::cheer" if fb2.callping() != "FooBar2::ping();": - raise RuntimeError, "bad fb2.callping" + raise RuntimeError, "bad fb2.callping" if fb2.callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();": - raise RuntimeError, "bad fb2.callcheer" + raise RuntimeError, "bad fb2.callcheer" if fb3.callping() != "Bar::ping();": - raise RuntimeError, "bad fb3.callping" + raise RuntimeError, "bad fb3.callping" if fb3.callcheer() != "FooBar3::cheer();": - raise RuntimeError, "bad fb3.callcheer" - - + raise RuntimeError, "bad fb3.callcheer" diff --git a/Examples/test-suite/python/director_smartptr_runme.py b/Examples/test-suite/python/director_smartptr_runme.py new file mode 100644 index 00000000000..c8bab9d7a7a --- /dev/null +++ b/Examples/test-suite/python/director_smartptr_runme.py @@ -0,0 +1,37 @@ +from director_smartptr import * + + +class director_smartptr_MyBarFoo(Foo): + + def ping(self): + return "director_smartptr_MyBarFoo.ping()" + + def pong(self): + return "director_smartptr_MyBarFoo.pong();" + self.ping() + + def upcall(self, fooBarPtr): + return "override;" + fooBarPtr.FooBarDo() + + def makeFoo(self): + return Foo() + +def check(got, expected): + if (got != expected): + raise RuntimeError, "Failed, got: " + got + " expected: " + expected + +fooBar = FooBar() + +myBarFoo = director_smartptr_MyBarFoo() +check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()") +check(Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()") +check(Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()") + +myFoo = myBarFoo.makeFoo() +check(myFoo.pong(), "Foo::pong();Foo::ping()") +check(Foo.callPong(myFoo), "Foo::pong();Foo::ping()") +check(myFoo.upcall(FooBar()), "Bar::Foo2::Foo2Bar()") + +myFoo2 = Foo().makeFoo() +check(myFoo2.pong(), "Foo::pong();Foo::ping()") +check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()") +check(myFoo2.upcall(FooBar()), "Bar::Foo2::Foo2Bar()") diff --git a/Examples/test-suite/python/director_stl_runme.py b/Examples/test-suite/python/director_stl_runme.py index aaea0362aa6..0c3e5af976f 100644 --- a/Examples/test-suite/python/director_stl_runme.py +++ b/Examples/test-suite/python/director_stl_runme.py @@ -1,20 +1,22 @@ import director_stl + class MyFoo(director_stl.Foo): - def ping(self, s): - return "MyFoo::ping():" + s - def pident(self, arg): - return arg - - def vident(self,v): - return v + def ping(self, s): + return "MyFoo::ping():" + s + + def pident(self, arg): + return arg + + def vident(self, v): + return v - def vidents(self,v): - return v + def vidents(self, v): + return v - def vsecond(self,v1,v2): - return v2 + def vsecond(self, v1, v2): + return v2 a = MyFoo() @@ -22,18 +24,18 @@ def vsecond(self,v1,v2): a.tping("hello") a.tpong("hello") -p = (1,2) +p = (1, 2) a.pident(p) -v = (3,4) +v = (3, 4) a.vident(v) a.tpident(p) a.tvident(v) -v1 = (3,4) -v2 = (5,6) -a.tvsecond(v1,v2) +v1 = (3, 4) +v2 = (5, 6) +a.tvsecond(v1, v2) -vs=("hi", "hello") +vs = ("hi", "hello") vs a.tvidents(vs) diff --git a/Examples/test-suite/python/director_string_runme.py b/Examples/test-suite/python/director_string_runme.py index f2db416caac..dcd47d647e2 100644 --- a/Examples/test-suite/python/director_string_runme.py +++ b/Examples/test-suite/python/director_string_runme.py @@ -1,29 +1,29 @@ from director_string import * + class B(A): - def __init__(self,string): - A.__init__(self,string) - def get_first(self): - return A.get_first(self) + " world!" + def __init__(self, string): + A.__init__(self, string) + + def get_first(self): + return A.get_first(self) + " world!" - def process_text(self, string): - A.process_text(self, string) - self.smem = "hello" - + def process_text(self, string): + A.process_text(self, string) + self.smem = "hello" b = B("hello") b.get(0) if b.get_first() != "hello world!": - print b.get_first() - raise RuntimeError + print b.get_first() + raise RuntimeError b.call_process_func() if b.smem != "hello": - print smem - raise RuntimeError - + print smem + raise RuntimeError diff --git a/Examples/test-suite/python/director_thread_runme.py b/Examples/test-suite/python/director_thread_runme.py index 15a12ab800f..4fcf3bfd104 100644 --- a/Examples/test-suite/python/director_thread_runme.py +++ b/Examples/test-suite/python/director_thread_runme.py @@ -1,6 +1,8 @@ from director_thread import Foo -class Derived(Foo) : + +class Derived(Foo): + def __init__(self): Foo.__init__(self) diff --git a/Examples/test-suite/python/director_unroll_runme.py b/Examples/test-suite/python/director_unroll_runme.py index e2bc9377912..60bc0558576 100644 --- a/Examples/test-suite/python/director_unroll_runme.py +++ b/Examples/test-suite/python/director_unroll_runme.py @@ -1,8 +1,10 @@ import director_unroll + class MyFoo(director_unroll.Foo): - def ping(self): - return "MyFoo::ping()" + + def ping(self): + return "MyFoo::ping()" a = MyFoo() @@ -14,6 +16,5 @@ def ping(self): if not (a.this == c.this): - print a, c - raise RuntimeError - + print a, c + raise RuntimeError diff --git a/Examples/test-suite/python/director_wstring_runme.py b/Examples/test-suite/python/director_wstring_runme.py index f3f29de5e8e..242b2758277 100644 --- a/Examples/test-suite/python/director_wstring_runme.py +++ b/Examples/test-suite/python/director_wstring_runme.py @@ -1,28 +1,28 @@ from director_wstring import * + class B(A): - def __init__(self,string): - A.__init__(self,string) - def get_first(self): - return A.get_first(self) + u" world!" + def __init__(self, string): + A.__init__(self, string) + + def get_first(self): + return A.get_first(self) + u" world!" - def process_text(self, string): - self.smem = u"hello" - + def process_text(self, string): + self.smem = u"hello" b = B(u"hello") b.get(0) if b.get_first() != u"hello world!": - print b.get_first() - raise RuntimeError + print b.get_first() + raise RuntimeError b.call_process_func() if b.smem != u"hello": - print smem - raise RuntimeError - + print smem + raise RuntimeError diff --git a/Examples/test-suite/python/disown_runme.py b/Examples/test-suite/python/disown_runme.py index b8cae077a9e..1f355f040d1 100644 --- a/Examples/test-suite/python/disown_runme.py +++ b/Examples/test-suite/python/disown_runme.py @@ -14,7 +14,7 @@ a.thisown = tmp if (a.thisown != tmp): - raise RuntimeError + raise RuntimeError b = B() diff --git a/Examples/test-suite/python/dynamic_cast_runme.py b/Examples/test-suite/python/dynamic_cast_runme.py index 68b06db503f..59e86d34cb8 100644 --- a/Examples/test-suite/python/dynamic_cast_runme.py +++ b/Examples/test-suite/python/dynamic_cast_runme.py @@ -9,4 +9,3 @@ a = dynamic_cast.do_test(y) if a != "Bar::test": print "Failed!!" - diff --git a/Examples/test-suite/python/empty_c_runme.py b/Examples/test-suite/python/empty_c_runme.py new file mode 100644 index 00000000000..b7cfbd67361 --- /dev/null +++ b/Examples/test-suite/python/empty_c_runme.py @@ -0,0 +1 @@ +import empty_c diff --git a/Examples/test-suite/python/enum_forward_runme.py b/Examples/test-suite/python/enum_forward_runme.py index 9af476f9781..130ba715b84 100644 --- a/Examples/test-suite/python/enum_forward_runme.py +++ b/Examples/test-suite/python/enum_forward_runme.py @@ -1,10 +1,10 @@ import enum_forward - -f1 = enum_forward.get_enum1(); -f1 = enum_forward.test_function1(f1); -f2 = enum_forward.get_enum2(); -f2 = enum_forward.test_function2(f2); +f1 = enum_forward.get_enum1() +f1 = enum_forward.test_function1(f1) -f3 = enum_forward.get_enum3(); -f3 = enum_forward.test_function3(f3); +f2 = enum_forward.get_enum2() +f2 = enum_forward.test_function2(f2) + +f3 = enum_forward.get_enum3() +f3 = enum_forward.test_function3(f3) diff --git a/Examples/test-suite/python/enum_template_runme.py b/Examples/test-suite/python/enum_template_runme.py index 6ad0a806022..64d06ce87f4 100644 --- a/Examples/test-suite/python/enum_template_runme.py +++ b/Examples/test-suite/python/enum_template_runme.py @@ -1,7 +1,6 @@ import enum_template if enum_template.MakeETest() != 1: - raise RuntimeError + raise RuntimeError if enum_template.TakeETest(0) != None: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/enums_runme.py b/Examples/test-suite/python/enums_runme.py index 8d491baf460..4870d7c5262 100644 --- a/Examples/test-suite/python/enums_runme.py +++ b/Examples/test-suite/python/enums_runme.py @@ -6,14 +6,13 @@ _enums.bar1(1) if _enums.cvar.enumInstance != 2: - raise RuntimeError + raise RuntimeError if _enums.cvar.Slap != 10: - raise RuntimeError + raise RuntimeError if _enums.cvar.Mine != 11: - raise RuntimeError + raise RuntimeError if _enums.cvar.Thigh != 12: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/exception_classname_runme.py b/Examples/test-suite/python/exception_classname_runme.py new file mode 100644 index 00000000000..c78f4e68bac --- /dev/null +++ b/Examples/test-suite/python/exception_classname_runme.py @@ -0,0 +1,4 @@ +import exception_classname + +a = exception_classname.Exception() +assert a.testfunc() == 42 diff --git a/Examples/test-suite/python/exception_order_runme.py b/Examples/test-suite/python/exception_order_runme.py index 8f095eb98ca..c53521e3e28 100644 --- a/Examples/test-suite/python/exception_order_runme.py +++ b/Examples/test-suite/python/exception_order_runme.py @@ -3,43 +3,42 @@ # This test is expected to fail with -builtin option. # Throwing builtin classes as exceptions not supported if is_python_builtin(): - exit(0) + exit(0) a = A() try: - a.foo() -except E1,e: - pass + a.foo() +except E1, e: + pass except: - raise RuntimeError, "bad exception order" + raise RuntimeError, "bad exception order" try: - a.bar() -except E2,e: - pass + a.bar() +except E2, e: + pass except: - raise RuntimeError, "bad exception order" + raise RuntimeError, "bad exception order" try: - a.foobar() -except RuntimeError,e: - if e.args[0] != "postcatch unknown": - print "bad exception order", - raise RuntimeError, e.args - + a.foobar() +except RuntimeError, e: + if e.args[0] != "postcatch unknown": + print "bad exception order", + raise RuntimeError, e.args try: - a.barfoo(1) -except E1,e: - pass + a.barfoo(1) +except E1, e: + pass except: - raise RuntimeError, "bad exception order" + raise RuntimeError, "bad exception order" try: - a.barfoo(2) -except E2,e: - pass + a.barfoo(2) +except E2, e: + pass except: - raise RuntimeError, "bad exception order" + raise RuntimeError, "bad exception order" diff --git a/Examples/test-suite/python/extend_placement_runme.py b/Examples/test-suite/python/extend_placement_runme.py index 97b7b1654fc..2c0be2c3192 100644 --- a/Examples/test-suite/python/extend_placement_runme.py +++ b/Examples/test-suite/python/extend_placement_runme.py @@ -2,12 +2,12 @@ foo = extend_placement.Foo() foo = extend_placement.Foo(1) -foo = extend_placement.Foo(1,1) +foo = extend_placement.Foo(1, 1) foo.spam() foo.spam("hello") foo.spam(1) -foo.spam(1,1) -foo.spam(1,1,1) +foo.spam(1, 1) +foo.spam(1, 1, 1) foo.spam(extend_placement.Foo()) foo.spam(extend_placement.Foo(), 1.0) @@ -17,20 +17,20 @@ bar.spam() bar.spam("hello") bar.spam(1) -bar.spam(1,1) -bar.spam(1,1,1) +bar.spam(1, 1) +bar.spam(1, 1, 1) bar.spam(extend_placement.Bar()) bar.spam(extend_placement.Bar(), 1.0) foo = extend_placement.FooTi() foo = extend_placement.FooTi(1) -foo = extend_placement.FooTi(1,1) +foo = extend_placement.FooTi(1, 1) foo.spam() foo.spam("hello") foo.spam(1) -foo.spam(1,1) -foo.spam(1,1,1) +foo.spam(1, 1) +foo.spam(1, 1, 1) foo.spam(extend_placement.Foo()) foo.spam(extend_placement.Foo(), 1.0) @@ -40,7 +40,7 @@ bar.spam() bar.spam("hello") bar.spam(1) -bar.spam(1,1) -bar.spam(1,1,1) +bar.spam(1, 1) +bar.spam(1, 1, 1) bar.spam(extend_placement.Bar()) bar.spam(extend_placement.Bar(), 1.0) diff --git a/Examples/test-suite/python/extern_c_runme.py b/Examples/test-suite/python/extern_c_runme.py index 1a6d2aa120f..91a218a871c 100644 --- a/Examples/test-suite/python/extern_c_runme.py +++ b/Examples/test-suite/python/extern_c_runme.py @@ -1,4 +1,3 @@ import extern_c extern_c.RealFunction(2) - diff --git a/Examples/test-suite/python/file_test_runme.py b/Examples/test-suite/python/file_test_runme.py index 9b94fa3b3c9..33ada500be4 100644 --- a/Examples/test-suite/python/file_test_runme.py +++ b/Examples/test-suite/python/file_test_runme.py @@ -2,7 +2,7 @@ import file_test if sys.version_info[0:2] < (3, 0): - file_test.nfile(sys.stdout) + file_test.nfile(sys.stdout) cstdout = file_test.GetStdOut() diff --git a/Examples/test-suite/python/friends_runme.py b/Examples/test-suite/python/friends_runme.py index 04897655a49..2d377fdd173 100644 --- a/Examples/test-suite/python/friends_runme.py +++ b/Examples/test-suite/python/friends_runme.py @@ -2,27 +2,36 @@ a = friends.A(2) -if friends.get_val1(a) != 2: raise RuntimeError -if friends.get_val2(a) != 4: raise RuntimeError -if friends.get_val3(a) != 6: raise RuntimeError +if friends.get_val1(a) != 2: + raise RuntimeError +if friends.get_val2(a) != 4: + raise RuntimeError +if friends.get_val3(a) != 6: + raise RuntimeError # nice overload working fine -if friends.get_val1(1,2,3) != 1: raise RuntimeError +if friends.get_val1(1, 2, 3) != 1: + raise RuntimeError b = friends.B(3) # David's case -if friends.mix(a,b) != 5: raise RuntimeError +if friends.mix(a, b) != 5: + raise RuntimeError di = friends.D_d(2) dd = friends.D_d(3.3) # incredible template overloading working just fine -if friends.get_val1(di) != 2: raise RuntimeError -if friends.get_val1(dd) != 3.3: raise RuntimeError +if friends.get_val1(di) != 2: + raise RuntimeError +if friends.get_val1(dd) != 3.3: + raise RuntimeError friends.set(di, 4) friends.set(dd, 1.3) -if friends.get_val1(di) != 4: raise RuntimeError -if friends.get_val1(dd) != 1.3: raise RuntimeError +if friends.get_val1(di) != 4: + raise RuntimeError +if friends.get_val1(dd) != 1.3: + raise RuntimeError diff --git a/Examples/test-suite/python/funcptr_cpp_runme.py b/Examples/test-suite/python/funcptr_cpp_runme.py index ae8616e9407..08e85ad7b11 100644 --- a/Examples/test-suite/python/funcptr_cpp_runme.py +++ b/Examples/test-suite/python/funcptr_cpp_runme.py @@ -1,9 +1,8 @@ from funcptr_cpp import * if call1(ADD_BY_VALUE, 10, 11) != 21: - raise RuntimeError + raise RuntimeError if call2(ADD_BY_POINTER, 12, 13) != 25: - raise RuntimeError + raise RuntimeError if call3(ADD_BY_REFERENCE, 14, 15) != 29: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/fvirtual_runme.py b/Examples/test-suite/python/fvirtual_runme.py index ada3313de85..99f5dc6b0d2 100644 --- a/Examples/test-suite/python/fvirtual_runme.py +++ b/Examples/test-suite/python/fvirtual_runme.py @@ -2,8 +2,7 @@ sw = NodeSwitch() n = Node() -i = sw.addChild(n); +i = sw.addChild(n) if i != 2: - raise RuntimeError, "addChild" - + raise RuntimeError, "addChild" diff --git a/Examples/test-suite/python/global_functions_runme.py b/Examples/test-suite/python/global_functions_runme.py index 17b70b7259c..f411261b6db 100644 --- a/Examples/test-suite/python/global_functions_runme.py +++ b/Examples/test-suite/python/global_functions_runme.py @@ -1,52 +1,52 @@ from global_functions import * + def check(a, b): - if a != b: - raise RuntimeError("Failed: " + str(a) + " != " + str(b)) + if a != b: + raise RuntimeError("Failed: " + str(a) + " != " + str(b)) global_void() check(global_one(1), 1) check(global_two(2, 2), 4) fail = True try: - global_void(1) + global_void(1) except TypeError, e: - fail = False + fail = False if fail: - raise RuntimeError("argument count check failed") + raise RuntimeError("argument count check failed") fail = True try: - global_one() + global_one() except TypeError, e: - fail = False + fail = False if fail: - raise RuntimeError("argument count check failed") + raise RuntimeError("argument count check failed") fail = True try: - global_one(2, 2) + global_one(2, 2) except TypeError, e: - fail = False + fail = False if fail: - raise RuntimeError("argument count check failed") + raise RuntimeError("argument count check failed") fail = True try: - global_two(1) + global_two(1) except TypeError, e: - fail = False + fail = False if fail: - raise RuntimeError("argument count check failed") + raise RuntimeError("argument count check failed") fail = True try: - global_two(3, 3, 3) + global_two(3, 3, 3) except TypeError, e: - fail = False + fail = False if fail: - raise RuntimeError("argument count check failed") - + raise RuntimeError("argument count check failed") diff --git a/Examples/test-suite/python/global_namespace_runme.py b/Examples/test-suite/python/global_namespace_runme.py index b64e75ca183..ac12fe2dc12 100644 --- a/Examples/test-suite/python/global_namespace_runme.py +++ b/Examples/test-suite/python/global_namespace_runme.py @@ -1,5 +1,9 @@ from global_namespace import * + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + k1 = Klass1() k2 = Klass2() k3 = Klass3() @@ -8,8 +12,12 @@ k6 = Klass6() k7 = Klass7() -KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) -KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) +if is_new_style_class(KlassMethods): + KlassMethods_static = KlassMethods +else: + KlassMethods_static = KlassMethods() +KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7) k1 = getKlass1A() k2 = getKlass2A() @@ -19,8 +27,8 @@ k6 = getKlass6A() k7 = getKlass7A() -KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) -KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7) k1 = getKlass1B() k2 = getKlass2B() @@ -30,11 +38,21 @@ k6 = getKlass6B() k7 = getKlass7B() -KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) -KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) - -XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) -XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) - -TheEnumMethods.methodA(theenum1, theenum2, theenum3) -TheEnumMethods.methodA(theenum1, theenum2, theenum3) +KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7) + +if is_new_style_class(XYZMethods): + XYZMethods_static = XYZMethods +else: + XYZMethods_static = XYZMethods() +XYZMethods_static.methodA( + XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) +XYZMethods_static.methodB( + XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) + +if is_new_style_class(TheEnumMethods): + TheEnumMethods_static = TheEnumMethods +else: + TheEnumMethods_static = TheEnumMethods() +TheEnumMethods_static.methodA(theenum1, theenum2, theenum3) +TheEnumMethods_static.methodA(theenum1, theenum2, theenum3) diff --git a/Examples/test-suite/python/global_ns_arg_runme.py b/Examples/test-suite/python/global_ns_arg_runme.py index cf1915648a2..f7fbc7a9eba 100644 --- a/Examples/test-suite/python/global_ns_arg_runme.py +++ b/Examples/test-suite/python/global_ns_arg_runme.py @@ -2,4 +2,3 @@ a = foo(1) b = bar_fn() - diff --git a/Examples/test-suite/python/global_vars_runme.py b/Examples/test-suite/python/global_vars_runme.py index 5d520b5cec3..3ef0b494f21 100644 --- a/Examples/test-suite/python/global_vars_runme.py +++ b/Examples/test-suite/python/global_vars_runme.py @@ -3,33 +3,32 @@ global_vars.init() b = global_vars.cvar.b if b != "string b": - raise RuntimeError("Unexpected string: " + b) + raise RuntimeError("Unexpected string: " + b) global_vars.cvar.b = "a string value" b = global_vars.cvar.b if b != "a string value": - raise RuntimeError("Unexpected string: " + b) + raise RuntimeError("Unexpected string: " + b) x = global_vars.cvar.x if x != 1234: - raise RuntimeError("Unexpected x: " + str(x)) + raise RuntimeError("Unexpected x: " + str(x)) global_vars.cvar.x = 9876 x = global_vars.cvar.x if x != 9876: - raise RuntimeError("Unexpected string: " + str(x)) + raise RuntimeError("Unexpected string: " + str(x)) fail = True try: - global_vars.cvar.notexist = "something" + global_vars.cvar.notexist = "something" except AttributeError, e: - fail = False + fail = False if fail: - raise RuntimeError("AttributeError should have been thrown") + raise RuntimeError("AttributeError should have been thrown") fail = True try: - g = global_vars.cvar.notexist + g = global_vars.cvar.notexist except AttributeError, e: - fail = False + fail = False if fail: - raise RuntimeError("AttributeError should have been thrown") - + raise RuntimeError("AttributeError should have been thrown") diff --git a/Examples/test-suite/python/iadd_runme.py b/Examples/test-suite/python/iadd_runme.py index fbeb0ec3ec4..ceaa38860c5 100644 --- a/Examples/test-suite/python/iadd_runme.py +++ b/Examples/test-suite/python/iadd_runme.py @@ -3,7 +3,7 @@ f = iadd.Foo() f.AsA.x = 3 -f.AsA += f.AsA +f.AsA += f.AsA if f.AsA.x != 6: raise RuntimeError diff --git a/Examples/test-suite/python/implicittest_runme.py b/Examples/test-suite/python/implicittest_runme.py index a9957bc7e14..4646d08c005 100644 --- a/Examples/test-suite/python/implicittest_runme.py +++ b/Examples/test-suite/python/implicittest_runme.py @@ -1,9 +1,14 @@ from implicittest import * + def check(a, b): if a != b: raise RuntimeError(str(a) + " does not equal " + str(b)) + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + #### Class #### # No implicit conversion @@ -17,7 +22,8 @@ def check(a, b): except ValueError: # ValueError: invalid null reference in method 'new_A', argument 1 of type 'B const &' # Arguably A(char *) should be chosen, but there is a bug to do with None passed to methods overloaded by value, - # references and pointers to different types, where pointers ought to be given a slightly higher precedence. + # references and pointers to different types, where pointers ought to be + # given a slightly higher precedence. pass check(1, get(1)) @@ -39,23 +45,31 @@ def check(a, b): check(3, A_int(B()).get()) check(4, A_int("hello").get()) -check(1, A_int.sget(1)) -check(2, A_int.sget(1.0)) -check(3, A_int.sget(B())) +if is_new_style_class(A_int): + A_int_static = A_int +else: + A_int_static = A_int(0) +check(1, A_int_static.sget(1)) +check(2, A_int_static.sget(1.0)) +check(3, A_int_static.sget(B())) # explicit constructor: try: - check(4, A_int.sget("hello")) + check(4, A_int_static.sget("hello")) raise RuntimeError except TypeError: pass #### Global variable assignment #### -cvar.foo = Foo(1); check(cvar.foo.ii, 1) -cvar.foo = 1; check(cvar.foo.ii, 1) -cvar.foo = 1.0; check(cvar.foo.ii, 2) -cvar.foo = Foo("hello"); check(cvar.foo.ii, 3) +cvar.foo = Foo(1) +check(cvar.foo.ii, 1) +cvar.foo = 1 +check(cvar.foo.ii, 1) +cvar.foo = 1.0 +check(cvar.foo.ii, 2) +cvar.foo = Foo("hello") +check(cvar.foo.ii, 3) # explicit constructor: try: @@ -67,10 +81,14 @@ def check(a, b): #### Member variable assignment #### # Note: also needs naturalvar -b = Bar(); check(b.f.ii, 0) -b.f = Foo("hello"); check(b.f.ii, 3) -b.f = 1; check(b.f.ii, 1) -b.f = 1.0; check(b.f.ii, 2) +b = Bar() +check(b.f.ii, 0) +b.f = Foo("hello") +check(b.f.ii, 3) +b.f = 1 +check(b.f.ii, 1) +b.f = 1.0 +check(b.f.ii, 2) # explicit constructor: try: @@ -122,4 +140,3 @@ def check(a, b): check(ccc.checkvalue, 10) check(ccc.xx(123), 11) check(ccc.yy(123, 123), 111) - diff --git a/Examples/test-suite/python/import_nomodule_runme.py b/Examples/test-suite/python/import_nomodule_runme.py index efcff9c481e..e43c233b493 100644 --- a/Examples/test-suite/python/import_nomodule_runme.py +++ b/Examples/test-suite/python/import_nomodule_runme.py @@ -3,11 +3,11 @@ # This test is expected to fail with -builtin option. # The base class is needed for the builtin class hierarchy if is_python_builtin(): - exit(0) + exit(0) f = create_Foo() -test1(f,42) +test1(f, 42) delete_Foo(f) b = Bar() -test1(b,37) +test1(b, 37) diff --git a/Examples/test-suite/python/import_stl_runme.py b/Examples/test-suite/python/import_stl_runme.py index 90c4114555b..69fe812b91d 100644 --- a/Examples/test-suite/python/import_stl_runme.py +++ b/Examples/test-suite/python/import_stl_runme.py @@ -1,7 +1,6 @@ import import_stl_b import import_stl_a -v_new = import_stl_b.process_vector([1,2,3]) -if v_new != (1,2,3,4): - raise RuntimeError, v_new - +v_new = import_stl_b.process_vector([1, 2, 3]) +if v_new != (1, 2, 3, 4): + raise RuntimeError, v_new diff --git a/Examples/test-suite/python/imports_runme.py b/Examples/test-suite/python/imports_runme.py index 50a3ab59f9c..3eec965a651 100644 --- a/Examples/test-suite/python/imports_runme.py +++ b/Examples/test-suite/python/imports_runme.py @@ -14,4 +14,4 @@ a2 = c.get_a_type(c) if a1.hello() != a2.hello(): - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/inctest_runme.py b/Examples/test-suite/python/inctest_runme.py index e10f4544c49..fa34929322a 100644 --- a/Examples/test-suite/python/inctest_runme.py +++ b/Examples/test-suite/python/inctest_runme.py @@ -2,31 +2,30 @@ error = 0 try: - a = inctest.A() + a = inctest.A() except: - print "didn't find A" - print "therefore, I didn't include 'testdir/subdir1/hello.i'" - error = 1 + print "didn't find A" + print "therefore, I didn't include 'testdir/subdir1/hello.i'" + error = 1 pass try: - b = inctest.B() + b = inctest.B() except: - print "didn't find B" - print "therefore, I didn't include 'testdir/subdir2/hello.i'" - error = 1 + print "didn't find B" + print "therefore, I didn't include 'testdir/subdir2/hello.i'" + error = 1 pass if error == 1: - raise RuntimeError + raise RuntimeError # Check the import in subdirectory worked if inctest.importtest1(5) != 15: - print "import test 1 failed" - raise RuntimeError + print "import test 1 failed" + raise RuntimeError if inctest.importtest2("black") != "white": - print "import test 2 failed" - raise RuntimeError - + print "import test 2 failed" + raise RuntimeError diff --git a/Examples/test-suite/python/inout_runme.py b/Examples/test-suite/python/inout_runme.py index fb290f62f85..bb198d774df 100644 --- a/Examples/test-suite/python/inout_runme.py +++ b/Examples/test-suite/python/inout_runme.py @@ -2,21 +2,20 @@ a = inout.AddOne1(1) if a != 2: - raise RuntimeError + raise RuntimeError -a = inout.AddOne3(1,1,1) -if a != [2,2,2]: - raise RuntimeError +a = inout.AddOne3(1, 1, 1) +if a != [2, 2, 2]: + raise RuntimeError -a = inout.AddOne1p((1,1)) -if a != (2,2): - raise RuntimeError +a = inout.AddOne1p((1, 1)) +if a != (2, 2): + raise RuntimeError -a = inout.AddOne2p((1,1),1) -if a != [(2,2),2]: - raise RuntimeError - -a = inout.AddOne3p(1,(1,1),1) -if a != [2,(2,2),2]: - raise RuntimeError +a = inout.AddOne2p((1, 1), 1) +if a != [(2, 2), 2]: + raise RuntimeError +a = inout.AddOne3p(1, (1, 1), 1) +if a != [2, (2, 2), 2]: + raise RuntimeError diff --git a/Examples/test-suite/python/inplaceadd_runme.py b/Examples/test-suite/python/inplaceadd_runme.py index b703c56c74a..7f292cbb552 100644 --- a/Examples/test-suite/python/inplaceadd_runme.py +++ b/Examples/test-suite/python/inplaceadd_runme.py @@ -3,18 +3,18 @@ a += 5 if a.val != 12: - print a.val - raise RuntimeError + print a.val + raise RuntimeError a -= 5 if a.val != 7: - raise RuntimeError + raise RuntimeError a *= 2 if a.val != 14: - raise RuntimeError + raise RuntimeError a += a if a.val != 28: - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/input_runme.py b/Examples/test-suite/python/input_runme.py index f5ef6dc8b7a..1a06e8b7b6e 100644 --- a/Examples/test-suite/python/input_runme.py +++ b/Examples/test-suite/python/input_runme.py @@ -2,19 +2,19 @@ f = Foo() if f.foo(2) != 4: - raise RuntimeError - -if f.foo(None)!= None: - raise RuntimeError + raise RuntimeError -if f.foo()!= None: - raise RuntimeError +if f.foo(None) != None: + raise RuntimeError + +if f.foo() != None: + raise RuntimeError if sfoo("Hello") != "Hello world": - raise RuntimeError + raise RuntimeError if sfoo(None) != None: - raise RuntimeError + raise RuntimeError if sfoo() != None: - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/keyword_rename_c_runme.py b/Examples/test-suite/python/keyword_rename_c_runme.py new file mode 100644 index 00000000000..c17aede4c3e --- /dev/null +++ b/Examples/test-suite/python/keyword_rename_c_runme.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +import keyword_rename_c +keyword_rename_c._in(1) +keyword_rename_c._except(1) diff --git a/Examples/test-suite/python/kwargs_feature_runme.py b/Examples/test-suite/python/kwargs_feature_runme.py index 37457c976cd..a2d4731abb3 100644 --- a/Examples/test-suite/python/kwargs_feature_runme.py +++ b/Examples/test-suite/python/kwargs_feature_runme.py @@ -1,81 +1,81 @@ from kwargs_feature import * + class MyFoo(Foo): - def __init__(self, a , b = 0): - Foo.__init__(self, a, b) - + def __init__(self, a, b=0): + Foo.__init__(self, a, b) + # Simple class f1 = MyFoo(2) -f = Foo(b=2,a=1) +f = Foo(b=2, a=1) -if f.foo(b=1,a=2) != 3: - raise RuntimeError +if f.foo(b=1, a=2) != 3: + raise RuntimeError if Foo_statfoo(b=2) != 3: - raise RuntimeError + raise RuntimeError if f.efoo(b=2) != 3: - raise RuntimeError + raise RuntimeError if Foo_sfoo(b=2) != 3: - raise RuntimeError + raise RuntimeError # Templated class -b = BarInt(b=2,a=1) +b = BarInt(b=2, a=1) -if b.bar(b=1,a=2) != 3: - raise RuntimeError +if b.bar(b=1, a=2) != 3: + raise RuntimeError if BarInt_statbar(b=2) != 3: - raise RuntimeError + raise RuntimeError if b.ebar(b=2) != 3: - raise RuntimeError + raise RuntimeError if BarInt_sbar(b=2) != 3: - raise RuntimeError + raise RuntimeError # Functions if templatedfunction(b=2) != 3: - raise RuntimeError + raise RuntimeError -if foo_fn(a=1,b=2) != 3: - raise RuntimeError +if foo_fn(a=1, b=2) != 3: + raise RuntimeError if foo_fn(b=2) != 3: - raise RuntimeError + raise RuntimeError -#Functions with keywords +# Functions with keywords if foo_kw(_from=2) != 4: - raise RuntimeError + raise RuntimeError if foo_nu(_from=2, arg2=3) != 2: - raise RuntimeError + raise RuntimeError if foo_mm(min=2) != 4: - raise RuntimeError + raise RuntimeError if foo_mm(max=3) != 4: - raise RuntimeError - -#Default args with references + raise RuntimeError + +# Default args with references if rfoo(n=123) != 120: - raise RuntimeError + raise RuntimeError if rfoo(x=10) != -10: - raise RuntimeError + raise RuntimeError if rfoo(n=11, x=22) != -11: - raise RuntimeError + raise RuntimeError if rfoo(x=11, n=22) != 11: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/langobj_runme.py b/Examples/test-suite/python/langobj_runme.py index c10e19303be..b32d5a18a13 100644 --- a/Examples/test-suite/python/langobj_runme.py +++ b/Examples/test-suite/python/langobj_runme.py @@ -2,7 +2,7 @@ from langobj import * -x ="hello" +x = "hello" rx = sys.getrefcount(x) v = identity(x) rv = sys.getrefcount(v) diff --git a/Examples/test-suite/python/li_attribute_runme.py b/Examples/test-suite/python/li_attribute_runme.py index db40b9b2aaa..13a01c97d55 100644 --- a/Examples/test-suite/python/li_attribute_runme.py +++ b/Examples/test-suite/python/li_attribute_runme.py @@ -2,73 +2,72 @@ import li_attribute -aa = li_attribute.A(1,2,3) +aa = li_attribute.A(1, 2, 3) if aa.a != 1: - raise RuntimeError + raise RuntimeError aa.a = 3 if aa.a != 3: - print aa.a - raise RuntimeError + print aa.a + raise RuntimeError if aa.b != 2: - print aa.b - raise RuntimeError + print aa.b + raise RuntimeError aa.b = 5 if aa.b != 5: - raise RuntimeError + raise RuntimeError if aa.d != aa.b: - raise RuntimeError + raise RuntimeError if aa.c != 3: - raise RuntimeError + raise RuntimeError #aa.c = 5 -#if aa.c != 3: +# if aa.c != 3: # raise RuntimeError pi = li_attribute.Param_i(7) if pi.value != 7: - raise RuntimeError + raise RuntimeError -pi.value=3 +pi.value = 3 if pi.value != 3: - raise RuntimeError + raise RuntimeError b = li_attribute.B(aa) if b.a.c != 3: - raise RuntimeError - + raise RuntimeError + # class/struct attribute with get/set methods using return/pass by reference myFoo = li_attribute.MyFoo() myFoo.x = 8 myClass = li_attribute.MyClass() myClass.Foo = myFoo if myClass.Foo.x != 8: - raise RuntimeError + raise RuntimeError # class/struct attribute with get/set methods using return/pass by value myClassVal = li_attribute.MyClassVal() if myClassVal.ReadWriteFoo.x != -1: - raise RuntimeError + raise RuntimeError if myClassVal.ReadOnlyFoo.x != -1: - raise RuntimeError + raise RuntimeError myClassVal.ReadWriteFoo = myFoo if myClassVal.ReadWriteFoo.x != 8: - raise RuntimeError + raise RuntimeError if myClassVal.ReadOnlyFoo.x != 8: - raise RuntimeError + raise RuntimeError # string attribute with get/set methods using return/pass by value myStringyClass = li_attribute.MyStringyClass("initial string") if myStringyClass.ReadWriteString != "initial string": - raise RuntimeError + raise RuntimeError if myStringyClass.ReadOnlyString != "initial string": - raise RuntimeError + raise RuntimeError myStringyClass.ReadWriteString = "changed string" if myStringyClass.ReadWriteString != "changed string": - raise RuntimeError + raise RuntimeError if myStringyClass.ReadOnlyString != "changed string": - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/li_attribute_template_runme.py b/Examples/test-suite/python/li_attribute_template_runme.py index 7423053f9bd..d33b123097e 100644 --- a/Examples/test-suite/python/li_attribute_template_runme.py +++ b/Examples/test-suite/python/li_attribute_template_runme.py @@ -2,66 +2,67 @@ import li_attribute_template -chell = li_attribute_template.Cintint(1,2,3) +chell = li_attribute_template.Cintint(1, 2, 3) -def rassert( what, master ): + +def rassert(what, master): if what != master: print what raise RuntimeError -## Testing primitive by value attribute -rassert( chell.a, 1 ) +# Testing primitive by value attribute +rassert(chell.a, 1) chell.a = 3 -rassert( chell.a, 3 ) +rassert(chell.a, 3) -## Testing primitive by ref attribute +# Testing primitive by ref attribute -rassert( chell.b, 2 ) +rassert(chell.b, 2) chell.b = 5 -rassert( chell.b,5 ) +rassert(chell.b, 5) -## Testing string +# Testing string chell.str = "abc" -rassert( chell.str, "abc" ) +rassert(chell.str, "abc") # Testing class by value -rassert( chell.d.value, 1 ) +rassert(chell.d.value, 1) chell.d = li_attribute_template.Foo(2) -rassert( chell.d.value, 2 ) +rassert(chell.d.value, 2) # Testing class by reference -rassert( chell.e.value, 2 ) +rassert(chell.e.value, 2) -chell.e= li_attribute_template.Foo(3) -rassert( chell.e.value, 3 ) +chell.e = li_attribute_template.Foo(3) +rassert(chell.e.value, 3) chell.e.value = 4 -rassert( chell.e.value, 4 ) +rassert(chell.e.value, 4) # Testing moderately complex template by value -rassert( chell.f.first, 1 ) -rassert( chell.f.second, 2 ) +rassert(chell.f.first, 1) +rassert(chell.f.second, 2) -pair = li_attribute_template.pair_intint(3,4) +pair = li_attribute_template.pair_intint(3, 4) chell.f = pair -rassert( chell.f.first, 3 ) -rassert( chell.f.second, 4 ) +rassert(chell.f.first, 3) +rassert(chell.f.second, 4) # Testing moderately complex template by ref -rassert( chell.g.first, 2 ) -rassert( chell.g.second, 3 ) +rassert(chell.g.first, 2) +rassert(chell.g.second, 3) -pair = li_attribute_template.pair_intint(4,5) +pair = li_attribute_template.pair_intint(4, 5) chell.g = pair -rassert( chell.g.first, 4 ) -rassert( chell.g.second, 5 ) +rassert(chell.g.first, 4) +rassert(chell.g.second, 5) chell.g.first = 6 chell.g.second = 7 -rassert( chell.g.first, 6 ) -rassert( chell.g.second, 7 ) +rassert(chell.g.first, 6) +rassert(chell.g.second, 7) diff --git a/Examples/test-suite/python/li_boost_array_runme.py b/Examples/test-suite/python/li_boost_array_runme.py new file mode 100644 index 00000000000..4fa7eb88286 --- /dev/null +++ b/Examples/test-suite/python/li_boost_array_runme.py @@ -0,0 +1,55 @@ +from li_boost_array import * +import sys + + +def failed(a, b, msg): + raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) + + +def compare_sequences(a, b): + if len(a) != len(b): + failed(a, b, "different sizes") + for i in range(len(a)): + if a[i] != b[i]: + failed(a, b, "elements are different") + +def compare_containers(pythonlist, swigarray): + compare_sequences(pythonlist, swigarray) + +ps = [0, 1, 2, 3, 4, 5] + +ai = ArrayInt6(ps) + +compare_containers(ps, ai) + +# Modify content +for i in range(len(ps)): + ps[i] = (ps[i] + 1) * 10 + ai[i] = (ai[i] + 1) * 10 +compare_containers(ps, ai) + +# Empty +ai = ArrayInt6() +compare_containers([0, 0, 0, 0, 0, 0], ai) + +# Check return +compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2]) +compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2]) +#compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2]) +#compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2]) + +# Check passing arguments +ai = arrayInVal([9, 8, 7, 6, 5, 4]) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +ai = arrayInConstRef([9, 8, 7, 6, 5, 4]) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +#ai = ArrayInt6([9, 8, 7, 6, 5, 4]) +#arrayInRef(ai) +#compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +#ai = ArrayInt6([9, 8, 7, 6, 5, 4]) +#arrayInPtr(ai) +#compare_containers(ai, [90, 80, 70, 60, 50, 40]) + diff --git a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py index 9313176154f..9b9c7d68356 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py @@ -1,17 +1,22 @@ from li_boost_shared_ptr_bits import * + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + + def check(nd): - nd.i = 200 - i = nd.i + nd.i = 200 + i = nd.i - try: - nd.notexist = 100 - passed = 0 - except: - passed = 1 + try: + nd.notexist = 100 + passed = 0 + except: + passed = 1 - if not passed: - raise "Test failed" + if not passed: + raise "Test failed" nd = NonDynamic() check(nd) @@ -27,8 +32,10 @@ def check(nd): sum = sum(v) if sum != 66: - raise "sum is wrong" + raise "sum is wrong" ################################ -p = HiddenDestructor.create() - +if is_new_style_class(HiddenDestructor): + p = HiddenDestructor.create() +else: + p = HiddenDestructor_create() diff --git a/Examples/test-suite/python/li_boost_shared_ptr_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_runme.py index f967def14f3..c960625ad68 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py @@ -4,541 +4,558 @@ debug = False # simple shared_ptr usage - created in C++ + + class li_boost_shared_ptr_runme: - def main(self): - if (debug): - print "Started" - - li_boost_shared_ptr.cvar.debug_shared = debug - - # Change loop count to run for a long time to monitor memory - loopCount = 1 #5000 - for i in range (0,loopCount): - self.runtest() - - # Expect 1 instance - the one global variable (GlobalValue) - if (li_boost_shared_ptr.Klass.getTotal_count() != 1): - raise RuntimeError("Klass.total_count=%s" % li_boost_shared_ptr.Klass.getTotal_count()) - - wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count() - if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING): - # Expect 1 instance - the one global variable (GlobalSmartValue) - if (wrapper_count != 1): - raise RuntimeError("shared_ptr wrapper count=%s" % wrapper_count) - - if (debug): - print "Finished" - - def runtest(self): - # simple shared_ptr usage - created in C++ - k = li_boost_shared_ptr.Klass("me oh my") - val = k.getValue() - self.verifyValue("me oh my", val) - self.verifyCount(1, k) - - # simple shared_ptr usage - not created in C++ - k = li_boost_shared_ptr.factorycreate() - val = k.getValue() - self.verifyValue("factorycreate", val) - self.verifyCount(1, k) - - # pass by shared_ptr - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.smartpointertest(k) - val = kret.getValue() - self.verifyValue("me oh my smartpointertest", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # pass by shared_ptr pointer - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.smartpointerpointertest(k) - val = kret.getValue() - self.verifyValue("me oh my smartpointerpointertest", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # pass by shared_ptr reference - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.smartpointerreftest(k) - val = kret.getValue() - self.verifyValue("me oh my smartpointerreftest", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # pass by shared_ptr pointer reference - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.smartpointerpointerreftest(k) - val = kret.getValue() - self.verifyValue("me oh my smartpointerpointerreftest", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # const pass by shared_ptr - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.constsmartpointertest(k) - val = kret.getValue() - self.verifyValue("me oh my", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # const pass by shared_ptr pointer - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.constsmartpointerpointertest(k) - val = kret.getValue() - self.verifyValue("me oh my", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # const pass by shared_ptr reference - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.constsmartpointerreftest(k) - val = kret.getValue() - self.verifyValue("me oh my", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # pass by value - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.valuetest(k) - val = kret.getValue() - self.verifyValue("me oh my valuetest", val) - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # pass by pointer - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.pointertest(k) - val = kret.getValue() - self.verifyValue("me oh my pointertest", val) - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # pass by reference - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.reftest(k) - val = kret.getValue() - self.verifyValue("me oh my reftest", val) - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # pass by pointer reference - k = li_boost_shared_ptr.Klass("me oh my") - kret = li_boost_shared_ptr.pointerreftest(k) - val = kret.getValue() - self.verifyValue("me oh my pointerreftest", val) - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # null tests - k = None - - if (li_boost_shared_ptr.smartpointertest(k) != None): - raise RuntimeError("return was not null") - - if (li_boost_shared_ptr.smartpointerpointertest(k) != None): - raise RuntimeError("return was not null") - - if (li_boost_shared_ptr.smartpointerreftest(k) != None): - raise RuntimeError("return was not null") - - if (li_boost_shared_ptr.smartpointerpointerreftest(k) != None): - raise RuntimeError("return was not null") - - if (li_boost_shared_ptr.nullsmartpointerpointertest(None) != "null pointer"): - raise RuntimeError("not null smartpointer pointer") - - try: - li_boost_shared_ptr.valuetest(k) - raise RuntimeError("Failed to catch null pointer") - except ValueError: - pass - - if (li_boost_shared_ptr.pointertest(k) != None): - raise RuntimeError("return was not null") - - try: - li_boost_shared_ptr.reftest(k) - raise RuntimeError("Failed to catch null pointer") - except ValueError: - pass - - # $owner - k = li_boost_shared_ptr.pointerownertest() - val = k.getValue() - self.verifyValue("pointerownertest", val) - self.verifyCount(1, k) - k = li_boost_shared_ptr.smartpointerpointerownertest() - val = k.getValue() - self.verifyValue("smartpointerpointerownertest", val) - self.verifyCount(1, k) - - # //////////////////////////////// Derived class //////////////////////////////////////// - # derived pass by shared_ptr - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.derivedsmartptrtest(k) - val = kret.getValue() - self.verifyValue("me oh my derivedsmartptrtest-Derived", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # derived pass by shared_ptr pointer - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.derivedsmartptrpointertest(k) - val = kret.getValue() - self.verifyValue("me oh my derivedsmartptrpointertest-Derived", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # derived pass by shared_ptr ref - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.derivedsmartptrreftest(k) - val = kret.getValue() - self.verifyValue("me oh my derivedsmartptrreftest-Derived", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # derived pass by shared_ptr pointer ref - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.derivedsmartptrpointerreftest(k) - val = kret.getValue() - self.verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # derived pass by pointer - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.derivedpointertest(k) - val = kret.getValue() - self.verifyValue("me oh my derivedpointertest-Derived", val) - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # derived pass by ref - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.derivedreftest(k) - val = kret.getValue() - self.verifyValue("me oh my derivedreftest-Derived", val) - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # //////////////////////////////// Derived and base class mixed //////////////////////////////////////// - # pass by shared_ptr (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.smartpointertest(k) - val = kret.getValue() - self.verifyValue("me oh my smartpointertest-Derived", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # pass by shared_ptr pointer (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.smartpointerpointertest(k) - val = kret.getValue() - self.verifyValue("me oh my smartpointerpointertest-Derived", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # pass by shared_ptr reference (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.smartpointerreftest(k) - val = kret.getValue() - self.verifyValue("me oh my smartpointerreftest-Derived", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # pass by shared_ptr pointer reference (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.smartpointerpointerreftest(k) - val = kret.getValue() - self.verifyValue("me oh my smartpointerpointerreftest-Derived", val) - self.verifyCount(2, k) - self.verifyCount(2, kret) - - # pass by value (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.valuetest(k) - val = kret.getValue() - self.verifyValue("me oh my valuetest", val) # note slicing - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # pass by pointer (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.pointertest(k) - val = kret.getValue() - self.verifyValue("me oh my pointertest-Derived", val) - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # pass by ref (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my") - kret = li_boost_shared_ptr.reftest(k) - val = kret.getValue() - self.verifyValue("me oh my reftest-Derived", val) - self.verifyCount(1, k) - self.verifyCount(1, kret) - - # //////////////////////////////// Overloading tests //////////////////////////////////////// - # Base class - k = li_boost_shared_ptr.Klass("me oh my") - self.verifyValue(li_boost_shared_ptr.overload_rawbyval(k), "rawbyval") - self.verifyValue(li_boost_shared_ptr.overload_rawbyref(k), "rawbyref") - self.verifyValue(li_boost_shared_ptr.overload_rawbyptr(k), "rawbyptr") - self.verifyValue(li_boost_shared_ptr.overload_rawbyptrref(k), "rawbyptrref") - - self.verifyValue(li_boost_shared_ptr.overload_smartbyval(k), "smartbyval") - self.verifyValue(li_boost_shared_ptr.overload_smartbyref(k), "smartbyref") - self.verifyValue(li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr") - self.verifyValue(li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref") - - # Derived class - k = li_boost_shared_ptr.KlassDerived("me oh my") - self.verifyValue(li_boost_shared_ptr.overload_rawbyval(k), "rawbyval") - self.verifyValue(li_boost_shared_ptr.overload_rawbyref(k), "rawbyref") - self.verifyValue(li_boost_shared_ptr.overload_rawbyptr(k), "rawbyptr") - self.verifyValue(li_boost_shared_ptr.overload_rawbyptrref(k), "rawbyptrref") - - self.verifyValue(li_boost_shared_ptr.overload_smartbyval(k), "smartbyval") - self.verifyValue(li_boost_shared_ptr.overload_smartbyref(k), "smartbyref") - self.verifyValue(li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr") - self.verifyValue(li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref") - - # 3rd derived class - k = li_boost_shared_ptr.Klass3rdDerived("me oh my") - val = k.getValue() - self.verifyValue("me oh my-3rdDerived", val) - self.verifyCount(1, k) - val = li_boost_shared_ptr.test3rdupcast(k) - self.verifyValue("me oh my-3rdDerived", val) - self.verifyCount(1, k) - - # //////////////////////////////// Member variables //////////////////////////////////////// - # smart pointer by value - m = li_boost_shared_ptr.MemberVariables() - k = li_boost_shared_ptr.Klass("smart member value") - m.SmartMemberValue = k - val = k.getValue() - self.verifyValue("smart member value", val) - self.verifyCount(2, k) - - kmember = m.SmartMemberValue - val = kmember.getValue() - self.verifyValue("smart member value", val) - self.verifyCount(3, kmember) - self.verifyCount(3, k) - - del m - self.verifyCount(2, kmember) - self.verifyCount(2, k) - - # smart pointer by pointer - m = li_boost_shared_ptr.MemberVariables() - k = li_boost_shared_ptr.Klass("smart member pointer") - m.SmartMemberPointer = k - val = k.getValue() - self.verifyValue("smart member pointer", val) - self.verifyCount(1, k) - - kmember = m.SmartMemberPointer - val = kmember.getValue() - self.verifyValue("smart member pointer", val) - self.verifyCount(2, kmember) - self.verifyCount(2, k) - - del m - self.verifyCount(2, kmember) - self.verifyCount(2, k) - - # smart pointer by reference - m = li_boost_shared_ptr.MemberVariables() - k = li_boost_shared_ptr.Klass("smart member reference") - m.SmartMemberReference = k - val = k.getValue() - self.verifyValue("smart member reference", val) - self.verifyCount(2, k) - - kmember = m.SmartMemberReference - val = kmember.getValue() - self.verifyValue("smart member reference", val) - self.verifyCount(3, kmember) - self.verifyCount(3, k) - - # The C++ reference refers to SmartMemberValue... - kmemberVal = m.SmartMemberValue - val = kmember.getValue() - self.verifyValue("smart member reference", val) - self.verifyCount(4, kmemberVal) - self.verifyCount(4, kmember) - self.verifyCount(4, k) - - del m - self.verifyCount(3, kmemberVal) - self.verifyCount(3, kmember) - self.verifyCount(3, k) - - # plain by value - m = li_boost_shared_ptr.MemberVariables() - k = li_boost_shared_ptr.Klass("plain member value") - m.MemberValue = k - val = k.getValue() - self.verifyValue("plain member value", val) - self.verifyCount(1, k) - - kmember = m.MemberValue - val = kmember.getValue() - self.verifyValue("plain member value", val) - self.verifyCount(1, kmember) - self.verifyCount(1, k) - - del m - self.verifyCount(1, kmember) - self.verifyCount(1, k) - - # plain by pointer - m = li_boost_shared_ptr.MemberVariables() - k = li_boost_shared_ptr.Klass("plain member pointer") - m.MemberPointer = k - val = k.getValue() - self.verifyValue("plain member pointer", val) - self.verifyCount(1, k) - - kmember = m.MemberPointer - val = kmember.getValue() - self.verifyValue("plain member pointer", val) - self.verifyCount(1, kmember) - self.verifyCount(1, k) - - del m - self.verifyCount(1, kmember) - self.verifyCount(1, k) - - # plain by reference - m = li_boost_shared_ptr.MemberVariables() - k = li_boost_shared_ptr.Klass("plain member reference") - m.MemberReference = k - val = k.getValue() - self.verifyValue("plain member reference", val) - self.verifyCount(1, k) - - kmember = m.MemberReference - val = kmember.getValue() - self.verifyValue("plain member reference", val) - self.verifyCount(1, kmember) - self.verifyCount(1, k) - - del m - self.verifyCount(1, kmember) - self.verifyCount(1, k) - - # null member variables - m = li_boost_shared_ptr.MemberVariables() - - # shared_ptr by value - k = m.SmartMemberValue - if (k != None): - raise RuntimeError("expected null") - m.SmartMemberValue = None - k = m.SmartMemberValue - if (k != None): - raise RuntimeError("expected null") - self.verifyCount(0, k) - - # plain by value - try: - m.MemberValue = None - raise RuntimeError("Failed to catch null pointer") - except ValueError: - pass - - # ////////////////////////////////// Global variables //////////////////////////////////////// - # smart pointer - kglobal = li_boost_shared_ptr.cvar.GlobalSmartValue - if (kglobal != None): - raise RuntimeError("expected null") - - k = li_boost_shared_ptr.Klass("smart global value") - li_boost_shared_ptr.cvar.GlobalSmartValue = k - self.verifyCount(2, k) - - kglobal = li_boost_shared_ptr.cvar.GlobalSmartValue - val = kglobal.getValue() - self.verifyValue("smart global value", val) - self.verifyCount(3, kglobal) - self.verifyCount(3, k) - self.verifyValue("smart global value", li_boost_shared_ptr.cvar.GlobalSmartValue.getValue()) - li_boost_shared_ptr.cvar.GlobalSmartValue = None - - # plain value - k = li_boost_shared_ptr.Klass("global value") - li_boost_shared_ptr.cvar.GlobalValue = k - self.verifyCount(1, k) - - kglobal = li_boost_shared_ptr.cvar.GlobalValue - val = kglobal.getValue() - self.verifyValue("global value", val) - self.verifyCount(1, kglobal) - self.verifyCount(1, k) - self.verifyValue("global value", li_boost_shared_ptr.cvar.GlobalValue.getValue()) - - try: - li_boost_shared_ptr.cvar.GlobalValue = None - raise RuntimeError("Failed to catch null pointer") - except ValueError: - pass - - # plain pointer - kglobal = li_boost_shared_ptr.cvar.GlobalPointer - if (kglobal != None): - raise RuntimeError("expected null") - - k = li_boost_shared_ptr.Klass("global pointer") - li_boost_shared_ptr.cvar.GlobalPointer = k - self.verifyCount(1, k) - - kglobal = li_boost_shared_ptr.cvar.GlobalPointer - val = kglobal.getValue() - self.verifyValue("global pointer", val) - self.verifyCount(1, kglobal) - self.verifyCount(1, k) - li_boost_shared_ptr.cvar.GlobalPointer = None - - # plain reference - kglobal - - k = li_boost_shared_ptr.Klass("global reference") - li_boost_shared_ptr.cvar.GlobalReference = k - self.verifyCount(1, k) - - kglobal = li_boost_shared_ptr.cvar.GlobalReference - val = kglobal.getValue() - self.verifyValue("global reference", val) - self.verifyCount(1, kglobal) - self.verifyCount(1, k) - - try: - li_boost_shared_ptr.cvar.GlobalReference = None - raise RuntimeError("Failed to catch null pointer") - except ValueError: - pass - - # ////////////////////////////////// Templates //////////////////////////////////////// - pid = li_boost_shared_ptr.PairIntDouble(10, 20.2) - if (pid.baseVal1 != 20 or pid.baseVal2 != 40.4): - raise RuntimeError("Base values wrong") - if (pid.val1 != 10 or pid.val2 != 20.2): - raise RuntimeError("Derived Values wrong") - - def verifyValue(self, expected, got): - if (expected != got): - raise RuntimeError("verify value failed. Expected: ", expected, " Got: ", got) - - def verifyCount(self, expected, k): - got = li_boost_shared_ptr.use_count(k) - if (expected != got): - raise RuntimeError("verify use_count failed. Expected: ", expected, " Got: ", got) + + def main(self): + if (debug): + print "Started" + + li_boost_shared_ptr.cvar.debug_shared = debug + + # Change loop count to run for a long time to monitor memory + loopCount = 1 # 5000 + for i in range(0, loopCount): + self.runtest() + + # Expect 1 instance - the one global variable (GlobalValue) + if (li_boost_shared_ptr.Klass_getTotal_count() != 1): + raise RuntimeError("Klass.total_count=%s" % + li_boost_shared_ptr.Klass.getTotal_count()) + + wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count() + if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING): + # Expect 1 instance - the one global variable (GlobalSmartValue) + if (wrapper_count != 1): + raise RuntimeError( + "shared_ptr wrapper count=%s" % wrapper_count) + + if (debug): + print "Finished" + + def runtest(self): + # simple shared_ptr usage - created in C++ + k = li_boost_shared_ptr.Klass("me oh my") + val = k.getValue() + self.verifyValue("me oh my", val) + self.verifyCount(1, k) + + # simple shared_ptr usage - not created in C++ + k = li_boost_shared_ptr.factorycreate() + val = k.getValue() + self.verifyValue("factorycreate", val) + self.verifyCount(1, k) + + # pass by shared_ptr + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.smartpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointertest", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr pointer + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.smartpointerpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerpointertest", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr reference + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.smartpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerreftest", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr pointer reference + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.smartpointerpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerpointerreftest", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # const pass by shared_ptr + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.constsmartpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # const pass by shared_ptr pointer + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.constsmartpointerpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # const pass by shared_ptr reference + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.constsmartpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by value + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.valuetest(k) + val = kret.getValue() + self.verifyValue("me oh my valuetest", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by pointer + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.pointertest(k) + val = kret.getValue() + self.verifyValue("me oh my pointertest", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by reference + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.reftest(k) + val = kret.getValue() + self.verifyValue("me oh my reftest", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by pointer reference + k = li_boost_shared_ptr.Klass("me oh my") + kret = li_boost_shared_ptr.pointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my pointerreftest", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # null tests + k = None + + if (li_boost_shared_ptr.smartpointertest(k) != None): + raise RuntimeError("return was not null") + + if (li_boost_shared_ptr.smartpointerpointertest(k) != None): + raise RuntimeError("return was not null") + + if (li_boost_shared_ptr.smartpointerreftest(k) != None): + raise RuntimeError("return was not null") + + if (li_boost_shared_ptr.smartpointerpointerreftest(k) != None): + raise RuntimeError("return was not null") + + if (li_boost_shared_ptr.nullsmartpointerpointertest(None) != "null pointer"): + raise RuntimeError("not null smartpointer pointer") + + try: + li_boost_shared_ptr.valuetest(k) + raise RuntimeError("Failed to catch null pointer") + except ValueError: + pass + + if (li_boost_shared_ptr.pointertest(k) != None): + raise RuntimeError("return was not null") + + try: + li_boost_shared_ptr.reftest(k) + raise RuntimeError("Failed to catch null pointer") + except ValueError: + pass + + # $owner + k = li_boost_shared_ptr.pointerownertest() + val = k.getValue() + self.verifyValue("pointerownertest", val) + self.verifyCount(1, k) + k = li_boost_shared_ptr.smartpointerpointerownertest() + val = k.getValue() + self.verifyValue("smartpointerpointerownertest", val) + self.verifyCount(1, k) + + # //////////////////////////////// Derived class ////////////////////// + # derived pass by shared_ptr + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.derivedsmartptrtest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedsmartptrtest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # derived pass by shared_ptr pointer + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.derivedsmartptrpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedsmartptrpointertest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # derived pass by shared_ptr ref + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.derivedsmartptrreftest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedsmartptrreftest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # derived pass by shared_ptr pointer ref + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.derivedsmartptrpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # derived pass by pointer + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.derivedpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedpointertest-Derived", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # derived pass by ref + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.derivedreftest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedreftest-Derived", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # //////////////////////////////// Derived and base class mixed /////// + # pass by shared_ptr (mixed) + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.smartpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointertest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr pointer (mixed) + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.smartpointerpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerpointertest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr reference (mixed) + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.smartpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerreftest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr pointer reference (mixed) + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.smartpointerpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerpointerreftest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by value (mixed) + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.valuetest(k) + val = kret.getValue() + self.verifyValue("me oh my valuetest", val) # note slicing + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by pointer (mixed) + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.pointertest(k) + val = kret.getValue() + self.verifyValue("me oh my pointertest-Derived", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by ref (mixed) + k = li_boost_shared_ptr.KlassDerived("me oh my") + kret = li_boost_shared_ptr.reftest(k) + val = kret.getValue() + self.verifyValue("me oh my reftest-Derived", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # //////////////////////////////// Overloading tests ////////////////// + # Base class + k = li_boost_shared_ptr.Klass("me oh my") + self.verifyValue(li_boost_shared_ptr.overload_rawbyval(k), "rawbyval") + self.verifyValue(li_boost_shared_ptr.overload_rawbyref(k), "rawbyref") + self.verifyValue(li_boost_shared_ptr.overload_rawbyptr(k), "rawbyptr") + self.verifyValue( + li_boost_shared_ptr.overload_rawbyptrref(k), "rawbyptrref") + + self.verifyValue( + li_boost_shared_ptr.overload_smartbyval(k), "smartbyval") + self.verifyValue( + li_boost_shared_ptr.overload_smartbyref(k), "smartbyref") + self.verifyValue( + li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr") + self.verifyValue( + li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref") + + # Derived class + k = li_boost_shared_ptr.KlassDerived("me oh my") + self.verifyValue(li_boost_shared_ptr.overload_rawbyval(k), "rawbyval") + self.verifyValue(li_boost_shared_ptr.overload_rawbyref(k), "rawbyref") + self.verifyValue(li_boost_shared_ptr.overload_rawbyptr(k), "rawbyptr") + self.verifyValue( + li_boost_shared_ptr.overload_rawbyptrref(k), "rawbyptrref") + + self.verifyValue( + li_boost_shared_ptr.overload_smartbyval(k), "smartbyval") + self.verifyValue( + li_boost_shared_ptr.overload_smartbyref(k), "smartbyref") + self.verifyValue( + li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr") + self.verifyValue( + li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref") + + # 3rd derived class + k = li_boost_shared_ptr.Klass3rdDerived("me oh my") + val = k.getValue() + self.verifyValue("me oh my-3rdDerived", val) + self.verifyCount(1, k) + val = li_boost_shared_ptr.test3rdupcast(k) + self.verifyValue("me oh my-3rdDerived", val) + self.verifyCount(1, k) + + # //////////////////////////////// Member variables /////////////////// + # smart pointer by value + m = li_boost_shared_ptr.MemberVariables() + k = li_boost_shared_ptr.Klass("smart member value") + m.SmartMemberValue = k + val = k.getValue() + self.verifyValue("smart member value", val) + self.verifyCount(2, k) + + kmember = m.SmartMemberValue + val = kmember.getValue() + self.verifyValue("smart member value", val) + self.verifyCount(3, kmember) + self.verifyCount(3, k) + + del m + self.verifyCount(2, kmember) + self.verifyCount(2, k) + + # smart pointer by pointer + m = li_boost_shared_ptr.MemberVariables() + k = li_boost_shared_ptr.Klass("smart member pointer") + m.SmartMemberPointer = k + val = k.getValue() + self.verifyValue("smart member pointer", val) + self.verifyCount(1, k) + + kmember = m.SmartMemberPointer + val = kmember.getValue() + self.verifyValue("smart member pointer", val) + self.verifyCount(2, kmember) + self.verifyCount(2, k) + + del m + self.verifyCount(2, kmember) + self.verifyCount(2, k) + + # smart pointer by reference + m = li_boost_shared_ptr.MemberVariables() + k = li_boost_shared_ptr.Klass("smart member reference") + m.SmartMemberReference = k + val = k.getValue() + self.verifyValue("smart member reference", val) + self.verifyCount(2, k) + + kmember = m.SmartMemberReference + val = kmember.getValue() + self.verifyValue("smart member reference", val) + self.verifyCount(3, kmember) + self.verifyCount(3, k) + + # The C++ reference refers to SmartMemberValue... + kmemberVal = m.SmartMemberValue + val = kmember.getValue() + self.verifyValue("smart member reference", val) + self.verifyCount(4, kmemberVal) + self.verifyCount(4, kmember) + self.verifyCount(4, k) + + del m + self.verifyCount(3, kmemberVal) + self.verifyCount(3, kmember) + self.verifyCount(3, k) + + # plain by value + m = li_boost_shared_ptr.MemberVariables() + k = li_boost_shared_ptr.Klass("plain member value") + m.MemberValue = k + val = k.getValue() + self.verifyValue("plain member value", val) + self.verifyCount(1, k) + + kmember = m.MemberValue + val = kmember.getValue() + self.verifyValue("plain member value", val) + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + del m + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + # plain by pointer + m = li_boost_shared_ptr.MemberVariables() + k = li_boost_shared_ptr.Klass("plain member pointer") + m.MemberPointer = k + val = k.getValue() + self.verifyValue("plain member pointer", val) + self.verifyCount(1, k) + + kmember = m.MemberPointer + val = kmember.getValue() + self.verifyValue("plain member pointer", val) + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + del m + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + # plain by reference + m = li_boost_shared_ptr.MemberVariables() + k = li_boost_shared_ptr.Klass("plain member reference") + m.MemberReference = k + val = k.getValue() + self.verifyValue("plain member reference", val) + self.verifyCount(1, k) + + kmember = m.MemberReference + val = kmember.getValue() + self.verifyValue("plain member reference", val) + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + del m + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + # null member variables + m = li_boost_shared_ptr.MemberVariables() + + # shared_ptr by value + k = m.SmartMemberValue + if (k != None): + raise RuntimeError("expected null") + m.SmartMemberValue = None + k = m.SmartMemberValue + if (k != None): + raise RuntimeError("expected null") + self.verifyCount(0, k) + + # plain by value + try: + m.MemberValue = None + raise RuntimeError("Failed to catch null pointer") + except ValueError: + pass + + # ////////////////////////////////// Global variables ///////////////// + # smart pointer + kglobal = li_boost_shared_ptr.cvar.GlobalSmartValue + if (kglobal != None): + raise RuntimeError("expected null") + + k = li_boost_shared_ptr.Klass("smart global value") + li_boost_shared_ptr.cvar.GlobalSmartValue = k + self.verifyCount(2, k) + + kglobal = li_boost_shared_ptr.cvar.GlobalSmartValue + val = kglobal.getValue() + self.verifyValue("smart global value", val) + self.verifyCount(3, kglobal) + self.verifyCount(3, k) + self.verifyValue( + "smart global value", li_boost_shared_ptr.cvar.GlobalSmartValue.getValue()) + li_boost_shared_ptr.cvar.GlobalSmartValue = None + + # plain value + k = li_boost_shared_ptr.Klass("global value") + li_boost_shared_ptr.cvar.GlobalValue = k + self.verifyCount(1, k) + + kglobal = li_boost_shared_ptr.cvar.GlobalValue + val = kglobal.getValue() + self.verifyValue("global value", val) + self.verifyCount(1, kglobal) + self.verifyCount(1, k) + self.verifyValue( + "global value", li_boost_shared_ptr.cvar.GlobalValue.getValue()) + + try: + li_boost_shared_ptr.cvar.GlobalValue = None + raise RuntimeError("Failed to catch null pointer") + except ValueError: + pass + + # plain pointer + kglobal = li_boost_shared_ptr.cvar.GlobalPointer + if (kglobal != None): + raise RuntimeError("expected null") + + k = li_boost_shared_ptr.Klass("global pointer") + li_boost_shared_ptr.cvar.GlobalPointer = k + self.verifyCount(1, k) + + kglobal = li_boost_shared_ptr.cvar.GlobalPointer + val = kglobal.getValue() + self.verifyValue("global pointer", val) + self.verifyCount(1, kglobal) + self.verifyCount(1, k) + li_boost_shared_ptr.cvar.GlobalPointer = None + + # plain reference + + k = li_boost_shared_ptr.Klass("global reference") + li_boost_shared_ptr.cvar.GlobalReference = k + self.verifyCount(1, k) + + kglobal = li_boost_shared_ptr.cvar.GlobalReference + val = kglobal.getValue() + self.verifyValue("global reference", val) + self.verifyCount(1, kglobal) + self.verifyCount(1, k) + + try: + li_boost_shared_ptr.cvar.GlobalReference = None + raise RuntimeError("Failed to catch null pointer") + except ValueError: + pass + + # ////////////////////////////////// Templates //////////////////////// + pid = li_boost_shared_ptr.PairIntDouble(10, 20.2) + if (pid.baseVal1 != 20 or pid.baseVal2 != 40.4): + raise RuntimeError("Base values wrong") + if (pid.val1 != 10 or pid.val2 != 20.2): + raise RuntimeError("Derived Values wrong") + + def verifyValue(self, expected, got): + if (expected != got): + raise RuntimeError( + "verify value failed. Expected: ", expected, " Got: ", got) + + def verifyCount(self, expected, k): + got = li_boost_shared_ptr.use_count(k) + if (expected != got): + raise RuntimeError( + "verify use_count failed. Expected: ", expected, " Got: ", got) runme = li_boost_shared_ptr_runme() runme.main() - diff --git a/Examples/test-suite/python/li_boost_shared_ptr_template_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_template_runme.py index c10627f361a..6b56ec47953 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_template_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_template_runme.py @@ -3,28 +3,28 @@ b = BaseINTEGER() d = DerivedINTEGER() if b.bar() != 1: - raise RuntimeError + raise RuntimeError if d.bar() != 2: - raise RuntimeError + raise RuntimeError if bar_getter(b) != 1: - raise RuntimeError + raise RuntimeError # Fix reverted in rev 12953 -#if bar_getter(d) != 2: +# if bar_getter(d) != 2: # raise RuntimeError b = BaseDefaultInt() d = DerivedDefaultInt() d2 = DerivedDefaultInt2() if b.bar2() != 3: - raise RuntimeError + raise RuntimeError if d.bar2() != 4: - raise RuntimeError + raise RuntimeError if d2.bar2() != 4: - raise RuntimeError + raise RuntimeError if bar2_getter(b) != 3: - raise RuntimeError + raise RuntimeError # Fix reverted in rev 12953 -#if bar2_getter(d) != 4: +# if bar2_getter(d) != 4: # raise RuntimeError -#if bar2_getter(d2) != 4: +# if bar2_getter(d2) != 4: # raise RuntimeError diff --git a/Examples/test-suite/python/li_carrays_cpp_runme.py b/Examples/test-suite/python/li_carrays_cpp_runme.py new file mode 100644 index 00000000000..54d79aa4660 --- /dev/null +++ b/Examples/test-suite/python/li_carrays_cpp_runme.py @@ -0,0 +1,9 @@ +from li_carrays_cpp import * + +d = doubleArray(10) + +d[0] = 7 +d[5] = d[0] + 3 + +if d[5] + d[0] != 17: + raise RuntimeError diff --git a/Examples/test-suite/python/li_cdata_cpp_runme.py b/Examples/test-suite/python/li_cdata_cpp_runme.py new file mode 100644 index 00000000000..30e4b938633 --- /dev/null +++ b/Examples/test-suite/python/li_cdata_cpp_runme.py @@ -0,0 +1,9 @@ + +from li_cdata_cpp import * + +s = "ABC abc" +m = malloc(256) +memmove(m, s) +ss = cdata(m, 7) +if ss != "ABC abc": + raise "failed" diff --git a/Examples/test-suite/python/li_cdata_runme.py b/Examples/test-suite/python/li_cdata_runme.py index 061ca6f6854..8a132e7dd10 100644 --- a/Examples/test-suite/python/li_cdata_runme.py +++ b/Examples/test-suite/python/li_cdata_runme.py @@ -6,5 +6,4 @@ memmove(m, s) ss = cdata(m, 7) if ss != "ABC abc": - raise "failed" - + raise "failed" diff --git a/Examples/test-suite/python/li_cpointer_cpp_runme.py b/Examples/test-suite/python/li_cpointer_cpp_runme.py new file mode 100644 index 00000000000..c49e9fc28a4 --- /dev/null +++ b/Examples/test-suite/python/li_cpointer_cpp_runme.py @@ -0,0 +1,10 @@ +from li_cpointer_cpp import * + + +p = new_intp() +intp_assign(p, 3) + +if intp_value(p) != 3: + raise RuntimeError + +delete_intp(p) diff --git a/Examples/test-suite/python/li_cpointer_runme.py b/Examples/test-suite/python/li_cpointer_runme.py index ac95ff4b9d6..1565069cf42 100644 --- a/Examples/test-suite/python/li_cpointer_runme.py +++ b/Examples/test-suite/python/li_cpointer_runme.py @@ -2,7 +2,7 @@ p = new_intp() -intp_assign(p,3) +intp_assign(p, 3) if intp_value(p) != 3: raise RuntimeError diff --git a/Examples/test-suite/python/li_cstring_runme.py b/Examples/test-suite/python/li_cstring_runme.py index 6503744bd22..55b51d1c76a 100644 --- a/Examples/test-suite/python/li_cstring_runme.py +++ b/Examples/test-suite/python/li_cstring_runme.py @@ -2,7 +2,7 @@ if count("ab\0ab\0ab\0", 0) != 3: - raise RuntimeError + raise RuntimeError if test1() != "Hello World": raise RuntimeError @@ -17,16 +17,15 @@ if test4("hello") != "hello-suffix": print test4("hello") raise RuntimeError - + if test5(4) != 'xxxx': raise RuntimeError if test6(10) != 'xxxxx': raise RuntimeError - -if test7() !="Hello world!": + +if test7() != "Hello world!": raise RuntimeError if test8() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_": raise RuntimeError - diff --git a/Examples/test-suite/python/li_cwstring_runme.py b/Examples/test-suite/python/li_cwstring_runme.py index 4ab59088278..aaa5b6e623e 100644 --- a/Examples/test-suite/python/li_cwstring_runme.py +++ b/Examples/test-suite/python/li_cwstring_runme.py @@ -1,7 +1,7 @@ from li_cwstring import * if count(u"ab\0ab\0ab\0", 0) != 3: - raise RuntimeError + raise RuntimeError if test1() != u"Hello World": raise RuntimeError @@ -14,16 +14,15 @@ if test4("hello") != u"hello-suffix": raise RuntimeError - + if test5(4) != u'xxxx': raise RuntimeError if test6(10) != u'xxxxx': raise RuntimeError - + if test7() != u"Hello world!": raise RuntimeError if test8() != u" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_": raise RuntimeError - diff --git a/Examples/test-suite/python/li_implicit_runme.py b/Examples/test-suite/python/li_implicit_runme.py index a0672e0168f..d8dd0fdcc91 100644 --- a/Examples/test-suite/python/li_implicit_runme.py +++ b/Examples/test-suite/python/li_implicit_runme.py @@ -9,9 +9,8 @@ ab, get(ab) if get(ai) != get(1): - raise RuntimeError,"bad implicit type" + raise RuntimeError, "bad implicit type" if get(ad) != get(2.0): - raise RuntimeError,"bad implicit type" + raise RuntimeError, "bad implicit type" if get(ab) != get(b): - raise RuntimeError,"bad implicit type" - + raise RuntimeError, "bad implicit type" diff --git a/Examples/test-suite/python/li_std_auto_ptr_runme.py b/Examples/test-suite/python/li_std_auto_ptr_runme.py index a29771479b6..6d2479f874c 100644 --- a/Examples/test-suite/python/li_std_auto_ptr_runme.py +++ b/Examples/test-suite/python/li_std_auto_ptr_runme.py @@ -2,16 +2,16 @@ k1 = makeKlassAutoPtr("first") k2 = makeKlassAutoPtr("second") -if Klass.getTotal_count() != 2: - raise "number of objects should be 2" +if Klass_getTotal_count() != 2: + raise "number of objects should be 2" del k1 -if Klass.getTotal_count() != 1: - raise "number of objects should be 1" +if Klass_getTotal_count() != 1: + raise "number of objects should be 1" if k2.getLabel() != "second": - raise "wrong object label" + raise "wrong object label" del k2 -if Klass.getTotal_count() != 0: - raise "no objects should be left" +if Klass_getTotal_count() != 0: + raise "no objects should be left" diff --git a/Examples/test-suite/python/li_std_carray_runme.py b/Examples/test-suite/python/li_std_carray_runme.py index 803bc96c5ac..36eeaf17378 100644 --- a/Examples/test-suite/python/li_std_carray_runme.py +++ b/Examples/test-suite/python/li_std_carray_runme.py @@ -2,7 +2,7 @@ v3 = Vector3() -for i in range(0,len(v3)): +for i in range(0, len(v3)): v3[i] = i i = 0 @@ -14,9 +14,9 @@ m3 = Matrix3() -for i in range(0,len(m3)): +for i in range(0, len(m3)): v3 = m3[i] - for j in range(0,len(v3)): + for j in range(0, len(v3)): v3[j] = i + j i = 0 @@ -30,12 +30,10 @@ i = i + 1 pass -for i in range(0,len(m3)): - for j in range(0,len(m3)): +for i in range(0, len(m3)): + for j in range(0, len(m3)): if m3[i][j] != i + j: raise RuntimeError -da = Vector3((1,2,3)) -ma = Matrix3(((1,2,3),(4,5,6),(7,8,9))) - - +da = Vector3((1, 2, 3)) +ma = Matrix3(((1, 2, 3), (4, 5, 6), (7, 8, 9))) diff --git a/Examples/test-suite/python/li_std_containers_int_runme.py b/Examples/test-suite/python/li_std_containers_int_runme.py index 3cbbb2862a3..c7d262f60d9 100644 --- a/Examples/test-suite/python/li_std_containers_int_runme.py +++ b/Examples/test-suite/python/li_std_containers_int_runme.py @@ -1,158 +1,170 @@ -# Check std::vector and std::list behaves the same as Python iterable types (list) +# Check std::vector and std::list behaves the same as Python iterable +# types (list) from li_std_containers_int import * import sys + def failed(a, b, msg): - raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) + raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) + def compare_sequences(a, b): - if len(a) != len(b): - failed(a, b, "different sizes") - for i in range(len(a)): - if a[i] != b[i]: - failed(a, b, "elements are different") + if len(a) != len(b): + failed(a, b, "different sizes") + for i in range(len(a)): + if a[i] != b[i]: + failed(a, b, "elements are different") + def compare_containers(pythonlist, swigvector, swiglist): - compare_sequences(pythonlist, swigvector) - compare_sequences(pythonlist, swiglist) + compare_sequences(pythonlist, swigvector) + compare_sequences(pythonlist, swiglist) + +# Check std::vector and std::list assignment behaves same as Python list +# assignment including exceptions + -# Check std::vector and std::list assignment behaves same as Python list assignment including exceptions def container_insert_step(i, j, step, newval): - ps = range(6) - iv = vector_int(ps) - il = list_int(ps) - - # Python slice - try: - if step == None: - if j == None: - ps[i] = newval - else: - ps[i:j] = newval - else: - if j == None: - ps[i::step] = newval - else: - ps[i:j:step] = newval - ps_error = None - except ValueError, e: - ps_error = e - except IndexError, e: - ps_error = e - - # std::vector - try: - if step == None: - if j == None: - iv[i] = newval - else: - iv[i:j] = newval - else: - if j == None: - iv[i::step] = newval - else: - iv[i:j:step] = newval - iv_error = None - except ValueError, e: - iv_error = e - except IndexError, e: - iv_error = e - - # std::list - try: - if step == None: - if j == None: - il[i] = newval - else: - il[i:j] = newval - else: - if j == None: - il[i::step] = newval - else: - il[i:j:step] = newval - il_error = None - except ValueError, e: - il_error = e - except IndexError, e: - il_error = e - - # Python 2.6 contains bug fixes in extended slicing syntax: http://docs.python.org/2/whatsnew/2.6.html - skip_check = ps_error != None and(iv_error == il_error == None) and step > 0 and (sys.version_info[0:2] < (2, 6)) - if not(skip_check): + ps = range(6) + iv = vector_int(ps) + il = list_int(ps) + + # Python slice + try: + if step == None: + if j == None: + ps[i] = newval + else: + ps[i:j] = newval + else: + if j == None: + ps[i::step] = newval + else: + ps[i:j:step] = newval + ps_error = None + except ValueError, e: + ps_error = e + except IndexError, e: + ps_error = e + + # std::vector + try: + if step == None: + if j == None: + iv[i] = newval + else: + iv[i:j] = newval + else: + if j == None: + iv[i::step] = newval + else: + iv[i:j:step] = newval + iv_error = None + except ValueError, e: + iv_error = e + except IndexError, e: + iv_error = e + + # std::list + try: + if step == None: + if j == None: + il[i] = newval + else: + il[i:j] = newval + else: + if j == None: + il[i::step] = newval + else: + il[i:j:step] = newval + il_error = None + except ValueError, e: + il_error = e + except IndexError, e: + il_error = e + + # Python 2.6 contains bug fixes in extended slicing syntax: + # http://docs.python.org/2/whatsnew/2.6.html + skip_check = ps_error != None and( + iv_error == il_error == None) and step > 0 and (sys.version_info[0:2] < (2, 6)) + if not(skip_check): + if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))): + raise RuntimeError, "ValueError exception not consistently thrown: " + \ + str(ps_error) + " " + str(iv_error) + " " + str(il_error) + + compare_containers(ps, iv, il) + + +# Check std::vector and std::list delete behaves same as Python list +# delete including exceptions +def container_delete_step(i, j, step): + ps = range(6) + iv = vector_int(ps) + il = list_int(ps) + + # Python slice + try: + if step == None: + if j == None: + del ps[i] + else: + del ps[i:j] + else: + if j == None: + del ps[i::step] + else: + del ps[i:j:step] + ps_error = None + except ValueError, e: + ps_error = e + except IndexError, e: + ps_error = e + + # std::vector + try: + if step == None: + if j == None: + del iv[i] + else: + del iv[i:j] + else: + if j == None: + del iv[i::step] + else: + del iv[i:j:step] + iv_error = None + except ValueError, e: + iv_error = e + except IndexError, e: + iv_error = e + + # std::list + try: + if step == None: + if j == None: + del il[i] + else: + del il[i:j] + else: + if j == None: + del il[i::step] + else: + del il[i:j:step] + il_error = None + except ValueError, e: + il_error = e + except IndexError, e: + il_error = e + if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))): - raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error) + raise RuntimeError, "ValueError exception not consistently thrown: " + \ + str(ps_error) + " " + str(iv_error) + " " + str(il_error) compare_containers(ps, iv, il) -# Check std::vector and std::list delete behaves same as Python list delete including exceptions -def container_delete_step(i, j, step): - ps = range(6) - iv = vector_int(ps) - il = list_int(ps) - - # Python slice - try: - if step == None: - if j == None: - del ps[i] - else: - del ps[i:j] - else: - if j == None: - del ps[i::step] - else: - del ps[i:j:step] - ps_error = None - except ValueError, e: - ps_error = e - except IndexError, e: - ps_error = e - - # std::vector - try: - if step == None: - if j == None: - del iv[i] - else: - del iv[i:j] - else: - if j == None: - del iv[i::step] - else: - del iv[i:j:step] - iv_error = None - except ValueError, e: - iv_error = e - except IndexError, e: - iv_error = e - - # std::list - try: - if step == None: - if j == None: - del il[i] - else: - del il[i:j] - else: - if j == None: - del il[i::step] - else: - del il[i:j:step] - il_error = None - except ValueError, e: - il_error = e - except IndexError, e: - il_error = e - - if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))): - raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error) - - compare_containers(ps, iv, il) - - -ps = [0,1,2,3,4,5] +ps = [0, 1, 2, 3, 4, 5] iv = vector_int(ps) il = list_int(ps) @@ -164,7 +176,7 @@ def container_delete_step(i, j, step): compare_containers(ps[2:4], iv[2:4], il[2:4]) compare_containers(ps[0:3], iv[0:3], il[0:3]) compare_containers(ps[3:6], iv[3:6], il[3:6]) -compare_containers(ps[3:10], iv[3:10], il[3:10]) # beyond end of range +compare_containers(ps[3:10], iv[3:10], il[3:10]) # beyond end of range # before beginning of range (negative indexing) compare_containers(ps[-1:7], iv[-1:7], il[-1:7]) @@ -172,7 +184,8 @@ def container_delete_step(i, j, step): compare_containers(ps[-5:7], iv[-5:7], il[-5:7]) compare_containers(ps[-6:7], iv[-6:7], il[-6:7]) -# before beginning of range (negative indexing, negative index is > container size) +# before beginning of range (negative indexing, negative index is > +# container size) compare_containers(ps[-7:7], iv[-7:7], il[-7:7]) compare_containers(ps[-100:7], iv[-100:7], il[-100:7]) @@ -222,48 +235,52 @@ def container_delete_step(i, j, step): # insert sequences (growing, shrinking and staying same size) for start in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]: - # single element set/replace - container_insert_step(start, None, None, 111) - for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]: - container_insert_step(start, end, None, [111, 222, 333, 444, 555, 666, 777]) - container_insert_step(start, end, None, [111, 222, 333, 444, 555, 666]) - container_insert_step(start, end, None, [111, 222, 333, 444, 555]) - container_insert_step(start, end, None, [111, 222, 333, 444]) - container_insert_step(start, end, None, [111, 222, 333]) - container_insert_step(start, end, None, [111, 222]) - container_insert_step(start, end, None, [111]) - container_insert_step(start, end, None, []) + # single element set/replace + container_insert_step(start, None, None, 111) + for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]: + container_insert_step( + start, end, None, [111, 222, 333, 444, 555, 666, 777]) + container_insert_step(start, end, None, [111, 222, 333, 444, 555, 666]) + container_insert_step(start, end, None, [111, 222, 333, 444, 555]) + container_insert_step(start, end, None, [111, 222, 333, 444]) + container_insert_step(start, end, None, [111, 222, 333]) + container_insert_step(start, end, None, [111, 222]) + container_insert_step(start, end, None, [111]) + container_insert_step(start, end, None, []) # delete sequences (growing, shrinking and staying same size) for start in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]: - # single element delete - container_delete_step(start, None, None) - for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]: - container_delete_step(start, end, None) - for step in range(-7,7): - container_delete_step(start, end, step) + # single element delete + container_delete_step(start, None, None) + for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]: + container_delete_step(start, end, None) + for step in range(-7, 7): + container_delete_step(start, end, step) ps = range(6) iv = vector_int(ps) il = list_int(ps) -del ps[:]; del iv[:]; del il[:] +del ps[:] +del iv[:] +del il[:] compare_containers(ps, iv, il) for end in range(7): - for step in range(-7,7): - for start in range(7): - container_insert_step(start, end, step, [111, 222, 333, 444, 555, 666, 777]) - container_insert_step(start, end, step, [111, 222, 333, 444, 555, 666]) - container_insert_step(start, end, step, [111, 222, 333, 444, 555]) - container_insert_step(start, end, step, [111, 222, 333, 444]) - container_insert_step(start, end, step, [111, 222, 333]) - container_insert_step(start, end, step, [111, 222]) - container_insert_step(start, end, step, [111]) - container_insert_step(start, end, step, []) + for step in range(-7, 7): + for start in range(7): + container_insert_step( + start, end, step, [111, 222, 333, 444, 555, 666, 777]) + container_insert_step( + start, end, step, [111, 222, 333, 444, 555, 666]) + container_insert_step(start, end, step, [111, 222, 333, 444, 555]) + container_insert_step(start, end, step, [111, 222, 333, 444]) + container_insert_step(start, end, step, [111, 222, 333]) + container_insert_step(start, end, step, [111, 222]) + container_insert_step(start, end, step, [111]) + container_insert_step(start, end, step, []) try: - x = iv[::0] - raise RuntimeError("Zero step not caught") + x = iv[::0] + raise RuntimeError("Zero step not caught") except ValueError: - pass - + pass diff --git a/Examples/test-suite/python/li_std_except_as_class_runme.py b/Examples/test-suite/python/li_std_except_as_class_runme.py index a86e7a56275..36abb33f42a 100644 --- a/Examples/test-suite/python/li_std_except_as_class_runme.py +++ b/Examples/test-suite/python/li_std_except_as_class_runme.py @@ -3,17 +3,29 @@ # This test is expected to fail with -builtin option. # Throwing builtin classes as exceptions not supported if is_python_builtin(): - try: test_domain_error() - except RuntimeError: pass - try: test_domain_error() - except RuntimeError: pass - try: test_domain_error() - except RuntimeError: pass + try: + test_domain_error() + except RuntimeError: + pass + try: + test_domain_error() + except RuntimeError: + pass + try: + test_domain_error() + except RuntimeError: + pass else: - # std::domain_error hierarchy - try: test_domain_error() - except domain_error: pass - try: test_domain_error() - except logic_error: pass - try: test_domain_error() - except exception: pass + # std::domain_error hierarchy + try: + test_domain_error() + except domain_error: + pass + try: + test_domain_error() + except logic_error: + pass + try: + test_domain_error() + except exception: + pass diff --git a/Examples/test-suite/python/li_std_map_member_runme.py b/Examples/test-suite/python/li_std_map_member_runme.py index 8b5877dae93..d2044247276 100644 --- a/Examples/test-suite/python/li_std_map_member_runme.py +++ b/Examples/test-suite/python/li_std_map_member_runme.py @@ -3,9 +3,9 @@ a = li_std_map_member.mapita() a[1] = li_std_map_member.TestA() -if (a[1].i != 1) : +if (a[1].i != 1): raise RuntimeError("a[1] != 1") a[1].i = 2 -if (a[1].i != 2) : +if (a[1].i != 2): raise RuntimeError("a[1] != 2") diff --git a/Examples/test-suite/python/li_std_map_runme.py b/Examples/test-suite/python/li_std_map_runme.py index ae75bdda069..af3e1d989ef 100644 --- a/Examples/test-suite/python/li_std_map_runme.py +++ b/Examples/test-suite/python/li_std_map_runme.py @@ -4,8 +4,8 @@ a2 = li_std_map.A(7) -p0 = li_std_map.pairii(1,2) -p1 = li_std_map.pairA(1,a1.this) +p0 = li_std_map.pairii(1, 2) +p1 = li_std_map.pairA(1, a1.this) m = {} m[1] = a1 m[2] = a2 @@ -14,38 +14,33 @@ mm = li_std_map.m_identa(m) - m = li_std_map.mapA() m[1] = a1 m[2] = a2 -pm ={} +pm = {} for k in m: - pm[k] = m[k] - -for k in m: - if pm[k].this != m[k].this: - print pm[k], m[k] - raise RuntimeError - - + pm[k] = m[k] +for k in m: + if pm[k].this != m[k].this: + print pm[k], m[k] + raise RuntimeError m = {} -m[1] = (1,2) +m[1] = (1, 2) m["foo"] = "hello" pm = li_std_map.pymap() -for k in m: - pm[k] = m[k] - -for k in pm: - if (pm[k] != m[k]): - raise RuntimeError +for k in m: + pm[k] = m[k] +for k in pm: + if (pm[k] != m[k]): + raise RuntimeError mii = li_std_map.IntIntMap() @@ -54,5 +49,4 @@ mii[1] = 2 if mii[1] != 2: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/li_std_pair_extra_runme.py b/Examples/test-suite/python/li_std_pair_extra_runme.py index dc6e31b76c8..f26badf08ad 100644 --- a/Examples/test-suite/python/li_std_pair_extra_runme.py +++ b/Examples/test-suite/python/li_std_pair_extra_runme.py @@ -1,59 +1,58 @@ import li_std_pair_extra -p = (1,2) +p = (1, 2) p1 = li_std_pair_extra.p_inout(p) p2 = li_std_pair_extra.p_inoutd(p1) d1 = li_std_pair_extra.d_inout(2) -i,d2 = li_std_pair_extra.d_inout2(2) +i, d2 = li_std_pair_extra.d_inout2(2) -i,p = li_std_pair_extra.p_inout2(p) -p3,p4 = li_std_pair_extra.p_inout3(p1,p1) +i, p = li_std_pair_extra.p_inout2(p) +p3, p4 = li_std_pair_extra.p_inout3(p1, p1) -psi = li_std_pair_extra.SIPair("hello",1) -pci = li_std_pair_extra.CIPair(1,1) +psi = li_std_pair_extra.SIPair("hello", 1) +pci = li_std_pair_extra.CIPair(1, 1) #psi.first = "hi" -psi = li_std_pair_extra.SIPair("hi",1) -if psi != ("hi",1): - raise RuntimeError +psi = li_std_pair_extra.SIPair("hi", 1) +if psi != ("hi", 1): + raise RuntimeError -psii = li_std_pair_extra.SIIPair(psi,1) +psii = li_std_pair_extra.SIIPair(psi, 1) a = li_std_pair_extra.A() b = li_std_pair_extra.B() -pab = li_std_pair_extra.ABPair(a,b); +pab = li_std_pair_extra.ABPair(a, b) pab.first = a pab.first.val = 2 if pab.first.val != 2: - raise RuntimeError - + raise RuntimeError -pci = li_std_pair_extra.CIntPair(1,0) + +pci = li_std_pair_extra.CIntPair(1, 0) a = li_std_pair_extra.A(5) -p1 = li_std_pair_extra.pairP1(1,a.this) -p2 = li_std_pair_extra.pairP2(a,1) -p3 = li_std_pair_extra.pairP3(a,a) +p1 = li_std_pair_extra.pairP1(1, a.this) +p2 = li_std_pair_extra.pairP2(a, 1) +p3 = li_std_pair_extra.pairP3(a, a) if a.val != li_std_pair_extra.p_identa(p1.this)[1].val: - raise RuntimeError - -p = li_std_pair_extra.IntPair(1,10) + raise RuntimeError + +p = li_std_pair_extra.IntPair(1, 10) p.first = 1 -p = li_std_pair_extra.paircA1(1,a) +p = li_std_pair_extra.paircA1(1, a) p.first p.second -p = li_std_pair_extra.paircA2(1,a) -pp = li_std_pair_extra.pairiiA(1,p) - +p = li_std_pair_extra.paircA2(1, a) +pp = li_std_pair_extra.pairiiA(1, p) diff --git a/Examples/test-suite/python/li_std_pair_using_runme.py b/Examples/test-suite/python/li_std_pair_using_runme.py index a8b26103558..18f96223509 100644 --- a/Examples/test-suite/python/li_std_pair_using_runme.py +++ b/Examples/test-suite/python/li_std_pair_using_runme.py @@ -6,5 +6,4 @@ two = StringIntPair(two_tuple) if bounce(one) != one_tuple: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/li_std_set_runme.py b/Examples/test-suite/python/li_std_set_runme.py index 449333e73dc..ad3c6d881ef 100644 --- a/Examples/test-suite/python/li_std_set_runme.py +++ b/Examples/test-suite/python/li_std_set_runme.py @@ -25,7 +25,7 @@ b = s.begin() e = s.end() sum = "" -while (b != e): +while (b != e): sum = sum + b.next() if sum != "abc": raise RuntimeError @@ -33,14 +33,13 @@ b = s.rbegin() e = s.rend() sum = "" -while (b != e): - sum = sum + b.next() +while (b != e): + sum = sum + b.next() if sum != "cba": raise RuntimeError - si = set_int() si.append(1) @@ -56,8 +55,6 @@ raise RuntimeError - - i = s.begin() i.next() s.erase(i) @@ -65,7 +62,7 @@ b = s.begin() e = s.end() sum = "" -while (b != e): +while (b != e): sum = sum + b.next() if sum != "ac": raise RuntimeError @@ -75,22 +72,21 @@ e = s.end() if e - b != 2: raise RuntimeError - + m = b + 1 if m.value() != "c": raise RuntimeError - s = pyset() -s.insert((1,2)) +s.insert((1, 2)) s.insert(1) s.insert("hello") sum = () for i in s: - sum = sum + (i,) + sum = sum + (i,) -if (len(sum) != 3 or (not 1 in sum) or (not 'hello' in sum) or (not (1, 2) in sum)) : +if (len(sum) != 3 or (not 1 in sum) or (not 'hello' in sum) or (not (1, 2) in sum)): raise RuntimeError diff --git a/Examples/test-suite/python/li_std_stream_runme.py b/Examples/test-suite/python/li_std_stream_runme.py index d41e41f4a56..08c30885601 100644 --- a/Examples/test-suite/python/li_std_stream_runme.py +++ b/Examples/test-suite/python/li_std_stream_runme.py @@ -1,7 +1,6 @@ from li_std_stream import * - a = A() o = ostringstream() @@ -9,6 +8,6 @@ o << a << " " << 2345 << " " << 1.435 -if o.str() != "A class 2345 1.435": - print "\"%s\"" % (o.str(),) - raise RuntimeError +if o.str() != "A class 2345 1.435": + print "\"%s\"" % (o.str(),) + raise RuntimeError diff --git a/Examples/test-suite/python/li_std_string_extra_runme.py b/Examples/test-suite/python/li_std_string_extra_runme.py index 503d09eb500..b65f0774a2b 100644 --- a/Examples/test-suite/python/li_std_string_extra_runme.py +++ b/Examples/test-suite/python/li_std_string_extra_runme.py @@ -1,135 +1,134 @@ import li_std_string_extra -x="hello" - +x = "hello" if li_std_string_extra.test_ccvalue(x) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_cvalue(x) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_value(x) != x: - print x, li_std_string_extra.test_value(x) - raise RuntimeError, "bad string mapping" + print x, li_std_string_extra.test_value(x) + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_const_reference(x) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" s = li_std_string_extra.string("he") #s += "ll" -#s.append('o') +# s.append('o') s = s + "llo" if s != x: - print s, x - raise RuntimeError, "bad string mapping" + print s, x + raise RuntimeError, "bad string mapping" if s[1:4] != x[1:4]: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_value(s) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_const_reference(s) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" a = li_std_string_extra.A(s) if li_std_string_extra.test_value(a) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_const_reference(a) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" b = li_std_string_extra.string(" world") s = a + b if a + b != "hello world": - print a + b - raise RuntimeError, "bad string mapping" - + print a + b + raise RuntimeError, "bad string mapping" + if a + " world" != "hello world": - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" # This is expected to fail with -builtin option # Reverse operators not supported in builtin types if not li_std_string_extra.is_python_builtin(): - if "hello" + b != "hello world": - raise RuntimeError, "bad string mapping" + if "hello" + b != "hello world": + raise RuntimeError, "bad string mapping" + + c = "hello" + b + if c.find_last_of("l") != 9: + raise RuntimeError, "bad string mapping" - c = "hello" + b - if c.find_last_of("l") != 9: - raise RuntimeError, "bad string mapping" - s = "hello world" b = li_std_string_extra.B("hi") b.name = li_std_string_extra.string("hello") if b.name != "hello": - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" b.a = li_std_string_extra.A("hello") if b.a != "hello": - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_value_basic1(x) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_value_basic2(x) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" if li_std_string_extra.test_value_basic3(x) != x: - raise RuntimeError, "bad string mapping" + raise RuntimeError, "bad string mapping" # Global variables s = "initial string" if li_std_string_extra.cvar.GlobalString2 != "global string 2": - raise RuntimeError, "GlobalString2 test 1" + raise RuntimeError, "GlobalString2 test 1" li_std_string_extra.cvar.GlobalString2 = s if li_std_string_extra.cvar.GlobalString2 != s: - raise RuntimeError, "GlobalString2 test 2" + raise RuntimeError, "GlobalString2 test 2" if li_std_string_extra.cvar.ConstGlobalString != "const global string": - raise RuntimeError, "ConstGlobalString test" + raise RuntimeError, "ConstGlobalString test" # Member variables myStructure = li_std_string_extra.Structure() if myStructure.MemberString2 != "member string 2": - raise RuntimeError, "MemberString2 test 1" + raise RuntimeError, "MemberString2 test 1" myStructure.MemberString2 = s if myStructure.MemberString2 != s: - raise RuntimeError, "MemberString2 test 2" + raise RuntimeError, "MemberString2 test 2" if myStructure.ConstMemberString != "const member string": - raise RuntimeError, "ConstMemberString test" + raise RuntimeError, "ConstMemberString test" if li_std_string_extra.cvar.Structure_StaticMemberString2 != "static member string 2": - raise RuntimeError, "StaticMemberString2 test 1" + raise RuntimeError, "StaticMemberString2 test 1" li_std_string_extra.cvar.Structure_StaticMemberString2 = s if li_std_string_extra.cvar.Structure_StaticMemberString2 != s: - raise RuntimeError, "StaticMemberString2 test 2" + raise RuntimeError, "StaticMemberString2 test 2" if li_std_string_extra.cvar.Structure_ConstStaticMemberString != "const static member string": - raise RuntimeError, "ConstStaticMemberString test" + raise RuntimeError, "ConstStaticMemberString test" if li_std_string_extra.test_reference_input("hello") != "hello": - raise RuntimeError + raise RuntimeError s = li_std_string_extra.test_reference_inout("hello") if s != "hellohello": - raise RuntimeError + raise RuntimeError if li_std_string_extra.stdstring_empty() != "": - raise RuntimeError - + raise RuntimeError + if li_std_string_extra.c_empty() != "": - raise RuntimeError + raise RuntimeError if li_std_string_extra.c_null() != None: - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/li_std_vector_enum_runme.py b/Examples/test-suite/python/li_std_vector_enum_runme.py index a2c8534f3a0..318d1bff6a6 100644 --- a/Examples/test-suite/python/li_std_vector_enum_runme.py +++ b/Examples/test-suite/python/li_std_vector_enum_runme.py @@ -1,8 +1,9 @@ import li_std_vector_enum + def check(a, b): - if (a != b): - raise RuntimeError("Not equal: ", a, b) + if (a != b): + raise RuntimeError("Not equal: ", a, b) ev = li_std_vector_enum.EnumVector() @@ -17,8 +18,7 @@ def check(a, b): v = it.value() check(v, 20) -expected = 10 +expected = 10 for val in ev.nums: - check(val, expected) - expected += 10 - + check(val, expected) + expected += 10 diff --git a/Examples/test-suite/python/li_std_vector_extra_runme.py b/Examples/test-suite/python/li_std_vector_extra_runme.py index d24d36cb689..d541de6db07 100644 --- a/Examples/test-suite/python/li_std_vector_extra_runme.py +++ b/Examples/test-suite/python/li_std_vector_extra_runme.py @@ -1,110 +1,108 @@ from li_std_vector_extra import * iv = IntVector(4) -for i in range(0,4): +for i in range(0, 4): iv[i] = i x = average(iv) -y = average([1,2,3,4]) +y = average([1, 2, 3, 4]) -a = half([10,10.5,11,11.5]) +a = half([10, 10.5, 11, 11.5]) dv = DoubleVector(10) -for i in range(0,10): - dv[i] = i/2.0 +for i in range(0, 10): + dv[i] = i / 2.0 halve_in_place(dv) bv = BoolVector(4) -bv[0]= bool(1) -bv[1]= bool(0) -bv[2]= bool(4) -bv[3]= bool(0) +bv[0] = bool(1) +bv[1] = bool(0) +bv[2] = bool(4) +bv[3] = bool(0) if bv[0] != bv[2]: - raise RuntimeError,"bad std::vector mapping" + raise RuntimeError, "bad std::vector mapping" b = B(5) -va = VecA([b,None,b,b]) +va = VecA([b, None, b, b]) if va[0].f(1) != 6: - raise RuntimeError,"bad std::vector mapping" + raise RuntimeError, "bad std::vector mapping" if vecAptr(va) != 6: - raise RuntimeError,"bad std::vector mapping" + raise RuntimeError, "bad std::vector mapping" b.val = 7 if va[3].f(1) != 8: - raise RuntimeError,"bad std::vector mapping" + raise RuntimeError, "bad std::vector mapping" ip = PtrInt() ap = new_ArrInt(10) -ArrInt_setitem(ip,0,123) -ArrInt_setitem(ap,2,123) +ArrInt_setitem(ip, 0, 123) +ArrInt_setitem(ap, 2, 123) -vi = IntPtrVector((ip,ap,None)) -if ArrInt_getitem(vi[0],0) != ArrInt_getitem(vi[1],2): - raise RuntimeError,"bad std::vector mapping" +vi = IntPtrVector((ip, ap, None)) +if ArrInt_getitem(vi[0], 0) != ArrInt_getitem(vi[1], 2): + raise RuntimeError, "bad std::vector mapping" -delete_ArrInt(ap) +delete_ArrInt(ap) -a = halfs([10,8,4,3]) +a = halfs([10, 8, 4, 3]) v = IntVector() -v[0:2] = [1,2] +v[0:2] = [1, 2] if v[0] != 1 or v[1] != 2: - raise RuntimeError,"bad setslice" + raise RuntimeError, "bad setslice" if v[0:-1][0] != 1: - raise RuntimeError,"bad getslice" + raise RuntimeError, "bad getslice" if v[0:-2].size() != 0: - raise RuntimeError,"bad getslice" + raise RuntimeError, "bad getslice" v[0:1] = [2] if v[0] != 2: - raise RuntimeError,"bad setslice" + raise RuntimeError, "bad setslice" v[1:] = [3] if v[1] != 3: - raise RuntimeError,"bad setslice" + raise RuntimeError, "bad setslice" v[2:] = [3] if v[2] != 3: - raise RuntimeError,"bad setslice" + raise RuntimeError, "bad setslice" if v[0:][0] != v[0]: - raise RuntimeError,"bad getslice" + raise RuntimeError, "bad getslice" del v[:] if v.size() != 0: - raise RuntimeError,"bad getslice" + raise RuntimeError, "bad getslice" del v[:] if v.size() != 0: - raise RuntimeError,"bad getslice" - + raise RuntimeError, "bad getslice" v = vecStr(["hello ", "world"]) if v[0] != 'hello world': - raise RuntimeError,"bad std::string+std::vector" - + raise RuntimeError, "bad std::string+std::vector" -pv = pyvector([1, "hello", (1,2)]) +pv = pyvector([1, "hello", (1, 2)]) if pv[1] != "hello": raise RuntimeError iv = IntVector(5) -for i in range(0,5): +for i in range(0, 5): iv[i] = i iv[1:3] = [] @@ -113,25 +111,25 @@ # Overloading checks if overloaded1(iv) != "vector": - raise RuntimeError + raise RuntimeError if overloaded1(dv) != "vector": - raise RuntimeError + raise RuntimeError if overloaded2(iv) != "vector": - raise RuntimeError + raise RuntimeError if overloaded2(dv) != "vector": - raise RuntimeError + raise RuntimeError if overloaded3(iv) != "vector *": - raise RuntimeError + raise RuntimeError if overloaded3(None) != "vector *": - raise RuntimeError + raise RuntimeError if overloaded3(100) != "int": - raise RuntimeError + raise RuntimeError # vector pointer checks @@ -139,38 +137,39 @@ dp = makeDoublePtr(33.3) error = 0 try: - vi = IntPtrVector((ip, dp)) # check vector does not accept double * element - error = 1 + # check vector does not accept double * element + vi = IntPtrVector((ip, dp)) + error = 1 except: - pass + pass if error: - raise RuntimeError + raise RuntimeError vi = IntPtrVector((ip, makeIntPtr(22))) if extractInt(vi[0]) != 11: - raise RuntimeError + raise RuntimeError if extractInt(vi[1]) != 22: - raise RuntimeError + raise RuntimeError # vector const pointer checks csp = makeConstShortPtr(111) error = 0 try: - vcs = ConstShortPtrVector((csp, dp)) # check vector does not accept double * element - error = 1 + # check vector does not accept double * element + vcs = ConstShortPtrVector((csp, dp)) + error = 1 except: - pass + pass if error: - raise RuntimeError + raise RuntimeError vcs = ConstShortPtrVector((csp, makeConstShortPtr(222))) if extractConstShort(vcs[0]) != 111: - raise RuntimeError + raise RuntimeError if extractConstShort(vcs[1]) != 222: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/li_std_vector_ptr_runme.py b/Examples/test-suite/python/li_std_vector_ptr_runme.py index c5f72fde45f..01c654109f3 100644 --- a/Examples/test-suite/python/li_std_vector_ptr_runme.py +++ b/Examples/test-suite/python/li_std_vector_ptr_runme.py @@ -5,4 +5,3 @@ vi = IntPtrVector((ip1, ip2)) displayVector(vi) - diff --git a/Examples/test-suite/python/li_std_wstream_runme.py b/Examples/test-suite/python/li_std_wstream_runme.py index f7379bdf861..045645b6155 100644 --- a/Examples/test-suite/python/li_std_wstream_runme.py +++ b/Examples/test-suite/python/li_std_wstream_runme.py @@ -1,13 +1,12 @@ from li_std_wstream import * - a = A() o = wostringstream() o << a << u" " << 2345 << u" " << 1.435 << wends -if o.str() != "A class 2345 1.435\0": - print "\"%s\"" % (o.str(),) - raise RuntimeError +if o.str() != "A class 2345 1.435\0": + print "\"%s\"" % (o.str(),) + raise RuntimeError diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py index a467ae8bc34..e93196b809c 100644 --- a/Examples/test-suite/python/li_std_wstring_runme.py +++ b/Examples/test-suite/python/li_std_wstring_runme.py @@ -1,85 +1,83 @@ import li_std_wstring -x=u"h" +x = u"h" if li_std_wstring.test_wcvalue(x) != x: - print li_std_wstring.test_wcvalue(x) - raise RuntimeError("bad string mapping") + print li_std_wstring.test_wcvalue(x) + raise RuntimeError("bad string mapping") -x=u"hello" +x = u"hello" if li_std_wstring.test_ccvalue(x) != x: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") if li_std_wstring.test_cvalue(x) != x: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") if li_std_wstring.test_wchar_overload(x) != x: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") if li_std_wstring.test_wchar_overload("not unicode") != "not unicode": - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") if li_std_wstring.test_value(x) != x: - print x, li_std_wstring.test_value(x) - raise RuntimeError("bad string mapping") + print x, li_std_wstring.test_value(x) + raise RuntimeError("bad string mapping") if li_std_wstring.test_const_reference(x) != x: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") s = li_std_wstring.wstring(u"he") s = s + u"llo" if s != x: - print s, x - raise RuntimeError("bad string mapping") + print s, x + raise RuntimeError("bad string mapping") if s[1:4] != x[1:4]: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") if li_std_wstring.test_value(s) != x: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") if li_std_wstring.test_const_reference(s) != x: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") a = li_std_wstring.A(s) if li_std_wstring.test_value(a) != x: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") if li_std_wstring.test_const_reference(a) != x: - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") b = li_std_wstring.wstring(" world") if a + b != "hello world": - raise RuntimeError("bad string mapping") - + raise RuntimeError("bad string mapping") + if a + " world" != "hello world": - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") # This is expected to fail if -builtin is used # Reverse operators not supported in builtin types if not li_std_wstring.is_python_builtin(): - if "hello" + b != "hello world": - raise RuntimeError("bad string mapping") + if "hello" + b != "hello world": + raise RuntimeError("bad string mapping") + + c = "hello" + b + if c.find_last_of("l") != 9: + raise RuntimeError("bad string mapping") - c = "hello" + b - if c.find_last_of("l") != 9: - raise RuntimeError("bad string mapping") - s = "hello world" b = li_std_wstring.B("hi") b.name = li_std_wstring.wstring(u"hello") if b.name != "hello": - raise RuntimeError("bad string mapping") + raise RuntimeError("bad string mapping") b.a = li_std_wstring.A("hello") if b.a != u"hello": - raise RuntimeError("bad string mapping") - - + raise RuntimeError("bad string mapping") diff --git a/Examples/test-suite/python/member_pointer_runme.py b/Examples/test-suite/python/member_pointer_runme.py index 3d68e916d57..5ae7ab9a4b9 100644 --- a/Examples/test-suite/python/member_pointer_runme.py +++ b/Examples/test-suite/python/member_pointer_runme.py @@ -2,9 +2,11 @@ from member_pointer import * + def check(what, expected, actual): - if expected != actual: - raise RuntimeError ("Failed: " , what , " Expected: " , expected , " Actual: " , actual) + if expected != actual: + raise RuntimeError( + "Failed: ", what, " Expected: ", expected, " Actual: ", actual) # Get the pointers @@ -17,20 +19,20 @@ def check(what, expected, actual): # Do some calculations -check ("Square area ", 100.0, do_op(s,area_pt)) -check ("Square perim", 40.0, do_op(s,perim_pt)) +check("Square area ", 100.0, do_op(s, area_pt)) +check("Square perim", 40.0, do_op(s, perim_pt)) memberPtr = cvar.areavar memberPtr = cvar.perimetervar # Try the variables -check ("Square area ", 100.0, do_op(s,cvar.areavar)) -check ("Square perim", 40.0, do_op(s,cvar.perimetervar)) +check("Square area ", 100.0, do_op(s, cvar.areavar)) +check("Square perim", 40.0, do_op(s, cvar.perimetervar)) # Modify one of the variables cvar.areavar = perim_pt -check ("Square perimeter", 40.0, do_op(s,cvar.areavar)) +check("Square perimeter", 40.0, do_op(s, cvar.areavar)) # Try the constants @@ -38,9 +40,9 @@ def check(what, expected, actual): memberPtr = PERIMPT memberPtr = NULLPT -check ("Square area ", 100.0, do_op(s,AREAPT)) -check ("Square perim", 40.0, do_op(s,PERIMPT)) +check("Square area ", 100.0, do_op(s, AREAPT)) +check("Square perim", 40.0, do_op(s, PERIMPT)) -check ("Add by value", 3, call1(ADD_BY_VALUE, 1, 2)) -check ("Add by pointer", 7, call2(ADD_BY_POINTER, 3, 4)) -check ("Add by reference", 11, call3(ADD_BY_REFERENCE, 5, 6)) +check("Add by value", 3, call1(ADD_BY_VALUE, 1, 2)) +check("Add by pointer", 7, call2(ADD_BY_POINTER, 3, 4)) +check("Add by reference", 11, call3(ADD_BY_REFERENCE, 5, 6)) diff --git a/Examples/test-suite/python/memberin_extend_c_runme.py b/Examples/test-suite/python/memberin_extend_c_runme.py index 314761f8920..da601ae2a95 100644 --- a/Examples/test-suite/python/memberin_extend_c_runme.py +++ b/Examples/test-suite/python/memberin_extend_c_runme.py @@ -3,4 +3,4 @@ t = memberin_extend_c.Person() t.name = "Fred Bloggs" if t.name != "FRED BLOGGS": - raise RuntimeError("name wrong") + raise RuntimeError("name wrong") diff --git a/Examples/test-suite/python/minherit_runme.py b/Examples/test-suite/python/minherit_runme.py index d7ad0b36b47..b7e7d019c67 100644 --- a/Examples/test-suite/python/minherit_runme.py +++ b/Examples/test-suite/python/minherit_runme.py @@ -10,26 +10,28 @@ raise RuntimeError, "Bad attribute value" if b.yget() != 2: - raise RuntimeError, "Bad attribute value" + raise RuntimeError, "Bad attribute value" if c.xget() != 1 or c.yget() != 2 or c.zget() != 3: - raise RuntimeError, "Bad attribute value" + raise RuntimeError, "Bad attribute value" if d.xget() != 1 or d.yget() != 2 or d.zget() != 3 or d.wget() != 4: - raise RuntimeError, "Bad attribute value" + raise RuntimeError, "Bad attribute value" if minherit.xget(a) != 1: - raise RuntimeError, "Bad attribute value %d" % (minherit.xget(a)) + raise RuntimeError, "Bad attribute value %d" % (minherit.xget(a)) if minherit.yget(b) != 2: - raise RuntimeError, "Bad attribute value %d" % (minherit.yget(b)) + raise RuntimeError, "Bad attribute value %d" % (minherit.yget(b)) if minherit.xget(c) != 1 or minherit.yget(c) != 2 or minherit.zget(c) != 3: - raise RuntimeError, "Bad attribute value %d %d %d" % (minherit.xget(c), minherit.yget(c), minherit.zget(c)) + raise RuntimeError, "Bad attribute value %d %d %d" % ( + minherit.xget(c), minherit.yget(c), minherit.zget(c)) if minherit.xget(d) != 1 or minherit.yget(d) != 2 or minherit.zget(d) != 3 or minherit.wget(d) != 4: - raise RuntimeError, "Bad attribute value %d %d %d %d" % (minherit.xget(d), minherit.yget(d), minherit.zget(d), minherit.wget(d)) + raise RuntimeError, "Bad attribute value %d %d %d %d" % ( + minherit.xget(d), minherit.yget(d), minherit.zget(d), minherit.wget(d)) # Cleanse all of the pointers and see what happens @@ -42,30 +44,24 @@ raise RuntimeError, "Bad attribute value" if bb.yget() != 2: - raise RuntimeError, "Bad attribute value" + raise RuntimeError, "Bad attribute value" if cc.xget() != 1 or cc.yget() != 2 or cc.zget() != 3: - raise RuntimeError, "Bad attribute value" + raise RuntimeError, "Bad attribute value" if dd.xget() != 1 or dd.yget() != 2 or dd.zget() != 3 or dd.wget() != 4: - raise RuntimeError, "Bad attribute value" + raise RuntimeError, "Bad attribute value" if minherit.xget(aa) != 1: - raise RuntimeError, "Bad attribute value %d" % (minherit.xget(aa)) + raise RuntimeError, "Bad attribute value %d" % (minherit.xget(aa)) if minherit.yget(bb) != 2: - raise RuntimeError, "Bad attribute value %d" % (minherit.yget(bb)) + raise RuntimeError, "Bad attribute value %d" % (minherit.yget(bb)) if minherit.xget(cc) != 1 or minherit.yget(cc) != 2 or minherit.zget(cc) != 3: - raise RuntimeError, "Bad attribute value %d %d %d" % (minherit.xget(cc), minherit.yget(cc), minherit.zget(cc)) + raise RuntimeError, "Bad attribute value %d %d %d" % ( + minherit.xget(cc), minherit.yget(cc), minherit.zget(cc)) if minherit.xget(dd) != 1 or minherit.yget(dd) != 2 or minherit.zget(dd) != 3 or minherit.wget(dd) != 4: - raise RuntimeError, "Bad attribute value %d %d %d %d" % (minherit.xget(dd), minherit.yget(dd), minherit.zget(dd), minherit.wget(dd)) - - - - - - - - + raise RuntimeError, "Bad attribute value %d %d %d %d" % ( + minherit.xget(dd), minherit.yget(dd), minherit.zget(dd), minherit.wget(dd)) diff --git a/Examples/test-suite/python/multi_import_runme.py b/Examples/test-suite/python/multi_import_runme.py index f8a2f19c7a1..27f86a9ef8f 100644 --- a/Examples/test-suite/python/multi_import_runme.py +++ b/Examples/test-suite/python/multi_import_runme.py @@ -3,16 +3,16 @@ x = multi_import_b.XXX() if x.testx() != 0: - raise RuntimeError + raise RuntimeError y = multi_import_b.YYY() if y.testx() != 0: - raise RuntimeError + raise RuntimeError if y.testy() != 1: - raise RuntimeError + raise RuntimeError z = multi_import_a.ZZZ() if z.testx() != 0: - raise RuntimeError + raise RuntimeError if z.testz() != 2: - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/namespace_class_runme.py b/Examples/test-suite/python/namespace_class_runme.py index d139527b769..e0bd3ca09f5 100644 --- a/Examples/test-suite/python/namespace_class_runme.py +++ b/Examples/test-suite/python/namespace_class_runme.py @@ -1,24 +1,31 @@ from namespace_class import * + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + try: - p = Private1() - error = 1 + p = Private1() + error = 1 except: - error = 0 + error = 0 if (error): - raise RuntimeError, "Private1 is private" + raise RuntimeError, "Private1 is private" try: - p = Private2() - error = 1 + p = Private2() + error = 1 except: - error = 0 + error = 0 if (error): - raise RuntimeError, "Private2 is private" + raise RuntimeError, "Private2 is private" -EulerT3D.toFrame(1,1,1) +if is_new_style_class(EulerT3D): + EulerT3D.toFrame(1, 1, 1) +else: + EulerT3D().toFrame(1, 1, 1) b = BooT_i() b = BooT_H() @@ -33,6 +40,7 @@ f = FooT_H() f.foo(Hi) -f_type = str(type(f)) -if f_type.find("'namespace_class.FooT_H'") == -1: - raise RuntimeError("Incorrect type: " + f_type) +if is_new_style_class(FooT_H): + f_type = str(type(f)) + if f_type.find("'namespace_class.FooT_H'") == -1: + raise RuntimeError("Incorrect type: " + f_type) diff --git a/Examples/test-suite/python/namespace_typemap_runme.py b/Examples/test-suite/python/namespace_typemap_runme.py index 682ad3bb122..14379496d4c 100644 --- a/Examples/test-suite/python/namespace_typemap_runme.py +++ b/Examples/test-suite/python/namespace_typemap_runme.py @@ -36,7 +36,7 @@ if stest12("hello") != "hello": raise RuntimeError -c = complex(2,3) +c = complex(2, 3) r = c.real if ctest1(c) != r: diff --git a/Examples/test-suite/python/nested_template_base_runme.py b/Examples/test-suite/python/nested_template_base_runme.py index 3d54b8391b3..fc5844300df 100644 --- a/Examples/test-suite/python/nested_template_base_runme.py +++ b/Examples/test-suite/python/nested_template_base_runme.py @@ -1,13 +1,13 @@ from nested_template_base import * -ois = InnerS(123); -oic = InnerC(); +ois = InnerS(123) +oic = InnerC() # Check base method is available if (oic.outer(ois).val != 123): - raise RuntimeError("Wrong value calling outer"); + raise RuntimeError("Wrong value calling outer") # Check non-derived class using base class if (oic.innerc().outer(ois).val != 123): - raise RuntimeError("Wrong value calling innerc"); + raise RuntimeError("Wrong value calling innerc") diff --git a/Examples/test-suite/python/nested_workaround_runme.py b/Examples/test-suite/python/nested_workaround_runme.py index a8a75d37088..c11299ed4fd 100644 --- a/Examples/test-suite/python/nested_workaround_runme.py +++ b/Examples/test-suite/python/nested_workaround_runme.py @@ -4,10 +4,10 @@ outer = Outer() newInner = outer.doubleInnerValue(inner) if newInner.getValue() != 10: - raise RuntimeError + raise RuntimeError outer = Outer() inner = outer.createInner(3) newInner = outer.doubleInnerValue(inner) if outer.getInnerValue(newInner) != 6: - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/operbool_runme.py b/Examples/test-suite/python/operbool_runme.py index 4218b5dd45f..708dea786ba 100644 --- a/Examples/test-suite/python/operbool_runme.py +++ b/Examples/test-suite/python/operbool_runme.py @@ -1,4 +1,3 @@ #!/usr/bin/env python import operbool assert not operbool.Test() - diff --git a/Examples/test-suite/python/overload_bool_runme.py b/Examples/test-suite/python/overload_bool_runme.py index ed7d1b5a15e..8192b37ced9 100644 --- a/Examples/test-suite/python/overload_bool_runme.py +++ b/Examples/test-suite/python/overload_bool_runme.py @@ -2,25 +2,25 @@ # Overloading bool, int, string if overload_bool.overloaded(True) != "bool": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded(False) != "bool": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded(0) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded(1) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded(2) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded("1234") != "string": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") # Test bool masquerading as int if overload_bool.intfunction(True) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.intfunction(False) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") # Test int masquerading as bool # Not possible @@ -30,26 +30,25 @@ # Overloading bool, int, string if overload_bool.overloaded_ref(True) != "bool": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded_ref(False) != "bool": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded_ref(0) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded_ref(1) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded_ref(2) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.overloaded_ref("1234") != "string": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") # Test bool masquerading as int if overload_bool.intfunction_ref(True) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") if overload_bool.intfunction_ref(False) != "int": - raise RuntimeError("wrong!") + raise RuntimeError("wrong!") # Test int masquerading as bool # Not possible - diff --git a/Examples/test-suite/python/overload_complicated_runme.py b/Examples/test-suite/python/overload_complicated_runme.py index 2b7467d4d6a..9c039a0a537 100644 --- a/Examples/test-suite/python/overload_complicated_runme.py +++ b/Examples/test-suite/python/overload_complicated_runme.py @@ -7,41 +7,41 @@ p = Pop(pInt, 0) -# Check overloaded in const only and pointers/references which target languages cannot disambiguate +# Check overloaded in const only and pointers/references which target +# languages cannot disambiguate if p.hip(0) != 701: - raise RuntimeError,"Test 1 failed" + raise RuntimeError, "Test 1 failed" if p.hip(pInt) != 702: - raise RuntimeError,"Test 2 failed" + raise RuntimeError, "Test 2 failed" # Reverse the order for the above if p.hop(pInt) != 805: - raise RuntimeError,"Test 3 failed" + raise RuntimeError, "Test 3 failed" if p.hop(0) != 801: - raise RuntimeError,"Test 4 failed" + raise RuntimeError, "Test 4 failed" # Few more variations and order shuffled if p.pop(0) != 901: - raise RuntimeError,"Test 5 failed" + raise RuntimeError, "Test 5 failed" if p.pop(pInt) != 902: - raise RuntimeError,"Test 6 failed" + raise RuntimeError, "Test 6 failed" if p.pop() != 905: - raise RuntimeError,"Test 7 failed" + raise RuntimeError, "Test 7 failed" # Overload on const only if p.bop(pInt) != 1001: - raise RuntimeError,"Test 8 failed" + raise RuntimeError, "Test 8 failed" if p.bip(pInt) != 2001: - raise RuntimeError,"Test 9 failed" + raise RuntimeError, "Test 9 failed" # Globals if muzak(0) != 3001: - raise RuntimeError,"Test 10 failed" + raise RuntimeError, "Test 10 failed" if muzak(pInt) != 3002: - raise RuntimeError,"Test 11 failed" - + raise RuntimeError, "Test 11 failed" diff --git a/Examples/test-suite/python/overload_extendc_runme.py b/Examples/test-suite/python/overload_extend2_runme.py similarity index 56% rename from Examples/test-suite/python/overload_extendc_runme.py rename to Examples/test-suite/python/overload_extend2_runme.py index cea3ea61863..923a9a7e34b 100644 --- a/Examples/test-suite/python/overload_extendc_runme.py +++ b/Examples/test-suite/python/overload_extend2_runme.py @@ -1,22 +1,21 @@ -import overload_extendc +import overload_extend2 -f = overload_extendc.Foo() +f = overload_extend2.Foo() if f.test(3) != 1: raise RuntimeError if f.test("hello") != 2: raise RuntimeError -if f.test(3.5,2.5) != 3: +if f.test(3.5, 2.5) != 3: raise RuntimeError -if f.test("hello",20) != 1020: +if f.test("hello", 20) != 1020: raise RuntimeError -if f.test("hello",20,100) != 120: +if f.test("hello", 20, 100) != 120: raise RuntimeError # C default args if f.test(f) != 30: raise RuntimeError -if f.test(f,100) != 120: +if f.test(f, 100) != 120: raise RuntimeError -if f.test(f,100,200) != 300: +if f.test(f, 100, 200) != 300: raise RuntimeError - diff --git a/Examples/test-suite/python/overload_extend_c_runme.py b/Examples/test-suite/python/overload_extend_c_runme.py new file mode 100644 index 00000000000..35e6811f58f --- /dev/null +++ b/Examples/test-suite/python/overload_extend_c_runme.py @@ -0,0 +1,13 @@ +import overload_extend_c + +f = overload_extend_c.Foo() +if f.test() != 0: + raise RuntimeError +if f.test(3) != 1: + raise RuntimeError +if f.test("hello") != 2: + raise RuntimeError +if f.test(3, 2) != 5: + raise RuntimeError +if f.test(3.0) != 1003: + raise RuntimeError diff --git a/Examples/test-suite/python/overload_extend_runme.py b/Examples/test-suite/python/overload_extend_runme.py index 7d08d482bcb..4a8a0165e21 100644 --- a/Examples/test-suite/python/overload_extend_runme.py +++ b/Examples/test-suite/python/overload_extend_runme.py @@ -7,8 +7,7 @@ raise RuntimeError if f.test("hello") != 2: raise RuntimeError -if f.test(3,2) != 5: +if f.test(3, 2) != 5: raise RuntimeError if f.test(3.0) != 1003: raise RuntimeError - diff --git a/Examples/test-suite/python/overload_numeric_runme.py b/Examples/test-suite/python/overload_numeric_runme.py index 639fb5e5dd0..9f3382d8666 100644 --- a/Examples/test-suite/python/overload_numeric_runme.py +++ b/Examples/test-suite/python/overload_numeric_runme.py @@ -5,9 +5,10 @@ nums = Nums() limits = Limits() + def check(got, expected): - if got != expected: - raise RuntimeError("got: " + got + " expected: " + expected) + if got != expected: + raise RuntimeError("got: " + got + " expected: " + expected) check(nums.over(0), "signed char") check(nums.over(0.0), "float") @@ -15,21 +16,21 @@ def check(got, expected): check(nums.over(limits.schar_min()), "signed char") check(nums.over(limits.schar_max()), "signed char") -check(nums.over(limits.schar_min()-1), "short") -check(nums.over(limits.schar_max()+1), "short") +check(nums.over(limits.schar_min() - 1), "short") +check(nums.over(limits.schar_max() + 1), "short") check(nums.over(limits.shrt_min()), "short") check(nums.over(limits.shrt_max()), "short") -check(nums.over(limits.shrt_min()-1), "int") -check(nums.over(limits.shrt_max()+1), "int") +check(nums.over(limits.shrt_min() - 1), "int") +check(nums.over(limits.shrt_max() + 1), "int") check(nums.over(limits.int_min()), "int") check(nums.over(limits.int_max()), "int") check(nums.over(limits.flt_min()), "float") check(nums.over(limits.flt_max()), "float") -check(nums.over(limits.flt_max()*10), "double") -check(nums.over(-limits.flt_max()*10), "double") +check(nums.over(limits.flt_max() * 10), "double") +check(nums.over(-limits.flt_max() * 10), "double") check(nums.over(limits.dbl_max()), "double") check(nums.over(-limits.dbl_max()), "double") diff --git a/Examples/test-suite/python/overload_rename_runme.py b/Examples/test-suite/python/overload_rename_runme.py index b192f7d5d8a..dcad1b95a24 100644 --- a/Examples/test-suite/python/overload_rename_runme.py +++ b/Examples/test-suite/python/overload_rename_runme.py @@ -2,7 +2,6 @@ f = overload_rename.Foo(1) -f = overload_rename.Foo(1,1) -f = overload_rename.Foo_int(1,1) -f = overload_rename.Foo_int(1,1,1) - +f = overload_rename.Foo(1, 1) +f = overload_rename.Foo_int(1, 1) +f = overload_rename.Foo_int(1, 1, 1) diff --git a/Examples/test-suite/python/overload_simple_runme.py b/Examples/test-suite/python/overload_simple_runme.py index a78f3720a25..6d72ec0810d 100644 --- a/Examples/test-suite/python/overload_simple_runme.py +++ b/Examples/test-suite/python/overload_simple_runme.py @@ -70,7 +70,7 @@ s = Spam(3) if s.type != "int": raise RuntimeError, "Spam(int)" - + s = Spam(3.4) if s.type != "double": raise RuntimeError, "Spam(double)" @@ -92,9 +92,6 @@ raise RuntimeError, "Spam(void *)" - - - free_void(v) diff --git a/Examples/test-suite/python/overload_subtype_runme.py b/Examples/test-suite/python/overload_subtype_runme.py index 6bf77dc5942..3f32a5583de 100644 --- a/Examples/test-suite/python/overload_subtype_runme.py +++ b/Examples/test-suite/python/overload_subtype_runme.py @@ -8,4 +8,3 @@ if spam(b) != 2: raise RuntimeError, "bar" - diff --git a/Examples/test-suite/python/overload_template_fast_runme.py b/Examples/test-suite/python/overload_template_fast_runme.py index d47f7d14d4e..95349a9b133 100644 --- a/Examples/test-suite/python/overload_template_fast_runme.py +++ b/Examples/test-suite/python/overload_template_fast_runme.py @@ -1,79 +1,84 @@ from overload_template_fast import * + + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + f = foo() -a = maximum(3,4) -b = maximum(3.4,5.2) +a = maximum(3, 4) +b = maximum(3.4, 5.2) # mix 1 if (mix1("hi") != 101): - raise RuntimeError, ("mix1(const char*)") + raise RuntimeError, ("mix1(const char*)") if (mix1(1.0, 1.0) != 102): - raise RuntimeError, ("mix1(double, const double &)") + raise RuntimeError, ("mix1(double, const double &)") if (mix1(1.0) != 103): - raise RuntimeError, ("mix1(double)") + raise RuntimeError, ("mix1(double)") # mix 2 if (mix2("hi") != 101): - raise RuntimeError, ("mix2(const char*)") + raise RuntimeError, ("mix2(const char*)") if (mix2(1.0, 1.0) != 102): - raise RuntimeError, ("mix2(double, const double &)") + raise RuntimeError, ("mix2(double, const double &)") if (mix2(1.0) != 103): - raise RuntimeError, ("mix2(double)") + raise RuntimeError, ("mix2(double)") # mix 3 if (mix3("hi") != 101): - raise RuntimeError, ("mix3(const char*)") + raise RuntimeError, ("mix3(const char*)") if (mix3(1.0, 1.0) != 102): - raise RuntimeError, ("mix3(double, const double &)") + raise RuntimeError, ("mix3(double, const double &)") if (mix3(1.0) != 103): - raise RuntimeError, ("mix3(double)") + raise RuntimeError, ("mix3(double)") # Combination 1 if (overtparams1(100) != 10): - raise RuntimeError, ("overtparams1(int)") + raise RuntimeError, ("overtparams1(int)") if (overtparams1(100.0, 100) != 20): - raise RuntimeError, ("overtparams1(double, int)") + raise RuntimeError, ("overtparams1(double, int)") # Combination 2 if (overtparams2(100.0, 100) != 40): - raise RuntimeError, ("overtparams2(double, int)") + raise RuntimeError, ("overtparams2(double, int)") # Combination 3 if (overloaded() != 60): - raise RuntimeError, ("overloaded()") + raise RuntimeError, ("overloaded()") if (overloaded(100.0, 100) != 70): - raise RuntimeError, ("overloaded(double, int)") + raise RuntimeError, ("overloaded(double, int)") # Combination 4 if (overloadedagain("hello") != 80): - raise RuntimeError, ("overloadedagain(const char *)") + raise RuntimeError, ("overloadedagain(const char *)") if (overloadedagain() != 90): - raise RuntimeError, ("overloadedagain(double)") + raise RuntimeError, ("overloadedagain(double)") # specializations if (specialization(10) != 202): - raise RuntimeError, ("specialization(int)") + raise RuntimeError, ("specialization(int)") if (specialization(10.0) != 203): - raise RuntimeError, ("specialization(double)") + raise RuntimeError, ("specialization(double)") if (specialization(10, 10) != 204): - raise RuntimeError, ("specialization(int, int)") + raise RuntimeError, ("specialization(int, int)") if (specialization(10.0, 10.0) != 205): - raise RuntimeError, ("specialization(double, double)") + raise RuntimeError, ("specialization(double, double)") if (specialization("hi", "hi") != 201): - raise RuntimeError, ("specialization(const char *, const char *)") + raise RuntimeError, ("specialization(const char *, const char *)") # simple specialization @@ -83,63 +88,66 @@ # a bit of everything if (overload("hi") != 0): - raise RuntimeError, ("overload()") + raise RuntimeError, ("overload()") if (overload(1) != 10): - raise RuntimeError, ("overload(int t)") + raise RuntimeError, ("overload(int t)") if (overload(1, 1) != 20): - raise RuntimeError, ("overload(int t, const int &)") + raise RuntimeError, ("overload(int t, const int &)") if (overload(1, "hello") != 30): - raise RuntimeError, ("overload(int t, const char *)") + raise RuntimeError, ("overload(int t, const char *)") k = Klass() if (overload(k) != 10): - raise RuntimeError, ("overload(Klass t)") + raise RuntimeError, ("overload(Klass t)") if (overload(k, k) != 20): - raise RuntimeError, ("overload(Klass t, const Klass &)") + raise RuntimeError, ("overload(Klass t, const Klass &)") if (overload(k, "hello") != 30): - raise RuntimeError, ("overload(Klass t, const char *)") + raise RuntimeError, ("overload(Klass t, const char *)") if (overload(10.0, "hi") != 40): - raise RuntimeError, ("overload(double t, const char *)") + raise RuntimeError, ("overload(double t, const char *)") if (overload() != 50): - raise RuntimeError, ("overload(const char *)") + raise RuntimeError, ("overload(const char *)") # everything put in a namespace if (nsoverload("hi") != 1000): - raise RuntimeError, ("nsoverload()") + raise RuntimeError, ("nsoverload()") if (nsoverload(1) != 1010): - raise RuntimeError, ("nsoverload(int t)") + raise RuntimeError, ("nsoverload(int t)") if (nsoverload(1, 1) != 1020): - raise RuntimeError, ("nsoverload(int t, const int &)") + raise RuntimeError, ("nsoverload(int t, const int &)") if (nsoverload(1, "hello") != 1030): - raise RuntimeError, ("nsoverload(int t, const char *)") + raise RuntimeError, ("nsoverload(int t, const char *)") if (nsoverload(k) != 1010): - raise RuntimeError, ("nsoverload(Klass t)") + raise RuntimeError, ("nsoverload(Klass t)") if (nsoverload(k, k) != 1020): - raise RuntimeError, ("nsoverload(Klass t, const Klass &)") + raise RuntimeError, ("nsoverload(Klass t, const Klass &)") if (nsoverload(k, "hello") != 1030): - raise RuntimeError, ("nsoverload(Klass t, const char *)") + raise RuntimeError, ("nsoverload(Klass t, const char *)") if (nsoverload(10.0, "hi") != 1040): - raise RuntimeError, ("nsoverload(double t, const char *)") + raise RuntimeError, ("nsoverload(double t, const char *)") if (nsoverload() != 1050): - raise RuntimeError, ("nsoverload(const char *)") + raise RuntimeError, ("nsoverload(const char *)") -A.foo(1) +if is_new_style_class(A): + A.foo(1) +else: + A_foo(1) b = B() b.foo(1) diff --git a/Examples/test-suite/python/overload_template_runme.py b/Examples/test-suite/python/overload_template_runme.py index c1337ba6a0b..014ec71cbb0 100644 --- a/Examples/test-suite/python/overload_template_runme.py +++ b/Examples/test-suite/python/overload_template_runme.py @@ -1,79 +1,79 @@ from overload_template import * f = foo() -a = maximum(3,4) -b = maximum(3.4,5.2) +a = maximum(3, 4) +b = maximum(3.4, 5.2) # mix 1 if (mix1("hi") != 101): - raise RuntimeError, ("mix1(const char*)") + raise RuntimeError, ("mix1(const char*)") if (mix1(1.0, 1.0) != 102): - raise RuntimeError, ("mix1(double, const double &)") + raise RuntimeError, ("mix1(double, const double &)") if (mix1(1.0) != 103): - raise RuntimeError, ("mix1(double)") + raise RuntimeError, ("mix1(double)") # mix 2 if (mix2("hi") != 101): - raise RuntimeError, ("mix2(const char*)") + raise RuntimeError, ("mix2(const char*)") if (mix2(1.0, 1.0) != 102): - raise RuntimeError, ("mix2(double, const double &)") + raise RuntimeError, ("mix2(double, const double &)") if (mix2(1.0) != 103): - raise RuntimeError, ("mix2(double)") + raise RuntimeError, ("mix2(double)") # mix 3 if (mix3("hi") != 101): - raise RuntimeError, ("mix3(const char*)") + raise RuntimeError, ("mix3(const char*)") if (mix3(1.0, 1.0) != 102): - raise RuntimeError, ("mix3(double, const double &)") + raise RuntimeError, ("mix3(double, const double &)") if (mix3(1.0) != 103): - raise RuntimeError, ("mix3(double)") + raise RuntimeError, ("mix3(double)") # Combination 1 if (overtparams1(100) != 10): - raise RuntimeError, ("overtparams1(int)") + raise RuntimeError, ("overtparams1(int)") if (overtparams1(100.0, 100) != 20): - raise RuntimeError, ("overtparams1(double, int)") + raise RuntimeError, ("overtparams1(double, int)") # Combination 2 if (overtparams2(100.0, 100) != 40): - raise RuntimeError, ("overtparams2(double, int)") + raise RuntimeError, ("overtparams2(double, int)") # Combination 3 if (overloaded() != 60): - raise RuntimeError, ("overloaded()") + raise RuntimeError, ("overloaded()") if (overloaded(100.0, 100) != 70): - raise RuntimeError, ("overloaded(double, int)") + raise RuntimeError, ("overloaded(double, int)") # Combination 4 if (overloadedagain("hello") != 80): - raise RuntimeError, ("overloadedagain(const char *)") + raise RuntimeError, ("overloadedagain(const char *)") if (overloadedagain() != 90): - raise RuntimeError, ("overloadedagain(double)") + raise RuntimeError, ("overloadedagain(double)") # specializations if (specialization(10) != 202): - raise RuntimeError, ("specialization(int)") + raise RuntimeError, ("specialization(int)") if (specialization(10.0) != 203): - raise RuntimeError, ("specialization(double)") + raise RuntimeError, ("specialization(double)") if (specialization(10, 10) != 204): - raise RuntimeError, ("specialization(int, int)") + raise RuntimeError, ("specialization(int, int)") if (specialization(10.0, 10.0) != 205): - raise RuntimeError, ("specialization(double, double)") + raise RuntimeError, ("specialization(double, double)") if (specialization("hi", "hi") != 201): - raise RuntimeError, ("specialization(const char *, const char *)") + raise RuntimeError, ("specialization(const char *, const char *)") # simple specialization @@ -83,61 +83,61 @@ # a bit of everything if (overload("hi") != 0): - raise RuntimeError, ("overload()") + raise RuntimeError, ("overload()") if (overload(1) != 10): - raise RuntimeError, ("overload(int t)") + raise RuntimeError, ("overload(int t)") if (overload(1, 1) != 20): - raise RuntimeError, ("overload(int t, const int &)") + raise RuntimeError, ("overload(int t, const int &)") if (overload(1, "hello") != 30): - raise RuntimeError, ("overload(int t, const char *)") + raise RuntimeError, ("overload(int t, const char *)") k = Klass() if (overload(k) != 10): - raise RuntimeError, ("overload(Klass t)") + raise RuntimeError, ("overload(Klass t)") if (overload(k, k) != 20): - raise RuntimeError, ("overload(Klass t, const Klass &)") + raise RuntimeError, ("overload(Klass t, const Klass &)") if (overload(k, "hello") != 30): - raise RuntimeError, ("overload(Klass t, const char *)") + raise RuntimeError, ("overload(Klass t, const char *)") if (overload(10.0, "hi") != 40): - raise RuntimeError, ("overload(double t, const char *)") + raise RuntimeError, ("overload(double t, const char *)") if (overload() != 50): - raise RuntimeError, ("overload(const char *)") + raise RuntimeError, ("overload(const char *)") # everything put in a namespace if (nsoverload("hi") != 1000): - raise RuntimeError, ("nsoverload()") + raise RuntimeError, ("nsoverload()") if (nsoverload(1) != 1010): - raise RuntimeError, ("nsoverload(int t)") + raise RuntimeError, ("nsoverload(int t)") if (nsoverload(1, 1) != 1020): - raise RuntimeError, ("nsoverload(int t, const int &)") + raise RuntimeError, ("nsoverload(int t, const int &)") if (nsoverload(1, "hello") != 1030): - raise RuntimeError, ("nsoverload(int t, const char *)") + raise RuntimeError, ("nsoverload(int t, const char *)") if (nsoverload(k) != 1010): - raise RuntimeError, ("nsoverload(Klass t)") + raise RuntimeError, ("nsoverload(Klass t)") if (nsoverload(k, k) != 1020): - raise RuntimeError, ("nsoverload(Klass t, const Klass &)") + raise RuntimeError, ("nsoverload(Klass t, const Klass &)") if (nsoverload(k, "hello") != 1030): - raise RuntimeError, ("nsoverload(Klass t, const char *)") + raise RuntimeError, ("nsoverload(Klass t, const char *)") if (nsoverload(10.0, "hi") != 1040): - raise RuntimeError, ("nsoverload(double t, const char *)") + raise RuntimeError, ("nsoverload(double t, const char *)") if (nsoverload() != 1050): - raise RuntimeError, ("nsoverload(const char *)") + raise RuntimeError, ("nsoverload(const char *)") A_foo(1) diff --git a/Examples/test-suite/python/pointer_reference_runme.py b/Examples/test-suite/python/pointer_reference_runme.py index e1a1a1f4b71..b9b47881d9d 100644 --- a/Examples/test-suite/python/pointer_reference_runme.py +++ b/Examples/test-suite/python/pointer_reference_runme.py @@ -2,15 +2,15 @@ s = pointer_reference.get() if s.value != 10: - raise RuntimeError, "get test failed" + raise RuntimeError, "get test failed" ss = pointer_reference.Struct(20) pointer_reference.set(ss) if pointer_reference.cvar.Struct_instance.value != 20: - raise RuntimeError, "set test failed" + raise RuntimeError, "set test failed" if pointer_reference.overloading(1) != 111: - raise RuntimeError, "overload test 1 failed" + raise RuntimeError, "overload test 1 failed" if pointer_reference.overloading(ss) != 222: - raise RuntimeError, "overload test 2 failed" + raise RuntimeError, "overload test 2 failed" diff --git a/Examples/test-suite/python/preproc_defined_runme.py b/Examples/test-suite/python/preproc_defined_runme.py index 9a295533a55..af46816be34 100644 --- a/Examples/test-suite/python/preproc_defined_runme.py +++ b/Examples/test-suite/python/preproc_defined_runme.py @@ -1,7 +1,7 @@ import preproc_defined if preproc_defined.call_checking() != 1: - raise RuntimeError + raise RuntimeError d = preproc_defined.Defined() d.defined = 10 diff --git a/Examples/test-suite/python/preproc_include_runme.py b/Examples/test-suite/python/preproc_include_runme.py index 778de3c87e0..7c3a360cea5 100644 --- a/Examples/test-suite/python/preproc_include_runme.py +++ b/Examples/test-suite/python/preproc_include_runme.py @@ -1,23 +1,22 @@ import preproc_include if preproc_include.multiply10(10) != 100: - raise RuntimeError + raise RuntimeError if preproc_include.multiply20(10) != 200: - raise RuntimeError + raise RuntimeError if preproc_include.multiply30(10) != 300: - raise RuntimeError + raise RuntimeError if preproc_include.multiply40(10) != 400: - raise RuntimeError + raise RuntimeError if preproc_include.multiply50(10) != 500: - raise RuntimeError + raise RuntimeError if preproc_include.multiply60(10) != 600: - raise RuntimeError + raise RuntimeError if preproc_include.multiply70(10) != 700: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/preproc_runme.py b/Examples/test-suite/python/preproc_runme.py index 3049f00abd6..99a6d0307ab 100644 --- a/Examples/test-suite/python/preproc_runme.py +++ b/Examples/test-suite/python/preproc_runme.py @@ -1,16 +1,16 @@ import preproc if preproc.endif != 1: - raise RuntimeError + raise RuntimeError if preproc.define != 1: - raise RuntimeError + raise RuntimeError if preproc.defined != 1: - raise RuntimeError + raise RuntimeError -if 2*preproc.one != preproc.two: - raise RuntimeError +if 2 * preproc.one != preproc.two: + raise RuntimeError if preproc.methodX(99) != 199: - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index d4173b7d314..b2060a028e1 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -1,3 +1,4 @@ +import sys from primitive_types import * var_init() @@ -28,81 +29,142 @@ v_check() + def pyerror(name, val, cte): - print "bad val/cte", name, val, cte - raise RuntimeError - pass - -if cvar.var_bool != cct_bool: pyerror("bool", cvar.var_bool, cct_bool) -if cvar.var_schar != cct_schar: pyerror("schar", cvar.var_schar, cct_schar) -if cvar.var_uchar != cct_uchar: pyerror("uchar", cvar.var_uchar, cct_uchar) -if cvar.var_int != cct_int: pyerror("int", cvar.var_int, cct_int) -if cvar.var_uint != cct_uint: pyerror("uint", cvar.var_uint, cct_uint) -if cvar.var_short != cct_short: pyerror("short", cvar.var_short, cct_short) -if cvar.var_ushort != cct_ushort: pyerror("ushort", cvar.var_ushort, cct_ushort) -if cvar.var_long != cct_long: pyerror("long", cvar.var_long, cct_long) -if cvar.var_ulong != cct_ulong: pyerror("ulong", cvar.var_ulong, cct_ulong) -if cvar.var_llong != cct_llong: pyerror("llong", cvar.var_llong, cct_llong) -if cvar.var_ullong != cct_ullong: pyerror("ullong", cvar.var_ullong, cct_ullong) -if cvar.var_char != cct_char: pyerror("char", cvar.var_char, cct_char) -if cvar.var_pchar != cct_pchar: pyerror("pchar", cvar.var_pchar, cct_pchar) -if cvar.var_pcharc != cct_pcharc: pyerror("pchar", cvar.var_pcharc, cct_pcharc) -if cvar.var_pint != cct_pint: pyerror("pint", cvar.var_pint, cct_pint) -if cvar.var_sizet != cct_sizet: pyerror("sizet", cvar.var_sizet, cct_sizet) -if cvar.var_hello != cct_hello: pyerror("hello", cvar.var_hello, cct_hello) -if cvar.var_myint != cct_myint: pyerror("myint", cvar.var_myint, cct_myint) -if cvar.var_namet != def_namet: pyerror("name", cvar.var_namet, def_namet) + print "bad val/cte", name, val, cte + raise RuntimeError + pass + +if cvar.var_bool != cct_bool: + pyerror("bool", cvar.var_bool, cct_bool) +if cvar.var_schar != cct_schar: + pyerror("schar", cvar.var_schar, cct_schar) +if cvar.var_uchar != cct_uchar: + pyerror("uchar", cvar.var_uchar, cct_uchar) +if cvar.var_int != cct_int: + pyerror("int", cvar.var_int, cct_int) +if cvar.var_uint != cct_uint: + pyerror("uint", cvar.var_uint, cct_uint) +if cvar.var_short != cct_short: + pyerror("short", cvar.var_short, cct_short) +if cvar.var_ushort != cct_ushort: + pyerror("ushort", cvar.var_ushort, cct_ushort) +if cvar.var_long != cct_long: + pyerror("long", cvar.var_long, cct_long) +if cvar.var_ulong != cct_ulong: + pyerror("ulong", cvar.var_ulong, cct_ulong) +if cvar.var_llong != cct_llong: + pyerror("llong", cvar.var_llong, cct_llong) +if cvar.var_ullong != cct_ullong: + pyerror("ullong", cvar.var_ullong, cct_ullong) +if cvar.var_char != cct_char: + pyerror("char", cvar.var_char, cct_char) +if cvar.var_pchar != cct_pchar: + pyerror("pchar", cvar.var_pchar, cct_pchar) +if cvar.var_pcharc != cct_pcharc: + pyerror("pchar", cvar.var_pcharc, cct_pcharc) +if cvar.var_pint != cct_pint: + pyerror("pint", cvar.var_pint, cct_pint) +if cvar.var_sizet != cct_sizet: + pyerror("sizet", cvar.var_sizet, cct_sizet) +if cvar.var_hello != cct_hello: + pyerror("hello", cvar.var_hello, cct_hello) +if cvar.var_myint != cct_myint: + pyerror("myint", cvar.var_myint, cct_myint) +if cvar.var_namet != def_namet: + pyerror("name", cvar.var_namet, def_namet) + class PyTest (TestDirector): - def __init__(self): - TestDirector.__init__(self) + + def __init__(self): + TestDirector.__init__(self) + pass + + def ident(self, x): + return x + + def vval_bool(self, x): return self.ident(x) + + def vval_schar(self, x): return self.ident(x) + + def vval_uchar(self, x): return self.ident(x) + + def vval_int(self, x): return self.ident(x) + + def vval_uint(self, x): return self.ident(x) + + def vval_short(self, x): return self.ident(x) + + def vval_ushort(self, x): return self.ident(x) + + def vval_long(self, x): return self.ident(x) + + def vval_ulong(self, x): return self.ident(x) + + def vval_llong(self, x): return self.ident(x) + + def vval_ullong(self, x): return self.ident(x) + + def vval_float(self, x): return self.ident(x) + + def vval_double(self, x): return self.ident(x) + + def vval_char(self, x): return self.ident(x) + + def vval_pchar(self, x): return self.ident(x) + + def vval_pcharc(self, x): return self.ident(x) + + def vval_pint(self, x): return self.ident(x) + + def vval_sizet(self, x): return self.ident(x) + + def vval_hello(self, x): return self.ident(x) + + def vval_myint(self, x): return self.ident(x) + + def vref_bool(self, x): return self.ident(x) + + def vref_schar(self, x): return self.ident(x) + + def vref_uchar(self, x): return self.ident(x) + + def vref_int(self, x): return self.ident(x) + + def vref_uint(self, x): return self.ident(x) + + def vref_short(self, x): return self.ident(x) + + def vref_ushort(self, x): return self.ident(x) + + def vref_long(self, x): return self.ident(x) + + def vref_ulong(self, x): return self.ident(x) + + def vref_llong(self, x): return self.ident(x) + + def vref_ullong(self, x): return self.ident(x) + + def vref_float(self, x): return self.ident(x) + + def vref_double(self, x): return self.ident(x) + + def vref_char(self, x): return self.ident(x) + + def vref_pchar(self, x): return self.ident(x) + + def vref_pcharc(self, x): return self.ident(x) + + def vref_pint(self, x): return self.ident(x) + + def vref_sizet(self, x): return self.ident(x) + + def vref_hello(self, x): return self.ident(x) + + def vref_myint(self, x): return self.ident(x) + pass - def ident(self, x): - return x - - def vval_bool(self, x): return self.ident(x) - def vval_schar(self, x): return self.ident(x) - def vval_uchar(self, x): return self.ident(x) - def vval_int(self, x): return self.ident(x) - def vval_uint(self, x): return self.ident(x) - def vval_short(self, x): return self.ident(x) - def vval_ushort(self, x): return self.ident(x) - def vval_long(self, x): return self.ident(x) - def vval_ulong(self, x): return self.ident(x) - def vval_llong(self, x): return self.ident(x) - def vval_ullong(self, x): return self.ident(x) - def vval_float(self, x): return self.ident(x) - def vval_double(self, x): return self.ident(x) - def vval_char(self, x): return self.ident(x) - def vval_pchar(self, x): return self.ident(x) - def vval_pcharc(self, x): return self.ident(x) - def vval_pint(self, x): return self.ident(x) - def vval_sizet(self, x): return self.ident(x) - def vval_hello(self, x): return self.ident(x) - def vval_myint(self, x): return self.ident(x) - - def vref_bool(self, x): return self.ident(x) - def vref_schar(self, x): return self.ident(x) - def vref_uchar(self, x): return self.ident(x) - def vref_int(self, x): return self.ident(x) - def vref_uint(self, x): return self.ident(x) - def vref_short(self, x): return self.ident(x) - def vref_ushort(self, x): return self.ident(x) - def vref_long(self, x): return self.ident(x) - def vref_ulong(self, x): return self.ident(x) - def vref_llong(self, x): return self.ident(x) - def vref_ullong(self, x): return self.ident(x) - def vref_float(self, x): return self.ident(x) - def vref_double(self, x): return self.ident(x) - def vref_char(self, x): return self.ident(x) - def vref_pchar(self, x): return self.ident(x) - def vref_pcharc(self, x): return self.ident(x) - def vref_pint(self, x): return self.ident(x) - def vref_sizet(self, x): return self.ident(x) - def vref_hello(self, x): return self.ident(x) - def vref_myint(self, x): return self.ident(x) - - pass t = Test() @@ -111,7 +173,7 @@ def vref_myint(self, x): return self.ident(x) # internal call check if t.c_check() != p.c_check(): - raise RuntimeError, "bad director" + raise RuntimeError, "bad director" p.var_bool = p.stc_bool p.var_schar = p.stc_schar @@ -166,63 +228,63 @@ def vref_myint(self, x): return self.ident(x) # this value contains a '0' char! if def_namet != 'hola': - print "bad namet", def_namet - raise RuntimeError + print "bad namet", def_namet + raise RuntimeError t.var_namet = def_namet if t.var_namet != def_namet: - print "bad namet", t.var_namet, def_namet - raise RuntimeError + print "bad namet", t.var_namet, def_namet + raise RuntimeError t.var_namet = 'hola' if t.var_namet != 'hola': - print "bad namet", t.var_namet - raise RuntimeError + print "bad namet", t.var_namet + raise RuntimeError t.var_namet = 'hol' if t.var_namet != 'hol': -#if t.var_namet != 'hol\0\0': - print "bad namet", t.var_namet - raise RuntimeError + # if t.var_namet != 'hol\0\0': + print "bad namet", t.var_namet + raise RuntimeError cvar.var_char = '\0' if cvar.var_char != '\0': - raise RuntimeError, "bad char '0' case" - + raise RuntimeError, "bad char '0' case" + cvar.var_char = 0 if cvar.var_char != '\0': - raise RuntimeError, "bad char '0' case" + raise RuntimeError, "bad char '0' case" cvar.var_namet = '\0' -#if cvar.var_namet != '\0\0\0\0\0': +# if cvar.var_namet != '\0\0\0\0\0': if cvar.var_namet != '': - print 'hola', '', cvar.var_namet - raise RuntimeError, "bad char '\0' case" + print 'hola', '', cvar.var_namet + raise RuntimeError, "bad char '\0' case" cvar.var_namet = '' -#if cvar.var_namet != '\0\0\0\0\0': +# if cvar.var_namet != '\0\0\0\0\0': if cvar.var_namet != '': - raise RuntimeError, "bad char empty case" + raise RuntimeError, "bad char empty case" cvar.var_pchar = None if cvar.var_pchar != None: - raise RuntimeError, "bad None case" + raise RuntimeError, "bad None case" cvar.var_pchar = '' if cvar.var_pchar != '': - print '%c' % (cvar.var_pchar[0],) - raise RuntimeError, "bad char empty case" + print '%c' % (cvar.var_pchar[0],) + raise RuntimeError, "bad char empty case" cvar.var_pcharc = None if cvar.var_pcharc != None: - raise RuntimeError, "bad None case" + raise RuntimeError, "bad None case" cvar.var_pcharc = '' if cvar.var_pcharc != '': - raise RuntimeError, "bad char empty case" + raise RuntimeError, "bad char empty case" # @@ -238,13 +300,13 @@ def vref_myint(self, x): return self.ident(x) cvar.var_pchar = pc if cvar.var_pchar != "hola": - print cvar.var_pchar - raise RuntimeError, "bad pointer case" + print cvar.var_pchar + raise RuntimeError, "bad pointer case" cvar.var_namet = pc -#if cvar.var_namet != "hola\0": +# if cvar.var_namet != "hola\0": if cvar.var_namet != "hola": - raise RuntimeError, "bad pointer case" + raise RuntimeError, "bad pointer case" delete_pchar(pc) @@ -254,125 +316,296 @@ def vref_myint(self, x): return self.ident(x) try: - error = 0 - a = t.var_uchar - t.var_uchar = 10000 - error = 1 -except OverflowError: - if a != t.var_uchar: + error = 0 + a = t.var_uchar + t.var_uchar = 10000 error = 1 - pass +except OverflowError: + if a != t.var_uchar: + error = 1 + pass if error: - raise RuntimeError, "bad uchar typemap" - + raise RuntimeError, "bad uchar typemap" try: - error = 0 - a = t.var_char - t.var_char = '23' - error = 1 -except TypeError: - if a != t.var_char: + error = 0 + a = t.var_char + t.var_char = '23' error = 1 - pass +except TypeError: + if a != t.var_char: + error = 1 + pass if error: - raise RuntimeError, "bad char typemap" + raise RuntimeError, "bad char typemap" try: - error = 0 - a = t.var_ushort - t.var_ushort = -1 - error = 1 -except OverflowError: - if a != t.var_ushort: + error = 0 + a = t.var_ushort + t.var_ushort = -1 error = 1 - pass +except OverflowError: + if a != t.var_ushort: + error = 1 + pass if error: - raise RuntimeError, "bad ushort typemap" + raise RuntimeError, "bad ushort typemap" try: - error = 0 - a = t.var_uint - t.var_uint = -1 - error = 1 -except OverflowError: - if a != t.var_uint: + error = 0 + a = t.var_uint + t.var_uint = -1 error = 1 - pass +except OverflowError: + if a != t.var_uint: + error = 1 + pass if error: - raise RuntimeError, "bad uint typemap" + raise RuntimeError, "bad uint typemap" try: - error = 0 - a = t.var_sizet - t.var_sizet = -1 - error = 1 -except OverflowError: - if a != t.var_sizet: + error = 0 + a = t.var_sizet + t.var_sizet = -1 error = 1 - pass +except OverflowError: + if a != t.var_sizet: + error = 1 + pass if error: - raise RuntimeError, "bad sizet typemap" + raise RuntimeError, "bad sizet typemap" try: - error = 0 - a = t.var_ulong - t.var_ulong = -1 - error = 1 -except OverflowError: - if a != t.var_ulong: + error = 0 + a = t.var_ulong + t.var_ulong = -1 error = 1 - pass +except OverflowError: + if a != t.var_ulong: + error = 1 + pass if error: - raise RuntimeError, "bad ulong typemap" + raise RuntimeError, "bad ulong typemap" # # try: - error = 0 - a = t.var_namet - t.var_namet = '123456' - error = 1 -except TypeError: - if a != t.var_namet: + error = 0 + a = t.var_namet + t.var_namet = '123456' error = 1 - pass +except TypeError: + if a != t.var_namet: + error = 1 + pass if error: - raise RuntimeError, "bad namet typemap" + raise RuntimeError, "bad namet typemap" # # # t2 = p.vtest(t) -if t.var_namet != t2.var_namet: - raise RuntimeError, "bad SWIGTYPE* typemap" - +if t.var_namet != t2.var_namet: + raise RuntimeError, "bad SWIGTYPE* typemap" + if cvar.fixsize != 'ho\0la\0\0\0': - raise RuntimeError, "bad FIXSIZE typemap" + raise RuntimeError, "bad FIXSIZE typemap" cvar.fixsize = 'ho' if cvar.fixsize != 'ho\0\0\0\0\0\0': - raise RuntimeError, "bad FIXSIZE typemap" + raise RuntimeError, "bad FIXSIZE typemap" f = Foo(3) f1 = fptr_val(f) f2 = fptr_ref(f) if f1._a != f2._a: - raise RuntimeError, "bad const ptr& typemap" - + raise RuntimeError, "bad const ptr& typemap" + + +v = char_foo(1, 3) +if v != 3: + raise RuntimeError, "bad int typemap" -v = char_foo(1,3) -if v !=3: - raise RuntimeError, "bad int typemap" +s = char_foo(1, "hello") +if s != "hello": + raise RuntimeError, "bad char* typemap" -s = char_foo(1,"hello") -if s !="hello": - raise RuntimeError, "bad char* typemap" - -v = SetPos(1,3) -if v !=4: - raise RuntimeError, "bad int typemap" +v = SetPos(1, 3) +if v != 4: + raise RuntimeError, "bad int typemap" + +# +# Check the bounds for converting various types +# + +# ctypes not available until 2.5 +if sys.version_info[0:2] <= (2, 4): + sys.exit(0) +import ctypes + +# Get the minimum and maximum values that fit in signed char, short, int, long, and long long +overchar = 2 ** 7 +while ctypes.c_byte(overchar).value > 0: + overchar *= 2 +minchar = -overchar +maxchar = overchar - 1 +maxuchar = 2 * maxchar + 1 +overshort = overchar +while ctypes.c_short(overshort).value > 0: + overshort *= 2 +minshort = -overshort +maxshort = overshort - 1 +maxushort = 2 * maxshort + 1 +overint = overshort +while ctypes.c_int(overint).value > 0: + overint *= 2 +minint = -overint +maxint = overint - 1 +maxuint = 2 * maxint + 1 +overlong = overint +while ctypes.c_long(overlong).value > 0: + overlong *= 2 +minlong = -overlong +maxlong = overlong - 1 +maxulong = 2 * maxlong + 1 +overllong = overlong +while ctypes.c_longlong(overllong).value > 0: + overllong *= 2 +minllong = -overllong +maxllong = overllong - 1 +maxullong = 2 * maxllong + 1 + +# Make sure Python 2's sys.maxint is the same as the maxlong we calculated +if sys.version_info[0] <= 2 and maxlong != sys.maxint: + raise RuntimeError, "sys.maxint is not the maximum value of a signed long" + +def checkType(t, e, val, delta): + """t = Test object, e = type name (e.g. ulong), val = max or min allowed value, delta = +1 for max, -1 for min""" + error = 0 + # Set the extreme valid value for var_* + setattr(t, 'var_' + e, val) + # Make sure it was set properly and works properly in the val_* and ref_* methods + if getattr(t, 'var_' + e) != val or getattr(t, 'val_' + e)(val) != val or getattr(t, 'ref_' + e)(val) != val: + error = 1 + # Make sure setting a more extreme value fails without changing the value + try: + a = getattr(t, 'var_' + e) + setattr(t, 'var_' + e, val + delta) + error = 1 + except OverflowError: + if a != getattr(t, 'var_' + e): + error = 1 + # Make sure the val_* and ref_* methods fail with a more extreme value + try: + getattr(t, 'val_' + e)(val + delta) + error = 1 + except OverflowError: + pass + try: + getattr(t, 'ref_' + e)(val + delta) + error = 1 + except OverflowError: + pass + if error: + raise RuntimeError, "bad " + e + " typemap" + +def checkFull(t, e, maxval, minval): + """Check the maximum and minimum bounds for the type given by e""" + checkType(t, e, maxval, 1) + checkType(t, e, minval, -1) + +checkFull(t, 'llong', maxllong, minllong) +checkFull(t, 'long', maxlong, minlong) +checkFull(t, 'int', maxint, minint) +checkFull(t, 'short', maxshort, minshort) +checkFull(t, 'schar', maxchar, minchar) +checkFull(t, 'ullong', maxullong, 0) +checkFull(t, 'ulong', maxulong, 0) +checkFull(t, 'uint', maxuint, 0) +checkFull(t, 'ushort', maxushort, 0) +checkFull(t, 'uchar', maxuchar, 0) + +def checkOverload(t, name, val, delta, prevval, limit): + """ + Check that overloading works + t = Test object + name = type name (e.g. ulong) + val = max or min allowed value + delta = +1 for max, -1 for min + prevval = corresponding value for one smaller type + limit = most extreme value for any type + """ + # If val == prevval, then the smaller typemap will win + if val != prevval: + # Make sure the most extreme value of this type gives the name of this type + if t.ovr_str(val) != name: + raise RuntimeError, "bad " + name + " typemap" + # Make sure a more extreme value doesn't give the name of this type + try: + if t.ovr_str(val + delta) == name: + raise RuntimeError, "bad " + name + " typemap" + if val == limit: + # Should raise NotImplementedError here since this is the largest integral type + raise RuntimeError, "bad " + name + " typemap" + except NotImplementedError: + # NotImplementedError is expected only if this is the most extreme type + if val != limit: + raise RuntimeError, "bad " + name + " typemap" + except TypeError: + # TypeError is raised instead if swig is run with -O or -fastdispatch + if val != limit: + raise RuntimeError, "bad " + name + " typemap" + +# Check that overloading works: uchar > schar > ushort > short > uint > int > ulong > long > ullong > llong +checkOverload(t, 'uchar', maxuchar, +1, 0, maxullong) +checkOverload(t, 'ushort', maxushort, +1, maxuchar, maxullong) +checkOverload(t, 'uint', maxuint, +1, maxushort, maxullong) +checkOverload(t, 'ulong', maxulong, +1, maxuint, maxullong) +checkOverload(t, 'ullong', maxullong, +1, maxulong, maxullong) +checkOverload(t, 'schar', minchar, -1, 0, minllong) +checkOverload(t, 'short', minshort, -1, minchar, minllong) +checkOverload(t, 'int', minint, -1, minshort, minllong) +checkOverload(t, 'long', minlong, -1, minint, minllong) +checkOverload(t, 'llong', minllong, -1, minlong, minllong) + +# Make sure that large ints can be converted to doubles properly +if val_double(sys.maxint + 1) != float(sys.maxint + 1): + raise RuntimeError, "bad double typemap" +if val_double(-sys.maxint - 2) != float(-sys.maxint - 2): + raise RuntimeError, "bad double typemap" + + +# Check the minimum and maximum values that fit in ptrdiff_t and size_t +def checkType(name, maxfunc, maxval, minfunc, minval, echofunc): + if maxfunc() != maxval: + raise RuntimeError, "bad " + name + " typemap" + if minfunc() != minval: + raise RuntimeError, "bad " + name + " typemap" + if echofunc(maxval) != maxval: + raise RuntimeError, "bad " + name + " typemap" + if echofunc(minval) != minval: + raise RuntimeError, "bad " + name + " typemap" + error = 0 + try: + echofunc(maxval + 1) + error = 1 + except OverflowError: + pass + if error == 1: + raise RuntimeError, "bad " + name + " typemap" + try: + echofunc(minval - 1) + error = 1 + except OverflowError: + pass + if error == 1: + raise RuntimeError, "bad " + name + " typemap" + +# sys.maxsize is the largest value supported by Py_ssize_t, which should be the same as ptrdiff_t +if sys.version_info[0:2] >= (2, 6): + checkType("ptrdiff_t", get_ptrdiff_max, sys.maxsize, get_ptrdiff_min, -(sys.maxsize + 1), ptrdiff_echo) + checkType("size_t", get_size_max, (2 * sys.maxsize) + 1, get_size_min, 0, size_echo) diff --git a/Examples/test-suite/python/profiletest_runme.py b/Examples/test-suite/python/profiletest_runme.py index d4f07dc11b9..1e5851e8850 100644 --- a/Examples/test-suite/python/profiletest_runme.py +++ b/Examples/test-suite/python/profiletest_runme.py @@ -1,5 +1,5 @@ -import _profiletest -import profiletest +import _profiletest +import profiletest a = profiletest.A() print a @@ -9,24 +9,24 @@ fn = b.fn i = 50000 while i: - a = fn(a) #1 - a = fn(a) #2 - a = fn(a) #3 - a = fn(a) #4 - a = fn(a) #5 - a = fn(a) #6 - a = fn(a) #7 - a = fn(a) #8 - a = fn(a) #9 - a = fn(a) #10 - a = fn(a) #1 - a = fn(a) #2 - a = fn(a) #3 - a = fn(a) #4 - a = fn(a) #5 - a = fn(a) #6 - a = fn(a) #7 - a = fn(a) #8 - a = fn(a) #9 - a = fn(a) #20 - i -= 1 + a = fn(a) # 1 + a = fn(a) # 2 + a = fn(a) # 3 + a = fn(a) # 4 + a = fn(a) # 5 + a = fn(a) # 6 + a = fn(a) # 7 + a = fn(a) # 8 + a = fn(a) # 9 + a = fn(a) # 10 + a = fn(a) # 1 + a = fn(a) # 2 + a = fn(a) # 3 + a = fn(a) # 4 + a = fn(a) # 5 + a = fn(a) # 6 + a = fn(a) # 7 + a = fn(a) # 8 + a = fn(a) # 9 + a = fn(a) # 20 + i -= 1 diff --git a/Examples/test-suite/python/profiletestc_runme.py b/Examples/test-suite/python/profiletestc_runme.py index 33461e484a3..fe64f969a6a 100644 --- a/Examples/test-suite/python/profiletestc_runme.py +++ b/Examples/test-suite/python/profiletestc_runme.py @@ -1,54 +1,54 @@ -import _profiletest -#import profiletest +import _profiletest +#import profiletest pa = _profiletest.new_A() -pb = _profiletest.new_B() +pb = _profiletest.new_B() fn = _profiletest.B_fn destroy = _profiletest.delete_A i = 50000 a = pa while i: - a = fn(pb,a) #1 - destroy(a) - a = fn(pb,a) #2 - destroy(a) - a = fn(pb,a) #3 - destroy(a) - a = fn(pb,a) #4 - destroy(a) - a = fn(pb,a) #5 - destroy(a) - a = fn(pb,a) #6 - destroy(a) - a = fn(pb,a) #7 - destroy(a) - a = fn(pb,a) #8 - destroy(a) - a = fn(pb,a) #9 - destroy(a) - a = fn(pb,a) #10 - destroy(a) - a = fn(pb,a) #1 - destroy(a) - a = fn(pb,a) #2 - destroy(a) - a = fn(pb,a) #3 - destroy(a) - a = fn(pb,a) #4 - destroy(a) - a = fn(pb,a) #5 - destroy(a) - a = fn(pb,a) #6 - destroy(a) - a = fn(pb,a) #7 - destroy(a) - a = fn(pb,a) #8 - destroy(a) - a = fn(pb,a) #9 - destroy(a) - a = fn(pb,a) #20 - destroy(a) - i -= 1 + a = fn(pb, a) # 1 + destroy(a) + a = fn(pb, a) # 2 + destroy(a) + a = fn(pb, a) # 3 + destroy(a) + a = fn(pb, a) # 4 + destroy(a) + a = fn(pb, a) # 5 + destroy(a) + a = fn(pb, a) # 6 + destroy(a) + a = fn(pb, a) # 7 + destroy(a) + a = fn(pb, a) # 8 + destroy(a) + a = fn(pb, a) # 9 + destroy(a) + a = fn(pb, a) # 10 + destroy(a) + a = fn(pb, a) # 1 + destroy(a) + a = fn(pb, a) # 2 + destroy(a) + a = fn(pb, a) # 3 + destroy(a) + a = fn(pb, a) # 4 + destroy(a) + a = fn(pb, a) # 5 + destroy(a) + a = fn(pb, a) # 6 + destroy(a) + a = fn(pb, a) # 7 + destroy(a) + a = fn(pb, a) # 8 + destroy(a) + a = fn(pb, a) # 9 + destroy(a) + a = fn(pb, a) # 20 + destroy(a) + i -= 1 _profiletest.delete_A(pa) _profiletest.delete_B(pb) diff --git a/Examples/test-suite/python/python_abstractbase_runme3.py b/Examples/test-suite/python/python_abstractbase_runme3.py index 9b189964df2..b4a20f08512 100644 --- a/Examples/test-suite/python/python_abstractbase_runme3.py +++ b/Examples/test-suite/python/python_abstractbase_runme3.py @@ -4,7 +4,7 @@ # This is expected to fail with -builtin option # Builtin types can't inherit from pure-python abstract bases if is_python_builtin(): - exit(0) + exit(0) assert issubclass(Mapii, MutableMapping) assert issubclass(Multimapii, MutableMapping) @@ -19,4 +19,3 @@ intmultiset = IntMultiset() intvector = IntVector() intlist = IntList() - diff --git a/Examples/test-suite/python/python_append_runme.py b/Examples/test-suite/python/python_append_runme.py index 54d7a3e00d1..6675f350943 100644 --- a/Examples/test-suite/python/python_append_runme.py +++ b/Examples/test-suite/python/python_append_runme.py @@ -1,16 +1,29 @@ from python_append import * + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + # test not relevant for -builtin if is_python_builtin(): - exit(0) + exit(0) -t=Test() +t = Test() t.func() -t.static_func() +if is_new_style_class(Test): + t.static_func() +else: + Test_static_func() if grabpath() != os.path.dirname(mypath): - raise RuntimeError("grabpath failed") + raise RuntimeError("grabpath failed") if grabstaticpath() != os.path.basename(mypath): - raise RuntimeError("grabstaticpath failed") + raise RuntimeError("grabstaticpath failed") +clearstaticpath() +if grabstaticpath() != None: + raise RuntimeError("Resetting staticfuncpath failed") +Test.static_func() +if grabstaticpath() != os.path.basename(mypath): + raise RuntimeError("grabstaticpath failed") diff --git a/Examples/test-suite/python/python_destructor_exception_runme.py b/Examples/test-suite/python/python_destructor_exception_runme.py new file mode 100644 index 00000000000..671eff3cc4d --- /dev/null +++ b/Examples/test-suite/python/python_destructor_exception_runme.py @@ -0,0 +1,64 @@ +import python_destructor_exception +from StringIO import StringIO +import sys + +def error_function(): + python_destructor_exception.ClassWithThrowingDestructor().GetBlah() + +def runtest(): + attributeErrorOccurred = False + try: + error_function() + except AttributeError, e: + attributeErrorOccurred = True + return attributeErrorOccurred + +def test1(): + stderr_saved = sys.stderr + buffer = StringIO() + attributeErrorOccurred = False + try: + # Suppress stderr while making this call to suppress the output shown by PyErr_WriteUnraisable + sys.stderr = buffer + + attributeErrorOccurred = runtest() + finally: + sys.stderr.flush() + sys.stderr = stderr_saved + + assert attributeErrorOccurred + assert buffer.getvalue().count("I am the ClassWithThrowingDestructor dtor doing bad things") >= 1 + +class VectorHolder(object): + def __init__(self, v): + self.v = v + def gen(self): + for e in self.v: + yield e + +# See issue #559, #560, #573 - In Python 3.5, test2() call to the generator 'gen' was +# resulting in the following (not for -builtin where there is no call to SWIG_Python_CallFunctor +# as SwigPyObject_dealloc is not used): +# +# StopIteration +# +# During handling of the above exception, another exception occurred: +# ... +# SystemError: returned a result with an error set + +def addup(): + sum = 0 + for i in VectorHolder(python_destructor_exception.VectorInt([1, 2, 3])).gen(): + sum = sum + i + return sum + +def test2(): + sum = addup() + + if sum != 6: + raise RuntimeError("Sum is incorrect") + +# These two tests are different are two different ways to recreate essentially the same problem +# reported by Python 3.5 that an exception was already set when destroying a wrapped object +test1() +test2() diff --git a/Examples/test-suite/python/python_docstring_runme.py b/Examples/test-suite/python/python_docstring_runme.py new file mode 100644 index 00000000000..0284ea0ded3 --- /dev/null +++ b/Examples/test-suite/python/python_docstring_runme.py @@ -0,0 +1,100 @@ +from python_docstring import * +import inspect + +def check(got, expected): + expected_list = expected.split("\n") + got_list = got.split("\n") + + if expected_list != got_list: + raise RuntimeError("\n" + "Expected: " + str(expected_list) + "\n" + "Got : " + str(got_list)) + +# When getting docstrings, use inspect.getdoc(x) instead of x.__doc__ otherwise the different options +# such as -O, -builtin, -classic produce different initial indentation. + +check(inspect.getdoc(DocStrings.docstring1), + " line 1\n" + "line 2\n" + "\n" + "\n" + "\n" + "line 3" + ) + +check(inspect.getdoc(DocStrings.docstring2), + "line 1\n" + " line 2\n" + "\n" + "\n" + "\n" + " line 3" + ) + +check(inspect.getdoc(DocStrings.docstring3), + "line 1\n" + " line 2\n" + "\n" + "\n" + "\n" + " line 3" + ) + +check(inspect.getdoc(DocStrings.docstring4), + "line 1\n" + " line 2\n" + "\n" + "\n" + "\n" + " line 3" + ) + +check(inspect.getdoc(DocStrings.docstring5), + "line 1\n" + " line 2\n" + "\n" + "\n" + "\n" + " line 3" + ) + +check(inspect.getdoc(DocStrings.docstring6), + "line 1\n" + " line 2\n" + "\n" + "\n" + "\n" + " line 3" + ) + +check(inspect.getdoc(DocStrings.docstring7), + "line 1\n" + "line 2\n" + "line 3" + ) + +check(inspect.getdoc(DocStrings.docstringA), + "first line\n" + "second line" + ) + +check(inspect.getdoc(DocStrings.docstringB), + "first line\n" + "second line" + ) + +check(inspect.getdoc(DocStrings.docstringC), + "first line\n" + "second line" + ) + +# One line doc special case, use __doc__ +check(DocStrings.docstringX.__doc__, + " one line docs" + ) + +check(inspect.getdoc(DocStrings.docstringX), + "one line docs" + ) + +check(inspect.getdoc(DocStrings.docstringY), + "one line docs" + ) diff --git a/Examples/test-suite/python/python_nondynamic_runme.py b/Examples/test-suite/python/python_nondynamic_runme.py index b860ba0d7a8..6a430961ef2 100644 --- a/Examples/test-suite/python/python_nondynamic_runme.py +++ b/Examples/test-suite/python/python_nondynamic_runme.py @@ -5,42 +5,44 @@ aa.a = 1 aa.b = 2 try: - aa.c = 2 - err = 0 + aa.c = 2 + err = 0 except: - err = 1 + err = 1 + +if not err: + raise RuntimeError, "A is not static" -if not err: - raise RuntimeError, "A is not static" class B(python_nondynamic.A): - c = 4 - def __init__(self): - python_nondynamic.A.__init__(self) + c = 4 + + def __init__(self): + python_nondynamic.A.__init__(self) + pass pass - pass bb = B() try: - bb.c = 3 - err = 0 + bb.c = 3 + err = 0 except: - err = 1 + err = 1 if not err: - print "bb.c = %d" % bb.c - print "B.c = %d" % B.c - raise RuntimeError, "B.c class variable messes up nondynamic-ness of B" + print "bb.c = %d" % bb.c + print "B.c = %d" % B.c + raise RuntimeError, "B.c class variable messes up nondynamic-ness of B" try: - bb.d = 2 - err = 0 + bb.d = 2 + err = 0 except: - err = 1 + err = 1 + +if not err: + raise RuntimeError, "B is not static" -if not err: - raise RuntimeError, "B is not static" - cc = python_nondynamic.C() cc.d = 3 diff --git a/Examples/test-suite/python/python_overload_simple_cast_runme.py b/Examples/test-suite/python/python_overload_simple_cast_runme.py index 1b3a5482cfc..79ef6cd2e1f 100644 --- a/Examples/test-suite/python/python_overload_simple_cast_runme.py +++ b/Examples/test-suite/python/python_overload_simple_cast_runme.py @@ -1,16 +1,20 @@ from python_overload_simple_cast import * + class Ai: - def __init__(self,x): + + def __init__(self, x): self.x = x - + def __int__(self): return self.x + class Ad: - def __init__(self,x): + + def __init__(self, x): self.x = x - + def __float__(self): return self.x @@ -26,7 +30,7 @@ def __float__(self): good = 1 if not good: - raise RuntimeError, "fint(int)" + raise RuntimeError, "fint(int)" if fint(ad) != "fint:int": @@ -40,7 +44,7 @@ def __float__(self): if fint(5.0) != "fint:int": raise RuntimeError, "fint(int)" - + if fint(3) != "fint:int": raise RuntimeError, "fint(int)" if fint(3.0) != "fint:int": @@ -53,20 +57,19 @@ def __float__(self): if fdouble(3.0) != "fdouble:double": raise RuntimeError, "fdouble(double)" -if fid(3,3.0) != "fid:intdouble": +if fid(3, 3.0) != "fid:intdouble": raise RuntimeError, "fid:intdouble" -if fid(3.0,3) != "fid:doubleint": +if fid(3.0, 3) != "fid:doubleint": raise RuntimeError, "fid:doubleint" -if fid(ad,ai) != "fid:doubleint": +if fid(ad, ai) != "fid:doubleint": raise RuntimeError, "fid:doubleint" -if fid(ai,ad) != "fid:intdouble": +if fid(ai, ad) != "fid:intdouble": raise RuntimeError, "fid:intdouble" - if foo(3) != "foo:int": raise RuntimeError, "foo(int)" @@ -137,7 +140,7 @@ def __float__(self): s = Spam(3) if s.type != "int": raise RuntimeError, "Spam(int)" - + s = Spam(3.4) if s.type != "double": raise RuntimeError, "Spam(double)" @@ -160,7 +163,7 @@ def __float__(self): # unsigned long long -ullmax = 9223372036854775807 #0xffffffffffffffff +ullmax = 9223372036854775807 # 0xffffffffffffffff ullmaxd = 9007199254740992.0 ullmin = 0 ullmind = 0.0 @@ -174,7 +177,7 @@ def __float__(self): raise RuntimeError, "ull(ullmaxd)" # long long -llmax = 9223372036854775807 #0x7fffffffffffffff +llmax = 9223372036854775807 # 0x7fffffffffffffff llmin = -9223372036854775808 # these are near the largest floats we can still convert into long long llmaxd = 9007199254740992.0 diff --git a/Examples/test-suite/python/python_pybuf_runme3.py b/Examples/test-suite/python/python_pybuf_runme3.py index 152aecdc018..4e57b69e861 100644 --- a/Examples/test-suite/python/python_pybuf_runme3.py +++ b/Examples/test-suite/python/python_pybuf_runme3.py @@ -1,42 +1,41 @@ -#run: +# run: # python python_pybuf_runme3.py benchmark -#for the benchmark, other wise the test case will be run +# for the benchmark, other wise the test case will be run import python_pybuf import sys -if len(sys.argv)>=2 and sys.argv[1]=="benchmark": - #run the benchmark +if len(sys.argv) >= 2 and sys.argv[1] == "benchmark": + # run the benchmark import time - k=1000000 #number of times to excute the functions + k = 1000000 # number of times to excute the functions - t=time.time() + t = time.time() a = bytearray(b'hello world') for i in range(k): - pybuf.title1(a) - print("Time used by bytearray:",time.time()-t) + pybuf.title1(a) + print("Time used by bytearray:", time.time() - t) - t=time.time() + t = time.time() b = 'hello world' for i in range(k): - pybuf.title2(b) - print("Time used by string:",time.time()-t) + pybuf.title2(b) + print("Time used by string:", time.time() - t) else: - #run the test case + # run the test case buf1 = bytearray(10) buf2 = bytearray(50) pybuf.func1(buf1) - assert buf1 == b'a'*10 + assert buf1 == b'a' * 10 pybuf.func2(buf2) assert buf2.startswith(b"Hello world!\x00") count = pybuf.func3(buf2) - assert count==10 #number of alpha and number in 'Hello world!' + assert count == 10 # number of alpha and number in 'Hello world!' length = pybuf.func4(buf2) - assert length==12 + assert length == 12 buf3 = bytearray(b"hello") pybuf.title1(buf3) - assert buf3==b'Hello' - + assert buf3 == b'Hello' diff --git a/Examples/test-suite/python/python_pythoncode_runme.py b/Examples/test-suite/python/python_pythoncode_runme.py new file mode 100644 index 00000000000..da238780d61 --- /dev/null +++ b/Examples/test-suite/python/python_pythoncode_runme.py @@ -0,0 +1,5 @@ +import python_pythoncode + +# No need to actually do anything, this is a regression test for a bug which +# caused an invalid python_pythoncode.py to be generated, so if we can import +# it the bug is still fixed. diff --git a/Examples/test-suite/python/python_richcompare_runme.py b/Examples/test-suite/python/python_richcompare_runme.py index e077989cc4f..a68da2f983a 100644 --- a/Examples/test-suite/python/python_richcompare_runme.py +++ b/Examples/test-suite/python/python_richcompare_runme.py @@ -11,90 +11,96 @@ b3 = python_richcompare.SubClassB(3) # Check == and != within a single type -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------- -if not (base1 == base1) : +if not (base1 == base1): raise RuntimeError("Object not == to itself") -if not (base1 == python_richcompare.BaseClass(1)) : +if not (base1 == python_richcompare.BaseClass(1)): raise RuntimeError("Object not == to an equivalent object") -if (base1 == base2) : - raise RuntimeError("Comparing non-equivalent objects of the same type, == returned True") +if (base1 == base2): + raise RuntimeError( + "Comparing non-equivalent objects of the same type, == returned True") -if (base1 != base1) : +if (base1 != base1): raise RuntimeError("Object is != itself") -if (base1 != python_richcompare.BaseClass(1)) : +if (base1 != python_richcompare.BaseClass(1)): raise RuntimeError("Object is != an equivalent object") -if not (base1 != base2) : - raise RuntimeError("Comparing non-equivalent objects of the same type, != returned False") +if not (base1 != base2): + raise RuntimeError( + "Comparing non-equivalent objects of the same type, != returned False") # Check redefined operator== in SubClassA -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------- -if (a2 == base2) : +if (a2 == base2): raise RuntimeError("Redefined operator== in SubClassA failed") -if (a2 == b2) : +if (a2 == b2): raise RuntimeError("Redefined operator== in SubClassA failed") -if not (a1 == a2) : +if not (a1 == a2): raise RuntimeError("Redefined operator== in SubClassA failed") # Check up-casting of subclasses -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------- -if (base2 != a2) : - raise RuntimeError("Comparing equivalent base and subclass instances, != returned True") +if (base2 != a2): + raise RuntimeError( + "Comparing equivalent base and subclass instances, != returned True") -if (a2 == base2) : - raise RuntimeError("Comparing non-equivalent base and subclass instances, == returned True") +if (a2 == base2): + raise RuntimeError( + "Comparing non-equivalent base and subclass instances, == returned True") -if (a1 == b1) : - raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True") +if (a1 == b1): + raise RuntimeError( + "Comparing equivalent instances of different subclasses, == returned True") + +if (b1 == a1): + raise RuntimeError( + "Comparing equivalent instances of different subclasses, == returned True") -if (b1 == a1) : - raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True") - # Check inequalities -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------- -if (a2 > b2) : +if (a2 > b2): raise RuntimeError("operator> failed") -if (a2 < b2) : +if (a2 < b2): raise RuntimeError("operator< failed") -if not (a2 >= b2) : +if not (a2 >= b2): raise RuntimeError("operator>= failed") -if not (a2 <= b2) : +if not (a2 <= b2): raise RuntimeError("operator<= failed") # Check inequalities used for ordering -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------- x = sorted([a2, a3, a1]) -if not (x[0] is a1) : +if not (x[0] is a1): raise RuntimeError("Ordering failed") -if not (x[1] is a2) : +if not (x[1] is a2): raise RuntimeError("Ordering failed") -if not (x[2] is a3) : +if not (x[2] is a3): raise RuntimeError("Ordering failed") x = sorted([base2, a3, b1]) -if not (x[0] is b1) : +if not (x[0] is b1): raise RuntimeError("Ordering failed") -if not (x[1] is base2) : +if not (x[1] is base2): raise RuntimeError("Ordering failed") -if not (x[2] is a3) : +if not (x[2] is a3): raise RuntimeError("Ordering failed") diff --git a/Examples/test-suite/python/python_strict_unicode_runme.py b/Examples/test-suite/python/python_strict_unicode_runme.py new file mode 100644 index 00000000000..642e127fa2f --- /dev/null +++ b/Examples/test-suite/python/python_strict_unicode_runme.py @@ -0,0 +1,79 @@ +import python_strict_unicode +from sys import version_info + +test_bytes = 'hello \x01world\x99' +BYTES = 'BYTES' +test_unicode = u'h\udce9llo w\u00f6rld' + +# Python < 2.6 rejects the b prefix for byte string literals as a SyntaxError, +# so instead create Python3 bytes objects by encoding unicode strings as +# latin-1, which maps code points 0-255 directly to the corresponding bytes. +if version_info[0] >= 3: + test_bytes = test_bytes.encode('latin-1') + BYTES = BYTES.encode('latin-1') + +# Test that byte string inputs and outputs work as expected +bdbl = python_strict_unicode.double_str(test_bytes) +if bdbl != test_bytes + test_bytes: + raise RuntimeError("Failed to double string") +if type(bdbl) != type(BYTES): + raise RuntimeError("Wrong type output for string") +bout = python_strict_unicode.same_str(test_bytes) +if bout != test_bytes: + raise RuntimeError("Failed to copy char*") +if type(bout) != type(BYTES): + raise RuntimeError("Wrong type output for char*") + +# Test that unicode string inputs and outputs work as expected +udbl = python_strict_unicode.double_wstr(test_unicode) +if udbl != test_unicode + test_unicode: + raise RuntimeError("Failed to double wide string") +if type(udbl) != type(u''): + raise RuntimeError("Wrong type output for wide string") +uout = python_strict_unicode.same_wstr(test_unicode) +if uout != test_unicode: + raise RuntimeError("Failed to copy wchar_t*") +if type(uout) != type(u''): + raise RuntimeError("Wrong type output for wchar_t*") + +# Test that overloading is handled properly +bovr = python_strict_unicode.overload(test_bytes) +if bovr != BYTES: + raise RuntimeError("Failed to return bytes from overload") +if type(bovr) != type(BYTES): + raise RuntimeError("Wrong type output from overload") +uovr = python_strict_unicode.overload(test_unicode) +if uovr != u'UNICODE': + raise RuntimeError("Failed to return unicode from overload") +if type(uovr) != type(u''): + raise RuntimeERror("Wrong type output from overload") + +# Test that bytes aren't accepted as wide strings and unicode isn't accepted as narrow strings +try: + python_strict_unicode.double_str(test_unicode) + error = 1 +except TypeError: + error = 0 +if error: + raise RuntimeError("Unicode accepted for string") +try: + python_strict_unicode.same_str(test_unicode) + error = 1 +except TypeError: + error = 0 +if error: + raise RuntimeError("Unicode accepted for char*") +try: + python_strict_unicode.double_wstr(test_bytes) + error = 1 +except TypeError: + error = 0 +if error: + raise RuntimeError("Bytes accepted for wstring") +try: + python_strict_unicode.same_wstr(test_bytes) + error = 1 +except TypeError: + error = 0 +if error: + raise RuntimeError("Bytes accepted for wchar_t*") diff --git a/Examples/test-suite/python/python_threads_runme.py b/Examples/test-suite/python/python_threads_runme.py index d00e2458f44..74cd0552b8f 100644 --- a/Examples/test-suite/python/python_threads_runme.py +++ b/Examples/test-suite/python/python_threads_runme.py @@ -3,8 +3,9 @@ action = ActionGroup() count = 1 for child in action.GetActionList(): - if child.val != count: - raise RuntimeError("Expected: " + str(count) + " got: " + str(child.val)) - count = count + 1 + if child.val != count: + raise RuntimeError( + "Expected: " + str(count) + " got: " + str(child.val)) + count = count + 1 # Was seg faulting at the end here diff --git a/Examples/test-suite/python/python_varargs_typemap_runme.py b/Examples/test-suite/python/python_varargs_typemap_runme.py index 65be757c80c..f3a70e8256c 100644 --- a/Examples/test-suite/python/python_varargs_typemap_runme.py +++ b/Examples/test-suite/python/python_varargs_typemap_runme.py @@ -1,7 +1,7 @@ import python_varargs_typemap -if (python_varargs_typemap.testfunc(1, 2.0, "three") != "three") : +if (python_varargs_typemap.testfunc(1, 2.0, "three") != "three"): raise RuntimeError("testfunc failed!") -if (python_varargs_typemap.testfunc(1, 2.0, "three", "four", "five") != "threefourfive") : +if (python_varargs_typemap.testfunc(1, 2.0, "three", "four", "five") != "threefourfive"): raise RuntimeError("testfunc failed! {}") diff --git a/Examples/test-suite/python/refcount_runme.py b/Examples/test-suite/python/refcount_runme.py index ab1803f24a5..2cab6a77e3b 100644 --- a/Examples/test-suite/python/refcount_runme.py +++ b/Examples/test-suite/python/refcount_runme.py @@ -5,19 +5,18 @@ a = A3() b1 = B(a) -b2 = B.create(a) - +b2 = B_create(a) if a.ref_count() != 3: - raise RuntimeError("Count = %d" % a.ref_count()) + raise RuntimeError("Count = %d" % a.ref_count()) rca = b2.get_rca() -b3 = B.create(rca) +b3 = B_create(rca) if a.ref_count() != 5: - raise RuntimeError("Count = %d" % a.ref_count()) + raise RuntimeError("Count = %d" % a.ref_count()) v = vector_A(2) @@ -28,28 +27,28 @@ del v if a.ref_count() != 6: - raise RuntimeError("Count = %d" % a.ref_count()) + raise RuntimeError("Count = %d" % a.ref_count()) # Check %newobject b4 = b2.cloner() if b4.ref_count() != 1: - raise RuntimeError + raise RuntimeError b5 = global_create(a) if b5.ref_count() != 1: - raise RuntimeError + raise RuntimeError -b6 = Factory.create(a) +b6 = Factory_create(a) if b6.ref_count() != 1: - raise RuntimeError + raise RuntimeError b7 = Factory().create2(a) if b7.ref_count() != 1: - raise RuntimeError + raise RuntimeError if a.ref_count() != 10: - raise RuntimeError("Count = %d" % a.ref_count()) + raise RuntimeError("Count = %d" % a.ref_count()) del b4 del b5 @@ -57,5 +56,4 @@ del b7 if a.ref_count() != 6: - raise RuntimeError("Count = %d" % a.ref_count()) - + raise RuntimeError("Count = %d" % a.ref_count()) diff --git a/Examples/test-suite/python/reference_global_vars_runme.py b/Examples/test-suite/python/reference_global_vars_runme.py index 98aaec5fe2e..6c2d181acf9 100644 --- a/Examples/test-suite/python/reference_global_vars_runme.py +++ b/Examples/test-suite/python/reference_global_vars_runme.py @@ -71,4 +71,3 @@ cvar.var_TestClass = createref_TestClass(TestClass(20)) if value_TestClass(cvar.var_TestClass).num != 20: raise RuntimeError - diff --git a/Examples/test-suite/python/rename_pcre_encoder_runme.py b/Examples/test-suite/python/rename_pcre_encoder_runme.py index 419acd1a128..aa60e4b18d1 100644 --- a/Examples/test-suite/python/rename_pcre_encoder_runme.py +++ b/Examples/test-suite/python/rename_pcre_encoder_runme.py @@ -10,7 +10,7 @@ a.DoSomething() evt = wxEVTSomeEvent() -t = xUnchangedName() +t = xUnchangedName() if StartINSAneAndUNSAvoryTraNSAtlanticRaNSAck() != 42: raise RuntimeError("Unexpected result of renamed function call") diff --git a/Examples/test-suite/python/rename_predicates_runme.py b/Examples/test-suite/python/rename_predicates_runme.py index 2ce097737de..2ace8274cbf 100644 --- a/Examples/test-suite/python/rename_predicates_runme.py +++ b/Examples/test-suite/python/rename_predicates_runme.py @@ -8,22 +8,22 @@ GF_global_function() if r.MV_member_variable != 123: - raise RuntimeError("variable wrong") -r.MV_member_variable = 1234; + raise RuntimeError("variable wrong") +r.MV_member_variable = 1234 if r.MV_member_variable != 1234: - raise RuntimeError("variable wrong") + raise RuntimeError("variable wrong") if cvar.RenamePredicates_MV_static_member_variable != 456: - raise RuntimeError("variable wrong") -cvar.RenamePredicates_MV_static_member_variable = 4567; + raise RuntimeError("variable wrong") +cvar.RenamePredicates_MV_static_member_variable = 4567 if cvar.RenamePredicates_MV_static_member_variable != 4567: - raise RuntimeError("variable wrong") + raise RuntimeError("variable wrong") if cvar.GV_global_variable != 789: - raise RuntimeError("variable wrong") -cvar.GV_global_variable = 7890; + raise RuntimeError("variable wrong") +cvar.GV_global_variable = 7890 if cvar.GV_global_variable != 7890: - raise RuntimeError("variable wrong") + raise RuntimeError("variable wrong") UC_UPPERCASE() LC_lowercase() diff --git a/Examples/test-suite/python/rename_strip_encoder_runme.py b/Examples/test-suite/python/rename_strip_encoder_runme.py index 64be611d6d5..010c14246fc 100644 --- a/Examples/test-suite/python/rename_strip_encoder_runme.py +++ b/Examples/test-suite/python/rename_strip_encoder_runme.py @@ -3,4 +3,3 @@ s = SomeWidget() a = AnotherWidget() a.DoSomething() - diff --git a/Examples/test-suite/python/return_const_value_runme.py b/Examples/test-suite/python/return_const_value_runme.py index 516e9f5d9e1..94710284064 100644 --- a/Examples/test-suite/python/return_const_value_runme.py +++ b/Examples/test-suite/python/return_const_value_runme.py @@ -1,12 +1,12 @@ import return_const_value import sys -p = return_const_value.Foo_ptr.getPtr() +p = return_const_value.Foo_ptr_getPtr() if (p.getVal() != 17): - print "Runtime test1 faild. p.getVal()=", p.getVal() - sys.exit(1) + print "Runtime test1 faild. p.getVal()=", p.getVal() + sys.exit(1) -p = return_const_value.Foo_ptr.getConstPtr() +p = return_const_value.Foo_ptr_getConstPtr() if (p.getVal() != 17): - print "Runtime test2 faild. p.getVal()=", p.getVal() - sys.exit(1) + print "Runtime test2 faild. p.getVal()=", p.getVal() + sys.exit(1) diff --git a/Examples/test-suite/python/smart_pointer_const_overload_runme.py b/Examples/test-suite/python/smart_pointer_const_overload_runme.py index 098e5b4c340..9cec1da9fc6 100644 --- a/Examples/test-suite/python/smart_pointer_const_overload_runme.py +++ b/Examples/test-suite/python/smart_pointer_const_overload_runme.py @@ -3,115 +3,116 @@ CONST_ACCESS = 1 MUTABLE_ACCESS = 2 + def test(b, f): - if f.x != 0: - raise RuntimeError - - # Test member variable get - if b.x != 0: - raise RuntimeError - - if f.access != CONST_ACCESS: - raise RuntimeError - - # Test member variable set - b.x = 1 - - if f.x != 1: - raise RuntimeError - - if f.access != MUTABLE_ACCESS: - raise RuntimeError - - # Test const method - if b.getx() != 1: - raise RuntimeError - - if f.access != CONST_ACCESS: - raise RuntimeError - - # Test mutable method - b.setx(2) - - if f.x != 2: - raise RuntimeError - - if f.access != MUTABLE_ACCESS: - raise RuntimeError - - # Test extended const method - if b.getx2() != 2: - raise RuntimeError - - if f.access != CONST_ACCESS: - raise RuntimeError - - # Test extended mutable method - b.setx2(3) - - if f.x != 3: - raise RuntimeError - - if f.access != MUTABLE_ACCESS: - raise RuntimeError - - # Test static method - b.statMethod() - - if f.access != CONST_ACCESS: - raise RuntimeError - - # Test const member - f.access = MUTABLE_ACCESS - - if b.y != 0: - raise RuntimeError - - if f.access != CONST_ACCESS: - raise RuntimeError - - # Test get through mutable pointer to const member - f.access = MUTABLE_ACCESS - - if get_int(b.yp) != 0: - raise RuntimeError - - if f.access != CONST_ACCESS: - raise RuntimeError - - # Test get through const pointer to mutable member - f.x = 4 - f.access = MUTABLE_ACCESS - - if get_int(b.xp) != 4: - raise RuntimeError - - if f.access != CONST_ACCESS: - raise RuntimeError - - # Test set through const pointer to mutable member - f.access = MUTABLE_ACCESS - set_int(b.xp, 5) - - if f.x != 5: - raise RuntimeError - - if f.access != CONST_ACCESS: - raise RuntimeError - - # Test set pointer to const member - b.yp = new_int(6) - - if f.y != 0: - raise RuntimeError - - if get_int(f.yp) != 6: - raise RuntimeError - - if f.access != MUTABLE_ACCESS: - raise RuntimeError - - delete_int(f.yp); + if f.x != 0: + raise RuntimeError + + # Test member variable get + if b.x != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test member variable set + b.x = 1 + + if f.x != 1: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test const method + if b.getx() != 1: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test mutable method + b.setx(2) + + if f.x != 2: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test extended const method + if b.getx2() != 2: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test extended mutable method + b.setx2(3) + + if f.x != 3: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test static method + b.statMethod() + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test const member + f.access = MUTABLE_ACCESS + + if b.y != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test get through mutable pointer to const member + f.access = MUTABLE_ACCESS + + if get_int(b.yp) != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test get through const pointer to mutable member + f.x = 4 + f.access = MUTABLE_ACCESS + + if get_int(b.xp) != 4: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test set through const pointer to mutable member + f.access = MUTABLE_ACCESS + set_int(b.xp, 5) + + if f.x != 5: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test set pointer to const member + b.yp = new_int(6) + + if f.y != 0: + raise RuntimeError + + if get_int(f.yp) != 6: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + delete_int(f.yp) f = Foo() b = Bar(f) diff --git a/Examples/test-suite/python/smart_pointer_extend_runme.py b/Examples/test-suite/python/smart_pointer_extend_runme.py index 969757b4cbf..0b252508183 100644 --- a/Examples/test-suite/python/smart_pointer_extend_runme.py +++ b/Examples/test-suite/python/smart_pointer_extend_runme.py @@ -4,7 +4,7 @@ b = Bar(f) if b.extension() != f.extension(): - raise RuntimeError + raise RuntimeError b = CBase() @@ -12,14 +12,13 @@ p = CPtr() if b.bar() != p.bar(): - raise RuntimeError + raise RuntimeError if d.foo() != p.foo(): - raise RuntimeError + raise RuntimeError if b.hello() != p.hello(): - raise RuntimeError - + raise RuntimeError d = DFoo() @@ -27,8 +26,7 @@ dp = DPtrFoo(d) if d.SExt(1) != dp.SExt(1): - raise RuntimeError + raise RuntimeError if d.Ext(1) != dp.Ext(1): - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/smart_pointer_member_runme.py b/Examples/test-suite/python/smart_pointer_member_runme.py index 70e65565213..ce91da2bd77 100644 --- a/Examples/test-suite/python/smart_pointer_member_runme.py +++ b/Examples/test-suite/python/smart_pointer_member_runme.py @@ -1,30 +1,29 @@ from smart_pointer_member import * + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + f = Foo() f.y = 1 if f.y != 1: - raise RuntimeError + raise RuntimeError b = Bar(f) b.y = 2 if f.y != 2: - print f.y - print b.y - raise RuntimeError + print f.y + print b.y + raise RuntimeError if b.x != f.x: - raise RuntimeError + raise RuntimeError if b.z != f.z: - raise RuntimeError - -if Foo.z == Bar.z: - raise RuntimeError - - - - - + raise RuntimeError +if is_new_style_class(Bar): # feature not supported in old style classes + if Foo.z == Bar.z: + raise RuntimeError diff --git a/Examples/test-suite/python/smart_pointer_multi_runme.py b/Examples/test-suite/python/smart_pointer_multi_runme.py index c17053055a8..26c22d4493d 100644 --- a/Examples/test-suite/python/smart_pointer_multi_runme.py +++ b/Examples/test-suite/python/smart_pointer_multi_runme.py @@ -12,4 +12,3 @@ g.x = 4 if g.getx() != 4: raise RuntimeError - diff --git a/Examples/test-suite/python/smart_pointer_multi_typedef_runme.py b/Examples/test-suite/python/smart_pointer_multi_typedef_runme.py index ebf4c9b0910..3014febcd13 100644 --- a/Examples/test-suite/python/smart_pointer_multi_typedef_runme.py +++ b/Examples/test-suite/python/smart_pointer_multi_typedef_runme.py @@ -12,4 +12,3 @@ g.x = 4 if g.getx() != 4: raise RuntimeError - diff --git a/Examples/test-suite/python/smart_pointer_not_runme.py b/Examples/test-suite/python/smart_pointer_not_runme.py index 4c90b376b7e..69704c4ef4b 100644 --- a/Examples/test-suite/python/smart_pointer_not_runme.py +++ b/Examples/test-suite/python/smart_pointer_not_runme.py @@ -13,7 +13,7 @@ try: x = s.x - print "Error! s.x" + print "Error! s.x" except: pass @@ -25,13 +25,13 @@ try: x = b.getx() - print "Error! b.getx()" + print "Error! b.getx()" except: pass try: x = s.getx() - print "Error! s.getx()" + print "Error! s.getx()" except: pass diff --git a/Examples/test-suite/python/smart_pointer_overload_runme.py b/Examples/test-suite/python/smart_pointer_overload_runme.py index c9fd3a5b0b4..16f6997fe54 100644 --- a/Examples/test-suite/python/smart_pointer_overload_runme.py +++ b/Examples/test-suite/python/smart_pointer_overload_runme.py @@ -17,5 +17,3 @@ raise RuntimeError if b.test("hello") != 3: raise RuntimeError - - diff --git a/Examples/test-suite/python/smart_pointer_rename_runme.py b/Examples/test-suite/python/smart_pointer_rename_runme.py index c6d22273c54..785f69e6414 100644 --- a/Examples/test-suite/python/smart_pointer_rename_runme.py +++ b/Examples/test-suite/python/smart_pointer_rename_runme.py @@ -9,5 +9,5 @@ if b.ftest1(1) != 1: raise RuntimeError -if b.ftest2(2,3) != 2: +if b.ftest2(2, 3) != 2: raise RuntimeError diff --git a/Examples/test-suite/python/smart_pointer_templatevariables_runme.py b/Examples/test-suite/python/smart_pointer_templatevariables_runme.py index 367dcf3b287..46555148091 100644 --- a/Examples/test-suite/python/smart_pointer_templatevariables_runme.py +++ b/Examples/test-suite/python/smart_pointer_templatevariables_runme.py @@ -3,15 +3,14 @@ d = DiffImContainerPtr_D(create(1234, 5678)) if (d.id != 1234): - raise RuntimeError -#if (d.xyz != 5678): + raise RuntimeError +# if (d.xyz != 5678): # raise RuntimeError d.id = 4321 #d.xyz = 8765 if (d.id != 4321): - raise RuntimeError -#if (d.xyz != 8765): + raise RuntimeError +# if (d.xyz != 8765): # raise RuntimeError - diff --git a/Examples/test-suite/python/sneaky1_runme.py b/Examples/test-suite/python/sneaky1_runme.py index 9c2c32f852d..c56f56f9e0d 100644 --- a/Examples/test-suite/python/sneaky1_runme.py +++ b/Examples/test-suite/python/sneaky1_runme.py @@ -1,5 +1,5 @@ import sneaky1 -x = sneaky1.add(3,4) -y = sneaky1.subtract(3,4) -z = sneaky1.mul(3,4) -w = sneaky1.divide(3,4) +x = sneaky1.add(3, 4) +y = sneaky1.subtract(3, 4) +z = sneaky1.mul(3, 4) +w = sneaky1.divide(3, 4) diff --git a/Examples/test-suite/python/special_variable_macros_runme.py b/Examples/test-suite/python/special_variable_macros_runme.py index eaf9c18581c..e487f9a50ed 100644 --- a/Examples/test-suite/python/special_variable_macros_runme.py +++ b/Examples/test-suite/python/special_variable_macros_runme.py @@ -2,17 +2,16 @@ name = special_variable_macros.Name() if special_variable_macros.testFred(name) != "none": - raise "test failed" + raise "test failed" if special_variable_macros.testJack(name) != "$specialname": - raise "test failed" + raise "test failed" if special_variable_macros.testJill(name) != "jilly": - raise "test failed" + raise "test failed" if special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap": - raise "test failed" + raise "test failed" if special_variable_macros.testJames(name) != "SWIGTYPE_Name": - raise "test failed" + raise "test failed" if special_variable_macros.testJim(name) != "multiname num": - raise "test failed" + raise "test failed" if special_variable_macros.testJohn(special_variable_macros.PairIntBool(10, False)) != 123: - raise "test failed" - + raise "test failed" diff --git a/Examples/test-suite/python/static_const_member_2_runme.py b/Examples/test-suite/python/static_const_member_2_runme.py index 081726361a9..01704e39c19 100644 --- a/Examples/test-suite/python/static_const_member_2_runme.py +++ b/Examples/test-suite/python/static_const_member_2_runme.py @@ -12,5 +12,5 @@ raise RuntimeError -if Foo.BAZ.val != 2*Foo.BAR.val: +if Foo.BAZ.val != 2 * Foo.BAR.val: raise RuntimeError diff --git a/Examples/test-suite/python/std_containers_runme.py b/Examples/test-suite/python/std_containers_runme.py index f90c984059b..d4625daa03c 100644 --- a/Examples/test-suite/python/std_containers_runme.py +++ b/Examples/test-suite/python/std_containers_runme.py @@ -5,73 +5,72 @@ cube = (((1, 2), (3, 4)), ((5, 6), (7, 8))) icube = std_containers.cident(cube) -for i in range(0,len(cube)): - if cube[i] != icube[i]: - raise RuntimeError, "bad cident" +for i in range(0, len(cube)): + if cube[i] != icube[i]: + raise RuntimeError, "bad cident" -p = (1,2) +p = (1, 2) if p != std_containers.pident(p): - raise RuntimeError, "bad pident" + raise RuntimeError, "bad pident" -v = (1,2,3,4,5,6) +v = (1, 2, 3, 4, 5, 6) iv = std_containers.vident(v) -for i in range(0,len(v)): - if v[i] != iv[i]: - raise RuntimeError, "bad vident" - +for i in range(0, len(v)): + if v[i] != iv[i]: + raise RuntimeError, "bad vident" iv = std_containers.videntu(v) -for i in range(0,len(v)): - if v[i] != iv[i]: - raise RuntimeError, "bad videntu" +for i in range(0, len(v)): + if v[i] != iv[i]: + raise RuntimeError, "bad videntu" vu = std_containers.vector_ui(v) if vu[2] != std_containers.videntu(vu)[2]: - raise RuntimeError, "bad videntu" - + raise RuntimeError, "bad videntu" + if v[0:3][1] != vu[0:3][1]: - print v[0:3][1], vu[0:3][1] - raise RuntimeError, "bad getslice" - + print v[0:3][1], vu[0:3][1] + raise RuntimeError, "bad getslice" -m = ((1,2,3),(2,3),(3,4)) + +m = ((1, 2, 3), (2, 3), (3, 4)) im = std_containers.midenti(m) -for i in range(0,len(m)): - for j in range(0,len(m[i])): - if m[i][j] != im[i][j]: - raise RuntimeError, "bad getslice" +for i in range(0, len(m)): + for j in range(0, len(m[i])): + if m[i][j] != im[i][j]: + raise RuntimeError, "bad getslice" -m = ((True,False,True),(True,True),(True,True)) +m = ((True, False, True), (True, True), (True, True)) im = std_containers.midentb(m) -for i in range(0,len(m)): - for j in range(0,len(m[i])): - if m[i][j] != im[i][j]: - raise RuntimeError, "bad getslice" +for i in range(0, len(m)): + for j in range(0, len(m[i])): + if m[i][j] != im[i][j]: + raise RuntimeError, "bad getslice" mi = std_containers.imatrix(m) mc = std_containers.cmatrix(m) if mi[0][1] != mc[0][1]: - raise RuntimeError, "bad matrix" + raise RuntimeError, "bad matrix" -map ={} +map = {} map['hello'] = 1 map['hi'] = 2 map['3'] = 2 imap = std_containers.mapident(map) for k in map: - if map[k] != imap[k]: - raise RuntimeError, "bad map" + if map[k] != imap[k]: + raise RuntimeError, "bad map" -mapc ={} +mapc = {} c1 = std_containers.C() c2 = std_containers.C() mapc[1] = c1.this @@ -80,23 +79,23 @@ std_containers.mapidentc(mapc) -vi = std_containers.vector_i((2,2,3,4)) +vi = std_containers.vector_i((2, 2, 3, 4)) -v = (1,2) +v = (1, 2) v1 = std_containers.v_inout(vi) vi[1], v1[1] -v1,v2 = ((1,2),(3,4)) -v1,v2 = std_containers.v_inout2(v1,v2) +v1, v2 = ((1, 2), (3, 4)) +v1, v2 = std_containers.v_inout2(v1, v2) a1 = std_containers.A(1) a2 = std_containers.A(2) -p1 = (1,a1) -p2 = (2,a2) -v = (p1,p2) -v2= std_containers.pia_vident(v) +p1 = (1, a1) +p2 = (2, a2) +v = (p1, p2) +v2 = std_containers.pia_vident(v) v2[0][1].a v2[1][1].a @@ -110,10 +109,8 @@ s.append(1) s.append(2) s.append(3) -j=1 +j = 1 for i in s: - if i != j: - raise RuntimeError - j = j + 1 - - + if i != j: + raise RuntimeError + j = j + 1 diff --git a/Examples/test-suite/python/struct_initialization_runme.py b/Examples/test-suite/python/struct_initialization_runme.py index fbed6a5e9b2..524b8963080 100644 --- a/Examples/test-suite/python/struct_initialization_runme.py +++ b/Examples/test-suite/python/struct_initialization_runme.py @@ -1,20 +1,19 @@ from struct_initialization import * if cvar.instanceC1.x != 10: - raise RuntimeError + raise RuntimeError if cvar.instanceD1.x != 10: - raise RuntimeError + raise RuntimeError if cvar.instanceD2.x != 20: - raise RuntimeError + raise RuntimeError if cvar.instanceD3.x != 30: - raise RuntimeError + raise RuntimeError if cvar.instanceE1.x != 1: - raise RuntimeError + raise RuntimeError if cvar.instanceF1.x != 1: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/struct_value_runme.py b/Examples/test-suite/python/struct_value_runme.py index 727996f53d4..aa3ece38c47 100644 --- a/Examples/test-suite/python/struct_value_runme.py +++ b/Examples/test-suite/python/struct_value_runme.py @@ -3,7 +3,32 @@ b = struct_value.Bar() b.a.x = 3 -if b.a.x != 3: raise RuntimeError +if b.a.x != 3: + raise RuntimeError b.b.x = 3 -if b.b.x != 3: raise RuntimeError +if b.b.x != 3: + raise RuntimeError + + +# Test dynamically added attributes - Github pull request #320 +b.added = 123 + +if b.added != 123: + raise RuntimeError("Wrong attribute value") + +if not b.__dict__.has_key("added"): + raise RuntimeError("Missing added attribute in __dict__") + + +class PyBar(struct_value.Bar): + + def __init__(self): + self.extra = "hi" + struct_value.Bar.__init__(self) + +pybar = PyBar() +if not pybar.__dict__.has_key("extra"): + raise RuntimeError("Missing extra attribute in __dict__") +if pybar.extra != "hi": + raise RuntimeError("Incorrect attribute value for extra") diff --git a/Examples/test-suite/python/swigobject_runme.py b/Examples/test-suite/python/swigobject_runme.py index a906108e331..346b05d408f 100644 --- a/Examples/test-suite/python/swigobject_runme.py +++ b/Examples/test-suite/python/swigobject_runme.py @@ -1,5 +1,5 @@ -from swigobject import * +from swigobject import * a = A() @@ -8,11 +8,12 @@ a2 = a_ptr(a) if a1.this != a2.this: - raise RuntimeError - + raise RuntimeError + lthis = long(a.this) -# match pointer value, but deal with leading zeros on 8/16 bit systems and different C++ compilers interpretation of %p +# match pointer value, but deal with leading zeros on 8/16 bit systems and +# different C++ compilers interpretation of %p xstr1 = "%016X" % (lthis,) xstr1 = str.lstrip(xstr1, '0') xstr2 = pointer_str(a) @@ -22,8 +23,8 @@ xstr2 = str.upper(xstr2) if xstr1 != xstr2: - print xstr1, xstr2 - raise RuntimeError + print xstr1, xstr2 + raise RuntimeError s = str(a.this) r = repr(a.this) @@ -31,4 +32,4 @@ v1 = v_ptr(a) v2 = v_ptr(a) if long(v1) != long(v2): - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/template_classes_runme.py b/Examples/test-suite/python/template_classes_runme.py new file mode 100644 index 00000000000..38b2d7a62ca --- /dev/null +++ b/Examples/test-suite/python/template_classes_runme.py @@ -0,0 +1,44 @@ +from template_classes import * + +# This test is just testing incorrect number of arguments/parameters checking + +point = PointInt() + +rectangle = RectangleInt() +rectangle.setPoint(point) +rectangle.getPoint() +RectangleInt.static_noargs() +RectangleInt.static_onearg(1) + +fail = True +try: + rectangle.setPoint() +except TypeError, e: + fail = False +if fail: + raise RuntimeError("argument count check failed") + + +fail = True +try: + rectangle.getPoint(0) +except TypeError, e: + fail = False +if fail: + raise RuntimeError("argument count check failed") + +fail = True +try: + RectangleInt.static_noargs(0) +except TypeError, e: + fail = False +if fail: + raise RuntimeError("argument count check failed") + +fail = True +try: + RectangleInt.static_onearg() +except TypeError, e: + fail = False +if fail: + raise RuntimeError("argument count check failed") diff --git a/Examples/test-suite/python/template_default_arg_overloaded_runme.py b/Examples/test-suite/python/template_default_arg_overloaded_runme.py new file mode 100644 index 00000000000..22d46b39db8 --- /dev/null +++ b/Examples/test-suite/python/template_default_arg_overloaded_runme.py @@ -0,0 +1,47 @@ +from template_default_arg_overloaded import * + +def check(expected, got): + if expected != got: + raise RuntimeError("Expected: " + str(expected) + " got: " + str(got)) + + +pl = PropertyList() +check(1, pl.setInt("int", 10)) +check(1, pl.setInt("int", 10, False)) + +check(2, pl.set("int", pl)) +check(2, pl.set("int", pl, False)) + +check(3, pl.setInt("int", 10, "int")) +check(3, pl.setInt("int", 10, "int", False)) + + +pl = PropertyListGlobal() +check(1, pl.setIntGlobal("int", 10)) +check(1, pl.setIntGlobal("int", 10, False)) + +check(2, pl.set("int", pl)) +check(2, pl.set("int", pl, False)) + +check(3, pl.setIntGlobal("int", 10, "int")) +check(3, pl.setIntGlobal("int", 10, "int", False)) + + +check(1, GoopIntGlobal(10)) +check(1, GoopIntGlobal(10, True)) + +check(2, goopGlobal(3)) +check(2, goopGlobal()) + +check(3, GoopIntGlobal("int", False)) +check(3, GoopIntGlobal("int")) + + +check(1, GoopInt(10)) +check(1, GoopInt(10, True)) + +check(2, goop(3)) +check(2, goop()) + +check(3, GoopInt("int", False)) +check(3, GoopInt("int")) diff --git a/Examples/test-suite/python/template_default_arg_runme.py b/Examples/test-suite/python/template_default_arg_runme.py index 235a2313ac1..91b1e0e8c01 100644 --- a/Examples/test-suite/python/template_default_arg_runme.py +++ b/Examples/test-suite/python/template_default_arg_runme.py @@ -7,22 +7,20 @@ x = template_default_arg.X_int() if (x.meth(20.0, 200) != 200): - raise RuntimeError, ("X_int test 1 failed") + raise RuntimeError, ("X_int test 1 failed") if (x.meth(20) != 20): - raise RuntimeError, ("X_int test 2 failed") + raise RuntimeError, ("X_int test 2 failed") if (x.meth() != 0): - raise RuntimeError, ("X_int test 3 failed") - + raise RuntimeError, ("X_int test 3 failed") y = template_default_arg.Y_unsigned() if (y.meth(20.0, 200) != 200): - raise RuntimeError, ("Y_unsigned test 1 failed") + raise RuntimeError, ("Y_unsigned test 1 failed") if (y.meth(20) != 20): - raise RuntimeError, ("Y_unsigned test 2 failed") + raise RuntimeError, ("Y_unsigned test 2 failed") if (y.meth() != 0): - raise RuntimeError, ("Y_unsigned test 3 failed") - + raise RuntimeError, ("Y_unsigned test 3 failed") x = template_default_arg.X_longlong() @@ -37,7 +35,8 @@ x = template_default_arg.X_hello_unsigned() x = template_default_arg.X_hello_unsigned(20.0) -x = template_default_arg.X_hello_unsigned(20.0, template_default_arg.Hello_int()) +x = template_default_arg.X_hello_unsigned( + 20.0, template_default_arg.Hello_int()) y = template_default_arg.Y_hello_unsigned() @@ -46,7 +45,6 @@ y.meth() - fz = template_default_arg.Foo_Z_8() x = template_default_arg.X_Foo_Z_8() fzc = x.meth(fz) @@ -56,43 +54,40 @@ # plain function: int ott(Foo) if (template_default_arg.ott(template_default_arg.Foo_int()) != 30): - raise RuntimeError, ("ott test 1 failed") + raise RuntimeError, ("ott test 1 failed") # %template(ott) ott if (template_default_arg.ott() != 10): - raise RuntimeError, ("ott test 2 failed") + raise RuntimeError, ("ott test 2 failed") if (template_default_arg.ott(1) != 10): - raise RuntimeError, ("ott test 3 failed") + raise RuntimeError, ("ott test 3 failed") if (template_default_arg.ott(1, 1) != 10): - raise RuntimeError, ("ott test 4 failed") + raise RuntimeError, ("ott test 4 failed") if (template_default_arg.ott("hi") != 20): - raise RuntimeError, ("ott test 5 failed") + raise RuntimeError, ("ott test 5 failed") if (template_default_arg.ott("hi", 1) != 20): - raise RuntimeError, ("ott test 6 failed") + raise RuntimeError, ("ott test 6 failed") if (template_default_arg.ott("hi", 1, 1) != 20): - raise RuntimeError, ("ott test 7 failed") + raise RuntimeError, ("ott test 7 failed") # %template(ott) ott if (template_default_arg.ottstring(template_default_arg.Hello_int(), "hi") != 40): - raise RuntimeError, ("ott test 8 failed") + raise RuntimeError, ("ott test 8 failed") if (template_default_arg.ottstring(template_default_arg.Hello_int()) != 40): - raise RuntimeError, ("ott test 9 failed") + raise RuntimeError, ("ott test 9 failed") # %template(ott) ott if (template_default_arg.ottint(template_default_arg.Hello_int(), 1) != 50): - raise RuntimeError, ("ott test 10 failed") + raise RuntimeError, ("ott test 10 failed") if (template_default_arg.ottint(template_default_arg.Hello_int()) != 50): - raise RuntimeError, ("ott test 11 failed") + raise RuntimeError, ("ott test 11 failed") # %template(ott) ott if (template_default_arg.ott(template_default_arg.Hello_int(), 1.0) != 60): - raise RuntimeError, ("ott test 12 failed") + raise RuntimeError, ("ott test 12 failed") if (template_default_arg.ott(template_default_arg.Hello_int()) != 60): - raise RuntimeError, ("ott test 13 failed") - - - + raise RuntimeError, ("ott test 13 failed") diff --git a/Examples/test-suite/python/template_inherit_runme.py b/Examples/test-suite/python/template_inherit_runme.py index bb1465a2bdd..2c47770a523 100644 --- a/Examples/test-suite/python/template_inherit_runme.py +++ b/Examples/test-suite/python/template_inherit_runme.py @@ -50,4 +50,3 @@ if invoke_blah_uint(f) != "Bar": raise ValueError - diff --git a/Examples/test-suite/python/template_matrix_runme.py b/Examples/test-suite/python/template_matrix_runme.py index 95815a068bd..208aafb8e27 100644 --- a/Examples/test-suite/python/template_matrix_runme.py +++ b/Examples/test-suite/python/template_matrix_runme.py @@ -1,6 +1,4 @@ -from template_matrix import * -passVector([1,2,3]) -passMatrix([[1,2],[1,2,3]]) -passCube([[[1,2],[1,2,3]],[[1,2],[1,2,3]]]) - - +from template_matrix import * +passVector([1, 2, 3]) +passMatrix([[1, 2], [1, 2, 3]]) +passCube([[[1, 2], [1, 2, 3]], [[1, 2], [1, 2, 3]]]) diff --git a/Examples/test-suite/python/template_ns4_runme.py b/Examples/test-suite/python/template_ns4_runme.py index 81107b4938f..deef019ebb2 100644 --- a/Examples/test-suite/python/template_ns4_runme.py +++ b/Examples/test-suite/python/template_ns4_runme.py @@ -1,5 +1,5 @@ from template_ns4 import * -d = make_Class_DD(); +d = make_Class_DD() if d.test() != "test": - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/template_ns_runme.py b/Examples/test-suite/python/template_ns_runme.py index 20cc9b99c62..888d125c4c3 100644 --- a/Examples/test-suite/python/template_ns_runme.py +++ b/Examples/test-suite/python/template_ns_runme.py @@ -1,5 +1,5 @@ from template_ns import * -p1 = pairii(2,3) +p1 = pairii(2, 3) p2 = pairii(p1) if p2.first != 2: @@ -7,7 +7,7 @@ if p2.second != 3: raise RuntimeError -p3 = pairdd(3.5,2.5) +p3 = pairdd(3.5, 2.5) p4 = pairdd(p3) if p4.first != 3.5: diff --git a/Examples/test-suite/python/template_opaque_runme.py b/Examples/test-suite/python/template_opaque_runme.py index f3aeb39d196..6f21116eef9 100644 --- a/Examples/test-suite/python/template_opaque_runme.py +++ b/Examples/test-suite/python/template_opaque_runme.py @@ -3,4 +3,3 @@ v = template_opaque.OpaqueVectorType(10) template_opaque.FillVector(v) - diff --git a/Examples/test-suite/python/template_ref_type_runme.py b/Examples/test-suite/python/template_ref_type_runme.py index 0b3e4dd26b6..f4ebc354c4d 100644 --- a/Examples/test-suite/python/template_ref_type_runme.py +++ b/Examples/test-suite/python/template_ref_type_runme.py @@ -1,5 +1,5 @@ import template_ref_type xr = template_ref_type.XC() -y = template_ref_type.Y() +y = template_ref_type.Y() y.find(xr) diff --git a/Examples/test-suite/python/template_static_runme.py b/Examples/test-suite/python/template_static_runme.py index 9171d93b52a..c87a5243923 100644 --- a/Examples/test-suite/python/template_static_runme.py +++ b/Examples/test-suite/python/template_static_runme.py @@ -1,3 +1,3 @@ -from template_static import * +from template_static import * Foo_bar_double(1) diff --git a/Examples/test-suite/python/template_tbase_template_runme.py b/Examples/test-suite/python/template_tbase_template_runme.py index d13c5f2c20e..b5f2e31f4a2 100644 --- a/Examples/test-suite/python/template_tbase_template_runme.py +++ b/Examples/test-suite/python/template_tbase_template_runme.py @@ -2,4 +2,4 @@ a = make_Class_dd() if a.test() != "test": - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/template_type_namespace_runme.py b/Examples/test-suite/python/template_type_namespace_runme.py index 19ea5f5ce72..5f00fe5f2c1 100644 --- a/Examples/test-suite/python/template_type_namespace_runme.py +++ b/Examples/test-suite/python/template_type_namespace_runme.py @@ -1,5 +1,4 @@ from template_type_namespace import * if type(foo()[0]) != type(""): - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/template_typedef_cplx2_runme.py b/Examples/test-suite/python/template_typedef_cplx2_runme.py index 04c59932905..3043d4285ec 100644 --- a/Examples/test-suite/python/template_typedef_cplx2_runme.py +++ b/Examples/test-suite/python/template_typedef_cplx2_runme.py @@ -5,28 +5,28 @@ # try: - d = make_Identity_double() - a = d.this + d = make_Identity_double() + a = d.this except: - print d, "is not an instance" - raise RuntimeError + print d, "is not an instance" + raise RuntimeError s = '%s' % d if str.find(s, 'ArithUnaryFunction') == -1: - print d, "is not an ArithUnaryFunction" - raise RuntimeError + print d, "is not an ArithUnaryFunction" + raise RuntimeError try: - e = make_Multiplies_double_double_double_double(d, d) - a = e.this + e = make_Multiplies_double_double_double_double(d, d) + a = e.this except: - print e, "is not an instance" - raise RuntimeError + print e, "is not an instance" + raise RuntimeError s = '%s' % e if str.find(s, 'ArithUnaryFunction') == -1: - print e, "is not an ArithUnaryFunction" - raise RuntimeError + print e, "is not an ArithUnaryFunction" + raise RuntimeError # @@ -34,61 +34,60 @@ # try: - c = make_Identity_complex() - a = c.this + c = make_Identity_complex() + a = c.this except: - print c, "is not an instance" - raise RuntimeError + print c, "is not an instance" + raise RuntimeError s = '%s' % c if str.find(s, 'ArithUnaryFunction') == -1: - print c, "is not an ArithUnaryFunction" - raise RuntimeError + print c, "is not an ArithUnaryFunction" + raise RuntimeError try: - f = make_Multiplies_complex_complex_complex_complex(c, c) - a = f.this + f = make_Multiplies_complex_complex_complex_complex(c, c) + a = f.this except: - print f, "is not an instance" - raise RuntimeError + print f, "is not an instance" + raise RuntimeError s = '%s' % f if str.find(s, 'ArithUnaryFunction') == -1: - print f, "is not an ArithUnaryFunction" - raise RuntimeError + print f, "is not an ArithUnaryFunction" + raise RuntimeError # # Mix case # try: - g = make_Multiplies_double_double_complex_complex(d, c) - a = g.this + g = make_Multiplies_double_double_complex_complex(d, c) + a = g.this except: - print g, "is not an instance" - raise RuntimeError + print g, "is not an instance" + raise RuntimeError s = '%s' % g if str.find(s, 'ArithUnaryFunction') == -1: - print g, "is not an ArithUnaryFunction" - raise RuntimeError + print g, "is not an ArithUnaryFunction" + raise RuntimeError try: - h = make_Multiplies_complex_complex_double_double(c, d) - a = h.this + h = make_Multiplies_complex_complex_double_double(c, d) + a = h.this except: - print h, "is not an instance" - raise RuntimeError + print h, "is not an instance" + raise RuntimeError s = '%s' % h if str.find(s, 'ArithUnaryFunction') == -1: - print h, "is not an ArithUnaryFunction" - raise RuntimeError + print h, "is not an ArithUnaryFunction" + raise RuntimeError try: - a = g.get_value() + a = g.get_value() except: - print g, "has not get_value() method" - raise RuntimeError - + print g, "has not get_value() method" + raise RuntimeError diff --git a/Examples/test-suite/python/template_typedef_cplx3_runme.py b/Examples/test-suite/python/template_typedef_cplx3_runme.py index b8ac1b6efe5..ad361426eef 100644 --- a/Examples/test-suite/python/template_typedef_cplx3_runme.py +++ b/Examples/test-suite/python/template_typedef_cplx3_runme.py @@ -11,14 +11,14 @@ s.get_value() s.get_arith_value() my_func_r(s) -make_Multiplies_double_double_double_double(s,s) +make_Multiplies_double_double_double_double(s, s) z = CSin() z.get_base_value() z.get_value() z.get_arith_value() my_func_c(z) -make_Multiplies_complex_complex_complex_complex(z,z) +make_Multiplies_complex_complex_complex_complex(z, z) # # Here we fail @@ -28,7 +28,3 @@ c = make_Identity_complex() my_func_c(c) - - - - diff --git a/Examples/test-suite/python/template_typedef_cplx4_runme.py b/Examples/test-suite/python/template_typedef_cplx4_runme.py index faeca219fd2..25ac851fbff 100644 --- a/Examples/test-suite/python/template_typedef_cplx4_runme.py +++ b/Examples/test-suite/python/template_typedef_cplx4_runme.py @@ -11,14 +11,14 @@ s.get_value() s.get_arith_value() my_func_r(s) -make_Multiplies_double_double_double_double(s,s) +make_Multiplies_double_double_double_double(s, s) z = CSin() z.get_base_value() z.get_value() z.get_arith_value() my_func_c(z) -make_Multiplies_complex_complex_complex_complex(z,z) +make_Multiplies_complex_complex_complex_complex(z, z) # # Here we fail @@ -28,7 +28,3 @@ c = make_Identity_complex() my_func_c(c) - - - - diff --git a/Examples/test-suite/python/template_typedef_cplx_runme.py b/Examples/test-suite/python/template_typedef_cplx_runme.py index 2cd9c834887..afb97d0701d 100644 --- a/Examples/test-suite/python/template_typedef_cplx_runme.py +++ b/Examples/test-suite/python/template_typedef_cplx_runme.py @@ -5,28 +5,28 @@ # try: - d = make_Identity_double() - a = d.this + d = make_Identity_double() + a = d.this except: - print d, "is not an instance" - raise RuntimeError + print d, "is not an instance" + raise RuntimeError s = '%s' % d if str.find(s, 'ArithUnaryFunction') == -1: - print d, "is not an ArithUnaryFunction" - raise RuntimeError + print d, "is not an ArithUnaryFunction" + raise RuntimeError try: - e = make_Multiplies_double_double_double_double(d, d) - a = e.this + e = make_Multiplies_double_double_double_double(d, d) + a = e.this except: - print e, "is not an instance" - raise RuntimeError + print e, "is not an instance" + raise RuntimeError s = '%s' % e if str.find(s, 'ArithUnaryFunction') == -1: - print e, "is not an ArithUnaryFunction" - raise RuntimeError + print e, "is not an ArithUnaryFunction" + raise RuntimeError # @@ -34,54 +34,54 @@ # try: - c = make_Identity_complex() - a = c.this + c = make_Identity_complex() + a = c.this except: - print c, "is not an instance" - raise RuntimeError + print c, "is not an instance" + raise RuntimeError s = '%s' % c if str.find(s, 'ArithUnaryFunction') == -1: - print c, "is not an ArithUnaryFunction" - raise RuntimeError + print c, "is not an ArithUnaryFunction" + raise RuntimeError try: - f = make_Multiplies_complex_complex_complex_complex(c, c) - a = f.this + f = make_Multiplies_complex_complex_complex_complex(c, c) + a = f.this except: - print f, "is not an instance" - raise RuntimeError + print f, "is not an instance" + raise RuntimeError s = '%s' % f if str.find(s, 'ArithUnaryFunction') == -1: - print f, "is not an ArithUnaryFunction" - raise RuntimeError + print f, "is not an ArithUnaryFunction" + raise RuntimeError # # Mix case # try: - g = make_Multiplies_double_double_complex_complex(d, c) - a = g.this + g = make_Multiplies_double_double_complex_complex(d, c) + a = g.this except: - print g, "is not an instance" - raise RuntimeError + print g, "is not an instance" + raise RuntimeError s = '%s' % g if str.find(s, 'ArithUnaryFunction') == -1: - print g, "is not an ArithUnaryFunction" - raise RuntimeError + print g, "is not an ArithUnaryFunction" + raise RuntimeError try: - h = make_Multiplies_complex_complex_double_double(c, d) - a = h.this + h = make_Multiplies_complex_complex_double_double(c, d) + a = h.this except: - print h, "is not an instance" - raise RuntimeError + print h, "is not an instance" + raise RuntimeError s = '%s' % h if str.find(s, 'ArithUnaryFunction') == -1: - print h, "is not an ArithUnaryFunction" - raise RuntimeError + print h, "is not an ArithUnaryFunction" + raise RuntimeError diff --git a/Examples/test-suite/python/template_typedef_import_runme.py b/Examples/test-suite/python/template_typedef_import_runme.py index 5c0b0b9363f..5da489feaf8 100644 --- a/Examples/test-suite/python/template_typedef_import_runme.py +++ b/Examples/test-suite/python/template_typedef_import_runme.py @@ -11,14 +11,14 @@ s.get_value() s.get_arith_value() my_func_r(s) -make_Multiplies_double_double_double_double(s,s) +make_Multiplies_double_double_double_double(s, s) z = CSin() z.get_base_value() z.get_value() z.get_arith_value() my_func_c(z) -make_Multiplies_complex_complex_complex_complex(z,z) +make_Multiplies_complex_complex_complex_complex(z, z) # # Here we fail @@ -28,7 +28,3 @@ c = make_Identity_complex() my_func_c(c) - - - - diff --git a/Examples/test-suite/python/template_typedef_runme.py b/Examples/test-suite/python/template_typedef_runme.py index 4b3970593cf..16695bada4e 100644 --- a/Examples/test-suite/python/template_typedef_runme.py +++ b/Examples/test-suite/python/template_typedef_runme.py @@ -5,42 +5,42 @@ try: - a = d.this - a = c.this + a = d.this + a = c.this except: - raise RuntimeError + raise RuntimeError try: - e = make_Multiplies_float_float_float_float(d, d) - a = e.this + e = make_Multiplies_float_float_float_float(d, d) + a = e.this except: - print e, "is not an instance" - raise RuntimeError + print e, "is not an instance" + raise RuntimeError try: - f = make_Multiplies_reald_reald_reald_reald(c, c) - a = f.this + f = make_Multiplies_reald_reald_reald_reald(c, c) + a = f.this except: - print f, "is not an instance" - raise RuntimeError + print f, "is not an instance" + raise RuntimeError try: - g = make_Multiplies_float_float_reald_reald(d, c) - a = g.this + g = make_Multiplies_float_float_reald_reald(d, c) + a = g.this except: - print g, "is not an instance" - raise RuntimeError + print g, "is not an instance" + raise RuntimeError # the old large format if not SWIG_TypeQuery("vfncs::ArithUnaryFunction::argument_type,vfncs::arith_traits::result_type > *"): - raise RuntimeError + raise RuntimeError # the reduced format if not SWIG_TypeQuery("vfncs::ArithUnaryFunction *"): - raise RuntimeError + raise RuntimeError # this is a bad name if SWIG_TypeQuery("vfncs::ArithUnaryFunction *"): - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/template_typemaps_typedef2_runme.py b/Examples/test-suite/python/template_typemaps_typedef2_runme.py index 8a66d27d001..258f4436683 100644 --- a/Examples/test-suite/python/template_typemaps_typedef2_runme.py +++ b/Examples/test-suite/python/template_typemaps_typedef2_runme.py @@ -13,8 +13,8 @@ #dummy_pair = m2.make_dummy_pair() #val = m2.typemap_test(dummy_pair) -#print val -#if val != 4321: +# print val +# if val != 4321: # raise RuntimeError, "typemaps not working" if typedef_test1(dummy_pair).val != 1234: @@ -34,4 +34,3 @@ if typedef_test6(dummy_pair).val != 1234: raise RuntimeError, "typedef_test6 not working" - diff --git a/Examples/test-suite/python/template_typemaps_typedef_runme.py b/Examples/test-suite/python/template_typemaps_typedef_runme.py index a4d6fd0a758..1ca3f835c34 100644 --- a/Examples/test-suite/python/template_typemaps_typedef_runme.py +++ b/Examples/test-suite/python/template_typemaps_typedef_runme.py @@ -13,8 +13,8 @@ #dummy_pair = m2.make_dummy_pair() #val = m2.typemap_test(dummy_pair) -#print val -#if val != 4321: +# print val +# if val != 4321: # raise RuntimeError, "typemaps not working" if typedef_test1(dummy_pair).val != 1234: @@ -34,4 +34,3 @@ if typedef_test6(dummy_pair).val != 1234: raise RuntimeError, "typedef_test6 not working" - diff --git a/Examples/test-suite/python/threads_exception_runme.py b/Examples/test-suite/python/threads_exception_runme.py index 6fe6947ec7e..056bd849bee 100644 --- a/Examples/test-suite/python/threads_exception_runme.py +++ b/Examples/test-suite/python/threads_exception_runme.py @@ -2,40 +2,39 @@ t = threads_exception.Test() try: - t.unknown() -except RuntimeError,e: - pass + t.unknown() +except RuntimeError, e: + pass try: - t.simple() -except RuntimeError,e: - if e.args[0] != 37: - raise RuntimeError + t.simple() +except RuntimeError, e: + if e.args[0] != 37: + raise RuntimeError try: - t.message() -except RuntimeError,e: - if e.args[0] != "I died.": - raise RuntimeError + t.message() +except RuntimeError, e: + if e.args[0] != "I died.": + raise RuntimeError # This is expected fail with -builtin option # Throwing builtin classes as exceptions not supported if not threads_exception.is_python_builtin(): - try: - t.hosed() - except threads_exception.Exc,e: - code = e.code - if code != 42: - raise RuntimeError, "bad... code: %d" % code - msg = e.msg - if msg != "Hosed": - raise RuntimeError, "bad... msg: '%s' len: %d" % (msg, len(msg)) - -for i in range(1,4): - try: - t.multi(i) - except RuntimeError,e: - pass - except threads_exception.Exc,e: - pass + try: + t.hosed() + except threads_exception.Exc, e: + code = e.code + if code != 42: + raise RuntimeError, "bad... code: %d" % code + msg = e.msg + if msg != "Hosed": + raise RuntimeError, "bad... msg: '%s' len: %d" % (msg, len(msg)) +for i in range(1, 4): + try: + t.multi(i) + except RuntimeError, e: + pass + except threads_exception.Exc, e: + pass diff --git a/Examples/test-suite/python/typedef_class_runme.py b/Examples/test-suite/python/typedef_class_runme.py index 71436b399d1..6d2f2a5c388 100644 --- a/Examples/test-suite/python/typedef_class_runme.py +++ b/Examples/test-suite/python/typedef_class_runme.py @@ -1,7 +1,7 @@ import typedef_class -a = typedef_class.RealA() -a.a = 3 - -b = typedef_class.B() -b.testA(a) +a = typedef_class.RealA() +a.a = 3 + +b = typedef_class.B() +b.testA(a) diff --git a/Examples/test-suite/python/typedef_scope_runme.py b/Examples/test-suite/python/typedef_scope_runme.py index 37bfc97b15d..edd3e9f3a2c 100644 --- a/Examples/test-suite/python/typedef_scope_runme.py +++ b/Examples/test-suite/python/typedef_scope_runme.py @@ -1,12 +1,10 @@ import typedef_scope b = typedef_scope.Bar() -x = b.test1(42,"hello") +x = b.test1(42, "hello") if x != 42: print "Failed!!" -x = b.test2(42,"hello") +x = b.test2(42, "hello") if x != "hello": print "Failed!!" - - diff --git a/Examples/test-suite/python/typedef_typedef_runme.py b/Examples/test-suite/python/typedef_typedef_runme.py index 1d83065a612..92e85c27eab 100644 --- a/Examples/test-suite/python/typedef_typedef_runme.py +++ b/Examples/test-suite/python/typedef_typedef_runme.py @@ -2,4 +2,4 @@ b = typedef_typedef.B() if b.getValue(123) != 1234: - raise Exception("Failed") + raise Exception("Failed") diff --git a/Examples/test-suite/python/typemap_arrays_runme.py b/Examples/test-suite/python/typemap_arrays_runme.py index c23222c635a..ea0f08d6be3 100644 --- a/Examples/test-suite/python/typemap_arrays_runme.py +++ b/Examples/test-suite/python/typemap_arrays_runme.py @@ -2,4 +2,3 @@ if sumA(None) != 60: raise RuntimeError, "Sum is wrong" - diff --git a/Examples/test-suite/python/typemap_namespace_runme.py b/Examples/test-suite/python/typemap_namespace_runme.py index 581a0f437b0..b55eb8ba552 100644 --- a/Examples/test-suite/python/typemap_namespace_runme.py +++ b/Examples/test-suite/python/typemap_namespace_runme.py @@ -5,4 +5,3 @@ if test2("hello") != "hello": raise RuntimeError - diff --git a/Examples/test-suite/python/typemap_out_optimal_runme.py b/Examples/test-suite/python/typemap_out_optimal_runme.py index b148f2d062c..c7a34308e1f 100644 --- a/Examples/test-suite/python/typemap_out_optimal_runme.py +++ b/Examples/test-suite/python/typemap_out_optimal_runme.py @@ -1,5 +1,4 @@ from typemap_out_optimal import * cvar.XX_debug = False -x = XX.create() - +x = XX_create() diff --git a/Examples/test-suite/python/typemap_qualifier_strip_runme.py b/Examples/test-suite/python/typemap_qualifier_strip_runme.py index 5e466cf6923..dff94f8b4a0 100644 --- a/Examples/test-suite/python/typemap_qualifier_strip_runme.py +++ b/Examples/test-suite/python/typemap_qualifier_strip_runme.py @@ -51,4 +51,3 @@ if typemap_qualifier_strip.testD4(val) != 111: raise RuntimeError - diff --git a/Examples/test-suite/python/typename_runme.py b/Examples/test-suite/python/typename_runme.py index 10c7bff1be7..aac936fde15 100644 --- a/Examples/test-suite/python/typename_runme.py +++ b/Examples/test-suite/python/typename_runme.py @@ -4,9 +4,8 @@ b = typename.Bar() x = typename.twoFoo(f) -if not isinstance(x,types.FloatType): - raise RuntimeError,"Wrong return type (FloatType) !" +if not isinstance(x, types.FloatType): + raise RuntimeError, "Wrong return type (FloatType) !" y = typename.twoBar(b) -if not isinstance(y,types.IntType): - raise RuntimeError,"Wrong return type (IntType)!" - +if not isinstance(y, types.IntType): + raise RuntimeError, "Wrong return type (IntType)!" diff --git a/Examples/test-suite/python/types_directive_runme.py b/Examples/test-suite/python/types_directive_runme.py index c28453e847c..401e3ae1d86 100644 --- a/Examples/test-suite/python/types_directive_runme.py +++ b/Examples/test-suite/python/types_directive_runme.py @@ -1,12 +1,13 @@ from types_directive import * d1 = Time1(2001, 2, 3, 60) -newDate = add(d1, 7) # check that a Time1 instance is accepted where Date is expected +# check that a Time1 instance is accepted where Date is expected +newDate = add(d1, 7) if newDate.day != 10: - raise RuntimeError + raise RuntimeError d2 = Time2(1999, 8, 7, 60) -newDate = add(d2, 7) # check that a Time2 instance is accepted where Date is expected +# check that a Time2 instance is accepted where Date is expected +newDate = add(d2, 7) if newDate.day != 14: - raise RuntimeError - + raise RuntimeError diff --git a/Examples/test-suite/python/unicode_strings_runme.py b/Examples/test-suite/python/unicode_strings_runme.py index e1fc7adecba..3ce98bcdb47 100644 --- a/Examples/test-suite/python/unicode_strings_runme.py +++ b/Examples/test-suite/python/unicode_strings_runme.py @@ -12,3 +12,12 @@ raise ValueError('Test comparison mismatch') if unicode_strings.non_utf8_std_string() != test_string: raise ValueError('Test comparison mismatch') + +# Testing SWIG_PYTHON_2_UNICODE flag which allows unicode strings to be passed to C +if sys.version_info[0:2] < (3, 0): + assert unicode_strings.charstring("hello1") == "hello1" + assert unicode_strings.charstring(str(u"hello2")) == "hello2" + assert unicode_strings.charstring(u"hello3") == "hello3" + assert unicode_strings.charstring(unicode("hello4")) == "hello4" + unicode_strings.charstring(u"hell\xb05") + unicode_strings.charstring(u"hell\u00f66") diff --git a/Examples/test-suite/python/unions_runme.py b/Examples/test-suite/python/unions_runme.py index d59e2429e00..387a048c863 100644 --- a/Examples/test-suite/python/unions_runme.py +++ b/Examples/test-suite/python/unions_runme.py @@ -1,5 +1,5 @@ -# This is the union runtime testcase. It ensures that values within a +# This is the union runtime testcase. It ensures that values within a # union embedded within a struct can be set and read correctly. import unions @@ -23,12 +23,12 @@ eut.uni.small = small Jill1 = eut.uni.small.jill if (Jill1 != 200): - print "Runtime test1 failed. eut.uni.small.jill=" , Jill1 + print "Runtime test1 failed. eut.uni.small.jill=", Jill1 sys.exit(1) Num1 = eut.number if (Num1 != 1): - print "Runtime test2 failed. eut.number=" , Num1 + print "Runtime test2 failed. eut.number=", Num1 sys.exit(1) # Secondly check the BigStruct in EmbeddedUnionTest @@ -36,16 +36,15 @@ eut.uni.big = big Jack1 = eut.uni.big.jack if (Jack1 != 300): - print "Runtime test3 failed. eut.uni.big.jack=" , Jack1 + print "Runtime test3 failed. eut.uni.big.jack=", Jack1 sys.exit(1) Jill2 = eut.uni.big.smallstruct.jill if (Jill2 != 200): - print "Runtime test4 failed. eut.uni.big.smallstruct.jill=" , Jill2 + print "Runtime test4 failed. eut.uni.big.smallstruct.jill=", Jill2 sys.exit(1) Num2 = eut.number if (Num2 != 2): - print "Runtime test5 failed. eut.number=" , Num2 + print "Runtime test5 failed. eut.number=", Num2 sys.exit(1) - diff --git a/Examples/test-suite/python/using_composition_runme.py b/Examples/test-suite/python/using_composition_runme.py index 6baa16d13b9..c4f3390953b 100644 --- a/Examples/test-suite/python/using_composition_runme.py +++ b/Examples/test-suite/python/using_composition_runme.py @@ -2,33 +2,32 @@ f = FooBar() if f.blah(3) != 3: - raise RuntimeError,"FooBar::blah(int)" + raise RuntimeError, "FooBar::blah(int)" if f.blah(3.5) != 3.5: - raise RuntimeError,"FooBar::blah(double)" + raise RuntimeError, "FooBar::blah(double)" if f.blah("hello") != "hello": - raise RuntimeError,"FooBar::blah(char *)" + raise RuntimeError, "FooBar::blah(char *)" f = FooBar2() if f.blah(3) != 3: - raise RuntimeError,"FooBar2::blah(int)" + raise RuntimeError, "FooBar2::blah(int)" if f.blah(3.5) != 3.5: - raise RuntimeError,"FooBar2::blah(double)" + raise RuntimeError, "FooBar2::blah(double)" if f.blah("hello") != "hello": - raise RuntimeError,"FooBar2::blah(char *)" + raise RuntimeError, "FooBar2::blah(char *)" f = FooBar3() if f.blah(3) != 3: - raise RuntimeError,"FooBar3::blah(int)" + raise RuntimeError, "FooBar3::blah(int)" if f.blah(3.5) != 3.5: - raise RuntimeError,"FooBar3::blah(double)" + raise RuntimeError, "FooBar3::blah(double)" if f.blah("hello") != "hello": - raise RuntimeError,"FooBar3::blah(char *)" - + raise RuntimeError, "FooBar3::blah(char *)" diff --git a/Examples/test-suite/python/using_extend_runme.py b/Examples/test-suite/python/using_extend_runme.py index 14615a05e96..038a1686a8e 100644 --- a/Examples/test-suite/python/using_extend_runme.py +++ b/Examples/test-suite/python/using_extend_runme.py @@ -2,20 +2,20 @@ f = FooBar() if f.blah(3) != 3: - raise RuntimeError,"blah(int)" + raise RuntimeError, "blah(int)" if f.blah(3.5) != 3.5: - raise RuntimeError,"blah(double)" + raise RuntimeError, "blah(double)" if f.blah("hello") != "hello": - raise RuntimeError,"blah(char *)" + raise RuntimeError, "blah(char *)" -if f.blah(3,4) != 7: - raise RuntimeError,"blah(int,int)" +if f.blah(3, 4) != 7: + raise RuntimeError, "blah(int,int)" -if f.blah(3.5,7.5) != (3.5+7.5): - raise RuntimeError,"blah(double,double)" +if f.blah(3.5, 7.5) != (3.5 + 7.5): + raise RuntimeError, "blah(double,double)" if f.duh(3) != 3: - raise RuntimeError,"duh(int)" + raise RuntimeError, "duh(int)" diff --git a/Examples/test-suite/python/using_inherit_runme.py b/Examples/test-suite/python/using_inherit_runme.py index b00e66ec3fb..4fd5959683f 100644 --- a/Examples/test-suite/python/using_inherit_runme.py +++ b/Examples/test-suite/python/using_inherit_runme.py @@ -2,48 +2,47 @@ b = Bar() if b.test(3) != 3: - raise RuntimeError,"Bar::test(int)" + raise RuntimeError, "Bar::test(int)" if b.test(3.5) != 3.5: - raise RuntimeError, "Bar::test(double)" + raise RuntimeError, "Bar::test(double)" b = Bar2() if b.test(3) != 6: - raise RuntimeError,"Bar2::test(int)" + raise RuntimeError, "Bar2::test(int)" if b.test(3.5) != 7.0: - raise RuntimeError, "Bar2::test(double)" + raise RuntimeError, "Bar2::test(double)" b = Bar3() if b.test(3) != 6: - raise RuntimeError,"Bar3::test(int)" + raise RuntimeError, "Bar3::test(int)" if b.test(3.5) != 7.0: - raise RuntimeError, "Bar3::test(double)" + raise RuntimeError, "Bar3::test(double)" b = Bar4() if b.test(3) != 6: - raise RuntimeError,"Bar4::test(int)" + raise RuntimeError, "Bar4::test(int)" if b.test(3.5) != 7.0: - raise RuntimeError, "Bar4::test(double)" + raise RuntimeError, "Bar4::test(double)" b = Fred1() if b.test(3) != 3: - raise RuntimeError,"Fred1::test(int)" + raise RuntimeError, "Fred1::test(int)" if b.test(3.5) != 7.0: - raise RuntimeError, "Fred1::test(double)" + raise RuntimeError, "Fred1::test(double)" b = Fred2() if b.test(3) != 3: - raise RuntimeError,"Fred2::test(int)" + raise RuntimeError, "Fred2::test(int)" if b.test(3.5) != 7.0: - raise RuntimeError, "Fred2::test(double)" - + raise RuntimeError, "Fred2::test(double)" diff --git a/Examples/test-suite/python/varargs_overload_runme.py b/Examples/test-suite/python/varargs_overload_runme.py index a3b2068b58f..37958620c3b 100644 --- a/Examples/test-suite/python/varargs_overload_runme.py +++ b/Examples/test-suite/python/varargs_overload_runme.py @@ -28,4 +28,3 @@ if varargs_overload.vararg_over4("Hello", 123) != "Hello": raise RuntimeError, "Failed" - diff --git a/Examples/test-suite/python/varargs_runme.py b/Examples/test-suite/python/varargs_runme.py index 2c68f4e0660..7105ba8d77a 100644 --- a/Examples/test-suite/python/varargs_runme.py +++ b/Examples/test-suite/python/varargs_runme.py @@ -11,7 +11,7 @@ raise RuntimeError, "Failed" -if varargs.test_def("Hello",1) != "Hello": +if varargs.test_def("Hello", 1) != "Hello": raise RuntimeError, "Failed" if varargs.test_def("Hello") != "Hello": diff --git a/Examples/test-suite/python/virtual_derivation_runme.py b/Examples/test-suite/python/virtual_derivation_runme.py index 8a6e743afdf..68546c6eb11 100644 --- a/Examples/test-suite/python/virtual_derivation_runme.py +++ b/Examples/test-suite/python/virtual_derivation_runme.py @@ -4,5 +4,4 @@ # b = B(3) if b.get_a() != b.get_b(): - raise RuntimeError, "something is really wrong" - + raise RuntimeError, "something is really wrong" diff --git a/Examples/test-suite/python/virtual_poly_runme.py b/Examples/test-suite/python/virtual_poly_runme.py index 7e202f9cf77..0df6271ef05 100644 --- a/Examples/test-suite/python/virtual_poly_runme.py +++ b/Examples/test-suite/python/virtual_poly_runme.py @@ -5,25 +5,25 @@ # # the copy methods return the right polymorphic types -# +# dc = d.copy() ic = i.copy() if d.get() != dc.get(): - raise RuntimeError + raise RuntimeError if i.get() != ic.get(): - raise RuntimeError + raise RuntimeError virtual_poly.incr(ic) if (i.get() + 1) != ic.get(): - raise RuntimeError + raise RuntimeError dr = d.ref_this() if d.get() != dr.get(): - raise RuntimeError + raise RuntimeError # @@ -31,8 +31,8 @@ # ddc = virtual_poly.NDouble_narrow(d.nnumber()) if d.get() != ddc.get(): - raise RuntimeError + raise RuntimeError dic = virtual_poly.NInt_narrow(i.nnumber()) if i.get() != dic.get(): - raise RuntimeError + raise RuntimeError diff --git a/Examples/test-suite/python/voidtest_runme.py b/Examples/test-suite/python/voidtest_runme.py index a7b421d6e06..b16cacf0008 100644 --- a/Examples/test-suite/python/voidtest_runme.py +++ b/Examples/test-suite/python/voidtest_runme.py @@ -6,10 +6,11 @@ voidtest.Foo_staticmemberfunc() + def fvoid(): pass -if f.memberfunc() != fvoid(): +if f.memberfunc() != fvoid(): raise RuntimeError diff --git a/Examples/test-suite/python/wrapmacro_runme.py b/Examples/test-suite/python/wrapmacro_runme.py index 0272afd5d77..5e28d6bc926 100644 --- a/Examples/test-suite/python/wrapmacro_runme.py +++ b/Examples/test-suite/python/wrapmacro_runme.py @@ -2,6 +2,6 @@ a = 2 b = -1 -wrapmacro.maximum(a,b) -wrapmacro.maximum(a/7.0, -b*256) +wrapmacro.maximum(a, b) +wrapmacro.maximum(a / 7.0, -b * 256) wrapmacro.GUINT16_SWAP_LE_BE_CONSTANT(1) diff --git a/Examples/test-suite/python_append.i b/Examples/test-suite/python_append.i index f37a6c199f7..2a71b5784ba 100644 --- a/Examples/test-suite/python_append.i +++ b/Examples/test-suite/python_append.i @@ -12,6 +12,9 @@ def grabpath(): return funcpath def grabstaticpath(): return staticfuncpath +def clearstaticpath(): + global staticfuncpath + staticfuncpath = None %} %pythonappend Test::func %{ diff --git a/Examples/test-suite/python_destructor_exception.i b/Examples/test-suite/python_destructor_exception.i new file mode 100644 index 00000000000..150a396de4b --- /dev/null +++ b/Examples/test-suite/python_destructor_exception.i @@ -0,0 +1,19 @@ +/* File : example.i */ +%module python_destructor_exception +%include exception.i + +%exception ClassWithThrowingDestructor::~ClassWithThrowingDestructor() +{ + $action + SWIG_exception(SWIG_RuntimeError, "I am the ClassWithThrowingDestructor dtor doing bad things"); +} + +%inline %{ +class ClassWithThrowingDestructor +{ +}; + +%} + +%include +%template(VectorInt) std::vector; diff --git a/Examples/test-suite/python_docstring.i b/Examples/test-suite/python_docstring.i new file mode 100644 index 00000000000..3b88167ebed --- /dev/null +++ b/Examples/test-suite/python_docstring.i @@ -0,0 +1,98 @@ +%module python_docstring + +// Test indentation when using the docstring feature. +// Checks tabs and spaces as input for indentation. + +%feature("docstring") docstring1 %{ + line 1 +line 2 + + + +line 3 +%} + +%feature("docstring") docstring2 %{ +line 1 + line 2 + + + + line 3 + %} + +%feature("docstring") docstring3 %{ + line 1 + line 2 + + + + line 3 + %} + +%feature("docstring") docstring4 %{ + line 1 + line 2 + + + + line 3 + %} + +%feature("docstring") docstring5 +%{ line 1 + line 2 + + + + line 3 + %} + +%feature("docstring") docstring6 +{ + line 1 + line 2 + + + + line 3 +} + +%feature("docstring") docstring7 +{ +line 1 +line 2 +line 3 +} + +%feature("docstring") docstringA +%{ first line + second line%} + +%feature("docstring") docstringB +%{ first line + second line%} + +%feature("docstring") docstringC +%{ first line + second line%} + +%feature("docstring") docstringX " one line docs" +%feature("docstring") docstringY "one line docs" + +%inline %{ +struct DocStrings { + void docstring1() {} + void docstring2() {} + void docstring3() {} + void docstring4() {} + void docstring5() {} + void docstring6() {} + void docstring7() {} + void docstringA() {} + void docstringB() {} + void docstringC() {} + void docstringX() {} + void docstringY() {} +}; +%} diff --git a/Examples/test-suite/python_pythoncode.i b/Examples/test-suite/python_pythoncode.i new file mode 100644 index 00000000000..70474d44c8b --- /dev/null +++ b/Examples/test-suite/python_pythoncode.i @@ -0,0 +1,31 @@ +%module python_pythoncode + +// github issue#379 - these examples failed with 3.0.5 and earlier (at least as +// far back as 1.3.37): + +struct TYPE { +%pythoncode %{ + def one(): + a = 1 +# Comment XXXX + return a +%} +}; + +%define %bar +%pythoncode %{ + def one(): + a = 1 + # + return a +%} +%enddef + +struct TYPE2 { +%bar +}; + +%{ +struct TYPE { }; +struct TYPE2 { }; +%} diff --git a/Examples/test-suite/python_strict_unicode.i b/Examples/test-suite/python_strict_unicode.i new file mode 100644 index 00000000000..93240a9b7fb --- /dev/null +++ b/Examples/test-suite/python_strict_unicode.i @@ -0,0 +1,41 @@ +%module python_strict_unicode + +%include +%include + +%begin %{ +#define SWIG_PYTHON_STRICT_BYTE_CHAR +#define SWIG_PYTHON_STRICT_UNICODE_WCHAR +%} + +%inline %{ +std::string double_str(const std::string& in) +{ + return in + in; +} + +char *same_str(char* in) +{ + return in; +} + +std::wstring double_wstr(const std::wstring& in) +{ + return in + in; +} + +wchar_t *same_wstr(wchar_t* in) +{ + return in; +} + +std::wstring overload(const std::wstring& in) +{ + return L"UNICODE"; +} + +std::string overload(const std::string& in) +{ + return "BYTES"; +} +%} diff --git a/Examples/test-suite/python_varargs_typemap.i b/Examples/test-suite/python_varargs_typemap.i index 09deea3b7a9..c7d8b83ec0d 100644 --- a/Examples/test-suite/python_varargs_typemap.i +++ b/Examples/test-suite/python_varargs_typemap.i @@ -6,7 +6,7 @@ %typemap(in) (...)(char *vargs[10]) { int i; - int argc; + Py_ssize_t argc; for (i = 0; i < 10; i++) vargs[i] = 0; argc = PyTuple_Size(varargs); if (argc > 10) { diff --git a/Examples/test-suite/r/Makefile.in b/Examples/test-suite/r/Makefile.in index d0489531f48..312834a512d 100644 --- a/Examples/test-suite/r/Makefile.in +++ b/Examples/test-suite/r/Makefile.in @@ -5,7 +5,7 @@ LANGUAGE = r SCRIPTSUFFIX = _runme.R WRAPSUFFIX = .R -RUNR = R CMD BATCH --no-save --no-restore +RUNR = R CMD BATCH --no-save --no-restore '--args $(SCRIPTDIR)' srcdir = @srcdir@ top_srcdir = @top_srcdir@ @@ -44,6 +44,7 @@ include $(srcdir)/../common.mk +$(swig_and_compile_multi_cpp) $(run_multitestcase) + # Runs the testcase. # # Run the runme if it exists. If not just load the R wrapper to @@ -66,7 +67,7 @@ run_multitestcase = \ done # Clean clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" r_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' r_clean %.clean: @rm -f $*.R $*_wrap.so $*_wrap.cpp $*_wrap.c $*_wrap.o $*_runme.Rout $*.Rout diff --git a/Examples/test-suite/r/arrays_dimensionless_runme.R b/Examples/test-suite/r/arrays_dimensionless_runme.R index 9b97de2d887..4fc2541ffc4 100644 --- a/Examples/test-suite/r/arrays_dimensionless_runme.R +++ b/Examples/test-suite/r/arrays_dimensionless_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("arrays_dimensionless", .Platform$dynlib.ext, sep="")) source("arrays_dimensionless.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/funcptr_runme.R b/Examples/test-suite/r/funcptr_runme.R index 3d5281bfaff..c6127ef68d5 100644 --- a/Examples/test-suite/r/funcptr_runme.R +++ b/Examples/test-suite/r/funcptr_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("funcptr", .Platform$dynlib.ext, sep="")) source("funcptr.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/ignore_parameter_runme.R b/Examples/test-suite/r/ignore_parameter_runme.R index 89e461d71fb..612b7001318 100644 --- a/Examples/test-suite/r/ignore_parameter_runme.R +++ b/Examples/test-suite/r/ignore_parameter_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("ignore_parameter", .Platform$dynlib.ext, sep="")) source("ignore_parameter.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/integers_runme.R b/Examples/test-suite/r/integers_runme.R index e31099a3b0e..6e2f63b706d 100644 --- a/Examples/test-suite/r/integers_runme.R +++ b/Examples/test-suite/r/integers_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("integers", .Platform$dynlib.ext, sep="")) source("integers.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/overload_method_runme.R b/Examples/test-suite/r/overload_method_runme.R index afb590a7477..790f3df1048 100644 --- a/Examples/test-suite/r/overload_method_runme.R +++ b/Examples/test-suite/r/overload_method_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("overload_method", .Platform$dynlib.ext, sep="")) source("overload_method.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/preproc_constants_runme.R b/Examples/test-suite/r/preproc_constants_runme.R new file mode 100644 index 00000000000..138786e67da --- /dev/null +++ b/Examples/test-suite/r/preproc_constants_runme.R @@ -0,0 +1,12 @@ +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + +dyn.load(paste("preproc_constants", .Platform$dynlib.ext, sep="")) +source("preproc_constants.R") +cacheMetaData(1) + +v <- enumToInteger('kValue', '_MyEnum') +print(v) +# temporarily removed until fixed (in progress, see Github patch #500) +#unittest(v,4) +q(save="no") diff --git a/Examples/test-suite/r/r_copy_struct_runme.R b/Examples/test-suite/r/r_copy_struct_runme.R index 21bd93b6456..deadc61fed8 100644 --- a/Examples/test-suite/r/r_copy_struct_runme.R +++ b/Examples/test-suite/r/r_copy_struct_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("r_copy_struct", .Platform$dynlib.ext, sep="")) source("r_copy_struct.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/r_legacy_runme.R b/Examples/test-suite/r/r_legacy_runme.R index 7e5ade87faa..3ca229ff892 100644 --- a/Examples/test-suite/r/r_legacy_runme.R +++ b/Examples/test-suite/r/r_legacy_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("r_legacy", .Platform$dynlib.ext, sep="")) source("r_legacy.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/r_sexp_runme.R b/Examples/test-suite/r/r_sexp_runme.R index 96b36e8af01..e7b28a9654d 100644 --- a/Examples/test-suite/r/r_sexp_runme.R +++ b/Examples/test-suite/r/r_sexp_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("r_sexp", .Platform$dynlib.ext, sep="")) source("r_sexp.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/rename_simple_runme.R b/Examples/test-suite/r/rename_simple_runme.R index b25aeb84448..0628ca6c929 100644 --- a/Examples/test-suite/r/rename_simple_runme.R +++ b/Examples/test-suite/r/rename_simple_runme.R @@ -1,4 +1,6 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + dyn.load(paste("rename_simple", .Platform$dynlib.ext, sep="")) source("rename_simple.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/simple_array_runme.R b/Examples/test-suite/r/simple_array_runme.R index a6758dedda5..fe70dc32445 100644 --- a/Examples/test-suite/r/simple_array_runme.R +++ b/Examples/test-suite/r/simple_array_runme.R @@ -1,4 +1,5 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) dyn.load(paste("simple_array", .Platform$dynlib.ext, sep="")) source("simple_array.R") cacheMetaData(1) diff --git a/Examples/test-suite/r/unions_runme.R b/Examples/test-suite/r/unions_runme.R index 76870d10c52..fd148c7ef4b 100644 --- a/Examples/test-suite/r/unions_runme.R +++ b/Examples/test-suite/r/unions_runme.R @@ -1,4 +1,5 @@ -source("unittest.R") +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) dyn.load(paste("unions", .Platform$dynlib.ext, sep="")) source("unions.R") cacheMetaData(1) diff --git a/Examples/test-suite/r_copy_struct.i b/Examples/test-suite/r_copy_struct.i index fda321afb4d..6a79b542234 100644 --- a/Examples/test-suite/r_copy_struct.i +++ b/Examples/test-suite/r_copy_struct.i @@ -48,7 +48,7 @@ getA() return a; } -static struct A fixed = {20, 3, 42.0}; +static struct A fixed = {20, 3, 42.0, 0, 0}; struct A * getARef() diff --git a/Examples/test-suite/rename.h b/Examples/test-suite/rename.h index 4750337a9ce..c8199eeebb3 100644 --- a/Examples/test-suite/rename.h +++ b/Examples/test-suite/rename.h @@ -31,13 +31,27 @@ namespace Space { }; } +#if defined(SWIG) +%exception Space::ABC::operator ABC %{ +#if defined(__clang__) + // Workaround for: warning: conversion function converting 'Space::ABC' to itself will never be used + result = *arg1; +#else + $action +#endif +%} +#endif + namespace Space { // non-templated class using itself in method and operator class ABC { public: void method(ABC a) const {} void method(Klass k) const {} +#if !defined(__clang__) + // Workaround for: warning: conversion function converting 'Space::ABC' to itself will never be used operator ABC() const { ABC a; return a; } +#endif operator Klass() const { Klass k; return k; } }; } diff --git a/Examples/test-suite/rename4.i b/Examples/test-suite/rename4.i index 3f61e0c6906..9ddff362f33 100644 --- a/Examples/test-suite/rename4.i +++ b/Examples/test-suite/rename4.i @@ -78,6 +78,15 @@ namespace Space { }; } +%exception Space::ABC::operator ABC %{ +#if defined(__clang__) + // Workaround for: warning: conversion function converting 'Space::ABC' to itself will never be used + result = *arg1; +#else + $action +#endif +%} + namespace Space { // non-templated class using itself in method and operator class ABC { @@ -90,7 +99,10 @@ class ABC { void method(ABC a) const {} void method(Klass k) const {} +#if !defined(__clang__) + // Workaround for: warning: conversion function converting 'Space::ABC' to itself will never be used operator ABC() const { ABC a; return a; } +#endif operator Klass() const { Klass k; return k; } }; } diff --git a/Examples/test-suite/ruby/Makefile.in b/Examples/test-suite/ruby/Makefile.in index ae499588291..847c959199c 100644 --- a/Examples/test-suite/ruby/Makefile.in +++ b/Examples/test-suite/ruby/Makefile.in @@ -11,7 +11,6 @@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ CPP_TEST_CASES = \ - li_cdata \ li_cstring \ li_factory \ li_std_functors \ @@ -22,6 +21,7 @@ CPP_TEST_CASES = \ li_std_stack \ primitive_types \ ruby_keywords \ + ruby_minherit_shared_ptr \ ruby_naming \ ruby_track_objects \ ruby_track_objects_directors \ @@ -30,7 +30,6 @@ CPP_TEST_CASES = \ # stl_new C_TEST_CASES += \ - li_cdata \ li_cstring include $(srcdir)/../common.mk @@ -61,7 +60,7 @@ ruby_naming.cpptest: SWIGOPT += -autorename # a file is found which has _runme.rb appended after the testcase name. run_testcase = \ if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) -I$(srcdir):. $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) $(RUBYFLAGS) -I$(srcdir):. $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \ fi # Clean @@ -69,4 +68,4 @@ run_testcase = \ @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" ruby_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/test-suite/ruby/cpp11_li_std_array_runme.rb b/Examples/test-suite/ruby/cpp11_li_std_array_runme.rb new file mode 100644 index 00000000000..770f37c0fe6 --- /dev/null +++ b/Examples/test-suite/ruby/cpp11_li_std_array_runme.rb @@ -0,0 +1,134 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'swig_assert' + +require 'cpp11_li_std_array' + +include Cpp11_li_std_array + + +def failed(a, b, msg) + raise RuntimeError, "#{msg} #{a} #{b}" +end + +def compare_sequences(a, b) + if a.size != b.size + failed(a, b, "different sizes") + end + for i in 0..a.size-1 + failed(a, b, "elements are different:") if a[i] != b[i] + end +end + +def compare_containers(rubyarray, swigarray) + compare_sequences(rubyarray, swigarray) +end + +def setslice_exception(swigarray, newval) + begin + swigarray[0..swigarray.size] = newval + raise RuntimeError, "swigarray[] = #{newval} missed set exception for swigarray: #{swigarray}" + rescue ArgumentError => e +# print "exception: #{e}" + end +end + + +# Check std::array has similar behaviour to a Ruby array +# except it is not resizable + +ps = [0, 1, 2, 3, 4, 5] + +ai = ArrayInt6.new(ps) + +compare_containers(ps, ai) + +# slices +compare_containers(ps[0..5], ai[0..5]) +compare_containers(ps[-6..-1], ai[-6..-1]) +compare_containers(ps[0..10], ai[0..10]) + +# Reverse (.reverse is not provided) +rev = [] +ai.reverse_each { |i| rev.push i } +compare_containers(ps.reverse, rev) + +# Modify content +for i in 0..ps.size-1 + ps[i] = ps[i] * 10 + ai[i] = ai[i] * 10 +end +compare_containers(ps, ai) + +# Empty +ai = ArrayInt6.new() +compare_containers([0, 0, 0, 0, 0, 0], ai) + +# Set slice +newvals = [10, 20, 30, 40, 50, 60] +ai[0, 6] = newvals +compare_containers(ai, newvals) + +ai[-6, 6] = newvals +compare_containers(ai, newvals) + +setslice_exception(ai, [1, 2, 3, 4, 5, 6, 7]) +setslice_exception(ai, [1, 2, 3, 4, 5]) +setslice_exception(ai, [1, 2, 3, 4]) +setslice_exception(ai, [1, 2, 3]) +setslice_exception(ai, [1, 2]) +setslice_exception(ai, [1]) +setslice_exception(ai, []) + +# Check return +compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2]) +compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2]) +compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2]) +compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2]) + +# Check passing arguments +ai = arrayInVal([9, 8, 7, 6, 5, 4]) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +ai = arrayInConstRef([9, 8, 7, 6, 5, 4]) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +ai = ArrayInt6.new([9, 8, 7, 6, 5, 4]) +arrayInRef(ai) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +ai = ArrayInt6.new([9, 8, 7, 6, 5, 4]) +arrayInPtr(ai) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +# indexing +ai = ArrayInt6.new([9, 8, 7, 6, 5, 4]) +swig_assert_equal(ai[0], 9, binding) +swig_assert_equal(ai[5], 4, binding) +swig_assert_equal(ai[6], nil, binding) +swig_assert_equal(ai[-7], nil, binding) + +# fill +ai.fill(111) +compare_containers(ai, [111, 111, 111, 111, 111, 111]) + +# various +ai = ArrayInt6.new([9, 8, 7, 6, 5, 4]) +swig_assert(ai.include? 9) +swig_assert(!ai.include?(99)) +swig_assert(ai.kind_of? ArrayInt6) +swig_assert(ai.find {|x| x == 6 } == 6) +swig_assert(ai.find {|x| x == 66 } == nil) +swig_assert(ai.respond_to?(:each)) +swig_assert(ai.respond_to?(:each_with_index)) + +ai = [0, 10, 20, 30, 40, 50] +ai.each_with_index { |e,i| swig_assert(e/10 == i) } + diff --git a/Examples/test-suite/ruby/default_constructor_runme.rb b/Examples/test-suite/ruby/default_constructor_runme.rb index 2706f67ca65..5cd675879af 100644 --- a/Examples/test-suite/ruby/default_constructor_runme.rb +++ b/Examples/test-suite/ruby/default_constructor_runme.rb @@ -143,9 +143,6 @@ # This should work fine f = F.new -# This should work fine -ff = FFF.new - # This should work fine g = G.new diff --git a/Examples/test-suite/ruby/director_smartptr_runme.rb b/Examples/test-suite/ruby/director_smartptr_runme.rb new file mode 100644 index 00000000000..8b4bd3d6d14 --- /dev/null +++ b/Examples/test-suite/ruby/director_smartptr_runme.rb @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'director_smartptr' + +include Director_smartptr + +class Director_smartptr_MyBarFoo < Foo + + def ping() + return "director_smartptr_MyBarFoo.ping()" + end + + def pong() + return "director_smartptr_MyBarFoo.pong();" + ping() + end + + def upcall(fooBarPtr) + return "override;" + fooBarPtr.FooBarDo() + end + + def makeFoo() + return Foo.new() + end +end + +def check(got, expected) + if (got != expected) + raise RuntimeError, "Failed, got: #{got} expected: #{expected}" + end +end + +fooBar = Director_smartptr::FooBar.new() + +myBarFoo = Director_smartptr_MyBarFoo.new() +check(myBarFoo.ping(), "director_smartptr_MyBarFoo.ping()") +check(Foo.callPong(myBarFoo), "director_smartptr_MyBarFoo.pong();director_smartptr_MyBarFoo.ping()") +check(Foo.callUpcall(myBarFoo, fooBar), "override;Bar::Foo2::Foo2Bar()") + +myFoo = myBarFoo.makeFoo() +check(myFoo.pong(), "Foo::pong();Foo::ping()") +check(Foo.callPong(myFoo), "Foo::pong();Foo::ping()") +check(myFoo.upcall(FooBar.new()), "Bar::Foo2::Foo2Bar()") + +myFoo2 = Foo.new().makeFoo() +check(myFoo2.pong(), "Foo::pong();Foo::ping()") +check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()") +check(myFoo2.upcall(FooBar.new()), "Bar::Foo2::Foo2Bar()") diff --git a/Examples/test-suite/ruby/li_boost_array_runme.rb b/Examples/test-suite/ruby/li_boost_array_runme.rb new file mode 100644 index 00000000000..a7b7720ea5d --- /dev/null +++ b/Examples/test-suite/ruby/li_boost_array_runme.rb @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'swig_assert' + +require 'li_boost_array' + +include Li_boost_array + + +def failed(a, b, msg) + raise RuntimeError, "#{msg} #{a} #{b}" +end + +def compare_sequences(a, b) + if a.size != b.size + failed(a, b, "different sizes") + end + for i in 0..a.size-1 + failed(a, b, "elements are different:") if a[i] != b[i] + end +end + +def compare_containers(rubyarray, swigarray) + compare_sequences(rubyarray, swigarray) +end + +ps = [0, 1, 2, 3, 4, 5] + +ai = ArrayInt6.new(ps) + +compare_containers(ps, ai) + +# Modify content +for i in 0..ps.size-1 + ps[i] = ps[i] * 10 + ai[i] = ai[i] * 10 +end +compare_containers(ps, ai) + +# Empty +ai = ArrayInt6.new() + +# Check return +compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2]) +compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2]) +#compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2]) +#compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2]) + +# Check passing arguments +ai = arrayInVal([9, 8, 7, 6, 5, 4]) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +ai = arrayInConstRef([9, 8, 7, 6, 5, 4]) +compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +#ai = ArrayInt6.new([9, 8, 7, 6, 5, 4]) +#arrayInRef(ai) +#compare_containers(ai, [90, 80, 70, 60, 50, 40]) + +#ai = ArrayInt6.new([9, 8, 7, 6, 5, 4]) +#arrayInPtr(ai) +#compare_containers(ai, [90, 80, 70, 60, 50, 40]) + diff --git a/Examples/test-suite/ruby/li_boost_shared_ptr_bits_runme.rb b/Examples/test-suite/ruby/li_boost_shared_ptr_bits_runme.rb new file mode 100644 index 00000000000..bcd817e5ac7 --- /dev/null +++ b/Examples/test-suite/ruby/li_boost_shared_ptr_bits_runme.rb @@ -0,0 +1,32 @@ +require 'li_boost_shared_ptr_bits' +require 'swig_gc' + +v = Li_boost_shared_ptr_bits::VectorIntHolder.new() +v.push(Li_boost_shared_ptr_bits::IntHolder.new(11)) +v.push(Li_boost_shared_ptr_bits::IntHolder.new(22)) +v.push(Li_boost_shared_ptr_bits::IntHolder.new(33)) + +sum = Li_boost_shared_ptr_bits::sum(v) +if (sum != 66) + raise RuntimeError, "sum is wrong" +end + +hidden = Li_boost_shared_ptr_bits::HiddenDestructor.create() +GC.track_class = Li_boost_shared_ptr_bits::HiddenPrivateDestructor +GC.stats if $VERBOSE +hidden = nil +GC.start + +hiddenPrivate = Li_boost_shared_ptr_bits::HiddenPrivateDestructor.create() +if (Li_boost_shared_ptr_bits::HiddenPrivateDestructor.DeleteCount != 0) + # GC doesn't always run +# raise RuntimeError, "Count should be zero" +end + +GC.stats if $VERBOSE +hiddenPrivate = nil +GC.start +if (Li_boost_shared_ptr_bits::HiddenPrivateDestructor.DeleteCount != 1) + # GC doesn't always run +# raise RuntimeError, "Count should be one" +end diff --git a/Examples/test-suite/ruby/li_boost_shared_ptr_runme.rb b/Examples/test-suite/ruby/li_boost_shared_ptr_runme.rb new file mode 100644 index 00000000000..cc5c0cab062 --- /dev/null +++ b/Examples/test-suite/ruby/li_boost_shared_ptr_runme.rb @@ -0,0 +1,614 @@ +require 'li_boost_shared_ptr' +require 'swig_gc' + +#debug = $VERBOSE +debug = false + +# simple shared_ptr usage - created in C++ + + +class Li_boost_shared_ptr_runme + + def main(debug) + if (debug) + puts "Started" + end + + Li_boost_shared_ptr::debug_shared = debug + + # Change loop count to run for a long time to monitor memory + loopCount = 1 # 5000 + 1.upto(loopCount) do + self.runtest() + end + + # Expect 1 instance - the one global variable (GlobalValue) + GC.track_class = Li_boost_shared_ptr::Klass + invokeGC("Final GC") + +# Actual count is 3 due to memory leaks calling rb_raise in the call to Li_boost_shared_ptr::valuetest(nil) +# as setjmp/longjmp are used thereby failing to call destructors of Klass instances on the stack in _wrap_valuetest +# This is a generic problem in Ruby wrappers, not shared_ptr specific +# expectedCount = 1 + expectedCount = 3 + actualCount = Li_boost_shared_ptr::Klass.getTotal_count() + if (actualCount != expectedCount) +# raise RuntimeError, "GC failed to run (li_boost_shared_ptr). Expected count: #{expectedCount} Actual count: #{actualCount}" + puts "GC failed to run (li_boost_shared_ptr). Expected count: #{expectedCount} Actual count: #{actualCount}" + end + + wrapper_count = Li_boost_shared_ptr::shared_ptr_wrapper_count() + if (wrapper_count != Li_boost_shared_ptr.NOT_COUNTING) + # Expect 1 instance - the one global variable (GlobalSmartValue) + if (wrapper_count != 1) + raise RuntimeError, "shared_ptr wrapper count=#{wrapper_count}" + end + end + + if (debug) + puts "Finished" + end + end + + def invokeGC(debug_msg) + puts "invokeGC #{debug_msg} start" if $VERBOSE + GC.stats if $VERBOSE + GC.start + puts "invokeGC #{debug_msg} end" if $VERBOSE + end + + def runtest + # simple shared_ptr usage - created in C++ + k = Li_boost_shared_ptr::Klass.new("me oh my") + val = k.getValue() + self.verifyValue("me oh my", val) + self.verifyCount(1, k) + + # simple shared_ptr usage - not created in C++ + k = Li_boost_shared_ptr::factorycreate() + val = k.getValue() + self.verifyValue("factorycreate", val) + self.verifyCount(1, k) + + # pass by shared_ptr + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::smartpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointertest", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr pointer + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::smartpointerpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerpointertest", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr reference + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::smartpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerreftest", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr pointer reference + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::smartpointerpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerpointerreftest", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # const pass by shared_ptr + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::constsmartpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # const pass by shared_ptr pointer + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::constsmartpointerpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # const pass by shared_ptr reference + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::constsmartpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by value + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::valuetest(k) + val = kret.getValue() + self.verifyValue("me oh my valuetest", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by pointer + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::pointertest(k) + val = kret.getValue() + self.verifyValue("me oh my pointertest", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by reference + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::reftest(k) + val = kret.getValue() + self.verifyValue("me oh my reftest", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by pointer reference + k = Li_boost_shared_ptr::Klass.new("me oh my") + kret = Li_boost_shared_ptr::pointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my pointerreftest", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # null tests + k = nil + + if (Li_boost_shared_ptr::smartpointertest(k) != nil) + raise RuntimeError, "return was not null" + end + + if (Li_boost_shared_ptr::smartpointerpointertest(k) != nil) + raise RuntimeError, "return was not null" + end + + if (Li_boost_shared_ptr::smartpointerreftest(k) != nil) + raise RuntimeError, "return was not null" + end + + if (Li_boost_shared_ptr::smartpointerpointerreftest(k) != nil) + raise RuntimeError, "return was not null" + end + + if (Li_boost_shared_ptr::nullsmartpointerpointertest(nil) != "null pointer") + raise RuntimeError, "not null smartpointer pointer" + end + + begin + Li_boost_shared_ptr::valuetest(k) + raise RuntimeError, "Failed to catch null pointer" + rescue ArgumentError + end + + if (Li_boost_shared_ptr::pointertest(k) != nil) + raise RuntimeError, "return was not null" + end + + begin + Li_boost_shared_ptr::reftest(k) + raise RuntimeError, "Failed to catch null pointer" + rescue ArgumentError + end + + # $owner + k = Li_boost_shared_ptr::pointerownertest() + val = k.getValue() + self.verifyValue("pointerownertest", val) + self.verifyCount(1, k) + k = Li_boost_shared_ptr::smartpointerpointerownertest() + val = k.getValue() + self.verifyValue("smartpointerpointerownertest", val) + self.verifyCount(1, k) + + # //////////////////////////////// Derived class ////////////////////// + # derived pass by shared_ptr + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::derivedsmartptrtest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedsmartptrtest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # derived pass by shared_ptr pointer + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::derivedsmartptrpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedsmartptrpointertest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # derived pass by shared_ptr ref + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::derivedsmartptrreftest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedsmartptrreftest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # derived pass by shared_ptr pointer ref + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::derivedsmartptrpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # derived pass by pointer + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::derivedpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedpointertest-Derived", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # derived pass by ref + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::derivedreftest(k) + val = kret.getValue() + self.verifyValue("me oh my derivedreftest-Derived", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # //////////////////////////////// Derived and base class mixed /////// + # pass by shared_ptr (mixed) + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::smartpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointertest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr pointer (mixed) + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::smartpointerpointertest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerpointertest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr reference (mixed) + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::smartpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerreftest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by shared_ptr pointer reference (mixed) + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::smartpointerpointerreftest(k) + val = kret.getValue() + self.verifyValue("me oh my smartpointerpointerreftest-Derived", val) + self.verifyCount(2, k) + self.verifyCount(2, kret) + + # pass by value (mixed) + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::valuetest(k) + val = kret.getValue() + self.verifyValue("me oh my valuetest", val) # note slicing + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by pointer (mixed) + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::pointertest(k) + val = kret.getValue() + self.verifyValue("me oh my pointertest-Derived", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # pass by ref (mixed) + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + kret = Li_boost_shared_ptr::reftest(k) + val = kret.getValue() + self.verifyValue("me oh my reftest-Derived", val) + self.verifyCount(1, k) + self.verifyCount(1, kret) + + # //////////////////////////////// Overloading tests ////////////////// + # Base class + k = Li_boost_shared_ptr::Klass.new("me oh my") + self.verifyValue(Li_boost_shared_ptr::overload_rawbyval(k), "rawbyval") + self.verifyValue(Li_boost_shared_ptr::overload_rawbyref(k), "rawbyref") + self.verifyValue(Li_boost_shared_ptr::overload_rawbyptr(k), "rawbyptr") + self.verifyValue( + Li_boost_shared_ptr::overload_rawbyptrref(k), "rawbyptrref") + + self.verifyValue( + Li_boost_shared_ptr::overload_smartbyval(k), "smartbyval") + self.verifyValue( + Li_boost_shared_ptr::overload_smartbyref(k), "smartbyref") + self.verifyValue( + Li_boost_shared_ptr::overload_smartbyptr(k), "smartbyptr") + self.verifyValue( + Li_boost_shared_ptr::overload_smartbyptrref(k), "smartbyptrref") + + # Derived class + k = Li_boost_shared_ptr::KlassDerived.new("me oh my") + self.verifyValue(Li_boost_shared_ptr::overload_rawbyval(k), "rawbyval") + self.verifyValue(Li_boost_shared_ptr::overload_rawbyref(k), "rawbyref") + self.verifyValue(Li_boost_shared_ptr::overload_rawbyptr(k), "rawbyptr") + self.verifyValue( + Li_boost_shared_ptr::overload_rawbyptrref(k), "rawbyptrref") + + self.verifyValue( + Li_boost_shared_ptr::overload_smartbyval(k), "smartbyval") + self.verifyValue( + Li_boost_shared_ptr::overload_smartbyref(k), "smartbyref") + self.verifyValue( + Li_boost_shared_ptr::overload_smartbyptr(k), "smartbyptr") + self.verifyValue( + Li_boost_shared_ptr::overload_smartbyptrref(k), "smartbyptrref") + + # 3rd derived class + k = Li_boost_shared_ptr::Klass3rdDerived.new("me oh my") + val = k.getValue() + self.verifyValue("me oh my-3rdDerived", val) + self.verifyCount(1, k) + val = Li_boost_shared_ptr::test3rdupcast(k) + self.verifyValue("me oh my-3rdDerived", val) + self.verifyCount(1, k) + + # //////////////////////////////// Member variables /////////////////// + # smart pointer by value + m = Li_boost_shared_ptr::MemberVariables.new() + k = Li_boost_shared_ptr::Klass.new("smart member value") + m.SmartMemberValue = k + val = k.getValue() + self.verifyValue("smart member value", val) + self.verifyCount(2, k) + + kmember = m.SmartMemberValue + val = kmember.getValue() + self.verifyValue("smart member value", val) + self.verifyCount(3, kmember) + self.verifyCount(3, k) + + GC.track_class = Li_boost_shared_ptr::MemberVariables + m = nil + invokeGC("m = nil (A)") + + self.verifyCount(2, kmember) + self.verifyCount(2, k) + + # smart pointer by pointer + m = Li_boost_shared_ptr::MemberVariables.new() + k = Li_boost_shared_ptr::Klass.new("smart member pointer") + m.SmartMemberPointer = k + val = k.getValue() + self.verifyValue("smart member pointer", val) + self.verifyCount(1, k) + + kmember = m.SmartMemberPointer + val = kmember.getValue() + self.verifyValue("smart member pointer", val) + self.verifyCount(2, kmember) + self.verifyCount(2, k) + + m = nil + invokeGC("m = nil (B)") + + self.verifyCount(2, kmember) + self.verifyCount(2, k) + + # smart pointer by reference + m = Li_boost_shared_ptr::MemberVariables.new() + k = Li_boost_shared_ptr::Klass.new("smart member reference") + m.SmartMemberReference = k + val = k.getValue() + self.verifyValue("smart member reference", val) + self.verifyCount(2, k) + + kmember = m.SmartMemberReference + val = kmember.getValue() + self.verifyValue("smart member reference", val) + self.verifyCount(3, kmember) + self.verifyCount(3, k) + + # The C++ reference refers to SmartMemberValue... + kmemberVal = m.SmartMemberValue + val = kmember.getValue() + self.verifyValue("smart member reference", val) + self.verifyCount(4, kmemberVal) + self.verifyCount(4, kmember) + self.verifyCount(4, k) + + m = nil + invokeGC("m = nil (C)") + + + self.verifyCount(3, kmemberVal) + self.verifyCount(3, kmember) + self.verifyCount(3, k) + + # plain by value + m = Li_boost_shared_ptr::MemberVariables.new() + k = Li_boost_shared_ptr::Klass.new("plain member value") + m.MemberValue = k + val = k.getValue() + self.verifyValue("plain member value", val) + self.verifyCount(1, k) + + kmember = m.MemberValue + val = kmember.getValue() + self.verifyValue("plain member value", val) + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + m = nil + invokeGC("m = nil (D)") + + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + # plain by pointer + m = Li_boost_shared_ptr::MemberVariables.new() + k = Li_boost_shared_ptr::Klass.new("plain member pointer") + m.MemberPointer = k + val = k.getValue() + self.verifyValue("plain member pointer", val) + self.verifyCount(1, k) + + kmember = m.MemberPointer + val = kmember.getValue() + self.verifyValue("plain member pointer", val) + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + m = nil + invokeGC("m = nil (E)") + + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + # plain by reference + m = Li_boost_shared_ptr::MemberVariables.new() + k = Li_boost_shared_ptr::Klass.new("plain member reference") + m.MemberReference = k + val = k.getValue() + self.verifyValue("plain member reference", val) + self.verifyCount(1, k) + + kmember = m.MemberReference + val = kmember.getValue() + self.verifyValue("plain member reference", val) + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + m = nil + invokeGC("m = nil (F)") + + self.verifyCount(1, kmember) + self.verifyCount(1, k) + + # null member variables + m = Li_boost_shared_ptr::MemberVariables.new() + + # shared_ptr by value + k = m.SmartMemberValue + if (k != nil) + raise RuntimeError, "expected null" + end + m.SmartMemberValue = nil + k = m.SmartMemberValue + if (k != nil) + raise RuntimeError, "expected null" + end + self.verifyCount(0, k) + + # plain by value + begin + m.MemberValue = nil + raise RuntimeError, "Failed to catch null pointer" + rescue ArgumentError + end + + # ////////////////////////////////// Global variables ///////////////// + # smart pointer + kglobal = Li_boost_shared_ptr.GlobalSmartValue + if (kglobal != nil) + raise RuntimeError, "expected null" + end + + k = Li_boost_shared_ptr::Klass.new("smart global value") + Li_boost_shared_ptr.GlobalSmartValue = k + self.verifyCount(2, k) + + kglobal = Li_boost_shared_ptr.GlobalSmartValue + val = kglobal.getValue() + self.verifyValue("smart global value", val) + self.verifyCount(3, kglobal) + self.verifyCount(3, k) + self.verifyValue( + "smart global value", Li_boost_shared_ptr.GlobalSmartValue.getValue()) + Li_boost_shared_ptr.GlobalSmartValue = nil + + # plain value + k = Li_boost_shared_ptr::Klass.new("global value") + Li_boost_shared_ptr.GlobalValue = k + self.verifyCount(1, k) + + kglobal = Li_boost_shared_ptr.GlobalValue + val = kglobal.getValue() + self.verifyValue("global value", val) + self.verifyCount(1, kglobal) + self.verifyCount(1, k) + self.verifyValue( + "global value", Li_boost_shared_ptr.GlobalValue.getValue()) + + begin + Li_boost_shared_ptr.GlobalValue = nil + raise RuntimeError, "Failed to catch null pointer" + rescue ArgumentError + end + + # plain pointer + kglobal = Li_boost_shared_ptr.GlobalPointer + if (kglobal != nil) + raise RuntimeError, "expected null" + end + + k = Li_boost_shared_ptr::Klass.new("global pointer") + Li_boost_shared_ptr.GlobalPointer = k + self.verifyCount(1, k) + + kglobal = Li_boost_shared_ptr.GlobalPointer + val = kglobal.getValue() + self.verifyValue("global pointer", val) + self.verifyCount(1, kglobal) + self.verifyCount(1, k) + Li_boost_shared_ptr.GlobalPointer = nil + + # plain reference + + k = Li_boost_shared_ptr::Klass.new("global reference") + Li_boost_shared_ptr.GlobalReference = k + self.verifyCount(1, k) + + kglobal = Li_boost_shared_ptr.GlobalReference + val = kglobal.getValue() + self.verifyValue("global reference", val) + self.verifyCount(1, kglobal) + self.verifyCount(1, k) + + begin + Li_boost_shared_ptr.GlobalReference = nil + raise RuntimeError, "Failed to catch null pointer" + rescue ArgumentError + end + + # ////////////////////////////////// Templates //////////////////////// + pid = Li_boost_shared_ptr::PairIntDouble.new(10, 20.2) + if (pid.baseVal1 != 20 or pid.baseVal2 != 40.4) + raise RuntimeError, "Base values wrong" + end + if (pid.val1 != 10 or pid.val2 != 20.2) + raise RuntimeError, "Derived Values wrong" + end + end + + def verifyValue(expected, got) + if (expected != got) + raise RuntimeError, "verify value failed. Expected: #{expected} Got: #{got}" + end + end + + def verifyCount(expected, k) + got = Li_boost_shared_ptr::use_count(k) + if (expected != got) + puts "skipped verifyCount expect/got: #{expected}/#{got}" +# raise RuntimeError, "verify use_count failed. Expected: #{expected} Got: #{got}" + end + end +end + +runme = Li_boost_shared_ptr_runme.new() +runme.main(debug) diff --git a/Examples/test-suite/ruby/li_boost_shared_ptr_template_runme.rb b/Examples/test-suite/ruby/li_boost_shared_ptr_template_runme.rb new file mode 100644 index 00000000000..7d446a4744a --- /dev/null +++ b/Examples/test-suite/ruby/li_boost_shared_ptr_template_runme.rb @@ -0,0 +1,45 @@ +require 'li_boost_shared_ptr_template' + +begin + b = Li_boost_shared_ptr_template::BaseINTEGER.new() + d = Li_boost_shared_ptr_template::DerivedINTEGER.new() + if (b.bar() != 1) + raise RuntimeError("test 1") + end + if (d.bar() != 2) + raise RuntimeError("test 2") + end + if (Li_boost_shared_ptr_template.bar_getter(b) != 1) + raise RuntimeError("test 3") + end +# Needs fixing as it does for Python +# if (Li_boost_shared_ptr_template.bar_getter(d) != 2) +# raise RuntimeError("test 4") +# end +end + +begin + b = Li_boost_shared_ptr_template::BaseDefaultInt.new() + d = Li_boost_shared_ptr_template::DerivedDefaultInt.new() + d2 = Li_boost_shared_ptr_template::DerivedDefaultInt2.new() + if (b.bar2() != 3) + raise RuntimeError("test 5") + end + if (d.bar2() != 4) + raise RuntimeError("test 6") + end + if (d2.bar2() != 4) + raise RuntimeError("test 6") + end + if (Li_boost_shared_ptr_template.bar2_getter(b) != 3) + raise RuntimeError("test 7") + end +# Needs fixing as it does for Python +# if (Li_boost_shared_ptr_template.bar2_getter(d) != 4) +# raise RuntimeError("test 8") +# end +# if (Li_boost_shared_ptr_template.bar2_getter(d2) != 4) +# raise RuntimeError("test 8") +# end +end + diff --git a/Examples/test-suite/ruby/li_carrays_cpp_runme.rb b/Examples/test-suite/ruby/li_carrays_cpp_runme.rb new file mode 100644 index 00000000000..692d210654c --- /dev/null +++ b/Examples/test-suite/ruby/li_carrays_cpp_runme.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'swig_assert' + +require 'li_carrays_cpp' + +include Li_carrays_cpp + +# +# Testing for %array_functions(int,intArray) +# +ary = new_intArray(2) +intArray_setitem(ary, 0, 0) +intArray_setitem(ary, 1, 1) +intArray_getitem(ary, 0) +intArray_getitem(ary, 1) +delete_intArray(ary) + +# +# Testing for %array_class(double, doubleArray) +# +ary = DoubleArray.new(2) +ary[0] = 0.0 +ary[1] = 1.0 +ary[0] +ary[1] +ptr = ary.cast +ary2 = DoubleArray.frompointer(ptr) + diff --git a/Examples/test-suite/ruby/li_std_vector_runme.rb b/Examples/test-suite/ruby/li_std_vector_runme.rb index fe3d9e0ce03..68feb8f1af2 100644 --- a/Examples/test-suite/ruby/li_std_vector_runme.rb +++ b/Examples/test-suite/ruby/li_std_vector_runme.rb @@ -39,12 +39,12 @@ "iv.slice(1,2).to_s" => "12", "iv[0,-2]" => nil, "iv[0,3].to_s" => "012", - "iv[0,10].to_s" => "012", + "iv[0,10].to_s" => "0123", "iv[1..2].to_s" => '12', "iv[1..3].to_s" => '123', "iv[1..4].to_s" => '123', "iv[1..-2].to_s" => '12', - "iv[2..-3]" => nil, + "iv[2..-3].to_s" => '', }.each do |k,v| swig_assert( "#{k} == #{v.inspect}", binding ) end @@ -68,6 +68,141 @@ iv.delete_if { |x| x == 0 || x == 3 || x == 6 } swig_assert_equal(iv.to_s, '1245', binding) +iv[1,2] = [-2, -4] +swig_assert_equal(iv.to_s, '1-2-45', binding) + +iv = IntVector.new([0,1,2,3]) +iv[0,1] = [-1, -2] +swig_assert_equal(iv.to_s, '-1-2123', binding) + +iv = IntVector.new([1,2,3,4]) +iv[1,3] = [6,7,8,9] +#__setitem__ needs fixing +#swig_assert_equal(iv.to_s, '16789', binding) + +iv = IntVector.new([1,2,3,4]) + +swig_assert_equal(iv[0], 1, binding) +swig_assert_equal(iv[3], 4, binding) +swig_assert_equal(iv[4], nil, binding) +swig_assert_equal(iv[-5], nil, binding) + +iv[-1] = 9 +iv[-4] = 6 +swig_assert_equal(iv.to_s, '6239', binding) + +begin + iv[-5] = 99 + raise "exception missed" +rescue IndexError +end + +iv[6] = 5 +swig_assert_equal(iv.to_s, '6239555', binding) + +def failed(a, b, msg) + a = 'nil' if a == nil + b = 'nil' if b == nil + raise RuntimeError, "#{msg}: #{a} ... #{b}" +end + +def compare_sequences(a, b) + if a != nil && b != nil + if a.size != b.size + failed(a, b, "different sizes") + end + for i in 0..a.size-1 + failed(a, b, "elements are different") if a[i] != b[i] + end + else + unless a == nil && b == nil + failed(a, b, "only one of the sequences is nil") + end + end +end + +def compare_expanded_sequences(a, b) + # a can contain nil elements which indicate additional elements + # b won't contain nil for additional elements + if a != nil && b != nil + if a.size != b.size + failed(a, b, "different sizes") + end + for i in 0..a.size-1 + failed(a, b, "elements are different") if a[i] != b[i] && a[i] != nil + end + else + unless a == nil && b == nil + failed(a, b, "only one of the sequences is nil") + end + end +end + +def check_slice(i, length) + aa = [1,2,3,4] + iv = IntVector.new(aa) + + aa_slice = aa[i, length] + iv_slice = iv[i, length] + compare_sequences(aa_slice, iv_slice) + + aa_slice = aa.slice(i, length) + iv_slice = iv.slice(i, length) + compare_sequences(aa_slice, iv_slice) +end + +def check_range(i, j) + aa = [1,2,3,4] + iv = IntVector.new(aa) + + aa_range = aa[i..j] + iv_range = iv[i..j] + compare_sequences(aa_range, iv_range) + + aa_range = aa[Range.new(i, j, true)] + iv_range = iv[Range.new(i, j, true)] + compare_sequences(aa_range, iv_range) +end + +def set_slice(i, length, expect_nil_expanded_elements) + aa = [1,2,3,4] + iv = IntVector.new(aa) + aa_new = [8, 9] + iv_new = IntVector.new(aa_new) + + aa[i, length] = aa_new + iv[i, length] = iv_new + if expect_nil_expanded_elements + compare_expanded_sequences(aa, iv) + else + compare_sequences(aa, iv) + end +end + +for i in -5..5 + for length in -5..5 + check_slice(i, length) + end +end + +for i in -5..5 + for j in -5..5 + check_range(i, j) + end +end + +for i in -4..4 + for length in 0..4 + set_slice(i, length, false) + end +end + +for i in [5, 6] + for length in 0..5 + set_slice(i, length, true) + end +end + dv = DoubleVector.new(10) diff --git a/Examples/test-suite/ruby/overload_extend2_runme.rb b/Examples/test-suite/ruby/overload_extend2_runme.rb new file mode 100644 index 00000000000..81b456c1049 --- /dev/null +++ b/Examples/test-suite/ruby/overload_extend2_runme.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'swig_assert' + +require 'overload_extend2' + +f = Overload_extend2::Foo.new + +raise RuntimeError if f.test(3) != 1 +raise RuntimeError if f.test("hello") != 2 +raise RuntimeError if f.test(3.5,2.5) != 3 diff --git a/Examples/test-suite/ruby/overload_extendc_runme.rb b/Examples/test-suite/ruby/overload_extend_c_runme.rb similarity index 77% rename from Examples/test-suite/ruby/overload_extendc_runme.rb rename to Examples/test-suite/ruby/overload_extend_c_runme.rb index a2682bf4288..357afdb6439 100644 --- a/Examples/test-suite/ruby/overload_extendc_runme.rb +++ b/Examples/test-suite/ruby/overload_extend_c_runme.rb @@ -9,10 +9,11 @@ require 'swig_assert' -require 'overload_extend' +require 'overload_extend_c' -f = Overload_extend::Foo.new +f = Overload_extend_c::Foo.new raise RuntimeError if f.test(3) != 1 raise RuntimeError if f.test("hello") != 2 raise RuntimeError if f.test(3.5,2.5) != 6 + diff --git a/Examples/test-suite/ruby/ruby_minherit_shared_ptr_runme.rb b/Examples/test-suite/ruby/ruby_minherit_shared_ptr_runme.rb new file mode 100644 index 00000000000..9381fee2b99 --- /dev/null +++ b/Examples/test-suite/ruby/ruby_minherit_shared_ptr_runme.rb @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'ruby_minherit_shared_ptr' + +md = Ruby_minherit_shared_ptr::MultiDerived.new(11, 22) + +if md.Base1Func != 11 then + raise RuntimeError +end +if md.Interface1Func != 22 then + raise RuntimeError +end +if Ruby_minherit_shared_ptr.BaseCheck(md) != 11 then + raise RuntimeError +end +if Ruby_minherit_shared_ptr.InterfaceCheck(md) != 22 then + raise RuntimeError +end +if Ruby_minherit_shared_ptr.DerivedCheck(md) != 33 then + raise RuntimeError +end diff --git a/Examples/test-suite/ruby/swig_assert.rb b/Examples/test-suite/ruby/swig_assert.rb index 200b0838400..69a1a020708 100644 --- a/Examples/test-suite/ruby/swig_assert.rb +++ b/Examples/test-suite/ruby/swig_assert.rb @@ -22,6 +22,8 @@ class SwigRubyError < RuntimeError # msg - optional additional message to print # def swig_assert_equal( a, b, scope = nil, msg = nil ) + a = 'nil' if a == nil + b = 'nil' if b == nil begin check = "#{a} == #{b}" if scope.kind_of? Binding diff --git a/Examples/test-suite/ruby_minherit_shared_ptr.i b/Examples/test-suite/ruby_minherit_shared_ptr.i new file mode 100644 index 00000000000..6a0e3f94cad --- /dev/null +++ b/Examples/test-suite/ruby_minherit_shared_ptr.i @@ -0,0 +1,39 @@ +// Test ruby_minherit (multiple inheritance support) and shared_ptr +%module(ruby_minherit="1") ruby_minherit_shared_ptr + +%include +%shared_ptr(Interface1) +%shared_ptr(Base1) +%shared_ptr(MultiDerived) + +%inline %{ +#include +class Interface1 { +public: + virtual int Interface1Func() const = 0; +}; + +class Base1 { + int val; +public: + Base1(int a = 0) : val(a) {} + virtual int Base1Func() const { return val; } +}; + +class MultiDerived : public Base1, public Interface1 { + int multi; +public: + MultiDerived(int v1, int v2) : Base1(v1), multi(v2) {} + virtual int Interface1Func() const { return multi; } +}; + +int BaseCheck(const Base1& b) { + return b.Base1Func(); +} +int InterfaceCheck(const Interface1& i) { + return i.Interface1Func(); +} +int DerivedCheck(const MultiDerived& m) { + return m.Interface1Func() + m.Base1Func(); +} +%} diff --git a/Examples/test-suite/schemerunme/overload_extend_c.scm b/Examples/test-suite/schemerunme/overload_extend_c.scm new file mode 100644 index 00000000000..0b03b285aef --- /dev/null +++ b/Examples/test-suite/schemerunme/overload_extend_c.scm @@ -0,0 +1,12 @@ +(define f (new-Foo)) + +(if (not (= (Foo-test f 3) 1)) + (error "test integer bad")) + +(if (not (= (Foo-test f "hello") 2)) + (error "test string bad")) + +(if (not (= (Foo-test f 3.5 2.5) 6.0)) + (error "test reals bad")) + +(exit 0) diff --git a/Examples/test-suite/scilab/Makefile.in b/Examples/test-suite/scilab/Makefile.in new file mode 100644 index 00000000000..9ddd8f1aab6 --- /dev/null +++ b/Examples/test-suite/scilab/Makefile.in @@ -0,0 +1,90 @@ +####################################################################### +# Makefile for scilab test-suite +####################################################################### + +LANGUAGE = scilab +SCILAB = @SCILAB@ +SCILAB_OPT = @SCILABOPT@ +SCRIPTSUFFIX = _runme.sci + +srcdir = @srcdir@ +top_srcdir = ../@top_srcdir@ +top_builddir = ../@top_builddir@ + +C_TEST_CASES += \ + scilab_consts \ + scilab_enums \ + scilab_identifier_name \ + +CPP_TEST_CASES += \ + inout \ + primitive_types \ + scilab_li_matrix \ + scilab_multivalue \ + scilab_pointer_conversion_functions \ + +CPP_STD_TEST_CASES += \ + li_std_container_typemaps \ + li_std_string_extra \ + +include $(srcdir)/../common.mk + +# Overriden variables +SRCDIR = ../$(srcdir)/ + +# Local variables +TEST_DIR = $*.dir +RUNME_SCRIPT = $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) +SRC_RUNME_SCRIPT = $(srcdir)/$(RUNME_SCRIPT) + +# Hide too long identifier warnings +SWIGOPT += -w720 + +# Rules for the different types of tests +%.cpptest: + $(setup) + +(cd $(TEST_DIR) && $(swig_and_compile_cpp)) + cd $(TEST_DIR) && $(run_testcase) + +%.ctest: + $(setup) + +(cd $(TEST_DIR) && $(swig_and_compile_c)) + cd $(TEST_DIR) && $(run_testcase) + +%.multicpptest: + $(setup) + +(cd $(TEST_DIR) && $(swig_and_compile_multi_cpp)) + cd $(TEST_DIR) && $(run_testcase) + +# Copies files and creates directories needed for the test case +setup = \ + if [ ! -d $(TEST_DIR) ]; then \ + mkdir $(TEST_DIR); \ + fi; \ + if [ -f $(SRC_RUNME_SCRIPT) ]; then \ + echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test)" ; \ + if [ ! -f $(TEST_DIR) ]; then \ + cp $(SRC_RUNME_SCRIPT) $(TEST_DIR); \ + fi; \ + if [ ! -f $(TEST_DIR)/swigtest.start ]; then \ + cp $(srcdir)/swigtest.start $(TEST_DIR); \ + fi; \ + if [ ! -f $(TEST_DIR)/swigtest.quit ]; then \ + cp $(srcdir)/swigtest.quit $(TEST_DIR); \ + fi; \ + else \ + echo "$(ACTION)ing $(LANGUAGE) testcase $*" ; \ + fi; \ + +# Runs the testcase. A testcase is only run if +# a file is found which has _runme.sci appended after the testcase name. +run_testcase = \ + if [ -f $(RUNME_SCRIPT) ]; then ( \ + env LD_LIBRARY_PATH=$(srcdir):$$LD_LIBRARY_PATH $(RUNTOOL) $(SCILAB) $(SCILAB_OPT) -f $(RUNME_SCRIPT); ) \ + fi + +# Clean: remove the generated files +%.clean: + @rm -rf $(TEST_DIR) + +clean: diff --git a/Examples/test-suite/scilab/abstract_access_runme.sci b/Examples/test-suite/scilab/abstract_access_runme.sci new file mode 100644 index 00000000000..900a2618b1d --- /dev/null +++ b/Examples/test-suite/scilab/abstract_access_runme.sci @@ -0,0 +1,16 @@ +exec("swigtest.start", -1); + +try + D = new_D(); +catch + swigtesterror(); +end +if A_do_x(D) <> 1 then swigtesterror(); end + +try + delete_D(D); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/abstract_inherit_ok_runme.sci b/Examples/test-suite/scilab/abstract_inherit_ok_runme.sci new file mode 100644 index 00000000000..0ee1e291beb --- /dev/null +++ b/Examples/test-suite/scilab/abstract_inherit_ok_runme.sci @@ -0,0 +1,11 @@ +exec("swigtest.start", -1); + +try + Spam = new_Spam() +catch + swigtesterror(); +end + +if Foo_blah(Spam)<>0 then swigtesterror; end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/abstract_inherit_runme.sci b/Examples/test-suite/scilab/abstract_inherit_runme.sci new file mode 100644 index 00000000000..b9058e614a4 --- /dev/null +++ b/Examples/test-suite/scilab/abstract_inherit_runme.sci @@ -0,0 +1,10 @@ +exec("swigtest.start", -1); + +try + // This call must fail because the constructor does not exist + Spam = new_Spam() + swigtesterror(); +catch +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/abstract_signature_runme.sci b/Examples/test-suite/scilab/abstract_signature_runme.sci new file mode 100644 index 00000000000..d60acfd76cf --- /dev/null +++ b/Examples/test-suite/scilab/abstract_signature_runme.sci @@ -0,0 +1,10 @@ +exec("swigtest.start", -1); + +// These calls must fail +ierr = execstr('abstract_foo_meth(1)', 'errcatch'); +if ierr == 0 then swigtesterror(); end + +ierr = execstr('abstract_bar_meth(1)', 'errcatch'); +if ierr == 0 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/abstract_typedef2_runme.sci b/Examples/test-suite/scilab/abstract_typedef2_runme.sci new file mode 100644 index 00000000000..8da9c2fab5e --- /dev/null +++ b/Examples/test-suite/scilab/abstract_typedef2_runme.sci @@ -0,0 +1,15 @@ +exec("swigtest.start", -1); + +try + a = new_A_UF(); +catch + swigtesterror(); +end + +try + delete_A_UF(a); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/abstract_typedef_runme.sci b/Examples/test-suite/scilab/abstract_typedef_runme.sci new file mode 100644 index 00000000000..bfb03a2f1ff --- /dev/null +++ b/Examples/test-suite/scilab/abstract_typedef_runme.sci @@ -0,0 +1,17 @@ +exec("swigtest.start", -1); + +try + e = new_Engine(); +catch + swigtesterror(); +end + +try + a = new_A(); +catch + swigtesterror(); +end + +// TODO: test write method + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/abstract_virtual_runme.sci b/Examples/test-suite/scilab/abstract_virtual_runme.sci new file mode 100644 index 00000000000..55379eee263 --- /dev/null +++ b/Examples/test-suite/scilab/abstract_virtual_runme.sci @@ -0,0 +1,27 @@ +exec("swigtest.start", -1); + +try + d = new_D(); +catch + swigtesterror(); +end + +try + delete_D(d); +catch + swigtesterror(); +end + +try + e = new_E(); +catch + swigtesterror(); +end + +try + delete_E(e); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/access_change_runme.sci b/Examples/test-suite/scilab/access_change_runme.sci new file mode 100644 index 00000000000..e3705a2b35e --- /dev/null +++ b/Examples/test-suite/scilab/access_change_runme.sci @@ -0,0 +1,39 @@ +exec("swigtest.start", -1); + +try + baseInt = new_BaseInt(); +catch + swigtesterror(); +end + +try + delete_BaseInt(baseInt); +catch + swigtesterror(); +end + +try + derivedInt = new_DerivedInt(); +catch + swigtesterror(); +end + +try + delete_DerivedInt(derivedInt); +catch + swigtesterror(); +end + +try + bottomInt = new_BottomInt(); +catch + swigtesterror(); +end + +try + delete_BottomInt(bottomInt); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/add_link_runme.sci b/Examples/test-suite/scilab/add_link_runme.sci new file mode 100644 index 00000000000..f15d84e1d9b --- /dev/null +++ b/Examples/test-suite/scilab/add_link_runme.sci @@ -0,0 +1,27 @@ +exec("swigtest.start", -1); + +try + foo = new_Foo(); +catch + swigtesterror(); +end + +try + foo2 = Foo_blah(foo); +catch + swigtesterror(); +end + +try + delete_Foo(foo); +catch + swigtesterror(); +end + +try + delete_Foo(foo2); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/aggregate_runme.sci b/Examples/test-suite/scilab/aggregate_runme.sci new file mode 100644 index 00000000000..ba5768013fe --- /dev/null +++ b/Examples/test-suite/scilab/aggregate_runme.sci @@ -0,0 +1,21 @@ +exec("swigtest.start", -1); + +if UP_get()<>1 then swigtesterror(); end +if typeof(UP_get())<>"constant" then pause; end + +if DOWN_get()<>2 then swigtesterror(); end +if typeof(DOWN_get())<>"constant" then pause; end + +if LEFT_get()<>3 then swigtesterror(); end +if typeof(LEFT_get())<>"constant" then pause; end + +if RIGHT_get()<>4 then swigtesterror(); end +if typeof(RIGHT_get())<>"constant" then pause; end + +// TODO: move is a Scilab function... +//result = move(UP_get()); +//result = move(DOWN_get()); +//result = move(LEFT_get()); +//result = move(RIGHT_get()); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/allowexcept_runme.sci b/Examples/test-suite/scilab/allowexcept_runme.sci new file mode 100644 index 00000000000..014c77830c0 --- /dev/null +++ b/Examples/test-suite/scilab/allowexcept_runme.sci @@ -0,0 +1,5 @@ +exec("swigtest.start", -1); + +// TODO: add tests here + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/allprotected_runme.sci b/Examples/test-suite/scilab/allprotected_runme.sci new file mode 100644 index 00000000000..7bc74fac0df --- /dev/null +++ b/Examples/test-suite/scilab/allprotected_runme.sci @@ -0,0 +1,80 @@ +exec("swigtest.start", -1); + +// Class Klass +try + klass = new_Klass("allprotected_klass") +catch + swigtesterror(lasterror()); +end + +checkequal(Klass_getName(klass), "allprotected_klass", "Klass_getName(new_Klass(""allprotected_klass""))"); + +// Class PubBase +try + pubBase = new_PubBase("allprotected_PubBase"); +catch + swigtesterror(lasterror()); +end + +checkequal(PubBase_virtualMethod(pubBase), "PublicBase", "PubBase_virtualMethod(pubBase)"); + +class = PubBase_instanceMethod(pubBase, klass); +checkequal(Klass_getName(class), "allprotected_klass", "Klass_getName(PubBase_instanceMethod(pubBase, klass))"); + +class = PubBase_instanceOverload(pubBase, klass); +checkequal(Klass_getName(class), "allprotected_klass", "Klass_getName(PubBase_instanceOverloaded(pubBase, klass))"); + +class = PubBase_instanceOverload(pubBase, klass, "allprotected_klass2"); +checkequal(Klass_getName(class), "allprotected_klass2", "Klass_getName(PubBase_instanceOverloaded(pubBase, klass, ""allprotected_klass2""))"); + +class = PubBase_staticMethod(klass); +checkequal(Klass_getName(class), "allprotected_klass", "Klass_getName(PubBase_staticMethod(klass))"); + +class = PubBase_staticOverloaded(klass); +checkequal(Klass_getName(class), "allprotected_klass", "Klass_getName(PubBase_staticOverloaded(klass))"); + + +class = PubBase_staticOverloaded(klass, "allprotected_klass3"); +checkequal(Klass_getName(class), "allprotected_klass3", "Klass_getName(PubBase_staticOverloaded(klass, ""allprotected_klass3""))"); + +checkequal(PubBase_EnumVal1_get(), 0, "PubBase_EnumVal1_get()"); +checkequal(PubBase_EnumVal2_get(), 1, "(PubBase_EnumVal2_get()"); + + +PubBase_instanceMemb_set(pubBase, 12); +checkequal(PubBase_instanceMemb_get(pubBase), 12, "PubBase_instanceMemb_get(pubBase)"); + +checkequal(PubBase_staticConstM_get(), 20, "PubBase_staticConstM_get()"); +checkequal(PubBase_staticMember_get(), 10, "PubBase_staticMember_get()") + +PubBase_stringMember_set(pubBase, "dummy"); +checkequal(PubBase_stringMember_get(pubBase), "dummy", "PubBase_stringMember_get()"); + +// TODO does not work (wrong ENUM mapping?) +//PubBase_anEnum_get(PubBase) +//PubBase_anEnum_set(PubBase, ???) + + +// Class ProcBase +try +// Constructor is propected and must not be defined here + ProcBase = new_ProctectedBase("allprotected_ProcBase"); + swigtesterror(); +catch +end + +checkequal(ProcBase_EnumVal1_get(), 0, "ProcBase_EnumVal1_get()"); +checkequal(ProcBase_EnumVal2_get(), 1, "ProcBase_EnumVal2_get()"); + +try + delete_Klass(klass); +catch + swigtesterror(); +end +try + delete_PubBase(pubBase); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/anonymous_bitfield_runme.sci b/Examples/test-suite/scilab/anonymous_bitfield_runme.sci new file mode 100644 index 00000000000..9bc462a8967 --- /dev/null +++ b/Examples/test-suite/scilab/anonymous_bitfield_runme.sci @@ -0,0 +1,60 @@ +exec("swigtest.start", -1); + +try + foo = new_Foo(); +catch + swigtesterror(); +end + +checkequal(Foo_x_get(foo), 0, "Foo_x_get()"); + +checkequal(Foo_y_get(foo), 0, "Foo_y_get()"); + +checkequal(Foo_z_get(foo), 0, "Foo_y_get()"); + +checkequal(Foo_f_get(foo), 0, "Foo_f_get()"); + +checkequal(Foo_seq_get(foo), 0, "Foo_seq_get()"); + +try + Foo_x_set(foo, 5); +catch + swigtesterror(); +end +checkequal(Foo_x_get(foo), 5, "Foo_x_get()"); + +try + Foo_y_set(foo, 5); +catch + swigtesterror(); +end +checkequal(Foo_y_get(foo), 5, "Foo_y_get()"); + +try + Foo_f_set(foo, 1); +catch + swigtesterror(); +end +checkequal(Foo_f_get(foo), 1, "Foo_f_get()"); + +try + Foo_z_set(foo, 13); +catch + swigtesterror(); +end +checkequal(Foo_z_get(foo), 13, "Foo_z_get()"); + +try + Foo_seq_set(foo, 3); +catch + swigtesterror(); +end +checkequal(Foo_seq_get(foo), 3, "Foo_seq_get()"); + +try + delete_Foo(foo); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/apply_signed_char_runme.sci b/Examples/test-suite/scilab/apply_signed_char_runme.sci new file mode 100644 index 00000000000..f4aa782eb1e --- /dev/null +++ b/Examples/test-suite/scilab/apply_signed_char_runme.sci @@ -0,0 +1,43 @@ +exec("swigtest.start", -1); + +smallnum = -127; +checkequal(CharValFunction(smallnum), smallnum, "CharValFunction(smallnum)"); +checkequal(CCharValFunction(smallnum), smallnum, "CCharValFunction(smallnum)"); +checkequal(CCharRefFunction(smallnum), smallnum, "CCharRefFunction(smallnum)"); + +try + globalchar_set(smallnum); +catch + swigtesterror(); +end +checkequal(globalchar_get(), smallnum, "globalchar_get()"); +checkequal(globalconstchar_get(), -110, "globalconstchar_get()"); + +try + dirTest = new_DirTest(); +catch + swigtesterror(); +end + +checkequal(DirTest_CharValFunction(dirTest, smallnum), smallnum, "DirTest_CharValFunction(dirTest, smallnum)"); +checkequal(DirTest_CCharValFunction(dirTest, smallnum), smallnum, "DirTest_CCharValFunction(dirTest, smallnum)"); +checkequal(DirTest_CCharRefFunction(dirTest, smallnum), smallnum, "DirTest_CCharRefFunction(dirTest, smallnum)"); + +// TODO Too long identifiers +//if dirTest_memberchar_get(dirTest) <> -111 then swigtesterror(); end +//try +// dirTest_memberchar_set(dirTest, smallnum) +//catch +// swigtesterror(); +//end +//if dirTest_memberchar_get(dirTest) <> smallnum then swigtesterror(); end + +//if dirTest_memberconstchar_get(dirTest) <> -112 then swigtesterror(); end + +try + delete_DirTest(dirTest); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/apply_strings_runme.sci b/Examples/test-suite/scilab/apply_strings_runme.sci new file mode 100644 index 00000000000..6fb039a7e9c --- /dev/null +++ b/Examples/test-suite/scilab/apply_strings_runme.sci @@ -0,0 +1,45 @@ +exec("swigtest.start", -1); + +testString = "Scilab test string"; + +checkequal(UCharFunction(testString), testString, "UCharFunction(testString)"); +checkequal(SCharFunction(testString), testString, "SCharFunction(testString)"); +checkequal(CUCharFunction(testString), testString, "CUCharFunction(testString)"); +checkequal(CSCharFunction(testString), testString, "CSCharFunction(testString)"); +//checkequal(CharFunction(testString), testString, "CharFunction(testString)"); +//checkequal(CCharFunction(testString), testString, "CCharFunction(testString)"); + +try + tNum = new_TNum(); +catch + swigtesterror(); +end +//TNumber_DigitsMemberA_get() +//TNumber_DigitsMemberA_set +//TNumber_DigitsMemberB_get() +//TNumber_DigitsMemberB_set +try + delete_TNum(tNum); +catch + swigtesterror(); +end + +try + dirTest = new_DirTest(); +catch + swigtesterror(); +end + +checkequal(DirTest_UCharFunction(dirTest, testString), testString, "DirTest_UCharFunction"); +checkequal(DirTest_SCharFunction(dirTest, testString), testString, "DirTest_SCharFunction(dirTest, testString)"); +checkequal(DirTest_CUCharFunction(dirTest, testString), testString, "DirTest_CUCharFunction(dirTest, testString)"); +checkequal(DirTest_CSCharFunction(dirTest, testString), testString, "DirTest_CSharFunction(dirTest, testString)"); +//checkequal(DirTest_CharFunction(dirTest, testString), testString, "DirTest_CharFunction(dirTest, testString)"); +//checkequal(DirTest_CCharFunction(dirTest, testString), testString, "DirTest_CCharFunction(dirTest, testString)"); +try + delete_DirTest(dirTest); +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/array_member_runme.sci b/Examples/test-suite/scilab/array_member_runme.sci new file mode 100644 index 00000000000..d839f48eeaf --- /dev/null +++ b/Examples/test-suite/scilab/array_member_runme.sci @@ -0,0 +1,16 @@ +exec("swigtest.start", -1); + +f = new_Foo(); +Foo_data_set(f, [0:7]); +checkequal(Foo_data_get(f), [0:7], "Foo_data_get()"); + +Foo_text_set(f, "abcdefgh"); +checkequal(Foo_text_get(f), "abcdefgh", "Foo_text_get()"); +delete_Foo(f); + +m = new_MyBuff(); +MyBuff_x_set(m, [0:11]); +checkequal(MyBuff_x_get(m), [0:11], "MyBuff_x_get()"); +delete_MyBuff(m); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/arrays_dimensionless_runme.sci b/Examples/test-suite/scilab/arrays_dimensionless_runme.sci new file mode 100644 index 00000000000..ac737545f9c --- /dev/null +++ b/Examples/test-suite/scilab/arrays_dimensionless_runme.sci @@ -0,0 +1,55 @@ +exec("swigtest.start", -1); + +// bool +checkequal(arr_bool([%T %F %F %T %F %T %T %T], 8), 5, "arr_bool"); + +// char +checkequal(arr_char(["charptr"], 7), 756, "arr_char"); + +// signed char +checkequal(arr_schar([1, 2, 3, 4], 4), 10, "arr_schar"); +checkequal(arr_schar(int8([1, 2, 3, 4]), 4), 10, "arr_schar"); + +// unsigned char +checkequal(arr_uchar([1, 2, 3, 4], 4), 10, "arr_uchar"); +checkequal(arr_uchar(uint8([1, 2, 3, 4]), 4), 10, "arr_uchar"); + +// short +checkequal(arr_short([1, 2, 3, 4], 4), 10, "arr_short"); +checkequal(arr_short(int16([1, 2, 3, 4]), 4), 10, "arr_short"); + +// unsigned short +checkequal(arr_ushort([1, 2, 3, 4], 4), 10, "arr_ushort"); +checkequal(arr_ushort(uint16([1, 2, 3, 4]), 4), 10, "arr_ushort"); + +// int +checkequal(arr_int([1, 2, 3, 4], 4), 10, "arr_int"); +checkequal(arr_int(int32([1, 2, 3, 4]), 4), 10, "arr_int"); + +// unsigned int +checkequal(arr_uint([1, 2, 3, 4], 4), 10, ""); +checkequal(arr_uint(uint32([1, 2, 3, 4]), 4), 10, ""); + +// long +checkequal(arr_long([1, 2, 3, 4], 4), 10, "arr_long"); +checkequal(arr_long(int32([1, 2, 3, 4]), 4), 10, "arr_long"); + +// unsigned long +checkequal(arr_ulong([1, 2, 3, 4], 4), 10, "arr_ulong"); +checkequal(arr_ulong(uint32([1, 2, 3, 4]), 4), 10, "arr_ulong"); + +// long long +// No equivalent in Scilab 5 + +// unsigned long long +// No equivalent in Scilab 5 + +// float +a = [1, 2, 3, 4]; +checkequal(arr_float(a, 4), 10, "arr_float"); + +// double +a = [1, 2, 3, 4]; +checkequal(arr_double(a, 4), 10, "arr_double"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/arrays_global_runme.sci b/Examples/test-suite/scilab/arrays_global_runme.sci new file mode 100644 index 00000000000..2426276c5a7 --- /dev/null +++ b/Examples/test-suite/scilab/arrays_global_runme.sci @@ -0,0 +1,54 @@ +exec("swigtest.start", -1); + +function testArray(arrayName, arraySetFunc, arrayGetFunc, in_values, .. + expected_out_values) + try + arraySetFunc(in_values); + catch + swigtesterror("error in " + arrayName + "_set()"); + end + try + checkequal(arrayGetFunc(), expected_out_values, arrayName + "_get()"); + catch + swigtesterror("error in " + arrayName + "_get()"); + end +endfunction + +m = [-10, 20]; +um = [10, 20]; +testArray("array_c", array_c_set, array_c_get, ['ab'], ['ab']); +testArray("array_sc", array_sc_set, array_sc_get, m, m); +testArray("array_sc", array_sc_set, array_sc_get, int8(m), m); +testArray("array_uc", array_uc_set, array_uc_get, uint8(um), um); +testArray("array_s", array_s_set, array_s_get, m, m); +testArray("array_s", array_s_set, array_s_get, int16(m), m); +testArray("array_us", array_us_set, array_us_get, uint16(um), um); +testArray("array_i", array_i_set, array_i_get, m, m); +testArray("array_i", array_i_set, array_i_get, int32(m), m); +testArray("array_ui", array_ui_set, array_ui_get, uint32(um), um); +testArray("array_l", array_l_set, array_l_get, m, m); +testArray("array_l", array_l_set, array_l_get, int32(m), m); +testArray("array_ul", array_ul_set, array_ul_get, uint32(um), um); +testArray("array_f", array_f_set, array_f_get, [-2.5, 2.5], [-2.5, 2.5]); +testArray("array_d", array_d_set, array_d_get, [-10.5, 20.4], [-10.5, 20.4]); + +checkequal(array_const_i_get(), [10, 20], "array_const_i_get()"); + +ierr = execstr('array_i_set([0:10]', 'errcatch'); +if ierr == 0 then swigtesterror("Overflow error expected"); end + +checkequal(BeginString_FIX44a_get(), "FIX.a.a", "BeginString_FIX44a_get()"); +checkequal(BeginString_FIX44b_get(), "FIX.b.b", "BeginString_FIX44b_get()"); +checkequal(BeginString_FIX44c_get(), "FIX.c.c", "BeginString_FIX44c_get()"); +checkequal(BeginString_FIX44d_get(), "FIX.d.d", "BeginString_FIX44d_get()"); +BeginString_FIX44b_set(strcat(["12","\0","45"])); +checkequal(BeginString_FIX44b_get(), "12\045", "BeginString_FIX44b_get()"); +checkequal(BeginString_FIX44d_get(), "FIX.d.d", "BeginString_FIX44d_get()"); +checkequal(BeginString_FIX44e_get(), "FIX.e.e", "BeginString_FIX44e_get()"); +checkequal(BeginString_FIX44f_get(), "FIX.f.f", "BeginString_FIX44f_get()"); + +checkequal(test_a("hello","hi","chello","chi"), "hi", "test_a()"); + +checkequal(test_b("1234567","hi"), "1234567", "test_b()"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/arrays_global_twodim_runme.sci b/Examples/test-suite/scilab/arrays_global_twodim_runme.sci new file mode 100644 index 00000000000..6af5ff217d2 --- /dev/null +++ b/Examples/test-suite/scilab/arrays_global_twodim_runme.sci @@ -0,0 +1,12 @@ +exec("swigtest.start", -1); + +a = [1, 2, 3, 4; 5, 6, 7, 8;] + +//try +// array_d_set(a); +//catch +// swigtesterror(); +//end +//if array_d_get() <> a then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/bools_runme.sci b/Examples/test-suite/scilab/bools_runme.sci new file mode 100644 index 00000000000..9516a5df518 --- /dev/null +++ b/Examples/test-suite/scilab/bools_runme.sci @@ -0,0 +1,20 @@ +exec("swigtest.start", -1); + +function checkBool(bool_val, expected_bool_val) + if typeof(bool_val) <> "boolean" then swigtesterror(); end + if bool_val <> expected_bool_val then swigtesterror(); end +endfunction + +checkBool(constbool_get(), %f); + +checkBool(bool1_get(), %t); +checkBool(bool2_get(), %f); + +checkBool(bo(%t), %t); +checkBool(bo(%f), %f); + +bs = new_BoolSt(); +checkBool(BoolSt_m_bool1_get(bs), %t); +checkBool(BoolSt_m_bool2_get(bs), %f); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/char_constant_runme.sci b/Examples/test-suite/scilab/char_constant_runme.sci new file mode 100644 index 00000000000..e48e3068d9f --- /dev/null +++ b/Examples/test-suite/scilab/char_constant_runme.sci @@ -0,0 +1,9 @@ +exec("swigtest.start", -1); + +if CHAR_CONSTANT_get() <> "x" then swigtesterror(); end +if STRING_CONSTANT_get() <> "xyzzy" then swigtesterror(); end +if ESC_CONST_get() <> ascii(1) then swigtesterror(); end +if ia_get() <> ascii('a') then swigtesterror(); end +if ib_get() <> ascii('b') then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/constover_runme.sci b/Examples/test-suite/scilab/constover_runme.sci new file mode 100644 index 00000000000..5b8935f684d --- /dev/null +++ b/Examples/test-suite/scilab/constover_runme.sci @@ -0,0 +1,22 @@ +exec("swigtest.start", -1); + +p = test("test"); +if strcmp(p, "test") <> 0 then swigtesterror(); end + +p = test_pconst("test"); +if strcmp(p, "test_pconst") <> 0 then swigtesterror(); end + +f = new_Foo(); +p = Foo_test(f, "test"); +if strcmp(p,"test") <> 0 then swigtesterror(); end + +p = Foo_test_pconst(f, "test"); +if strcmp(p,"test_pconst") <> 0 then swigtesterror(); end + +p = Foo_test_constm(f, "test"); +if strcmp(p,"test_constmethod") <> 0 then swigtesterror(); end + +p = Foo_test_pconstm(f, "test"); +if strcmp(p,"test_pconstmethod") <> 0 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/constructor_copy_runme.sci b/Examples/test-suite/scilab/constructor_copy_runme.sci new file mode 100644 index 00000000000..bfd2b1c20f5 --- /dev/null +++ b/Examples/test-suite/scilab/constructor_copy_runme.sci @@ -0,0 +1,36 @@ +exec("swigtest.start", -1); + + +f1 = new_Foo1(3); +f11 = new_Foo1(f1); + +checkequal(Foo1_x_get(f1), Foo1_x_get(f11), "Foo1_x_get(f1) <> Foo1_x_get(f11)"); + +delete_Foo1(f1); +delete_Foo1(f11); + +f8 = new_Foo8(); +try + f81 = new_Foo8(f8); + swigtesterror("Foo(f8) called."); +catch +end + +bi = new_Bari(5); +bc = new_Bari(bi); + +checkequal(Bari_x_get(bi), Bari_x_get(bc), "Bar_x_get(bi) <> Bar_x_get(bc)"); + +delete_Bari(bi); +delete_Bari(bc); + +bd = new_Bard(5); +try + bc = Bard(bd); + swigtesterror("Bard(bd) called."); +catch +end + + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/cpp_basic_runme.sci b/Examples/test-suite/scilab/cpp_basic_runme.sci new file mode 100644 index 00000000000..6b64de4db93 --- /dev/null +++ b/Examples/test-suite/scilab/cpp_basic_runme.sci @@ -0,0 +1,64 @@ +exec("swigtest.start", -1); + +f = new_Foo(4); +checkequal(Foo_num_get(f), 4, "Foo_num_get(f)"); +Foo_num_set(f, -17); +checkequal(Foo_num_get(f), -17, "Foo_num_get(f)"); + +b = new_Bar(); +Bar_fptr_set(b, f); + +fptr = Bar_fptr_get(b); +checkequal(Foo_num_get(fptr), -17, "Foo_num_get(ftr)"); + +checkequal(Bar_test(b, -3, fptr), -5, "Bar_test(b, -3, fptr)"); + +fref = Bar_fref_get(b); +checkequal(Foo_num_get(fref), -4, "Foo_num_get(fref)"); + +checkequal(Bar_test(b, 12, fref), 23, "Bar_test(b, 12, fref)"); + +f2 = new_Foo(23); +Bar_fref_set(b, f2); + +fref = Bar_fref_get(b); +checkequal(Foo_num_get(fref), 23, "Foo_num_get(fref)"); + +fval = Bar_fval_get(b); +checkequal(Bar_test(b, 3, fval), 33, "Bar_test(b, 3, fval)"); + +Bar_fval_set(b, new_Foo(-15)); + +fval = Bar_fval_get(b); +checkequal(Foo_num_get(fval), -15, "Foo_num_get(fval)"); +checkequal(Bar_test(b, 3, fval), -27, "Bar_test(b, 3, fval)"); + +f3 = Bar_testFoo(b, 12, fref); +checkequal(Foo_num_get(f3), 32, "Foo_num_get(f3)"); + + +// Test globals +f4 = new_Foo(6); +Bar_global_fptr_set(f4); +checkequal(Foo_num_get(Bar_global_fptr_get()), 6, "Foo_num_get(Bar_global_fptr_get())"); + +checkequal(Foo_num_get(Bar_global_fref_get()), 23, "Foo_num_get(Bar_global_fref_get())"); + +checkequal(Foo_num_get(Bar_global_fval_get()), 3, "Foo_num_get(Bar_global_fval_get())"); + + +// Test member function pointers +func1_ptr = get_func1_ptr(); +func2_ptr = get_func2_ptr(); + +Foo_num_set(f, 4); +checkequal(Foo_func1(f, 2), 16, "Foo_func1(f, 2)"); +checkequal(Foo_func2(f, 2), -8, "Foo_func2(f, 2)"); + +Foo_func_ptr_set(f, func1_ptr); +checkequal(test_func_ptr(f, 2), 16, "Foo_test_func_ptr(f, 2)"); + +Foo_func_ptr_set(f, func2_ptr); +checkequal(test_func_ptr(f, 2), -8, "Foo_test_func_ptr(f, 2)"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/cpp_enum_runme.sci b/Examples/test-suite/scilab/cpp_enum_runme.sci new file mode 100644 index 00000000000..d684affe9b7 --- /dev/null +++ b/Examples/test-suite/scilab/cpp_enum_runme.sci @@ -0,0 +1,10 @@ +exec("swigtest.start", -1); + +f = new_Foo(); + +if Foo_hola_get(f) <> Hello_get() then swigtesterror("Foo_hola_get() <> ""Hello"""); end + +Foo_hola_set(f, Hi_get()); +if Foo_hola_get(f) <> Hi_get() then swigtesterror("Foo_hola_get() <> ""Hi"""); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/default_args_runme.sci b/Examples/test-suite/scilab/default_args_runme.sci new file mode 100644 index 00000000000..15754fdfd84 --- /dev/null +++ b/Examples/test-suite/scilab/default_args_runme.sci @@ -0,0 +1,67 @@ +exec("swigtest.start", -1); + +checkequal(anonymous(), 7771, "anonymous()"); +checkequal(anonymous(1234), 1234, "anonymous(1234)"); + +checkequal(booltest(), %T, "booltest()"); +checkequal(booltest(%T), %T, "booltest(%T)"); +checkequal(booltest(%F), %F, "booltest(%T)"); + +ec = new_EnumClass(); +checkequal(EnumClass_blah(ec), %T, "EnumClass_blah(ec)"); + +checkequal(casts1(), [], "casts1()"); +checkequal(casts1("Ciao"), "Ciao", "casts1(""Ciao"")"); +checkequal(casts2(), "Hello", "casts2()"); +checkequal(chartest1(), 'x', "chartest1()"); +checkequal(chartest2(), '', "chartest2()"); +checkequal(chartest1('y'), 'y', "chartest1(''y'')"); +checkequal(reftest1(), 42, "reftest1()"); +checkequal(reftest1(400), 400, "reftest1(400)"); +checkequal(reftest2(), "hello", "reftest2()"); + +// Rename +f = new_Foo(); +Foo_newname(f); +Foo_newname(f, 10); +Foo_renamed3arg(f, 10, 10.0); +Foo_renamed2arg(f, 10); +Foo_renamed1arg(f); +delete_Foo(f); + +// Static functions +checkequal(Statics_staticmethod(), 10+20+30, "Statics_staticmethod()"); +checkequal(Statics_staticmethod(100), 100+20+30, "Statics_staticmethod(100)"); +checkequal(Statics_staticmethod(100, 200, 300), 100+200+300, "Statics_staticmethod(100, 200, 300)"); + +tricky = new_Tricky(); +checkequal(Tricky_privatedefault(tricky), 200, "Tricky_privatedefault(tricky)"); +checkequal(Tricky_protectedint(tricky), 2000, "Tricky_protectedint(tricky)"); +checkequal(Tricky_protecteddouble(tricky), 987.654, "Tricky_protecteddouble(tricky)"); +checkequal(Tricky_functiondefault(tricky), 500, "Tricky_functiondefault(tricky)"); +checkequal(Tricky_contrived(tricky), 'X', "Tricky_contrived(tricky)"); +delete_Tricky(tricky); + +// Default argument is a constructor +k = constructorcall(); +checkequal(Klass_val_get(k), -1, "Klass_constructorcall()"); +delete_Klass(k); +k = constructorcall(new_Klass(2222)); +checkequal(Klass_val_get(k), 2222, "Klass_constructorcall(new Klass(2222)"); +delete_Klass(k); +k = constructorcall(new_Klass()); +checkequal(Klass_val_get(k), -1, "Klass_constructorcall(new_Klass()"); +delete_Klass(k); + +// Const methods +cm = new_ConstMethods(); +checkequal(ConstMethods_coo(cm), 20, "ConstMethods_coo()"); +checkequal(ConstMethods_coo(cm, 1.0), 20, "ConstMethods_coo(1.0)"); + +// C linkage (extern "C") +checkequal(cfunc1(1), 2, "cfunc1(1)"); +checkequal(cfunc2(1), 3, "cfunc2(1)"); +checkequal(cfunc3(1), 4, "cfunc3(1)"); + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/default_constructor_runme.sci b/Examples/test-suite/scilab/default_constructor_runme.sci new file mode 100644 index 00000000000..26726f1e096 --- /dev/null +++ b/Examples/test-suite/scilab/default_constructor_runme.sci @@ -0,0 +1,104 @@ +exec("swigtest.start", -1); + +a = new_A(); +delete_A(a); + +aa = new_AA(); +delete_AA(aa); + +try + b = new_B(); + swigtestswigtesterror("new_BB created.") +catch +end + +del_b = delete_B; + +try + bb = new_BB(); + swigtesterror("new_BB created.") +catch + +end + +del_bb = delete_BB; + +try + c = new_C(); + swigtesterror("new_C created.") +catch +end + +del_c = delete_C; + +cc = new_CC(); +delete_CC(cc); + +try + d = new_D(); + swigtesterror("new_D created") +catch +end + +del_d = delete_D; + +try + dd = new_DD(); + swigtesterror("new_DD created") +catch +end + +dd = delete_DD; + +try + ad = new_AD(); + swigtesterror("new_AD created") +catch +end + +del_ad = delete_AD; + +exec("swigtest.start", -1); + +e = new_E(); +delete_E(e); + +ee = new_EE(); +delete_EE(ee); + +try + eb = new_EB(); + swigtesterror("new_EB created") +catch +end + +del_eb = delete_EB; + +f = new_F(); + +try + del_f = delete_F; + swigtesterror("delete_F created") +catch +end + +F_destroy(f); + +g = new_G(); + +try + del_g = delete_G; + swigtesterror("delete_G created") +catch +end + +G_destroy(g); + +gg = new_GG(); +delete_GG(gg); + +hh = new_HH(1,1); + +exec("swigtest.quit", -1); + + diff --git a/Examples/test-suite/scilab/empty_c_runme.sci b/Examples/test-suite/scilab/empty_c_runme.sci new file mode 100644 index 00000000000..48db2d52b31 --- /dev/null +++ b/Examples/test-suite/scilab/empty_c_runme.sci @@ -0,0 +1,3 @@ +exec("swigtest.start", -1); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/empty_runme.sci b/Examples/test-suite/scilab/empty_runme.sci new file mode 100644 index 00000000000..48db2d52b31 --- /dev/null +++ b/Examples/test-suite/scilab/empty_runme.sci @@ -0,0 +1,3 @@ +exec("swigtest.start", -1); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/enums_runme.sci b/Examples/test-suite/scilab/enums_runme.sci new file mode 100644 index 00000000000..7320d7867a0 --- /dev/null +++ b/Examples/test-suite/scilab/enums_runme.sci @@ -0,0 +1,39 @@ +exec("swigtest.start", -1); + +if typeof(CSP_ITERATION_FWD_get()) <> "constant" then swigtesterror(); end +if typeof(CSP_ITERATION_BWD_get()) <> "constant" then swigtesterror(); end +if typeof(ABCDE_get()) <> "constant" then swigtesterror(); end +if typeof(FGHJI_get()) <> "constant" then swigtesterror(); end + +try + bar1(CSP_ITERATION_FWD_get()) + bar1(CSP_ITERATION_BWD_get()) + bar1(1) + bar1(int32(1)) + + bar2(ABCDE_get()) + bar2(FGHJI_get()) + bar2(1) + bar2(int32(1)) + + bar3(ABCDE_get()) + bar3(FGHJI_get()) + bar3(1) + bar3(int32(1)) +catch + swigtesterror() +end + +if typeof(enumInstance_get()) <> "constant" then swigtesterror(); end +if enumInstance_get() <> 2 then swigtesterror(); end + +if typeof(Slap_get()) <> "constant" then swigtesterror(); end +if Slap_get() <> 10 then swigtesterror(); end + +if typeof(Mine_get()) <> "constant" then swigtesterror(); end +if Mine_get() <> 11 then swigtesterror(); end + +if typeof(Thigh_get()) <> "constant" then swigtesterror(); end +if Thigh_get() <> 12 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/funcptr_cpp_runme.sci b/Examples/test-suite/scilab/funcptr_cpp_runme.sci new file mode 100644 index 00000000000..cb4c3cd0d10 --- /dev/null +++ b/Examples/test-suite/scilab/funcptr_cpp_runme.sci @@ -0,0 +1,7 @@ +exec("swigtest.start", -1); + +checkequal(call1(ADD_BY_VALUE_get(), 10, 11), 21, "ADD_BY_VALUE"); +checkequal(call2(ADD_BY_POINTER_get(), 12, 13), 25, "ADD_BY_POINTER"); +checkequal(call3(ADD_BY_REFERENCE_get(), 14, 15), 29, "ADD_BY_REFERENCE"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/funcptr_runme.sci b/Examples/test-suite/scilab/funcptr_runme.sci new file mode 100644 index 00000000000..430d1534975 --- /dev/null +++ b/Examples/test-suite/scilab/funcptr_runme.sci @@ -0,0 +1,6 @@ +exec("swigtest.start", -1); + +if add(7, 9) <> 16 then swigtesterror(); end +if do_op(7, 9, funcvar_get()) <> 16 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/global_vars_runme.sci b/Examples/test-suite/scilab/global_vars_runme.sci new file mode 100644 index 00000000000..721eaf614cd --- /dev/null +++ b/Examples/test-suite/scilab/global_vars_runme.sci @@ -0,0 +1,31 @@ +exec("swigtest.start", -1); + +b_set("hello"); +checkequal(b_get(), "hello", "b_get()"); + +sa = new_A(); +A_x_set(sa, 5); +checkequal(A_x_get(sa), 5, "A_x_get(sa)"); + +a_set(sa); +checkequal(A_x_get(a_get()), 5, "A_x_get(a)"); + +ap_set(sa); +A_x_set(sa, 14); +checkequal(A_x_get(ap_get()), 14, "A_x_get(ap)"); +delete_A(sa); + +sa2 = new_A(); +cap_set(sa2); +A_x_set(sa2, 16); +checkequal(A_x_get(cap_get()), 16, "A_x_get(cap)"); + +checkequal(A_x_get(ar_get()), 5, "A_x_get(ar)"); +ar_set(sa2); +checkequal(A_x_get(ar_get()), 16, "A_x_get(ar)"); +delete_A(sa2); + +x_set(11); +checkequal(x_get(), 11, "x_get()"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/inctest_runme.sci b/Examples/test-suite/scilab/inctest_runme.sci new file mode 100644 index 00000000000..5a8df7b8f5f --- /dev/null +++ b/Examples/test-suite/scilab/inctest_runme.sci @@ -0,0 +1,20 @@ +exec("swigtest.start", -1); + +try + a = new_A(); +catch + printf("did not find A\ntherefore, I did not include ""testdir/subdir1/hello.i""\n"); + swigtesterror(); +end + +try + b = new_B(); +catch + printf("did not find B\ntherefore, I did not include ""testdir/subdir2/hello.i""\n"); + swigtesterror(); +end + +if importtest1(5) <> 15 then swigtesterror(); end +if importtest2("black") <> "white" then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/inherit_missing_runme.sci b/Examples/test-suite/scilab/inherit_missing_runme.sci new file mode 100644 index 00000000000..d68ab7e1fbe --- /dev/null +++ b/Examples/test-suite/scilab/inherit_missing_runme.sci @@ -0,0 +1,15 @@ +exec("swigtest.start", -1); + +a = new_Foo(); +b = new_Bar(); +c = new_Spam(); + +checkequal(do_blah(a), "Foo::blah", "do_blah(a)"); +checkequal(do_blah(b), "Bar::blah", "do_blah(b)"); +checkequal(do_blah(c), "Spam::blah", "do_blah(c)"); + +delete_Foo(a); +delete_Bar(b); +delete_Spam(c); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/inout_runme.sci b/Examples/test-suite/scilab/inout_runme.sci new file mode 100644 index 00000000000..6c25a6deb72 --- /dev/null +++ b/Examples/test-suite/scilab/inout_runme.sci @@ -0,0 +1,15 @@ +exec("swigtest.start", -1); + +a = AddOne1(10); +if a <> 11 then swigtesterror(); end + +[a, b, c] = AddOne3(1, 2, 3); +if a <> 2 then swigtesterror(); end +if b <> 3 then swigtesterror(); end +if c <> 4 then swigtesterror(); end + +a = AddOne1r(20); +if a <> 21 then swigtesterror(); end + + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/integers_runme.sci b/Examples/test-suite/scilab/integers_runme.sci new file mode 100644 index 00000000000..1a59578d805 --- /dev/null +++ b/Examples/test-suite/scilab/integers_runme.sci @@ -0,0 +1,29 @@ +exec("swigtest.start", -1); + +// Negative values +checkequal(signed_char_identity(-1), -1, "signed_char_identity(-1)"); +checkequal(signed_short_identity(-1), -1, "signed_short_identity(-1)"); +checkequal(signed_int_identity(-1), -1, "signed_int_identity(-1)"); +checkequal(signed_long_identity(-1), -1, "signed_long_identity(-1)"); + +// Overflow errors +ierr = execstr('signed_char_identity(2^8)', 'errcatch'); +checkequal(ierr, 20007, 'signed_char_identity(2^8)'); +ierr = execstr('signed_short_identity(2^16)', 'errcatch'); +checkequal(ierr, 20007, 'signed_short_identity(2^16)'); +ierr = execstr('signed_int_identity(2^32)', 'errcatch'); +checkequal(ierr, 20007, 'signed_int_identity(2^32)'); +ierr = execstr('signed_long_identity(2^64)', 'errcatch'); +checkequal(ierr, 20007, 'signed_long_identity(2^64)'); + +// Value errors +ierr = execstr('signed_char_identity(100.2)', 'errcatch'); +checkequal(ierr, 20009, 'signed_char_identity(100.2)'); +ierr = execstr('signed_short_identity(100.2)', 'errcatch'); +checkequal(ierr, 20009, 'signed_short_identity(100.2)'); +ierr = execstr('signed_int_identity(100.2)', 'errcatch'); +checkequal(ierr, 20009, 'signed_int_identity(100.2)'); +ierr = execstr('signed_long_identity(100.2)', 'errcatch'); +checkequal(ierr, 20009, 'signed_long_identity(100.2)'); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/li_carrays_cpp_runme.sci b/Examples/test-suite/scilab/li_carrays_cpp_runme.sci new file mode 100644 index 00000000000..0ac157446fc --- /dev/null +++ b/Examples/test-suite/scilab/li_carrays_cpp_runme.sci @@ -0,0 +1,11 @@ +exec("swigtest.start", -1); + +d = new_intArray(10); + +intArray_setitem(d, 0, 7); + +intArray_setitem(d, 5, intArray_getitem(d, 0) + 3); + +checkequal(intArray_getitem(d, 5) + intArray_getitem(d, 0), 17, "d(5) + d(0) <> 17"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/li_carrays_runme.sci b/Examples/test-suite/scilab/li_carrays_runme.sci new file mode 100644 index 00000000000..0ac157446fc --- /dev/null +++ b/Examples/test-suite/scilab/li_carrays_runme.sci @@ -0,0 +1,11 @@ +exec("swigtest.start", -1); + +d = new_intArray(10); + +intArray_setitem(d, 0, 7); + +intArray_setitem(d, 5, intArray_getitem(d, 0) + 3); + +checkequal(intArray_getitem(d, 5) + intArray_getitem(d, 0), 17, "d(5) + d(0) <> 17"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/li_cpointer_cpp_runme.sci b/Examples/test-suite/scilab/li_cpointer_cpp_runme.sci new file mode 100644 index 00000000000..0aa4339c86a --- /dev/null +++ b/Examples/test-suite/scilab/li_cpointer_cpp_runme.sci @@ -0,0 +1,8 @@ +exec("swigtest.start", -1); + +p = new_intp(); +intp_assign(p, 3); +checkequal(intp_value(p), 3, "intp_value(p)"); +delete_intp(p); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/li_cpointer_runme.sci b/Examples/test-suite/scilab/li_cpointer_runme.sci new file mode 100644 index 00000000000..0aa4339c86a --- /dev/null +++ b/Examples/test-suite/scilab/li_cpointer_runme.sci @@ -0,0 +1,8 @@ +exec("swigtest.start", -1); + +p = new_intp(); +intp_assign(p, 3); +checkequal(intp_value(p), 3, "intp_value(p)"); +delete_intp(p); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/li_math_runme.sci b/Examples/test-suite/scilab/li_math_runme.sci new file mode 100644 index 00000000000..d05f8eb18fd --- /dev/null +++ b/Examples/test-suite/scilab/li_math_runme.sci @@ -0,0 +1,9 @@ +exec("swigtest.start", -1); + +try + x = fmod(M_PI_get(), M_1_PI_get()) +catch + swigtesterror(); +end + +exec("swigtest.quit", -1); \ No newline at end of file diff --git a/Examples/test-suite/scilab/li_std_container_typemaps_runme.sci b/Examples/test-suite/scilab/li_std_container_typemaps_runme.sci new file mode 100644 index 00000000000..e4832efe6fc --- /dev/null +++ b/Examples/test-suite/scilab/li_std_container_typemaps_runme.sci @@ -0,0 +1,108 @@ +// test STL containers typemaps + +exec("swigtest.start", -1); + +function checkerror(ierr, cmd) + if ierr <> 0 then swigtesterror("error " + string(ierr) + " in """ + cmd + """"); end +endfunction + +// test container of pointers returned from fonction (expected a list) +function [classAPtr_list, classAPtr1, classAPtr2] = testCreateContainerPtr(container, value1, value2) + classAPtr1 = new_ClassA(value1); + classAPtr2 = new_ClassA(value2); + func = msprintf("ret_ClassAPtr_%s", container); + cmd = msprintf("classAPtr_list = %s(classAPtr1, classAPtr2);", func); + ierr = execstr(cmd, "errcatch"); + if ierr <> 0 then swigtesterror("error in " + cmd); end + if ~exists('classAPtr_list') | (size(classAPtr_list) <> 2) then + swigtesterror(func); + end + + checkequal(ClassA_a_get(classAPtr_list(1)), value1, "ClassA_a_get(classAPtr_list(1))"); + checkequal(ClassA_a_get(classAPtr_list(2)), value2, "ClassA_a_get(classAPtr_list(2))"); +endfunction + +// test a given container of pointer +// -container: type of container: "vector", "set"... +// -value1, value2: values to store in container +// -expected_accumulate_value: expected value of an accumulation function +// computed on the container +function testContainerPtr(container, value1, value2, expected_accumulate_value) + // test container of pointers returned from flonction (expected a list) + [classAPtr_list, classAPtr1, classAPtr2] = testCreateContainerPtr(container, value1, value2); + + // test container passed as value of function + func = msprintf("val_ClassAPtr_%s", container); + cmd = msprintf("classAPtr = %s(classAPtr_list);", func); + ierr = execstr(cmd, "errcatch"); + checkerror(ierr, cmd); + checkequal(ClassA_a_get(classAPtr), expected_accumulate_value, func); + + // recreate a container + [classAPtr_list, classAPtr1, classAPtr2] = testCreateContainerPtr(container, value1, value2); + + // test container passed as reference of function + func = msprintf("ref_ClassAPtr_%s", container); + cmd = msprintf("classAPtr = %s(classAPtr_list);", func); + ierr = execstr(cmd, "errcatch"); + checkerror(ierr, cmd); + checkequal(ClassA_a_get(classAPtr), expected_accumulate_value, func); +endfunction + +// test a given container of a given primitive type +// -container: type of container: "vector", "set"... +// -value_type: type of element stored in container: "int", ... +// -value1, value2: values to store in container +// -expected_accumulate_value: expected value of an accumulation function +// computed on the container +function testContainerType(container, value_type, value1, value2, .. + expected_returned_container, expected_accumulate_value) + // test container of basic type returned from fonction + func = msprintf("ret_%s_%s", value_type, container); + if value_type == "string" then + cmd = msprintf("c = %s(''%s'', ''%s'');", func, value1, value2); + elseif value_type == "bool" then + cmd = msprintf("c = %s(%s, %s);", func, "%"+string(value1), "%"+string(value2)); + else + cmd = msprintf("c = %s(%d, %d);", func, value1, value2); + end + ierr = execstr(cmd, "errcatch"); + checkerror(ierr, cmd); + checkequal(c, expected_returned_container, func); + + // test container passed as value of function + func = msprintf("val_%s_%s", value_type, container); + cmd = msprintf("s = %s(c);", func); + ierr = execstr(cmd, "errcatch"); + checkerror(ierr, cmd); + checkequal(s, expected_accumulate_value, func); + + // test container passed as reference of function + func = msprintf("ref_%s_%s", value_type, container); + cmd = msprintf("s = %s(c);", func); + ierr = execstr(cmd, "errcatch"); + checkerror(ierr, cmd); + checkequal(s, expected_accumulate_value, func); +endfunction + +// test a given container of different types +// -container: type of container: "vector", "set"... +function testContainer(container) + testContainerType(container, "int", 1, 2, [1, 2], 3); + testContainerType(container, "double", 2., 3., [2., 3.], 5.); + testContainerType(container, "float", 2., 3., [2., 3.], 5.); + testContainerType(container, "string", "a", "b", ["a", "b"], "ab"); + testContainerType(container, "bool", %F, %T, [%F, %T], %T); + testContainerPtr("vector", 1, 3, 4); +endfunction + + +testContainer("vector"); +testContainer("list"); +testContainer("deque"); +testContainer("set"); +testContainer("multiset"); + +exec("swigtest.quit", -1); + + diff --git a/Examples/test-suite/scilab/li_std_deque_runme.sci b/Examples/test-suite/scilab/li_std_deque_runme.sci new file mode 100644 index 00000000000..c0680846b22 --- /dev/null +++ b/Examples/test-suite/scilab/li_std_deque_runme.sci @@ -0,0 +1,49 @@ +exec("swigtest.start", -1); + +// Test constructors for std::deque +intDeque = new_IntDeque(); +intDeque2 = new_IntDeque(3); +intDeque3 = new_IntDeque(4, 42); +//intDeque4 = new_IntDeque(intDeque3); + +// Test constructors for std::deque +doubleDeque = new_DoubleDeque(); +doubleDeque2 = new_DoubleDeque(3); +doubleDeque3 = new_DoubleDeque(4, 42.0); +//doubleDeque4 = new_DoubleDeque(doubleDeque3); + +// Test constructors for std::deque +realDeque = new_RealDeque(); +realDeque2 = new_RealDeque(3); +realDeque3 = new_RealDeque(4, 42.0); +//realDeque4 = new_RealDeque(realDeque3); + +// average() should return the average of all values in a std::deque +IntDeque_push_back(intDeque, 2); +IntDeque_push_back(intDeque, 4); +IntDeque_push_back(intDeque, 6); +avg = average(intDeque); +checkequal(avg, 4.0, "average(intDeque)"); + +// half shoud return a deque with elements half of the input elements +RealDeque_clear(realDeque); +RealDeque_push_front(realDeque, 2.0); +RealDeque_push_front(realDeque, 4.0); +halfDeque = half(realDeque); +checkequal(halfDeque, [2., 1.], "half(realDeque)"); + +// same for halve_in_place +//DoubleDeque_clear(doubleDeque); +//DoubleDeque_push_front(doubleDeque, 2.0); +//DoubleDeque_push_front(doubleDeque, 4.0); +//halfDeque2 = halve_in_place(doubleDeque); +//checkequal(halfDeque2, [2., 1.], "halve_in_place(doubleDeque)"); + +delete_IntDeque(intDeque); +delete_DoubleDeque(doubleDeque); +delete_RealDeque(realDeque); + +exec("swigtest.quit", -1); + + + diff --git a/Examples/test-suite/scilab/li_std_except_runme.sci b/Examples/test-suite/scilab/li_std_except_runme.sci new file mode 100644 index 00000000000..3b6522f45fc --- /dev/null +++ b/Examples/test-suite/scilab/li_std_except_runme.sci @@ -0,0 +1,33 @@ +exec('swigtest.start', -1); + +function checkException(cmd, expected_ierr, expected_error_msg) + ierr = execstr(cmd, 'errcatch'); + checkequal(ierr, expected_ierr, cmd + ': ierr'); + checkequal(lasterror(), 'SWIG/Scilab: ' + expected_error_msg, cmd + ': msg'); +endfunction + +t = new_Test(); + +checkException('Test_throw_bad_exception(t)', 20010, 'SystemError: std::bad_exception'); + +checkException('Test_throw_domain_error(t)', 20009, 'ValueError: oops'); + +checkException('Test_throw_exception(t)', 20010, 'SystemError: std::exception'); + +checkException('Test_throw_invalid_argum(t)', 20009, 'ValueError: oops'); + +checkException('Test_throw_length_error(t)', 20004, 'IndexError: oops'); + +checkException('Test_throw_logic_error(t)', 20003, 'RuntimeError: oops'); + +checkException('Test_throw_out_of_range(t)', 20004, 'IndexError: oops'); + +checkException('Test_throw_overflow_erro(t)', 20007, 'OverflowError: oops'); + +checkException('Test_throw_range_error(t)', 20007, 'OverflowError: oops'); + +checkException('Test_throw_runtime_error(t)', 20003, 'RuntimeError: oops'); + +delete_Test(t); + +exec('swigtest.quit', -1); diff --git a/Examples/test-suite/scilab/li_std_pair_runme.sci b/Examples/test-suite/scilab/li_std_pair_runme.sci new file mode 100644 index 00000000000..e5f5607ee4d --- /dev/null +++ b/Examples/test-suite/scilab/li_std_pair_runme.sci @@ -0,0 +1,38 @@ +exec("swigtest.start", -1); + +function checkPair(pair, expected_first, expected_second, func) + checkequal(IntPair_first_get(pair), expected_first, func + ": first");; + checkequal(IntPair_second_get(pair), expected_second, func + ": second");; +endfunction + +intPair = makeIntPair(7, 6); +checkPair(intPair, 7, 6, "makeIntPair()"); + +intPairPtr = makeIntPairPtr(7, 6); +checkPair(intPairPtr, 7, 6, "makeIntPairPtr()"); + +intPairRef = makeIntPairRef(7, 6); +checkPair(intPairRef, 7, 6, "makeIntPairRef()"); + +intPairConstRef = makeIntPairConstRef(7, 6); +checkPair(intPairConstRef, 7, 6, "makeIntPairConstRef()"); + +// call fns +checkequal(product1(intPair), 42, "product1(intPair)"); +checkequal(product2(intPair), 42, "product2(intPair)"); +checkequal(product3(intPair), 42, "product3(intPair)") + +// also use the pointer version +checkequal(product1(intPairPtr), 42, "product1(intPairPtr)"); +checkequal(product2(intPairPtr), 42, "product2(intPairPtr)"); +checkequal(product3(intPairPtr), 42, "product3(intPairPtr)"); + +// or the other types +checkequal(product1(intPairRef), 42, "product1(intPairRef)"); +checkequal(product2(intPairRef), 42, "product2(intPairRef)"); +checkequal(product3(intPairRef), 42, "product3(intPairRef)"); +checkequal(product1(intPairConstRef), 42, "product3(intPairConstRef)"); +checkequal(product2(intPairConstRef), 42, "product2(intPairConstRef)"); +checkequal(product3(intPairConstRef), 42, "product1(intPairConstRef)"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/li_std_string_extra_runme.sci b/Examples/test-suite/scilab/li_std_string_extra_runme.sci new file mode 100644 index 00000000000..b96b07e8443 --- /dev/null +++ b/Examples/test-suite/scilab/li_std_string_extra_runme.sci @@ -0,0 +1,58 @@ +exec("swigtest.start", -1); + +x = "hello"; + +// li_std_string tests + +// Function tests + +checkequal(test_ccvalue(x), x, "test_ccvalue()"); +checkequal(test_cvalue(x), x, "test_cvalue(x)"); +checkequal(test_value(x), x, "test_value()"); + +checkequal(test_const_reference(x), x, "test_const_reference(x)"); +checkequal(test_reference_input(x), x, "test_reference_input(x)"); +checkequal(test_reference_inout(x), x+x, "test_reference_inout(x)"); + +//checkequal(test_reference_out(), "test_reference_out message", "test_reference_out()"); +//checkequal(test_const_pointer_out(), "x", "test_const_pointer_out()"); + +s = "initial string"; + +// Global variable tests + +checkequal(GlobalString2_get(), "global string 2", "GlobalString2_get()"); +GlobalString2_set(s); +checkequal(GlobalString2_get(), s, "GlobalString2_get()"); + +checkequal(ConstGlobalString_get(), "const global string", "ConstGlobalString_get()"); + +// Member variable tests + +myStructure = new_Structure(); +checkequal(Structure_Str2_get(myStructure), "member string 2", "Structure_Str2_get(myStructure)"); + +Structure_Str2_set(myStructure, s); +checkequal(Structure_Str2_get(myStructure), s, "Structure_Str2_get(myStructure)"); + +checkequal(Structure_ConstStr_get(myStructure), "const member string", "Structure_ConstStr_get(myStructure)"); + +checkequal(Structure_StaticStr2_get(), "static member string 2", "Structure_StaticStr2_get()"); + +Structure_StaticStr2_set(s); +checkequal(Structure_StaticStr2_get(), s, "Structure_StaticStr2_get()"); + +checkequal(Structure_ConstStati_get(), "const static member string", "Structure_ConstStaticStr_get()"); + + +checkequal(stdstring_empty(), "", "stdstring_empty()"); +checkequal(c_empty(), "", "c_empty()"); + + +// li_std_string_extra tests + +//checkequal(test_value_basic1(x), x, ""); +//checkequal(test_value_basic2(x), x, ""); +//checkequal(test_value_basic3(x), x, ""); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/li_std_vector_runme.sci b/Examples/test-suite/scilab/li_std_vector_runme.sci new file mode 100644 index 00000000000..4f21edd1891 --- /dev/null +++ b/Examples/test-suite/scilab/li_std_vector_runme.sci @@ -0,0 +1,12 @@ +exec("swigtest.start", -1); + +// TODO: support for STL vectors operator = +iv = new_DoubleVector(); +//for i=1:4 +// iv(i) = i; +//end +//x = average(iv); + +//if x <> 2.5 then swigtesterror(); end +exit +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/li_typemaps_runme.sci b/Examples/test-suite/scilab/li_typemaps_runme.sci new file mode 100644 index 00000000000..d9ea0218f5a --- /dev/null +++ b/Examples/test-suite/scilab/li_typemaps_runme.sci @@ -0,0 +1,116 @@ +exec("swigtest.start", -1); + + +// double +checkequal(in_double(22.22), 22.22, "in_double"); +checkequal(inr_double(22.22), 22.22, "inr_double"); +checkequal(out_double(22.22), 22.22, "out_double"); +checkequal(outr_double(22.22), 22.22, "outr_double"); +checkequal(inout_double(22.22), 22.22, "inout_double"); +checkequal(inoutr_double(22.22), 22.22, "inoutr_double"); + +// signed char +checkequal(in_schar(22), 22, "in_schar"); +checkequal(inr_schar(22), 22, "inr_schar"); +checkequal(out_schar(22), 22, "out_schar"); +checkequal(outr_schar(22), 22, "outr_schar"); +checkequal(inout_schar(22), 22, "inout_schar"); +checkequal(inoutr_schar(22), 22, "inoutr_schar"); + +// unsigned char +checkequal(in_uchar(uint8(22)), 22, "in_uchar"); +checkequal(inr_uchar(uint8(22)), 22, "inr_uchar"); +checkequal(out_uchar(uint8(22)), 22, "out_uchar"); +checkequal(outr_uchar(uint8(22)), 22, "outr_uchar"); +checkequal(inout_uchar(uint8(22)), 22, "inout_uchar"); +checkequal(inoutr_uchar(uint8(22)), 22, "inoutr_uchar"); + +// short +checkequal(in_short(22), 22, "in_short"); +checkequal(inr_short(22), 22, "inr_short"); +checkequal(out_short(22), 22, "out_short"); +checkequal(outr_short(22), 22, "outr_short"); +checkequal(inout_short(22), 22, "inout_short"); +checkequal(inoutr_short(22), 22, "inoutr_short"); + +// unsigned short +checkequal(in_ushort(uint16(22)), 22, "in_ushort"); +checkequal(inr_ushort(uint16(22)), 22, "in_ushort"); +checkequal(out_ushort(uint16(22)), 22, "out_ushort"); +checkequal(outr_ushort(uint16(22)), 22, "outr_ushort"); +checkequal(inout_ushort(uint16(22)), 22, "inout_ushort"); +checkequal(inoutr_ushort(uint16(22)), 22, "inoutr_ushort"); + +// int +checkequal(in_int(22), 22, "in_int"); +checkequal(inr_int(22), 22, "inr_int"); +checkequal(out_int(22), 22, "out_int"); +checkequal(outr_int(22), 22, "outr_int"); +checkequal(inout_int(22), 22, "inout_int"); +checkequal(inoutr_int(22), 22, "inoutr_int"); + +// unsigned int +checkequal(in_uint(uint32(22)), 22, "in_uint"); +checkequal(inr_uint(uint32(22)), 22, "inr_uint"); +checkequal(out_uint(uint32(22)), 22, "out_uint"); +checkequal(outr_uint(uint32(22)), 22, "outr_uint"); +checkequal(inout_uint(uint32(22)), 22, "inout_uint"); +checkequal(inoutr_uint(uint32(22)), 22, "inoutr_uint"); + +// long +checkequal(in_long(22), 22, "in_long"); +checkequal(inr_long(22), 22, "inr_long"); +checkequal(out_long(22), 22, "out_long"); +checkequal(outr_long(22), 22, "outr_long"); +checkequal(inout_long(22), 22, "inout_long"); +checkequal(inoutr_long(22), 22, "inoutr_long"); + +// unsigned long +checkequal(in_ulong(uint32(22)), 22, "in_ulong"); +checkequal(inr_ulong(uint32(22)), 22, "inr_ulong"); +checkequal(out_ulong(uint32(22)), 22, "out_ulong"); +checkequal(outr_ulong(uint32(22)), 22, "outr_ulong"); +checkequal(inout_ulong(uint32(22)), 22, "inout_ulong"); +checkequal(inoutr_ulong(uint32(22)), 22, "inoutr_ulong"); + +// bool +checkequal(in_bool(%t), %t, "in_bool"); +checkequal(inr_bool(%f), %f, "inr_bool"); +checkequal(out_bool(%t), %t, "out_bool"); +checkequal(outr_bool(%f), %f, "outr_bool"); +checkequal(inout_bool(%t), %t, "inout_bool"); +checkequal(inoutr_bool(%f), %f, "inoutr_bool"); + +// float +checkequal(in_float(2.5), 2.5, "in_float"); +checkequal(inr_float(2.5), 2.5, "inr_float"); +checkequal(out_float(2.5), 2.5, "out_float"); +checkequal(outr_float(2.5), 2.5, "outr_float"); +checkequal(inout_float(2.5), 2.5, "inout_float"); +checkequal(inoutr_float(2.5), 2.5, "inoutr_float"); + +// long long +// Not supported in Scilab 5.5 +//checkequal(in_longlong(22), 22, "in_longlong"); +//checkequal(inr_longlong(22), 22, "inr_longlong"); +//checkequal(out_longlong(22), 22, "out_longlong"); +//checkequal(outr_longlong(22), 22, "outr_longlong"); +//checkequal(inout_longlong(22), 22, "inout_longlong"); +//checkequal(inoutr_longlong(22), 22, "inoutr_longlong"); + +// unsigned long long +// Not supported in Scilab 5.5 +//checkequal(in_ulonglong(uint64(22)), 22, "in_ulonglong"); +//checkequal(inr_ulonglong(uint64(22)), 22, "inr_ulonglong"); +//checkequal(out_ulonglong(uint64(22)), 22, "out_ulonglong"); +//checkequal(outr_ulonglong(uint64(22)), 22, "outr_ulonglong"); +//checkequal(inout_ulonglong(uint64(22)), 22, "inout_ulonglong"); +//checkequal(inoutr_ulonglong(uint64(22)), 22, "inoutr_ulonglong"); + +// the others +//a,b = inoutr_int2(1, 2); +//checkequal(a<>1 || b<>2), ""); +//f,i = out_foo(10) +//checkequal(f.a, 10 || i, 20), ""); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/member_pointer_runme.sci b/Examples/test-suite/scilab/member_pointer_runme.sci new file mode 100644 index 00000000000..5d90f172fb8 --- /dev/null +++ b/Examples/test-suite/scilab/member_pointer_runme.sci @@ -0,0 +1,20 @@ +exec("swigtest.start", -1); + +s = new_Square(10); + +// Functions +checkequal(do_op(s, areapt()), 100.0, "Square area"); +checkequal(do_op(s, perimeterpt()), 40.0, "Square perimeter"); + +// Variables +checkequal(do_op(s, areavar_get()), 100.0, "Square area"); +areavar_set(perimeterpt()); +checkequal(do_op(s, areavar_get()), 40.0, "Square perimeter"); + +// Constants +checkequal(do_op(s, AREAPT_get()), 100.0, "Square area"); +checkequal(do_op(s, PERIMPT_get()), 40.0, "Square perimeter"); + +delete_Square(s); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/name_runme.sci b/Examples/test-suite/scilab/name_runme.sci new file mode 100644 index 00000000000..dd901df616e --- /dev/null +++ b/Examples/test-suite/scilab/name_runme.sci @@ -0,0 +1,11 @@ +exec("swigtest.start", -1); + +try + foo_2(); +catch + swigtesterror(); +end +if bar_2_get() <> 17 then swigtesterror(); end +if Baz_2_get() <> 47 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/nested_structs_runme.sci b/Examples/test-suite/scilab/nested_structs_runme.sci new file mode 100644 index 00000000000..1899fe378a8 --- /dev/null +++ b/Examples/test-suite/scilab/nested_structs_runme.sci @@ -0,0 +1,34 @@ +exec("swigtest.start", -1); + +try + outer = new_Outer(); + setValues(outer, 10); + + inner1 = Outer_inner1_get(outer); + inner2 = Outer_inner2_get(outer); + inner3 = Outer_inner3_get(outer); + inner4 = Outer_inner4_get(outer); +catch + swigtesterror(); +end + +checkequal(Outer_inner1_val_get(inner1), 10, "Outer_inner1_val_get(inner1)"); +checkequal(Outer_inner1_val_get(inner2), 20, "Outer_inner1_val_get(inner2)"); +checkequal(Outer_inner1_val_get(inner3), 20, "Outer_inner1_val_get(inner3)"); +checkequal(Outer_inner1_val_get(inner4), 40, "Outer_inner1_val_get(inner4)"); + +try + inside1 = Outer_inside1_get(outer); + inside2 = Outer_inside2_get(outer); + inside3 = Outer_inside3_get(outer); + inside4 = Outer_inside4_get(outer); +catch + swigtesterror(); +end + +checkequal(Named_val_get(inside1), 100, "Named_val_get(inside1)"); +checkequal(Named_val_get(inside2), 200, "Named_val_get(inside2)"); +checkequal(Named_val_get(inside3), 200, "Named_val_get(inside3)"); +checkequal(Named_val_get(inside4), 400, "Named_val_get(inside4)"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/newobject2_runme.sci b/Examples/test-suite/scilab/newobject2_runme.sci new file mode 100644 index 00000000000..da1d50cbdf7 --- /dev/null +++ b/Examples/test-suite/scilab/newobject2_runme.sci @@ -0,0 +1,31 @@ +exec("swigtest.start", -1); + +try + x = makeFoo(); +catch + swigtesterror(); +end +if fooCount() <> 1 then swigtesterror(); end + +try + y = makeFoo(); +catch + swigtesterror(); +end +if fooCount() <> 2 then swigtesterror(); end + +try + delete_Foo(x); +catch + swigtesterror(); +end +if fooCount() <> 1 then swigtesterror(); end + +try + delete_Foo(y); +catch + swigtesterror(); +end +if fooCount() <> 0 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/null_pointer_runme.sci b/Examples/test-suite/scilab/null_pointer_runme.sci new file mode 100644 index 00000000000..2c693d2594a --- /dev/null +++ b/Examples/test-suite/scilab/null_pointer_runme.sci @@ -0,0 +1,7 @@ +exec("swigtest.start", -1); + +p = getnull(); +checkequal(SWIG_this(p), 0, "SWIG_this(p)"); +checkequal(func(p), %T, "func(p)"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/operator_overload_runme.sci b/Examples/test-suite/scilab/operator_overload_runme.sci new file mode 100644 index 00000000000..ca41acd7543 --- /dev/null +++ b/Examples/test-suite/scilab/operator_overload_runme.sci @@ -0,0 +1,82 @@ +exec("swigtest.start", -1); + +function checktrue(value, msg) + checkequal(value, %T, msg) +endfunction + +a = new_Op(); +b = new_Op(5); +c = new_Op(b); +d = new_Op(2); +dd = new_Op(); + +// Assignment operator +Op_Equal(dd, d); + +// Comparison operator +checktrue(Op_NotEqual(a, b), "Op_NotEqual(a, b)"); +checktrue(Op_EqualEqual(b, c), "Op_EqualEqual(b, c)"); +checktrue(Op_NotEqual(a, d), "Op_NotEqual(a, d)"); +checktrue(Op_EqualEqual(d, dd), "Op_EqualEqual(d, dd)"); + +checktrue(Op_LessThan(a, b), "Op_LessThan(a, b)"); +checktrue(Op_LessThanEqual(a, b), "Op_LessThanEqual(a, b)"); +checktrue(Op_LessThanEqual(b, c), "Op_LessThanEqual(b, c)"); +checktrue(Op_GreaterThanEqual(b, c), "Op_GreaterThanEqual(b, c)"); +checktrue(Op_GreaterThan(b, d), "Op_GreaterThan(b, d)"); +checktrue(Op_GreaterThanEqual(b, d), "Op_GreaterThanEqual(b, d)"); + +delete_Op(a); +delete_Op(b); +delete_Op(c); +delete_Op(d); +delete_Op(dd); + +f = new_Op(1); +g = new_Op(1); + +expop = new_Op(); + +op = Op_Plus(f, g); +Op_i_set(expop, 2); +checktrue(Op_EqualEqual(op, expop), "Op_Plus(f, g) <> Op(2)"); +delete_Op(op); + +op = Op_Minus(f, g); +Op_i_set(expop, 0); +checktrue(Op_EqualEqual(op, expop), "Op_Minus(f, g) <> Op(0)"); +delete_Op(op); + +op = Op_Multiply(f, g); +Op_i_set(expop, 1); +checktrue(Op_EqualEqual(op, expop), "Op_Multiply(f, g) <> Op(1)"); +delete_Op(op); + +op = Op_Divide(f, g); +Op_i_set(expop, 1); +checktrue(Op_EqualEqual(op, expop), "Op_Divide(f, g) <> Op(1)"); +delete_Op(op); + +// Unary operator +op = Op_PlusPlusPrefix(new_Op(3)); +Op_i_set(expop, 4); +checktrue(Op_EqualEqual(op, expop), "Op_PlusPlusPrefix(op) <> Op(4)"); + +// Square bracket operator +checkequal(Op_IndexIntoConst(op, uint32(0)), 4, "Op_IndexIntoConst(op, 0) <> 4"); +checkequal(Op_IndexIntoConst(op, uint32(1)), 0, "Op_IndexIntoConst(op, 1) <> 0"); + +// Functor +i = new_Op(3); +checkequal(Op_Functor(i), 3, "Op_Functor(i)"); +checkequal(Op_Functor(i, 1), 4, "Op_Functor(i, 1)"); + +delete_Op(f); +delete_Op(g); + +delete_Op(i); + +delete_Op(expop); + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/overload_arrays_runme.sci b/Examples/test-suite/scilab/overload_arrays_runme.sci new file mode 100644 index 00000000000..4d9a8b035e4 --- /dev/null +++ b/Examples/test-suite/scilab/overload_arrays_runme.sci @@ -0,0 +1,46 @@ +exec("swigtest.start", -1); + +// Functions + +checkequal(foo(int32([1, 2, 3])), "foo:int[SIZE]", "foo(int[SIZE])"); +checkequal(foo([1, 2, 3]), "foo:double[SIZE]", "foo(double[SIZE])"); +checkequal(foo(["1" "2" "3"]), "foo:char *[SIZE]", "foo(char *[SIZE])"); + +// Class methods + +s = new_Spam(); +checkequal(Spam_foo(s, int32([1, 2, 3])), "foo:int[SIZE]", "Spam::foo(int[SIZE])"); +checkequal(Spam_foo(s, [1, 2, 3]), "foo:double[SIZE]", "Spam::foo(double[SIZE])"); +checkequal(Spam_foo(s, ["1" "2" "3"]), "foo:char *[SIZE]", "Spam::foo(char *[SIZE])"); +delete_Spam(s); + +// Static class methods + +checkequal(Spam_bar(int32([1, 2, 3])), "bar:int[SIZE]", "Spam::bar(int[SIZE])"); +checkequal(Spam_bar([1, 2, 3]), "bar:double[SIZE]", "Spam::bar(double[SIZE])"); +checkequal(Spam_bar("hello"), "bar:char *[SIZE]", "Spam::bar(char *[SIZE])"); + +// Constructors + +s = new_Spam(); +checkequal(Spam_type_get(s), "none", "Spam::Spam()"); +delete_Spam(s); + +s = new_Spam(int32([1, 2, 3])); +checkequal(Spam_type_get(s), "int[SIZE]", "Spam::Spam(int[SIZE])"); +delete_Spam(s); + +s = new_Spam([1, 2, 3]); +checkequal(Spam_type_get(s), "double[SIZE]", "Spam::Spam(double[SIZE])"); +delete_Spam(s); + +s = new_Spam(["1" "2" "3"]); +checkequal(Spam_type_get(s), "char *[SIZE]", "Spam::Spam(char *[SIZE])"); +delete_Spam(s); + + +a = new_ClassA(); +b = ClassA_method1(a, [1 2 3]); + + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/overload_complicated_runme.sci b/Examples/test-suite/scilab/overload_complicated_runme.sci new file mode 100644 index 00000000000..f1c24717ae3 --- /dev/null +++ b/Examples/test-suite/scilab/overload_complicated_runme.sci @@ -0,0 +1,25 @@ +exec("swigtest.start", -1); + +NULL = SWIG_ptr(0); +p = new_Pop(NULL); +p = new_Pop(NULL, %T); + +checkequal(Pop_hip(p, %T), 701, "Pop_hip(%T)"); +checkequal(Pop_hip(p, NULL), 702, "Pop_hip(NULL)"); + +checkequal(Pop_hop(p, %T), 801, "Pop_hop(%T)"); +checkequal(Pop_hop(p, NULL), 805, "Pop_hop(NULL)"); + +checkequal(Pop_pop(p, %T), 901, "Pop_pop(%T)"); +checkequal(Pop_pop(p, NULL), 904, "Pop_pop(NULL)"); +checkequal(Pop_pop(p), 905, "Pop_pop()"); + +checkequal(Pop_bop(p, NULL), 1001, "Pop_bop(NULL)"); + +checkequal(Pop_bip(p, NULL), 2002, "Pop_bip(%T)"); + +checkequal(muzak(%T), 3001, "muzak(%T)"); +checkequal(muzak(NULL), 3002, "muzak(%T)"); + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/overload_copy_runme.sci b/Examples/test-suite/scilab/overload_copy_runme.sci new file mode 100644 index 00000000000..6d163ffa771 --- /dev/null +++ b/Examples/test-suite/scilab/overload_copy_runme.sci @@ -0,0 +1,10 @@ +exec("swigtest.start", -1); + +f = new_Foo(); +g = new_Foo(f); + +delete_Foo(f); +delete_Foo(g); + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/overload_extend2_runme.sci b/Examples/test-suite/scilab/overload_extend2_runme.sci new file mode 100644 index 00000000000..bf474ddbf34 --- /dev/null +++ b/Examples/test-suite/scilab/overload_extend2_runme.sci @@ -0,0 +1,15 @@ +exec("swigtest.start", -1); + +try + x = new_Foo(); +catch + swigtesterror(); +end +if Foo_test(x, 1) <> 1 then swigtesterror(); end +if Foo_test(x, "Hello swig!") <> 2 then swigtesterror(); end +if Foo_test(x, 2, 3) <> 3 then swigtesterror(); end +if Foo_test(x, x) <> 30 then swigtesterror(); end +if Foo_test(x, x, 4) <> 24 then swigtesterror(); end +if Foo_test(x, x, 4, 5) <> 9 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/overload_extend_c_runme.sci b/Examples/test-suite/scilab/overload_extend_c_runme.sci new file mode 100644 index 00000000000..416477bcbad --- /dev/null +++ b/Examples/test-suite/scilab/overload_extend_c_runme.sci @@ -0,0 +1,13 @@ +exec("swigtest.start", -1); + +//try +// x = new_Foo(); +//catch +// swigtesterror(); +//end +//if Foo_test(x) <> 0 then swigtesterror(); end +//if Foo_test(x, 1) <> 1 then swigtesterror(); end +//if Foo_test(x, 2, 3) <> 5 then swigtesterror(); end +//if Foo_test(x, "Hello, swig!") <> 2 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/overload_extend_runme.sci b/Examples/test-suite/scilab/overload_extend_runme.sci new file mode 100644 index 00000000000..416477bcbad --- /dev/null +++ b/Examples/test-suite/scilab/overload_extend_runme.sci @@ -0,0 +1,13 @@ +exec("swigtest.start", -1); + +//try +// x = new_Foo(); +//catch +// swigtesterror(); +//end +//if Foo_test(x) <> 0 then swigtesterror(); end +//if Foo_test(x, 1) <> 1 then swigtesterror(); end +//if Foo_test(x, 2, 3) <> 5 then swigtesterror(); end +//if Foo_test(x, "Hello, swig!") <> 2 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/overload_numeric_runme.sci b/Examples/test-suite/scilab/overload_numeric_runme.sci new file mode 100644 index 00000000000..ea79cff6144 --- /dev/null +++ b/Examples/test-suite/scilab/overload_numeric_runme.sci @@ -0,0 +1,16 @@ +exec("swigtest.start", -1); + +nums = new_Nums(); + +// In overloading in Scilab, double has priority over all other numeric types +checkequal(Nums_over(nums, 0), "double", "Nums_over(nums, 0)"); + +// Just checkequal if the following are accepted without exceptions being thrown +Nums_doublebounce(nums, %inf); +Nums_doublebounce(nums, -%inf); +Nums_doublebounce(nums, %nan); + +delete_Nums(nums); + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/overload_simple_runme.sci b/Examples/test-suite/scilab/overload_simple_runme.sci new file mode 100644 index 00000000000..23be43db9cb --- /dev/null +++ b/Examples/test-suite/scilab/overload_simple_runme.sci @@ -0,0 +1,73 @@ +exec("swigtest.start", -1); + +// Functions + +checkequal(foo(int32(3)), "foo:int", "foo(int)"); +checkequal(foo(3), "foo:double", "foo(double)"); +checkequal(foo("hello"), "foo:char *", "foo(char* )"); +f = new_Foo(); +checkequal(foo(f), "foo:Foo *", "foo(Foo *)"); +//b = new_Bar(); +//checkequal(foo(b), "foo:Bar *", "foo(Bar *)"); +//v = malloc_void(32); +//checkequal(foo(v), "foo:void *", "foo(void *)"); + +// Class methods + +s = new_Spam(); +checkequal(Spam_foo(s, int32(3)), "foo:int", "Spam::foo(int)"); +checkequal(Spam_foo(s, 3), "foo:double", "Spam::foo(double)"); +checkequal(Spam_foo(s, "hello"), "foo:char *", "Spam::foo(char *)"); +checkequal(Spam_foo(s, f), "foo:Foo *", "Spam::foo(Foo *)"); +//checkequal(Spam_foo(s, b), "foo:Bar *", "Spam::foo(Bar *)"); +//checkequal(Spam_foo(s, v), "foo:void *", "Spam::foo(void *)"); +delete_Spam(s); + +// Static class methods + +checkequal(Spam_bar(int32(3)), "bar:int", "Spam::bar(int)"); +checkequal(Spam_bar(3.1), "bar:double", "Spam::bar(double)"); +checkequal(Spam_bar("hello"), "bar:char *", "Spam::bar(char *)"); +checkequal(Spam_bar(f), "bar:Foo *", "Spam::bar(Foo *)"); +//checkequal(Spam_bar(b), "bar:Bar *", "Spam::bar(Bar *)"); +//checkequal(Spam_bar(b), "bar:void *", "Spam::bar(void *)"); + +// Constructors + +s = new_Spam(); +checkequal(Spam_type_get(s), "none", "Spam::Spam()"); +delete_Spam(s); + +s = new_Spam(int32(3)); +checkequal(Spam_type_get(s), "int", "Spam::Spam(int)"); +delete_Spam(s); + +s = new_Spam(3.1); +checkequal(Spam_type_get(s), "double", "Spam::Spam(double)"); +delete_Spam(s); + +s = new_Spam("hello"); +checkequal(Spam_type_get(s), "char *", "Spam::Spam(char *)"); +delete_Spam(s); + +s = new_Spam(f); +checkequal(Spam_type_get(s), "Foo *", "Spam::Spam(Foo *)"); +delete_Spam(s); + +//s = new_Spam(b); +//checkequal(Spam_type_get(s), "Bar *", "Spam::Spam(Bar *)"); +//delete_Spam(s); + +//s = new_Spam(v); +//checkequal(Spam_type_get(s), "void *", "Spam::Spam(void *)"); +//delete_Spam(s); + +delete_Foo(f); +//delete_Bar(b); +//free_void(v); + +a = new_ClassA(); +b = ClassA_method1(a, 1); + + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/preproc_constants_runme.sci b/Examples/test-suite/scilab/preproc_constants_runme.sci new file mode 100644 index 00000000000..d3d0a4b569b --- /dev/null +++ b/Examples/test-suite/scilab/preproc_constants_runme.sci @@ -0,0 +1,30 @@ +exec("swigtest.start", -1); + +checkequal(CONST_INT1_get(), 10, "CONST_INT1"); +checkequal(CONST_DOUBLE3_get(), 12.3, "CONST_DOUBLE3"); +checkequal(CONST_BOOL1_get(), %T, "CONST_BOOL1"); +checkequal(CONST_CHAR_get(), 'x', "CONST_CHAR"); +checkequal(CONST_STRING1_get(), "const string", "CONST_STRING1"); + +// Test global constants can be seen within functions +function test_global() + global CONST_INT1 + global CONST_DOUBLE3 + global CONST_BOOL1 + global CONST_CHAR + global CONST_STRING1 + + checkequal(CONST_INT1_get(), 10, "CONST_INT1"); + checkequal(CONST_DOUBLE3_get(), 12.3, "CONST_DOUBLE3"); + checkequal(CONST_BOOL1_get(), %T, "CONST_BOOL1"); + checkequal(CONST_CHAR_get(), 'x', "CONST_CHAR"); + checkequal(CONST_STRING1_get(), "const string", "CONST_STRING1"); +endfunction + +test_global(); + + +// Test assignement in enums +checkequal(kValue_get(), 4, "kValue"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/preproc_runme.sci b/Examples/test-suite/scilab/preproc_runme.sci new file mode 100644 index 00000000000..a54815a3492 --- /dev/null +++ b/Examples/test-suite/scilab/preproc_runme.sci @@ -0,0 +1,8 @@ +exec("swigtest.start", -1); + +if endif_get() <> 1 then swigtesterror(); end +if define_get() <> 1 then swigtesterror(); end +if defined_get() <> 1 then swigtesterror(); end +if 2 * one_get() <> two_get() then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/primitive_ref_runme.sci b/Examples/test-suite/scilab/primitive_ref_runme.sci new file mode 100644 index 00000000000..9ff400ea5a2 --- /dev/null +++ b/Examples/test-suite/scilab/primitive_ref_runme.sci @@ -0,0 +1,24 @@ +exec("swigtest.start", -1); + +checkequal(ref_int(3), 3, "ref_int() test fails."); +checkequal(ref_uint(uint32(3)), 3, "ref_uint() test fails."); + +checkequal(ref_short(3), 3, "ref_short() test fails."); +checkequal(ref_ushort(uint16(3)), 3, "ref_ushort() test fails."); + +checkequal(ref_long(3), 3, "ref_long() test fails."); +checkequal(ref_ulong(uint32(3)), 3, "ref_ulong() test fails."); + +checkequal(ref_schar(3), 3, "ref_schar() test fails."); +checkequal(ref_uchar(uint8(3)), 3, "ref_uchar() test fails."); + +checkequal(ref_float(3), 3, "ref_float() test fails."); +checkequal(ref_double(3), 3, "ref_double() test fails."); + +checkequal(ref_bool(%T), %T, "ref_bool() test fails."); + +checkequal(ref_char('x'), 'x', "ref_char() test fails."); + +checkequal(ref_over(0), 0, "ref_over() test fails."); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/primitive_types_runme.sci b/Examples/test-suite/scilab/primitive_types_runme.sci new file mode 100644 index 00000000000..423ee44aeaf --- /dev/null +++ b/Examples/test-suite/scilab/primitive_types_runme.sci @@ -0,0 +1,57 @@ +exec("swigtest.start", -1); + +// Check passing by value + +checkequal(val_double(42), 42, "val_double() test fails."); +checkequal(val_float(42), 42, "val_float() test fails."); + +checkequal(val_char('a'), 'a', "val_char() test fails."); +checkequal(val_schar(42), 42, "val_schar() test fails."); +checkequal(val_schar(int8(42)), 42, "val_schar() test fails."); +checkequal(val_uchar(uint8(42)), 42, "val_uchar() test fails."); + +checkequal(val_short(42), 42, "val_short() test fails."); +checkequal(val_short(int16(42)), 42, "val_short() test fails."); +checkequal(val_ushort(uint16(42)), 42, "val_ushort() test fails."); + +checkequal(val_int(42), 42, "val_int() test fails."); +checkequal(val_int(int32(42)), 42, "val_int() test fails."); +checkequal(val_uint(uint32(42)), 42, "val_uint() test fails."); + +checkequal(val_long(42), 42, "val_long() test fails."); +checkequal(val_long(int32(42)), 42, "val_long() test fails."); +checkequal(val_ulong(uint32(42)), 42, "val_long() test fails."); + +checkequal(val_bool(%t), %t, "val_bool() test fails."); + +// longlong is not supported in Scilab 5.x +//checkequal(val_llong(42), 42, "val_llong() test fails."); +//checkequal(val_llong(int64(42)), 42, "val_llong() test fails."); +//checkequal(val_ullong(uint64(42)), 42, "val_ullong() test fails."); + +// Check passing by reference +checkequal(ref_char('a'), 'a', "ref_char() test fails."); +checkequal(ref_schar(42), 42, "ref_schar() test fails."); +checkequal(ref_schar(int8(42)), 42, "ref_schar() test fails."); +checkequal(ref_uchar(uint8(42)), 42, "ref_uchar() test fails."); + +checkequal(ref_short(42), 42, "ref_short() test fails.") +checkequal(ref_short(int16(42)), 42, "ref_short() test fails.") +checkequal(ref_ushort(uint16(42)), 42, "ref_ushort() test fails.") + +checkequal(ref_int(42), 42, "ref_int() test fails."); +checkequal(ref_int(int32(42)), 42, "ref_int() test fails."); +checkequal(ref_uint(uint32(42)), 42, "ref_uint() test fails."); + +checkequal(ref_long(42), 42, "ref_long() test fails."); +checkequal(ref_long(int32(42)), 42, "ref_long() test fails."); +checkequal(ref_ulong(uint32(42)), 42, "ref_ulong() test fails."); + +checkequal(ref_bool(%t), %t, "ref_bool() test fails."); + +// long long is not supported in Scilab 5.x +//checkequal(ref_llong(42), 42, "ref_llong() test fails."); +//checkequal(ref_llong(int64(42)), 42, "ref_llong() test fails."); +//checkequal(ref_ullong(uint64(42)), 42, "ref_ullong() test fails."); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/ret_by_value_runme.sci b/Examples/test-suite/scilab/ret_by_value_runme.sci new file mode 100644 index 00000000000..6475c8678f0 --- /dev/null +++ b/Examples/test-suite/scilab/ret_by_value_runme.sci @@ -0,0 +1,28 @@ +exec("swigtest.start", -1); + +try + a = get_test(); +catch + swigtesterror(); +end + +// Test default values +checkequal(test_myInt_get(a), 100, "test_myInt_get() test fails."); +checkequal(test_myShort_get(a), 200, "test_myShort_get() test fails."); + +// Write new values +try + test_myInt_set(a, 42) + test_myShort_set(a, 12) +catch + swigtesterror(); +end + +// Read new values +checkequal(test_myInt_get(a), 42, "test_myInt_get() test fails."); +checkequal(test_myShort_get(a), 12, "test_myShort_get() test fails."); + +// Destroy pointer +delete_test(a); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/return_const_value_runme.sci b/Examples/test-suite/scilab/return_const_value_runme.sci new file mode 100644 index 00000000000..662bf3625d1 --- /dev/null +++ b/Examples/test-suite/scilab/return_const_value_runme.sci @@ -0,0 +1,11 @@ +exec("swigtest.start", -1); + +foo_ptr = Foo_ptr_getPtr(); +foo = Foo_ptr___deref__(foo_ptr); +checkequal(Foo_getVal(foo), 17, "Foo_getVal(p)"); + +foo_ptr = Foo_ptr_getConstPtr(); +foo = Foo_ptr___deref__(foo_ptr); +checkequal(Foo_getVal(foo), 17, "Foo_getVal(p)"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/scilab_consts_runme.sci b/Examples/test-suite/scilab/scilab_consts_runme.sci new file mode 100644 index 00000000000..d33b45743a4 --- /dev/null +++ b/Examples/test-suite/scilab/scilab_consts_runme.sci @@ -0,0 +1,35 @@ +exec("swigtest.start", -1); + +checkequal(ICONST0_get(), 42, "ICONST0_get()"); +checkequal(FCONST0_get(), 2.1828, "FCONST0_get()"); +checkequal(CCONST0_get(), "x", "CCONST0_get()"); +//checkequal(CCONST0_2_get(), "\n", "CCONST0_2_get()"); +checkequal(SCONST0_get(), "Hello World", "SCONST0_get()"); +checkequal(SCONST0_2_get(), """Hello World""", "SCONST0_2_get()"); +checkequal(EXPR0_get(), 48.5484, "EXPR0_get()"); +checkequal(iconst0_get(), 37, "iconst0_get()"); +checkequal(fconst0_get(), 42.2, "fconst0_get()"); + +checkequal(UNSIGNED0_get(), hex2dec("5FFF"), "UNSIGNED0_get()"); +checkequal(LONG0_get(), hex2dec("3FFF0000"), "LONG0_get()"); +checkequal(ULONG0_get(), hex2dec("5FF0000"), "ULONG0_get()"); + +if isdef('BAR0') then swigtesterror("BAR0"); end + +checkequal(ICONST1, int32(42), "ICONST1"); +checkequal(FCONST1, 2.1828, "FCONST1"); +checkequal(CCONST1, "x", "CCONST1"); +//checkequal(CCONST1_2, "\n", "CCONST1_2"); +checkequal(SCONST1, "Hello World", "SCONST1"); +checkequal(SCONST1_2, """Hello World""", "SCONST1_2"); +checkequal(EXPR1, 48.5484, "EXPR1"); +checkequal(iconst1, int32(37), "iconst1"); +checkequal(fconst1, 42.2, "fconst1"); + +checkequal(UNSIGNED1, uint32(hex2dec("5FFF")), "UNSIGNED1"); +checkequal(LONG1, int32(hex2dec("3FFF0000")), "LONG1"); +checkequal(ULONG1, uint32(hex2dec("5FF0000")), "ULONG1"); + +if isdef('BAR1') then swigtesterror("BAR1"); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/scilab_enums_runme.sci b/Examples/test-suite/scilab/scilab_enums_runme.sci new file mode 100644 index 00000000000..3e9fb7ae048 --- /dev/null +++ b/Examples/test-suite/scilab/scilab_enums_runme.sci @@ -0,0 +1,27 @@ +exec("swigtest.start", -1); + +function checkEnum(enum_val, expected_enum_val) + if typeof(enum_val) <> "constant" then swigtesterror(); end + if enum_val <> expected_enum_val then swigtesterror(); end +endfunction + +checkEnum(ENUM_1, 0); +checkEnum(ENUM_2, 1); + +checkEnum(ENUM_EXPLICIT_1_1, 5); +checkEnum(ENUM_EXPLICIT_1_2, 6); + +checkEnum(ENUM_EXPLICIT_2_1, 0); +checkEnum(ENUM_EXPLICIT_2_2, 10); + +checkEnum(ENUM_EXPLICIT_3_1, 2); +checkEnum(ENUM_EXPLICIT_3_2, 5); +checkEnum(ENUM_EXPLICIT_3_3, 8); + +checkEnum(TYPEDEF_ENUM_1_1, 21); +checkEnum(TYPEDEF_ENUM_1_2, 22); + +checkEnum(TYPEDEF_ENUM_2_1, 31); +checkEnum(TYPEDEF_ENUM_2_2, 32); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/scilab_identifier_name_runme.sci b/Examples/test-suite/scilab/scilab_identifier_name_runme.sci new file mode 100644 index 00000000000..9a4f3cc082c --- /dev/null +++ b/Examples/test-suite/scilab/scilab_identifier_name_runme.sci @@ -0,0 +1,29 @@ +exec("swigtest.start", -1); + + +// Test truncating variables, constants, functions identifier names +// not truncated +gvar_identifier_name_set(-101); +checkequal(gvar_identifier_name_get(), -101, "gvar_identifier_name_get()"); +checkequal(CONS_IDENTIFIER_NAME_get(), -11, "CONS_IDENTIFIER_NAME_get()"); +checkequal(function_identifier_name(), -21, "function_identifier_name()"); + +// truncated +too_long_gvar_identi_set(101); +checkequal(too_long_gvar_identi_get(), 101, "too_long_variable_id_get()"); +checkequal(TOO_LONG_CONST_IDENT_get(), 11, "TOO_LONG_CONST_IDENT_get()"); +checkequal(too_long_function_identi(), 21, "too_long_function_identi()"); + +// Test truncating when %scilabconst mode is activated +checkequal(SC_CONST_IDENTIFIER_NAME, int32(-12), "SC_TOO_LONG_IDENTIF"); +checkequal(SC_TOO_LONG_CONST_IDENTI, int32(14), "SC_TOO_LONG_IDENTIF"); + +// Test truncating in the case of struct +st = new_st(); +st_m_identifier_name_set(st, 15); +checkequal(st_m_identifier_name_get(st), 15, "st_m_identifier_name_get(st)"); +st_too_long_member_i_set(st, 25); +checkequal(st_too_long_member_i_get(st), 25, "st_too_long_member_i_get(st)"); +delete_st(st); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/scilab_li_matrix_runme.sci b/Examples/test-suite/scilab/scilab_li_matrix_runme.sci new file mode 100644 index 00000000000..41924d6f93b --- /dev/null +++ b/Examples/test-suite/scilab/scilab_li_matrix_runme.sci @@ -0,0 +1,67 @@ +// test matrix.i library + +exec("swigtest.start", -1); + +// test matrix passed as output argument from fonction +function test_outMatrix(func, valueType, expectedOutMatrix) + funcName = msprintf("out%s%s", valueType, func); + cmd = msprintf("outMatrix = %s();", funcName); + ierr = execstr(cmd, "errcatch"); + if ierr <> 0 then + swigtesterror(msprintf("Error %d in %s", ierr, funcName)); + end + checkequal(outMatrix, expectedOutMatrix, funcName); +endfunction + +// test matrix passed as input argument of fonction +function test_inMatrix(func, valueType, inMatrix, expectedInValue) + funcName = msprintf("in%s%s", valueType, func); + cmd = msprintf("inValue = %s(inMatrix);", funcName); + ierr = execstr(cmd, "errcatch"); + if ierr <> 0 then + swigtesterror(msprintf("Error %d in %s", ierr, funcName)); + end + checkequal(inValue, expectedInValue, funcName); +endfunction + +// test matrixes passed as input and output arguments of fonction +function test_inoutMatrix(func, valueType, inoutMatrix, expectedInoutMatrix) + funcName = msprintf("inout%s%s", valueType, func); + cmd = msprintf("inoutMatrix = %s(inoutMatrix);", funcName); + ierr = execstr(cmd, "errcatch"); + if ierr <> 0 then + swigtesterror(msprintf("Error %d in %s", ierr, funcName)); + end + checkequal(inoutMatrix, expectedInoutMatrix, funcName); +endfunction + +function test_matrix_typemaps(valueType, .. + expectedOutMatrixDims, expectedOutMatrixSize, .. + expectedInValue, .. + expectedInoutMatrixDims, expectedInoutMatrixSize) + + test_outMatrix("MatrixDims", valueType, expectedOutMatrixDims); + test_outMatrix("MatrixSize", valueType, expectedOutMatrixSize); + matrixDims = expectedOutMatrixDims; + matrixSize = expectedOutMatrixSize; + test_inMatrix("MatrixDims", valueType, matrixDims, expectedInValue); + test_inMatrix("MatrixSize", valueType, matrixSize, expectedInValue); + test_inoutMatrix("MatrixDims", valueType, matrixDims, expectedInoutMatrixDims); + test_inoutMatrix("MatrixSize", valueType, matrixSize, expectedInoutMatrixSize); +endfunction + + +m = [0 3; 1 4; 2 5]; +v = [0 1 2 3 4 5]; +test_matrix_typemaps("Int", m, v, sum(m), m .* m, v .* v); +test_matrix_typemaps("Double", m, v, sum(m), m .* m, v .* v); + +m = ["A" "D"; "B" "E"; "C" "F"]; +v = ["A" "B" "C" "D" "E" "F"]; +test_matrix_typemaps("CharPtr", m, v, strcat(m), m + m, v + v); + +m = [%T %F; %F %T; %T %F]; +v = [%T %F %T %F %T %F]; +test_matrix_typemaps("Bool", m, v, %T, ~m, ~v); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/scilab_multivalue_runme.sci b/Examples/test-suite/scilab/scilab_multivalue_runme.sci new file mode 100644 index 00000000000..581890408fb --- /dev/null +++ b/Examples/test-suite/scilab/scilab_multivalue_runme.sci @@ -0,0 +1,87 @@ +exec("swigtest.start", -1); + +// OUTPUT + +[a, b] = output2(); +checkequal(a, 1, "[a, b] = output2(): a"); +checkequal(b, 2, "[a, b] = output2(): b"); + +[ret, a, b] = output2Ret(); +checkequal(ret, 3, "[a, b] = output2Ret(): b"); +checkequal(a, 1, "[a, b] = output2Ret(): a"); +checkequal(b, 2, "[a, b] = output2Ret(): b"); + +[c, d] = output2Input2(1, 2); +checkequal(c, 2, "[c, d] = output2Input2(1, 2): c"); +checkequal(d, 4, "[c, d] = output2Input2(1, 2): d"); + +[ret, c, d] = output2Input2Ret(1, 2); +checkequal(ret, 6, "[ret, c, d] = output2Input2Ret(1, 2): ret"); +checkequal(c, 2, "[ret, c, d] = output2Input2Ret(1, 2): c"); +checkequal(d, 4, "[ret, c, d = output2Input2Ret(1, 2): d"); + +[ret, a, b, c] = output3Input1Ret(10); +checkequal(ret, 10, "[ret, a, b, c] = output3Input1Ret(10): ret"); +checkequal(a, 11, "[ret, a, b, c] = output3Input1Ret(10): a"); +checkequal(b, 12, "[ret, a, b, c] = output3Input1Ret(10): b"); +checkequal(c, 13, "[ret, a, b, c] = output3Input1Ret(10): c"); + +[ret, a, b, c] = output3Input3Ret(10, 20, 30); +checkequal(ret, 66, "[ret, a, b, c] = output3Input1Ret(10, 20, 30): ret"); +checkequal(a, 11, "[ret, a, b, c] = output3Input1Ret(10, 20, 30): a"); +checkequal(b, 22, "[ret, a, b, c] = output3Input1Ret(10, 20, 30): b"); +checkequal(c, 33, "[ret, a, b, c] = output3Input1Ret(10, 20, 30): c"); + + +// INOUT + +[a, b] = inout2(1, 2); +checkequal(a, 2, "[a, b] = output2(1, 2): a"); +checkequal(b, 4, "[a, b] = output2(1, 2): b"); + +[ret, a, b] = inout2Ret(1, 2); +checkequal(ret, 6, "[a, b] = inout2Ret(1, 2): b"); +checkequal(a, 2, "[a, b] = inout2Ret(1, 2): a"); +checkequal(b, 4, "[a, b] = inout2Ret(1, 2): b"); + +[c, d] = inout2Input2(1, 2, 1, 1); +checkequal(c, 2, "[c, d] = inout2Input2(1, 2): c"); +checkequal(d, 3, "[c, d] = inout2Input2(1, 2): d"); + +[ret, c, d] = inout2Input2Ret(1, 2, 1, 1); +checkequal(ret, 5, "[c, d] = inout2Input2Ret(1, 2): ret"); +checkequal(c, 2, "[c, d] = inout2Input2Ret(1, 2): c"); +checkequal(d, 3, "[c, d] = inout2Input2Ret(1, 4): d"); + +[ret, a, b, c] = inout3Input1Ret(10, 1, 2, 3); +checkequal(ret, 10, "[ret, a, b, c] = output3Input1Ret(ret, 1, 2, 3): ret"); +checkequal(a, 11, "[ret, a, b, c] = output3Input1Ret(ret, 1, 2, 3): a"); +checkequal(b, 12, "[ret, a, b, c] = output3Input1Ret(ret, 1, 2, 3): b"); +checkequal(c, 13, "[ret, a, b, c] = output3Input1Ret(ret, 1, 2, 3): c"); + +[ret, a, b, c] = inout3Input3Ret(10, 1, 20, 2, 30, 3); +checkequal(ret, 66, "[ret, a, b, c] = output3Input1Ret(10, 20, 30): ret"); +checkequal(a, 11, "[ret, a, b, c] = inout3Input1Ret(10, 1, 20, 2, 30, 3): a"); +checkequal(b, 22, "[ret, a, b, c] = inout3Input1Ret(10, 1, 20, 2, 30, 3): b"); +checkequal(c, 33, "[ret, a, b, c] = inout3Input1Ret(10, 1, 20, 2, 30, 3): c"); + + +// CLASS + +a = new_ClassA(); + +[ret, c, d] = ClassA_output2Input2Ret(a, 1, 2); +checkequal(ret, 6, "[ret, c, d] = ClassA_output2Input2Ret(a, 1, 2): ret"); +checkequal(c, 2, "[c, d] = ClassA_output2Input2Ret(a, 1, 2): c"); +checkequal(d, 4, "[c, d] = ClassA_output2Input2Ret(a, 1, 2): d"); + +[ret, c, d] = ClassA_inout2Input2Ret(a, 1, 2, 1, 1); +checkequal(ret, 5, "[ret, c, d] = ClassA_inout2Input2Ret(a, 1, 2): ret"); +checkequal(c, 2, "[c, d] = ClassA_inout2Input2(a, 1, 2): c"); +checkequal(d, 3, "[c, d] = ClassA_inout2Input2(a, 1, 2): d"); + +delete_ClassA(a); + + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/scilab_pointer_conversion_functions_runme.sci b/Examples/test-suite/scilab/scilab_pointer_conversion_functions_runme.sci new file mode 100644 index 00000000000..d24f60eb906 --- /dev/null +++ b/Examples/test-suite/scilab/scilab_pointer_conversion_functions_runme.sci @@ -0,0 +1,18 @@ +exec("swigtest.start", -1); + +// Test on NULL +null = getNull(); +checkequal(SWIG_this(null), 0, "SWIG_this(null)"); + +null = SWIG_ptr(0); +checkequal(isNull(null), %T, "func(null)"); + +// Test on variable +expected_foo_addr = getFooAddress(); +foo_addr = SWIG_this(pfoo_get()); +checkequal(foo_addr, expected_foo_addr, "SWIG_this(pfoo_get())"); + +pfoo = SWIG_ptr(foo_addr); +checkequal(equalFooPointer(pfoo), %T, "equalFooPointer(pfoo)"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/simple_array_runme.sci b/Examples/test-suite/scilab/simple_array_runme.sci new file mode 100644 index 00000000000..8ff1a3a57d6 --- /dev/null +++ b/Examples/test-suite/scilab/simple_array_runme.sci @@ -0,0 +1,12 @@ +exec("swigtest.start", -1); + +try + initArray(); +catch + swigtesterror(); +end + +if x_get() <> int32([0,1,2,3,4,5,6,7,8,9]) then swigtesterror(); end +if y_get() <> [0/7,1/7,2/7,3/7,4/7,5/7,6/7] then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/sizet_runme.sci b/Examples/test-suite/scilab/sizet_runme.sci new file mode 100644 index 00000000000..11702497327 --- /dev/null +++ b/Examples/test-suite/scilab/sizet_runme.sci @@ -0,0 +1,11 @@ +exec("swigtest.start", -1); + +s = 2000; +s = test1(s+1); +s = test2(s+1); +s = test3(s+1); +s = test4(s+1); +if s <> 2004 then swigtesterror(); end + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/smart_pointer_simple_runme.sci b/Examples/test-suite/scilab/smart_pointer_simple_runme.sci new file mode 100644 index 00000000000..7ab9085fe42 --- /dev/null +++ b/Examples/test-suite/scilab/smart_pointer_simple_runme.sci @@ -0,0 +1,13 @@ +exec("swigtest.start", -1); + +f = new_Foo(); +b = new_Bar(f); + +Bar_x_set(b, 3); +if Bar_x_get(b) <> 3 then swigtesterror(); end + +fp = Bar___deref__(b); +Bar_x_set(b, 4); +if Bar_x_get(b) <> 4 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/sneaky1_runme.sci b/Examples/test-suite/scilab/sneaky1_runme.sci new file mode 100644 index 00000000000..5d9e24407e6 --- /dev/null +++ b/Examples/test-suite/scilab/sneaky1_runme.sci @@ -0,0 +1,31 @@ +exec("swigtest.start", -1); + +try + x = add(3, 4); +catch + swigtesterror(); +end +if x <> 7 then swigtesterror(); end + +try + y = subtract(3,4); +catch + swigtesterror(); +end +if y <> -1 then swigtesterror(); end + +try + z = mul(3,4); +catch + swigtesterror(); +end +if z <> 12 then swigtesterror(); end + +try + w = divide(3,4); +catch + swigtesterror(); +end +if w <> 0 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/struct_initialization_runme.sci b/Examples/test-suite/scilab/struct_initialization_runme.sci new file mode 100644 index 00000000000..fcdb3fcccc5 --- /dev/null +++ b/Examples/test-suite/scilab/struct_initialization_runme.sci @@ -0,0 +1,15 @@ +exec("swigtest.start", -1); + +if StructC_x_get(instanceC1_get()) <> 10 then swigtesterror(); end + +if StructD_x_get(instanceD1_get()) <> 10 then swigtesterror(); end + +if StructD_x_get(instanceD2_get()) <> 20 then swigtesterror(); end + +if StructD_x_get(instanceD3_get()) <> 30 then swigtesterror(); end + +if StructE_x_get(instanceE1_get()) <> 1 then swigtesterror(); end + +if StructF_x_get(instanceF1_get()) <> 1 then swigtesterror(); end + +exec("swigtest.quit", -1); \ No newline at end of file diff --git a/Examples/test-suite/scilab/struct_rename_runme.sci b/Examples/test-suite/scilab/struct_rename_runme.sci new file mode 100644 index 00000000000..2737d446e1b --- /dev/null +++ b/Examples/test-suite/scilab/struct_rename_runme.sci @@ -0,0 +1,11 @@ +exec("swigtest.start", -1); + +try + a = new_Bar(); + Bar_x_set(a,100); +catch + swigtesterror(); +end +if Bar_x_get(a) <> 100 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/struct_value_runme.sci b/Examples/test-suite/scilab/struct_value_runme.sci new file mode 100644 index 00000000000..b00970ef905 --- /dev/null +++ b/Examples/test-suite/scilab/struct_value_runme.sci @@ -0,0 +1,16 @@ +exec("swigtest.start", -1); + +foo = new_Foo(); +Foo_x_set(foo, 1); +if Foo_x_get(foo) <> 1 then swigtesterror(); end + +bar = new_Bar(); +Bar_a_set(bar, foo); +a = Bar_a_get(bar); +if Foo_x_get(a) <> 1 then swigtesterror(); end + +Bar_b_set(bar, foo); +b = Bar_b_get(bar); +if Foo_x_get(b) <> 1 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/swigtest.quit b/Examples/test-suite/scilab/swigtest.quit new file mode 100644 index 00000000000..307077da11f --- /dev/null +++ b/Examples/test-suite/scilab/swigtest.quit @@ -0,0 +1,2 @@ +// Exit from Scilab +exit diff --git a/Examples/test-suite/scilab/swigtest.start b/Examples/test-suite/scilab/swigtest.start new file mode 100644 index 00000000000..e4347bd90ae --- /dev/null +++ b/Examples/test-suite/scilab/swigtest.start @@ -0,0 +1,57 @@ +lines(0); +warning('off'); +ilib_verbose(0); + +// Get test name (used in swigtest.quit file) +[units, typ, names] = file(1); +swigtestname = strsubst(fileparts(names, "fname"), "_runme", ""); + +// Does the library exists? If not then exit! +libname = "lib" + swigtestname + getdynlibext(); +if ~isfile(libname) then + mfprintf(0, "*** LIBRARY NOT FOUND: %s ***\n", libname); + exit(1) +end + +// Load library +try + exec("loader.sce", -1); +catch + mfprintf(0, "*** LOADER EXECUTION FAILED ***\n"); + exit(1) +end + +// Module initialization +try + moduleInit = sprintf("%s_Init()", swigtestname); + execstr(moduleInit); +catch + mfprintf(0, "*** MODULE INIT FAILED ***\n"); + exit(1) +end + +// Error management function +function swigtesterror(msg) + [lines, names] = where(); + if size(lines, '*') > 0 + mfprintf(0, "*** TEST FAILED (at line %d) ***\n", lines($)); + if argn(2) >= 1 then disp(msg); end + else + mfprintf(0, "*** TEST FAILED ***\n"); + end; + exit(1) +endfunction + +// Check equal function +function checkequal(returned, expected, message) + if typeof(returned) <> typeof(expected) then + returned_type_msg = ["returned type:"; typeof(returned)]; + expected_type_msg = ["expected type:"; typeof(expected)]; + swigtesterror([message; returned_type_msg; expected_type_msg]); + end + if ~isequal(returned, expected) then + returned_value_msg = ["returned value:"; string(returned)]; + expected_value_msg = ["expected value:"; string(expected)]; + swigtesterror([message; returned_value_msg; expected_value_msg]); + end +endfunction diff --git a/Examples/test-suite/scilab/template_classes_runme.sci b/Examples/test-suite/scilab/template_classes_runme.sci new file mode 100644 index 00000000000..b4b3a2c5394 --- /dev/null +++ b/Examples/test-suite/scilab/template_classes_runme.sci @@ -0,0 +1,8 @@ +exec("swigtest.start", -1); + +ri = new_RectangleInt(); +pi = RectangleInt_getPoint(ri); +x = PointInt_getX(pi); +delete_RectangleInt(ri); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/template_ns_runme.sci b/Examples/test-suite/scilab/template_ns_runme.sci new file mode 100644 index 00000000000..aea784114c8 --- /dev/null +++ b/Examples/test-suite/scilab/template_ns_runme.sci @@ -0,0 +1,15 @@ +exec("swigtest.start", -1); + +p1 = new_pairii(2, 3); +p2 = new_pairii(p1); + +checkequal(pairii_first_get(p2), 2, "pairii_first(p2) test fails."); +checkequal(pairii_second_get(p2), 3, "pairii_second(p2) test fails."); + +p3 = new_pairdd(0.5, 2.5); +p4 = new_pairdd(p3); + +checkequal(pairdd_first_get(p4), 0.5, "pairdd_first(p4) test fails."); +checkequal(pairdd_second_get(p4), 2.5, "pairdd_second(p4) test fails."); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/template_rename_runme.sci b/Examples/test-suite/scilab/template_rename_runme.sci new file mode 100644 index 00000000000..9c9512930a8 --- /dev/null +++ b/Examples/test-suite/scilab/template_rename_runme.sci @@ -0,0 +1,15 @@ +exec("swigtest.start", -1); + +i = new_iFoo(); +checkequal(iFoo_blah_test(i, 4), 4, "iFoo_blah_test(i, 4) test fails"); +checkequal(iFoo_spam_test(i, 5), 5, "iFoo_spam_test(i, 5) test fails"); +checkequal(iFoo_groki_test(i, 6), 6, "iFoo_groki_test(i, 6) test fails"); +delete_iFoo(i); + +d = new_iFoo(); +checkequal(dFoo_blah_test(d, 4), 4, "dFoo_blah_test(d, 4) test fails"); +checkequal(dFoo_spam(d, 5), 5, "dFoo_spam_test(d, 5) test fails"); +checkequal(dFoo_grok_test(d, 6), 6, "dFoo_groki_test(d, 6) test fails"); +delete_dFoo(d); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/template_static_runme.sci b/Examples/test-suite/scilab/template_static_runme.sci new file mode 100644 index 00000000000..e17c461430a --- /dev/null +++ b/Examples/test-suite/scilab/template_static_runme.sci @@ -0,0 +1,8 @@ +exec("swigtest.start", -1); + +checkequal(foo_i_test_get(), 0, "foo_i_test_get() test fails."); +checkequal(foo_d_test_get(), 0, "foo_i_test_get() test fails."); + +checkequal(Foo_bar_double(0), 1, "Foo_bar_double() test fails"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/throw_exception_runme.sci b/Examples/test-suite/scilab/throw_exception_runme.sci new file mode 100644 index 00000000000..2eada4be2e5 --- /dev/null +++ b/Examples/test-suite/scilab/throw_exception_runme.sci @@ -0,0 +1,23 @@ +exec("swigtest.start", -1); + +function checkException(cmd, expected_error_msg) + ierr = execstr(cmd, 'errcatch'); + checkequal(ierr, 20000, cmd + ': ierr'); + checkequal(lasterror(), 'SWIG/Scilab: ' + expected_error_msg, cmd + ': msg'); +endfunction + +foo = new_Foo(); + +checkException('Foo_test_int(foo)', 'Exception (int) occured: 37'); + +checkException('Foo_test_msg(foo)', 'Exception (char const *) occured: Dead'); + +checkException('Foo_test_multi(foo, 1)', 'Exception (int) occured: 37'); + +checkException('Foo_test_multi(foo, 2)', 'Exception (char const *) occured: Dead'); + +checkException('Foo_test_cls(foo)', 'Exception (CError) occured.'); + +delete_Foo(foo); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/typedef_struct_cpp_runme.sci b/Examples/test-suite/scilab/typedef_struct_cpp_runme.sci new file mode 100644 index 00000000000..e41c21629e4 --- /dev/null +++ b/Examples/test-suite/scilab/typedef_struct_cpp_runme.sci @@ -0,0 +1,29 @@ +exec("swigtest.start", -1); + +try + x = new_LineObj(); + LineObj_numpoints_set(x, 100); +catch + swigtesterror(); +end +if LineObj_numpoints_get(x) <> 100 then swigtesterror(); end + +if MS_NOOVERRIDE_get() <> -1111 then swigtesterror(); end + +try + y = make_a(); + A_t_a_set(y, 200); +catch + swigtesterror(); +end +if A_t_a_get(y) <> 200 then swigtesterror(); end + +try + A_t_b_set(y, 300); +catch + swigtesterror(); +end +if A_t_b_get(y) <> 300 then swigtesterror(); end + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/typedef_struct_runme.sci b/Examples/test-suite/scilab/typedef_struct_runme.sci new file mode 100644 index 00000000000..e41c21629e4 --- /dev/null +++ b/Examples/test-suite/scilab/typedef_struct_runme.sci @@ -0,0 +1,29 @@ +exec("swigtest.start", -1); + +try + x = new_LineObj(); + LineObj_numpoints_set(x, 100); +catch + swigtesterror(); +end +if LineObj_numpoints_get(x) <> 100 then swigtesterror(); end + +if MS_NOOVERRIDE_get() <> -1111 then swigtesterror(); end + +try + y = make_a(); + A_t_a_set(y, 200); +catch + swigtesterror(); +end +if A_t_a_get(y) <> 200 then swigtesterror(); end + +try + A_t_b_set(y, 300); +catch + swigtesterror(); +end +if A_t_b_get(y) <> 300 then swigtesterror(); end + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab/union_parameter_runme.sci b/Examples/test-suite/scilab/union_parameter_runme.sci new file mode 100644 index 00000000000..2918856d914 --- /dev/null +++ b/Examples/test-suite/scilab/union_parameter_runme.sci @@ -0,0 +1,35 @@ +// Some lines are commented out because of too long identifiers... + +exec("swigtest.start", -1); + +event = new_SDL_Event(); + +for i=1:2 + evAvailable = SDL_PollEvent(event); + evType = SDL_Event_type_get(event); + + if evType==1 then + specEvent = SDL_Event_active_get(event); + _type = SDL_ActiveEvent_type_get(specEvent); + + if _type <> evType then swigtesterror(); end + + gain = SDL_ActiveEvent_gain_get(specEvent); + //state = SDL_ActiveEvent_state_get(specEvent); + end + + if evType==2 then + specEvent = SDL_Event_key_get(event); + //_type = SDL_KeyboardEvent_type_get(specEvent); + + //if _type <> evType then swigtesterror(); end + + //_which = SDL_KeyboardEvent_which_get(specEvent); + //state = SDL_KeyboardEvent_state_get(specEvent); + end + +end + +delete_SDL_Event(event); + +exec("swigtest.quit", -1); \ No newline at end of file diff --git a/Examples/test-suite/scilab/unions_runme.sci b/Examples/test-suite/scilab/unions_runme.sci new file mode 100644 index 00000000000..c8c6a944441 --- /dev/null +++ b/Examples/test-suite/scilab/unions_runme.sci @@ -0,0 +1,23 @@ +exec("swigtest.start", -1); + +try + small = new_SmallStruct(); + SmallStruct_jill_set(small, 200); + + big = new_BigStruct(); + BigStruct_jack_set(big, 300); + + Jill = SmallStruct_jill_get(small); +catch + swigtesterror(); +end +if Jill <> 200 then swigtesterror(); end + +try + Jack = BigStruct_jack_get(big); +catch + swigtesterror(); +end +if Jack <> 300 then swigtesterror(); end + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/varargs_overload_runme.sci b/Examples/test-suite/scilab/varargs_overload_runme.sci new file mode 100644 index 00000000000..7603b667c50 --- /dev/null +++ b/Examples/test-suite/scilab/varargs_overload_runme.sci @@ -0,0 +1,21 @@ +exec("swigtest.start", -1); + +checkequal(vararg_over1("Hello"), "Hello", "vararg_over1(""Hello"")"); + +checkequal(vararg_over1(2), "2", "vararg_over1(2)"); + +checkequal(vararg_over2("Hello"), "Hello", "vararg_over1(""Hello"")"); + +checkequal(vararg_over2(2, 2.2), "2 2.2", "vararg_over2(2, 2.2)") + +checkequal(vararg_over3("Hello"), "Hello", "vararg_over3(""Hello"")"); + +checkequal(vararg_over3(2, 2.2, "hey"), "2 2.2 hey", "vararg_over3(2, 2.2, ""hey"")"); + +checkequal(vararg_over4("Hello"), "Hello", "vararg_over4(""Hello"")"); + +checkequal(vararg_over4(123), "123", "vararg_over4(123)"); + +checkequal(vararg_over4("Hello", 123), "Hello", "vararg_over4(""Hello"", 123)"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/varargs_runme.sci b/Examples/test-suite/scilab/varargs_runme.sci new file mode 100644 index 00000000000..333838c0086 --- /dev/null +++ b/Examples/test-suite/scilab/varargs_runme.sci @@ -0,0 +1,17 @@ +exec("swigtest.start", -1); + +checkequal(test("Hello"), "Hello", "test(""Hello"")"); + +f = new_Foo("Greetings"); +checkequal(Foo_str_get(f), "Greetings", "new_Foo(""Greetings"")"); + +checkequal(Foo_test(f, "Hello"), "Hello", "Foo_test(f)"); +delete_Foo(f); + +checkequal(Foo_statictest("Hello", 1), "Hello", "Foo_statictest(""Hello"", 1)"); + +checkequal(test_def("Hello", 1), "Hello", "test_def(""Hello"", 1)"); + +checkequal(test_def("Hello"), "Hello", "test_def(""Hello"")"); + +exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab/voidtest_runme.sci b/Examples/test-suite/scilab/voidtest_runme.sci new file mode 100644 index 00000000000..395e8f6302e --- /dev/null +++ b/Examples/test-suite/scilab/voidtest_runme.sci @@ -0,0 +1,22 @@ +exec("swigtest.start", -1); + +globalfunc(); + +f = new_Foo(); +Foo_memberfunc(f); + +Foo_staticmemberfunc(); + +v1 = vfunc1(f); +checkequal(SWIG_this(v1), SWIG_this(f), "vfunc1(f) <> f"); + +v2 = vfunc2(f); +checkequal(SWIG_this(v2), SWIG_this(f), "vfunc2(f) <> f"); + +v3 = vfunc3(v1); +checkequal(SWIG_this(v3), SWIG_this(f), "vfunc3(f) <> f"); + +Foo_memberfunc(v3); + +exec("swigtest.quit", -1); + diff --git a/Examples/test-suite/scilab_consts.i b/Examples/test-suite/scilab_consts.i new file mode 100644 index 00000000000..11f2504b7c7 --- /dev/null +++ b/Examples/test-suite/scilab_consts.i @@ -0,0 +1,52 @@ +%module scilab_consts + +/* Default mode: constants are wrapped as getter functions */ +%scilabconst(0); + +#define ICONST0 42 +#define FCONST0 2.1828 +#define CCONST0 'x' +#define CCONST0_2 '\n' +#define SCONST0 "Hello World" +#define SCONST0_2 "\"Hello World\"" + +/* Constants with type */ +#define UNSIGNED0 0x5FFFU +#define LONG0 0x3FFF0000L +#define ULONG0 0x5FF0000UL + +/* Expressions should work too */ +#define EXPR0 ICONST0 + 3*FCONST0 + +/* This shouldn't do anything, bar is not defined */ +#define BAR0 bar + +/* SWIG directive %constant produces constants too */ +%constant int iconst0 = 37; +%constant double fconst0 = 42.2; + + +/* Alternative mode: constants are wrapped as variables */ +%scilabconst(1); + +#define ICONST1 42 +#define FCONST1 2.1828 +#define CCONST1 'x' +#define CCONST1_2 '\n' +#define SCONST1 "Hello World" +#define SCONST1_2 "\"Hello World\"" + +/* Constants with type */ +#define UNSIGNED1 0x5FFFU +#define LONG1 0x3FFF0000L +#define ULONG1 0x5FF0000UL + +/* Expressions should work too */ +#define EXPR1 ICONST1 + 3*FCONST1 + +/* This shouldn't do anything, bar is not defined */ +#define BAR1 bar + +/* SWIG directive %constant produces constants too */ +%constant int iconst1 = 37; +%constant double fconst1 = 42.2; diff --git a/Examples/test-suite/scilab_enums.i b/Examples/test-suite/scilab_enums.i new file mode 100644 index 00000000000..32d5a34deec --- /dev/null +++ b/Examples/test-suite/scilab_enums.i @@ -0,0 +1,38 @@ +%module scilab_enums + +%scilabconst(1); + +%inline %{ + +enum ENUM { + ENUM_1, + ENUM_2 +}; + +enum ENUM_EXPLICIT_1 { + ENUM_EXPLICIT_1_1 = 5, + ENUM_EXPLICIT_1_2 +}; + +enum ENUM_EXPLICIT_2 { + ENUM_EXPLICIT_2_1, + ENUM_EXPLICIT_2_2 = 10 +}; + +enum ENUM_EXPLICIT_3 { + ENUM_EXPLICIT_3_1 = 2, + ENUM_EXPLICIT_3_2 = 5, + ENUM_EXPLICIT_3_3 = 8 +}; + +typedef enum { + TYPEDEF_ENUM_1_1 = 21, + TYPEDEF_ENUM_1_2 = 22 +} TYPEDEF_ENUM_1; + +typedef enum TYPEDEF_ENUM_2 { + TYPEDEF_ENUM_2_1 = 31, + TYPEDEF_ENUM_2_2 = 32 +} TYPEDEF_ENUM_2; + +%} diff --git a/Examples/test-suite/scilab_identifier_name.i b/Examples/test-suite/scilab_identifier_name.i new file mode 100644 index 00000000000..94dde47e0b3 --- /dev/null +++ b/Examples/test-suite/scilab_identifier_name.i @@ -0,0 +1,53 @@ +%module scilab_identifier_name + +// +// Test long identifier name (> 24 characters) truncating +// + +// Test truncating variables, constants, functions identifier names + +%inline %{ +// these identifier names wont be truncated +int gvar_identifier_name = -1; +#define CONS_IDENTIFIER_NAME -11 +int function_identifier_name() { return -21; }; + +// these identifier names will be truncated +int too_long_gvar_identifier_name_1 = 1; +int too_long_gvar_identifier_name_2 = 2; + +#define TOO_LONG_CONST_IDENTIFIER_NAME_1 11 + +int too_long_function_identifier_name_1() { return 21; }; +%} + +// Test truncating when %scilabconst mode is activated +%scilabconst(1); + +%inline %{ +#define SC_CONST_IDENTIFIER_NAME -12; + +#define SC_TOO_LONG_CONST_IDENTIFIER_NAME_1 13 +#define SC_TOO_LONG_CONST_IDENTIFIER_NAME_2 14 +%} +%scilabconst(0); + +// Test truncating in the case of struct +%inline %{ +struct st { + int m_identifier_name; + int too_long_member_identifier_name; +}; + +%} + + + + + + + + + + + diff --git a/Examples/test-suite/scilab_li_matrix.i b/Examples/test-suite/scilab_li_matrix.i new file mode 100644 index 00000000000..ae5ad76bb8b --- /dev/null +++ b/Examples/test-suite/scilab_li_matrix.i @@ -0,0 +1,161 @@ +%module scilab_li_matrix + +%include "matrix.i" + +%define %use_matrix_apply(TYPE...) +%apply (TYPE *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (TYPE *matrix, int nbRow, int nbCol) } +%apply (TYPE **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (TYPE **matrixRes, int *nbRowRes, int *nbColRes) } +%apply (TYPE *IN, int IN_SIZE) { (TYPE *matrix, int size) } +%apply (TYPE **OUT, int *OUT_SIZE) { (TYPE **matrixRes, int *sizeRes) } +%enddef + +%use_matrix_apply(int); +%use_matrix_apply(double); +%use_matrix_apply(char *); +%use_matrix_apply(bool); + +%inline %{ + +/* + * (T *matrixIn, int matrixInSize) pattern functions + */ + +template T inMatrixSize(T *matrix, int size) { + T sum = 0; + int i; + for (i = 0; i < size; i++) + sum += matrix[i]; + return sum; +} + +template void outMatrixSize(T **matrixRes, int *sizeRes) { + int size; + int i; + *sizeRes = 6; + *matrixRes = (T*) malloc(*sizeRes * sizeof(T)); + for (i = 0; i < *sizeRes; i++) + (*matrixRes)[i] = i; +} + +template void inoutMatrixSize(T *matrix, int size, T **matrixRes, int *sizeRes) { + int i; + *sizeRes = size; + *matrixRes = (T*) malloc(size * sizeof(T)); + for (i = 0; i < size; i++) { + (*matrixRes)[i] = matrix[i] * matrix[i]; + } +} + +/* + * (char **matrixIn, int matrixInSize) pattern functions + */ + +template<> char* inMatrixSize(char **matrix, int size) { + char *s = (char *) calloc(size + 1, sizeof(char)); + int i; + for (i = 0; i < size; i++) + strcat(s, matrix[i]); + return s; +} + +template<> void outMatrixSize(char ***matrixRes, int *sizeRes) { + char *s; + int i; + *sizeRes = 6; + *matrixRes = (char **) malloc(*sizeRes * sizeof(char *)); + for (i = 0; i < *sizeRes; i++) { + s = (char *) malloc(sizeof(char)+1); + sprintf(s, "%c", char(65 + i)); + (*matrixRes)[i] = s; + } +} + +template<> void inoutMatrixSize(char **matrix, int size, + char ***matrixRes, int *sizeRes) { + int i; + char *s; + *sizeRes = size; + *matrixRes = (char **) malloc(*sizeRes * sizeof(char* )); + for (i = 0; i < *sizeRes; i++) { + s = (char *) malloc((2 * strlen(matrix[i]) + 1) * sizeof(char)); + sprintf(s, "%s%s", matrix[i], matrix[i]); + (*matrixRes)[i] = s; + } +} + +/* + * (bool **matrixIn, int matrixInSize) pattern functions + */ + +template<> bool inMatrixSize(bool *matrix, int size) { + bool b = true; + int i; + b = matrix[0]; + for (i = 1; i < size; i++) + b = b ^ matrix[i]; + return b; +} + +template<> void outMatrixSize(bool **matrixRes, int *sizeRes) { + int i; + *sizeRes = 6; + *matrixRes = (bool*) malloc(*sizeRes * sizeof(bool)); + for (i = 0; i < *sizeRes; i++) { + (*matrixRes)[i] = i % 2 == 0; + } +} + +template<> void inoutMatrixSize(bool *matrix, int size, + bool **matrixRes, int *sizeRes) { + int i; + *sizeRes = size; + *matrixRes = (bool*) malloc(*sizeRes * sizeof(bool)); + for (i = 0; i < *sizeRes; i++) { + (*matrixRes)[i] = matrix[i] == 1 ? 0 : 1; + } +} + +/* + * (T *matrixIn, int matrixInRowCount, int matrixInColCount) pattern functions + */ + +template T inMatrixDims(T *matrix, int nbRow, int nbCol) { + return inMatrixSize(matrix, nbRow * nbCol); +} + +template void outMatrixDims(T **matrixRes, int *nbRowRes, int *nbColRes) { + int size = 0; + outMatrixSize(matrixRes, &size); + *nbRowRes = 3; + *nbColRes = 2; +} + +template void inoutMatrixDims(T *matrix, int nbRow, int nbCol, + T **matrixRes, int *nbRowRes, int *nbColRes) { + *nbRowRes = nbRow; + *nbColRes = nbCol; + int sizeRes = 0; + inoutMatrixSize(matrix, nbRow * nbCol, matrixRes, &sizeRes); +} + +%} + +%define %instantiate_matrix_template_functions(NAME, TYPE...) +%template(in ## NAME ## MatrixDims) inMatrixDims; +%template(out ## NAME ## MatrixDims) outMatrixDims; +%template(inout ## NAME ## MatrixDims) inoutMatrixDims; +%template(in ## NAME ## MatrixSize) inMatrixSize; +%template(out ## NAME ## MatrixSize) outMatrixSize; +%template(inout ## NAME ## MatrixSize) inoutMatrixSize; +%enddef + +%instantiate_matrix_template_functions(Int, int); +%instantiate_matrix_template_functions(Double, double); +%instantiate_matrix_template_functions(CharPtr, char *); +%instantiate_matrix_template_functions(Bool, bool); + + + + + + diff --git a/Examples/test-suite/scilab_multivalue.i b/Examples/test-suite/scilab_multivalue.i new file mode 100644 index 00000000000..3165d48e1cd --- /dev/null +++ b/Examples/test-suite/scilab_multivalue.i @@ -0,0 +1,123 @@ +%module scilab_multivalue + + + +void output2(int *OUTPUT, int *OUTPUT); +int output2Ret(int *OUTPUT, int *OUTPUT); +void output2Input2(int a, int b, int *OUTPUT, int *OUTPUT); +int output2Input2Ret(int a, int b, int *OUTPUT, int *OUTPUT); +int output3Input1Ret(int a, int *OUTPUT, int *OUTPUT, int *OUTPUT); +int output3Input3Ret(int x, int *OUTPUT, int y, int *OUTPUT, int z, int *OUTPUT); + +void inout2(int *INOUT, int *INOUT); +int inout2Ret(int *INOUT, int *INOUT); +void inout2Input2(int a, int b, int *INOUT, int *INOUT); +int inout2Input2Ret(int a, int b, int *INOUT, int *INOUT); +int inout3Input1Ret(int a, int *INOUT, int *INOUT, int *INOUT); +int inout3Input3Ret(int x, int *INOUT, int y, int *INOUT, int z, int *INOUT); + +class ClassA { +public: + ClassA() {}; + int output2Input2Ret(int a, int b, int *OUTPUT, int *OUTPUT); + int inout2Input2Ret(int a, int b, int *INOUT, int *INOUT); +}; + +%{ + +// Test return of multiple values with OUTPUT + +void output2(int *a, int *b) { + *a = 1; + *b = 2; +} + +int output2Ret(int *a, int *b) { + *a = 1; + *b = 2; + return *a + *b; +} + +void output2Input2(int a, int b, int *c, int *d) { + *c = a + 1; + *d = b + 2; +} + +int output2Input2Ret(int a, int b, int *c, int *d) { + *c = a + 1; + *d = b + 2; + return *c + *d; +} + +int output3Input1Ret(int x, int *a, int *b, int *c) { + *a = x + 1; + *b = x + 2; + *c = x + 3; + return x; +} + +int output3Input3Ret(int x, int *a, int y, int *b, int z, int *c) { + *a = x + 1; + *b = y + 2; + *c = z + 3; + return *a + *b + *c; +} + + +// Test return of multiple values with INOUT + +void inout2(int *a, int *b) { + *a = *a + 1; + *b = *a + 2; +} + +int inout2Ret(int *a, int *b) { + *a = *a + 1; + *b = *a + 2; + return *a + *b; +} + +void inout2Input2(int a, int b, int *c, int *d) { + *c = *c + a; + *d = *d + b; +} + +int inout2Input2Ret(int a, int b, int *c, int *d) { + *c = *c + a; + *d = *d + b; + return *c + *d; +} + +int inout3Input1Ret(int x, int *a, int *b, int *c) { + *a = *a + x; + *b = *b + x; + *c = *c + x; + return x; +} + +int inout3Input3Ret(int x, int *a, int y, int *b, int z, int *c) { + *a = *a + x; + *b = *b + y; + *c = *c + z; + return *a + *b + *c; +} + +// Test return multiples from class methods + +class ClassA { +public: + ClassA() {}; + int output2Input2Ret(int a, int b, int *c, int *d) { + *c = a + 1; + *d = b + 2; + return *c + *d; + } + int inout2Input2Ret(int a, int b, int *c, int *d) { + *c = *c + a; + *d = *d + b; + return *c + *d; + } +}; + + +%} diff --git a/Examples/test-suite/scilab_pointer_conversion_functions.i b/Examples/test-suite/scilab_pointer_conversion_functions.i new file mode 100644 index 00000000000..5e29926c116 --- /dev/null +++ b/Examples/test-suite/scilab_pointer_conversion_functions.i @@ -0,0 +1,18 @@ +%module scilab_pointer_conversion_functions + +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) pfoo; /* Setting a pointer/reference variable may leak memory. */ + +%inline %{ + +void* getNull() { return NULL; } +bool isNull(void *p) { return p == NULL; } + +int foo = 3; +int *pfoo = &foo; + +double getFooAddress() { return (double) (unsigned long) pfoo; } +bool equalFooPointer(void *p) { return p == pfoo; } + +%} + + diff --git a/Examples/test-suite/sizeof_pointer.i b/Examples/test-suite/sizeof_pointer.i index 993ba4de5d5..aa6cfcd5c42 100644 --- a/Examples/test-suite/sizeof_pointer.i +++ b/Examples/test-suite/sizeof_pointer.i @@ -4,16 +4,17 @@ This testcase tests whether the sizeof operator on a pointer is working. %module sizeof_pointer + %inline %{ #define NO_PROBLEM sizeof(char) #define STAR_PROBLEM sizeof(char*) #define STAR_STAR_PROBLEM sizeof(char**) -typedef struct SizeofPointerTest { +typedef struct SizePtrTst { unsigned char array1[NO_PROBLEM]; unsigned char array2[STAR_PROBLEM]; unsigned char array3[STAR_STAR_PROBLEM]; -} SizeofPointerTest; +} SizePtrTst; %} diff --git a/Examples/test-suite/special_variable_attributes.i b/Examples/test-suite/special_variable_attributes.i new file mode 100644 index 00000000000..973a09344de --- /dev/null +++ b/Examples/test-suite/special_variable_attributes.i @@ -0,0 +1,170 @@ +%module special_variable_attributes + +// Special variable expansion and special variable macros, aka embedded typemaps - expansion tests +// Tests these are expanded within typemap attributes. +// Also tests that these are expanded when used together, so that the special variables +// can be used as the type passed to the special variable macro. +// C# is used for testing as it is one of the few languages that uses a lot of typemap attributes. +// Attributes in both 'in' and 'out' typemaps are needed, that is, +// typemaps targeting both parameters and return values respectively). + +#ifdef SWIGCSHARP +// Check special variable expansion in typemap attributes. +// This changes return by reference into return by value. +// Takes advantage of the fact that 'int' is a valid type in both C and C#. +// This is not a realistic use, just a way to test the variable expansion in the 'out' attribute. +%typemap(ctype, out="$*1_ltype") int& getNumber1 "_not_used_" +%typemap(imtype, out="$*1_ltype") int& getNumber1 "_not_used_" +%typemap(cstype, out="$*1_ltype") int& getNumber1 "_not_used_" +%typemap(out) int& getNumber1 "$result = *$1;" +%typemap(csout, excode=SWIGEXCODE) int & getNumber1 { + int ret = $imcall;$excode + return ret; + } +#endif + +%inline %{ +int& getNumber1() { + static int num = 111; + return num; +} +%} + +#ifdef SWIGCSHARP +// Check special variable macro expansion in typemap attributes. +// This changes return by reference into return by value. +%typemap(ctype, out="$typemap(ctype, int)") int& getNumber2 "_not_used_" +%typemap(imtype, out="$typemap(imtype, int)") int& getNumber2 "_not_used_" +%typemap(cstype, out="$typemap(cstype, int)") int& getNumber2 "_not_used_" +%typemap(out) int& getNumber2 "$result = *$1;" +%typemap(csout, excode=SWIGEXCODE) int & getNumber2 { + int ret = $imcall;$excode + return ret; + } +#endif + +%inline %{ +int& getNumber2() { + static int num = 222; + return num; +} +%} + + +#ifdef SWIGCSHARP +// Check special variable macro expansion and special variable expansion in typemap attributes. +// This changes return by reference into return by value. +%typemap(ctype, out="$typemap(ctype, $*1_ltype)") int& getNumber3 "_not_used_" +%typemap(imtype, out="$typemap(imtype, $*1_ltype)") int& getNumber3 "_not_used_" +%typemap(cstype, out="$typemap(cstype, $*1_ltype)") int& getNumber3 "_not_used_" +%typemap(out) int& getNumber3 "$result = *$1;" +%typemap(csout, excode=SWIGEXCODE) int & getNumber3 { + int ret = $imcall;$excode + return ret; + } +#endif + +%inline %{ +int& getNumber3() { + static int num = 333; + return num; +} +%} + +#ifdef SWIGCSHARP +// Check special variable macro expansion in typemap attributes. +%typemap(csin, + pre=" $typemap(cstype, int) $csinput_scaled = 11;" + ) int num1 +%{$csinput * $csinput_scaled %} +#endif + +%inline %{ +int bounceNumber1(int num1) { + return num1; +} +%} + +#ifdef SWIGCSHARP +// Check special variable expansion in typemap attributes. +%typemap(csin, + pre=" $1_type $csinput_scaled = 22;" + ) int num2 +%{$csinput * $csinput_scaled %} +#endif + +%inline %{ +int bounceNumber2(int num2) { + return num2; +} +%} + +#ifdef SWIGCSHARP +// Check special variable and special variable macro expansion in typemap attributes. +%typemap(csin, + pre=" $typemap(cstype, $1_type) $csinput_scaled = 33;" + ) int num3 +%{$csinput * $csinput_scaled %} +#endif + +%inline %{ +int bounceNumber3(int num3) { + return num3; +} +%} + +///////////////////////////////// +//// Multi-argument typemaps //// +///////////////////////////////// + +// Test expansion of special variables +#ifdef SWIGCSHARP +%typemap(ctype) (int intvar, char charvar) "double" +%typemap(imtype) (int intvar, char charvar) "double" +%typemap(cstype) (int intvar, char charvar) "double" +%typemap(in) (int intvar, char charvar) +%{ + // split double value a.b into two numbers, a and b*100 + $1 = (int)$input; + $2 = (char)(($input - $1 + 0.005) * 100); +%} +%typemap(csin, + pre=" $1_type $csinput_$1_type = 50;\n" // $1_type should expand to int + " $2_type $csinput_$2_type = 'A';" // $2_type should expand to char + ) (int intvar, char charvar) +%{$csinput + ($csinput_int - 50 + $csinput_char - 'A') + ($csinput_$1_type - 50 + $csinput_$2_type - 'A')%} +#endif + +%inline %{ +int multi1(int intvar, char charvar) { + return intvar + charvar; +} +%} + +#ifdef SWIGCSHARP +%typemap(csin, + pre=" $typemap(cstype, int) $csinput_$typemap(cstype, int) = 50;\n" // also should expand to int + " $typemap(cstype, char) $csinput_$typemap(cstype, char) = 'A';" // also should expand to char + ) (int intvar, char charvar) +%{55 + $csinput + ($csinput_int - 50 + $csinput_char - 'A') + ($csinput_$typemap(cstype, int) - 50 + $csinput_$typemap(cstype, char) - 'A')%} +#endif + +%inline %{ +int multi2(int intvar, char charvar) { + return intvar + charvar; +} +%} + +#ifdef SWIGCSHARP +%typemap(csin, + pre=" $typemap(cstype, $1_type) $csinput_$typemap(cstype, $1_type) = 50;\n" // also should expand to int + " $typemap(cstype, $2_type) $csinput_$typemap(cstype, $2_type) = 'A';" // also should expand to char + ) (int intvar, char charvar) +%{77 + $csinput + ($csinput_int - 50 + $csinput_char - 'A') + ($csinput_$typemap(cstype, $1_type) - 50 + $csinput_$typemap(cstype, $2_type) - 'A')%} +#endif + +%inline %{ +int multi3(int intvar, char charvar) { + return intvar + charvar; +} +%} diff --git a/Examples/test-suite/tcl/Makefile.in b/Examples/test-suite/tcl/Makefile.in index 82c59dee4fd..322e71914c1 100644 --- a/Examples/test-suite/tcl/Makefile.in +++ b/Examples/test-suite/tcl/Makefile.in @@ -55,4 +55,4 @@ run_testcase = \ @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" tcl_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' tcl_clean diff --git a/Examples/test-suite/template_classes.i b/Examples/test-suite/template_classes.i index ebe13bd9fbd..d357e418ee9 100644 --- a/Examples/test-suite/template_classes.i +++ b/Examples/test-suite/template_classes.i @@ -18,6 +18,9 @@ class RectangleTest { public: Point& getPoint() {return point;} void setPoint(Point& value) {point = value;} + + static int static_noargs() { return 0; } + static int static_onearg(int i) { return i; } private: Point point; diff --git a/Examples/test-suite/template_default_arg.i b/Examples/test-suite/template_default_arg.i index faa0f686b78..8747fb98833 100644 --- a/Examples/test-suite/template_default_arg.i +++ b/Examples/test-suite/template_default_arg.i @@ -38,7 +38,7 @@ X(const T& t = T()) {} X(double a, const T& t = T(0)) {} T meth(double a, const T& t = T(0)) { return t; } - const T& meth(const T& t = T(0)) { return t; } + const T& meth(const T& t = T(0)) { static T tt; tt = t; return tt; } }; template class Y : private X { diff --git a/Examples/test-suite/template_default_arg_overloaded.i b/Examples/test-suite/template_default_arg_overloaded.i new file mode 100644 index 00000000000..ef8320692b8 --- /dev/null +++ b/Examples/test-suite/template_default_arg_overloaded.i @@ -0,0 +1,67 @@ +%module template_default_arg_overloaded + +// Github issue #529 + +%include + +%inline %{ +#include + +namespace lsst { +namespace daf { +namespace bass { + +class PropertyList { +public: + PropertyList(void) {}; + + virtual ~PropertyList(void) {}; + + template int set(std::string const& name1, T const& value1, bool inPlace1=true) { return 1; } + + int set(std::string const& name2, PropertyList const& value2, bool inPlace2=true) { return 2; } + + template int set(std::string const& name3, T const& value3, std::string const& comment3, bool inPlace3=true) { return 3; } +}; + +}}} // namespace lsst::daf::bass + +// As above but in global namespace +class PropertyListGlobal { +public: + PropertyListGlobal(void) {}; + + virtual ~PropertyListGlobal(void) {}; + + template int set(std::string const& name1, T const& value1, bool inPlace1=true) { return 1; } + + int set(std::string const& name2, PropertyListGlobal const& value2, bool inPlace2=true) { return 2; } + + template int set(std::string const& name3, T const& value3, std::string const& comment3, bool inPlace3=true) { return 3; } +}; + +%} + +%template(setInt) lsst::daf::bass::PropertyList::set; +%template(setIntGlobal) PropertyListGlobal::set; + + +// Global functions +%inline %{ +template int goopGlobal(T i1, bool b1 = true) { return 1; } +int goopGlobal(short s2 = 0) { return 2; } +template int goopGlobal(const char *s3, bool b3 = true) { return 3; } +%} + +// Global functions in a namespace +%inline %{ +namespace lsst { +template int goop(T i1, bool b1 = true) { return 1; } +int goop(short s2 = 0) { return 2; } +template int goop(const char *s3, bool b3 = true) { return 3; } +} +%} + +%template(GoopIntGlobal) goopGlobal; +%template(GoopInt) lsst::goop; + diff --git a/Examples/test-suite/template_default_class_parms.i b/Examples/test-suite/template_default_class_parms.i index e5a8c9d49e0..d07a1309f33 100644 --- a/Examples/test-suite/template_default_class_parms.i +++ b/Examples/test-suite/template_default_class_parms.i @@ -41,7 +41,7 @@ namespace Teuchos { namespace KokkosClassic { namespace DefaultNode { struct DefaultNodeType {}; - }; + } } namespace Tpetra { diff --git a/Examples/test-suite/template_keyword_in_type.i b/Examples/test-suite/template_keyword_in_type.i new file mode 100644 index 00000000000..b54b8ad4a53 --- /dev/null +++ b/Examples/test-suite/template_keyword_in_type.i @@ -0,0 +1,42 @@ +%module template_keyword_in_type + +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) YYY; + +%inline %{ + template struct XXX; + + template struct XXX { + template struct YYY { + typedef TT type; + }; + int xxx(int h) { return h; } + }; + +#if defined(SWIG) || defined(__clang__) + // gcc doesn't parse this (tested with gcc-4.8) + template void testXXX1(::template XXX::template YYY::type xx) {} +#else + template void testXXX1(:: XXX::template YYY::type xx) {} +#endif + template void testXXX2(XXX::YYY::type xx) {} + template void testXXX3(::XXX::template YYY::type) {} +%} + +%inline %{ +typedef double Val; +template struct ListBucket { +}; +namespace Alloc { + template struct rebind { + typedef int other; + }; +} + +template void other1(typename Alloc::template rebind >::other) {} +#if !defined(__SUNPRO_CC) +template void other2(typename Alloc::template rebind< ::template ListBucket >::other) {} +#else +template void other2(typename Alloc::template rebind< :: ListBucket >::other) {} +#endif +template void other3(Alloc::template rebind) {} +%} diff --git a/Examples/test-suite/template_nested.i b/Examples/test-suite/template_nested.i index 81a551a414a..67668fb1a83 100644 --- a/Examples/test-suite/template_nested.i +++ b/Examples/test-suite/template_nested.i @@ -114,6 +114,8 @@ namespace ns { }; } %} + +#if !defined(SWIGSCILAB) %extend ns::OuterClass { %template(T_OuterClassInner2Double) Inner2; } @@ -125,3 +127,14 @@ namespace ns { %template(T_OuterClassInner1Int) ns::OuterClass::Inner1; %template(T_OuterClassInner2NormalClass) ns::OuterClass::Inner2; %template(T_OuterClassInner2Int) ns::OuterClass::Inner2; + +#else +%extend ns::OuterClass { + %template(T_OutClsIn2Dbl) Inner2; +} + +%template(T_OutClsIn1Int) ns::OuterClass::Inner1; +%template(T_OutClsIn2NormCls) ns::OuterClass::Inner2; +%template(T_OutClsIn2Int) ns::OuterClass::Inner2; + +#endif diff --git a/Examples/test-suite/template_template_parameters.i b/Examples/test-suite/template_template_parameters.i index 0c3989603fa..89197229eeb 100644 --- a/Examples/test-suite/template_template_parameters.i +++ b/Examples/test-suite/template_template_parameters.i @@ -13,7 +13,7 @@ template class list_impl_t {}; template class t_alloc = pfc::alloc_fast > - class list_t : public list_impl_t > { + class list_tt : public list_impl_t > { public: t_item item; // typename t_alloc::alloc_type allotype; // SWIG can't handle this yet @@ -32,8 +32,8 @@ void TestInstantiations() { %} %template(ListImplFastBool) list_impl_t >; -%template(ListFastBool) list_t; +%template(ListFastBool) list_tt; %template(ListImplFastDouble) list_impl_t >; -%template(ListDefaultDouble) list_t; +%template(ListDefaultDouble) list_tt; diff --git a/Examples/test-suite/template_typedef_inherit.i b/Examples/test-suite/template_typedef_inherit.i index 861905b435c..ccc96f49f78 100644 --- a/Examples/test-suite/template_typedef_inherit.i +++ b/Examples/test-suite/template_typedef_inherit.i @@ -10,7 +10,10 @@ typedef std::string String; namespace Type { - template class TypedInterfaceObject {}; + template class TypedInterfaceObject { + public: + virtual ~TypedInterfaceObject() {} + }; template class TypedCollectionInterfaceObject : public TypedInterfaceObject { public: @@ -27,6 +30,7 @@ namespace Type { /** Method add() appends an element to the collection */ inline virtual void add(const T & elt) {} + virtual ~PersistentCollection() {} }; } %} diff --git a/Examples/test-suite/testdir/go_subdir_import/go_subdir_import_c.i b/Examples/test-suite/testdir/go_subdir_import/go_subdir_import_c.i new file mode 100644 index 00000000000..dff269c3fe2 --- /dev/null +++ b/Examples/test-suite/testdir/go_subdir_import/go_subdir_import_c.i @@ -0,0 +1,12 @@ +/* File : go_subdir_import_c.i */ +%module go_subdir_import_c + +%inline %{ +class ObjC { + public: + virtual int getInt() const { + return 18; + } +}; +%} + diff --git a/Examples/test-suite/typedef_struct_cpp.i b/Examples/test-suite/typedef_struct_cpp.i new file mode 100644 index 00000000000..7c6e3fff978 --- /dev/null +++ b/Examples/test-suite/typedef_struct_cpp.i @@ -0,0 +1,3 @@ +%module typedef_struct_cpp + +%include "typedef_struct.i" diff --git a/Examples/test-suite/typemap_array_qualifiers.i b/Examples/test-suite/typemap_array_qualifiers.i index cbc6c95ff2f..c3965ced2f0 100644 --- a/Examples/test-suite/typemap_array_qualifiers.i +++ b/Examples/test-suite/typemap_array_qualifiers.i @@ -33,8 +33,10 @@ typedef SomeType myarray[3]; typedef const SomeType myconstarray[4]; typedef volatile SomeType ** mycrazyarray[5]; - typedef volatile SomeType (mycrazyfunc)(SomeType); - typedef volatile SomeType (*mycrazyfuncptr)(SomeType); + extern "C" { + typedef volatile SomeType (mycrazyfunc)(SomeType); + typedef volatile SomeType (*mycrazyfuncptr)(SomeType); + } %} CLEAR_SWIGTYPE_TYPEMAPS; diff --git a/Examples/test-suite/typemap_variables.i b/Examples/test-suite/typemap_variables.i index 687cae1dafb..b1ae24fdff8 100644 --- a/Examples/test-suite/typemap_variables.i +++ b/Examples/test-suite/typemap_variables.i @@ -63,6 +63,19 @@ %typemap(javain) int Space::Struct::smember "/*int smember in */ $javainput" %typemap(javaout) int Space::Struct::smember "/*int smember out*/ { return $jnicall; }" +#if defined(SWIGSCILAB) +%clear int globul; +%clear int Space::nspace; +%clear int Space::Struct::smember; +%ignore Space::Struct::member; +%typemap(varin) int globul "TYPEMAP_VARIABLES_FAIL"; +%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int globul "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;"; +%typemap(varin) int Space::nspace "TYPEMAP_VARIABLES_FAIL"; +%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int Space::nspace "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;"; +%typemap(varin) int Space::Struct::smember "TYPEMAP_VARIABLES_FAIL"; +%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int Space::Struct::smember "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;"; +#endif + %inline %{ int globul; diff --git a/Examples/test-suite/uffi/Makefile.in b/Examples/test-suite/uffi/Makefile.in index 275778c87d7..5d6dc110c4d 100644 --- a/Examples/test-suite/uffi/Makefile.in +++ b/Examples/test-suite/uffi/Makefile.in @@ -48,4 +48,4 @@ run_testcase = \ @exit 0 clean: - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" uffi_clean + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' uffi_clean diff --git a/Examples/test-suite/unicode_strings.i b/Examples/test-suite/unicode_strings.i index 56063c8a42c..9be3748e6f2 100644 --- a/Examples/test-suite/unicode_strings.i +++ b/Examples/test-suite/unicode_strings.i @@ -2,6 +2,10 @@ %include +%begin %{ +#define SWIG_PYTHON_2_UNICODE +%} + %inline %{ const char* non_utf8_c_str(void) { @@ -12,4 +16,8 @@ std::string non_utf8_std_string(void) { return std::string("h\xe9llo w\xc3\xb6rld"); } +char *charstring(char *s) { + return s; +} + %} diff --git a/Examples/test-suite/unions.i b/Examples/test-suite/unions.i index 49bb85de4a0..405d28c6792 100644 --- a/Examples/test-suite/unions.i +++ b/Examples/test-suite/unions.i @@ -8,7 +8,7 @@ This testcase checks that unions can be set and read. /* Must undefine small to work on Windows. small is defined as a char in rpcndr.h */ #ifdef small -#undef small +#undef small #endif %} @@ -37,6 +37,12 @@ typedef struct { SmallStruct small; } uni; int number; -} EmbeddedUnionTest; +} +#if !defined(SWIGSCILAB) +EmbeddedUnionTest; +#else +EmbedUnionTst; +#endif %} + diff --git a/Examples/test-suite/using_protected.i b/Examples/test-suite/using_protected.i index 402a7c8dae9..331d99585b5 100644 --- a/Examples/test-suite/using_protected.i +++ b/Examples/test-suite/using_protected.i @@ -6,6 +6,7 @@ protected: int x; int blah(int xx) { return xx; } virtual int vmethod(int xx) { return xx; } + virtual ~Foo() {} }; class FooBar : public Foo { diff --git a/Examples/test-suite/varargs_overload.i b/Examples/test-suite/varargs_overload.i index 1ba00ba659c..9a24e15a8ff 100644 --- a/Examples/test-suite/varargs_overload.i +++ b/Examples/test-suite/varargs_overload.i @@ -3,6 +3,8 @@ %module varargs_overload %inline %{ +#include + const char *vararg_over1(const char *fmt, ...) { return fmt; } diff --git a/Examples/test-suite/virtual_vs_nonvirtual_base.i b/Examples/test-suite/virtual_vs_nonvirtual_base.i index 00946183529..25dfd7cf64e 100644 --- a/Examples/test-suite/virtual_vs_nonvirtual_base.i +++ b/Examples/test-suite/virtual_vs_nonvirtual_base.i @@ -13,6 +13,7 @@ class SimpleNonVirtual { public: int dummy() { return 0; } + virtual ~SimpleNonVirtual() {} }; class SimpleReturnClass diff --git a/Examples/test-suite/voidtest.i b/Examples/test-suite/voidtest.i index 90779e22782..f0e64937327 100644 --- a/Examples/test-suite/voidtest.i +++ b/Examples/test-suite/voidtest.i @@ -17,7 +17,5 @@ void *vfunc1(void *f) { return f; } void *vfunc2(Foo *f) { return f; } Foo *vfunc3(void *f) { return (Foo *) f; } Foo *vfunc4(Foo *f) { return f; } - %} - diff --git a/Examples/xml/Makefile.in b/Examples/xml/Makefile.in index 27c86e3e9f5..44894b8eac2 100644 --- a/Examples/xml/Makefile.in +++ b/Examples/xml/Makefile.in @@ -1,6 +1,13 @@ # Examples/xml/Makefile +srcdir = @srcdir@ top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ + +SWIGEXE = $(top_builddir)/swig +SWIG_LIB_DIR = $(top_srcdir)/Lib +SWIG_LIB_SET = @SWIG_LIB_SET@ +SWIGINVOKE = $(SWIG_LIB_SET) $(SWIGTOOL) $(SWIGEXE) cleanup = tail +2 \ | sed -e 's/ident="ID[0-9A-F]*"//g' \ @@ -19,14 +26,12 @@ all-dot-i-files = \ example_xml.i \ gnarly.i -chk-swiglib = $(top_srcdir)/Lib - check: for f in $(all-dot-i-files) ; do \ base=`basename $$f .i` ; \ xml=$$base.xml ; \ - SWIG_LIB=$(chk-swiglib) $(top_srcdir)/swig -xml $$xml $$f ; \ - cat $$xml | $(cleanup) | diff -c $$base.expected-xml - ; \ + $(SWIGINVOKE) -xml $$xml ${srcdir}/$$f ; \ + cat $$xml | $(cleanup) | diff -c ${srcdir}/$$base.expected-xml - ; \ done clean: @@ -38,7 +43,7 @@ distclean: clean # from here on, non-developers beware! %.expected-xml : %.i - SWIG_LIB=$(top_srcdir)/Lib $(top_srcdir)/swig -xml tmp-file $^ + $(SWIGINVOKE) -xml tmp-file $^ cat tmp-file | $(cleanup) > $@ rm -f tmp-file diff --git a/Lib/carrays.i b/Lib/carrays.i index 201c17cac28..3a9c3cfee9b 100644 --- a/Lib/carrays.i +++ b/Lib/carrays.i @@ -81,7 +81,7 @@ typedef struct { #ifdef __cplusplus NAME(int nelements) { - return new TYPE[nelements]; + return new TYPE[nelements](); } ~NAME() { delete [] self; diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 94a0771ba4d..f7b7927bac7 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -203,7 +203,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(directorin) int "$input = $1;" %typemap(directorin) unsigned int "$input = $1;" %typemap(directorin) long "$input = $1;" -%typemap(directorin) unsigned long "$input = $1;" +%typemap(directorin) unsigned long "$input = (unsigned long)$1;" %typemap(directorin) long long "$input = $1;" %typemap(directorin) unsigned long long "$input = $1;" %typemap(directorin) float "$input = $1;" diff --git a/Lib/d/carrays.i b/Lib/d/carrays.i index 37b59c871d5..f2803ea4671 100644 --- a/Lib/d/carrays.i +++ b/Lib/d/carrays.i @@ -21,7 +21,7 @@ %{ static TYPE *new_##NAME(int nelements) { %} #ifdef __cplusplus -%{ return new TYPE[nelements]; %} +%{ return new TYPE[nelements](); %} #else %{ return (TYPE *) calloc(nelements,sizeof(TYPE)); %} #endif @@ -78,7 +78,7 @@ typedef struct {} NAME; %extend NAME { #ifdef __cplusplus NAME(int nelements) { - return new TYPE[nelements]; + return new TYPE[nelements](); } ~NAME() { delete [] self; diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg index 786ca6e6657..50e9c2e877b 100644 --- a/Lib/d/dhead.swg +++ b/Lib/d/dhead.swg @@ -28,7 +28,7 @@ typedef enum { SWIG_DIllegalArgumentException, SWIG_DIllegalElementException, SWIG_DIOException, - SWIG_DNoSuchElementException, + SWIG_DNoSuchElementException } SWIG_DExceptionCodes; typedef void (* SWIG_DExceptionCallback_t)(const char *); diff --git a/Lib/director_common.swg b/Lib/director_common.swg new file mode 100644 index 00000000000..9ce93c7e778 --- /dev/null +++ b/Lib/director_common.swg @@ -0,0 +1,15 @@ +/* ----------------------------------------------------------------------------- + * director_common.swg + * + * This file contains support for director classes which is common between + * languages. + * ----------------------------------------------------------------------------- */ + +/* + Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the + 'Swig' namespace. This could be useful for multi-modules projects. +*/ +#ifdef SWIG_DIRECTOR_STATIC +/* Force anonymous (static) namespace */ +#define Swig +#endif diff --git a/Lib/go/cdata.i b/Lib/go/cdata.i index 9e6dc216136..b4411af97fb 100644 --- a/Lib/go/cdata.i +++ b/Lib/go/cdata.i @@ -8,16 +8,47 @@ typedef struct SWIGCDATA { char *data; intgo len; - intgo cap; } SWIGCDATA; %} -%typemap(gotype) SWIGCDATA %{ []byte %} -%typemap(out) SWIGCDATA %{ - $result.data = (char*)_swig_goallocate($1.len); - memcpy($result.data, $1.data, $1.len); - $result.len = (intgo)$1.len; - $result.cap = $result.len; +%fragment("cdata", "header") %{ +struct swigcdata { + intgo size; + void *data; +}; +%} + +%typemap(gotype) SWIGCDATA "[]byte" + +%typemap(imtype) SWIGCDATA "uint64" + +%typemap(out, fragment="cdata") SWIGCDATA(struct swigcdata *swig_out) %{ + swig_out = (struct swigcdata *)malloc(sizeof(*swig_out)); + if (swig_out) { + swig_out->size = $1.len; + swig_out->data = malloc(swig_out->size); + if (swig_out->data) { + memcpy(swig_out->data, $1.data, swig_out->size); + } + } + $result = *(long long *)(void **)&swig_out; +%} + +%typemap(goout) SWIGCDATA %{ + { + type swigcdata struct { size int; data uintptr } + p := (*swigcdata)(unsafe.Pointer(uintptr($1))) + if p == nil || p.data == 0 { + $result = nil + } else { + b := make([]byte, p.size) + a := (*[0x7fffffff]byte)(unsafe.Pointer(p.data))[:p.size] + copy(b, a) + Swig_free(p.data) + Swig_free(uintptr(unsafe.Pointer(p))) + $result = b + } + } %} /* ----------------------------------------------------------------------------- diff --git a/Lib/go/go.swg b/Lib/go/go.swg index e0ad5d1479c..24f1b73f747 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -4,6 +4,8 @@ * Go configuration module. * ------------------------------------------------------------ */ +%include + /* Code insertion directives */ #define %go_import(...) %insert(go_imports) %{__VA_ARGS__%} @@ -75,6 +77,22 @@ double %{ $result = $1; %} +%typemap(goout) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +"" + %typemap(out) const bool &, const char &, const signed char &, @@ -91,8 +109,26 @@ const double & %{ $result = ($*1_ltype)*$1; %} +%typemap(goout) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +"" + %typemap(out) void "" +%typemap(goout) void "" + %typemap(directorin) bool, char, signed char, @@ -109,6 +145,22 @@ double %{ $input = ($1_ltype)$1; %} +%typemap(godirectorin) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +"" + %typemap(directorin) const bool &, const char &, const signed char &, @@ -125,6 +177,22 @@ const double & %{ $input = ($*1_ltype)$1; %} +%typemap(godirectorin) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +"" + %typemap(directorout) bool, char, signed char, @@ -141,7 +209,7 @@ double %{ $result = ($1_ltype)$input; %} -%typemap(directorout) const bool &, +%typemap(directorout,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) const bool &, const char &, const signed char &, const unsigned char &, @@ -156,8 +224,8 @@ const float &, const double & %{ - $result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype)); - *$result = *($1_ltype)&$input; + $result = new $*1_ltype($input); + swig_acquire_pointer(&swig_mem, $result); %} /* The size_t type. */ @@ -173,22 +241,30 @@ %typemap(out) size_t %{ $result = $1; %} +%typemap(goout) size_t "" + %typemap(out) const size_t & %{ $result = ($*1_ltype)*$1; %} +%typemap(goout) const size_t & "" + %typemap(directorin) size_t %{ $input = (size_t)$1; %} +%typemap(godirectorin) size_t "" + %typemap(directorin) const size_t & %{ $input = ($*1_ltype)$1; %} +%typemap(godirectorin) const size_t & "" + %typemap(directorout) size_t %{ $result = ($1_ltype)$input; %} -%typemap(directorout) const size_t & +%typemap(directorout,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) const size_t & %{ - $result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype)); - *$result = *($1_ltype)$input; + $result = new $*1_ltype($input); + swig_acquire_pointer(&swig_mem, $result); %} /* Member pointers. */ @@ -201,17 +277,45 @@ %typemap(out) SWIGTYPE (CLASS::*) %{ - $result = _swig_goallocate(sizeof($1_ltype)); - *($&1_ltype)$result = $1; + struct swig_out_type { intgo size; void* val; } *swig_out; + swig_out = (struct swig_out_type*)malloc(sizeof(*swig_out)); + if (swig_out) { + swig_out->size = sizeof($1_ltype); + swig_out->val = malloc(swig_out->size); + if (swig_out->val) { + *($&1_ltype)(swig_out->val) = $1; + } + } + $result = swig_out; +%} + +%typemap(goout) SWIGTYPE (CLASS::*) +%{ + { + type swig_out_type struct { size int; val uintptr } + p := (*swig_out_type)(unsafe.Pointer($1)) + if p == nil || p.val == 0 { + $result = nil + } else { + m := make([]byte, p.size) + a := (*[1024]byte)(unsafe.Pointer(p.val))[:p.size] + copy(m, a) + Swig_free(p.val) + Swig_free(uintptr(unsafe.Pointer(p))) + $result = &m[0] + } + } %} %typemap(directorin) SWIGTYPE (CLASS::*) %{ $input = *($&1_ltype)$1; %} +%typemap(godirectorin) SWIGTYPE (CLASS::*) "" + %typemap(directorout) SWIGTYPE (CLASS::*) %{ - $result = _swig_goallocate(sizeof($1_ltype)); - *($&1_ltype)$result = $input; + $result = new $1_ltype($input); + swig_acquire_pointer(&swig_mem, $result); %} /* Pointers. */ @@ -227,9 +331,13 @@ %typemap(out) SWIGTYPE * %{ *($&1_ltype)&$result = ($1_ltype)$1; %} +%typemap(goout) SWIGTYPE * "" + %typemap(directorin) SWIGTYPE * %{ *($&1_ltype)&$input = ($1_ltype)$1; %} +%typemap(godirectorin) SWIGTYPE * "" + %typemap(directorout) SWIGTYPE * %{ $result = *($&1_ltype)&$input; %} @@ -249,6 +357,8 @@ %typemap(out) SWIGTYPE *const& %{ *($1_ltype)&$result = *$1; %} +%typemap(goout) SWIGTYPE *const& "" + /* References. */ /* Converting a C++ reference to Go has to be handled in the C++ @@ -262,9 +372,13 @@ %typemap(out) SWIGTYPE & %{ *($&1_ltype)&$result = $1; %} +%typemap(goout) SWIGTYPE & "" + %typemap(directorin) SWIGTYPE & %{ $input = ($1_ltype)&$1; %} +%typemap(godirectorin) SWIGTYPE & "" + %typemap(directorout) SWIGTYPE & %{ *($&1_ltype)&$result = $input; %} @@ -277,9 +391,13 @@ %typemap(out) SWIGTYPE && %{ *($&1_ltype)&$result = $1; %} +%typemap(goout) SWIGTYPE && "" + %typemap(directorin) SWIGTYPE && %{ $input = ($1_ltype)&$1_name; %} +%typemap(godirectorin) SWIGTYPE && "" + %typemap(directorout) SWIGTYPE && %{ *($&1_ltype)&$result = $input; %} @@ -295,19 +413,20 @@ %typemap(out) SWIGTYPE [] %{ *($&1_ltype)&$result = $1; %} +%typemap(goout) SWIGTYPE [] "" + %typemap(directorin) SWIGTYPE [] %{ $input = *($1_ltype)&$1; %} +%typemap(godirectorin) SWIGTYPE [] "" + %typemap(directorout) SWIGTYPE [] %{ *($&1_ltype)&$result = $input; %} /* Strings. */ %typemap(gotype) - char *, char *&, char[ANY], char[], - signed char *, signed char *&, signed char[ANY], signed char[], - unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] -"string" + char *, char *&, char[ANY], char[] "string" /* Needed to avoid confusion with the way the go module handles references. */ @@ -315,32 +434,34 @@ %typemap(gotype) signed char& "*int8" %typemap(in) - char *, char[ANY], char[], - signed char *, signed char[ANY], signed char[], - unsigned char *, unsigned char[ANY], unsigned char[] + char *, char[ANY], char[] %{ $1 = ($1_ltype)$input.p; %} -%typemap(in) char *&, signed char *&, unsigned char *& +%typemap(in) char *& %{ $1 = ($1_ltype)$input.p; %} -%typemap(out) - char *, char *&, char[ANY], char[], - signed char *, signed char *&, signed char[ANY], signed char[], - unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] -%{ $result = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0); %} +%typemap(out,fragment="AllocateString") + char *, char *&, char[ANY], char[] +%{ $result = Swig_AllocateString((char*)$1, $1 ? strlen((char*)$1) : 0); %} -%typemap(directorin) - char *, char *&, char[ANY], char[], - signed char *, signed char *&, signed char[ANY], signed char[], - unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +%typemap(goout,fragment="CopyString") + char *, char *&, char[ANY], char[] +%{ $result = swigCopyString($1) %} + +%typemap(directorin,fragment="AllocateString") + char *, char *&, char[ANY], char[] +%{ + $input = Swig_AllocateString((char*)$1, $1 ? strlen((char*)$1) : 0); +%} + +%typemap(godirectorin,fragment="CopyString") + char *, char *&, char[ANY], char[] %{ - $input = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0); + $result = swigCopyString($input) %} %typemap(directorout) - char *, char *&, char[ANY], char[], - signed char *, signed char *&, signed char[ANY], signed char[], - unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] + char *, char *&, char[ANY], char[] %{ $result = ($1_ltype)$input.p; %} /* String & length */ @@ -353,11 +474,17 @@ $2 = ($2_ltype)$input.n; %} -%typemap(out) (char *STRING, size_t LENGTH) -%{ $result = _swig_makegostring((char*)$1, (size_t)$2); %} +%typemap(out,fragment="AllocateString") (char *STRING, size_t LENGTH) +%{ $result = Swig_AllocateString((char*)$1, (size_t)$2); %} + +%typemap(goout,fragment="CopyString") (char *STRING, size_t LENGTH) +%{ $result = swigCopyString($1) %} + +%typemap(directorin,fragment="AllocateString") (char *STRING, size_t LENGTH) +%{ $input = Swig_AllocateString((char*)$1, $2); %} -%typemap(directorin) (char *STRING, size_t LENGTH) -%{ $input = _swig_makegostring((char*)$1, $2); %} +%typemap(godirectorin,fragment="CopyString") (char *STRING, size_t LENGTH) +%{ $result = swigCopyString($input) %} %typemap(directorout) (char *STRING, size_t LENGTH) %{ @@ -378,18 +505,24 @@ %typemap(out) enum SWIGTYPE %{ $result = (intgo)$1; %} +%typemap(goout) enum SWIGTYPE "" + %typemap(directorin) enum SWIGTYPE %{ $input = (intgo)$1; %} +%typemap(godirectorin) enum SWIGTYPE "" + %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} %typemap(directorin) enum SWIGTYPE & (intgo e) %{ e = (intgo)$1; - $input = &e; + $input = ($1_ltype)&e; %} +%typemap(godirectorin) enum SWIGTYPE & "" + %typemap(directorout) enum SWIGTYPE & %{ $*1_ltype f = ($*1_ltype)*$input; @@ -423,9 +556,13 @@ } #endif +%typemap(goout) SWIGTYPE "" + %typemap(directorin) SWIGTYPE %{ $input = ($&1_ltype)&$1; %} +%typemap(godirectorin) SWIGTYPE "" + %typemap(directorout) SWIGTYPE %{ $result = *($&1_ltype)$input; %} diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index ef64186b73b..e7a33adc44e 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -4,6 +4,12 @@ * Go runtime code for the various generated files. * ------------------------------------------------------------ */ +%inline %{ +static void Swig_free(void* p) { + free(p); +} +%} + %insert(runtime) %{ #include #include @@ -13,21 +19,63 @@ %} +#if SWIGGO_CGO +%insert(cgo_comment_typedefs) %{ +#include +%} +#endif + #if SWIGGO_INTGO_SIZE == 32 %insert(runtime) %{ typedef int intgo; typedef unsigned int uintgo; %} +#if SWIGGO_CGO +%insert(cgo_comment_typedefs) %{ +typedef int intgo; +typedef unsigned int uintgo; +%} +#endif #elif SWIGGO_INTGO_SIZE == 64 %insert(runtime) %{ typedef long long intgo; typedef unsigned long long uintgo; %} +#if SWIGGO_CGO +%insert(cgo_comment_typedefs) %{ +typedef long long intgo; +typedef unsigned long long uintgo; +%} +#endif #else %insert(runtime) %{ typedef ptrdiff_t intgo; typedef size_t uintgo; %} +#if SWIGGO_CGO +%insert(cgo_comment_typedefs) %{ +typedef ptrdiff_t intgo; +typedef size_t uintgo; +%} +#endif +#endif + +#ifndef SWIGGO_GCCGO +// Set the host compiler struct attribute that will be +// used to match gc's struct layout. For example, on 386 Windows, +// gcc wants to 8-align int64s, but gc does not. +// Use __gcc_struct__ to work around http://gcc.gnu.org/PR52991 on x86, +// and https://golang.org/issue/5603. +// See: https://github.com/golang/go/blob/fcbf04f9b93b4cd8addd05c2ed784118eb50a46c/src/cmd/cgo/out.go#L663 +%insert(runtime) %{ +# if !defined(__clang__) && (defined(__i386__) || defined(__x86_64__)) +# define SWIGSTRUCTPACKED __attribute__((__packed__, __gcc_struct__)) +# else +# define SWIGSTRUCTPACKED __attribute__((__packed__)) +# endif +%} +#else +# define SWIGSTRUCTPACKED #endif %insert(runtime) %{ @@ -37,6 +85,17 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} +#ifdef SWIGGO_CGO + +%insert(cgo_comment_typedefs) %{ + +typedef struct { char *p; intgo n; } _gostring_; +typedef struct { void* array; intgo len; intgo cap; } _goslice_; + +%} + +#endif + #ifndef SWIGGO_GCCGO /* Boilerplate for C/C++ code when using 6g/8g. This code is compiled with gcc. */ @@ -72,26 +131,38 @@ static char *_swig_topofstack() { } } +static void _swig_gopanic(const char *p) { + struct { + const char *p; + } SWIGSTRUCTPACKED a; + a.p = p; + crosscall2(_cgo_panic, &a, (int) sizeof a); +} + +%} + +#if !SWIGGO_CGO + +/* This is here for backward compatibility, but it will not work + with Go 1.5 or later. Do not use it in new code. */ +%insert(runtime) %{ + static void *_swig_goallocate(size_t len) { struct { size_t len; void *ret; - } a; + } SWIGSTRUCTPACKED a; a.len = len; crosscall2(_cgo_allocate, &a, (int) sizeof a); return a.ret; } -static void _swig_gopanic(const char *p) { - struct { - const char *p; - } a; - a.p = p; - crosscall2(_cgo_panic, &a, (int) sizeof a); -} - %} +#endif + +#if !SWIGGO_CGO + /* Boilerplate for C code when using 6g/8g. This code is compiled with 6c/8c. */ %insert(gc_header) %{ @@ -105,6 +176,8 @@ void *·_cgo_runtime_cgocall = &cgocall; %} +#endif + #else /* Boilerplate for C/C++ code when using gccgo. */ @@ -116,6 +189,17 @@ extern "C" { #endif extern void *_cgo_allocate(size_t); extern void _cgo_panic(const char *); +#ifdef __cplusplus +} +#endif + +#define _swig_goallocate _cgo_allocate +#define _swig_gopanic _cgo_panic +%} + +#if !SWIGGO_CGO + +%insert(runtime) %{ /* Implementations of SwigCgocall and friends for different versions of gccgo. The Go code will call these functions using C names with @@ -124,6 +208,10 @@ extern void _cgo_panic(const char *); version. We assume that the version of gcc used to compile this file is the same as the version of gccgo. */ +#ifdef __cplusplus +extern "C" { +#endif + #define SWIG_GCC_VERSION \ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) @@ -178,15 +266,18 @@ void SwigCgocallBackDone() { } #endif -#define _swig_goallocate _cgo_allocate -#define _swig_gopanic _cgo_panic - %} #endif +#endif + +#if !SWIGGO_CGO + %insert(runtime) %{ +/* This is here for backward compatibility, but it will not work + with Go 1.5 or later. Do not use it in new code. */ static _gostring_ _swig_makegostring(const char *p, size_t l) { _gostring_ ret; ret.p = (char*)_swig_goallocate(l + 1); @@ -195,6 +286,12 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) { return ret; } +%} + +#endif + +%insert(runtime) %{ + #define SWIG_contract_assert(expr, msg) \ if (!(expr)) { _swig_gopanic(msg); } else %} @@ -203,9 +300,11 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) { %go_import("unsafe", _ "runtime/cgo") +#if !SWIGGO_CGO %insert(go_header) %{ var _cgo_runtime_cgocall func(unsafe.Pointer, uintptr) %} +#endif #else @@ -242,3 +341,127 @@ var Swig_escape_val interface{} type _swig_fnptr *byte type _swig_memberptr *byte %} + +/* Handle memory management for directors. */ + +%insert(director) %{ +#include + +namespace { + struct GCItem { + virtual ~GCItem() {} + }; + + struct GCItem_var { + GCItem_var(GCItem *item = 0) : _item(item) { + } + + GCItem_var& operator=(GCItem *item) { + GCItem *tmp = _item; + _item = item; + delete tmp; + return *this; + } + + ~GCItem_var() { + delete _item; + } + + GCItem* operator->() { + return _item; + } + + private: + GCItem *_item; + }; + + template + struct GCItem_T : GCItem { + GCItem_T(Type *ptr) : _ptr(ptr) { + } + + virtual ~GCItem_T() { + delete _ptr; + } + + private: + Type *_ptr; + }; +} + +class Swig_memory { +public: + template + void swig_acquire_pointer(Type* vptr) { + if (vptr) { + swig_owner[vptr] = new GCItem_T(vptr); + } + } +private: + typedef std::map swig_ownership_map; + swig_ownership_map swig_owner; +}; + +template +static void swig_acquire_pointer(Swig_memory** pmem, Type* ptr) { + if (!pmem) { + *pmem = new Swig_memory; + } + (*pmem)->swig_acquire_pointer(ptr); +} +%} + +/* For directors we need C++ to track a Go pointer. Since we can't + pass a Go pointer into C++, we use a map to track the pointers on + the Go side. */ + +%go_import("sync") + +%insert(go_header) %{ +type _ sync.Mutex +%} + +%insert(go_director) %{ + +var swigDirectorTrack struct { + sync.Mutex + m map[int]interface{} + c int +} + +func swigDirectorAdd(v interface{}) int { + swigDirectorTrack.Lock() + defer swigDirectorTrack.Unlock() + if swigDirectorTrack.m == nil { + swigDirectorTrack.m = make(map[int]interface{}) + } + swigDirectorTrack.c++ + ret := swigDirectorTrack.c + swigDirectorTrack.m[ret] = v + return ret +} + +func swigDirectorLookup(c int) interface{} { + swigDirectorTrack.Lock() + defer swigDirectorTrack.Unlock() + ret := swigDirectorTrack.m[c] + if ret == nil { + panic("C++ director pointer not found (possible use-after-free)") + } + return ret +} + +func swigDirectorDelete(c int) { + swigDirectorTrack.Lock() + defer swigDirectorTrack.Unlock() + if swigDirectorTrack.m[c] == nil { + if c > swigDirectorTrack.c { + panic("C++ director pointer invalid (possible memory corruption") + } else { + panic("C++ director pointer not found (possible use-after-free)") + } + } + delete(swigDirectorTrack.m, c) +} + +%} diff --git a/Lib/go/gostring.swg b/Lib/go/gostring.swg new file mode 100644 index 00000000000..44cbbb8eec4 --- /dev/null +++ b/Lib/go/gostring.swg @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------ + * gostring.swg + * + * Support for returning strings from C to Go. + * ------------------------------------------------------------ */ + +// C/C++ code to convert a memory buffer into a Go string allocated in +// C/C++ memory. +%fragment("AllocateString", "runtime") %{ +static _gostring_ Swig_AllocateString(const char *p, size_t l) { + _gostring_ ret; + ret.p = (char*)malloc(l); + memcpy(ret.p, p, l); + ret.n = l; + return ret; +} +%} + +// Go code to convert a string allocated in C++ memory to one +// allocated in Go memory. +%fragment("CopyString", "go_runtime") %{ +type swig_gostring struct { p uintptr; n int } +func swigCopyString(s string) string { + p := *(*swig_gostring)(unsafe.Pointer(&s)) + r := string((*[0x7fffffff]byte)(unsafe.Pointer(p.p))[:p.n]) + Swig_free(p.p) + return r +} +%} diff --git a/Lib/go/std_string.i b/Lib/go/std_string.i index 9922fbe135a..068c688cb0d 100644 --- a/Lib/go/std_string.i +++ b/Lib/go/std_string.i @@ -27,11 +27,17 @@ class string; %typemap(directorout) string %{ $result.assign($input.p, $input.n); %} -%typemap(out) string -%{ $result = _swig_makegostring($1.data(), $1.length()); %} +%typemap(out,fragment="AllocateString") string +%{ $result = Swig_AllocateString($1.data(), $1.length()); %} -%typemap(directorin) string -%{ $input = _swig_makegostring($1.data(), $1.length()); %} +%typemap(goout,fragment="CopyString") string +%{ $result = swigCopyString($1) %} + +%typemap(directorin,fragment="AllocateString") string +%{ $input = Swig_AllocateString($1.data(), $1.length()); %} + +%typemap(godirectorin,fragment="CopyString") string +%{ $result = swigCopyString($input) %} %typemap(in) const string & %{ @@ -46,10 +52,16 @@ class string; $result = &$1_str; %} -%typemap(out) const string & -%{ $result = _swig_makegostring((*$1).data(), (*$1).length()); %} +%typemap(out,fragment="AllocateString") const string & +%{ $result = Swig_AllocateString((*$1).data(), (*$1).length()); %} + +%typemap(goout,fragment="CopyString") const string & +%{ $result = swigCopyString($1) %} + +%typemap(directorin,fragment="AllocateString") const string & +%{ $input = Swig_AllocateString($1.data(), $1.length()); %} -%typemap(directorin) const string & -%{ $input = _swig_makegostring($1.data(), $1.length()); %} +%typemap(godirectorin,fragment="CopyString") const string & +%{ $result = swigCopyString($input) %} } diff --git a/Lib/go/typemaps.i b/Lib/go/typemaps.i index c339fb37e01..d2e60d37c8b 100644 --- a/Lib/go/typemaps.i +++ b/Lib/go/typemaps.i @@ -67,6 +67,8 @@ char * typemaps instead: %typemap(out) TYPE *INPUT, TYPE &INPUT "" +%typemap(goout) TYPE *INPUT, TYPE &INPUT "" + %typemap(freearg) TYPE *INPUT, TYPE &INPUT "" %typemap(argout) TYPE *INPUT, TYPE &INPUT "" @@ -167,6 +169,8 @@ char * typemaps instead: %typemap(out) TYPE *OUTPUT, TYPE &OUTPUT "" +%typemap(goout) TYPE *INPUT, TYPE &INPUT "" + %typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT "" %typemap(argout) TYPE *OUTPUT, TYPE &OUTPUT @@ -268,6 +272,8 @@ char * typemaps instead: %typemap(out) TYPE *INOUT, TYPE &INOUT "" +%typemap(goout) TYPE *INOUT, TYPE &INOUT "" + %typemap(freearg) TYPE *INOUT, TYPE &INOUT "" %typemap(argout) TYPE *INOUT, TYPE &INOUT "" diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index 1e1014f5491..fefbe2e7751 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -43,9 +43,9 @@ namespace std { template class map { %typemap(in) map (std::map* m) { if (scm_is_null($input)) { - $1 = std::map(); + $1 = std::map< K, T >(); } else if (scm_is_pair($input)) { - $1 = std::map(); + $1 = std::map< K, T >(); SCM alist = $input; while (!scm_is_null(alist)) { K* k; @@ -77,10 +77,10 @@ namespace std { const map* (std::map temp, std::map* m) { if (scm_is_null($input)) { - temp = std::map(); + temp = std::map< K, T >(); $1 = &temp; } else if (scm_is_pair($input)) { - temp = std::map(); + temp = std::map< K, T >(); $1 = &temp; SCM alist = $input; while (!scm_is_null(alist)) { @@ -109,8 +109,7 @@ namespace std { } %typemap(out) map { SCM alist = SCM_EOL; - for (std::map::reverse_iterator i=$i.rbegin(); - i!=$i.rend(); ++i) { + for (std::map< K, T >::reverse_iterator i=$i.rbegin(); i!=$i.rend(); ++i) { K* key = new K(i->first); T* val = new T(i->second); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); @@ -156,7 +155,7 @@ namespace std { } } else { /* wrapped map? */ - std::map* m; + std::map< K, T >* m; if (SWIG_ConvertPtr($input,(void **) &m, $&1_descriptor, 0) == 0) $1 = 1; @@ -201,7 +200,7 @@ namespace std { } } else { /* wrapped map? */ - std::map* m; + std::map< K, T >* m; if (SWIG_ConvertPtr($input,(void **) &m, $1_descriptor, 0) == 0) $1 = 1; @@ -222,14 +221,14 @@ namespace std { typedef K key_type; typedef T mapped_type; map(); - map(const map &); + map(const map< K, T> &); unsigned int size() const; bool empty() const; void clear(); %extend { const T& __getitem__(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) return i->second; else @@ -239,20 +238,19 @@ namespace std { (*self)[key] = x; } void __delitem__(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) self->erase(i); else throw std::out_of_range("key not found"); } bool has_key(const K& key) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); return i != self->end(); } SCM keys() { SCM result = SCM_EOL; - for (std::map::reverse_iterator i=self->rbegin(); - i!=self->rend(); ++i) { + for (std::map< K, T >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) { K* key = new K(i->first); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); result = scm_cons(k,result); @@ -270,9 +268,9 @@ namespace std { template class map { %typemap(in) map (std::map* m) { if (scm_is_null($input)) { - $1 = std::map(); + $1 = std::map< K, T >(); } else if (scm_is_pair($input)) { - $1 = std::map(); + $1 = std::map< K, T >(); SCM alist = $input; while (!scm_is_null(alist)) { T* x; @@ -305,10 +303,10 @@ namespace std { const map* (std::map temp, std::map* m) { if (scm_is_null($input)) { - temp = std::map(); + temp = std::map< K, T >(); $1 = &temp; } else if (scm_is_pair($input)) { - temp = std::map(); + temp = std::map< K, T >(); $1 = &temp; SCM alist = $input; while (!scm_is_null(alist)) { @@ -338,8 +336,7 @@ namespace std { } %typemap(out) map { SCM alist = SCM_EOL; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map< K, T >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) { T* val = new T(i->second); SCM k = CONVERT_TO(i->first); SCM x = SWIG_NewPointerObj(val,$descriptor(T *), 1); @@ -382,7 +379,7 @@ namespace std { } } else { // wrapped map? - std::map* m; + std::map< K, T >* m; if (SWIG_ConvertPtr($input,(void **) &m, $&1_descriptor, 0) == 0) $1 = 1; @@ -425,7 +422,7 @@ namespace std { } } else { // wrapped map? - std::map* m; + std::map< K, T >* m; if (SWIG_ConvertPtr($input,(void **) &m, $1_descriptor, 0) == 0) $1 = 1; @@ -442,14 +439,14 @@ namespace std { %rename("has-key?") has_key; public: map(); - map(const map &); + map(const map< K, T > &); unsigned int size() const; bool empty() const; void clear(); %extend { T& __getitem__(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) return i->second; else @@ -459,20 +456,19 @@ namespace std { (*self)[key] = x; } void __delitem__(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) self->erase(i); else throw std::out_of_range("key not found"); } bool has_key(K key) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); return i != self->end(); } SCM keys() { SCM result = SCM_EOL; - for (std::map::reverse_iterator i=self->rbegin(); - i!=self->rend(); ++i) { + for (std::map< K, T >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) { SCM k = CONVERT_TO(i->first); result = scm_cons(k,result); } @@ -486,9 +482,9 @@ namespace std { template class map { %typemap(in) map (std::map* m) { if (scm_is_null($input)) { - $1 = std::map(); + $1 = std::map< K, T >(); } else if (scm_is_pair($input)) { - $1 = std::map(); + $1 = std::map< K, T >(); SCM alist = $input; while (!scm_is_null(alist)) { K* k; @@ -520,10 +516,10 @@ namespace std { const map* (std::map temp, std::map* m) { if (scm_is_null($input)) { - temp = std::map(); + temp = std::map< K, T >(); $1 = &temp; } else if (scm_is_pair($input)) { - temp = std::map(); + temp = std::map< K, T >(); $1 = &temp; SCM alist = $input; while (!scm_is_null(alist)) { @@ -552,8 +548,7 @@ namespace std { } %typemap(out) map { SCM alist = SCM_EOL; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map< K, T >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) { K* key = new K(i->first); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); SCM x = CONVERT_TO(i->second); @@ -595,7 +590,7 @@ namespace std { } } else { // wrapped map? - std::map* m; + std::map< K, T >* m; if (SWIG_ConvertPtr($input,(void **) &m, $&1_descriptor, 0) == 0) $1 = 1; @@ -637,7 +632,7 @@ namespace std { } } else { // wrapped map? - std::map* m; + std::map< K, T >* m; if (SWIG_ConvertPtr($input,(void **) &m, $1_descriptor, 0) == 0) $1 = 1; @@ -654,14 +649,14 @@ namespace std { %rename("has-key?") has_key; public: map(); - map(const map &); + map(const map< K, T > &); unsigned int size() const; bool empty() const; void clear(); %extend { T __getitem__(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) return i->second; else @@ -671,20 +666,19 @@ namespace std { (*self)[key] = x; } void __delitem__(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) self->erase(i); else throw std::out_of_range("key not found"); } bool has_key(const K& key) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); return i != self->end(); } SCM keys() { SCM result = SCM_EOL; - for (std::map::reverse_iterator i=self->rbegin(); - i!=self->rend(); ++i) { + for (std::map< K, T >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) { K* key = new K(i->first); SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); result = scm_cons(k,result); @@ -700,9 +694,9 @@ namespace std { template<> class map { %typemap(in) map (std::map* m) { if (scm_is_null($input)) { - $1 = std::map(); + $1 = std::map< K, T >(); } else if (scm_is_pair($input)) { - $1 = std::map(); + $1 = std::map< K, T >(); SCM alist = $input; while (!scm_is_null(alist)) { SCM entry, key, val; @@ -736,10 +730,10 @@ namespace std { const map* (std::map temp, std::map* m) { if (scm_is_null($input)) { - temp = std::map(); + temp = std::map< K, T >(); $1 = &temp; } else if (scm_is_pair($input)) { - temp = std::map(); + temp = std::map< K, T >(); $1 = &temp; SCM alist = $input; while (!scm_is_null(alist)) { @@ -769,8 +763,7 @@ namespace std { } %typemap(out) map { SCM alist = SCM_EOL; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map< K, T >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) { SCM k = CONVERT_K_TO(i->first); SCM x = CONVERT_T_TO(i->second); SCM entry = scm_cons(k,x); @@ -809,7 +802,7 @@ namespace std { } } else { // wrapped map? - std::map* m; + std::map< K, T >* m; if (SWIG_ConvertPtr($input,(void **) &m, $&1_descriptor, 0) == 0) $1 = 1; @@ -849,7 +842,7 @@ namespace std { } } else { // wrapped map? - std::map* m; + std::map< K, T >* m; if (SWIG_ConvertPtr($input,(void **) &m, $1_descriptor, 0) == 0) $1 = 1; @@ -866,14 +859,14 @@ namespace std { %rename("has-key?") has_key; public: map(); - map(const map &); + map(const map< K, T> &); unsigned int size() const; bool empty() const; void clear(); %extend { T __getitem__(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) return i->second; else @@ -883,20 +876,19 @@ namespace std { (*self)[key] = x; } void __delitem__(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) self->erase(i); else throw std::out_of_range("key not found"); } bool has_key(K key) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); return i != self->end(); } SCM keys() { SCM result = SCM_EOL; - for (std::map::reverse_iterator i=self->rbegin(); - i!=self->rend(); ++i) { + for (std::map< K, T >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) { SCM k = CONVERT_K_TO(i->first); result = scm_cons(k,result); } diff --git a/Lib/guile/std_pair.i b/Lib/guile/std_pair.i index 512d0d55573..92dec5faedc 100644 --- a/Lib/guile/std_pair.i +++ b/Lib/guile/std_pair.i @@ -79,7 +79,7 @@ namespace std { } } else { /* wrapped pair? */ - std::pair* m; + std::pair< T, U >* m; if (SWIG_ConvertPtr($input,(void **) &m, $&1_descriptor, 0) == 0) $1 = 1; @@ -105,7 +105,7 @@ namespace std { } } else { /* wrapped pair? */ - std::pair* m; + std::pair< T, U >* m; if (SWIG_ConvertPtr($input,(void **) &m, $1_descriptor, 0) == 0) $1 = 1; @@ -183,7 +183,7 @@ namespace std { } } else { /* wrapped pair? */ - std::pair* m; + std::pair< T, U >* m; if (SWIG_ConvertPtr($input,(void **) &m, $&1_descriptor, 0) == 0) $1 = 1; @@ -207,7 +207,7 @@ namespace std { } } else { /* wrapped pair? */ - std::pair* m; + std::pair< T, U >* m; if (SWIG_ConvertPtr($input,(void **) &m, $1_descriptor, 0) == 0) $1 = 1; @@ -283,7 +283,7 @@ namespace std { } } else { /* wrapped pair? */ - std::pair* m; + std::pair< T, U >* m; if (SWIG_ConvertPtr($input,(void **) &m, $&1_descriptor, 0) == 0) $1 = 1; @@ -307,7 +307,7 @@ namespace std { } } else { /* wrapped pair? */ - std::pair* m; + std::pair< T, U >* m; if (SWIG_ConvertPtr($input,(void **) &m, $1_descriptor, 0) == 0) $1 = 1; @@ -377,7 +377,7 @@ namespace std { } } else { /* wrapped pair? */ - std::pair* m; + std::pair< T, U >* m; if (SWIG_ConvertPtr($input,(void **) &m, $&1_descriptor, 0) == 0) $1 = 1; @@ -398,7 +398,7 @@ namespace std { } } else { /* wrapped pair? */ - std::pair* m; + std::pair< T, U >* m; if (SWIG_ConvertPtr($input,(void **) &m, $1_descriptor, 0) == 0) $1 = 1; diff --git a/Lib/guile/std_vector.i b/Lib/guile/std_vector.i index 1c55239c1d8..d7a7140c6ba 100644 --- a/Lib/guile/std_vector.i +++ b/Lib/guile/std_vector.i @@ -44,17 +44,17 @@ namespace std { %typemap(in) vector { if (scm_is_vector($input)) { unsigned long size = scm_c_vector_length($input); - $1 = std::vector(size); + $1 = std::vector< T >(size); for (unsigned long i=0; i(); + $1 = std::vector< T >(); } else if (scm_is_pair($input)) { SCM head, tail; - $1 = std::vector(); + $1 = std::vector< T >(); tail = $input; while (!scm_is_null(tail)) { head = SCM_CAR(tail); @@ -72,7 +72,7 @@ namespace std { const vector* (std::vector temp) { if (scm_is_vector($input)) { unsigned long size = scm_c_vector_length($input); - temp = std::vector(size); + temp = std::vector< T >(size); $1 = &temp; for (unsigned long i=0; i(); + temp = std::vector< T >(); $1 = &temp; } else if (scm_is_pair($input)) { - temp = std::vector(); + temp = std::vector< T >(); $1 = &temp; SCM head, tail; tail = $input; @@ -138,7 +138,7 @@ namespace std { $1 = 0; } else { /* wrapped vector? */ - std::vector* v; + std::vector< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor, 0) != -1) $1 = 1; @@ -178,7 +178,7 @@ namespace std { $1 = 0; } else { /* wrapped vector? */ - std::vector* v; + std::vector< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $1_descriptor, 0) != -1) $1 = 1; @@ -232,7 +232,7 @@ namespace std { %typemap(in) vector { if (scm_is_vector($input)) { unsigned long size = scm_c_vector_length($input); - $1 = std::vector(size); + $1 = std::vector< T >(size); for (unsigned long i=0; i(size); + $1 = std::vector< T >(size); for (unsigned long i=0; i* (std::vector temp) { if (scm_is_vector($input)) { unsigned long size = scm_c_vector_length($input); - temp = std::vector(size); + temp = std::vector< T >(size); $1 = &temp; for (unsigned long i=0; i(); + temp = std::vector< T >(); $1 = &temp; } else if (scm_is_pair($input)) { SCM v = scm_vector($input); unsigned long size = scm_c_vector_length(v); - temp = std::vector(size); + temp = std::vector< T >(size); $1 = &temp; for (unsigned long i=0; i* v; + std::vector< T >* v; $1 = (SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor, 0) != -1) ? 1 : 0; } @@ -345,7 +345,7 @@ namespace std { $1 = CHECK(head) ? 1 : 0; } else { /* wrapped vector? */ - std::vector* v; + std::vector< T >* v; $1 = (SWIG_ConvertPtr($input,(void **) &v, $1_descriptor, 0) != -1) ? 1 : 0; } diff --git a/Lib/java/arrays_java.i b/Lib/java/arrays_java.i index 4b780aef921..402f088d509 100644 --- a/Lib/java/arrays_java.i +++ b/Lib/java/arrays_java.i @@ -52,7 +52,7 @@ static int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **ca #ifdef __cplusplus %{ *carr = new CTYPE[sz]; %} #else -%{ *carr = (CTYPE*) calloc(sz, sizeof(CTYPE)); %} +%{ *carr = (CTYPE*) malloc(sz * sizeof(CTYPE)); %} #endif %{ if (!*carr) { SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); @@ -259,7 +259,7 @@ JAVA_ARRAYS_TYPEMAPS(double, double, jdouble, Double, "[D") /* double[ANY] * #ifdef __cplusplus $1 = new $*1_ltype[sz]; #else - $1 = ($1_ltype) calloc(sz, sizeof($*1_ltype)); + $1 = ($1_ltype) malloc(sz * sizeof($*1_ltype)); #endif if (!$1) { SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); @@ -289,7 +289,7 @@ JAVA_ARRAYS_TYPEMAPS(double, double, jdouble, Double, "[D") /* double[ANY] * #ifdef __cplusplus $1 = new $*1_ltype[sz]; #else - $1 = ($1_ltype) calloc(sz, sizeof($*1_ltype)); + $1 = ($1_ltype) malloc(sz * sizeof($*1_ltype)); #endif if (!$1) { SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); diff --git a/Lib/java/boost_intrusive_ptr.i b/Lib/java/boost_intrusive_ptr.i index f9525894fc9..1d8fa7445b7 100644 --- a/Lib/java/boost_intrusive_ptr.i +++ b/Lib/java/boost_intrusive_ptr.i @@ -263,7 +263,7 @@ // Base proxy classes %typemap(javabody) TYPE %{ - private long swigCPtr; + private transient long swigCPtr; private boolean swigCMemOwnBase; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { @@ -278,7 +278,7 @@ // Derived proxy classes %typemap(javabody_derived) TYPE %{ - private long swigCPtr; + private transient long swigCPtr; private boolean swigCMemOwnDerived; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { @@ -413,7 +413,7 @@ // Base proxy classes %typemap(javabody) TYPE %{ - private long swigCPtr; + private transient long swigCPtr; private boolean swigCMemOwnBase; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { @@ -428,7 +428,7 @@ // Derived proxy classes %typemap(javabody_derived) TYPE %{ - private long swigCPtr; + private transient long swigCPtr; private boolean swigCMemOwnDerived; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i index e752369936a..136570da51b 100644 --- a/Lib/java/boost_shared_ptr.i +++ b/Lib/java/boost_shared_ptr.i @@ -145,8 +145,8 @@ // Base proxy classes %typemap(javabody) TYPE %{ - private long swigCPtr; - private boolean swigCMemOwn; + private transient long swigCPtr; + private transient boolean swigCMemOwn; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { swigCMemOwn = cMemoryOwn; @@ -160,7 +160,7 @@ // Derived proxy classes %typemap(javabody_derived) TYPE %{ - private long swigCPtr; + private transient long swigCPtr; private boolean swigCMemOwnDerived; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { diff --git a/Lib/java/director.swg b/Lib/java/director.swg index 031cdf2a935..355e62d6761 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -209,6 +209,20 @@ namespace Swig { } }; + // Zero initialized bool array + template class BoolArray { + bool array_[N]; + public: + BoolArray() { + memset(array_, 0, sizeof(array_)); + } + bool& operator[](size_t n) { + return array_[n]; + } + bool operator[](size_t n) const { + return array_[n]; + } + }; // Utility classes and functions for exception handling. @@ -355,7 +369,7 @@ namespace Swig { static char *copystr(const char *srcmsg) { char *target = 0; if (srcmsg) { - int msglen = strlen(srcmsg) + 1; + size_t msglen = strlen(srcmsg) + 1; target = new char[msglen]; strncpy(target, srcmsg, msglen); } @@ -367,7 +381,7 @@ namespace Swig { }; // Helper method to determine if a Java throwable matches a particular Java class type - bool ExceptionMatches(JNIEnv *jenv, jthrowable throwable, const char *classname) { + SWIGINTERN bool ExceptionMatches(JNIEnv *jenv, jthrowable throwable, const char *classname) { bool matches = false; if (throwable && jenv && classname) { diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 98524e85e81..0ff487d8060 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -1148,8 +1148,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %define SWIG_JAVABODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) // Base proxy classes %typemap(javabody) TYPE %{ - private long swigCPtr; - protected boolean swigCMemOwn; + private transient long swigCPtr; + protected transient boolean swigCMemOwn; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { swigCMemOwn = cMemoryOwn; @@ -1163,7 +1163,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { // Derived proxy classes %typemap(javabody_derived) TYPE %{ - private long swigCPtr; + private transient long swigCPtr; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { super($imclassname.$javaclazznameSWIGUpcast(cPtr), cMemoryOwn); @@ -1179,9 +1179,9 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %define SWIG_JAVABODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) // Typewrapper classes %typemap(javabody) TYPE *, TYPE &, TYPE &&, TYPE [] %{ - private long swigCPtr; + private transient long swigCPtr; - PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean futureUse) { + PTRCTOR_VISIBILITY $javaclassname(long cPtr, @SuppressWarnings("unused") boolean futureUse) { swigCPtr = cPtr; } @@ -1197,7 +1197,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(javabody) TYPE (CLASS::*) %{ private String swigCMemberPtr; - PTRCTOR_VISIBILITY $javaclassname(String cMemberPtr, boolean futureUse) { + PTRCTOR_VISIBILITY $javaclassname(String cMemberPtr, @SuppressWarnings("unused") boolean futureUse) { swigCMemberPtr = cMemberPtr; } @@ -1330,8 +1330,8 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) %typemap(freearg) (char *STRING, size_t LENGTH) "" %typemap(in) (char *STRING, size_t LENGTH) { if ($input) { - $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0); - $2 = (size_t) JCALL1(GetArrayLength, jenv, $input); + $1 = ($1_ltype) JCALL2(GetByteArrayElements, jenv, $input, 0); + $2 = ($2_type) JCALL1(GetArrayLength, jenv, $input); } else { $1 = 0; $2 = 0; @@ -1341,12 +1341,14 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); } %typemap(directorin, descriptor="[B") (char *STRING, size_t LENGTH) { - jbyteArray jb = (jenv)->NewByteArray($2); - (jenv)->SetByteArrayRegion(jb, 0, $2, (jbyte *)$1); + jbyteArray jb = (jenv)->NewByteArray((jsize)$2); + (jenv)->SetByteArrayRegion(jb, 0, (jsize)$2, (jbyte *)$1); $input = jb; } %typemap(directorargout) (char *STRING, size_t LENGTH) -%{(jenv)->GetByteArrayRegion($input, 0, $2, (jbyte *)$1); %} +%{(jenv)->GetByteArrayRegion($input, 0, (jsize)$2, (jbyte *)$1); +(jenv)->DeleteLocalRef($input);%} +%typemap(javadirectorin, descriptor="[B") (char *STRING, size_t LENGTH) "$jniinput" %apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) } /* java keywords */ diff --git a/Lib/java/various.i b/Lib/java/various.i index bfcf346d3e3..76fb2b1297c 100644 --- a/Lib/java/various.i +++ b/Lib/java/various.i @@ -29,7 +29,7 @@ #ifdef __cplusplus $1 = new char*[size+1]; #else - $1 = (char **)calloc(size+1, sizeof(char *)); + $1 = (char **)malloc((size+1) * sizeof(char *)); #endif for (i = 0; i LONG_MAX) ? JSValueMakeNumber(context, value) : JSValueMakeNumber(context, %numeric_cast(value,long)); } +%#endif } %fragment(SWIG_AsVal_frag(unsigned long long),"header", fragment=SWIG_AsVal_frag(unsigned long), fragment="SWIG_CanCastAsInteger", - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(JSValueRef obj, unsigned long long *val) { + long long longVal; if(!JSValueIsNumber(context, obj)) { return SWIG_TypeError; } - long long longVal = (unsigned long long) JSValueToNumber(context, obj, NULL); + longVal = (unsigned long long) JSValueToNumber(context, obj, NULL); if(longVal < 0) { return SWIG_OverflowError; @@ -156,6 +165,7 @@ SWIG_AsVal_dec(unsigned long long)(JSValueRef obj, unsigned long long *val) return SWIG_OK; } +%#endif } /* double */ diff --git a/Lib/javascript/jsc/javascriptstrings.swg b/Lib/javascript/jsc/javascriptstrings.swg index b3f46ae41d7..55c8e4b989b 100644 --- a/Lib/javascript/jsc/javascriptstrings.swg +++ b/Lib/javascript/jsc/javascriptstrings.swg @@ -52,6 +52,7 @@ SWIG_JSC_FromCharPtrAndSize(JSContextRef context, const char* carray, size_t siz return JSValueMakeUndefined(context); } else { JSStringRef jsstring; + JSValueRef result; if(size < 2) { char c[2]; int i; @@ -63,7 +64,7 @@ SWIG_JSC_FromCharPtrAndSize(JSContextRef context, const char* carray, size_t siz } else { jsstring = JSStringCreateWithUTF8CString(carray); } - JSValueRef result = JSValueMakeString(context, jsstring); + result = JSValueMakeString(context, jsstring); JSStringRelease(jsstring); return result; } diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg index 12db9b4abf1..0bcb508f358 100644 --- a/Lib/javascript/v8/javascriptcode.swg +++ b/Lib/javascript/v8/javascriptcode.swg @@ -102,7 +102,7 @@ fail: %{ if(args.Length() == $jsargcount) { errorHandler.err.Clear(); -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) self = $jswrapper(args, errorHandler); if(errorHandler.err.IsEmpty()) { SWIGV8_ESCAPE(self); @@ -124,13 +124,13 @@ fail: %fragment ("js_dtor", "templates") %{ -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) static void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) static void $jswrapper(v8::Isolate *isolate, v8::Persistent object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) static void $jswrapper(v8::Isolate *isolate, v8::Persistent *object, SWIGV8_Proxy *proxy) { #else static void $jswrapper(const v8::WeakCallbackData &data) { @@ -148,11 +148,11 @@ static void $jswrapper(const v8::WeakCallbackData &dat object.Clear(); -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) object.Dispose(); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) object.Dispose(isolate); -#elif (SWIG_V8_VERSION < 0x032100) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) object->Dispose(isolate); #else object->Dispose(); @@ -168,13 +168,13 @@ static void $jswrapper(const v8::WeakCallbackData &dat * ----------------------------------------------------------------------------- */ %fragment ("js_dtoroverride", "templates") %{ -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) static void $jswrapper(v8::Persistent object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) static void $jswrapper(v8::Isolate *isolate, v8::Persistent object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) static void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object> *object, SWIGV8_Proxy *proxy) { #else static void $jswrapper(const v8::WeakCallbackData &data) { @@ -188,13 +188,13 @@ static void $jswrapper(const v8::WeakCallbackData &dat } delete proxy; -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) object.Dispose(); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) object.Dispose(isolate); -#elif (SWIG_V8_VERSION < 0x032100) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) object->Dispose(isolate); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) object->Dispose(); #else object.Clear(); @@ -326,7 +326,7 @@ fail: if(args.Length() == $jsargcount) { errorHandler.err.Clear(); -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) jsresult = $jswrapper(args, errorHandler); if(errorHandler.err.IsEmpty()) { SWIGV8_ESCAPE(jsresult); @@ -376,7 +376,7 @@ fail: %{ if (SWIGTYPE_p$jsbaseclass->clientdata && !(static_cast(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ.IsEmpty())) { -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) $jsmangledname_class->Inherit(static_cast(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ); #else $jsmangledname_class->Inherit( diff --git a/Lib/javascript/v8/javascriptcomplex.swg b/Lib/javascript/v8/javascriptcomplex.swg index 683b972bcb3..1c0107beb62 100644 --- a/Lib/javascript/v8/javascriptcomplex.swg +++ b/Lib/javascript/v8/javascriptcomplex.swg @@ -4,7 +4,7 @@ the complex Constructor method, and the Real and Imag complex accessor methods. - See the std_complex.i and ccomplex.i for concret examples. + See the std_complex.i and ccomplex.i for concrete examples. */ /* the common from converter */ diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index 969225401b3..f9901fb0214 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -1,7 +1,7 @@ %insert(runtime) %{ // Note: since 3.19 there are new CallBack types, since 03.21.9 the old ones have been removed -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) typedef v8::InvocationCallback SwigV8FunctionCallback; typedef v8::AccessorGetter SwigV8AccessorGetterCallback; typedef v8::AccessorSetter SwigV8AccessorSetterCallback; diff --git a/Lib/javascript/v8/javascriptprimtypes.swg b/Lib/javascript/v8/javascriptprimtypes.swg index fe826b863d6..c0055c48eec 100644 --- a/Lib/javascript/v8/javascriptprimtypes.swg +++ b/Lib/javascript/v8/javascriptprimtypes.swg @@ -112,18 +112,21 @@ int SWIG_AsVal_dec(unsigned long)(v8::Handle obj, unsigned long *val) %fragment(SWIG_From_frag(long long),"header", fragment=SWIG_From_frag(long), - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE v8::Handle SWIG_From_dec(long long)(long long value) { return SWIGV8_NUMBER_NEW(value); } +%#endif } %fragment(SWIG_AsVal_frag(long long),"header", fragment=SWIG_AsVal_frag(long), fragment="SWIG_CanCastAsInteger", - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(long long)(v8::Handle obj, long long* val) { @@ -134,6 +137,7 @@ int SWIG_AsVal_dec(long long)(v8::Handle obj, long long* val) return SWIG_OK; } +%#endif } /* unsigned long long */ @@ -141,19 +145,22 @@ int SWIG_AsVal_dec(long long)(v8::Handle obj, long long* val) %fragment(SWIG_From_frag(unsigned long long),"header", fragment=SWIG_From_frag(long long), - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE v8::Handle SWIG_From_dec(unsigned long long)(unsigned long long value) { return (value > LONG_MAX) ? SWIGV8_INTEGER_NEW_UNS(value) : SWIGV8_INTEGER_NEW(%numeric_cast(value,long)); } +%#endif } %fragment(SWIG_AsVal_frag(unsigned long long),"header", fragment=SWIG_AsVal_frag(unsigned long), fragment="SWIG_CanCastAsInteger", - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(v8::Handle obj, unsigned long long *val) { @@ -171,6 +178,7 @@ int SWIG_AsVal_dec(unsigned long long)(v8::Handle obj, unsigned long return SWIG_OK; } +%#endif } /* double */ diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index b37059cca78..57c5afcd66f 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -7,13 +7,13 @@ #define SWIGV8_SETWEAK_VERSION 0x032224 -#if (SWIG_V8_VERSION < 0x031803) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031803) #define SWIGV8_STRING_NEW2(cstr, len) v8::String::New(cstr, len) #else #define SWIGV8_STRING_NEW2(cstr, len) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::String::kNormalString, len) #endif -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) typedef v8::Handle SwigV8ReturnValue; typedef v8::Arguments SwigV8Arguments; typedef v8::AccessorInfo SwigV8PropertyCallbackInfo; @@ -27,11 +27,11 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return #endif -#if (SWIG_V8_VERSION < 0x032117) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032117) #define SWIGV8_HANDLESCOPE() v8::HandleScope scope #define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope #define SWIGV8_ESCAPE(val) return scope.Close(val) -#elif (SWIG_V8_VERSION < 0x032224) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032224) #define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); #define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope(v8::Isolate::GetCurrent()); #define SWIGV8_ESCAPE(val) return scope.Close(val) @@ -41,7 +41,7 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_ESCAPE(val) return scope.Escape(val) #endif -#if (SWIG_V8_VERSION < 0x032224) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032224) #define SWIGV8_ADJUST_MEMORY(size) v8::V8::AdjustAmountOfExternalAllocatedMemory(size) #define SWIGV8_CURRENT_CONTEXT() v8::Context::GetCurrent() #define SWIGV8_THROW_EXCEPTION(err) v8::ThrowException(err) @@ -55,7 +55,7 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_SYMBOL_NEW(sym) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym) #endif -#if (SWIG_V8_VERSION < 0x032318) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318) #define SWIGV8_ARRAY_NEW() v8::Array::New() #define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(bool) #define SWIGV8_EXTERNAL_NEW(val) v8::External::New(val) @@ -83,9 +83,9 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_NULL() v8::Null(v8::Isolate::GetCurrent()) #endif -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) #define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ = v8::Persistent::New(class); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) #define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ = v8::Persistent::New(v8::Isolate::GetCurrent(), class); #else #define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ.Reset(v8::Isolate::GetCurrent(), class); @@ -101,7 +101,7 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIG_fail goto fail #define SWIGV8_OVERLOAD false -static void SWIG_V8_Raise(const char *msg) { +SWIGINTERN void SWIG_V8_Raise(const char *msg) { SWIGV8_THROW_EXCEPTION(v8::Exception::Error(SWIGV8_STRING_NEW(msg))); } @@ -126,7 +126,7 @@ public: } }; // this is used in usually -static V8ErrorHandler SWIGV8_ErrorHandler; +SWIGRUNTIME V8ErrorHandler SWIGV8_ErrorHandler; // instances of this are used in overloaded functions class OverloadErrorHandler: public V8ErrorHandler { @@ -156,13 +156,13 @@ public: }; ~SWIGV8_Proxy() { -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) handle.ClearWeak(); handle.Dispose(); -#elif (SWIG_V8_VERSION < 0x032100) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) handle.ClearWeak(v8::Isolate::GetCurrent()); handle.Dispose(v8::Isolate::GetCurrent()); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) handle.ClearWeak(); handle.Dispose(); #else @@ -170,7 +170,7 @@ public: handle.Reset(); #endif -#if (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) handle.Clear(); #endif @@ -187,25 +187,25 @@ class SWIGV8_ClientData { public: v8::Persistent class_templ; -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) void (*dtor) (v8::Persistent< v8::Value> object, void *parameter); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Value> object, void *parameter); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy); #else void (*dtor) (const v8::WeakCallbackData &data); #endif }; -static v8::Persistent SWIGV8_SWIGTYPE_Proxy_class_templ; +SWIGRUNTIME v8::Persistent SWIGV8_SWIGTYPE_Proxy_class_templ; -static int SWIG_V8_ConvertInstancePtr(v8::Handle objRef, void **ptr, swig_type_info *info, int flags) { +SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(v8::Handle objRef, void **ptr, swig_type_info *info, int flags) { SWIGV8_HANDLESCOPE(); if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; -#if (SWIG_V8_VERSION < 0x031511) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) v8::Handle cdataRef = objRef->GetInternalField(0); SWIGV8_Proxy *cdata = static_cast(v8::External::Unwrap(cdataRef)); #else @@ -233,23 +233,23 @@ static int SWIG_V8_ConvertInstancePtr(v8::Handle objRef, void **ptr, } -#if (SWIG_V8_VERSION < 0x031710) -static void SWIGV8_Proxy_DefaultDtor(v8::Persistent< v8::Value > object, void *parameter) { +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) +SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Persistent< v8::Value > object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (SWIG_V8_VERSION < 0x031900) -static void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Value > object, void *parameter) { +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) +SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Value > object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) -static void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy) { +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy) { #else -static void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackData &data) { +SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackData &data) { SWIGV8_Proxy *proxy = data.GetParameter(); #endif delete proxy; } -static int SWIG_V8_GetInstancePtr(v8::Handle valRef, void **ptr) { +SWIGRUNTIME int SWIG_V8_GetInstancePtr(v8::Handle valRef, void **ptr) { if(!valRef->IsObject()) { return SWIG_TypeError; } @@ -257,7 +257,7 @@ static int SWIG_V8_GetInstancePtr(v8::Handle valRef, void **ptr) { if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; -#if (SWIG_V8_VERSION < 0x031511) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) v8::Handle cdataRef = objRef->GetInternalField(0); SWIGV8_Proxy *cdata = static_cast(v8::External::Unwrap(cdataRef)); #else @@ -273,40 +273,40 @@ static int SWIG_V8_GetInstancePtr(v8::Handle valRef, void **ptr) { return SWIG_OK; } -static void SWIGV8_SetPrivateData(v8::Handle obj, void *ptr, swig_type_info *info, int flags) { +SWIGRUNTIME void SWIGV8_SetPrivateData(v8::Handle obj, void *ptr, swig_type_info *info, int flags) { SWIGV8_Proxy *cdata = new SWIGV8_Proxy(); cdata->swigCObject = ptr; cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0; cdata->info = info; -#if (SWIG_V8_VERSION < 0x031511) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) obj->SetPointerInInternalField(0, cdata); #else obj->SetAlignedPointerInInternalField(0, cdata); #endif -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) cdata->handle = v8::Persistent::New(obj); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) cdata->handle = v8::Persistent::New(v8::Isolate::GetCurrent(), obj); #else cdata->handle.Reset(v8::Isolate::GetCurrent(), obj); #endif -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) // clientdata must be set for owned data as we need to register the dtor if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); } else { cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor); } -#elif (SWIG_V8_VERSION < 0x031918) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031918) if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); } else { cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, SWIGV8_Proxy_DefaultDtor); } -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); } else { @@ -320,9 +320,9 @@ static void SWIGV8_SetPrivateData(v8::Handle obj, void *ptr, swig_ty } #endif -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) cdata->handle.MarkIndependent(); -#elif (SWIG_V8_VERSION < 0x032100) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) cdata->handle.MarkIndependent(v8::Isolate::GetCurrent()); #else cdata->handle.MarkIndependent(); @@ -330,7 +330,7 @@ static void SWIGV8_SetPrivateData(v8::Handle obj, void *ptr, swig_ty } -static int SWIG_V8_ConvertPtr(v8::Handle valRef, void **ptr, swig_type_info *info, int flags) { +SWIGRUNTIME int SWIG_V8_ConvertPtr(v8::Handle valRef, void **ptr, swig_type_info *info, int flags) { SWIGV8_HANDLESCOPE(); /* special case: JavaScript null => C NULL pointer */ @@ -345,21 +345,21 @@ static int SWIG_V8_ConvertPtr(v8::Handle valRef, void **ptr, swig_typ return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags); } -static v8::Handle SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) { +SWIGRUNTIME v8::Handle SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) { SWIGV8_HANDLESCOPE_ESC(); v8::Handle class_templ; if (ptr == NULL) { -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) SWIGV8_ESCAPE(SWIGV8_NULL()); #else v8::Local result = SWIGV8_NULL(); SWIGV8_ESCAPE(result); -#endif +#endif } -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) if(info->clientdata != 0) { class_templ = ((SWIGV8_ClientData*) info->clientdata)->class_templ; } else { @@ -393,7 +393,7 @@ static v8::Handle SWIG_V8_NewPointerObj(void *ptr, swig_type_info *in #define SWIG_GetInstancePtr(obj, ptr) SWIG_V8_GetInstancePtr(obj, ptr) -static SwigV8ReturnValue _SWIGV8_wrap_equals(const SwigV8Arguments &args) { +SWIGRUNTIME SwigV8ReturnValue _SWIGV8_wrap_equals(const SwigV8Arguments &args) { SWIGV8_HANDLESCOPE(); v8::Handle jsresult; @@ -423,7 +423,7 @@ fail: SWIGV8_RETURN(SWIGV8_UNDEFINED()); } -static SwigV8ReturnValue _wrap_getCPtr(const SwigV8Arguments &args) { +SWIGRUNTIME SwigV8ReturnValue _wrap_getCPtr(const SwigV8Arguments &args) { SWIGV8_HANDLESCOPE(); v8::Handle jsresult; @@ -483,7 +483,7 @@ swig_type_info *SwigV8Packed_UnpackData(v8::Handle valRef, void *ptr, v8::Handle objRef = valRef->ToObject(); -#if (SWIG_V8_VERSION < 0x031511) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) v8::Handle cdataRef = objRef->GetInternalField(0); sobj = static_cast(v8::External::Unwrap(cdataRef)); #else @@ -511,31 +511,31 @@ int SWIGV8_ConvertPacked(v8::Handle valRef, void *ptr, size_t sz, swi return SWIG_OK; } -#if (SWIG_V8_VERSION < 0x031710) -static void _wrap_SwigV8PackedData_delete(v8::Persistent< v8::Value > object, void *parameter) { +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) +SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Persistent< v8::Value > object, void *parameter) { SwigV8PackedData *cdata = static_cast(parameter); -#elif (SWIG_V8_VERSION < 0x031900) -static void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent object, void *parameter) { +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) +SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent object, void *parameter) { SwigV8PackedData *cdata = static_cast(parameter); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) -static void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent *object, SwigV8PackedData *cdata) { +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent *object, SwigV8PackedData *cdata) { #else -static void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData &data) { +SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData &data) { v8::Local object = data.GetValue(); SwigV8PackedData *cdata = data.GetParameter(); #endif delete cdata; -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) object.Clear(); object.Dispose(); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) object.Clear(); object.Dispose(isolate); -#elif (SWIG_V8_VERSION < 0x032100) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) object->Dispose(isolate); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) object->Dispose(); #else object.Clear(); @@ -552,35 +552,35 @@ v8::Handle SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf obj->SetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"), SWIGV8_BOOLEAN_NEW(true)); -#if (SWIG_V8_VERSION < 0x031511) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) obj->SetPointerInInternalField(0, cdata); #else obj->SetAlignedPointerInInternalField(0, cdata); #endif -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) cdata->handle = v8::Persistent::New(obj); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) cdata->handle = v8::Persistent::New(v8::Isolate::GetCurrent(), obj); #else cdata->handle.Reset(v8::Isolate::GetCurrent(), obj); #endif -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete); -#elif (SWIG_V8_VERSION < 0x031918) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031918) cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete); -#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete); #else cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete); // v8::V8::SetWeak(&cdata->handle, cdata, _wrap_SwigV8PackedData_delete); #endif -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) cdata->handle.MarkIndependent(); -#elif (SWIG_V8_VERSION < 0x032100) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) cdata->handle.MarkIndependent(v8::Isolate::GetCurrent()); #else cdata->handle.MarkIndependent(); @@ -600,7 +600,7 @@ v8::Handle SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf SWIGRUNTIME -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) v8::Handle SWIGV8_AppendOutput(v8::Handle result, v8::Handle obj) { #else v8::Handle SWIGV8_AppendOutput(v8::Local result, v8::Handle obj) { @@ -610,11 +610,11 @@ v8::Handle SWIGV8_AppendOutput(v8::Local result, v8::Handl if (result->IsUndefined()) { result = SWIGV8_ARRAY_NEW(); } -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) v8::Handle arr = v8::Handle::Cast(result); #else v8::Local arr = v8::Local::Cast(result); -#endif +#endif arr->Set(arr->Length(), obj); SWIGV8_ESCAPE(arr); diff --git a/Lib/javascript/v8/javascriptruntime.swg b/Lib/javascript/v8/javascriptruntime.swg index ea11b0837b1..0e405932639 100644 --- a/Lib/javascript/v8/javascriptruntime.swg +++ b/Lib/javascript/v8/javascriptruntime.swg @@ -5,11 +5,22 @@ // V8 Version Macro // ---------------- -// v8 does not (until now) provide a version macro - which is still discussed and may come soon. -// Until then, we set a default version which can be overridden via command line using V8_VERSION: -// swig -javascript -v8 -DV8_VERSION=0x031110 +// +// v8 added version macros V8_MAJOR_VERSION, V8_MINOR_VERSION, V8_BUILD_NUMBER +// and V8_PATCH_LEVEL in version 4.3.0. SWIG generated code uses these if +// they are defined - to support earlier versions you can specify the V8 version +// in use via the command line when you run SWIG: +// +// swig -c++ -javascript -v8 -DV8_VERSION=0x032530 example.i +// // Or code in the interface file using SWIG_V8_VERSION: +// // %begin %{#define SWIG_V8_VERSION 0x031110%} +// +// This is specified as a hex constant, but the constant is read as pairs of +// decimal digits, so for V8 3.25.30 use constant 0x032530. This scheme can't +// represent components > 99, but this constant is only useful for V8 < 4.3.0, +// and no V8 versions from that era had a component > 99. %define %swig_v8_define_version(version) %insert("runtime") %{ diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index 892d15798ed..9c21d081299 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -185,7 +185,7 @@ use %include instead // char is changed to a string %typemap(throws) char -%{lua_pushfstring(L,"%c",$1);SWIG_fail;%} +%{lua_pushlstring(L,&$1,1);SWIG_fail;%} /* Throwing object is a serious problem: diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index d9124887df5..721fac22b77 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -1831,7 +1831,7 @@ SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) { switch(constants[i].type) { case SWIG_LUA_INT: lua_pushstring(L,constants[i].name); - lua_pushnumber(L,(lua_Number)constants[i].lvalue); + lua_pushinteger(L,(lua_Number)constants[i].lvalue); lua_rawset(L,-3); break; case SWIG_LUA_FLOAT: @@ -1841,7 +1841,10 @@ SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) { break; case SWIG_LUA_CHAR: lua_pushstring(L,constants[i].name); - lua_pushfstring(L,"%c",(char)constants[i].lvalue); + { + char c = constants[i].lvalue; + lua_pushlstring(L,&c,1); + } lua_rawset(L,-3); break; case SWIG_LUA_STRING: diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index c86b40d74f1..5d98e61075a 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -122,14 +122,14 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) { %{$1 = (lua_tostring(L, $input))[0];%} %typemap(out) char -%{ lua_pushfstring(L,"%c",$1); SWIG_arg++;%} +%{ lua_pushlstring(L, &$1, 1); SWIG_arg++;%} // by const ref %typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char& (char temp) %{temp = (lua_tostring(L, $input))[0]; $1=&temp;%} %typemap(out) const char& -%{ lua_pushfstring(L,"%c",*$1); SWIG_arg++;%} +%{ lua_pushlstring(L, $1, 1); SWIG_arg++;%} // pointers and references // under SWIG rules, it is ok, to have a pass in a lua nil, diff --git a/Lib/ocaml/director.swg b/Lib/ocaml/director.swg index fea0cada620..158cbfeecec 100644 --- a/Lib/ocaml/director.swg +++ b/Lib/ocaml/director.swg @@ -72,7 +72,7 @@ namespace Swig { mutable bool swig_disown_flag; public: - /* wrap a ocaml object, optionally taking ownership */ + /* wrap a ocaml object. */ Director(CAML_VALUE self) : swig_self(self), swig_disown_flag(false) { register_global_root(&swig_self); } diff --git a/Lib/ocaml/ocamldec.swg b/Lib/ocaml/ocamldec.swg index e6b8939fb81..96e1cd2ce90 100644 --- a/Lib/ocaml/ocamldec.swg +++ b/Lib/ocaml/ocamldec.swg @@ -130,7 +130,7 @@ CAMLextern int64 Int64_val(caml_value_t v); SWIGSTATIC CAML_VALUE caml_array_new( int n ); SWIGSTATIC void caml_array_set( CAML_VALUE arr, int n, CAML_VALUE item ); SWIGSTATIC CAML_VALUE caml_array_nth( CAML_VALUE arr, int n ); - SWIGSTATIC int caml_array_length( CAML_VALUE arr ); + SWIGSTATIC int caml_array_len( CAML_VALUE arr ); SWIGSTATIC CAML_VALUE caml_val_char( char c ); SWIGSTATIC CAML_VALUE caml_val_uchar( unsigned char c ); @@ -165,5 +165,3 @@ CAMLextern int64 Int64_val(caml_value_t v); #ifdef __cplusplus } #endif - -/* mzschemedec.swg ends here */ diff --git a/Lib/octave/boost_shared_ptr.i b/Lib/octave/boost_shared_ptr.i index 93b1a896f20..e91862057b2 100644 --- a/Lib/octave/boost_shared_ptr.i +++ b/Lib/octave/boost_shared_ptr.i @@ -29,7 +29,8 @@ } } %typemap(out) CONST TYPE { - %set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } %typemap(varin) CONST TYPE { @@ -40,14 +41,15 @@ %variable_fail(res, "$type", "$name"); } if (!argp) { - %argument_nullref("$type", $symname, $argnum); + %variable_nullref("$type", "$name"); } else { $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); } } %typemap(varout) CONST TYPE { - %set_varoutput(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } // plain pointer @@ -124,7 +126,9 @@ %variable_fail(res, "$type", "$name"); } SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; - if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (!argp) { + %variable_nullref("$type", "$name"); + } if (newmem & SWIG_CAST_NEW_MEMORY) { tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); diff --git a/Lib/octave/director.swg b/Lib/octave/director.swg index c399a6a89a0..e80877ef645 100644 --- a/Lib/octave/director.swg +++ b/Lib/octave/director.swg @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- * director.swg * - * This file contains support for director classes so that D proxy + * This file contains support for director classes so that Octave proxy * methods can be called from C++. * ----------------------------------------------------------------------------- */ diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index 723256ca0a0..0211b33c6c4 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ %{ +#include #include %} diff --git a/Lib/octave/octprimtypes.swg b/Lib/octave/octprimtypes.swg index 6f43f21b0fa..663d1fe1033 100644 --- a/Lib/octave/octprimtypes.swg +++ b/Lib/octave/octprimtypes.swg @@ -97,15 +97,20 @@ SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val) // long long -%fragment(SWIG_From_frag(long long),"header") { +%fragment(SWIG_From_frag(long long),"header", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE octave_value SWIG_From_dec(long long) (long long value) { return octave_int64(value); } +%#endif } -%fragment(SWIG_AsVal_frag(long long),"header") { +%fragment(SWIG_AsVal_frag(long long),"header", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(long long)(const octave_value& ov, long long* val) { if (!ov.is_scalar_type()) @@ -127,16 +132,22 @@ SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val) } return SWIG_OK; } +%#endif } -%fragment(SWIG_From_frag(unsigned long long),"header") { +%fragment(SWIG_From_frag(unsigned long long),"header", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long long) (unsigned long long value) { return octave_uint64(value); } +%#endif } -%fragment(SWIG_AsVal_frag(unsigned long long),"header") { +%fragment(SWIG_AsVal_frag(unsigned long long),"header", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(const octave_value& ov, unsigned long long* val) { if (!ov.is_scalar_type()) @@ -171,6 +182,7 @@ SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val) } return SWIG_OK; } +%#endif } // double diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index dc9b6b6e662..c1c0dcd67d5 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -363,41 +363,44 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return octave_value_list(); } - bool dispatch_unary_op(const std::string &symbol, octave_value &ret) { - member_value_pair *m = find_member(symbol, false); + bool dispatch_unary_op(const std::string &symbol, octave_value &ret) const { + octave_swig_type *nc_this = const_cast < octave_swig_type *>(this); + member_value_pair *m = nc_this->find_member(symbol, false); if (!m || m->first->is_static() || m->first->is_global()) return false; octave_value_list args; - args.append(as_value()); - octave_value_list argout(member_invoke(m, args, 1)); + args.append(nc_this->as_value()); + octave_value_list argout(nc_this->member_invoke(m, args, 1)); if (argout.length() < 1) return false; ret = argout(0); return true; } - bool dispatch_binary_op(const std::string &symbol, const octave_base_value &rhs, octave_value &ret) { - member_value_pair *m = find_member(symbol, false); + bool dispatch_binary_op(const std::string &symbol, const octave_base_value &rhs, octave_value &ret) const { + octave_swig_type *nc_this = const_cast < octave_swig_type *>(this); + member_value_pair *m = nc_this->find_member(symbol, false); if (!m || m->first->is_static() || m->first->is_global()) return false; octave_value_list args; - args.append(as_value()); + args.append(nc_this->as_value()); args.append(make_value_hack(rhs)); - octave_value_list argout(member_invoke(m, args, 1)); + octave_value_list argout(nc_this->member_invoke(m, args, 1)); if (argout.length() < 1) return false; ret = argout(0); return true; } - bool dispatch_index_op(const std::string &symbol, const octave_value_list &rhs, octave_value_list &ret) { - member_value_pair *m = find_member(symbol, false); + bool dispatch_index_op(const std::string &symbol, const octave_value_list &rhs, octave_value_list &ret) const { + octave_swig_type *nc_this = const_cast < octave_swig_type *>(this); + member_value_pair *m = nc_this->find_member(symbol, false); if (!m || m->first->is_static() || m->first->is_global()) return false; octave_value_list args; - args.append(as_value()); + args.append(nc_this->as_value()); args.append(rhs); - octave_value_list argout(member_invoke(m, args, 1)); + octave_value_list argout(nc_this->member_invoke(m, args, 1)); if (argout.length() >= 1) ret = argout(0); return true; @@ -459,22 +462,9 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } dim_vector dims(void) const { - octave_swig_type *nc_this = const_cast < octave_swig_type *>(this); - - // Find the __dims__ method of this object - member_value_pair *m = nc_this->find_member("__dims__", false); - - if (!m) return dim_vector(1,1); - - // Call the __dims__ method of this object - octave_value_list inarg; - inarg.append(nc_this->as_value()); - octave_value_list outarg = nc_this->member_invoke(m, inarg, 1); - - // __dims__ should return (at least) one output argument - if (outarg.length() < 1) return dim_vector(1,1); - - octave_value & out = outarg(0); + octave_value out; + if (!dispatch_unary_op("__dims__", out)) + return dim_vector(1,1); // Return value should be cell or matrix of integers if (out.is_cell()) { @@ -578,26 +568,40 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); swig_member_const_iterator swig_members_begin() { return members.begin(); } swig_member_const_iterator swig_members_end() { return members.end(); } - void *cast(swig_type_info *type, int *_own, int flags) { + int cast(void **vptr, swig_type_info *type, int *_own, int flags) { + int res = SWIG_ERROR; if (_own) *_own = own; if (flags &SWIG_POINTER_DISOWN) own = 0; - if (!type && types.size()) - return types[0].second.ptr; + if (!type && types.size()) { + if(vptr) + *vptr = types[0].second.ptr; + return SWIG_OK; + } for (unsigned int j = 0; j < types.size(); ++j) - if (type == types[j].first) - return types[j].second.ptr; + if (type == types[j].first) { + if(vptr) + *vptr = types[j].second.ptr; + return SWIG_OK; + } for (unsigned int j = 0; j < types.size(); ++j) { swig_cast_info *tc = SWIG_TypeCheck(types[j].first->name, type); if (!tc) continue; - int newmemory = 0; - void *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory); - assert(!newmemory); // newmemory handling not yet implemented - return vptr; + if(vptr) { + int newmemory = 0; + *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(_own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ + if (_own) + *_own = *_own | SWIG_CAST_NEW_MEMORY; + } + } + res = SWIG_OK; + break; } - return 0; + return res; } bool is_owned() const { @@ -800,20 +804,38 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } virtual std::string string_value(bool force = false) const { - octave_swig_type *nc_this = const_cast < octave_swig_type *>(this); - member_value_pair *m = nc_this->find_member("__str__", false); - if (!m) { - error("__str__ method not defined"); - return std::string(); + octave_value ret; + if (!dispatch_unary_op("__str__", ret)) { + error("__str__ method not defined"); + return std::string(); } - octave_value_list outarg = nc_this->member_invoke(m, octave_value_list(nc_this->as_value()), 1); - if (outarg.length() < 1 || !outarg(0).is_string()) { + if (!ret.is_string()) { error("__str__ method did not return a string"); return std::string(); } - return outarg(0).string_value(); + return ret.string_value(); + } + + virtual double scalar_value(bool frc_str_conv = false) const { + octave_value ret; + if (!dispatch_unary_op("__float__", ret)) { + error("__float__ method not defined"); + } + return ret.scalar_value(); } +#if SWIG_OCTAVE_PREREQ(3,8,0) + virtual octave_value map(octave_base_value::unary_mapper_t umap) const { + const std::string opname = std::string("__") + octave_base_value::get_umap_name(umap) + std::string("__"); + octave_value ret; + if (!dispatch_unary_op(opname, ret)) { + error((opname + std::string(" method not found")).c_str()); + return octave_value(); + } + return ret; + } +#endif + #if SWIG_OCTAVE_PREREQ(3,3,52) virtual octave_map map_value() const { return octave_map(); @@ -854,6 +876,17 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } #if defined (HAVE_HDF5) +# if SWIG_OCTAVE_PREREQ(4,0,0) + virtual bool + save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) { + return true; + } + + virtual bool + load_hdf5 (octave_hdf5_id loc_id, const char *name, bool have_h5giterate_bug) { + return true; + } +# else virtual bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) { return true; @@ -863,6 +896,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) { return true; } +# endif #endif virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const { @@ -955,7 +989,12 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return octave_value(); } - void print(std::ostream &os, bool pr_as_read_syntax = false) const { +#if SWIG_OCTAVE_PREREQ(4,0,0) + void print(std::ostream &os, bool pr_as_read_syntax = false) +#else + void print(std::ostream &os, bool pr_as_read_syntax = false) const +#endif + { if (is_string()) { os << string_value(); return; @@ -1050,6 +1089,14 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); virtual std::string string_value(bool force = false) const { return ptr->string_value(force); } + virtual double scalar_value(bool frc_str_conv = false) const + { return ptr->scalar_value(frc_str_conv); } + +#if SWIG_OCTAVE_PREREQ(3,8,0) + virtual octave_value map(octave_base_value::unary_mapper_t umap) const + { return ptr->map(umap); } +#endif + #if SWIG_OCTAVE_PREREQ(3,3,52) virtual octave_map map_value() const { return ptr->map_value(); } @@ -1075,6 +1122,15 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); { return ptr->load_binary(is, swap, fmt); } #if defined (HAVE_HDF5) +# if SWIG_OCTAVE_PREREQ(4,0,0) + virtual bool + save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) + { return ptr->save_hdf5(loc_id, name, save_as_floats); } + + virtual bool + load_hdf5 (octave_hdf5_id loc_id, const char *name, bool have_h5giterate_bug) + { return ptr->load_hdf5(loc_id, name, have_h5giterate_bug); } +# else virtual bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) { return ptr->save_hdf5(loc_id, name, save_as_floats); } @@ -1082,6 +1138,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); virtual bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) { return ptr->load_hdf5(loc_id, name, have_h5giterate_bug); } +# endif #endif virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const @@ -1090,14 +1147,32 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const { return ptr->convert_to_str_internal(pad, force, type); } +#if SWIG_OCTAVE_PREREQ(4,0,0) + void print(std::ostream &os, bool pr_as_read_syntax = false) +#else void print(std::ostream &os, bool pr_as_read_syntax = false) const +#endif { return ptr->print(os, pr_as_read_syntax); } + virtual type_conv_info numeric_conversion_function(void) const { + return octave_base_value::type_conv_info (default_numeric_conversion_function, + octave_scalar::static_type_id ()); + } + private: + static octave_base_value *default_numeric_conversion_function (const octave_base_value& a) { + const octave_swig_ref& v = dynamic_cast(a); + return new octave_scalar(v.scalar_value()); + } + +#if !SWIG_OCTAVE_PREREQ(4,0,0) DECLARE_OCTAVE_ALLOCATOR; +#endif DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; }; +#if !SWIG_OCTAVE_PREREQ(4,0,0) DEFINE_OCTAVE_ALLOCATOR(octave_swig_ref); +#endif DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_ref, "swig_ref", "swig_ref"); class octave_swig_packed:public octave_base_value { @@ -1129,7 +1204,12 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return true; } - void print(std::ostream &os, bool pr_as_read_syntax = false) const { +#if SWIG_OCTAVE_PREREQ(4,0,0) + void print(std::ostream &os, bool pr_as_read_syntax = false) +#else + void print(std::ostream &os, bool pr_as_read_syntax = false) const +#endif + { indent(os); os << "swig packed type: name = " << (type ? type->name : std::string()) << ", len = " << buf.size(); newline(os); } @@ -1153,6 +1233,17 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } #if defined (HAVE_HDF5) +# if SWIG_OCTAVE_PREREQ(4,0,0) + virtual bool + save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) { + return true; + } + + virtual bool + load_hdf5 (octave_hdf5_id loc_id, const char *name, bool have_h5giterate_bug) { + return true; + } +# else virtual bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) { return true; @@ -1162,13 +1253,18 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) { return true; } +# endif #endif private: +#if !SWIG_OCTAVE_PREREQ(4,0,0) DECLARE_OCTAVE_ALLOCATOR; +#endif DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; }; +#if !SWIG_OCTAVE_PREREQ(4,0,0) DEFINE_OCTAVE_ALLOCATOR(octave_swig_packed); +#endif DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_packed, "swig_packed", "swig_packed"); SWIGRUNTIME octave_value_list octave_set_immutable(const octave_value_list &args, int nargout) { @@ -1327,12 +1423,7 @@ SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_t return SWIG_ERROR; octave_swig_ref *osr = static_cast < octave_swig_ref *>(ov.internal_rep()); octave_swig_type *ost = osr->get_ptr(); - void *vptr = ost->cast(type, own, flags); - if (!vptr) - return SWIG_ERROR; - if (ptr) - *ptr = vptr; - return SWIG_OK; + return ost->cast(ptr, type, own, flags); } SWIGRUNTIME octave_value SWIG_Octave_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index fbf2007f6cc..1efc96f8fd5 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -182,6 +183,23 @@ DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) { return octave_value(octave_uint64((unsigned long long) ost->swig_this())); } +static const char *const swig_octave_prereq_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} swig_octave_prereq(@var{major}, @var{minor}, @var{patch})\n\ +Return true if the version of Octave is at least @var{major}.@var{minor}.@var{patch}.\n\ +@end deftypefn"; + +DEFUN_DLD( swig_octave_prereq, args, nargout, swig_octave_prereq_usage ) { + if (args.length() != 3) { + error("swig_octave_prereq: must be called with 3 arguments"); + return octave_value_list(); + } + const int major = args(0).int_value(); + const int minor = args(1).int_value(); + const int patch = args(2).int_value(); + const bool prereq = SWIG_OCTAVE_PREREQ(major, minor, patch); + return octave_value(prereq); +} + static const char *const SWIG_name_usage = "-*- texinfo -*- \n\ @deftypefn {Loadable Module} {} " SWIG_name_d "\n\ Loads the SWIG-generated module `" SWIG_name_d "'.\n\ @@ -235,6 +253,9 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { octave_function *me = octave_call_stack::current(); + if (!SWIG_Octave_InstallFunction(me, "subclass")) { + return octave_value_list(); + } if (!SWIG_Octave_InstallFunction(me, "swig_type")) { return octave_value_list(); } @@ -244,7 +265,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { if (!SWIG_Octave_InstallFunction(me, "swig_this")) { return octave_value_list(); } - if (!SWIG_Octave_InstallFunction(me, "subclass")) { + if (!SWIG_Octave_InstallFunction(me, "swig_octave_prereq")) { return octave_value_list(); } diff --git a/Lib/octave/std_common.i b/Lib/octave/std_common.i index 9aebf7f45bd..c8f17ba7fb0 100644 --- a/Lib/octave/std_common.i +++ b/Lib/octave/std_common.i @@ -11,17 +11,17 @@ fragment=SWIG_From_frag(Type), fragment="StdTraits") { namespace swig { - template <> struct traits { + template <> struct traits< Type > { typedef value_category category; static const char* type_name() { return #Type; } - }; - template <> struct traits_asval { + }; + template <> struct traits_asval< Type > { typedef Type value_type; - static int asval(octave_value obj, value_type *val) { + static int asval(octave_value obj, value_type *val) { return SWIG_AsVal(Type)(obj, val); } }; - template <> struct traits_from { + template <> struct traits_from< Type > { typedef Type value_type; static octave_value from(const value_type& val) { return SWIG_From(Type)(val); @@ -44,13 +44,13 @@ namespace swig { fragment=SWIG_From_frag(int), fragment="StdTraits") { namespace swig { - template <> struct traits_asval { + template <> struct traits_asval< Type > { typedef Type value_type; - static int asval(octave_value obj, value_type *val) { + static int asval(octave_value obj, value_type *val) { return SWIG_AsVal(int)(obj, (int *)val); } }; - template <> struct traits_from { + template <> struct traits_from< Type > { typedef Type value_type; static octave_value from(const value_type& val) { return SWIG_From(int)((int)val); diff --git a/Lib/octave/std_shared_ptr.i b/Lib/octave/std_shared_ptr.i new file mode 100644 index 00000000000..df873679c62 --- /dev/null +++ b/Lib/octave/std_shared_ptr.i @@ -0,0 +1,2 @@ +#define SWIG_SHARED_PTR_NAMESPACE std +%include diff --git a/Lib/perl5/director.swg b/Lib/perl5/director.swg index 714a8787745..f0a6614fc5c 100644 --- a/Lib/perl5/director.swg +++ b/Lib/perl5/director.swg @@ -227,13 +227,12 @@ namespace Swig { } public: - /* wrap a Perl object, optionally taking ownership */ + /* wrap a Perl object. */ Director(SV *pkg) : swig_disown_flag(false) { STRLEN len; char *str = SvPV(pkg, len); swig_class = std::string(str, len); swig_self = newRV_inc((SV *)newHV()); - swig_incref(); } /* discard our reference at destruction */ diff --git a/Lib/perl5/noembed.h b/Lib/perl5/noembed.h index 936d50ba6d6..4e30f1117c8 100644 --- a/Lib/perl5/noembed.h +++ b/Lib/perl5/noembed.h @@ -103,6 +103,9 @@ #ifdef stat #undef stat #endif +#ifdef seed + #undef seed +#endif #ifdef bool /* Leave if macro is from C99 stdbool.h */ diff --git a/Lib/perl5/perlprimtypes.swg b/Lib/perl5/perlprimtypes.swg index d7ac6f94e71..4cb675671c1 100644 --- a/Lib/perl5/perlprimtypes.swg +++ b/Lib/perl5/perlprimtypes.swg @@ -37,7 +37,7 @@ SWIGINTERNINLINE SV * SWIG_From_dec(long)(long value) { SV *sv; - if (value >= IV_MIN && value <= IV_MAX) + if (IVSIZE >= sizeof(value) || (value >= IV_MIN && value <= IV_MAX)) sv = newSViv(value); else sv = newSVpvf("%ld", value); @@ -46,20 +46,22 @@ SWIG_From_dec(long)(long value) } %fragment(SWIG_AsVal_frag(long),"header", + fragment="", + fragment="", fragment="SWIG_CanCastAsInteger") { SWIGINTERN int SWIG_AsVal_dec(long)(SV *obj, long* val) { if (SvUOK(obj)) { UV v = SvUV(obj); - if (v <= LONG_MAX) { + if (UVSIZE < sizeof(*val) || v <= LONG_MAX) { if (val) *val = v; return SWIG_OK; } return SWIG_OverflowError; } else if (SvIOK(obj)) { IV v = SvIV(obj); - if (v >= LONG_MIN && v <= LONG_MAX) { + if (IVSIZE <= sizeof(*val) || (v >= LONG_MIN && v <= LONG_MAX)) { if(val) *val = v; return SWIG_OK; } @@ -102,7 +104,7 @@ SWIGINTERNINLINE SV * SWIG_From_dec(unsigned long)(unsigned long value) { SV *sv; - if (value <= UV_MAX) + if (UVSIZE >= sizeof(value) || value <= UV_MAX) sv = newSVuv(value); else sv = newSVpvf("%lu", value); @@ -111,20 +113,22 @@ SWIG_From_dec(unsigned long)(unsigned long value) } %fragment(SWIG_AsVal_frag(unsigned long),"header", + fragment="", + fragment="", fragment="SWIG_CanCastAsInteger") { SWIGINTERN int SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val) { if (SvUOK(obj)) { UV v = SvUV(obj); - if (v <= ULONG_MAX) { + if (UVSIZE <= sizeof(*val) || v <= ULONG_MAX) { if (val) *val = v; return SWIG_OK; } return SWIG_OverflowError; } else if (SvIOK(obj)) { IV v = SvIV(obj); - if (v >= 0 && v <= ULONG_MAX) { + if (v >= 0 && (IVSIZE <= sizeof(*val) || v <= ULONG_MAX)) { if (val) *val = v; return SWIG_OK; } @@ -163,14 +167,14 @@ SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val) /* long long */ %fragment(SWIG_From_frag(long long),"header", - fragment=SWIG_From_frag(long), - fragment="", + fragment="SWIG_LongLongAvailable", fragment="") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE SV * SWIG_From_dec(long long)(long long value) { SV *sv; - if (value >= IV_MIN && value <= IV_MAX) + if (IVSIZE >= sizeof(value) || (value >= IV_MIN && value <= IV_MAX)) sv = newSViv((IV)(value)); else { //sv = newSVpvf("%lld", value); doesn't work in non 64bit Perl @@ -180,26 +184,28 @@ SWIG_From_dec(long long)(long long value) } return sv_2mortal(sv); } +%#endif } %fragment(SWIG_AsVal_frag(long long),"header", - fragment="", + fragment="SWIG_LongLongAvailable", fragment="", fragment="SWIG_CanCastAsInteger") { - +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(long long)(SV *obj, long long *val) { if (SvUOK(obj)) { UV v = SvUV(obj); - if (v < LLONG_MAX) { + /* pretty sure this could allow v == LLONG MAX */ + if (UVSIZE < sizeof(*val) || v < LLONG_MAX) { if (val) *val = v; return SWIG_OK; } return SWIG_OverflowError; } else if (SvIOK(obj)) { IV v = SvIV(obj); - if (v >= LLONG_MIN && v <= LLONG_MAX) { + if (IVSIZE <= sizeof(*val) || (v >= LLONG_MIN && v <= LLONG_MAX)) { if (val) *val = v; return SWIG_OK; } @@ -235,19 +241,20 @@ SWIG_AsVal_dec(long long)(SV *obj, long long *val) } return SWIG_TypeError; } +%#endif } /* unsigned long long */ %fragment(SWIG_From_frag(unsigned long long),"header", - fragment=SWIG_From_frag(long long), - fragment="", + fragment="SWIG_LongLongAvailable", fragment="") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE SV * SWIG_From_dec(unsigned long long)(unsigned long long value) { SV *sv; - if (value <= UV_MAX) + if (UVSIZE >= sizeof(value) || value <= UV_MAX) sv = newSVuv((UV)(value)); else { //sv = newSVpvf("%llu", value); doesn't work in non 64bit Perl @@ -257,21 +264,25 @@ SWIG_From_dec(unsigned long long)(unsigned long long value) } return sv_2mortal(sv); } +%#endif } %fragment(SWIG_AsVal_frag(unsigned long long),"header", - fragment="", + fragment="SWIG_LongLongAvailable", fragment="", fragment="SWIG_CanCastAsInteger") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val) { if (SvUOK(obj)) { + /* pretty sure this should be conditional on + * (UVSIZE <= sizeof(*val) || v <= ULLONG_MAX) */ if (val) *val = SvUV(obj); return SWIG_OK; } else if (SvIOK(obj)) { IV v = SvIV(obj); - if (v >= 0 && v <= ULLONG_MAX) { + if (v >= 0 && (IVSIZE <= sizeof(*val) || v <= ULLONG_MAX)) { if (val) *val = v; return SWIG_OK; } else { @@ -307,6 +318,7 @@ SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val) } return SWIG_TypeError; } +%#endif } /* double */ diff --git a/Lib/perl5/std_list.i b/Lib/perl5/std_list.i index 8248ca67920..cd5a61120bd 100644 --- a/Lib/perl5/std_list.i +++ b/Lib/perl5/std_list.i @@ -106,7 +106,7 @@ namespace std { } } %typemap(out) list { - std::list::const_iterator i; + std::list< T >::const_iterator i; unsigned int j; int len = $1.size(); SV **svs = new SV*[len]; @@ -125,7 +125,7 @@ namespace std { %typecheck(SWIG_TYPECHECK_LIST) list { { /* wrapped list? */ - std::list* v; + std::list< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $1_&descriptor,0) != -1) { $1 = 1; @@ -158,7 +158,7 @@ namespace std { const list* { { /* wrapped list? */ - std::list* v; + std::list< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $1_descriptor,0) != -1) { $1 = 1; @@ -265,7 +265,7 @@ namespace std { } } %typemap(out) list { - std::list::const_iterator i; + std::list< T >::const_iterator i; unsigned int j; int len = $1.size(); SV **svs = new SV*[len]; @@ -282,7 +282,7 @@ namespace std { %typecheck(SWIG_TYPECHECK_LIST) list { { /* wrapped list? */ - std::list* v; + std::list< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $1_&descriptor,0) != -1) { $1 = 1; @@ -313,7 +313,7 @@ namespace std { const list* { { /* wrapped list? */ - std::list* v; + std::list< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $1_descriptor,0) != -1) { $1 = 1; diff --git a/Lib/perl5/std_map.i b/Lib/perl5/std_map.i index 493307dd902..af49ed38e4d 100644 --- a/Lib/perl5/std_map.i +++ b/Lib/perl5/std_map.i @@ -35,7 +35,7 @@ namespace std { void clear(); %extend { const T& get(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) return i->second; else @@ -45,14 +45,14 @@ namespace std { (*self)[key] = x; } void del(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); if (i != self->end()) self->erase(i); else throw std::out_of_range("key not found"); } bool has_key(const K& key) { - std::map::iterator i = self->find(key); + std::map< K, T >::iterator i = self->find(key); return i != self->end(); } } diff --git a/Lib/perl5/std_vector.i b/Lib/perl5/std_vector.i index 860cdba7ed0..ec844946407 100644 --- a/Lib/perl5/std_vector.i +++ b/Lib/perl5/std_vector.i @@ -119,7 +119,7 @@ namespace std { %typecheck(SWIG_TYPECHECK_VECTOR) vector { { /* wrapped vector? */ - std::vector* v; + std::vector< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor,0) != -1) { $1 = 1; @@ -151,7 +151,7 @@ namespace std { const vector* { { /* wrapped vector? */ - std::vector* v; + std::vector< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $1_descriptor,0) != -1) { $1 = 1; @@ -292,7 +292,7 @@ namespace std { %typecheck(SWIG_TYPECHECK_VECTOR) vector { { /* wrapped vector? */ - std::vector* v; + std::vector< T *>* v; int res = SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor,0); if (SWIG_IsOK(res)) { $1 = 1; @@ -323,7 +323,7 @@ namespace std { %typecheck(SWIG_TYPECHECK_VECTOR) const vector&,const vector* { { /* wrapped vector? */ - std::vector *v; + std::vector< T *> *v; int res = SWIG_ConvertPtr($input,%as_voidptrptr(&v), $1_descriptor,0); if (SWIG_IsOK(res)) { $1 = 1; @@ -466,7 +466,7 @@ namespace std { %typecheck(SWIG_TYPECHECK_VECTOR) vector { { /* wrapped vector? */ - std::vector* v; + std::vector< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor,0) != -1) { $1 = 1; @@ -496,7 +496,7 @@ namespace std { const vector* { { /* wrapped vector? */ - std::vector* v; + std::vector< T >* v; if (SWIG_ConvertPtr($input,(void **) &v, $1_descriptor,0) != -1) { $1 = 1; diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 92c1499998a..638a1697d27 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -12,15 +12,6 @@ #include #include -/* - Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the - 'Swig' namespace. This could be useful for multi-modules projects. -*/ -#ifdef SWIG_DIRECTOR_STATIC -/* Force anonymous (static) namespace */ -#define Swig -#endif - namespace Swig { /* memory handler */ diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 8b5fb7be36b..05d25a1df7b 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -170,7 +170,7 @@ force=0; if (arg1==NULL) { #ifdef __cplusplus - ptr=new $*1_ltype; + ptr=new $*1_ltype(); #else ptr=($*1_ltype) calloc(1,sizeof($*1_ltype)); #endif diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 00d8bc560ef..3f0aa7ac6cb 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -24,6 +24,10 @@ extern "C" { # define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_NAMED_FE(ZN, N, A) #endif +#ifndef ZEND_FE_END +# define ZEND_FE_END { NULL, NULL, NULL } +#endif + #ifndef Z_SET_ISREF_P /* For PHP < 5.3 */ # define Z_SET_ISREF_P(z) (z)->is_ref = 1 diff --git a/Lib/php/typemaps.i b/Lib/php/typemaps.i index ca49ec32749..0372884a6b5 100644 --- a/Lib/php/typemaps.i +++ b/Lib/php/typemaps.i @@ -299,7 +299,7 @@ INT_TYPEMAP(unsigned long long); force=0; if (arg1==NULL) { #ifdef __cplusplus - ptr=new $*1_ltype; + ptr=new $*1_ltype(); #else ptr=($*1_ltype) calloc(1,sizeof($*1_ltype)); #endif diff --git a/Lib/python/README b/Lib/python/README index 98ec5605db6..fa8ef61e7d3 100644 --- a/Lib/python/README +++ b/Lib/python/README @@ -15,7 +15,6 @@ complex.i C99 or C++ complex type cstring.i Various forms of C character string handling cwstring.i Various forms of C wchar_t string handling embed.i embedding the Python interpreter in something else -embed15.i embedding the Python interpreter in something else file.i FILE C type implicit.i Allow the use of implicit C++ constructors wchar.i wchar_t C type diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index 100ed3e8286..40a1ae1ef8e 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -51,7 +51,7 @@ %variable_fail(res, "$type", "$name"); } if (!argp) { - %argument_nullref("$type", $symname, $argnum); + %variable_nullref("$type", "$name"); } else { $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); @@ -137,7 +137,9 @@ %variable_fail(res, "$type", "$name"); } SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; - if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (!argp) { + %variable_nullref("$type", "$name"); + } if (newmem & SWIG_CAST_NEW_MEMORY) { tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 28c557a21e1..5767a14229a 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -9,8 +9,18 @@ SWIGINTERN void \ wrapper##_closure(PyObject *a) { \ SwigPyObject *sobj; \ sobj = (SwigPyObject *)a; \ + Py_XDECREF(sobj->dict); \ if (sobj->own) { \ - PyObject *o = wrapper(a, NULL); \ + PyObject *o; \ + PyObject *val = 0, *type = 0, *tb = 0; \ + PyErr_Fetch(&val, &type, &tb); \ + o = wrapper(a, NULL); \ + if (!o) { \ + PyObject *deallocname = PyString_FromString(#wrapper); \ + PyErr_WriteUnraisable(deallocname); \ + Py_DECREF(deallocname); \ + } \ + PyErr_Restore(val, type, tb); \ Py_XDECREF(o); \ } \ if (PyType_IS_GC(a->ob_type)) { \ @@ -63,7 +73,7 @@ wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \ #define SWIGPY_TERNARYCALLFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ -wrapper##_closure(PyObject *callable_object, PyObject *args, PyObject *) { \ +wrapper##_closure(PyObject *callable_object, PyObject *args, PyObject *) { \ return wrapper(callable_object, args); \ } @@ -123,7 +133,7 @@ wrapper##_closure(PyObject *a, Py_ssize_t b) { \ return result; \ } -#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \ +#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a, Py_ssize_t b) { \ PyObject *arg, *result; \ @@ -432,10 +442,19 @@ SwigPyStaticVar_Type(void) { 0, /* tp_del */ #endif #if PY_VERSION_HEX >= 0x02060000 - 0, /* tp_version */ + 0, /* tp_version_tag */ +#endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ #endif }; staticvar_type = tmp; diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 90c58c10785..4bdc94dc237 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -40,16 +40,6 @@ #endif -/* - Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the - 'Swig' namespace. This could be useful for multi-modules projects. -*/ -#ifdef SWIG_DIRECTOR_STATIC -/* Force anonymous (static) namespace */ -#define Swig -#endif - - /* Use -DSWIG_DIRECTOR_NORTTI if you prefer to avoid the use of the native C++ RTTI and dynamic_cast<>. But be aware that directors @@ -338,9 +328,8 @@ namespace Swig { } public: - /* wrap a python object, optionally taking ownership */ + /* wrap a python object. */ Director(PyObject *self) : swig_self(self), swig_disown_flag(false) { - swig_incref(); } /* discard our reference at destruction */ diff --git a/Lib/python/embed.i b/Lib/python/embed.i index c29e8fd9fd0..efd04878975 100644 --- a/Lib/python/embed.i +++ b/Lib/python/embed.i @@ -1,8 +1,8 @@ // // embed.i // SWIG file embedding the Python interpreter in something else. -// This file is based on Python-1.5. It will not work with -// earlier versions. +// This file is deprecated and no longer actively maintained, but it still +// seems to work with Python 2.7. Status with Python 3 is unknown. // // This file makes it possible to extend Python and all of its // built-in functions without having to hack its setup script. @@ -24,13 +24,8 @@ present in your current Python executable (including any special purpose modules you have enabled such as Tkinter). Thus, you may need to provide additional link libraries when compiling. -This library file only works with Python 1.5. A version -compatible with Python 1.4 is available as embed14.i and -a Python1.3 version is available as embed13.i. As far as -I know, this module is C++ safe. +As far as I know, this module is C++ safe. %} -#else -%echo "embed.i : Using Python 1.5" #endif %wrapper %{ @@ -51,12 +46,12 @@ extern "C" { #endif #include -#undef _PyImport_Inittab +#undef _PyImport_Inittab /* Now define our own version of it. Hopefully someone does not have more than 1000 built-in modules */ -struct _inittab SWIG_Import_Inittab[1000]; +struct _inittab SWIG_Import_Inittab[1000]; static int swig_num_modules = 0; @@ -68,18 +63,18 @@ static void swig_add_module(char *name, void (*initfunc)()) { swig_num_modules++; SWIG_Import_Inittab[swig_num_modules].name = (char *) 0; SWIG_Import_Inittab[swig_num_modules].initfunc = 0; -} +} -/* Function to add all of Python's build in modules to our interpreter */ +/* Function to add all of Python's built-in modules to our interpreter */ static void swig_add_builtin() { int i = 0; while (swig_inittab[i].name) { swig_add_module(swig_inittab[i].name, swig_inittab[i].initfunc); - i++; - } + i++; + } #ifdef SWIGMODINIT - SWIGMODINIT + SWIGMODINIT #endif /* Add SWIG builtin function */ swig_add_module(SWIG_name, SWIG_init); @@ -109,7 +104,3 @@ main(int argc, char **argv) { } %} - - - - diff --git a/Lib/python/embed15.i b/Lib/python/embed15.i deleted file mode 100644 index 3c419b9a3a0..00000000000 --- a/Lib/python/embed15.i +++ /dev/null @@ -1,115 +0,0 @@ -/* ----------------------------------------------------------------------------- - * embed15.i - * - * SWIG file embedding the Python interpreter in something else. - * This file is based on Python-1.5. It will not work with - * earlier versions. - * - * This file makes it possible to extend Python and all of its - * built-in functions without having to hack its setup script. - * ----------------------------------------------------------------------------- */ - -#ifdef AUTODOC -%subsection "embed.i" -%text %{ -This module provides support for building a new version of the -Python executable. This will be necessary on systems that do -not support shared libraries and may be necessary with C++ -extensions. This file contains everything you need to build -a new version of Python from include files and libraries normally -installed with the Python language. - -This module will automatically grab all of the Python modules -present in your current Python executable (including any special -purpose modules you have enabled such as Tkinter). Thus, you -may need to provide additional link libraries when compiling. - -This library file only works with Python 1.5. A version -compatible with Python 1.4 is available as embed14.i and -a Python1.3 version is available as embed13.i. As far as -I know, this module is C++ safe. -%} -#else -%echo "embed.i : Using Python 1.5" -#endif - -%wrapper %{ - -#include - -#ifdef __cplusplus -extern "C" -#endif -void SWIG_init(); /* Forward reference */ - -#define _PyImport_Inittab swig_inittab - -/* Grab Python's inittab[] structure */ - -#ifdef __cplusplus -extern "C" { -#endif -#include - -#undef _PyImport_Inittab - -/* Now define our own version of it. - Hopefully someone does not have more than 1000 built-in modules */ - -struct _inittab SWIG_Import_Inittab[1000]; - -static int swig_num_modules = 0; - -/* Function for adding modules to Python */ - -static void swig_add_module(char *name, void (*initfunc)()) { - SWIG_Import_Inittab[swig_num_modules].name = name; - SWIG_Import_Inittab[swig_num_modules].initfunc = initfunc; - swig_num_modules++; - SWIG_Import_Inittab[swig_num_modules].name = (char *) 0; - SWIG_Import_Inittab[swig_num_modules].initfunc = 0; -} - -/* Function to add all of Python's build in modules to our interpreter */ - -static void swig_add_builtin() { - int i = 0; - while (swig_inittab[i].name) { - swig_add_module(swig_inittab[i].name, swig_inittab[i].initfunc); - i++; - } -#ifdef SWIGMODINIT - SWIGMODINIT -#endif - /* Add SWIG builtin function */ - swig_add_module(SWIG_name, SWIG_init); -} - -#ifdef __cplusplus -} -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -extern int Py_Main(int, char **); - -#ifdef __cplusplus -} -#endif - -extern struct _inittab *PyImport_Inittab; - -int -main(int argc, char **argv) { - swig_add_builtin(); - PyImport_Inittab = SWIG_Import_Inittab; - return Py_Main(argc,argv); -} - -%} - - - - diff --git a/Lib/python/pyabc.i b/Lib/python/pyabc.i index 3da06b5a961..12ce65985ed 100644 --- a/Lib/python/pyabc.i +++ b/Lib/python/pyabc.i @@ -1,7 +1,7 @@ %define %pythonabc(Type, Abc) %feature("python:abc", #Abc) Type; %enddef -%pythoncode {import collections}; +%pythoncode %{import collections%} %pythonabc(std::vector, collections.MutableSequence); %pythonabc(std::list, collections.MutableSequence); %pythonabc(std::map, collections.MutableMapping); diff --git a/Lib/python/pycomplex.swg b/Lib/python/pycomplex.swg index 74be5b970fc..087c50f9040 100644 --- a/Lib/python/pycomplex.swg +++ b/Lib/python/pycomplex.swg @@ -4,7 +4,7 @@ the complex Constructor method, and the Real and Imag complex accessor methods. - See the std_complex.i and ccomplex.i for concret examples. + See the std_complex.i and ccomplex.i for concrete examples. */ /* the common from converter */ diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index e5543cd6b6c..46d04388b19 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -252,6 +252,12 @@ namespace swig { return pos; } + template + inline void + erase(Sequence* seq, const typename Sequence::iterator& position) { + seq->erase(position); + } + template inline Sequence* getslice(const Sequence* self, Difference i, Difference j, Py_ssize_t step) { @@ -415,7 +421,7 @@ namespace swig template struct SwigPySequence_Ref { - SwigPySequence_Ref(PyObject* seq, int index) + SwigPySequence_Ref(PyObject* seq, Py_ssize_t index) : _seq(seq), _index(index) { } @@ -427,7 +433,7 @@ namespace swig return swig::as(item, true); } catch (std::exception& e) { char msg[1024]; - sprintf(msg, "in sequence element %d ", _index); + sprintf(msg, "in sequence element %d ", (int)_index); if (!PyErr_Occurred()) { ::%type_error(swig::type_name()); } @@ -445,7 +451,7 @@ namespace swig private: PyObject* _seq; - int _index; + Py_ssize_t _index; }; template @@ -466,13 +472,13 @@ namespace swig typedef Reference reference; typedef T value_type; typedef T* pointer; - typedef int difference_type; + typedef Py_ssize_t difference_type; SwigPySequence_InputIterator() { } - SwigPySequence_InputIterator(PyObject* seq, int index) + SwigPySequence_InputIterator(PyObject* seq, Py_ssize_t index) : _seq(seq), _index(index) { } @@ -552,6 +558,7 @@ namespace swig difference_type _index; }; + // STL container wrapper around a Python sequence template struct SwigPySequence_Cont { @@ -559,8 +566,8 @@ namespace swig typedef const SwigPySequence_Ref const_reference; typedef T value_type; typedef T* pointer; - typedef int difference_type; - typedef int size_type; + typedef Py_ssize_t difference_type; + typedef size_t size_type; typedef const pointer const_pointer; typedef SwigPySequence_InputIterator iterator; typedef SwigPySequence_InputIterator const_iterator; @@ -621,13 +628,13 @@ namespace swig bool check(bool set_err = true) const { - int s = size(); - for (int i = 0; i < s; ++i) { + Py_ssize_t s = size(); + for (Py_ssize_t i = 0; i < s; ++i) { swig::SwigVar_PyObject item = PySequence_GetItem(_seq, i); if (!swig::check(item)) { if (set_err) { char msg[1024]; - sprintf(msg, "in sequence element %d", i); + sprintf(msg, "in sequence element %d", (int)i); SWIG_Error(SWIG_RuntimeError, msg); } return false; @@ -710,8 +717,8 @@ namespace swig #if defined(SWIGPYTHON_BUILTIN) %feature("python:slot", "tp_iter", functype="getiterfunc") iterator; #else - %pythoncode {def __iter__(self): - return self.iterator()} + %pythoncode %{def __iter__(self): + return self.iterator()%} #endif } @@ -748,7 +755,6 @@ namespace swig return self->size(); } } - %enddef @@ -756,7 +762,7 @@ namespace swig %define %swig_sequence_methods_common(Sequence...) %swig_sequence_iterator(%arg(Sequence)) %swig_container_methods(%arg(Sequence)) - + %fragment("SwigPySequence_Base"); #if defined(SWIGPYTHON_BUILTIN) @@ -769,14 +775,6 @@ namespace swig #endif // SWIGPYTHON_BUILTIN %extend { - value_type pop() throw (std::out_of_range) { - if (self->size() == 0) - throw std::out_of_range("pop from empty container"); - Sequence::value_type x = self->back(); - self->pop_back(); - return x; - } - /* typemap for slice object support */ %typemap(in) PySliceObject* { if (!PySlice_Check($input)) { @@ -794,7 +792,11 @@ namespace swig return swig::getslice(self, i, j, 1); } - void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence()) throw (std::out_of_range, std::invalid_argument) { + void __setslice__(difference_type i, difference_type j) throw (std::out_of_range, std::invalid_argument) { + swig::setslice(self, i, j, 1, Sequence()); + } + + void __setslice__(difference_type i, difference_type j, const Sequence& v) throw (std::out_of_range, std::invalid_argument) { swig::setslice(self, i, j, 1, v); } @@ -803,11 +805,10 @@ namespace swig } #endif - void __delitem__(difference_type i) throw (std::out_of_range) { - self->erase(swig::getpos(self,i)); + void __delitem__(difference_type i) throw (std::out_of_range, std::invalid_argument) { + swig::erase(self, swig::getpos(self, i)); } - /* Overloaded methods for Python 3 compatibility * (Also useful in Python 2.x) */ @@ -858,12 +859,11 @@ namespace swig Sequence::difference_type jd = j; swig::delslice(self, id, jd, step); } - - } + } %enddef -%define %swig_sequence_methods(Sequence...) +%define %swig_sequence_methods_non_resizable(Sequence...) %swig_sequence_methods_common(%arg(Sequence)) %extend { const value_type& __getitem__(difference_type i) const throw (std::out_of_range) { @@ -876,19 +876,32 @@ namespace swig #if defined(SWIGPYTHON_BUILTIN) // This will be called through the mp_ass_subscript slot to delete an entry. - void __setitem__(difference_type i) throw (std::out_of_range) { - self->erase(swig::getpos(self,i)); + void __setitem__(difference_type i) throw (std::out_of_range, std::invalid_argument) { + swig::erase(self, swig::getpos(self, i)); } #endif + } +%enddef + +%define %swig_sequence_methods(Sequence...) + %swig_sequence_methods_non_resizable(%arg(Sequence)) + %extend { + value_type pop() throw (std::out_of_range) { + if (self->size() == 0) + throw std::out_of_range("pop from empty container"); + Sequence::value_type x = self->back(); + self->pop_back(); + return x; + } + void append(const value_type& x) { self->push_back(x); } - } - + } %enddef -%define %swig_sequence_methods_val(Sequence...) +%define %swig_sequence_methods_non_resizable_val(Sequence...) %swig_sequence_methods_common(%arg(Sequence)) %extend { value_type __getitem__(difference_type i) throw (std::out_of_range) { @@ -901,16 +914,28 @@ namespace swig #if defined(SWIGPYTHON_BUILTIN) // This will be called through the mp_ass_subscript slot to delete an entry. - void __setitem__(difference_type i) throw (std::out_of_range) { - self->erase(swig::getpos(self,i)); + void __setitem__(difference_type i) throw (std::out_of_range, std::invalid_argument) { + swig::erase(self, swig::getpos(self, i)); } #endif + } +%enddef + +%define %swig_sequence_methods_val(Sequence...) + %swig_sequence_methods_non_resizable_val(%arg(Sequence)) + %extend { + value_type pop() throw (std::out_of_range) { + if (self->size() == 0) + throw std::out_of_range("pop from empty container"); + Sequence::value_type x = self->back(); + self->pop_back(); + return x; + } void append(value_type x) { self->push_back(x); } - } - + } %enddef @@ -988,10 +1013,9 @@ namespace swig { %#endif size_type size = seq.size(); if (size <= (size_type)INT_MAX) { - PyObject *obj = PyTuple_New((int)size); - int i = 0; - for (const_iterator it = seq.begin(); - it != seq.end(); ++it, ++i) { + PyObject *obj = PyTuple_New((Py_ssize_t)size); + Py_ssize_t i = 0; + for (const_iterator it = seq.begin(); it != seq.end(); ++it, ++i) { PyTuple_SetItem(obj,i,swig::from(*it)); } return obj; diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg index cedd017a74e..63df684b60d 100644 --- a/Lib/python/pyhead.swg +++ b/Lib/python/pyhead.swg @@ -97,10 +97,6 @@ PyString_FromFormat(const char *fmt, ...) { } #endif -/* Add PyObject_Del for old Pythons */ -#if PY_VERSION_HEX < 0x01060000 -# define PyObject_Del(op) PyMem_DEL((op)) -#endif #ifndef PyObject_DEL # define PyObject_DEL PyObject_Del #endif diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 47d3d9700f7..2e21b826586 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -183,10 +183,19 @@ swig_varlink_type(void) { 0, /* tp_del */ #endif #if PY_VERSION_HEX >= 0x02060000 - 0, /* tp_version */ + 0, /* tp_version_tag */ +#endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ #endif }; varlink_type = tmp; @@ -275,7 +284,9 @@ SWIG_Python_FixMethods(PyMethodDef *methods, size_t i; for (i = 0; methods[i].ml_name; ++i) { const char *c = methods[i].ml_doc; - if (c && (c = strstr(c, "swig_ptr: "))) { + if (!c) continue; + c = strstr(c, "swig_ptr: "); + if (c) { int j; swig_const_info *ci = 0; const char *name = c + 10; diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index 110c431fe8e..8fbb3122613 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -344,8 +344,8 @@ namespace swig %feature("python:slot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__; #else %extend SwigPyIterator { - %pythoncode {def __iter__(self): - return self} + %pythoncode %{def __iter__(self): + return self%} } #endif diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg index ecbe7834e1e..80a0d68c67d 100644 --- a/Lib/python/pyopers.swg +++ b/Lib/python/pyopers.swg @@ -151,11 +151,11 @@ __bool__ = __nonzero__ They translate the inplace C++ operators (+=, -=, ...) into the corresponding python equivalents(__iadd__,__isub__), etc, - disabling the ownership of the input 'self' pointer, and assigning + disabling the ownership of the input 'this' pointer, and assigning it to the returning object: - %feature("del") *::Operator; - %feature("new") *::Operator; + %feature("del") *::Operator; // disables ownership by generating SWIG_POINTER_DISOWN + %feature("new") *::Operator; // claims ownership by generating SWIG_POINTER_OWN This makes the most common case safe, ie: @@ -174,8 +174,8 @@ __bool__ = __nonzero__ that never get deleted (maybe, not sure, it depends). But if that is the case, you could recover the old behaviour using - %feature("del","") A::operator+=; - %feature("new","") A::operator+=; + %feature("del","0") A::operator+=; + %feature("new","0") A::operator+=; which recovers the old behaviour for the class 'A', or if you are 100% sure your entire system works fine in the old way, use: @@ -183,6 +183,12 @@ __bool__ = __nonzero__ %feature("del","") *::operator+=; %feature("new","") *::operator+=; + The default behaviour assumes that the 'this' pointer's memory is + already owned by the SWIG object; it relinquishes ownership then + takes it back. This may not be the case though as the SWIG object + might be owned by memory managed elsewhere, eg after calling a + function that returns a C++ reference. In such case you will need + to use the features above to recover the old behaviour too. */ #if defined(SWIGPYTHON_BUILTIN) diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 30bb64f6608..fb5bbf6dfe9 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -67,7 +67,7 @@ SWIGINTERNINLINE PyObject* /* long */ %fragment(SWIG_From_frag(long),"header") { - %define_as(SWIG_From_dec(long), PyLong_FromLong) + %define_as(SWIG_From_dec(long), PyInt_FromLong) } %fragment(SWIG_AsVal_frag(long),"header", @@ -75,16 +75,20 @@ SWIGINTERNINLINE PyObject* SWIGINTERN int SWIG_AsVal_dec(long)(PyObject *obj, long* val) { +%#if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { if (val) *val = PyInt_AsLong(obj); return SWIG_OK; - } else if (PyLong_Check(obj)) { + } else +%#endif + if (PyLong_Check(obj)) { long v = PyLong_AsLong(obj); if (!PyErr_Occurred()) { if (val) *val = v; return SWIG_OK; } else { PyErr_Clear(); + return SWIG_OverflowError; } } %#ifdef SWIG_PYTHON_CAST_MODE @@ -119,7 +123,7 @@ SWIGINTERNINLINE PyObject* SWIG_From_dec(unsigned long)(unsigned long value) { return (value > LONG_MAX) ? - PyLong_FromUnsignedLong(value) : PyLong_FromLong(%numeric_cast(value,long)); + PyLong_FromUnsignedLong(value) : PyInt_FromLong(%numeric_cast(value,long)); } } @@ -146,18 +150,7 @@ SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) return SWIG_OK; } else { PyErr_Clear(); -%#if PY_VERSION_HEX >= 0x03000000 - { - long v = PyLong_AsLong(obj); - if (!PyErr_Occurred()) { - if (v < 0) { - return SWIG_OverflowError; - } - } else { - PyErr_Clear(); - } - } -%#endif + return SWIG_OverflowError; } } %#ifdef SWIG_PYTHON_CAST_MODE @@ -187,20 +180,22 @@ SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) /* long long */ %fragment(SWIG_From_frag(long long),"header", - fragment=SWIG_From_frag(long), - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE PyObject* SWIG_From_dec(long long)(long long value) { return ((value < LONG_MIN) || (value > LONG_MAX)) ? - PyLong_FromLongLong(value) : PyLong_FromLong(%numeric_cast(value,long)); + PyLong_FromLongLong(value) : PyInt_FromLong(%numeric_cast(value,long)); } +%#endif } %fragment(SWIG_AsVal_frag(long long),"header", fragment=SWIG_AsVal_frag(long), fragment="SWIG_CanCastAsInteger", - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(long long)(PyObject *obj, long long *val) { @@ -212,6 +207,7 @@ SWIG_AsVal_dec(long long)(PyObject *obj, long long *val) return SWIG_OK; } else { PyErr_Clear(); + res = SWIG_OverflowError; } } else { long v; @@ -236,25 +232,28 @@ SWIG_AsVal_dec(long long)(PyObject *obj, long long *val) %#endif return res; } +%#endif } /* unsigned long long */ %fragment(SWIG_From_frag(unsigned long long),"header", - fragment=SWIG_From_frag(long long), - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE PyObject* SWIG_From_dec(unsigned long long)(unsigned long long value) { return (value > LONG_MAX) ? - PyLong_FromUnsignedLongLong(value) : PyLong_FromLong(%numeric_cast(value,long)); + PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(%numeric_cast(value,long)); } +%#endif } %fragment(SWIG_AsVal_frag(unsigned long long),"header", fragment=SWIG_AsVal_frag(unsigned long), fragment="SWIG_CanCastAsInteger", - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val) { @@ -266,6 +265,7 @@ SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val) return SWIG_OK; } else { PyErr_Clear(); + res = SWIG_OverflowError; } } else { unsigned long v; @@ -289,6 +289,7 @@ SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val) %#endif return res; } +%#endif } /* double */ @@ -305,9 +306,11 @@ SWIG_AsVal_dec(double)(PyObject *obj, double *val) if (PyFloat_Check(obj)) { if (val) *val = PyFloat_AsDouble(obj); return SWIG_OK; +%#if PY_VERSION_HEX < 0x03000000 } else if (PyInt_Check(obj)) { if (val) *val = PyInt_AsLong(obj); return SWIG_OK; +%#endif } else if (PyLong_Check(obj)) { double v = PyLong_AsDouble(obj); if (!PyErr_Occurred()) { diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index a713486d105..08f0848d414 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -161,7 +161,7 @@ SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { /* Unpack the argument tuple */ -SWIGINTERN int +SWIGINTERN Py_ssize_t SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) { if (!args) { @@ -175,7 +175,7 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi } if (!PyTuple_Check(args)) { if (min <= 1 && max >= 1) { - int i; + Py_ssize_t i; objs[0] = args; for (i = 1; i < max; ++i) { objs[i] = 0; @@ -195,7 +195,7 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi name, (min == max ? "" : "at most "), (int)max, (int)l); return 0; } else { - int i; + Py_ssize_t i; for (i = 0; i < l; ++i) { objs[i] = PyTuple_GET_ITEM(args, i); } @@ -381,6 +381,23 @@ typedef struct { #endif } SwigPyObject; + +#ifdef SWIGPYTHON_BUILTIN + +SWIGRUNTIME PyObject * +SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) +{ + SwigPyObject *sobj = (SwigPyObject *)v; + + if (!sobj->dict) + sobj->dict = PyDict_New(); + + Py_INCREF(sobj->dict); + return sobj->dict; +} + +#endif + SWIGRUNTIME PyObject * SwigPyObject_long(SwigPyObject *v) { @@ -519,16 +536,32 @@ SwigPyObject_dealloc(PyObject *v) if (destroy) { /* destroy is always a VARARGS method */ PyObject *res; + + /* PyObject_CallFunction() has the potential to silently drop + the active active exception. In cases of unnamed temporary + variable or where we just finished iterating over a generator + StopIteration will be active right now, and this needs to + remain true upon return from SwigPyObject_dealloc. So save + and restore. */ + + PyObject *val = NULL, *type = NULL, *tb = NULL; + PyErr_Fetch(&val, &type, &tb); + if (data->delargs) { - /* we need to create a temporary object to carry the destroy operation */ - PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); - res = SWIG_Python_CallFunctor(destroy, tmp); - Py_DECREF(tmp); + /* we need to create a temporary object to carry the destroy operation */ + PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); + res = SWIG_Python_CallFunctor(destroy, tmp); + Py_DECREF(tmp); } else { - PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); - PyObject *mself = PyCFunction_GET_SELF(destroy); - res = ((*meth)(mself, v)); + PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); + PyObject *mself = PyCFunction_GET_SELF(destroy); + res = ((*meth)(mself, v)); } + if (!res) + PyErr_WriteUnraisable(destroy); + + PyErr_Restore(val, type, tb); + Py_XDECREF(res); } #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) @@ -552,6 +585,7 @@ SwigPyObject_append(PyObject* v, PyObject* next) next = tmp; #endif if (!SwigPyObject_Check(next)) { + PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject"); return NULL; } sobj->next = next; @@ -651,7 +685,7 @@ swigobject_methods[] = { static PyMethodDef swigobject_methods[] = { {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"acquires ownership of the pointer"}, {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, {(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, {(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, @@ -707,7 +741,9 @@ SwigPyObject_TypeOnce(void) { (unaryfunc)SwigPyObject_oct, /*nb_oct*/ (unaryfunc)SwigPyObject_hex, /*nb_hex*/ #endif -#if PY_VERSION_HEX >= 0x03000000 /* 3.0 */ +#if PY_VERSION_HEX >= 0x03050000 /* 3.5 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_matrix_multiply */ +#elif PY_VERSION_HEX >= 0x03000000 /* 3.0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ #elif PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ @@ -787,10 +823,19 @@ SwigPyObject_TypeOnce(void) { 0, /* tp_del */ #endif #if PY_VERSION_HEX >= 0x02060000 - 0, /* tp_version */ + 0, /* tp_version_tag */ +#endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ #endif }; swigpyobject_type = tmp; @@ -966,10 +1011,19 @@ SwigPyPacked_TypeOnce(void) { 0, /* tp_del */ #endif #if PY_VERSION_HEX >= 0x02060000 - 0, /* tp_version */ + 0, /* tp_version_tag */ +#endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ #endif }; swigpypacked_type = tmp; @@ -1420,18 +1474,21 @@ SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int f newobj = (SwigPyObject *) newobj->next; newobj->next = next_self; newobj = (SwigPyObject *)next_self; +#ifdef SWIGPYTHON_BUILTIN + newobj->dict = 0; +#endif } } else { newobj = PyObject_New(SwigPyObject, clientdata->pytype); +#ifdef SWIGPYTHON_BUILTIN + newobj->dict = 0; +#endif } if (newobj) { newobj->ptr = ptr; newobj->ty = type; newobj->own = own; newobj->next = 0; -#ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; -#endif return (PyObject*) newobj; } return SWIG_Py_Void(); @@ -1494,13 +1551,11 @@ PyModule_AddObject(PyObject *m, char *name, PyObject *o) { PyObject *dict; if (!PyModule_Check(m)) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs module as first arg"); + PyErr_SetString(PyExc_TypeError, "PyModule_AddObject() needs module as first arg"); return SWIG_ERROR; } if (!o) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs non-NULL value"); + PyErr_SetString(PyExc_TypeError, "PyModule_AddObject() needs non-NULL value"); return SWIG_ERROR; } diff --git a/Lib/python/pystrings.swg b/Lib/python/pystrings.swg index 2b14547adef..fd37855eb4f 100644 --- a/Lib/python/pystrings.swg +++ b/Lib/python/pystrings.swg @@ -6,13 +6,18 @@ SWIGINTERN int SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) { %#if PY_VERSION_HEX>=0x03000000 +%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) + if (PyBytes_Check(obj)) +%#else if (PyUnicode_Check(obj)) +%#endif %#else if (PyString_Check(obj)) %#endif { char *cstr; Py_ssize_t len; %#if PY_VERSION_HEX>=0x03000000 +%#if !defined(SWIG_PYTHON_STRICT_BYTE_CHAR) if (!alloc && cptr) { /* We can't allow converting without allocation, since the internal representation of string in Python 3 is UCS-2/UCS-4 but we require @@ -21,8 +26,9 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) return SWIG_RuntimeError; } obj = PyUnicode_AsUTF8String(obj); - PyBytes_AsStringAndSize(obj, &cstr, &len); if(alloc) *alloc = SWIG_NEWOBJ; +%#endif + PyBytes_AsStringAndSize(obj, &cstr, &len); %#else PyString_AsStringAndSize(obj, &cstr, &len); %#endif @@ -42,27 +48,58 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) %#else if (*alloc == SWIG_NEWOBJ) %#endif - { - *cptr = %new_copy_array(cstr, len + 1, char); - *alloc = SWIG_NEWOBJ; - } - else { + { + *cptr = %new_copy_array(cstr, len + 1, char); + *alloc = SWIG_NEWOBJ; + } else { *cptr = cstr; *alloc = SWIG_OLDOBJ; } } else { - %#if PY_VERSION_HEX>=0x03000000 - assert(0); /* Should never reach here in Python 3 */ - %#endif +%#if PY_VERSION_HEX>=0x03000000 +%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) + *cptr = PyBytes_AsString(obj); +%#else + assert(0); /* Should never reach here with Unicode strings in Python 3 */ +%#endif +%#else *cptr = SWIG_Python_str_AsChar(obj); +%#endif } } if (psize) *psize = len + 1; -%#if PY_VERSION_HEX>=0x03000000 +%#if PY_VERSION_HEX>=0x03000000 && !defined(SWIG_PYTHON_STRICT_BYTE_CHAR) Py_XDECREF(obj); %#endif return SWIG_OK; } else { +%#if defined(SWIG_PYTHON_2_UNICODE) +%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) +%#error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once" +%#endif +%#if PY_VERSION_HEX<0x03000000 + if (PyUnicode_Check(obj)) { + char *cstr; Py_ssize_t len; + if (!alloc && cptr) { + return SWIG_RuntimeError; + } + obj = PyUnicode_AsUTF8String(obj); + if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) { + if (cptr) { + if (alloc) *alloc = SWIG_NEWOBJ; + *cptr = %new_copy_array(cstr, len + 1, char); + } + if (psize) *psize = len + 1; + + Py_XDECREF(obj); + return SWIG_OK; + } else { + Py_XDECREF(obj); + } + } +%#endif +%#endif + swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); if (pchar_descriptor) { void* vptr = 0; @@ -89,13 +126,17 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size) SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void(); } else { %#if PY_VERSION_HEX >= 0x03000000 +%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) + return PyBytes_FromStringAndSize(carray, %numeric_cast(size, Py_ssize_t)); +%#else %#if PY_VERSION_HEX >= 0x03010000 - return PyUnicode_DecodeUTF8(carray, %numeric_cast(size,int), "surrogateescape"); + return PyUnicode_DecodeUTF8(carray, %numeric_cast(size, Py_ssize_t), "surrogateescape"); %#else - return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int)); + return PyUnicode_FromStringAndSize(carray, %numeric_cast(size, Py_ssize_t)); +%#endif %#endif %#else - return PyString_FromStringAndSize(carray, %numeric_cast(size,int)); + return PyString_FromStringAndSize(carray, %numeric_cast(size, Py_ssize_t)); %#endif } } else { @@ -104,4 +145,3 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size) } } - diff --git a/Lib/python/pythonkw.swg b/Lib/python/pythonkw.swg index 2f76a664af2..1a4329d20b3 100644 --- a/Lib/python/pythonkw.swg +++ b/Lib/python/pythonkw.swg @@ -8,10 +8,11 @@ /* Warnings for Python keywords - http://www.fnorb.org/docs/1.2/Fnorb-Guide/node62.html + https://docs.python.org/2/reference/lexical_analysis.html#keywords */ PYTHONKW(and); +PYTHONKW(as); PYTHONKW(assert); PYTHONKW(break); PYTHONKW(class); @@ -39,11 +40,12 @@ PYTHONKW(raise); PYTHONKW(return); PYTHONKW(try); PYTHONKW(while); +PYTHONKW(with); PYTHONKW(yield); /* built-in functions - http://www.zvon.org/other/python/doc21/lib/built-in-funcs.html + https://docs.python.org/2/library/functions.html */ PYTHONBN(abs); diff --git a/Lib/python/pywstrings.swg b/Lib/python/pywstrings.swg index 864376b01e9..e64618762c7 100644 --- a/Lib/python/pywstrings.swg +++ b/Lib/python/pywstrings.swg @@ -16,7 +16,7 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc) { PyObject *tmp = 0; int isunicode = PyUnicode_Check(obj); -%#if PY_VERSION_HEX < 0x03000000 +%#if PY_VERSION_HEX < 0x03000000 && !defined(SWIG_PYTHON_STRICT_UNICODE_WCHAR) if (!isunicode && PyString_Check(obj)) { obj = tmp = PyUnicode_FromObject(obj); isunicode = 1; @@ -58,7 +58,7 @@ SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size) return pwchar_descriptor ? SWIG_InternalNewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void(); } else { - return PyUnicode_FromWideChar(carray, %numeric_cast(size,int)); + return PyUnicode_FromWideChar(carray, %numeric_cast(size, Py_ssize_t)); } } else { return SWIG_Py_Void(); diff --git a/Lib/python/std_array.i b/Lib/python/std_array.i new file mode 100644 index 00000000000..bad818be72f --- /dev/null +++ b/Lib/python/std_array.i @@ -0,0 +1,91 @@ +/* + std::array +*/ + +%fragment("StdArrayTraits","header",fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(PyObject *obj, std::array **vec) { + return traits_asptr_stdseq >::asptr(obj, vec); + } + }; + + template + struct traits_from > { + static PyObject *from(const std::array& vec) { + return traits_from_stdseq >::from(vec); + } + }; + + template + inline void + assign(const SwigPySeq& swigpyseq, std::array* seq) { + if (swigpyseq.size() < seq->size()) + throw std::invalid_argument("std::array cannot be expanded in size"); + else if (swigpyseq.size() > seq->size()) + throw std::invalid_argument("std::array cannot be reduced in size"); + std::copy(swigpyseq.begin(), swigpyseq.end(), seq->begin()); + } + + template + inline void + erase(std::array* SWIGUNUSEDPARM(seq), const typename std::array::iterator& SWIGUNUSEDPARM(position)) { + throw std::invalid_argument("std::array object does not support item deletion"); + } + + // Only limited slicing is supported as std::array is fixed in size + template + inline std::array* + getslice(const std::array* self, Difference i, Difference j, Py_ssize_t step) { + typedef std::array Sequence; + typename Sequence::size_type size = self->size(); + Difference ii = 0; + Difference jj = 0; + swig::slice_adjust(i, j, step, size, ii, jj); + + if (step == 1 && ii == 0 && jj == size) { + Sequence *sequence = new Sequence(); + std::copy(self->begin(), self->end(), sequence->begin()); + return sequence; + } else if (step == -1 && ii == (size - 1) && jj == -1) { + Sequence *sequence = new Sequence(); + std::copy(self->rbegin(), self->rend(), sequence->begin()); + return sequence; + } else { + throw std::invalid_argument("std::array object only supports getting a slice that is the size of the array"); + } + } + + template + inline void + setslice(std::array* self, Difference i, Difference j, Py_ssize_t step, const InputSeq& is = InputSeq()) { + typedef std::array Sequence; + typename Sequence::size_type size = self->size(); + Difference ii = 0; + Difference jj = 0; + swig::slice_adjust(i, j, step, size, ii, jj, true); + + if (step == 1 && ii == 0 && jj == size) { + std::copy(is.begin(), is.end(), self->begin()); + } else if (step == -1 && ii == (size - 1) && jj == -1) { + std::copy(is.rbegin(), is.rend(), self->begin()); + } else { + throw std::invalid_argument("std::array object only supports setting a slice that is the size of the array"); + } + } + + template + inline void + delslice(std::array* SWIGUNUSEDPARM(self), Difference SWIGUNUSEDPARM(i), Difference SWIGUNUSEDPARM(j), Py_ssize_t SWIGUNUSEDPARM(step)) { + throw std::invalid_argument("std::array object does not support item deletion"); + } + } +%} + +#define %swig_array_methods(Type...) %swig_sequence_methods_non_resizable(Type) +#define %swig_array_methods_val(Type...) %swig_sequence_methods_non_resizable_val(Type); + +%include + diff --git a/Lib/python/std_common.i b/Lib/python/std_common.i index 401bbde7f83..605766238bb 100644 --- a/Lib/python/std_common.i +++ b/Lib/python/std_common.i @@ -13,17 +13,17 @@ fragment=SWIG_From_frag(Type), fragment="StdTraits") { namespace swig { - template <> struct traits { + template <> struct traits< Type > { typedef value_category category; static const char* type_name() { return #Type; } - }; - template <> struct traits_asval { + }; + template <> struct traits_asval< Type > { typedef Type value_type; - static int asval(PyObject *obj, value_type *val) { + static int asval(PyObject *obj, value_type *val) { return SWIG_AsVal(Type)(obj, val); } }; - template <> struct traits_from { + template <> struct traits_from< Type > { typedef Type value_type; static PyObject *from(const value_type& val) { return SWIG_From(Type)(val); @@ -46,13 +46,13 @@ namespace swig { fragment=SWIG_From_frag(int), fragment="StdTraits") { namespace swig { - template <> struct traits_asval { + template <> struct traits_asval< Type > { typedef Type value_type; - static int asval(PyObject *obj, value_type *val) { + static int asval(PyObject *obj, value_type *val) { return SWIG_AsVal(int)(obj, (int *)val); } }; - template <> struct traits_from { + template <> struct traits_from< Type > { typedef Type value_type; static PyObject *from(const value_type& val) { return SWIG_From(int)((int)val); diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 58902bca4a6..65dd91d9c8b 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -119,10 +119,9 @@ static PyObject *asdict(const map_type& map) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; size_type size = map.size(); - int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (size_type) INT_MAX) ? (Py_ssize_t) size : -1; if (pysize < 0) { - PyErr_SetString(PyExc_OverflowError, - "map size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "map size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } @@ -176,14 +175,14 @@ #else %extend { - %pythoncode {def __iter__(self): - return self.key_iterator()} - %pythoncode {def iterkeys(self): - return self.key_iterator()} - %pythoncode {def itervalues(self): - return self.value_iterator()} - %pythoncode {def iteritems(self): - return self.iterator()} + %pythoncode %{def __iter__(self): + return self.key_iterator()%} + %pythoncode %{def iterkeys(self): + return self.key_iterator()%} + %pythoncode %{def itervalues(self): + return self.value_iterator()%} + %pythoncode %{def iteritems(self): + return self.iterator()%} } #endif @@ -211,17 +210,16 @@ PyObject* keys() { Map::size_type size = self->size(); - int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1; SWIG_PYTHON_THREAD_BEGIN_BLOCK; if (pysize < 0) { - PyErr_SetString(PyExc_OverflowError, - "map size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "map size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } PyObject* keyList = PyList_New(pysize); Map::const_iterator i = self->begin(); - for (int j = 0; j < pysize; ++i, ++j) { + for (Py_ssize_t j = 0; j < pysize; ++i, ++j) { PyList_SET_ITEM(keyList, j, swig::from(i->first)); } SWIG_PYTHON_THREAD_END_BLOCK; @@ -230,17 +228,16 @@ PyObject* values() { Map::size_type size = self->size(); - int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1; SWIG_PYTHON_THREAD_BEGIN_BLOCK; if (pysize < 0) { - PyErr_SetString(PyExc_OverflowError, - "map size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "map size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } PyObject* valList = PyList_New(pysize); Map::const_iterator i = self->begin(); - for (int j = 0; j < pysize; ++i, ++j) { + for (Py_ssize_t j = 0; j < pysize; ++i, ++j) { PyList_SET_ITEM(valList, j, swig::from(i->second)); } SWIG_PYTHON_THREAD_END_BLOCK; @@ -249,17 +246,16 @@ PyObject* items() { Map::size_type size = self->size(); - int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1; SWIG_PYTHON_THREAD_BEGIN_BLOCK; if (pysize < 0) { - PyErr_SetString(PyExc_OverflowError, - "map size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "map size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } PyObject* itemList = PyList_New(pysize); Map::const_iterator i = self->begin(); - for (int j = 0; j < pysize; ++i, ++j) { + for (Py_ssize_t j = 0; j < pysize; ++i, ++j) { PyList_SET_ITEM(itemList, j, swig::from(*i)); } SWIG_PYTHON_THREAD_END_BLOCK; diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i index c81e2ac5d62..2c539cf29d3 100644 --- a/Lib/python/std_multimap.i +++ b/Lib/python/std_multimap.i @@ -45,11 +45,10 @@ return SWIG_InternalNewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN); } else { size_type size = multimap.size(); - int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (size_type) INT_MAX) ? (Py_ssize_t) size : -1; if (pysize < 0) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(PyExc_OverflowError, - "multimap size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "multimap size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index 73d47e1980b..5694e7e09e1 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -176,7 +176,7 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c) %define %swig_pair_methods(pair...) #if !defined(SWIGPYTHON_BUILTIN) %extend { -%pythoncode {def __len__(self): +%pythoncode %{def __len__(self): return 2 def __repr__(self): return str((self.first, self.second)) @@ -189,7 +189,7 @@ def __setitem__(self, index, val): if not (index % 2): self.first = val else: - self.second = val} + self.second = val%} } #endif %enddef diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i index 73746823411..f956f4fb382 100644 --- a/Lib/python/std_unordered_map.i +++ b/Lib/python/std_unordered_map.i @@ -48,11 +48,10 @@ return SWIG_NewPointerObj(new unordered_map_type(unordered_map), desc, SWIG_POINTER_OWN); } else { size_type size = unordered_map.size(); - int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (size_type) INT_MAX) ? (Py_ssize_t) size : -1; if (pysize < 0) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(PyExc_OverflowError, - "unordered_map size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "unordered_map size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } @@ -164,17 +163,16 @@ PyObject* keys() { Map::size_type size = self->size(); - int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1; if (pysize < 0) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(PyExc_OverflowError, - "unordered_map size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "unordered_map size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } PyObject* keyList = PyList_New(pysize); Map::const_iterator i = self->begin(); - for (int j = 0; j < pysize; ++i, ++j) { + for (Py_ssize_t j = 0; j < pysize; ++i, ++j) { PyList_SET_ITEM(keyList, j, swig::from(i->first)); } return keyList; @@ -182,17 +180,16 @@ PyObject* values() { Map::size_type size = self->size(); - int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1; if (pysize < 0) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(PyExc_OverflowError, - "unordered_map size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "unordered_map size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } PyObject* valList = PyList_New(pysize); Map::const_iterator i = self->begin(); - for (int j = 0; j < pysize; ++i, ++j) { + for (Py_ssize_t j = 0; j < pysize; ++i, ++j) { PyList_SET_ITEM(valList, j, swig::from(i->second)); } return valList; @@ -200,17 +197,16 @@ PyObject* items() { Map::size_type size = self->size(); - int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (Map::size_type) INT_MAX) ? (Py_ssize_t) size : -1; if (pysize < 0) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(PyExc_OverflowError, - "unordered_map size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "unordered_map size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } PyObject* itemList = PyList_New(pysize); Map::const_iterator i = self->begin(); - for (int j = 0; j < pysize; ++i, ++j) { + for (Py_ssize_t j = 0; j < pysize; ++i, ++j) { PyList_SET_ITEM(itemList, j, swig::from(*i)); } return itemList; @@ -231,14 +227,14 @@ return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); } - %pythoncode {def __iter__(self): - return self.key_iterator()} - %pythoncode {def iterkeys(self): - return self.key_iterator()} - %pythoncode {def itervalues(self): - return self.value_iterator()} - %pythoncode {def iteritems(self): - return self.iterator()} + %pythoncode %{def __iter__(self): + return self.key_iterator()%} + %pythoncode %{def iterkeys(self): + return self.key_iterator()%} + %pythoncode %{def itervalues(self): + return self.value_iterator()%} + %pythoncode %{def iteritems(self): + return self.iterator()%} } %enddef diff --git a/Lib/python/std_unordered_multimap.i b/Lib/python/std_unordered_multimap.i index adf86f251c9..b3b723637c6 100644 --- a/Lib/python/std_unordered_multimap.i +++ b/Lib/python/std_unordered_multimap.i @@ -45,11 +45,10 @@ return SWIG_NewPointerObj(new unordered_multimap_type(unordered_multimap), desc, SWIG_POINTER_OWN); } else { size_type size = unordered_multimap.size(); - int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + Py_ssize_t pysize = (size <= (size_type) INT_MAX) ? (Py_ssize_t) size : -1; if (pysize < 0) { SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(PyExc_OverflowError, - "unordered_multimap size not valid in python"); + PyErr_SetString(PyExc_OverflowError, "unordered_multimap size not valid in python"); SWIG_PYTHON_THREAD_END_BLOCK; return NULL; } diff --git a/Lib/r/boost_shared_ptr.i b/Lib/r/boost_shared_ptr.i index 17e9cfe8a0e..8ef8d2ef239 100644 --- a/Lib/r/boost_shared_ptr.i +++ b/Lib/r/boost_shared_ptr.i @@ -40,7 +40,7 @@ %variable_fail(res, "$type", "$name"); } if (!argp) { - %argument_nullref("$type", $symname, $argnum); + %variable_nullref("$type", "$name"); } else { $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); @@ -124,7 +124,9 @@ %variable_fail(res, "$type", "$name"); } SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; - if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (!argp) { + %variable_nullref("$type", "$name"); + } if (newmem & SWIG_CAST_NEW_MEMORY) { tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); diff --git a/Lib/r/r.swg b/Lib/r/r.swg index 126611d619e..a6014965e15 100644 --- a/Lib/r/r.swg +++ b/Lib/r/r.swg @@ -264,8 +264,8 @@ x setAs('ExternalReference', 'character', function(from) {if (!is.null(from$"__str__")) from$"__str__"()}) -setMethod('print', 'ExternalReference', -function(x) {print(as(x, "character"))}) +suppressWarnings(setMethod('print', 'ExternalReference', +function(x) {print(as(x, "character"))})) %} diff --git a/Lib/r/rfragments.swg b/Lib/r/rfragments.swg index 2ec8f867f15..b89212b057c 100644 --- a/Lib/r/rfragments.swg +++ b/Lib/r/rfragments.swg @@ -44,21 +44,27 @@ SWIG_AsVal_dec(long)(SEXP obj, long *val) } -%fragment(SWIG_From_frag(long long),"header") { +%fragment(SWIG_From_frag(long long),"header", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE SEXP SWIG_From_dec(long long)(long long value) { return Rf_ScalarInteger((int)value); } +%#endif } -%fragment(SWIG_AsVal_frag(long long),"header") { +%fragment(SWIG_AsVal_frag(long long),"header", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE int SWIG_AsVal_dec(long long)(SEXP obj, long long *val) { if (val) *val = Rf_asInteger(obj); return SWIG_OK; } +%#endif } %fragment(SWIG_From_frag(unsigned long),"header") { @@ -80,22 +86,28 @@ SWIG_AsVal_dec(unsigned long)(SEXP obj, unsigned long *val) } -%fragment(SWIG_From_frag(unsigned long long),"header") { +%fragment(SWIG_From_frag(unsigned long long),"header", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE SEXP SWIG_From_dec(unsigned long long)(unsigned long long value) { return Rf_ScalarInteger((int)value); } +%#endif } -%fragment(SWIG_AsVal_frag(unsigned long long),"header") { +%fragment(SWIG_AsVal_frag(unsigned long long),"header", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE int SWIG_AsVal_dec(unsigned long long)(SEXP obj, unsigned long long *val) { if (val) *val = Rf_asInteger(obj); return SWIG_OK; } +%#endif } %fragment(SWIG_From_frag(double),"header") { diff --git a/Lib/r/rkw.swg b/Lib/r/rkw.swg index 2c181faa0ab..074d7dfd96b 100644 --- a/Lib/r/rkw.swg +++ b/Lib/r/rkw.swg @@ -3,6 +3,7 @@ */ #define RKW(x) %keywordwarn("'" `x` "' is a R keyword, renaming to '_" `x`"'", rename="_%s") `x` +#define RSWIGKW(x) %keywordwarn("'" `x` "' is a SWIG R reserved parameter name, renaming to '_" `x`"'", rename="_%s") `x` /* Warnings for R reserved words taken from @@ -29,4 +30,7 @@ RKW(NA_real_); RKW(NA_complex_); RKW(NA_character_); +RSWIGKW(self); + #undef RKW +#undef RSWIGKW diff --git a/Lib/r/srun.swg b/Lib/r/srun.swg index 71a508d49af..2045ab94e4c 100644 --- a/Lib/r/srun.swg +++ b/Lib/r/srun.swg @@ -62,7 +62,7 @@ function(className, ..., append = TRUE) if(!isGeneric("copyToC")) setGeneric("copyToC", - function(value, obj = RSWIG_createNewRef(class(value))) + function(value, obj = SWIG_createNewRef(class(value))) standardGeneric("copyToC" )) @@ -147,4 +147,4 @@ function(fun, userData = NULL) } -####################################################################### \ No newline at end of file +####################################################################### diff --git a/Lib/r/std_common.i b/Lib/r/std_common.i index 8e97521b02d..cda26231054 100644 --- a/Lib/r/std_common.i +++ b/Lib/r/std_common.i @@ -12,17 +12,17 @@ fragment=SWIG_From_frag(Type), fragment="StdTraits") { namespace swig { - template <> struct traits { + template <> struct traits< Type > { typedef value_category category; static const char* type_name() { return #Type; } - }; - template <> struct traits_asval { + }; + template <> struct traits_asval< Type > { typedef Type value_type; - static int asval(SEXP obj, value_type *val) { + static int asval(SEXP obj, value_type *val) { return SWIG_AsVal(Type)(obj, val); } }; - template <> struct traits_from { + template <> struct traits_from< Type > { typedef Type value_type; static SEXP from(const value_type& val) { return SWIG_From(Type)(val); @@ -45,13 +45,13 @@ namespace swig { fragment=SWIG_From_frag(int), fragment="StdTraits") { namespace swig { - template <> struct traits_asval { + template <> struct traits_asval< Type > { typedef Type value_type; - static int asval(SEXP obj, value_type *val) { + static int asval(SEXP obj, value_type *val) { return SWIG_AsVal(int)(obj, (int *)val); } }; - template <> struct traits_from { + template <> struct traits_from< Type > { typedef Type value_type; static SEXP from(const value_type& val) { return SWIG_From(int)((int)val); diff --git a/Lib/ruby/boost_shared_ptr.i b/Lib/ruby/boost_shared_ptr.i new file mode 100644 index 00000000000..938074d8181 --- /dev/null +++ b/Lib/ruby/boost_shared_ptr.i @@ -0,0 +1,323 @@ +%include + +// Set SHARED_PTR_DISOWN to $disown if required, for example +// #define SHARED_PTR_DISOWN $disown +#if !defined(SHARED_PTR_DISOWN) +#define SHARED_PTR_DISOWN 0 +#endif + +%fragment("SWIG_null_deleter_python", "header", fragment="SWIG_null_deleter") { +%#define SWIG_NO_NULL_DELETER_SWIG_BUILTIN_INIT +} + +// Language specific macro implementing all the customisations for handling the smart pointer +%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) + +// %naturalvar is as documented for member variables +%naturalvar TYPE; +%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + +// destructor wrapper customisation +%feature("unref") TYPE + %{(void)arg1; + delete reinterpret_cast< SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > * >(self);%} + +// Typemap customisations... + +// plain value +%typemap(in) CONST TYPE (void *argp, int res = 0) { + swig_ruby_owntype newmem = {0, 0}; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { + %argument_nullref("$type", $symname, $argnum); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem.own & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(out) CONST TYPE { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE { + void *argp = 0; + swig_ruby_owntype newmem = {0, 0}; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + if (!argp) { + %variable_nullref("$type", "$name"); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem.own & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(varout) CONST TYPE { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain pointer +// Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance +%typemap(in) CONST TYPE * (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) { + swig_ruby_owntype newmem = {0, 0}; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem.own & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} + +%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE * { + void *argp = 0; + swig_ruby_owntype newmem = {0, 0}; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0; + if (newmem.own & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain reference +%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + swig_ruby_owntype newmem = {0, 0}; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (newmem.own & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + $1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); + } +} +%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE & { + void *argp = 0; + swig_ruby_owntype newmem = {0, 0}; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + if (!argp) { + %variable_nullref("$type", "$name"); + } + if (newmem.own & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = *%const_cast(tempshared.get(), $1_ltype); + } else { + $1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain pointer by reference +// Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + swig_ruby_owntype newmem = {0, 0}; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem.own & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + temp = %const_cast(tempshared.get(), $*1_ltype); + } else { + temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype); + } + $1 = &temp; +} +%typemap(out, fragment="SWIG_null_deleter_python") TYPE *CONST& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) TYPE *CONST& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) TYPE *CONST& %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by value +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) { + swig_ruby_owntype newmem = {0, 0}; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) $1 = *(%reinterpret_cast(argp, $<ype)); + if (newmem.own & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + swig_ruby_owntype newmem = {0, 0}; + void *argp = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + $1 = argp ? *(%reinterpret_cast(argp, $<ype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >(); + if (newmem.own & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// shared_ptr by reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) { + swig_ruby_owntype newmem = {0, 0}; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem.own & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) { + swig_ruby_owntype newmem = {0, 0}; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem.own & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + if ($owner) delete $1; +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) { + swig_ruby_owntype newmem = {0, 0}; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) tempshared = *%reinterpret_cast(argp, $*ltype); + if (newmem.own & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype); + temp = &tempshared; + $1 = &temp; +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varout typemap not implemented" +%} + +// Typecheck typemaps +// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting +// function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + int res = SWIG_ConvertPtr($input, 0, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), 0); + $1 = SWIG_CheckState(res); +} + + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} + + +%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + + +%enddef diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index c2c4150e63f..c6c53a343dc 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -29,8 +29,9 @@ namespace Swig { virtual ~GCItem() { } - virtual ruby_owntype get_own() const { - return 0; + virtual swig_ruby_owntype get_own() const { + swig_ruby_owntype own = {0, 0}; + return own; } }; @@ -72,18 +73,18 @@ namespace Swig { }; struct GCItem_Object : GCItem { - GCItem_Object(ruby_owntype own) : _own(own) { + GCItem_Object(swig_ruby_owntype own) : _own(own) { } virtual ~GCItem_Object() { } - ruby_owntype get_own() const { + swig_ruby_owntype get_own() const { return _own; } private: - ruby_owntype _own; + swig_ruby_owntype _own; }; template @@ -278,7 +279,7 @@ namespace Swig { mutable bool swig_disown_flag; public: - /* wrap a Ruby object, optionally taking ownership */ + /* wrap a Ruby object. */ Director(VALUE self) : swig_self(self), swig_disown_flag(false) { } @@ -323,20 +324,20 @@ namespace Swig { } } - void swig_acquire_ownership_obj(void *vptr, ruby_owntype own) const { - if (vptr && own) { + void swig_acquire_ownership_obj(void *vptr, swig_ruby_owntype own) const { + if (vptr && own.datafree) { SWIG_GUARD(swig_mutex_own); swig_owner[vptr] = new GCItem_Object(own); } } - ruby_owntype swig_release_ownership(void *vptr) const { - ruby_owntype own = 0; + swig_ruby_owntype swig_release_ownership(void *vptr) const { + swig_ruby_owntype own = {0, 0}; if (vptr) { SWIG_GUARD(swig_mutex_own); swig_ownership_map::iterator iter = swig_owner.find(vptr); if (iter != swig_owner.end()) { - own = iter->second->get_own(); + own.datafree = iter->second->get_own().datafree; swig_owner.erase(iter); } } diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index 69db367d972..2908ef7b739 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -91,11 +91,17 @@ namespace swig { return pos; } + template + inline void + resize(Sequence *seq, typename Sequence::size_type n, typename Sequence::value_type x) { + seq->resize(n, x); + } + template inline Sequence* getslice(const Sequence* self, Difference i, Difference j) { typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size); + typename Sequence::size_type ii = swig::check_index(i, size, (i == size && j == size)); typename Sequence::size_type jj = swig::slice_index(j, size); if (jj > ii) { @@ -164,7 +170,6 @@ namespace swig * of an element of a Ruby Array of stuff. * It can be used by RubySequence_InputIterator to make it work with STL * algorithms. - * */ template struct RubySequence_Ref @@ -210,7 +215,6 @@ namespace swig * RubySequence_Ref. * It can be used by RubySequence_InputIterator to make it work with STL * algorithms. - * */ template struct RubySequence_ArrowProxy @@ -225,7 +229,6 @@ namespace swig /** * Input Iterator. This adapator class is a random access iterator that * allows you to use STL algorithms with a Ruby class (a Ruby Array by default). - * */ template > struct RubySequence_InputIterator @@ -326,7 +329,6 @@ namespace swig /** * This adaptor class allows you to use a Ruby Array as if it was an STL * container, giving it begin(), end(), and iterators. - * */ template struct RubySequence_Cont @@ -419,7 +421,6 @@ namespace swig /** * Macros used to typemap an STL iterator -> SWIGIterator conversion. - * */ %define %swig_sequence_iterator(Sequence...) #if defined(SWIG_EXPORT_ITERATOR_METHODS) @@ -549,7 +550,6 @@ namespace swig /** * Macro used to define common Ruby printing methods for STL container - * */ %define %swig_sequence_printing_methods(Sequence...) @@ -609,9 +609,8 @@ namespace swig /** * Macro used to add common methods to all STL sequence-type containers - * */ -%define %swig_sequence_methods_common(Sequence...) +%define %swig_sequence_methods_non_resizable_common(Sequence...) %swig_container_methods(%arg(Sequence)) %swig_sequence_iterator(%arg(Sequence)) %swig_sequence_printing_methods(%arg(Sequence)) @@ -620,24 +619,28 @@ namespace swig %extend { + VALUE slice( difference_type i, difference_type length ) throw (std::invalid_argument) { + if ( length < 0 ) + return Qnil; + std::size_t len = $self->size(); + if ( i < 0 ) { + if ( i + static_cast(len) < 0 ) + return Qnil; + else + i = len + i; + } + Sequence::difference_type j = length + i; + if ( j > static_cast(len) ) + j = len; - VALUE slice( difference_type i, difference_type j ) - { - if ( j <= 0 ) return Qnil; - std::size_t len = $self->size(); - if ( i < 0 ) i = len - i; - j += i; - if ( static_cast(j) >= len ) j = len-1; - - VALUE r = Qnil; - try { - r = swig::from< const Sequence* >( swig::getslice(self, i, j) ); - } - catch( std::out_of_range ) - { - } - return r; + VALUE r = Qnil; + try { + r = swig::from< const Sequence* >( swig::getslice(self, i, j) ); } + catch( std::out_of_range ) { + } + return r; + } Sequence* each() @@ -657,12 +660,23 @@ namespace swig return self; } + VALUE __delete2__(const value_type& i) { + VALUE r = Qnil; + return r; + } + + } +%enddef + +%define %swig_sequence_methods_resizable_common(Sequence...) + %extend { + %newobject select; Sequence* select() { if ( !rb_block_given_p() ) rb_raise( rb_eArgError, "no block given" ); - Sequence* r = new Sequence; + Sequence* r = new Sequence(); Sequence::const_iterator i = $self->begin(); Sequence::const_iterator e = $self->end(); for ( ; i != e; ++i ) @@ -687,21 +701,17 @@ namespace swig } return r; } - - - VALUE __delete2__(const value_type& i) { - VALUE r = Qnil; - return r; - } - } %enddef +%define %swig_sequence_methods_common(Sequence...) + %swig_sequence_methods_non_resizable_common(%arg(Sequence)) + %swig_sequence_methods_resizable_common(%arg(Sequence)) +%enddef /** * Macro used to add functions for back insertion of values in - * STL Sequence containers - * + * STL sequence containers */ %define %swig_sequence_back_inserters( Sequence... ) %extend { @@ -724,7 +734,7 @@ namespace swig if ( !rb_block_given_p() ) rb_raise( rb_eArgError, "no block given" ); - Sequence* r = new Sequence; + Sequence* r = new Sequence(); std::remove_copy_if( $self->begin(), $self->end(), std::back_inserter(*r), swig::yield< Sequence::value_type >() ); @@ -748,15 +758,7 @@ namespace swig } %enddef -/** - * Macro used to add functions for Sequences - * - */ -%define %swig_sequence_methods(Sequence...) - %swig_sequence_methods_common(%arg(Sequence)); - %swig_sequence_methods_extra(%arg(Sequence)); - %swig_sequence_back_inserters(%arg(Sequence)); - +%define %swig_sequence_methods_non_resizable_accessors(Sequence...) %extend { VALUE at(difference_type i) const { @@ -764,25 +766,31 @@ namespace swig try { r = swig::from< Sequence::value_type >( *(swig::cgetpos(self, i)) ); } - catch( std::out_of_range ) - { - } + catch( std::out_of_range ) { + } return r; } - VALUE __getitem__(difference_type i, difference_type j) const { - if ( j <= 0 ) return Qnil; + VALUE __getitem__(difference_type i, difference_type length) const throw (std::invalid_argument) { + if ( length < 0 ) + return Qnil; std::size_t len = $self->size(); - if ( i < 0 ) i = len - i; - j += i; if ( static_cast(j) >= len ) j = len-1; + if ( i < 0 ) { + if ( i + static_cast(len) < 0 ) + return Qnil; + else + i = len + i; + } + Sequence::difference_type j = length + i; + if ( j > static_cast(len) ) + j = len; VALUE r = Qnil; try { r = swig::from< const Sequence* >( swig::getslice(self, i, j) ); } - catch( std::out_of_range ) - { - } + catch( std::out_of_range ) { + } return r; } @@ -791,17 +799,15 @@ namespace swig try { r = swig::from< Sequence::value_type >( *(swig::cgetpos(self, i)) ); } - catch( std::out_of_range ) - { - } + catch( std::out_of_range ) { + } return r; } - VALUE __getitem__(VALUE i) const { - if ( rb_obj_is_kind_of( i, rb_cRange ) == Qfalse ) - { - rb_raise( rb_eTypeError, "not a valid index or range" ); - } + VALUE __getitem__(VALUE i) const throw (std::invalid_argument) { + if ( rb_obj_is_kind_of( i, rb_cRange ) == Qfalse ) { + rb_raise( rb_eTypeError, "not a valid index or range" ); + } static ID id_end = rb_intern("end"); static ID id_start = rb_intern("begin"); @@ -814,53 +820,81 @@ namespace swig int len = $self->size(); int s = NUM2INT( start ); - if ( s < 0 ) s = len + s; - else if ( s >= len ) return Qnil; + if ( s < 0 ) { + s = len + s; + if ( s < 0 ) + return Qnil; + } else if ( s > len ) + return Qnil; int e = NUM2INT( end ); if ( e < 0 ) e = len + e; - - if ( e < s ) return Qnil; //std::swap( s, e ); - if ( noend ) e -= 1; + if ( e < 0 ) e = -1; if ( e >= len ) e = len - 1; + if ( s == len ) e = len - 1; return swig::from< Sequence* >( swig::getslice(self, s, e+1) ); } - VALUE __setitem__(difference_type i, const value_type& x) + VALUE __setitem__(difference_type i, const value_type& x) throw (std::invalid_argument, std::out_of_range) { - std::size_t len = $self->size(); - if ( i < 0 ) i = len - i; - else if ( static_cast(i) >= len ) - $self->resize( i+1, x ); - else - *(swig::getpos(self,i)) = x; + if ( i >= static_cast( $self->size()) ) + swig::resize( $self, i+1, x ); + else + *(swig::getpos($self, i)) = x; return swig::from< Sequence::value_type >( x ); } - VALUE __setitem__(difference_type i, difference_type j, const Sequence& v) - throw (std::invalid_argument) { + VALUE __setitem__(difference_type i, difference_type length, const Sequence& v) throw (std::invalid_argument) { - if ( j <= 0 ) return Qnil; + if ( length < 0 ) + return Qnil; std::size_t len = $self->size(); - if ( i < 0 ) i = len - i; - j += i; - if ( static_cast(j) >= len ) { - $self->resize( j+1, *(v.begin()) ); - j = len-1; + if ( i < 0 ) { + if ( i + static_cast(len) < 0 ) + return Qnil; + else + i = len + i; + } + Sequence::difference_type j = length + i; + if ( j > static_cast(len) ) { + swig::resize( $self, j, *(v.begin()) ); } VALUE r = Qnil; - swig::setslice(self, i, j, v); + swig::setslice($self, i, j, v); r = swig::from< const Sequence* >( &v ); return r; } - } %enddef +/** + * Macro used to add functions for non resizable sequences + */ +%define %swig_sequence_methods_non_resizable(Sequence...) + %swig_sequence_methods_non_resizable_common(%arg(Sequence)) + %swig_sequence_methods_non_resizable_accessors(%arg(Sequence)) +%enddef + + +/** + * Macro used to add functions for sequences + */ +%define %swig_sequence_methods(Sequence...) + %swig_sequence_methods_non_resizable_common(%arg(Sequence)) + %swig_sequence_methods_resizable_common(%arg(Sequence)) + %swig_sequence_methods_non_resizable_accessors(%arg(Sequence)) + %swig_sequence_methods_extra(%arg(Sequence)); + %swig_sequence_back_inserters(%arg(Sequence)); +%enddef + +%define %swig_sequence_methods_non_resizable_val(Sequence...) + %swig_sequence_methods_non_resizable(%arg(Sequence)) +%enddef + %define %swig_sequence_methods_val(Sequence...) %swig_sequence_methods(%arg(Sequence)) %enddef @@ -869,10 +903,8 @@ namespace swig /** * Macro used to add functions for front insertion of * elements in STL sequence containers that support it. - * */ %define %swig_sequence_front_inserters( Sequence... ) - %extend { VALUE shift() @@ -952,7 +984,6 @@ namespace swig return $self; } - } %enddef diff --git a/Lib/ruby/rubyprimtypes.swg b/Lib/ruby/rubyprimtypes.swg index aa4f7ad374b..3a848191cd7 100644 --- a/Lib/ruby/rubyprimtypes.swg +++ b/Lib/ruby/rubyprimtypes.swg @@ -124,15 +124,20 @@ SWIG_AsVal_dec(unsigned long)(VALUE obj, unsigned long *val) %fragment(SWIG_From_frag(long long),"header", fragment=SWIG_From_frag(long), - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE VALUE SWIG_From_dec(long long)(long long value) { return LL2NUM(value); } +%#endif } -%fragment(SWIG_AsVal_frag(long long),"header",fragment="SWIG_ruby_failed") { +%fragment(SWIG_AsVal_frag(long long),"header", + fragment="SWIG_ruby_failed", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE %ruby_aux_method(long long, NUM2LL, type == T_FIXNUM ? NUM2LL(obj) : rb_big2ll(obj)) SWIGINTERN int @@ -151,21 +156,26 @@ SWIG_AsVal_dec(long long)(VALUE obj, long long *val) } return SWIG_TypeError; } +%#endif } /* unsigned long long */ %fragment(SWIG_From_frag(unsigned long long),"header", - fragment=SWIG_From_frag(long long), - fragment="") { + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE VALUE SWIG_From_dec(unsigned long long)(unsigned long long value) { return ULL2NUM(value); } +%#endif } -%fragment(SWIG_AsVal_frag(unsigned long long),"header",fragment="SWIG_ruby_failed") { +%fragment(SWIG_AsVal_frag(unsigned long long),"header", + fragment="SWIG_ruby_failed", + fragment="SWIG_LongLongAvailable") { +%#ifdef SWIG_LONG_LONG_AVAILABLE %ruby_aux_method(long long, NUM2ULL, type == T_FIXNUM ? NUM2ULL(obj) : rb_big2ull(obj)) SWIGINTERN int @@ -184,6 +194,7 @@ SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val) } return SWIG_TypeError; } +%#endif } /* double */ diff --git a/Lib/ruby/rubyrun.swg b/Lib/ruby/rubyrun.swg index c3e0b749b96..e18208f902c 100644 --- a/Lib/ruby/rubyrun.swg +++ b/Lib/ruby/rubyrun.swg @@ -14,7 +14,7 @@ #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, own) #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags) #define SWIG_AcquirePtr(ptr, own) SWIG_Ruby_AcquirePtr(ptr, own) -#define swig_owntype ruby_owntype +#define swig_owntype swig_ruby_owntype /* for raw packed data */ #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags) @@ -238,22 +238,24 @@ SWIG_Ruby_MangleStr(VALUE obj) } /* Acquire a pointer value */ -typedef void (*ruby_owntype)(void*); +typedef struct { + void (*datafree)(void *); + int own; +} swig_ruby_owntype; -SWIGRUNTIME ruby_owntype -SWIG_Ruby_AcquirePtr(VALUE obj, ruby_owntype own) { +SWIGRUNTIME swig_ruby_owntype +SWIG_Ruby_AcquirePtr(VALUE obj, swig_ruby_owntype own) { + swig_ruby_owntype oldown = {0, 0}; if (obj) { - ruby_owntype oldown = RDATA(obj)->dfree; - RDATA(obj)->dfree = own; - return oldown; - } else { - return 0; + oldown.datafree = RDATA(obj)->dfree; + RDATA(obj)->dfree = own.datafree; } + return oldown; } /* Convert a pointer value */ SWIGRUNTIME int -SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, ruby_owntype *own) +SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, swig_ruby_owntype *own) { char *c; swig_cast_info *tc; @@ -261,7 +263,8 @@ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, /* Grab the pointer */ if (NIL_P(obj)) { - *ptr = 0; + if (ptr) + *ptr = 0; return SWIG_OK; } else { if (TYPE(obj) != T_DATA) { @@ -270,7 +273,10 @@ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, Data_Get_Struct(obj, void, vptr); } - if (own) *own = RDATA(obj)->dfree; + if (own) { + own->datafree = RDATA(obj)->dfree; + own->own = 0; + } /* Check to see if the input object is giving up ownership of the underlying C struct or C++ object. If so then we @@ -299,16 +305,6 @@ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, /* Do type-checking if type info was provided */ if (ty) { - if (ty->clientdata) { - if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) { - if (vptr == 0) { - /* The object has already been deleted */ - return SWIG_ObjectPreviouslyDeletedError; - } - *ptr = vptr; - return SWIG_OK; - } - } if ((c = SWIG_MangleStr(obj)) == NULL) { return SWIG_ERROR; } @@ -316,12 +312,27 @@ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, if (!tc) { return SWIG_ERROR; } else { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc, vptr, &newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ + if (vptr == 0) { + /* The object has already been deleted */ + return SWIG_ObjectPreviouslyDeletedError; + } + if (ptr) { + if (tc->type == ty) { + *ptr = vptr; + } else { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc, vptr, &newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ + if (own) + own->own = own->own | SWIG_CAST_NEW_MEMORY; + } + } + } } } else { - *ptr = vptr; + if (ptr) + *ptr = vptr; } return SWIG_OK; diff --git a/Lib/ruby/rubytracking.swg b/Lib/ruby/rubytracking.swg index 0a36f4a05d4..8f9f01be873 100644 --- a/Lib/ruby/rubytracking.swg +++ b/Lib/ruby/rubytracking.swg @@ -11,6 +11,11 @@ extern "C" { #endif +#if !defined(ST_DATA_T_DEFINED) +/* Needs to be explicitly included for Ruby 1.8 and earlier */ +#include +#endif + /* Ruby 1.8 actually assumes the first case. */ #if SIZEOF_VOIDP == SIZEOF_LONG # define SWIG2NUM(v) LONG2NUM((unsigned long)v) @@ -22,19 +27,19 @@ extern "C" { # error sizeof(void*) is not the same as long or long long #endif - -/* Global Ruby hash table to store Trackings from C/C++ +/* Global hash table to store Trackings from C/C++ structs to Ruby Objects. */ -static VALUE swig_ruby_trackings = Qnil; +static st_table* swig_ruby_trackings = NULL; -/* Global variable that stores a reference to the ruby - hash table delete function. */ -static ID swig_ruby_hash_delete; +static VALUE swig_ruby_trackings_count(ANYARGS) { + return SWIG2NUM(swig_ruby_trackings->num_entries); +} -/* Setup a Ruby hash table to store Trackings */ + +/* Setup a hash table to store Trackings */ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) { - /* Create a ruby hash table to store Trackings from C++ + /* Create a hash table to store Trackings from C++ objects to Ruby objects. */ /* Try to see if some other .so has already created a @@ -43,88 +48,46 @@ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) { This is done to allow multiple DSOs to share the same tracking table. */ - ID trackings_id = rb_intern( "@__trackings__" ); + VALUE trackings_value = Qnil; + /* change the variable name so that we can mix modules + compiled with older SWIG's - this used to be called "@__trackings__" */ + ID trackings_id = rb_intern( "@__safetrackings__" ); VALUE verbose = rb_gv_get("VERBOSE"); rb_gv_set("VERBOSE", Qfalse); - swig_ruby_trackings = rb_ivar_get( _mSWIG, trackings_id ); + trackings_value = rb_ivar_get( _mSWIG, trackings_id ); rb_gv_set("VERBOSE", verbose); - /* No, it hasn't. Create one ourselves */ - if ( swig_ruby_trackings == Qnil ) - { - swig_ruby_trackings = rb_hash_new(); - rb_ivar_set( _mSWIG, trackings_id, swig_ruby_trackings ); - } - - /* Now store a reference to the hash table delete function - so that we only have to look it up once.*/ - swig_ruby_hash_delete = rb_intern("delete"); -} - -/* Get a Ruby number to reference a pointer */ -SWIGRUNTIME VALUE SWIG_RubyPtrToReference(void* ptr) { - /* We cast the pointer to an unsigned long - and then store a reference to it using - a Ruby number object. */ - - /* Convert the pointer to a Ruby number */ - return SWIG2NUM(ptr); -} - -/* Get a Ruby number to reference an object */ -SWIGRUNTIME VALUE SWIG_RubyObjectToReference(VALUE object) { - /* We cast the object to an unsigned long - and then store a reference to it using - a Ruby number object. */ - - /* Convert the Object to a Ruby number */ - return SWIG2NUM(object); -} - -/* Get a Ruby object from a previously stored reference */ -SWIGRUNTIME VALUE SWIG_RubyReferenceToObject(VALUE reference) { - /* The provided Ruby number object is a reference - to the Ruby object we want.*/ + /* The trick here is that we have to store the hash table + pointer in a Ruby variable. We do not want Ruby's GC to + treat this pointer as a Ruby object, so we convert it to + a Ruby numeric value. */ + if (trackings_value == Qnil) { + /* No, it hasn't. Create one ourselves */ + swig_ruby_trackings = st_init_numtable(); + rb_ivar_set( _mSWIG, trackings_id, SWIG2NUM(swig_ruby_trackings) ); + } else { + swig_ruby_trackings = (st_table*)NUM2SWIG(trackings_value); + } - /* Convert the Ruby number to a Ruby object */ - return NUM2SWIG(reference); + rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", swig_ruby_trackings_count, NULL); } /* Add a Tracking from a C/C++ struct to a Ruby object */ SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) { - /* In a Ruby hash table we store the pointer and - the associated Ruby object. The trick here is - that we cannot store the Ruby object directly - if - we do then it cannot be garbage collected. So - instead we typecast it as a unsigned long and - convert it to a Ruby number object.*/ - - /* Get a reference to the pointer as a Ruby number */ - VALUE key = SWIG_RubyPtrToReference(ptr); - - /* Get a reference to the Ruby object as a Ruby number */ - VALUE value = SWIG_RubyObjectToReference(object); - /* Store the mapping to the global hash table. */ - rb_hash_aset(swig_ruby_trackings, key, value); + st_insert(swig_ruby_trackings, (st_data_t)ptr, object); } /* Get the Ruby object that owns the specified C/C++ struct */ SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) { - /* Get a reference to the pointer as a Ruby number */ - VALUE key = SWIG_RubyPtrToReference(ptr); - /* Now lookup the value stored in the global hash table */ - VALUE value = rb_hash_aref(swig_ruby_trackings, key); - - if (value == Qnil) { - /* No object exists - return nil. */ + VALUE value; + + if (st_lookup(swig_ruby_trackings, (st_data_t)ptr, &value)) { + return value; + } else { return Qnil; } - else { - /* Convert this value to Ruby object */ - return SWIG_RubyReferenceToObject(value); - } } /* Remove a Tracking from a C/C++ struct to a Ruby object. It @@ -132,12 +95,8 @@ SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) { since the same memory address may be reused later to create a new object. */ SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) { - /* Get a reference to the pointer as a Ruby number */ - VALUE key = SWIG_RubyPtrToReference(ptr); - - /* Delete the object from the hash table by calling Ruby's - do this we need to call the Hash.delete method.*/ - rb_funcall(swig_ruby_trackings, swig_ruby_hash_delete, 1, key); + /* Delete the object from the hash table */ + st_delete(swig_ruby_trackings, (st_data_t *)&ptr, NULL); } /* This is a helper method that unlinks a Ruby object from its @@ -147,10 +106,25 @@ SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) { VALUE object = SWIG_RubyInstanceFor(ptr); if (object != Qnil) { + if (TYPE(object) != T_DATA) + abort(); DATA_PTR(object) = 0; } } +/* This is a helper method that iterates over all the trackings + passing the C++ object pointer and its related Ruby object + to the passed callback function. */ + +/* Proxy method to abstract the internal trackings datatype */ +static int swig_ruby_internal_iterate_callback(void* ptr, VALUE obj, void(*meth)(void* ptr, VALUE obj)) { + (*meth)(ptr, obj); + return ST_CONTINUE; +} + +SWIGRUNTIME void SWIG_RubyIterateTrackings( void(*meth)(void* ptr, VALUE obj) ) { + st_foreach(swig_ruby_trackings, (int (*)(ANYARGS))&swig_ruby_internal_iterate_callback, (st_data_t)meth); +} #ifdef __cplusplus } diff --git a/Lib/ruby/std_array.i b/Lib/ruby/std_array.i new file mode 100644 index 00000000000..a4d3ef54b8b --- /dev/null +++ b/Lib/ruby/std_array.i @@ -0,0 +1,102 @@ +/* + std::array +*/ + +%fragment("StdArrayTraits","header",fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(VALUE obj, std::array **vec) { + return traits_asptr_stdseq >::asptr(obj, vec); + } + }; + + template + struct traits_from > { + static VALUE from(const std::array& vec) { + return traits_from_stdseq >::from(vec); + } + }; + + template + inline void + assign(const RubySeq& rubyseq, std::array* seq) { + if (rubyseq.size() < seq->size()) + throw std::invalid_argument("std::array cannot be expanded in size"); + else if (rubyseq.size() > seq->size()) + throw std::invalid_argument("std::array cannot be reduced in size"); + std::copy(rubyseq.begin(), rubyseq.end(), seq->begin()); + } + + template + inline void + resize(std::array *seq, typename std::array::size_type n, typename std::array::value_type x) { + throw std::invalid_argument("std::array is a fixed size container and does not support resizing"); + } + + // Only limited slicing is supported as std::array is fixed in size + template + inline std::array* + getslice(const std::array* self, Difference i, Difference j) { + typedef std::array Sequence; + typename Sequence::size_type size = self->size(); + typename Sequence::size_type ii = swig::check_index(i, size, (i == size && j == size)); + typename Sequence::size_type jj = swig::slice_index(j, size); + + if (ii == 0 && jj == size) { + Sequence *sequence = new Sequence(); + std::copy(self->begin(), self->end(), sequence->begin()); + return sequence; + } else { + throw std::invalid_argument("std::array object only supports getting a slice that is the size of the array"); + } + } + + template + inline void + setslice(std::array* self, Difference i, Difference j, const InputSeq& v) { + typedef std::array Sequence; + typename Sequence::size_type size = self->size(); + typename Sequence::size_type ii = swig::check_index(i, size, true); + typename Sequence::size_type jj = swig::slice_index(j, size); + + if (ii == 0 && jj == size) { + std::copy(v.begin(), v.end(), self->begin()); + } else { + throw std::invalid_argument("std::array object only supports setting a slice that is the size of the array"); + } + } + + template + inline void + delslice(std::array* self, Difference i, Difference j) { + throw std::invalid_argument("std::array object does not support item deletion"); + } + } +%} + + +%define %swig_array_methods(Type...) + %swig_sequence_methods_non_resizable(Type) +%enddef + +%define %swig_array_methods_val(Type...) + %swig_sequence_methods_non_resizable_val(Type); +%enddef + + +%mixin std::array "Enumerable"; +%ignore std::array::push_back; +%ignore std::array::pop_back; + + +%rename("delete") std::array::__delete__; +%rename("reject!") std::array::reject_bang; +%rename("map!") std::array::map_bang; +%rename("empty?") std::array::empty; +%rename("include?" ) std::array::__contains__ const; +%rename("has_key?" ) std::array::has_key const; + +%include + diff --git a/Lib/ruby/std_common.i b/Lib/ruby/std_common.i index 14fba0df381..0cf9ce109c6 100644 --- a/Lib/ruby/std_common.i +++ b/Lib/ruby/std_common.i @@ -14,17 +14,17 @@ fragment=SWIG_From_frag(Type), fragment="StdTraits") { namespace swig { - template <> struct traits { + template <> struct traits< Type > { typedef value_category category; static const char* type_name() { return #Type; } - }; - template <> struct traits_asval { + }; + template <> struct traits_asval< Type > { typedef Type value_type; - static int asval(VALUE obj, value_type *val) { + static int asval(VALUE obj, value_type *val) { return SWIG_AsVal(Type)(obj, val); } }; - template <> struct traits_from { + template <> struct traits_from< Type > { typedef Type value_type; static VALUE from(const value_type& val) { return SWIG_From(Type)(val); @@ -47,13 +47,13 @@ namespace swig { fragment=SWIG_From_frag(int), fragment="StdTraits") { namespace swig { - template <> struct traits_asval { + template <> struct traits_asval< Type > { typedef Type value_type; - static int asval(VALUE obj, value_type *val) { + static int asval(VALUE obj, value_type *val) { return SWIG_AsVal(int)(obj, (int *)val); } }; - template <> struct traits_from { + template <> struct traits_from< Type > { typedef Type value_type; static VALUE from(const value_type& val) { return SWIG_From(int)((int)val); diff --git a/Lib/ruby/std_shared_ptr.i b/Lib/ruby/std_shared_ptr.i new file mode 100644 index 00000000000..df873679c62 --- /dev/null +++ b/Lib/ruby/std_shared_ptr.i @@ -0,0 +1,2 @@ +#define SWIG_SHARED_PTR_NAMESPACE std +%include diff --git a/Lib/scilab/boost_shared_ptr.i b/Lib/scilab/boost_shared_ptr.i new file mode 100644 index 00000000000..b90422a6676 --- /dev/null +++ b/Lib/scilab/boost_shared_ptr.i @@ -0,0 +1,320 @@ +%include + +// Set SHARED_PTR_DISOWN to $disown if required, for example +// #define SHARED_PTR_DISOWN $disown +#if !defined(SHARED_PTR_DISOWN) +#define SHARED_PTR_DISOWN 0 +#endif + +// Language specific macro implementing all the customisations for handling the smart pointer +%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) + +// %naturalvar is as documented for member variables +%naturalvar TYPE; +%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + +// destructor wrapper customisation +%feature("unref") TYPE +//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n" + "(void)arg1; delete smartarg1;" + +// Typemap customisations... + +// plain value +%typemap(in) CONST TYPE (void *argp, int res = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { + %argument_nullref("$type", $symname, $argnum); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(out) CONST TYPE { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + if (!argp) { + %variable_nullref("$type", "$name"); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(varout) CONST TYPE { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain pointer +// Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance +%typemap(in) CONST TYPE * (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} + +%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE * { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0; + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain reference +%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + $1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); + } +} +%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE & { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + if (!argp) { + %variable_nullref("$type", "$name"); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = *%const_cast(tempshared.get(), $1_ltype); + } else { + $1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// plain pointer by reference +// Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + temp = %const_cast(tempshared.get(), $*1_ltype); + } else { + temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype); + } + $1 = &temp; +} +%typemap(out, fragment="SWIG_null_deleter_python") TYPE *CONST& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) TYPE *CONST& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) TYPE *CONST& %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by value +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) $1 = *(%reinterpret_cast(argp, $<ype)); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + int newmem = 0; + void *argp = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + $1 = argp ? *(%reinterpret_cast(argp, $<ype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >(); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +// shared_ptr by reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + if ($owner) delete $1; +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) tempshared = *%reinterpret_cast(argp, $*ltype); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype); + temp = &tempshared; + $1 = &temp; +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varout typemap not implemented" +%} + +// Typecheck typemaps +// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting +// function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + int res = SWIG_ConvertPtr($input, 0, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), 0); + $1 = SWIG_CheckState(res); +} + + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} + + +%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + + +%enddef + diff --git a/Lib/scilab/carrays.i b/Lib/scilab/carrays.i new file mode 100644 index 00000000000..014de37ff8c --- /dev/null +++ b/Lib/scilab/carrays.i @@ -0,0 +1,5 @@ +%define %array_class(TYPE,NAME) + %array_class_wrap(TYPE,NAME,__paren__,__paren_asgn__) +%enddef + +%include diff --git a/Lib/scilab/cmalloc.i b/Lib/scilab/cmalloc.i new file mode 100644 index 00000000000..248f06b961b --- /dev/null +++ b/Lib/scilab/cmalloc.i @@ -0,0 +1 @@ +%include diff --git a/Lib/scilab/cpointer.i b/Lib/scilab/cpointer.i new file mode 100644 index 00000000000..d824792fa7a --- /dev/null +++ b/Lib/scilab/cpointer.i @@ -0,0 +1 @@ +%include diff --git a/Lib/scilab/exception.i b/Lib/scilab/exception.i new file mode 100644 index 00000000000..17f4175c4ec --- /dev/null +++ b/Lib/scilab/exception.i @@ -0,0 +1,6 @@ +%include + + +%insert("runtime") { + %define_as(SWIG_exception(code, msg), SWIG_Scilab_Error(code, msg);) +} diff --git a/Lib/scilab/matrix.i b/Lib/scilab/matrix.i new file mode 100644 index 00000000000..0936d936542 --- /dev/null +++ b/Lib/scilab/matrix.i @@ -0,0 +1,11 @@ +/* + * Matrix typemaps + * + */ + +%include +%include +%include +%include + + diff --git a/Lib/scilab/sciarray.swg b/Lib/scilab/sciarray.swg new file mode 100644 index 00000000000..c00e3837eab --- /dev/null +++ b/Lib/scilab/sciarray.swg @@ -0,0 +1,115 @@ +/* -------------------------------------------------------------------------- + * + * Arrays typemaps + * + * --------------------------------------------------------------------------*/ + +%{ +#include +%} + +%define %scilab_asarray_withallocatecopy(TYPEMAPTYPE, FRAGMENTNAME, CTYPE, TEMPDATATYPE) +%typemap(TYPEMAPTYPE, fragment="FRAGMENTNAME") CTYPE { + size_t i = 0; + int iRows = 0; + int iCols = 0; + TEMPDATATYPE *pTempData = NULL; + if (FRAGMENTNAME(pvApiCtx, $input, &iRows, &iCols, &pTempData, fname)) { + return SWIG_ERROR; + } + $1 = ($1_ltype)MALLOC(sizeof($*1_ltype) * iRows * iCols); + for (i = 0; i < iRows * iCols; i++) { + $1[i] = ($*1_ltype) pTempData[i]; + } +} +%enddef + +%define %scilab_asarrayandsize_withcopy(TYPEMAPTYPE, FRAGMENTNAME, CTYPE, TEMPDATATYPE) +%typemap(TYPEMAPTYPE, fragment="FRAGMENTNAME") CTYPE { + int iRows = 0; + int iCols = 0; + TEMPDATATYPE *pTempData = NULL; + if (FRAGMENTNAME(pvApiCtx, $input, &iRows, &iCols, &pTempData, fname)) { + return SWIG_ERROR; + } + if (iRows*iCols <= $1_dim0) { + size_t i; + for (i = 0; i < $1_dim0; i++) { + $1[i] = ($*1_ltype) pTempData[i]; + } + } + else { + char errmsg[100]; + sprintf(errmsg, "Size of input data (%d) is too big (maximum is %d)", + iRows*iCols, $1_dim0); + SWIG_exception_fail(SWIG_OverflowError, errmsg); + } +} +%enddef + +%define %scilab_fromarrayandsize(TYPEMAPTYPE, FRAGMENTNAME, CTYPE) +%typemap(TYPEMAPTYPE, noblock=1, fragment="FRAGMENTNAME") CTYPE { + %set_output(FRAGMENTNAME(pvApiCtx, $result, 1, $1_dim0, $1)); +} +%enddef + +%define %scilab_array_typemaps(CTYPE, ASARRAY_FRAGMENT, FROMARRAY_FRAGMENT, TEMPDATATYPE) + %scilab_asarrayandsize_withcopy(varin, ASARRAY_FRAGMENT, CTYPE[ANY], TEMPDATATYPE); + %scilab_asarray_withallocatecopy(in, ASARRAY_FRAGMENT, CTYPE[ANY], TEMPDATATYPE); + %scilab_fromarrayandsize(varout, FROMARRAY_FRAGMENT, CTYPE[ANY]); + %scilab_fromarrayandsize(out, FROMARRAY_FRAGMENT, CTYPE[ANY]); + + %apply SWIGTYPE[] { CTYPE[] }; + %scilab_asarray_withallocatecopy(in, ASARRAY_FRAGMENT, CTYPE[], TEMPDATATYPE); +%enddef + + +// Double +%scilab_array_typemaps(double, SWIG_SciDouble_AsDoubleArrayAndSize, + SWIG_SciDouble_FromDoubleArrayAndSize, double); + +// Signed char + +%scilab_array_typemaps(signed char, SWIG_SciDoubleOrInt8_AsSignedCharArrayAndSize, + SWIG_SciDouble_FromSignedCharArrayAndSize, signed char); + +// Unsigned char +%scilab_array_typemaps(unsigned char, SWIG_SciDoubleOrUint8_AsUnsignedCharArrayAndSize, + SWIG_SciDouble_FromUnsignedCharArrayAndSize, unsigned char); + +// Short +%scilab_array_typemaps(short, SWIG_SciDoubleOrInt16_AsShortArrayAndSize, + SWIG_SciDouble_FromShortArrayAndSize, short); + +// Unsigned short +%scilab_array_typemaps(unsigned short, SWIG_SciDoubleOrUint16_AsUnsignedShortArrayAndSize, + SWIG_SciDouble_FromUnsignedShortArrayAndSize, unsigned short); + +// Int +%scilab_array_typemaps(int, SWIG_SciDoubleOrInt32_AsIntArrayAndSize, + SWIG_SciDouble_FromIntArrayAndSize, int); + +// Unsigned int +%scilab_array_typemaps(unsigned int, SWIG_SciDoubleOrUint32_AsUnsignedIntArrayAndSize, + SWIG_SciDouble_FromUnsignedIntArrayAndSize, unsigned int); + +// Long +%scilab_array_typemaps(long, SWIG_SciDoubleOrInt32_AsIntArrayAndSize, + SWIG_SciDouble_FromLongArrayAndSize, int); + +// Unsigned long +%scilab_array_typemaps(unsigned long, SWIG_SciDoubleOrUint32_AsUnsignedIntArrayAndSize, + SWIG_SciDouble_FromUnsignedLongArrayAndSize, unsigned int); + +// Float +%scilab_array_typemaps(float, SWIG_SciDouble_AsFloatArrayAndSize, + SWIG_SciDouble_FromFloatArrayAndSize, float); + +// Bool +%scilab_array_typemaps(bool, SWIG_SciBoolean_AsIntArrayAndSize, + SWIG_SciBoolean_FromBoolArrayAndSize, int); + +// Char * +%scilab_array_typemaps(char *, SWIG_SciString_AsCharPtrArrayAndSize, + SWIG_SciString_FromCharPtrArrayAndSize, char *); + diff --git a/Lib/scilab/scibool.swg b/Lib/scilab/scibool.swg new file mode 100644 index 00000000000..ea7938dc88f --- /dev/null +++ b/Lib/scilab/scibool.swg @@ -0,0 +1,157 @@ +/* + * C-type: bool + * Scilab type: boolean scalar + */ +%fragment(SWIG_AsVal_frag(bool), "header") { +SWIGINTERN int +SWIG_AsVal_dec(bool)(SwigSciObject iVar, bool *pbValue) { + SciErr sciErr; + int iRet = 0; + int *piAddrVar = NULL; + int iTempValue = 0; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (!isBooleanType(pvApiCtx, piAddrVar)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), SWIG_Scilab_GetFuncName(), iVar); + return SWIG_ERROR; + } + + if (!isScalar(pvApiCtx, piAddrVar)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), SWIG_Scilab_GetFuncName(), iVar); + return SWIG_ERROR; + } + + iRet = getScalarBoolean(pvApiCtx, piAddrVar, &iTempValue); + if (iRet) { + return SWIG_ERROR; + } + + *pbValue = iTempValue; + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(bool), "header") { +SWIGINTERN int +SWIG_From_dec(bool)(bool bValue) { + if (createScalarBoolean(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + + SWIG_Scilab_GetOutputPosition(), bValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +/* + * C-type: bool[] + * Scilab type: boolean matrix + */ +%fragment("SWIG_SciBoolean_AsBoolArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciBoolean_AsBoolArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, bool **pbValue, char *fname) { + SciErr sciErr; + int *piAddrVar = NULL; + int *piValue = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isBooleanType(pvApiCtx, piAddrVar)) { + int i; + sciErr = getMatrixOfBoolean(pvApiCtx, piAddrVar, iRows, iCols, &piValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + *pbValue = (bool*) malloc((*iRows) * (*iCols) * sizeof(bool)); + for (i = 0; i < (*iRows) * (*iCols); i++) + (*pbValue)[i] = piValue[i] != 0; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A boolean matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment("SWIG_SciBoolean_FromBoolArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciBoolean_FromBoolArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, bool *pbValue) { + SciErr sciErr; + int *piValue = NULL; + int i; + + piValue = (int*) malloc(iRows * iCols * sizeof(int)); + for (i = 0; i < iRows * iCols; i++) + piValue[i] = pbValue[i]; + + sciErr = createMatrixOfBoolean(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, iRows, iCols, piValue); + if(sciErr.iErr) { + printError(&sciErr, 0); + free(piValue); + return SWIG_ERROR; + } + + free(piValue); + return SWIG_OK; +} +} + +/* + * C-type: int[] + * Scilab type: boolean matrix + */ +%fragment("SWIG_SciBoolean_AsIntArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciBoolean_AsIntArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, int **piValue, char *fname) { + SciErr sciErr; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isBooleanType(pvApiCtx, piAddrVar)) { + int i; + sciErr = getMatrixOfBoolean(pvApiCtx, piAddrVar, iRows, iCols, piValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A boolean matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment("SWIG_SciBoolean_FromIntArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciBoolean_FromIntArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, int *piValue) { + SciErr sciErr; + + sciErr = createMatrixOfBoolean(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, iRows, iCols, piValue); + if(sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} diff --git a/Lib/scilab/scichar.swg b/Lib/scilab/scichar.swg new file mode 100644 index 00000000000..5edbf5b7630 --- /dev/null +++ b/Lib/scilab/scichar.swg @@ -0,0 +1,292 @@ +/* + * C-type: char or char* + * Scilab type: string + */ + +/* + * CHAR + */ + +%fragment(SWIG_AsVal_frag(char), "header", fragment="SWIG_SciString_AsChar") { +#define SWIG_AsVal_char(scilabValue, valuePointer) SWIG_SciString_AsChar(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciString_AsChar", "header") { +SWIGINTERN int +SWIG_SciString_AsChar(void *pvApiCtx, int iVar, char *pcValue, char *fname) { + SciErr sciErr; + int *piAddrVar = NULL; + char *pstValue = NULL; + int iRet; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isStringType(pvApiCtx, piAddrVar) == 0) + { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A single string expected.\n"), fname, iVar); + return SWIG_TypeError; + } + + iRet = getAllocatedSingleString(pvApiCtx, piAddrVar, &pstValue); + if (iRet) { + return SWIG_ERROR; + } + + if (pcValue != NULL) { + *pcValue = pstValue[0]; + } + + freeAllocatedSingleString(pstValue); + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(char), "header", fragment="SWIG_SciString_FromChar") { +#define SWIG_From_char(value) SWIG_SciString_FromChar(pvApiCtx, SWIG_Scilab_GetOutputPosition(), value) +} +%fragment("SWIG_SciString_FromChar", "header") { +SWIGINTERN int +SWIG_SciString_FromChar(void *pvApiCtx, int iVarOut, char chValue) { + char *pchValue = (char*)malloc(sizeof(char) * 2); + pchValue[0] = chValue; + pchValue[1] = '\0'; + + if (createSingleString(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, pchValue)) + return SWIG_ERROR; + + free(pchValue); + return SWIG_OK; +} +} + +/* + * CHAR * +*/ + +%fragment("SWIG_AsCharArray", "header", fragment = "SWIG_SciString_AsCharPtr") { +#define SWIG_AsCharArray(scilabValue, charPtrPointer, charPtrLength) SWIG_SciString_AsCharPtr(pvApiCtx, scilabValue, charPtrPointer, charPtrLength, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciString_AsCharPtr", "header") { +SWIGINTERN int +SWIG_SciString_AsCharPtr(void *pvApiCtx, int iVar, char *pcValue, int iLength, char *fname) { + SciErr sciErr; + int *piAddrVar = NULL; + char* pcTmpValue = NULL; + int iRet; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + iRet = getAllocatedSingleString(pvApiCtx, piAddrVar, &pcTmpValue); + if (iRet) { + return SWIG_ERROR; + } + + if (pcValue != NULL) { + strncpy(pcValue, pcTmpValue, iLength); + } + + freeAllocatedSingleString(pcTmpValue); + return SWIG_OK; +} +} + +%fragment("SWIG_AsCharPtrAndSize", "header", fragment = "SWIG_SciString_AsCharPtrAndSize") { +#define SWIG_AsCharPtrAndSize(scilabValue, charPtrPointer, charPtrLength, allocMemory) SWIG_SciString_AsCharPtrAndSize(pvApiCtx, scilabValue, charPtrPointer, charPtrLength, allocMemory, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciString_AsCharPtrAndSize", "header") { +SWIGINTERN int +SWIG_SciString_AsCharPtrAndSize(void *pvApiCtx, int iVar, char **pcValue, size_t *piLength, int *alloc, char *fname) { + SciErr sciErr; + int *piAddrVar = NULL; + char *pstString = NULL; + int iRows = 0; + int iCols = 0; + int iLen = 0; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isScalar(pvApiCtx, piAddrVar) == 0 || isStringType(pvApiCtx, piAddrVar) == 0) + { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A single string expected.\n"), fname, iVar); + return SWIG_TypeError; + } + + sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &iLen, NULL); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + pstString = %new_array(iLen + 1, char); + + sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &iLen, &pstString); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + // TODO: return SWIG_ERROR if pcValue NULL (now returning SWIG_ERROR fails some typechecks) + if (pcValue) { + *pcValue = pstString; + } + + if (alloc != NULL) { + *alloc = SWIG_NEWOBJ; + } + + if (piLength != NULL) { + *piLength = strlen(pstString); + } + + return SWIG_OK; +} +} + +%fragment("SWIG_FromCharPtr", "header", fragment = "SWIG_SciString_FromCharPtr") { +#define SWIG_FromCharPtr(charPtr) SWIG_SciString_FromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) +} +%fragment("SWIG_SciString_FromCharPtr", "header") { +SWIGINTERN int +SWIG_SciString_FromCharPtr(void *pvApiCtx, int iVarOut, const char *pchValue) { + if (pchValue) { + SciErr sciErr; + const char* pstStrings[1]; + pstStrings[0] = pchValue; + + sciErr = createMatrixOfString(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, 1, 1, pstStrings); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + int iRet = createEmptyMatrix(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut); + if (iRet) { + return SWIG_ERROR; + } + } + + return SWIG_OK; +} +} + +/* + * CHAR * ARRAY + */ + +%fragment("SWIG_SciString_AsCharPtrArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciString_AsCharPtrArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, char ***charPtrArray, char *fname) { + SciErr sciErr; + int i = 0; + int *piAddrVar = NULL; + int* piLength = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getMatrixOfString(pvApiCtx, piAddrVar, iRows, iCols, NULL, NULL); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + piLength = (int*) malloc((*iRows) * (*iCols) * sizeof(int)); + + sciErr = getMatrixOfString(pvApiCtx, piAddrVar, iRows, iCols, piLength, NULL); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + *charPtrArray = (char**) malloc((*iRows) * (*iCols) * sizeof(char*)); + for(i = 0 ; i < (*iRows) * (*iCols); i++) { + (*charPtrArray)[i] = (char*) malloc(sizeof(char) * (piLength[i] + 1)); + } + + sciErr = getMatrixOfString(pvApiCtx, piAddrVar, iRows, iCols, piLength, *charPtrArray); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + free(piLength); + return SWIG_OK; +} +} + +%fragment("SWIG_SciString_FromCharPtrArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciString_FromCharPtrArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, char **charPtrArray) { + SciErr sciErr; + + sciErr = createMatrixOfString(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, iRows, iCols, (const char* const*) charPtrArray); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment("SWIG_FromCharPtrAndSize", "header", fragment = "SWIG_SciString_FromCharPtr") { +#define SWIG_FromCharPtrAndSize(charPtr, charPtrLength) SWIG_SciString_FromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) +} + + +/* + * Char* Scilab variable + */ + +%fragment(SWIG_CreateScilabVariable_frag(char), "wrapper") { +SWIGINTERN int +SWIG_CreateScilabVariable_dec(char)(void *pvApiCtx, const char* psVariableName, const char cVariableValue) { + SciErr sciErr; + char sValue[2]; + const char* psStrings[1]; + + sValue[0] = cVariableValue; + sValue[1] = '\0'; + psStrings[0] = sValue; + + sciErr = createNamedMatrixOfString(pvApiCtx, psVariableName, 1, 1, psStrings); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + return SWIG_OK; +} +} + +%fragment(SWIG_CreateScilabVariable_frag(charptr), "wrapper") { +SWIGINTERN int +SWIG_CreateScilabVariable_dec(charptr)(void *pvApiCtx, const char* psVariableName, const char* psVariableValue) { + SciErr sciErr; + const char* psStrings[1]; + psStrings[0] = psVariableValue; + + sciErr = createNamedMatrixOfString(pvApiCtx, psVariableName, 1, 1, psStrings); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + return SWIG_OK; +} +} diff --git a/Lib/scilab/scicontainer.swg b/Lib/scilab/scicontainer.swg new file mode 100644 index 00000000000..529d2788816 --- /dev/null +++ b/Lib/scilab/scicontainer.swg @@ -0,0 +1,445 @@ +/* ----------------------------------------------------------------------------- + * scicontainer.swg + * + * Scilab list <-> C++ container wrapper + * + * This wrapper, and its iterator, allows a general use (and reuse) of + * the mapping between C++ and Scilab, thanks to the C++ templates. + * + * Of course, it needs the C++ compiler to support templates, but + * since we will use this wrapper with the STL containers, that should + * be the case. + * ----------------------------------------------------------------------------- */ + +%{ +#include +%} + +#if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS) +# if !defined(SWIG_EXPORT_ITERATOR_METHODS) +# define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS +# endif +#endif + + +// #define (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS) +// if defined: sequences in return are converted from/to Scilab lists or matrices +// if not defined: sequences are passed from/to Scilab as pointers + +%{ +#define SWIG_STD_NOASSIGN_STL +%} + +%include +%include + +%{ +#include +%} + +%include +%include + +%fragment("SciSequence_Cont", "header", + fragment="StdTraits", + fragment="SwigSciIterator_T") +{ +namespace swig +{ + template + struct SciSequence_Ref + { + SciSequence_Ref(const SwigSciObject& seq, int index) + : _seq(seq), _index(index) + { + if (traits_as_sequence::get(_seq, &piSeqAddr) != SWIG_OK) + { + throw std::invalid_argument("Cannot get sequence data."); + } + } + + operator T () const + { + try + { + return traits_asval_sequenceitem::asval(_seq, piSeqAddr, _index); + } + catch (std::exception& e) + { + SWIG_exception(SWIG_RuntimeError, e.what()); + } + } + + SciSequence_Ref& operator=(const T& v) + { + // TODO + return *this; + } + + private: + SwigSciObject _seq; + int _index; + void *piSeqAddr; + }; + + + template + struct SciSequence_ArrowProxy + { + SciSequence_ArrowProxy(const T& x): m_value(x) {} + const T* operator->() const { return &m_value; } + operator const T*() const { return &m_value; } + T m_value; + }; + + template + struct SwigSciSequence_InputIterator + { + typedef SwigSciSequence_InputIterator self; + + typedef std::random_access_iterator_tag iterator_category; + typedef Reference reference; + typedef T value_type; + typedef T* pointer; + typedef int difference_type; + + SwigSciSequence_InputIterator() + { + } + + SwigSciSequence_InputIterator(const SwigSciObject& seq, int index) + : _seq(seq), _index(index) + { + } + + reference operator*() const + { + return reference(_seq, _index); + } + + SciSequence_ArrowProxy + operator->() const { + return SciSequence_ArrowProxy(operator*()); + } + + bool operator==(const self& ri) const + { + return (_index == ri._index); + } + + bool operator!=(const self& ri) const + { + return !(operator==(ri)); + } + + self& operator ++ () + { + ++_index; + return *this; + } + + self& operator -- () + { + --_index; + return *this; + } + + self& operator += (difference_type n) + { + _index += n; + return *this; + } + + self operator +(difference_type n) const + { + return self(_seq, _index + n); + } + + self& operator -= (difference_type n) + { + _index -= n; + return *this; + } + + self operator -(difference_type n) const + { + return self(_seq, _index - n); + } + + difference_type operator - (const self& ri) const + { + return _index - ri._index; + } + + bool operator < (const self& ri) const + { + return _index < ri._index; + } + + reference + operator[](difference_type n) const + { + return reference(_seq, _index + n); + } + + private: + SwigSciObject _seq; + difference_type _index; + }; + + template + struct SciSequence_Cont + { + typedef SciSequence_Ref reference; + typedef const SciSequence_Ref const_reference; + typedef T value_type; + typedef T* pointer; + typedef int difference_type; + typedef int size_type; + typedef const pointer const_pointer; + typedef SwigSciSequence_InputIterator iterator; + typedef SwigSciSequence_InputIterator const_iterator; + + SciSequence_Cont(const SwigSciObject& seq) : _seq(seq) + { + } + + ~SciSequence_Cont() + { + } + + size_type size() const + { + int iSeqSize; + if (traits_as_sequence::size(_seq, &iSeqSize) == SWIG_OK) + { + return iSeqSize; + } + else + { + return SWIG_ERROR; + } + } + + bool empty() const + { + return size() == 0; + } + + iterator begin() + { + return iterator(_seq, 0); + } + + const_iterator begin() const + { + return const_iterator(_seq, 0); + } + + iterator end() + { + return iterator(_seq, size()); + } + + const_iterator end() const + { + return const_iterator(_seq, size()); + } + + reference operator[](difference_type n) + { + return reference(_seq, n); + } + + const_reference operator[](difference_type n) const + { + return const_reference(_seq, n); + } + + private: + SwigSciObject _seq; + }; +} +} + +%define %swig_sequence_iterator(Sequence...) +#if defined(SWIG_EXPORT_ITERATOR_METHODS) + class iterator; + class reverse_iterator; + class const_iterator; + class const_reverse_iterator; + + %typemap(out,noblock=1,fragment="SciSequence_Cont") + iterator, reverse_iterator, const_iterator, const_reverse_iterator { + %set_output(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &)), + swig::SciSwigIterator::descriptor(),SWIG_POINTER_OWN)); + } + %typemap(out,fragment="SciSequence_Cont") + std::pair, std::pair { + // TODO: return a Scilab list from the pair (see code for Octave) + } + + %fragment("SciSwigPairBoolOutputIterator", "header", + fragment=SWIG_From_frag(bool), fragment="SciSequence_Cont") {} + + %typemap(out,fragment="SciSwigPairBoolOutputIterator") + std::pair, std::pair { + // TODO: return a Scilab list from the pair (see code for Octave) + } + + %typemap(in,noblock=1,fragment="SciSequence_Cont") + iterator(swig::SciSwigIterator *iter = 0, int res), + reverse_iterator(swig::SciSwigIterator *iter = 0, int res), + const_iterator(swig::SciSwigIterator *iter = 0, int res), + const_reverse_iterator(swig::SciSwigIterator *iter = 0, int res) { + res = SWIG_ConvertPtr((SwigSciObject)$input, %as_voidptrptr(&iter), swig::SciSwigIterator::descriptor(), 0); + if (!SWIG_IsOK(res) || !iter) { + %argument_fail(SWIG_TypeError, "$type", $symname, $argnum); + } else { + swig::SwigSciIterator_T<$type > *iter_t = dynamic_cast *>(iter); + if (iter_t) { + $1 = iter_t->get_current(); + } else { + %argument_fail(SWIG_TypeError, "$type", $symname, $argnum); + } + } + } + + %typecheck(%checkcode(ITERATOR),noblock=1,fragment="SciSequence_Cont") + iterator, reverse_iterator, const_iterator, const_reverse_iterator { + swig::SciSwigIterator *iter = 0; + int res = SWIG_ConvertPtr((SwigSciObject)$input, %as_voidptrptr(&iter), swig::SciSwigIterator::descriptor(), 0); + $1 = (SWIG_IsOK(res) && iter && (dynamic_cast *>(iter) != 0)); + } + + %fragment("SciSequence_Cont"); +#endif //SWIG_EXPORT_ITERATOR_METHODS +%enddef + +// The Scilab container methods + +%define %swig_container_methods(Container...) +%enddef + +%define %swig_sequence_methods_common(Sequence...) + %swig_sequence_iterator(%arg(Sequence)) + %swig_container_methods(%arg(Sequence)) + +%enddef + +%define %swig_sequence_methods(Sequence...) + %swig_sequence_methods_common(%arg(Sequence)) +%enddef + +%define %swig_sequence_methods_val(Sequence...) + %swig_sequence_methods_common(%arg(Sequence)) +%enddef + +// +// Common fragments +// + +%fragment("StdSequenceTraits","header", + fragment="StdTraits", + fragment="SciSequence_Cont", + fragment=SWIG_Traits_SequenceItem_frag(ptr)) +{ +namespace swig { + template + inline void + assign(const SciSeq& sciSeq, Seq* seq) { +%#ifdef SWIG_STD_NOASSIGN_STL + typedef typename SciSeq::value_type value_type; + typename SciSeq::const_iterator it = sciSeq.begin(); + for (;it != sciSeq.end(); ++it) { + seq->insert(seq->end(),(value_type)(*it)); + } +%#else + seq->assign(sciSeq.begin(), sciSeq.end()); +%#endif + } + + template + struct traits_asptr_stdseq { + typedef Seq sequence; + typedef T value_type; + + static int asptr(const SwigSciObject& obj, sequence **seq) + { + swig_type_info *typeInfo = swig::type_info(); + if (typeInfo) + { + sequence *p; + if (SWIG_ConvertPtr(obj, (void**)&p, typeInfo, 0) == SWIG_OK) + { + if (seq) + *seq = p; + return SWIG_OLDOBJ; + } + } + + if (traits_as_sequence::check(obj) == SWIG_OK) + { + try + { + SciSequence_Cont sciSeq(obj); + if (seq) + { + *seq = new sequence(); + assign(sciSeq, *seq); + return SWIG_NEWOBJ; + } + else + { + return true; + } + } + catch (std::exception& e) + { + SWIG_exception(SWIG_RuntimeError, e.what()); + } + } + } + }; + + template + struct traits_from_stdseq { + typedef Seq sequence; + typedef T value_type; + typedef typename Seq::size_type size_type; + typedef typename sequence::const_iterator const_iterator; + + static SwigSciObject from(const sequence& seq) + { + %#ifdef SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS + swig_type_info *typeInfo = swig::type_info(); + if (typeInfo) + { + return SWIG_NewPointerObj(new sequence(seq), typeInfo, SWIG_POINTER_OWN); + } + %#endif + + try + { + void *data; + size_type size = seq.size(); + if (traits_from_sequence::create(size, &data) == SWIG_OK) { + const_iterator it; + int index = 0; + for (it = seq.begin(); it != seq.end(); ++it) + { + traits_from_sequenceitem::from(data, index, *it); + index++; + } + return traits_from_sequence::set(size, data); + } + return SWIG_OK; + } + catch (std::exception& e) + { + SWIG_exception(SWIG_RuntimeError, e.what()); + } + } + }; +} +} diff --git a/Lib/scilab/scidouble.swg b/Lib/scilab/scidouble.swg new file mode 100644 index 00000000000..1b826330645 --- /dev/null +++ b/Lib/scilab/scidouble.swg @@ -0,0 +1,108 @@ +/* + * DOUBLE SCALAR + */ +%fragment(SWIG_AsVal_frag(double), "header", fragment="SWIG_SciDouble_AsDouble") { +%#define SWIG_AsVal_double(scilabValue, valuePointer) SWIG_SciDouble_AsDouble(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDouble_AsDouble", "header") { +SWIGINTERN int +SWIG_SciDouble_AsDouble(void *pvApiCtx, SwigSciObject iVar, double *pdblValue, char *fname) { + SciErr sciErr; + int iRet = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (!isDoubleType(pvApiCtx, piAddrVar) || isVarComplex(pvApiCtx, piAddrVar)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + if (!isScalar(pvApiCtx, piAddrVar)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + iRet = getScalarDouble(pvApiCtx, piAddrVar, pdblValue); + if (iRet) { + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(double), "header", fragment="SWIG_SciDouble_FromDouble") { +%#define SWIG_From_double(scilabValue) SWIG_SciDouble_FromDouble(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDouble_FromDouble", "header") { +SWIGINTERN int +SWIG_SciDouble_FromDouble(void *pvApiCtx, int iVarOut, double dblValue, char *fname) { + if (createScalarDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, dblValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +/* + * DOUBLE ARRAY + */ + +%fragment("SWIG_SciDouble_AsDoubleArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_AsDoubleArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, double **pdValue, char *fname) { + SciErr sciErr; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) { + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, pdValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment("SWIG_SciDouble_FromDoubleArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromDoubleArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, double *pdblValue) { + SciErr sciErr; + sciErr = createMatrixOfDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, iRows, iCols, pdblValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_CreateScilabVariable_frag(double), "wrapper") { +SWIGINTERN int +SWIG_CreateScilabVariable_dec(double)(void *pvApiCtx, const char* psVariableName, const double dVariableValue) { + SciErr sciErr; + sciErr = createNamedMatrixOfDouble(pvApiCtx, psVariableName, 1, 1, &dVariableValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + return SWIG_OK; +} +} diff --git a/Lib/scilab/scienum.swg b/Lib/scilab/scienum.swg new file mode 100644 index 00000000000..54ec1f85c90 --- /dev/null +++ b/Lib/scilab/scienum.swg @@ -0,0 +1,31 @@ +/* + * C-type: enum + * Scilab type: double or int32 + */ + +%fragment(SWIG_AsVal_frag(Enum), "header", fragment="SWIG_Int_AsEnum") { +%#define SWIG_AsVal_Enum(scilabValue, valuePointer) SWIG_Int_AsEnum(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_Int_AsEnum", "header", fragment="SWIG_SciDoubleOrInt32_AsInt") { +SWIGINTERN int +SWIG_Int_AsEnum(void *pvApiCtx, int iVar, int *enumValue, char *fname) { + int iValue = 0; + if (SWIG_SciDoubleOrInt32_AsInt(pvApiCtx, iVar, &iValue, fname) != SWIG_OK) + return SWIG_ERROR; + *enumValue = iValue; + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(Enum), "header", fragment="SWIG_Int_FromEnum") { +%#define SWIG_From_Enum(scilabValue) SWIG_Int_FromEnum(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_Int_FromEnum", "header", fragment="SWIG_SciDouble_FromInt") { +SWIGINTERN int +SWIG_Int_FromEnum(void *pvApiCtx, int iVarOut, int enumValue, char *fname) { + if (SWIG_SciDouble_FromInt(pvApiCtx, iVarOut, enumValue, fname) != SWIG_OK) + return SWIG_ERROR; + SWIG_Scilab_SetOutput(pvApiCtx, iVarOut); + return SWIG_OK; +} +} diff --git a/Lib/scilab/sciexception.swg b/Lib/scilab/sciexception.swg new file mode 100644 index 00000000000..a5eb4c00fd7 --- /dev/null +++ b/Lib/scilab/sciexception.swg @@ -0,0 +1,60 @@ +/* + * Exception typemaps (throws) + */ + +%include + +%typemap(throws, noblock=1) int, unsigned int, signed int, + int&,unsigned int&, signed int&, + long, unsigned long, signed long, + short, unsigned short,signed short, + long long, unsigned long long, + unsigned char, signed char, + long&, unsigned long&, signed long&, + short&, unsigned short&, signed short&, + long long&, unsigned long long&, + unsigned char&, signed char&, + size_t, size_t&, + ptrdiff_t, ptrdiff_t& { + char obj[20]; + sprintf(obj, "%d", (int)$1); + SWIG_Scilab_Raise_Ex(obj, "$type", $descriptor); +} + +%typemap(throws, noblock=1) enum SWIGTYPE { + char obj[20]; + sprintf(obj, "%d", (int)$1); + SWIG_Scilab_Raise_Ex(obj, "$type", $descriptor); +} + +%typemap(throws, noblock=1) float, double, + float&, double& { + char obj[20]; + sprintf(obj, "%5.3f", (double)$1); + SWIG_Scilab_Raise_Ex(obj, "$type", $descriptor); +} + +%typemap(throws, noblock=1) bool, bool& { + SWIG_Scilab_Raise_Ex($1 ? "true" : "false", "$type", $descriptor); +} + +%typemap(throws, noblock=1) char*, char[ANY] { + SWIG_Scilab_Raise_Ex($1, "$type", $descriptor); +} + +%typemap(throws, noblock=1) char, char& { + char obj[1]; + sprintf(obj, "%c", (char)$1); + SWIG_Scilab_Raise_Ex(obj, "$type", $descriptor); +} + +%typemap(throws, noblock=1) SWIGTYPE, + SWIGTYPE*, + SWIGTYPE [ANY], + SWIGTYPE & { + SWIG_Scilab_Raise_Ex((char*)NULL, "$type", $descriptor); +} + +%typemap(throws, noblock=1) (...) { + SWIG_exception(SWIG_RuntimeError, "unknown exception"); +} diff --git a/Lib/scilab/scifloat.swg b/Lib/scilab/scifloat.swg new file mode 100644 index 00000000000..f0af17c0e1c --- /dev/null +++ b/Lib/scilab/scifloat.swg @@ -0,0 +1,83 @@ +/* + * FLOAT SCALAR + */ + +%fragment(SWIG_AsVal_frag(float), "header", fragment=SWIG_AsVal_frag(double)) { +SWIGINTERN int +SWIG_AsVal_dec(float)(SwigSciObject iVar, float *pfValue) { + double dblValue = 0.0; + if(SWIG_AsVal_dec(double)(iVar, &dblValue) != SWIG_OK) { + return SWIG_ERROR; + } + if (pfValue) + *pfValue = (float) dblValue; + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(float), "header") { +SWIGINTERN int +SWIG_From_dec(float)(float flValue) { + if (createScalarDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + + SWIG_Scilab_GetOutputPosition(), (double)flValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +%fragment("SWIG_SciDouble_AsFloatArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_AsFloatArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, float **pfValue, char *fname) { + SciErr sciErr; + int *piAddrVar = NULL; + double *pdValue = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) { + int i; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, &pdValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + *pfValue = (float *) malloc((*iRows) * (*iCols) * sizeof(float)); + for (i=0; i < (*iRows) * (*iCols); i++) + (*pfValue)[i] = (float) pdValue[i]; + + return SWIG_OK; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } +} +} + +%fragment("SWIG_SciDouble_FromFloatArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromFloatArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, float *pfValue) { + SciErr sciErr; + double *pdValue; + int i; + + pdValue = (double *) malloc(iRows * iCols * sizeof(double)); + for (i = 0; i < iRows * iCols; i++) + pdValue[i] = pfValue[i]; + + sciErr = createMatrixOfDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, iRows, iCols, pdValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + free(pdValue); + return SWIG_OK; +} +} diff --git a/Lib/scilab/sciint.swg b/Lib/scilab/sciint.swg new file mode 100644 index 00000000000..2d6993569f8 --- /dev/null +++ b/Lib/scilab/sciint.swg @@ -0,0 +1,202 @@ +/* + * C-type: int + * Scilab type: double or int32 + */ + +%fragment(SWIG_AsVal_frag(int), "header", fragment="SWIG_SciDoubleOrInt32_AsInt", fragment="") { +%#define SWIG_AsVal_int(scilabValue, valuePointer) SWIG_SciDoubleOrInt32_AsInt(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDoubleOrInt32_AsInt", "header") { +SWIGINTERN int +SWIG_SciDoubleOrInt32_AsInt(void *pvApiCtx, SwigSciObject iVar, int *piValue, char *fname) +{ + SciErr sciErr; + int iType = 0; + int iRows = 0; + int iCols = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_ints) { + if (piValue) { + int iPrec = 0; + int *piData = NULL; + + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT32) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + sciErr = getMatrixOfInteger32(pvApiCtx, piAddrVar, &iRows, &iCols, &piData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + *piValue = *piData; + } + } + else if (iType == sci_matrix) { + if (piValue) { + double *pdData = NULL; + double dValue = 0.0f; + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + dValue = *pdData; + if (dValue != floor(dValue)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 32-bit signed integer.\n"), fname, iVar); + return SWIG_ValueError; + } + if ((dValue < INT_MIN) || (dValue > INT_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 32-bit signed integer.\n"), fname, iVar); + return SWIG_OverflowError; + } + *piValue = (int) dValue; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(int), "header", fragment="SWIG_SciDouble_FromInt") { +%#define SWIG_From_int(scilabValue) SWIG_SciDouble_FromInt(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDouble_FromInt", "header") { +SWIGINTERN int +SWIG_SciDouble_FromInt(void *pvApiCtx, int iVarOut, int iValue, char *fname){ + if (createScalarDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + + iVarOut, (double) iValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +/* + * C-type: int[] + * Scilab type: double or int32 matrix + */ +%fragment("SWIG_SciDoubleOrInt32_AsIntArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDoubleOrInt32_AsIntArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, int **piValue, char *fname) { + SciErr sciErr; + int iType = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_matrix) { + double *pdData = NULL; + int size = 0; + int i; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + size = (*iRows) * (*iCols); + *piValue = (int*) malloc(size * sizeof(int*)); + for (i = 0; i < size; i++) + (*piValue)[i] = (int) pdData[i]; + } + else if (iType == sci_ints) { + int iPrec = 0; + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT32) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + sciErr = getMatrixOfInteger32(pvApiCtx, piAddrVar, iRows, iCols, piValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + return SWIG_OK; +} +} + +%fragment("SWIG_SciDouble_FromIntArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromIntArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, const int *piData) { + SciErr sciErr; + double *pdValues = NULL; + int i; + + pdValues = (double*) malloc(iRows * iCols * sizeof(double)); + for (i=0; i + +%fragment("SciSwigIterator","header",fragment="") { +namespace swig { + struct stop_iteration { + }; + + struct SciSwigIterator { + private: + SwigSciObject _seq; + + protected: + SciSwigIterator(SwigSciObject seq) : _seq(seq) + { + } + + public: + virtual ~SciSwigIterator() {} + + virtual SwigSciObject value() const = 0; + + virtual SciSwigIterator *incr(size_t n = 1) = 0; + + virtual SciSwigIterator *decr(size_t n = 1) + { + throw stop_iteration(); + } + + virtual ptrdiff_t distance(const SciSwigIterator &x) const + { + throw std::invalid_argument("operation not supported"); + } + + virtual bool equal (const SciSwigIterator &x) const + { + throw std::invalid_argument("operation not supported"); + } + + virtual SciSwigIterator *copy() const = 0; + + SwigSciObject next() + { + SwigSciObject obj = value(); + incr(); + return obj; + } + + SwigSciObject previous() + { + decr(); + return value(); + } + + SciSwigIterator *advance(ptrdiff_t n) + { + return (n > 0) ? incr(n) : decr(-n); + } + + bool operator == (const SciSwigIterator& x) const + { + return equal(x); + } + + bool operator != (const SciSwigIterator& x) const + { + return ! operator==(x); + } + + SciSwigIterator* operator ++ () { + incr(); + return this; + } + + SciSwigIterator* operator -- () { + decr(); + return this; + } + + SciSwigIterator* operator + (ptrdiff_t n) const + { + return copy()->advance(n); + } + + SciSwigIterator* operator - (ptrdiff_t n) const + { + return copy()->advance(-n); + } + + ptrdiff_t operator - (const SciSwigIterator& x) const + { + return x.distance(*this); + } + + static swig_type_info* descriptor() { + static int init = 0; + static swig_type_info* desc = 0; + if (!init) { + desc = SWIG_TypeQuery("swig::SciSwigIterator *"); + init = 1; + } + return desc; + } + }; +} +} + +%fragment("SwigSciIterator_T","header",fragment="",fragment="SciSwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") { +namespace swig { + template + class SwigSciIterator_T : public SciSwigIterator + { + public: + typedef OutIterator out_iterator; + typedef typename std::iterator_traits::value_type value_type; + typedef SwigSciIterator_T self_type; + + SwigSciIterator_T(out_iterator curr, SwigSciObject seq) + : SciSwigIterator(seq), current(curr) + { + } + + const out_iterator& get_current() const + { + return current; + } + + + bool equal (const SciSwigIterator &iter) const + { + const self_type *iters = dynamic_cast(&iter); + if (iters) { + return (current == iters->get_current()); + } else { + throw std::invalid_argument("bad iterator type"); + } + } + + ptrdiff_t distance(const SciSwigIterator &iter) const + { + const self_type *iters = dynamic_cast(&iter); + if (iters) { + return std::distance(current, iters->get_current()); + } else { + throw std::invalid_argument("bad iterator type"); + } + } + + protected: + out_iterator current; + }; + + template + struct from_oper + { + typedef const ValueType& argument_type; + typedef SwigSciObject result_type; + result_type operator()(argument_type v) const + { + return swig::from(v); + } + }; + + template::value_type, + typename FromOper = from_oper > + class SciSwigIteratorOpen_T : public SwigSciIterator_T + { + public: + FromOper from; + typedef OutIterator out_iterator; + typedef ValueType value_type; + typedef SwigSciIterator_T base; + typedef SciSwigIteratorOpen_T self_type; + + SciSwigIteratorOpen_T(out_iterator curr, SwigSciObject seq) + : SwigSciIterator_T(curr, seq) + { + } + + SwigSciObject value() const { + return from(static_cast(*(base::current))); + } + + SciSwigIterator *copy() const + { + return new self_type(*this); + } + + SciSwigIterator *incr(size_t n = 1) + { + while (n--) { + ++base::current; + } + return this; + } + + SciSwigIterator *decr(size_t n = 1) + { + while (n--) { + --base::current; + } + return this; + } + }; + + template::value_type, + typename FromOper = from_oper > + class SciSwigIteratorClosed_T : public SwigSciIterator_T + { + public: + FromOper from; + typedef OutIterator out_iterator; + typedef ValueType value_type; + typedef SwigSciIterator_T base; + typedef SciSwigIteratorClosed_T self_type; + + SciSwigIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, SwigSciObject seq) + : SwigSciIterator_T(curr, seq), begin(first), end(last) + { + } + + SwigSciObject value() const { + if (base::current == end) { + throw stop_iteration(); + } else { + return from(static_cast(*(base::current))); + } + } + + SciSwigIterator *copy() const + { + return new self_type(*this); + } + + SciSwigIterator *incr(size_t n = 1) + { + while (n--) { + if (base::current == end) { + throw stop_iteration(); + } else { + ++base::current; + } + } + return this; + } + + SciSwigIterator *decr(size_t n = 1) + { + while (n--) { + if (base::current == begin) { + throw stop_iteration(); + } else { + --base::current; + } + } + return this; + } + + private: + out_iterator begin; + out_iterator end; + }; + + template + inline SciSwigIterator* + make_output_iterator(const OutIter& current, const OutIter& begin,const OutIter& end, SwigSciObject seq = SwigSciObject()) + { + return new SciSwigIteratorClosed_T(current, begin, end, seq); + } + + template + inline SciSwigIterator* + make_output_iterator(const OutIter& current, SwigSciObject seq = SwigSciObject()) + { + return new SciSwigIteratorOpen_T(current, seq); + } +} +} + + +%fragment("SciSwigIterator"); +namespace swig +{ +// Throw a StopIteration exception + %ignore stop_iteration; + struct stop_iteration {}; + + %typemap(throws, noblock=1) stop_iteration + { + SWIG_Scilab_Raise(0, "stop_iteration", NULL); + return SWIG_ERROR; + } + +// Mark methods that return new objects + %newobject SciSwigIterator::copy; + %newobject SciSwigIterator::operator + (ptrdiff_t n) const; + %newobject SciSwigIterator::operator - (ptrdiff_t n) const; + + %nodirector SciSwigIterator; + + %catches(swig::stop_iteration) SciSwigIterator::value() const; + %catches(swig::stop_iteration) SciSwigIterator::incr(size_t n = 1); + %catches(swig::stop_iteration) SciSwigIterator::decr(size_t n = 1); + %catches(std::invalid_argument) SciSwigIterator::distance(const SciSwigIterator &x) const; + %catches(std::invalid_argument) SciSwigIterator::equal (const SciSwigIterator &x) const; + %catches(swig::stop_iteration) SciSwigIterator::next(); + %catches(swig::stop_iteration) SciSwigIterator::previous(); + %catches(swig::stop_iteration) SciSwigIterator::advance(ptrdiff_t n); + %catches(swig::stop_iteration) SciSwigIterator::operator += (ptrdiff_t n); + %catches(swig::stop_iteration) SciSwigIterator::operator -= (ptrdiff_t n); + %catches(swig::stop_iteration) SciSwigIterator::operator + (ptrdiff_t n) const; + %catches(swig::stop_iteration) SciSwigIterator::operator - (ptrdiff_t n) const; + + %ignore SciSwigIterator::operator==; + %ignore SciSwigIterator::operator!=; + %ignore SciSwigIterator::operator++; + %ignore SciSwigIterator::operator--; + %ignore SciSwigIterator::operator+; + %ignore SciSwigIterator::operator-; + + struct SciSwigIterator + { + protected: + SciSwigIterator(SwigSciObject seq); + + public: + virtual ~SciSwigIterator(); + + virtual SwigSciObject value() const = 0; + + virtual SciSwigIterator *incr(size_t n = 1) = 0; + + virtual SciSwigIterator *decr(size_t n = 1); + + virtual ptrdiff_t distance(const SciSwigIterator &x) const; + + virtual bool equal (const SciSwigIterator &x) const; + + virtual SciSwigIterator *copy() const = 0; + + SwigSciObject next(); + SwigSciObject previous(); + SciSwigIterator *advance(ptrdiff_t n); + + bool operator == (const SciSwigIterator& x) const; + bool operator != (const SciSwigIterator& x) const; + SciSwigIterator* operator ++ (); + SciSwigIterator* operator -- (); + SciSwigIterator* operator + (ptrdiff_t n) const; + SciSwigIterator* operator - (ptrdiff_t n) const; + ptrdiff_t operator - (const SciSwigIterator& x) const; + }; +} diff --git a/Lib/scilab/scilab.swg b/Lib/scilab/scilab.swg new file mode 100644 index 00000000000..3b5f6e81771 --- /dev/null +++ b/Lib/scilab/scilab.swg @@ -0,0 +1,6 @@ +%include +%include +%include +%include +%include + diff --git a/Lib/scilab/scilist.swg b/Lib/scilab/scilist.swg new file mode 100644 index 00000000000..513f40b6429 --- /dev/null +++ b/Lib/scilab/scilist.swg @@ -0,0 +1,91 @@ +/* + * Scilab list related functions + * + */ + +%fragment("SWIG_ScilabList", "header") +{ +SWIGINTERN int +SWIG_GetScilabList(SwigSciObject obj, int **piListAddr) +{ + SciErr sciErr; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, piListAddr); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +SWIGINTERN int +SWIG_GetScilabListSize(SwigSciObject obj, int *piListSize) +{ + SciErr sciErr; + int *piListAddr; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, &piListAddr); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getListItemNumber(pvApiCtx, piListAddr, piListSize); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +SWIGINTERN int +SWIG_GetScilabListAndSize(SwigSciObject obj, int **piListAddr, int *piListSize) +{ + SciErr sciErr; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, piListAddr); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getListItemNumber(pvApiCtx, *piListAddr, piListSize); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +SWIGINTERN int +SWIG_CheckScilabList(SwigSciObject obj) +{ + SciErr sciErr; + int *piListAddr; + int iType; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, &piListAddr); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piListAddr, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if ((iType != sci_list) && (iType != sci_tlist) && (iType != sci_mlist)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A list is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +} + diff --git a/Lib/scilab/scilong.swg b/Lib/scilab/scilong.swg new file mode 100644 index 00000000000..4e55be5394d --- /dev/null +++ b/Lib/scilab/scilong.swg @@ -0,0 +1,123 @@ +/* + * C-type: long + * Scilab type: double or int32 + */ + +%fragment(SWIG_AsVal_frag(long), "header", fragment="SWIG_SciDoubleOrInt32_AsLong", fragment="") { +%#define SWIG_AsVal_long(scilabValue, valuePointer) SWIG_SciDoubleOrInt32_AsLong(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()); +} +%fragment("SWIG_SciDoubleOrInt32_AsLong", "header") { +SWIGINTERN int +SWIG_SciDoubleOrInt32_AsLong(void *pvApiCtx, SwigSciObject iVar, long *plValue, char *fname) { + SciErr sciErr; + int iType = 0; + int iRows = 0; + int iCols = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_ints) { + int iPrec = 0; + int *piData = NULL; + + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT32) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + sciErr = getMatrixOfInteger32(pvApiCtx, piAddrVar, &iRows, &iCols, &piData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + *plValue = (long) *piData; + } + else if (iType == sci_matrix) { + double *pdData = NULL; + double dValue = 0.0f; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + dValue = *pdData; + if (dValue != floor(dValue)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 32-bit signed integer.\n"), fname, iVar); + return SWIG_ValueError; + } + if ((dValue < LONG_MIN) || (dValue > LONG_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 32-bit signed integer.\n"), fname, iVar); + return SWIG_OverflowError; + } + *plValue = (long) dValue; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(long), "header", fragment="SWIG_SciDouble_FromLong") { +%#define SWIG_From_long(scilabValue) SWIG_SciDouble_FromLong(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDouble_FromLong", "header") { +SWIGINTERN int +SWIG_SciDouble_FromLong(void *pvApiCtx, int iVarOut, long lValue, char *fname) { + if (createScalarDouble(pvApiCtx, + SWIG_NbInputArgument(pvApiCtx) + iVarOut, (double) lValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + + +%fragment("SWIG_SciDouble_FromLongArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromLongArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, const long *plData) { + SciErr sciErr; + int i; + double *pdValues = NULL; + + pdValues = (double*) malloc(iRows * iCols * sizeof(double)); + for (i=0; i + +// in (bool *IN, int IN_ROWCOUNT, int IN_COLCOUNT) + +%typemap(in, noblock=1, fragment="SWIG_SciBoolean_AsBoolArrayAndSize") (bool *IN, int IN_ROWCOUNT, int IN_COLCOUNT) +{ + if (SWIG_SciBoolean_AsBoolArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + +// in (int IN_ROWCOUNT, int IN_COLCOUNT, bool *IN) + +%typemap(in, noblock=1, fragment="SWIG_SciBoolean_AsBoolArrayAndSize") (int IN_ROWCOUNT, int IN_COLCOUNT, bool *IN) +{ + if (SWIG_SciBoolean_AsBoolArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + +// in (bool *IN, int IN_SIZE) + +%typemap(in, noblock=1, fragment="SWIG_SciBoolean_AsBoolArrayAndSize") (bool *IN, int IN_SIZE) (int rowCount, int colCount) +{ + if (SWIG_SciBoolean_AsBoolArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) == SWIG_OK) { + $2 = rowCount * colCount; + } + else { + return SWIG_ERROR; + } +} + +// in (int IN_SIZE, bool *IN) + +%typemap(in, noblock=1) (int IN_SIZE, bool *IN) (int rowCount, int colCount) +{ + if (SWIG_SciBoolean_AsBoolArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) == SWIG_OK) { + $1 = rowCount * colCount; + } + else { + return SWIG_ERROR; + } +} + +// out (bool **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) + +%typemap(in, noblock=1, numinputs=0) (bool **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ +} + +%typemap(arginit, noblock=1) (bool **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + $1 = (bool**) malloc(sizeof(bool*)); + $2 = (int*) malloc(sizeof(int)); + $3 = (int*) malloc(sizeof(int)); +} + +%typemap(freearg, noblock=1) (bool **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + free(*$1); + free($1); + free($2); + free($3); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciBoolean_FromBoolArrayAndSize") (bool **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + if (SWIG_SciBoolean_FromBoolArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +// out (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, bool **OUT) + +%typemap(in, noblock=1, numinputs=0) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, bool **OUT) +{ +} + +%typemap(arginit, noblock=1) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, bool **OUT) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (int*) malloc(sizeof(int)); + $3 = (bool**) malloc(sizeof(bool*)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciBoolean_FromBoolArrayAndSize") (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, bool **OUT) +{ + if (SWIG_SciBoolean_FromBoolArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, bool **OUT) +{ + free($1); + free($2); + free(*$3); + free($3); +} + + +// out (bool **OUT, int *OUT_SIZE) + +%typemap(in, noblock=1, numinputs=0) (bool **OUT, int *OUT_SIZE) +{ +} + +%typemap(arginit, noblock=1) (bool **OUT, int *OUT_SIZE) +{ + $1 = (bool**) malloc(sizeof(bool*)); + $2 = (int*) malloc(sizeof(int)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciBoolean_FromBoolArrayAndSize") (bool **OUT, int *OUT_SIZE) +{ + if (SWIG_SciBoolean_FromBoolArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (bool **OUT, int *OUT_SIZE) +{ + free(*$1); + free($1); + free($2); +} + + +// out (int *OUT_SIZE, bool **OUT) + +%typemap(in, noblock=1, numinputs=0) (int *OUT_SIZE, bool **OUT) +{ +} + +%typemap(arginit, noblock=1) (int *OUT_SIZE, bool **OUT) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (bool**) malloc(sizeof(bool*)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciBoolean_FromBoolArrayAndSize") (int *OUT_SIZE, bool **OUT) +{ + if (SWIG_SciBoolean_FromBoolArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int *OUT_SIZE, bool **OUT) +{ + free($1); + free(*$2); + free($2); +} diff --git a/Lib/scilab/scimatrixchar.swg b/Lib/scilab/scimatrixchar.swg new file mode 100644 index 00000000000..37f683396bf --- /dev/null +++ b/Lib/scilab/scimatrixchar.swg @@ -0,0 +1,199 @@ +/* + * C-type: char* + * Scilab type: string matrix + */ + +%include + +// in (char **IN, int IN_ROWCOUNT, int IN_COLCOUNT) + +%typemap(in, noblock=1, fragment="SWIG_SciString_AsCharPtrArrayAndSize") (char **IN, int IN_ROWCOUNT, int IN_COLCOUNT) +{ + if (SWIG_SciString_AsCharPtrArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + +// in (int IN_ROWCOUNT, int IN_COLCOUNT, char **IN) + +%typemap(in, noblock=1, fragment="SWIG_SciString_AsCharPtrArrayAndSize") (int IN_ROWCOUNT, int IN_COLCOUNT, char **IN) +{ + if (SWIG_SciString_AsCharPtrArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + +// in (char **IN, int IN_SIZE) + +%typemap(in, noblock=1, fragment="SWIG_SciString_AsCharPtrArrayAndSize") (char **IN, int IN_SIZE) (int rowCount, int colCount) +{ + if (SWIG_SciString_AsCharPtrArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) == SWIG_OK) { + $2 = rowCount * colCount; + } + else { + return SWIG_ERROR; + } +} + +// in (int IN_SIZE, char **IN) + +%typemap(in, noblock=1, fragment="SWIG_SciString_AsCharPtrArrayAndSize") (int IN_SIZE, char **IN) (int rowCount, int colCount) +{ + if (SWIG_SciString_AsCharPtrArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) == SWIG_OK) { + $1 = rowCount * colCount; + } + else { + return SWIG_ERROR; + } +} + +// out (char ***OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) + +%typemap(in, noblock=1, numinputs=0) (char ***OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ +} + +%typemap(arginit, noblock=1) (char ***OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + $1 = (char***) malloc(sizeof(char**)); + $2 = (int*) malloc(sizeof(int)); + $3 = (int*) malloc(sizeof(int)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciString_FromCharPtrArrayAndSize") (char ***OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + if (SWIG_SciString_FromCharPtrArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (char ***OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + { + int i; + for (i = 0; i < (*$2) * (*$3); i++) + free((*$1)[i]); + } + free(*$1); + free($1); + free($2); + free($3); +} + +// out (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, char ***OUT) + +%typemap(in, noblock=1, numinputs=0) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, char ***OUT) +{ +} + +%typemap(arginit, noblock=1) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, char ***OUT) +{ + $1 = (char***) malloc(sizeof(char**)); + $2 = (int*) malloc(sizeof(int)); + $3 = (int**) malloc(sizeof(int*)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciString_FromCharPtrArrayAndSize") (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, char ***OUT) +{ + if (SWIG_SciString_FromCharPtrArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, char ***OUT) +{ + free($1); + free($2); + { + int i; + for (i = 0; i < (*$1) * (*$2); i++) + free((*$3)[i]); + } + free(*$3); + free($3); +} + + +// out (char ***OUT, int *OUT_SIZE) + +%typemap(in, noblock=1, numinputs=0) (char ***OUT, int *OUT_SIZE) +{ +} + +%typemap(arginit, noblock=1) (char ***OUT, int *OUT_SIZE) +{ + $1 = (char***) malloc(sizeof(char**)); + $2 = (int*) malloc(sizeof(int)); +} + +%typemap(freearg, noblock=1) (char ***OUT, int *OUT_SIZE) +{ + { + int i; + for (i = 0; i < *$2; i++) + free((*$1)[i]); + } + free(*$1); + free($1); + free($2); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciString_FromCharPtrArrayAndSize") (char ***OUT, int *OUT_SIZE) +{ + if (SWIG_SciString_FromCharPtrArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +// in (int IN_SIZE, char **IN) + +%typemap(in, noblock=1, fragment="SWIG_SciString_AsCharPtrArrayAndSize") (int IN_SIZE, char **IN) +{ + if (SWIG_SciString_AsCharPtrArrayAndSize(pvApiCtx, $input, 1, &$1, &$2, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + +// out (int *OUT_SIZE, char ***OUT) + +%typemap(in, noblock=1, numinputs=0) (int *OUT_SIZE, char ***OUT) +{ +} + +%typemap(arginit, noblock=1) (int *OUT_SIZE, char ***OUT) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (char***) malloc(sizeof(char**)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciString_FromCharPtrArrayAndSize") (int *OUT_SIZE, char ***OUT) +{ + if (SWIG_SciString_FromCharPtrArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int *OUT_SIZE, char ***OUT) +{ + free($1); + { + int i; + for (i = 0; i < *$1; i++) + free((*$2)[i]); + } + free(*$2); + free($2); +} + diff --git a/Lib/scilab/scimatrixdouble.swg b/Lib/scilab/scimatrixdouble.swg new file mode 100644 index 00000000000..b8272e9a6b1 --- /dev/null +++ b/Lib/scilab/scimatrixdouble.swg @@ -0,0 +1,170 @@ +/* + * C-type: double array + * Scilab type: double matrix + */ + +%include + +// in (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) + +%typemap(in, noblock=1, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) +{ + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + +// in (int IN_ROWCOUNT, int IN_COLCOUNT, double *IN) + +%typemap(in, noblock=1, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int IN_ROWCOUNT, int IN_COLCOUNT, double *IN) +{ + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + +// in (double *IN, int IN_SIZE) + +%typemap(in, noblock=1, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double *IN, int IN_SIZE) (int rowCount, int colCount) +{ + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) == SWIG_OK) { + $2 = rowCount * colCount; + } + else { + return SWIG_ERROR; + } +} + +// in (int IN_SIZE, double *IN) + +%typemap(in, noblock=1, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int IN_SIZE, double *IN) (int rowCount, int colCount) +{ + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) == SWIG_OK) { + $1 = rowCount * colCount; + } + else { + return SWIG_ERROR; + } +} + +// out (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) + +%typemap(in, noblock=1, numinputs=0) (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ +} + +%typemap(arginit, noblock=1) (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + $1 = (double**) malloc(sizeof(double*)); + $2 = (int*) malloc(sizeof(int)); + $3 = (int*) malloc(sizeof(int)); +} + +%typemap(freearg, noblock=1) (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + free(*$1); + free($1); + free($2); + free($3); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +// out (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, double **OUT) + +%typemap(in, noblock=1, numinputs=0) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, double **OUT) +{ +} + +%typemap(arginit, noblock=1) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, double **OUT) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (int*) malloc(sizeof(int)); + $3 = (double**) malloc(sizeof(double*)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (int *IN_ROWCOUNT, int *IN_COLCOUNT, double **OUT) +{ + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, double **OUT) +{ + free($1); + free($2); + free(*$3); + free($3); +} + + +// out (double **OUT, int *OUT_SIZE) + +%typemap(in, noblock=1, numinputs=0) (double **OUT, int *OUT_SIZE) +{ +} + +%typemap(arginit, noblock=1) (double **OUT, int *OUT_SIZE) +{ + $1 = (double**) malloc(sizeof(double*)); + $2 = (int*) malloc(sizeof(int)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double **OUT, int *OUT_SIZE) +{ + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (double **OUT, int *OUT_SIZE) +{ + free(*$1); + free($1); + free($2); +} + + +// out (int *OUT_SIZE, double **OUT) + +%typemap(in, noblock=1, numinputs=0) (int *OUT_SIZE, double **OUT) +{ +} + +%typemap(arginit, noblock=1) (int *OUT_SIZE, double **OUT) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (double**) malloc(sizeof(double*)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (int *OUT_SIZE, double **OUT) +{ + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int *OUT_SIZE, double **OUT) +{ + free($1); + free(*$2); + free($2); +} diff --git a/Lib/scilab/scimatrixint.swg b/Lib/scilab/scimatrixint.swg new file mode 100644 index 00000000000..b7270d5d583 --- /dev/null +++ b/Lib/scilab/scimatrixint.swg @@ -0,0 +1,175 @@ +/* + * C-type: int array + * Scilab type: 32-bit integer matrix + */ + +%include + +// in (int *IN, int IN_ROWCOUNT, int IN_COLCOUNT) + +%typemap(in, noblock=1, fragment="SWIG_SciDoubleOrInt32_AsIntArrayAndSize") (int *IN, int IN_ROWCOUNT, int IN_COLCOUNT) +{ + if (SWIG_SciDoubleOrInt32_AsIntArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + + +// in (int IN_ROWCOUNT, int IN_COLCOUNT, int *IN) + +%typemap(in, noblock=1, fragment="SWIG_SciDoubleOrInt32_AsIntArrayAndSize") (int IN_ROWCOUNT, int IN_COLCOUNT, int *IN) +{ + if (SWIG_SciDoubleOrInt32_AsIntArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) != SWIG_OK) { + return SWIG_ERROR; + } +} + + +// in (int *IN, int IN_SIZE) + +%typemap(in, noblock=1, fragment="SWIG_SciDoubleOrInt32_AsIntArrayAndSize") (int *IN, int IN_SIZE) (int rowCount, int colCount) +{ + if (SWIG_SciDoubleOrInt32_AsIntArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) == SWIG_OK) { + $2 = rowCount * colCount; + } + else { + return SWIG_ERROR; + } +} + + +// in (int IN_SIZE, int *IN) + +%typemap(in, noblock=1, fragment="SWIG_SciDoubleOrInt32_AsIntArrayAndSize") (int IN_SIZE, int *IN) (int rowCount, int colCount) +{ + if (SWIG_SciDoubleOrInt32_AsIntArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) == SWIG_OK) { + $1 = rowCount * colCount; + } + else { + return SWIG_ERROR; + } +} + +// out (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) + +%typemap(in, noblock=1, numinputs=0) (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ +} + +%typemap(arginit, noblock=1) (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + $1 = (int**) malloc(sizeof(int*)); + $2 = (int*) malloc(sizeof(int)); + $3 = (int*) malloc(sizeof(int)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromIntArrayAndSize") (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + if (SWIG_SciDouble_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) +{ + free(*$1); + free($1); + free($2); + free($3); +} + + +// out (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, int **OUT) + +%typemap(in, noblock=1, numinputs=0) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, int **OUT) +{ +} + +%typemap(arginit, noblock=1) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, int **OUT) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (int*) malloc(sizeof(int)); + $3 = (int**) malloc(sizeof(int*)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromIntArrayAndSize") (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, int **OUT) +{ + if (SWIG_SciDouble_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int *OUT_ROWCOUNT, int *OUT_COLCOUNT, int **OUT) +{ + free($1); + free($2); + free(*$3); + free($3); +} + + +// out (int **OUT, int *OUT_SIZE) + +%typemap(in, noblock=1, numinputs=0) (int **OUT, int *OUT_SIZE) +{ +} + +%typemap(arginit) (int **OUT, int *OUT_SIZE) +{ + $1 = (int**) malloc(sizeof(int*)); + $2 = (int*) malloc(sizeof(int)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromIntArrayAndSize") (int **OUT, int *OUT_SIZE) +{ + if (SWIG_SciDouble_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int **OUT, int *OUT_SIZE) +{ + free(*$1); + free($1); + free($2); +} + + +// out (int *OUT_SIZE, int **OUT) + +%typemap(in, noblock=1, numinputs=0) (int *OUT_SIZE, int **OUT) +{ +} + +%typemap(arginit, noblock=1) (int *OUT_SIZE, int **OUT) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (int**) malloc(sizeof(int*)); +} + +%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromIntArrayAndSize") (int *OUT_SIZE, int **OUT) +{ + if (SWIG_SciDouble_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) == SWIG_OK) { + SWIG_Scilab_SetOutput(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition()); + } + else { + return SWIG_ERROR; + } +} + +%typemap(freearg, noblock=1) (int *IN_SIZE, int **OUT) +{ + free($1); + free(*$2); + free($2); +} + diff --git a/Lib/scilab/scimisctypes.swg b/Lib/scilab/scimisctypes.swg new file mode 100644 index 00000000000..fe75e156830 --- /dev/null +++ b/Lib/scilab/scimisctypes.swg @@ -0,0 +1,69 @@ +// Other primitive such as size_t and ptrdiff_t + +/* + * C-type: size_t + * Scilab type: double or int32 + */ + +%fragment(SWIG_AsVal_frag(size_t), "header", fragment="SWIG_Int_AsSize") { +%#define SWIG_AsVal_size_t(scilabValue, valuePointer) SWIG_Int_AsSize(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_Int_AsSize", "header", fragment=SWIG_AsVal_frag(int)) +{ +SWIGINTERN int +SWIG_Int_AsSize(void *pvApiCtx, SwigSciObject iVar, size_t *piValue, char *fname) { + int iValue = 0; + if (SWIG_AsVal_dec(int)(iVar, &iValue) != SWIG_OK) + return SWIG_ERROR; + + if (piValue) + *piValue = (size_t) iValue; + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(size_t), "header", fragment="SWIG_Int_FromSize") { +%#define SWIG_From_size_t(scilabValue) SWIG_Int_FromSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_Int_FromSize", "header", fragment=SWIG_From_frag(int)) +{ +SWIGINTERN int +SWIG_Int_FromSize(void *pvApiCtx, int iVarOut, size_t iValue, char *fname) { + return SWIG_From_dec(int)((int)iValue); +} +} + +/* + * C-type: ptrdiff_t + * Scilab type: double or int32 + */ + +%fragment(SWIG_AsVal_frag(ptrdiff_t), "header", fragment="SWIG_Int_AsPtrDiff") { +%#define SWIG_AsVal_ptrdiff_t(scilabValue, valuePointer) SWIG_Int_AsPtrDiff(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_Int_AsPtrDiff", "header", fragment=SWIG_AsVal_frag(int)) +{ +SWIGINTERN int +SWIG_Int_AsPtrDiff(void *pvApiCtx, SwigSciObject iVar, ptrdiff_t *piValue, char *fname) { + int iValue = 0; + if (SWIG_AsVal_dec(int)(iVar, &iValue) != SWIG_OK) + return SWIG_ERROR; + + if (piValue) + *piValue = (ptrdiff_t) iValue; + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(ptrdiff_t), "header", fragment="SWIG_Int_FromPtrDiff") { +%#define SWIG_From_ptrdiff_t(scilabValue) SWIG_Int_FromPtrDiff(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_Int_FromPtrDiff", "header", fragment=SWIG_From_frag(int)) { +SWIGINTERN int +SWIG_Int_FromPtrDiff(void *pvApiCtx, int iVarOut, ptrdiff_t iValue, char *fname) { + return SWIG_From_dec(int)((int)iValue); +} +} + diff --git a/Lib/scilab/scipointer.swg b/Lib/scilab/scipointer.swg new file mode 100644 index 00000000000..8d0526d4d7a --- /dev/null +++ b/Lib/scilab/scipointer.swg @@ -0,0 +1,32 @@ +/* + * POINTER + */ +%fragment("SWIG_ConvertPtr", "header") { +#define SWIG_ConvertPtr(scilabValue, voidPointer, pointerDescriptor, flags) SwigScilabPtrToObject(pvApiCtx, scilabValue, voidPointer, pointerDescriptor, flags, SWIG_Scilab_GetFuncName()) +} + +%fragment("SWIG_NewPointerObj", "header") { +#define SWIG_NewPointerObj(pointer, pointerDescriptor, flags) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, flags) +} + +/* + * FUNCTION POINTER + */ +%fragment("SWIG_ConvertFunctionPtr", "header") { +#define SWIG_ConvertFunctionPtr(scilabValue, voidPointer, pointerDescriptor) SwigScilabPtrToObject(pvApiCtx, scilabValue, voidPointer, pointerDescriptor, 0, SWIG_Scilab_GetFuncName()) +} + +%fragment("SWIG_NewFunctionPtrObj", "header") { +#define SWIG_NewFunctionPtrObj(pointer, pointerDescriptor) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, 0) +} +// No fragment used here, the functions "SwigScilabPtrToObject" and "SwigScilabPtrFromObject" are defined in sciruntime.swg + +/* + * C++ member pointers, ie, member methods + */ +%fragment("SWIG_NewMemberObj", "header") { +#define SWIG_NewMemberObj(ptr, sz, tp) SWIG_Scilab_NewMemberObj(pvApiCtx, $result, ptr, sz, tp) +} +%fragment("SWIG_ConvertMember", "header") { +#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Scilab_ConvertPacked(pvApiCtx, obj, ptr, sz, ty, SWIG_Scilab_GetFuncName()) +} diff --git a/Lib/scilab/sciprimtypes.swg b/Lib/scilab/sciprimtypes.swg new file mode 100644 index 00000000000..b5e30d932c3 --- /dev/null +++ b/Lib/scilab/sciprimtypes.swg @@ -0,0 +1,23 @@ +%include +%include + +%include + +%include +%include + +%include +%include + +%include +%include + +%include +%include +%include + +%include + +%include +%include + diff --git a/Lib/scilab/scirun.swg b/Lib/scilab/scirun.swg new file mode 100644 index 00000000000..71641e0743b --- /dev/null +++ b/Lib/scilab/scirun.swg @@ -0,0 +1,327 @@ +/* ----------------------------------------------------------------------------- + * Scilab support runtime + * -----------------------------------------------------------------------------*/ + +/* Scilab version macro */ + +#include "version.h" +#define SWIG_SCILAB_VERSION (SCI_VERSION_MAJOR * 100) + (SCI_VERSION_MINOR * 10) + SCI_VERSION_MAINTENANCE + +/* Scilab standard headers */ + +#ifdef __cplusplus +extern "C" { +#endif +#include "api_scilab.h" +#if SWIG_SCILAB_VERSION < 540 +#define __USE_DEPRECATED_STACK_FUNCTIONS__ +#include "stack-c.h" +#endif +#include "MALLOC.h" +#include "Scierror.h" +#include "localization.h" +#include "freeArrayOfString.h" +#include +#include +#ifdef __cplusplus +} +#endif + +/* Gateway signature */ + +#if SWIG_SCILAB_VERSION >= 600 +#define SWIG_GatewayParameters char* fname, void *pvApiCtx +#define SWIG_GatewayArguments fname, pvApiCtx +#else +#define SWIG_GatewayParameters char* fname, unsigned long fname_len +#define SWIG_GatewayArguments fname, fname_len +#endif + +/* Function name management functions */ + +#include +static char *SwigFuncName = NULL; +static char *SWIG_Scilab_GetFuncName(void) { + return SwigFuncName; +} +static void SWIG_Scilab_SetFuncName(char *funcName) { + if (SwigFuncName != NULL) { + free(SwigFuncName); + } + SwigFuncName = strdup(funcName); +} + +/* Api context management functions */ + +#if SWIG_SCILAB_VERSION >= 600 +static void *pvApiCtx = NULL; +static void SWIG_Scilab_SetApiContext(void *apiCtx) { + pvApiCtx = apiCtx; +} +#else +#define SWIG_Scilab_SetApiContext(apiCtx) +#endif + +/* Argument management functions */ + +#if SWIG_SCILAB_VERSION >= 540 +#define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) +#define SWIG_CheckInputArgumentAtLeast(pvApiCtx, minInputArgument) CheckInputArgumentAtLeast(pvApiCtx, minInputArgument) +#define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) +#define SWIG_NbInputArgument(pvApiCtx) nbInputArgument(pvApiCtx) +#define SWIG_AssignOutputArgument(pvApiCtx, outputArgumentPos, argumentPos) AssignOutputVariable(pvApiCtx, outputArgumentPos) = argumentPos +#else +#define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckRhs(minInputArgument, maxInputArgument) +#define SWIG_CheckInputArgumentAtLeast(pvApiCtx, minInputArgument) CheckRhs(minInputArgument, 256) +#define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckLhs(minOutputArgument, maxOutputArgument) +#define SWIG_NbInputArgument(pvApiCtx) Rhs +#define SWIG_AssignOutputArgument(pvApiCtx, outputArgumentPos, argumentPos) LhsVar(outputArgumentPos) = argumentPos +#endif + +typedef int SwigSciObject; + +static int SwigOutputPosition = -1; +static int SWIG_Scilab_GetOutputPosition(void) { + return SwigOutputPosition; +} +static void SWIG_Scilab_SetOutputPosition(int outputPosition) { + SwigOutputPosition = outputPosition; +} + +SWIGRUNTIME int +SWIG_Scilab_SetOutput(void *pvApiCtx, SwigSciObject output) { + int outputPosition = SWIG_Scilab_GetOutputPosition(); + if (outputPosition < 0) + return SWIG_ERROR; + SWIG_AssignOutputArgument(pvApiCtx, outputPosition, + SWIG_NbInputArgument(pvApiCtx) + outputPosition); + return SWIG_OK; +} + + +/* Pointer conversion functions */ + +SWIGINTERN int +SwigScilabPtrToObject(void *pvApiCtx, int iVar, void **pObjValue, swig_type_info *descriptor, int flags, char *fname) { + SciErr sciErr; + int iType = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_pointer) { + sciErr = getPointer(pvApiCtx, piAddrVar, pObjValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + return SWIG_ERROR; + } + + return SWIG_OK; +} + +SWIGRUNTIMEINLINE int +SwigScilabPtrFromObject(void *pvApiCtx, int iVarOut, void *obj, swig_type_info *descriptor, int flags) { + SciErr sciErr; + + sciErr = createPointer(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, (void *)obj); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +SWIGRUNTIME int +SWIG_Scilab_ConvertPacked(void *pvApiCtx, int iVar, void *ptr, int sz, swig_type_info *ty, char *fname) { + swig_cast_info *tc; + int *piAddrVar = NULL; + char *pstString = NULL; + char *pstStringPtr = NULL; + SciErr sciErr; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (getAllocatedSingleString(pvApiCtx, piAddrVar, &pstString)) { + return SWIG_ERROR; + } + + /* Pointer values must start with leading underscore */ + if (*pstString != '_') { + freeAllocatedSingleString(pstString); + return SWIG_ERROR; + } + + pstStringPtr = pstString; + pstStringPtr++; + pstStringPtr = (char*)SWIG_UnpackData(pstStringPtr, ptr, sz); + + if (ty) { + if (!pstStringPtr) { + freeAllocatedSingleString(pstString); + return SWIG_ERROR; + } + tc = SWIG_TypeCheck(pstStringPtr, ty); + if (!tc) { + freeAllocatedSingleString(pstString); + return SWIG_ERROR; + } + } + + freeAllocatedSingleString(pstString); + return SWIG_OK; +} + +SWIGRUNTIME int +SWIG_Scilab_NewMemberObj(void *pvApiCtx, int iVarOut, void *ptr, int sz, swig_type_info *type) { + char result[1024]; + char *r = result; + + if ((2*sz + 1 + strlen(type->name)) > 1000) { + return SWIG_ERROR; + } + *(r++) = '_'; + r = SWIG_PackData(r, ptr, sz); + strcpy(r, type->name); + + if (createSingleString(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, &result[0])) + return SWIG_ERROR; + + return SWIG_OK; +} + + +/* Error functions */ + +#define SCILAB_API_ARGUMENT_ERROR 999 + +SWIGINTERN const char* +SWIG_Scilab_ErrorType(int code) { + switch(code) { + case SWIG_MemoryError: + return "MemoryError"; + case SWIG_IOError: + return "IOError"; + case SWIG_RuntimeError: + return "RuntimeError"; + case SWIG_IndexError: + return "IndexError"; + case SWIG_TypeError: + return "TypeError"; + case SWIG_DivisionByZero: + return "ZeroDivisionError"; + case SWIG_OverflowError: + return "OverflowError"; + case SWIG_SyntaxError: + return "SyntaxError"; + case SWIG_ValueError: + return "ValueError"; + case SWIG_SystemError: + return "SystemError"; + case SWIG_AttributeError: + return "AttributeError"; + default: + return "RuntimeError"; + } +} +#define SWIG_ErrorType(code) SWIG_Scilab_ErrorType(code) + +#ifndef SWIG_SCILAB_ERROR +#define SWIG_SCILAB_ERROR 20000 +#endif + +SWIGINTERN void +SWIG_Scilab_Error(int code, const char *msg) +{ + Scierror(SWIG_SCILAB_ERROR - code, _("SWIG/Scilab: %s: %s\n"), SWIG_Scilab_ErrorType(code), msg); +} + +#define SWIG_Error(code, msg) SWIG_Scilab_Error(code, msg) + +#define SWIG_fail return SWIG_ERROR; + +SWIGRUNTIME void +SWIG_Scilab_Raise_Ex(const char *obj, const char *type, swig_type_info *descriptor) { + if (type) { + if (obj) + Scierror(SWIG_SCILAB_ERROR, "SWIG/Scilab: Exception (%s) occured: %s\n", type, obj); + else + Scierror(SWIG_SCILAB_ERROR, "SWIG/Scilab: Exception (%s) occured.\n", type); + } +} + +SWIGRUNTIME void +SWIG_Scilab_Raise(const int obj, const char *type, swig_type_info *descriptor) { + Scierror(SWIG_SCILAB_ERROR, "SWIG/Scilab: Exception (%s) occured.\n", type); +} + +/* + * Pointer utility functions + */ + +#include + +#ifdef __cplusplus +extern "C" +#endif +int SWIG_this(SWIG_GatewayParameters) { + void *ptrValue = NULL; + if (SwigScilabPtrToObject(pvApiCtx, 1, &ptrValue, NULL, 0, fname) == SWIG_OK) { + SWIG_Scilab_SetOutputPosition(1); + return SWIG_Scilab_SetOutput(pvApiCtx, + createScalarDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + 1, + (double)(uintptr_t)ptrValue)); + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The value is not a pointer.\n"), fname, 1); + return SWIG_ERROR; + } +} + +#ifdef __cplusplus +extern "C" +#endif +int SWIG_ptr(SWIG_GatewayParameters) { + double dValue = 0; + int *piAddr; + SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); + if(sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (getScalarDouble(pvApiCtx, piAddr, &dValue) == 0) { + if (dValue != (uintptr_t)dValue) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a pointer.\n"), fname, 1); + return SWIG_ValueError; + } + if ((dValue < 0) || (dValue > ULONG_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a pointer.\n"), fname, 1); + return SWIG_OverflowError; + } + SWIG_Scilab_SetOutputPosition(1); + return SWIG_Scilab_SetOutput(pvApiCtx, + SwigScilabPtrFromObject(pvApiCtx, 1, (void *) (uintptr_t)dValue, NULL, 0)); + } + else { + return SWIG_ERROR; + } +} + diff --git a/Lib/scilab/sciruntime.swg b/Lib/scilab/sciruntime.swg new file mode 100644 index 00000000000..9832ed4117d --- /dev/null +++ b/Lib/scilab/sciruntime.swg @@ -0,0 +1,33 @@ +%insert(runtime) "swigrun.swg"; +%insert(runtime) "swigerrors.swg"; + +#define %scilabcode %insert("scilab") + +%insert(runtime) "scirun.swg"; + +%init %{ +#define SWIG_GetModule(clientdata) SWIG_Scilab_GetModule() +#define SWIG_SetModule(clientdata, pointer) SWIG_Scilab_SetModule(pointer) + +SWIGRUNTIME swig_module_info* +SWIG_Scilab_GetModule(void) +{ + return NULL; +} + +SWIGRUNTIME void +SWIG_Scilab_SetModule(swig_module_info *swig_module) +{ +} +%} + +%insert(init) "swiginit.swg" + +%init %{ +#ifdef __cplusplus +extern "C" +#endif +int _Init(SWIG_GatewayParameters) { + SWIG_InitializeModule(NULL); + SWIG_CreateScilabVariables(pvApiCtx); +%} diff --git a/Lib/scilab/scisequence.swg b/Lib/scilab/scisequence.swg new file mode 100644 index 00000000000..cc9da1fabb7 --- /dev/null +++ b/Lib/scilab/scisequence.swg @@ -0,0 +1,195 @@ +/* + * + * Scilab sequence conversions + * + */ + +#define SWIG_Traits_Sequence_frag(Type) %fragment_name(AsVal_Traits_Sequence, Type) + +#define SWIG_AsCheck_Sequence_frag(Type...) %fragment_name(AsCheck_Sequence, Type) +#define SWIG_AsCheck_Sequence_dec(Type...) %symbol_name(AsCheck_Sequence, Type) +#define SWIG_AsGet_Sequence_frag(Type...) %fragment_name(AsGet_Sequence, Type) +#define SWIG_AsGet_Sequence_dec(Type...) %symbol_name(AsGet_Sequence, Type) +#define SWIG_AsSize_Sequence_frag(Type...) %fragment_name(AsSize_Sequence, Type) +#define SWIG_AsSize_Sequence_dec(Type...) %symbol_name(AsSize_Sequence, Type) +#define SWIG_FromCreate_Sequence_frag(Type...) %fragment_name(FromCreate_Sequence, Type) +#define SWIG_FromCreate_Sequence_dec(Type...) %symbol_name(FromCreate_Sequence, Type) +#define SWIG_FromSet_Sequence_frag(Type...) %fragment_name(FromSet_Sequence, Type) +#define SWIG_FromSet_Sequence_dec(Type...) %symbol_name(FromSet_Sequence, Type) + +#define SWIG_Traits_SequenceItem_frag(Type) %fragment_name(AsVal_Traits_SequenceItem, Type) +#define SWIG_AsVal_SequenceItem_frag(Type...) %fragment_name(AsVal_SequenceItem, Type) +#define SWIG_AsVal_SequenceItem_dec(Type...) %symbol_name(AsVal_SequenceItem, Type) +#define SWIG_From_SequenceItem_frag(Type...) %fragment_name(From_SequenceItem, Type) +#define SWIG_From_SequenceItem_dec(Type...) %symbol_name(From_SequenceItem, Type) + +%include +%include +%include +%include +%include +%include + +// +// Sequence conversion +// + +%fragment(SWIG_Traits_Sequence_frag(ptr), "header", + fragment=SWIG_AsCheck_Sequence_frag(ptr), + fragment=SWIG_AsGet_Sequence_frag(ptr), + fragment=SWIG_AsSize_Sequence_frag(ptr), + fragment=SWIG_FromCreate_Sequence_frag(ptr), + fragment=SWIG_FromSet_Sequence_frag(ptr), + fragment="StdTraits", + fragment="") { + +namespace swig { + // Error returned for sequence containers of default item type + template struct traits_as_sequence { + static int check(SwigSciObject obj) { + SWIG_Error(SWIG_TypeError, type_name()); + } + static int get(SwigSciObject obj, void **sequence) { + SWIG_Error(SWIG_TypeError, type_name()); + } + static int size(SwigSciObject obj, int *size) { + SWIG_Error(SWIG_TypeError, type_name()); + } + }; + template struct traits_from_sequence { + static int create(int size, void **sequence) { + SWIG_Error(SWIG_TypeError, type_name()); + } + static SwigSciObject set(int size, void *sequence) { + SWIG_Error(SWIG_TypeError, type_name()); + } + }; + + // Support sequence containers of pointers + template struct traits_as_sequence { + static int check(SwigSciObject obj) { + return SWIG_AsCheck_Sequence_dec(ptr)(obj); + } + static int get(SwigSciObject obj, void **sequence) { + return SWIG_AsGet_Sequence_dec(ptr)(obj, (int **)sequence); + } + static int size(SwigSciObject obj, int *size) { + return SWIG_AsSize_Sequence_dec(ptr)(obj, size); + } + }; + template struct traits_from_sequence { + static int create(int size, void **sequence) { + return SWIG_FromCreate_Sequence_dec(ptr)(size, (uintptr_t **)sequence); + } + static SwigSciObject set(int size, void *sequence) { + return SWIG_FromSet_Sequence_dec(ptr)(size, (uintptr_t *)sequence); + } + }; +} +} + +%define %traits_sequence(CppType, ScilabType) + %fragment(SWIG_Traits_Sequence_frag(CppType), "header", + fragment=SWIG_Traits_Sequence_frag(ptr), + fragment=SWIG_AsCheck_Sequence_frag(CppType), + fragment=SWIG_AsGet_Sequence_frag(CppType), + fragment=SWIG_AsSize_Sequence_frag(CppType), + fragment=SWIG_FromCreate_Sequence_frag(CppType), + fragment=SWIG_FromSet_Sequence_frag(CppType)) { + +namespace swig { + template <> struct traits_as_sequence { + static int check(SwigSciObject obj) { + return SWIG_AsCheck_Sequence_dec(CppType)(obj); + } + static int get(SwigSciObject obj, void **sequence) { + return SWIG_AsGet_Sequence_dec(CppType)(obj, (ScilabType **)sequence); + } + static int size(SwigSciObject obj, int *size) { + return SWIG_AsSize_Sequence_dec(CppType)(obj, size); + } + }; + template <> struct traits_from_sequence { + static int create(int size, void **sequence) { + return SWIG_FromCreate_Sequence_dec(CppType)(size, (ScilabType **)sequence); + } + static SwigSciObject set(int size, void *sequence) { + return SWIG_FromSet_Sequence_dec(CppType)(size, (ScilabType *)sequence); + } + }; +} +} +%enddef + + +// +// Sequence item conversion +// + +%fragment(SWIG_Traits_SequenceItem_frag(ptr), "header", + fragment=SWIG_AsVal_SequenceItem_frag(ptr), + fragment=SWIG_From_SequenceItem_frag(ptr), + fragment="StdTraits", + fragment="") { + +namespace swig { + // Error returned for sequence containers of default item type + template struct traits_asval_sequenceitem { + static T asval(SwigSciObject obj, void *pSequence, int iItemIndex) { + SWIG_Error(SWIG_TypeError, type_name()); + } + }; + template struct traits_from_sequenceitem { + static int from(void *pSequence, int iItemIndex, T itemValue) { + SWIG_Error(SWIG_TypeError, type_name()); + } + }; + + // Support sequence containers of pointers + template struct traits_asval_sequenceitem { + static T* asval(SwigSciObject obj, void *pSequence, int iItemIndex) { + return static_cast(SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex)); + } + }; + template struct traits_from_sequenceitem { + static int from(void *pSequence, int iItemIndex, T *itemValue) { + return SWIG_From_SequenceItem_dec(ptr)((uintptr_t *)pSequence, iItemIndex, (uintptr_t) itemValue); + } + }; +} +} + +%define %traits_sequenceitem(CppType, ScilabType) + %fragment(SWIG_Traits_SequenceItem_frag(CppType), "header", + fragment=SWIG_Traits_SequenceItem_frag(ptr), + fragment=SWIG_AsVal_SequenceItem_frag(CppType), + fragment=SWIG_From_SequenceItem_frag(CppType)) { + +namespace swig { + template <> struct traits_asval_sequenceitem { + static CppType asval(SwigSciObject obj, void *pSequence, int iItemIndex) { + return SWIG_AsVal_SequenceItem_dec(CppType)(obj, (ScilabType *)pSequence, iItemIndex); + } + }; + template <> struct traits_from_sequenceitem { + static int from(void *pSequence, int iItemIndex, CppType itemValue) { + return SWIG_From_SequenceItem_dec(CppType)((ScilabType *)pSequence, iItemIndex, itemValue); + } + }; +} +} +%enddef + +%define %add_traits_sequence(CppType, ScilabType) + %traits_sequence(CppType, ScilabType); + %fragment(SWIG_Traits_Sequence_frag(CppType)); + %traits_sequenceitem(CppType, ScilabType); + %fragment(SWIG_Traits_SequenceItem_frag(CppType)); +%enddef + +%add_traits_sequence(int, int); +%add_traits_sequence(double, double); +%add_traits_sequence(float, float); +%add_traits_sequence(std::string, char*); +%add_traits_sequence(bool, int); + diff --git a/Lib/scilab/scisequencebool.swg b/Lib/scilab/scisequencebool.swg new file mode 100644 index 00000000000..0430c3e397d --- /dev/null +++ b/Lib/scilab/scisequencebool.swg @@ -0,0 +1,98 @@ +/* + * + * Scilab matrix of bool <-> C++ bool container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(bool), "header") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(bool)(SwigSciObject obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isBooleanType(pvApiCtx, piAddrVar)) { + return SWIG_OK; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A boolean is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(bool)(SwigSciObject obj, int **pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciBoolean_AsIntArrayAndSize(pvApiCtx, obj, &iMatrixRowCount, &iMatrixColCount, pSequence, SWIG_Scilab_GetFuncName())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(bool)(SwigSciObject obj, int *piSize) { + int *piMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciBoolean_AsIntArrayAndSize(pvApiCtx, obj, &iMatrixRowCount, &iMatrixColCount, &piMatrix, SWIG_Scilab_GetFuncName()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: An integer vector is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } + *piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(bool), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(bool)(int size, int **pSequence) { + *pSequence = new int[size]; + return *pSequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_FromIntArrayAndSize") { + +SWIGINTERN SwigSciObject +SWIG_FromSet_Sequence_dec(bool)(int size, int *pSequence) { + SwigSciObject obj = SWIG_SciBoolean_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, size, pSequence); + delete (int *)pSequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(bool), "header") { + +SWIGINTERN bool +SWIG_AsVal_SequenceItem_dec(bool)(SwigSciObject obj, int *pSequence, int iItemIndex) { + return pSequence[iItemIndex]; +} +} + +%fragment(SWIG_From_SequenceItem_frag(bool), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(bool)(int *pSequence, int iItemIndex, bool itemValue) { + pSequence[iItemIndex] = itemValue; + return SWIG_OK; +} +} diff --git a/Lib/scilab/scisequencedouble.swg b/Lib/scilab/scisequencedouble.swg new file mode 100644 index 00000000000..29cc52d6a1d --- /dev/null +++ b/Lib/scilab/scisequencedouble.swg @@ -0,0 +1,99 @@ +/* + * + * Scilab matrix of double <-> C++ double container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(double), "header") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(double)(SwigSciObject obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isDoubleType(pvApiCtx, piAddrVar)) { + return SWIG_OK; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A double is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_AsDoubleArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(double)(SwigSciObject obj, double **pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, obj, &iMatrixRowCount, &iMatrixColCount, pSequence, SWIG_Scilab_GetFuncName())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_AsDoubleArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(double)(SwigSciObject obj, int *piSize) { + double *pdblMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, obj, &iMatrixRowCount, &iMatrixColCount, &pdblMatrix, SWIG_Scilab_GetFuncName()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A double vector is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } + *piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(double), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(double)(int size, double **pSequence) { + *pSequence = new double[size]; + return *pSequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_FromDoubleArrayAndSize") { + +SWIGINTERN SwigSciObject +SWIG_FromSet_Sequence_dec(double)(int size, double *pSequence) { + SwigSciObject obj = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, size, pSequence); + delete (double *)pSequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(double), "header") { + +SWIGINTERN double +SWIG_AsVal_SequenceItem_dec(double)(SwigSciObject obj, double *pSequence, int iItemIndex) { + return pSequence[iItemIndex]; +} +} + +%fragment(SWIG_From_SequenceItem_frag(double), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(double)(double *pSequence, int iItemIndex, double itemValue) { + pSequence[iItemIndex] = itemValue; + return SWIG_OK; +} +} + diff --git a/Lib/scilab/scisequencefloat.swg b/Lib/scilab/scisequencefloat.swg new file mode 100644 index 00000000000..41d37e558b3 --- /dev/null +++ b/Lib/scilab/scisequencefloat.swg @@ -0,0 +1,98 @@ +/* + * + * Scilab matrix of float <-> C++ float container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(float), "header") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(float)(SwigSciObject obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isDoubleType(pvApiCtx, piAddrVar)) { + return SWIG_OK; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A double is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(float), "header", + fragment="SWIG_SciDouble_AsFloatArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(float)(SwigSciObject obj, float **pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciDouble_AsFloatArrayAndSize(pvApiCtx, obj, &iMatrixRowCount, &iMatrixColCount, pSequence, SWIG_Scilab_GetFuncName())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(float), "header", + fragment="SWIG_SciDouble_AsFloatArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(float)(SwigSciObject obj, int *piSize) { + float *pdblMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciDouble_AsFloatArrayAndSize(pvApiCtx, obj, &iMatrixRowCount, &iMatrixColCount, &pdblMatrix, SWIG_Scilab_GetFuncName()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A float vector is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } + *piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(float), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(float)(int size, float **pSequence) { + *pSequence = new float[size]; + return *pSequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(float), "header", + fragment="SWIG_SciDouble_FromFloatArrayAndSize") { + +SWIGINTERN SwigSciObject +SWIG_FromSet_Sequence_dec(float)(int size, float *pSequence) { + SwigSciObject obj = SWIG_SciDouble_FromFloatArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, size, pSequence); + delete (float *)pSequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(float), "header") { + +SWIGINTERN float +SWIG_AsVal_SequenceItem_dec(float)(SwigSciObject obj, float *pSequence, int iItemIndex) { + return pSequence[iItemIndex]; +} +} + +%fragment(SWIG_From_SequenceItem_frag(float), "header") { +SWIGINTERN int +SWIG_From_SequenceItem_dec(float)(float *pSequence, int iItemIndex, float itemValue) { + pSequence[iItemIndex] = itemValue; + return SWIG_OK; +} +} + diff --git a/Lib/scilab/scisequenceint.swg b/Lib/scilab/scisequenceint.swg new file mode 100644 index 00000000000..3a9f7bf6372 --- /dev/null +++ b/Lib/scilab/scisequenceint.swg @@ -0,0 +1,104 @@ +/* + * + * Scilab matrix of int <-> C++ int container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(int), "header") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(int)(SwigSciObject obj) { + SciErr sciErr; + int *piAddrVar; + int iType = 0; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if ((iType == sci_matrix) || (iType == sci_ints)) { + return SWIG_OK; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: An integer is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(int), "header", + fragment="SWIG_SciDoubleOrInt32_AsIntArrayAndSize") { +SWIGINTERN int +SWIG_AsGet_Sequence_dec(int)(SwigSciObject obj, int **pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciDoubleOrInt32_AsIntArrayAndSize(pvApiCtx, obj, &iMatrixRowCount, &iMatrixColCount, pSequence, SWIG_Scilab_GetFuncName())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(int), "header", + fragment="SWIG_SciDoubleOrInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(int)(SwigSciObject obj, int *piSize) { + int *piMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciDoubleOrInt32_AsIntArrayAndSize(pvApiCtx, obj, &iMatrixRowCount, &iMatrixColCount, &piMatrix, SWIG_Scilab_GetFuncName()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: An integer vector is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } + *piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(int), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(int)(int size, int **pSequence) { + *pSequence = new int[size]; + return *pSequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(int), "header", + fragment="SWIG_SciDouble_FromIntArrayAndSize") { + +SWIGINTERN SwigSciObject +SWIG_FromSet_Sequence_dec(int)(int size, int *pSequence) { + SwigSciObject obj = SWIG_SciDouble_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, size, pSequence); + delete (int *)pSequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(int), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(int)(SwigSciObject obj, int *pSequence, int iItemIndex) { + return pSequence[iItemIndex]; +} +} + +%fragment(SWIG_From_SequenceItem_frag(int), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(int)(int *pSequence, int iItemIndex, int itemValue) { + pSequence[iItemIndex] = itemValue; + return SWIG_OK; +} +} diff --git a/Lib/scilab/scisequencepointer.swg b/Lib/scilab/scisequencepointer.swg new file mode 100644 index 00000000000..b3618e9412e --- /dev/null +++ b/Lib/scilab/scisequencepointer.swg @@ -0,0 +1,123 @@ +/* + * + * Scilab list of pointer <-> C++ pointer container + * + */ + +%include + +%fragment("", "header") { +%#include +} + +%fragment(SWIG_AsCheck_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(ptr)(SwigSciObject obj) { + return SWIG_CheckScilabList(obj); +} +} + +%fragment(SWIG_AsGet_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(ptr)(SwigSciObject obj, int **piSequence) { + return SWIG_GetScilabList(obj, piSequence); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(ptr)(SwigSciObject obj, int *piSize) { + return SWIG_GetScilabListSize(obj, piSize); +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(ptr), "header", + fragment="") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(ptr)(int size, uintptr_t **pSequence) { + *pSequence = new uintptr_t[size]; + return *pSequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(ptr), "header", + fragment="") { + +SWIGINTERN SwigSciObject +SWIG_FromSet_Sequence_dec(ptr)(int size, uintptr_t *pSequence) { + SciErr sciErr; + int *piListAddr; + + int iVarOut = SWIG_NbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + + sciErr = createList(pvApiCtx, iVarOut, size, &piListAddr); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + for (int i=0; i C++ std::string container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(std::string), "header") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(std::string)(SwigSciObject obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isStringType(pvApiCtx, piAddrVar)) { + return SWIG_OK; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A string is expected.\n"), SWIG_Scilab_GetFuncName(), obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(std::string), "header", + fragment="SWIG_SciString_AsCharPtrArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(std::string)(SwigSciObject obj, char ***pSequence) { + int iRows = 0; + int iCols = 0; + return (SWIG_SciString_AsCharPtrArrayAndSize(pvApiCtx, obj, &iRows, &iCols, pSequence, SWIG_Scilab_GetFuncName())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(std::string), "header", + fragment="SWIG_SciString_AsCharPtrArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(std::string)(SwigSciObject obj, int *piSize) { + char **pstMatrix; + int iCols = 0; + int iRows = 0; + if (SWIG_SciString_AsCharPtrArrayAndSize(pvApiCtx, obj, &iRows, &iCols, &pstMatrix, SWIG_Scilab_GetFuncName()) == SWIG_OK) { + *piSize = iRows * iCols; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(std::string), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(std::string)(int size, char ***pSequence) { + *pSequence = new char*[size]; + return *pSequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(std::string), "header", + fragment="SWIG_SciString_FromCharPtrArrayAndSize") { + +SWIGINTERN SwigSciObject +SWIG_FromSet_Sequence_dec(std::string)(int size, char **pSequence) { + SwigSciObject obj = SWIG_SciString_FromCharPtrArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, size, pSequence); + delete (char **)pSequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(std::string), "header") { + +SWIGINTERN std::string +SWIG_AsVal_SequenceItem_dec(std::string)(SwigSciObject obj, char **pSequence, int iItemIndex) { + return std::string(pSequence[iItemIndex]); +} +} + +%fragment(SWIG_From_SequenceItem_frag(std::string), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(std::string)(char **pSequence, int iItemIndex, std::string itemValue) { + char *pChar = new char(itemValue.size() + 1); + strcpy(pChar, itemValue.c_str()); + pSequence[iItemIndex] = pChar; + return SWIG_OK; +} +} + diff --git a/Lib/scilab/scishort.swg b/Lib/scilab/scishort.swg new file mode 100644 index 00000000000..3d2f0f97a84 --- /dev/null +++ b/Lib/scilab/scishort.swg @@ -0,0 +1,188 @@ +/* + * C-type: short + * Scilab type: double or int16 + */ + +%fragment(SWIG_AsVal_frag(short), "header", fragment="SWIG_SciDoubleOrInt16_AsShort", fragment="") { +#define SWIG_AsVal_short(scilabValue, valuePointer) SWIG_SciDoubleOrInt16_AsShort(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDoubleOrInt16_AsShort", "header") { +SWIGINTERN int +SWIG_SciDoubleOrInt16_AsShort(void *pvApiCtx, int iVar, short *psValue, char *fname) { + SciErr sciErr; + int iType = 0; + int iRows = 0; + int iCols = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_ints) { + int iPrec = 0; + short *psData = NULL; + + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT16) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + sciErr = getMatrixOfInteger16(pvApiCtx, piAddrVar, &iRows, &iCols, &psData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A 16-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + *psValue = *psData; + } + else if (iType == sci_matrix) { + double *pdData = NULL; + double dValue = 0.0f; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A 16-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + dValue = *pdData; + if (dValue != floor(dValue)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 16-bit signed integer.\n"), fname, iVar); + return SWIG_ValueError; + } + if ((dValue < SHRT_MIN) || (dValue > SHRT_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 16-bit signed integer.\n"), fname, iVar); + return SWIG_OverflowError; + } + *psValue = (short) dValue; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(short), "header", fragment="SWIG_SciDouble_FromShort") { +#define SWIG_From_short(scilabValue) SWIG_SciDouble_FromShort(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDouble_FromShort", "header") { +SWIGINTERN int +SWIG_SciDouble_FromShort(void *pvApiCtx, int iVarOut, short sValue, char *fname) { + if (createScalarDouble(pvApiCtx, + SWIG_NbInputArgument(pvApiCtx) + iVarOut, (double) sValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +/* + * C-type: short[] + * Scilab type: double or int16 matrix + */ +%fragment("SWIG_SciDoubleOrInt16_AsShortArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDoubleOrInt16_AsShortArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, short **psValue, char *fname) { + SciErr sciErr; + int iType = 0; + int iPrec = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_matrix) { + double *pdData = NULL; + int size = 0; + int i; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + size = (*iRows) * (*iCols); + *psValue = (short*) malloc(size * sizeof(int*)); + for (i = 0; i < size; i++) + (*psValue)[i] = (short) pdData[i]; + } + else if (iType == sci_ints) { + int iPrec = 0; + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT16) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or a double matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + sciErr = getMatrixOfInteger16(pvApiCtx, piAddrVar, iRows, iCols, psValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or a double matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} +%fragment("SWIG_SciDouble_FromShortArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromShortArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, short *psValue) { + SciErr sciErr; + int i; + double *pdValues = NULL; + + pdValues = (double*) malloc(iRows * iCols * sizeof(double)); + for (i=0; i SCHAR_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 8-bit signed integer.\n"), fname, iVar); + return SWIG_OverflowError; + } + *pscValue = (signed char) dValue; + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 8-bit signed integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(signed char), "header", fragment="SWIG_SciDouble_FromSignedChar") { +#define SWIG_From_signed_SS_char(scilabValue) SWIG_SciDouble_FromSignedChar(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue) +} +%fragment("SWIG_SciDouble_FromSignedChar", "header") { +SWIGINTERN int +SWIG_SciDouble_FromSignedChar(void *pvApiCtx, int iVarOut, signed char scValue) { + if (createScalarDouble(pvApiCtx, + SWIG_NbInputArgument(pvApiCtx) + iVarOut, (double) scValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +/* + * C-type: signed char[] + * Scilab type: double or int8 matrix + */ +%fragment("SWIG_SciDoubleOrInt8_AsSignedCharArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDoubleOrInt8_AsSignedCharArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, signed char **pscValue, char *fname) { + SciErr sciErr; + int iType = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_matrix) { + double *pdData = NULL; + int size = 0; + int i; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + size = (*iRows) * (*iCols); + *pscValue = (signed char*) malloc(size * sizeof(int*)); + for (i = 0; i < size; i++) + (*pscValue)[i] = (signed char) pdData[i]; + } + else if (iType == sci_ints) { + int iPrec = 0; + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT8) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 8-bit signed integer or a double matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + sciErr = getMatrixOfInteger8(pvApiCtx, piAddrVar, iRows, iCols, (char **)pscValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 8-bit signed integer or a double matrix expected.\n"), fname, iVar); + return SWIG_ERROR; + } + return SWIG_OK; +} +} + +%fragment("SWIG_SciDouble_FromSignedCharArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromSignedCharArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, const signed char *pscValue) { + SciErr sciErr; + int i; + double *pdValues = NULL; + + pdValues = (double*) malloc(iRows * iCols * sizeof(double)); + for (i=0; i struct traits_from_ptr { + static SwigSciObject from(Type *val, int owner = 0) { + return SWIG_OK; //SWIG_NewPointerObj(val, type_info(), owner); + } + }; + + template struct traits_from { + static SwigSciObject from(const Type& val) { + return traits_from_ptr::from(new Type(val), 1); + } + }; + + template struct traits_from { + static SwigSciObject from(Type* val) { + return traits_from_ptr::from(val, 0); + } + }; + + template struct traits_from { + static SwigSciObject from(const Type* val) { + return traits_from_ptr::from(const_cast(val), 0); + } + }; + + + template + inline SwigSciObject from(const Type& val) { + return traits_from::from(val); + } + + template + inline SwigSciObject from_ptr(Type* val, int owner) { + return traits_from_ptr::from(val, owner); + } + + // Traits that provides the asval/as/check method + template + struct traits_asptr { + static int asptr(const SwigSciObject& obj, Type **val) { + Type *p; + int res = SWIG_ConvertPtr(obj, (void**)&p, type_info(), 0); + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template + inline int asptr(const SwigSciObject& obj, Type **vptr) { + return traits_asptr::asptr(obj, vptr); + } + + template + struct traits_asval { + static int asval(const SwigSciObject& obj, Type *val) { + if (val) { + Type *p = 0; + int res = traits_asptr::asptr(obj, &p); + if (!SWIG_IsOK(res)) + return res; + if (p) { + typedef typename noconst_traits::noconst_type noconst_type; + *(const_cast(val)) = *p; + if (SWIG_IsNewObj(res)){ + %delete(p); + res = SWIG_DelNewMask(res); + } + return res; + } else { + return SWIG_ERROR; + } + } else { + return traits_asptr::asptr(obj, (Type **)(0)); + } + } + }; + + template struct traits_asval { + static int asval(const SwigSciObject& obj, Type **val) { + if (val) { + typedef typename noconst_traits::noconst_type noconst_type; + noconst_type *p = 0; + int res = traits_asptr::asptr(obj, &p); + if (SWIG_IsOK(res)) { + *(const_cast(val)) = p; + } + return res; + } else { + return traits_asptr::asptr(obj, (Type **)(0)); + } + } + }; + + template + inline int asval(const SwigSciObject& obj, Type *val) { + return traits_asval::asval(obj, val); + } + + template + struct traits_as { + static Type as(const SwigSciObject& obj, bool throw_error) { + Type v; + int res = asval(obj, &v); + if (SWIG_IsOK(res)) { + return v; + } else { + %type_error(swig::type_name()); + if (throw_error) + throw std::invalid_argument("bad type"); + return res; + } + } + }; + + template + struct traits_as { + static Type as(const SwigSciObject& obj, bool throw_error) { + Type *v = 0; + int res = traits_asptr::asptr(obj, &v); + if (SWIG_IsOK(res) && v) { + if (SWIG_IsNewObj(res)) { + Type r(*v); + %delete(v); + return r; + } else { + return *v; + } + } else { + // Uninitialized return value, no Type() constructor required. + static Type *v_def = (Type*) malloc(sizeof(Type)); + %type_error(swig::type_name()); + if (throw_error) + throw std::invalid_argument("bad type"); + memset(v_def,0,sizeof(Type)); + return *v_def; + } + } + }; + + template + struct traits_as { + static Type* as(const SwigSciObject& obj, bool throw_error) { + Type *v = 0; + int res = traits_asptr::asptr(obj, &v); + if (SWIG_IsOK(res)) { + return v; + } else { + %type_error(swig::type_name()); + if (throw_error) + throw std::invalid_argument("bad type"); + return SWIG_OK; + } + } + }; + + template + inline Type as(const SwigSciObject& obj, bool te = false) { + return traits_as::category>::as(obj, te); + } + + template + struct traits_check { + static bool check(const SwigSciObject& obj) { + int res = asval(obj, (Type *)(0)); + return SWIG_IsOK(res) ? true : false; + } + }; + + template + struct traits_check { + static bool check(const SwigSciObject& obj) { + int res = asptr(obj, (Type **)(0)); + return SWIG_IsOK(res) ? true : false; + } + }; + + template + inline bool check(const SwigSciObject& obj) { + return traits_check::category>::check(obj); + } +} +} + +%define %specialize_std_container(Type,Check,As,From) +%{ +namespace swig { + template <> struct traits_asval { + typedef Type value_type; + static int asval(const SwigSciObject& obj, value_type *val) { + if (Check(obj)) { + if (val) *val = As(obj); + return SWIG_OK; + } + return SWIG_ERROR; + } + }; + template <> struct traits_from { + typedef Type value_type; + static SwigSciObject from(const value_type& val) { + return From(val); + } + }; + + template <> + struct traits_check { + static int check(const SwigSciObject& obj) { + int res = Check(obj); + return obj && res ? res : 0; + } + }; +} +%} +%enddef + + +#define specialize_std_vector(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) +#define specialize_std_list(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) +#define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) +#define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) +#define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From) + diff --git a/Lib/scilab/scitypemaps.swg b/Lib/scilab/scitypemaps.swg new file mode 100644 index 00000000000..62a819f3504 --- /dev/null +++ b/Lib/scilab/scitypemaps.swg @@ -0,0 +1,243 @@ +// Scilab fragments for primitive types +%include + +%include + +// Scilab object type +#define SWIG_Object int + +#define %append_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR +#define %set_constant(name, obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR // Name is managed by the the function name +#define %raise(obj, type, desc) SWIG_Scilab_Raise(obj, type, desc) +#define %set_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR +#define %set_varoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR +#define %set_argoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR + +// Include the unified typemap library +%include + +/* ---------------------------------------------------------------------------*/ +/* Generic typmemaps */ +/* */ +/* This typemap is used when Scilab does not store this type directly */ +/* For example, a 'float' is stored in Scilab as a 'double' */ +/* So we read a 'double' in Scilab and cast it to a 'float' */ +/* ---------------------------------------------------------------------------*/ + +%define %scilab_in_typemap_withcast(TYPEMAPTYPE, FRAGMENTNAME, CTYPE, TEMPTYPE, TEMPINIT) +%typemap(TYPEMAPTYPE, fragment="FRAGMENTNAME") CTYPE { + TEMPTYPE tempValue = TEMPINIT; + if(FRAGMENTNAME(pvApiCtx, $input, &tempValue, SWIG_Scilab_GetFuncName()) != SWIG_OK) { + return SWIG_ERROR; + } + $1 = (CTYPE) tempValue; +} +%enddef +%define %scilab_inptr_typemap(TYPEMAPTYPE, FRAGMENTNAME, CTYPE) +%typemap(TYPEMAPTYPE, noblock=1, fragment="FRAGMENTNAME") CTYPE { + if (FRAGMENTNAME(pvApiCtx, $input, %as_voidptrptr(&$1), SWIG_Scilab_GetFuncName()) != SWIG_OK) { + return SWIG_ERROR; + } +} +%enddef + +%define %scilab_out_typemap(TYPEMAPTYPE, FRAGMENTNAME, CTYPE) +%typemap(TYPEMAPTYPE, noblock=1, fragment="FRAGMENTNAME") CTYPE { + if (FRAGMENTNAME(pvApiCtx, $result, $1) != SWIG_OK) { + return SWIG_ERROR; + } +} +%enddef + +%define %scilab_outptr_typemap(TYPEMAPTYPE, FRAGMENTNAME, CTYPE) +%typemap(TYPEMAPTYPE, noblock=1, fragment="FRAGMENTNAME") CTYPE { + if (FRAGMENTNAME(pvApiCtx, $result, %as_voidptr($1)) != SWIG_OK) { + return SWIG_ERROR; + } +} +%enddef + +%define %scilab_varout_typemap(TYPEMAPTYPE, FRAGMENTNAME, CTYPE) +%typemap(TYPEMAPTYPE, noblock=1, fragment="FRAGMENTNAME") CTYPE { + if (FRAGMENTNAME(pvApiCtx, $result, $value) != SWIG_OK) { + return SWIG_ERROR; + } +} +%enddef + +%define %scilab_varoutptr_typemap(TYPEMAPTYPE, FRAGMENTNAME, CTYPE) +%typemap(TYPEMAPTYPE, noblock=1, fragment="FRAGMENTNAME") CTYPE { + if (FRAGMENTNAME(pvApiCtx, $result, %as_voidptr($value)) != SWIG_OK) { + return SWIG_ERROR; + } +} +%enddef + +%define %scilab_in_typemap(TYPEMAPTYPE, FRAGMENTNAME, CTYPE) +%typemap(TYPEMAPTYPE, noblock=1, fragment="FRAGMENTNAME") CTYPE { + if (FRAGMENTNAME(pvApiCtx, $input, &$1, SWIG_Scilab_GetFuncName()) != SWIG_OK) { + return SWIG_ERROR; + } +} +%enddef + + +/* ---------------------------------------------------------------------------*/ +/* Array typmemaps */ +/* ---------------------------------------------------------------------------*/ + +%include + + +/* ---------------------------------------------------------------------------*/ +/* Enum typemaps */ +/* ---------------------------------------------------------------------------*/ + +%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(Enum)) enum SWIGTYPE (int val) { + if (SWIG_AsVal_dec(Enum)($input, &val) != SWIG_OK) { + return SWIG_ERROR; + } + $1 = %reinterpret_cast(val, $ltype); +} + +%typemap(out, fragment=SWIG_From_frag(Enum)) enum SWIGTYPE { + if (SWIG_From_dec(Enum)($1) != SWIG_OK) { + return SWIG_ERROR; + } +} + +/* ---------------------------------------------------------------------------*/ +/* Typecheck typemaps */ +/* ---------------------------------------------------------------------------*/ + +%define %scilab_typecheck_generic(PRECEDENCE, TYPE_CHECK_FUNCTION, TYPE) +%typecheck(PRECEDENCE) TYPE { + int *piAddrVar = NULL; + SciErr sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + $1 = TYPE_CHECK_FUNCTION(pvApiCtx, piAddrVar); +} +%enddef + +/* Scilab equivalent for C integers can be sci_ints or sci_matrix */ +%define %scilab_typecheck_integer(PRECEDENCE, INTTYPE, TYPE) +%typecheck(PRECEDENCE) TYPE { + int *piAddrVar = NULL; + SciErr sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + $1 = isIntegerType(pvApiCtx, piAddrVar); + if ($1 == 1) { + int iPrec = 0; + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + $1 = (iPrec == INTTYPE) ? 1 : 0; + } + else { + $1 = isDoubleType(pvApiCtx, piAddrVar); + } +} +%enddef + +// Double (and Float) have priority over before Integer type. + +// Primitive types +%scilab_typecheck_generic(SWIG_TYPECHECK_VOIDPTR, isPointerType, SWIGTYPE *) +%scilab_typecheck_generic(SWIG_TYPECHECK_POINTER, isPointerType, SWIGTYPE *) +%scilab_typecheck_generic(SWIG_TYPECHECK_BOOL, isBooleanType, bool) +%scilab_typecheck_generic(16, isDoubleType, double) +%scilab_typecheck_generic(17, isDoubleType, float) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT8, SCI_INT8, signed char) +%scilab_typecheck_integer(SWIG_TYPECHECK_UINT8, SCI_UINT8, unsigned char) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT16, SCI_INT16, short) +%scilab_typecheck_integer(SWIG_TYPECHECK_UINT16, SCI_UINT16, unsigned short) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT32, SCI_INT32, int) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT32, SCI_INT32, long) +%scilab_typecheck_integer(SWIG_TYPECHECK_UINT32, SCI_UINT32, unsigned int) +%scilab_typecheck_integer(SWIG_TYPECHECK_UINT32, SCI_UINT32, unsigned long) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT32, SCI_INT32, enum SWIGTYPE) +%scilab_typecheck_generic(SWIG_TYPECHECK_CHAR, isStringType, char) + +// Arrays +%scilab_typecheck_generic(SWIG_TYPECHECK_BOOL_ARRAY, isBooleanType, bool) +%scilab_typecheck_generic(1016, isDoubleType, double [ANY]) +%scilab_typecheck_generic(1017, isDoubleType, float [ANY]) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT8_ARRAY, SCI_INT8, signed char [ANY]) +%scilab_typecheck_integer(1026, SCI_UINT8, unsigned char [ANY]) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT16_ARRAY, SCI_INT16, short [ANY]) +%scilab_typecheck_integer(1036, SCI_UINT16, unsigned short [ANY]) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT32_ARRAY, SCI_INT32, int [ANY]) +%scilab_typecheck_integer(SWIG_TYPECHECK_INT32_ARRAY, SCI_INT32, long [ANY]) +%scilab_typecheck_integer(1046, SCI_UINT32, unsigned int [ANY]) +%scilab_typecheck_integer(1046, SCI_UINT32, unsigned long [ANY]) +%scilab_typecheck_generic(SWIG_TYPECHECK_CHAR_ARRAY, isStringType, char [ANY]) +%scilab_typecheck_generic(SWIG_TYPECHECK_STRING_ARRAY, isStringType, char *[ANY]) +%scilab_typecheck_generic(SWIG_TYPECHECK_STRING_ARRAY, isStringType, char **) + + +/* ---------------------------------------------------------------------------*/ +/* %scilabconstcode() feature typemaps */ +/* ---------------------------------------------------------------------------*/ + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(double)) double +%{ + if (SWIG_CreateScilabVariable_double(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) int +%{ + if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(uint)) unsigned int +%{ + if (SWIG_CreateScilabVariable_uint(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) long +%{ + if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(uint)) unsigned long +%{ + if (SWIG_CreateScilabVariable_uint(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(char)) char +%{ + if (SWIG_CreateScilabVariable_char(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(charptr)) char * +%{ + if (SWIG_CreateScilabVariable_charptr(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + +%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(double)) enum SWIGTYPE +%{ + if (SWIG_CreateScilabVariable_double(pvApiCtx, "$result", $value) != SWIG_OK) + return SWIG_ERROR; +%} + + +/* ---------------------------------------------------------------------------*/ +/* Exception typmemaps */ +/* ---------------------------------------------------------------------------*/ + +%include diff --git a/Lib/scilab/sciunsignedchar.swg b/Lib/scilab/sciunsignedchar.swg new file mode 100644 index 00000000000..f733895807c --- /dev/null +++ b/Lib/scilab/sciunsignedchar.swg @@ -0,0 +1,190 @@ +/* + * C-type: unsigned char + * Scilab type: double or uint8 + */ +%fragment(SWIG_AsVal_frag(unsigned char), "header", fragment="SWIG_SciDoubleOrUint8_AsUnsignedChar", fragment="") { +#define SWIG_AsVal_unsigned_SS_char(scilabValue, valuePointer) SWIG_SciDoubleOrUint8_AsUnsignedChar(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDoubleOrUint8_AsUnsignedChar", "header") { +SWIGINTERN int +SWIG_SciDoubleOrUint8_AsUnsignedChar(void *pvApiCtx, int iVar, unsigned char *pucValue, char *fname) { + SciErr sciErr; + int iType = 0; + int iRows = 0; + int iCols = 0; + int iPrec = 0; + int *piAddrVar = NULL; + unsigned char *pucData = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_ints) { + if (pucValue) { + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_UINT8) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + sciErr = getMatrixOfUnsignedInteger8(pvApiCtx, piAddrVar, &iRows, &iCols, &pucData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), fname, iVar); + return SWIG_ERROR; + } + *pucValue = *pucData; + } + } + else if (iType == sci_matrix) { + if (pucValue) { + double *pdData = NULL; + double dValue = 0.0f; + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), fname, iVar); + return SWIG_TypeError; + } + dValue = *pdData; + if (dValue != floor(dValue)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 8-bit unsigned integer.\n"), fname, iVar); + return SWIG_ValueError; + } + if ((dValue < 0) || (dValue > UCHAR_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 8-bit unsigned integer.\n"), fname, iVar); + return SWIG_OverflowError; + } + *pucValue = (unsigned char) dValue; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(unsigned char), "header", fragment="SWIG_SciDouble_FromUnsignedChar") { +#define SWIG_From_unsigned_SS_char(value) SWIG_SciDouble_FromUnsignedChar(pvApiCtx, SWIG_Scilab_GetOutputPosition(), value) +} +%fragment("SWIG_SciDouble_FromUnsignedChar", "header") { +SWIGINTERN int +SWIG_SciDouble_FromUnsignedChar(void *pvApiCtx, int iVarOut, unsigned char ucValue) { + if (createScalarDouble(pvApiCtx, + SWIG_NbInputArgument(pvApiCtx) + iVarOut, (double) ucValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +/* + * C-type: unsigned char[] + * Scilab type: double or uint8 matrix + */ +%fragment("SWIG_SciDoubleOrUint8_AsUnsignedCharArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDoubleOrUint8_AsUnsignedCharArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, unsigned char **pucValue, char *fname) { + SciErr sciErr; + int iType = 0; + int iPrec = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_matrix) { + double *pdData = NULL; + int size = 0; + int i; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + size = (*iRows) * (*iCols); + *pucValue = (unsigned char*) malloc(size * sizeof(int*)); + for (i = 0; i < size; i++) + (*pucValue)[i] = (unsigned char) pdData[i]; + } + else if (iType == sci_ints) { + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iPrec != SCI_UINT8) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double vector expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + sciErr = getMatrixOfUnsignedInteger8(pvApiCtx, piAddrVar, iRows, iCols, pucValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double vector expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment("SWIG_SciDouble_FromUnsignedCharArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromUnsignedCharArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, const unsigned char *pucValues) { + SciErr sciErr; + double *pdValues = NULL; + int i; + + pdValues = (double*) malloc(iRows * iCols * sizeof(double)); + for (i=0; i UINT_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 32-bit unsigned integer.\n"), fname, iVar); + return SWIG_OverflowError; + } + *puiValue = (unsigned int) dValue; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer or a double expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(unsigned int), "header", fragment="SWIG_SciDouble_FromUnsignedInt") { +%#define SWIG_From_unsigned_SS_int(scilabValue) SWIG_SciDouble_FromUnsignedInt(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDouble_FromUnsignedInt", "header") { +SWIGINTERN int +SWIG_SciDouble_FromUnsignedInt(void *pvApiCtx, int iVarOut, unsigned int uiValue, char *fname) { + if (createScalarDouble(pvApiCtx, + SWIG_NbInputArgument(pvApiCtx) + iVarOut, (double) uiValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +/* + * C-type: unsigned int[] + * Scilab type: uint32 vector + */ +%fragment("SWIG_SciDoubleOrUint32_AsUnsignedIntArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDoubleOrUint32_AsUnsignedIntArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, unsigned int **puiValue, char *fname) { + SciErr sciErr; + int iType = 0; + int iPrec = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_matrix) { + double *pdData = NULL; + int size = 0; + int i; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + size = (*iRows) * (*iCols); + *puiValue = (unsigned int*) malloc(size * sizeof(int*)); + for (i = 0; i < size; i++) + (*puiValue)[i] = (unsigned int) pdData[i]; + } + else if (iType == sci_ints) { + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iPrec != SCI_UINT32) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer or a double vector expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, piAddrVar, iRows, iCols, puiValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer or a double vector expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment("SWIG_SciDouble_FromUnsignedIntArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromUnsignedIntArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, unsigned int *puiValues) { + SciErr sciErr; + double *pdValues = NULL; + int i; + + pdValues = (double*) malloc(iRows * iCols * sizeof(double)); + for (i=0; i USHRT_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 16-bit unsigned integer.\n"), fname, iVar); + return SWIG_OverflowError; + } + *pusValue = (unsigned short) dValue; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_frag(unsigned short), "header", fragment="SWIG_SciDouble_FromUnsignedShort") { +%#define SWIG_From_unsigned_SS_short(scilabValue) SWIG_SciDouble_FromUnsignedShort(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +} +%fragment("SWIG_SciDouble_FromUnsignedShort", "header") { +SWIGINTERN int +SWIG_SciDouble_FromUnsignedShort(void *pvApiCtx, int iVarOut, unsigned short usValue, char *fname) { + if (createScalarDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, (double) usValue)) + return SWIG_ERROR; + return SWIG_OK; +} +} + +/* + * C-type: unsigned short[] + * Scilab type: uint16 vector + */ +%fragment("SWIG_SciDoubleOrUint16_AsUnsignedShortArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDoubleOrUint16_AsUnsignedShortArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, unsigned short **pusValue, char *fname) { + SciErr sciErr; + int iType = 0; + int iPrec = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_matrix) { + double *pdData = NULL; + int size = 0; + int i; + + sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + size = (*iRows) * (*iCols); + *pusValue = (unsigned short*) malloc(size * sizeof(int*)); + for (i = 0; i < size; i++) + (*pusValue)[i] = (unsigned short) pdData[i]; + } + else if (iType == sci_ints) { + sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iPrec != SCI_UINT16) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double vector expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + sciErr = getMatrixOfUnsignedInteger16(pvApiCtx, piAddrVar, iRows, iCols, pusValue); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double vector expected.\n"), fname, iVar); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment("SWIG_SciDouble_FromUnsignedShortArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciDouble_FromUnsignedShortArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, unsigned short *pusValues) { + SciErr sciErr; + double *pdValues = NULL; + int i; + + pdValues = (double*) malloc(iRows * iCols * sizeof(double)); + for (i=0; i + diff --git a/Lib/scilab/std_basic_string.i b/Lib/scilab/std_basic_string.i new file mode 100644 index 00000000000..4922abd3546 --- /dev/null +++ b/Lib/scilab/std_basic_string.i @@ -0,0 +1,47 @@ +/* + * C++: basic_string + * Scilab: string + */ + +#define %swig_basic_string(Type...) %swig_sequence_methods_val(Type) + +%fragment(SWIG_AsPtr_frag(std::basic_string), "header", fragment="SWIG_SciString_AsCharPtrAndLength") { +SWIGINTERN int +SWIG_AsPtr_dec(std::basic_string)(int _iVar, std::basic_string **_pstValue) { + char* buf = 0; + size_t len = 0; + int alloc = SWIG_OLDOBJ; + + if (SWIG_IsOK((SWIG_SciString_AsCharPtrAndSize(pvApiCtx, _iVar, &buf, &len, &alloc, SWIG_Scilab_GetFuncName())))) { + if (buf) { + if (_pstValue) { + *_pstValue = new std::string(buf, len - 1); + sciprint("%s\n", (*_pstValue)->c_str()); + } + if (alloc == SWIG_NEWOBJ) { + delete[] buf; + } + return SWIG_NEWOBJ; + } + else { + if (_pstValue) { + *_pstValue = NULL; + } + return SWIG_OLDOBJ; + } + } else { + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_From_frag(std::basic_string), "header", fragment="SWIG_SciString_FromCharPtr") { +SWIGINTERN int +SWIG_From_dec(std::basic_string)(std::basic_string _pstValue) { + return SWIG_SciString_FromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _pstValue.c_str()); +} +} + +%include + + diff --git a/Lib/scilab/std_char_traits.i b/Lib/scilab/std_char_traits.i new file mode 100644 index 00000000000..bf4e6c47dd4 --- /dev/null +++ b/Lib/scilab/std_char_traits.i @@ -0,0 +1 @@ +%include diff --git a/Lib/scilab/std_common.i b/Lib/scilab/std_common.i new file mode 100644 index 00000000000..97cfa7b0743 --- /dev/null +++ b/Lib/scilab/std_common.i @@ -0,0 +1,72 @@ +%include +%include + + +// Generate the traits for a 'primitive' type, such as 'double', +// for which the SWIG_AsVal and SWIG_From methods are already defined. + +%define %traits_ptypen(Type...) + %fragment(SWIG_Traits_frag(Type),"header", + fragment=SWIG_AsVal_frag(Type), + fragment=SWIG_From_frag(Type), + fragment="StdTraits") { +namespace swig { + template <> struct traits< Type > { + typedef value_category category; + static const char* type_name() { return #Type; } + }; + template <> struct traits_asval< Type > { + typedef Type value_type; + static int asval(SwigSciObject obj, value_type *val) { + return SWIG_AsVal(Type)(obj, val); + } + }; + template <> struct traits_from< Type > { + typedef Type value_type; + static SwigSciObject from(const value_type& val) { + return SWIG_From(Type)(val); + } + }; +} +} +%enddef + +/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums + is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit + instantiations required using %template). The STL containers define the 'front' method and the typemap + below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the + standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from + required in the generated code for enums. */ + +%define %traits_enum(Type...) + %fragment("SWIG_Traits_enum_"{Type},"header", + fragment=SWIG_AsVal_frag(int), + fragment=SWIG_From_frag(int), + fragment="StdTraits") { +namespace swig { + template <> struct traits_asval< Type > { + typedef Type value_type; + static int asval(SwigSciObject obj, value_type *val) { + return SWIG_AsVal(int)(obj, (int *)val); + } + }; + template <> struct traits_from< Type > { + typedef Type value_type; + static SwigSciObject from(const value_type& val) { + return SWIG_From(int)((int)val); + } + }; +} +} +%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%} +%enddef + + +%include + +// +// Generates the traits for all the known primitive +// C++ types (int, double, ...) +// +%apply_cpptypes(%traits_ptypen); + diff --git a/Lib/scilab/std_container.i b/Lib/scilab/std_container.i new file mode 100644 index 00000000000..a1e037b8c10 --- /dev/null +++ b/Lib/scilab/std_container.i @@ -0,0 +1,3 @@ +%include +%include + diff --git a/Lib/scilab/std_deque.i b/Lib/scilab/std_deque.i new file mode 100644 index 00000000000..d2ca597a87e --- /dev/null +++ b/Lib/scilab/std_deque.i @@ -0,0 +1,31 @@ +/* + * + * C++ type : STL deque + * Scilab type : matrix (for primitive types) or list (for pointer types) + * +*/ + +%fragment("StdDequeTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(const SwigSciObject &obj, std::deque **deq) { + return traits_asptr_stdseq >::asptr(obj, deq); + } + }; + + template + struct traits_from > { + static SwigSciObject from(const std::deque& deq) { + return traits_from_stdseq >::from(deq); + } + }; + } +%} + + +#define %swig_deque_methods(Type...) %swig_sequence_methods(Type) +#define %swig_deque_methods_val(Type...) %swig_sequence_methods_val(Type); + +%include diff --git a/Lib/scilab/std_except.i b/Lib/scilab/std_except.i new file mode 100644 index 00000000000..af98428f65d --- /dev/null +++ b/Lib/scilab/std_except.i @@ -0,0 +1 @@ +%include diff --git a/Lib/scilab/std_list.i b/Lib/scilab/std_list.i new file mode 100644 index 00000000000..75d002d49d3 --- /dev/null +++ b/Lib/scilab/std_list.i @@ -0,0 +1,30 @@ +/* + * + * C++ type : STL list + * Scilab type : matrix (for primitive types) or list (for pointer types) + * +*/ + +%fragment("StdListTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(SwigSciObject obj, std::list **lis) { + return traits_asptr_stdseq >::asptr(obj, lis); + } + }; + + template + struct traits_from > { + static SwigSciObject from(const std::list &lis) { + return traits_from_stdseq >::from(lis); + } + }; + } +%} + +#define %swig_list_methods(Type...) %swig_sequence_methods(Type) +#define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type); + +%include diff --git a/Lib/scilab/std_map.i b/Lib/scilab/std_map.i new file mode 100644 index 00000000000..250d2d84c5f --- /dev/null +++ b/Lib/scilab/std_map.i @@ -0,0 +1,69 @@ +// +// SWIG typemaps for std::map +// +// Common implementation + +%include + +// ------------------------------------------------------------------------ +// std::map +// ------------------------------------------------------------------------ + +%{ +#include +#include +#include +%} + +// exported class + +namespace std { + + template class map { + // add typemaps here + public: + map(); + map(const map &); + + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + const T& get(const K& key) throw (std::out_of_range) { + std::map::iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); + } + void set(const K& key, const T& x) { + (*self)[key] = x; + } + void del(const K& key) throw (std::out_of_range) { + std::map::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + bool has_key(const K& key) { + std::map::iterator i = self->find(key); + return i != self->end(); + } + } + }; + +// Legacy macros (deprecated) +%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" +%enddef + +%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" +%enddef + +%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) +#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" +%enddef + +} diff --git a/Lib/scilab/std_multiset.i b/Lib/scilab/std_multiset.i new file mode 100644 index 00000000000..67e17926fd1 --- /dev/null +++ b/Lib/scilab/std_multiset.i @@ -0,0 +1,30 @@ +/* + * + * C++ type : STL multiset + * Scilab type : matrix (for primitive types) or list (for pointer types) + * +*/ + +%fragment("StdMultisetTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(const SwigSciObject &obj, std::multiset **multiset) { + return traits_asptr_stdseq >::asptr(obj, multiset); + } + }; + + template + struct traits_from > { + static SwigSciObject from(const std::multiset& multiset) { + return traits_from_stdseq >::from(multiset); + } + }; + } +%} + +#define %swig_multiset_methods(Set...) %swig_sequence_methods(Type) +#define %swig_multiset_methods_val(Type...) %swig_sequence_methods_val(Type); + +%include diff --git a/Lib/scilab/std_pair.i b/Lib/scilab/std_pair.i new file mode 100644 index 00000000000..1448d65242f --- /dev/null +++ b/Lib/scilab/std_pair.i @@ -0,0 +1,34 @@ +/* ----------------------------------------------------------------------------- + * std_pair.i + * + * Typemaps for std::pair + * ----------------------------------------------------------------------------- */ + +%include +%include + +// ------------------------------------------------------------------------ +// std::pair +// ------------------------------------------------------------------------ + +%{ +#include +%} + +namespace std { + + template struct pair { + + pair(); + pair(T first, U second); + pair(const pair& p); + + template pair(const pair &p); + + T first; + U second; + }; + + // add specializations here + +} diff --git a/Lib/scilab/std_set.i b/Lib/scilab/std_set.i new file mode 100644 index 00000000000..9070e2d6860 --- /dev/null +++ b/Lib/scilab/std_set.i @@ -0,0 +1,32 @@ +/* + * + * C++ type : STL set + * Scilab type : matrix (for primitive types) or list (for pointer types) + * +*/ + +%fragment("StdSetTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(const SwigSciObject &obj, std::set **set) { + return traits_asptr_stdseq >::asptr(obj, set); + } + }; + + template + struct traits_from > { + static SwigSciObject from(const std::set& set) { + return traits_from_stdseq >::from(set); + } + }; + } +%} + + +#define %swig_set_methods(Type...) %swig_sequence_methods(Type) +#define %swig_set_methods_val(Type...) %swig_sequence_methods_val(Type); + +%include + diff --git a/Lib/scilab/std_string.i b/Lib/scilab/std_string.i new file mode 100644 index 00000000000..71ac6d2f433 --- /dev/null +++ b/Lib/scilab/std_string.i @@ -0,0 +1,39 @@ +/* + * POINTER + */ +%fragment(SWIG_AsPtr_frag(std::string), "header", fragment="SWIG_SciString_AsCharPtrAndSize") { +SWIGINTERN int +SWIG_AsPtr_dec(std::string)(int iVar, std::string **pstValue) { + char* buf = 0; + size_t size = 0; + int alloc = SWIG_OLDOBJ; + + if (SWIG_IsOK((SWIG_SciString_AsCharPtrAndSize(pvApiCtx, iVar, &buf, &size, &alloc, SWIG_Scilab_GetFuncName())))) { + if (buf) { + if (pstValue) { + *pstValue = new std::string(buf, size); + } + if (alloc == SWIG_NEWOBJ) { + delete[] buf; + } + return SWIG_NEWOBJ; + } else { + if (pstValue) { + *pstValue = NULL; + } + return SWIG_OLDOBJ; + } + } else { + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_From_frag(std::string), "header", fragment="SWIG_SciString_FromCharPtr") { +SWIGINTERN int +SWIG_From_dec(std::string)(std::string pstValue) { + return SWIG_SciString_FromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pstValue.c_str()); +} +} + +%include diff --git a/Lib/scilab/std_vector.i b/Lib/scilab/std_vector.i new file mode 100644 index 00000000000..6eaeeca57fd --- /dev/null +++ b/Lib/scilab/std_vector.i @@ -0,0 +1,31 @@ +/* + * + * C++ type : STL vector + * Scilab type : matrix (for primitive types) or list (for pointer types) + * +*/ + +%fragment("StdVectorTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(const SwigSciObject &obj, std::vector **vec) { + return traits_asptr_stdseq >::asptr(obj, vec); + } + }; + + template + struct traits_from > { + static SwigSciObject from(const std::vector& vec) { + return traits_from_stdseq >::from(vec); + } + }; + } +%} + + +#define %swig_vector_methods(Type...) %swig_sequence_methods(Type) +#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type); + +%include diff --git a/Lib/scilab/stl.i b/Lib/scilab/stl.i new file mode 100644 index 00000000000..b29f7d84dc3 --- /dev/null +++ b/Lib/scilab/stl.i @@ -0,0 +1,6 @@ +/* initial STL definition. extended as needed in each language */ +%include +%include +%include +%include +%include diff --git a/Lib/scilab/typemaps.i b/Lib/scilab/typemaps.i new file mode 100644 index 00000000000..9d713874355 --- /dev/null +++ b/Lib/scilab/typemaps.i @@ -0,0 +1,62 @@ +/* ----------------------------------------------------------------------------- + * typemaps.i + * + * ----------------------------------------------------------------------------- */ + +// INPUT typemaps +%define %scilab_input_typemap(Type) +%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(Type)) Type *INPUT(Type temp)(int ecode), Type &INPUT(Type temp)(int ecode) { + ecode = SWIG_AsVal_dec(Type)($input, &temp); + if (!SWIG_IsOK(ecode)) { + %argument_fail(ecode, "$type", $symname, $argnum); + } + $1 = &temp; +} + +%typemap(freearg, noblock=1) Type *INPUT, Type &INPUT { +} + +%typemap(typecheck) Type *INPUT, Type &INPUT { +} +%enddef + +// OUTPUT typemaps +%define %scilab_output_typemap(Type) +%typemap(argout, noblock=1, fragment=SWIG_From_frag(Type)) Type *OUTPUT, Type &OUTPUT { + %set_output(SWIG_From_dec(Type)(*$1)); +} +%enddef + +// INOUT typemaps +%define %scilab_inout_typemap(Type) + %typemap(in) Type *INOUT = Type *INPUT; + %typemap(in) Type &INOUT = Type &INPUT; + %typemap(argout) Type *INOUT = Type *OUTPUT; + %typemap(argout) Type &INOUT = Type &OUTPUT; +%enddef + + +%define %scilab_inout_typemaps(Type) + %scilab_input_typemap(%arg(Type)) + %scilab_output_typemap(%arg(Type)) + %scilab_inout_typemap(%arg(Type)) +%enddef + +%scilab_inout_typemaps(double); +%scilab_inout_typemaps(signed char); +%scilab_inout_typemaps(unsigned char); +%scilab_inout_typemaps(short); +%scilab_inout_typemaps(unsigned short); +%scilab_inout_typemaps(int); +%scilab_inout_typemaps(unsigned int); +%scilab_inout_typemaps(long); +%scilab_inout_typemaps(unsigned long); +%scilab_inout_typemaps(bool); +%scilab_inout_typemaps(float); + +//%apply_ctypes(%scilab_inout_typemaps); + + + + + diff --git a/Lib/std/_std_deque.i b/Lib/std/_std_deque.i index 7dd3552dbdf..e860e947f2c 100644 --- a/Lib/std/_std_deque.i +++ b/Lib/std/_std_deque.i @@ -35,11 +35,11 @@ deque(); deque(unsigned int size, const T& value=T()); - deque(const deque &); + deque(const deque< T > &); ~deque(); void assign(unsigned int n, const T& value); - void swap(deque &x); + void swap(deque< T > &x); unsigned int size() const; unsigned int max_size() const; void resize(unsigned int n, T c = T()); @@ -78,17 +78,17 @@ throw std::out_of_range("deque index out of range"); } } - std::deque getslice(int i, int j) { + std::deque< T > getslice(int i, int j) { int size = int(self->size()); if (i<0) i = size+i; if (j<0) j = size+j; if (i<0) i = 0; if (j>size) j = size; - std::deque tmp(j-i); + std::deque< T > tmp(j-i); std::copy(self->begin()+i,self->begin()+j,tmp.begin()); return tmp; } - void setslice(int i, int j, const std::deque& v) { + void setslice(int i, int j, const std::deque< T >& v) { int size = int(self->size()); if (i<0) i = size+i; if (j<0) j = size+j; diff --git a/Lib/std/std_array.i b/Lib/std/std_array.i new file mode 100644 index 00000000000..aadc3b80c40 --- /dev/null +++ b/Lib/std/std_array.i @@ -0,0 +1,85 @@ +// +// std::array +// + +%include + +%define %std_array_methods(array...) + %std_sequence_methods_non_resizable(array) + void fill(const value_type& u); +%enddef + + +%define %std_array_methods_val(array...) + %std_sequence_methods_non_resizable_val(array) + void fill(const value_type& u); +%enddef + +// ------------------------------------------------------------------------ +// std::array +// +// The aim of all that follows would be to integrate std::array with +// as much as possible, namely, to allow the user to pass and +// be returned tuples or lists. +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::array), f(const std::array&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::array can be passed. +// -- f(std::array&), f(std::array*): +// the parameter may be modified; therefore, only a wrapped std::array +// can be passed. +// -- std::array f(), const std::array& f(): +// the array is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::array& f(), std::array* f(): +// the array is returned by reference; therefore, a wrapped std::array +// is returned +// -- const std::array* f(), f(const std::array*): +// for consistency, they expect and return a plain array pointer. +// ------------------------------------------------------------------------ + + +// exported classes + +namespace std { + + template + class array { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + + %traits_swigtype(_Tp); + %traits_enum(_Tp); + + %fragment(SWIG_Traits_frag(std::array< _Tp, _Nm >), "header", + fragment=SWIG_Traits_frag(_Tp), + fragment="StdArrayTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::array<" #_Tp "," #_Nm " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_STDARRAY, std::array< _Tp, _Nm >); + +#ifdef %swig_array_methods + // Add swig/language extra methods + %swig_array_methods(std::array< _Tp, _Nm >); +#endif + + %std_array_methods(array); + }; +} + diff --git a/Lib/std/std_basic_string.i b/Lib/std/std_basic_string.i index 1aa5721c96e..fb7afc1e67e 100644 --- a/Lib/std/std_basic_string.i +++ b/Lib/std/std_basic_string.i @@ -200,7 +200,7 @@ namespace std { #ifdef %swig_basic_string // Add swig/language extra methods - %swig_basic_string(std::basic_string<_CharT, _Traits, _Alloc >); + %swig_basic_string(std::basic_string< _CharT, _Traits, _Alloc >); #endif #ifdef SWIG_EXPORT_ITERATOR_METHODS @@ -238,19 +238,19 @@ namespace std { %newobject __radd__; %extend { - std::basic_string<_CharT,_Traits,_Alloc >* __add__(const basic_string& v) { - std::basic_string<_CharT,_Traits,_Alloc >* res = new std::basic_string<_CharT,_Traits,_Alloc >(*self); + std::basic_string< _CharT,_Traits,_Alloc >* __add__(const basic_string& v) { + std::basic_string< _CharT,_Traits,_Alloc >* res = new std::basic_string< _CharT,_Traits,_Alloc >(*self); *res += v; return res; } - std::basic_string<_CharT,_Traits,_Alloc >* __radd__(const basic_string& v) { - std::basic_string<_CharT,_Traits,_Alloc >* res = new std::basic_string<_CharT,_Traits,_Alloc >(v); + std::basic_string< _CharT,_Traits,_Alloc >* __radd__(const basic_string& v) { + std::basic_string< _CharT,_Traits,_Alloc >* res = new std::basic_string< _CharT,_Traits,_Alloc >(v); *res += *self; return res; } - std::basic_string<_CharT,_Traits,_Alloc > __str__() { + std::basic_string< _CharT,_Traits,_Alloc > __str__() { return *self; } diff --git a/Lib/std/std_common.i b/Lib/std/std_common.i index 6e93e29f600..b79eaff3a5d 100644 --- a/Lib/std/std_common.i +++ b/Lib/std/std_common.i @@ -72,7 +72,7 @@ namespace std { %} %fragment("StdTraitsCommon","header",fragment="") %{ -namespace swig { +namespace swig { template struct noconst_traits { typedef Type noconst_type; @@ -86,7 +86,7 @@ namespace swig { /* type categories */ - struct pointer_category { }; + struct pointer_category { }; struct value_category { }; /* @@ -99,12 +99,12 @@ namespace swig { return traits::noconst_type >::type_name(); } - template + template struct traits_info { static swig_type_info *type_query(std::string name) { name += " *"; return SWIG_TypeQuery(name.c_str()); - } + } static swig_type_info *type_info() { static swig_type_info *info = type_query(type_name()); return info; @@ -125,22 +125,22 @@ namespace swig { std::string ptrname = name; ptrname += " *"; return ptrname; - } + } static const char* type_name() { static std::string name = make_ptr_name(swig::type_name()); return name.c_str(); } }; - template + template struct traits_as { }; - - template + + template struct traits_check { }; } %} - + /* Generate the traits for a swigtype */ @@ -148,7 +148,7 @@ namespace swig { %define %traits_swigtype(Type...) %fragment(SWIG_Traits_frag(Type),"header",fragment="StdTraits") { namespace swig { - template <> struct traits { + template <> struct traits< Type > { typedef pointer_category category; static const char* type_name() { return #Type; } }; @@ -164,7 +164,7 @@ namespace swig { %define %typemap_traits(Code,Type...) %typemaps_asvalfrom(%arg(Code), - %arg(swig::asval), + %arg(swig::asval< Type >), %arg(swig::from), %arg(SWIG_Traits_frag(Type)), %arg(SWIG_Traits_frag(Type)), @@ -194,10 +194,10 @@ namespace swig { bool operator == (const Type& v) { return *self == v; } - + bool operator != (const Type& v) { return *self != v; - } + } } %enddef @@ -211,7 +211,7 @@ namespace swig { bool operator > (const Type& v) { return *self > v; } - + bool operator < (const Type& v) { return *self < v; } diff --git a/Lib/std/std_container.i b/Lib/std/std_container.i index 8ed327bbe13..5fa085afa0f 100644 --- a/Lib/std/std_container.i +++ b/Lib/std/std_container.i @@ -6,20 +6,17 @@ #include %} -// Common container methods +// Common non-resizable container methods + +%define %std_container_methods_non_resizable(container...) -%define %std_container_methods(container...) container(); container(const container&); bool empty() const; size_type size() const; - void clear(); - void swap(container& v); - allocator_type get_allocator() const; - #ifdef SWIG_EXPORT_ITERATOR_METHODS class iterator; class reverse_iterator; @@ -34,17 +31,27 @@ %enddef +// Common container methods + +%define %std_container_methods(container...) + %std_container_methods_non_resizable(%arg(container)) + + void clear(); + allocator_type get_allocator() const; + +%enddef + // Common sequence %define %std_sequence_methods_common(sequence) - + %std_container_methods(%arg(sequence)); - + sequence(size_type size); void pop_back(); - + void resize(size_type new_size); - + #ifdef SWIG_EXPORT_ITERATOR_METHODS %extend { // %extend wrapper used for differing definitions of these methods introduced in C++11 @@ -52,24 +59,31 @@ iterator erase(iterator first, iterator last) { return $self->erase(first, last); } } #endif - + %enddef +%define %std_sequence_methods_non_resizable(sequence) + + %std_container_methods_non_resizable(%arg(sequence)) + + const value_type& front() const; + const value_type& back() const; + +%enddef %define %std_sequence_methods(sequence) - + %std_sequence_methods_common(%arg(sequence)); - + sequence(size_type size, const value_type& value); - void push_back(const value_type& x); + void push_back(const value_type& x); const value_type& front() const; const value_type& back() const; - - void assign(size_type n, const value_type& x); + void assign(size_type n, const value_type& x); void resize(size_type new_size, const value_type& x); - + #ifdef SWIG_EXPORT_ITERATOR_METHODS %extend { // %extend wrapper used for differing definitions of these methods introduced in C++11 @@ -77,23 +91,33 @@ void insert(iterator pos, size_type n, const value_type& x) { $self->insert(pos, n, x); } } #endif - + +%enddef + +%define %std_sequence_methods_non_resizable_val(sequence...) + + %std_container_methods_non_resizable(%arg(sequence)) + + value_type front() const; + value_type back() const; + +#endif + %enddef %define %std_sequence_methods_val(sequence...) - + %std_sequence_methods_common(%arg(sequence)); - + sequence(size_type size, value_type value); - void push_back(value_type x); + void push_back(value_type x); value_type front() const; value_type back() const; - - void assign(size_type n, value_type x); + void assign(size_type n, value_type x); void resize(size_type new_size, value_type x); - + #ifdef SWIG_EXPORT_ITERATOR_METHODS %extend { // %extend wrapper used for differing definitions of these methods introduced in C++11 @@ -101,7 +125,7 @@ void insert(iterator pos, size_type n, value_type x) { $self->insert(pos, n, x); } } #endif - + %enddef @@ -109,10 +133,10 @@ // Ignore member methods for Type with no default constructor // %define %std_nodefconst_type(Type...) -%feature("ignore") std::vector::vector(size_type size); -%feature("ignore") std::vector::resize(size_type size); -%feature("ignore") std::deque::deque(size_type size); -%feature("ignore") std::deque::resize(size_type size); -%feature("ignore") std::list::list(size_type size); -%feature("ignore") std::list::resize(size_type size); +%feature("ignore") std::vector< Type >::vector(size_type size); +%feature("ignore") std::vector< Type >::resize(size_type size); +%feature("ignore") std::deque< Type >::deque(size_type size); +%feature("ignore") std::deque< Type >::resize(size_type size); +%feature("ignore") std::list< Type >::list(size_type size); +%feature("ignore") std::list< Type >::resize(size_type size); %enddef diff --git a/Lib/std/std_deque.i b/Lib/std/std_deque.i index a99763b79d3..29560caed6e 100644 --- a/Lib/std/std_deque.i +++ b/Lib/std/std_deque.i @@ -49,7 +49,7 @@ namespace std { - template > + template > class deque { public: typedef size_t size_type; @@ -63,11 +63,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::deque<_Tp, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::deque< _Tp, _Alloc >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdDequeTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::deque<" #_Tp " >"; @@ -76,18 +76,18 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_DEQUE, std::deque<_Tp, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_DEQUE, std::deque< _Tp, _Alloc >); #ifdef %swig_deque_methods // Add swig/language extra methods - %swig_deque_methods(std::deque<_Tp, _Alloc >); + %swig_deque_methods(std::deque< _Tp, _Alloc >); #endif %std_deque_methods(deque); }; template - class deque<_Tp*, _Alloc > { + class deque< _Tp*, _Alloc > { public: typedef size_t size_type; typedef ptrdiff_t difference_type; @@ -100,11 +100,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::deque<_Tp*, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::deque< _Tp*, _Alloc >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdDequeTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef value_category category; static const char* type_name() { return "std::deque<" #_Tp " * >"; @@ -113,14 +113,14 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_DEQUE, std::deque<_Tp*, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_DEQUE, std::deque< _Tp*, _Alloc >); #ifdef %swig_deque_methods_val // Add swig/language extra methods - %swig_deque_methods_val(std::deque<_Tp*, _Alloc >); + %swig_deque_methods_val(std::deque< _Tp*, _Alloc >); #endif - %std_deque_methods_val(std::deque<_Tp*, _Alloc >); + %std_deque_methods_val(std::deque< _Tp*, _Alloc >); }; } diff --git a/Lib/std/std_list.i b/Lib/std/std_list.i index e0893517092..1aaec0aa977 100644 --- a/Lib/std/std_list.i +++ b/Lib/std/std_list.i @@ -61,7 +61,7 @@ namespace std { - template > + template > class list { public: typedef size_t size_type; @@ -75,11 +75,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::list<_Tp, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::list< _Tp, _Alloc >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdListTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::list<" #_Tp ", " #_Alloc " >"; @@ -88,18 +88,18 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list<_Tp, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list< _Tp, _Alloc >); #ifdef %swig_list_methods // Add swig/language extra methods - %swig_list_methods(std::list<_Tp, _Alloc >); + %swig_list_methods(std::list< _Tp, _Alloc >); #endif %std_list_methods(list); }; template - class list<_Tp*, _Alloc> { + class list< _Tp*, _Alloc> { public: typedef size_t size_type; typedef ptrdiff_t difference_type; @@ -112,11 +112,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::list<_Tp*, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::list< _Tp*, _Alloc >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdListTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef value_category category; static const char* type_name() { return "std::list<" #_Tp " *," #_Alloc " >"; @@ -125,11 +125,11 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list<_Tp*, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list< _Tp*, _Alloc >); #ifdef %swig_list_methods_val // Add swig/language extra methods - %swig_list_methods_val(std::list<_Tp*, _Alloc >); + %swig_list_methods_val(std::list< _Tp*, _Alloc >); #endif %std_list_methods_val(list); @@ -138,9 +138,9 @@ namespace std { } %define %std_extequal_list(...) -%extend std::list<__VA_ARGS__ > { +%extend std::list< __VA_ARGS__ > { void remove(const value_type& x) { self->remove(x); } - void merge(std::list<__VA_ARGS__ >& x){ self->merge(x); } + void merge(std::list< __VA_ARGS__ >& x){ self->merge(x); } void unique() { self->unique(); } void sort() { self->sort(); } } diff --git a/Lib/std/std_map.i b/Lib/std/std_map.i index d1f6b3a161d..8043f924c70 100644 --- a/Lib/std/std_map.i +++ b/Lib/std/std_map.i @@ -66,14 +66,14 @@ namespace std { template, - class _Alloc = allocator > > + class _Alloc = allocator > > class map { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef _Key key_type; typedef _Tp mapped_type; - typedef std::pair value_type; + typedef std::pair< const _Key, _Tp > value_type; typedef value_type* pointer; typedef const value_type* const_pointer; @@ -98,11 +98,11 @@ namespace std { } } - %fragment(SWIG_Traits_frag(std::map<_Key, _Tp, _Compare, _Alloc >), "header", - fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >), + %fragment(SWIG_Traits_frag(std::map< _Key, _Tp, _Compare, _Alloc >), "header", + fragment=SWIG_Traits_frag(std::pair< _Key, _Tp >), fragment="StdMapTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::map<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >"; @@ -111,13 +111,13 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_MAP, std::map<_Key, _Tp, _Compare, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_MAP, std::map< _Key, _Tp, _Compare, _Alloc >); map( const _Compare& ); #ifdef %swig_map_methods // Add swig/language extra methods - %swig_map_methods(std::map<_Key, _Tp, _Compare, _Alloc >); + %swig_map_methods(std::map< _Key, _Tp, _Compare, _Alloc >); #endif %std_map_methods(map); diff --git a/Lib/std/std_multimap.i b/Lib/std/std_multimap.i index 39f674da501..7aa94990768 100644 --- a/Lib/std/std_multimap.i +++ b/Lib/std/std_multimap.i @@ -41,15 +41,15 @@ namespace std { - template, - class _Alloc = allocator > > + template, + class _Alloc = allocator > > class multimap { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef _Key key_type; typedef _Tp mapped_type; - typedef std::pair value_type; + typedef std::pair< const _Key, _Tp > value_type; typedef value_type* pointer; typedef const value_type* const_pointer; @@ -74,11 +74,11 @@ namespace std { } } - %fragment(SWIG_Traits_frag(std::multimap<_Key, _Tp, _Compare, _Alloc >), "header", - fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >), + %fragment(SWIG_Traits_frag(std::multimap< _Key, _Tp, _Compare, _Alloc >), "header", + fragment=SWIG_Traits_frag(std::pair< _Key, _Tp >), fragment="StdMultimapTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::multimap<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >"; @@ -87,13 +87,13 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_MULTIMAP, std::multimap<_Key, _Tp, _Compare, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_MULTIMAP, std::multimap< _Key, _Tp, _Compare, _Alloc >); multimap( const _Compare& ); #ifdef %swig_multimap_methods // Add swig/language extra methods - %swig_multimap_methods(std::multimap<_Key, _Tp, _Compare, _Alloc >); + %swig_multimap_methods(std::multimap< _Key, _Tp, _Compare, _Alloc >); #endif %std_multimap_methods(multimap); diff --git a/Lib/std/std_multiset.i b/Lib/std/std_multiset.i index b63fb92b9c9..1aa7ccce8a1 100644 --- a/Lib/std/std_multiset.i +++ b/Lib/std/std_multiset.i @@ -40,8 +40,8 @@ namespace std { //multiset - template , - class _Alloc = allocator<_Key> > + template , + class _Alloc = allocator< _Key > > class multiset { public: typedef size_t size_type; @@ -56,11 +56,11 @@ namespace std { %traits_swigtype(_Key); - %fragment(SWIG_Traits_frag(std::multiset<_Key, _Compare, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::multiset< _Key, _Compare, _Alloc >), "header", fragment=SWIG_Traits_frag(_Key), fragment="StdMultisetTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::multiset<" #_Key "," #_Compare "," #_Alloc " >"; @@ -69,13 +69,13 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_MULTISET, std::multiset<_Key, _Compare, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_MULTISET, std::multiset< _Key, _Compare, _Alloc >); multiset( const _Compare& ); #ifdef %swig_multiset_methods // Add swig/language extra methods - %swig_multiset_methods(std::multiset<_Key, _Compare, _Alloc >); + %swig_multiset_methods(std::multiset< _Key, _Compare, _Alloc >); #endif %std_multiset_methods(multiset); diff --git a/Lib/std/std_pair.i b/Lib/std/std_pair.i index 2743430e9f1..001cd6738f1 100644 --- a/Lib/std/std_pair.i +++ b/Lib/std/std_pair.i @@ -13,12 +13,12 @@ namespace std { %traits_swigtype(T); %traits_swigtype(U); - %fragment(SWIG_Traits_frag(std::pair), "header", + %fragment(SWIG_Traits_frag(std::pair< T, U >), "header", fragment=SWIG_Traits_frag(T), fragment=SWIG_Traits_frag(U), fragment="StdPairTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::pair<" #T "," #U " >"; @@ -28,23 +28,23 @@ namespace std { } #ifndef SWIG_STD_PAIR_ASVAL - %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair); + %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair< T, U >); #else - %typemap_traits(SWIG_TYPECHECK_PAIR, std::pair); + %typemap_traits(SWIG_TYPECHECK_PAIR, std::pair< T, U >); #endif pair(); pair(T first, U second); pair(const pair& p); - template pair(const pair &p); + template pair(const pair< U1, U2 > &p); T first; U second; #ifdef %swig_pair_methods // Add swig/language extra methods - %swig_pair_methods(std::pair) + %swig_pair_methods(std::pair< T, U >) #endif }; @@ -52,19 +52,19 @@ namespace std { // The following specializations should disappear or get // simplified when a 'const SWIGTYPE*&' can be defined // *** - template struct pair { + template struct pair< T, U* > { typedef T first_type; typedef U* second_type; %traits_swigtype(T); %traits_swigtype(U); - %fragment(SWIG_Traits_frag(std::pair), "header", + %fragment(SWIG_Traits_frag(std::pair< T, U* >), "header", fragment=SWIG_Traits_frag(T), fragment=SWIG_Traits_frag(U), fragment="StdPairTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::pair<" #T "," #U " * >"; @@ -73,7 +73,7 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair); + %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair< T, U* >); pair(); pair(T __a, U* __b); @@ -84,23 +84,23 @@ namespace std { #ifdef %swig_pair_methods // Add swig/language extra methods - %swig_pair_methods(std::pair) + %swig_pair_methods(std::pair< T, U* >) #endif }; - template struct pair { + template struct pair< T*, U > { typedef T* first_type; typedef U second_type; %traits_swigtype(T); %traits_swigtype(U); - %fragment(SWIG_Traits_frag(std::pair), "header", + %fragment(SWIG_Traits_frag(std::pair< T*, U >), "header", fragment=SWIG_Traits_frag(T), fragment=SWIG_Traits_frag(U), fragment="StdPairTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::pair<" #T " *," #U " >"; @@ -109,7 +109,7 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair); + %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair< T*, U >); pair(); pair(T* __a, U __b); @@ -120,23 +120,23 @@ namespace std { #ifdef %swig_pair_methods // Add swig/language extra methods - %swig_pair_methods(std::pair) + %swig_pair_methods(std::pair< T*, U >) #endif }; - template struct pair { + template struct pair< T*, U* > { typedef T* first_type; typedef U* second_type; %traits_swigtype(T); %traits_swigtype(U); - %fragment(SWIG_Traits_frag(std::pair), "header", + %fragment(SWIG_Traits_frag(std::pair< T*, U* >), "header", fragment=SWIG_Traits_frag(T), fragment=SWIG_Traits_frag(U), fragment="StdPairTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::pair<" #T " *," #U " * >"; @@ -145,7 +145,7 @@ namespace std { } } - %typemap_traits(SWIG_TYPECHECK_PAIR, std::pair); + %typemap_traits(SWIG_TYPECHECK_PAIR, std::pair< T*, U* >); pair(); pair(T* __a, U* __b); @@ -156,7 +156,7 @@ namespace std { #ifdef %swig_pair_methods // Add swig/language extra methods - %swig_pair_methods(std::pair) + %swig_pair_methods(std::pair< T*, U* >) #endif }; diff --git a/Lib/std/std_queue.i b/Lib/std/std_queue.i index 42273eee6c1..7452a4b602f 100644 --- a/Lib/std/std_queue.i +++ b/Lib/std/std_queue.i @@ -57,7 +57,7 @@ namespace std { - template > + template > class queue { public: typedef size_t size_type; @@ -68,11 +68,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::queue<_Tp, _Sequence >), "header", + %fragment(SWIG_Traits_frag(std::queue< _Tp, _Sequence >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdQueueTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::queue<" #_Tp "," #_Sequence " >"; @@ -81,18 +81,18 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_QUEUE, std::queue<_Tp, _Sequence >); + %typemap_traits_ptr(SWIG_TYPECHECK_QUEUE, std::queue< _Tp, _Sequence >); #ifdef %swig_queue_methods // Add swig/language extra methods - %swig_queue_methods(std::queue<_Tp, _Sequence >); + %swig_queue_methods(std::queue< _Tp, _Sequence >); #endif %std_queue_methods(queue); }; template - class queue<_Tp*, _Sequence > { + class queue< _Tp*, _Sequence > { public: typedef size_t size_type; typedef _Tp value_type; @@ -102,11 +102,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::queue<_Tp*, _Sequence >), "header", + %fragment(SWIG_Traits_frag(std::queue< _Tp*, _Sequence >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdQueueTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef value_category category; static const char* type_name() { return "std::queue<" #_Tp "," #_Sequence " * >"; @@ -115,14 +115,14 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_QUEUE, std::queue<_Tp*, _Sequence >); + %typemap_traits_ptr(SWIG_TYPECHECK_QUEUE, std::queue< _Tp*, _Sequence >); #ifdef %swig_queue_methods_val // Add swig/language extra methods - %swig_queue_methods_val(std::queue<_Tp*, _Sequence >); + %swig_queue_methods_val(std::queue< _Tp*, _Sequence >); #endif - %std_queue_methods_val(std::queue<_Tp*, _Sequence >); + %std_queue_methods_val(std::queue< _Tp*, _Sequence >); }; } diff --git a/Lib/std/std_set.i b/Lib/std/std_set.i index f96ddd9f1e9..107a23c71e8 100644 --- a/Lib/std/std_set.i +++ b/Lib/std/std_set.i @@ -79,8 +79,8 @@ namespace std { - template , - class _Alloc = allocator<_Key> > + template , + class _Alloc = allocator< _Key > > class set { public: typedef size_t size_type; @@ -95,11 +95,11 @@ namespace std { %traits_swigtype(_Key); - %fragment(SWIG_Traits_frag(std::set<_Key, _Compare, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::set< _Key, _Compare, _Alloc >), "header", fragment=SWIG_Traits_frag(_Key), fragment="StdSetTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::set<" #_Key "," #_Compare "," #_Alloc " >"; @@ -108,13 +108,13 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_SET, std::set<_Key, _Compare, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_SET, std::set< _Key, _Compare, _Alloc >); set( const _Compare& ); #ifdef %swig_set_methods // Add swig/language extra methods - %swig_set_methods(std::set<_Key, _Compare, _Alloc >); + %swig_set_methods(std::set< _Key, _Compare, _Alloc >); #endif %std_set_methods(set); diff --git a/Lib/std/std_stack.i b/Lib/std/std_stack.i index fb900a57c96..48dae0585d8 100644 --- a/Lib/std/std_stack.i +++ b/Lib/std/std_stack.i @@ -56,7 +56,7 @@ namespace std { - template > + template > class stack { public: typedef size_t size_type; @@ -67,11 +67,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::stack<_Tp, _Sequence >), "header", + %fragment(SWIG_Traits_frag(std::stack< _Tp, _Sequence >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdStackTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::stack<" #_Tp "," #_Sequence " >"; @@ -80,18 +80,18 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_STACK, std::stack<_Tp, _Sequence >); + %typemap_traits_ptr(SWIG_TYPECHECK_STACK, std::stack< _Tp, _Sequence >); #ifdef %swig_stack_methods // Add swig/language extra methods - %swig_stack_methods(std::stack<_Tp, _Sequence >); + %swig_stack_methods(std::stack< _Tp, _Sequence >); #endif %std_stack_methods(stack); }; template - class stack<_Tp*, _Sequence > { + class stack< _Tp*, _Sequence > { public: typedef size_t size_type; typedef _Sequence::value_type value_type; @@ -101,11 +101,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::stack<_Tp*, _Sequence >), "header", + %fragment(SWIG_Traits_frag(std::stack< _Tp*, _Sequence >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdStackTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef value_category category; static const char* type_name() { return "std::stack<" #_Tp "," #_Sequence " * >"; @@ -114,14 +114,14 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_STACK, std::stack<_Tp*, _Sequence >); + %typemap_traits_ptr(SWIG_TYPECHECK_STACK, std::stack< _Tp*, _Sequence >); #ifdef %swig_stack_methods_val // Add swig/language extra methods - %swig_stack_methods_val(std::stack<_Tp*, _Sequence >); + %swig_stack_methods_val(std::stack< _Tp*, _Sequence >); #endif - %std_stack_methods_val(std::stack<_Tp*, _Sequence >); + %std_stack_methods_val(std::stack< _Tp*, _Sequence >); }; } diff --git a/Lib/std/std_unordered_map.i b/Lib/std/std_unordered_map.i index 8c276172a72..1cb7148211f 100644 --- a/Lib/std/std_unordered_map.i +++ b/Lib/std/std_unordered_map.i @@ -68,15 +68,15 @@ namespace std { - template, - class _Alloc = allocator > > + template, + class _Alloc = allocator > > class unordered_map { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef _Key key_type; typedef _Tp mapped_type; - typedef std::pair value_type; + typedef std::pair< const _Key, _Tp > value_type; typedef value_type* pointer; typedef const value_type* const_pointer; @@ -101,11 +101,11 @@ namespace std { } } - %fragment(SWIG_Traits_frag(std::unordered_map<_Key, _Tp, _Compare, _Alloc >), "header", - fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >), + %fragment(SWIG_Traits_frag(std::unordered_map< _Key, _Tp, _Compare, _Alloc >), "header", + fragment=SWIG_Traits_frag(std::pair< _Key, _Tp >), fragment="StdMapTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::unordered_map<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >"; @@ -114,13 +114,13 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_MAP, std::unordered_map<_Key, _Tp, _Compare, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_MAP, std::unordered_map< _Key, _Tp, _Compare, _Alloc >); unordered_map( const _Compare& ); #ifdef %swig_unordered_map_methods // Add swig/language extra methods - %swig_unordered_map_methods(std::unordered_map<_Key, _Tp, _Compare, _Alloc >); + %swig_unordered_map_methods(std::unordered_map< _Key, _Tp, _Compare, _Alloc >); #endif %std_unordered_map_methods(unordered_map); diff --git a/Lib/std/std_unordered_multimap.i b/Lib/std/std_unordered_multimap.i index 74efb2896c9..46b56d88ab7 100644 --- a/Lib/std/std_unordered_multimap.i +++ b/Lib/std/std_unordered_multimap.i @@ -44,15 +44,15 @@ namespace std { - template, - class _Alloc = allocator > > + template, + class _Alloc = allocator > > class unordered_multimap { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef _Key key_type; typedef _Tp mapped_type; - typedef std::pair value_type; + typedef std::pair< const _Key, _Tp > value_type; typedef value_type* pointer; typedef const value_type* const_pointer; @@ -63,11 +63,11 @@ namespace std { %traits_swigtype(_Key); %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >), "header", - fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >), + %fragment(SWIG_Traits_frag(std::unordered_multimap< _Key, _Tp, _Compare, _Alloc >), "header", + fragment=SWIG_Traits_frag(std::pair< _Key, _Tp >), fragment="StdMultimapTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::unordered_multimap<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >"; @@ -76,13 +76,13 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_MULTIMAP, std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_MULTIMAP, std::unordered_multimap< _Key, _Tp, _Compare, _Alloc >); unordered_multimap( const _Compare& ); #ifdef %swig_unordered_multimap_methods // Add swig/language extra methods - %swig_unordered_multimap_methods(std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >); + %swig_unordered_multimap_methods(std::unordered_multimap< _Key, _Tp, _Compare, _Alloc >); #endif %std_unordered_multimap_methods(unordered_multimap); diff --git a/Lib/std/std_unordered_multiset.i b/Lib/std/std_unordered_multiset.i index 56b97101168..725ca2fe700 100644 --- a/Lib/std/std_unordered_multiset.i +++ b/Lib/std/std_unordered_multiset.i @@ -43,8 +43,8 @@ namespace std { //unordered_multiset - template , - class _Alloc = allocator<_Key> > + template , + class _Alloc = allocator< _Key > > class unordered_multiset { public: typedef size_t size_type; @@ -59,11 +59,11 @@ namespace std { %traits_swigtype(_Key); - %fragment(SWIG_Traits_frag(std::unordered_multiset<_Key, _Compare, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::unordered_multiset< _Key, _Compare, _Alloc >), "header", fragment=SWIG_Traits_frag(_Key), fragment="StdMultisetTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::unordered_multiset<" #_Key "," #_Compare "," #_Alloc " >"; @@ -72,13 +72,13 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_MULTISET, std::unordered_multiset<_Key, _Compare, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_MULTISET, std::unordered_multiset< _Key, _Compare, _Alloc >); unordered_multiset( const _Compare& ); #ifdef %swig_unordered_multiset_methods // Add swig/language extra methods - %swig_unordered_multiset_methods(std::unordered_multiset<_Key, _Compare, _Alloc >); + %swig_unordered_multiset_methods(std::unordered_multiset< _Key, _Compare, _Alloc >); #endif %std_unordered_multiset_methods(unordered_multiset); diff --git a/Lib/std/std_unordered_set.i b/Lib/std/std_unordered_set.i index ed8888eb4b1..98e7920401b 100644 --- a/Lib/std/std_unordered_set.i +++ b/Lib/std/std_unordered_set.i @@ -77,9 +77,9 @@ namespace std { - template , - class _Compare = std::equal_to<_Key>, - class _Alloc = allocator<_Key> > + template , + class _Compare = std::equal_to< _Key >, + class _Alloc = allocator< _Key > > class unordered_set { public: typedef size_t size_type; @@ -95,11 +95,11 @@ namespace std { %traits_swigtype(_Key); - %fragment(SWIG_Traits_frag(std::unordered_set<_Key, _Hash, _Compare, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::unordered_set< _Key, _Hash, _Compare, _Alloc >), "header", fragment=SWIG_Traits_frag(_Key), fragment="StdUnorderedSetTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::unordered_set<" #_Key "," #_Hash "," #_Compare "," #_Alloc " >"; @@ -108,13 +108,13 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_SET, std::unordered_set<_Key, _Hash, _Compare, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_SET, std::unordered_set< _Key, _Hash, _Compare, _Alloc >); unordered_set( const _Compare& ); #ifdef %swig_unordered_set_methods // Add swig/language extra methods - %swig_unordered_set_methods(std::unordered_set<_Key, _Hash, _Compare, _Alloc >); + %swig_unordered_set_methods(std::unordered_set< _Key, _Hash, _Compare, _Alloc >); #endif %std_unordered_set_methods(unordered_set); diff --git a/Lib/std/std_vector.i b/Lib/std/std_vector.i index baecf85076b..fae759a36b9 100644 --- a/Lib/std/std_vector.i +++ b/Lib/std/std_vector.i @@ -71,11 +71,11 @@ namespace std { %traits_swigtype(_Tp); %traits_enum(_Tp); - %fragment(SWIG_Traits_frag(std::vector<_Tp, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::vector< _Tp, _Alloc >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdVectorTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef pointer_category category; static const char* type_name() { return "std::vector<" #_Tp "," #_Alloc " >"; @@ -84,11 +84,11 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp, _Alloc >); #ifdef %swig_vector_methods // Add swig/language extra methods - %swig_vector_methods(std::vector<_Tp, _Alloc >); + %swig_vector_methods(std::vector< _Tp, _Alloc >); #endif %std_vector_methods(vector); @@ -99,7 +99,7 @@ namespace std { // a 'const SWIGTYPE*&' can be defined // *** template - class vector<_Tp*, _Alloc > { + class vector< _Tp*, _Alloc > { public: typedef size_t size_type; typedef ptrdiff_t difference_type; @@ -112,11 +112,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::vector<_Tp*, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::vector< _Tp*, _Alloc >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdVectorTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef value_category category; static const char* type_name() { return "std::vector<" #_Tp " *," #_Alloc " >"; @@ -125,11 +125,11 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp*, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp*, _Alloc >); #ifdef %swig_vector_methods_val // Add swig/language extra methods - %swig_vector_methods_val(std::vector<_Tp*, _Alloc >); + %swig_vector_methods_val(std::vector< _Tp*, _Alloc >); #endif %std_vector_methods_val(vector); @@ -139,7 +139,7 @@ namespace std { // const pointer specialization // *** template - class vector<_Tp const *, _Alloc > { + class vector< _Tp const *, _Alloc > { public: typedef size_t size_type; typedef ptrdiff_t difference_type; @@ -152,11 +152,11 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::vector<_Tp const*, _Alloc >), "header", + %fragment(SWIG_Traits_frag(std::vector< _Tp const*, _Alloc >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdVectorTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef value_category category; static const char* type_name() { return "std::vector<" #_Tp " const*," #_Alloc " >"; @@ -165,11 +165,11 @@ namespace std { } } - %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp const*, _Alloc >); + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp const*, _Alloc >); #ifdef %swig_vector_methods_val // Add swig/language extra methods - %swig_vector_methods_val(std::vector<_Tp const*, _Alloc >); + %swig_vector_methods_val(std::vector< _Tp const*, _Alloc >); #endif %std_vector_methods_val(vector); diff --git a/Lib/swig.swg b/Lib/swig.swg index c33ae385438..6f48f0d205c 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -359,6 +359,7 @@ static int NAME(TYPE x) { %define SWIG_TYPECHECK_STDSTRING 135 %enddef %define SWIG_TYPECHECK_STRING 140 %enddef %define SWIG_TYPECHECK_PAIR 150 %enddef +%define SWIG_TYPECHECK_STDARRAY 155 %enddef %define SWIG_TYPECHECK_VECTOR 160 %enddef %define SWIG_TYPECHECK_DEQUE 170 %enddef %define SWIG_TYPECHECK_LIST 180 %enddef diff --git a/Lib/swigarch.i b/Lib/swigarch.i index f5aea4678e3..bf4ee8ef862 100644 --- a/Lib/swigarch.i +++ b/Lib/swigarch.i @@ -42,7 +42,7 @@ #include #endif #if (__WORDSIZE == 64) || (LONG_MAX != INT_MAX) -# error "SWIG wrapped code invalid in 64 bit architecture, regenarete code using -DSWIGWORDSIZE64" +# error "SWIG wrapped code invalid in 64 bit architecture, regenerate code using -DSWIGWORDSIZE64" #endif %} #endif @@ -54,7 +54,7 @@ #include #endif #if (__WORDSIZE == 32) || (LONG_MAX == INT_MAX) -# error "SWIG wrapped code invalid in 32 bit architecture, regenarete code using -DSWIGWORDSIZE32" +# error "SWIG wrapped code invalid in 32 bit architecture, regenerate code using -DSWIGWORDSIZE32" #endif %} #endif diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg index 69e368ac1d2..cb72c36eb1a 100644 --- a/Lib/swiginit.swg +++ b/Lib/swiginit.swg @@ -55,7 +55,7 @@ SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; - int found, init; + int init; /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { @@ -74,22 +74,18 @@ SWIG_InitializeModule(void *clientdata) { /* This is the first module loaded for this interpreter */ /* so set the swig module into the interpreter */ SWIG_SetModule(clientdata, &swig_module); - module_head = &swig_module; } else { /* the interpreter has loaded a SWIG module, but has it loaded this one? */ - found=0; iter=module_head; do { if (iter==&swig_module) { - found=1; - break; + /* Our module is already in the list, so there's nothing more to do. */ + return; } iter=iter->next; } while (iter!= module_head); - /* if the is found in the list, then all is done and we may leave */ - if (found) return; - /* otherwise we must add out module into the list */ + /* otherwise we must add our module into the list */ swig_module.next = module_head->next; module_head->next = &swig_module; } diff --git a/Lib/swiglabels.swg b/Lib/swiglabels.swg index d428ac33d5a..b3855665e2c 100644 --- a/Lib/swiglabels.swg +++ b/Lib/swiglabels.swg @@ -65,9 +65,11 @@ #endif /* exporting methods */ -#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -# ifndef GCC_HASCLASSVISIBILITY -# define GCC_HASCLASSVISIBILITY +#if defined(__GNUC__) +# if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif # endif #endif @@ -106,3 +108,16 @@ # define _SCL_SECURE_NO_DEPRECATE #endif +/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ +#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) +# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 +#endif + +/* Intel's compiler complains if a variable which was never initialised is + * cast to void, which is a common idiom which we use to indicate that we + * are aware a variable isn't used. So we just silence that warning. + * See: https://github.com/swig/swig/issues/192 for more discussion. + */ +#ifdef __INTEL_COMPILER +# pragma warning disable 592 +#endif diff --git a/Lib/tcl/tclprimtypes.swg b/Lib/tcl/tclprimtypes.swg index e781798e028..3b6d04f5952 100644 --- a/Lib/tcl/tclprimtypes.swg +++ b/Lib/tcl/tclprimtypes.swg @@ -112,8 +112,9 @@ SWIG_AsVal_dec(unsigned long)(Tcl_Obj *obj, unsigned long *val) { %fragment(SWIG_From_frag(long long),"header", fragment=SWIG_From_frag(long), - fragment="", + fragment="SWIG_LongLongAvailable", fragment="") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE Tcl_Obj* SWIG_From_dec(long long)(long long value) { @@ -125,11 +126,13 @@ SWIG_From_dec(long long)(long long value) return Tcl_NewStringObj(temp,-1); } } +%#endif } %fragment(SWIG_AsVal_frag(long long),"header", - fragment="", + fragment="SWIG_LongLongAvailable", fragment="") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val) { @@ -160,14 +163,16 @@ SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val) } return SWIG_TypeError; } +%#endif } /* unsigned long long */ %fragment(SWIG_From_frag(unsigned long long),"header", fragment=SWIG_From_frag(long long), - fragment="", + fragment="SWIG_LongLongAvailable", fragment="") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERNINLINE Tcl_Obj* SWIG_From_dec(unsigned long long)(unsigned long long value) { @@ -179,12 +184,14 @@ SWIG_From_dec(unsigned long long)(unsigned long long value) return Tcl_NewStringObj(temp,-1); } } +%#endif } %fragment(SWIG_AsVal_frag(unsigned long long),"header", fragment=SWIG_AsVal_frag(unsigned long), - fragment="", + fragment="SWIG_LongLongAvailable", fragment="") { +%#ifdef SWIG_LONG_LONG_AVAILABLE SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(Tcl_Obj *obj, unsigned long long *val) { @@ -216,6 +223,7 @@ SWIG_AsVal_dec(unsigned long long)(Tcl_Obj *obj, unsigned long long *val) } return SWIG_TypeError; } +%#endif } /* double */ diff --git a/Lib/tcl/tclrun.swg b/Lib/tcl/tclrun.swg index c91a7e511ca..fd1052a2869 100644 --- a/Lib/tcl/tclrun.swg +++ b/Lib/tcl/tclrun.swg @@ -67,6 +67,12 @@ #define SWIG_GetConstant SWIG_GetConstantObj #define SWIG_Tcl_GetConstant SWIG_Tcl_GetConstantObj +#if TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 5 +#define SWIG_TCL_HASHTABLE_INIT {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#else +#define SWIG_TCL_HASHTABLE_INIT {0} +#endif + #include "assert.h" #ifdef __cplusplus diff --git a/Lib/typemaps/fragments.swg b/Lib/typemaps/fragments.swg index 447df6e2e26..048fd34d384 100644 --- a/Lib/typemaps/fragments.swg +++ b/Lib/typemaps/fragments.swg @@ -168,8 +168,11 @@ %fragment("SWIG_isfinite","header",fragment=",") %{ /* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */ #ifndef SWIG_isfinite +/* isfinite() is a macro for C99, but a function in namespace std for C++11. */ # if defined(isfinite) # define SWIG_isfinite(X) (isfinite(X)) +# elif defined __cplusplus && __cplusplus >= 201103L +# define SWIG_isfinite(X) (std::isfinite(X)) # elif defined(_MSC_VER) # define SWIG_isfinite(X) (_finite(X)) # elif defined(__sun) && defined(__SVR4) diff --git a/Lib/typemaps/primtypes.swg b/Lib/typemaps/primtypes.swg index 45632c31fc5..dd80eb775e3 100644 --- a/Lib/typemaps/primtypes.swg +++ b/Lib/typemaps/primtypes.swg @@ -148,6 +148,12 @@ SWIG_AsVal_dec(bool)(SWIG_Object obj, bool *val) /* long long/unsigned long long */ +%fragment("SWIG_LongLongAvailable","header", fragment="") %{ +#if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE) +# define SWIG_LONG_LONG_AVAILABLE +#endif +%} + %ensure_type_fragments(long long) %ensure_type_fragments(unsigned long long) @@ -157,42 +163,82 @@ SWIG_AsVal_dec(bool)(SWIG_Object obj, bool *val) /* size_t */ -%fragment(SWIG_From_frag(size_t),"header",fragment=SWIG_From_frag(unsigned long)) { +%fragment(SWIG_From_frag(size_t),"header",fragment=SWIG_From_frag(unsigned long),fragment=SWIG_From_frag(unsigned long long)) { SWIGINTERNINLINE SWIG_Object SWIG_From_dec(size_t)(size_t value) { - return SWIG_From(unsigned long)(%numeric_cast(value, unsigned long)); +%#ifdef SWIG_LONG_LONG_AVAILABLE + if (sizeof(size_t) <= sizeof(unsigned long)) { +%#endif + return SWIG_From(unsigned long)(%numeric_cast(value, unsigned long)); +%#ifdef SWIG_LONG_LONG_AVAILABLE + } else { + /* assume sizeof(size_t) <= sizeof(unsigned long long) */ + return SWIG_From(unsigned long long)(%numeric_cast(value, unsigned long long)); + } +%#endif } } -%fragment(SWIG_AsVal_frag(size_t),"header",fragment=SWIG_AsVal_frag(unsigned long)) { +%fragment(SWIG_AsVal_frag(size_t),"header",fragment=SWIG_AsVal_frag(unsigned long),fragment=SWIG_AsVal_frag(unsigned long long)) { SWIGINTERNINLINE int SWIG_AsVal_dec(size_t)(SWIG_Object obj, size_t *val) { - unsigned long v; - int res = SWIG_AsVal(unsigned long)(obj, val ? &v : 0); - if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, size_t); + int res = SWIG_TypeError; +%#ifdef SWIG_LONG_LONG_AVAILABLE + if (sizeof(size_t) <= sizeof(unsigned long)) { +%#endif + unsigned long v; + res = SWIG_AsVal(unsigned long)(obj, val ? &v : 0); + if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, size_t); +%#ifdef SWIG_LONG_LONG_AVAILABLE + } else if (sizeof(size_t) <= sizeof(unsigned long long)) { + unsigned long long v; + res = SWIG_AsVal(unsigned long long)(obj, val ? &v : 0); + if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, size_t); + } +%#endif return res; } } /* ptrdiff_t */ -%fragment(SWIG_From_frag(ptrdiff_t),"header",fragment=SWIG_From_frag(long)) { +%fragment(SWIG_From_frag(ptrdiff_t),"header",fragment=SWIG_From_frag(long),fragment=SWIG_From_frag(long long)) { SWIGINTERNINLINE SWIG_Object SWIG_From_dec(ptrdiff_t)(ptrdiff_t value) { - return SWIG_From(long)(%numeric_cast(value,long)); +%#ifdef SWIG_LONG_LONG_AVAILABLE + if (sizeof(ptrdiff_t) <= sizeof(long)) { +%#endif + return SWIG_From(long)(%numeric_cast(value, long)); +%#ifdef SWIG_LONG_LONG_AVAILABLE + } else { + /* assume sizeof(ptrdiff_t) <= sizeof(long long) */ + return SWIG_From(long long)(%numeric_cast(value, long long)); + } +%#endif } } -%fragment(SWIG_AsVal_frag(ptrdiff_t),"header",fragment=SWIG_AsVal_frag(long)) { +%fragment(SWIG_AsVal_frag(ptrdiff_t),"header",fragment=SWIG_AsVal_frag(long),fragment=SWIG_AsVal_frag(long long)) { SWIGINTERNINLINE int SWIG_AsVal_dec(ptrdiff_t)(SWIG_Object obj, ptrdiff_t *val) { - long v; - int res = SWIG_AsVal(long)(obj, val ? &v : 0); - if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, ptrdiff_t); + int res = SWIG_TypeError; +%#ifdef SWIG_LONG_LONG_AVAILABLE + if (sizeof(ptrdiff_t) <= sizeof(long)) { +%#endif + long v; + res = SWIG_AsVal(long)(obj, val ? &v : 0); + if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, ptrdiff_t); +%#ifdef SWIG_LONG_LONG_AVAILABLE + } else if (sizeof(ptrdiff_t) <= sizeof(long long)) { + long long v; + res = SWIG_AsVal(long long)(obj, val ? &v : 0); + if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, ptrdiff_t); + } +%#endif return res; } } diff --git a/Lib/typemaps/strings.swg b/Lib/typemaps/strings.swg index 6bac0b98a72..87e97dd740e 100644 --- a/Lib/typemaps/strings.swg +++ b/Lib/typemaps/strings.swg @@ -300,7 +300,7 @@ /* varout */ -%typemap(varout,noblock=1,fragment=#SWIG_CharBufLen) +%typemap(varout,fragment=#SWIG_CharBufLen) Char [ANY], const Char [ANY] { %#ifndef SWIG_PRESERVE_CARRAY_SIZE size_t size = SWIG_CharBufLen($1, $1_dim0); diff --git a/Makefile.in b/Makefile.in index f326385b04a..4e3c63fba73 100644 --- a/Makefile.in +++ b/Makefile.in @@ -21,7 +21,7 @@ FLAGS = -k -s ##################################################################### SHELL = /bin/sh -SWIG_LIB = @swig_lib@ +SWIG_LIB_INSTALL = @SWIG_LIB_INSTALL@ BIN_DIR = @bindir@ ENABLE_CCACHE = @ENABLE_CCACHE@ TARGET_NOEXE= swig @@ -49,15 +49,12 @@ maintainer: libfiles # Documentation ##################################################################### -docs: docs-main docs-ccache +docs: docs-main docs-main: @echo making docs @test -d $(DOCS) || exit 0; cd $(DOCS) && $(MAKE) all clean-baks -docs-ccache: - test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) docs) - ##################################################################### # All the languages SWIG speaks (when it wants to) ##################################################################### @@ -83,6 +80,7 @@ skip-clisp = test -n "@SKIP_CLISP@" skip-cffi = test -n "@SKIP_CFFI@" skip-uffi = test -n "@SKIP_UFFI@" skip-r = test -n "@SKIP_R@" +skip-scilab = test -n "@SKIP_SCILAB@" skip-go = test -n "@SKIP_GO@" skip-d = test -n "@SKIP_D@" skip-javascript = test -n "@SKIP_JAVASCRIPT@" @@ -94,6 +92,12 @@ skip-android = test -n "@SKIP_ANDROID@" # Special errors test-case skip-errors = test -n "" +check-%-enabled: + @if $(skip-$*); then \ + echo skipping $* version; \ + exit 1; \ + fi + ##################################################################### # CHECK ##################################################################### @@ -101,10 +105,6 @@ skip-errors = test -n "" ACTION = check NOSKIP = -chk-set-swiglib = SWIG_LIB=@ROOT_DIR@/$(srcdir)/Lib -chk-set-swig = SWIG=@ROOT_DIR@/$(TARGET) -chk-set-env = $(chk-set-swiglib) $(chk-set-swig) - check-aliveness: test -x ./$(TARGET) ./$(TARGET) -version @@ -130,6 +130,7 @@ check-aliveness: @$(skip-cffi) || ./$(TARGET) -cffi -help @$(skip-lua) || ./$(TARGET) -lua -help @$(skip-r) || ./$(TARGET) -r -help + @$(skip-scilab) || ./$(TARGET) -scilab -help @$(skip-go) || ./$(TARGET) -go -help @$(skip-d) || ./$(TARGET) -d -help @$(skip-javascript) || ./$(TARGET) -javascript -help @@ -162,6 +163,7 @@ check-versions: \ check-uffi-version \ check-cffi-version \ check-r-version \ + check-scilab-version \ check-go-version \ check-d-version @@ -202,6 +204,7 @@ check-examples: \ check-uffi-examples \ check-cffi-examples \ check-r-examples \ + check-scilab-examples \ check-go-examples \ check-d-examples \ check-javascript-examples @@ -228,6 +231,7 @@ clisp_examples := uffi_examples := cffi_examples := r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list) +scilab_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/scilab/check.list) go_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/go/check.list) d_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/d/check.list) javascript_examples:=$(shell sed '/^\#/d' $(srcdir)/Examples/javascript/check.list) @@ -250,7 +254,7 @@ check-%-examples : %.actionexample: @cd Examples && $(MAKE) Makefile @echo $(ACTION)ing Examples/$(LANGUAGE)/$* - @(cd Examples/$(LANGUAGE)/$* && $(MAKE) $(FLAGS) $(chk-set-env) $(ACTION) RUNPIPE=$(RUNPIPE)) + @(cd Examples/$(LANGUAGE)/$* && $(MAKE) $(FLAGS) $(ACTION) RUNPIPE=$(RUNPIPE)) # gcj individual example java.actionexample: @@ -259,7 +263,7 @@ java.actionexample: echo "skipping Examples/$(LANGUAGE)/java $(ACTION) (gcj test)"; \ else \ echo $(ACTION)ing Examples/$(LANGUAGE)/java; \ - (cd Examples/$(LANGUAGE)/java && $(MAKE) $(FLAGS) $(chk-set-env) $(ACTION) RUNPIPE=$(RUNPIPE)) \ + (cd Examples/$(LANGUAGE)/java && $(MAKE) $(FLAGS) $(ACTION) RUNPIPE=$(RUNPIPE)) \ fi # Checks testcases in the test-suite excluding those which are known to be broken @@ -286,6 +290,7 @@ check-test-suite: \ check-cffi-test-suite \ check-chicken-test-suite \ check-r-test-suite \ + check-scilab-test-suite \ check-go-test-suite \ check-d-test-suite \ check-javascript-test-suite @@ -340,6 +345,7 @@ all-test-suite: \ all-cffi-test-suite \ all-chicken-test-suite \ all-r-test-suite \ + all-scilab-test-suite \ all-go-test-suite \ all-d-test-suite \ all-javascript-test-suite @@ -370,6 +376,7 @@ broken-test-suite: \ broken-cffi-test-suite \ broken-chicken-test-suite \ broken-r-test-suite \ + broken-scilab-test-suite \ broken-go-test-suite \ broken-d-test-suite \ broken-javascript-test-suite @@ -409,7 +416,7 @@ clean-ccache: # DISTCLEAN - clean what configure built ##################################################################### -DISTCLEAN-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log libtool preinst-swig +DISTCLEAN-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log preinst-swig distclean-helper: distclean-test-suite distclean-examples distclean-tools distclean-dead @@ -505,23 +512,23 @@ install-main: lib-languages = gcj typemaps tcl perl5 python guile java mzscheme ruby php ocaml octave matlab \ pike chicken csharp modula3 allegrocl clisp lua cffi uffi r go d javascript javascript/jsc \ - javascript/v8 + javascript/v8 scilab lib-modules = std install-lib: @echo "Installing the SWIG library" - @$(MKINSTDIRS) $(DESTDIR)$(SWIG_LIB) + @$(MKINSTDIRS) $(DESTDIR)$(SWIG_LIB_INSTALL) @for file in $(srcdir)/Lib/*.i $(srcdir)/Lib/*.swg ; do \ i=`basename $$file` ; \ - echo "Installing $(DESTDIR)$(SWIG_LIB)/$$i"; \ - $(INSTALL_DATA) $$file $(DESTDIR)$(SWIG_LIB)/$$i; \ + echo "Installing $(DESTDIR)$(SWIG_LIB_INSTALL)/$$i"; \ + $(INSTALL_DATA) $$file $(DESTDIR)$(SWIG_LIB_INSTALL)/$$i; \ done; @for lang in $(lib-languages) $(lib-modules); \ do \ echo "Installing language specific files for $$lang"; \ - dst=$(DESTDIR)$(SWIG_LIB)/$$lang; \ + dst=$(DESTDIR)$(SWIG_LIB_INSTALL)/$$lang; \ $(MKINSTDIRS) $$dst; \ (doti="`cd $(srcdir)/Lib/$$lang && ls *.i 2>/dev/null || echo ''`"; \ dotswg="`cd $(srcdir)/Lib/$$lang && ls *.swg 2>/dev/null || echo ''`"; \ @@ -556,7 +563,7 @@ uninstall-main: uninstall-lib: @echo "Uninstalling the SWIG library" - rm -rf $(DESTDIR)$(SWIG_LIB)/ + rm -rf $(DESTDIR)$(SWIG_LIB_INSTALL)/ uninstall-ccache: test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) uninstall) @@ -570,8 +577,9 @@ dd = @PACKAGE_NAME@-@PACKAGE_VERSION@ srpm = @PACKAGE_NAME@-@PACKAGE_VERSION@ dist: - @echo "not implemented - use Tools/makedist.py instead." - false + @echo "'make dist' not implemented - use Tools/mkdist.py instead - e.g.:" + @echo "Tools/mkdist.py @VERSION@ master" + @false srcrpm: rm -fr $(srpm) $(srpm).src.rpm diff --git a/README b/README index cbfc708ea13..b24475d6115 100644 --- a/README +++ b/README @@ -1,13 +1,13 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 3.0.5 (in progress) +Version: 3.0.9 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, - Octave, R, Scheme (Guile, MzScheme/Racket, CHICKEN), Ocaml, - Modula-3, Common Lisp (CLISP, Allegro CL, CFFI, UFFI) and Pike. - SWIG can also export its parse tree into Lisp s-expressions and - XML. + Octave, R, Scheme (Guile, MzScheme/Racket, CHICKEN), Scilab, + Ocaml, Modula-3, Common Lisp (CLISP, Allegro CL, CFFI, UFFI) + and Pike. SWIG can also export its parse tree into XML and + Lisp s-expressions. SWIG reads annotated C/C++ header files and creates wrapper code (glue code) in order to make the corresponding C/C++ libraries available to diff --git a/RELEASENOTES b/RELEASENOTES index 2aff1d26501..3f08074abee 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,31 @@ and CHANGES files. Release Notes ============= +Detailed release notes are available with the release and are also +published on the SWIG web site at http://swig.org/release.html. + +SWIG-3.0.8 summary: +- pdf documentation enhancements. +- Various Python 3.5 issues fixed. +- std::array support added for Ruby and Python. +- shared_ptr support added for Ruby. +- Minor improvements for CFFI, Go, Java, Perl, Python, Ruby. + +SWIG-3.0.7 summary: +- Add support for Octave-4.0.0. +- Remove potential Android security exploit in generated Java classes. +- Minor new features and bug fixes. + +SWIG-3.0.6 summary: +- Stability and regression fixes. +- Fixed parsing of C++ corner cases. +- Language improvements and bug fixes for C#, Go, Java, Lua, Python, R. + +SWIG-3.0.5 summary: +- Added support for Scilab. +- Important Python regression fix when wrapping C++ default arguments. +- Minor improvements for C#, Go, Octave, PHP and Python. + SWIG-3.0.4 summary: - Python regression fix when wrapping C++ default arguments. - Improved error messages. @@ -353,7 +378,7 @@ SWIG-1.3.22 summary: exceptions into target language exceptions. - Improved enum support, mapping to built-in Java 1.5 enums and C# enums or the typesafe enum pattern for these two languages. -- Python - much better STL suppport and support for std::wstring, +- Python - much better STL support and support for std::wstring, wchar_t and FILE *. - Initial support for Modula3 and Allegro CL. - 64 bit TCL support. diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index 84a486fb72d..ab5f74b1908 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -57,6 +57,7 @@ extern "C" { /* util.c */ extern void Swig_cparse_replace_descriptor(String *s); + extern SwigType *Swig_cparse_smartptr(Node *n); extern void cparse_normalize_void(Node *); extern Parm *Swig_cparse_parm(String *s); extern ParmList *Swig_cparse_parms(String *s, Node *file_line_node); diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index d86c4590af7..637ac9d6035 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -610,7 +610,10 @@ int yylex(void) { */ - nexttok = Scanner_token(scan); + do { + nexttok = Scanner_token(scan); + } while (nexttok == SWIG_TOKEN_ENDLINE || nexttok == SWIG_TOKEN_COMMENT); + if (Scanner_isoperator(nexttok)) { /* One of the standard C/C++ symbolic operators */ Append(s,Scanner_text(scan)); @@ -681,6 +684,8 @@ int yylex(void) { Append(s," "); } Append(s,Scanner_text(scan)); + } else if (nexttok == SWIG_TOKEN_ENDLINE) { + } else if (nexttok == SWIG_TOKEN_COMMENT) { } else { Append(s,Scanner_text(scan)); needspace = 0; @@ -717,7 +722,7 @@ int yylex(void) { Setfile(cs,cparse_file); Scanner_push(scan,cs); Delete(cs); - return COPERATOR; + return CONVERSIONOPERATOR; } } if (termtoken) @@ -886,7 +891,7 @@ int yylex(void) { return (WARN); /* Note down the apparently unknown directive for error reporting. */ - cparse_unknown_directive = Swig_copy_string(yytext); + cparse_unknown_directive = NewString(yytext); } /* Have an unknown identifier, as a last step, we'll do a typedef lookup on it. */ diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1fb759081d3..621d4342134 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -51,7 +51,7 @@ static String *Classprefix = 0; static String *Namespaceprefix = 0; static int inclass = 0; static Node *currentOuterClass = 0; /* for nested classes */ -static char *last_cpptype = 0; +static const char *last_cpptype = 0; static int inherit_list = 0; static Parm *template_parameters = 0; static int extendmode = 0; @@ -142,6 +142,11 @@ static Node *copy_node(Node *n) { Setattr(nn, key, k.item); continue; } + /* defaultargs will be patched back in later */ + if (strcmp(ckey,"defaultargs") == 0) { + Setattr(nn, "needs_defaultargs", "1"); + continue; + } /* Looks okay. Just copy the data using Copy */ ci = Copy(k.item); Setattr(nn, key, ci); @@ -371,6 +376,10 @@ static void add_symbols(Node *n) { if ((Cmp(Getattr(n,"storage"),"virtual") == 0) && (Cmp(Getattr(n,"value"),"0") == 0)) { only_csymbol = 0; } + if (Cmp(nodeType(n),"destructor") == 0) { + /* Needed for "unref" feature */ + only_csymbol = 0; + } } } else { Setattr(n,"access", "public"); @@ -459,18 +468,24 @@ static void add_symbols(Node *n) { SetFlag(n,"feature:ignore"); } } - if (only_csymbol || GetFlag(n,"feature:ignore")) { + if (only_csymbol || GetFlag(n,"feature:ignore") || strncmp(Char(symname),"$ignore",7) == 0) { /* Only add to C symbol table and continue */ Swig_symbol_add(0, n); - } else if (strncmp(Char(symname),"$ignore",7) == 0) { - char *c = Char(symname)+7; - SetFlag(n,"feature:ignore"); - if (strlen(c)) { - SWIG_WARN_NODE_BEGIN(n); - Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1); - SWIG_WARN_NODE_END(n); + if (!only_csymbol && !GetFlag(n, "feature:ignore")) { + /* Print the warning attached to $ignore name, if any */ + char *c = Char(symname) + 7; + if (strlen(c)) { + SWIG_WARN_NODE_BEGIN(n); + Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1); + SWIG_WARN_NODE_END(n); + } + /* If the symbol was ignored via "rename" and is visible, set also feature:ignore*/ + SetFlag(n, "feature:ignore"); + } + if (!GetFlag(n, "feature:ignore") && Strcmp(symname,"$ignore") == 0) { + /* Add feature:ignore if the symbol was explicitely ignored, regardless of visibility */ + SetFlag(n, "feature:ignore"); } - Swig_symbol_add(0, n); } else { Node *c; if ((wrn) && (Len(wrn))) { @@ -642,6 +657,25 @@ static void add_symbols_copy(Node *n) { } } +static void update_defaultargs(Node *n) { + if (n) { + Node *firstdefaultargs = n; + update_defaultargs(firstChild(n)); + n = nextSibling(n); + while (n) { + update_defaultargs(firstChild(n)); + assert(!Getattr(n, "defaultargs")); + if (Getattr(n, "needs_defaultargs")) { + Setattr(n, "defaultargs", firstdefaultargs); + Delattr(n, "needs_defaultargs"); + } else { + firstdefaultargs = n; + } + n = nextSibling(n); + } + } +} + /* Check a set of declarations to see if any are pure-abstract */ static List *pure_abstracts(Node *n) { @@ -699,14 +733,14 @@ static String *make_class_name(String *name) { /* Use typedef name as class name */ -static void add_typedef_name(Node *n, Node *decl, String *oldName, Symtab *cscope, String *scpname) { +static void add_typedef_name(Node *n, Node *declnode, String *oldName, Symtab *cscope, String *scpname) { String *class_rename = 0; - SwigType *decltype = Getattr(decl, "decl"); - if (!decltype || !Len(decltype)) { + SwigType *decl = Getattr(declnode, "decl"); + if (!decl || !Len(decl)) { String *cname; String *tdscopename; String *class_scope = Swig_symbol_qualifiedscopename(cscope); - String *name = Getattr(decl, "name"); + String *name = Getattr(declnode, "name"); cname = Copy(name); Setattr(n, "tdname", cname); tdscopename = class_scope ? NewStringf("%s::%s", class_scope, name) : Copy(name); @@ -717,7 +751,7 @@ static void add_typedef_name(Node *n, Node *decl, String *oldName, Symtab *cscop if (!Equal(scpname, tdscopename) && !Getattr(classes_typedefs, tdscopename)) { Setattr(classes_typedefs, tdscopename, n); } - Setattr(n, "decl", decltype); + Setattr(n, "decl", decl); Delete(class_scope); Delete(cname); Delete(tdscopename); @@ -740,7 +774,7 @@ static String *remove_block(Node *kw, const String *inputcode) { String *name = Getattr(kw,"name"); if (name && (Cmp(name,"noblock") == 0)) { char *cstr = Char(inputcode); - size_t len = Len(inputcode); + int len = Len(inputcode); if (len && cstr[0] == '{') { --len; ++cstr; if (len && cstr[len - 1] == '}') { --len; } @@ -977,7 +1011,6 @@ static void update_nested_classes(Node *n) static Node *nested_forward_declaration(const char *storage, const char *kind, String *sname, String *name, Node *cpp_opt_declarators) { Node *nn = 0; - int warned = 0; if (sname) { /* Add forward declaration of the nested type */ @@ -1021,13 +1054,12 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S if (!currentOuterClass || !GetFlag(currentOuterClass, "nested")) { if (nn && Equal(nodeType(nn), "classforward")) { Node *n = nn; - SWIG_WARN_NODE_BEGIN(n); - Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name); - SWIG_WARN_NODE_END(n); - warned = 1; - } - - if (!warned) { + if (!GetFlag(n, "feature:ignore")) { + SWIG_WARN_NODE_BEGIN(n); + Swig_warning(WARN_PARSE_NAMED_NESTED_CLASS, cparse_file, cparse_line,"Nested %s not currently supported (%s ignored)\n", kind, sname ? sname : name); + SWIG_WARN_NODE_END(n); + } + } else { Swig_warning(WARN_PARSE_UNNAMED_NESTED_CLASS, cparse_file, cparse_line, "Nested %s not currently supported (ignored).\n", kind); } } @@ -1297,7 +1329,7 @@ static void mark_nodes_as_extend(Node *n) { %} %union { - char *id; + const char *id; List *bases; struct Define { String *val; @@ -1372,7 +1404,7 @@ static void mark_nodes_as_extend(Node *n) { %token NONID DSTAR DCNOT %token TEMPLATE %token OPERATOR -%token COPERATOR +%token CONVERSIONOPERATOR %token PARSETYPE PARSEPARM PARSEPARMS %left CAST @@ -1414,7 +1446,7 @@ static void mark_nodes_as_extend(Node *n) { /* Misc */ %type identifier; %type initializer cpp_const exception_specification; -%type storage_class; +%type storage_class extern_string; %type parms ptail rawparms varargs_parms ; %type templateparameters templateparameterstail; %type

    parm valparm rawvalparms valparms valptail ; @@ -1428,7 +1460,7 @@ static void mark_nodes_as_extend(Node *n) { %type definetype def_args etype default_delete deleted_definition explicit_default; %type expr exprnum exprcompound valexpr; %type ename ; -%type template_decl; +%type less_valparms_greater; %type type_qualifier ; %type type_qualifier_raw; %type idstring idstringopt; @@ -1436,11 +1468,11 @@ static void mark_nodes_as_extend(Node *n) { %type pragma_arg; %type includetype; %type pointer primitive_type; -%type declarator direct_declarator notso_direct_declarator parameter_declarator typemap_parameter_declarator; +%type declarator direct_declarator notso_direct_declarator parameter_declarator plain_declarator; %type abstract_declarator direct_abstract_declarator ctor_end; %type typemap_type; -%type idcolon idcolontail idcolonnt idcolontailnt idtemplate stringbrace stringbracesemi; -%type string stringnum wstring; +%type idcolon idcolontail idcolonnt idcolontailnt idtemplate idtemplatetemplate stringbrace stringbracesemi; +%type string stringnum wstring; %type template_parms; %type cpp_end cpp_vend; %type rename_namewarn; @@ -1530,11 +1562,11 @@ declaration : swig_directive { $$ = $1; } This is nearly impossible to parse normally. We just let the first part generate a syntax error and then resynchronize on the - COPERATOR token---discarding the rest of the definition. Ugh. + CONVERSIONOPERATOR token---discarding the rest of the definition. Ugh. */ - | error COPERATOR { + | error CONVERSIONOPERATOR { $$ = 0; skip_decl(); } @@ -1739,7 +1771,7 @@ echo_directive : ECHO HBLOCK { } | ECHO string { char temp[64]; - String *s = NewString($2); + String *s = $2; Replace(s,"$file",cparse_file, DOH_REPLACE_ANY); sprintf(temp,"%d", cparse_line); Replace(s,"$line",temp,DOH_REPLACE_ANY); @@ -1844,7 +1876,7 @@ fragment_directive: FRAGMENT LPAREN fname COMMA kwargs RPAREN HBLOCK { include_directive: includetype options string BEGINFILE { $1.filename = Copy(cparse_file); $1.line = cparse_line; - scanner_set_location(NewString($3),1); + scanner_set_location($3,1); if ($2) { String *maininput = Getattr($2, "maininput"); if (maininput) @@ -2099,7 +2131,7 @@ pragma_directive : PRAGMA pragma_lang identifier EQUAL pragma_arg { } ; -pragma_arg : string { $$ = NewString($1); } +pragma_arg : string { $$ = $1; } | HBLOCK { $$ = $1; } ; @@ -2251,7 +2283,7 @@ feature_directive : FEATURE LPAREN idstring RPAREN declarator cpp_const stringbr scanner_clear_rename(); } | FEATURE LPAREN idstring COMMA stringnum RPAREN declarator cpp_const SEMI { - String *val = Len($5) ? NewString($5) : 0; + String *val = Len($5) ? $5 : 0; new_feature($3, val, 0, $7.id, $7.type, $7.parms, $8.qualifier); $$ = 0; scanner_clear_rename(); @@ -2263,7 +2295,7 @@ feature_directive : FEATURE LPAREN idstring RPAREN declarator cpp_const stringbr scanner_clear_rename(); } | FEATURE LPAREN idstring COMMA stringnum featattr RPAREN declarator cpp_const SEMI { - String *val = Len($5) ? NewString($5) : 0; + String *val = Len($5) ? $5 : 0; new_feature($3, val, $6, $8.id, $8.type, $8.parms, $9.qualifier); $$ = 0; scanner_clear_rename(); @@ -2277,7 +2309,7 @@ feature_directive : FEATURE LPAREN idstring RPAREN declarator cpp_const stringbr scanner_clear_rename(); } | FEATURE LPAREN idstring COMMA stringnum RPAREN SEMI { - String *val = Len($5) ? NewString($5) : 0; + String *val = Len($5) ? $5 : 0; new_feature($3, val, 0, 0, 0, 0, 0); $$ = 0; scanner_clear_rename(); @@ -2289,7 +2321,7 @@ feature_directive : FEATURE LPAREN idstring RPAREN declarator cpp_const stringbr scanner_clear_rename(); } | FEATURE LPAREN idstring COMMA stringnum featattr RPAREN SEMI { - String *val = Len($5) ? NewString($5) : 0; + String *val = Len($5) ? $5 : 0; new_feature($3, val, $6, 0, 0, 0, 0); $$ = 0; scanner_clear_rename(); @@ -2464,7 +2496,7 @@ tm_tail : COMMA typemap_parm tm_tail { | empty { $$ = 0;} ; -typemap_parm : type typemap_parameter_declarator { +typemap_parm : type plain_declarator { Parm *parm; SwigType_push($1,$2.type); $$ = new_node("typemapitem"); @@ -2565,6 +2597,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va { Node *nn = n; Node *linklistend = 0; + Node *linkliststart = 0; while (nn) { Node *templnode = 0; if (Strcmp(nodeType(nn),"template") == 0) { @@ -2646,7 +2679,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va } templnode = copy_node(nn); - update_nested_classes(templnode); /* update classes nested withing template */ + update_nested_classes(templnode); /* update classes nested within template */ /* We need to set the node name based on name used to instantiate */ Setattr(templnode,"name",tname); Delete(tname); @@ -2666,7 +2699,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va String *symname = Swig_name_make(templnode,0,$3,0,0); */ - String *symname = $3; + String *symname = NewString($3); Swig_cparse_template_expand(templnode,symname,temparms,tscope); Setattr(templnode,"sym:name",symname); } else { @@ -2763,6 +2796,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va } /* all the overloaded templated functions are added into a linked list */ + if (!linkliststart) + linkliststart = templnode; if (nscope_inner) { /* non-global namespace */ if (templnode) { @@ -2783,6 +2818,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va } nn = Getattr(nn,"sym:nextSibling"); /* repeat for overloaded templated functions. If a templated class there will never be a sibling. */ } + update_defaultargs(linkliststart); } Swig_symbol_setscope(tscope); Delete(Namespaceprefix); @@ -2848,10 +2884,11 @@ c_declaration : c_decl { Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line, "Lambda expressions and closures are not fully supported yet.\n"); SWIG_WARN_NODE_END($$); } - | USING idcolon EQUAL { - skip_decl(); + | USING idcolon EQUAL type plain_declarator SEMI { $$ = new_node("using"); Setattr($$,"name",$2); + SwigType_push($4,$5.type); + Setattr($$,"uname",$4); add_symbols($$); SWIG_WARN_NODE_BEGIN($$); Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line, "The 'using' keyword in type aliasing is not fully supported yet.\n"); @@ -2859,15 +2896,17 @@ c_declaration : c_decl { $$ = 0; /* TODO - ignored for now */ } - | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL identifier { - skip_decl(); + | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL type plain_declarator SEMI { $$ = new_node("using"); - Setattr($$,"uname",$8); Setattr($$,"name",$6); + SwigType_push($8,$9.type); + Setattr($$,"uname",$8); add_symbols($$); SWIG_WARN_NODE_BEGIN($$); Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line, "The 'using' keyword in template aliasing is not fully supported yet.\n"); SWIG_WARN_NODE_END($$); + + $$ = 0; /* TODO - ignored for now */ } ; @@ -2914,8 +2953,8 @@ c_decl : storage_class type declarator initializer c_decl_tail { matches that of the declaration, then we will allow it. Otherwise, delete. */ String *p = Swig_scopename_prefix($3.id); if (p) { - if ((Namespaceprefix && Strcmp(p,Namespaceprefix) == 0) || - (inclass && Strcmp(p,Classprefix) == 0)) { + if ((Namespaceprefix && Strcmp(p, Namespaceprefix) == 0) || + (Classprefix && Strcmp(p, Classprefix) == 0)) { String *lstr = Swig_scopename_last($3.id); Setattr($$,"name",lstr); Delete(lstr); @@ -2970,8 +3009,8 @@ c_decl : storage_class type declarator initializer c_decl_tail { if (Strstr($3.id,"::")) { String *p = Swig_scopename_prefix($3.id); if (p) { - if ((Namespaceprefix && Strcmp(p,Namespaceprefix) == 0) || - (inclass && Strcmp(p,Classprefix) == 0)) { + if ((Namespaceprefix && Strcmp(p, Namespaceprefix) == 0) || + (Classprefix && Strcmp(p, Classprefix) == 0)) { String *lstr = Swig_scopename_last($3.id); Setattr($$,"name",lstr); Delete(lstr); @@ -3068,7 +3107,9 @@ initializer : def_args { cpp_alternate_rettype : primitive_type { $$ = $1; } | TYPE_BOOL { $$ = $1; } | TYPE_VOID { $$ = $1; } +/* | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } +*/ | TYPE_RAW { $$ = $1; } | idcolon { $$ = $1; } | decltype { $$ = $1; } @@ -3605,6 +3646,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Swig_symbol_setscope(cscope); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); + Classprefix = currentOuterClass ? Getattr(currentOuterClass, "Classprefix") : 0; } /* An unnamed struct, possibly with a typedef */ @@ -3641,7 +3683,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { cparse_start_line = cparse_line; currentOuterClass = $$; inclass = 1; - Classprefix = NewStringEmpty(); + Classprefix = 0; Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); /* save the structure declaration to make a typedef for it later*/ @@ -3654,6 +3696,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { String *name = 0; Node *n; Classprefix = 0; + (void)$5; $$ = currentOuterClass; currentOuterClass = Getattr($$, "nested:outer"); if (!currentOuterClass) @@ -3751,6 +3794,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delete($$); $$ = $6; /* pass member list to outer class/namespace (instead of self)*/ } + Classprefix = currentOuterClass ? Getattr(currentOuterClass, "Classprefix") : 0; } ; @@ -4435,7 +4479,7 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { /* C++ type conversion operator */ -cpp_conversion_operator : storage_class COPERATOR type pointer LPAREN parms RPAREN cpp_vend { +cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN parms RPAREN cpp_vend { $$ = new_node("cdecl"); Setattr($$,"type",$3); Setattr($$,"name",$2); @@ -4450,7 +4494,7 @@ cpp_conversion_operator : storage_class COPERATOR type pointer LPAREN parms RPAR Setattr($$,"conversion_operator","1"); add_symbols($$); } - | storage_class COPERATOR type AND LPAREN parms RPAREN cpp_vend { + | storage_class CONVERSIONOPERATOR type AND LPAREN parms RPAREN cpp_vend { SwigType *decl; $$ = new_node("cdecl"); Setattr($$,"type",$3); @@ -4467,7 +4511,7 @@ cpp_conversion_operator : storage_class COPERATOR type pointer LPAREN parms RPAR Setattr($$,"conversion_operator","1"); add_symbols($$); } - | storage_class COPERATOR type LAND LPAREN parms RPAREN cpp_vend { + | storage_class CONVERSIONOPERATOR type LAND LPAREN parms RPAREN cpp_vend { SwigType *decl; $$ = new_node("cdecl"); Setattr($$,"type",$3); @@ -4485,7 +4529,7 @@ cpp_conversion_operator : storage_class COPERATOR type pointer LPAREN parms RPAR add_symbols($$); } - | storage_class COPERATOR type pointer AND LPAREN parms RPAREN cpp_vend { + | storage_class CONVERSIONOPERATOR type pointer AND LPAREN parms RPAREN cpp_vend { SwigType *decl; $$ = new_node("cdecl"); Setattr($$,"type",$3); @@ -4504,7 +4548,7 @@ cpp_conversion_operator : storage_class COPERATOR type pointer LPAREN parms RPAR add_symbols($$); } - | storage_class COPERATOR type LPAREN parms RPAREN cpp_vend { + | storage_class CONVERSIONOPERATOR type LPAREN parms RPAREN cpp_vend { String *t = NewStringEmpty(); $$ = new_node("cdecl"); Setattr($$,"type",$3); @@ -4641,7 +4685,9 @@ anon_bitfield_type : primitive_type { $$ = $1; } | TYPE_BOOL { $$ = $1; } | TYPE_VOID { $$ = $1; } +/* | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } +*/ | TYPE_RAW { $$ = $1; } | idcolon { @@ -4652,28 +4698,22 @@ anon_bitfield_type : primitive_type { $$ = $1; /* ====================================================================== * PRIMITIVES * ====================================================================== */ - -storage_class : EXTERN { $$ = "extern"; } - | EXTERN string { - if (strcmp($2,"C") == 0) { +extern_string : EXTERN string { + if (Strcmp($2,"C") == 0) { $$ = "externc"; - } else if (strcmp($2,"C++") == 0) { + } else if (Strcmp($2,"C++") == 0) { $$ = "extern"; } else { Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2); $$ = 0; } } - | EXTERN string THREAD_LOCAL { - if (strcmp($2,"C") == 0) { - $$ = "externc thread_local"; - } else if (strcmp($2,"C++") == 0) { - $$ = "extern thread_local"; - } else { - Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2); - $$ = 0; - } - } + ; + +storage_class : EXTERN { $$ = "extern"; } + | extern_string { $$ = $1; } + | extern_string THREAD_LOCAL { $$ = "thread_local"; } + | extern_string TYPEDEF { $$ = "typedef"; } | STATIC { $$ = "static"; } | TYPEDEF { $$ = "typedef"; } | VIRTUAL { $$ = "virtual"; } @@ -4884,7 +4924,7 @@ parameter_declarator : declarator def_args { } ; -typemap_parameter_declarator : declarator { +plain_declarator : declarator { $$ = $1; if (SwigType_isfunction($1.type)) { Delete(SwigType_pop_function($1.type)); @@ -5594,7 +5634,9 @@ type_right : primitive_type { $$ = $1; } | TYPE_BOOL { $$ = $1; } | TYPE_VOID { $$ = $1; } +/* | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } +*/ | c_enum_key idcolon { $$ = NewStringf("enum %s", $2); } | TYPE_RAW { $$ = $1; } @@ -5777,17 +5819,6 @@ definetype : { /* scanner_check_typedef(); */ } expr { | default_delete { $$ = $1; } -/* - | string { - $$.val = NewString($1); - $$.rawval = NewStringf("\"%(escape)s\"",$$.val); - $$.type = T_STRING; - $$.bitfield = 0; - $$.throws = 0; - $$.throwf = 0; - $$.nexcept = 0; - } -*/ ; default_delete : deleted_definition { @@ -5910,7 +5941,7 @@ expr : valexpr { $$ = $1; } valexpr : exprnum { $$ = $1; } | string { - $$.val = NewString($1); + $$.val = $1; $$.type = T_STRING; } | SIZEOF LPAREN type parameter_declarator RPAREN { @@ -5925,7 +5956,7 @@ valexpr : exprnum { $$ = $1; } } | exprcompound { $$ = $1; } | wstring { - $$.val = NewString($1); + $$.val = $1; $$.rawval = NewStringf("L\"%s\"", $$.val); $$.type = T_WSTRING; } @@ -6420,14 +6451,13 @@ mem_initializer : idcolon LPAREN { } ; -template_decl : LESSTHAN valparms GREATERTHAN { +less_valparms_greater : LESSTHAN valparms GREATERTHAN { String *s = NewStringEmpty(); SwigType_add_template(s,$2); $$ = Char(s); scanner_last_id(1); - } - | empty { $$ = (char*)""; } - ; + } + ; /* Identifiers including the C++11 identifiers with special meaning */ identifier : ID { $$ = $1; } @@ -6436,8 +6466,8 @@ identifier : ID { $$ = $1; } ; idstring : identifier { $$ = $1; } - | default_delete { $$ = $1.val; } - | string { $$ = $1; } + | default_delete { $$ = Char($1.val); } + | string { $$ = Char($1); } ; idstringopt : idstring { $$ = $1; } @@ -6449,35 +6479,38 @@ idcolon : idtemplate idcolontail { if (!$$) $$ = NewStringf("%s%s", $1,$2); Delete($2); } - | NONID DCOLON idtemplate idcolontail { + | NONID DCOLON idtemplatetemplate idcolontail { $$ = NewStringf("::%s%s",$3,$4); Delete($4); } | idtemplate { $$ = NewString($1); } - | NONID DCOLON idtemplate { + | NONID DCOLON idtemplatetemplate { $$ = NewStringf("::%s",$3); } | OPERATOR { - $$ = NewString($1); + $$ = NewStringf("%s", $1); + } + | OPERATOR less_valparms_greater { + $$ = NewStringf("%s%s", $1, $2); } | NONID DCOLON OPERATOR { $$ = NewStringf("::%s",$3); } ; -idcolontail : DCOLON idtemplate idcolontail { +idcolontail : DCOLON idtemplatetemplate idcolontail { $$ = NewStringf("::%s%s",$2,$3); Delete($3); } - | DCOLON idtemplate { + | DCOLON idtemplatetemplate { $$ = NewStringf("::%s",$2); } | DCOLON OPERATOR { $$ = NewStringf("::%s",$2); } -/* | DCOLON COPERATOR { +/* | DCOLON CONVERSIONOPERATOR { $$ = NewString($2); } */ @@ -6487,12 +6520,20 @@ idcolontail : DCOLON idtemplate idcolontail { ; -idtemplate : identifier template_decl { - $$ = NewStringf("%s%s",$1,$2); - /* if (Len($2)) { - scanner_last_id(1); - } */ - } +idtemplate : identifier { + $$ = NewStringf("%s", $1); + } + | identifier less_valparms_greater { + $$ = NewStringf("%s%s", $1, $2); + } + ; + +idtemplatetemplate : idtemplate { + $$ = $1; + } + | TEMPLATE identifier less_valparms_greater { + $$ = NewStringf("%s%s", $2, $3); + } ; /* Identifier, but no templates */ @@ -6536,30 +6577,24 @@ idcolontailnt : DCOLON identifier idcolontailnt { /* Concatenated strings */ string : string STRING { - $$ = (char *) malloc(strlen($1)+strlen($2)+1); - strcpy($$,$1); - strcat($$,$2); + $$ = NewStringf("%s%s", $1, $2); } - | STRING { $$ = $1;} + | STRING { $$ = NewString($1);} ; /* Concatenated wide strings: L"str1" L"str2" */ wstring : wstring WSTRING { - $$ = (char *) malloc(strlen($1)+strlen($2)+1); - strcpy($$,$1); - strcat($$,$2); + $$ = NewStringf("%s%s", $1, $2); } /* Concatenated wide string and normal string literal: L"str1" "str2" */ /*not all the compilers support this concatenation mode, so perhaps better to postpone it*/ /*| wstring STRING { here $2 comes unescaped, we have to escape it back first via NewStringf("%(escape)s)" - $$ = (char *) malloc(strlen($1)+strlen($2)+1); - strcpy($$,$1); - strcat($$,$2); + $$ = NewStringf("%s%s", $1, $2); }*/ - | WSTRING { $$ = $1;} + | WSTRING { $$ = NewString($1);} ; stringbrace : string { - $$ = NewString($1); + $$ = $1; } | LBRACE { skip_balanced('{','}'); diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index fe8fc280055..e575073a448 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -97,6 +97,15 @@ static int cparse_template_expand(Node *n, String *tname, String *rname, String Append(cpatchlist, Getattr(n, "sym:name")); } } + if (checkAttribute(n, "storage", "friend")) { + String *symname = Getattr(n, "sym:name"); + if (symname) { + String *stripped_name = SwigType_templateprefix(symname); + Setattr(n, "sym:name", stripped_name); + Delete(stripped_name); + } + Append(typelist, Getattr(n, "name")); + } add_parms(Getattr(n, "parms"), cpatchlist, typelist); add_parms(Getattr(n, "throws"), cpatchlist, typelist); @@ -228,7 +237,7 @@ String *partial_arg(String *s, String *p) { if (!c) { return Copy(s); } - prefix = NewStringWithSize(cp, c - cp); + prefix = NewStringWithSize(cp, (int)(c - cp)); newarg = Copy(s); Replace(newarg, prefix, "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); Delete(prefix); diff --git a/Source/CParse/util.c b/Source/CParse/util.c index 320671d9a0d..0e2136a4936 100644 --- a/Source/CParse/util.c +++ b/Source/CParse/util.c @@ -70,6 +70,28 @@ void Swig_cparse_replace_descriptor(String *s) { } } +/* ----------------------------------------------------------------------------- + * Swig_cparse_smartptr() + * + * Parse the type in smartptr feature and convert into a SwigType. + * Error out if the parsing fails as this is like a parser syntax error. + * ----------------------------------------------------------------------------- */ + +SwigType *Swig_cparse_smartptr(Node *n) { + SwigType *smart = 0; + String *smartptr = Getattr(n, "feature:smartptr"); + if (smartptr) { + SwigType *cpt = Swig_cparse_type(smartptr); + if (cpt) { + smart = SwigType_typedef_resolve_all(cpt); + Delete(cpt); + } else { + Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, SwigType_namestr(Getattr(n, "name"))); + } + } + return smart; +} + /* ----------------------------------------------------------------------------- * cparse_normalize_void() * diff --git a/Source/DOH/base.c b/Source/DOH/base.c index 4034e562654..12351dd094d 100644 --- a/Source/DOH/base.c +++ b/Source/DOH/base.c @@ -146,7 +146,7 @@ int DohLen(const DOH *obj) { } return 0; } else { - return strlen((char *) obj); + return (int)strlen((char *) obj); } } @@ -636,7 +636,7 @@ int DohRead(DOH *obj, void *buffer, int length) { return -1; } /* Hmmm. Not a file. Maybe it's a real FILE */ - return fread(buffer, 1, length, (FILE *) b); + return (int)fread(buffer, 1, length, (FILE *) b); } /* ----------------------------------------------------------------------------- @@ -654,7 +654,7 @@ int DohWrite(DOH *obj, const void *buffer, int length) { return -1; } /* Hmmm. Not a file. Maybe it's a real FILE */ - return fwrite(buffer, 1, length, (FILE *) b); + return (int)fwrite(buffer, 1, length, (FILE *) b); } /* ----------------------------------------------------------------------------- diff --git a/Source/DOH/file.c b/Source/DOH/file.c index 7409ebbfbf1..5c56771d0c1 100644 --- a/Source/DOH/file.c +++ b/Source/DOH/file.c @@ -52,7 +52,7 @@ static int File_read(DOH *fo, void *buffer, int len) { DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { - return fread(buffer, 1, len, f->filep); + return (int)fread(buffer, 1, len, f->filep); } else if (f->fd) { #ifdef DOH_INTFILE return read(f->fd, buffer, len); diff --git a/Source/DOH/fio.c b/Source/DOH/fio.c index 7055ffc85cd..77419008ce5 100644 --- a/Source/DOH/fio.c +++ b/Source/DOH/fio.c @@ -304,9 +304,9 @@ int DohvPrintf(DOH *so, const char *format, va_list ap) { } if (strlen(encoder)) { enc = encode(encoder, Sval); - maxwidth = maxwidth + strlen(newformat) + Len(enc); + maxwidth = maxwidth + (int)strlen(newformat) + Len(enc); } else { - maxwidth = maxwidth + strlen(newformat) + Len(Sval); + maxwidth = maxwidth + (int)strlen(newformat) + Len(Sval); } *(fmt++) = 's'; *fmt = 0; @@ -320,7 +320,7 @@ int DohvPrintf(DOH *so, const char *format, va_list ap) { } else { nbytes += sprintf(stemp, newformat, Data(Sval)); } - if (Writen(so, stemp, strlen(stemp)) < 0) + if (Writen(so, stemp, (int)strlen(stemp)) < 0) return -1; if ((DOH *) Sval != doh) { Delete(Sval); @@ -346,7 +346,7 @@ int DohvPrintf(DOH *so, const char *format, va_list ap) { } else { enc = 0; } - maxwidth = maxwidth + strlen(newformat) + strlen((char *) doh); + maxwidth = maxwidth + (int)strlen(newformat) + (int)strlen((char *) doh); *(fmt++) = 's'; *fmt = 0; if ((maxwidth + 1) < OBUFLEN) { @@ -355,7 +355,7 @@ int DohvPrintf(DOH *so, const char *format, va_list ap) { stemp = (char *) DohMalloc(maxwidth + 1); } nbytes += sprintf(stemp, newformat, doh); - if (Writen(so, stemp, strlen(stemp)) < 0) + if (Writen(so, stemp, (int)strlen(stemp)) < 0) return -1; if (stemp != obuffer) { DohFree(stemp); @@ -366,7 +366,7 @@ int DohvPrintf(DOH *so, const char *format, va_list ap) { } else { *(fmt++) = *p; *fmt = 0; - maxwidth = maxwidth + strlen(newformat) + 64; + maxwidth = maxwidth + (int)strlen(newformat) + 64; /* Only allocate a buffer if it is too big to fit. Shouldn't have to do this very often */ @@ -401,7 +401,7 @@ int DohvPrintf(DOH *so, const char *format, va_list ap) { default: break; } - if (Writen(so, stemp, strlen(stemp)) < 0) + if (Writen(so, stemp, (int)strlen(stemp)) < 0) return -1; if (stemp != obuffer) DohFree(stemp); @@ -414,7 +414,7 @@ int DohvPrintf(DOH *so, const char *format, va_list ap) { if (state) { int r; *fmt = 0; - r = Writen(so, fmt, strlen(fmt)); + r = Writen(so, fmt, (int)strlen(fmt)); if (r < 0) return -1; nbytes += r; @@ -455,7 +455,7 @@ int DohPrintv(DOHFile * f, ...) { if (DohCheck(obj)) { ret += DohDump(obj, f); } else { - ret += DohWrite(f, obj, strlen((char *) obj)); + ret += DohWrite(f, obj, (int)strlen((char *) obj)); } } va_end(ap); diff --git a/Source/DOH/string.c b/Source/DOH/string.c index cfc6c70f607..490198dfabb 100644 --- a/Source/DOH/string.c +++ b/Source/DOH/string.c @@ -687,7 +687,7 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co return 0; base = str->str; - tokenlen = strlen(token); + tokenlen = (int)strlen(token); s = (*match) (base, base, token, tokenlen); if (!s) @@ -724,7 +724,7 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co } first = s; - replen = strlen(rep); + replen = (int)strlen(rep); delta = (replen - tokenlen); diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 1210d64a6e5..bc54bc77478 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -232,6 +232,14 @@ /* please leave 700-719 free for D */ +#define WARN_SCILAB_TRUNCATED_NAME 720 + +/* please leave 720-739 free for Scilab */ + +#define WARN_PYTHON_INDENT_MISMATCH 740 + +/* please leave 740-759 free for Python */ + #define WARN_RUBY_WRONG_NAME 801 #define WARN_RUBY_MULTIPLE_INHERITANCE 802 diff --git a/Source/Makefile.am b/Source/Makefile.am index 708c0e5f633..a316b83d1be 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -67,6 +67,7 @@ eswig_SOURCES = CParse/cscanner.c \ Modules/r.cxx \ Modules/ruby.cxx \ Modules/s-exp.cxx \ + Modules/scilab.cxx \ Modules/swigmain.cxx \ Modules/tcl8.cxx \ Modules/typepass.cxx \ diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index c7d9ff21bdc..fae255b7f36 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1635,9 +1635,7 @@ int ALLEGROCL::top(Node *n) { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGALLEGROCL\n"); - Printf(f_runtime, "\n"); + Printf(f_runtime, "\n\n#ifndef SWIGALLEGROCL\n#define SWIGALLEGROCL\n#endif\n\n"); Swig_banner_target_lang(f_cl, ";;"); @@ -1794,12 +1792,12 @@ static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { String *t2 = Getattr(p2, "tmap:typecheck:precedence"); if ((!t1) && (!nodes[i].error)) { Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), - "Overloaded method %s not supported (no type checking rule for '%s').\n", + "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0)); nodes[i].error = 1; } else if ((!t2) && (!nodes[j].error)) { Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s not supported (no type checking rule for '%s').\n", + "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0)); nodes[j].error = 1; } diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index dc3820766ed..f79373d183d 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -941,6 +941,8 @@ Allocate(): Setattr(inclass, "allocate:default_destructor", "1"); } else if (cplus_mode == PROTECTED) { Setattr(inclass, "allocate:default_base_destructor", "1"); + } else if (cplus_mode == PRIVATE) { + Setattr(inclass, "allocate:private_destructor", "1"); } } else { Setattr(inclass, "allocate:has_destructor", "1"); diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx index a1be00100de..5d2b8435ca0 100644 --- a/Source/Modules/cffi.cxx +++ b/Source/Modules/cffi.cxx @@ -61,6 +61,11 @@ class CFFI:public Language { virtual int classHandler(Node *n); private: + static void checkConstraints(ParmList *parms, Wrapper *f); + static void argout(ParmList *parms, Wrapper *f); + static String *freearg(ParmList *parms); + static void cleanupFunction(Node *n, Wrapper *f, ParmList *parms); + void emit_defun(Node *n, String *name); void emit_defmethod(Node *n); void emit_initialize_instance(Node *n); @@ -169,9 +174,7 @@ int CFFI::top(Node *n) { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGCFFI\n"); - Printf(f_runtime, "\n"); + Printf(f_runtime, "\n\n#ifndef SWIGCFFI\n#define SWIGCFFI\n#endif\n\n"); Swig_banner_target_lang(f_lisp, ";;;"); @@ -364,6 +367,77 @@ int CFFI::membervariableHandler(Node *n) { return Language::membervariableHandler(n); } + +void CFFI::checkConstraints(ParmList *parms, Wrapper *f) { + Parm *p = parms; + while (p) { + String *tm = Getattr(p, "tmap:check"); + if (!tm) { + p = nextSibling(p); + } else { + tm = Copy(tm); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(f->code, tm, "\n\n", NULL); + Delete(tm); + p = Getattr(p, "tmap:check:next"); + } + } +} + +void CFFI::argout(ParmList *parms, Wrapper *f) { + Parm *p = parms; + while (p) { + String *tm = Getattr(p, "tmap:argout"); + if (!tm) { + p = nextSibling(p); + } else { + tm = Copy(tm); + Replaceall(tm, "$result", Swig_cresult_name()); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(f->code, tm, "\n", NULL); + Delete(tm); + p = Getattr(p, "tmap:argout:next"); + } + } +} + +String *CFFI::freearg(ParmList *parms) { + String *ret = NewString(""); + Parm *p = parms; + while (p) { + String *tm = Getattr(p, "tmap:freearg"); + if (!tm) { + p = nextSibling(p); + } else { + tm = Copy(tm); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(ret, tm, "\n", NULL); + Delete(tm); + p = Getattr(p, "tmap:freearg:next"); + } + } + return ret; +} + +void CFFI::cleanupFunction(Node *n, Wrapper *f, ParmList *parms) { + String *cleanup = freearg(parms); + Printv(f->code, cleanup, NULL); + + if (GetFlag(n, "feature:new")) { + String *tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0); + if (tm) { + Replaceall(tm, "$source", Swig_cresult_name()); + Printv(f->code, tm, "\n", NULL); + Delete(tm); + } + } + + Replaceall(f->code, "$cleanup", cleanup); + Delete(cleanup); + + Replaceall(f->code, "$symname", Getattr(n, "sym:name")); +} + int CFFI::functionWrapper(Node *n) { ParmList *parms = Getattr(n, "parms"); @@ -451,6 +525,9 @@ int CFFI::functionWrapper(Node *n) { // Emit the function definition String *signature = SwigType_str(return_type, name_and_parms); Printf(f->def, "EXPORT %s {", signature); + + checkConstraints(parms, f); + Printf(f->code, " try {\n"); String *actioncode = emit_action(n); @@ -459,9 +536,17 @@ int CFFI::functionWrapper(Node *n) { if (result_convert) { Replaceall(result_convert, "$result", "lresult"); Printf(f->code, "%s\n", result_convert); - if(!is_void_return) Printf(f->code, " return lresult;\n"); - Delete(result_convert); } + Delete(result_convert); + + argout(parms, f); + + cleanupFunction(n, f, parms); + + if (!is_void_return) { + Printf(f->code, " return lresult;\n"); + } + emit_return_variable(n, Getattr(n, "type"), f); Printf(f->code, " } catch (...) {\n"); @@ -831,7 +916,12 @@ void CFFI::emit_struct_union(Node *n, bool un = false) { if (slot_name && (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0)) slot_name = NewStringf("t_var"); - Printf(f_cl, "\n\t(%s %s)", slot_name, typespec); + if (SwigType_isarray(childType) && SwigType_array_ndim(childType) == 1) { + String *dim = SwigType_array_getdim(childType, 0); + Printf(f_cl, "\n\t(%s %s :count %s)", slot_name, typespec, dim); + Delete(dim); + } else + Printf(f_cl, "\n\t(%s %s)", slot_name, typespec); Delete(node); Delete(childType); @@ -855,8 +945,11 @@ void CFFI::emit_struct_union(Node *n, bool un = false) { } void CFFI::emit_export(Node *n, String *name) { - if (GetInt(n, "feature:export")) - Printf(f_cl, "\n(cl:export '%s)\n", name); + if (GetInt(n, "feature:export")) { + String* package = Getattr(n, "feature:export:package"); + Printf(f_cl, "\n(cl:export '%s%s%s)\n", name, package ? " " : "", + package ? package : ""); + } } void CFFI::emit_inline(Node *n, String *name) { diff --git a/Source/Modules/chicken.cxx b/Source/Modules/chicken.cxx index 986638cf391..68a42a29b94 100644 --- a/Source/Modules/chicken.cxx +++ b/Source/Modules/chicken.cxx @@ -222,8 +222,7 @@ int CHICKEN::top(Node *n) { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGCHICKEN\n"); + Printf(f_runtime, "\n\n#ifndef SWIGCHICKEN\n#define SWIGCHICKEN\n#endif\n\n"); if (no_collection) Printf(f_runtime, "#define SWIG_CHICKEN_NO_COLLECTION 1\n"); diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 3b1e0356008..8a047c46d4d 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -34,6 +34,7 @@ class CSHARP:public Language { File *f_init; File *f_directors; File *f_directors_h; + File *f_single_out; List *filenames_list; bool proxy_flag; // Flag for generating proxy classes @@ -78,6 +79,7 @@ class CSHARP:public Language { String *director_method_types; // Director method types String *director_connect_parms; // Director delegates parameter list for director connect call String *destructor_call; //C++ destructor call if any + String *output_file; // File name for single file mode. If set all generated code will be written to this file // Director method stuff: List *dmethods_seq; @@ -108,6 +110,7 @@ class CSHARP:public Language { f_init(NULL), f_directors(NULL), f_directors_h(NULL), + f_single_out(NULL), filenames_list(NULL), proxy_flag(true), native_function_flag(false), @@ -150,6 +153,7 @@ class CSHARP:public Language { director_method_types(NULL), director_connect_parms(NULL), destructor_call(NULL), + output_file(NULL), dmethods_seq(NULL), dmethods_table(NULL), n_dmethods(0), @@ -244,6 +248,16 @@ class CSHARP:public Language { } else if (strcmp(argv[i], "-oldvarnames") == 0) { Swig_mark_arg(i); old_variable_names = true; + } else if (strcmp(argv[i], "-outfile") == 0) { + if (argv[i + 1]) { + output_file = NewString(""); + Printf(output_file, argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } } else if (strcmp(argv[i], "-help") == 0) { Printf(stdout, "%s\n", usage); } @@ -378,8 +392,7 @@ class CSHARP:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGCSHARP\n"); + Printf(f_runtime, "\n\n#ifndef SWIGCSHARP\n#define SWIGCSHARP\n#endif\n\n"); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); @@ -402,8 +415,16 @@ class CSHARP:public Language { } Printf(f_runtime, "\n"); + if (namespce) { + String *wrapper_name = NewStringf(""); + Printf(wrapper_name, "CSharp_%s_%%f", namespce); + Swig_name_register("wrapper", wrapper_name); + Delete(wrapper_name); + } + else { + Swig_name_register("wrapper", "CSharp_%f"); + } - Swig_name_register("wrapper", "CSharp_%f"); if (old_variable_names) { Swig_name_register("set", "set_%n%v"); Swig_name_register("get", "get_%n%v"); @@ -418,22 +439,12 @@ class CSHARP:public Language { if (directorsEnabled()) { // Insert director runtime into the f_runtime file (make it occur before %header section) + Swig_insert_file("director_common.swg", f_runtime); Swig_insert_file("director.swg", f_runtime); } // Generate the intermediary class { - String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), imclass_name); - File *f_im = NewFile(filen, "w", SWIG_output_files()); - if (!f_im) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Append(filenames_list, Copy(filen)); - Delete(filen); - filen = NULL; - - // Start writing out the intermediary class file - emitBanner(f_im); + File *f_im = getOutputFile(SWIG_output_directory(), imclass_name); addOpenNamespace(0, f_im); @@ -461,23 +472,14 @@ class CSHARP:public Language { Printf(f_im, "}\n"); addCloseNamespace(0, f_im); - Delete(f_im); + if (f_im != f_single_out) + Delete(f_im); + f_im = NULL; } // Generate the C# module class { - String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), module_class_name); - File *f_module = NewFile(filen, "w", SWIG_output_files()); - if (!f_module) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Append(filenames_list, Copy(filen)); - Delete(filen); - filen = NULL; - - // Start writing out the module class file - emitBanner(f_module); + File *f_module = getOutputFile(SWIG_output_directory(), module_class_name); addOpenNamespace(0, f_module); @@ -513,7 +515,9 @@ class CSHARP:public Language { Printf(f_module, "}\n"); addCloseNamespace(0, f_module); - Delete(f_module); + if (f_module != f_single_out) + Delete(f_module); + f_module = NULL; } if (upcasts_code) @@ -612,6 +616,12 @@ class CSHARP:public Language { f_directors_h = NULL; } + if (f_single_out) { + Dump(f_single_out, f_begin); + Delete(f_single_out); + f_single_out = NULL; + } + Dump(f_wrappers, f_begin); Wrapper_pretty_print(f_init, f_begin); Delete(f_header); @@ -634,6 +644,50 @@ class CSHARP:public Language { Printf(f, "//------------------------------------------------------------------------------\n\n"); } + /* ----------------------------------------------------------------------------- + * getOutputFile() + * + * Prepares a File object by creating the file in the file system and + * writing the banner for auto-generated files to it (emitBanner). + * If '-outfile' is provided (single file mode) the supplied parameters will + * be ignored and the returned file will always be: + * / + * Otherwise the file will be: + *

    /.cs + * ----------------------------------------------------------------------------- */ + + File *getOutputFile(const String *dir, const String *name) { + if (output_file) { + if (!f_single_out) { + String *filen = NewStringf("%s%s", SWIG_output_directory(), output_file); + f_single_out = NewFile(filen, "w", SWIG_output_files()); + if (!f_single_out) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); + } + Append(filenames_list, Copy(filen)); + Delete(filen); + filen = NULL; + + emitBanner(f_single_out); + } + return f_single_out; + } else { + String *filen = NewStringf("%s%s.cs", dir, name); + File *f = NewFile(filen, "w", SWIG_output_files()); + if (!f) { + FileErrorDisplay(f); + SWIG_exit(EXIT_FAILURE); + } + Append(filenames_list, Copy(filen)); + Delete(filen); + filen = NULL; + + emitBanner(f); + return f; + } + } + /*----------------------------------------------------------------------- * Add new director upcall signature *----------------------------------------------------------------------*/ @@ -1085,7 +1139,7 @@ class CSHARP:public Language { scope = NewString(""); if (nspace) Printf(scope, "%s", nspace); - if (Node* cls = getCurrentClass()) { + if (Node *cls = getCurrentClass()) { if (Node *outer = Getattr(cls, "nested:outer")) { String *outerClassesPrefix = Copy(Getattr(outer, "sym:name")); for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { @@ -1197,18 +1251,7 @@ class CSHARP:public Language { } else { // Global enums are defined in their own file String *output_directory = outputDirectory(nspace); - String *filen = NewStringf("%s%s.cs", output_directory, symname); - File *f_enum = NewFile(filen, "w", SWIG_output_files()); - if (!f_enum) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Append(filenames_list, Copy(filen)); - Delete(filen); - filen = NULL; - - // Start writing out the enum file - emitBanner(f_enum); + File *f_enum = getOutputFile(output_directory, symname); addOpenNamespace(nspace, f_enum); @@ -1216,7 +1259,9 @@ class CSHARP:public Language { "\n", enum_code, "\n", NIL); addCloseNamespace(nspace, f_enum); - Delete(f_enum); + if (f_enum != f_single_out) + Delete(f_enum); + f_enum = NULL; Delete(output_directory); } } else { @@ -1641,7 +1686,7 @@ class CSHARP:public Language { String *proxyclassname = Getattr(n, "classtypeobj"); String *baseclassname = Getattr(base.item, "name"); Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", SwigType_namestr(proxyclassname), SwigType_namestr(baseclassname)); + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", SwigType_namestr(proxyclassname), SwigType_namestr(baseclassname)); base = Next(base); } } @@ -1816,8 +1861,8 @@ class CSHARP:public Language { // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { - String *smartptr = Getattr(n, "feature:smartptr"); - String *upcast_method = Swig_name_member(getNSpace(), getClassPrefix(), smartptr != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast"); + SwigType *smart = Swig_cparse_smartptr(n); + String *upcast_method = Swig_name_member(getNSpace(), getClassPrefix(), smart != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast"); String *wname = Swig_name_wrapper(upcast_method); Printv(imclass_cppcasts_code, "\n [global::System.Runtime.InteropServices.DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); @@ -1825,29 +1870,22 @@ class CSHARP:public Language { Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name); - if (smartptr) { - SwigType *spt = Swig_cparse_type(smartptr); - if (spt) { - SwigType *smart = SwigType_typedef_resolve_all(spt); - Delete(spt); - SwigType *bsmart = Copy(smart); - SwigType *rclassname = SwigType_typedef_resolve_all(c_classname); - SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass); - Replaceall(bsmart, rclassname, rbaseclass); - Delete(rclassname); - Delete(rbaseclass); - String *smartnamestr = SwigType_namestr(smart); - String *bsmartnamestr = SwigType_namestr(bsmart); - Printv(upcasts_code, - "SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", wname, "(", smartnamestr, " *jarg1) {\n", - " return jarg1 ? new ", bsmartnamestr, "(*jarg1) : 0;\n" - "}\n", "\n", NIL); - Delete(bsmartnamestr); - Delete(smartnamestr); - Delete(bsmart); - } else { - Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, c_classname); - } + if (smart) { + SwigType *bsmart = Copy(smart); + SwigType *rclassname = SwigType_typedef_resolve_all(c_classname); + SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass); + Replaceall(bsmart, rclassname, rbaseclass); + Delete(rclassname); + Delete(rbaseclass); + String *smartnamestr = SwigType_namestr(smart); + String *bsmartnamestr = SwigType_namestr(bsmart); + Printv(upcasts_code, + "SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", wname, "(", smartnamestr, " *jarg1) {\n", + " return jarg1 ? new ", bsmartnamestr, "(*jarg1) : 0;\n" + "}\n", "\n", NIL); + Delete(bsmartnamestr); + Delete(smartnamestr); + Delete(bsmart); } else { Printv(upcasts_code, "SWIGEXPORT ", c_baseclass, " * SWIGSTDCALL ", wname, "(", c_classname, " *jarg1) {\n", @@ -1856,6 +1894,7 @@ class CSHARP:public Language { } Delete(wname); Delete(upcast_method); + Delete(smart); } Delete(baseclass); } @@ -1916,21 +1955,9 @@ class CSHARP:public Language { } } - // Each outer proxy class goes into a separate file if (!has_outerclass) { String *output_directory = outputDirectory(nspace); - String *filen = NewStringf("%s%s.cs", output_directory, proxy_class_name); - f_proxy = NewFile(filen, "w", SWIG_output_files()); - if (!f_proxy) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Append(filenames_list, Copy(filen)); - Delete(filen); - filen = NULL; - - // Start writing out the proxy class file - emitBanner(f_proxy); + f_proxy = getOutputFile(output_directory, proxy_class_name); addOpenNamespace(nspace, f_proxy); } @@ -1990,7 +2017,8 @@ class CSHARP:public Language { if (!has_outerclass) { Printf(f_proxy, "}\n"); addCloseNamespace(nspace, f_proxy); - Delete(f_proxy); + if (f_proxy != f_single_out) + Delete(f_proxy); f_proxy = NULL; } else { for (int i = 0; i < nesting_depth; ++i) @@ -2003,7 +2031,7 @@ class CSHARP:public Language { good place to put this code, since Abstract Base Classes (ABCs) can and should have downcasts, making the constructorHandler() a bad place (because ABCs don't get to have constructors emitted.) */ - if (GetFlag(n, "feature:javadowncast")) { + if (GetFlag(n, "feature:csdowncast")) { String *downcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGDowncast"); String *wname = Swig_name_wrapper(downcast_method); @@ -3215,18 +3243,7 @@ class CSHARP:public Language { Setline(n, line_number); String *swigtype = NewString(""); - String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), classname); - File *f_swigtype = NewFile(filen, "w", SWIG_output_files()); - if (!f_swigtype) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Append(filenames_list, Copy(filen)); - Delete(filen); - filen = NULL; - - // Start writing out the type wrapper class file - emitBanner(f_swigtype); + File *f_swigtype = getOutputFile(SWIG_output_directory(), classname); addOpenNamespace(0, f_swigtype); @@ -3261,8 +3278,9 @@ class CSHARP:public Language { Printv(f_swigtype, swigtype, NIL); addCloseNamespace(0, f_swigtype); - - Delete(f_swigtype); + if (f_swigtype != f_single_out) + Delete(f_swigtype); + f_swigtype = NULL; Delete(swigtype); Delete(n); } @@ -3358,7 +3376,7 @@ class CSHARP:public Language { /* ----------------------------------------------------------------------------- * outputDirectory() * - * Return the directory to use for generating Java classes/enums and create the + * Return the directory to use for generating C# classes/enums and create the * subdirectory (does not create if language specific outdir does not exist). * ----------------------------------------------------------------------------- */ @@ -3452,7 +3470,7 @@ class CSHARP:public Language { Wrapper *code_wrap = NewWrapper(); Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname); - if (Len(smartptr)) { + if (smartptr) { Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", smartptr, smartptr); Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n"); Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n"); @@ -3498,7 +3516,7 @@ class CSHARP:public Language { * classDirectorMethod() * * Emit a virtual director method to pass a method call on to the - * underlying Java object. + * underlying C# object. * * --------------------------------------------------------------- */ @@ -3659,7 +3677,7 @@ class CSHARP:public Language { if (!ignored_method) Printf(w->code, "} else {\n"); - /* Go through argument list, convert from native to Java */ + /* Go through argument list, convert from native to C# */ for (i = 0, p = l; p; ++i) { /* Is this superfluous? */ while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { @@ -4284,4 +4302,5 @@ C# Options (available with -csharp)\n\ -noproxy - Generate the low-level functional interface instead\n\ of proxy classes\n\ -oldvarnames - Old intermediary method names for variable wrappers\n\ + -outfile - Write all C# into a single located in the output directory\n\ \n"; diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 8546372ea98..5fc21ad1823 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -472,8 +472,7 @@ class D : public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGD\n"); + Printf(f_runtime, "\n\n#ifndef SWIGD\n#define SWIGD\n#endif\n\n"); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); @@ -508,6 +507,7 @@ class D : public Language { if (directorsEnabled()) { // Insert director runtime into the f_runtime file (before %header section). + Swig_insert_file("director_common.swg", f_runtime); Swig_insert_file("director.swg", f_runtime); } @@ -3328,45 +3328,33 @@ class D : public Language { /* --------------------------------------------------------------------------- * D::writeClassUpcast() * --------------------------------------------------------------------------- */ - void writeClassUpcast(Node *n, const String* d_class_name, - String* c_class_name, String* c_base_name) { - - String *smartptr = Getattr(n, "feature:smartptr"); - String *upcast_name = Swig_name_member(getNSpace(), d_class_name, - (smartptr != 0 ? "SmartPtrUpcast" : "Upcast")); + void writeClassUpcast(Node *n, const String* d_class_name, String* c_class_name, String* c_base_name) { + SwigType *smart = Swig_cparse_smartptr(n); + String *upcast_name = Swig_name_member(getNSpace(), d_class_name, (smart != 0 ? "SmartPtrUpcast" : "Upcast")); String *upcast_wrapper_name = Swig_name_wrapper(upcast_name); writeImDModuleFunction(upcast_name, "void*", "(void* objectRef)", upcast_wrapper_name); - if (smartptr) { - SwigType *spt = Swig_cparse_type(smartptr); - if (spt) { - SwigType *smart = SwigType_typedef_resolve_all(spt); - Delete(spt); - SwigType *bsmart = Copy(smart); - SwigType *rclassname = SwigType_typedef_resolve_all(c_class_name); - SwigType *rbaseclass = SwigType_typedef_resolve_all(c_base_name); - Replaceall(bsmart, rclassname, rbaseclass); - Delete(rclassname); - Delete(rbaseclass); - String *smartnamestr = SwigType_namestr(smart); - String *bsmartnamestr = SwigType_namestr(bsmart); - Printv(upcasts_code, - "SWIGEXPORT ", bsmartnamestr, " * ", upcast_wrapper_name, - "(", smartnamestr, " *objectRef) {\n", - " return objectRef ? new ", bsmartnamestr, "(*objectRef) : 0;\n" - "}\n", - "\n", NIL); - Delete(bsmartnamestr); - Delete(smartnamestr); - Delete(bsmart); - } else { - Swig_error(Getfile(n), Getline(n), - "Invalid type (%s) in 'smartptr' feature for class %s.\n", - smartptr, c_class_name); - } + if (smart) { + SwigType *bsmart = Copy(smart); + SwigType *rclassname = SwigType_typedef_resolve_all(c_class_name); + SwigType *rbaseclass = SwigType_typedef_resolve_all(c_base_name); + Replaceall(bsmart, rclassname, rbaseclass); + Delete(rclassname); + Delete(rbaseclass); + String *smartnamestr = SwigType_namestr(smart); + String *bsmartnamestr = SwigType_namestr(bsmart); + Printv(upcasts_code, + "SWIGEXPORT ", bsmartnamestr, " * ", upcast_wrapper_name, + "(", smartnamestr, " *objectRef) {\n", + " return objectRef ? new ", bsmartnamestr, "(*objectRef) : 0;\n" + "}\n", + "\n", NIL); + Delete(bsmartnamestr); + Delete(smartnamestr); + Delete(bsmart); } else { Printv(upcasts_code, "SWIGEXPORT ", c_base_name, " * ", upcast_wrapper_name, @@ -3381,6 +3369,7 @@ class D : public Language { Delete(upcast_name); Delete(upcast_wrapper_name); + Delete(smart); } /* --------------------------------------------------------------------------- diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index eac83a5a550..002247fe532 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -11,6 +11,103 @@ #include "cparse.h" #include +/* ---------------------------------------------------------------------- + * siphash() + * + * 64-bit SipHash-2-4 to generate unique id for each module + * ---------------------------------------------------------------------- */ + +// An unsigned 64-bit integer that works on a 32-bit host. +typedef struct { + // Assume unsigned long is at least 32 bits. + unsigned long hi; + unsigned long lo; +} swig_uint64; + +// Rotate v left by bits, which must be <= 32. +static inline void _rotl(swig_uint64 *v, int bits) { + assert(bits <= 32); + unsigned long tmp = v->hi; + if (bits == 32) { + v->hi = v->lo; + v->lo = tmp; + } else { + v->hi = (tmp << bits) | ((0xfffffffful & v->lo) >> (32 - bits)); + v->lo = (v->lo << bits) | ((0xfffffffful & tmp) >> (32 - bits)); + } +} + +// dst ^= src +static inline void _xor(swig_uint64 *dst, swig_uint64 *src) { + dst->lo ^= src->lo; + dst->hi ^= src->hi; +} + +// dst += src +static inline void _add(swig_uint64 *dst, swig_uint64 *src) { + dst->lo += src->lo; + dst->hi += src->hi + ((dst->lo & 0xfffffffful) < (src->lo&0xfffffffful) ? 1 : 0); +} +#define SIPROUND \ + do { \ + _add(&v0, &v1); _rotl(&v1, 13); _xor(&v1, &v0); _rotl(&v0, 32); \ + _add(&v2, &v3); _rotl(&v3, 16); _xor(&v3, &v2); \ + _add(&v0, &v3); _rotl(&v3, 21); _xor(&v3, &v0); \ + _add(&v2, &v1); _rotl(&v1, 17); _xor(&v1, &v2); _rotl(&v2, 32); \ + } while(0) + +// Set out to the hash of inc/inlen. +static void siphash(swig_uint64 *out, const char *inc, unsigned long inlen) { + /* "somepseudorandomlygeneratedbytes" */ + swig_uint64 v0 = {0x736f6d65UL, 0x70736575UL}; + swig_uint64 v1 = {0x646f7261UL, 0x6e646f6dUL}; + swig_uint64 v2 = {0x6c796765UL, 0x6e657261UL}; + swig_uint64 v3 = {0x74656462UL, 0x79746573UL}; + swig_uint64 b; + /* hard-coded k. */ + swig_uint64 k0 = {0x07060504UL, 0x03020100UL}; + swig_uint64 k1 = {0x0F0E0D0CUL, 0x0B0A0908UL}; + int i; + const int cROUNDS = 2, dROUNDS = 4; + const unsigned char *in = (const unsigned char *)inc; + const unsigned char *end = in + inlen - (inlen % 8); + int left = inlen & 7; + _xor(&v3, &k1); _xor(&v2, &k0); _xor(&v1, &k1); _xor(&v0, &k0); + for (; in != end; in += 8) { + b.hi = 0; b.lo = 0; + for (i = 0; i < 4; i++) { + b.lo |= ((unsigned long)in[i]) << (8*i); + } + for (i = 0; i < 4; i++) { + b.hi |= ((unsigned long)in[i+4]) << (8*i); + } + _xor(&v3, &b); + for (i = 0; i < cROUNDS; i++) { + SIPROUND; + } + _xor(&v0, &b); + } + b.hi = (inlen & 0xff)<<24; b.lo = 0; + for (; left; left--) { + if (left > 4) { + b.hi |= ((unsigned long)in[left-1]) << (8*left-8-32); + } else { + b.lo |= ((unsigned long)in[left-1]) << (8*left-8); + } + } + _xor(&v3, &b); + for(i=0; ilo = 0; out->hi = 0; + _xor(out, &v0); _xor(out, &v1); _xor(out, &v2); _xor(out, &v3); +} +#undef SIPROUND + class GO:public Language { static const char *const usage; @@ -18,6 +115,8 @@ class GO:public Language { String *package; // SWIG module name. String *module; + // Flag for generating cgo input files. + bool cgo_flag; // Flag for generating gccgo output. bool gccgo_flag; // Prefix to use with gccgo. @@ -49,9 +148,12 @@ class GO:public Language { File *f_go_runtime; File *f_go_header; File *f_go_wrappers; + File *f_go_directors; File *f_gc_runtime; File *f_gc_header; File *f_gc_wrappers; + File *f_cgo_comment; + File *f_cgo_comment_typedefs; // True if we imported a module. bool saw_import; @@ -91,10 +193,13 @@ class GO:public Language { // A hash table of all the go_imports already imported. The index is a full // import name e.g. '"runtime"' or '_ "runtime/cgo"' or 'sc "syscall"'. Hash *go_imports; + // A unique ID used to make public symbols unique. + String *unique_id; public: GO():package(NULL), module(NULL), + cgo_flag(false), gccgo_flag(false), go_prefix(NULL), prefix_option(NULL), @@ -115,9 +220,12 @@ class GO:public Language { f_go_runtime(NULL), f_go_header(NULL), f_go_wrappers(NULL), + f_go_directors(NULL), f_gc_runtime(NULL), f_gc_header(NULL), f_gc_wrappers(NULL), + f_cgo_comment(NULL), + f_cgo_comment_typedefs(NULL), saw_import(false), imported_package(NULL), interfaces(NULL), @@ -130,7 +238,8 @@ class GO:public Language { undefined_enum_types(NULL), undefined_types(NULL), defined_types(NULL), - go_imports(NULL) { + go_imports(NULL), + unique_id(NULL) { director_multiple_inheritance = 1; director_language = 1; director_prot_ctor_code = NewString("_swig_gopanic(\"accessing abstract class or protected constructor\");"); @@ -157,6 +266,9 @@ class GO:public Language { } else { Swig_arg_error(); } + } else if (strcmp(argv[i], "-cgo") == 0) { + Swig_mark_arg(i); + cgo_flag = true; } else if (strcmp(argv[i], "-gccgo") == 0) { Swig_mark_arg(i); gccgo_flag = true; @@ -226,6 +338,10 @@ class GO:public Language { // Add preprocessor symbol to parser. Preprocessor_define("SWIGGO 1", 0); + if (cgo_flag) { + Preprocessor_define("SWIGGO_CGO 1", 0); + } + if (gccgo_flag) { Preprocessor_define("SWIGGO_GCCGO 1", 0); } @@ -314,7 +430,7 @@ class GO:public Language { } if (!pkgpath_option) { Append(go_prefix, "."); - Append(go_prefix, package); + Append(go_prefix, getModuleName(package)); } } @@ -333,6 +449,20 @@ class GO:public Language { Printf(gc_filename, "%s%s_gc.c", SWIG_output_directory(), module); } + // Generate a unique ID based on a hash of the SWIG input. + swig_uint64 hash = {0, 0}; + FILE *swig_input = Swig_open(swig_filename); + if (swig_input == NULL) { + FileErrorDisplay(swig_filename); + SWIG_exit(EXIT_FAILURE); + } + String *swig_input_content = Swig_read_file(swig_input); + siphash(&hash, Char(swig_input_content), Len(swig_input_content)); + Delete(swig_input_content); + fclose(swig_input); + unique_id = NewString(""); + Printf(unique_id, "_%s_%08x%08x", getModuleName(package), hash.hi, hash.lo); + // Open files. f_c_begin = NewFile(c_filename, "w", SWIG_output_files()); @@ -359,7 +489,7 @@ class GO:public Language { SWIG_exit(EXIT_FAILURE); } - if (!gccgo_flag) { + if (!gccgo_flag && !cgo_flag) { f_gc_begin = NewFile(gc_filename, "w", SWIG_output_files()); if (!f_gc_begin) { FileErrorDisplay(gc_filename); @@ -376,11 +506,16 @@ class GO:public Language { f_go_runtime = NewString(""); f_go_header = NewString(""); f_go_wrappers = NewString(""); - if (!gccgo_flag) { + f_go_directors = NewString(""); + if (!gccgo_flag && !cgo_flag) { f_gc_runtime = NewString(""); f_gc_header = NewString(""); f_gc_wrappers = NewString(""); } + if (cgo_flag) { + f_cgo_comment = NewString(""); + f_cgo_comment_typedefs = NewString(""); + } Swig_register_filebyname("begin", f_c_begin); Swig_register_filebyname("runtime", f_c_runtime); @@ -394,12 +529,17 @@ class GO:public Language { Swig_register_filebyname("go_runtime", f_go_runtime); Swig_register_filebyname("go_header", f_go_header); Swig_register_filebyname("go_wrapper", f_go_wrappers); - if (!gccgo_flag) { + Swig_register_filebyname("go_director", f_go_directors); + if (!gccgo_flag && !cgo_flag) { Swig_register_filebyname("gc_begin", f_gc_begin); Swig_register_filebyname("gc_runtime", f_gc_runtime); Swig_register_filebyname("gc_header", f_gc_header); Swig_register_filebyname("gc_wrapper", f_gc_wrappers); } + if (cgo_flag) { + Swig_register_filebyname("cgo_comment", f_cgo_comment); + Swig_register_filebyname("cgo_comment_typedefs", f_cgo_comment_typedefs); + } Swig_banner(f_c_begin); if (CPlusPlus) { @@ -421,6 +561,7 @@ class GO:public Language { Printf(f_c_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module); Printf(f_c_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module); + Printf(f_c_directors_h, "class Swig_memory;\n\n"); Printf(f_c_directors, "\n// C++ director class methods.\n"); String *filename = Swig_file_filename(c_filename_h); @@ -431,18 +572,28 @@ class GO:public Language { Swig_banner(f_go_begin); Printf(f_go_begin, "\n// source: %s\n", swig_filename); - if (!gccgo_flag && soname) { + if (!gccgo_flag && !cgo_flag && soname) { Swig_banner(f_gc_begin); Printf(f_gc_begin, "\n/* source: %s */\n\n", swig_filename); Printf(f_gc_begin, "\n/* This file should be compiled with 6c/8c. */\n"); Printf(f_gc_begin, "#pragma dynimport _ _ \"%s\"\n", soname); } + if (cgo_flag) { + Printv(f_cgo_comment_typedefs, "/*\n", NULL); + + // The cgo program defines the intgo type after our function + // definitions, but we want those definitions to be able to use + // intgo also. + Printv(f_cgo_comment_typedefs, "#define intgo swig_intgo\n", NULL); + Printv(f_cgo_comment_typedefs, "typedef void *swig_voidp;\n", NULL); + } + // Output module initialization code. - Printf(f_go_begin, "\npackage %s\n\n", package); + Printf(f_go_begin, "\npackage %s\n\n", getModuleName(package)); - if (gccgo_flag) { + if (gccgo_flag && !cgo_flag) { Printf(f_go_runtime, "func SwigCgocall()\n"); Printf(f_go_runtime, "func SwigCgocallDone()\n"); Printf(f_go_runtime, "func SwigCgocallBack()\n"); @@ -514,14 +665,29 @@ class GO:public Language { // End the extern "C". Printv(f_c_wrappers, "#ifdef __cplusplus\n", "}\n", "#endif\n\n", NULL); + if (cgo_flag) { + // End the cgo comment. + Printv(f_cgo_comment, "#undef intgo\n", NULL); + Printv(f_cgo_comment, "*/\n", NULL); + Printv(f_cgo_comment, "import \"C\"\n", NULL); + Printv(f_cgo_comment, "\n", NULL); + } + Dump(f_c_runtime, f_c_begin); Dump(f_c_wrappers, f_c_begin); Dump(f_c_init, f_c_begin); + if (cgo_flag) { + Dump(f_cgo_comment_typedefs, f_go_begin); + Dump(f_cgo_comment, f_go_begin); + } Dump(f_go_imports, f_go_begin); Dump(f_go_header, f_go_begin); Dump(f_go_runtime, f_go_begin); Dump(f_go_wrappers, f_go_begin); - if (!gccgo_flag) { + if (directorsEnabled()) { + Dump(f_go_directors, f_go_begin); + } + if (!gccgo_flag && !cgo_flag) { Dump(f_gc_header, f_gc_begin); Dump(f_gc_runtime, f_gc_begin); Dump(f_gc_wrappers, f_gc_begin); @@ -535,15 +701,20 @@ class GO:public Language { Delete(f_go_runtime); Delete(f_go_header); Delete(f_go_wrappers); - if (!gccgo_flag) { + Delete(f_go_directors); + if (!gccgo_flag && !cgo_flag) { Delete(f_gc_runtime); Delete(f_gc_header); Delete(f_gc_wrappers); } + if (cgo_flag) { + Delete(f_cgo_comment); + Delete(f_cgo_comment_typedefs); + } Delete(f_c_begin); Delete(f_go_begin); - if (!gccgo_flag) { + if (!gccgo_flag && !cgo_flag) { Delete(f_gc_begin); } @@ -614,6 +785,13 @@ class GO:public Language { return SWIG_OK; } + // Don't emit constructors for abstract director classes. They + // will never succeed anyhow. + if (Swig_methodclass(n) && Swig_directorclass(n) + && Strcmp(Char(Getattr(n, "wrap:action")), director_prot_ctor_code) == 0) { + return SWIG_OK; + } + String *name = Getattr(n, "sym:name"); String *nodetype = Getattr(n, "nodeType"); bool is_static = is_static_member_function || isStatic(n); @@ -677,8 +855,7 @@ class GO:public Language { Delete(c2); Delete(c1); - if (Swig_methodclass(n) && Swig_directorclass(n) - && Strcmp(Char(Getattr(n, "wrap:action")), director_prot_ctor_code) != 0) { + if (Swig_methodclass(n) && Swig_directorclass(n)) { // The core SWIG code skips the first parameter when // generating the $nondirector_new string. Recreate the // action in this case. But don't it if we are using the @@ -744,6 +921,7 @@ class GO:public Language { if (overname) { Append(wname, overname); } + Append(wname, unique_id); Setattr(n, "wrap:name", wname); ParmList *parms = Getattr(n, "parms"); @@ -822,24 +1000,33 @@ class GO:public Language { assert(result); - int r = goFunctionWrapper(n, name, go_name, overname, wname, base, parms, result, is_static); - if (r != SWIG_OK) { - return r; - } + int ret = SWIG_OK; - if (!gccgo_flag) { - r = gcFunctionWrapper(wname); - if (r != SWIG_OK) { - return r; - } - r = gccFunctionWrapper(n, base, wname, parms, result); + if (cgo_flag) { + int r = makeCgoWrappers(n, go_name, overname, wname, base, parms, result, is_static); if (r != SWIG_OK) { - return r; + ret = r; } } else { - r = gccgoFunctionWrapper(n, base, wname, parms, result); + int r = goFunctionWrapper(n, name, go_name, overname, wname, base, parms, result, is_static); if (r != SWIG_OK) { - return r; + ret = r; + } + + if (!gccgo_flag) { + r = gcFunctionWrapper(wname); + if (r != SWIG_OK) { + ret = r; + } + r = gccFunctionWrapper(n, base, wname, parms, result); + if (r != SWIG_OK) { + ret = r; + } + } else { + r = gccgoFunctionWrapper(n, base, wname, parms, result); + if (r != SWIG_OK) { + ret = r; + } } } @@ -847,204 +1034,136 @@ class GO:public Language { Setattr(class_methods, Getattr(n, "name"), NewString("")); } - return SWIG_OK; + return ret; } /* ---------------------------------------------------------------------- - * goFunctionWrapper() + * struct cgoWrapperInfo * - * Write out a function wrapper in Go. When not implementing a - * method, the actual code is all in C; here we just declare the C - * function. When implementing a method, we have to call the C - * function, because it will have a different name. If base is not - * NULL, then we are being called to forward a virtual method to a - * base class. + * Information needed by the CGO wrapper functions. * ---------------------------------------------------------------------- */ - int goFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { - Wrapper *dummy = NewWrapper(); - emit_attach_parmmaps(parms, dummy); + struct cgoWrapperInfo { + // The function we are generating code for. + Node *n; + // The name of the Go function. + String *go_name; + // The overload string for an overloaded function. + String *overname; + // The name of the C wrapper function. + String *wname; + // The base classes. + List *base; + // The parameters. + ParmList *parms; + // The result type. + SwigType *result; + // Whether this is a static function, not a class method. + bool is_static; + // The Go receiver type. + String *receiver; + // Whether this is a class constructor. + bool is_constructor; + // Whether this is a class destructor. + bool is_destructor; + }; - Parm *p = parms; - int parm_count = emit_num_arguments(parms); - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - Swig_cparm_name(p, i); - p = nextParm(p); - } + /* ---------------------------------------------------------------------- + * makeCgoWrappers() + * + * Write out the wrappers for a function when producing cgo input + * files. + * ---------------------------------------------------------------------- */ - Swig_typemap_attach_parms("default", parms, dummy); - Swig_typemap_attach_parms("gotype", parms, dummy); - Swig_typemap_attach_parms("goin", parms, dummy); - Swig_typemap_attach_parms("goargout", parms, dummy); - Swig_typemap_attach_parms("imtype", parms, dummy); + int makeCgoWrappers(Node *n, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { + Swig_save("makeCgoWrappers", n, "emit:cgotype", "emit:cgotypestruct", NULL); - int required_count = emit_num_required(parms); + cgoWrapperInfo info; - String *receiver = class_receiver; - if (receiver && is_static) { - receiver = NULL; + info.n = n; + info.go_name = go_name; + info.overname = overname; + info.wname = wname; + info.base = base; + info.parms = parms; + info.result = result; + info.is_static = is_static; + + info.receiver = class_receiver; + if (is_static) { + info.receiver = NULL; } String *nodetype = Getattr(n, "nodeType"); - bool is_constructor = Cmp(nodetype, "constructor") == 0; - bool is_destructor = Cmp(nodetype, "destructor") == 0; - if (is_constructor || is_destructor) { + info.is_constructor = Cmp(nodetype, "constructor") == 0; + info.is_destructor = Cmp(nodetype, "destructor") == 0; + if (info.is_constructor || info.is_destructor) { assert(class_receiver); assert(!base); - receiver = NULL; + info.receiver = NULL; } - String *goout = Swig_typemap_lookup("goout", n, "swig_r", NULL); - - bool add_to_interface = (interfaces && !is_constructor && !is_destructor && !is_static && !overname && checkFunctionVisibility(n, NULL)); - - bool needs_wrapper = (gccgo_flag || receiver || is_constructor || is_destructor || parm_count > required_count); + int ret = SWIG_OK; - bool has_goout = false; - if (goout) { - has_goout = true; + int r = cgoGoWrapper(&info); + if (r != SWIG_OK) { + ret = r; } - // See whether any of the function parameters are represented by - // interface values. When calling the C++ code, we need to convert - // back to a uintptr. - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *ty = Getattr(p, "type"); - if (Getattr(p, "tmap:goargout")) { - has_goout = true; - needs_wrapper = true; - } else if (goTypeIsInterface(p, ty) || Getattr(p, "tmap:goin")) { - needs_wrapper = true; - } - - if (paramNeedsEscape(p)) { - needs_wrapper = true; - } - - p = nextParm(p); - } - if (goTypeIsInterface(n, result) || goout != NULL) { - needs_wrapper = true; + r = cgoCommentWrapper(&info); + if (r != SWIG_OK) { + ret = r; } - if (!gccgo_flag) { - Printv(f_go_wrappers, "var ", wname, " unsafe.Pointer\n\n", NULL); + r = cgoGccWrapper(&info); + if (r != SWIG_OK) { + ret = r; } - // If this is a method, first declare the C function we will call. - // If we do not need a wrapper, then we will only be writing a - // declaration. - String *wrapper_name = NULL; - if (needs_wrapper) { - wrapper_name = buildGoWrapperName(name, overname); - - if (gccgo_flag) { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); - } - - bool arg = false; - Printv(f_go_wrappers, "func ", wrapper_name, "(", NULL); - if (parm_count > required_count) { - Printv(f_go_wrappers, argName(&arg), " int", NULL); - } - Parm *p = getParm(parms); - int i = 0; - if (is_destructor) { - if (parm_count > required_count) { - Printv(f_go_wrappers, ", ", NULL); - } - Printv(f_go_wrappers, argName(&arg), " uintptr", NULL); - ++i; - p = nextParm(p); - } else if (receiver && (base || !is_constructor)) { - if (parm_count > required_count) { - Printv(f_go_wrappers, ", ", NULL); - } - Printv(f_go_wrappers, argName(&arg), " ", receiver, NULL); - if (!base) { - ++i; - p = nextParm(p); - } - } - for (; i < parm_count; ++i) { - p = getParm(p); - if (i > 0 || (base && receiver) || parm_count > required_count) { - Printv(f_go_wrappers, ", ", NULL); - } - String *tm = goWrapperType(p, Getattr(p, "type"), false); - Printv(f_go_wrappers, argName(&arg), " ", tm, NULL); - Delete(tm); - p = nextParm(p); - } - Printv(f_go_wrappers, ")", NULL); - if (is_constructor) { - Printv(f_go_wrappers, " (", argName(&arg), " ", class_receiver, ")", NULL); - } else { - if (SwigType_type(result) != T_VOID) { - String *tm = goWrapperType(n, result, true); - Printv(f_go_wrappers, " (", argName(&arg), " ", tm, ")", NULL); - Delete(tm); - } - } + Swig_restore(n); - if (!gccgo_flag) { - Printv(f_go_wrappers, " {\n", NULL); - if (arg) { - Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&base))\n", NULL); - } else { - Printv(f_go_wrappers, "\tvar _swig_p uintptr\n", NULL); - } - Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); - Printv(f_go_wrappers, "\treturn\n", NULL); - Printv(f_go_wrappers, "}", NULL); - } + return ret; + } - Printv(f_go_wrappers, "\n\n", NULL); - } + /* ---------------------------------------------------------------------- + * cgoGoWrapper() + * + * Write out Go code to call a cgo function. This code will go into + * the generated Go output file. + * ---------------------------------------------------------------------- */ + int cgoGoWrapper(const cgoWrapperInfo *info) { - // Start defining the Go function. + Wrapper *dummy = initGoTypemaps(info->parms); - if (!needs_wrapper && gccgo_flag) { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); - } + bool add_to_interface = interfaces && !info->is_constructor && !info->is_destructor && !info->is_static && !info->overname && checkFunctionVisibility(info->n, NULL); Printv(f_go_wrappers, "func ", NULL); - p = parms; + Parm *p = info->parms; int pi = 0; - // Add the receiver if this is a method. - String *first = NULL; - if (receiver) { + // Add the receiver first if this is a method. + if (info->receiver) { Printv(f_go_wrappers, "(", NULL); - if (base && receiver) { + if (info->base && info->receiver) { Printv(f_go_wrappers, "_swig_base", NULL); - if (first == NULL) { - first = NewString("_swig_base"); - } } else { Printv(f_go_wrappers, Getattr(p, "lname"), NULL); - if (first == NULL) { - first = Copy(Getattr(p, "lname")); - } p = nextParm(p); ++pi; } - Printv(f_go_wrappers, " ", receiver, ") ", NULL); + Printv(f_go_wrappers, " ", info->receiver, ") ", NULL); } - Printv(f_go_wrappers, go_name, NULL); - if (overname) { - Printv(f_go_wrappers, overname, NULL); + Printv(f_go_wrappers, info->go_name, NULL); + if (info->overname) { + Printv(f_go_wrappers, info->overname, NULL); } Printv(f_go_wrappers, "(", NULL); - // If we are doing methods, add this function to the interface. + // If we are doing methods, add this method to the interface. if (add_to_interface) { - Printv(interfaces, "\t", go_name, "(", NULL); + Printv(interfaces, "\t", info->go_name, "(", NULL); } // Write out the parameters to both the function definition and @@ -1052,30 +1171,27 @@ class GO:public Language { String *parm_print = NewString(""); + int parm_count = emit_num_arguments(info->parms); + int required_count = emit_num_required(info->parms); + int args = 0; + for (; pi < parm_count; ++pi) { p = getParm(p); - if (pi == 0 && is_destructor) { + if (pi == 0 && info->is_destructor) { String *cl = exportedName(class_name); Printv(parm_print, Getattr(p, "lname"), " ", cl, NULL); - if (first == NULL) { - first = Copy(Getattr(p, "lname")); - } Delete(cl); + ++args; } else { - if (pi > (receiver && !base ? 1 : 0)) { + if (args > 0) { Printv(parm_print, ", ", NULL); } + ++args; if (pi >= required_count) { Printv(parm_print, "_swig_args ...interface{}", NULL); - if (first == NULL) { - first = NewString("_swig_args"); - } break; } Printv(parm_print, Getattr(p, "lname"), " ", NULL); - if (first == NULL) { - first = Copy(Getattr(p, "lname")); - } String *tm = goType(p, Getattr(p, "type")); Printv(parm_print, tm, NULL); Delete(tm); @@ -1086,20 +1202,14 @@ class GO:public Language { Printv(parm_print, ")", NULL); // Write out the result type. - if (is_constructor) { + if (info->is_constructor) { String *cl = exportedName(class_name); Printv(parm_print, " (_swig_ret ", cl, ")", NULL); - if (first == NULL) { - first = NewString("_swig_ret"); - } Delete(cl); } else { - if (SwigType_type(result) != T_VOID) { - String *tm = goType(n, result); + if (SwigType_type(info->result) != T_VOID) { + String *tm = goType(info->n, info->result); Printv(parm_print, " (_swig_ret ", tm, ")", NULL); - if (first == NULL) { - first = NewString("_swig_ret"); - } Delete(tm); } } @@ -1109,17 +1219,630 @@ class GO:public Language { Printv(interfaces, parm_print, "\n", NULL); } - // If this is a wrapper, we need to actually call the C function. - if (needs_wrapper) { - Printv(f_go_wrappers, " {\n", NULL); + // Write out the function body. - if (parm_count > required_count) { - Parm *p = parms; - int i; - for (i = 0; i < required_count; ++i) { - p = getParm(p); - p = nextParm(p); - } + Printv(f_go_wrappers, " {\n", NULL); + + if (parm_count > required_count) { + Parm *p = info->parms; + int i; + for (i = 0; i < required_count; ++i) { + p = getParm(p); + p = nextParm(p); + } + for (; i < parm_count; ++i) { + p = getParm(p); + String *tm = goType(p, Getattr(p, "type")); + Printv(f_go_wrappers, "\tvar ", Getattr(p, "lname"), " ", tm, "\n", NULL); + Printf(f_go_wrappers, "\tif len(_swig_args) > %d {\n", i - required_count); + Printf(f_go_wrappers, "\t\t%s = _swig_args[%d].(%s)\n", Getattr(p, "lname"), i - required_count, tm); + Printv(f_go_wrappers, "\t}\n", NULL); + Delete(tm); + p = nextParm(p); + } + } + + String *call = NewString("\t"); + + String *ret_type = NULL; + bool memcpy_ret = false; + String *wt = NULL; + if (SwigType_type(info->result) != T_VOID) { + if (info->is_constructor) { + ret_type = exportedName(class_name); + } else { + ret_type = goImType(info->n, info->result); + } + Printv(f_go_wrappers, "\tvar swig_r ", ret_type, "\n", NULL); + + bool c_struct_type; + Delete(cgoTypeForGoValue(info->n, info->result, &c_struct_type)); + if (c_struct_type) { + memcpy_ret = true; + } + + if (memcpy_ret) { + Printv(call, "swig_r_p := ", NULL); + } else { + Printv(call, "swig_r = (", ret_type, ")(", NULL); + } + + if (info->is_constructor || goTypeIsInterface(info->n, info->result)) { + if (info->is_constructor) { + wt = Copy(class_receiver); + } else { + wt = goWrapperType(info->n, info->result, true); + } + Printv(call, wt, "(", NULL); + } + } + + Printv(call, "C.", info->wname, "(", NULL); + + args = 0; + + if (parm_count > required_count) { + Printv(call, "C.swig_intgo(len(_swig_args))", NULL); + ++args; + } + + if (info->base && info->receiver) { + if (args > 0) { + Printv(call, ", ", NULL); + } + ++args; + Printv(call, "C.uintptr_t(_swig_base)", NULL); + } + + p = info->parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + if (args > 0) { + Printv(call, ", ", NULL); + } + ++args; + + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + + String *ivar = NewStringf("_swig_i_%d", i); + + String *goin = goGetattr(p, "tmap:goin"); + if (goin == NULL) { + Printv(f_go_wrappers, "\t", ivar, " := ", ln, NULL); + if ((i == 0 && info->is_destructor) || ((i > 0 || !info->receiver || info->base || info->is_constructor) && goTypeIsInterface(p, pt))) { + Printv(f_go_wrappers, ".Swigcptr()", NULL); + } + Printv(f_go_wrappers, "\n", NULL); + Setattr(p, "emit:goinput", ln); + } else { + String *itm = goImType(p, pt); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, "\n", NULL); + goin = Copy(goin); + Replaceall(goin, "$input", ln); + Replaceall(goin, "$result", ivar); + Printv(f_go_wrappers, goin, "\n", NULL); + Delete(goin); + Setattr(p, "emit:goinput", ivar); + } + + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); + if (c_struct_type) { + Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); + } else { + Printv(call, "C.", ct, "(", ivar, ")", NULL); + } + Delete(ct); + + p = nextParm(p); + } + + Printv(f_go_wrappers, call, ")", NULL); + Delete(call); + + if (wt) { + // Close the type conversion to the wrapper type. + Printv(f_go_wrappers, ")", NULL); + } + if (SwigType_type(info->result) != T_VOID && !memcpy_ret) { + // Close the type conversion of the return value. + Printv(f_go_wrappers, ")", NULL); + } + + Printv(f_go_wrappers, "\n", NULL); + + if (memcpy_ret) { + Printv(f_go_wrappers, "\tswig_r = *(*", ret_type, ")(unsafe.Pointer(&swig_r_p))\n", NULL); + } + if (ret_type) { + Delete(ret_type); + } + + goargout(info->parms); + + if (SwigType_type(info->result) != T_VOID) { + String *goout = goTypemapLookup("goout", info->n, "swig_r"); + if (goout == NULL) { + Printv(f_go_wrappers, "\treturn swig_r\n", NULL); + } else { + String *tm = goType(info->n, info->result); + Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); + goout = Copy(goout); + Replaceall(goout, "$input", "swig_r"); + Replaceall(goout, "$result", "swig_r_1"); + Printv(f_go_wrappers, goout, "\n", NULL); + Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); + } + } + + Printv(f_go_wrappers, "}\n\n", NULL); + + DelWrapper(dummy); + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * cgoCommentWrapper() + * + * Write out a cgo function to call a C/C++ function. This code + * will go into the cgo comment in the generated Go output file. + * ---------------------------------------------------------------------- */ + int cgoCommentWrapper(const cgoWrapperInfo *info) { + String *ret_type; + if (SwigType_type(info->result) == T_VOID) { + ret_type = NewString("void"); + } else { + bool c_struct_type; + ret_type = cgoTypeForGoValue(info->n, info->result, &c_struct_type); + } + + Printv(f_cgo_comment, "extern ", ret_type, " ", info->wname, "(", NULL); + + Delete(ret_type); + + int parm_count = emit_num_arguments(info->parms); + int required_count = emit_num_required(info->parms); + int args = 0; + + if (parm_count > required_count) { + Printv(f_cgo_comment, "intgo _swig_args", NULL); + ++args; + } + + if (info->base && info->receiver) { + if (args > 0) { + Printv(f_cgo_comment, ", ", NULL); + } + ++args; + Printv(f_cgo_comment, "uintptr_t _swig_base", NULL); + } + + Parm *p = info->parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + if (args > 0) { + Printv(f_cgo_comment, ", ", NULL); + } + ++args; + + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); + Printv(f_cgo_comment, ct, " ", ln, NULL); + Delete(ct); + + p = nextParm(p); + } + + if (args == 0) { + Printv(f_cgo_comment, "void", NULL); + } + + Printv(f_cgo_comment, ");\n", NULL); + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * cgoGccWrapper() + * + * Write out code to the C/C++ wrapper file. This code will be + * called by the code generated by cgoCommentWrapper. + * ---------------------------------------------------------------------- */ + int cgoGccWrapper(const cgoWrapperInfo *info) { + Wrapper *f = NewWrapper(); + + Swig_save("cgoGccWrapper", info->n, "parms", NULL); + + ParmList *parms = info->parms; + + Parm *base_parm = NULL; + if (info->base && !isStatic(info->n)) { + SwigType *base_type = Copy(getClassType()); + SwigType_add_pointer(base_type); + base_parm = NewParm(base_type, NewString("arg1"), info->n); + set_nextSibling(base_parm, parms); + parms = base_parm; + } + + emit_parameter_variables(parms, f); + emit_attach_parmmaps(parms, f); + int parm_count = emit_num_arguments(parms); + int required_count = emit_num_required(parms); + + emit_return_variable(info->n, info->result, f); + + // Start the function definition. + + String *fnname = NewString(""); + Printv(fnname, info->wname, "(", NULL); + + int args = 0; + + if (parm_count > required_count) { + Printv(fnname, "intgo _swig_optargc", NULL); + ++args; + } + + Parm *p = parms; + for (int i = 0; i < parm_count; ++i) { + if (args > 0) { + Printv(fnname, ", ", NULL); + } + ++args; + + p = getParm(p); + + SwigType *pt = Copy(Getattr(p, "type")); + if (SwigType_isarray(pt)) { + SwigType_del_array(pt); + SwigType_add_pointer(pt); + } + String *pn = NewStringf("_swig_go_%d", i); + String *ct = gcCTypeForGoValue(p, pt, pn); + Printv(fnname, ct, NULL); + Delete(ct); + Delete(pn); + Delete(pt); + + p = nextParm(p); + } + + Printv(fnname, ")", NULL); + + if (SwigType_type(info->result) == T_VOID) { + Printv(f->def, "void ", fnname, NULL); + } else { + String *ct = gcCTypeForGoValue(info->n, info->result, fnname); + Printv(f->def, ct, NULL); + Delete(ct); + + String *ln = NewString("_swig_go_result"); + ct = gcCTypeForGoValue(info->n, info->result, ln); + Wrapper_add_local(f, "_swig_go_result", ct); + Delete(ct); + Delete(ln); + } + + Delete(fnname); + + Printv(f->def, " {\n", NULL); + + // Apply the in typemaps. + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + String *tm = Getattr(p, "tmap:in"); + if (!tm) { + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "unable to use type %s as a function argument\n", SwigType_str(Getattr(p, "type"), 0)); + } else { + tm = Copy(tm); + String *pn = NewStringf("_swig_go_%d", i); + Replaceall(tm, "$input", pn); + if (i < required_count) { + Printv(f->code, "\t", tm, "\n", NULL); + } else { + Printf(f->code, "\tif (_swig_optargc > %d) {\n", i - required_count); + Printv(f->code, "\t\t", tm, "\n", NULL); + Printv(f->code, "\t}\n", NULL); + } + Delete(tm); + Setattr(p, "emit:input", pn); + } + p = nextParm(p); + } + + Printv(f->code, "\n", NULL); + + // Do the real work of the function. + + checkConstraints(parms, f); + + emitGoAction(info->n, info->base, parms, info->result, f); + + argout(parms, f); + + cleanupFunction(info->n, f, parms); + + if (SwigType_type(info->result) != T_VOID) { + Printv(f->code, "\treturn _swig_go_result;\n", NULL); + } + + Printv(f->code, "}\n", NULL); + + Wrapper_print(f, f_c_wrappers); + + Swig_restore(info->n); + + DelWrapper(f); + if (base_parm) { + Delete(base_parm); + } + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * goFunctionWrapper() + * + * Write out a function wrapper in Go. When not implementing a + * method, the actual code is all in C; here we just declare the C + * function. When implementing a method, we have to call the C + * function, because it will have a different name. If base is not + * NULL, then we are being called to forward a virtual method to a + * base class. + * ---------------------------------------------------------------------- */ + + int goFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { + Wrapper *dummy = initGoTypemaps(parms); + + int parm_count = emit_num_arguments(parms); + int required_count = emit_num_required(parms); + + String *receiver = class_receiver; + if (receiver && is_static) { + receiver = NULL; + } + + String *nodetype = Getattr(n, "nodeType"); + bool is_constructor = Cmp(nodetype, "constructor") == 0; + bool is_destructor = Cmp(nodetype, "destructor") == 0; + if (is_constructor || is_destructor) { + assert(class_receiver); + assert(!base); + receiver = NULL; + } + + String *goout = goTypemapLookup("goout", n, "swig_r"); + + bool add_to_interface = (interfaces && !is_constructor && !is_destructor && !is_static && !overname && checkFunctionVisibility(n, NULL)); + + bool needs_wrapper = (gccgo_flag || receiver || is_constructor || is_destructor || parm_count > required_count); + + bool has_goout = false; + if (goout) { + has_goout = true; + } + + // See whether any of the function parameters are represented by + // interface values. When calling the C++ code, we need to convert + // back to a uintptr. + Parm *p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + String *ty = Getattr(p, "type"); + if (goGetattr(p, "tmap:goargout")) { + has_goout = true; + needs_wrapper = true; + } else if (goTypeIsInterface(p, ty) || goGetattr(p, "tmap:goin")) { + needs_wrapper = true; + } + + if (paramNeedsEscape(p)) { + needs_wrapper = true; + } + + p = nextParm(p); + } + if (goTypeIsInterface(n, result) || goout != NULL) { + needs_wrapper = true; + } + + if (!gccgo_flag) { + Printv(f_go_wrappers, "var ", wname, " unsafe.Pointer\n\n", NULL); + } + + // If this is a method, first declare the C function we will call. + // If we do not need a wrapper, then we will only be writing a + // declaration. + String *wrapper_name = NULL; + if (needs_wrapper) { + wrapper_name = buildGoWrapperName(name, overname); + + if (gccgo_flag) { + Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); + } + + bool arg = false; + Printv(f_go_wrappers, "func ", wrapper_name, "(", NULL); + if (parm_count > required_count) { + Printv(f_go_wrappers, argName(&arg), " int", NULL); + } + Parm *p = getParm(parms); + int i = 0; + if (is_destructor) { + if (parm_count > required_count) { + Printv(f_go_wrappers, ", ", NULL); + } + Printv(f_go_wrappers, argName(&arg), " uintptr", NULL); + ++i; + p = nextParm(p); + } else if (receiver && (base || !is_constructor)) { + if (parm_count > required_count) { + Printv(f_go_wrappers, ", ", NULL); + } + Printv(f_go_wrappers, argName(&arg), " ", receiver, NULL); + if (!base) { + ++i; + p = nextParm(p); + } + } + for (; i < parm_count; ++i) { + p = getParm(p); + if (i > 0 || (base && receiver) || parm_count > required_count) { + Printv(f_go_wrappers, ", ", NULL); + } + String *tm = goWrapperType(p, Getattr(p, "type"), false); + Printv(f_go_wrappers, argName(&arg), " ", tm, NULL); + Delete(tm); + p = nextParm(p); + } + Printv(f_go_wrappers, ")", NULL); + if (is_constructor) { + Printv(f_go_wrappers, " (", argName(&arg), " ", class_receiver, ")", NULL); + } else { + if (SwigType_type(result) != T_VOID) { + String *tm = goWrapperType(n, result, true); + Printv(f_go_wrappers, " (", argName(&arg), " ", tm, ")", NULL); + Delete(tm); + } + } + + if (!gccgo_flag) { + Printv(f_go_wrappers, " {\n", NULL); + if (arg) { + Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&base))\n", NULL); + } else { + Printv(f_go_wrappers, "\tvar _swig_p uintptr\n", NULL); + } + Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); + Printv(f_go_wrappers, "\treturn\n", NULL); + Printv(f_go_wrappers, "}", NULL); + } + + Printv(f_go_wrappers, "\n\n", NULL); + } + + // Start defining the Go function. + + if (!needs_wrapper && gccgo_flag) { + Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); + } + + Printv(f_go_wrappers, "func ", NULL); + + p = parms; + int pi = 0; + + // Add the receiver if this is a method. + String *first = NULL; + if (receiver) { + Printv(f_go_wrappers, "(", NULL); + if (base && receiver) { + Printv(f_go_wrappers, "_swig_base", NULL); + if (first == NULL) { + first = NewString("_swig_base"); + } + } else { + Printv(f_go_wrappers, Getattr(p, "lname"), NULL); + if (first == NULL) { + first = Copy(Getattr(p, "lname")); + } + p = nextParm(p); + ++pi; + } + Printv(f_go_wrappers, " ", receiver, ") ", NULL); + } + + Printv(f_go_wrappers, go_name, NULL); + if (overname) { + Printv(f_go_wrappers, overname, NULL); + } + Printv(f_go_wrappers, "(", NULL); + + // If we are doing methods, add this function to the interface. + if (add_to_interface) { + Printv(interfaces, "\t", go_name, "(", NULL); + } + + // Write out the parameters to both the function definition and + // the interface. + + String *parm_print = NewString(""); + + for (; pi < parm_count; ++pi) { + p = getParm(p); + if (pi == 0 && is_destructor) { + String *cl = exportedName(class_name); + Printv(parm_print, Getattr(p, "lname"), " ", cl, NULL); + if (first == NULL) { + first = Copy(Getattr(p, "lname")); + } + Delete(cl); + } else { + if (pi > (receiver && !base ? 1 : 0)) { + Printv(parm_print, ", ", NULL); + } + if (pi >= required_count) { + Printv(parm_print, "_swig_args ...interface{}", NULL); + if (first == NULL) { + first = NewString("_swig_args"); + } + break; + } + Printv(parm_print, Getattr(p, "lname"), " ", NULL); + if (first == NULL) { + first = Copy(Getattr(p, "lname")); + } + String *tm = goType(p, Getattr(p, "type")); + Printv(parm_print, tm, NULL); + Delete(tm); + } + p = nextParm(p); + } + + Printv(parm_print, ")", NULL); + + // Write out the result type. + if (is_constructor) { + String *cl = exportedName(class_name); + Printv(parm_print, " (_swig_ret ", cl, ")", NULL); + if (first == NULL) { + first = NewString("_swig_ret"); + } + Delete(cl); + } else { + if (SwigType_type(result) != T_VOID) { + String *tm = goType(n, result); + Printv(parm_print, " (_swig_ret ", tm, ")", NULL); + if (first == NULL) { + first = NewString("_swig_ret"); + } + Delete(tm); + } + } + + Printv(f_go_wrappers, parm_print, NULL); + if (add_to_interface) { + Printv(interfaces, parm_print, "\n", NULL); + } + + // If this is a wrapper, we need to actually call the C function. + if (needs_wrapper) { + Printv(f_go_wrappers, " {\n", NULL); + + if (parm_count > required_count) { + Parm *p = parms; + int i; + for (i = 0; i < required_count; ++i) { + p = getParm(p); + p = nextParm(p); + } for (; i < parm_count; ++i) { p = getParm(p); String *tm = goType(p, Getattr(p, "type")); @@ -1188,7 +1911,7 @@ class GO:public Language { SwigType *pt = Getattr(p, "type"); String *ln = Getattr(p, "lname"); - String *goin = Getattr(p, "tmap:goin"); + String *goin = goGetattr(p, "tmap:goin"); if (goin == NULL) { Printv(call, ln, NULL); if ((i == 0 && is_destructor) || ((i > 0 || !receiver || base || is_constructor) && goTypeIsInterface(p, pt))) { @@ -1199,11 +1922,11 @@ class GO:public Language { String *ivar = NewString(""); Printf(ivar, "_swig_i_%d", i); String *itm = goImType(p, pt); - Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, NULL); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, "\n", NULL); goin = Copy(goin); Replaceall(goin, "$input", ln); Replaceall(goin, "$result", ivar); - Printv(f_go_wrappers, goin, NULL); + Printv(f_go_wrappers, goin, "\n", NULL); Delete(goin); Printv(call, ivar, NULL); Setattr(p, "emit:goinput", ivar); @@ -1228,7 +1951,7 @@ class GO:public Language { Printv(f_go_wrappers, call, NULL); Delete(call); - goargout(parms, parm_count); + goargout(parms); if (need_return_var) { if (goout == NULL) { @@ -1238,7 +1961,7 @@ class GO:public Language { Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); Replaceall(goout, "$input", "swig_r"); Replaceall(goout, "$result", "swig_r_1"); - Printv(f_go_wrappers, goout, NULL); + Printv(f_go_wrappers, goout, "\n", NULL); Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); } } @@ -1268,6 +1991,34 @@ class GO:public Language { return SWIG_OK; } + /* ---------------------------------------------------------------------- + * initGoTypemaps() + * + * Initialize the typenames for a Go wrapper, returning a dummy + * Wrapper*. Also set consistent names for the parameters. + * ---------------------------------------------------------------------- */ + + Wrapper* initGoTypemaps(ParmList *parms) { + Wrapper *dummy = NewWrapper(); + emit_attach_parmmaps(parms, dummy); + + Parm *p = parms; + int parm_count = emit_num_arguments(parms); + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + Swig_cparm_name(p, i); + p = nextParm(p); + } + + Swig_typemap_attach_parms("default", parms, dummy); + Swig_typemap_attach_parms("gotype", parms, dummy); + Swig_typemap_attach_parms("goin", parms, dummy); + Swig_typemap_attach_parms("goargout", parms, dummy); + Swig_typemap_attach_parms("imtype", parms, dummy); + + return dummy; + } + /* ---------------------------------------------------------------------- * argName() * @@ -1290,7 +2041,7 @@ class GO:public Language { * needs to explicitly escape. This is true if the parameter has a * non-empty argout or freearg typemap, because in those cases the * Go argument might be or contain a pointer. We need to ensure - * that that pointer does not oint into the stack, which means that + * that that pointer does not point into the stack, which means that * it needs to escape. * ---------------------------------------------------------------------- */ bool paramNeedsEscape(Parm *p) { @@ -1361,6 +2112,7 @@ class GO:public Language { emit_attach_parmmaps(parms, f); int parm_count = emit_num_arguments(parms); int required_count = emit_num_required(parms); + bool needs_swigargs = false; emit_return_variable(n, result, f); @@ -1371,10 +2123,11 @@ class GO:public Language { // The single function parameter is a pointer to the real argument // values. Define the structure that it points to. - Printv(f->code, "\tstruct swigargs {\n", NULL); + String *swigargs = NewString("\tstruct swigargs {\n"); if (parm_count > required_count) { - Printv(f->code, "\t\tintgo _swig_optargc;\n", NULL); + needs_swigargs = true; + Printv(swigargs, "\t\tintgo _swig_optargc;\n", NULL); } Parm *p = parms; @@ -1384,7 +2137,8 @@ class GO:public Language { String *ln = Getattr(p, "lname"); SwigType *pt = Getattr(p, "type"); String *ct = gcCTypeForGoValue(p, pt, ln); - Printv(f->code, "\t\t\t", ct, ";\n", NULL); + Printv(swigargs, "\t\t\t", ct, ";\n", NULL); + needs_swigargs = true; Delete(ct); String *gn = NewStringf("_swig_go_%d", i); @@ -1396,11 +2150,12 @@ class GO:public Language { p = nextParm(p); } if (SwigType_type(result) != T_VOID) { - Printv(f->code, "\t\tlong : 0;\n", NULL); + Printv(swigargs, "\t\tlong : 0;\n", NULL); String *ln = NewString(Swig_cresult_name()); String *ct = gcCTypeForGoValue(n, result, ln); Delete(ln); - Printv(f->code, "\t\t", ct, ";\n", NULL); + Printv(swigargs, "\t\t", ct, ";\n", NULL); + needs_swigargs = true; Delete(ct); ln = NewString("_swig_go_result"); @@ -1409,9 +2164,7 @@ class GO:public Language { Delete(ct); Delete(ln); } - Printv(f->code, "\t} *swig_a = (struct swigargs *) swig_v;\n", NULL); - - Printv(f->code, "\n", NULL); + Printv(swigargs, "\t} SWIGSTRUCTPACKED *swig_a = (struct swigargs *) swig_v;\n", NULL); // Copy the input arguments out of the structure into the Go local // variables. @@ -1459,12 +2212,18 @@ class GO:public Language { cleanupFunction(n, f, parms); + if (needs_swigargs) + { + Printv(f->locals, swigargs, NULL); + } + Printv(f->code, "}\n", NULL); Wrapper_print(f, f_c_wrappers); Swig_restore(n); + Delete(swigargs); DelWrapper(f); Delete(base_parm); @@ -1647,7 +2406,7 @@ class GO:public Language { * ----------------------------------------------------------------------- */ void emitGoAction(Node *n, List *base, ParmList *parms, SwigType *result, Wrapper *f) { - if (!gccgo_flag && SwigType_type(result) != T_VOID) { + if (!gccgo_flag && !cgo_flag && SwigType_type(result) != T_VOID) { Wrapper_add_local(f, "swig_stktop", "char *swig_stktop"); Printv(f->code, "\tswig_stktop = _swig_topofstack();\n", NULL); } @@ -1660,7 +2419,7 @@ class GO:public Language { actioncode = NewString(""); String *current = NewString(""); - if (!gccgo_flag) { + if (!gccgo_flag && !cgo_flag) { Printv(current, "swig_a->", NULL); } Printv(current, Getattr(parms, "lname"), NULL); @@ -1697,7 +2456,7 @@ class GO:public Language { Delete(tm); } - if (!gccgo_flag && SwigType_type(result) != T_VOID) { + if (!gccgo_flag && !cgo_flag && SwigType_type(result) != T_VOID) { // If the function called back into the Go code, the stack might // have been copied. We need to adjust swig_a accordingly here. // This is what cgo does. @@ -1741,10 +2500,9 @@ class GO:public Language { * property with the name to use to refer to that parameter. * ----------------------------------------------------------------------- */ - void goargout(ParmList *parms, int parm_count) { + void goargout(ParmList *parms) { Parm *p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); + while (p) { String *tm = Getattr(p, "tmap:goargout"); if (!tm) { p = nextSibling(p); @@ -1752,11 +2510,33 @@ class GO:public Language { tm = Copy(tm); Replaceall(tm, "$result", "swig_r"); Replaceall(tm, "$input", Getattr(p, "emit:goinput")); - Printv(f_go_wrappers, tm, NULL); + Printv(f_go_wrappers, tm, "\n", NULL); Delete(tm); p = Getattr(p, "tmap:goargout:next"); } } + + // When using cgo, if we need to memcpy a parameter to pass it to + // the C code, the compiler may think that the parameter is not + // live during the function call. If the garbage collector runs + // while the C/C++ function is running, the parameter may be + // freed. Force the compiler to see the parameter as live across + // the C/C++ function. + if (cgo_flag) { + int parm_count = emit_num_arguments(parms); + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + bool c_struct_type; + Delete(cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type)); + if (c_struct_type) { + Printv(f_go_wrappers, "\tif Swig_escape_always_false {\n", NULL); + Printv(f_go_wrappers, "\t\tSwig_escape_val = ", Getattr(p, "emit:goinput"), "\n", NULL); + Printv(f_go_wrappers, "\t}\n", NULL); + } + p = nextParm(p); + } + } } /* ----------------------------------------------------------------------- @@ -1862,7 +2642,7 @@ class GO:public Language { // exponentiation. Treat anything else as too complicated to // handle as a Go constant. char *p = Char(value); - int len = strlen(p); + int len = (int)strlen(p); bool need_copy = false; while (len > 0) { char c = p[len - 1]; @@ -1942,7 +2722,7 @@ class GO:public Language { Printv(f_go_wrappers, "type ", name, " int\n", NULL); } else { String *nw = NewString(""); - Printv(nw, imported_package, ".", name, NULL); + Printv(nw, getModuleName(imported_package), ".", name, NULL); Setattr(n, "go:enumname", nw); } } @@ -2044,6 +2824,7 @@ class GO:public Language { Append(go_name, sname); String *wname = Swig_name_wrapper(sname); + Append(wname, unique_id); Setattr(n, "wrap:name", wname); int r = makeWrappers(n, sname, go_name, NULL, wname, NULL, NULL, type, true); @@ -2332,6 +3113,7 @@ class GO:public Language { if (overname) { Append(wname, overname); } + Append(wname, unique_id); String *result = NewString(Getattr(method, "type")); SwigType_push(result, Getattr(method, "decl")); @@ -2391,15 +3173,26 @@ class GO:public Language { Setattr(var, "type", var_type); SwigType *vt = Copy(var_type); - if (SwigType_isclass(vt)) { - SwigType_add_pointer(vt); - } int flags = Extend | SmartPointer | use_naturalvar_mode(var); if (isNonVirtualProtectedAccess(var)) { flags |= CWRAP_ALL_PROTECTED_ACCESS; } + // Copied from Swig_wrapped_member_var_type. + if (SwigType_isclass(vt)) { + if (flags & CWRAP_NATURAL_VAR) { + if (CPlusPlus) { + if (!SwigType_isconst(vt)) { + SwigType_add_qualifier(vt, "const"); + } + SwigType_add_reference(vt); + } + } else { + SwigType_add_pointer(vt); + } + } + String *mname = Swig_name_member(getNSpace(), Getattr(var_class, "sym:name"), var_name); if (is_assignable(var)) { @@ -2419,6 +3212,7 @@ class GO:public Language { Swig_MembersetToFunction(var, class_name, flags); String *wname = Swig_name_wrapper(mname_set); + Append(wname, unique_id); ParmList *parms = NewParm(vt, var_name, var); String *result = NewString("void"); int r = makeWrappers(var, mname_set, go_name, NULL, wname, bases, parms, result, false); @@ -2448,6 +3242,7 @@ class GO:public Language { Append(go_name, var_name); String *wname = Swig_name_wrapper(mname_get); + Append(wname, unique_id); int r = makeWrappers(var, mname_get, go_name, NULL, wname, bases, NULL, vt, false); if (r != SWIG_OK) { @@ -2559,6 +3354,7 @@ class GO:public Language { Delete(c1); String *wname = Swig_name_wrapper(name); + Append(wname, unique_id); Setattr(n, "wrap:name", wname); SwigType *result = Copy(Getattr(b.item, "classtypeobj")); @@ -2767,11 +3563,17 @@ class GO:public Language { } } + String *fn_with_over_name = Copy(fn_name); + if (overname) { + Append(fn_with_over_name, overname); + } + String *wname = Swig_name_wrapper(fn_name); if (overname) { Append(wname, overname); } + Append(wname, unique_id); Setattr(n, "wrap:name", wname); bool is_static = isStatic(n); @@ -2781,6 +3583,8 @@ class GO:public Language { DelWrapper(dummy); Swig_typemap_attach_parms("gotype", parms, NULL); + Swig_typemap_attach_parms("goin", parms, NULL); + Swig_typemap_attach_parms("goargout", parms, NULL); Swig_typemap_attach_parms("imtype", parms, NULL); int parm_count = emit_num_arguments(parms); @@ -2792,8 +3596,7 @@ class GO:public Language { Append(func_with_over_name, overname); } - SwigType *first_type = NewString("void"); - SwigType_add_pointer(first_type); + SwigType *first_type = NewString("int"); Parm *first_parm = NewParm(first_type, "swig_p", n); set_nextSibling(first_parm, parms); Setattr(first_parm, "lname", "p"); @@ -2806,47 +3609,58 @@ class GO:public Language { } if (!is_ignored) { - // Declare the C++ wrapper. + if (cgo_flag) { + Printv(f_cgo_comment, "extern uintptr_t ", wname, "(int", NULL); - if (!gccgo_flag) { - Printv(f_go_wrappers, "var ", wname, " unsafe.Pointer\n\n", NULL); + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type); + Printv(f_cgo_comment, ", ", ct, " ", Getattr(p, "lname"), NULL); + p = nextParm(p); + } + Printv(f_cgo_comment, ");\n", NULL); } else { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); - } + // Declare the C++ wrapper. - Printv(f_go_wrappers, "func ", fn_name, NULL); - if (overname) { - Printv(f_go_wrappers, overname, NULL); - } - Printv(f_go_wrappers, "(_swig_director *", director_struct_name, NULL); + if (!gccgo_flag) { + Printv(f_go_wrappers, "var ", wname, " unsafe.Pointer\n\n", NULL); + } else { + Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); + } - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *tm = goType(p, Getattr(p, "type")); - Printv(f_go_wrappers, ", _ ", tm, NULL); - Delete(tm); - p = nextParm(p); - } + Printv(f_go_wrappers, "func ", fn_with_over_name, "(_swig_director int", NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + String *tm = goWrapperType(p, Getattr(p, "type"), false); + Printv(f_go_wrappers, ", _ ", tm, NULL); + Delete(tm); + p = nextParm(p); + } - Printv(f_go_wrappers, ") (_swig_ret ", go_type_name, ")", NULL); + Printv(f_go_wrappers, ") (_swig_ret ", go_type_name, ")", NULL); - if (!gccgo_flag) { - Printv(f_go_wrappers, " {\n", NULL); - Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&_swig_director))\n", NULL); - Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); - Printv(f_go_wrappers, "\treturn\n", NULL); - Printv(f_go_wrappers, "}", NULL); + if (!gccgo_flag) { + Printv(f_go_wrappers, " {\n", NULL); + Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&_swig_director))\n", NULL); + Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); + Printv(f_go_wrappers, "\treturn\n", NULL); + Printv(f_go_wrappers, "}", NULL); + } + + Printv(f_go_wrappers, "\n\n", NULL); } - Printv(f_go_wrappers, "\n\n", NULL); + // Write out the Go function that calls the wrapper. Printv(f_go_wrappers, "func ", func_with_over_name, "(v interface{}", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); - // Set the lname parameter. Printv(f_go_wrappers, ", ", Getattr(p, "lname"), " ", NULL); String *tm = goType(p, Getattr(p, "type")); Printv(f_go_wrappers, tm, NULL); @@ -2858,25 +3672,73 @@ class GO:public Language { Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL); - if (gccgo_flag) { + if (gccgo_flag && !cgo_flag) { Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); } - Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL); - if (overname) { - Printv(f_go_wrappers, overname, NULL); + String *call = NewString(""); + + Printv(call, "\tp.", class_receiver, " = ", NULL); + if (cgo_flag) { + Printv(call, go_type_name, "(C.", wname, "(C.int(swigDirectorAdd(p))", NULL); + } else { + Printv(call, fn_with_over_name, "(swigDirectorAdd(p)", NULL); } - Printv(f_go_wrappers, "(p", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { + Printv(call, ", ", NULL); + p = getParm(p); - Printv(f_go_wrappers, ", ", Getattr(p, "lname"), NULL); + String *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + + String *ivar = NewStringf("_swig_i_%d", i); + + String *goin = goGetattr(p, "tmap:goin"); + if (goin == NULL) { + Printv(f_go_wrappers, "\t", ivar, " := ", ln, NULL); + if (goTypeIsInterface(p, pt)) { + Printv(f_go_wrappers, ".Swigcptr()", NULL); + } + Printv(f_go_wrappers, "\n", NULL); + } else { + String *itm = goImType(p, pt); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, "\n", NULL); + goin = Copy(goin); + Replaceall(goin, "$input", ln); + Replaceall(goin, "$result", ivar); + Printv(f_go_wrappers, goin, "\n", NULL); + Delete(goin); + } + + Setattr(p, "emit:goinput", ivar); + + if (cgo_flag) { + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); + if (c_struct_type) { + Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); + } else { + Printv(call, "C.", ct, "(", ivar, ")", NULL); + } + Delete(ct); + } else { + Printv(call, ivar, NULL); + } p = nextParm(p); } - Printv(f_go_wrappers, ")\n", NULL); + Printv(call, ")", NULL); + if (cgo_flag) { + Printv(call, ")", NULL); + } + + Printv(f_go_wrappers, call, "\n", NULL); + + goargout(parms); + Printv(f_go_wrappers, "\treturn p\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); @@ -2885,7 +3747,9 @@ class GO:public Language { Swig_save("classDirectorConstructor", n, "wrap:name", "wrap:action", NULL); - Setattr(n, "wrap:name", Swig_name_wrapper(name)); + String *dwname = Swig_name_wrapper(name); + Append(dwname, unique_id); + Setattr(n, "wrap:name", dwname); String *action = NewString(""); Printv(action, Swig_cresult_name(), " = new SwigDirector_", class_name, "(", NULL); @@ -2907,7 +3771,26 @@ class GO:public Language { Printv(action, ");", NULL); Setattr(n, "wrap:action", action); - if (!gccgo_flag) { + if (cgo_flag) { + cgoWrapperInfo info; + + info.n = n; + info.go_name = func_name; + info.overname = overname; + info.wname = wname; + info.base = NULL; + info.parms = first_parm; + info.result = result; + info.is_static = false; + info.receiver = NULL; + info.is_constructor = true; + info.is_destructor = false; + + int r = cgoGccWrapper(&info); + if (r != SWIG_OK) { + return r; + } + } else if (!gccgo_flag) { int r = gcFunctionWrapper(wname); if (r != SWIG_OK) { return r; @@ -2954,7 +3837,7 @@ class GO:public Language { p = nextParm(p); } Printv(f_c_directors, "),\n", NULL); - Printv(f_c_directors, " go_val(swig_p)\n", NULL); + Printv(f_c_directors, " go_val(swig_p), swig_mem(0)\n", NULL); Printv(f_c_directors, "{ }\n\n", NULL); if (Getattr(n, "sym:overloaded") && !Getattr(n, "sym:nextSibling")) { @@ -2970,6 +3853,7 @@ class GO:public Language { Delete(go_type_name); Delete(director_struct_name); Delete(fn_name); + Delete(fn_with_over_name); Delete(func_name); Delete(func_with_over_name); Delete(wname); @@ -2999,6 +3883,7 @@ class GO:public Language { Delete(c1); String *wname = Swig_name_wrapper(fnname); + Append(wname, unique_id); Setattr(n, "wrap:name", fnname); @@ -3022,9 +3907,6 @@ class GO:public Language { // Go code is keeping a pointer to the C++ object, we need to call // back to the Go code to let it know that the C++ object is gone. - String *wname = NewString("_swiggo_wrap_DeleteDirector_"); - Append(wname, class_name); - String *go_name = NewString("Swiggo_DeleteDirector_"); Append(go_name, class_name); @@ -3042,58 +3924,111 @@ class GO:public Language { Printv(f_c_directors_h, ";\n", NULL); - if (!is_ignored) { - if (!gccgo_flag) { - Printv(f_c_directors, "extern \"C\" void ", wname, "(void*, int);\n", NULL); - } else { - Printv(f_c_directors, "extern \"C\" void ", wname, "(void*) __asm__(\"", go_prefix, ".", go_name, "\");\n", NULL); - } + String *director_sig = NewString(""); + + Printv(director_sig, "SwigDirector_", class_name, "::~SwigDirector_", class_name, "()", NULL); + + if (throws) { + Printv(director_sig, " ", throws, NULL); + Delete(throws); + } + + Printv(director_sig, "\n", NULL); + Printv(director_sig, "{\n", NULL); + + if (is_ignored) { + Printv(f_c_directors, director_sig, NULL); + } else { + makeDirectorDestructorWrapper(go_name, director_struct_name, director_sig); } - Printv(f_c_directors, "SwigDirector_", class_name, "::~SwigDirector_", class_name, "()", NULL); + Printv(f_c_directors, " delete swig_mem;\n", NULL); + + Printv(f_c_directors, "}\n\n", NULL); + + Delete(director_sig); + Delete(go_name); + Delete(cn); + Delete(director_struct_name); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * makeDirectorDestructorWrapper + * + * Emit the function wrapper for the destructor of a director class. + * This writes director_sig to f_c_directors and leaves the function + * unfinished. + * ------------------------------------------------------------ */ + + void makeDirectorDestructorWrapper(String *go_name, String *director_struct_name, String *director_sig) { + if (cgo_flag) { + makeCgoDirectorDestructorWrapper(go_name, director_struct_name, director_sig); + return; + } - if (throws) { - Printv(f_c_directors, " ", throws, NULL); - Delete(throws); + Printv(f_go_wrappers, "func ", go_name, "(c int) {\n", NULL); + if (gccgo_flag) { + Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL); + Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL); } + Printv(f_go_wrappers, "\tswigDirectorLookup(c).(*", director_struct_name, ").", class_receiver, " = 0\n", NULL); + Printv(f_go_wrappers, "\tswigDirectorDelete(c)\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); - Printv(f_c_directors, "\n", NULL); - Printv(f_c_directors, "{\n", NULL); + String *wname = NewString("_swiggo_wrap_DeleteDirector_"); + Append(wname, class_name); - if (!is_ignored) { - if (!gccgo_flag) { - Printv(f_c_directors, " struct { void *p; } a;\n", NULL); - Printv(f_c_directors, " a.p = go_val;\n", NULL); - Printv(f_c_directors, " crosscall2(", wname, ", &a, (int) sizeof a);\n", NULL); - - Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", NULL); - Printv(f_gc_wrappers, "#pragma cgo_export_static ", wname, " ", wname, "\n", NULL); - Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL); - Printv(f_gc_wrappers, "extern void \xc2\xb7", go_name, "();\n", NULL); - Printv(f_gc_wrappers, "void\n", NULL); - Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL); - Printv(f_gc_wrappers, "{\n", NULL); - Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL); - Printv(f_gc_wrappers, "}\n\n", NULL); - } else { - Printv(f_c_directors, " ", wname, "(go_val);\n", NULL); - } + if (!gccgo_flag) { + Printv(f_c_directors, "extern \"C\" void ", wname, "(void*, int);\n", NULL); + } else { + Printv(f_c_directors, "extern \"C\" void ", wname, "(intgo) __asm__(\"", go_prefix, ".", go_name, "\");\n", NULL); } - Printv(f_c_directors, "}\n\n", NULL); + Printv(f_c_directors, director_sig, NULL); - if (!is_ignored) { - Printv(f_go_wrappers, "func ", go_name, "(p *", director_struct_name, ") {\n", NULL); - Printv(f_go_wrappers, "\tp.", class_receiver, " = 0\n", NULL); - Printv(f_go_wrappers, "}\n\n", NULL); + if (!gccgo_flag) { + Printv(f_c_directors, " struct { intgo p; } SWIGSTRUCTPACKED a;\n", NULL); + Printv(f_c_directors, " a.p = go_val;\n", NULL); + Printv(f_c_directors, " crosscall2(", wname, ", &a, (int) sizeof a);\n", NULL); + + Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", NULL); + Printv(f_gc_wrappers, "#pragma cgo_export_static ", wname, " ", wname, "\n", NULL); + Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL); + Printv(f_gc_wrappers, "extern void \xc2\xb7", go_name, "();\n", NULL); + Printv(f_gc_wrappers, "void\n", NULL); + Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL); + Printv(f_gc_wrappers, "{\n", NULL); + Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL); + Printv(f_gc_wrappers, "}\n\n", NULL); + } else { + Printv(f_c_directors, " ", wname, "(go_val);\n", NULL); } Delete(wname); - Delete(go_name); - Delete(cn); - Delete(director_struct_name); + } - return SWIG_OK; + /* ------------------------------------------------------------ + * makeCgoDirectorDestructorWrapper + * + * When using cgo, emit the function wrapper for the destructor of a + * director class. + * ------------------------------------------------------------ */ + + void makeCgoDirectorDestructorWrapper(String *go_name, String *director_struct_name, String *director_sig) { + String *wname = Copy(go_name); + Append(wname, unique_id); + + Printv(f_go_wrappers, "//export ", wname, "\n", NULL); + Printv(f_go_wrappers, "func ", wname, "(c int) {\n", NULL); + Printv(f_go_wrappers, "\tswigDirectorLookup(c).(*", director_struct_name, ").", class_receiver, " = 0\n", NULL); + Printv(f_go_wrappers, "\tswigDirectorDelete(c)\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + Printv(f_c_directors, "extern \"C\" void ", wname, "(intgo);\n", NULL); + Printv(f_c_directors, director_sig, NULL); + Printv(f_c_directors, " ", wname, "(go_val);\n", NULL); } /* ------------------------------------------------------------ @@ -3134,6 +4069,7 @@ class GO:public Language { // set. String *wn = Swig_name_wrapper(Getattr(on, "sym:name")); Append(wn, Getattr(on, "sym:overname")); + Append(wn, unique_id); Setattr(on, "wrap:name", wn); Delete(wn); Setattr(on, "wrap:parms", Getattr(on, "parms")); @@ -3250,8 +4186,9 @@ class GO:public Language { if (overname) { Append(callback_name, overname); } - - String *callback_wname = Swig_name_wrapper(callback_name); + if (cgo_flag) { + Append(callback_name, unique_id); + } String *upcall_name = Copy(director_struct_name); Append(upcall_name, "_upcall_"); @@ -3261,6 +4198,7 @@ class GO:public Language { if (overname) { Append(upcall_wname, overname); } + Append(upcall_wname, unique_id); String *upcall_gc_name = buildGoWrapperName(upcall_name, overname); @@ -3309,43 +4247,68 @@ class GO:public Language { Printv(f_go_wrappers, "}\n\n", NULL); if (!GetFlag(n, "abstract")) { - // Declare the upcall function, which calls the method on the - // parent class. + if (cgo_flag) { + Printv(f_cgo_comment, "extern ", NULL); - if (!gccgo_flag) { - Printv(f_go_wrappers, "var ", upcall_wname, " unsafe.Pointer\n\n", NULL); + if (SwigType_type(result) == T_VOID) { + Printv(f_cgo_comment, "void", NULL); + } else { + bool c_struct_type; + String *ret_type = cgoTypeForGoValue(n, result, &c_struct_type); + Printv(f_cgo_comment, ret_type, NULL); + Delete(ret_type); + } + + Printv(f_cgo_comment, " ", upcall_wname, "(uintptr_t", NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type); + Printv(f_cgo_comment, ", ", ct, " ", Getattr(p, "lname"), NULL); + p = nextParm(p); + } + Printv(f_cgo_comment, ");\n", NULL); } else { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL); - } + // Declare the upcall function, which calls the method on + // the parent class. - Printv(f_go_wrappers, "func ", upcall_gc_name, "(_swig_ptr ", go_type_name, NULL); + if (!gccgo_flag) { + Printv(f_go_wrappers, "var ", upcall_wname, " unsafe.Pointer\n\n", NULL); + } else { + Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL); + } - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *tm = goWrapperType(p, Getattr(p, "type"), false); - Printv(f_go_wrappers, ", _ ", tm, NULL); - Delete(tm); - p = nextParm(p); - } + Printv(f_go_wrappers, "func ", upcall_gc_name, "(_swig_ptr ", go_type_name, NULL); - Printv(f_go_wrappers, ")", NULL); + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + String *tm = goWrapperType(p, Getattr(p, "type"), false); + Printv(f_go_wrappers, ", _ ", tm, NULL); + Delete(tm); + p = nextParm(p); + } - if (SwigType_type(result) != T_VOID) { - String *tm = goWrapperType(n, result, true); - Printv(f_go_wrappers, " (_swig_ret ", tm, ")", NULL); - Delete(tm); - } + Printv(f_go_wrappers, ")", NULL); - if (!gccgo_flag) { - Printv(f_go_wrappers, " {\n", NULL); - Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&_swig_ptr))\n", NULL); - Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", upcall_wname, ", _swig_p)\n", NULL); - Printv(f_go_wrappers, "\treturn\n", NULL); - Printv(f_go_wrappers, "}", NULL); - } + if (SwigType_type(result) != T_VOID) { + String *tm = goWrapperType(n, result, true); + Printv(f_go_wrappers, " (_swig_ret ", tm, ")", NULL); + Delete(tm); + } - Printv(f_go_wrappers, "\n\n", NULL); + if (!gccgo_flag) { + Printv(f_go_wrappers, " {\n", NULL); + Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&_swig_ptr))\n", NULL); + Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", upcall_wname, ", _swig_p)\n", NULL); + Printv(f_go_wrappers, "\treturn\n", NULL); + Printv(f_go_wrappers, "}", NULL); + } + + Printv(f_go_wrappers, "\n\n", NULL); + } } // Define the method on the director class in Go. @@ -3401,20 +4364,32 @@ class GO:public Language { if (GetFlag(n, "abstract")) { Printv(f_go_wrappers, "\tpanic(\"call to pure virtual method\")\n", NULL); } else { + String *ret_type = NULL; + bool memcpy_ret = false; + String *wt = NULL; bool has_goout = false; String *goout = NULL; if (SwigType_type(result) != T_VOID) { - Printv(f_go_wrappers, "\tvar swig_r ", goImType(n, result), "\n", NULL); - goout = Swig_typemap_lookup("goout", n, "swig_r", NULL); + ret_type = goImType(n, result); + Printv(f_go_wrappers, "\tvar swig_r ", ret_type, "\n", NULL); + goout = goTypemapLookup("goout", n, "swig_r"); if (goout) { has_goout = true; } + + if (cgo_flag) { + bool c_struct_type; + Delete(cgoTypeForGoValue(n, result, &c_struct_type)); + if (c_struct_type) { + memcpy_ret = true; + } + } } p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); - if (Getattr(p, "tmap:goargout")) { + if (goGetattr(p, "tmap:goargout")) { has_goout = true; } p = nextParm(p); @@ -3422,7 +4397,7 @@ class GO:public Language { String *call = NewString(""); - if (gccgo_flag) { + if (gccgo_flag && !cgo_flag) { if (has_goout) { Printv(call, "\tfunc() {\n", NULL); } @@ -3432,9 +4407,33 @@ class GO:public Language { Printv(call, "\t", NULL); if (SwigType_type(result) != T_VOID) { - Printv(call, "swig_r = ", NULL); + if (memcpy_ret) { + Printv(call, "swig_r_p := ", NULL); + } else { + Printv(call, "swig_r = ", NULL); + if (cgo_flag) { + Printv(call, "(", ret_type, ")(", NULL); + } + } + if (cgo_flag && goTypeIsInterface(n, result)) { + wt = goWrapperType(n, result, true); + Printv(call, "(", wt, ")(", NULL); + } + } + + if (cgo_flag) { + Printv(call, "C.", upcall_wname, NULL); + } else { + Printv(call, upcall_gc_name, NULL); + } + Printv(call, "(", NULL); + if (cgo_flag) { + Printv(call, "C.uintptr_t(", NULL); + } + Printv(call, "swig_p.", go_type_name, NULL); + if (cgo_flag) { + Printv(call, ")", NULL); } - Printv(call, upcall_gc_name, "(swig_p.", go_type_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3444,42 +4443,71 @@ class GO:public Language { String *ln = Getattr(p, "lname"); + String *ivar = NewStringf("_swig_i_%d", i); + // This is an ordinary call from Go to C++, so adjust using // the goin typemap. - String *goin = Getattr(p, "tmap:goin"); + String *goin = goGetattr(p, "tmap:goin"); if (goin == NULL) { - Printv(call, ln, NULL); + Printv(f_go_wrappers, "\t", ivar, " := ", ln, NULL); if (goTypeIsInterface(p, pt)) { - Printv(call, ".Swigcptr()", NULL); + Printv(f_go_wrappers, ".Swigcptr()", NULL); } - Setattr(p, "emit:goinput", ln); + Printv(f_go_wrappers, "\n", NULL); } else { - String *ivar = NewString(""); - Printf(ivar, "_swig_i_%d", i); String *itm = goImType(p, pt); - Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, NULL); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, "\n", NULL); goin = Copy(goin); Replaceall(goin, "$input", ln); Replaceall(goin, "$result", ivar); Printv(f_go_wrappers, goin, NULL); Delete(goin); + } + + Setattr(p, "emit:goinput", ivar); + + if (cgo_flag) { + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); + if (c_struct_type) { + Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); + } else { + Printv(call, "C.", ct, "(", ivar, ")", NULL); + } + } else { Printv(call, ivar, NULL); - Setattr(p, "emit:goinput", ivar); } p = nextParm(p); } - Printv(call, ")\n", NULL); + Printv(call, ")", NULL); + + if (gccgo_flag && !cgo_flag && has_goout) { + Printv(call, "\n\t}()", NULL); + } - if (gccgo_flag && has_goout) { - Printv(call, "\t}()\n", NULL); + if (cgo_flag) { + if (wt) { + // Close the type conversion to the wrapper type. + Printv(call, ")", NULL); + } + if (SwigType_type(result) != T_VOID && !memcpy_ret) { + // Close the type conversion of the return value. + Printv(call, ")", NULL); + } } + Printv(call, "\n", NULL); + Printv(f_go_wrappers, call, NULL); Delete(call); - goargout(parms, parm_count); + if (memcpy_ret) { + Printv(f_go_wrappers, "\tswig_r = *(*", ret_type, ")(unsafe.Pointer(&swig_r_p))\n", NULL); + } + + goargout(parms); if (SwigType_type(result) != T_VOID) { if (goout == NULL) { @@ -3489,10 +4517,17 @@ class GO:public Language { Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); Replaceall(goout, "$input", "swig_r"); Replaceall(goout, "$result", "swig_r_1"); - Printv(f_go_wrappers, goout, NULL); + Printv(f_go_wrappers, goout, "\n", NULL); Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); } } + + if (ret_type) { + Delete(ret_type); + } + if (wt) { + Delete(wt); + } } Printv(f_go_wrappers, "}\n\n", NULL); @@ -3574,7 +4609,26 @@ class GO:public Language { Printv(action, ");", NULL); Setattr(n, "wrap:action", action); - if (!gccgo_flag) { + if (cgo_flag) { + cgoWrapperInfo info; + + info.n = n; + info.go_name = go_name; + info.overname = overname; + info.wname = upcall_wname; + info.base = NULL; + info.parms = first_parm; + info.result = result; + info.is_static = is_static; + info.receiver = NULL; + info.is_constructor = false; + info.is_destructor = false; + + int r = cgoGccWrapper(&info); + if (r != SWIG_OK) { + return r; + } + } else if (!gccgo_flag) { // Write the upcall wrapper function. This is compiled by gc // and calls the C++ function. int r = gcFunctionWrapper(upcall_wname); @@ -3625,15 +4679,27 @@ class GO:public Language { Printv(f_go_wrappers, " {\n", NULL); + String *ret_type = NULL; + bool memcpy_ret = false; + String *wt = NULL; String *goout = NULL; if (SwigType_type(result) != T_VOID) { - Printv(f_go_wrappers, "\tvar swig_r ", goImType(n, result), "\n", NULL); - goout = Swig_typemap_lookup("goout", n, "swig_r", NULL); + ret_type = goImType(n, result); + Printv(f_go_wrappers, "\tvar swig_r ", ret_type, "\n", NULL); + goout = goTypemapLookup("goout", n, "swig_r"); + + if (cgo_flag) { + bool c_struct_type; + Delete(cgoTypeForGoValue(n, result, &c_struct_type)); + if (c_struct_type) { + memcpy_ret = true; + } + } } String *call = NewString(""); - if (gccgo_flag) { + if (gccgo_flag && !cgo_flag) { if (goout != NULL) { Printv(call, "\tfunc() {\n", NULL); } @@ -3643,9 +4709,33 @@ class GO:public Language { Printv(call, "\t", NULL); if (SwigType_type(result) != T_VOID) { - Printv(call, "swig_r = ", NULL); + if (memcpy_ret) { + Printv(call, "swig_r_p := ", NULL); + } else { + Printv(call, "swig_r = ", NULL); + if (cgo_flag) { + Printv(call, "(", ret_type, ")(", NULL); + } + } + if (cgo_flag && goTypeIsInterface(n, result)) { + wt = goWrapperType(n, result, true); + Printv(call, "(", wt, ")(", NULL); + } + } + + if (cgo_flag) { + Printv(call, "C.", upcall_wname, NULL); + } else { + Printv(call, upcall_gc_name, NULL); + } + Printv(call, "(", NULL); + if (cgo_flag) { + Printv(call, "C.uintptr_t(", NULL); + } + Printv(call, "p.(*", director_struct_name, ").", go_type_name, NULL); + if (cgo_flag) { + Printv(call, ")", NULL); } - Printv(call, upcall_gc_name, "(p.(*", director_struct_name, ").", go_type_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3653,27 +4743,39 @@ class GO:public Language { p = getParm(p); SwigType *pt = Getattr(p, "type"); + String *ivar = NewStringf("_swig_i_%d", i); + String *ln = Copy(Getattr(p, "lname")); - if (goTypeIsInterface(p, pt)) { - Printv(ln, ".Swigcptr()", NULL); - } - String *goin = Getattr(p, "tmap:goin"); + String *goin = goGetattr(p, "tmap:goin"); if (goin == NULL) { - Printv(call, ln, NULL); - Setattr(p, "emit:goinput", ln); + Printv(f_go_wrappers, "\t", ivar, " := ", ln, NULL); + if (goTypeIsInterface(p, pt)) { + Printv(f_go_wrappers, ".Swigcptr()", NULL); + } + Printv(f_go_wrappers, "\n", NULL); } else { - String *ivar = NewString(""); - Printf(ivar, "_swig_i_%d", i); String *itm = goImType(p, pt); - Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, NULL); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, "\n", NULL); goin = Copy(goin); Replaceall(goin, "$input", ln); Replaceall(goin, "$result", ivar); Printv(f_go_wrappers, goin, NULL); Delete(goin); + } + + Setattr(p, "emit:goinput", ivar); + + if (cgo_flag) { + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); + if (c_struct_type) { + Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); + } else { + Printv(call, "C.", ct, "(", ivar, ")", NULL); + } + } else { Printv(call, ivar, NULL); - Setattr(p, "emit:goinput", ivar); } Delete(ln); @@ -3681,16 +4783,33 @@ class GO:public Language { p = nextParm(p); } - Printv(call, ")\n", NULL); + Printv(call, ")", NULL); + + if (gccgo_flag && !cgo_flag && goout != NULL) { + Printv(call, "\n\t}()", NULL); + } - if (gccgo_flag && goout != NULL) { - Printv(call, "\t}()\n", NULL); + if (cgo_flag) { + if (wt) { + // Close the type conversion to the wrapper type. + Printv(call, ")", NULL); + } + if (SwigType_type(result) != T_VOID && !memcpy_ret) { + // Close the type conversion of the return value. + Printv(call, ")", NULL); + } } + Printv(call, "\n", NULL); + Printv(f_go_wrappers, call, NULL); Delete(call); - goargout(parms, parm_count); + if (memcpy_ret) { + Printv(f_go_wrappers, "\tswig_r = *(*", ret_type, ")(unsafe.Pointer(&swig_r_p))\n", NULL); + } + + goargout(parms); if (SwigType_type(result) != T_VOID) { if (goout == NULL) { @@ -3700,18 +4819,29 @@ class GO:public Language { Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); Replaceall(goout, "$input", "swig_r"); Replaceall(goout, "$result", "swig_r_1"); - Printv(f_go_wrappers, goout, NULL); + Printv(f_go_wrappers, goout, "\n", NULL); Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); } } Printv(f_go_wrappers, "}\n\n", NULL); + + if (ret_type) { + Delete(ret_type); + } + if (wt) { + Delete(wt); + } } - // The Go function which invokes the method. This is called - // from by the C++ method on the director class. + // The Go function which invokes the method. This is called by + // the C++ method on the director class. + + if (cgo_flag) { + Printv(f_go_wrappers, "//export ", callback_name, "\n", NULL); + } - Printv(f_go_wrappers, "func ", callback_name, "(p *", director_struct_name, NULL); + Printv(f_go_wrappers, "func ", callback_name, "(swig_c int", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3744,19 +4874,10 @@ class GO:public Language { Printv(f_go_wrappers, result_wrapper, NULL); } Printv(f_go_wrappers, "\n", NULL); - goout = Swig_typemap_lookup("godirectorout", n, "swig_r", NULL); + goout = goTypemapLookup("godirectorout", n, "swig_r"); } String *call = NewString(""); - - if (gccgo_flag) { - if (goout != NULL) { - Printv(call, "\tfunc() {\n", NULL); - } - Printv(call, "\tSwigCgocallBack()\n", NULL); - Printv(call, "\tdefer SwigCgocallBackDone()\n", NULL); - } - Printv(call, "\t", NULL); if (SwigType_type(result) != T_VOID) { @@ -3765,7 +4886,9 @@ class GO:public Language { Printv(call, result_wrapper, "(", NULL); } } - Printv(call, "p.", go_with_over_name, "(", NULL); + Printv(call, "swig_p.", go_with_over_name, "(", NULL); + + String *goincode = NewString(""); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3795,18 +4918,18 @@ class GO:public Language { Printv(ln, ")", NULL); } - String *goin = Getattr(p, "tmap:godirectorin"); + String *goin = goGetattr(p, "tmap:godirectorin"); if (goin == NULL) { Printv(call, ln, NULL); } else { String *ivar = NewString(""); Printf(ivar, "_swig_i_%d", i); String *itm = goType(p, pt); - Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, NULL); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, "\n", NULL); goin = Copy(goin); Replaceall(goin, "$input", ln); Replaceall(goin, "$result", ivar); - Printv(f_go_wrappers, goin, NULL); + Printv(goincode, goin, "\n", NULL); Delete(goin); Printv(call, ivar, NULL); Delete(ivar); @@ -3824,13 +4947,23 @@ class GO:public Language { } Printv(call, "\n", NULL); - if (gccgo_flag && goout != NULL) { - Printv(call, "\t}()\n", NULL); + if (gccgo_flag && !cgo_flag) { + if (goout != NULL) { + Printv(f_go_wrappers, "\tfunc() {\n", NULL); + } + Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL); + Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL); } + Printv(f_go_wrappers, "\tswig_p := swigDirectorLookup(swig_c).(*", director_struct_name, ")\n", NULL); + Printv(f_go_wrappers, goincode, NULL); Printv(f_go_wrappers, call, NULL); Delete(call); + if (gccgo_flag && !cgo_flag && goout != NULL) { + Printv(f_go_wrappers, "\t}()\n", NULL); + } + if (SwigType_type(result) != T_VOID) { if (goout == NULL) { Printv(f_go_wrappers, "\treturn swig_r\n", NULL); @@ -3839,7 +4972,7 @@ class GO:public Language { Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); Replaceall(goout, "$input", "swig_r"); Replaceall(goout, "$result", "swig_r_1"); - Printv(f_go_wrappers, goout, NULL); + Printv(f_go_wrappers, goout, "\n", NULL); Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); } } @@ -3851,284 +4984,426 @@ class GO:public Language { Delete(upcall_wname); Delete(upcall_gc_name); + Delete(go_with_over_name); + } - // Build the C++ functions. + if (!is_ignored || is_pure_virtual) { + // Declare the method for the director class. - if (!gccgo_flag) { - Printv(f_c_directors, "extern \"C\" void ", callback_wname, "(void*, int);\n", NULL); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); + String *decl = Swig_method_decl(rtype, Getattr(n, "decl"), Getattr(n, "name"), parms, 0, 0); + Printv(f_c_directors_h, " virtual ", decl, NULL); + Delete(decl); + + String *qname = NewString(""); + Printv(qname, "SwigDirector_", class_name, "::", Getattr(n, "name"), NULL); + decl = Swig_method_decl(rtype, Getattr(n, "decl"), qname, parms, 0, 0); + Printv(w->def, decl, NULL); + Delete(decl); + Delete(qname); + + String *throws = buildThrow(n); + if (throws) { + Printv(f_c_directors_h, " ", throws, NULL); + Printv(w->def, " ", throws, NULL); + Delete(throws); + } + + Printv(f_c_directors_h, ";\n", NULL); + + Printv(w->def, " {\n", NULL); + + if (SwigType_type(result) != T_VOID) { + Wrapper_add_local(w, "c_result", SwigType_lstr(result, "c_result")); + } + + if (!is_ignored) { + makeDirectorMethodWrapper(n, w, callback_name); + } else { + assert(is_pure_virtual); + Printv(w->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n", NULL); + if (SwigType_type(result) != T_VOID) { + String *retstr = SwigType_rcaststr(result, "c_result"); + Printv(w->code, " return ", retstr, ";\n", NULL); + Delete(retstr); + } + } + + Printv(w->code, "}", NULL); + + Replaceall(w->code, "$symname", symname); + Wrapper_print(w, f_c_directors); + } + + Delete(cn); + Delete(go_type_name); + Delete(director_struct_name); + Delete(interface_name); + Delete(callback_name); + Delete(upcall_name); + Delete(go_name); + DelWrapper(w); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * makeDirectorMethodWrapper + * + * Emit the function wrapper for a director method. + * ------------------------------------------------------------ */ + void makeDirectorMethodWrapper(Node *n, Wrapper *w, String *callback_name) { + if (cgo_flag) { + makeCgoDirectorMethodWrapper(n, w, callback_name); + return; + } + + ParmList *parms = Getattr(n, "wrap:parms"); + SwigType *result = Getattr(n, "type"); + + String *callback_wname = Swig_name_wrapper(callback_name); + Append(callback_wname, unique_id); + + if (!gccgo_flag) { + Printv(f_c_directors, "extern \"C\" void ", callback_wname, "(void*, int);\n", NULL); + } else { + Printv(f_c_directors, "extern \"C\" ", NULL); + + String *fnname = NewString(""); + Printv(fnname, callback_wname, "(int", NULL); + + Parm *p = parms; + while (p) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } + String *cg = gccgoCTypeForGoValue(p, Getattr(p, "type"), + Getattr(p, "lname")); + Printv(fnname, ", ", cg, NULL); + Delete(cg); + p = Getattr(p, "tmap:directorin:next"); + } + + Printv(fnname, ")", NULL); + + if (SwigType_type(result) == T_VOID) { + Printv(f_c_directors, "void ", fnname, NULL); } else { - Printv(f_c_directors, "extern \"C\" ", NULL); + String *tm = gccgoCTypeForGoValue(n, result, fnname); + Printv(f_c_directors, tm, NULL); + Delete(tm); + } + + Delete(fnname); + + Printv(f_c_directors, " __asm__(\"", go_prefix, ".", callback_name, "\");\n", NULL); + } - String *fnname = NewString(""); - Printv(fnname, callback_wname, "(void*", NULL); + if (!gccgo_flag) { + Printv(w->code, " struct {\n", NULL); + Printv(w->code, " intgo go_val;\n", NULL); - p = parms; - while (p) { - while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { - p = Getattr(p, "tmap:directorin:next"); - } - String *cg = gccgoCTypeForGoValue(p, Getattr(p, "type"), - Getattr(p, "lname")); - Printv(fnname, ", ", cg, NULL); - Delete(cg); + Parm *p = parms; + while (p) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { p = Getattr(p, "tmap:directorin:next"); } + String *ln = Getattr(p, "lname"); + String *cg = gcCTypeForGoValue(p, Getattr(p, "type"), ln); + Printv(w->code, " ", cg, ";\n", NULL); + Delete(cg); + p = Getattr(p, "tmap:directorin:next"); + } + if (SwigType_type(result) != T_VOID) { + Printv(w->code, " long : 0;\n", NULL); + String *rname = NewString(Swig_cresult_name()); + String *cg = gcCTypeForGoValue(n, result, rname); + Printv(w->code, " ", cg, ";\n", NULL); + Delete(cg); + Delete(rname); + } - Printv(fnname, ")", NULL); + Printv(w->code, " } SWIGSTRUCTPACKED swig_a;\n", NULL); + Printv(w->code, " swig_a.go_val = go_val;\n", NULL); - if (SwigType_type(result) == T_VOID) { - Printv(f_c_directors, "void ", fnname, NULL); + p = parms; + while (p) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } + String *tm = Getattr(p, "tmap:directorin"); + if (!tm) { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, + line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { - String *tm = gccgoCTypeForGoValue(n, result, fnname); - Printv(f_c_directors, tm, NULL); + tm = Copy(tm); + String *ln = Getattr(p, "lname"); + String *input = NewString(""); + Printv(input, "swig_a.", ln, NULL); + Setattr(p, "emit:directorinput", input); + Replaceall(tm, "$input", input); + Replaceall(tm, "$owner", "0"); + Delete(input); + Printv(w->code, "\t", tm, "\n", NULL); Delete(tm); } + p = Getattr(p, "tmap:directorin:next"); + } - Delete(fnname); + Printv(w->code, " crosscall2(", callback_wname, ", &swig_a, (int) sizeof swig_a);\n", NULL); - Printv(f_c_directors, " __asm__(\"", go_prefix, ".", callback_name, "\");\n", NULL); + /* Marshal outputs */ + for (p = parms; p;) { + String *tm; + if ((tm = Getattr(p, "tmap:directorargout"))) { + tm = Copy(tm); + Replaceall(tm, "$result", "jresult"); + Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } } - Delete(go_with_over_name); - } + if (SwigType_type(result) != T_VOID) { + String *result_str = NewString("c_result"); + String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); + if (!tm) { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use type %s as director method result\n", SwigType_str(result, 0)); + } else { + static const String *swig_a_result = NewStringf("swig_a.%s", Swig_cresult_name()); + Replaceall(tm, "$input", swig_a_result); + Replaceall(tm, "$result", "c_result"); + Printv(w->code, " ", tm, "\n", NULL); + String *retstr = SwigType_rcaststr(result, "c_result"); + Printv(w->code, " return ", retstr, ";\n", NULL); + Delete(retstr); + Delete(tm); + } + Delete(result_str); + } + + // The C wrapper code which calls the Go function. + Printv(f_gc_wrappers, "#pragma dynexport ", callback_wname, " ", callback_wname, "\n", NULL); + Printv(f_gc_wrappers, "#pragma cgo_export_static ", callback_wname, " ", callback_wname, "\n", NULL); + Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL); + Printv(f_gc_wrappers, "extern void \xc2\xb7", callback_name, "();\n", NULL); + Printv(f_gc_wrappers, "void\n", NULL); + Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL); + Printv(f_gc_wrappers, "{\n", NULL); + Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL); + Printv(f_gc_wrappers, "}\n\n", NULL); + } else { + if (SwigType_type(result) != T_VOID) { + String *r = NewString(Swig_cresult_name()); + String *tm = gccgoCTypeForGoValue(n, result, r); + Wrapper_add_local(w, r, tm); + Delete(tm); + Delete(r); + } - if (!is_ignored || is_pure_virtual) { - // Declare the method for the director class. + String *args = NewString(""); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type"); - String *decl = Swig_method_decl(rtype, Getattr(n, "decl"), Getattr(n, "name"), parms, 0, 0); - Printv(f_c_directors_h, " virtual ", decl, NULL); - Delete(decl); + Parm *p = parms; + while (p) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } - String *qname = NewString(""); - Printv(qname, "SwigDirector_", class_name, "::", Getattr(n, "name"), NULL); - decl = Swig_method_decl(rtype, Getattr(n, "decl"), qname, parms, 0, 0); - Printv(w->def, decl, NULL); - Delete(decl); - Delete(qname); + String *pn = NewString("g"); + Append(pn, Getattr(p, "lname")); + Setattr(p, "emit:directorinput", pn); - String *throws = buildThrow(n); - if (throws) { - Printv(f_c_directors_h, " ", throws, NULL); - Printv(w->def, " ", throws, NULL); - Delete(throws); - } + String *tm = gccgoCTypeForGoValue(n, Getattr(p, "type"), pn); + Wrapper_add_local(w, pn, tm); + Delete(tm); - Printv(f_c_directors_h, ";\n", NULL); + tm = Getattr(p, "tmap:directorin"); + if (!tm) { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, + line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); + } else { + tm = Copy(tm); + Replaceall(tm, "$input", pn); + Replaceall(tm, "$owner", 0); + Printv(w->code, " ", tm, "\n", NULL); + Delete(tm); - Printv(w->def, " {\n", NULL); + Printv(args, ", ", pn, NULL); + } + + p = Getattr(p, "tmap:directorin:next"); + } + Printv(w->code, " ", NULL); if (SwigType_type(result) != T_VOID) { - Wrapper_add_local(w, "c_result", SwigType_lstr(result, "c_result")); + Printv(w->code, Swig_cresult_name(), " = ", NULL); + } + Printv(w->code, callback_wname, "(go_val", args, ");\n", NULL); + + /* Marshal outputs */ + for (p = parms; p;) { + String *tm; + if ((tm = Getattr(p, "tmap:directorargout"))) { + tm = Copy(tm); + Replaceall(tm, "$result", "jresult"); + Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } } - if (!is_ignored) { - if (!gccgo_flag) { - Printv(w->code, " struct {\n", NULL); - Printv(w->code, " void *go_val;\n", NULL); + if (SwigType_type(result) != T_VOID) { + String *result_str = NewString("c_result"); + String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); + if (!tm) { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use type %s as director method result\n", SwigType_str(result, 0)); + } else { + Replaceall(tm, "$input", Swig_cresult_name()); + Replaceall(tm, "$result", "c_result"); + Printv(w->code, " ", tm, "\n", NULL); + String *retstr = SwigType_rcaststr(result, "c_result"); + Printv(w->code, " return ", retstr, ";\n", NULL); + Delete(retstr); + Delete(tm); + } + Delete(result_str); + } + } - p = parms; - while (p) { - while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { - p = Getattr(p, "tmap:directorin:next"); - } - String *ln = Getattr(p, "lname"); - String *cg = gcCTypeForGoValue(p, Getattr(p, "type"), ln); - Printv(w->code, " ", cg, ";\n", NULL); - Delete(cg); - p = Getattr(p, "tmap:directorin:next"); - } - if (SwigType_type(result) != T_VOID) { - Printv(w->code, " long : 0;\n", NULL); - String *rname = NewString(Swig_cresult_name()); - String *cg = gcCTypeForGoValue(n, result, rname); - Printv(w->code, " ", cg, ";\n", NULL); - Delete(cg); - Delete(rname); - } + Delete(callback_wname); + } - Printv(w->code, " } swig_a;\n", NULL); - Printv(w->code, " swig_a.go_val = go_val;\n", NULL); + /* ------------------------------------------------------------ + * makeDirectorMethodWrapper + * + * Emit the function wrapper for a director method for cgo. + * ------------------------------------------------------------ */ - p = parms; - while (p) { - while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { - p = Getattr(p, "tmap:directorin:next"); - } - String *tm = Getattr(p, "tmap:directorin"); - if (!tm) { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, - line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); - } else { - tm = Copy(tm); - String *ln = Getattr(p, "lname"); - String *input = NewString(""); - Printv(input, "swig_a.", ln, NULL); - Setattr(p, "emit:directorinput", input); - Replaceall(tm, "$input", input); - Replaceall(tm, "$owner", "0"); - Delete(input); - Printv(w->code, "\t", tm, "\n", NULL); - Delete(tm); - } - p = Getattr(p, "tmap:directorin:next"); - } + void makeCgoDirectorMethodWrapper(Node *n, Wrapper *w, String *callback_name) { + ParmList *parms = Getattr(n, "wrap:parms"); + SwigType *result = Getattr(n, "type"); - Printv(w->code, " crosscall2(", callback_wname, ", &swig_a, (int) sizeof swig_a);\n", NULL); - - /* Marshal outputs */ - for (p = parms; p;) { - String *tm; - if ((tm = Getattr(p, "tmap:directorargout"))) { - tm = Copy(tm); - Replaceall(tm, "$result", "jresult"); - Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); - Printv(w->code, tm, "\n", NIL); - Delete(tm); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } - } + Printv(f_c_directors, "extern \"C\" ", NULL); - if (SwigType_type(result) != T_VOID) { - String *result_str = NewString("c_result"); - String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); - if (!tm) { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use type %s as director method result\n", SwigType_str(result, 0)); - } else { - static const String *swig_a_result = NewStringf("swig_a.%s", Swig_cresult_name()); - Replaceall(tm, "$input", swig_a_result); - Replaceall(tm, "$result", "c_result"); - Printv(w->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(result, "c_result"); - Printv(w->code, " return ", retstr, ";\n", NULL); - Delete(retstr); - Delete(tm); - } - Delete(result_str); - } + String *fnname = Copy(callback_name); + Append(fnname, "(int"); - // The C wrapper code which calls the Go function. - Printv(f_gc_wrappers, "#pragma dynexport ", callback_wname, " ", callback_wname, "\n", NULL); - Printv(f_gc_wrappers, "#pragma cgo_export_static ", callback_wname, " ", callback_wname, "\n", NULL); - Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL); - Printv(f_gc_wrappers, "extern void \xc2\xb7", callback_name, "();\n", NULL); - Printv(f_gc_wrappers, "void\n", NULL); - Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL); - Printv(f_gc_wrappers, "{\n", NULL); - Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL); - Printv(f_gc_wrappers, "}\n\n", NULL); - } else { - if (SwigType_type(result) != T_VOID) { - String *r = NewString(Swig_cresult_name()); - String *tm = gccgoCTypeForGoValue(n, result, r); - Wrapper_add_local(w, r, tm); - Delete(tm); - Delete(r); - } + Parm *p = parms; + while (p) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } + String *cg = gcCTypeForGoValue(p, Getattr(p, "type"), Getattr(p, "lname")); + Printv(fnname, ", ", cg, NULL); + Delete(cg); + p = Getattr(p, "tmap:directorin:next"); + } - String *args = NewString(""); + Printv(fnname, ")", NULL); - p = parms; - while (p) { - while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { - p = Getattr(p, "tmap:directorin:next"); - } + if (SwigType_type(result) == T_VOID) { + Printv(f_c_directors, "void ", fnname, NULL); + } else { + String *tm = gcCTypeForGoValue(n, result, fnname); + Printv(f_c_directors, tm, NULL); + Delete(tm); + } - String *pn = NewString("g"); - Append(pn, Getattr(p, "lname")); - Setattr(p, "emit:directorinput", pn); + Delete(fnname); - String *tm = gccgoCTypeForGoValue(n, Getattr(p, "type"), pn); - Wrapper_add_local(w, pn, tm); - Delete(tm); + Printv(f_c_directors, ";\n", NULL); - tm = Getattr(p, "tmap:directorin"); - if (!tm) { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, - line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); - } else { - tm = Copy(tm); - Replaceall(tm, "$input", pn); - Replaceall(tm, "$owner", 0); - Printv(w->code, " ", tm, "\n", NULL); - Delete(tm); + if (SwigType_type(result) != T_VOID) { + String *r = NewString(Swig_cresult_name()); + String *tm = gcCTypeForGoValue(n, result, r); + Wrapper_add_local(w, r, tm); + Delete(tm); + Delete(r); + } - Printv(args, ", ", pn, NULL); - } + String *args = NewString(""); - p = Getattr(p, "tmap:directorin:next"); - } + p = parms; + while (p) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } - Printv(w->code, " ", NULL); - if (SwigType_type(result) != T_VOID) { - Printv(w->code, Swig_cresult_name(), " = ", NULL); - } - Printv(w->code, callback_wname, "(go_val", args, ");\n", NULL); - - /* Marshal outputs */ - for (p = parms; p;) { - String *tm; - if ((tm = Getattr(p, "tmap:directorargout"))) { - tm = Copy(tm); - Replaceall(tm, "$result", "jresult"); - Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); - Printv(w->code, tm, "\n", NIL); - Delete(tm); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } - } + String *pn = NewString("swig_"); + Append(pn, Getattr(p, "lname")); + Setattr(p, "emit:directorinput", pn); - if (SwigType_type(result) != T_VOID) { - String *result_str = NewString("c_result"); - String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); - if (!tm) { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use type %s as director method result\n", SwigType_str(result, 0)); - } else { - Replaceall(tm, "$input", Swig_cresult_name()); - Replaceall(tm, "$result", "c_result"); - Printv(w->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(result, "c_result"); - Printv(w->code, " return ", retstr, ";\n", NULL); - Delete(retstr); - Delete(tm); - } - Delete(result_str); - } - } + String *tm = gcCTypeForGoValue(p, Getattr(p, "type"), pn); + Wrapper_add_local(w, pn, tm); + Delete(tm); + + tm = Getattr(p, "tmap:directorin"); + if (!tm) { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, + line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { - assert(is_pure_virtual); - Printv(w->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n", NULL); - if (SwigType_type(result) != T_VOID) { - String *retstr = SwigType_rcaststr(result, "c_result"); - Printv(w->code, " return ", retstr, ";\n", NULL); - Delete(retstr); - } + tm = Copy(tm); + Replaceall(tm, "$input", pn); + Replaceall(tm, "$owner", 0); + Printv(w->code, " ", tm, "\n", NULL); + Delete(tm); + + Printv(args, ", ", pn, NULL); } - Printv(w->code, "}", NULL); + p = Getattr(p, "tmap:directorin:next"); + } - Replaceall(w->code, "$symname", symname); - Wrapper_print(w, f_c_directors); + Printv(w->code, " ", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(w->code, Swig_cresult_name(), " = ", NULL); } + Printv(w->code, callback_name, "(go_val", args, ");\n", NULL); - Delete(cn); - Delete(go_type_name); - Delete(director_struct_name); - Delete(interface_name); - Delete(upcall_name); - Delete(callback_wname); - Delete(go_name); - DelWrapper(w); + /* Marshal outputs */ + for (p = parms; p; ) { + String *tm; + if ((tm = Getattr(p, "tmap:directorargout"))) { + tm = Copy(tm); + Replaceall(tm, "$result", "jresult"); + Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); + Printv(w->code, tm, "\n", NULL); + Delete(tm); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } + } - return SWIG_OK; + if (SwigType_type(result) != T_VOID) { + String *result_str = NewString("c_result"); + String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); + if (!tm) { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use type %s as director method result\n", SwigType_str(result, 0)); + } else { + tm = Copy(tm); + Replaceall(tm, "$input", Swig_cresult_name()); + Replaceall(tm, "$result", "c_result"); + Printv(w->code, " ", tm, "\n", NULL); + String *retstr = SwigType_rcaststr(result, "c_result"); + Printv(w->code, " return ", retstr, ";\n", NULL); + Delete(retstr); + Delete(tm); + } + Delete(result_str); + } } + /* ------------------------------------------------------------ * classDirectorEnd * @@ -4139,7 +5414,8 @@ class GO:public Language { (void) n; Printv(f_c_directors_h, " private:\n", NULL); - Printv(f_c_directors_h, " void *go_val;\n", NULL); + Printv(f_c_directors_h, " intgo go_val;\n", NULL); + Printv(f_c_directors_h, " Swig_memory *swig_mem;\n", NULL); Printv(f_c_directors_h, "};\n\n", NULL); class_name = NULL; @@ -4386,9 +5662,9 @@ class GO:public Language { break; } - // If all the wrappers have the same type in this position, + // If all the overloads have the same type in this position, // we can omit the check. - SwigType *tm = goWrapperType(pj, Getattr(pj, "type"), true); + SwigType *tm = goOverloadType(pj, Getattr(pj, "type")); bool emitcheck = false; for (int k = 0; k < Len(coll) && !emitcheck; ++k) { Node *nk = Getitem(coll, k); @@ -4410,7 +5686,7 @@ class GO:public Language { break; } if (l == j) { - SwigType *tml = goWrapperType(pl, Getattr(pl, "type"), true); + SwigType *tml = goOverloadType(pl, Getattr(pl, "type")); if (Cmp(tm, tml) != 0) { emitcheck = true; } @@ -4428,7 +5704,7 @@ class GO:public Language { } fn = i + 1; - Printf(f_go_wrappers, "\t\tif _, ok := a[%d].(%s); !ok {\n", j, goType(pj, Getattr(pj, "type"))); + Printf(f_go_wrappers, "\t\tif _, ok := a[%d].(%s); !ok {\n", j, tm); Printf(f_go_wrappers, "\t\t\tgoto check_%d\n", fn); Printv(f_go_wrappers, "\t\t}\n", NULL); } @@ -4939,7 +6215,7 @@ class GO:public Language { Setattr(undefined_types, t, t); } else { String *nw = NewString(""); - Printv(nw, Getattr(cnmod, "name"), ".", ret, NULL); + Printv(nw, getModuleName(Getattr(cnmod, "name")), ".", ret, NULL); Delete(ret); ret = nw; } @@ -5048,6 +6324,118 @@ class GO:public Language { return ret; } + /* ---------------------------------------------------------------------- + * cgoTypeForGoValue() + * + * Given a SWIG type, return a string for the C type to use for the + * cgo wrapper code. This always returns a simple identifier, since + * it is used in Go code as C.name. + * + * This sets *c_struct_type if the C type uses a struct where the Go + * type uses a simple type. This is true for strings and slices. + * When this is true the Go code has to jump through unsafe hoops to + * pass the type checker. + * ---------------------------------------------------------------------- */ + + String *cgoTypeForGoValue(Node *n, SwigType *type, bool *c_struct_type) { + *c_struct_type = false; + + bool is_interface; + String *go_type = goTypeWithInfo(n, type, true, &is_interface); + if (is_interface) { + Delete(go_type); + return NewString("uintptr_t"); + } + if (Strcmp(go_type, "uintptr") == 0) { + Delete(go_type); + return NewString("uintptr_t"); + } + if (((char*)Char(go_type))[0] == '*') { + // Treat all pointers as void*. There is no meaningful type + // checking going on here anyhow, and that lets us avoid + // worrying about defining the base type of the pointer. + Delete(go_type); + return NewString("swig_voidp"); + } + + // Check for some Go types that are really pointers under the covers. + bool is_hidden_pointer = Strncmp(go_type, "func(", 5) == 0 || Strncmp(go_type, "map[", 4) == 0 || Strncmp(go_type, "chan ", 5) == 0; + + Delete(go_type); + + String *ct = Getattr(n, "emit:cgotype"); + if (ct) { + *c_struct_type = Getattr(n, "emit:cgotypestruct") ? true : false; + return Copy(ct); + } + + String *t = Copy(type); + if (SwigType_isarray(t)) { + SwigType_del_array(t); + SwigType_add_pointer(t); + } + + bool add_typedef = true; + + static int count; + ++count; + ct = NewStringf("swig_type_%d", count); + + String *gct = gcCTypeForGoValue(n, t, ct); + Delete(t); + + if (Strncmp(gct, "_gostring_", 10) == 0 || Strncmp(gct, "_goslice_", 9) == 0) { + *c_struct_type = true; + Setattr(n, "emit:cgotypestruct", type); + } else { + char *p = Strstr(gct, ct); + if (p != NULL && p > (char*)Char(gct) && p[-1] == '*' && p[Len(ct)] == '\0') { + // Treat all pointers as void*. See above. + Delete(ct); + --count; + ct = NewString("swig_voidp"); + add_typedef = false; + if (is_hidden_pointer) { + // A Go type that is really a pointer, like func, map, chan, + // is being represented in C by a pointer. This is fine, + // but we have to memcpy the type rather than simply + // converting it. + *c_struct_type = true; + Setattr(n, "emit:cgotypestruct", type); + } + } + + if (Strncmp(gct, "bool ", 5) == 0) { + // Change the C++ type bool to the C type _Bool. + Replace(gct, "bool", "_Bool", DOH_REPLACE_FIRST); + } + if (Strncmp(gct, "intgo ", 6) == 0) { + // We #define intgo to swig_intgo for the cgo comment. + Replace(gct, "intgo", "swig_intgo", DOH_REPLACE_FIRST); + } + p = Strstr(gct, ct); + if (p != NULL && p > (char*)Char(gct) && p[-1] == ' ' && p[Len(ct)] == '\0') { + String *q = NewStringWithSize(gct, Len(gct) - Len(ct) - 1); + if (validIdentifier(q)) { + // This is a simple type name, and we can use it directly. + Delete(ct); + --count; + ct = q; + add_typedef = false; + } + } + } + if (add_typedef) { + Printv(f_cgo_comment_typedefs, "typedef ", gct, ";\n", NULL); + } + + Setattr(n, "emit:cgotype", ct); + + Delete(gct); + + return Copy(ct); + } + /* ---------------------------------------------------------------------- * goWrapperType() * @@ -5090,6 +6478,46 @@ class GO:public Language { return ret; } + /* ---------------------------------------------------------------------- + * goOverloadType() + * + * Given a type, return the Go type to use when dispatching of + * overloaded functions. This is normally just the usual Go type. + * However, for a C++ class, the usual Go type is an interface type. + * And if that interface type represents a C++ type that SWIG does + * not know about, then the interface type generated for any C++ + * class will match that interface. So for that case, we match on + * the underlying integer type. + * + * It has to work this way so that we can handle a derived type of a + * %ignore'd type. It's unlikely that anybody will have a value of + * an undefined type, but we support it because it worked in the + * past. + * ---------------------------------------------------------------------- */ + + String *goOverloadType(Node *n, SwigType *type) { + SwigType *ty = SwigType_typedef_resolve_all(type); + while (true) { + if (SwigType_ispointer(ty)) { + SwigType_del_pointer(ty); + } else if (SwigType_isarray(ty)) { + SwigType_del_array(ty); + } else if (SwigType_isreference(ty)) { + SwigType_del_reference(ty); + } else if (SwigType_isqualifier(ty)) { + SwigType_del_qualifier(ty); + } else { + break; + } + } + + if (Getattr(undefined_types, ty) && !Getattr(defined_types, ty)) { + return goWrapperType(n, type, true); + } + + return goType(n, type); + } + /* ---------------------------------------------------------------------- * goCPointerType() * @@ -5125,7 +6553,7 @@ class GO:public Language { Append(ret, ex); } else { ret = NewString(""); - Printv(ret, Getattr(cnmod, "name"), ".Swigcptr", ex, NULL); + Printv(ret, getModuleName(Getattr(cnmod, "name")), ".Swigcptr", ex, NULL); } } Delete(ty); @@ -5160,6 +6588,7 @@ class GO:public Language { bool is_member = Strcmp(gt, "_swig_memberptr") == 0; bool is_complex64 = Strcmp(gt, "complex64") == 0; bool is_complex128 = Strcmp(gt, "complex128") == 0; + bool is_bool = false; bool is_int8 = false; bool is_int16 = false; bool is_int = Strcmp(gt, "int") == 0 || Strcmp(gt, "uint") == 0; @@ -5167,7 +6596,10 @@ class GO:public Language { bool is_int64 = false; bool is_float32 = false; bool is_float64 = false; - if ((n != NULL && Getattr(n, "tmap:gotype") != NULL) || hasGoTypemap(n, type)) { + + bool has_typemap = (n != NULL && Getattr(n, "tmap:gotype") != NULL) || hasGoTypemap(n, type); + if (has_typemap) { + is_bool = Strcmp(gt, "bool") == 0; is_int8 = Strcmp(gt, "int8") == 0 || Strcmp(gt, "uint8") == 0 || Strcmp(gt, "byte") == 0; is_int16 = Strcmp(gt, "int16") == 0 || Strcmp(gt, "uint16") == 0; is_int32 = Strcmp(gt, "int32") == 0 || Strcmp(gt, "uint32") == 0; @@ -5216,7 +6648,7 @@ class GO:public Language { return ret; } else { SwigType *t = SwigType_typedef_resolve_all(type); - if (SwigType_isreference(t)) { + if (!has_typemap && SwigType_isreference(t)) { // A const reference to a known type, or to a pointer, is not // mapped to a pointer. SwigType_del_reference(t); @@ -5254,7 +6686,9 @@ class GO:public Language { } Delete(t); - if (is_int8) { + if (is_bool) { + ret = NewString("bool "); + } else if (is_int8) { ret = NewString("char "); } else if (is_int16) { ret = NewString("short "); @@ -5275,7 +6709,7 @@ class GO:public Language { } Append(ret, tail); - if (SwigType_isreference(type)) { + if (!has_typemap && SwigType_isreference(type)) { Append(ret, "* "); } Append(ret, name); @@ -5420,6 +6854,47 @@ class GO:public Language { return storage && Strcmp(storage, "friend") == 0; } + /* ---------------------------------------------------------------------- + * goGetattr + * + * Fetch an attribute from a node but return NULL if it is the empty string. + * ---------------------------------------------------------------------- */ + Node *goGetattr(Node *n, const char *name) { + Node *ret = Getattr(n, name); + if (ret != NULL && Len(ret) == 0) { + ret = NULL; + } + return ret; + } + + /* ---------------------------------------------------------------------- + * goTypemapLookup + * + * Look up a typemap but return NULL if it is the empty string. + * ---------------------------------------------------------------------- */ + String *goTypemapLookup(const char *name, Node *node, const char *lname) { + String *ret = Swig_typemap_lookup(name, node, lname, NULL); + if (ret != NULL && Len(ret) == 0) { + ret = NULL; + } + return ret; + } + + /* ---------------------------------------------------------------------- + * getModuleName + * + * Return the name of a module. This is different from module path: + * "some/path/to/module" -> "module". + * ---------------------------------------------------------------------- */ + + String *getModuleName(String *module_path) { + char *suffix = strrchr(Char(module_path), '/'); + if (suffix == NULL) { + return module_path; + } + return Str(suffix + 1); + } + }; /* class GO */ /* ----------------------------------------------------------------------------- @@ -5440,6 +6915,7 @@ extern "C" Language *swig_go(void) { // Usage message. const char * const GO::usage = "\ Go Options (available with -go)\n\ + -cgo - Generate cgo input files\n\ -gccgo - Generate code for gccgo rather than 6g/8g\n\ -go-pkgpath

    - Like gccgo -fgo-pkgpath option\n\ -go-prefix

    - Like gccgo -fgo-prefix option\n\ diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 1c135b53d03..7b42ff94faa 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -322,8 +322,7 @@ class GUILE:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGGUILE\n"); + Printf(f_runtime, "\n\n#ifndef SWIGGUILE\n#define SWIGGUILE\n#endif\n\n"); /* Write out directives and declarations */ @@ -1300,13 +1299,13 @@ class GUILE:public Language { char *name = GetChar(n, "name"); char *iname = GetChar(n, "sym:name"); SwigType *type = Getattr(n, "type"); - String *value = Getattr(n, "value"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); int constasvar = GetFlag(n, "feature:constasvar"); String *proc_name; String *var_name; - String *rvalue; Wrapper *f; SwigType *nctype; String *tm; @@ -1334,23 +1333,14 @@ class GUILE:public Language { } // See if there's a typemap - bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0); - if (SwigType_type(nctype) == T_STRING) { - rvalue = NewStringf("\"%s\"", value); - } else if (SwigType_type(nctype) == T_CHAR && !is_enum_item) { - rvalue = NewStringf("\'%s\'", value); - } else { - rvalue = NewString(value); - } - if ((tm = Swig_typemap_lookup("constant", n, name, 0))) { - Replaceall(tm, "$source", rvalue); - Replaceall(tm, "$value", rvalue); + Replaceall(tm, "$source", value); + Replaceall(tm, "$value", value); Replaceall(tm, "$target", name); Printv(f_header, tm, "\n", NIL); } else { // Create variable and assign it a value - Printf(f_header, "static %s = (%s)(%s);\n", SwigType_str(type, var_name), SwigType_str(type, 0), rvalue); + Printf(f_header, "static %s = (%s)(%s);\n", SwigType_str(type, var_name), SwigType_str(type, 0), value); } { /* Hack alert: will cleanup later -- Dave */ @@ -1370,7 +1360,6 @@ class GUILE:public Language { Delete(var_name); Delete(nctype); Delete(proc_name); - Delete(rvalue); DelWrapper(f); return SWIG_OK; } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 82ecb41a45a..afe8ca8413c 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -425,7 +425,7 @@ class JAVA:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n#define SWIGJAVA\n"); + Printf(f_runtime, "\n\n#ifndef SWIGJAVA\n#define SWIGJAVA\n#endif\n\n"); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); @@ -481,6 +481,7 @@ class JAVA:public Language { if (directorsEnabled()) { // Insert director runtime into the f_runtime file (make it occur before %header section) + Swig_insert_file("director_common.swg", f_runtime); Swig_insert_file("director.swg", f_runtime); } // Generate the intermediary class @@ -1787,7 +1788,7 @@ class JAVA:public Language { } else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) { Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java. " - "Perhaps you need one of the 'replace' or 'notderived' attributes in the csbase typemap?\n", typemap_lookup_type, pure_baseclass); + "Perhaps you need one of the 'replace' or 'notderived' attributes in the javabase typemap?\n", typemap_lookup_type, pure_baseclass); } // Pure Java interfaces @@ -1874,40 +1875,33 @@ class JAVA:public Language { // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { - String *smartptr = Getattr(n, "feature:smartptr"); - String *upcast_method = Swig_name_member(getNSpace(), getClassPrefix(), smartptr != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast"); + SwigType *smart = Swig_cparse_smartptr(n); + String *upcast_method = Swig_name_member(getNSpace(), getClassPrefix(), smart != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast"); String *jniname = makeValidJniName(upcast_method); String *wname = Swig_name_wrapper(jniname); Printf(imclass_cppcasts_code, " public final static native long %s(long jarg1);\n", upcast_method); - if (smartptr) { - SwigType *spt = Swig_cparse_type(smartptr); - if (spt) { - SwigType *smart = SwigType_typedef_resolve_all(spt); - Delete(spt); - SwigType *bsmart = Copy(smart); - SwigType *rclassname = SwigType_typedef_resolve_all(c_classname); - SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass); - Replaceall(bsmart, rclassname, rbaseclass); - Delete(rclassname); - Delete(rbaseclass); - String *smartnamestr = SwigType_namestr(smart); - String *bsmartnamestr = SwigType_namestr(bsmart); - Printv(upcasts_code, - "SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n", - " jlong baseptr = 0;\n" - " ", smartnamestr, " *argp1;\n" - " (void)jenv;\n" - " (void)jcls;\n" - " argp1 = *(", smartnamestr, " **)&jarg1;\n" - " *(", bsmartnamestr, " **)&baseptr = argp1 ? new ", bsmartnamestr, "(*argp1) : 0;\n" - " return baseptr;\n" - "}\n", "\n", NIL); - Delete(bsmartnamestr); - Delete(smartnamestr); - Delete(bsmart); - } else { - Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, c_classname); - } + if (smart) { + SwigType *bsmart = Copy(smart); + SwigType *rclassname = SwigType_typedef_resolve_all(c_classname); + SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass); + Replaceall(bsmart, rclassname, rbaseclass); + Delete(rclassname); + Delete(rbaseclass); + String *smartnamestr = SwigType_namestr(smart); + String *bsmartnamestr = SwigType_namestr(bsmart); + Printv(upcasts_code, + "SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n", + " jlong baseptr = 0;\n" + " ", smartnamestr, " *argp1;\n" + " (void)jenv;\n" + " (void)jcls;\n" + " argp1 = *(", smartnamestr, " **)&jarg1;\n" + " *(", bsmartnamestr, " **)&baseptr = argp1 ? new ", bsmartnamestr, "(*argp1) : 0;\n" + " return baseptr;\n" + "}\n", "\n", NIL); + Delete(bsmartnamestr); + Delete(smartnamestr); + Delete(bsmart); } else { Printv(upcasts_code, "SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n", @@ -1921,6 +1915,7 @@ class JAVA:public Language { Delete(wname); Delete(jniname); Delete(upcast_method); + Delete(smart); } Delete(baseclass); } @@ -3427,7 +3422,7 @@ class JAVA:public Language { Printf(f_runtime, "namespace Swig {\n"); Printf(f_runtime, " namespace {\n"); Printf(f_runtime, " jclass jclass_%s = NULL;\n", imclass_name); - Printf(f_runtime, " jmethodID director_methids[%d];\n", n_methods); + Printf(f_runtime, " jmethodID director_method_ids[%d];\n", n_methods); Printf(f_runtime, " }\n"); Printf(f_runtime, "}\n"); @@ -3444,8 +3439,8 @@ class JAVA:public Language { Printf(w->code, "Swig::jclass_%s = (jclass) jenv->NewGlobalRef(jcls);\n", imclass_name); Printf(w->code, "if (!Swig::jclass_%s) return;\n", imclass_name); Printf(w->code, "for (i = 0; i < (int) (sizeof(methods)/sizeof(methods[0])); ++i) {\n"); - Printf(w->code, " Swig::director_methids[i] = jenv->GetStaticMethodID(jcls, methods[i].method, methods[i].signature);\n"); - Printf(w->code, " if (!Swig::director_methids[i]) return;\n"); + Printf(w->code, " Swig::director_method_ids[i] = jenv->GetStaticMethodID(jcls, methods[i].method, methods[i].signature);\n"); + Printf(w->code, " if (!Swig::director_method_ids[i]) return;\n"); Printf(w->code, "}\n"); Printf(w->code, "}\n"); @@ -3485,7 +3480,7 @@ class JAVA:public Language { "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, " "jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni); - if (Len(smartptr)) { + if (smartptr) { Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", smartptr, smartptr); Printf(code_wrap->code, " (void)jcls;\n"); Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n"); @@ -4099,7 +4094,7 @@ class JAVA:public Language { if (!is_void) Printf(w->code, "jresult = (%s) ", c_ret_type); - Printf(w->code, "jenv->%s(Swig::jclass_%s, Swig::director_methids[%s], %s);\n", methop, imclass_name, methid, jupcall_args); + Printf(w->code, "jenv->%s(Swig::jclass_%s, Swig::director_method_ids[%s], %s);\n", methop, imclass_name, methid, jupcall_args); // Generate code to handle any Java exception thrown by director delegation directorExceptHandler(n, catches_list ? catches_list : throw_parm_list, w); @@ -4488,7 +4483,7 @@ class JAVA:public Language { Printf(f_directors_h, " return (n < %d ? swig_override[n] : false);\n", n_methods); Printf(f_directors_h, " }\n"); Printf(f_directors_h, "protected:\n"); - Printf(f_directors_h, " bool swig_override[%d];\n", n_methods); + Printf(f_directors_h, " Swig::BoolArray<%d> swig_override;\n", n_methods); /* Emit the code to look up the class's methods, initialize the override array */ diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index 0c3f02a7552..6f0fb3afda8 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -1100,7 +1100,7 @@ int JSEmitter::emitSetter(Node *n, bool is_member, bool is_static) { * ----------------------------------------------------------------------------- */ int JSEmitter::emitConstant(Node *n) { - // HACK: somehow it happened under OSX that before everything started + // HACK: somehow it happened under Mac OS X that before everything started // a lot of SWIG internal constants were emitted // This didn't happen on other platforms yet... // we ignore those premature definitions @@ -1792,6 +1792,7 @@ int JSCEmitter::emitNamespaces() { namespace_definition.replace("$jsglobalvariables", variables) .replace("$jsglobalfunctions", functions) .replace("$jsnspace", name_mangled) + .replace("$jsmangledname", name_mangled) .pretty_print(f_wrap_cpp); Template t_createNamespace(getTemplate("jsc_nspace_definition")); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 3efd4e425ea..aa81581f06d 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -940,7 +940,7 @@ int Language::cDeclaration(Node *n) { } if (!validIdentifier(symname)) { - Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", symname); + Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", SwigType_namestr(symname)); return SWIG_NOWRAP; } @@ -3676,14 +3676,26 @@ int Language::abstractClassTest(Node *n) { return 0; if (Getattr(n, "allocate:nonew")) return 1; + + // A class cannot be instantiated if one of its bases has a private destructor + // Note that if the above does not hold the class can be instantiated if its own destructor is private + List *bases = Getattr(n, "bases"); + if (bases) { + for (int i = 0; i < Len(bases); i++) { + Node *b = Getitem(bases, i); + if (GetFlag(b, "allocate:private_destructor")) + return 1; + } + } + /* now check for the rest */ List *abstracts = Getattr(n, "abstracts"); if (!abstracts) return 0; int labs = Len(abstracts); #ifdef SWIG_DEBUG - List *bases = Getattr(n, "allbases"); - Printf(stderr, "testing %s %d %d\n", Getattr(n, "name"), labs, Len(bases)); + List *allbases = Getattr(n, "allbases"); + Printf(stderr, "testing %s %d %d\n", Getattr(n, "name"), labs, Len(allbases)); #endif if (!labs) return 0; /*strange, but need to be fixed */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 8211fb31761..12e8d10ba32 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -329,8 +329,7 @@ class LUA:public Language { /* Standard stuff for the SWIG runtime section */ Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGLUA\n"); + Printf(f_runtime, "\n\n#ifndef SWIGLUA\n#define SWIGLUA\n#endif\n\n"); emitLuaFlavor(f_runtime); diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index aa0d7d589cb..632a001ac32 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -131,8 +131,8 @@ static const char *usage3 = (const char *) "\ static const char *usage4 = (const char *) "\ -O - Enable the optimization options: \n\ -fastdispatch -fvirtual \n\ - -o - Set name of the output file to \n\ - -oh - Set name of the output header file to \n\ + -o - Set name of C/C++ output file to \n\ + -oh - Set name of C++ output header file for directors to \n\ -outcurrentdir - Set default output dir to current dir instead of input file's path\n\ -outdir

    - Set language specific files output directory to \n\ -pcreversion - Display PCRE version information\n\ @@ -595,7 +595,7 @@ void SWIG_getoptions(int argc, char *argv[]) { Swig_filename_correct(outfile_name); if (!outfile_name_h || !dependencies_file) { char *ext = strrchr(Char(outfile_name), '.'); - String *basename = ext ? NewStringWithSize(Char(outfile_name), Char(ext) - Char(outfile_name)) : NewString(outfile_name); + String *basename = ext ? NewStringWithSize(Char(outfile_name), (int)(Char(ext) - Char(outfile_name))) : NewString(outfile_name); if (!dependencies_file) { dependencies_file = NewStringf("%s.%s", basename, depends_extension); } @@ -899,7 +899,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { String *vers = NewString("SWIG_VERSION 0x"); int count = 0; while (token) { - int len = strlen(token); + int len = (int)strlen(token); assert(len == 1 || len == 2); Printf(vers, "%s%s", (len == 1) ? "0" : "", token); token = strtok(NULL, "."); @@ -1221,7 +1221,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { Printf(stdout, "debug-top stage 3\n"); Swig_print_tree(top); } - if (dump_module & STAGE3) { + if (top && (dump_module & STAGE3)) { Printf(stdout, "debug-module stage 3\n"); Swig_print_tree(Getattr(top, "module")); } @@ -1230,7 +1230,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { Printf(stdout, "Generating wrappers...\n"); } - if (dump_classes) { + if (top && dump_classes) { Hash *classes = Getattr(top, "classes"); if (classes) { Printf(stdout, "Classes\n"); diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index d9a0c922b3a..307c7857d23 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -958,9 +958,7 @@ MODULA3(): Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGMODULA3\n"); - Printf(f_runtime, "\n"); + Printf(f_runtime, "\n\n#ifndef SWIGMODULA3\n#define SWIGMODULA3\n#endif\n\n"); Swig_name_register("wrapper", "Modula3_%f"); if (old_variable_names) { diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index ed9641b3049..dd3aecc40be 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -150,9 +150,7 @@ class MZSCHEME:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGMZSCHEME\n"); - Printf(f_runtime, "\n"); + Printf(f_runtime, "\n\n#ifndef SWIGMZSCHEME\n#define SWIGMZSCHEME\n#endif\n\n"); module = Getattr(n, "name"); diff --git a/Source/Modules/nested.cxx b/Source/Modules/nested.cxx index c4ab6a8ea1b..0fcd5ad1820 100644 --- a/Source/Modules/nested.cxx +++ b/Source/Modules/nested.cxx @@ -340,6 +340,8 @@ static void insertNodeAfter(Node *n, Node *c) { } void Swig_nested_name_unnamed_c_structs(Node *n) { + if (!n) + return; if (!classhash) classhash = Getattr(n, "classes"); Node *c = firstChild(n); @@ -427,6 +429,8 @@ static void remove_outer_class_reference(Node *n) { } void Swig_nested_process_classes(Node *n) { + if (!n) + return; Node *c = firstChild(n); while (c) { Node *next = nextSibling(c); diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index ac73c1f0c73..1c5ceefaa67 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -269,8 +269,8 @@ class OCAML:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGOCAML\n"); + Printf(f_runtime, "\n\n#ifndef SWIGOCAML\n#define SWIGOCAML\n#endif\n\n"); + Printf(f_runtime, "#define SWIG_MODULE \"%s\"\n", module); /* Module name */ Printf(f_mlbody, "let module_name = \"%s\"\n", module); @@ -325,6 +325,7 @@ class OCAML:public Language { if (directorsEnabled()) { // Insert director runtime into the f_runtime file (make it occur before %header section) + Swig_insert_file("director_common.swg", f_runtime); Swig_insert_file("director.swg", f_runtime); } @@ -619,9 +620,9 @@ class OCAML:public Language { } /* if the object is a director, and the method call originated from its - * underlying python object, resolve the call by going up the c++ - * inheritance chain. otherwise try to resolve the method in python. - * without this check an infinite loop is set up between the director and + * underlying ocaml object, resolve the call by going up the c++ + * inheritance chain. otherwise try to resolve the method in ocaml. + * without this check an infinite loop is set up between the director and * shadow class method calls. */ @@ -989,7 +990,7 @@ class OCAML:public Language { find_marker += strlen("(*Stream:"); if (next) { - int num_chars = next - find_marker; + int num_chars = (int)(next - find_marker); String *stream_name = NewString(find_marker); Delslice(stream_name, num_chars, Len(stream_name)); File *fout = Swig_filebyname(stream_name); @@ -1000,7 +1001,7 @@ class OCAML:public Language { if (!following) following = next + strlen(next); String *chunk = NewString(next); - Delslice(chunk, following - next, Len(chunk)); + Delslice(chunk, (int)(following - next), Len(chunk)); Printv(fout, chunk, NIL); } } diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 12903166cc1..37cfeee6425 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -19,8 +19,10 @@ static String *op_prefix = 0; static const char *usage = "\ Octave Options (available with -octave)\n\ + -cppcast - Enable C++ casting operators (default)\n\ -globals - Set used to access C global variables [default: 'cvar']\n\ Use '.' to load C global variables into module namespace\n\ + -nocppcast - Disable C++ casting operators\n\ -opprefix - Prefix for global operator functions [default: 'op_']\n\ \n"; @@ -90,6 +92,8 @@ class OCTAVE:public Language { } virtual void main(int argc, char *argv[]) { + int cppcast = 1; + for (int i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-help") == 0) { @@ -112,6 +116,12 @@ class OCTAVE:public Language { } else { Swig_arg_error(); } + } else if (strcmp(argv[i], "-cppcast") == 0) { + cppcast = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nocppcast") == 0) { + cppcast = 0; + Swig_mark_arg(i); } } } @@ -120,6 +130,8 @@ class OCTAVE:public Language { global_name = NewString("cvar"); if (!op_prefix) op_prefix = NewString("op_"); + if(cppcast) + Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); SWIG_library_directory("octave"); Preprocessor_define("SWIGOCTAVE 1", 0); @@ -182,8 +194,8 @@ class OCTAVE:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGOCTAVE\n"); + Printf(f_runtime, "\n\n#ifndef SWIGOCTAVE\n#define SWIGOCTAVE\n#endif\n\n"); + Printf(f_runtime, "#define SWIG_name_d \"%s\"\n", module); Printf(f_runtime, "#define SWIG_name %s\n", module); @@ -216,11 +228,13 @@ class OCTAVE:public Language { if (Len(docs)) emit_doc_texinfo(); - if (directorsEnabled()) + if (directorsEnabled()) { + Swig_insert_file("director_common.swg", f_runtime); Swig_insert_file("director.swg", f_runtime); + } Printf(f_init, "return true;\n}\n"); - Printf(s_global_tab, "{0,0,0,0,0}\n};\n"); + Printf(s_global_tab, "{0,0,0,0,0,0}\n};\n"); Printv(f_wrappers, s_global_tab, NIL); SwigType_emit_type_table(f_runtime, f_wrappers); @@ -952,7 +966,14 @@ class OCTAVE:public Language { SwigType *t = Copy(Getattr(n, "name")); SwigType_add_pointer(t); + // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) + SwigType *smart = Swig_cparse_smartptr(n); String *wrap_class = NewStringf("&_wrap_class_%s", class_name); + if (smart) { + SwigType_add_pointer(smart); + SwigType_remember_clientdata(smart, wrap_class); + } + //String *wrap_class = NewStringf("&_wrap_class_%s", class_name); SwigType_remember_clientdata(t, wrap_class); int use_director = Swig_directorclass(n); @@ -977,7 +998,7 @@ class OCTAVE:public Language { Delete(cnameshdw); } - Printf(s_members_tab, "{0,0,0,0}\n};\n"); + Printf(s_members_tab, "{0,0,0,0,0,0}\n};\n"); Printv(f_wrappers, s_members_tab, NIL); String *base_class_names = NewString(""); @@ -1031,6 +1052,7 @@ class OCTAVE:public Language { Delete(base_class); Delete(base_class_names); + Delete(smart); Delete(t); Delete(s_members_tab); s_members_tab = 0; @@ -1354,7 +1376,7 @@ class OCTAVE:public Language { SwigType_namestr(name)); } } else { - // attach typemaps to arguments (C/C++ -> Python) + // attach typemaps to arguments (C/C++ -> Octave) String *parse_args = NewString(""); Swig_director_parms_fixup(l); diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index e95ef557f7b..dd3ca497241 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -158,12 +158,12 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { String *t2 = Getattr(p2, "tmap:typecheck:precedence"); if ((!t1) && (!nodes[i].error)) { Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), - "Overloaded method %s not supported (no type checking rule for '%s').\n", + "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0)); nodes[i].error = 1; } else if ((!t2) && (!nodes[j].error)) { Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s not supported (no type checking rule for '%s').\n", + "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0)); nodes[j].error = 1; } diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 224c4852e75..9182ce46b0f 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -13,8 +13,6 @@ #include "swigmod.h" #include "cparse.h" -static int treduce = SWIG_cparse_template_reduce(0); - #include static const char *usage = "\ @@ -327,8 +325,8 @@ class PERL5:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGPERL\n"); + Printf(f_runtime, "\n\n#ifndef SWIGPERL\n#define SWIGPERL\n#endif\n\n"); + if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); } @@ -470,6 +468,7 @@ class PERL5:public Language { if (directorsEnabled()) { // Insert director runtime into the f_runtime file (make it occur before %header section) + Swig_insert_file("director_common.swg", f_runtime); Swig_insert_file("director.swg", f_runtime); } @@ -1046,21 +1045,9 @@ class PERL5:public Language { String *tt = Getattr(n, "tmap:varout:type"); if (tt) { - String *tm = NewStringf("&SWIGTYPE%s", SwigType_manglestr(t)); - if (Replaceall(tt, "$1_descriptor", tm)) { - SwigType_remember(t); - } - Delete(tm); - SwigType *st = Copy(t); - SwigType_add_pointer(st); - tm = NewStringf("&SWIGTYPE%s", SwigType_manglestr(st)); - if (Replaceall(tt, "$&1_descriptor", tm)) { - SwigType_remember(st); - } - Delete(tm); - Delete(st); + tt = NewStringf("&%s", tt); } else { - tt = (String *) "0"; + tt = NewString("0"); } /* Now add symbol to the PERL interpreter */ if (GetFlag(n, "feature:immutable")) { @@ -1088,6 +1075,7 @@ class PERL5:public Language { if (export_all) Printf(exported, "$%s ", iname); + Delete(tt); DelWrapper(setf); DelWrapper(getf); Delete(getname); @@ -1996,8 +1984,8 @@ class PERL5:public Language { Printf(f_directors_h, " return (iv != swig_inner.end() ? iv->second : false);\n"); Printf(f_directors_h, " }\n"); - Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool val) const {\n"); - Printf(f_directors_h, " swig_inner[swig_protected_method_name] = val;\n"); + Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool swig_val) const {\n"); + Printf(f_directors_h, " swig_inner[swig_protected_method_name] = swig_val;\n"); Printf(f_directors_h, " }\n"); Printf(f_directors_h, "private:\n"); Printf(f_directors_h, " mutable std::map swig_inner;\n"); @@ -2254,7 +2242,7 @@ class PERL5:public Language { if (SwigType_isreference(ptype)) { Insert(ppname, 0, "&"); } - /* if necessary, cast away const since Python doesn't support it! */ + /* if necessary, cast away const since Perl doesn't support it! */ if (SwigType_isconst(nptype)) { nonconst = NewStringf("nc_tmp_%s", pname); String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index a2f0e36877d..fbece27150e 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -190,7 +190,7 @@ class PHP : public Language { p = strchr(p, '"'); if (p) { ++p; - Insert(action, p - Char(action), " TSRMLS_CC"); + Insert(action, (int)(p - Char(action)), " TSRMLS_CC"); } } } @@ -320,9 +320,7 @@ class PHP : public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGPHP\n"); - Printf(f_runtime, "\n"); + Printf(f_runtime, "\n\n#ifndef SWIGPHP\n#define SWIGPHP\n#endif\n\n"); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); @@ -473,6 +471,7 @@ class PHP : public Language { if (directorsEnabled()) { // Insert director runtime + Swig_insert_file("director_common.swg", s_header); Swig_insert_file("director.swg", s_header); } @@ -638,7 +637,7 @@ class PHP : public Language { Printv(f_begin, all_cs_entry, "\n\n", s_arginfo, "\n\n", s_entry, " SWIG_ZEND_NAMED_FE(swig_", module, "_alter_newobject,_wrap_swig_", module, "_alter_newobject,NULL)\n" " SWIG_ZEND_NAMED_FE(swig_", module, "_get_newobject,_wrap_swig_", module, "_get_newobject,NULL)\n" - "{NULL, NULL, NULL}\n};\n\n", NIL); + " ZEND_FE_END\n};\n\n", NIL); Printv(f_begin, s_init, NIL); Delete(s_header); Delete(s_wrappers); @@ -1721,7 +1720,7 @@ class PHP : public Language { Printf(output, "\t\t\treturn new %s%s($r);\n", prefix, Getattr(classLookup(d), "sym:name")); } else { Printf(output, "\t\t\t$c = new stdClass();\n"); - Printf(output, "\t\t\t$c->"SWIG_PTR" = $r;\n"); + Printf(output, "\t\t\t$c->" SWIG_PTR " = $r;\n"); Printf(output, "\t\t\treturn $c;\n"); } Printf(output, "\t\t}\n\t\treturn $r;\n"); @@ -1731,7 +1730,8 @@ class PHP : public Language { } } else { Printf(output, "\t\tif (!is_resource($r)) return $r;\n"); - Printf(output, "\t\tswitch (get_resource_type($r)) {\n"); + String *wrapobj = NULL; + String *common = NULL; Iterator i = First(ret_types); while (i.item) { SwigType *ret_type = i.item; @@ -1751,22 +1751,43 @@ class PHP : public Language { continue; } } - Printf(output, "\t\t"); - if (i.item) { - Printf(output, "case '%s': ", mangled); - } else { - Printf(output, "default: "); - } const char *classname = GetChar(class_node, "sym:name"); if (!classname) classname = GetChar(class_node, "name"); + String * action = NewStringEmpty(); if (classname) - Printf(output, "return new %s%s($r);\n", prefix, classname); + Printf(action, "return new %s%s($r);\n", prefix, classname); else - Printf(output, "return $r;\n"); + Printf(action, "return $r;\n"); + if (!wrapobj) { + wrapobj = NewString("\t\tswitch (get_resource_type($r)) {\n"); + common = action; + } else { + if (common && Cmp(common, action) != 0) { + Delete(common); + common = NULL; + } + } + Printf(wrapobj, "\t\t"); + if (i.item) { + Printf(wrapobj, "case '%s': ", mangled); + } else { + Printf(wrapobj, "default: "); + } + Printv(wrapobj, action, NIL); + if (action != common) Delete(action); Delete(mangled); } - Printf(output, "\t\t}\n"); + Printf(wrapobj, "\t\t}\n"); + if (common) { + // All cases have the same action, so eliminate the switch + // wrapper. + Printf(output, "\t\t%s", common); + Delete(common); + } else { + Printv(output, wrapobj, NIL); + } + Delete(wrapobj); } } else { if (non_void_return) { @@ -2401,7 +2422,7 @@ class PHP : public Language { String *target = Swig_method_decl(0, decl, classname, parms, 0, 0); const char * p = Char(target); const char * comma = strchr(p, ','); - size_t ins = comma ? comma - p : Len(target) - 1; + int ins = comma ? (int)(comma - p) : Len(target) - 1; Insert(target, ins, " TSRMLS_DC"); call = Swig_csuperclass_call(0, basetype, superparms); @@ -2420,7 +2441,7 @@ class PHP : public Language { String *target = Swig_method_decl(0, decl, classname, parms, 0, 1); const char * p = Char(target); const char * comma = strchr(p, ','); - size_t ins = comma ? comma - p : Len(target) - 1; + int ins = comma ? (int)(comma - p) : Len(target) - 1; Insert(target, ins, " TSRMLS_DC"); Printf(f_directors_h, " %s;\n", target); diff --git a/Source/Modules/pike.cxx b/Source/Modules/pike.cxx index 22c5a638bf6..6a74851c86e 100644 --- a/Source/Modules/pike.cxx +++ b/Source/Modules/pike.cxx @@ -149,9 +149,7 @@ class PIKE:public Language { /* Standard stuff for the SWIG runtime section */ Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGPIKE\n"); - Printf(f_runtime, "\n"); + Printf(f_runtime, "\n\n#ifndef SWIGPIKE\n#define SWIGPIKE\n#endif\n\n"); Printf(f_header, "#define SWIG_init pike_module_init\n"); Printf(f_header, "#define SWIG_name \"%s\"\n\n", module); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 73aa7dcb939..18824ac1d63 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -12,10 +12,8 @@ * ----------------------------------------------------------------------------- */ #include "swigmod.h" +#include #include "cparse.h" - -static int treduce = SWIG_cparse_template_reduce(0); - #include #include #include @@ -661,8 +659,7 @@ class PYTHON:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGPYTHON\n"); + Printf(f_runtime, "\n\n#ifndef SWIGPYTHON\n#define SWIGPYTHON\n#endif\n\n"); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); @@ -800,8 +797,14 @@ class PYTHON:public Language { Swig_register_filebyname("shadow", f_shadow); Swig_register_filebyname("python", f_shadow); - if (mod_docstring && Len(mod_docstring)) { - Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL); + if (mod_docstring) { + if (Len(mod_docstring)) { + const char *triple_double = "\"\"\""; + // follow PEP257 rules: https://www.python.org/dev/peps/pep-0257/ + // reported by pep257: https://github.com/GreenSteam/pep257 + bool multi_line_ds = Strchr(mod_docstring, '\n') != 0; + Printv(f_shadow, triple_double, multi_line_ds ? "\n":"", mod_docstring, multi_line_ds ? "\n":"", triple_double, "\n\n", NIL); + } Delete(mod_docstring); mod_docstring = NULL; } @@ -856,6 +859,11 @@ class PYTHON:public Language { if (modern || !classic) { Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n\n", NULL); } + + /* Need builtins to qualify names like Exception that might also be + defined in this module (try both Python 3 and Python 2 names) */ + Printv(f_shadow, "try:\n", tab4, "import builtins as __builtin__\n", "except ImportError:\n", tab4, "import __builtin__\n", NULL); + /* if (!modern) */ /* always needed, a class can be forced to be no-modern, such as an exception */ { @@ -873,7 +881,17 @@ class PYTHON:public Language { #else tab4, "if (not static):\n", #endif - tab4, tab4, "object.__setattr__(self, name, value)\n", + NIL); + if (!classic) { + if (!modern) + Printv(f_shadow, tab4, tab4, "if _newclass:\n", tab4, NIL); + Printv(f_shadow, tab4, tab4, "object.__setattr__(self, name, value)\n", NIL); + if (!modern) + Printv(f_shadow, tab4, tab4, "else:\n", tab4, NIL); + } + if (classic || !modern) + Printv(f_shadow, tab4, tab4, "self.__dict__[name] = value\n", NIL); + Printv(f_shadow, tab4, "else:\n", tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", "\n", "def _swig_setattr(self, class_type, name, value):\n", tab4, "return _swig_setattr_nondynamic(self, class_type, name, value, 0)\n\n", NIL); @@ -892,19 +910,14 @@ class PYTHON:public Language { Printv(f_shadow, "\n", "def _swig_repr(self):\n", tab4, "try:\n", tab8, "strthis = \"proxy of \" + self.this.__repr__()\n", - tab4, "except:\n", tab8, "strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); + tab4, "except __builtin__.Exception:\n", tab8, "strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); - if (!classic) { - /* Usage of types.ObjectType is deprecated. - * But don't sure wether this would broken old Python? - */ + if (!classic && !modern) { Printv(f_shadow, -// "import types\n", "try:\n", -// " _object = types.ObjectType\n", - tab4, "_object = object\n", tab4, "_newclass = 1\n", "except AttributeError:\n", tab4, "class _object:\n", tab8, "pass\n", tab4, "_newclass = 0\n", -// "del types\n", - "\n\n", NIL); + tab4, "_object = object\n", tab4, "_newclass = 1\n", + "except __builtin__.Exception:\n", + tab4, "class _object:\n", tab8, "pass\n", tab4, "_newclass = 0\n\n", NIL); } } if (modern) { @@ -922,7 +935,7 @@ class PYTHON:public Language { if (directorsEnabled()) { // Try loading weakref.proxy, which is only available in Python 2.1 and higher Printv(f_shadow, - "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); + "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except __builtin__.Exception:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); } } // Include some information in the code @@ -957,6 +970,7 @@ class PYTHON:public Language { if (directorsEnabled()) { // Insert director runtime into the f_runtime file (make it occur before %header section) + Swig_insert_file("director_common.swg", f_runtime); Swig_insert_file("director.swg", f_runtime); } @@ -988,7 +1002,7 @@ class PYTHON:public Language { if (shadow) { Swig_banner_target_lang(f_shadow_py, "#"); - if (!modern) { + if (!modern && !classic) { Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); } Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL); @@ -1176,7 +1190,7 @@ class PYTHON:public Language { const char *py3_end1 = Strchr(rpkg, '.'); if (!py3_end1) py3_end1 = (Char(rpkg)) + Len(rpkg); - py3_rlen1 = py3_end1 - (Char(rpkg)); + py3_rlen1 = (int)(py3_end1 - Char(rpkg)); } else { rpkg = NewString(""); } @@ -1291,7 +1305,7 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * import_name_string() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ static String *import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) { if (!relativeimport) { @@ -1337,9 +1351,10 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * funcCall() - * Emit shadow code to call a function in the extension - * module. Using proper argument and calling style for - * given node n. + * + * Emit shadow code to call a function in the extension + * module. Using proper argument and calling style for + * given node n. * ------------------------------------------------------------ */ String *funcCall(String *name, String *parms) { String *str = NewString(""); @@ -1348,12 +1363,15 @@ class PYTHON:public Language { return str; } - /* ------------------------------------------------------------ - * pythoncode() - Output python code into the shadow file + * indent_pythoncode() + * + * Format (indent) Python code. + * Remove leading whitespace from 'code' and re-indent using + * the indentation string in 'indent'. * ------------------------------------------------------------ */ - String *pythoncode(String *code, const_String_or_char_ptr indent) { + String *indent_pythoncode(const String *code, const_String_or_char_ptr indent, String *file, int line, const char *directive_name) { String *out = NewString(""); String *temp; char *t; @@ -1371,43 +1389,162 @@ class PYTHON:public Language { /* Split the input text into lines */ List *clist = SplitLines(temp); Delete(temp); - int initial = 0; - String *s = 0; + + // Line number within the pythoncode. + int py_line = 0; + + String *initial = 0; Iterator si; - /* Get the initial indentation */ - for (si = First(clist); si.item; si = Next(si)) { - s = si.item; - if (Len(s)) { - char *c = Char(s); - while (*c) { - if (!isspace(*c)) - break; - initial++; - c++; - } - if (*c && !isspace(*c)) { - break; - } else { - initial = 0; - } + /* Get the initial indentation. Skip lines which only contain whitespace + * and/or a comment, as the indentation of those doesn't matter: + * + * A logical line that contains only spaces, tabs, formfeeds and + * possibly a comment, is ignored (i.e., no NEWLINE token is + * generated). + * + * see: + * https://docs.python.org/2/reference/lexical_analysis.html#blank-lines + * https://docs.python.org/3/reference/lexical_analysis.html#blank-lines + */ + for (si = First(clist); si.item; si = Next(si), ++py_line) { + const char *c = Char(si.item); + int i; + for (i = 0; isspace((unsigned char)c[i]); i++) { + // Scan forward until we find a non-space (which may be a null byte). + } + char ch = c[i]; + if (ch && ch != '#') { + // Found a line with actual content. + initial = NewStringWithSize(c, i); + break; + } + if (ch) { + Printv(out, indent, c, NIL); } + Putc('\n', out); } - while (si.item) { - s = si.item; - if (Len(s) > initial) { - char *c = Char(s); - c += initial; + + // Process remaining lines. + for ( ; si.item; si = Next(si), ++py_line) { + const char *c = Char(si.item); + // If no prefixed line was found, the above loop should have completed. + assert(initial); + + int i; + for (i = 0; isspace((unsigned char)c[i]); i++) { + // Scan forward until we find a non-space (which may be a null byte). + } + char ch = c[i]; + if (!ch) { + // Line is just whitespace - emit an empty line. + Putc('\n', out); + continue; + } + + if (ch == '#') { + // Comment - the indentation doesn't matter to python, but try to + // adjust the whitespace for the benefit of human readers (though SWIG + // currently seems to always remove any whitespace before a '#' before + // we get here, in which case we'll just leave the comment at the start + // of the line). + if (i >= Len(initial)) { + Printv(out, indent, NIL); + } + + Printv(out, c + i, "\n", NIL); + continue; + } + + if (i < Len(initial)) { + // There's non-whitespace in the initial prefix of this line. + Swig_error(file, line, "Line indented less than expected (line %d of %s) as no line should be indented less than the indentation in line 1\n", py_line, directive_name); Printv(out, indent, c, "\n", NIL); } else { - Printv(out, "\n", NIL); + if (memcmp(c, Char(initial), Len(initial)) == 0) { + // Prefix matches initial, so just remove it. + Printv(out, indent, c + Len(initial), "\n", NIL); + continue; + } + Swig_warning(WARN_PYTHON_INDENT_MISMATCH, + file, line, "Whitespace indentation is inconsistent compared to earlier lines (line %d of %s)\n", py_line, directive_name); + // To avoid gratuitously breaking interface files which worked with + // SWIG <= 3.0.5, we remove a prefix of the same number of bytes for + // lines which start with different whitespace to the line we got + // 'initial' from. + Printv(out, indent, c + Len(initial), "\n", NIL); } - si = Next(si); } Delete(clist); return out; } + /* ------------------------------------------------------------ + * indent_docstring() + * + * Format (indent) a Python docstring. + * Remove leading whitespace from 'code' and re-indent using + * the indentation string in 'indent'. + * ------------------------------------------------------------ */ + + String *indent_docstring(const String *code, const_String_or_char_ptr indent) { + String *out = NewString(""); + String *temp; + char *t; + if (!indent) + indent = ""; + + temp = NewString(code); + + t = Char(temp); + if (*t == '{') { + Delitem(temp, 0); + Delitem(temp, DOH_END); + } + + /* Split the input text into lines */ + List *clist = SplitLines(temp); + Delete(temp); + + Iterator si; + + int truncate_characters_count = INT_MAX; + for (si = First(clist); si.item; si = Next(si)) { + const char *c = Char(si.item); + int i; + for (i = 0; isspace((unsigned char)c[i]); i++) { + // Scan forward until we find a non-space (which may be a null byte). + } + char ch = c[i]; + if (ch) { + // Found a line which isn't just whitespace + if (i < truncate_characters_count) + truncate_characters_count = i; + } + } + + if (truncate_characters_count == INT_MAX) + truncate_characters_count = 0; + + for (si = First(clist); si.item; si = Next(si)) { + const char *c = Char(si.item); + + int i; + for (i = 0; isspace((unsigned char)c[i]); i++) { + // Scan forward until we find a non-space (which may be a null byte). + } + char ch = c[i]; + if (!ch) { + // Line is just whitespace - emit an empty line. + Putc('\n', out); + continue; + } + + Printv(out, indent, c + truncate_characters_count, "\n", NIL); + } + Delete(clist); + return out; + } /* ------------------------------------------------------------ * autodoc level declarations @@ -1443,8 +1580,9 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * have_docstring() - * Check if there is a docstring directive and it has text, - * or there is an autodoc flag set + * + * Check if there is a docstring directive and it has text, + * or there is an autodoc flag set * ------------------------------------------------------------ */ bool have_docstring(Node *n) { @@ -1454,9 +1592,10 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * docstring() - * Get the docstring text, stripping off {} if neccessary, - * and enclose in triple double quotes. If autodoc is also - * set then it will build a combined docstring. + * + * Get the docstring text, stripping off {} if necessary, + * and enclose in triple double quotes. If autodoc is also + * set then it will build a combined docstring. * ------------------------------------------------------------ */ String *docstring(Node *n, autodoc_t ad_type, const String *indent, bool use_triple = true) { @@ -1490,20 +1629,22 @@ class PYTHON:public Language { // if (have_auto && have_ds) { // Both autodoc and docstring are present doc = NewString(""); - Printv(doc, triple_double, "\n", pythoncode(autodoc, indent), "\n", pythoncode(str, indent), indent, triple_double, NIL); + Printv(doc, triple_double, "\n", + indent_docstring(autodoc, indent), "\n", + indent_docstring(str, indent), indent, triple_double, NIL); } else if (!have_auto && have_ds) { // only docstring if (Strchr(str, '\n') == 0) { doc = NewStringf("%s%s%s", triple_double, str, triple_double); } else { doc = NewString(""); - Printv(doc, triple_double, "\n", pythoncode(str, indent), indent, triple_double, NIL); + Printv(doc, triple_double, "\n", indent_docstring(str, indent), indent, triple_double, NIL); } } else if (have_auto && !have_ds) { // only autodoc if (Strchr(autodoc, '\n') == 0) { doc = NewStringf("%s%s%s", triple_double, autodoc, triple_double); } else { doc = NewString(""); - Printv(doc, triple_double, "\n", pythoncode(autodoc, indent), indent, triple_double, NIL); + Printv(doc, triple_double, "\n", indent_docstring(autodoc, indent), indent, triple_double, NIL); } } else doc = NewString(""); @@ -1517,8 +1658,9 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * cdocstring() - * Get the docstring text as it would appear in C-language - * source code. + * + * Get the docstring text as it would appear in C-language + * source code. * ------------------------------------------------------------ */ String *cdocstring(Node *n, autodoc_t ad_type) @@ -1547,7 +1689,8 @@ class PYTHON:public Language { /* ----------------------------------------------------------------------------- * addMissingParameterNames() - * For functions that have not had nameless parameters set in the Language class. + * + * For functions that have not had nameless parameters set in the Language class. * * Inputs: * plist - entire parameter list @@ -1572,8 +1715,9 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * make_autodocParmList() - * Generate the documentation for the function parameters - * Parameters: + * + * Generate the documentation for the function parameters + * Parameters: * func_annotation: Function annotation support * ------------------------------------------------------------ */ @@ -1656,8 +1800,9 @@ class PYTHON:public Language { Append(doc, name); if (pdoc) { if (!pdocs) - pdocs = NewString("\nParameters:\n"); - Printf(pdocs, " %s\n", pdoc); + // numpydoc style: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt + pdocs = NewString("\nParameters\n----------\n"); + Printf(pdocs, "%s\n", pdoc); } // Write the function annotation if (func_annotation) @@ -1680,12 +1825,13 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * make_autodoc() - * Build a docstring for the node, using parameter and other - * info in the parse tree. If the value of the autodoc - * attribute is "0" then do not include parameter types, if - * it is "1" (the default) then do. If it has some other - * value then assume it is supplied by the extension writer - * and use it directly. + * + * Build a docstring for the node, using parameter and other + * info in the parse tree. If the value of the autodoc + * attribute is "0" then do not include parameter types, if + * it is "1" (the default) then do. If it has some other + * value then assume it is supplied by the extension writer + * and use it directly. * ------------------------------------------------------------ */ String *make_autodoc(Node *n, autodoc_t ad_type) { @@ -1745,10 +1891,17 @@ class PYTHON:public Language { // Only do the autodoc if there isn't a docstring for the class String *str = Getattr(n, "feature:docstring"); if (!str || Len(str) == 0) { - if (CPlusPlus) { - Printf(doc, "Proxy of C++ %s class", real_classname); + if (builtin) { + String *name = Getattr(n, "name"); + String *rname = add_explicit_scope(SwigType_namestr(name)); + Printf(doc, "%s", rname); + Delete(rname); } else { - Printf(doc, "Proxy of C %s struct", real_classname); + if (CPlusPlus) { + Printf(doc, "Proxy of C++ %s class.", real_classname); + } else { + Printf(doc, "Proxy of C %s struct.", real_classname); + } } } } @@ -1817,9 +1970,10 @@ class PYTHON:public Language { } /* ------------------------------------------------------------ - * convertDoubleValue() - * Check if the given string looks like a decimal floating point constant - * and return it if it does, otherwise return NIL. + * convertDoubleValue() + * + * Check if the given string looks like a decimal floating point constant + * and return it if it does, otherwise return NIL. * ------------------------------------------------------------ */ String *convertDoubleValue(String *v) { const char *const s = Char(v); @@ -1853,7 +2007,7 @@ class PYTHON:public Language { // Avoid unnecessary string allocation in the common case when we don't // need to remove any suffix. - return *end == '\0' ? v : NewStringWithSize(s, end - s); + return *end == '\0' ? v : NewStringWithSize(s, (int)(end - s)); } return NIL; @@ -1861,12 +2015,16 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * convertValue() - * Check if string v can be a Python value literal or a - * constant. Return NIL if it isn't. + * + * Check if string v can be a Python value literal or a + * constant. Return NIL if it isn't. * ------------------------------------------------------------ */ - String *convertValue(String *v, SwigType *t) { + String *convertValue(String *v, SwigType *type) { const char *const s = Char(v); char *end; + String *result = NIL; + bool fail = false; + SwigType *resolved_type = 0; // Check if this is a number in any base. long value = strtol(s, &end, 0); @@ -1875,141 +2033,164 @@ class PYTHON:public Language { if (errno == ERANGE) { // There was an overflow, we could try representing the value as Python // long integer literal, but for now don't bother with it. - return NIL; - } - - if (*end != '\0') { - // If there is a suffix after the number, we can safely ignore any - // combination of "l" and "u", but not anything else (again, stuff like - // "LL" could be handled, but we don't bother to do it currently). - bool seen_long = false; - for (char* p = end; *p != '\0'; ++p) { - switch (*p) { - case 'l': - case 'L': - // Bail out on "LL". - if (seen_long) - return NIL; - seen_long = true; - break; - - case 'u': - case 'U': - break; - - default: - // Except that our suffix could actually be the fractional part of - // a floating point number, so we still have to check for this. - return convertDoubleValue(v); + fail = true; + } else { + if (*end != '\0') { + // If there is a suffix after the number, we can safely ignore any + // combination of "l" and "u", but not anything else (again, stuff like + // "LL" could be handled, but we don't bother to do it currently). + bool seen_long = false; + for (char* p = end; *p != '\0'; ++p) { + switch (*p) { + case 'l': + case 'L': + // Bail out on "LL". + if (seen_long) { + fail = true; + break; + } + seen_long = true; + break; + + case 'u': + case 'U': + break; + + default: + // Except that our suffix could actually be the fractional part of + // a floating point number, so we still have to check for this. + result = convertDoubleValue(v); + } } } - } - // Deal with the values starting with 0 first as they can be octal or - // hexadecimal numbers or even pointers. - if (s[0] == '0') { - if (Len(v) == 1) { - // This is just a lone 0, but it needs to be represented differently - // in Python depending on whether it's a zero or a null pointer. - if (SwigType_ispointer(t)) - return NewString("None"); - else - return v; - } else if (s[1] == 'x' || s[1] == 'X') { - // This must have been a hex number, we can use it directly in Python, - // so nothing to do here. - } else { - // This must have been an octal number, we have to change its prefix - // to be "0o" in Python 3 only (and as long as we still support Python - // 2.5, this can't be done unconditionally). - if (py3) { - if (end - s > 1) { - String *res = NewString("0o"); - Append(res, NewStringWithSize(s + 1, end - s - 1)); - return res; + if (!fail) { + // Allow integers as the default value for a bool parameter. + resolved_type = SwigType_typedef_resolve_all(type); + if (Cmp(resolved_type, "bool") == 0) { + result = NewString(value ? "True" : "False"); + } else { + // Deal with the values starting with 0 first as they can be octal or + // hexadecimal numbers or even pointers. + if (s[0] == '0') { + if (Len(v) == 1) { + // This is just a lone 0, but it needs to be represented differently + // in Python depending on whether it's a zero or a null pointer. + if (SwigType_ispointer(resolved_type)) + result = NewString("None"); + else + result = v; + } else if (s[1] == 'x' || s[1] == 'X') { + // This must have been a hex number, we can use it directly in Python, + // so nothing to do here. + } else { + // This must have been an octal number, we have to change its prefix + // to be "0o" in Python 3 only (and as long as we still support Python + // 2.5, this can't be done unconditionally). + if (py3) { + if (end - s > 1) { + result = NewString("0o"); + Append(result, NewStringWithSize(s + 1, (int)(end - s - 1))); + } + } + } } + + // Avoid unnecessary string allocation in the common case when we don't + // need to remove any suffix. + if (!result) + result = *end == '\0' ? v : NewStringWithSize(s, (int)(end - s)); } } } - - // Avoid unnecessary string allocation in the common case when we don't - // need to remove any suffix. - return *end == '\0' ? v : NewStringWithSize(s, end - s); } // Check if this is a floating point number (notice that it wasn't // necessarily parsed as a long above, consider e.g. ".123"). - if (String *res = convertDoubleValue(v)) { - return res; - } - - if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) - return NewString("True"); - if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) - return NewString("False"); - if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0) - return SwigType_ispointer(t) ? NewString("None") : NewString("0"); + if (!fail && !result) { + result = convertDoubleValue(v); + if (!result) { + if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) + result = NewString("True"); + else if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) + result = NewString("False"); + else if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0) { + if (!resolved_type) + resolved_type = SwigType_typedef_resolve_all(type); + result = SwigType_ispointer(resolved_type) ? NewString("None") : NewString("0"); + } - // This could also be an enum type, default value of which could be - // representable in Python if it doesn't include any scope (which could, - // but currently is not, translated). - if (!Strchr(s, ':')) { - Node *lookup = Swig_symbol_clookup(v, 0); - if (lookup) { - if (Cmp(Getattr(lookup, "nodeType"), "enumitem") == 0) - return Getattr(lookup, "sym:name"); + // This could also be an enum type, default value of which could be + // representable in Python if it doesn't include any scope (which could, + // but currently is not, translated). + else if (!Strchr(s, ':')) { + Node *lookup = Swig_symbol_clookup(v, 0); + if (lookup) { + if (Cmp(Getattr(lookup, "nodeType"), "enumitem") == 0) + result = Getattr(lookup, "sym:name"); + } + } } } - return NIL; + Delete(resolved_type); + return result; } /* ------------------------------------------------------------ * is_representable_as_pyargs() - * Check if the function parameters default argument values - * can be represented in Python. * - * If this method returns false, the parameters will be translated - * to a generic "*args" which allows us to deal with default values - * at C++ code level where they can always be handled. + * Check if the function parameters default argument values + * can be represented in Python. + * + * If this method returns false, the parameters will be translated + * to a generic "*args" which allows us to deal with default values + * at C++ code level where they can always be handled. * ------------------------------------------------------------ */ bool is_representable_as_pyargs(Node *n) { - bool is_representable = true; - ParmList *plist = CopyParmList(Getattr(n, "parms")); + Swig_typemap_attach_parms("default", plist, NULL); + Parm *p; Parm *pnext; for (p = plist; p; p = pnext) { - pnext = NIL; + pnext = nextSibling(p); String *tm = Getattr(p, "tmap:in"); if (tm) { - pnext = Getattr(p, "tmap:in:next"); + Parm *in_next = Getattr(p, "tmap:in:next"); + if (in_next) + pnext = in_next; if (checkAttribute(p, "tmap:in:numinputs", "0")) { continue; } } - if (!pnext) { - pnext = nextSibling(p); - } + + // "default" typemap can contain arbitrary C++ code, so while it could, in + // principle, be possible to examine it and check if it's just something + // simple of the form "$1 = expression" and then use convertValue() to + // check if expression can be used in Python, but for now we just + // pessimistically give up and prefer to handle this at C++ level only. + if (Getattr(p, "tmap:default")) + return false; + if (String *value = Getattr(p, "value")) { String *type = Getattr(p, "type"); - if (!convertValue(value, type)) { - is_representable = false; - break; - } + if (!convertValue(value, type)) + return false; } } - return is_representable; + return true; } /* ------------------------------------------------------------ * is_real_overloaded() - * Check if the function is overloaded, but not just have some - * siblings generated due to the original function have - * default arguments. + * + * Check if the function is overloaded, but not just have some + * siblings generated due to the original function have + * default arguments. * ------------------------------------------------------------ */ bool is_real_overloaded(Node *n) { Node *h = Getattr(n, "sym:overloaded"); @@ -2033,8 +2214,9 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * make_pyParmList() - * Generate parameter list for Python functions or methods, - * reuse make_autodocParmList() to do so. + * + * Generate parameter list for Python functions or methods, + * reuse make_autodocParmList() to do so. * ------------------------------------------------------------ */ String *make_pyParmList(Node *n, bool in_class, bool is_calling, int kw) { /* Get the original function for a defaultargs copy, @@ -2043,8 +2225,17 @@ class PYTHON:public Language { if (nn) n = nn; - /* For overloaded function, just use *args */ - if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || !is_representable_as_pyargs(n)) { + /* We prefer to explicitly list all parameters of the C function in the + generated Python code as this makes the function more convenient to use, + however in some cases we must replace the real parameters list with just + the catch all "*args". This happens when: + + 1. The function is overloaded as Python doesn't support this. + 2. We were explicitly asked to use the "compact" arguments form. + 3. We were explicitly asked to use default args from C via the "python:cdefaultargs" feature. + 4. One of the default argument values can't be represented in Python. + */ + if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || GetFlag(n, "feature:python:cdefaultargs") || !is_representable_as_pyargs(n)) { String *parms = NewString(""); if (in_class) Printf(parms, "self, "); @@ -2071,7 +2262,8 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * have_pythonprepend() - * Check if there is a %pythonprepend directive and it has text + * + * Check if there is a %pythonprepend directive and it has text * ------------------------------------------------------------ */ bool have_pythonprepend(Node *n) { @@ -2081,7 +2273,8 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * pythonprepend() - * Get the %pythonprepend code, stripping off {} if neccessary + * + * Get the %pythonprepend code, stripping off {} if necessary * ------------------------------------------------------------ */ String *pythonprepend(Node *n) { @@ -2096,7 +2289,8 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * have_pythonappend() - * Check if there is a %pythonappend directive and it has text + * + * Check if there is a %pythonappend directive and it has text * ------------------------------------------------------------ */ bool have_pythonappend(Node *n) { @@ -2108,7 +2302,8 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * pythonappend() - * Get the %pythonappend code, stripping off {} if neccessary + * + * Get the %pythonappend code, stripping off {} if necessary * ------------------------------------------------------------ */ String *pythonappend(Node *n) { @@ -2126,7 +2321,8 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * have_addtofunc() - * Check if there is a %addtofunc directive and it has text + * + * Check if there is a %addtofunc directive and it has text * ------------------------------------------------------------ */ bool have_addtofunc(Node *n) { @@ -2136,8 +2332,9 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * returnTypeAnnotation() - * Helper function for constructing the function annotation - * of the returning type, return a empty string for Python 2.x + * + * Helper function for constructing the function annotation + * of the returning type, return a empty string for Python 2.x * ------------------------------------------------------------ */ String *returnTypeAnnotation(Node *n) { String *ret = 0; @@ -2170,9 +2367,10 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * emitFunctionShadowHelper() - * Refactoring some common code out of functionWrapper and - * dispatchFunction that writes the proxy code for non-member - * functions. + * + * Refactoring some common code out of functionWrapper and + * dispatchFunction that writes the proxy code for non-member + * functions. * ------------------------------------------------------------ */ void emitFunctionShadowHelper(Node *n, File *f_dest, String *name, int kw) { @@ -2183,16 +2381,16 @@ class PYTHON:public Language { if (have_docstring(n)) Printv(f_dest, tab4, docstring(n, AUTODOC_FUNC, tab4), "\n", NIL); if (have_pythonprepend(n)) - Printv(f_dest, pythoncode(pythonprepend(n), tab4), "\n", NIL); + Printv(f_dest, indent_pythoncode(pythonprepend(n), tab4, Getfile(n), Getline(n), "%pythonprepend or %feature(\"pythonprepend\")"), "\n", NIL); if (have_pythonappend(n)) { Printv(f_dest, tab4 "val = ", funcCall(name, callParms), "\n", NIL); - Printv(f_dest, pythoncode(pythonappend(n), tab4), "\n", NIL); + Printv(f_dest, indent_pythoncode(pythonappend(n), tab4, Getfile(n), Getline(n), "%pythonappend or %feature(\"pythonappend\")"), "\n", NIL); Printv(f_dest, tab4 "return val\n", NIL); } else { Printv(f_dest, tab4 "return ", funcCall(name, callParms), "\n", NIL); } - if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) { + if (!have_addtofunc(n)) { /* If there is no addtofunc directive then just assign from the extension module (for speed up) */ Printv(f_dest, name, " = ", module, ".", name, "\n", NIL); } @@ -2201,7 +2399,8 @@ class PYTHON:public Language { /* ------------------------------------------------------------ * check_kwargs() - * check if using kwargs is allowed for this Node + * + * check if using kwargs is allowed for this Node * ------------------------------------------------------------ */ int check_kwargs(Node *n) const { @@ -2234,18 +2433,12 @@ class PYTHON:public Language { if (!n) { Append(methods, "NULL"); - } else if (Getattr(n, "feature:callback")) { - if (have_docstring(n)) { - String *ds = cdocstring(n, AUTODOC_FUNC); - Printf(methods, "(char *)\"%s\\nswig_ptr: %s\"", ds, Getattr(n, "feature:callback:name")); - Delete(ds); - } else { - Printf(methods, "(char *)\"swig_ptr: %s\"", Getattr(n, "feature:callback:name")); - } } else if (have_docstring(n)) { String *ds = cdocstring(n, AUTODOC_FUNC); Printf(methods, "(char *)\"%s\"", ds); Delete(ds); + } else if (Getattr(n, "feature:callback")) { + Printf(methods, "(char *)\"swig_ptr: %s\"", Getattr(n, "feature:callback:name")); } else { Append(methods, "NULL"); } @@ -2281,15 +2474,15 @@ class PYTHON:public Language { Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); - Wrapper_add_local(f, "argc", "int argc"); - Printf(tmp, "PyObject *argv[%d]", maxargs + 1); + Wrapper_add_local(f, "argc", "Py_ssize_t argc"); + Printf(tmp, "PyObject *argv[%d] = {0}", maxargs + 1); Wrapper_add_local(f, "argv", tmp); if (!fastunpack) { - Wrapper_add_local(f, "ii", "int ii"); + Wrapper_add_local(f, "ii", "Py_ssize_t ii"); if (maxargs - (add_self ? 1 : 0) > 0) Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n"); - Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n"); + Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n"); if (add_self) Append(f->code, "argv[0] = self;\n"); Printf(f->code, "for (ii = 0; (ii < %d) && (ii < argc); ii++) {\n", add_self ? maxargs - 1 : maxargs); @@ -2673,14 +2866,12 @@ class PYTHON:public Language { Printv(f->locals, " char * kwnames[] = ", kwargs, ";\n", NIL); } - if (use_parse || allow_kwargs || !modernargs) { - if (builtin && in_class && tuple_arguments == 0) { - Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_fail;\n"); - } else { - Printf(parse_args, ":%s\"", iname); - Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); - funpack = 0; - } + if (builtin && !funpack && in_class && tuple_arguments == 0) { + Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_exception_fail(SWIG_TypeError, \"%s takes no arguments\");\n", iname); + } else if (use_parse || allow_kwargs || !modernargs) { + Printf(parse_args, ":%s\"", iname); + Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); + funpack = 0; } else { Clear(parse_args); if (funpack) { @@ -3047,6 +3238,17 @@ class PYTHON:public Language { } /* If this is a builtin type, create a PyGetSetDef entry for this member variable. */ + if (builtin) { + const char *memname = "__dict__"; + Hash *h = Getattr(builtin_getset, memname); + if (!h) { + h = NewHash(); + Setattr(builtin_getset, memname, h); + Delete(h); + } + Setattr(h, "getter", "SwigPyObject_get___dict__"); + } + if (builtin_getter) { String *memname = Getattr(n, "membervariableHandler:sym:name"); if (!memname) @@ -3298,6 +3500,7 @@ class PYTHON:public Language { // Generate method which registers the new constant Printf(f_wrappers, "SWIGINTERN PyObject *%s_swigconstant(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", iname); Printf(f_wrappers, tab2 "PyObject *module;\n", tm); + Printf(f_wrappers, tab2 "PyObject *d;\n"); if (modernargs) { if (fastunpack) { Printf(f_wrappers, tab2 "if (!SWIG_Python_UnpackTuple(args,(char*)\"swigconstant\", 1, 1,&module)) return NULL;\n"); @@ -3307,7 +3510,7 @@ class PYTHON:public Language { } else { Printf(f_wrappers, tab2 "if (!PyArg_ParseTuple(args,(char*)\"O:swigconstant\", &module)) return NULL;\n"); } - Printf(f_wrappers, tab2 "PyObject *d = PyModule_GetDict(module);\n"); + Printf(f_wrappers, tab2 "d = PyModule_GetDict(module);\n"); Printf(f_wrappers, tab2 "if (!d) return NULL;\n"); Printf(f_wrappers, tab2 "%s\n", tm); Printf(f_wrappers, tab2 "return SWIG_Py_Void();\n"); @@ -3506,8 +3709,8 @@ class PYTHON:public Language { Printf(f_directors_h, " return (iv != swig_inner.end() ? iv->second : false);\n"); Printf(f_directors_h, " }\n"); - Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool val) const {\n"); - Printf(f_directors_h, " swig_inner[swig_protected_method_name] = val;\n"); + Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool swig_val) const {\n"); + Printf(f_directors_h, " swig_inner[swig_protected_method_name] = swig_val;\n"); Printf(f_directors_h, " }\n"); Printf(f_directors_h, "private:\n"); Printf(f_directors_h, " mutable std::map swig_inner;\n"); @@ -3776,7 +3979,7 @@ class PYTHON:public Language { else quoted_symname = NewStringf("\"%s\"", symname); } - String *quoted_rname = NewStringf("\"%s\"", rname); + String *quoted_tp_doc_str = NewStringf("\"%s\"", getSlot(n, "feature:python:tp_doc")); char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "SwigPyBuiltin_BadInit"; String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); String *py3_tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE"); @@ -3819,7 +4022,7 @@ class PYTHON:public Language { Printv(f, "#else\n", NIL); printSlot(f, tp_flags, "tp_flags"); Printv(f, "#endif\n", NIL); - printSlot(f, quoted_rname, "tp_doc"); + printSlot(f, quoted_tp_doc_str, "tp_doc"); printSlot(f, getSlot(n, "feature:python:tp_traverse"), "tp_traverse", "traverseproc"); printSlot(f, getSlot(n, "feature:python:tp_clear"), "tp_clear", "inquiry"); printSlot(f, richcompare_func, "feature:python:tp_richcompare", "richcmpfunc"); @@ -3848,8 +4051,29 @@ class PYTHON:public Language { Printv(f, "#if PY_VERSION_HEX >= 0x02060000\n", NIL); printSlot(f, getSlot(n, "feature:python:tp_version_tag"), "tp_version_tag", "int"); Printv(f, "#endif\n", NIL); + Printv(f, "#if PY_VERSION_HEX >= 0x03040000\n", NIL); + printSlot(f, getSlot(n, "feature:python:tp_finalize"), "tp_finalize", "destructor"); + Printv(f, "#endif\n", NIL); + Printv(f, "#ifdef COUNT_ALLOCS\n", NIL); + printSlot(f, getSlot(), "tp_allocs", "Py_ssize_t"); + printSlot(f, getSlot(), "tp_frees", "Py_ssize_t"); + printSlot(f, getSlot(), "tp_maxalloc", "Py_ssize_t"); + Printv(f, "#if PY_VERSION_HEX >= 0x02050000\n", NIL); + printSlot(f, getSlot(), "tp_prev", "struct _typeobject*"); + Printv(f, "#endif\n", NIL); + printSlot(f, getSlot(), "tp_next", "struct _typeobject*"); + Printv(f, "#endif\n", NIL); Printf(f, " },\n"); + // PyAsyncMethods as_async + Printv(f, "#if PY_VERSION_HEX >= 0x03050000\n", NIL); + Printf(f, " {\n"); + printSlot(f, getSlot(n, "feature:python:am_await"), "am_await", "unaryfunc"); + printSlot(f, getSlot(n, "feature:python:am_aiter"), "am_aiter", "unaryfunc"); + printSlot(f, getSlot(n, "feature:python:am_anext"), "am_anext", "unaryfunc"); + Printf(f, " },\n"); + Printv(f, "#endif\n", NIL); + // PyNumberMethods as_number Printf(f, " {\n"); printSlot(f, getSlot(n, "feature:python:nb_add"), "nb_add", "binaryfunc"); @@ -3905,6 +4129,10 @@ class PYTHON:public Language { Printv(f, "#if PY_VERSION_HEX >= 0x02050000\n", NIL); printSlot(f, getSlot(n, "feature:python:nb_index"), "nb_index", "unaryfunc"); Printv(f, "#endif\n", NIL); + Printv(f, "#if PY_VERSION_HEX >= 0x03050000\n", NIL); + printSlot(f, getSlot(n, "feature:python:nb_matrix_multiply"), "nb_matrix_multiply", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_matrix_multiply"), "nb_inplace_matrix_multiply", "binaryfunc"); + Printv(f, "#endif\n", NIL); Printf(f, " },\n"); // PyMappingMethods as_mapping; @@ -3950,24 +4178,26 @@ class PYTHON:public Language { Printv(f, "#endif\n", NIL); Printf(f, " },\n"); - // PyObject *ht_name, *ht_slots + // PyObject *ht_name, *ht_slots, *ht_qualname; printSlot(f, getSlot(n, "feature:python:ht_name"), "ht_name", "PyObject*"); printSlot(f, getSlot(n, "feature:python:ht_slots"), "ht_slots", "PyObject*"); + Printv(f, "#if PY_VERSION_HEX >= 0x03030000\n", NIL); + printSlot(f, getSlot(n, "feature:python:ht_qualname"), "ht_qualname", "PyObject*"); + + // struct _dictkeysobject *ht_cached_keys; + printSlot(f, getSlot(n, "feature:python:ht_cached_keys"), "ht_cached_keys", "struct _dictkeysobject*"); + Printv(f, "#endif\n", NIL); Printf(f, "};\n\n"); String *clientdata = NewString(""); Printf(clientdata, "&%s_clientdata", templ); SwigType_remember_mangleddata(pmname, clientdata); - String *smartptr = Getattr(n, "feature:smartptr"); - if (smartptr) { - SwigType *spt = Swig_cparse_type(smartptr); - SwigType *smart = SwigType_typedef_resolve_all(spt); + SwigType *smart = Swig_cparse_smartptr(n); + if (smart) { SwigType_add_pointer(smart); String *smart_pmname = SwigType_manglestr(smart); SwigType_remember_mangleddata(smart_pmname, clientdata); - Delete(spt); - Delete(smart); Delete(smart_pmname); } @@ -3993,6 +4223,7 @@ class PYTHON:public Language { Printv(f_init, " d = md;\n", NIL); Delete(clientdata); + Delete(smart); Delete(rname); Delete(pname); Delete(mname); @@ -4002,7 +4233,7 @@ class PYTHON:public Language { Delete(tp_flags); Delete(py3_tp_flags); Delete(quoted_symname); - Delete(quoted_rname); + Delete(quoted_tp_doc_str); Delete(clientdata_klass); Delete(richcompare_func); Delete(getset_name); @@ -4102,6 +4333,11 @@ class PYTHON:public Language { String *str = cdocstring(n, AUTODOC_CLASS); Setattr(n, "feature:python:tp_doc", str); Delete(str); + } else { + String *name = Getattr(n, "name"); + String *rname = add_explicit_scope(SwigType_namestr(name)); + Setattr(n, "feature:python:tp_doc", rname); + Delete(rname); } } else { Printv(f_shadow, "class ", class_name, NIL); @@ -4121,7 +4357,7 @@ class PYTHON:public Language { if (have_docstring(n)) { String *str = docstring(n, AUTODOC_CLASS, tab4); if (str && Len(str)) - Printv(f_shadow, tab4, str, "\n", NIL); + Printv(f_shadow, tab4, str, "\n\n", NIL); } if (!modern) { @@ -4185,18 +4421,8 @@ class PYTHON:public Language { /* Complete the class */ if (shadow) { /* Generate a class registration function */ - String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) - SwigType *smart = 0; - if (smartptr) { - SwigType *cpt = Swig_cparse_type(smartptr); - if (cpt) { - smart = SwigType_typedef_resolve_all(cpt); - Delete(cpt); - } else { - // TODO: report line number of where the feature comes from - Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname); - } - } + // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) + SwigType *smart = Swig_cparse_smartptr(n); SwigType *ct = Copy(smart ? smart : real_classname); SwigType_add_pointer(ct); SwigType *realct = Copy(real_classname); @@ -4265,11 +4491,11 @@ class PYTHON:public Language { if (!modern) { Printv(f_shadow_file, tab8, "try:\n", tab8, tab4, "self.this.append(this)\n", - tab8, "except:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); + tab8, "except __builtin__.Exception:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); } else { Printv(f_shadow_file, tab8, "try:\n", tab8, tab4, "self.this.append(this)\n", - tab8, "except:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); + tab8, "except __builtin__.Exception:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); } } @@ -4380,7 +4606,7 @@ class PYTHON:public Language { have_repr = 1; } if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pycode = indent_pythoncode(Getattr(n, "feature:shadow"), tab4, Getfile(n), Getline(n), "%feature(\"shadow\")"); String *pyaction = NewStringf("%s.%s", module, fullname); Replaceall(pycode, "$action", pyaction); Delete(pyaction); @@ -4402,12 +4628,12 @@ class PYTHON:public Language { Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); if (have_pythonprepend(n)) { fproxy = 0; - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, indent_pythoncode(pythonprepend(n), tab8, Getfile(n), Getline(n), "%pythonprepend or %feature(\"pythonprepend\")"), "\n", NIL); } if (have_pythonappend(n)) { fproxy = 0; Printv(f_shadow, tab8, "val = ", funcCall(fullname, callParms), "\n", NIL); - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, indent_pythoncode(pythonappend(n), tab8, Getfile(n), Getline(n), "%pythonappend or %feature(\"pythonappend\")"), "\n", NIL); Printv(f_shadow, tab8, "return val\n\n", NIL); } else { Printv(f_shadow, tab8, "return ", funcCall(fullname, callParms), "\n\n", NIL); @@ -4479,7 +4705,7 @@ class PYTHON:public Language { } if (shadow) { - if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { + if (!Getattr(n, "feature:python:callback") && have_addtofunc(n)) { int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; String *parms = make_pyParmList(n, false, false, kw); String *callParms = make_pyParmList(n, false, true, kw); @@ -4487,33 +4713,27 @@ class PYTHON:public Language { if (have_docstring(n)) Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, indent_pythoncode(pythonprepend(n), tab8, Getfile(n), Getline(n), "%pythonprepend or %feature(\"pythonprepend\")"), "\n", NIL); if (have_pythonappend(n)) { Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, indent_pythoncode(pythonappend(n), tab8, Getfile(n), Getline(n), "%pythonappend or %feature(\"pythonappend\")"), "\n", NIL); Printv(f_shadow, tab8, "return val\n\n", NIL); } else { Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); } - if (!modern) - Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL); Printv(f_shadow, tab4, symname, " = staticmethod(", symname, ")\n", NIL); - - if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL); - } - } else { - if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", - NIL); - } if (!classic) { if (!modern) Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL); Printv(f_shadow, tab4, symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); } + if (classic || !modern) { + if (!classic) + Printv(f_shadow, tab4, "else:\n", tab4, NIL); + Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); + } } } return SWIG_OK; @@ -4575,7 +4795,7 @@ class PYTHON:public Language { if (!have_constructor && handled_as_init) { if (!builtin) { if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pycode = indent_pythoncode(Getattr(n, "feature:shadow"), tab4, Getfile(n), Getline(n), "%feature(\"shadow\")"); String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); Replaceall(pycode, "$action", pyaction); Delete(pyaction); @@ -4604,17 +4824,17 @@ class PYTHON:public Language { if (have_docstring(n)) Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, indent_pythoncode(pythonprepend(n), tab8, Getfile(n), Getline(n), "%pythonprepend or %feature(\"pythonprepend\")"), "\n", NIL); Printv(f_shadow, pass_self, NIL); if (fastinit) { - Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); + Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self, ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); } else { Printv(f_shadow, tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", - tab8, "try:\n", tab8, tab4, "self.this.append(this)\n", tab8, "except:\n", tab8, tab4, "self.this = this\n", NIL); + tab8, "try:\n", tab8, tab4, "self.this.append(this)\n", tab8, "except __builtin__.Exception:\n", tab8, tab4, "self.this = this\n", NIL); } if (have_pythonappend(n)) - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); + Printv(f_shadow, indent_pythoncode(pythonappend(n), tab8, Getfile(n), Getline(n), "%pythonappend or %feature(\"pythonappend\")"), "\n\n", NIL); Delete(pass_self); } have_constructor = 1; @@ -4623,7 +4843,7 @@ class PYTHON:public Language { /* Hmmm. We seem to be creating a different constructor. We're just going to create a function for it. */ if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); + String *pycode = indent_pythoncode(Getattr(n, "feature:shadow"), "", Getfile(n), Getline(n), "%feature(\"shadow\")"); String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); Replaceall(pycode, "$action", pyaction); Delete(pyaction); @@ -4637,7 +4857,7 @@ class PYTHON:public Language { if (have_docstring(n)) Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); if (have_pythonprepend(n)) - Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); + Printv(f_shadow_stubs, indent_pythoncode(pythonprepend(n), tab4, Getfile(n), Getline(n), "%pythonprepend or %feature(\"pythonprepend\")"), "\n", NIL); String *subfunc = NULL; /* if (builtin) @@ -4650,7 +4870,7 @@ class PYTHON:public Language { Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); #endif if (have_pythonappend(n)) - Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); + Printv(f_shadow_stubs, indent_pythoncode(pythonappend(n), tab4, Getfile(n), Getline(n), "%pythonappend or %feature(\"pythonappend\")"), "\n", NIL); Printv(f_shadow_stubs, tab4, "return val\n", NIL); Delete(subfunc); } @@ -4687,7 +4907,7 @@ class PYTHON:public Language { if (shadow) { if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pycode = indent_pythoncode(Getattr(n, "feature:shadow"), tab4, Getfile(n), Getline(n), "%feature(\"shadow\")"); String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname)); Replaceall(pycode, "$action", pyaction); Delete(pyaction); @@ -4705,15 +4925,15 @@ class PYTHON:public Language { if (have_docstring(n)) Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, indent_pythoncode(pythonprepend(n), tab8, Getfile(n), Getline(n), "%pythonprepend or %feature(\"pythonprepend\")"), "\n", NIL); #ifdef USE_THISOWN Printv(f_shadow, tab8, "try:\n", NIL); Printv(f_shadow, tab8, tab4, "if self.thisown:", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL); - Printv(f_shadow, tab8, "except: pass\n", NIL); + Printv(f_shadow, tab8, "except __builtin__.Exception: pass\n", NIL); #else #endif if (have_pythonappend(n)) - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, indent_pythoncode(pythonappend(n), tab8, Getfile(n), Getline(n), "%pythonappend or %feature(\"pythonappend\")"), "\n", NIL); Printv(f_shadow, tab8, "pass\n", NIL); Printv(f_shadow, "\n", NIL); } @@ -4893,12 +5113,12 @@ class PYTHON:public Language { if (!ImportMode && (Cmp(section, "python") == 0 || Cmp(section, "shadow") == 0)) { if (shadow) { - String *pycode = pythoncode(code, shadow_indent); + String *pycode = indent_pythoncode(code, shadow_indent, Getfile(n), Getline(n), "%pythoncode or %insert(\"python\") block"); Printv(f_shadow, pycode, NIL); Delete(pycode); } } else if (!ImportMode && (Cmp(section, "pythonbegin") == 0)) { - String *pycode = pythoncode(code, ""); + String *pycode = indent_pythoncode(code, "", Getfile(n), Getline(n), "%pythonbegin or %insert(\"pythonbegin\") block"); Printv(f_shadow_begin, pycode, NIL); Delete(pycode); } else { diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 3befcfbdd41..758cb00ee48 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -281,6 +281,7 @@ class R : public Language { void dispatchFunction(Node *n); int functionWrapper(Node *n); + int constantWrapper(Node *n); int variableWrapper(Node *n); int classDeclaration(Node *n); @@ -792,9 +793,7 @@ int R::top(Node *n) { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGR\n"); - Printf(f_runtime, "\n"); + Printf(f_runtime, "\n\n#ifndef SWIGR\n#define SWIGR\n#endif\n\n"); Swig_banner_target_lang(s_init, "#"); @@ -1381,12 +1380,12 @@ List * R::Swig_overload_rank(Node *n, } if ((!t1) && (!nodes[i].error)) { Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), - "Overloaded method %s not supported (no type checking rule for '%s').\n", + "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", Swig_name_decl(nodes[i].n), SwigType_str(Getattr(p1, "type"), 0)); nodes[i].error = 1; } else if ((!t2) && (!nodes[j].error)) { Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), - "xx Overloaded method %s not supported (no type checking rule for '%s').\n", + "Overloaded method %s not supported (incomplete type checking rule - no precedence level in typecheck typemap for '%s').\n", Swig_name_decl(nodes[j].n), SwigType_str(Getattr(p2, "type"), 0)); nodes[j].error = 1; } @@ -2181,6 +2180,16 @@ int R::functionWrapper(Node *n) { return SWIG_OK; } +/* ---------------------------------------------------------------------- + * R::constantWrapper() + * ---------------------------------------------------------------------- */ + +int R::constantWrapper(Node *n) { + (void) n; + // TODO + return SWIG_OK; +} + /***************************************************** Add the specified routine name to the collection of generated routines that are called from R functions. diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 310e89b8299..62a6d960c10 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -13,14 +13,12 @@ #include "swigmod.h" #include "cparse.h" -static int treduce = SWIG_cparse_template_reduce(0); - -#define SWIG_PROTECTED_TARGET_METHODS 1 - #include #include #include /* for INT_MAX */ +#define SWIG_PROTECTED_TARGET_METHODS 1 + class RClass { private: String *temp; @@ -234,7 +232,7 @@ class RUBY:public Language { /* ------------------------------------------------------------ * docstring() - * Get the docstring text, stripping off {} if neccessary, + * Get the docstring text, stripping off {} if necessary, * and enclose in triple double quotes. If autodoc is also * set then it will build a combined docstring. * ------------------------------------------------------------ */ @@ -1099,8 +1097,7 @@ class RUBY:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGRUBY\n"); + Printf(f_runtime, "\n\n#ifndef SWIGRUBY\n#define SWIGRUBY\n#endif\n\n"); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); @@ -1171,6 +1168,7 @@ class RUBY:public Language { if (directorsEnabled()) { // Insert director runtime into the f_runtime file (make it occur before %header section) + Swig_insert_file("director_common.swg", f_runtime); Swig_insert_file("director.swg", f_runtime); } @@ -1741,11 +1739,13 @@ class RUBY:public Language { /* Now write the wrapper function itself */ if (current == CONSTRUCTOR_ALLOCATE) { + Printv(f->def, "SWIGINTERN VALUE\n", NIL); Printf(f->def, "#ifdef HAVE_RB_DEFINE_ALLOC_FUNC\n"); - Printv(f->def, "SWIGINTERN VALUE\n", wname, "(VALUE self) {", NIL); + Printv(f->def, wname, "(VALUE self)\n", NIL); Printf(f->def, "#else\n"); - Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL); + Printv(f->def, wname, "(int argc, VALUE *argv, VALUE self)\n", NIL); Printf(f->def, "#endif\n"); + Printv(f->def, "{\n", NIL); } else if (current == CONSTRUCTOR_INITIALIZE) { Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL); if (!varargs) { @@ -1794,8 +1794,8 @@ class RUBY:public Language { /* if the object is a director, and the method call originated from its * underlying Ruby object, resolve the call by going up the c++ - * inheritance chain. otherwise try to resolve the method in python. - * without this check an infinite loop is set up between the director and + * inheritance chain. otherwise try to resolve the method in Ruby. + * without this check an infinite loop is set up between the director and * shadow class method calls. */ @@ -1831,10 +1831,19 @@ class RUBY:public Language { Wrapper_add_local(f, "classname", classname); } if (action) { - Printf(action, "\nDATA_PTR(self) = %s;", Swig_cresult_name()); + SwigType *smart = Swig_cparse_smartptr(pn); + String *result_name = NewStringf("%s%s", smart ? "smart" : "", Swig_cresult_name()); + if (smart) { + String *result_var = NewStringf("%s *%s = 0", SwigType_namestr(smart), result_name); + Wrapper_add_local(f, result_name, result_var); + Printf(action, "\n%s = new %s(%s);", result_name, SwigType_namestr(smart), Swig_cresult_name()); + } + Printf(action, "\nDATA_PTR(self) = %s;", result_name); if (GetFlag(pn, "feature:trackobjects")) { - Printf(action, "\nSWIG_RubyAddTracking(%s, self);", Swig_cresult_name()); + Printf(action, "\nSWIG_RubyAddTracking(%s, self);", result_name); } + Delete(result_name); + Delete(smart); } } @@ -1922,11 +1931,17 @@ class RUBY:public Language { /* Extra code needed for new and initialize methods */ if (current == CONSTRUCTOR_ALLOCATE) { + Node *pn = Swig_methodclass(n); + SwigType *smart = Swig_cparse_smartptr(pn); + if (smart) + SwigType_add_pointer(smart); + String *classtype = smart ? smart : t; need_result = 1; - Printf(f->code, "VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE%s);\n", Char(SwigType_manglestr(t))); + Printf(f->code, "VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE%s);\n", Char(SwigType_manglestr(classtype))); Printf(f->code, "#ifndef HAVE_RB_DEFINE_ALLOC_FUNC\n"); Printf(f->code, "rb_obj_call_init(vresult, argc, argv);\n"); Printf(f->code, "#endif\n"); + Delete(smart); } else if (current == CONSTRUCTOR_INITIALIZE) { need_result = 1; } @@ -2425,19 +2440,23 @@ class RUBY:public Language { SwigType *btype = NewString(basename); SwigType_add_pointer(btype); SwigType_remember(btype); + SwigType *smart = Swig_cparse_smartptr(base.item); + if (smart) { + SwigType_add_pointer(smart); + SwigType_remember(smart); + } + String *bmangle = SwigType_manglestr(smart ? smart : btype); if (multipleInheritance) { - String *bmangle = SwigType_manglestr(btype); Insert(bmangle, 0, "((swig_class *) SWIGTYPE"); Append(bmangle, "->clientdata)->mImpl"); Printv(klass->init, "rb_include_module(", klass->mImpl, ", ", bmangle, ");\n", NIL); - Delete(bmangle); } else { - String *bmangle = SwigType_manglestr(btype); Insert(bmangle, 0, "((swig_class *) SWIGTYPE"); Append(bmangle, "->clientdata)->klass"); Replaceall(klass->init, "$super", bmangle); - Delete(bmangle); } + Delete(bmangle); + Delete(smart); Delete(btype); } base = Next(base); @@ -2538,9 +2557,15 @@ class RUBY:public Language { SwigType *tt = NewString(name); SwigType_add_pointer(tt); SwigType_remember(tt); - String *tm = SwigType_manglestr(tt); + SwigType *smart = Swig_cparse_smartptr(n); + if (smart) { + SwigType_add_pointer(smart); + SwigType_remember(smart); + } + String *tm = SwigType_manglestr(smart ? smart : tt); Printf(klass->init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) &SwigClass%s);\n", tm, valid_name); Delete(tm); + Delete(smart); Delete(tt); Delete(valid_name); @@ -2719,7 +2744,9 @@ class RUBY:public Language { String *pname0 = Swig_cparm_name(0, 0); Printv(freefunc, "free_", klass->mname, NIL); - Printv(freebody, "SWIGINTERN void\n", freefunc, "(", klass->type, " *", pname0, ") {\n", tab4, NIL); + Printv(freebody, "SWIGINTERN void\n", freefunc, "(void *self) {\n", NIL); + Printv(freebody, tab4, klass->type, " *", pname0, " = (", klass->type, " *)self;\n", NIL); + Printv(freebody, tab4, NIL); /* Check to see if object tracking is activated for the class that owns this destructor. */ @@ -2972,6 +2999,7 @@ class RUBY:public Language { Printf(rescue->code, "if (%s == 0) ", depthCountName); Printv(rescue->code, Str(tm), "\n", NIL); Printv(rescue->code, "rb_exc_raise(error);\n", NIL); + Printv(rescue->code, "return Qnil;\n", NIL); Printv(rescue->code, "}", NIL); } diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx new file mode 100644 index 00000000000..63f689eaa68 --- /dev/null +++ b/Source/Modules/scilab.cxx @@ -0,0 +1,1125 @@ +/* ---------------------------------------------------------------------------- + * This file is part of SWIG, which is licensed as a whole under version 3 + * (or any later version) of the GNU General Public License. Some additional + * terms also apply to certain portions of SWIG. The full details of the SWIG + * license and copyrights can be found in the LICENSE and COPYRIGHT files + * included with the SWIG source code as distributed by the SWIG developers + * and at http://www.swig.org/legal.html. + * + * scilab.cxx + * + * Scilab language module for SWIG. + * --------------------------------------------------------------------------*/ + +#include "swigmod.h" + +static const int SCILAB_IDENTIFIER_NAME_CHAR_MAX = 24; +static const int SCILAB_VARIABLE_NAME_CHAR_MAX = SCILAB_IDENTIFIER_NAME_CHAR_MAX - 4; + +static const char *usage = (char *) " \ +Scilab options (available with -scilab)\n \ + -builder - Generate a Scilab builder script\n \ + -buildercflags - Add to the builder compiler flags\n \ + -builderflagscript - Set the Scilab script to use by builder to configure the build flags\n \ + -builderldflags - Add to the builder linker flags\n \ + -buildersources - Add the (comma separated) files to the builder sources\n \ + -builderverbositylevel - Set the builder verbosity level to (default 0: off, 2: high)\n \ + -gatewayxml - Generate gateway xml with the given \n \ +\n"; + + +class SCILAB:public Language { +protected: + /* General objects used for holding the strings */ + File *beginSection; + File *runtimeSection; + File *headerSection; + File *wrappersSection; + File *initSection; + + String *variablesCode; + + bool generateBuilder; + File *builderFile; + String *builderCode; + int builderFunctionCount; + + List *sourceFileList; + List *cflags; + List *ldflags; + + String *verboseBuildLevel; + String *buildFlagsScript; + + String *gatewayHeader; + String *gatewayHeaderV5; + String *gatewayHeaderV6; + + bool createGatewayXML; + File *gatewayXMLFile; + String *gatewayXML; + String *gatewayID; + int primitiveID; + + bool createLoader; + File *loaderFile; + String *loaderScript; +public: + + /* ------------------------------------------------------------------------ + * main() + * ----------------------------------------------------------------------*/ + + virtual void main(int argc, char *argv[]) { + + generateBuilder = false; + sourceFileList = NewList(); + cflags = NewList(); + ldflags = NewList(); + verboseBuildLevel = NULL; + buildFlagsScript = NULL; + + gatewayHeader = NULL; + gatewayHeaderV5 = NULL; + gatewayHeaderV6 = NULL; + + createGatewayXML = false; + gatewayXML = NULL; + gatewayXMLFile = NULL; + gatewayID = NULL; + + createLoader = true; + loaderFile = NULL; + loaderScript = NULL; + + /* Manage command line arguments */ + for (int argIndex = 1; argIndex < argc; argIndex++) { + if (argv[argIndex] != NULL) { + if (strcmp(argv[argIndex], "-help") == 0) { + Printf(stdout, "%s\n", usage); + } else if (strcmp(argv[argIndex], "-builder") == 0) { + Swig_mark_arg(argIndex); + generateBuilder = true; + createLoader = false; + } else if (strcmp(argv[argIndex], "-buildersources") == 0) { + if (argv[argIndex + 1] != NULL) { + Swig_mark_arg(argIndex); + char *sourceFile = strtok(argv[argIndex + 1], ","); + while (sourceFile != NULL) { + Insert(sourceFileList, Len(sourceFileList), sourceFile); + sourceFile = strtok(NULL, ","); + } + Swig_mark_arg(argIndex + 1); + } + } else if (strcmp(argv[argIndex], "-buildercflags") == 0) { + Swig_mark_arg(argIndex); + if (argv[argIndex + 1] != NULL) { + Insert(cflags, Len(cflags), argv[argIndex + 1]); + Swig_mark_arg(argIndex + 1); + } + } else if (strcmp(argv[argIndex], "-builderldflags") == 0) { + Swig_mark_arg(argIndex); + if (argv[argIndex + 1] != NULL) { + Insert(ldflags, Len(ldflags), argv[argIndex + 1]); + Swig_mark_arg(argIndex + 1); + } + } else if (strcmp(argv[argIndex], "-builderverbositylevel") == 0) { + Swig_mark_arg(argIndex); + verboseBuildLevel = NewString(argv[argIndex + 1]); + Swig_mark_arg(argIndex + 1); + } else if (strcmp(argv[argIndex], "-builderflagscript") == 0) { + Swig_mark_arg(argIndex); + buildFlagsScript = NewString(argv[argIndex + 1]); + Swig_mark_arg(argIndex + 1); + } else if (strcmp(argv[argIndex], "-gatewayxml") == 0) { + Swig_mark_arg(argIndex); + createGatewayXML = true; + gatewayID = NewString(argv[argIndex + 1]); + Swig_mark_arg(argIndex + 1); + } + } + } + + if (verboseBuildLevel == NULL) { + verboseBuildLevel = NewString("0"); + } + + /* Set language-specific subdirectory in SWIG library */ + SWIG_library_directory("scilab"); + + /* Add a symbol to the parser for conditional compilation */ + Preprocessor_define("SWIGSCILAB 1", 0); + + /* Set scilab configuration file */ + SWIG_config_file("scilab.swg"); + + /* Set typemap for scilab */ + SWIG_typemap_lang("scilab"); + + allow_overloading(); + } + + /* ------------------------------------------------------------------------ + * top() + * ----------------------------------------------------------------------*/ + + virtual int top(Node *node) { + + /* Get the module name */ + String *gatewayName = Getattr(node, "name"); + + // Set library name + String *gatewayLibraryName = NewStringf("lib%s", gatewayName); + + /* Get the output file name */ + String *outputFilename = Getattr(node, "outfile"); + + /* Initialize I/O */ + beginSection = NewFile(outputFilename, "w", SWIG_output_files()); + if (!beginSection) { + FileErrorDisplay(outputFilename); + SWIG_exit(EXIT_FAILURE); + } + runtimeSection = NewString(""); + initSection = NewString(""); + headerSection = NewString(""); + wrappersSection = NewString(""); + + /* Register file targets with the SWIG file handler */ + Swig_register_filebyname("begin", beginSection); + Swig_register_filebyname("header", headerSection); + Swig_register_filebyname("wrapper", wrappersSection); + Swig_register_filebyname("runtime", runtimeSection); + Swig_register_filebyname("init", initSection); + + /* Output module initialization code */ + Swig_banner(beginSection); + + Printf(runtimeSection, "\n\n#ifndef SWIGSCILAB\n#define SWIGSCILAB\n#endif\n\n"); + + // Gateway header source merged with wrapper source in nobuilder mode + if (!generateBuilder) + startGatewayHeader(gatewayLibraryName); + + // Create builder file if required + if (generateBuilder) { + createBuilderFile(outputFilename); + } + + // Create gateway XML if required + if (createGatewayXML) { + createGatewayXMLFile(gatewayName); + } + + // Create loader script if required + if (createLoader) { + createLoaderFile(gatewayLibraryName); + } + + // Module initialization function + String *gatewayInitFunctionName = NewStringf("%s_Init", gatewayName); + + /* Add initialization function to builder table */ + addFunctionToScilab(gatewayInitFunctionName, gatewayInitFunctionName); + + // Add helper functions to builder table + addHelperFunctions(); + + // Open Scilab wrapper variables creation function + variablesCode = NewString(""); + Printf(variablesCode, "int SWIG_CreateScilabVariables(void *_pvApiCtx) {"); + + /* Emit code for children */ + if (CPlusPlus) { + Printf(wrappersSection, "extern \"C\" {\n"); + } + + Language::top(node); + + if (CPlusPlus) { + Printf(wrappersSection, "}\n"); + } + // Close Scilab wrapper variables creation function + Printf(variablesCode, " return SWIG_OK;\n}\n"); + + // Add Builder footer code and save + if (generateBuilder) { + saveBuilderFile(gatewayName); + } + + /* Close the init function and rename with module name */ + Printf(initSection, "return 0;\n}\n"); + Replaceall(initSection, "", gatewayName); + + /* Write all to the wrapper file */ + SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double) + + // Gateway header source merged with wrapper source in nobuilder mode + if (!generateBuilder) { + terminateGatewayHeader(gatewayLibraryName); + Printv(initSection, gatewayHeader, NIL); + } + + Dump(runtimeSection, beginSection); + Dump(headerSection, beginSection); + Dump(wrappersSection, beginSection); + Dump(variablesCode, beginSection); + Wrapper_pretty_print(initSection, beginSection); + + if (createGatewayXML) { + saveGatewayXMLFile(); + } + + if (createLoader) { + saveLoaderFile(gatewayLibraryName); + } + + /* Cleanup files */ + Delete(runtimeSection); + Delete(headerSection); + Delete(wrappersSection); + Delete(initSection); + Delete(beginSection); + + Delete(sourceFileList); + Delete(cflags); + Delete(ldflags); + + return SWIG_OK; + } + + /* ------------------------------------------------------------------------ + * emitBanner() + * ----------------------------------------------------------------------*/ + + void emitBanner(File *f) { + Printf(f, "// ----------------------------------------------------------------------------\n"); + Swig_banner_target_lang(f, "// "); + Printf(f, "// ----------------------------------------------------------------------------- */\n\n"); + } + + /* ------------------------------------------------------------------------ + * functionWrapper() + * ----------------------------------------------------------------------*/ + + virtual int functionWrapper(Node *node) { + + /* Get some useful attributes of this function */ + String *functionName = Getattr(node, "sym:name"); + SwigType *functionReturnType = Getattr(node, "type"); + ParmList *functionParamsList = Getattr(node, "parms"); + + int paramIndex = 0; // Used for loops over ParmsList + Parm *param = NULL; // Used for loops over ParamsList + + /* Create the wrapper object */ + Wrapper *wrapper = NewWrapper(); + + /* Create the function wrapper name */ + String *wrapperName = Swig_name_wrapper(functionName); + + /* Deal with overloading */ + String *overloadedName = Copy(wrapperName); + /* Determine whether the function is overloaded or not */ + bool isOverloaded = ! !Getattr(node, "sym:overloaded"); + /* Determine whether the function is the last overloaded */ + bool isLastOverloaded = isOverloaded && !Getattr(node, "sym:nextSibling"); + + if (!isOverloaded && !addSymbol(functionName, node)) { + return SWIG_ERROR; + } + + if (isOverloaded) { + Append(overloadedName, Getattr(node, "sym:overname")); + } + + /* Write the wrapper function definition (standard Scilab gateway function prototype) */ + Printv(wrapper->def, "int ", overloadedName, "(SWIG_GatewayParameters) {", NIL); + + /* Emit all of the local variables for holding arguments */ + // E.g.: double arg1; + emit_parameter_variables(functionParamsList, wrapper); + + /* Attach typemaps to the parameter list */ + // Add local variables used in typemaps (iRows, iCols, ...) + emit_attach_parmmaps(functionParamsList, wrapper); + Setattr(node, "wrap:parms", functionParamsList); + + /* Check input/output arguments count */ + int maxInputArguments = emit_num_arguments(functionParamsList); + int minInputArguments = emit_num_required(functionParamsList); + int minOutputArguments = 0; + int maxOutputArguments = 0; + + if (!emit_isvarargs(functionParamsList)) { + Printf(wrapper->code, "SWIG_CheckInputArgument(pvApiCtx, $mininputarguments, $maxinputarguments);\n"); + } + else { + Printf(wrapper->code, "SWIG_CheckInputArgumentAtLeast(pvApiCtx, $mininputarguments-1);\n"); + } + Printf(wrapper->code, "SWIG_CheckOutputArgument(pvApiCtx, $minoutputarguments, $maxoutputarguments);\n"); + + /* Set context */ + Printf(wrapper->code, "SWIG_Scilab_SetFuncName(fname);\n"); + Printf(wrapper->code, "SWIG_Scilab_SetApiContext(pvApiCtx);\n"); + + /* Write typemaps(in) */ + + for (paramIndex = 0, param = functionParamsList; paramIndex < maxInputArguments; ++paramIndex) { + // Ignore parameter if the typemap specifies numinputs=0 + while (checkAttribute(param, "tmap:in:numinputs", "0")) { + param = Getattr(param, "tmap:in:next"); + } + + SwigType *paramType = Getattr(param, "type"); + String *paramTypemap = Getattr(param, "tmap:in"); + + if (paramTypemap) { + // Replace $input by the position on Scilab stack + String *source = NewString(""); + Printf(source, "%d", paramIndex + 1); + Setattr(param, "emit:input", source); + Replaceall(paramTypemap, "$input", Getattr(param, "emit:input")); + + if (Getattr(param, "wrap:disown") || (Getattr(param, "tmap:in:disown"))) { + Replaceall(paramTypemap, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(paramTypemap, "$disown", "0"); + } + + if (paramIndex >= minInputArguments) { /* Optional input argument management */ + Printf(wrapper->code, "if (SWIG_NbInputArgument(pvApiCtx) > %d) {\n%s\n}\n", paramIndex, paramTypemap); + } else { + Printf(wrapper->code, "%s\n", paramTypemap); + } + param = Getattr(param, "tmap:in:next"); + } else { + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(paramType, 0)); + break; + } + } + + /* TODO write constraints */ + + Setattr(node, "wrap:name", overloadedName); + + /* Emit the function call */ + Swig_director_emit_dynamic_cast(node, wrapper); + String *functionActionCode = emit_action(node); + + /* Insert the return variable */ + emit_return_variable(node, functionReturnType, wrapper); + + /* Return the function value if necessary */ + String *functionReturnTypemap = Swig_typemap_lookup_out("out", node, "result", wrapper, functionActionCode); + if (functionReturnTypemap) { + // Result is actually the position of output value on stack + if (Len(functionReturnTypemap) > 0) { + Printf(wrapper->code, "SWIG_Scilab_SetOutputPosition(%d);\n", 1); + } + Replaceall(functionReturnTypemap, "$result", "1"); + + if (GetFlag(node, "feature:new")) { + Replaceall(functionReturnTypemap, "$owner", "1"); + } else { + Replaceall(functionReturnTypemap, "$owner", "0"); + } + + Printf(wrapper->code, "%s\n", functionReturnTypemap); + + /* If the typemap is not empty, the function return one more argument than the typemaps gives */ + if (Len(functionReturnTypemap) > 0) { + minOutputArguments++; + maxOutputArguments++; + } + Delete(functionReturnTypemap); + + } else { + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(functionReturnType, 0), + functionName); + } + + /* Write typemaps(out) */ + for (param = functionParamsList; param;) { + String *paramTypemap = Getattr(param, "tmap:argout"); + if (paramTypemap) { + minOutputArguments++; + maxOutputArguments++; + Printf(wrapper->code, "SWIG_Scilab_SetOutputPosition(%d);\n", minOutputArguments); + String *result = NewString(""); + Printf(result, "%d", minOutputArguments); + Replaceall(paramTypemap, "$result", result); + Printf(wrapper->code, "%s\n", paramTypemap); + Delete(paramTypemap); + param = Getattr(param, "tmap:argout:next"); + } else { + param = nextSibling(param); + } + } + /* Add cleanup code */ + for (param = functionParamsList; param;) { + String *tm; + if ((tm = Getattr(param, "tmap:freearg"))) { + if (tm && (Len(tm) != 0)) { + Replaceall(tm, "$source", Getattr(param, "lname")); + Printf(wrapper->code, "%s\n", tm); + } + param = Getattr(param, "tmap:freearg:next"); + } else { + param = nextSibling(param); + } + } + + + /* Close the function(ok) */ + Printv(wrapper->code, "return SWIG_OK;\n", NIL); + Printv(wrapper->code, "}\n", NIL); + + /* Add the failure cleanup code */ + /* TODO */ + + /* Final substititions if applicable */ + Replaceall(wrapper->code, "$symname", functionName); + + /* Set CheckInputArgument and CheckOutputArgument input arguments */ + /* In Scilab there is always one output even if not defined */ + if (minOutputArguments == 0) { + maxOutputArguments = 1; + } + String *argnumber = NewString(""); + Printf(argnumber, "%d", minInputArguments); + Replaceall(wrapper->code, "$mininputarguments", argnumber); + + argnumber = NewString(""); + Printf(argnumber, "%d", maxInputArguments); + Replaceall(wrapper->code, "$maxinputarguments", argnumber); + + argnumber = NewString(""); + Printf(argnumber, "%d", minOutputArguments); + Replaceall(wrapper->code, "$minoutputarguments", argnumber); + + argnumber = NewString(""); + Printf(argnumber, "%d", maxOutputArguments); + Replaceall(wrapper->code, "$maxoutputarguments", argnumber); + + /* Dump the function out */ + Wrapper_print(wrapper, wrappersSection); + + String *scilabFunctionName = checkIdentifierName(functionName, SCILAB_IDENTIFIER_NAME_CHAR_MAX); + + /* Update builder.sce contents */ + if (isLastOverloaded) { + addFunctionToScilab(scilabFunctionName, wrapperName); + dispatchFunction(node); + } + + if (!isOverloaded) { + addFunctionToScilab(scilabFunctionName, wrapperName); + } + + /* tidy up */ + Delete(overloadedName); + Delete(wrapperName); + DelWrapper(wrapper); + + return SWIG_OK; + } + + /* ----------------------------------------------------------------------- + * dispatchFunction() + * ----------------------------------------------------------------------- */ + + void dispatchFunction(Node *node) { + Wrapper *wrapper = NewWrapper(); + + String *functionName = Getattr(node, "sym:name"); + String *wrapperName = Swig_name_wrapper(functionName); + int maxargs = 0; + + /* Generate the dispatch function */ + String *dispatch = Swig_overload_dispatch(node, "return %s(SWIG_GatewayArguments);", &maxargs); + String *tmp = NewString(""); + + Printv(wrapper->def, "int ", wrapperName, "(SWIG_GatewayParameters) {\n", NIL); + + /* Get the number of the parameters */ + Wrapper_add_local(wrapper, "argc", "int argc = SWIG_NbInputArgument(pvApiCtx)"); + Printf(tmp, "int argv[%d] = {", maxargs); + for (int j = 0; j < maxargs; ++j) { + Printf(tmp, "%s%d", j ? "," : " ", j + 1); + } + Printf(tmp, "}"); + Wrapper_add_local(wrapper, "argv", tmp); + + Printf(wrapper->code, "SWIG_Scilab_SetApiContext(pvApiCtx);\n"); + + /* Dump the dispatch function */ + Printv(wrapper->code, dispatch, "\n", NIL); + Printf(wrapper->code, "Scierror(999, _(\"No matching function for overload\"));\n"); + Printf(wrapper->code, "return SWIG_ERROR;\n"); + Printv(wrapper->code, "}\n", NIL); + Wrapper_print(wrapper, wrappersSection); + + Delete(tmp); + DelWrapper(wrapper); + Delete(dispatch); + Delete(wrapperName); + } + + /* ----------------------------------------------------------------------- + * variableWrapper() + * ----------------------------------------------------------------------- */ + + virtual int variableWrapper(Node *node) { + + /* Get information about variable */ + String *origVariableName = Getattr(node, "name"); // Ex: Shape::nshapes + String *variableName = Getattr(node, "sym:name"); // Ex; Shape_nshapes (can be used for function names, ...) + + // Variable names can have SCILAB_VARIABLE_NAME_CHAR_MAX because of suffixes "_get" or "_set" added to function + String *scilabVariableName = checkIdentifierName(variableName, SCILAB_VARIABLE_NAME_CHAR_MAX); + + /* Manage GET function */ + Wrapper *getFunctionWrapper = NewWrapper(); + String *getFunctionName = Swig_name_get(NSPACE_TODO, variableName); + String *scilabGetFunctionName = Swig_name_get(NSPACE_TODO, scilabVariableName); + + Setattr(node, "wrap:name", getFunctionName); + Printv(getFunctionWrapper->def, "int ", getFunctionName, "(SWIG_GatewayParameters) {\n", NIL); + + /* Check the number of input and output */ + Printf(getFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 0, 0);\n"); + Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n"); + Printf(getFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n"); + + String *varoutTypemap = Swig_typemap_lookup("varout", node, origVariableName, 0); + if (varoutTypemap != NULL) { + Printf(getFunctionWrapper->code, "SWIG_Scilab_SetOutputPosition(%d);\n", 1); + Replaceall(varoutTypemap, "$value", origVariableName); + Replaceall(varoutTypemap, "$result", "1"); + emit_action_code(node, getFunctionWrapper->code, varoutTypemap); + Delete(varoutTypemap); + } + Append(getFunctionWrapper->code, "return SWIG_OK;\n"); + Append(getFunctionWrapper->code, "}\n"); + Wrapper_print(getFunctionWrapper, wrappersSection); + + /* Add function to builder table */ + addFunctionToScilab(scilabGetFunctionName, getFunctionName); + + /* Manage SET function */ + if (is_assignable(node)) { + Wrapper *setFunctionWrapper = NewWrapper(); + String *setFunctionName = Swig_name_set(NSPACE_TODO, variableName); + String *scilabSetFunctionName = Swig_name_set(NSPACE_TODO, scilabVariableName); + + Setattr(node, "wrap:name", setFunctionName); + Printv(setFunctionWrapper->def, "int ", setFunctionName, "(SWIG_GatewayParameters) {\n", NIL); + + /* Check the number of input and output */ + Printf(setFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 1, 1);\n"); + Printf(setFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n"); + Printf(setFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n"); + + String *varinTypemap = Swig_typemap_lookup("varin", node, origVariableName, 0); + if (varinTypemap != NULL) { + Replaceall(varinTypemap, "$input", "1"); + emit_action_code(node, setFunctionWrapper->code, varinTypemap); + Delete(varinTypemap); + } + Append(setFunctionWrapper->code, "return SWIG_OK;\n"); + Append(setFunctionWrapper->code, "}\n"); + Wrapper_print(setFunctionWrapper, wrappersSection); + + /* Add function to builder table */ + addFunctionToScilab(scilabSetFunctionName, setFunctionName); + } + + return SWIG_OK; + } + + /* ----------------------------------------------------------------------- + * constantWrapper() + * ----------------------------------------------------------------------- */ + + virtual int constantWrapper(Node *node) { + + /* Get the useful information from the node */ + String *nodeName = Getattr(node, "name"); + SwigType *type = Getattr(node, "type"); + String *constantName = Getattr(node, "sym:name"); + String *rawValue = Getattr(node, "rawval"); + String *constantValue = rawValue ? rawValue : Getattr(node, "value"); + String *constantTypemap = NULL; + + // If feature scilab:const enabled, constants & enums are wrapped to Scilab variables + if (GetFlag(node, "feature:scilab:const")) { + bool isConstant = ((SwigType_issimple(type)) || (SwigType_type(type) == T_STRING)); + bool isEnum = (Cmp(nodeType(node), "enumitem") == 0); + + if (isConstant || isEnum) { + if (isEnum) { + Setattr(node, "type", "double"); + constantValue = Getattr(node, "enumvalue"); + } + + constantTypemap = Swig_typemap_lookup("scilabconstcode", node, nodeName, 0); + if (constantTypemap != NULL) { + String *scilabConstantName = checkIdentifierName(constantName, SCILAB_IDENTIFIER_NAME_CHAR_MAX); + + Setattr(node, "wrap:name", constantName); + Replaceall(constantTypemap, "$result", scilabConstantName); + Replaceall(constantTypemap, "$value", constantValue); + + emit_action_code(node, variablesCode, constantTypemap); + Delete(constantTypemap); + return SWIG_OK; + } + } + } + + /* Create variables for member pointer constants, not supported by typemaps (like Python wrapper does) */ + if (SwigType_type(type) == T_MPOINTER) { + String *wname = Swig_name_wrapper(constantName); + String *str = SwigType_str(type, wname); + Printf(headerSection, "static %s = %s;\n", str, constantValue); + Delete(str); + constantValue = wname; + } + // Constant names can have SCILAB_VARIABLE_NAME_CHAR_MAX because of suffixes "_get" added to function + String *scilabConstantName = checkIdentifierName(constantName, SCILAB_VARIABLE_NAME_CHAR_MAX); + + /* Create GET function to get the constant value */ + Wrapper *getFunctionWrapper = NewWrapper(); + String *getFunctionName = Swig_name_get(NSPACE_TODO, constantName); + String *scilabGetFunctionName = Swig_name_get(NSPACE_TODO, scilabConstantName); + Setattr(node, "wrap:name", getFunctionName); + Printv(getFunctionWrapper->def, "int ", getFunctionName, "(SWIG_GatewayParameters) {\n", NIL); + + /* Check the number of input and output */ + Printf(getFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 0, 0);\n"); + Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n"); + Printf(getFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n"); + + constantTypemap = Swig_typemap_lookup("constcode", node, nodeName, 0); + if (constantTypemap != NULL) { + Printf(getFunctionWrapper->code, "SWIG_Scilab_SetOutputPosition(%d);\n", 1); + Replaceall(constantTypemap, "$value", constantValue); + Replaceall(constantTypemap, "$result", "1"); + emit_action_code(node, getFunctionWrapper->code, constantTypemap); + Delete(constantTypemap); + } + + /* Dump the wrapper function */ + Append(getFunctionWrapper->code, "return SWIG_OK;\n"); + Append(getFunctionWrapper->code, "}\n"); + Wrapper_print(getFunctionWrapper, wrappersSection); + + /* Add the function to Scilab */ + addFunctionToScilab(scilabGetFunctionName, getFunctionName); + + DelWrapper(getFunctionWrapper); + + return SWIG_OK; + } + + /* --------------------------------------------------------------------- + * enumvalueDeclaration() + * --------------------------------------------------------------------- */ + + virtual int enumvalueDeclaration(Node *node) { + static int iPreviousEnumValue = 0; + + if (GetFlag(node, "feature:scilab:const")) { + // Compute the "absolute" value of enum if needed + // (most of time enum values are a linked list of relative values) + String *enumValue = Getattr(node, "enumvalue"); + String *enumValueEx = Getattr(node, "enumvalueex"); + + // First enum value ? + String *firstenumitem = Getattr(node, "firstenumitem"); + if (firstenumitem) { + if (enumValue) { + // Value is in 'enumvalue' + iPreviousEnumValue = atoi(Char(enumValue)); + } else if (enumValueEx) { + // Or value is in 'enumValueEx' + iPreviousEnumValue = atoi(Char(enumValueEx)); + + enumValue = NewString(""); + Printf(enumValue, "%d", iPreviousEnumValue); + Setattr(node, "enumvalue", enumValue); + } + } else if (!enumValue && enumValueEx) { + // Value is not specified, set it by incrementing last value + enumValue = NewString(""); + Printf(enumValue, "%d", ++iPreviousEnumValue); + Setattr(node, "enumvalue", enumValue); + } + // Enums in Scilab are mapped to double + Setattr(node, "type", "double"); + } + + return Language::enumvalueDeclaration(node); + } + + /* --------------------------------------------------------------------- + * membervariableHandler() + * --------------------------------------------------------------------- */ + virtual int membervariableHandler(Node *node) { + checkMemberIdentifierName(node, SCILAB_VARIABLE_NAME_CHAR_MAX); + return Language::membervariableHandler(node); + } + + /* ----------------------------------------------------------------------- + * checkIdentifierName() + * Truncates (and displays a warning) for too long identifier names + * (applies on functions, variables, constants...) + * (Scilab identifiers names are limited to 24 chars max) + * ----------------------------------------------------------------------- */ + + String *checkIdentifierName(String *name, int char_size_max) { + String *scilabIdentifierName; + if (Len(name) > char_size_max) { + scilabIdentifierName = DohNewStringWithSize(name, char_size_max); + Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number, + "Identifier name '%s' exceeds 24 characters and has been truncated to '%s'.\n", name, scilabIdentifierName); + } else + scilabIdentifierName = name; + return scilabIdentifierName; + } + + /* ----------------------------------------------------------------------- + * checkMemberIdentifierName() + * Truncates (and displays a warning) too long member identifier names + * (applies on members of structs, classes...) + * (Scilab identifiers names are limited to 24 chars max) + * ----------------------------------------------------------------------- */ + + void checkMemberIdentifierName(Node *node, int char_size_max) { + + String *memberName = Getattr(node, "sym:name"); + + Node *containerNode = parentNode(node); + String *containerName = Getattr(containerNode, "sym:name"); + + int lenContainerName = Len(containerName); + int lenMemberName = Len(memberName); + + if (lenContainerName + lenMemberName + 1 > char_size_max) { + int lenScilabMemberName = char_size_max - lenContainerName - 1; + + if (lenScilabMemberName > 0) { + String *scilabMemberName = DohNewStringWithSize(memberName, lenScilabMemberName); + Setattr(node, "sym:name", scilabMemberName); + Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number, + "Wrapping functions names for member '%s.%s' will exceed 24 characters, " + "so member name has been truncated to '%s'.\n", containerName, memberName, scilabMemberName); + } else + Swig_error(input_file, line_number, + "Wrapping functions names for member '%s.%s' will exceed 24 characters, " + "please rename the container of member '%s'.\n", containerName, memberName, containerName); + } + } + + + + /* ----------------------------------------------------------------------- + * addHelperFunctions() + * ----------------------------------------------------------------------- */ + + void addHelperFunctions() { + addFunctionToScilab("SWIG_this", "SWIG_this"); + addFunctionToScilab("SWIG_ptr", "SWIG_ptr"); + } + + /* ----------------------------------------------------------------------- + * addFunctionToScilab() + * Declare a wrapped function in Scilab (builder, gateway, XML, ...) + * ----------------------------------------------------------------------- */ + + void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) { + if (!generateBuilder) + addFunctionInGatewayHeader(scilabFunctionName, wrapperFunctionName); + + if (generateBuilder) { + addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, builderCode); + } + + if (createLoader) { + addFunctionInLoader(scilabFunctionName); + } + + if (gatewayXMLFile) { + Printf(gatewayXML, "\n", gatewayID, primitiveID++, scilabFunctionName); + } + } + + + /* ----------------------------------------------------------------------- + * createBuilderCode() + * ----------------------------------------------------------------------- */ + + void createBuilderFile(String *outputFilename) { + String *builderFilename = NewStringf("builder.sce"); + builderFile = NewFile(builderFilename, "w", SWIG_output_files()); + if (!builderFile) { + FileErrorDisplay(builderFilename); + SWIG_exit(EXIT_FAILURE); + } + emitBanner(builderFile); + + builderFunctionCount = 0; + builderCode = NewString(""); + Printf(builderCode, "mode(-1);\n"); + Printf(builderCode, "lines(0);\n"); /* Useful for automatic tests */ + + // Scilab needs to be in the build directory + Printf(builderCode, "originaldir = pwd();\n"); + Printf(builderCode, "builddir = get_absolute_file_path('builder.sce');\n"); + Printf(builderCode, "cd(builddir);\n"); + + Printf(builderCode, "ilib_verbose(%s);\n", verboseBuildLevel); + + Printf(builderCode, "libs = [];\n"); + + // Flags from command line arguments + Printf(builderCode, "cflags = [];\n"); + for (int i = 0; i < Len(cflags); i++) { + String *cflag = Getitem(cflags, i); + Printf(builderCode, "cflags = cflags + \" %s\";\n", cflag); + } + + if (Len(ldflags) > 0) { + for (int i = 0; i < Len(ldflags); i++) { + String *ldflag = Getitem(ldflags, i); + if (i == 0) { + Printf(builderCode, "ldflags = \"%s\";\n", ldflag); + } else { + Printf(builderCode, "ldflags = ldflags + \" %s\";\n", ldflag); + } + } + } else { + Printf(builderCode, "ldflags = [];\n"); + } + + // External script to set flags + if (buildFlagsScript) { + Printf(builderCode, "exec(\"%s\");\n", buildFlagsScript); + Printf(builderCode, "cflags = cflags + getCompilationFlags();\n"); + Printf(builderCode, "ldflags = ldflags + getLinkFlags();\n"); + } + // Additional sources + Insert(sourceFileList, 0, outputFilename); + for (int i = 0; i < Len(sourceFileList); i++) { + String *sourceFile = Getitem(sourceFileList, i); + if (i == 0) { + Printf(builderCode, "files = \"%s\";\n", sourceFile); + } else { + Printf(builderCode, "files($ + 1) = \"%s\";\n", sourceFile); + } + } + + Printf(builderCode, "table = ["); + } + + /* ----------------------------------------------------------------------- + * addFunctionInBuilderCode() + * Add a function wrapper in the function table of generated builder script + * ----------------------------------------------------------------------- */ + + void addFunctionInScriptTable(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName, String *scriptCode) { + if (++builderFunctionCount % 10 == 0) { + Printf(scriptCode, "];\ntable = [table;"); + } + Printf(scriptCode, "\"%s\",\"%s\";", scilabFunctionName, wrapperFunctionName); + } + + /* ----------------------------------------------------------------------- + * saveBuilderFile() + * ----------------------------------------------------------------------- */ + + void saveBuilderFile(String *gatewayName) { + Printf(builderCode, "];\n"); + Printf(builderCode, "ierr = 0;\n"); + Printf(builderCode, "if ~isempty(table) then\n"); + Printf(builderCode, " ierr = execstr(\"ilib_build(''%s'', table, files, libs, [], ldflags, cflags);\", 'errcatch');\n", gatewayName); + Printf(builderCode, " if ierr <> 0 then\n"); + Printf(builderCode, " err_msg = lasterror();\n"); + Printf(builderCode, " end\n"); + Printf(builderCode, "end\n"); + Printf(builderCode, "cd(originaldir);\n"); + Printf(builderCode, "if ierr <> 0 then\n"); + Printf(builderCode, " error(ierr, err_msg);\n"); + Printf(builderCode, "end\n"); + Printv(builderFile, builderCode, NIL); + Delete(builderFile); + } + + /* ----------------------------------------------------------------------- + * createGatewayXMLFile() + * This XML file is used by Scilab in the context of internal modules + * ----------------------------------------------------------------------- */ + + void createGatewayXMLFile(String *gatewayName) { + String *gatewayXMLFilename = NewStringf("%s_gateway.xml", gatewayName); + gatewayXMLFile = NewFile(gatewayXMLFilename, "w", SWIG_output_files()); + if (!gatewayXMLFile) { + FileErrorDisplay(gatewayXMLFilename); + SWIG_exit(EXIT_FAILURE); + } + // Add a slightly modified SWIG banner to the gateway XML ("--modify" is illegal in XML) + gatewayXML = NewString(""); + Printf(gatewayXML, "\n"); + Printf(gatewayXML, "\n"); + Printf(gatewayXML, "\n", gatewayName); + + primitiveID = 1; + } + + /* ----------------------------------------------------------------------- + * saveGatewayXMLFile() + * ----------------------------------------------------------------------- */ + + void saveGatewayXMLFile() { + Printf(gatewayXML, "\n"); + Printv(gatewayXMLFile, gatewayXML, NIL); + Delete(gatewayXMLFile); + } + + /* ----------------------------------------------------------------------- + * startGatewayHeader() + * Start the gateway header + * ----------------------------------------------------------------------- */ + void startGatewayHeader(String *gatewayLibraryName) { + gatewayHeader = NewString(""); + Printf(gatewayHeader, "\n"); + + gatewayHeaderV6 = NewString(""); + Printf(gatewayHeaderV6, "#include \"c_gateway_prototype.h\"\n"); + Printf(gatewayHeaderV6, "#include \"addfunction.h\"\n"); + Printf(gatewayHeaderV6, "\n"); + Printf(gatewayHeaderV6, "#define MODULE_NAME L\"%s\"\n", gatewayLibraryName); + Printf(gatewayHeaderV6, "#ifdef __cplusplus\n"); + Printf(gatewayHeaderV6, "extern \"C\"\n"); + Printf(gatewayHeaderV6, "#endif\n"); + Printf(gatewayHeaderV6, "int %s(wchar_t *pwstFuncName) {\n", gatewayLibraryName); + Printf(gatewayHeaderV6, "\n"); + } + + /* ----------------------------------------------------------------------- + * addFunctionInGatewayHeader() + * Add a function in the gateway header + * ----------------------------------------------------------------------- */ + + void addFunctionInGatewayHeader(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) { + if (gatewayHeaderV5 == NULL) { + gatewayHeaderV5 = NewString(""); + Printf(gatewayHeaderV5, "static GenericTable Tab[] = {\n"); + } else + Printf(gatewayHeaderV5, ",\n"); + Printf(gatewayHeaderV5, " {(Myinterfun)sci_gateway, (GT)%s, (char *)\"%s\"}", wrapperFunctionName, scilabFunctionName); + + Printf(gatewayHeaderV6, "if (wcscmp(pwstFuncName, L\"%s\") == 0) { addCFunction((wchar_t *)L\"%s\", &%s, (wchar_t *)MODULE_NAME); }\n", scilabFunctionName, scilabFunctionName, wrapperFunctionName); + } + + /* ----------------------------------------------------------------------- + * terminateGatewayHeader() + * Terminates the gateway header + * ----------------------------------------------------------------------- */ + + void terminateGatewayHeader(String *gatewayLibraryName) { + Printf(gatewayHeaderV5, "};\n"); + Printf(gatewayHeaderV5, "\n"); + Printf(gatewayHeaderV5, "#ifdef __cplusplus\n"); + Printf(gatewayHeaderV5, "extern \"C\" {\n"); + Printf(gatewayHeaderV5, "#endif\n"); + Printf(gatewayHeaderV5, "int C2F(%s)() {\n", gatewayLibraryName); + Printf(gatewayHeaderV5, " Rhs = Max(0, Rhs);\n"); + Printf(gatewayHeaderV5, " if (*(Tab[Fin-1].f) != NULL) {\n"); + Printf(gatewayHeaderV5, " if(pvApiCtx == NULL) {\n"); + Printf(gatewayHeaderV5, " pvApiCtx = (StrCtx *)MALLOC(sizeof(StrCtx));\n"); + Printf(gatewayHeaderV5, " }\n"); + Printf(gatewayHeaderV5, " pvApiCtx->pstName = (char *)Tab[Fin-1].name;\n"); + Printf(gatewayHeaderV5, " (*(Tab[Fin-1].f))(Tab[Fin-1].name,(GatefuncH)Tab[Fin-1].F);\n"); + Printf(gatewayHeaderV5, " }\n"); + Printf(gatewayHeaderV5, " return 0;\n"); + Printf(gatewayHeaderV5, "}\n"); + Printf(gatewayHeaderV5, "\n"); + Printf(gatewayHeaderV5, "#ifdef __cplusplus\n"); + Printf(gatewayHeaderV5, "}\n"); + Printf(gatewayHeaderV5, "#endif\n"); + + Printf(gatewayHeaderV6, "return 1;\n"); + Printf(gatewayHeaderV6, "};\n"); + + Printf(gatewayHeader, "#if SWIG_SCILAB_VERSION >= 600\n"); + Printv(gatewayHeader, gatewayHeaderV6, NIL); + Printf(gatewayHeader, "#else\n"); + Printv(gatewayHeader, gatewayHeaderV5, NIL); + Printf(gatewayHeader, "#endif\n"); + } + + + /* ----------------------------------------------------------------------- + * createLoaderScriptFile() + * Creates the loader script file (loader.sce) + * ----------------------------------------------------------------------- */ + + void createLoaderFile(String *gatewayLibraryName) { + String *loaderFilename = NewString("loader.sce"); + loaderFile = NewFile(loaderFilename, "w", SWIG_output_files()); + if (!loaderFile) { + FileErrorDisplay(loaderFilename); + SWIG_exit(EXIT_FAILURE); + } + + emitBanner(loaderFile); + + loaderScript = NewString(""); + Printf(loaderScript, "%s_path = get_absolute_file_path('loader.sce');\n", gatewayLibraryName); + Printf(loaderScript, "[bOK, ilib] = c_link('%s');\n", gatewayLibraryName); + Printf(loaderScript, "if bOK then\n"); + Printf(loaderScript, " ulink(ilib);\n"); + Printf(loaderScript, "end\n"); + Printf(loaderScript, "list_functions = [..\n"); + } + + /* ----------------------------------------------------------------------- + * addFunctionInLoaderScript() + * Add a function in the loader script table + * ----------------------------------------------------------------------- */ + + void addFunctionInLoader(const_String_or_char_ptr scilabFunctionName) { + Printf(loaderScript, " '%s'; ..\n", scilabFunctionName); + } + + /* ----------------------------------------------------------------------- + * saveLoaderScriptFile() + * Terminates and saves the loader script + * ----------------------------------------------------------------------- */ + + void saveLoaderFile(String *gatewayLibraryName) { + Printf(loaderScript, "];\n"); + Printf(loaderScript, "addinter(fullfile(%s_path, '%s' + getdynlibext()), '%s', list_functions);\n", + gatewayLibraryName, gatewayLibraryName, gatewayLibraryName); + Printf(loaderScript, "clear %s_path;\n", gatewayLibraryName); + Printf(loaderScript, "clear bOK;\n"); + Printf(loaderScript, "clear ilib;\n"); + Printf(loaderScript, "clear list_functions;\n"); + Printv(loaderFile, loaderScript, NIL); + + Delete(loaderFile); + } + +}; + +extern "C" Language *swig_scilab(void) { + return new SCILAB(); +} diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx index 6e2aa47b183..f895d202f9a 100644 --- a/Source/Modules/swigmain.cxx +++ b/Source/Modules/swigmain.cxx @@ -50,6 +50,7 @@ extern "C" { Language *swig_cffi(void); Language *swig_uffi(void); Language *swig_r(void); + Language *swig_scilab(void); Language *swig_go(void); Language *swig_d(void); Language *swig_javascript(void); @@ -91,6 +92,7 @@ static swig_module modules[] = { {"-python", swig_python, "Python"}, {"-r", swig_r, "R (aka GNU S)"}, {"-ruby", swig_ruby, "Ruby"}, + {"-scilab", swig_scilab, "Scilab"}, {"-sexp", swig_sexp, "Lisp S-Expressions"}, {"-tcl", swig_tcl, "Tcl"}, {"-tcl8", swig_tcl, 0}, diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index a30fdf8fa77..c4007be5102 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -18,12 +18,6 @@ #include "preprocessor.h" #include "swigwarn.h" -#if !defined(HAVE_BOOL) -typedef int bool; -#define true ((bool)1) -#define false ((bool)0) -#endif - #define NOT_VIRTUAL 0 #define PLAIN_VIRTUAL 1 #define PURE_VIRTUAL 2 diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index ac356098be4..1227af79c97 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -13,7 +13,6 @@ #include "swigmod.h" #include "cparse.h" -static int treduce = SWIG_cparse_template_reduce(0); static const char *usage = "\ Tcl 8 Options (available with -tcl)\n\ @@ -166,9 +165,7 @@ class TCL8:public Language { Swig_banner(f_begin); - Printf(f_runtime, "\n"); - Printf(f_runtime, "#define SWIGTCL\n"); - Printf(f_runtime, "\n"); + Printf(f_runtime, "\n\n#ifndef SWIGTCL\n#define SWIGTCL\n#endif\n\n"); /* Set the module name, namespace, and prefix */ @@ -969,7 +966,7 @@ class TCL8:public Language { Printf(f_wrappers, ",0"); } Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases,", - "swig_", mangled_classname, "_base_names, &swig_module };\n", NIL); + "swig_", mangled_classname, "_base_names, &swig_module, SWIG_TCL_HASHTABLE_INIT };\n", NIL); if (!itcl) { Printv(cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, (ClientData)&_wrap_class_", mangled_classname, diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 3e323f9102d..da077fd076d 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -254,41 +254,38 @@ class TypePass:private Dispatcher { Node *bclass = n; /* Getattr(n,"class"); */ Hash *scopes = Getattr(bclass, "typescope"); SwigType_inherit(clsname, bname, cast, 0); - String *smartptr = Getattr(first, "feature:smartptr"); - if (smartptr) { - SwigType *smart = 0; - SwigType *spt = Swig_cparse_type(smartptr); - if (spt) { - smart = SwigType_typedef_resolve_all(spt); - Delete(spt); - /* Record a (fake) inheritance relationship between smart pointer - and smart pointer to base class, so that smart pointer upcasts - are automatically generated. */ - SwigType *bsmart = Copy(smart); - SwigType *rclsname = SwigType_typedef_resolve_all(clsname); - SwigType *rbname = SwigType_typedef_resolve_all(bname); - Replaceall(bsmart, rclsname, rbname); - Delete(rclsname); - Delete(rbname); - String *smartnamestr = SwigType_namestr(smart); - String *bsmartnamestr = SwigType_namestr(bsmart); - /* construct casting code */ - String *convcode = NewStringf("\n *newmemory = SWIG_CAST_NEW_MEMORY;\n return (void *) new %s(*(%s *)$from);\n", bsmartnamestr, smartnamestr); - Delete(bsmartnamestr); - Delete(smartnamestr); - /* setup inheritance relationship between smart pointer templates */ - SwigType_inherit(smart, bsmart, 0, convcode); - if (!GetFlag(bclass, "feature:smartptr")) - Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Base class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(bclass, "name")), SwigType_namestr(Getattr(first, "name"))); - Delete(convcode); - Delete(bsmart); + if (ispublic && !GetFlag(bclass, "feature:ignore")) { + String *smartptr = Getattr(first, "feature:smartptr"); + if (smartptr) { + SwigType *smart = Swig_cparse_smartptr(first); + if (smart) { + /* Record a (fake) inheritance relationship between smart pointer + and smart pointer to base class, so that smart pointer upcasts + are automatically generated. */ + SwigType *bsmart = Copy(smart); + SwigType *rclsname = SwigType_typedef_resolve_all(clsname); + SwigType *rbname = SwigType_typedef_resolve_all(bname); + Replaceall(bsmart, rclsname, rbname); + Delete(rclsname); + Delete(rbname); + String *smartnamestr = SwigType_namestr(smart); + String *bsmartnamestr = SwigType_namestr(bsmart); + /* construct casting code */ + String *convcode = NewStringf("\n *newmemory = SWIG_CAST_NEW_MEMORY;\n return (void *) new %s(*(%s *)$from);\n", bsmartnamestr, smartnamestr); + Delete(bsmartnamestr); + Delete(smartnamestr); + /* setup inheritance relationship between smart pointer templates */ + SwigType_inherit(smart, bsmart, 0, convcode); + if (!GetFlag(bclass, "feature:smartptr")) + Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Base class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(bclass, "name")), SwigType_namestr(Getattr(first, "name"))); + Delete(convcode); + Delete(bsmart); + } Delete(smart); } else { - Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", SwigType_namestr(smartptr), SwigType_namestr(clsname)); + if (GetFlag(bclass, "feature:smartptr")) + Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Derived class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(first, "name")), SwigType_namestr(Getattr(bclass, "name"))); } - } else { - if (GetFlag(bclass, "feature:smartptr")) - Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Derived class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(first, "name")), SwigType_namestr(Getattr(bclass, "name"))); } if (!importmode) { String *btype = Copy(bname); diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index ac912f49e15..a183eecde59 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1771,7 +1771,10 @@ String *Preprocessor_parse(String *s) { } else if (Equal(id, "")) { /* Null directive */ } else { - Swig_error(Getfile(s), Getline(id), "Unknown SWIG preprocessor directive: %s (if this is a block of target language code, delimit it with %%{ and %%})\n", id); + /* Ignore unknown preprocessor directives which are inside an inactive + * conditional (github issue #394). */ + if (allow) + Swig_error(Getfile(s), Getline(id), "Unknown SWIG preprocessor directive: %s (if this is a block of target language code, delimit it with %%{ and %%})\n", id); } for (i = 0; i < cpp_lines; i++) Putc('\n', ns); diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 7e80172bab9..08226a25c2e 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -194,7 +194,7 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_ lastpath = filename; /* Skip the UTF-8 BOM if it's present */ - nbytes = fread(bom, 1, 3, f); + nbytes = (int)fread(bom, 1, 3, f); if (nbytes == 3 && bom[0] == (char)0xEF && bom[1] == (char)0xBB && bom[2] == (char)0xBF) { /* skip */ } else { @@ -369,7 +369,7 @@ String *Swig_file_filename(const_String_or_char_ptr filename) { String *Swig_file_dirname(const_String_or_char_ptr filename) { const char *delim = SWIG_FILE_DELIMITER; const char *c = strrchr(Char(filename), *delim); - return c ? NewStringWithSize(filename, c - Char(filename) + 1) : NewString(""); + return c ? NewStringWithSize(filename, (int)(c - Char(filename) + 1)) : NewString(""); } /* diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 7a6fb011461..c552ac2cb5f 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -127,7 +127,7 @@ String *Swig_strip_c_comments(const String *s) { } if (comment_begin && comment_end) { - int size = comment_begin - Char(s); + int size = (int)(comment_begin - Char(s)); String *stripmore = 0; stripped = NewStringWithSize(s, size); Printv(stripped, comment_end + 1, NIL); @@ -808,7 +808,7 @@ void Swig_scopename_split(const String *s, String **rprefix, String **rlast) { *rlast = Copy(s); return; } else { - *rprefix = NewStringWithSize(cc, co - cc - 2); + *rprefix = NewStringWithSize(cc, (int)(co - cc - 2)); *rlast = NewString(co); return; } @@ -835,7 +835,7 @@ void Swig_scopename_split(const String *s, String **rprefix, String **rlast) { } if (cc != tmp) { - *rprefix = NewStringWithSize(tmp, cc - tmp); + *rprefix = NewStringWithSize(tmp, (int)(cc - tmp)); *rlast = NewString(cc + 2); return; } else { @@ -858,7 +858,7 @@ String *Swig_scopename_prefix(const String *s) { if (co == cc) { return 0; } else { - String *prefix = NewStringWithSize(cc, co - cc - 2); + String *prefix = NewStringWithSize(cc, (int)(co - cc - 2)); return prefix; } } @@ -884,7 +884,7 @@ String *Swig_scopename_prefix(const String *s) { } if (cc != tmp) { - return NewStringWithSize(tmp, cc - tmp); + return NewStringWithSize(tmp, (int)(cc - tmp)); } else { return 0; } @@ -977,7 +977,7 @@ String *Swig_scopename_first(const String *s) { } } if (*c && (c != tmp)) { - return NewStringWithSize(tmp, c - tmp); + return NewStringWithSize(tmp, (int)(c - tmp)); } else { return 0; } @@ -1219,8 +1219,8 @@ static int split_regex_pattern_subst(String *s, String **pattern, String **subst if (!p) goto err_out; sube = p; - *pattern = NewStringWithSize(pats, pate - pats); - *subst = NewStringWithSize(subs, sube - subs); + *pattern = NewStringWithSize(pats, (int)(pate - pats)); + *subst = NewStringWithSize(subs, (int)(sube - subs)); *input = p + 1; return 1; @@ -1270,10 +1270,10 @@ String *replace_captures(int num_captures, const char *input, String *subst, int /* Copy part without substitutions */ const char *q = strchr(p, '\\'); if (!q) { - copy_with_maybe_case_conversion(result, p, strlen(p), &convertCase, convertNextOnly); + copy_with_maybe_case_conversion(result, p, (int)strlen(p), &convertCase, convertNextOnly); break; } - copy_with_maybe_case_conversion(result, p, q - p, &convertCase, convertNextOnly); + copy_with_maybe_case_conversion(result, p, (int)(q - p), &convertCase, convertNextOnly); p = q + 1; /* Handle substitution */ @@ -1350,7 +1350,7 @@ String *Swig_string_regex(String *s) { pcre_error, Char(pattern), pcre_errorpos); exit(1); } - rc = pcre_exec(compiled_pat, NULL, input, strlen(input), 0, 0, captures, 30); + rc = pcre_exec(compiled_pat, NULL, input, (int)strlen(input), 0, 0, captures, 30); if (rc >= 0) { res = replace_captures(rc, input, subst, captures, pattern, s); } else if (rc != PCRE_ERROR_NOMATCH) { diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 9e2b4a436ef..2d1effa186a 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -578,7 +578,7 @@ void Swig_name_object_inherit(Hash *namehash, String *base, String *derived) { bprefix = NewStringf("%s::", base); dprefix = NewStringf("%s::", derived); cbprefix = Char(bprefix); - plen = strlen(cbprefix); + plen = (int)strlen(cbprefix); for (ki = First(namehash); ki.key; ki = Next(ki)) { char *k = Char(ki.key); if (strncmp(k, cbprefix, plen) == 0) { @@ -1003,6 +1003,10 @@ static int nodes_are_equivalent(Node *a, Node *b, int a_inclass) { } return 0; } + if (Equal(ta, "template") && Equal(tb, "template")) { + if (Cmp(a_storage, "friend") == 0 || Cmp(b_storage, "friend") == 0) + return 1; + } } return 0; } @@ -1070,7 +1074,7 @@ static List *Swig_make_attrlist(const char *ckey) { String *nattr; const char *rattr = strchr(++cattr, '$'); while (rattr) { - nattr = NewStringWithSize(cattr, rattr - cattr); + nattr = NewStringWithSize(cattr, (int)(rattr - cattr)); Append(list, nattr); Delete(nattr); cattr = rattr + 1; diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index b0d608c9e1c..227a1d00c54 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -336,7 +336,7 @@ static void brackets_reset(Scanner *s) { * Usually called when '(' is found. * ----------------------------------------------------------------------------- */ static void brackets_push(Scanner *s) { - int *newInt = malloc(sizeof(int)); + int *newInt = (int *)malloc(sizeof(int)); *newInt = 0; Push(s->brackets, NewVoid(newInt, free)); } diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 506878799d7..a572227458d 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -195,7 +195,7 @@ int SwigType_ispointer_return(const SwigType *t) { if (!t) return 0; c = Char(t); - idx = strlen(c) - 4; + idx = (int)strlen(c) - 4; if (idx >= 0) { return (strcmp(c + idx, ").p.") == 0); } @@ -208,7 +208,7 @@ int SwigType_isreference_return(const SwigType *t) { if (!t) return 0; c = Char(t); - idx = strlen(c) - 4; + idx = (int)strlen(c) - 4; if (idx >= 0) { return (strcmp(c + idx, ").r.") == 0); } @@ -485,7 +485,7 @@ String *SwigType_namestr(const SwigType *t) { if (!c || !strstr(c + 2, ")>")) return NewString(t); - r = NewStringWithSize(d, c - d); + r = NewStringWithSize(d, (int)(c - d)); if (*(c - 1) == '<') Putc(' ', r); Putc('<', r); diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 5ee7f8d95b9..becae945661 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -409,8 +409,6 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f); extern String *Swig_typemap_lookup_out(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f, String *actioncode); - extern void Swig_typemap_new_scope(void); - extern Hash *Swig_typemap_pop_scope(void); extern void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *parms, Wrapper *f); diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 2202f61c646..d72451a14a2 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -1149,7 +1149,7 @@ Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) { Symtab *un = Getattr(s, "sym:symtab"); Node *ss = (!Equal(name, uname) || (un != n)) ? Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */ if (!ss) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname")); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname"))); } s = ss; } @@ -1221,7 +1221,7 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (* Node *ss; ss = Swig_symbol_clookup(Getattr(s, "uname"), Getattr(s, "sym:symtab")); if (!ss && !checkfunc) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname")); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname"))); } s = ss; } @@ -1272,7 +1272,7 @@ Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) { while (s && Checkattr(s, "nodeType", "using")) { Node *ss = Swig_symbol_clookup_local(Getattr(s, "uname"), Getattr(s, "sym:symtab")); if (!ss) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname")); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname"))); } s = ss; } @@ -1320,7 +1320,7 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n, while (s && Checkattr(s, "nodeType", "using")) { Node *ss = Swig_symbol_clookup_local_check(Getattr(s, "uname"), Getattr(s, "sym:symtab"), checkfunc); if (!ss && !checkfunc) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname")); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname"))); } s = ss; } diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index d817f1a857c..78c04dc9070 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -68,7 +68,7 @@ void Swig_print_node(Node *obj) { Node *cobj; print_indent(0); - Printf(stdout, "+++ %s ----------------------------------------\n", nodeType(obj)); + Printf(stdout, "+++ %s - %p ----------------------------------------\n", nodeType(obj), obj); ki = First(obj); while (ki.key) { String *k = ki.key; diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 0bfbb4bce33..ab2a8c0df4c 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -59,13 +59,9 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper * * ----------------------------------------------------------------------------- */ -#define MAX_SCOPE 32 +static Hash *typemaps; - -static Hash *typemaps[MAX_SCOPE]; -static int tm_scope = 0; - -static Hash *get_typemap(int tm_scope, const SwigType *type) { +static Hash *get_typemap(const SwigType *type) { Hash *tm = 0; SwigType *dtype = 0; SwigType *hashtype; @@ -79,7 +75,7 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) { /* remove unary scope operator (::) prefix indicating global scope for looking up in the hashmap */ hashtype = SwigType_remove_global_scope_prefix(type); - tm = Getattr(typemaps[tm_scope], hashtype); + tm = Getattr(typemaps, hashtype); Delete(dtype); Delete(hashtype); @@ -87,7 +83,7 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) { return tm; } -static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) { +static void set_typemap(const SwigType *type, Hash **tmhash) { SwigType *hashtype = 0; Hash *new_tm = 0; assert(*tmhash == 0); @@ -96,7 +92,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) { String *ty = Swig_symbol_template_deftype(rty, 0); String *tyq = Swig_symbol_type_qualify(ty, 0); hashtype = SwigType_remove_global_scope_prefix(tyq); - *tmhash = Getattr(typemaps[tm_scope], hashtype); + *tmhash = Getattr(typemaps, hashtype); Delete(rty); Delete(tyq); Delete(ty); @@ -111,7 +107,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) { } /* note that the unary scope operator (::) prefix indicating global scope has been removed from the type */ - Setattr(typemaps[tm_scope], hashtype, *tmhash); + Setattr(typemaps, hashtype, *tmhash); Delete(hashtype); Delete(new_tm); @@ -125,12 +121,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) { * ----------------------------------------------------------------------------- */ void Swig_typemap_init() { - int i; - for (i = 0; i < MAX_SCOPE; i++) { - typemaps[i] = 0; - } - typemaps[0] = NewHash(); - tm_scope = 0; + typemaps = NewHash(); } static String *typemap_method_name(const_String_or_char_ptr tmap_method) { @@ -160,32 +151,6 @@ static String *typemap_method_name(const_String_or_char_ptr tmap_method) { return s; } -#if 0 -/* ----------------------------------------------------------------------------- - * Swig_typemap_new_scope() - * - * Create a new typemap scope - * ----------------------------------------------------------------------------- */ - -void Swig_typemap_new_scope() { - tm_scope++; - typemaps[tm_scope] = NewHash(); -} - -/* ----------------------------------------------------------------------------- - * Swig_typemap_pop_scope() - * - * Pop the last typemap scope off - * ----------------------------------------------------------------------------- */ - -Hash *Swig_typemap_pop_scope() { - if (tm_scope > 0) { - return typemaps[tm_scope--]; - } - return 0; -} -#endif - /* ----------------------------------------------------------------------------- * typemap_register() * @@ -216,9 +181,9 @@ static void typemap_register(const_String_or_char_ptr tmap_method, ParmList *par pname = Getattr(parms, "name"); /* See if this type has been seen before */ - tm = get_typemap(tm_scope, type); + tm = get_typemap(type); if (!tm) { - set_typemap(tm_scope, type, &tm); + set_typemap(type, &tm); } if (pname) { /* See if parameter has been seen before */ @@ -311,15 +276,12 @@ void Swig_typemap_register(const_String_or_char_ptr tmap_method, ParmList *parms /* ----------------------------------------------------------------------------- * typemap_get() * - * Retrieve typemap information from current scope. + * Retrieve typemap information. * ----------------------------------------------------------------------------- */ -static Hash *typemap_get(SwigType *type, const_String_or_char_ptr name, int scope) { +static Hash *typemap_get(SwigType *type, const_String_or_char_ptr name) { Hash *tm, *tm1; - /* See if this type has been seen before */ - if ((scope < 0) || (scope > tm_scope)) - return 0; - tm = get_typemap(scope, type); + tm = get_typemap(type); if (!tm) { return 0; } @@ -342,51 +304,48 @@ int Swig_typemap_copy(const_String_or_char_ptr tmap_method, ParmList *srcparms, Parm *p; String *pname; SwigType *ptype; - int ts = tm_scope; String *tm_methods, *multi_tmap_method; if (ParmList_len(parms) != ParmList_len(srcparms)) return -1; tm_method = typemap_method_name(tmap_method); - while (ts >= 0) { - p = srcparms; - tm_methods = NewString(tm_method); - while (p) { - ptype = Getattr(p, "type"); - pname = Getattr(p, "name"); + p = srcparms; + tm_methods = NewString(tm_method); + while (p) { + ptype = Getattr(p, "type"); + pname = Getattr(p, "name"); - /* Lookup the type */ - tm = typemap_get(ptype, pname, ts); - if (!tm) - break; + /* Lookup the type */ + tm = typemap_get(ptype, pname); + if (!tm) + break; - tm = Getattr(tm, tm_methods); - if (!tm) - break; + tm = Getattr(tm, tm_methods); + if (!tm) + break; - /* Got a match. Look for next typemap */ - multi_tmap_method = NewStringf("%s-%s+%s:", tm_methods, ptype, pname); - Delete(tm_methods); - tm_methods = multi_tmap_method; - p = nextSibling(p); - } + /* Got a match. Look for next typemap */ + multi_tmap_method = NewStringf("%s-%s+%s:", tm_methods, ptype, pname); Delete(tm_methods); + tm_methods = multi_tmap_method; + p = nextSibling(p); + } + Delete(tm_methods); - if (!p && tm) { - /* Got some kind of match */ - String *parms_str = ParmList_str_multibrackets(parms); - String *srcparms_str = ParmList_str_multibrackets(srcparms); - String *source_directive = NewStringf("typemap(%s) %s = %s", tmap_method, parms_str, srcparms_str); + if (!p && tm) { + /* Got some kind of match */ + String *parms_str = ParmList_str_multibrackets(parms); + String *srcparms_str = ParmList_str_multibrackets(srcparms); + String *source_directive = NewStringf("typemap(%s) %s = %s", tmap_method, parms_str, srcparms_str); - typemap_register(tmap_method, parms, Getattr(tm, "code"), Getattr(tm, "locals"), Getattr(tm, "kwargs"), source_directive); + typemap_register(tmap_method, parms, Getattr(tm, "code"), Getattr(tm, "locals"), Getattr(tm, "kwargs"), source_directive); - Delete(source_directive); - Delete(srcparms_str); - Delete(parms_str); - return 0; - } - ts--; + Delete(source_directive); + Delete(srcparms_str); + Delete(parms_str); + return 0; } + /* Not found */ return -1; @@ -411,7 +370,7 @@ void Swig_typemap_clear(const_String_or_char_ptr tmap_method, ParmList *parms) { while (p) { type = Getattr(p, "type"); name = Getattr(p, "name"); - tm = typemap_get(type, name, tm_scope); + tm = typemap_get(type, name); if (!tm) return; p = nextSibling(p); @@ -452,7 +411,6 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) { String *ssig, *dsig; Parm *p, *np, *lastp, *dp, *lastdp = 0; int narg = 0; - int ts = tm_scope; SwigType *type = 0, *name; Hash *tm, *sm; int match = 0; @@ -480,9 +438,9 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) { /* make sure a typemap node exists for the last destination node */ type = Getattr(lastdp, "type"); - tm = get_typemap(tm_scope, type); + tm = get_typemap(type); if (!tm) { - set_typemap(tm_scope, type, &tm); + set_typemap(type, &tm); } name = Getattr(lastdp, "name"); if (name) { @@ -501,69 +459,65 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) { type = Getattr(lastp, "type"); name = Getattr(lastp, "name"); - while (ts >= 0) { + /* See if there is a matching typemap in this scope */ + sm = typemap_get(type, name); - /* See if there is a matching typemap in this scope */ - sm = typemap_get(type, name, ts); + /* if there is not matching, look for a typemap in the + original typedef, if any, like in: - /* if there is not matching, look for a typemap in the - original typedef, if any, like in: - - typedef unsigned long size_t; - ... - %apply(size_t) {my_size}; ==> %apply(unsigned long) {my_size}; - */ - if (!sm) { - SwigType *ntype = SwigType_typedef_resolve(type); - if (ntype && (Cmp(ntype, type) != 0)) { - sm = typemap_get(ntype, name, ts); - } - Delete(ntype); + typedef unsigned long size_t; + ... + %apply(size_t) {my_size}; ==> %apply(unsigned long) {my_size}; + */ + if (!sm) { + SwigType *ntype = SwigType_typedef_resolve(type); + if (ntype && (Cmp(ntype, type) != 0)) { + sm = typemap_get(ntype, name); } - - if (sm) { - /* Got a typemap. Need to only merge attributes for methods that match our signature */ - Iterator ki; - match = 1; - for (ki = First(sm); ki.key; ki = Next(ki)) { - /* Check for a signature match with the source signature */ - if ((count_args(ki.key) == narg) && (Strstr(ki.key, ssig))) { - String *oldm; - /* A typemap we have to copy */ - String *nkey = Copy(ki.key); - Replace(nkey, ssig, dsig, DOH_REPLACE_ANY); - - /* Make sure the typemap doesn't already exist in the target map */ - - oldm = Getattr(tm, nkey); - if (!oldm || (!Getattr(tm, "code"))) { - String *code; - ParmList *locals; - ParmList *kwargs; - Hash *sm1 = ki.item; - - code = Getattr(sm1, "code"); - locals = Getattr(sm1, "locals"); - kwargs = Getattr(sm1, "kwargs"); - if (code) { - String *src_str = ParmList_str_multibrackets(src); - String *dest_str = ParmList_str_multibrackets(dest); - String *source_directive = NewStringf("apply %s { %s }", src_str, dest_str); - - Replace(nkey, dsig, "", DOH_REPLACE_ANY); - Replace(nkey, "tmap:", "", DOH_REPLACE_ANY); - typemap_register(nkey, dest, code, locals, kwargs, source_directive); - - Delete(source_directive); - Delete(dest_str); - Delete(src_str); - } + Delete(ntype); + } + + if (sm) { + /* Got a typemap. Need to only merge attributes for methods that match our signature */ + Iterator ki; + match = 1; + for (ki = First(sm); ki.key; ki = Next(ki)) { + /* Check for a signature match with the source signature */ + if ((count_args(ki.key) == narg) && (Strstr(ki.key, ssig))) { + String *oldm; + /* A typemap we have to copy */ + String *nkey = Copy(ki.key); + Replace(nkey, ssig, dsig, DOH_REPLACE_ANY); + + /* Make sure the typemap doesn't already exist in the target map */ + + oldm = Getattr(tm, nkey); + if (!oldm || (!Getattr(tm, "code"))) { + String *code; + ParmList *locals; + ParmList *kwargs; + Hash *sm1 = ki.item; + + code = Getattr(sm1, "code"); + locals = Getattr(sm1, "locals"); + kwargs = Getattr(sm1, "kwargs"); + if (code) { + String *src_str = ParmList_str_multibrackets(src); + String *dest_str = ParmList_str_multibrackets(dest); + String *source_directive = NewStringf("apply %s { %s }", src_str, dest_str); + + Replace(nkey, dsig, "", DOH_REPLACE_ANY); + Replace(nkey, "tmap:", "", DOH_REPLACE_ANY); + typemap_register(nkey, dest, code, locals, kwargs, source_directive); + + Delete(source_directive); + Delete(dest_str); + Delete(src_str); } - Delete(nkey); } + Delete(nkey); } } - ts--; } Delete(ssig); Delete(dsig); @@ -597,7 +551,7 @@ void Swig_typemap_clear_apply(Parm *parms) { } p = np; } - tm = get_typemap(tm_scope, Getattr(lastp, "type")); + tm = get_typemap(Getattr(lastp, "type")); if (!tm) { Delete(tsig); return; @@ -711,7 +665,6 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type SwigType *primitive = 0; SwigType *ctype = 0; SwigType *ctype_unstripped = 0; - int ts; int isarray; const String *cname = 0; const String *cqualifiedname = 0; @@ -722,90 +675,86 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type cname = name; if ((qualifiedname) && Len(qualifiedname)) cqualifiedname = qualifiedname; - ts = tm_scope; if (debug_display) { String *typestr = SwigType_str(type, cqualifiedname ? cqualifiedname : cname); Swig_diagnostic(Getfile(node), Getline(node), "Searching for a suitable '%s' typemap for: %s\n", tmap_method, typestr); Delete(typestr); } - while (ts >= 0) { - ctype = Copy(type); - ctype_unstripped = Copy(ctype); - while (ctype) { - /* Try to get an exact type-match */ - tm = get_typemap(ts, ctype); - result = typemap_search_helper(debug_display, tm, tm_method, ctype, cqualifiedname, cname, &backup); - if (result && Getattr(result, "code")) - goto ret_result; - - { - /* Look for the type reduced to just the template prefix - for templated types without the template parameter list being specified */ - SwigType *template_prefix = SwigType_istemplate_only_templateprefix(ctype); - if (template_prefix) { - tm = get_typemap(ts, template_prefix); - result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup); - Delete(template_prefix); - if (result && Getattr(result, "code")) - goto ret_result; - } - } + ctype = Copy(type); + ctype_unstripped = Copy(ctype); + while (ctype) { + /* Try to get an exact type-match */ + tm = get_typemap(ctype); + result = typemap_search_helper(debug_display, tm, tm_method, ctype, cqualifiedname, cname, &backup); + if (result && Getattr(result, "code")) + goto ret_result; - /* look for [ANY] arrays */ - isarray = SwigType_isarray(ctype); - if (isarray) { - /* If working with arrays, strip away all of the dimensions and replace with "ANY". - See if that generates a match */ - SwigType *noarrays = strip_arrays(ctype); - tm = get_typemap(ts, noarrays); - result = typemap_search_helper(debug_display, tm, tm_method, noarrays, cqualifiedname, cname, &backup); - Delete(noarrays); + { + /* Look for the type reduced to just the template prefix - for templated types without the template parameter list being specified */ + SwigType *template_prefix = SwigType_istemplate_only_templateprefix(ctype); + if (template_prefix) { + tm = get_typemap(template_prefix); + result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup); + Delete(template_prefix); if (result && Getattr(result, "code")) goto ret_result; } + } - /* No match so far - try with a qualifier stripped (strip one qualifier at a time until none remain) - * The order of stripping in SwigType_strip_single_qualifier is used to provide some sort of consistency - * with the default (SWIGTYPE) typemap matching rules for the first qualifier to be stripped. */ - { - SwigType *oldctype = ctype; - ctype = SwigType_strip_single_qualifier(oldctype); - if (!Equal(ctype, oldctype)) { - Delete(oldctype); - continue; - } - Delete(oldctype); - } + /* look for [ANY] arrays */ + isarray = SwigType_isarray(ctype); + if (isarray) { + /* If working with arrays, strip away all of the dimensions and replace with "ANY". + See if that generates a match */ + SwigType *noarrays = strip_arrays(ctype); + tm = get_typemap(noarrays); + result = typemap_search_helper(debug_display, tm, tm_method, noarrays, cqualifiedname, cname, &backup); + Delete(noarrays); + if (result && Getattr(result, "code")) + goto ret_result; + } - /* Once all qualifiers are stripped try resolve a typedef */ - { - SwigType *oldctype = ctype; - ctype = SwigType_typedef_resolve(ctype_unstripped); + /* No match so far - try with a qualifier stripped (strip one qualifier at a time until none remain) + * The order of stripping in SwigType_strip_single_qualifier is used to provide some sort of consistency + * with the default (SWIGTYPE) typemap matching rules for the first qualifier to be stripped. */ + { + SwigType *oldctype = ctype; + ctype = SwigType_strip_single_qualifier(oldctype); + if (!Equal(ctype, oldctype)) { Delete(oldctype); - ctype_unstripped = Copy(ctype); + continue; } + Delete(oldctype); } - /* Hmmm. Well, no match seems to be found at all. See if there is some kind of default (SWIGTYPE) mapping */ + /* Once all qualifiers are stripped try resolve a typedef */ + { + SwigType *oldctype = ctype; + ctype = SwigType_typedef_resolve(ctype_unstripped); + Delete(oldctype); + ctype_unstripped = Copy(ctype); + } + } - primitive = SwigType_default_create(type); - while (primitive) { - tm = get_typemap(ts, primitive); - result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup); - if (result && Getattr(result, "code")) - goto ret_result; + /* Hmmm. Well, no match seems to be found at all. See if there is some kind of default (SWIGTYPE) mapping */ - { - SwigType *nprim = SwigType_default_deduce(primitive); - Delete(primitive); - primitive = nprim; - } - } - if (ctype != type) { - Delete(ctype); - ctype = 0; + primitive = SwigType_default_create(type); + while (primitive) { + tm = get_typemap(primitive); + result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup); + if (result && Getattr(result, "code")) + goto ret_result; + + { + SwigType *nprim = SwigType_default_deduce(primitive); + Delete(primitive); + primitive = nprim; } - ts--; /* Hmmm. Nothing found in this scope. Guess we'll go try another scope */ + } + if (ctype != type) { + Delete(ctype); + ctype = 0; } result = backup; @@ -1318,6 +1267,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No char *cmethod = Char(tmap_method); int optimal_attribute = 0; int optimal_substitution = 0; + int delete_optimal_attribute = 0; int num_substitutions = 0; SwigType *matchtype = 0; @@ -1372,7 +1322,6 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No Delete(typestr); } - Delete(qpname); qpname = 0; Delete(noscope_pname); @@ -1391,23 +1340,16 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No s = Copy(s); /* Make a local copy of the typemap code */ - /* Attach kwargs - ie the typemap attributes */ - kw = Getattr(tm, "kwargs"); - while (kw) { - String *value = Copy(Getattr(kw, "value")); - String *kwtype = Getattr(kw, "type"); - char *ckwname = Char(Getattr(kw, "name")); - if (kwtype) { - String *mangle = Swig_string_mangle(kwtype); - Append(value, mangle); - Delete(mangle); + /* Look in the "out" typemap for the "optimal" attribute */ + if (Cmp(cmethod, "out") == 0) { + kw = Getattr(tm, "kwargs"); + while (kw) { + if (Cmp(Getattr(kw, "name"), "optimal") == 0) { + optimal_attribute = GetFlag(kw, "value"); + break; + } + kw = nextSibling(kw); } - sprintf(temp, "%s:%s", cmethod, ckwname); - Setattr(node, typemap_method_name(temp), value); - if (Cmp(temp, "out:optimal") == 0) - optimal_attribute = (Cmp(value, "0") != 0) ? 1 : 0; - Delete(value); - kw = nextSibling(kw); } if (optimal_attribute) { @@ -1438,14 +1380,15 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No } } if (!optimal_substitution) { - Swig_warning(WARN_TYPEMAP_OUT_OPTIMAL_IGNORED, Getfile(node), Getline(node), "Method %s usage of the optimal attribute ignored\n", Swig_name_decl(node)); - Swig_warning(WARN_TYPEMAP_OUT_OPTIMAL_IGNORED, Getfile(s), Getline(s), "in the out typemap as the following cannot be used to generate optimal code: %s\n", clname); - Delattr(node, "tmap:out:optimal"); + Swig_warning(WARN_TYPEMAP_OUT_OPTIMAL_IGNORED, Getfile(node), Getline(node), "Method %s usage of the optimal attribute ignored\n", Swig_name_decl(node)); + Swig_warning(WARN_TYPEMAP_OUT_OPTIMAL_IGNORED, Getfile(s), Getline(s), "in the out typemap as the following cannot be used to generate optimal code: %s\n", clname); + delete_optimal_attribute = 1; } } else { assert(!f); } } + if (actioncode) { assert(f); Append(f->code, actioncode); @@ -1486,6 +1429,41 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No Delete(parm_sublist); } + /* Attach kwargs - ie the typemap attributes */ + kw = Getattr(tm, "kwargs"); + while (kw) { + String *value = Copy(Getattr(kw, "value")); + String *kwtype = Getattr(kw, "type"); + char *ckwname = Char(Getattr(kw, "name")); + { + /* Expand special variables in typemap attributes. */ + SwigType *ptype = Getattr(node, "type"); + String *pname = Getattr(node, "name"); + SwigType *mtype = Getattr(node, "tmap:match"); + SwigType *matchtype = mtype ? mtype : ptype; + ParmList *parm_sublist; + typemap_replace_vars(value, NULL, matchtype, ptype, pname, (char *)lname, 1); + + /* Expand special variable macros (embedded typemaps) in typemap attributes. */ + parm_sublist = NewParmWithoutFileLineInfo(ptype, pname); + Setattr(parm_sublist, "lname", lname); + replace_embedded_typemap(value, parm_sublist, NULL, tm); + Delete(parm_sublist); + } + if (kwtype) { + String *mangle = Swig_string_mangle(kwtype); + Append(value, mangle); + Delete(mangle); + } + sprintf(temp, "%s:%s", cmethod, ckwname); + Setattr(node, typemap_method_name(temp), value); + Delete(value); + kw = nextSibling(kw); + } + + if (delete_optimal_attribute) + Delattr(node, "tmap:out:optimal"); + Replace(s, "$name", pname, DOH_REPLACE_ANY); symname = Getattr(node, "sym:name"); @@ -1558,17 +1536,44 @@ String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *node, co * If this hash (tm) contains a linked list of parameters under its "kwargs" * attribute, add keys for each of those named keyword arguments to this * parameter for later use. - * For example, attach the typemap attributes to p: + * For example, attach the typemap attributes to firstp (first parameter in parameter list): * %typemap(in, foo="xyz") ... - * A new attribute called "tmap:in:foo" with value "xyz" is attached to p. + * A new attribute called "tmap:in:foo" with value "xyz" is attached to firstp. + * Also expands special variables and special variable macros in the typemap attributes. * ----------------------------------------------------------------------------- */ -static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method, Parm *p) { +static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method, Parm *firstp, int nmatch) { String *temp = NewStringEmpty(); Parm *kw = Getattr(tm, "kwargs"); while (kw) { String *value = Copy(Getattr(kw, "value")); String *type = Getattr(kw, "type"); + int i; + Parm *p = firstp; + /* Expand special variables */ + for (i = 0; i < nmatch; i++) { + SwigType *type = Getattr(p, "type"); + String *pname = Getattr(p, "name"); + String *lname = Getattr(p, "lname"); + SwigType *mtype = Getattr(p, "tmap:match"); + SwigType *matchtype = mtype ? mtype : type; + typemap_replace_vars(value, NULL, matchtype, type, pname, lname, i + 1); + p = nextSibling(p); + } + + /* Expand special variable macros (embedded typemaps). + * Special variable are expanded first above as they might be used in the special variable macros. + * For example: $typemap(imtype, $2_type). */ + p = firstp; + for (i = 0; i < nmatch; i++) { + SwigType *type = Getattr(p, "type"); + String *pname = Getattr(p, "name"); + String *lname = Getattr(p, "lname"); + ParmList *parm_sublist = NewParmWithoutFileLineInfo(type, pname); + Setattr(parm_sublist, "lname", lname); + replace_embedded_typemap(value, parm_sublist, NULL, tm); + p = nextSibling(p); + } if (type) { Hash *v = NewHash(); Setattr(v, "type", type); @@ -1578,13 +1583,13 @@ static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method } Clear(temp); Printf(temp, "%s:%s", tmap_method, Getattr(kw, "name")); - Setattr(p, typemap_method_name(temp), value); + Setattr(firstp, typemap_method_name(temp), value); Delete(value); kw = nextSibling(kw); } Clear(temp); Printf(temp, "%s:match_type", tmap_method); - Setattr(p, typemap_method_name(temp), Getattr(tm, "type")); + Setattr(firstp, typemap_method_name(temp), Getattr(tm, "type")); Delete(temp); } @@ -1779,7 +1784,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *p Setattr(firstp, typemap_method_name(temp), p); /* Attach kwargs */ - typemap_attach_kwargs(tm, tmap_method, firstp); + typemap_attach_kwargs(tm, tmap_method, firstp, nmatch); /* Replace the argument number */ sprintf(temp, "%d", argnum); @@ -1844,7 +1849,7 @@ static List *split_embedded_typemap(String *s) { } } if ((level == 0) && angle_level == 0 && ((*c == ',') || (*c == ')'))) { - String *tmp = NewStringWithSize(start, c - start); + String *tmp = NewStringWithSize(start, (int)(c - start)); Append(args, tmp); Delete(tmp); start = c + 1; @@ -1915,10 +1920,10 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper c++; } if (end) { - dollar_typemap = NewStringWithSize(start, (end - start)); + dollar_typemap = NewStringWithSize(start, (int)((end - start))); syntax_error = 0; } else { - dollar_typemap = NewStringWithSize(start, (c - start)); + dollar_typemap = NewStringWithSize(start, (int)((c - start))); } if (!syntax_error) { @@ -1963,7 +1968,7 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper char *eq = strchr(Char(parm), '='); char *c = Char(parm); if (eq && (eq - c > 0)) { - String *name = NewStringWithSize(c, eq - c); + String *name = NewStringWithSize(c, (int)(eq - c)); String *value = NewString(eq + 1); Insert(name, 0, "$"); Setattr(vars, name, value); @@ -2054,16 +2059,9 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper * ----------------------------------------------------------------------------- */ void Swig_typemap_debug() { - int ts; int nesting_level = 2; Printf(stdout, "---[ typemaps ]--------------------------------------------------------------\n"); - - ts = tm_scope; - while (ts >= 0) { - Printf(stdout, "::: scope %d\n\n", ts); - Swig_print(typemaps[ts], nesting_level); - ts--; - } + Swig_print(typemaps, nesting_level); Printf(stdout, "-----------------------------------------------------------------------------\n"); } diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 622eac1180b..b2832b6a9a6 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -361,7 +361,7 @@ SwigType *SwigType_del_pointer(SwigType *t) { printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n"); abort(); } - Delslice(t, 0, (c - s) + 2); + Delslice(t, 0, (int)((c - s) + 2)); return t; } @@ -915,7 +915,7 @@ SwigType *SwigType_add_template(SwigType *t, ParmList *parms) { String *SwigType_templateprefix(const SwigType *t) { const char *s = Char(t); const char *c = strstr(s, "<("); - return c ? NewStringWithSize(s, c - s) : NewString(s); + return c ? NewStringWithSize(s, (int)(c - s)) : NewString(s); } /* ----------------------------------------------------------------------------- @@ -966,7 +966,7 @@ String *SwigType_templatesuffix(const SwigType *t) { String *SwigType_istemplate_templateprefix(const SwigType *t) { const char *s = Char(t); const char *c = strstr(s, "<("); - return c ? NewStringWithSize(s, c - s) : 0; + return c ? NewStringWithSize(s, (int)(c - s)) : 0; } /* ----------------------------------------------------------------------------- @@ -989,7 +989,7 @@ String *SwigType_istemplate_only_templateprefix(const SwigType *t) { const char *s = Char(t); if (len >= 4 && strcmp(s + len - 2, ")>") == 0) { const char *c = strstr(s, "<("); - return c ? NewStringWithSize(s, c - s) : 0; + return c ? NewStringWithSize(s, (int)(c - s)) : 0; } else { return 0; } @@ -1022,7 +1022,7 @@ String *SwigType_templateargs(const SwigType *t) { nest--; c++; } - return NewStringWithSize(start, c - start); + return NewStringWithSize(start, (int)(c - start)); } c++; } diff --git a/Tools/config/ac_compare_version.m4 b/Tools/config/ac_compare_version.m4 deleted file mode 100644 index 0828f4789bd..00000000000 --- a/Tools/config/ac_compare_version.m4 +++ /dev/null @@ -1,40 +0,0 @@ -dnl @synopsis AC_COMPARE_VERSION\ -dnl (version-a, version-b, action-if-greater, action-if-equal, action-if-less) -dnl -dnl This macro compares two version numbers and executes the indicated action -dnl based on whether they're equal or one is greater than the other. -dnl It's needed to determine whether ocaml is new enough that the incompatible -dnl change 'loc' -> '_loc' is present in this version of camlp4. -dnl -dnl It's implemented from scratch just for SWIG by arty. -dnl -dnl @category Misc -dnl @author arty -dnl @version 2006-11-02 -dnl @license GPLWithACException - -AC_DEFUN([AC_COMPARE_VERSION], [ - # Split the version into units. - ver_a="[$1]" - ver_b="[$2]" - nodots_a=`echo $ver_a | sed -e 's/\./ /g'` - condition="equal" - isolate_b_regex='\([[0-9]]\+\).*' - for ver_part in $nodots_a ; do - b_ver_part=`echo "$ver_b" | sed -e 's/'"$isolate_b_regex"'/\1/'` - if test \( "$ver_part" -lt "$b_ver_part" \) -a \( "x$condition" = "xequal" \) ; then - condition=less - elif test \( "$ver_part" -gt "$b_ver_part" \) -a \( "x$condition" = "xequal" \) ; then - condition=greater - fi - isolate_b_regex='[[0-9]]\+\.'"$isolate_b_regex" - done - - if test "x$condition" = "xequal" ; then - [$4] - elif test "x$condition" = "xless" ; then - [$3] - elif test "x$condition" = "xgreater" ; then - [$5] - fi -]) diff --git a/Tools/config/ax_boost_base.m4 b/Tools/config/ax_boost_base.m4 index 550b6413813..f3279f2b76e 100644 --- a/Tools/config/ax_boost_base.m4 +++ b/Tools/config/ax_boost_base.m4 @@ -33,7 +33,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 23 +#serial 26 AC_DEFUN([AX_BOOST_BASE], [ @@ -92,8 +92,11 @@ if test "x$want_boost" = "xyes"; then libsubdirs="lib" ax_arch=`uname -m` case $ax_arch in - x86_64|ppc64|s390x|sparc64|aarch64) - libsubdirs="lib64 lib lib64" + x86_64) + libsubdirs="lib64 libx32 lib lib64" + ;; + ppc64|s390x|sparc64|aarch64|ppc64le) + libsubdirs="lib64 lib lib64 ppc64le" ;; esac @@ -170,6 +173,10 @@ if test "x$want_boost" = "xyes"; then dnl if we found no boost with system layout we search for boost libraries dnl built and installed without the --layout=system option or for a staged(not installed) version if test "x$succeeded" != "xyes"; then + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + BOOST_CPPFLAGS= + BOOST_LDFLAGS= _version=0 if test "$ac_boost_path" != ""; then if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then @@ -182,6 +189,12 @@ if test "x$want_boost" = "xyes"; then VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" done + dnl if nothing found search for layout used in Windows distributions + if test -z "$BOOST_CPPFLAGS"; then + if test -d "$ac_boost_path/boost" && test -r "$ac_boost_path/boost"; then + BOOST_CPPFLAGS="-I$ac_boost_path" + fi + fi fi else if test "$cross_compiling" != yes; then @@ -270,4 +283,3 @@ if test "x$want_boost" = "xyes"; then fi ]) - diff --git a/Tools/config/ax_path_generic.m4 b/Tools/config/ax_path_generic.m4 index 6960d612a35..f77fc78d606 100644 --- a/Tools/config/ax_path_generic.m4 +++ b/Tools/config/ax_path_generic.m4 @@ -69,7 +69,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 11 +#serial 13 AU_ALIAS([AC_PATH_GENERIC], [AX_PATH_GENERIC]) AC_DEFUN([AX_PATH_GENERIC],[ @@ -89,7 +89,7 @@ AC_DEFUN([AX_PATH_GENERIC],[ AC_ARG_VAR(UP[]_CFLAGS, [CFLAGS used for $1]) AC_ARG_VAR(UP[]_LIBS, [LIBS used for $1]) - AS_IF([test x$UP[]_CFLAGS != x -o x$UP[]_LIBS != x],[ + AS_IF([test x"$UP[]_CFLAGS" != x -o x"$UP[]_LIBS" != x],[ dnl Don't run config script at all, use user-provided values instead. AC_SUBST(UP[]_CFLAGS) AC_SUBST(UP[]_LIBS) diff --git a/Tools/convertpath b/Tools/convertpath new file mode 100755 index 00000000000..0cc8b74bbe5 --- /dev/null +++ b/Tools/convertpath @@ -0,0 +1,34 @@ +#!/bin/sh + +# Unix to Windows path conversion in a script. +# Useful for avoiding backslash quoting difficulties in Makefiles. +# Acts as a much dumbed down cygpath tool mainly for use on MinGW. + +usage() +{ + cat <&2; exit 1 ;; + esac ;; + -u) shift; echo $@ | sed -e 's,\\,/,g' ;; + -w) shift; echo $@ | sed -e 's,/,\\,g' ;; + -h) shift; usage; ;; + *) usage; exit 1 ;; +esac + +exit 0 diff --git a/Tools/javascript/Makefile.in b/Tools/javascript/Makefile.in index 1eec5bc1e3c..5eeec078572 100644 --- a/Tools/javascript/Makefile.in +++ b/Tools/javascript/Makefile.in @@ -14,7 +14,7 @@ all: javascript CC = @CC@ -# HACK: under OSX a g++ compiled interpreter is seg-faulting when loading module libraries +# HACK: under Mac OS X a g++ compiled interpreter is seg-faulting when loading module libraries # with 'c++' it works... probably some missing flags? JSCXX = @JSINTERPRETERCXX@ CPPFLAGS = @BOOST_CPPFLAGS@ diff --git a/Tools/javascript/v8_shell.cxx b/Tools/javascript/v8_shell.cxx index 7016e9c3169..5001bc25a6a 100644 --- a/Tools/javascript/v8_shell.cxx +++ b/Tools/javascript/v8_shell.cxx @@ -13,7 +13,7 @@ typedef int (*V8ExtensionInitializer) (v8::Handle module); // Note: these typedefs and defines are used to deal with v8 API changes since version 3.19.00 -#if (SWIG_V8_VERSION < 0x031903) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) typedef v8::Handle SwigV8ReturnValue; typedef v8::Arguments SwigV8Arguments; typedef v8::AccessorInfo SwigV8PropertyCallbackInfo; @@ -28,11 +28,11 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #endif -#if (SWIG_V8_VERSION < 0x032117) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032117) #define SWIGV8_HANDLESCOPE() v8::HandleScope scope #define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope #define SWIGV8_ESCAPE(val) return scope.Close(val) -#elif (SWIG_V8_VERSION < 0x032318) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318) #define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); #define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope(v8::Isolate::GetCurrent()); #define SWIGV8_ESCAPE(val) return scope.Close(val) @@ -42,7 +42,7 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_ESCAPE(val) return scope.Escape(val) #endif -#if (SWIG_V8_VERSION < 0x032318) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318) #define SWIGV8_CURRENT_CONTEXT() v8::Context::GetCurrent() #define SWIGV8_STRING_NEW(str) v8::String::New(str) #define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(func) @@ -59,7 +59,7 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #endif -#if (SWIG_V8_VERSION < 0x031900) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) typedef v8::Persistent SwigV8Context; #else typedef v8::Local SwigV8Context; @@ -149,9 +149,9 @@ bool V8Shell::RunScript(const std::string &scriptPath) { context->Exit(); -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) context.Dispose(); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) context.Dispose(v8::Isolate::GetCurrent()); #else // context.Dispose(); @@ -193,9 +193,9 @@ bool V8Shell::RunShell() { context->Exit(); -#if (SWIG_V8_VERSION < 0x031710) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) context.Dispose(); -#elif (SWIG_V8_VERSION < 0x031900) +#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) context.Dispose(v8::Isolate::GetCurrent()); #else // context.Dispose(); @@ -249,7 +249,7 @@ SwigV8Context V8Shell::CreateShellContext() { global->Set(SWIGV8_STRING_NEW("require"), SWIGV8_FUNCTEMPLATE_NEW(V8Shell::Require)); global->Set(SWIGV8_STRING_NEW("version"), SWIGV8_FUNCTEMPLATE_NEW(V8Shell::Version)); -#if (SWIG_V8_VERSION < 0x031900) +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) SwigV8Context context = v8::Context::New(NULL, global); return context; #else diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 2e69dbece71..98f9912a41a 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -95,8 +95,6 @@ def failed(): # Build documentation print "Building html documentation" os.system("cd "+dirname+"/Doc/Manual && make all clean-baks") == 0 or failed() -print "Building man pages" -os.system("cd "+dirname+"/CCache && yodl2man -o ccache-swig.1 ccache.yo") == 0 or failed() # Build the tar-ball os.system("tar -cf "+dirname+".tar "+dirname) == 0 or failed() diff --git a/Tools/mkwindows.sh b/Tools/mkwindows.sh index 6042361b385..f3a20409a01 100755 --- a/Tools/mkwindows.sh +++ b/Tools/mkwindows.sh @@ -44,6 +44,9 @@ else zip=zip fi extraconfigureoptions="--host=i586-mingw32msvc --build=i686-linux" + echo "Checking that mingw gcc is installed/available" + i586-mingw32msvc-gcc --version || exit 1 + i586-mingw32msvc-g++ --version || exit 1 else if test "$cygwin"; then echo "Building native Windows executable on Cygwin" diff --git a/Tools/nuget-install.cmd b/Tools/nuget-install.cmd new file mode 100644 index 00000000000..08caea7e0e3 --- /dev/null +++ b/Tools/nuget-install.cmd @@ -0,0 +1,28 @@ +rem Workaround 'nuget install' not being reliable by retrying a few times + +@echo off +rem initiate the retry number +set errorCode=1 +set retryNumber=0 +set maxRetries=5 + +:RESTORE +nuget install %* + +rem problem? +IF ERRORLEVEL %errorCode% GOTO :RETRY + +rem everything is fine! +GOTO :EXIT + +:RETRY +@echo Oops, nuget restore exited with code %errorCode% - let us try again! +set /a retryNumber=%retryNumber%+1 +IF %reTryNumber% LSS %maxRetries% (GOTO :RESTORE) +IF %retryNumber% EQU %maxRetries% (GOTO :ERR) + +:ERR +@echo Sorry, we tried restoring nuget packages for %maxRetries% times and all attempts were unsuccessful! +EXIT /B 1 + +:EXIT diff --git a/Tools/obs-buildlogs.py b/Tools/obs-buildlogs.py new file mode 100755 index 00000000000..eaf0f613bdb --- /dev/null +++ b/Tools/obs-buildlogs.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import os +import subprocess +import argparse +import glob + +def remove_old_files(): + files = glob.glob("*.log") + for file in files: + os.remove(file) + +def download(): + repos = subprocess.Popen(['osc', 'repositories'], stdout=subprocess.PIPE) + for line in repos.stdout: + command = ['osc', 'buildlog', '--last'] + line.split() + filename = "-".join(line.split()) + ".log" + print "Downloading logs using: {}".format(" ".join(command)) + buildlog = subprocess.Popen(command, stdout=subprocess.PIPE) + + print("Writing log to {}".format(filename)) + file = open(filename, "w") + if buildlog.stderr != None: + print("Errors: {}".format(buildlog.stderr)) + for log_line in buildlog.stdout: + file.write(log_line) + + print("Finished") + +parser = argparse.ArgumentParser(description="Download OpenBuild logs using osc. All the logs for each architecture from the last completed builds are downloaded and stored as .log files. Must be run from a working copy that is already checked out, eg after running obs-update.") +args = parser.parse_args() + +remove_old_files() +download() diff --git a/Tools/testflags.py b/Tools/testflags.py new file mode 100755 index 00000000000..9aafd8eb7ce --- /dev/null +++ b/Tools/testflags.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python + +def get_cflags(language, std, compiler): + if std == None or len(std) == 0: + std = "gnu89" + c_common = "-fdiagnostics-show-option -std=" + std + " -Wno-long-long -Wreturn-type -Wdeclaration-after-statement -Wmissing-field-initializers" + cflags = { + "csharp":"-Werror " + c_common, + "d":"-Werror " + c_common, + "go":"-Werror " + c_common, + "guile":"-Werror " + c_common, + "java":"-Werror " + c_common, + "javascript":"-Werror " + c_common, + "lua":"-Werror " + c_common, + "octave":"-Werror " + c_common, + "perl5":"-Werror " + c_common, + "php":"-Werror " + c_common, + "python":"-Werror " + c_common, + "r":"-Werror " + c_common, + "ruby":"-Werror " + c_common, + "scilab":"-Werror " + c_common, + "tcl":"-Werror " + c_common, + } + if compiler == 'clang': + cflags["guile"] += " -Wno-attributes" # -Wno-attributes is for clang LLVM 3.5 and bdw-gc < 7.5 used by guile + + if language not in cflags: + raise RuntimeError("{} is not a supported language".format(language)) + + return cflags[language] + +def get_cxxflags(language, std, compiler): + if std == None or len(std) == 0: + std = "c++98" + cxx_common = "-fdiagnostics-show-option -std=" + std + " -Wno-long-long -Wreturn-type -Wmissing-field-initializers" + cxxflags = { + "csharp":"-Werror " + cxx_common, + "d":"-Werror " + cxx_common, + "go":"-Werror " + cxx_common, + "guile":"-Werror " + cxx_common, + "java":"-Werror " + cxx_common, + "javascript":"-Werror " + cxx_common + " -Wno-error=unused-function", # Until overload_rename is fixed for node + "lua":"-Werror " + cxx_common, + "octave":"-Werror " + cxx_common, + "perl5":"-Werror " + cxx_common, + "php":"-Werror " + cxx_common, + "python":"-Werror " + cxx_common, + "r":"-Werror " + cxx_common, + "ruby":"-Werror " + cxx_common, + "scilab": cxx_common, + "tcl":"-Werror " + cxx_common, + } + if compiler == 'clang': + cxxflags["guile"] += " -Wno-attributes" # -Wno-attributes is for clang LLVM 3.5 and bdw-gc < 7.5 used by guile + + if language not in cxxflags: + raise RuntimeError("{} is not a supported language".format(language)) + + return cxxflags[language] + +import argparse +parser = argparse.ArgumentParser(description="Display CFLAGS or CXXFLAGS to use for testing the SWIG examples and test-suite.") +parser.add_argument('-l', '--language', required=True, help='set language to show flags for') +flags = parser.add_mutually_exclusive_group(required=True) +flags.add_argument('-c', '--cflags', action='store_true', default=False, help='show CFLAGS') +flags.add_argument('-x', '--cxxflags', action='store_true', default=False, help='show CXXFLAGS') +parser.add_argument('-s', '--std', required=False, help='language standard flags for the -std= option') +parser.add_argument('-C', '--compiler', required=False, help='compiler used (clang or gcc)') +args = parser.parse_args() + +if args.cflags: + get_flags = get_cflags +elif args.cxxflags: + get_flags = get_cxxflags +else: + parser.print_help() + exit(1) + +print(get_flags(args.language, args.std, args.compiler)) diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh new file mode 100755 index 00000000000..9e2ecadeb67 --- /dev/null +++ b/Tools/travis-linux-install.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +set -e # exit on failure + +lsb_release -a +sudo apt-get -qq update + +if [[ "$CC" == gcc-5 ]]; then + sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + sudo add-apt-repository -y ppa:boost-latest/ppa + sudo apt-get -qq update + sudo apt-get install -qq g++-5 libboost1.55-dev +else + sudo apt-get -qq install libboost-dev +fi + +WITHLANG=$SWIGLANG + +case "$SWIGLANG" in + "") ;; + "csharp") + sudo apt-get -qq install mono-devel + ;; + "d") + wget http://downloads.dlang.org/releases/2014/dmd_2.066.0-0_amd64.deb + sudo dpkg -i dmd_2.066.0-0_amd64.deb + ;; + "go") + # Until configure.ac is fixed + go env | sed -e 's/^/export /' > goenvsetup + source goenvsetup + rm -f goenvsetup + ;; + "javascript") + case "$ENGINE" in + "node") + sudo add-apt-repository -y ppa:chris-lea/node.js + sudo apt-get -qq update + sudo apt-get install -qq nodejs rlwrap + sudo npm install -g node-gyp + ;; + "jsc") + sudo apt-get install -qq libwebkitgtk-dev + ;; + "v8") + sudo apt-get install -qq libv8-dev + ;; + esac + ;; + "guile") + sudo apt-get -qq install guile-2.0-dev + ;; + "lua") + sudo apt-get -qq install lua5.1 liblua5.1-dev + ;; + "ocaml") + # configure also looks for ocamldlgen, but this isn't packaged. But it isn't used by default so this doesn't matter. + sudo apt-get -qq install ocaml ocaml-findlib + ;; + "octave") + if [[ -z "$VER" ]]; then + sudo apt-get -qq install octave3.2 octave3.2-headers + else + sudo add-apt-repository -y ppa:kwwette/octaves + sudo apt-get -qq update + sudo apt-get -qq install liboctave${VER}-dev + fi + ;; + "php") + sudo apt-get install php5-cli php5-dev + ;; + "python") + git clone https://github.com/jcrocholl/pep8.git + ( + cd pep8 + git checkout tags/1.5.7 + python ./setup.py build + sudo python ./setup.py install + ) + if [[ "$PY3" ]]; then + sudo apt-get install -qq python3-dev + fi + WITHLANG=$SWIGLANG$PY3 + if [[ "$VER" ]]; then + sudo add-apt-repository -y ppa:fkrull/deadsnakes + sudo apt-get -qq update + sudo apt-get -qq install python${VER}-dev + WITHLANG=$SWIGLANG$PY3=$SWIGLANG$VER + fi + ;; + "r") + sudo apt-get -qq install r-base + ;; + "ruby") + if [[ "$VER" ]]; then + rvm install $VER + fi + ;; + "scilab") + sudo apt-get -qq install scilab + ;; + "tcl") + sudo apt-get -qq install tcl8.4-dev + ;; +esac diff --git a/Tools/travis-osx-install.sh b/Tools/travis-osx-install.sh new file mode 100755 index 00000000000..965deed423d --- /dev/null +++ b/Tools/travis-osx-install.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e # exit on failure + +sw_vers +brew update +brew list +brew install pcre +# brew install boost + +WITHLANG=$SWIGLANG + +case "$SWIGLANG" in + "csharp") + brew install https://s3.amazonaws.com/travisbuilds.swig.org/mono.rb + ;; + "guile") + Tools/brew-install guile + ;; + "lua") + brew install lua + ;; + "python") + WITHLANG=$SWIGLANG$PY3 + if [[ "$PY3" ]]; then + brew install python3 + brew list -v python3 + fi + ;; +esac diff --git a/Tools/vcfilter b/Tools/vcfilter index 2683fc2dbd2..05daefd8047 100755 --- a/Tools/vcfilter +++ b/Tools/vcfilter @@ -2,9 +2,9 @@ # This is a simple utility for Cygwin/Mingw which is useful when running the SWIG # test-suite through Visual Studio. If the output from the test-suite is piped -# through this utility, it will filter the junk that the compiler generates. +# through this utility, it will filter the junk that the compiler outputs to stdout. # Typical usage: make check | vcfilter # dos2unix needed for ^ and $ to work. -2>&1 dos2unix | grep -v "\.cxx$" | grep -v "\.c$" | grep -v "^ Creating library" | grep -v "^Generating Code" +2>&1 dos2unix | grep -v -e "\.cxx$" -e "\.c$" -e "^ Creating library" -e "^Generating Code" diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000000..9f206890360 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,78 @@ +platform: +- x86 +- x64 + +environment: + matrix: + - SWIGLANG: csharp + VSVER: 14 + - SWIGLANG: csharp + VSVER: 12 + - SWIGLANG: java + VSVER: 12 + - SWIGLANG: python + VSVER: 12 + VER: 27 + - SWIGLANG: python + VSVER: 12 + VER: 35 + PY3: 1 + +install: +- date /T & time /T +- set PATH=C:\cygwin\bin;%PATH% +- set CYGWIN=nodosfilewarning +- git clone -q --depth=1 --single-branch --branch cccl-1.0 git://github.com/swig/cccl.git C:\cccl-1.0 +- bash -c "cp C:/cccl-1.0/cccl /usr/bin" +- ps: >- + If ($env:Platform -Match "x86") { + $env:PCRE_PLATFORM="Win32" + $env:JAVA_HOME="C:/Program Files (x86)/Java/jdk1.8.0" + $env:VCVARS_PLATFORM="x86" + $env:LANG_PLATFORM="" + } Else { + $env:PCRE_PLATFORM="x64" + $env:JAVA_HOME="C:/Program Files/Java/jdk1.8.0" + $env:VCVARS_PLATFORM="amd64" + $env:LANG_PLATFORM="-x64" + } +- ps: $env:VSCOMNTOOLS=(Get-Content ("env:VS" + "$env:VSVER" + "0COMNTOOLS")) +- echo "Using Visual Studio %VSVER%.0 at %VSCOMNTOOLS%" +- call "%VSCOMNTOOLS%\..\..\VC\vcvarsall.bat" %VCVARS_PLATFORM% +- Tools\nuget-install.cmd pcre -Verbosity detailed -Version 8.33.0.1 -OutputDirectory C:\pcre +- set PCRE_ROOT=C:/pcre/pcre.8.33.0.1/build/native +- set PATH=C:\Python%VER%%LANG_PLATFORM%;%PATH% +- python -V +- bash -c "which python" +- bash -c "python -V" +- bash -c "which cl.exe" +- bash -c "cl.exe /? 2>&1 | head -n 2" +- bash -c "which csc.exe" +- bash -c "csc.exe /? | head -n 2" +- bash -c "which cccl" +- bash -c "cccl --version" +- make --version +- uname -a + +build_script: +- set CCCL_OPTIONS=--cccl-muffle /W3 +- set CHECK_OPTIONS=CSHARPOPTIONS=-platform:%Platform% + # Open dummy file descriptor to fix error on cygwin: ./configure: line 560: 0: Bad file descriptor +- bash -c "exec 0- + If ("$env:SWIGLANG$env:VER" -Match "python27") { + $env:CCCL_OPTIONS="$env:CCCL_OPTIONS /wd4717" + } +- .\swig.exe -version +- bash -c "file ./swig.exe" +- bash -c "time make -k check-%SWIGLANG%-version" +- bash -c "time make -k check-%SWIGLANG%-examples %CHECK_OPTIONS%" +- bash -c "time make -k check-%SWIGLANG%-test-suite %CHECK_OPTIONS%" + +# Do not build on tags (GitHub only) +skip_tags: true diff --git a/configure.ac b/configure.ac index 79df729affe..bcb3ba812be 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.5],[http://www.swig.org]) +AC_INIT([swig],[3.0.9],[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 @@ -40,11 +40,6 @@ AC_DEFINE_UNQUOTED(SWIG_PLATFORM, ["$host"], [Platform that SWIG is built for]) dnl Checks for header files. AC_HEADER_STDC -dnl Checks for types. -AC_LANG_PUSH([C++]) -AC_CHECK_TYPES([bool]) -AC_LANG_POP([C++]) - dnl Look for popen AC_ARG_WITH(popen, AS_HELP_STRING([--without-popen], [Disable popen]), with_popen="$withval") if test x"${with_popen}" = xno ; then @@ -122,23 +117,6 @@ echo "Note : None of the following packages are required for users to compile an echo "" AC_PROG_YACC -AC_PROG_RANLIB -AC_CHECK_PROGS(AR, ar aal, ar) -AC_SUBST(AR) -AC_CHECK_PROGS(YODL2MAN, yodl2man) -AC_CHECK_PROGS(YODL2HTML, yodl2html) - -if test -n "$YODL2MAN"; then - AC_MSG_CHECKING([yodl2man version >= 2.02]) - [yodl_version=`$YODL2MAN --version 2>&1 | grep 'yodl version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\).*/\1/g'`] - AX_COMPARE_VERSION([$yodl_version],[ge],[2.02], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no - $yodl_version found])]) -fi - -if test -n "$YODL2HTML"; then - AC_MSG_CHECKING([yodl2html version >= 2.02]) - [yodl_version=`$YODL2HTML --version 2>&1 | grep 'yodl version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`] - AX_COMPARE_VERSION([$yodl_version],[ge],[2.02], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no - $yodl_version found])]) -fi echo "" echo "Checking for installed target languages and other information in order to compile and run" @@ -274,6 +252,8 @@ then then CCSHARED="-fpic" else CCSHARED="+z" fi;; + s390x*-*-*) CCSHARED="-fpic" ;; + s390*-*-*) CCSHARED="-fPIC" ;; *-*-linux*) CCSHARED="-fpic";; *-*-freebsd* | *-*-openbsd*) CCSHARED="-fpic";; *-*-netbsd*) CCSHARED="-fPIC";; @@ -335,9 +315,10 @@ AC_MSG_CHECKING([whether to enable C++11 testing]) AC_MSG_RESULT([$enable_cpp11_testing]) PLATCXXFLAGS="$PLATCFLAGS" -if test x"$enable_cpp11_testing" = xyes; then +if test x"$enable_cpp11_testing" = xyes; then AC_LANG_PUSH([C++]) CXXFLAGS_SAVED=$CXXFLAGS + CXXFLAGS= AX_CXX_COMPILE_STDCXX_11([noext], [nostop]) CXXFLAGS=$CXXFLAGS_SAVED AC_LANG_POP([C++]) @@ -353,8 +334,8 @@ if test x"$enable_cpp11_testing" = xyes; then fi # On darwin 10.7,10.8,10.9 using clang++, need to ensure using -# libc++ for tests and examples to run under mono. May affect -# other language targets as well - problem is an OSX incompatibility +# libc++ for tests and examples to run under mono. May affect +# other language targets as well - problem is a Mac OS X incompatibility # between libraries depending on libstdc++ and libc++. CLANGXX= $CXX -v 2>&1 | grep -i clang >/dev/null && CLANGXX=yes @@ -461,6 +442,12 @@ fi]) AC_ARG_WITH(alllang, AS_HELP_STRING([--without-alllang], [Disable all languages]), with_alllang="$withval") +if test "$with_alllang" = "no"; then + alllang_default=no +else + alllang_default=yes +fi + AC_CHECK_PROGS(PKGCONFIG, [pkg-config]) #-------------------------------------------------------------------- @@ -475,14 +462,14 @@ AC_ARG_WITH(tclconfig, AS_HELP_STRING([--without-tcl], [Disable Tcl]) AS_HELP_STRING([--with-tclconfig=path], [Set location of tclConfig.sh]), [with_tclconfig="$withval"], [with_tclconfig=]) AC_ARG_WITH(tcl, [ --with-tcl=path Set location of Tcl package],[ - TCLPACKAGE="$withval"], [TCLPACKAGE=yes]) + TCLPACKAGE="$withval"], [TCLPACKAGE="$alllang_default"]) AC_ARG_WITH(tclincl,[ --with-tclincl=path Set location of Tcl include directory],[ TCLINCLUDE="$ISYSTEM$withval"], [TCLINCLUDE=]) AC_ARG_WITH(tcllib,[ --with-tcllib=path Set location of Tcl library directory],[ TCLLIB="-L$withval"], [TCLLIB=]) # First, check for "--without-tcl" or "--with-tcl=no". -if test x"${TCLPACKAGE}" = xno -o x"${with_alllang}" = xno; then +if test x"${TCLPACKAGE}" = xno; then AC_MSG_NOTICE([Disabling Tcl]) else AC_MSG_CHECKING([for Tcl configuration]) @@ -599,80 +586,124 @@ AC_SUBST(TCLCXXSHARED) PYINCLUDE= PYLIB= +PYLINK= PYPACKAGE= AC_ARG_WITH(python, AS_HELP_STRING([--without-python], [Disable Python]) -AS_HELP_STRING([--with-python=path], [Set location of Python executable]),[ PYBIN="$withval"], [PYBIN=yes]) +AS_HELP_STRING([--with-python=path], [Set location of Python executable]),[ PYBIN="$withval"], [PYBIN="$alllang_default"]) # First, check for "--without-python" or "--with-python=no". -if test x"${PYBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PYBIN}" = xno; then AC_MSG_NOTICE([Disabling Python]) else # First figure out the name of the Python executable if test "x$PYBIN" = xyes; then - AC_CHECK_PROGS(PYTHON, [python python2.8 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python1.4]) + AC_CHECK_PROGS(PYTHON, [python python2.8 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0]) else PYTHON="$PYBIN" fi + PYVER=0 if test -n "$PYTHON"; then + AC_MSG_CHECKING([for $PYTHON major version number]) + PYVER=`($PYTHON -c "import sys; sys.stdout.write(sys.version[[0]])") 2>/dev/null` + AC_MSG_RESULT($PYVER) + if test -z "$PYVER"; then + PYVER=0 + else + AC_MSG_CHECKING(for Python os.name) + PYOSNAME=`($PYTHON -c "import sys, os; sys.stdout.write(os.name)")` + AC_MSG_RESULT($PYOSNAME) + fi + fi + + if test $PYVER -eq 1 -o $PYVER -eq 2; then AC_MSG_CHECKING(for Python prefix) - PYPREFIX=`($PYTHON -c "import sys; print sys.prefix") 2>/dev/null` + PYPREFIX=`($PYTHON -c "import sys; sys.stdout.write(sys.prefix)") 2>/dev/null` AC_MSG_RESULT($PYPREFIX) AC_MSG_CHECKING(for Python exec-prefix) - PYEPREFIX=`($PYTHON -c "import sys; print sys.exec_prefix") 2>/dev/null` + PYEPREFIX=`($PYTHON -c "import sys; sys.stdout.write(sys.exec_prefix)") 2>/dev/null` AC_MSG_RESULT($PYEPREFIX) + if test x"$PYOSNAME" = x"nt"; then + # Windows installations are quite different to posix installations + PYPREFIX=`echo "$PYPREFIX" | sed -e 's,\\\\,/,g'` # Forward slashes are easier to use and even work on Windows most of the time + PYTHON_SO=.pyd - # Note: I could not think of a standard way to get the version string from different versions. - # This trick pulls it out of the file location for a standard library file. - - AC_MSG_CHECKING(for Python version) - - # Need to do this hack since autoconf replaces __file__ with the name of the configure file - filehack="file__" - PYVERSION=`($PYTHON -c "import string,operator,os.path; print operator.getitem(os.path.split(operator.getitem(os.path.split(string.__$filehack),0)),1)")` - AC_MSG_RESULT($PYVERSION) - - # Find the directory for libraries this is necessary to deal with - # platforms that can have apps built for multiple archs: e.g. x86_64 - AC_MSG_CHECKING(for Python lib dir) - PYLIBDIR=`($PYTHON -c "import sys; print sys.lib") 2>/dev/null` - if test -z "$PYLIBDIR"; then - # Fedora patch Python to add sys.lib, for other distros we assume "lib". - PYLIBDIR="lib" - fi - AC_MSG_RESULT($PYLIBDIR) + AC_MSG_CHECKING(for Python header files) + if test -r $PYPREFIX/include/Python.h; then + PYINCLUDE="-I$PYPREFIX/include" + fi + AC_MSG_RESULT($PYINCLUDE) + + AC_MSG_CHECKING(for Python library directory) + if test -d $PYPREFIX/libs; then + PYLIB=$PYPREFIX/libs + PYLINKFILE=`ls $PYLIB/python*.lib | grep "python[[0-9]][[0-9]]\.lib"` + if test -r "$PYLINKFILE"; then + PYLINK=-l`basename $PYLINKFILE | sed -e 's/\.lib$//'` + else + PYLIB= + fi + fi + else + # Note: I could not think of a standard way to get the version string from different versions. + # This trick pulls it out of the file location for a standard library file. + + AC_MSG_CHECKING(for Python version) + + # Need to do this hack since autoconf replaces __file__ with the name of the configure file + filehack="file__" + PYVERSION=`($PYTHON -c "import sys,string,operator,os.path; sys.stdout.write(operator.getitem(os.path.split(operator.getitem(os.path.split(string.__$filehack),0)),1))")` + AC_MSG_RESULT($PYVERSION) + + # Find the directory for libraries this is necessary to deal with + # platforms that can have apps built for multiple archs: e.g. x86_64 + AC_MSG_CHECKING(for Python lib dir) + PYLIBDIR=`($PYTHON -c "import sys; sys.stdout.write(sys.lib)") 2>/dev/null` + if test -z "$PYLIBDIR"; then + # Fedora patch Python to add sys.lib, for other distros we assume "lib". + PYLIBDIR="lib" + fi + AC_MSG_RESULT($PYLIBDIR) - # Set the include directory + # Set the include directory - AC_MSG_CHECKING(for Python header files) - if test -r $PYPREFIX/include/$PYVERSION/Python.h; then - PYINCLUDE="-I$PYPREFIX/include/$PYVERSION -I$PYEPREFIX/$PYLIBDIR/$PYVERSION/config" - fi - if test -z "$PYINCLUDE"; then - if test -r $PYPREFIX/include/Py/Python.h; then - PYINCLUDE="-I$PYPREFIX/include/Py -I$PYEPREFIX/$PYLIBDIR/python/lib" + AC_MSG_CHECKING(for Python header files) + if test -r $PYPREFIX/include/$PYVERSION/Python.h; then + PYINCLUDE="-I$PYPREFIX/include/$PYVERSION -I$PYEPREFIX/$PYLIBDIR/$PYVERSION/config" + fi + if test -z "$PYINCLUDE"; then + if test -r $PYPREFIX/include/Py/Python.h; then + PYINCLUDE="-I$PYPREFIX/include/Py -I$PYEPREFIX/$PYLIBDIR/python/lib" + fi fi + AC_MSG_RESULT($PYINCLUDE) + + # Set the library directory blindly. This probably won't work with older versions + AC_MSG_CHECKING(for Python library directory) + dirs="$PYVERSION/config $PYVERSION/$PYLIBDIR python/$PYLIBDIR" + for i in $dirs; do + if test -d $PYEPREFIX/$PYLIBDIR/$i; then + PYLIB="$PYEPREFIX/$PYLIBDIR/$i" + break + fi + done + + PYLINK="-l$PYVERSION" fi - AC_MSG_RESULT($PYINCLUDE) - # Set the library directory blindly. This probably won't work with older versions - AC_MSG_CHECKING(for Python library) - dirs="$PYVERSION/config $PYVERSION/$PYLIBDIR python/$PYLIBDIR" - for i in $dirs; do - if test -d $PYEPREFIX/$PYLIBDIR/$i; then - PYLIB="$PYEPREFIX/$PYLIBDIR/$i" - break - fi - done if test -z "$PYLIB"; then AC_MSG_RESULT(Not found) else AC_MSG_RESULT($PYLIB) fi - - PYLINK="-l$PYVERSION" + AC_MSG_CHECKING(for Python library) + if test -z "$PYLINK"; then + AC_MSG_RESULT(Not found) + else + AC_MSG_RESULT($PYLINK) + fi fi # Cygwin (Windows) needs the library for dynamic linking @@ -695,103 +726,165 @@ AC_SUBST(PYTHONDYNAMICLINKING) # Look for Python 3.x #---------------------------------------------------------------- -# mostly copy & pasted from "Look for Python" section, -# did some trim, fix and rename - PY3INCLUDE= PY3LIB= +PY3LINK= PY3PACKAGE= AC_ARG_WITH(python3, AS_HELP_STRING([--without-python3], [Disable Python 3.x support]) -AS_HELP_STRING([--with-python3=path], [Set location of Python 3.x executable]),[ PY3BIN="$withval"], [PY3BIN=yes]) +AS_HELP_STRING([--with-python3=path], [Set location of Python 3.x executable]),[ PY3BIN="$withval"], [PY3BIN="$alllang_default"]) # First, check for "--without-python3" or "--with-python3=no". -if test x"${PY3BIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PY3BIN}" = xno; then AC_MSG_NOTICE([Disabling Python 3.x support]) else + if test -z "$PYVER"; then + PYVER=0 + fi if test "x$PY3BIN" = xyes; then - for py_ver in 3 3.6 3.5 3.4 3.3 3.2 3.1 3.0; do - AC_CHECK_PROGS(PYTHON3, [python$py_ver]) - if test -n "$PYTHON3"; then - AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config]) - if test -n "$PY3CONFIG"; then - break + if test x"$PYOSNAME" = x"nt" -a $PYVER -ge 3; then + PYTHON3="$PYTHON" + else + for py_ver in 3 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0 ""; do + AC_CHECK_PROGS(PYTHON3, [python$py_ver]) + if test -n "$PYTHON3"; then + AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config]) + if test -n "$PY3CONFIG"; then + break + fi fi - fi - done + done + fi else PYTHON3="$PY3BIN" AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config]) fi + if test -n "$PYTHON3"; then + AC_MSG_CHECKING([for $PYTHON3 major version number]) + PYVER=`($PYTHON3 -c "import sys; sys.stdout.write(sys.version[[0]])") 2>/dev/null` + AC_MSG_RESULT($PYVER) + if test -z "$PYVER"; then + PYVER=0 + fi + fi - if test -n "$PYTHON3" -a -n "$PY3CONFIG"; then - AC_MSG_CHECKING([for Python 3.x prefix]) - PY3PREFIX=`($PY3CONFIG --prefix) 2>/dev/null` - AC_MSG_RESULT($PY3PREFIX) - AC_MSG_CHECKING(for Python 3.x exec-prefix) - PY3EPREFIX=`($PY3CONFIG --exec-prefix) 2>/dev/null` - AC_MSG_RESULT($PY3EPREFIX) - - # Note: I could not think of a standard way to get the version string from different versions. - # This trick pulls it out of the file location for a standard library file. - - AC_MSG_CHECKING([for Python 3.x version]) + if test $PYVER -ge 3; then + AC_MSG_CHECKING(for Python 3.x os.name) + PY3OSNAME=`($PYTHON3 -c "import sys, os; sys.stdout.write(os.name)")` + AC_MSG_RESULT($PY3OSNAME) + + if test x"$PY3OSNAME" = x"nt"; then + # Windows installations are quite different to posix installations + # There is no python-config to use + AC_MSG_CHECKING(for Python 3.x prefix) + PY3PREFIX=`($PYTHON3 -c "import sys; sys.stdout.write(sys.prefix)") 2>/dev/null` + AC_MSG_RESULT($PY3PREFIX) + PY3PREFIX=`echo "$PY3PREFIX" | sed -e 's,\\\\,/,g'` # Forward slashes are easier to use and even work on Windows most of the time + PYTHON_SO=.pyd + + AC_MSG_CHECKING(for Python 3.x header files) + if test -r $PY3PREFIX/include/Python.h; then + PY3INCLUDE="-I$PY3PREFIX/include" + fi + AC_MSG_RESULT($PY3INCLUDE) + + AC_MSG_CHECKING(for Python 3.x library directory) + if test -d $PY3PREFIX/libs; then + PY3LIB=$PY3PREFIX/libs + PY3LINKFILE=`ls $PY3LIB/python*.lib | grep "python[[0-9]][[0-9]]\.lib"` + if test -r "$PY3LINKFILE"; then + PY3LINK=-l`basename $PY3LINKFILE | sed -e 's/\.lib$//'` + else + PY3LIB= + fi + fi + if test -z "$PY3LIB"; then + AC_MSG_RESULT([Not found]) + else + AC_MSG_RESULT($PY3LIB) + fi + AC_MSG_CHECKING([for Python 3.x library]) + if test -z "$PY3LINK"; then + AC_MSG_RESULT(Not found) + else + AC_MSG_RESULT($PY3LINK) + fi + elif test -n "$PY3CONFIG"; then + AC_MSG_CHECKING([for Python 3.x prefix]) + PY3PREFIX=`($PY3CONFIG --prefix) 2>/dev/null` + AC_MSG_RESULT($PY3PREFIX) + AC_MSG_CHECKING(for Python 3.x exec-prefix) + PY3EPREFIX=`($PY3CONFIG --exec-prefix) 2>/dev/null` + AC_MSG_RESULT($PY3EPREFIX) + + # Note: I could not think of a standard way to get the version string from different versions. + # This trick pulls it out of the file location for a standard library file. + + AC_MSG_CHECKING([for Python 3.x version]) + + # Need to do this hack since autoconf replaces __file__ with the name of the configure file + filehack="file__" + PY3VERSION=`($PYTHON3 -c "import string,operator,os.path; print(operator.getitem(os.path.split(operator.getitem(os.path.split(string.__$filehack),0)),1))")` + AC_MSG_RESULT($PY3VERSION) + + # Find the directory for libraries this is necessary to deal with + # platforms that can have apps built for multiple archs: e.g. x86_64 + AC_MSG_CHECKING([for Python 3.x lib dir]) + PY3LIBDIR=`($PYTHON3 -c "import sys; print(sys.lib)") 2>/dev/null` + if test -z "$PY3LIBDIR"; then + # some dists don't have sys.lib so the best we can do is assume lib + PY3LIBDIR="lib" + fi + AC_MSG_RESULT($PY3LIBDIR) - # Need to do this hack since autoconf replaces __file__ with the name of the configure file - filehack="file__" - PY3VERSION=`($PYTHON3 -c "import string,operator,os.path; print(operator.getitem(os.path.split(operator.getitem(os.path.split(string.__$filehack),0)),1))")` - AC_MSG_RESULT($PY3VERSION) + # Set the include directory - # Find the directory for libraries this is necessary to deal with - # platforms that can have apps built for multiple archs: e.g. x86_64 - AC_MSG_CHECKING([for Python 3.x lib dir]) - PY3LIBDIR=`($PYTHON3 -c "import sys; print(sys.lib)") 2>/dev/null` - if test -z "$PY3LIBDIR"; then - # some dists don't have sys.lib so the best we can do is assume lib - PY3LIBDIR="lib" - fi - AC_MSG_RESULT($PY3LIBDIR) + AC_MSG_CHECKING([for Python 3.x header files]) + PY3INCLUDE=`($PY3CONFIG --includes) 2>/dev/null` + AC_MSG_RESULT($PY3INCLUDE) - # Set the include directory + # Set the library directory blindly. This probably won't work with older versions + AC_MSG_CHECKING([for Python 3.x library directory]) + dirs="$PY3VERSION/config $PY3VERSION/$PY3LIBDIR python/$PY3LIBDIR" + for i in $dirs; do + if test -d $PY3EPREFIX/$PY3LIBDIR/$i; then + PY3LIB="$PY3EPREFIX/$PY3LIBDIR/$i" + break + fi + done + if test -z "$PY3LIB"; then + AC_MSG_RESULT([Not found]) + else + AC_MSG_RESULT($PY3LIB) + fi - AC_MSG_CHECKING([for Python 3.x header files]) - PY3INCLUDE=`($PY3CONFIG --includes) 2>/dev/null` - AC_MSG_RESULT($PY3INCLUDE) + PY3LINK="-l$PY3VERSION" - # Set the library directory blindly. This probably won't work with older versions - AC_MSG_CHECKING([for Python 3.x library]) - dirs="$PY3VERSION/config $PY3VERSION/$PY3LIBDIR python/$PY3LIBDIR" - for i in $dirs; do - if test -d $PY3EPREFIX/$PY3LIBDIR/$i; then - PY3LIB="$PY3EPREFIX/$PY3LIBDIR/$i" - break + AC_MSG_CHECKING([for Python 3.x library]) + if test -z "$PY3LINK"; then + AC_MSG_RESULT(Not found) + else + AC_MSG_RESULT($PY3LINK) fi - done - if test -z "$PY3LIB"; then - AC_MSG_RESULT([Not found]) - else - AC_MSG_RESULT($PY3LIB) fi - - PY3LINK="-l$PY3VERSION" fi # Cygwin (Windows) needs the library for dynamic linking case $host in *-*-cygwin* | *-*-mingw*) - PYTHON3DYNAMICLINKING="-L$PYLIB $PY3LINK" + PYTHON3DYNAMICLINKING="-L$PY3LIB $PY3LINK" DEFS="-DUSE_DL_IMPORT $DEFS" ;; *)PYTHON3DYNAMICLINKING="";; esac -fi -AC_SUBST(PY3INCLUDE) -AC_SUBST(PY3LIB) -AC_SUBST(PY3LINK) -AC_SUBST(PYTHON3DYNAMICLINKING) -AC_CHECK_PROGS(PEP8, pep8) + AC_SUBST(PY3INCLUDE) + AC_SUBST(PY3LIB) + AC_SUBST(PY3LINK) + AC_SUBST(PYTHON3DYNAMICLINKING) + AC_CHECK_PROGS(PEP8, pep8) +fi #---------------------------------------------------------------- # Look for Perl5 @@ -800,10 +893,10 @@ AC_CHECK_PROGS(PEP8, pep8) PERLBIN= AC_ARG_WITH(perl5, AS_HELP_STRING([--without-perl5], [Disable Perl5]) -AS_HELP_STRING([--with-perl5=path], [Set location of Perl5 executable]),[ PERLBIN="$withval"], [PERLBIN=yes]) +AS_HELP_STRING([--with-perl5=path], [Set location of Perl5 executable]),[ PERLBIN="$withval"], [PERLBIN="$alllang_default"]) # First, check for "--without-perl5" or "--with-perl5=no". -if test x"${PERLBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PERLBIN}" = xno; then AC_MSG_NOTICE([Disabling Perl5]) PERL= else @@ -911,10 +1004,10 @@ OCTAVEBIN= OCTAVE_SO=.oct AC_ARG_WITH(octave, AS_HELP_STRING([--without-octave], [Disable Octave]) -AS_HELP_STRING([--with-octave=path], [Set location of Octave executable]),[OCTAVEBIN="$withval"], [OCTAVEBIN=yes]) +AS_HELP_STRING([--with-octave=path], [Set location of Octave executable]),[OCTAVEBIN="$withval"], [OCTAVEBIN="$alllang_default"]) # First, check for "--without-octave" or "--with-octave=no". -if test x"${OCTAVEBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${OCTAVEBIN}" = xno; then AC_MSG_NOTICE([Disabling Octave]) OCTAVE= @@ -928,7 +1021,7 @@ fi if test -n "$OCTAVE"; then AC_MSG_CHECKING([for mkoctfile]) - mkoctfile="`dirname ${OCTAVE}`/mkoctfile" + mkoctfile="$(dirname $OCTAVE)/$(basename $OCTAVE | sed -e 's/octave/mkoctfile/')" AS_IF([test -x "${mkoctfile}"],[ AC_MSG_RESULT([${mkoctfile}]) ],[ @@ -1064,29 +1157,186 @@ AC_SUBST(MATLAB) AC_SUBST(MATLAB_HOME) AC_SUBST(MATLAB_MEX) AC_SUBST(MATLAB_MEXSUFFIX) +# Look for Scilab +#---------------------------------------------------------------- + +AC_ARG_WITH(scilab, AS_HELP_STRING([--without-scilab], [Disable Scilab]) +AS_HELP_STRING([--with-scilab=path], [Set location of Scilab executable]),[SCILABBIN="$withval"], [SCILABBIN="$alllang_default"]) +AC_ARG_WITH(scilab-inc, [ --with-scilab-inc=path Set location of Scilab include directory], [SCILABINCDIR="$withval"], [SCILABINCDIR=""]) + +# First, check for "--without-scilab" or "--with-scilab=no". +if test x"${SCILABBIN}" = xno; then + AC_MSG_NOTICE([Disabling Scilab]) + SCILAB= +else + # Check for Scilab executable + if test "x$SCILABBIN" = xyes; then + AC_CHECK_PROGS(SCILAB, scilab) + else + AC_MSG_CHECKING(for scilab) + if test -f "$SCILABBIN"; then + AC_MSG_RESULT($SCILABBIN) + SCILAB="$SCILABBIN" + else + AC_MSG_RESULT(not found) + fi + fi + + if test -n "$SCILAB"; then + # Check for Scilab version (needs api_scilab so needs version 5.3.3 or higher) + SCILAB_FULL_VERSION=`$SCILAB -version | head -1 | sed -e 's|Scilab version \"\(.*\)\"|\1|g'` + + AC_MSG_CHECKING(Scilab version is 5.3.3 or higher) + SCILAB_MAJOR_VERSION=`echo $SCILAB_FULL_VERSION | cut -d. -f1` + SCILAB_MINOR_VERSION=`echo $SCILAB_FULL_VERSION | cut -d. -f2` + SCILAB_MAINTENANCE_VERSION=`echo $SCILAB_FULL_VERSION | cut -d. -f3` + SCILAB_VERSION="$SCILAB_MAJOR_VERSION$SCILAB_MINOR_VERSION$SCILAB_MAINTENANCE_VERSION" + + if test $SCILAB_VERSION -ge 533; then + AC_MSG_RESULT(yes) + else + AC_MSG_RESULT(no) + SCILAB= + fi + + if test -n "$SCILAB"; then + # Set Scilab startup options depending on version + AC_MSG_CHECKING(for Scilab startup options) + SCILABOPT="-nwni -nb" + if test $SCILAB_VERSION -ge 540; then + SCILABOPT+=" -noatomsautoload" + fi + AC_MSG_RESULT($SCILABOPT) + + # Check for Scilab header files + AC_MSG_CHECKING(for Scilab header files) + if test "$SCILABINCDIR" != ""; then + dirs="$SCILABINCDIR" + elif test -n "$PKGCONFIG"; then + dirs=`$PKGCONFIG scilab --cflags-only-I | sed -e 's/-I//g'` + else + dirs="" + fi + for i in $dirs; do + if test -r $i/api_scilab.h; then + AC_MSG_RESULT($i) + SCILABINCLUDE="-I$i" + break + fi + if test -r $i/scilab/api_scilab.h; then + AC_MSG_RESULT($i/scilab) + SCILABINCLUDE="-I$i/scilab" + break + fi + done + if test "$SCILABINCLUDE" = "" ; then + AC_MSG_RESULT(not found) + SCILAB= + fi + fi + fi +fi + +AC_SUBST(SCILAB) +AC_SUBST(SCILABINCLUDE) +AC_SUBST(SCILABOPT) #---------------------------------------------------------------- # Look for java #---------------------------------------------------------------- AC_ARG_WITH(java, AS_HELP_STRING([--without-java], [Disable Java]) -AS_HELP_STRING([--with-java=path], [Set location of java executable]),[JAVABIN="$withval"], [JAVABIN=yes]) +AS_HELP_STRING([--with-java=path], [Set location of java executable]),[JAVABIN="$withval"], [JAVABIN="$alllang_default"]) AC_ARG_WITH(javac, [ --with-javac=path Set location of javac executable],[JAVACBIN="$withval"], [JAVACBIN=]) # First, check for "--without-java" or "--with-java=no". -if test x"${JAVABIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${JAVABIN}" = xno; then AC_MSG_NOTICE([Disabling Java]) JAVA= else +dnl Detect everything we need for Java: java for running Java tests, javac for +dnl compiling them and C headers for compiling C code. +dnl +dnl If JAVA_HOME is defined and contains everything needed, as it's supposed to, +dnl just use it. Otherwise try to locate the necessary files in the path. +case $host in + *-*-cygwin*) + dnl Ensure that JAVA_HOME is in the form we can use, it's typically set to Windows path by the installer. + if test -n "$JAVA_HOME"; then + JAVA_HOME=`cygpath --mixed "$JAVA_HOME"` + fi + ;; + *-*-mingw*) + if test -n "$JAVA_HOME"; then + JAVA_HOME=`${srcdir}/Tools/convertpath -u "$JAVA_HOME"` + fi + ;; + *-*-darwin*) + dnl Under OS X JAVA_HOME is not set by default, try to use the system default JRE. + if test -z "$JAVA_HOME" -a -x /usr/libexec/java_home; then + JAVA_HOME=`/usr/libexec/java_home` + fi + dnl The JAVA_HOME doesn't contain the JDK headers though, but they seem to + dnl always be in the same location, according to Apple JNI documentation. + JAVA_OSX_STD_INCDIR="/System/Library/Frameworks/JavaVM.framework/Headers" + if test -r "$JAVA_OSX_STD_INCDIR/jni.h"; then + JAVA_HOME_INCDIR=$JAVA_OSX_STD_INCDIR + fi + ;; +esac + +AC_MSG_CHECKING(for java JDK) +if test -n "$JAVA_HOME"; then + dnl Don't complain about missing executables/headers if they had been + dnl explicitly overridden from the command line, but otherwise verify that we + dnl have everything we need. + java_home_ok=1 + if test -z "$JAVABIN" -a ! -x "$JAVA_HOME/bin/java"; then + AC_MSG_WARN([No java executable under JAVA_HOME.]) + java_home_ok=0 + fi + if test -z "$JAVACBIN" -a ! -x "$JAVA_HOME/bin/javac"; then + AC_MSG_WARN([No javac executable under JAVA_HOME.]) + java_home_ok=0 + fi + + dnl By default the headers are under JAVA_HOME/include, but OS X is special + dnl and defines JAVA_HOME_INCDIR differently above. + if test -z "$JAVA_HOME_INCDIR"; then + JAVA_HOME_INCDIR="$JAVA_HOME/include" + fi + if test -z "$JAVAINCDIR" -a ! -r "$JAVA_HOME_INCDIR/jni.h"; then + AC_MSG_WARN([No java headers under JAVA_HOME (does it point to a JDK and not just JRE?).]) + java_home_ok=0 + fi + if test "$java_home_ok" = 1; then + AC_MSG_RESULT([found (in $JAVA_HOME)]) + else + AC_MSG_RESULT(no) + AC_MSG_WARN([JAVA_HOME ($JAVA_HOME) is defined but does not point to a complete JDK installation, ignoring it.]) + JAVA_HOME= + fi +else + AC_MSG_RESULT([no (JAVA_HOME is not defined)]) +fi + if test "x$JAVABIN" = xyes; then - AC_CHECK_PROGS(JAVA, java kaffe guavac) + if test -n "$JAVA_HOME"; then + JAVA="$JAVA_HOME/bin/java" + else + AC_CHECK_PROGS(JAVA, java kaffe guavac) + fi else JAVA="$JAVABIN" fi if test -z "$JAVACBIN"; then - AC_CHECK_PROGS(JAVAC, javac) + if test -n "$JAVA_HOME"; then + JAVAC="$JAVA_HOME/bin/javac" + else + AC_CHECK_PROGS(JAVAC, javac) + fi else JAVAC="$JAVACBIN" fi @@ -1094,48 +1344,67 @@ fi AC_MSG_CHECKING(for java include file jni.h) AC_ARG_WITH(javaincl, [ --with-javaincl=path Set location of Java include directory], [JAVAINCDIR="$withval"], [JAVAINCDIR=]) +JAVAINC="" if test -z "$JAVAINCDIR" ; then - JAVAINCDIR="/usr/j2sdk*/include /usr/local/j2sdk*/include /usr/jdk*/include /usr/local/jdk*/include /opt/j2sdk*/include /opt/jdk*/include /usr/java/include /usr/java/j2sdk*/include /usr/java/jdk*/include /usr/local/java/include /opt/java/include /usr/include/java /usr/local/include/java /usr/lib/java/include /usr/lib/jvm/java*/include /usr/lib64/jvm/java*/include /usr/include/kaffe /usr/local/include/kaffe /usr/include" + if test -n "$JAVA_HOME"; then + JAVAINCDIR="$JAVA_HOME_INCDIR" + JAVAINC=-I\"$JAVAINCDIR\" + else + JAVAINCDIR="/usr/j2sdk*/include /usr/local/j2sdk*/include /usr/jdk*/include /usr/local/jdk*/include /opt/j2sdk*/include /opt/jdk*/include /usr/java/include /usr/java/j2sdk*/include /usr/java/jdk*/include /usr/local/java/include /opt/java/include /usr/include/java /usr/local/include/java /usr/lib/java/include /usr/lib/jvm/java*/include /usr/lib64/jvm/java*/include /usr/include/kaffe /usr/local/include/kaffe /usr/include" - # Add in default installation directory on Windows for Cygwin - case $host in - *-*-cygwin* | *-*-mingw*) JAVAINCDIR="c:/Program*Files/Java/jdk*/include d:/Program*Files/Java/jdk*/include c:/j2sdk*/include d:/j2sdk*/include c:/jdk*/include d:/jdk*/include $JAVAINCDIR";; - *-*-darwin*) JAVAINCDIR="/System/Library/Frameworks/JavaVM.framework/Headers $JAVAINCDIR";; - *);; - esac -fi + # Add in default installation directory on Windows for Cygwin + case $host in + *-*-cygwin* | *-*-mingw*) JAVAINCDIR="c:/Program*Files*/Java/jdk*/include d:/Program*Files*/Java/jdk*/include c:/j2sdk*/include d:/j2sdk*/include c:/jdk*/include d:/jdk*/include $JAVAINCDIR";; + *-*-darwin*) JAVAINCDIR="$JAVA_OSX_STD_INCDIR $JAVAINCDIR";; + *);; + esac -JAVAINC="" -for d in $JAVAINCDIR ; do - if test -r "$d/jni.h" ; then - AC_MSG_RESULT($d) - JAVAINCDIR=$d - JAVAINC=-I\"$d\" - break + for d in $JAVAINCDIR ; do + if test -r "$d/jni.h" ; then + JAVAINCDIR=$d + JAVAINC=-I\"$d\" + break + fi + done fi -done +else + if test -r "$JAVAINCDIR/jni.h" ; then + JAVAINC=-I\"$JAVAINCDIR\" + fi +fi if test "$JAVAINC" = "" ; then AC_MSG_RESULT(not found) else + AC_MSG_RESULT($JAVAINC) # now look for /jni_md.h AC_MSG_CHECKING(for java include file jni_md.h) JAVAMDDIR=`find "$JAVAINCDIR" -follow -name jni_md.h -print` if test "$JAVAMDDIR" = "" ; then AC_MSG_RESULT(not found) else - JAVAMDDIR=`dirname "$JAVAMDDIR" | tail -1` - JAVAINC="${JAVAINC} -I\"$JAVAMDDIR\"" + JAVAMDDIR=-I\"`dirname "$JAVAMDDIR" | tail -1`\" AC_MSG_RESULT($JAVAMDDIR) + JAVAINC="${JAVAINC} ${JAVAMDDIR}" fi fi +case $host in +*-*-cygwin*) + # TODO: Only use this flag if the compiler supports it, later versions of gcc no longer have it + GCC_MNO_CYGWIN=" -mno-cygwin" + ;; +*) + GCC_MNO_CYGWIN="" + ;; +esac + # java.exe on Cygwin requires the Windows standard (Pascal) calling convention as it is a normal Windows executable and not a Cygwin built executable case $host in *-*-cygwin* | *-*-mingw*) if test "$GCC" = yes; then - JAVADYNAMICLINKING=" -mno-cygwin -mthreads -Wl,--add-stdcall-alias" - JAVACFLAGS="-mno-cygwin -mthreads" + JAVADYNAMICLINKING="$GCC_MNO_CYGWIN -mthreads -Wl,--add-stdcall-alias" + JAVACFLAGS="$GCC_MNO_CYGWIN -mthreads" else JAVADYNAMICLINKING="" JAVACFLAGS="" @@ -1171,6 +1440,15 @@ case $host in esac fi +# Quote for spaces in path to executables +if test -n "$JAVA"; then + JAVA=\"$JAVA\" +fi +if test -n "$JAVAC"; then + JAVAC=\"$JAVAC\" +fi + + AC_SUBST(JAVA) AC_SUBST(JAVAC) AC_SUBST(JAVAINC) @@ -1184,10 +1462,10 @@ AC_SUBST(JAVACFLAGS) #---------------------------------------------------------------- # Look for Javascript #---------------------------------------------------------------- -AC_ARG_WITH(javascript, AS_HELP_STRING([--without-javascript], [Disable Javascript]), [with_javascript="$withval"], [with_javascript=yes]) +AC_ARG_WITH(javascript, AS_HELP_STRING([--without-javascript], [Disable Javascript]), [with_javascript="$withval"], [with_javascript="$alllang_default"]) # First, check for "--without-javascript" or "--with-javascript=no". -if test x"${with_javascript}" = xno -o x"${with_alllang}" = xno ; then +if test x"${with_javascript}" = xno; then AC_MSG_NOTICE([Disabling Javascript]) JAVASCRIPT= else @@ -1215,7 +1493,7 @@ else # Look for Node.js which is the default Javascript engine #---------------------------------------------------------------- - AC_CHECK_PROGS(NODEJS, node) + AC_CHECK_PROGS(NODEJS, [nodejs node]) if test -n "$NODEJS"; then # node-gyp is needed to run the test-suite/examples @@ -1231,14 +1509,14 @@ 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-jscinc=path Set location of Javascript include directory], [JSCOREINCDIR="$withval"], [JSCOREINCDIR=]) JSCOREVERSION= if test -z "$JSCOREINCDIR"; then JSCOREINCDIR="/usr/include/ /usr/local/include/" - # Add in default directory for JavaScriptCore headers for Linux and MacOSX + # Add in default directory for JavaScriptCore headers for Linux and Mac OS X case $host in *-*-linux*) JSCOREINCDIR="/usr/include/webkit-1.0/ /usr/include/webkitgtk-1.0/ /usr/local/include/webkit-1.0/JavaScriptCore/ $JSCOREINCDIR" @@ -1265,7 +1543,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-jsclib=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) @@ -1289,11 +1567,11 @@ 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"]) # if not include dir is specified we try to find if test -z "$JSV8INCDIR"; then - # Add in default directory for JavaScriptCore headers for Linux and MacOSX + # Add in default directory for JavaScriptCore headers for Linux and Mac OS X case $host in *-*-linux*) JSV8INCDIR="/usr/include /usr/local/include/ $JSV8INCDIR" @@ -1322,7 +1600,7 @@ else # check for V8 library AC_MSG_CHECKING(for V8 Javascript library) - AC_ARG_WITH(jsv8lib,[ --with-jsv8lib=path Set location of V8 Javascript library directory],[JSV8LIBDIR="$withval"], [JSV8LIB=]) + AC_ARG_WITH(jsv8lib,[ --with-jsv8lib=path Set location of V8 Javascript library directory],[JSV8LIBDIR="$withval"], [JSV8LIB=]) v8libdirs="$JSV8LIBDIR /usr/lib64/ /usr/local/lib64/ /usr/lib/ /usr/local/lib/" for d in $v8libdirs ; do @@ -1377,11 +1655,11 @@ AC_SUBST(NODEGYP) #---------------------------------------------------------------- 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=yes]) +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 -o x"${with_alllang}" = xno ; then +if test x"${GCJBIN}" = xno; then AC_MSG_NOTICE([Disabling GCJ]) else if test "x$GCJBIN" = xyes; then @@ -1405,13 +1683,13 @@ AC_SUBST(GCJH) #---------------------------------------------------------------- AC_ARG_WITH(android, AS_HELP_STRING([--without-android], [Disable Android]) -AS_HELP_STRING([--with-android=path], [Set location of android executable]),[ANDROIDBIN="$withval"], [ANDROIDBIN=yes]) -AC_ARG_WITH(adb, [ --with-adb=path Set location of adb executable - Android Debug Bridge],[ADBBIN="$withval"], [ADBBIN=]) -AC_ARG_WITH(ant, [ --with-ant=path Set location of ant executable for Android],[ANTBIN="$withval"], [ANTBIN=]) -AC_ARG_WITH(ndk-build, [ --with-ndk-build=path Set location of Android ndk-build executable],[NDKBUILDBIN="$withval"], [NDKBUILDBIN=]) +AS_HELP_STRING([--with-android=path], [Set location of android executable]),[ANDROIDBIN="$withval"], [ANDROIDBIN="$alllang_default"]) +AC_ARG_WITH(adb, [ --with-adb=path Set location of adb executable - Android Debug Bridge],[ADBBIN="$withval"], [ADBBIN=]) +AC_ARG_WITH(ant, [ --with-ant=path Set location of ant executable for Android],[ANTBIN="$withval"], [ANTBIN=]) +AC_ARG_WITH(ndk-build, [ --with-ndk-build=path Set location of Android ndk-build executable],[NDKBUILDBIN="$withval"], [NDKBUILDBIN=]) # First, check for "--without-android" or "--with-android=no". -if test x"${ANDROIDBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${ANDROIDBIN}" = xno; then AC_MSG_NOTICE([Disabling Android]) ANDROID= else @@ -1454,16 +1732,16 @@ GUILE_CFLAGS= GUILE_LIBS= AC_ARG_WITH(guile-config, AS_HELP_STRING([--without-guile], [Disable Guile]) - AS_HELP_STRING([--with-guile-config=path], [Set location of guile-config]),[ GUILE_CONFIG="$withval"], [GUILE_CONFIG=]) +AS_HELP_STRING([--with-guile-config=path], [Set location of guile-config]),[ GUILE_CONFIG="$withval"], [GUILE_CONFIG=]) AC_ARG_WITH(guile,[ --with-guile=path Set location of Guile executable],[ - GUILE="$withval"], [GUILE=yes]) + GUILE="$withval"], [GUILE="$alllang_default"]) AC_ARG_WITH(guile-cflags,[ --with-guile-cflags=cflags Set cflags required to compile against Guile],[ GUILE_CFLAGS="$withval"]) AC_ARG_WITH(guile-libs,[ --with-guile-libs=ldflags Set ldflags needed to link with Guile],[ GUILE_LIBS="$withval"]) # First, check for "--without-guile" or "--with-guile=no". -if test x"${GUILE}" = xno -o x"${with_alllang}" = xno ; then +if test x"${GUILE}" = xno; then AC_MSG_NOTICE([Disabling Guile]) else if test -z "$GUILE_CONFIG" ; then @@ -1516,11 +1794,11 @@ AC_SUBST(GUILE_LIBS) #---------------------------------------------------------------- AC_ARG_WITH(mzscheme, AS_HELP_STRING([--without-mzscheme], [Disable MzScheme]) -AS_HELP_STRING([--with-mzscheme=path], [Set location of MzScheme executable]),[ MZSCHEMEBIN="$withval"], [MZSCHEMEBIN=yes]) +AS_HELP_STRING([--with-mzscheme=path], [Set location of MzScheme executable]),[ MZSCHEMEBIN="$withval"], [MZSCHEMEBIN="$alllang_default"]) AC_ARG_WITH(mzc, AS_HELP_STRING([--with-mzc=path], [Set location of MzScheme's mzc]), [ MZCBIN="$withval"], [MZCBIN=]) # First, check for "--without-mzscheme" or "--with-mzscheme=no". -if test x"${MZSCHEMEBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${MZSCHEMEBIN}" = xno; then AC_MSG_NOTICE([Disabling MzScheme]) MZC= else @@ -1560,11 +1838,11 @@ AC_SUBST(MZDYNOBJ) RUBYBIN= AC_ARG_WITH(ruby, AS_HELP_STRING([--without-ruby], [Disable Ruby]) -AS_HELP_STRING([--with-ruby=path], [Set location of Ruby executable]),[ RUBYBIN="$withval"], [RUBYBIN=yes]) +AS_HELP_STRING([--with-ruby=path], [Set location of Ruby executable]),[ RUBYBIN="$withval"], [RUBYBIN="$alllang_default"]) # First, check for "--without-ruby" or "--with-ruby=no". RUBYSO=$SO -if test x"${RUBYBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${RUBYBIN}" = xno; then AC_MSG_NOTICE([Disabling Ruby]) RUBY= else @@ -1581,6 +1859,7 @@ AC_MSG_CHECKING(for Ruby header files) if test -n "$RUBY"; then # Try Ruby1.9+ first RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyhdrdir"]] || $rubyhdrdir') 2>/dev/null` + RUBYARCHHDRDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyarchhdrdir"]] || $rubyarchhdrdir') 2>/dev/null` if test x"$RUBYDIR" = x"" || test x"$RUBYDIR" = x"nil"; then RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["archdir"]] || $archdir') 2>/dev/null` else @@ -1593,6 +1872,8 @@ if test -n "$RUBY"; then if test -r $i/ruby.h; then if test x"$RUBYARCH" = x""; then RUBYINCLUDE="-I$i" + elif test -n "$RUBYARCHHDRDIR"; then + RUBYINCLUDE="-I$i -I$RUBYARCHHDRDIR" else RUBYINCLUDE="-I$i -I$i/$RUBYARCH" fi @@ -1607,9 +1888,10 @@ if test -n "$RUBY"; then # Find library and path for linking. AC_MSG_CHECKING(for Ruby library) RUBYLIB="" + rb_archlibdir=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["archlibdir"]]') 2>/dev/null` rb_libdir=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["libdir"]]') 2>/dev/null` rb_bindir=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["bindir"]]') 2>/dev/null` - dirs="$dirs $rb_libdir $rb_bindir" + dirs="$dirs $rb_archlibdir $rb_libdir $rb_bindir" rb_libruby=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["LIBRUBY_A"]]') 2>/dev/null` RUBYLINK=`($RUBY -rrbconfig -e ' @@ -1688,10 +1970,10 @@ AC_SUBST(RUBYDYNAMICLINKING) PHPBIN= AC_ARG_WITH(php, AS_HELP_STRING([--without-php], [Disable PHP]) -AS_HELP_STRING([--with-php=path], [Set location of PHP executable]),[ PHPBIN="$withval"], [PHPBIN=yes]) +AS_HELP_STRING([--with-php=path], [Set location of PHP executable]),[ PHPBIN="$withval"], [PHPBIN="$alllang_default"]) # First, check for "--without-php" or "--with-php=no". -if test x"${PHPBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PHPBIN}" = xno; then AC_MSG_NOTICE([Disabling PHP]) PHP= else @@ -1731,88 +2013,49 @@ AC_SUBST(PHPINC) # Look for ocaml #---------------------------------------------------------------- -AC_ARG_WITH(ocaml, AS_HELP_STRING([--without-ocaml], [Disable OCaml]) -AS_HELP_STRING([--with-ocaml=path], [Set location of ocaml executable]),[ OCAMLBIN="$withval"], [OCAMLBIN=yes]) +AC_ARG_WITH(ocaml, AS_HELP_STRING([--without-ocaml], [Disable OCaml]), [with_ocaml="$withval"], [with_ocaml="$alllang_default"]) AC_ARG_WITH(ocamlc,[ --with-ocamlc=path Set location of ocamlc executable],[ OCAMLC="$withval"], [OCAMLC=]) AC_ARG_WITH(ocamldlgen,[ --with-ocamldlgen=path Set location of ocamldlgen],[ OCAMLDLGEN="$withval" ], [OCAMLDLGEN=]) AC_ARG_WITH(ocamlfind,[ --with-ocamlfind=path Set location of ocamlfind],[OCAMLFIND="$withval"],[OCAMLFIND=]) AC_ARG_WITH(ocamlmktop,[ --with-ocamlmktop=path Set location of ocamlmktop executable],[ OCAMLMKTOP="$withval"], [OCAMLMKTOP=]) +AC_ARG_WITH(camlp4,[ --with-camlp4=path Set location of camlp4 executable],[ CAMLP4="$withval"], [CAMLP4=]) # First, check for "--without-ocaml" or "--with-ocaml=no". -if test x"${OCAMLBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${with_ocaml}" = xno; then AC_MSG_NOTICE([Disabling OCaml]) - OCAMLBIN= + OCAMLC= else - AC_MSG_CHECKING(for Ocaml DL load generator) if test -z "$OCAMLDLGEN"; then - AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen, :) + AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen) fi AC_MSG_CHECKING(for Ocaml package tool) if test -z "$OCAMLFIND"; then - AC_CHECK_PROGS(OCAMLFIND, ocamlfind, :) + AC_CHECK_PROGS(OCAMLFIND, ocamlfind) fi AC_MSG_CHECKING(for Ocaml compiler) if test -z "$OCAMLC"; then - AC_CHECK_PROGS(OCAMLC, ocamlc, :) - fi - - AC_MSG_CHECKING(for Ocaml interpreter) - if test "x$OCAMLBIN" = xyes; then - AC_CHECK_PROGS(OCAMLBIN, ocaml, :) + AC_CHECK_PROGS(OCAMLC, ocamlc) fi AC_MSG_CHECKING(for Ocaml toplevel creator) if test -z "$OCAMLMKTOP"; then - AC_CHECK_PROGS(OCAMLMKTOP, ocamlmktop, :) + AC_CHECK_PROGS(OCAMLMKTOP, ocamlmktop) fi - OCAMLLOC=loc - if test "$OCAMLC" != ":" ; then - AC_MSG_CHECKING(for Ocaml header files) - dirs="/usr/lib/ocaml/caml /usr/local/lib/ocaml/caml" - dir="`$OCAMLC -where 2>/dev/null`" - if test "$dir"; then - dirs="$dir/caml $dirs" - fi - for i in $dirs; do - if test -r $i/mlvalues.h; then - AC_MSG_RESULT($i) - OCAMLEXT="$i" - OCAMLINC="-I$OCAMLEXT" - break - fi - done - if test -z "$OCAMLINC"; then - AC_MSG_RESULT(not found) - fi - - AC_MSG_CHECKING(for Ocaml version 3.08.2 or higher) - OCAMLVER=`$OCAMLC -version | sed -e 's/.*version //g'` - AC_COMPARE_VERSION([$OCAMLVER],[3.08.2],[:],[:],[OCAMLLOC=_loc]) - AC_MSG_RESULT($OCAMLVER) + AC_MSG_CHECKING(for Ocaml Pre-Processor-Pretty-Printer) + if test -z "$CAMLP4"; then + AC_CHECK_PROGS(CAMLP4, camlp4) fi fi # Disabling ocaml -export OCAMLLOC -export OCAMLVER -export OCAMLINC -export OCAMLBIN -export OCAMLC -export OCAMLDLGEN -export OCAMLFIND -export OCAMLMKTOP - -AC_SUBST(OCAMLLOC) -AC_SUBST(OCAMLVER) -AC_SUBST(OCAMLINC) -AC_SUBST(OCAMLBIN) AC_SUBST(OCAMLC) AC_SUBST(OCAMLDLGEN) AC_SUBST(OCAMLFIND) AC_SUBST(OCAMLMKTOP) +AC_SUBST(CAMLP4) #---------------------------------------------------------------- # Look for Pike @@ -1822,10 +2065,10 @@ AC_SUBST(OCAMLMKTOP) # Priority: configure option, automatic search PIKEBIN= AC_ARG_WITH(pike, AS_HELP_STRING([--without-pike], [Disable Pike]) -AS_HELP_STRING([--with-pike=path], [Set location of Pike executable]),[PIKEBIN="$withval"], [PIKEBIN=yes]) +AS_HELP_STRING([--with-pike=path], [Set location of Pike executable]),[PIKEBIN="$withval"], [PIKEBIN="$alllang_default"]) # First, check for "--without-pike" or "--with-pike=no". -if test x"${PIKEBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${PIKEBIN}" = xno; then AC_MSG_NOTICE([Disabling Pike]) PIKEBIN= else @@ -1892,10 +2135,10 @@ CHICKENLIB= AC_ARG_WITH(chicken, AS_HELP_STRING([--without-chicken], [Disable CHICKEN]) -AS_HELP_STRING([--with-chicken=path], [Set location of CHICKEN executable]),[ CHICKENBIN="$withval"], [CHICKENBIN=yes]) +AS_HELP_STRING([--with-chicken=path], [Set location of CHICKEN executable]),[ CHICKENBIN="$withval"], [CHICKENBIN="$alllang_default"]) # First, check for "--without-chicken" or "--with-chicken=no". -if test x"${CHICKENBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${CHICKENBIN}" = xno; then AC_MSG_NOTICE([Disabling CHICKEN]) else @@ -1986,12 +2229,12 @@ AC_SUBST(CHICKENSHAREDLIB) # Look for C# #---------------------------------------------------------------- -AC_ARG_WITH(csharp, AS_HELP_STRING([--without-csharp], [Disable CSharp]), [with_csharp="$withval"], [with_csharp=yes]) +AC_ARG_WITH(csharp, AS_HELP_STRING([--without-csharp], [Disable CSharp]), [with_csharp="$withval"], [with_csharp="$alllang_default"]) AC_ARG_WITH(cil-interpreter, [ --with-cil-interpreter=path Set location of CIL interpreter for CSharp],[CSHARPBIN="$withval"], [CSHARPBIN=]) AC_ARG_WITH(csharp-compiler, [ --with-csharp-compiler=path Set location of CSharp compiler],[CSHARPCOMPILERBIN="$withval"], [CSHARPCOMPILERBIN=]) # First, check for "--without-csharp" or "--with-csharp=no". -if test x"${with_csharp}" = xno -o x"${with_alllang}" = xno ; then +if test x"${with_csharp}" = xno; then AC_MSG_NOTICE([Disabling CSharp]) CSHARPCOMPILER= else @@ -2018,8 +2261,7 @@ else CSHARPCOMPILER="$CSHARPCOMPILERBIN" fi -CSHARPPATHSEPARATOR="/" -CSHARPCYGPATH_W=echo +CSHARPCONVERTPATH="Tools/convertpath -u" if test -z "$CSHARPBIN" ; then CSHARPCILINTERPRETER="" CSHARPCILINTERPRETER_FLAGS="" @@ -2046,8 +2288,7 @@ if test -z "$CSHARPBIN" ; then CSHARPCILINTERPRETER_FLAGS="--debug" else if test "csc" = "$CSHARPCOMPILER"; then - CSHARPPATHSEPARATOR="\\\\" - CSHARPCYGPATH_W='cygpath -w' + CSHARPCONVERTPATH="Tools/convertpath -w" fi fi fi @@ -2059,8 +2300,8 @@ fi case $host in *-*-cygwin* | *-*-mingw*) if test "$GCC" = yes; then - CSHARPDYNAMICLINKING=" -mno-cygwin -mthreads -Wl,--add-stdcall-alias" - CSHARPCFLAGS="-mno-cygwin -mthreads" + CSHARPDYNAMICLINKING="$GCC_MNO_CYGWIN -mthreads -Wl,--add-stdcall-alias" + CSHARPCFLAGS="$GCC_MNO_CYGWIN -mthreads" else CSHARPDYNAMICLINKING="" CSHARPCFLAGS="" @@ -2090,11 +2331,10 @@ fi AC_SUBST(CSHARPCILINTERPRETER_FLAGS) AC_SUBST(CSHARPCILINTERPRETER) -AC_SUBST(CSHARPPATHSEPARATOR) -AC_SUBST(CSHARPCYGPATH_W) +AC_SUBST(CSHARPCONVERTPATH) AC_SUBST(CSHARPCOMPILER) AC_SUBST(CSHARPDYNAMICLINKING) -AC_SUBST(CSHARPLIBRARYPREFIX) # Is this going to be used? +AC_SUBST(CSHARPLIBRARYPREFIX) AC_SUBST(CSHARPCFLAGS) AC_SUBST(CSHARPSO) @@ -2112,14 +2352,14 @@ LUALINK= # LUABIN will be cleared if certain dependencies cannot be found AC_ARG_WITH(lua, AS_HELP_STRING([--without-lua], [Disable Lua]) -AS_HELP_STRING([--with-lua=path], [Set location of Lua executable]),[ LUABIN="$withval"], [LUABIN=yes]) +AS_HELP_STRING([--with-lua=path], [Set location of Lua executable]),[ LUABIN="$withval"], [LUABIN="$alllang_default"]) AC_ARG_WITH(luaincl,[ --with-luaincl=path Set location of Lua include directory],[ LUAINCLUDE="$withval"], [LUAINCLUDE=]) AC_ARG_WITH(lualib,[ --with-lualib=path Set location of Lua library directory],[ LUALIB="$withval"], [LUALIB=]) # First, check for "--without-lua" or "--with-lua=no". -if test x"${LUABIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${LUABIN}" = xno; then AC_MSG_NOTICE([Disabling Lua]) else @@ -2135,85 +2375,85 @@ fi # check version: we need Lua 5.x if test "$LUABIN"; then - AC_MSG_CHECKING(Lua version) - # if version 5.x - LUAV5=`$LUABIN -e 'if string.sub(_VERSION,5,5)=="5" then print "1" end'` - # if not version 5.0 - LUAV51=`$LUABIN -e 'if string.sub(_VERSION,5,7)~="5.0" then print "1" end'` - - if test -z "$LUAV5"; then - AC_MSG_WARN(Not Lua 5.x, SWIG does not support this version of Lua) - LUABIN="" - elif test -z "$LUAV51"; then - AC_MSG_RESULT(Lua 5.0.x) - else - AC_MSG_RESULT(Lua 5.1 or later) - fi + AC_MSG_CHECKING(Lua version) + # if version 5.x + LUAV5=`$LUABIN -e 'if string.sub(_VERSION,5,5)=="5" then print "1" end'` + # if not version 5.0 + LUAV51=`$LUABIN -e 'if string.sub(_VERSION,5,7)~="5.0" then print "1" end'` + + if test -z "$LUAV5"; then + AC_MSG_WARN(Not Lua 5.x, SWIG does not support this version of Lua) + LUABIN="" + elif test -z "$LUAV51"; then + AC_MSG_RESULT(Lua 5.0.x) + else + AC_MSG_RESULT(Lua 5.1 or later) + fi fi if test "$LUABIN"; then - AC_MSG_CHECKING(whether Lua dynamic loading is enabled) - # using Lua to check Lua - # lua 5.0 & 5.1 have different fn names - if test -z "$LUAV51"; then - LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=loadlib("no_such_lib","") if c~="absent" then print "1" end'` - else - LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=package.loadlib("no_such_lib","") if c~="absent" then print "1" end'` - fi + AC_MSG_CHECKING(whether Lua dynamic loading is enabled) + # using Lua to check Lua + # lua 5.0 & 5.1 have different fn names + if test -z "$LUAV51"; then + LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=loadlib("no_such_lib","") if c~="absent" then print "1" end'` + else + LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=package.loadlib("no_such_lib","") if c~="absent" then print "1" end'` + fi - if test -z "$LUADYNAMICLOADLIB"; then - AC_MSG_RESULT(no) - else - AC_MSG_RESULT(yes) - fi -fi + if test -z "$LUADYNAMICLOADLIB"; then + AC_MSG_RESULT(no) + else + AC_MSG_RESULT(yes) + fi -# look for the header files & set LUAFLAGS accordingly -# will clear LUABIN if not present -if test -n "$LUAINCLUDE"; then - AC_CHECK_FILE($LUAINCLUDE/lua.h,[LUAFLAGS="$ISYSTEM$LUAINCLUDE"],[LUABIN=]) -else - LUA_OK="1" - AC_CHECK_HEADER(lua.h,[LUAFLAGS=""],[LUA_OK=""]) - # if we didn't get it, going to have to look elsewhere (the hard way) - if test -z "$LUA_OK"; then - AC_MSG_CHECKING(for lua.h in other locations) - # note: Debian/Ubuntu seem to like /usr/include/lua5.1/lua.h - # The ordering of the include directories to search should match - # the ordering of libraries to search in the library test below. - inc=/usr/include - dirs="$inc/lua5.2 $inc/lua5.1 $inc/lua51 $inc/lua5.0 $inc/lua50 /usr/local/include" - for i in $dirs; do - #echo "$i" - if test -r $i/lua.h; then - AC_MSG_RESULT($i/lua.h) - LUAFLAGS="$ISYSTEM$i" - break + # look for the header files & set LUAFLAGS accordingly + # will clear LUABIN if not present + if test -n "$LUAINCLUDE"; then + AC_CHECK_FILE($LUAINCLUDE/lua.h,[LUAFLAGS="$ISYSTEM$LUAINCLUDE"],[LUABIN=]) + else + LUA_OK="1" + AC_CHECK_HEADER(lua.h,[LUAFLAGS=""],[LUA_OK=""]) + # if we didn't get it, going to have to look elsewhere (the hard way) + if test -z "$LUA_OK"; then + AC_MSG_CHECKING(for lua.h in other locations) + # note: Debian/Ubuntu seem to like /usr/include/lua5.1/lua.h + # The ordering of the include directories to search should match + # the ordering of libraries to search in the library test below. + inc=/usr/include + dirs="$inc/lua5.2 $inc/lua5.1 $inc/lua51 $inc/lua5.0 $inc/lua50 /usr/local/include" + for i in $dirs; do + #echo "$i" + if test -r $i/lua.h; then + AC_MSG_RESULT($i/lua.h) + LUAFLAGS="$ISYSTEM$i" + break + fi + done + if test -z "$LUAFLAGS"; then + AC_MSG_RESULT(not found) + LUABIN="" # clear the bin fi - done - if test -z "$LUAFLAGS"; then - AC_MSG_RESULT(not found) - LUABIN="" # clear the bin fi fi -fi -# look for the library files & set LUALINK accordingly -# will clear LUABIN if not present -lua_save_LIBS=$LIBS # the code seems to disrupt LIBS, so saving + # look for the library files & set LUALINK accordingly + # will clear LUABIN if not present + lua_save_LIBS=$LIBS # the code seems to disrupt LIBS, so saving -if test -n "$LUALIB"; then - AC_CHECK_FILE($LUALIB/liblua.a,[LUALINK="-L$LUALIB -llua"],[LUABIN=]) -else - AC_SEARCH_LIBS(lua_close, [lua lua5.2 lua5.1 lua51 lua5.0 lua50], [LUALINK="-l$ac_lib"],[LUABIN=]) -fi + if test -n "$LUALIB"; then + AC_CHECK_FILE($LUALIB/liblua.a,[LUALINK="-L$LUALIB -llua"],[LUABIN=]) + else + AC_SEARCH_LIBS(lua_close, [lua lua5.2 lua5.1 lua51 lua5.0 lua50], [LUALINK="-l$ac_lib"],[LUABIN=]) + fi -# adding lualib for lua 5.0 -if test -z "$LUAV51"; then # extra for lua 5.0 - LUALINK="$LUALINK -llualib" -fi + # adding lualib for lua 5.0 + if test -z "$LUAV51"; then # extra for lua 5.0 + LUALINK="$LUALINK -llualib" + fi -LIBS=$lua_save_LIBS # restore LIBS + LIBS=$lua_save_LIBS # restore LIBS +fi fi # if not disabled @@ -2229,10 +2469,10 @@ AC_SUBST(LUABIN) ALLEGROCLBIN= AC_ARG_WITH(allegrocl, AS_HELP_STRING([--without-allegrocl], [Disable Allegro CL]) -AS_HELP_STRING([--with-allegrocl=path], [Set location of Allegro CL executable (alisp)]),[ ALLEGROCLBIN="$withval"], [ALLEGROCLBIN=yes]) +AS_HELP_STRING([--with-allegrocl=path], [Set location of Allegro CL executable (alisp)]),[ ALLEGROCLBIN="$withval"], [ALLEGROCLBIN="$alllang_default"]) # First, check for "--without-allegrocl" or "--with-allegrocl=no". -if test x"${ALLEGROCLBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${ALLEGROCLBIN}" = xno; then AC_MSG_NOTICE([Disabling Allegro CL]) ALLEGROCLBIN= else @@ -2252,10 +2492,10 @@ AC_SUBST(ALLEGROCLBIN) CLISPBIN= AC_ARG_WITH(clisp, AS_HELP_STRING([--without-clisp], [Disable CLISP]) -AS_HELP_STRING([--with-clisp=path], [Set location of CLISP executable (clisp)]),[ CLISPBIN="$withval"], [CLISPBIN=yes]) +AS_HELP_STRING([--with-clisp=path], [Set location of CLISP executable (clisp)]),[ CLISPBIN="$withval"], [CLISPBIN="$alllang_default"]) # First, check for "--without-clisp" or "--with-clisp=no". -if test x"${CLISPBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${CLISPBIN}" = xno; then AC_MSG_NOTICE([Disabling CLISP]) CLISPBIN= else @@ -2275,10 +2515,10 @@ AC_SUBST(CLISPBIN) RBIN= AC_ARG_WITH(r, AS_HELP_STRING([--without-r], [Disable R]) -AS_HELP_STRING([--with-r=path], [Set location of R executable (r)]),[ RBIN="$withval"], [RBIN=yes]) +AS_HELP_STRING([--with-r=path], [Set location of R executable (r)]),[ RBIN="$withval"], [RBIN="$alllang_default"]) # First, check for "--without-r" or "--with-r=no". -if test x"${RBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${RBIN}" = xno; then AC_MSG_NOTICE([Disabling R]) RBIN= else @@ -2296,131 +2536,138 @@ AC_SUBST(RBIN) #---------------------------------------------------------------- AC_ARG_WITH(go, AS_HELP_STRING([--without-go], [Disable Go]) -AS_HELP_STRING([--with-go=path], [Set location of Go compiler]),[GOBIN="$withval"], [GOBIN=yes]) +AS_HELP_STRING([--with-go=path], [Set location of Go compiler]),[GOBIN="$withval"], [GOBIN="$alllang_default"]) -if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then +if test x"${GOBIN}" = xno; then AC_MSG_NOTICE([Disabling Go]) GO= GOC= GO1=false GO12=false GO13=false + GO15=false GOGCC=false + GCCGO= GOOPT= + GCCGOOPT= GOVERSIONOPTION= else if test "x$GOBIN" = xyes; then - AC_CHECK_PROGS(GO, go 6g 8g gccgo) + AC_CHECK_PROGS(GO, go) else GO="$GOBIN" fi GOGCC=false + GCCGO= GO1=false GO12=false GO13=false + GO15=false GOOPT= + GCCGOOPT= GOVERSIONOPTION= + if test -n "$GO" ; then - if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then - GOGCC=true - GOVERSIONOPTION=--version + GO1=true + GOVERSIONOPTION=version + go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //') + case "$go_version" in + go1 | go1.[[01234]]*) + GOC=$(sh -c "$(go env) && echo \$GOCHAR")c + ;; + *) + GOC=compile + ;; + esac + AC_MSG_CHECKING([whether go version is too old]) + case $go_version in + go1.0* | go1 ) + AC_MSG_RESULT([yes - minimum version is 1.1]) + GO= + GOOPT="-intgosize 32" + ;; + *) + AC_MSG_RESULT([no]) + case "$(go env GOARCH)" in + amd64 | arm64 | ppc64*) + GOOPT="-intgosize 64" + ;; + *) + GOOPT="-intgosize 32" + ;; + esac + ;; + esac + case $go_version in + go1.0* | go1 | go1.1*) + GOOPT="$GOOPT -use-shlib" + ;; + go1.2*) + GO12=true + ;; + go1.3* | go1.4*) + GO13=true + ;; + *) + GO15=true + ;; + esac + fi + + AC_CHECK_PROGS(GCCGO, gccgo) + + if test -n "$GCCGO" ; then + if $GCCGO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then AC_MSG_CHECKING([whether gccgo version is too old]) go_version=[`$GO $GOVERSIONOPTION | sed -n '1p' | sed -e 's/^.* \([0-9.]*\) *$/\1/' -e 's/[.]//g'`] if test "x$go_version" = x; then - AC_MSG_RESULT([could not determine gccgo version - disabling Go]) - GO= + AC_MSG_RESULT([could not determine gccgo version]) + GCCGO= elif test "$go_version" -lt 470; then AC_MSG_RESULT([yes - minimum version is 4.7.0]) - GO= + GCCGO= else - AC_MSG_RESULT([no]) + AC_MSG_RESULT([no]) if test "$go_version" -lt 480; then - GOOPT="-intgosize 32" - else - AC_CHECK_SIZEOF([void *], [4]) - if test "$ac_cv_sizeof_void_p" = "8"; then - GOOPT="-intgosize 64" - else - GOOPT="-intgosize 32" - fi + GCCGOOPT="-intgosize 32" + else + AC_CHECK_SIZEOF([void *], [4]) + if test "$ac_cv_sizeof_void_p" = "8"; then + GCCGOOPT="-intgosize 64" + else + GCCGOOPT="-intgosize 32" + fi fi fi - elif test "`echo $GO | sed -e 's|.*/||'`" = "go"; then - GO1=true - GOVERSIONOPTION=version - GOC=$(sh -c "$(go env) && echo \$GOCHAR")c - go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //') - AC_MSG_CHECKING([whether go version is too old]) - case $go_version in - go1.0* | go1 ) - AC_MSG_RESULT([yes - minimum version is 1.1]) - GO= - GOOPT="-intgosize 32" - ;; - *) - AC_MSG_RESULT([no]) - if test "$GOC" = "6c"; then - GOOPT="-intgosize 64" - else - GOOPT="-intgosize 32" - fi - ;; - esac - case $go_version in - go1.0* | go1 | go1.1*) - GOOPT="$GOOPT -use-shlib" - ;; - go1.2*) - GO12=true - ;; - *) - GO13=true - ;; - esac - else - GOC=`echo $GO | sed -e 's/g/c/'` - GOVERSIONOPTION=-V - AC_MSG_CHECKING([whether Go ($GO) version is too old]) - AC_MSG_RESULT([yes - minimum version is 1.1]) - GO= - dnl Old code retained for now in case we implement an option for it. - dnl go_version=`$GO $GOVERSIONOPTION 2>/dev/null | sed -e 's/.*version.* \([[0-9]]*\).*/\1/'` - dnl go_min_version=7077 - dnl if test "$go_version" != "" -a "$go_version" -lt $go_min_version; then - dnl AC_MSG_RESULT([yes - minimum version is $go_min_version]) - dnl GO= - dnl else - dnl AC_MSG_RESULT([no]) - dnl fi - GOOPT="-intgosize 32" - GO12=false - GO13=false fi fi fi AC_SUBST(GOGCC) +AC_SUBST(GCCGO) AC_SUBST(GO) AC_SUBST(GOC) AC_SUBST(GO1) AC_SUBST(GO12) AC_SUBST(GO13) +AC_SUBST(GO15) AC_SUBST(GOOPT) +AC_SUBST(GCCGOOPT) AC_SUBST(GOVERSIONOPTION) #---------------------------------------------------------------- # Look for D #---------------------------------------------------------------- -AC_ARG_WITH(d, AS_HELP_STRING([--without-d], [Disable D]), [with_d="$withval"], [with_d=yes]) +AC_ARG_WITH(d, AS_HELP_STRING([--without-d], [Disable D]), [with_d="$withval"], [with_d="$alllang_default"]) AC_ARG_WITH(d1-compiler, [ --with-d1-compiler=path Set location of D1/Tango compiler (DMD compatible)],[D1COMPILERBIN="$withval"], [D1COMPILERBIN=]) AC_ARG_WITH(d2-compiler, [ --with-d2-compiler=path Set location of D2 compiler (DMD compatible)],[D2COMPILERBIN="$withval"], [D2COMPILERBIN=]) # First, check for "--without-d" or "--with-d=no". -if test x"${with_d}" = xno -o x"${with_alllang}" = xno ; then +if test x"${with_d}" = xno; then AC_MSG_NOTICE([Disabling D]) D1COMPILER= D2COMPILER= @@ -2526,14 +2773,14 @@ fi AC_SUBST(SKIP_MATLAB) SKIP_PYTHON= -if (test -z "$PYINCLUDE") && - (test -z "$PY3INCLUDE") ; then +if (test -z "$PYINCLUDE" || test -z "$PYLINK") && + (test -z "$PY3INCLUDE" || test -z "$PY3LINK") ; then SKIP_PYTHON="1" fi AC_SUBST(SKIP_PYTHON) SKIP_PYTHON3= -if test -z "$PY3INCLUDE" ; then +if test -z "$PY3INCLUDE" || test -z "$PY3LINK" ; then SKIP_PYTHON3="1" fi AC_SUBST(SKIP_PYTHON3) @@ -2579,7 +2826,7 @@ AC_SUBST(SKIP_PHP) SKIP_OCAML= -if test -z "$OCAMLBIN" || test -z "$OCAMLINC" ; then +if test -z "$OCAMLC" ; then SKIP_OCAML="1" fi AC_SUBST(SKIP_OCAML) @@ -2649,6 +2896,12 @@ SKIP_UFFI= #fi AC_SUBST(SKIP_UFFI) +SKIP_SCILAB= +if test -z "$SCILAB"; then + SKIP_SCILAB="1" +fi +AC_SUBST(SKIP_SCILAB) + SKIP_GO= if test -z "$GO" ; then SKIP_GO="1" @@ -2687,15 +2940,31 @@ AC_SUBST(SKIP_ANDROID) # Miscellaneous #---------------------------------------------------------------- +ABS_SRCDIR=`(cd ${srcdir} && pwd)` + +dnl Under Cygwin, we may need native absolute path as it is used by SWIG, which +dnl may be a native, and not a Cygwin, program (this is the case when it's +dnl built using MinGW or cccl compiler in Cygwin environment). However it may, +dnl although this is probably more rare, also be built as a Cygwin program. +dnl Using "mixed" path like we do here allows the path to work in both cases. +case $host in + *-*-mingw* ) ABS_SRCDIR=`${srcdir}/Tools/convertpath -m $ABS_SRCDIR` ;; + *-*-cygwin* ) ABS_SRCDIR=`cygpath --mixed $ABS_SRCDIR` ;; +esac # Root directory -# Translate path for native Windows compilers for use with 'make check' ROOT_DIR=`pwd` case $host in -*-*-cygwin* | *-*-mingw*) +*-*-cygwin*) + # Translate path for native Windows compilers for use with 'make check' if (cygpath --mixed $ROOT_DIR) >/dev/null 2>/dev/null; then ROOT_DIR=`cygpath --mixed $ROOT_DIR` fi + ;; +esac + +case $host in +*-*-cygwin* | *-*-mingw*) # Extra files generated by some Windows compilers EXTRA_CLEAN="*.stackdump *.exp *.lib *.pdb *.ilk" ;; @@ -2709,17 +2978,34 @@ AC_SUBST(ac_aux_dir) AC_ARG_WITH(swiglibdir,[ --with-swiglibdir=DIR Put SWIG system-independent libraries into DIR.], [swig_lib="$withval"], [swig_lib="${datadir}/swig/${PACKAGE_VERSION}"]) -AC_SUBST(swig_lib) +SWIG_LIB_INSTALL=${swig_lib} +AC_SUBST(SWIG_LIB_INSTALL) AC_DEFINE_DIR(SWIG_LIB, swig_lib, [Directory for SWIG system-independent libraries]) case $build in - # Windows does not understand unix directories. Convert into a windows directory with drive letter. - *-*-mingw*) SWIG_LIB_WIN_UNIX=`cmd //c echo $SWIG_LIB | sed -e "s/[ ]*$//"`;; # This echo converts unix to mixed paths. Then zap unexpected trailing space. - *-*-cygwin*) SWIG_LIB_WIN_UNIX=`cygpath --mixed "$SWIG_LIB"`;; - *) SWIG_LIB_WIN_UNIX="";; + # Windows does not understand unix directories. Convert into a windows directory with drive letter. + *-*-mingw*) SWIG_LIB_WIN_UNIX=`${srcdir}/Tools/convertpath -m $SWIG_LIB`;; + *-*-cygwin*) SWIG_LIB_WIN_UNIX=`cygpath --mixed "$SWIG_LIB"`;; + *) SWIG_LIB_WIN_UNIX="";; esac AC_DEFINE_UNQUOTED(SWIG_LIB_WIN_UNIX, ["$SWIG_LIB_WIN_UNIX"], [Directory for SWIG system-independent libraries (Unix install on native Windows)]) +SWIG_LIB_PREINST=$ABS_SRCDIR/Lib +AC_SUBST(SWIG_LIB_PREINST) + +dnl For testing purposes, clear SWIG_LIB when building SWIG in the source +dnl directory under Windows because it is supposed to work without SWIG_LIB +dnl being set. Otherwise it always needs to be set. +SWIG_LIB_SET="env SWIG_LIB=\$(SWIG_LIB_DIR)" +if test "${srcdir}" = "."; then + AC_EGREP_CPP([yes], + [#ifdef _WIN32 + yes + #endif + ], [SWIG_LIB_SET="env SWIG_LIB="], []) +fi +AC_SUBST(SWIG_LIB_SET) + AC_CONFIG_FILES([ Makefile swig.spec @@ -2742,6 +3028,7 @@ AC_CONFIG_FILES([ Examples/test-suite/pike/Makefile Examples/test-suite/python/Makefile Examples/test-suite/ruby/Makefile + Examples/test-suite/scilab/Makefile Examples/test-suite/tcl/Makefile Examples/test-suite/lua/Makefile Examples/test-suite/allegrocl/Makefile @@ -2771,7 +3058,7 @@ AC_CONFIG_COMMANDS([Examples],[ for mkfile in `cd ${srcdir} && find Examples/ -type f -name Makefile`; do dir=`dirname ${mkfile}` d=${dir} - reldir=""; + reldir="" while test "x$d" != "x." ; do d=`dirname $d` reldir="${reldir}../" @@ -2781,6 +3068,7 @@ AC_CONFIG_COMMANDS([Examples],[ cat <${mkfile} # DO NOT EDIT: instead edit ${relsrcdir}${mkfile} # and run (cd ${reldir} && ./config.status) to regenerate +TOP_BUILDDIR_TO_TOP_SRCDIR = ${srcdir}/ SRCDIR = ${relsrcdir}${dir}/ EOF @@ -2816,6 +3104,7 @@ test -n "$SKIP_PIKE" || langs="${langs}pike " test -n "$SKIP_PYTHON" || langs="${langs}python " test -n "$SKIP_R" || langs="${langs}r " test -n "$SKIP_RUBY" || langs="${langs}ruby " +test -n "$SKIP_SCILAB" || langs="${langs}scilab " test -n "$SKIP_TCL" || langs="${langs}tcl " test -n "$SKIP_UFFI" || langs="${langs}uffi " diff --git a/preinst-swig.in b/preinst-swig.in index 384593ce1e0..ac00602bb10 100755 --- a/preinst-swig.in +++ b/preinst-swig.in @@ -1,7 +1,9 @@ #!/bin/sh -builddir=`dirname $0` -srcdir=`cd "$builddir" && cd '@srcdir@' && pwd` -SWIG_LIB=$srcdir/Lib -#SWIG_LIB=`cygpath -w $srcdir/Lib` # For native Windows version of SWIG + +# Convenience script for running SWIG before it is installed. +# Intended for ad-hoc usage and not by the test-suite or examples. + +builddir=`dirname "$0"` +SWIG_LIB='@SWIG_LIB_PREINST@' export SWIG_LIB exec "$builddir/swig" "$@"