diff --git a/.gitignore b/.gitignore index 63fe6ddc9..ce576445d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,10 @@ *.class # Editor files and various other junk -*.sw? +.*.sw? *.bak +*.log +.DS_Store # Local PCRE pcre @@ -23,6 +25,7 @@ pcre *.so *.so.* *.dylib +*.bundle # C/C++ static libraries, based on: # https://github.com/github/gitignore/blob/master/C.gitignore @@ -67,11 +70,11 @@ Examples/Makefile Examples/guile/Makefile Examples/test-suite/*/Makefile Examples/xml/Makefile -Lib/ocaml/swigp4.ml /Makefile Source/Include/stamp-h1 Source/Include/swigconfig.h Source/Makefile +Tools/javascript/Makefile .deps config.log config.status @@ -82,10 +85,14 @@ swig.spec .dirstamp CCache/ccache-swig CCache/ccache-swig.1 +CCache/web/ccache-man.html +Lib/swigwarn.swg Source/CParse/parser.c Source/CParse/parser.h Source/eswig +Source/TAGS swig +Tools/javascript/javascript # Generated documentation Doc/Manual/CCache.html @@ -103,6 +110,7 @@ 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/*/ @@ -115,11 +123,19 @@ Examples/test-suite/r/*/ Examples/test-suite/ruby/*/ Examples/test-suite/tcl/*/ Examples/test-suite/uffi/*/ +*_wrap.c +*_wrap.cxx +*-gypcopy.cxx -# SWIG generated files in examples -Examples/**/*_wrap.c -Examples/**/*_wrap.cxx -Examples/**/*_wrap.cpp +# C# generated files +*_runme.exe.mdb +*_runme.exe + +# Javascript generated files +*.gyp + +# Octave generated files +swigexample*.oct # Python generated files, based on: # https://github.com/github/gitignore/blob/master/Python.gitignore @@ -127,10 +143,6 @@ Examples/**/*_wrap.cpp */__pycache__/ /__pycache__/ -# C# generated files -*_runme.exe.mdb -*_runme.exe - # Scilab generated files builder.sce loader.sce @@ -143,3 +155,5 @@ lib*.hxx # Scratch directories Examples/scratch +# Out of source tree build directories +*build*/ diff --git a/.travis.yml b/.travis.yml index 61ed1f681..342c3cd47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,33 +7,117 @@ env: matrix: include: - compiler: gcc - env: SWIGLANG=python + env: SWIGLANG=csharp + - compiler: gcc + env: SWIGLANG=go + - compiler: gcc + env: SWIGLANG=guile + - compiler: gcc + env: SWIGLANG=java + - compiler: gcc + env: SWIGLANG=javascript ENGINE=node + - compiler: gcc + env: SWIGLANG=javascript ENGINE=jsc + - compiler: gcc + env: SWIGLANG=javascript ENGINE=v8 + - compiler: gcc + env: SWIGLANG=lua + - compiler: gcc + env: SWIGLANG=octave SWIGJOBS=-j4 + - compiler: gcc + env: SWIGLANG=perl5 + - compiler: gcc + env: SWIGLANG=php + - compiler: gcc + env: SWIGLANG=python VER=2.4 + - compiler: gcc + env: SWIGLANG=python VER=2.5 + - compiler: gcc + env: SWIGLANG=python VER=2.6 + - compiler: gcc + env: SWIGLANG=python # 2.7 + - compiler: gcc + env: SWIGLANG=python PY3=3 # 3.2 + - compiler: gcc + env: SWIGLANG=python PY3=3 VER=3.3 + - compiler: gcc + env: SWIGLANG=python PY3=3 VER=3.4 + - compiler: gcc + env: SWIGLANG=ruby + - compiler: gcc + env: SWIGLANG=tcl - compiler: gcc env: SWIGLANG=scilab SWIGJOBS=-j4 allow_failures: - # None + # None before_install: - - lsb_release -a + - 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" = "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"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi - if test "$SWIGLANG" = "scilab"; then sudo apt-get -qq install scilab; fi - if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi - - if test "$SWIGLANG" = "python" -a "$PY3"; then sudo apt-get install python3-dev; 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" + ["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" + ["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" + ) + - $CC --version + - $CXX --version script: - - ./autogen.sh && ./configure + - echo 'Configuring...' && echo -en 'travis_fold:start:script.1\\r' + - ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure $CONFIGOPTS + - echo -en 'travis_fold:end:script.1\\r' - make -s $SWIGJOBS - - if test -z "$SWIGLANG"; then make -s check-ccache; fi - - ./swig -version + - ./swig -version && ./swig -pcreversion + - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi + - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi + - 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' - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi - - if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-examples; 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 + - echo 'Cleaning...' && echo -en 'travis_fold:start:script.3\\r' + - make check-maintainer-clean && ../../configure $CONFIGOPTS + - echo -en 'travis_fold:end:script.3\\r' branches: only: - master diff --git a/ANNOUNCE b/ANNOUNCE index 90cc9ba24..58de2fe10 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 3.0.0 (in progress) *** +*** ANNOUNCE: SWIG 3.0.2 (4 Jun 2014) *** http://www.swig.org -We're pleased to announce SWIG-3.0.0, the latest SWIG release. +We're pleased to announce SWIG-3.0.2, the latest SWIG release. What is SWIG? ============= @@ -10,22 +10,22 @@ What is SWIG? 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, 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, +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. Availability ============ The release is available for download on Sourceforge at - http://prdownloads.sourceforge.net/swig/swig-3.0.0.tar.gz + http://prdownloads.sourceforge.net/swig/swig-3.0.2.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-3.0.0.zip + http://prdownloads.sourceforge.net/swig/swigwin-3.0.2.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 d8f9042fe..6cded08d4 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -14,7 +14,7 @@ NOSOFTLINKSTEST= CC=@CC@ CFLAGS=@CFLAGS@ -I. SWIG=swig -SWIG_LIB=../../Lib +SWIG_LIB=../$(srcdir)/../Lib EXEEXT=@EXEEXT@ # Use standard autoconf approach to transform executable name using --program-prefix and --program-suffix @@ -27,38 +27,40 @@ HEADERS = ccache.h mdfour.h all: $(PACKAGE_NAME)$(EXEEXT) +# Regenerate Makefile if Makefile.in or config.status have changed. +Makefile: $(srcdir)/Makefile.in ./config.status + $(SHELL) ./config.status + # Note that HTML documentation is actually generated and used from the main SWIG documentation Makefile -docs: $(PACKAGE_NAME).1 web/ccache-man.html +docs: $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/ccache-man.html $(PACKAGE_NAME)$(EXEEXT): $(OBJS) $(HEADERS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) -$(PACKAGE_NAME).1: ccache.yo - -yodl2man -o $(PACKAGE_NAME).1 ccache.yo +$(srcdir)/$(PACKAGE_NAME).1: $(srcdir)/ccache.yo + -yodl2man -o $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/ccache.yo -web/ccache-man.html: ccache.yo - yodl2html -o web/ccache-man.html ccache.yo +$(srcdir)/web/ccache-man.html: $(srcdir)/ccache.yo + yodl2html -o $(srcdir)/web/ccache-man.html $(srcdir)/ccache.yo -install: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1 +install: $(PACKAGE_NAME)$(EXEEXT) $(srcdir)/$(PACKAGE_NAME).1 @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) @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 + ${INSTALLCMD} -m 644 $(srcdir)/$(PACKAGE_NAME).1 $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1 -uninstall: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1 +uninstall: $(PACKAGE_NAME)$(EXEEXT) $(srcdir)/$(PACKAGE_NAME).1 rm -f $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT) rm -f $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1 clean: /bin/rm -f $(OBJS) *~ $(PACKAGE_NAME)$(EXEEXT) -check : test - test: test.sh - SWIG_LIB='$(SWIG_LIB)' PATH=../..:$$PATH SWIG='$(SWIG)' CC='$(CC)' NOSOFTLINKSTEST='$(NOSOFTLINKSTEST)' ./test.sh + SWIG_LIB='$(SWIG_LIB)' PATH=../..:$$PATH SWIG='$(SWIG)' CC='$(CC)' NOSOFTLINKSTEST='$(NOSOFTLINKSTEST)' $(srcdir)/test.sh check: test @@ -67,11 +69,11 @@ distclean: clean /bin/rm -rf autom4te.cache maintainer-clean: distclean - /bin/rm -f $(PACKAGE_NAME).1 web/ccache-man.html + /bin/rm -f $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/ccache-man.html + - # FIXME: To fix this, test.sh needs to be able to take ccache from the # installed prefix, not from the source dir. -installcheck: +installcheck: @echo "WARNING! This is not really \"installcheck\" yet." $(MAKE) check diff --git a/CHANGES b/CHANGES index 4cc222901..1cfedc31e 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,513 @@ 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.1 (27 May 2014) +=========================== + +2014-05-25: hfalcic + [Python] Python 3 byte string output: use errors="surrogateescape" + if available on the version of Python that's in use. This allows + obtaining the original byte string (and potentially trying a fallback + encoding) if the bytes can't be decoded as UTF-8. + + Previously, a UnicodeDecodeError would be raised with no way to treat + the data as bytes or try another codec. + +2014-05-18: vkalinin + Bug #175 - Restore %extend to work for unnamed nested structures by using a C + symbol comprising the outer structure name and unnamed variable instance name. + +2014-05-15: kwwette + Add #166 - 'make check' now works out of source. This required te examples to build + out of source. The main languages have been tested - C#, Go, Guile, Java, Javascript, + Lua, Octave, Perl, PHP, Python, Ruby and Tcl. + +2014-05-01: Oliver Buchtala + Javascript support added, see Javascript chapter in the documentation. + +2014-05-01: olly + [PHP] The generated __isset() method now returns true for read-only properties. + +2014-04-24: kwwette + [Go] Fix go ./configure parsing of gccgo --version, and + goruntime.swg typo in __GNUC_PATCHLEVEL__ (SF Bug #1298) + +2014-04-24: kwwette + Fix {python|perl5|ruby|tcl}/java examples + + In Lib/gcj/cni.i, for compatibility with newer gcj versions: + + - remove JvAllocObject() which gcj no longer defines, from gcj Changelog: + 2004-04-16 Bryce McKinlay + * gcj/cni.h (JvAllocObject): Remove these obsolete, + undocumented CNI calls. + + - change JvCreateJavaVM() argument from void* to JvVMInitArgs*, from gcj Changelog: + 2005-02-23 Thomas Fitzsimmons + PR libgcj/16923 + ... + (JvCreateJavaVM): Declare vm_args as JvVMInitArgs* rather than void*. + + *** POTENTIAL INCOMPATIBILITY *** + +2014-04-08: wsfulton + SF Bug #1366 - Remove duplicate declarations of strtoimax and strtoumax in inttypes.i + +2014-04-08: wsfulton + [Java C#] Enums which have been ignored via %ignore and are subsequently + used are handled slightly differently. Type wrapper classes are now generated + which are effectively a wrapper of an empty enum. Previously in Java uncompilable + code was generated and in C# an int was used. + +2014-04-04: wsfulton + Fix regression in 3.0.0 where legal code following an operator<< definition might + give a syntax error. SF Bug #1365. + +2014-04-03: olly + [PHP] Fix wrapping director constructors with default parameters + with a ZTS-enabled build of PHP. + +2014-04-02: olly + [PHP] Pass the ZTS context we already have to avoid needing to + call TSRMLS_FETCH, which is relatively expensive. + +2014-04-02: olly + [PHP] Pass ZTS context through to t_output_helper() so it works + with a ZTS-enabled build of PHP. Reported by Pierre Labastie in + github PR#155. + +2014-03-28: wsfulton + [Java C# D Go] Fixes for C enums used in an API and the definition of the enum + has not been parsed. For D, this fixes a segfault in SWIG. The other languages + now produce code that compiles, although the definition of the enum is needed + in order to use the enum properly from the target language. + +2014-03-23: v-for-vandal + [Lua] Fix for usage of snprintf in Lua runtime which Visual Studio does not have. + +Version 3.0.0 (16 Mar 2014) +=========================== + +2014-03-16: wsfulton + C++11 support initially developed as C++0x support by Matevz Jekovec as a Google Summer of Code + project has been further extended. The C++11 support is comprehensive, but by no means complete + or without limitations. Full details for each new feature in C++11 is covered in the + CPlusPlus11.html chapter in the documentation which is included in SWIG and also available + online at http://www.swig.org/Doc3.0/CPlusPlus11.html. + +2014-03-14: v-for-vandal + [Lua] Numerous Lua improvements: + 1. %nspace support has been added. Namespaces are mapped to tables in the module, with the same + name as the C++ namespace. + 2. Inheritance is now handled differently. Each class metatable keeps a list of class bases instead + of merging all members of all bases into the derived class. + 3. The new metatables result in differences in accessing class members. For example: + + %module example + struct Test { + enum { TEST1 = 10, TEST2 = 20 }; + static const int ICONST = 12; + }; + + Now this can be used as follows: + print(example.Test.TEST1) + print(example.Test.ICONST) + The old way was: + print(example.Test_TEST1) + print(example.Test_ICONST) + + 4. The special class metatable member ".constructor" was removed. Now SWIG generates the proxy + function by itself and assigns it directly to the class table "__call" method. + 5. eLua should also now support inheritance. + 6. 'const' subtable in eLua is considered deprecated. + + Changes in behaviour: + a. You can no longer assign to non-existing class members in classes without a __setitem__ method. + It will cause a Lua error. + b. You can no longer iterate over a module table and copy everything into the global namespace. + Actually, this was never the case, but it is now explicitly prohibited. + c. Now changing a base class will immediately affect all derived classes. + d. There might be some issues with inheritance. Although the bases iteration scheme is the same + as was used for merging base classes into derived one, some unknown issues may arise. + + The old metatable behaviour can be restored by using the -no-old-metatable-bindings option. + + *** POTENTIAL INCOMPATIBILITY *** + +2014-03-06: wsfulton + [Python] Change in default behaviour wrapping C++ bool. Only a Python True or False + will now work for C++ bool parameters. This fixes overloading bool with other types. + Python 2.3 minimum is now required for wrapping bool. + + When wrapping: + + const char* overloaded(bool value) { return "bool"; } + const char* overloaded(int value) { return "int"; } + + Previous behaviour: + >>> overloaded(False) + 'int' + >>> overloaded(True) + 'int' + >>> overloaded(0) + 'int' + + Now we get the expected behaviour: + >>> overloaded(False) + 'bool' + >>> overloaded(0) + 'int' + + The consequence is when wrapping bool in non-overloaded functions: + + const char* boolfunction(bool value) { return value ? "true" : "false"; } + + The previous behaviour was very Pythonic: + >>> boolfunction("") + 'false' + >>> boolfunction("hi") + 'true' + >>> boolfunction(12.34) + 'true' + >>> boolfunction(0) + 'false' + >>> boolfunction(1) + 'true' + + Now the new behaviour more along the lines of C++ due to stricter type checking. The + above calls result in an exception and need to be explicitly converted into a bool as + follows: + >>> boolfunction(0) + Traceback (most recent call last): + File "", line 1, in + TypeError: in method 'boolfunction', argument 1 of type 'bool' + >>> boolfunction(bool(0)) + 'false' + + The old behaviour can be resurrected by passing the -DSWIG_PYTHON_LEGACY_BOOL command line + parameter when executing SWIG. Typemaps can of course be written to customise the behaviour + for specific parameters. + + *** POTENTIAL INCOMPATIBILITY *** + +2014-03-06: wsfulton + Fix SF Bug #1363 - Problem with method overloading when some methods are added by %extend + and others are real methods and using template default parameters with smart pointers. + This is noticeable as a regression since 2.0.12 when using the default smart pointer + handling for some languages when the smart pointer wraps std::map and other STL containers. + +2014-03-02: wsfulton + [Python] SF Patch #346 from Jens Krueger. Correct exception thrown attempting to + access a non-existent C/C++ global variable on the 'cvar' object. The exception thrown + used to be a NameError. However, as this access is via a primary, an AttributeError + is more correct and so the exception thrown now is an AttributeError. Reference: + http://docs.python.org/2/reference/expressions.html#attribute-references + + *** POTENTIAL INCOMPATIBILITY *** + +2014-03-01: wsfulton + [Python] Patch #143 Fix type shown when using type() to include the module and package + name when using -builtin. + +2014-03-01: wsfulton + [Python] SF patch #347 Fix missing argument count checking with -modern. + Fixes regression introduced when builtin changes were introduced in SWIG-2.0.3. + +2014-02-21: wsfulton + [PHP] Fix warning suppression using %warnfilter for PHP reserved class names. + +2014-02-19: olly + [Lua] Add keyword warnings for Lua keywords and Basic Functions. + +2014-02-19: olly + -Wallkw now includes keywords for all languages with keyword + warnings (previously Go and R were missing). + +2014-02-19: olly + [PHP] Update the lists of PHP keywords with new ones from PHP 5.4 + and newer (and some missing ones from 5.3). Reserved PHP constants + names are now checked against enum values and constants, instead + of against function and method names. Built-in PHP function names + no longer match methods added by %extend. Functions and methods + named '__sleep', '__wakeup', 'not', 'parent', or 'virtual' are no + longer needlessly renamed. + +2014-02-15: wsfulton + Fix the %$ismember %rename predicates to also apply to members added via %extend. + + Add %$isextendmember for %rename of members added via %extend. This can be used to + distinguish between normal class/struct members and %extend members. For example + '%$ismember, %$not %$isextendmember' will now identify just class/struct members. + + *** POTENTIAL INCOMPATIBILITY *** + +2014-02-16: hfalcic + [Python] Patch #137 - fix crashes/exceptions in exception handling in Python 3.3 + +2014-02-15: wsfulton + [Java] Add support for the cdata library. + +2014-02-08: vkalinin + Nested class support added. This primarily allows SWIG to properly parse nested + classes and keep the nested class information in the parse tree. Java and C# + have utilised this information wrapping the C++ nested classes as Java/C# + nested classes. The remaining target languages ignore nested classes as in + previous versions. Help is needed by users of these remaining languages to + design how C++ nested classes can be best wrapped. Please talk to us on the + swig-devel mailing list if you think you can help. + + Previously, there was limited nested class support. Nested classes were treated + as opaque pointers. However, the "nestedworkaround" feature provided a way to + wrap a nested class as if it was a global class. This feature no longer exists + and is replaced by the new "flatnested" feature. This effectively does the same + thing with less manual code to be written. Please see the 'Nested classes' + section in the documentation in SWIGPlus.html if you were previously using this + feature. + + SWIG now parses the contents of nested classes where previously it did not. You + may find that you will need to make adjustments to your interface file as + effectively extra code is being wrapped. + + *** POTENTIAL INCOMPATIBILITY *** + +2014-02-06: gjanssens + [Guile] Patch #133. Make scm to string conversion work with non-ascii strings. + Guile 2 has a completely rewritten string implementation. SWIG made some assumptions + that are no longer valid as to the internals of guile's string representation. + +2014-01-30: wsfulton + [C#] Add new swigtype_inout.i library containing SWIGTYPE *& OUTPUT typemaps. + + Example usage wrapping: + + void f(XXX *& x) { x = new XXX(111); } + + would be: + + XXX x = null; + f(out x); + // use x + x.Dispose(); // manually clear memory or otherwise leave out and leave it to the garbage collector + +2014-01-21: ianlancetaylor + [Go] Add %go_import directive. + +2014-01-21: ianlancetaylor + [Go] Add support for Go 1.3, not yet released. + +2014-01-20: wsfulton + Director exceptions (Swig::DirectorException) now derive from std::exception + and hence provide the what() method. In Python and Ruby, this replaces the now + deprecated DirectorException::getMessage() method. + +2014-01-14: diorcety + Patch #112 - Fix symbol resolution involving scopes that have multiple levels + of typedefs - fixes some template resolutions as well as some typemap searches. + +2014-01-11: wsfulton + Fix and document the naturalvar feature override behaviour - the naturalvar + feature attached to a variable name has precedence over the naturalvar + feature attached to the variable's type. The overriding was not working + when turning the feature off on the variable's name. + + Fix so that any use of the naturalvar feature will override the global + setting. Previously when set globally by -naturalvar or %module(naturalvar=1), + use of the naturalvar feature was not always honoured. + +2014-01-06: ianlancetaylor + [Go] Fix bug that broke using directors from a thread not + created by Go. + +2013-12-24: ptomulik + [Python] SF Bug #1297 + + Resolve several issues related to python imports. + For example, it's now possible to import modules having the same module + names, but belonging in different packages. + + From the user's viewpoint, this patch gives a little bit more control on + import statements generated by SWIG. The user may choose to use relative + or absolute imports. + + Some details: + - we (still) generate import statements in the form 'import a.b.c' which + corresponds to absolute imports in python3 and (the only available) + ambiguous one in python2. + - added -relativeimport option to use explicit relative import syntax + (python3), + + The "Python Packages" section in the documentation discusses how to work + with importing packages including the new -relativeimport command line option. + +2013-12-23: vadz + [Octave, Perl, Python, R, Ruby, Tcl] Change the length of strings created from fixed-size char + buffers in C code. + + This is a potential backwards compatibility break: a "char buf[5]" containing "ho\0la" was + returned as a string of length 5 before, but is returned as a string of length 2 now. Also, + it was possible to assign a (non-NUL-terminated) string "hello" to such a buffer before but + now this fails and only "helo" can fit. + + Apply "char FIXSIZE[ANY]" typemaps to explicitly choose the old behaviour. + + *** POTENTIAL INCOMPATIBILITY *** + +2013-12-23: talby + [Perl] Add support for directors. + +2013-12-18: ianlancetaylor + [Go] Don't require that Go environment variables be set + when running examples or testsuite when using Go 1 or + later. + +2013-12-17: ianlancetaylor + [Go] Remove -longsize option (for backward compatibility, + ignore it if seen). + +2013-12-17: ianlancetaylor + [Go] Add -go-pkgpath option. + +2013-12-16: ianlancetaylor + [Go] Update for Go 1.2 release. Add support for linking + SWIG code directly into executable, rather than using a + shared library. + +2013-12-13: ianlancetaylor + [Go] Add SWIG source file name as comments in generated + files. This can be used by Go documentation tools. + +2013-12-12: jleveque + [Lua] Fix typo (wchar instead of wchar_t) which made wchar.i + for Lua useless. + +2013-12-12: vmiklos + [PHP] PHP's peculiar call-time pass-by-reference feature was + deprecated in PHP 5.3 and removed in PHP 5.4, so update the REF + typemaps in phppointers.i to specify pass-by-reference in the + function definition. Examples/php/pointer has been updated + accordingly. + +2013-12-12: olly + [PHP] The usage of $input in PHP directorout typemaps has been + changed to be consistent with other languages. The typemaps + provided by SWIG have been updated accordingly, but if you + have written your own directorout typemaps, you'll need to + update $input to &$input (or make equivalent changes). + + *** POTENTIAL INCOMPATIBILITY *** + +2013-11-27: vadz + [C#, Java, Python] Add std_auto_ptr.i defining typemaps for returning std::auto_ptr<>. + +2013-11-09: wsfulton + [C#] Apply patch #79 from Brant Kyser + - Remove using directives from the generated C# code and fully qualify the use of all .NET + framework types in order to minimize potential name collisions from input files defining + types, namespace, etc with the same name as .NET framework members. + - Globally qualify the use of .NET framework types in the System namespace + - Remove .NET 1.1 support, .NET 2 is the minimum for the C# module + + This is a potential backwards compatibility break if code has been added relying on these using + statements that used to be generated: + + using System; + using System.Runtime.InteropServices; + + The quick fix to add these back in is to add the -DSWIG2_CSHARP command line option when + executing SWIG. See CSharp.html documentation for more info. + + *** POTENTIAL INCOMPATIBILITY *** + +2013-11-05: wsfulton + [Java] Fix some corner cases for the $packagepath/$javaclassname special variable substitution. + +2013-11-05: wsfulton + [Java] Apply patch #91 from Marvin Greenberg - Add director:except feature for improved + exception handling in director methods for Java. + +2013-10-15: vadz + Allow using \l, \L, \u, \U and \E in the substitution part of %(regex:/pattern/subst/) + inside %rename to change the case of the text being replaced. + +2013-10-12: wsfulton + [CFFI] Apply #96 - superclass not lispify + +2013-10-12: wsfulton + Merge in C++11 support from the gsoc2009-matevz branch where Matevz Jekovec first + started the C++0x additions. Documentation of the C++11 features supported is in a + new Chapter of the documentation, "SWIG and C++11" in Doc/Manual/CPlusPlus11.html. + +2013-10-04: wsfulton + Fix %naturalvar not having any affect on templated classes instantiated with an + enum as the template parameter type. Problem reported by Vadim Zeitlin. + +2013-09-20: wsfulton + [Java] Fix a memory leak for the java char **STRING_ARRAY typemaps. + +Version 2.0.12 (9 Feb 2014) +=========================== + +2014-01-16: wsfulton + [PHP] Fix compilation error in ZTS mode (64 bit windows) due to incorrect placement + of TSRMLS_FETCH() in SWIG_Php_GetModule() as reported by Mark Dawson-Butterworth. + +2014-01-13: kwwette + [Octave] update support to Octave version 3.8.0 + + - Octave 3.8.0 no longer defines OCTAVE_API_VERSION_NUMBER, but 3.8.1 + will define OCTAVE_{MAJOR,MINOR,PATCH}_VERSION instead: see + http://hg.savannah.gnu.org/hgweb/octave/rev/b6b6e0dc700e + So we now use a new macro SWIG_OCTAVE_PREREQ(major,minor,patch) to + enable features requiring Octave version major.minor.patch or later. + + For Octave versions prior to 3.8.1, we reconstruct values for + OCTAVE_{MAJOR,MINOR,PATCH}_VERSION based on OCTAVE_API_VERSION_NUMBER, + extracted from Octave's ChangeLogs. An additional hack is needed to + distinguish between Octave <= 3.2.x and 3.8.0, neither of which define + OCTAVE_API_VERSION_NUMBER. + + - Octave 3.8.0 deprecates symbol_table::varref(), so remove its use + for this and future versions of Octave. + + - Octave 3.8.0 removes octave_value::is_real_nd_array(), used in + octave_swig_type::dims(). Its use is not required here, so remove it. + + - Retested against Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0. + + - Updated Octave documentation with tested Octave versions, and added a + warning against using versions <= 3.x.x, which are no longer tested. + +2013-12-22: wsfulton + C++11 support for new versions of erase and insert in the STL containers. + + The erase and insert methods in the containers use const_iterator instead + of iterator in C++11. There are times when the methods wrapped must match + the parameters exactly. Specifically when full type information for + template types is missing or SWIG fails to look up the type correctly, + for example: + + %include + typedef float Real; + %template(RealVector) std::vector; + + SWIG does not find std::vector::iterator because %template using + typedefs does not always work and so SWIG doesn't know if the type is + copyable and so uses SwigValueWrapper which does + not support conversion to another type (const_iterator). This resulted + in compilation errors when using the C++11 version of the containers. + + Closes #73 + +2013-10-17: wsfulton + [R] Fix SF #1340 - Visual Studio compile error in C++ wrappers due to #include + within extern "C" block. + +2013-10-17: wsfulton + [Python] Fix SF #1345 - Missing #include for offsetof when using -builtin. + +2013-10-12: wsfulton + [Lua] Apply #92 - missing return statements for SWIG_Lua_add_namespace_details() + and SWIG_Lua_namespace_register(). Version 2.0.11 (15 Sep 2013) ============================ @@ -201,7 +708,7 @@ Version 2.0.10 (27 May 2013) The macros are silently ignored. 2013-04-17: wsfulton - [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjuction with directors. + [C#] Pull patch #34 from BrantKyser to fix smart pointers in conjunction with directors. 2013-04-15: kwwette [Octave] Fix bugs in output of cleanup code. @@ -5206,7 +5713,7 @@ Version 1.3.29 (March 21, 2006) 6146 _std_containers.so 174 _std_containers.so.hidden - Excecution times: + Execution times: real 0m0.050s user 0m0.039s sys 0m0.005s _std_containers.so real 0m0.039s user 0m0.026s sys 0m0.007s _std_containers.so.hidden @@ -5292,7 +5799,7 @@ Version 1.3.29 (March 21, 2006) protected methods by default. In previous releases, you needed to use the 'dirprot' - option to acheive the same. + option to achieve the same. If you want, you can disable the new default behaviour, use the 'nodirprot' option: @@ -5619,7 +6126,7 @@ Version 1.3.28 (February 12, 2006) %rename("%(utitle)s",%$isfunction,%$ismember) ""; - to avoid clashings with other swig macros/directives. + to avoid clashes with other swig macros/directives. 01/14/2006: cfisavage [Ruby] @@ -9547,7 +10054,7 @@ Version 1.3.23 (November 11, 2004) - Remove the ability to share type information by using c linking. All type sharing happens through a global variable in the target language. + Remove SWIG_NOIMPORT, SWIG_RUNTIME, and related defines. - + Depreciate -runtime, -noruntime command line options + + Deprecate -runtime, -noruntime command line options + Update test-suite common.mk to correctly build multicpptest + Remove reference to precommon.swg + Update the guile_gh interface to share data by a global var instead @@ -11722,7 +12229,7 @@ Version 1.3.20 (December 17, 2003) 11/30/2003: cheetah (William Fulton) [Java] Fixed [ 766409 ] missing symbol SWIG_JavaThrowException during module load - SWIGs internal functions are all static as there is no need for different SWIG + SWIG's internal functions are all static as there is no need for different SWIG generated modules to share any code at runtime. 11/30/2003: beazley @@ -20789,9 +21296,9 @@ Version 1.3 Alpha 1 (February 11, 2000) *** POTENTIAL INCOMPATIBILITY *** 1/30/00 : loic - Conditionaly compile experimental code with --enable-experiment + Conditionally compile experimental code with --enable-experiment configure flag. - Fix .cvsignore to ignore configrue & yacc generated files + Fix .cvsignore to ignore configure & yacc generated files 1/28/00 : loic Apply automake everywhere @@ -21303,7 +21810,7 @@ Version 1.1 Patch 4 (January 4, 1998) 12/29/97: Fixed configure script and a few makefiles to support Python 1.5 12/29/97: Added 'embed15.i' library file. This file should be used to - staticly link versions of Python 1.5. To make it the default, + statically link versions of Python 1.5. To make it the default, simply copy 'swig_lib/python/embed15.i' to 'swig_lib/python/embed.i' Version 1.1 Patch 3 (November 24, 1997) diff --git a/CHANGES.current b/CHANGES.current index edd39af31..bb8bbdc41 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,13 +2,22 @@ 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.0 (in progress) -============================ +Version 3.0.2 (4 Jun 2014) +=========================== -2013-10-04: wsfulton - Fix %naturalvar not having any affect on templated classes instantiated with an - enum as the template parameter type. Problem reported by Vadim Zeitlin. +2014-06-02: v-for-vandal + [Lua] Pull request #176: + If class has no __eq implemented, then default __eq is generated. + Default __eq compares actual pointers stored inside Lua userdata. -2013-09-20: wsfulton - [Java] Fix a memory leak for the java char **STRING_ARRAY typemaps. +2014-06-02: vkalinin + Fix #183 - %extend and unnamed nested structs +2014-05-28: kwwette + Fix install failure when using an 'out of source' build using the shipped + tarball - regression introduced in swig-3.0.1. + +2014-05-24: kwwette + [Octave] Remove deprecated -global/-noglobal command-line arguments + + *** POTENTIAL INCOMPATIBILITY *** diff --git a/COPYRIGHT b/COPYRIGHT index 524797d86..4a26f5947 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -11,60 +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) + 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) - Baozeng Ding (Scilab) - Ian Lance Taylor (Go) - Vadim Zeitlin (PCRE) - Stefan Zager (szager@gmail.com) (Python) - Vincent Couvert (Scilab) - Sylvestre Ledru (Scilab) - Wolfgang Frisch (Scilab) + 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) + 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/Devel/cpp11.html b/Doc/Devel/cpp11.html new file mode 100644 index 000000000..fc35465ae --- /dev/null +++ b/Doc/Devel/cpp11.html @@ -0,0 +1,788 @@ + + + + + + + + + + + + + + + +

C++0x/C++11 support for SWIG

+

Summary

+

This is a technical overview of the C++0x/C++11 support for the Swig. +This area of Swig is a work in progress. Initial C++0x/C++11 support for +Swig was written during the Google Summer of Code 2009 period by +Matevž Jekovec.

+

SVN branch

+

branches/gsoc2009-matevz

+

New C++11 features status

+

Wikipedia article: http://en.wikipedia.org/wiki/C%2B%2B0x +

+

Rvalue reference and move semantics [done]

+

The Rvalues are used in practice to speed up the move operations +on different containers.

+

In the following example, we want to swap the given elements:

+
template <class T> swap(T& a, T& b) {
+    T tmp(a);   // now we have two copies of a
+    a = b;      // now we have two copies of b
+    b = tmp;    // now we have two copies of tmp (aka a)
+}

+This can now be solved using the new function std::move():

+
template <class T> swap(T& a, T& b) {
+    T tmp(std::move(a));
+    a = std::move(b);   
+    b = std::move(tmp);
+}

+For the move function to take effect, user needs to reimplement the +move constructor (taking ClassType&& as an argument) and +operator=(ClassType&&):

+
class MyClass {
+  MyClass(MyClass&& p) : ptr(p.ptr) {p.ptr = 0;}
+  MyClass& operator=(MyClass&& p) {
+    std::swap(ptr, p.ptr);
+    return *this;
+  }
+};

+In practice, the Rvalues are used for temporaries (when passing the +result of one function as an argument to another).

+

Done: Added type&& to Swig parser. Added testcase +cpp11_rvalue_reference.i. Operator && is treated the same as +operator &. R11450

+

Article: +http://www.artima.com/cppsource/rvalue.html

+

Generalized constant expressions [done]

+

In C++11 you can define functions as constant expressions. +Functions need to return constant value in form "return expr", +where expr is a constant expression. +

+

A keyword "constexpr" is introduced for this. eg.: +constexpr int getNumber() { return 5; } const int MY_CONSTANT = +getNumber(); +

+

Constants are treated as normal variables in interpreted languages +because they are not compiled into the executable. Java "final" +constants are defined runtime as well. C++ constants need to be +declared in the header file and defined in the implementation file, +so swig doesn't need to know about the constant values when parsing +the header file. +

+

Done: Added the “constexpr “ keyword to Swig. Added testcase +cpp11_constexpr. R11322

+

Problem: No compilers were known to support constexpr yet, so the +testcase was temporarily commented out in common.mk. +

+

Extern template [done]

+

Extern template forces the GCC compiler to not instantiate the +template in the translation unit at that time. It's a feature +specifically aimed at compilers to speed up the compilation process. +

+

Done: Added support for 'extern template class +std::vector<MyClass>;'. Added testcase cpp11_template_explicit. +R11385 , R11386

+

Initializer lists [done]

+

Initializer list is a new type in standard library: +std::initializer_list<T>. New symbols {} are introduced for the +initializer lists. +

+

One can now use: +

+
 class A {
+ public:
+   A( std::initializer_list<int> );
+ };
+ A a1 = {1,2,3,4};

+Languages like Java, C# and Python already support direct creation of +lists natively.

+

Problem: initializer_list cannot be treated as an ordinary list. +The constructor containing initializer_list can only be accessed by +assigning the value using the {} brackets. I also don't think there +is a simple way to convert an ordinary list or a vector to the +initializer_list.

+

Done: Ignored the constructor having initializer_list as its +argument. Show warning to the user. Added testcase +cpp11_initializer_list. R11450

+

Article: +http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1919.pdf

+

Uniform initialization [done]

+

The new C++11 standard will allow the following:

+
struct IdString {
+  std::string name;
+  int identifier;
+};
+ 
+IdString GetString() {
+  return {"SomeName", 4}; //Note the lack of explicit type.
+}

+The feature works exactly as it did now for POD types only (eg. int +a[] = {1,2,3};). The following declarations are the same in the new +C++11:

+
IdString str1 = {„SomeName“, 4};
+IdString str2{„SomeName“, 4};

+The new way of using uniform initialization allows the following:

+
struct BasicStruct {
+ int x;
+ double y;
+};
+ 
+struct AltStruct {
+  AltStruct(int x, double y) : x_{x}, y_{y} {}
+ 
+private:
+  int x_;
+  double y_;
+};
+ 
+BasicStruct var1{5, 3.2}; // only fills the struct components
+AltStruct var2{2, 4.3};   // calls the constructor

+The new syntax is specific to C++. Java, C# and scripting languages +do not support this behaviour, but always need constructors. They +support {} brackets for declaration of arrays as C does + they add +support for creation of arrays on-the-fly (what C++11 introduced with +this feature and more).

+

Done: Added syntax for {} member initialization in class +constructor. Added testcase cpp11_uniform_initialization. R11413

+

Type inference [partially done]

+

A new keyword 'auto' is introduced in C++11:

+
auto a1 = 100;
+auto a2 = myFunc();

+The type of a1 and a2 is automatically determined according to the +initialization value during the semantic phase of the compiler.

+

Another macro 'decltype()' is introduced. The macro takes the +concrete object as an argument and returns its type. User could use +this as:

+
int i = 100;
+decltype(i) j = 200; // decltype(i) = int

+Calling operators are allowed as well:

+
decltype(i+j) k = 300;

+Done: Added support for decltype() syntax. Test cases for normal +decltype members and alternate function members work fine. Currently +only syntax in form decltype(variable name) work. No support for +custom expresions eg. decltype(i+j) yet. R11525

+

TODO: William proposed to support the hidden variables as well +(ones not parsed by Swig and added to symbol table). This also allows +Swig to parse custom expressions like decltype(i+j). The idea is to +introduce a new SwigType for this.

+

Range-based for-loop [ignored]

+

This feature is always present inside the implementation block +only. +

+

Lambda functions and expressions [done]

+

C++11 introduces lambda functions defined as:

+
[](int x, int y) -> int { return x + y; }

+If the lambda function contains a single return statement only or the +function doesn't return any type, the return type '->' can be +omitted. Lambda functions are function objects.

+

The following example prints the number of items stored in a list:

+
std::vector<int> someList;
+int total = 0;
+std::for_each( someList.begin(), someList.end(), [&total](int x) {total += x} );
+std::cout << total;

+Parameters inside the [] are the visible parameters of the lambda +functions. These can be & (references), = (copies), variable name +(variable copy), &variable name (variable reference) or this +(copy of the current object).

+

Lambda functions can be stored using:

+
auto myLambdaFunc = [this]() { this->SomePrivateMemberFunction() };

+Proposal: Lambda functions are most commonly used inside the function +block to quickly define how the sort, find and similar functions +should work (the other way would be overriding a class – the Java +style). The latest GCC does not support lambda functions yet so it is +difficult to test the feature once implemented. I would implement the +syntax support for this feature, but produce no wrapper code. Lambda +functions still work inside the function block though.

+

Article: +http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2550.pdf

+

Done: Added syntax support for the lambda functions. Added +testcase cpp11_lambda_functions.i. R11491, R11492

+

Alternate function syntax [done]

+

The problem with decltype() is that the parameters need to be +defined before the decltype. The following syntax is not valid, +because lhs and rhs hasn't been defined at the time of decltype:

+
template< typename LHS, typename RHS> 
+  decltype(lhs+rhs) AddingFunc(const LHS &lhs, const RHS &rhs) {return lhs + rhs;} //Not legal C++11

+The solution C++11 offers is the combination of the 'auto' keyword +before and '-> rettype' after the function declaration:

+
template< typename LHS, typename RHS> 
+  auto AddingFunc(const LHS &lhs, const RHS &rhs) -> decltype(lhs+rhs) {return lhs + rhs;}

+The new syntax only makes the job for the C++ compilers easier when +parsing such functions. The new syntax can be used for ordinary +functions as well:

+
struct SomeStruct {
+  auto FuncName(int x, int y) -> int;
+};
+ 
+auto SomeStruct::FuncName(int x, int y) -> int {
+  return x + y;
+}

+Done: Added support for the 'auto' return type. Added support for the +'-> type' after the funtion declaration. Added testcases +cpp11_alternate_function_syntax.i and +cpp11_alternate_function_syntax_runme.py. R11414

+

Concepts, Axioms [ignored]

+

In C++ there is a common problem when you use a template in the +class which doesn't support all the operations the functions in the +class actually do on the type. Compiler errors are usually very long +and unreadable. C++11 adds support for the "concepts". The +idea is to define what operations and attributes should the template +have. In contrast to class inheritance and polimorphism, all lookups +are done in compile-time. +

+

Basic syntax (note LessThanComparable? +instead of "class" or "typename"): +

+
 template<LessThanComparable? T>
+ const T& min(const T &x, const T &y) {
+   return y < x ? y : x;
+ }

+Extended syntax (requires conditions are separated with &&, +|| or !): +

+
 template< typename T> requires LessThanComparable?<T>
+ const T& min(const T &x, const T &y) {
+   return y < x ? y : x;
+ }

+Definition of the concepts: +

+
 concept LessThanComparable?< typename T > {
+   bool operator<(T,T);
+   requires GreaterThanComparable?<T>;
+   typename value_type;
+   typename reference;
+ };

+Concept maps allow usage of a specific type: +

+
 template< typename T>
+ concept_map InputIterator?<T*> {
+   typedef T value_type ;
+   typedef T& reference ;
+   typedef T* pointer ;
+   typedef std::ptrdiff_t difference_type ;
+ };

+Concept maps can act as mini-types, with function definitions and +other constructs commonly associated with classes: +

+
 concept Stack< typename X> {
+   typename value_type;
+   void push(X&, const value_type&);
+   void pop(X&);
+   value_type top(const X&);
+   bool empty(const X&);
+ };
+ template< typename T>
+ concept_map Stack<std::vector<T> > {
+   typedef T value_type;
+   void push(std::vector<T>& v, const T& x) { v.push_back(x); }
+   void pop(std::vector<T>& v) { v.pop_back(); }
+   T top(const std::vector<T>& v) { return v.back(); }
+   bool empty(const std::vector<T>& v) { return v.empty(); }
+ };

+Axioms are a facility pertaining to concepts supplied by C++11 to +express the semantic properties of concepts. For example, the concept +Semigroup can be defined with an axiom Associativity as: +

+
 concept Semigroup< typename Op, typename T> : CopyConstructible?<T> {
+   T operator()(Op, T, T);
+   axiom Associativity(Op op, T x, T y, T z) {
+     op(x, op(y, z)) == op(op(x, y), z);
+   }
+ };

+Axioms are more like hints to the compiler to speed-up the process of +compilation. +

+

Ignored: Concepts and axioms were removed from the C++11 standard. +

+

Object construction improvement [done]

+

This feature allows classes constructors to call other +constructors with different arguments (similar to Java and C# +behaviour). +

+

The syntax is as follows: +

+
 class SomeType {
+  int number;
+ public:
+   SomeType(int newNumber) : number(newNumber) {}
+   SomeType() : SomeType(42) {}
+ };

+Also when using the inheritance, the feature introduces inheritance +of all superclass constructors without being defined separately in +the inherited class: +

+
 class BaseClass {
+ public:
+   BaseClass(int iValue);
+ };
+ class DerivedClass: public BaseClass {
+   public:
+   using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
+ };

+Swig already correctly parses and produces the correct wrapper for +the “using” keyword.

+

Done: Added testcase cpp11_constructors.i which covers both +constructor delegation and constructor inheritance. R11532

+

Problem: Constructor delegation and constructor inheritance is not +supported by any compiler yet, so it's impossible to try and test +this feature.

+

Null pointer constant [done]

+

nullptr is part of the standard library. +

+

It's defined as typedef decltype(nullptr) nullptr_t; +

+

nullptr_t is defined in <cstddef>. +

+

As far as the C++ is compatible with 0 as the pointer value, swig +values will work for the C++. And the other way around, nullptr +behaves as the ordinary pointer (false, if empty, true, if not +empty), so it's ok for swig to compare it.

+

Done: Written a testcase cpp11_null_pointer_constant.i and +cpp11_null_pointer_constant_runme.py to prove the nullptr +functionality. R11484

+

Strongly typed enumerations [partially done]

+

C++11 introduces a new syntax for strongly typed enum declaration: +

+
 enum class Enumeration {
+  Val1,
+  Val2,
+  Val3 = 100,
+  Val4 /* = 101 */
+ };

+Typing if (Val4 == 101) will result in compilation error. +

+

The enum itself can now be explicitely of type int, long, unsigned +int etc.: +

+
 enum class Enum2 : unsigned int {Val1, Val2};

+And it can be forward declared as well: +

+
 enum Enum1;                   //Illegal in C++ and C++11; no size is explicitly specified.
+ enum Enum2 : unsigned int;    //Legal in C++11.
+ enum class Enum3;             //Legal in C++11, because enum class declarations have a default type of "int".
+ enum class Enum4: unsigned int; //Legal C++11.
+ enum Enum2 : unsigned short;  //Illegal in C++11, because Enum2 was previously declared with a different type.

+Done: Added syntax 'enum class Name' and forward declarators 'enum +Name : inherited type' or 'enum class Name : inherited type' in +R11449.

+

TODO: Add semantic support for enum elements not clashing with +enum elements in other enum classes. See cpp11_strongly_typed_enums.i +warnings.

+

Problem: Swig currently doesn't support nested classes. This +feature should be implemented using a new nested class when using +“enum class” with a single anonymous “enum {elements}” +element inside. For example:

+
class A { enum class EA { a,b,c,d }; };

+should be mapped to

+
class A { class EA { enum {a,b,c,d}; }; };

+Angle bracket [done]

+

Support for right angled brackets was implemented using the +following article as a base: +http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html +

+

Done: Added support for angle brackets. Used the preferred +"Approach 1". Added a testcase named +cpp11_template_double_brackets. R11245

+

Explicit conversion operators [done]

+

This is used when converting one type to another (eg. if +(myObject) {}, where myObject is your custom class converted to +bool). +

+

Requires both operator and function overloading which is not +supported in any target language (eg. python, php). +

+

Done: Swig already supports the keyword "explicit" for +function types as well. Added test case +cpp11_explicit_conversion_operators. R11323

+

Template typedefs [partially done]

+

The new C++11 will allow creation of wrapper around the template. +For example, if we want to do this:

+
template< typename first, typename second, int third>
+class SomeType;
+ 
+template< typename second>
+typedef SomeType<OtherType, second, 5> TypedefName; //Illegal in C++

+This is still illegal! But we can now use the new syntax for +achieving the same effect:

+
template< typename first, typename second, int third>
+class SomeType;
+
+template< typename second>
+using TypedefName = SomeType<OtherType, second, 5>;

+Here we created a new wrapper TypedefName taking one template +argument <second> which creates a type SomeType<OtherType, +second, 5>. OtherType and 5 are predefined here and hidden from +the user – the user only uses TypedefName type.

+

The same goes for the following example:

+
typedef void (*PFD)(double);            // Old style
+using PF = void (*)(double);            // New introduced syntax

+Swig supports parsing typedefs for templates as well for example:

+
typedef List<int> intList;

+Done: Expanded support for the new 'using' syntax and template +aliasing. Added testcase cpp11_template_typedefs. R11533

+

TODO: Make Swig aware of the newly defined typedef. The TYPEDEF +keyword is part of the storage_class rule and type+declarator (see +c_decl rule) is the right part of the definition – for example void +(*PFD)(double) cannot be transformed to void *(double) easily. To +fully support the new 'using' form, we'll probably have to change the +type, type_right rules and declarator, direct_declarator, +notso_direct_declarator etc., which is PITA.

+

Unrestricted unions [done]

+

C++ currently offers usage of unions for types with trivial +constructors only. The new C++11 standard allows usage of types with +non-trivial constructors as well:

+
 struct point {
+  point() {}
+  point(int x, int y): x_(x), y_(y) {}
+  int x_, y_;
+ };
+ union P {
+  int z;
+  double w;
+  point p;  // Illegal in C++; point has a non-trivial constructor.  However, this is legal in C++11.
+ } p1;

+Swig already parses the given syntax.

+

Done: Added testcase cpp11_unrestricted_unions. R11435, R11447

+

Problem: GCC doesn't support unrestricted unions yet so there is +no way to actually test, if it works.

+

Variadic templates [partially done]

+

The new C++11 offers the following syntax:

+
template<typename... Values> class tuple;

+This can be used for example:

+
class tuple<int, std::vector<int>, std::map<std::string, std::vector<int>>> someInstanceName;

+The ... is used in two cases. One is in the template header where it +marks on the left the keywords 'typename' or 'class' and a type name +on the right. The second case is usually in the function block to +decompose typename on the left of the ... . For example:

+
void printf(const char *s) {
+  while (*s) {
+    if (*s == '%' && *(++s) != '%')
+      throw std::runtime_error("invalid format string: missing arguments");
+    std::cout << *s++;
+  }
+}
+ 
+template<typename T, typename... Args>
+void printf(const char* s, T value, Args... args) { // recursive action – split previous args to value + args
+  while (*s) {
+    if (*s == '%' && *(++s) != '%') {
+      std::cout << value;
+      printf(*s ? ++s : s, args...); // call even when *s == 0 to detect extra arguments
+      return;
+    }
+    std::cout << *s++;
+  }
+  throw std::logic_error("extra arguments provided to printf");
+}

+The tricky part is that variadic templates can unpack actually +anywhere – including the class inheritance :(

+
template <typename... BaseClasses> class ClassName : public BaseClasses... {
+public:
+ 
+   ClassName (BaseClasses&&... baseClasses) : BaseClasses(baseClasses)... {}
+}

+A new extension to sizeof is also introduced with this feature. The +... after sizeof returns number of arguments:

+
template<typename ...Args> struct SomeStruct {
+  static const int size = sizeof...(Args);
+}
+// SomeStruct<Type1, Type2>::size is 2 and SomeStruct<>::size is 0

+Done: Added syntax support for 'typename' or 'class' + ... + id. +Added testcase cpp11_variadic_templates. R11458

+

Done: Added syntax support for BaseClass + ..., type + ... + id in +parameters and baseclass + ... for intializers after constructor. +Extended Swig syntax to support sizeof...(Args). R11467

+

Done: Fixed %template to support variadic number of templates.

+

TODO: Only (if present) first variadically defined argument is +currently used in %template directive. The next ones are ignored.

+

New string literals [partially done]

+

Beside the implementation, the new C++11 Unicode and custom +delimeter constants can occur in templates in the header file. +

+

Done: Added symbols 'u', 'u8' and 'U' to mark the beginning of the +UTF string. Also added test case cpp11_raw_string_literals. R11327

+

Done: Added R"DELIMITER[, ]DELIMITER" for a custom +delimiter for the beginning/end of the string. R11328

+

TODO: Fix the Swig's C++ preprocessor bug when parsing an odd +number of “ inside the string brackets. See +Source/Preprocessor/cpp.c.

+

User-defined literals [partially done]

+

C++ has different suffix literals. eg. 12.5f marks the number 12.5 +as float. +

+

C++11 allows user to define his own suffix for the strings always +starting with the underscore (_). eg. int a = "hello"_mySuffix; +

+

The syntax is similar to other operator overloading functions: +

+
 OutputType operator "" _mySuffix(const char * string_values);

+The null terminated const char* is the string between the "". +The _mySuffix is the name of the suffix operator. And the OutputType +is the outputType the operator returns. +

+

Other forms are: +

+
 OutputType operator "" _mySuffix(const char * string_values, size_t num_chars);
+ OutputType operator "" _mySuffix(const wchar_t * string_values, size_t num_chars);
+ OutputType operator "" _mySuffix(const char16_t * string_values, size_t num_chars);
+ OutputType operator "" _mySuffix(const char32_t * string_values, size_t num_chars);
+ OutputType operator "" _mySuffix(int value); /* cooked version - ie. atoi() of string */

+Another possibility is to use variadic templates: +

+
 template<char...> OutputType operator "" _mySuffix();
+ OutputType someVariable = "1234"_mySuffix;

+This instantiates the literal processing function as +operator""_Suffix<'1', '2', '3', '4'>. In this form, +there is no terminating null character to the string. The main +purpose to doing this is to use C++11's constexpr keyword and the +compiler to allow the literal to be transformed entirely at compile +time, assuming OutputType is a constexpr-constructable and copyable +type, and the literal processing function is a constexpr function.

+

Article: +http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf

+

Done: Added syntax support for userdefined literals. Added +testcase cpp11_userdefined_literals.i. R11494

+

TODO: %rename doesn't parse operator”” yet.

+

Thread-local storage [done] +

+

New C++11 introduces keyword "thread_local" which marks +the following variable dynamically located depending on the current +thread when using the address-of (&) operator. +

+

Syntax: +

+
 struct A {
+   thread_local int val;
+ };

+Done: Add "thread_local" keyword to Swig. Added testcase +cpp11_thread_local. R11393

+

Defaulting/deleting of standard functions on C++ objects [done]

+

C++ automatically creates default constructor with empty +parameters, copy constructor, operator= and destructor for any class. +Sometimes user wants to explicitly remove one of them or enable them +(eg. default constructor with empty parameters doesn't work any more, +if any other constructor is defined). +

+

Words "default" and "delete" are introduced. +The syntax is similar to declaration of pure virtual function: +

+
 struct NonCopyable {
+   NonCopyable & operator=(const NonCopyable&) = delete; /* Removes operator= */
+   NonCopyable(const NonCopyable&) = delete; /* Removed copy constructor */
+   NonCopyable() = default; /* Explicitly allows the empty constructor */
+   void *operator new(std::size_t) = delete; /* Removes new NonCopyable */
+ };

+User has the ability by using keyword delete to disallow calling of +the standard functions brought by C++ itself. +

+
 struct A1 {
+   void f(int i);
+   void f(double i) = delete;  /* Don't cast double to int. Compiler returns an error */
+ };
+ struct A2 {
+   void f(int i);
+   template<class T> void f(T) = delete; /* Only accept int */
+ };

+Ignored: Swig already parses the keywords "= delete" and "= +default". These keywords are used for built-in functions (copy +constructor, operator= etc.), which are ignored by Swig anyway.

+

Done: Added testcase cpp11_default_delete. R11535

+

Type long long int [done]

+

Type long long int is an integer type that has at least 64 useful +bits. C99 added it to its standard, but the C++ didn't adopt it until +C++11. Most C++ compilers supported it though. +

+

Done: Swig already parses the C code including the long long type. +

+

Static assertions [done]

+

static_assert() can be used at class scope as well eg.: +

+
 template <typename T>
+ struct Check {
+  static_assert(sizeof(int) <= sizeof(T), "not big enough");
+ };

+Done: Added syntax support for "static_assert()". Added +test case cpp11_static_assert. R11369

+

Allow sizeof to work on members of classes without an explicit +object [done]

+

C++11 allows calls of sizeof to concrete objects as well: +

+
 struct A { int member; };
+ sizeof(A::member); //Does not work with C++03. Okay with C++11

+This kind of syntax is already supported by Swig.

+

Done: Added testcase cpp11_sizeof_objects. R11538 +

+

Threading facilities [ignored]

+

C++11 will add the following classes to the standard library: +

+
 * std::thread
+ * std::mutex, std::recursive_mutex
+ * std::condition_variable, std::condition_variable_any
+ * std::lock_guard, std::unique_lock
+ * std::packaged_task

+Ignored: No changes to the language itself is made. +

+

Tuple types [TODO]

+

Tuple is array of various types. C++11 introduced this feature +using variadic templates. Tuple is defined as:

+
template <class ...Types> class tuple;

+Constructor is automatically generated filling the tuple elements. +get<X> function is introduced to get the Xth element in the +tuple.

+
typedef tuple< int, double, long &, const char * > test_tuple ;
+long lengthy = 12 ;
+test_tuple proof( 18, 6.5, lengthy, "Ciao!" ) ;
+lengthy = get<0>(proof) ;  // Assign to 'lengthy' the value 18.
+get<3>(proof) = " Beautiful!" ;  // Modify the tuple’s fourth element.

+Tuples can be copied to each other, if all the elements are copiable:

+
typedef tuple< int , double, string       > tuple_1 t1 ;
+typedef tuple< char, short , const char * > tuple_2 t2( 'X', 2, "Hola!" ) ;
+t1 = t2 ;  // Ok, first two elements can be converted,
+           // the third one can be constructed from a 'const char *'.

+TODO: Implement wrappers for the tuplet<> class.

+

Hash tables [TODO]

+

C++11 introduces the "unordered" version of existing +types, which in practice work faster than the linear types: +

+
 - unordered set
+ - unordered multiset
+ - unordered map
+ - unordered multimap

+Swig should use the "unordered" types exactly the same as +the original linear types.

+

Problem: Unordered types do not contain exactly same members as +ordered ones (eg. _Hashtable_iterator does not offer operator--() and +constructor with compare function which is required). So simply +aliasing unordered classes to ordered ones doesn't work.

+

TODO: Implement wrappers for unordered_ types. Initial work is +already done in Lib/std/unordered_*.i files.

+

Regular expressions [ignored]

+

Two new classes are introduced in C++11: basic_regex and +match_results. Both are defined in regex header file. +

+

Ignored: The new feature extends the standardy library only. No +changes to Swig needed. +

+

General-purpose smart pointers [done]

+

This feature deprecates auto_ptr and adds shared_ptr, weak_ptr and +unique_ptr to the standard library. +

+

This feature only adds the smart pointers to the standard library +and doesn't effect the C++ syntax.

+

Done: Added test case which uses all three smart pointers in the +class. R11394

+

Problem: GCC standard library doesn't contain the new smart +pointers yet. +

+

Extensible random number facility [ignored]

+

This feature standardize the pseudo random number algorithm +(currently, the random number generator was dependent on the +platform/compiler). It adds functions linear_congruential, +subtract_with_carry and mersenne_twister and symbols +uniform_int_distribution, bernoulli_distribution, +geometric_distribution, poisson_distribution, binomial_distribution, +uniform_real_distribution, exponential_distribution, +normal_distribution and gamma_distribution to the standard library. +

+

Ignored: The new feature extends the standardy library only. No +changes to Swig needed. +

+

Wrapper reference [ignored]

+

This feature adds ref and cref classes to the standard library +(#include <utility>) usually used in tempalte functions. +

+

Ignored: The new feature extends the standardy library only. No +changes to Swig needed. +

+

Polymorphous wrappers for function objects [done]

+

Two features are introduced: +

+
    +
  • The function template wrapper: +

    +
+
 function<int ( int, int )> pF;
+
    +
  • and the function object: +

    +
+
 struct Test {
+   bool operator()( short x, short y );
+ };

+Swig already supports the two.

+

Done: Added a runtime testcase for function objects +cpp11_function_objects. R11419.

+

Type traits for metaprogramming [ignored]

+

C++11 adds a new header file <type_traits> which includes +helper functions to determine the template type while initializing +the object at compile time. +

+

Swig already supports the following code: +

+
 template< int B, int N >
+ struct Pow {
+  // recursive call and recombination.
+  enum{ value = B*Pow< B, N-1 >::value };
+ };
+ template< int B > struct Pow< B, 0 >  // N == 0 condition of termination.
+ {
+  enum{ value = 1 };
+ };
+ int quartic_of_three = Pow< 3, 4 >::value ;

+Functions is_convertible, is_integral, is_integral_const etc. are +part of the new header: +

+
// First way of operating.
+template< bool B > struct algorithm {
+  template< class T1, class T2 > int do_it( T1 &, T2 & )  { /*...*/ }
+};
+// Second way of operating.
+template<> struct algorithm<true> {
+  template< class T1, class T2 > int do_it( T1, T2 )  { /*...*/ }
+};
+// Instantiating 'elaborate' will automatically instantiate the correct way to operate.
+template< class T1, class T2 > int elaborate( T1 A, T2 B ) {
+  // Use the second way only if 'T1' is an integer and if 'T2' is
+  // in floating point, otherwise use the first way.
+  return algorithm< is_integral<T1>::value && is_floating_point<T2>::value >::do_it( A, B );
+}

+Swig correctly parses the syntax for template<bool>, +template<class T> and template<>. +

+

Ignored: Swig requires explicitly defined template class +(%template directive) to export it to the target language.

+

Uniform method for computing return type of function objects +[partially done]

+

The template function is introduced: std::result_of() which +depends on decltype: +

+
template< class Obj >
+class calculus_ver2 {
+ public:
+   template< class Arg >
+   typename std::result_of<Obj(Arg)>::type operator()( Arg& a ) const { 
+     return member(a);
+   }
+ private:
+   Obj member;
+};

+Swig correctly parses the result_of class.

+

TODO: The return type (the result_of::type member) is not +calculated by Swig. This needs a much more complex semantic parser.

+

Done: Added testcase cpp11_result_of. R11534

+ + diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html index 94a82519d..c9082d3f6 100644 --- a/Doc/Devel/internals.html +++ b/Doc/Devel/internals.html @@ -347,7 +347,7 @@ Delete(a); /* Destroy a */ All objects are referenced counted and given a reference count of 1 when initially created. The Delete() function only destroys an object when the reference count reaches zero. When -an object is placed in a list or hash table, it's reference count is automatically increased. For example: +an object is placed in a list or hash table, its reference count is automatically increased. For example:
@@ -844,7 +844,7 @@ Returns a type object corresponding to the type string produced by the Swig_cloc
 
  • char *Swig_clocal_deref(DataType *t, char *name)
    This function is the inverse of the clocal() function. Given a type and a name, it produces a string containing the code needed to cast/convert the type produced by -Swig_clocal() back into it's original type. +Swig_clocal() back into its original type.

  • char *Swig_clocal_assign(DataType *t, char *name)
    diff --git a/Doc/Devel/tree.html b/Doc/Devel/tree.html index db3c6fee4..73a49ed55 100644 --- a/Doc/Devel/tree.html +++ b/Doc/Devel/tree.html @@ -185,7 +185,7 @@ this function merely records that those attributes did not exist in the original
    This function is similar to Swig_save() except that adds additional attribute checking. There are different interpretations of the attribute names. A name of "attr" merely requests that the function check for the presence of an attribute. If the attribute is missing, SWIG will exit with a failed assertion. An attribute name of "?attr" specifies that the attribute "attr" is optional and -that it's old value must be saved (if any). An attribute name of "*attr" specifies that the attribute is required and that +that its old value must be saved (if any). An attribute name of "*attr" specifies that the attribute is required and that its value must be saved. The saving of attributes is performed in the same manner as with Swig_save(). Here is an example:
    diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html
    index 12b915ee2..8295bad1c 100644
    --- a/Doc/Manual/Allegrocl.html
    +++ b/Doc/Manual/Allegrocl.html
    @@ -8,7 +8,7 @@
     
     
     
    -

    17 SWIG and Allegro Common Lisp

    +

    18 SWIG and Allegro Common Lisp

      @@ -135,10 +135,10 @@ be unhappy to see some enterprising folk use this work to add to it.

      -

      17.1 Basics

      +

      18.1 Basics

      -

      17.1.1 Running SWIG

      +

      18.1.1 Running SWIG

      @@ -360,7 +360,7 @@ need to link in the Allegro shared library. The library you create from the C++ wrapper will be what you then load into Allegro CL.

      -

      17.1.2 Command Line Options

      +

      18.1.2 Command Line Options

      @@ -396,7 +396,7 @@ See Section 17.5 Identifier converter functions for more details.

      -

      17.1.3 Inserting user code into generated files

      +

      18.1.3 Inserting user code into generated files

      @@ -436,7 +436,7 @@ Note that the block %{ ... %} is effectively a shortcut for

      -

      17.2 Wrapping Overview

      +

      18.2 Wrapping Overview

      @@ -446,7 +446,7 @@ New users to SWIG are encouraged to read interested in generating an interface to C++.

      -

      17.2.1 Function Wrapping

      +

      18.2.1 Function Wrapping

      @@ -499,7 +499,7 @@ interested in generating an interface to C++.

    -

    17.2.2 Foreign Wrappers

    +

    18.2.2 Foreign Wrappers

    @@ -512,7 +512,7 @@ interested in generating an interface to C++. typemap.

    -

    17.2.3 FFI Wrappers

    +

    18.2.3 FFI Wrappers

    @@ -593,7 +593,7 @@ char *xxx(); ff:def-foreign-call's.

    -

    17.2.4 Non-overloaded Defuns

    +

    18.2.4 Non-overloaded Defuns

    @@ -606,7 +606,7 @@ char *xxx(); this function can be manipulated via the lout typemap.

    -

    17.2.5 Overloaded Defuns

    +

    18.2.5 Overloaded Defuns

    @@ -622,7 +622,7 @@ char *xxx(); can be manipulated via the lout typemap.

    -

    17.2.6 What about constant and variable access?

    +

    18.2.6 What about constant and variable access?

    @@ -635,7 +635,7 @@ char *xxx(); into the foreign module.

    -

    17.2.7 Object Wrapping

    +

    18.2.7 Object Wrapping

    @@ -657,7 +657,7 @@ char *xxx(); foreign function interface.

    -

    17.3 Wrapping Details

    +

    18.3 Wrapping Details

    @@ -665,7 +665,7 @@ char *xxx(); translated into lisp.

    -

    17.3.1 Namespaces

    +

    18.3.1 Namespaces

    @@ -742,13 +742,13 @@ namespace car { function such as (car '(1 2 3).

    -

    17.3.2 Constants

    +

    18.3.2 Constants

    Constants, as declared by the preprocessor #define macro or SWIG - %constant directive, are included in SWIGs parse tree + %constant directive, are included in SWIG's parse tree when it can be determined that they are, or could be reduced to, a literal value. Such values are translated into defconstant forms in the generated lisp wrapper when the -nocwrap command-line @@ -803,7 +803,7 @@ namespace car { not use the -nocwrap command-line option.

    -

    17.3.3 Variables

    +

    18.3.3 Variables

    @@ -881,13 +881,13 @@ globalvar> (globalvar.nnn::glob_float)

  • -

    17.3.4 Enumerations

    +

    18.3.4 Enumerations

    In C, an enumeration value is an integer value, while in C++ an enumeration value is implicitly convertible to an integer value, - but can also be distinguished by it's enum type. For each enum + but can also be distinguished by its enum type. For each enum declaration a def-foreign-type is generated, assigning the enum a default type of :int. Users may adjust the foreign type of enums via SWIG typemaps. @@ -901,7 +901,7 @@ globalvar> (globalvar.nnn::glob_float) of it not being necessary to probe into foreign space to retrieve enum values. When generating a .cxx wrapper file, a more general solution is employed. A wrapper variable is created in the module_wrap.cxx file, and - a ff:def-foreign-variable call is generated to retrieve it's value into lisp. + a ff:def-foreign-variable call is generated to retrieve its value into lisp.

    For example, the following header file @@ -957,7 +957,7 @@ EXPORT const int ACL_ENUM___FOO3__SWIG_0 = FOO3; -

    17.3.5 Arrays

    +

    18.3.5 Arrays

    @@ -1105,10 +1105,10 @@ namespace BAR { -

    17.3.6 Classes and Structs and Unions (oh my!)

    +

    18.3.6 Classes and Structs and Unions (oh my!)

    -

    17.3.6.1 CLOS wrapping of

    +

    18.3.6.1 CLOS wrapping of

    @@ -1123,7 +1123,7 @@ namespace BAR { integer values.

    -

    17.3.6.2 CLOS Inheritance

    +

    18.3.6.2 CLOS Inheritance

    @@ -1131,12 +1131,12 @@ namespace BAR { inheritance of the classes in foreign code, with the ff:foreign-pointer class at its root. ff:foreign-pointer is a thin wrapper for pointers that is made available by the foreign function - interface. It's key benefit is that it may be passed as an argument + interface. Its key benefit is that it may be passed as an argument to any ff:def-foreign-call that is expecting a pointer as the parameter.

    -

    17.3.6.3 Member fields and functions

    +

    18.3.6.3 Member fields and functions

    @@ -1152,7 +1152,7 @@ namespace BAR { the interface does nothing for friend directives,

    -

    17.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,11 +1170,11 @@ namespace BAR { use the more robust wrapper functions.

    -

    17.3.7 Templates

    +

    18.3.7 Templates

    -

    17.3.7.1 Generating wrapper code for templates

    +

    18.3.7.1 Generating wrapper code for templates

    @@ -1187,7 +1187,7 @@ namespace BAR { directive.

    -

    17.3.7.2 Implicit Template instantiation

    +

    18.3.7.2 Implicit Template instantiation

    @@ -1197,7 +1197,7 @@ namespace BAR { class schema.

    -

    17.3.8 Typedef, Templates, and Synonym Types

    +

    18.3.8 Typedef, Templates, and Synonym Types

    @@ -1277,7 +1277,7 @@ synonym> -

    17.3.8.1 Choosing a primary type

    +

    18.3.8.1 Choosing a primary type

    @@ -1298,7 +1298,7 @@ synonym> -

    17.3.9 Function overloading/Parameter defaulting

    +

    18.3.9 Function overloading/Parameter defaulting

    @@ -1461,7 +1461,7 @@ overload> -

    17.3.10 Operator wrapping and Operator overloading

    +

    18.3.10 Operator wrapping and Operator overloading

    @@ -1607,7 +1607,7 @@ opoverload> -

    17.3.11 Varargs

    +

    18.3.11 Varargs

    @@ -1617,7 +1617,7 @@ opoverload> directive. This directive allows you to specify a (finite) argument list which will be inserted into the wrapper in place of the variable length argument indicator. As an example, - consider the function printf(). It's declaration would + consider the function printf(). Its declaration would appear as follows:

    @@ -1628,7 +1628,7 @@ opoverload> with other ways such functions can be wrapped.

    -

    17.3.12 C++ Exceptions

    +

    18.3.12 C++ Exceptions

    @@ -1640,7 +1640,7 @@ opoverload> implemented.

    -

    17.3.13 Pass by value, pass by reference

    +

    18.3.13 Pass by value, pass by reference

    @@ -1652,7 +1652,7 @@ opoverload> newly defined types.

    -

    17.4 Typemaps

    +

    18.4 Typemaps

    @@ -1663,7 +1663,7 @@ opoverload> on Typemaps for more information.

    -

    17.4.1 Code Generation in the C++ Wrapper

    +

    18.4.1 Code Generation in the C++ Wrapper

    @@ -1693,7 +1693,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -

    17.4.1.1 IN Typemap

    +

    18.4.1.1 IN Typemap

    @@ -1728,14 +1728,14 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -

    17.4.1.2 OUT Typemap

    +

    18.4.1.2 OUT Typemap

    The out typemap is used to generate code to form the return value of the wrapper from the return value of the wrapped function. This code is placed in the <convert and bind result to lresult> - section of the above code diagram. It's default mapping is as follows: + section of the above code diagram. Its default mapping is as follows:

    @@ -1752,13 +1752,13 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
    -

    17.4.1.3 CTYPE Typemap

    +

    18.4.1.3 CTYPE Typemap

    This typemap is not used for code generation, but purely for the transformation of types in the parameter list of the wrapper function. - It's primary use is to handle by-value to by-reference conversion in the + Its primary use is to handle by-value to by-reference conversion in the wrappers parameter list. Its default settings are:

    @@ -1784,7 +1784,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) these common typemaps here.

    -

    17.4.2 Code generation in Lisp wrappers

    +

    18.4.2 Code generation in Lisp wrappers

    @@ -1803,7 +1803,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) 16.3.1 Namespaces for details.

    -

    17.4.2.1 LIN Typemap

    +

    18.4.2.1 LIN Typemap

    @@ -1846,7 +1846,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -

    17.4.2.2 LOUT Typemap

    +

    18.4.2.2 LOUT Typemap

    @@ -1889,7 +1889,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -

    17.4.2.3 FFITYPE Typemap

    +

    18.4.2.3 FFITYPE Typemap

    @@ -1939,7 +1939,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -

    17.4.2.4 LISPTYPE Typemap

    +

    18.4.2.4 LISPTYPE Typemap

    @@ -1959,7 +1959,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -

    17.4.2.5 LISPCLASS Typemap

    +

    18.4.2.5 LISPCLASS Typemap

    @@ -1983,7 +1983,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -

    17.4.3 Modifying SWIG behavior using typemaps

    +

    18.4.3 Modifying SWIG behavior using typemaps

    @@ -2017,10 +2017,10 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -

    17.5 Identifier Converter functions

    +

    18.5 Identifier Converter functions

    -

    17.5.1 Creating symbols in the lisp environment

    +

    18.5.1 Creating symbols in the lisp environment

    @@ -2041,11 +2041,11 @@ return-val wrapper-name(parm0, parm1, ..., parmN) of arguments.

    -

    17.5.2 Existing identifier-converter functions

    +

    18.5.2 Existing identifier-converter functions

    Two basic identifier routines have been defined. -

    17.5.2.1 identifier-convert-null

    +

    18.5.2.1 identifier-convert-null

    @@ -2054,7 +2054,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) strings, from which a symbol will be created.

    -

    17.5.2.2 identifier-convert-lispify

    +

    18.5.2.2 identifier-convert-lispify

    @@ -2063,7 +2063,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) same symbol transformations.

    -

    17.5.2.3 Default identifier to symbol conversions

    +

    18.5.2.3 Default identifier to symbol conversions

    @@ -2072,7 +2072,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) default naming conventions.

    -

    17.5.3 Defining your own identifier-converter

    +

    18.5.3 Defining your own identifier-converter

    @@ -2093,7 +2093,7 @@ foreign environment.

    The :type keyword argument provides more information on the type of -identifier. It's value is a symbol. This allows the +identifier. Its value is a symbol. This allows the identifier-converter to apply different heuristics when mapping different types of identifiers to symbols. SWIG will generate calls to your identifier-converter using the following types. @@ -2123,12 +2123,12 @@ scope in the specified class.

    The :arity keyword argument only appears in swig:swig-defmethod forms -generated for overloaded functions. It's value is an integer +generated for overloaded functions. Its value is an integer indicating the number of arguments passed to the routine indicated by this identifier.

    -

    17.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 4d1be3944..e62139797 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -5,7 +5,7 @@ -

    18 SWIG and Android

    +

    19 SWIG and Android

      @@ -30,7 +30,7 @@ This chapter describes SWIG's support of Android. -

      18.1 Overview

      +

      19.1 Overview

      @@ -40,10 +40,10 @@ Everything in the Java chapter applies to generating cod This chapter contains a few Android specific notes and examples.

      -

      18.2 Android examples

      +

      19.2 Android examples

      -

      18.2.1 Examples introduction

      +

      19.2.1 Examples introduction

      @@ -76,7 +76,7 @@ $ android list targets The following examples are shipped with SWIG under the Examples/android directory and include a Makefile to build and install each example.

      -

      18.2.2 Simple C example

      +

      19.2.2 Simple C example

      @@ -398,7 +398,7 @@ Run the app again and this time you will see the output pictured below, showing

      Android screenshot of SwigSimple example
      -

      18.2.3 C++ class example

      +

      19.2.3 C++ class example

      @@ -435,11 +435,11 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -447,18 +447,18 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); };

    @@ -482,19 +482,19 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } @@ -746,7 +746,7 @@ Run the app to see the result of calling the C++ code from Java:
    Android screenshot of SwigClass example
    -

    18.2.4 Other examples

    +

    19.2.4 Other examples

    @@ -758,7 +758,7 @@ Note that the 'extend' example is demonstrates the directors feature. 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.

    -

    18.3 C++ STL

    +

    19.3 C++ STL

    diff --git a/Doc/Manual/Arguments.html b/Doc/Manual/Arguments.html index 1ae9a6d2f..3b7713686 100644 --- a/Doc/Manual/Arguments.html +++ b/Doc/Manual/Arguments.html @@ -6,7 +6,7 @@ -

    9 Argument Handling

    +

    10 Argument Handling

      @@ -42,7 +42,7 @@ return multiple values through the arguments of a function. This chapter describes some of the techniques for doing this.

      -

      9.1 The typemaps.i library

      +

      10.1 The typemaps.i library

      @@ -50,7 +50,7 @@ This section describes the typemaps.i library file--commonly used to change certain properties of argument conversion.

      -

      9.1.1 Introduction

      +

      10.1.1 Introduction

      @@ -194,7 +194,7 @@ else. To clear a typemap, the %clear directive should be used. For e

    -

    9.1.2 Input parameters

    +

    10.1.2 Input parameters

    @@ -247,7 +247,7 @@ When the function is used in the scripting language interpreter, it will work li result = add(3,4) -

    9.1.3 Output parameters

    +

    10.1.3 Output parameters

    @@ -314,7 +314,7 @@ iresult, dresult = foo(3.5, 2) -

    9.1.4 Input/Output parameters

    +

    10.1.4 Input/Output parameters

    @@ -379,7 +379,7 @@ rather than directly overwriting the value of the original input object. SWIG. Backwards compatibility is preserved, but deprecated.

    -

    9.1.5 Using different names

    +

    10.1.5 Using different names

    @@ -413,7 +413,7 @@ Typemap declarations are lexically scoped so a typemap takes effect from the poi file or a matching %clear declaration.

    -

    9.2 Applying constraints to input values

    +

    10.2 Applying constraints to input values

    @@ -423,7 +423,7 @@ insure that a value is positive, or that a pointer is non-NULL. This can be accomplished including the constraints.i library file.

    -

    9.2.1 Simple constraint example

    +

    10.2.1 Simple constraint example

    @@ -449,7 +449,7 @@ the arguments violate the constraint condition, a scripting language exception will be raised. As a result, it is possible to catch bad values, prevent mysterious program crashes and so on.

    -

    9.2.2 Constraint methods

    +

    10.2.2 Constraint methods

    @@ -465,7 +465,7 @@ NONNULL Non-NULL pointer (pointers only). -

    9.2.3 Applying constraints to new datatypes

    +

    10.2.3 Applying constraints to new datatypes

    diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html new file mode 100644 index 000000000..ce9174254 --- /dev/null +++ b/Doc/Manual/CPlusPlus11.html @@ -0,0 +1,1182 @@ + + + +SWIG and C++11 + + + + +

    7 SWIG and C++11

    + + + + + + +

    7.1 Introduction

    + + +

    This chapter gives you a brief overview about the SWIG +implementation of the C++11 standard. This part of SWIG is still a work in +progress. +

    +

    SWIG supports the new C++ syntax changes with some minor limitations +in some areas such as decltype expressions and variadic templates. Wrappers for the +new STL types (unordered_ containers, result_of, tuples) are incomplete. +The wrappers for the new containers would work much like the C++03 containers and +users are welcome to help by adapting the existing container interface files and submitting them +as a patch for inclusion in future versions of SWIG. +

    + +

    7.2 Core language changes

    + + +

    7.2.1 Rvalue reference and move semantics

    + + +

    +SWIG correctly parses the rvalue reference syntax '&&', +for example the typical usage of it in the move constructor and move assignment operator below: +

    + +
    +class MyClass {
    +...
    +  std::vector<int> numbers;
    +public:
    +  MyClass(MyClass &&other) : numbers(std::move(other.numbers)) {}
    +  MyClass & operator=(MyClass &&other) {
    +    numbers = std::move(other.numbers);
    +    return *this;
    +  }
    +};
    +
    + +

    +Rvalue references are designed for C++ temporaries and so are not very useful when used from non-C++ target languages. +Generally you would just ignore them via %ignore before parsing the class. +For example, ignore the move constructor: +

    + +
    +%ignore MyClass::MyClass(MyClass &&);
    +
    + +

    +The plan is to ignore move constructors by default in a future version of SWIG. Note that both normal assignment operators as well as move assignment operators are ignored by default in most target languages with the following warning: +

    + +
    +
    +example.i:18: Warning 503: Can't wrap 'operator =' unless renamed to a valid identifier.
    +
    +
    + + +

    7.2.2 Generalized constant expressions

    + + +

    SWIG parses and identifies the keyword constexpr, but cannot fully utilise it. +These C++ compile time constants are usable as runtime constants from the target languages. +Below shows example usage for assigning a C++ compile time constant from a compile time constant function: +

    + +
    +constexpr int XXX() { return 10; }
    +constexpr int YYY = XXX() + 100;
    +
    + +

    +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

    + + +

    SWIG correctly parses the keywords extern template. +However, this template instantiation suppression in a translation unit has no relevance outside of the C++ compiler and so is not used by SWIG. +SWIG only uses %template for instantiating and wrapping templates.

    + +
    +template class std::vector<int>;        // C++03 explicit instantiation in C++
    +extern template class std::vector<int>; // C++11 explicit instantiation suppression in C++
    +%template(VectorInt) std::vector<int>;  // SWIG instantiation
    +
    + +

    7.2.4 Initializer lists

    + + +

    +Initializer lists are very much a C++ compiler construct and are not very accessible from wrappers as +they are intended for compile time initialization of classes using the special std::initializer_list type. +SWIG detects usage of initializer lists and will emit a special informative warning each time one is used: +

    + +
    +
    +example.i:33: Warning 476: Initialization using std::initializer_list.
    +
    +
    + +

    +Initializer lists usually appear in constructors but can appear in any function or method. +They often appear in constructors which are overloaded with alternative approaches to initializing a class, +such as the std container's push_back method for adding elements to a container. +The recommended approach then is to simply ignore the initializer-list constructor, for example: +

    + +
    +%ignore Container::Container(std::initializer_list<int>);
    +class Container {
    +public:
    +  Container(std::initializer_list<int>); // initializer-list constructor
    +  Container();
    +  void push_back(const int &);
    +  ...
    +};
    +
    + +

    Alternatively you could modify the class and add another constructor for initialization by some other means, +for example by a std::vector:

    + +
    +%include <std_vector.i>
    +class Container {
    +public:
    +  Container(const std::vector<int> &);
    +  Container(std::initializer_list<int>); // initializer-list constructor
    +  Container();
    +  void push_back(const int &);
    +  ...
    +};
    +
    + +

    And then call this constructor from your target language, for example, in Python, the following will call the constructor taking the std::vector:

    + +
    +>>> c = Container( [1,2,3,4] )
    +
    + +

    +If you are unable to modify the class being wrapped, consider ignoring the initializer-list constructor and using +%extend to add in an alternative constructor: +

    + +
    +%include <std_vector.i>
    +%extend Container {
    +  Container(const std::vector<int> &elements) {
    +    Container *c = new Container();
    +    for (int element : elements)
    +      c->push_back(element);
    +    return c;
    +  }
    +}
    +
    +%ignore Container::Container(std::initializer_list<int>);
    +
    +class Container {
    +public:
    +  Container(std::initializer_list<int>); // initializer-list constructor
    +  Container();
    +  void push_back(const int &);
    +  ...
    +};
    +
    + +

    +The above makes the wrappers look is as if the class had been declared as follows: +

    + +
    +%include <std_vector.i>
    +class Container {
    +public:
    +  Container(const std::vector<int> &);
    +//  Container(std::initializer_list<int>); // initializer-list constructor (ignored)
    +  Container();
    +  void push_back(const int &);
    +  ...
    +};
    +
    + +

    +std::initializer_list is simply a container that can only be initialized at compile time. +As it is just a C++ type, it is possible to write typemaps for a target language container to map onto +std::initializer_list. However, this can only be done for a fixed number of elements as +initializer lists are not designed to be constructed with a variable number of arguments at runtime. +The example below is a very simple approach which ignores any parameters passed in and merely initializes +with a fixed list of fixed integer values chosen at compile time: +

    + +
    +%typemap(in) std::initializer_list<int> {
    +  $1 = {10, 20, 30, 40, 50};
    +}
    +class Container {
    +public:
    +  Container(std::initializer_list<int>); // initializer-list constructor
    +  Container();
    +  void push_back(const int &);
    +  ...
    +};
    +
    + +

    +Any attempt at passing in values from the target language will be ignored and be replaced by {10, 20, 30, 40, 50}. +Needless to say, this approach is very limited, but could be improved upon, but only slightly. +A typemap could be written to map a fixed number of elements on to the std::initializer_list, +but with values decided at runtime. +The typemaps would be target language specific. +

    + +

    +Note that the default typemap for std::initializer_list does nothing but issue the warning +and hence any user supplied typemaps will override it and suppress the warning. +

    + +

    7.2.5 Uniform initialization

    + + +

    The curly brackets {} for member initialization are fully +supported by SWIG:

    + +
    +struct BasicStruct {
    + int x;
    + double y;
    +};
    + 
    +struct AltStruct {
    +  AltStruct(int x, double y) : x_{x}, y_{y} {}
    + 
    +  int x_;
    +  double y_;
    +};
    +
    +BasicStruct var1{5, 3.2}; // only fills the struct components
    +AltStruct var2{2, 4.3};   // calls the constructor
    +
    + +

    Uniform initialization does not affect usage from the target language, for example in Python:

    + +
    +>>> a = AltStruct(10, 142.15)
    +>>> a.x_
    +10
    +>>> a.y_
    +142.15
    +
    + +

    7.2.6 Type inference

    + + +

    SWIG supports decltype() with some limitations. Single +variables are allowed, however, expressions are not supported yet. For +example, the following code will work:

    +
    +int i;
    +decltype(i) j;
    +
    + +

    However, using an expression inside the decltype results in syntax error:

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

    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

    + + +

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

    +
    +auto val = [] { return something; };
    +auto sum = [](int x, int y) { return x+y; };
    +auto sum = [](int x, int y) -> int { return x+y; };
    +
    + +

    The lambda functions are removed from the wrappers for now, because of the lack of support +for closures (scope of the lambda functions) in the target languages.

    + +

    +Lambda functions used to create variables can also be parsed, but due to limited support of auto when +the type is deduced from the expression, the variables are simply ignored. +

    + +
    +auto six = [](int x, int y) { return x+y; }(4, 2);
    +
    + +

    +Better support should be available in a later release. +

    + +

    7.2.9 Alternate function syntax

    + + +

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

    +
    +struct SomeStruct {
    +  int FuncName(int x, int y);
    +};
    +
    + +

    can now be written as in C++11:

    + +
    +struct SomeStruct {
    +  auto FuncName(int x, int y) -> int;
    +};
    + 
    +auto SomeStruct::FuncName(int x, int y) -> int {
    +  return x + y;
    +}
    +
    + +

    The usage in the target languages remains the same, for example in Python:

    + +
    +>>> a = SomeStruct()
    +>>> a.FuncName(10,5)
    +15
    +
    + +

    SWIG will also deal with type inference for the return type, as per the limitations described earlier. For example:

    +
    +auto square(float a, float b) -> decltype(a);
    +
    + +

    7.2.10 Object construction improvement

    + + +

    +There are three parts to object construction improvement. +The first improvement is constructor delegation such as the following: +

    + +
    +class A {
    +public:
    +  int a;
    +  int b;
    +  int c;
    +
    +  A() : A(10) {}
    +  A(int aa) : A(aa, 20) {}
    +  A(int aa, int bb) : A(aa, bb, 30) {}
    +  A(int aa, int bb, int cc) { a=aa; b=bb; c=cc; }
    +};
    +
    + +

    +where peer constructors can be called. SWIG handles this without any issue. +

    + +

    +The second improvement is constructor inheritance via a using declaration. +This is parsed correctly, but the additional constructors are not currently added to the derived proxy class in the target language. +An example is shown below: + +

    + +
    +class BaseClass {
    +public:
    +  BaseClass(int iValue);
    +};
    +
    +class DerivedClass: public BaseClass {
    +  public:
    +  using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
    +};
    +
    + +

    +The final part is member initialization at the site of the declaration. +This kind of initialization is handled by SWIG. +

    + +
    +class SomeClass {
    +public:
    +    SomeClass() {}
    +    explicit SomeClass(int new_value) : value(new_value) {}
    +
    +    int value = 5;
    +};
    +
    + +

    7.2.11 Explicit overrides and final

    + + +

    +The special identifiers final and override can be used on methods and destructors, +such as in the following example: +

    + +
    +struct BaseStruct {
    +  virtual void ab() const = 0;
    +  virtual void cd();
    +  virtual void ef();
    +  virtual ~BaseStruct();
    +};
    +struct DerivedStruct : BaseStruct {
    +  virtual void ab() const override;
    +  virtual void cd() final;
    +  virtual void ef() final override;
    +  virtual ~DerivedStruct() override;
    +};
    +
    + + +

    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

    + + +

    SWIG parses the new enum class syntax and forward declarator for the enums:

    +
    +enum class MyEnum : unsigned int;
    +
    + +

    The strongly typed enumerations are treated the same as the ordinary and anonymous enums. +This is because the required nested class support in SWIG is new and has not yet been incorporated into the wrapping of these strongly typed enum classes. +This is usually not a problem, however, +there may be some name clashes. For example, the following code:

    + +
    +class Color {
    +  enum class PrintingColors : unsigned int {
    +    Cyan, Magenta, Yellow, Black
    +  };
    +  
    +  enum class BasicColors {
    +    Red, Green, Blue
    +  };
    +  
    +  enum class AllColors {
    +    // produces warnings because of duplicate names
    +    Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
    +  };
    +};
    +
    + +

    A workaround is to write these as a series of separate classes containing anonymous enums:

    + +
    +class PrintingColors {
    +  enum : unsigned int {
    +    Cyan, Magenta, Yellow, Black
    +  };
    +};
    +
    +class BasicColors {
    +  enum : unsigned int {
    +    Red, Green, Blue
    +  };
    +};
    +
    +class AllColors {
    +  enum : unsigned int {
    +    Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
    +  };
    +};
    +
    + +

    +Expect to see this improved in a future version of SWIG. +

    + +

    7.2.14 Double angle brackets

    + + +

    SWIG correctly parses the symbols >> as closing the +template block, if found inside it at the top level, or as the right +shift operator >> otherwise.

    + +
    +std::vector<std::vector<int>> myIntTable;
    +
    + +

    7.2.15 Explicit conversion operators

    + + +

    SWIG correctly parses the keyword explicit for operators in addition to constructors now. +For example:

    + +
    +class U {
    +public:
    +  int u;
    +};
    +
    +class V {
    +public:
    +  int v;
    +};
    +
    +class TestClass {
    +public:
    +  //implicit converting constructor
    +  TestClass(U const &val) { t=val.u; }
    +
    +  // explicit constructor
    +  explicit TestClass(V const &val) { t=val.v; }
    +
    +  int t;
    +};
    +
    +struct Testable {
    +  // explicit conversion operator
    +  explicit operator bool() const {
    +    return false;
    +  }
    +};
    +
    + +

    +The effect of explicit constructors and operators has little relevance for the proxy classes as target +languages don't have the same concepts of implicit conversions as C++. +Conversion operators either with or without explicit need renaming to a valid identifier name in order to make +them available as a normal proxy method. +

    + +

    7.2.16 Alias templates

    + + +

    +The following is an example of an alias template: + +

    +template< typename T1, typename T2, int >
    +class SomeType {
    +  T1 a;
    +  T2 b;
    +  int c;
    +};
    +
    +template< typename T2 >
    +using TypedefName = SomeType<char*, T2, 5>;
    +
    + +

    +These are partially supported as SWIG will parse these and identify them, however, they are ignored as they are not added to the type system. A warning such as the following is issued: +

    + +
    +
    +example.i:13: Warning 342: The 'using' keyword in template aliasing is not fully supported yet.
    +
    +
    + +

    +Similarly for non-template type aliasing: +

    + +
    +using PFD = void (*)(double); // New introduced syntax
    +
    + +

    +A warning will be issued: +

    + +
    +
    +example.i:17: Warning 341: The 'using' keyword in type aliasing is not fully supported yet.
    +
    +
    + + +

    The equivalent old style typedefs can be used as a workaround:

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

    7.2.17 Unrestricted unions

    + + +

    SWIG fully supports any type inside a union even if it does not +define a trivial constructor. For example, the wrapper for the following +code correctly provides access to all members in the union:

    + +
    +struct point {
    +  point() {}
    +  point(int x, int y) : x_(x), y_(y) {}
    +  int x_, y_;
    +};
    +
    +#include <new> // For placement 'new' in the constructor below
    +union P {
    +  int z;
    +  double w;
    +  point p; // Illegal in C++03; legal in C++11.
    +  // Due to the point member, a constructor definition is required.
    +  P() {
    +    new(&p) point();
    +  }
    +} p1;
    +
    + +

    7.2.18 Variadic templates

    + + +

    SWIG supports the variadic templates syntax (inside the <> +block, variadic class inheritance and variadic constructor and +initializers) with some limitations. The following code is correctly parsed:

    + +
    +template <typename... BaseClasses> class ClassName : public BaseClasses... {
    +public:
    +   ClassName (BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
    +}
    +
    + +

    +For now however, the %template directive only accepts one parameter substitution +for the variable template parameters. +

    + +
    +%template(MyVariant1) ClassName<>         // zero argument not supported yet
    +%template(MyVariant2) ClassName<int>      // ok
    +%template(MyVariant3) ClassName<int, int> // too many arguments not supported yet
    +
    + +

    Support for the variadic sizeof() function is correctly parsed:

    + +
    +const int SIZE = sizeof...(ClassName<int, int>);
    +
    + +

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

    + +

    7.2.19 New string literals

    + + +

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

    + +
    +// New string literals
    +wstring         aa =  L"Wide string";
    +const char     *bb = u8"UTF-8 string";
    +const char16_t *cc =  u"UTF-16 string";
    +const char32_t *dd =  U"UTF-32 string";
    +
    +// Raw string literals
    +const char      *xx =        ")I'm an \"ascii\" \\ string.";
    +const char      *ee =   R"XXX()I'm an "ascii" \ string.)XXX"; // same as xx
    +wstring          ff =  LR"XXX(I'm a "raw wide" \ string.)XXX";
    +const char      *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX";
    +const char16_t  *hh =  uR"XXX(I'm a "raw UTF-16" \ string.)XXX";
    +const char32_t  *ii =  UR"XXX(I'm a "raw UTF-32" \ string.)XXX";
    +
    + +

    +Non-ASCII string support varies quite a bit among the various target languages though. +

    + +

    +Note: There is a bug currently where SWIG's preprocessor incorrectly parses an odd number of double quotes +inside raw string literals. +

    + +

    7.2.20 User-defined literals

    + + +

    +SWIG parses the declaration of user-defined literals, that is, the operator "" _mysuffix() function syntax. +

    + +

    +Some examples are the raw literal: +

    +
    +OutputType operator "" _myRawLiteral(const char * value);
    +
    + +

    +numeric cooked literals: +

    +
    +OutputType operator "" _mySuffixIntegral(unsigned long long);
    +OutputType operator "" _mySuffixFloat(long double);
    +
    + +

    +and cooked string literals: +

    +
    +OutputType operator "" _mySuffix(const char * string_values, size_t num_chars);
    +OutputType operator "" _mySuffix(const wchar_t * string_values, size_t num_chars);
    +OutputType operator "" _mySuffix(const char16_t * string_values, size_t num_chars);
    +OutputType operator "" _mySuffix(const char32_t * string_values, size_t num_chars);
    +
    + +

    +Like other operators that SWIG parses, a warning is given about renaming the operator in order for it to be wrapped: +

    + +
    +example.i:27: Warning 503: Can't wrap 'operator "" _myRawLiteral' unless renamed to a valid identifier.
    +
    + +

    +If %rename is used, then it can be called like any other wrapped method. +Currently you need to specify the full declaration including parameters for %rename: +

    + +
    +%rename(MyRawLiteral)  operator"" _myRawLiteral(const char * value);
    +
    + +

    +Or if you just wish to ignore it altogether: +

    + +
    +%ignore operator "" _myRawLiteral(const char * value);
    +
    + +

    +Note that use of user-defined literals such as the following still give a syntax error: +

    + +
    +OutputType var1 = "1234"_suffix;
    +OutputType var2 = 1234_suffix;
    +OutputType var3 = 3.1416_suffix;
    +
    + +

    7.2.21 Thread-local storage

    + + +

    SWIG correctly parses the thread_local keyword. For example, variables +reachable by the current thread can be defined as:

    + +
    +struct A {
    +   static thread_local int val;
    +};
    +thread_local int global_val;
    +
    + +

    +The use of the thread_local storage specifier does not affect the wrapping process; it does not modify +the wrapper code compared to when it is not specified. +A variable will be thread local if accessed from different threads from the target language in the +same way that it will be thread local if accessed from C++ code. +

    + +

    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. +For example:

    + +
    +struct NonCopyable {
    +  NonCopyable & operator=(const NonCopyable &) = delete; /* Removes operator= */
    +  NonCopyable(const NonCopyable &) = delete;             /* Removes copy constructor */
    +  NonCopyable() = default;                               /* Explicitly allows the empty constructor */
    +};
    +
    + +

    +Wrappers for deleted functions will not be available in the target language. +Wrappers for defaulted functions will of course be available in the target language. +Explicitly defaulted functions have no direct effect for SWIG wrapping as the declaration is handled +much like any other method declaration parsed by SWIG. +

    + +

    +Deleted functions are also designed to prevent implicit conversions when calling the function. +For example, the C++ compiler will not compile any code which attempts to use an int as the type of the parameter passed to f below: +

    + +
    +struct NoInt {
    +    void f(double i);
    +    void f(int) = delete;
    +};
    +
    + +

    +This is a C++ compile time check and SWIG does not make any attempt to detect if the target language is using an int instead of a double though, +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

    + + +

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

    + +

    7.2.24 Static assertions

    + + +

    +SWIG correctly parses the new static_assert declarations. +This is a C++ compile time directive so there isn't anything useful that SWIG can do with it. +

    + +
    +template <typename T>
    +struct Check {
    +  static_assert(sizeof(int) <= sizeof(T), "not big enough");
    +};
    +
    + +

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

    + + +

    +SWIG can parse the new sizeof() on types as well as on objects. For example: +

    + +
    +struct A {
    +  int member;
    +};
    +
    +const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++11
    +
    + +

    In Python:

    +
    +>>> SIZE
    +8
    +
    + +

    7.2.26 Exception specifications and noexcept

    + + +

    +C++11 added in the noexcept specification to exception specifications to indicate that a function simply may or may not throw an exception, without actually naming any exception. +SWIG understands these, although there isn't any useful way that this information can be taken advantage of by target languages, +so it is as good as ignored during the wrapping process. +Below are some examples of noexcept in function declarations: +

    + +
    +static void noex1() noexcept;
    +int noex2(int) noexcept(true);
    +int noex3(int, bool) noexcept(false);
    +
    + +

    7.2.27 Control and query object alignment

    + + +

    +An alignof operator is used mostly within C++ to return alignment in number of bytes, but could be used to initialize a variable as shown below. +The variable's value will be available for access by the target language as any other variable's compile time initialised value. + +

    +const int align1 = alignof(A::member);
    +
    + +

    +The alignas specifier for variable alignment is not yet supported. +Example usage: +

    + +
    +struct alignas(16) S {
    +  int num;
    +};
    +alignas(double) unsigned char c[sizeof(double)];
    +
    + +

    +Use the preprocessor to work around this for now: +

    + +
    +#define alignas(T)
    +
    + + +

    7.2.28 Attributes

    + + +

    +Attributes such as those shown below, are not yet supported and will give a syntax error. +

    + +
    +int [[attr1]] i [[attr2, attr3]];
    +
    +[[noreturn, nothrow]] void f [[noreturn]] ();
    +
    + +

    7.3 Standard library changes

    + + +

    7.3.1 Threading facilities

    + + +

    SWIG does not currently wrap or use any of the new threading +classes introduced (thread, mutex, locks, condition variables, task). The main reason is that +SWIG target languages offer their own threading facilities so there is limited use for them. +

    + +

    7.3.2 Tuple types

    + + +

    +SWIG does not provide library files for the new tuple types yet. +Variadic template support requires further work to provide substantial tuple wrappers. +

    + +

    7.3.3 Hash tables

    + + +

    +The new hash tables in the STL are unordered_set, unordered_multiset, unordered_map, unordered_multimap. +These are not available in SWIG, but in principle should be easily implemented by adapting the current STL containers. +

    + +

    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

    + + +

    +SWIG provides special smart pointer handling for std::shared_ptr in the same way it has support for boost::shared_ptr. +Please see the shared_ptr smart pointer library section. +There is no special smart pointer handling available for std::weak_ptr and std::unique_ptr yet. +

    + +

    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

    + + +

    +Wrapper references are similar to normal C++ references but are copy-constructible and copy-assignable. +They could conceivably be used in public APIs. +There is no special support for std::reference_wrapper in SWIG though. +Users would need to write their own typemaps if wrapper references are being used and these would be similar to the plain C++ reference typemaps. +

    + + +

    7.3.8 Polymorphous wrappers for function objects

    + + +

    +SWIG supports functor classes in a few languages in a very natural way. +However nothing is provided yet for the new std::function template. +SWIG will parse usage of the template like any other template. +

    + +
    +%rename(__call__) Test::operator(); // Default renaming used for Python
    +
    +struct Test {
    +  bool operator()(int x, int y); // function object
    +};
    +
    +#include <functional>
    +std::function<void (int, int)> pF = Test;   // function template wrapper
    +
    +
    + +

    +Example of supported usage of the plain functor from Python is shown below. +It does not involve std::function. +

    + +
    +t = Test()
    +b = t(1,2) # invoke C++ function object
    +
    + +

    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:

    + +
    +#include <type_traits>
    +
    +// First way of operating.
    +template< bool B > struct algorithm {
    +  template< class T1, class T2 > static int do_it(T1 &, T2 &)  { /*...*/ return 1; }
    +};
    +
    +// Second way of operating.
    +template<> struct algorithm<true> {
    +  template< class T1, class T2 > static int do_it(T1, T2)  { /*...*/ return 2; }
    +};
    +
    +// Instantiating 'elaborate' will automatically instantiate the correct way to operate, depending on the types used.
    +template< class T1, class T2 > int elaborate(T1 A, T2 B) {
    +  // Use the second way only if 'T1' is an integer and if 'T2' is a floating point,
    +  // otherwise use the first way.
    +  return algorithm< std::is_integral<T1>::value && std::is_floating_point<T2>::value >::do_it(A, B);
    +}
    +
    + +

    +SWIG correctly parses the template specialization, template types etc. +However, metaprogramming and the additional support in the type_traits header is really for compile time and is not much use at runtime for the target languages. +For example, as SWIG requires explicit instantiation of templates via %template, there isn't much that std::is_integral<int> is going to provide by itself. +However, template functions using such metaprogramming techniques might be useful to wrap. +For example, the following instantiations could be made: +

    + +
    +%template(Elaborate) elaborate<int, int>;
    +%template(Elaborate) elaborate<int, double>;
    +
    + +

    +Then the appropriate algorithm can be called for the subset of types given by the above %template instantiations from a target language, such as Python: +

    + +
    +>>> Elaborate(0, 0)
    +1
    +>>> Elaborate(0, 0.0)
    +2
    +
    + +

    7.3.10 Uniform method for computing return type of function objects

    + + +

    +The new std::result_of class introduced in the <functional> header provides a generic way to obtain the return type of a function type via std::result_of::type. +There isn't any library interface file to support this type. +With a bit of work, SWIG will deduce the return type of functions when used in std::result_of using the approach shown below. +The technique basically forward declares the std::result_of template class, then partially specializes it for the function types of interest. +SWIG will use the partial specialization and hence correctly use the std::result_of::type provided in the partial specialization. +

    + +
    +%inline %{
    +#include <functional>
    +typedef double(*fn_ptr)(double);
    +%}
    +
    +namespace std {
    +  // Forward declaration of result_of
    +  template<typename Func> struct result_of;
    +  // Add in a partial specialization of result_of
    +  template<> struct result_of< fn_ptr(double) > {
    +    typedef double type;
    +  };
    +}
    +
    +%template() std::result_of< fn_ptr(double) >;
    +
    +%inline %{
    +
    +double square(double x) {
    +  return (x * x);
    +}
    +
    +template<class Fun, class Arg>
    +typename std::result_of<Fun(Arg)>::type test_result_impl(Fun fun, Arg arg) {
    +  return fun(arg);
    +}
    +%}
    +
    +%template(test_result) test_result_impl< fn_ptr, double >;
    +%constant double (*SQUARE)(double) = square;
    +
    + +

    +Note the first use of %template which SWIG requires to instantiate the template. +The empty template instantiation suffices as no proxy class is required for std::result_of<Fun(Arg)>::type as this type is really just a double. +The second %template instantiates the template function which is being wrapped for use as a callback. +The %constant can then be used for any callback function as described in Pointers to functions and callbacks. +

    + +

    +Example usage from Python should give the not too surprising result: +

    + +
    +>>> test_result(SQUARE, 5.0)
    +25.0
    +
    + +

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

    + + + diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 6df2594c4..7f53423fc 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -5,11 +5,14 @@ -

    19 SWIG and C#

    +

    20 SWIG and C#

    • Introduction +
    • Differences to the Java module
    • Void pointers
    • C# Arrays @@ -49,7 +52,7 @@ -

      19.1 Introduction

      +

      20.1 Introduction

      @@ -69,7 +72,14 @@ The Microsoft Developer Network (MSDN) h Monodoc, available from the Mono project, has a very useful section titled Interop with native libraries.

      -

      19.2 Differences to the Java module

      +

      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

      @@ -262,7 +272,7 @@ An example shows that char * could be marshalled in different ways,

      -%typemap(imtype, out="IntPtr") char * "string"
      +%typemap(imtype, out="global::System.IntPtr") char * "string"
       char * function(char *);
       
      @@ -273,7 +283,7 @@ The output type is thus IntPtr and the input type is string. The resulting inter
      -public static extern IntPtr function(string jarg1);
      +public static extern global::System.IntPtr function(string jarg1);
       
      @@ -294,8 +304,8 @@ For example:
       %typemap(imtype,
      -         inattributes="[MarshalAs(UnmanagedType.LPStr)]",
      -         outattributes="[return: MarshalAs(UnmanagedType.LPStr)]") const char * "String"
      +         inattributes="[global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]",
      +         outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]") const char * "String"
       
       const char * GetMsg() {}
       void SetMsg(const char *msg) {}
      @@ -310,12 +320,12 @@ The intermediary class will then have the marshalling as specified by everything
       
       class examplePINVOKE {
         ...
      -  [DllImport("example", EntryPoint="CSharp_GetMsg")]
      -  [return: MarshalAs(UnmanagedType.LPStr)]
      +  [global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_GetMsg")]
      +  [return: global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]
         public static extern String GetMsg();
       
      -  [DllImport("example", EntryPoint="CSharp_SetMsg")]
      -  public static extern void SetMsg([MarshalAs(UnmanagedType.LPStr)]String jarg1);
      +  [global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_SetMsg")]
      +  public static extern void SetMsg([global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]String jarg1);
       }
       
      @@ -368,7 +378,7 @@ will generate a C# proxy class:
       [ThreadSafe]
      -public class AClass : IDisposable {
      +public class AClass : global::System.IDisposable {
         ...
         [ThreadSafe(false)]
         public AClass(double a) ...
      @@ -392,9 +402,9 @@ An example for attaching attributes to the enum and enum values is shown below.
       
       
      -%typemap(csattributes) Couleur "[System.ComponentModel.Description(\"Colours\")]"
      -%csattributes Rouge "[System.ComponentModel.Description(\"Red\")]"
      -%csattributes Vert "[System.ComponentModel.Description(\"Green\")]"
      +%typemap(csattributes) Couleur "[global::System.ComponentModel.Description(\"Colours\")]"
      +%csattributes Rouge "[global::System.ComponentModel.Description(\"Red\")]"
      +%csattributes Vert "[global::System.ComponentModel.Description(\"Green\")]"
       %inline %{
         enum Couleur { Rouge, Orange, Vert };
       %}
      @@ -407,12 +417,12 @@ which will result in the following C# enum:
       
       
      -[System.ComponentModel.Description("Colours")]
      +[global::System.ComponentModel.Description("Colours")]
       public enum Couleur {
      -  [System.ComponentModel.Description("Red")]
      +  [global::System.ComponentModel.Description("Red")]
         Rouge,
         Orange,
      -  [System.ComponentModel.Description("Green")]
      +  [global::System.ComponentModel.Description("Green")]
         Vert
       }
       
      @@ -482,7 +492,7 @@ Windows users can also get the examples working using a Cygwin 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. -

      19.3 Void pointers

      +

      20.3 Void pointers

      @@ -500,7 +510,7 @@ void * f(void *v);

      -

      19.4 C# Arrays

      +

      20.4 C# Arrays

      @@ -512,7 +522,7 @@ with one of the following three approaches; namely the SWIG C arrays library, P/ pinned arrays.

      -

      19.4.1 The SWIG C arrays library

      +

      20.4.1 The SWIG C arrays library

      @@ -549,7 +559,7 @@ example.print_array(c.cast()); // Pass to C

      -

      19.4.2 Managed arrays using P/Invoke default array marshalling

      +

      20.4.2 Managed arrays using P/Invoke default array marshalling

      @@ -618,9 +628,9 @@ marshalling for the arrays:

      -[DllImport("example", EntryPoint="CSharp_myArrayCopy")]
      -public static extern void myArrayCopy([In, MarshalAs(UnmanagedType.LPArray)]int[] jarg1, 
      -                                      [Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
      +[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArrayCopy")]
      +public static extern void myArrayCopy([global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg1, 
      +                                      [global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
                                              int jarg3);
       
      @@ -668,15 +678,15 @@ and intermediary class method
      -  [DllImport("example", EntryPoint="CSharp_myArraySwap")]
      -  public static extern void myArraySwap([In, Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg1, 
      -                                        [In, Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
      +  [global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArraySwap")]
      +  public static extern void myArraySwap([global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg1, 
      +                                        [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
                                                int jarg3);
       
      -

      19.4.3 Managed arrays using pinning

      +

      20.4.3 Managed arrays using pinning

      @@ -743,7 +753,7 @@ As a result, we get the following method in the module class: fixed ( int *swig_ptrTo_sourceArray = sourceArray ) { fixed ( int *swig_ptrTo_targetArray = targetArray ) { { - examplePINVOKE.myArrayCopy((IntPtr)swig_ptrTo_sourceArray, (IntPtr)swig_ptrTo_targetArray, + examplePINVOKE.myArrayCopy((global::System.IntPtr)swig_ptrTo_sourceArray, (global::System.IntPtr)swig_ptrTo_targetArray, nitems); } } @@ -764,14 +774,14 @@ example - the method is expecting an IntPtr as the parameter type.

      -[DllImport("example", EntryPoint="CSharp_myArrayCopy")]
      -public static extern void myArrayCopy(IntPtr jarg1, IntPtr jarg2, int jarg3);
      +[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArrayCopy")]
      +public static extern void myArrayCopy(global::System.IntPtr jarg1, global::System.IntPtr jarg2, int jarg3);
       
      -

      19.5 C# Exceptions

      +

      20.5 C# Exceptions

      @@ -868,11 +878,11 @@ set so should only be used when a C# exception is not created.

      -

      19.5.1 C# exception example using "check" typemap

      +

      20.5.1 C# exception example using "check" typemap

      -Lets say we have the following simple C++ method: +Let's say we have the following simple C++ method:

      @@ -1050,7 +1060,7 @@ method and C# code does not handle pending exceptions via the canthrow attribute Actually it will issue this warning for any function beginning with SWIG_CSharpSetPendingException.

      -

      19.5.2 C# exception example using %exception

      +

      20.5.2 C# exception example using %exception

      @@ -1115,7 +1125,7 @@ The managed code generated does check for the pending exception as mentioned ear

    -

    19.5.3 C# exception example using exception specifications

    +

    20.5.3 C# exception example using exception specifications

    @@ -1172,7 +1182,7 @@ SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) { Multiple catch handlers are generated should there be more than one exception specifications declared.

    -

    19.5.4 Custom C# ApplicationException example

    +

    20.5.4 Custom C# ApplicationException example

    @@ -1220,7 +1230,7 @@ the C# code can be generated into the intermediary class using the imclassco static CustomExceptionDelegate customDelegate = new CustomExceptionDelegate(SetPendingCustomException); - [DllImport("$dllimport", EntryPoint="CustomExceptionRegisterCallback")] + [global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="CustomExceptionRegisterCallback")] public static extern void CustomExceptionRegisterCallback(CustomExceptionDelegate customCallback); @@ -1264,7 +1274,7 @@ The boiler plate code above must be used in addition to a handcrafted Custom

     // Custom C# Exception
    -class CustomApplicationException : System.ApplicationException {
    +class CustomApplicationException : global::System.ApplicationException {
       public CustomApplicationException(string message) 
         : base(message) {
       }
    @@ -1306,7 +1316,7 @@ try {
     
    -

    19.6 C# Directors

    +

    20.6 C# Directors

    @@ -1319,7 +1329,7 @@ The following sections provide information on the C# director implementation and However, the Java directors section should also be read in order to gain more insight into directors.

    -

    19.6.1 Directors example

    +

    20.6.1 Directors example

    @@ -1440,7 +1450,7 @@ CSharpDerived - UIntMethod(123) -

    19.6.2 Directors implementation

    +

    20.6.2 Directors implementation

    @@ -1457,20 +1467,17 @@ Below is the generated C# Base director class.

    -using System;
    -using System.Runtime.InteropServices;
    -
    -public class Base : IDisposable {
    -  private HandleRef swigCPtr;
    +public class Base : global::System.IDisposable {
    +  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
       protected bool swigCMemOwn;
     
    -  internal Base(IntPtr cPtr, bool cMemoryOwn) {
    +  internal Base(global::System.IntPtr cPtr, bool cMemoryOwn) {
         swigCMemOwn = cMemoryOwn;
    -    swigCPtr = new HandleRef(this, cPtr);
    +    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
       }
     
    -  internal static HandleRef getCPtr(Base obj) {
    -    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
    +  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Base obj) {
    +    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
       }
     
       ~Base() {
    @@ -1479,12 +1486,12 @@ public class Base : IDisposable {
     
       public virtual void Dispose() {
         lock(this) {
    -      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
    +      if(swigCPtr.Handle != global::System.IntPtr.Zero && swigCMemOwn) {
             swigCMemOwn = false;
             examplePINVOKE.delete_Base(swigCPtr);
           }
    -      swigCPtr = new HandleRef(null, IntPtr.Zero);
    -      GC.SuppressFinalize(this);
    +      swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
    +      global::System.GC.SuppressFinalize(this);
         }
       }
     
    @@ -1511,7 +1518,7 @@ public class Base : IDisposable {
         examplePINVOKE.Base_director_connect(swigCPtr, swigDelegate0, swigDelegate1);
       }
     
    -  private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes) {
    +  private bool SwigDerivedClassHasMethod(string methodName, global::System.global::System.Type[] methodTypes) {
         System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, methodTypes);
         bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(Base));
         return hasDerivedMethod;
    @@ -1521,18 +1528,18 @@ public class Base : IDisposable {
         return UIntMethod(x);
       }
     
    -  private void SwigDirectorBaseBoolMethod(IntPtr b, bool flag) {
    +  private void SwigDirectorBaseBoolMethod(global::System.IntPtr b, bool flag) {
         BaseBoolMethod(new Base(b, false), flag);
       }
     
       internal delegate uint SwigDelegateBase_0(uint x);
    -  internal delegate void SwigDelegateBase_1(IntPtr b, bool flag);
    +  internal delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
     
       private SwigDelegateBase_0 swigDelegate0;
       private SwigDelegateBase_1 swigDelegate1;
     
    -  private static Type[] swigMethodTypes0 = new Type[] { typeof(uint) };
    -  private static Type[] swigMethodTypes1 = new Type[] { typeof(Base), typeof(bool) };
    +  private static global::System.Type[] swigMethodTypes0 = new global::System.Type[] { typeof(uint) };
    +  private static global::System.Type[] swigMethodTypes1 = new global::System.Type[] { typeof(Base), typeof(bool) };
     }
     
    @@ -1626,7 +1633,7 @@ void SwigDirector_Base::BaseBoolMethod(Base const &b, bool flag) { -

    19.6.3 Director caveats

    +

    20.6.3 Director caveats

    @@ -1674,7 +1681,7 @@ However, a call from C# to CSharpDefaults.DefaultMethod() will of cours should pass the call on to CSharpDefaults.DefaultMethod(int)using the C++ default value, as shown above.

    -

    19.7 Multiples modules

    +

    20.7 Multiples modules

    @@ -1709,7 +1716,7 @@ the [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrows if you don't want users to easily stumble upon these so called 'internal workings' of the wrappers.

    -

    19.8 C# Typemap examples

    +

    20.8 C# Typemap examples

    This section includes a few examples of typemaps. For more examples, you @@ -1717,7 +1724,7 @@ might look at the files "csharp.swg" and "typemaps.i" in the SWIG library. -

    19.8.1 Memory management when returning references to member variables

    +

    20.8.1 Memory management when returning references to member variables

    @@ -1755,9 +1762,9 @@ and the following usage from C# after running the code through SWIG: Wheel wheel = new Bike(10).getWheel(); Console.WriteLine("wheel size: " + wheel.size); // Simulate a garbage collection - System.GC.Collect(); - System.GC.WaitForPendingFinalizers(); - Console.WriteLine("wheel size: " + wheel.size); + global::System.GC.Collect(); + global::System.GC.WaitForPendingFinalizers(); + global::System.Console.WriteLine("wheel size: " + wheel.size); @@ -1795,9 +1802,9 @@ is called using the following typemaps. // of dangling C++ pointer. Intended for methods that return pointers or // references to a member variable. %typemap(csout, excode=SWIGEXCODE) Wheel& getWheel { - IntPtr cPtr = $imcall;$excode + global::System.IntPtr cPtr = $imcall;$excode $csclassname ret = null; - if (cPtr != IntPtr.Zero) { + if (cPtr != global::System.IntPtr.Zero) { ret = new $csclassname(cPtr, $owner); ret.addReference(this); } @@ -1813,7 +1820,7 @@ The code in the second typemap constitutes the bulk of the code in the generated

    -public class Wheel : IDisposable {
    +public class Wheel : global::System.IDisposable {
       ...
       // Ensure that the GC doesn't collect any Bike instance set from C#
       private Bike bikeReference;
    @@ -1822,12 +1829,12 @@ public class Wheel : IDisposable {
       }
     }
     
    -public class Bike : IDisposable {
    +public class Bike : global::System.IDisposable {
       ...
       public Wheel getWheel() {
    -    IntPtr cPtr = examplePINVOKE.Bike_getWheel(swigCPtr);
    +    global::System.IntPtr cPtr = examplePINVOKE.Bike_getWheel(swigCPtr);
         Wheel ret = null;
    -    if (cPtr != IntPtr.Zero) {
    +    if (cPtr != global::System.IntPtr.Zero) {
           ret = new Wheel(cPtr, false);
           ret.addReference(this);
         }
    @@ -1841,7 +1848,7 @@ public class Bike : IDisposable {
     Note the addReference call.
     

    -

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

    +

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

    @@ -1904,9 +1911,9 @@ In order to understand why, consider a garbage collection occuring... container.setElement(element); Console.WriteLine("element.value: " + container.getElement().value); // Simulate a garbage collection - System.GC.Collect(); - System.GC.WaitForPendingFinalizers(); - Console.WriteLine("element.value: " + container.getElement().value); + global::System.GC.Collect(); + global::System.GC.WaitForPendingFinalizers(); + global::System.Console.WriteLine("element.value: " + container.getElement().value);

    @@ -1918,14 +1925,14 @@ One solution is to add in the appropriate references in the C# layer...
    -public class Container : IDisposable {
    +public class Container : global::System.IDisposable {
     
       ...
     
       // Ensure that the GC doesn't collect any Element set from C#
       // as the underlying C++ class stores a shallow copy
       private Element elementReference;
    -  private HandleRef getCPtrAndAddReference(Element element) {
    +  private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
         elementReference = element;
         return Element.getCPtr(element);
       }
    @@ -1951,7 +1958,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class.
       // Ensure that the GC doesn't collect any Element set from C#
       // as the underlying C++ class stores a shallow copy
       private Element elementReference;
    -  private HandleRef getCPtrAndAddReference(Element element) {
    +  private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
         elementReference = element;
         return Element.getCPtr(element);
       }
    @@ -1960,7 +1967,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class.
     
    -

    19.8.3 Date marshalling using the csin typemap and associated attributes

    +

    20.8.3 Date marshalling using the csin typemap and associated attributes

    @@ -2000,7 +2007,7 @@ First let's look at the code that is generated by default, where the C# proxy cl

    -public class Action : IDisposable {
    +public class Action : global::System.IDisposable {
       ...
       public Action(CDate dateIn, CDate dateOut) 
           : this(examplePINVOKE.new_Action(CDate.getCPtr(dateIn), CDate.getCPtr(dateOut)), true) {
    @@ -2081,7 +2088,7 @@ The resulting generated proxy code in the Action class follows:
     
     
    -public class Action : IDisposable {
    +public class Action : global::System.IDisposable {
       ...
       public int doSomething(System.DateTime dateIn, out System.DateTime dateOut) {
         CDate tempdateIn = new CDate(dateIn.Year, dateIn.Month, dateIn.Day);
    @@ -2099,7 +2106,7 @@ public class Action : IDisposable {
         }
       }
     
    -  static private IntPtr SwigConstructAction(System.DateTime dateIn, out System.DateTime dateOut) {
    +  static private global::System.IntPtr SwigConstructAction(System.DateTime dateIn, out System.DateTime dateOut) {
         CDate tempdateIn = new CDate(dateIn.Year, dateIn.Month, dateIn.Day);
         CDate tempdateOut = new CDate();
         try {
    @@ -2246,7 +2253,7 @@ public class example {
     
    -

    19.8.4 A date example demonstrating marshalling of C# properties

    +

    20.8.4 A date example demonstrating marshalling of C# properties

    @@ -2299,8 +2306,8 @@ The typemap type required is thus CDate *. Given that the previous sect %typemap(csvarout, excode=SWIGEXCODE2) CDate * %{ /* csvarout typemap code */ get { - IntPtr cPtr = $imcall; - CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode + global::System.IntPtr cPtr = $imcall; + CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(), 0, 0, 0); } %} @@ -2322,8 +2329,8 @@ public class example { } /* csvarout typemap code */ get { - IntPtr cPtr = examplePINVOKE.ImportantDate_get(); - CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, false); + global::System.IntPtr cPtr = examplePINVOKE.ImportantDate_get(); + CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, false); return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(), 0, 0, 0); } @@ -2346,7 +2353,7 @@ Some points to note:

  • 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. -

    19.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

    @@ -2389,7 +2396,7 @@ The generated proxy class code will then contain the following wrapper for calli

     ...
    -  private void SwigDirectorsomeCallback(IntPtr date) {
    +  private void SwigDirectorsomeCallback(global::System.IntPtr date) {
         System.DateTime tempdate = new System.DateTime();
         try {
           someCallback(out tempdate);
    @@ -2408,7 +2415,7 @@ Pay special attention to the memory management issues, using these attributes.
     

    -

    19.8.6 Turning wrapped classes into partial classes

    +

    20.8.6 Turning wrapped classes into partial classes

    @@ -2432,7 +2439,7 @@ The default C# proxy class generated is:

    -public class ExtendMe : IDisposable {
    +public class ExtendMe : global::System.IDisposable {
       ...
       public int Part1() {
         ...
    @@ -2468,7 +2475,7 @@ The C# proxy class becomes a partial class:
     
     
    -public partial class ExtendMe : IDisposable {
    +public partial class ExtendMe : global::System.IDisposable {
       ...
       public int Part1() {
         ...
    @@ -2483,7 +2490,7 @@ You can then of course declare another part of the partial class elsewhere, for
     
     
    -public partial class ExtendMe : IDisposable {
    +public partial class ExtendMe : global::System.IDisposable {
       public int Part2() {
         return 2;
       }
    @@ -2508,7 +2515,7 @@ demonstrating that the class contains methods calling both unmanaged code - 
     The following example is an alternative approach to adding managed code to the generated proxy class.
     

    -

    19.8.7 Extending proxy classes with additional C# code

    +

    20.8.7 Extending proxy classes with additional C# code

    @@ -2535,7 +2542,7 @@ The generated C# proxy class will instead be:

    -public class ExtendMe : IDisposable {
    +public class ExtendMe : global::System.IDisposable {
       ...
       public int Part3() {
         return 3;
    @@ -2547,7 +2554,7 @@ public class ExtendMe : IDisposable {
     
    -

    19.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 4e43b9b90..82861c31c 100644 --- a/Doc/Manual/Chicken.html +++ b/Doc/Manual/Chicken.html @@ -8,7 +8,7 @@ -

    20 SWIG and Chicken

    +

    21 SWIG and Chicken

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

      -

      20.1 Preliminaries

      +

      21.1 Preliminaries

      @@ -89,7 +89,7 @@ directory for the basic steps to run SWIG CHICKEN.

      -

      20.1.1 Running SWIG in C mode

      +

      21.1.1 Running SWIG in C mode

      @@ -122,7 +122,7 @@ object files and linked into your project.

      -

      20.1.2 Running SWIG in C++ mode

      +

      21.1.2 Running SWIG in C++ mode

      @@ -151,10 +151,10 @@ object files and linked into your project.

      -

      20.2 Code Generation

      +

      21.2 Code Generation

      -

      20.2.1 Naming Conventions

      +

      21.2.1 Naming Conventions

      @@ -170,7 +170,7 @@ %rename SWIG directive in the SWIG interface file.

      -

      20.2.2 Modules

      +

      21.2.2 Modules

      @@ -192,7 +192,7 @@ (uses modulename)) CHICKEN Scheme form.

      -

      20.2.3 Constants and Variables

      +

      21.2.3 Constants and Variables

      @@ -229,7 +229,7 @@ for info on how to apply the %feature.

      -

      20.2.4 Functions

      +

      21.2.4 Functions

      @@ -248,7 +248,7 @@ parameters). The return values can then be accessed with (call-with-values).

      -

      20.2.5 Exceptions

      +

      21.2.5 Exceptions

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

    -

    20.3 TinyCLOS

    +

    21.3 TinyCLOS

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

    -

    20.4 Linkage

    +

    21.4 Linkage

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

    -

    20.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 @@ in which case the test script does not need to be linked with example.so. The t be run with csi.

    -

    20.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 @@ distributed and used by anyone, even if SWIG is not installed.

    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.

    -

    20.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 @@ with (declare (uses ...)). To create an extension library or an egg, just create a module_load.scm file that (declare (uses ...)) all the modules.

    -

    20.5 Typemaps

    +

    21.5 Typemaps

    @@ -486,7 +486,7 @@ all the modules.

    Lib/chicken/chicken.swg.

    -

    20.6 Pointers

    +

    21.6 Pointers

    @@ -519,7 +519,7 @@ all the modules.

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

    -

    20.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 @@ all the modules.

    must be called manually.

    -

    20.7 Unsupported features and known problems

    +

    21.7 Unsupported features and known problems

    -

    20.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 77280c8bc..4dd454352 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -262,7 +262,61 @@

    -

    7 Preprocessing

    +

    7 SWIG and C++11

    + + + + + +

    8 Preprocessing

    @@ -285,7 +339,7 @@
    -

    8 SWIG library

    +

    9 SWIG library

    -

    9 Argument Handling

    +

    10 Argument Handling

    @@ -343,7 +398,7 @@
    -

    10 Typemaps

    +

    11 Typemaps

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

    11 Customization Features

    +

    12 Customization Features

    @@ -459,7 +514,7 @@
    -

    12 Contracts

    +

    13 Contracts

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

    13 Variable Length Arguments

    +

    14 Variable Length Arguments

    @@ -490,7 +545,7 @@
    -

    14 Warning Messages

    +

    15 Warning Messages

    @@ -518,7 +573,7 @@
    -

    15 Working with Modules

    +

    16 Working with Modules

    @@ -534,7 +589,7 @@
    -

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

    +

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

    @@ -560,7 +615,7 @@
    -

    17 SWIG and Allegro Common Lisp

    +

    18 SWIG and Allegro Common Lisp

    @@ -644,7 +699,7 @@
    -

    18 SWIG and Android

    +

    19 SWIG and Android

    @@ -662,12 +717,15 @@
    -

    19 SWIG and C#

    +

    20 SWIG and C#

    -

    20 SWIG and Chicken

    +

    21 SWIG and Chicken

    @@ -743,7 +801,7 @@
    -

    21 SWIG and D

    +

    22 SWIG and D

    @@ -777,7 +835,7 @@
    -

    22 SWIG and Go

    +

    23 SWIG and Go

    @@ -808,7 +866,7 @@
    -

    23 SWIG and Guile

    +

    24 SWIG and Guile

    @@ -843,7 +901,7 @@
    -

    24 SWIG and Java

    +

    25 SWIG and Java

    -

    25 SWIG and Common Lisp

    +

    26 SWIG and Javascript

    + + + + + +

    27 SWIG and Common Lisp

    @@ -1010,7 +1111,7 @@
    -

    26 SWIG and Lua

    +

    28 SWIG and Lua

    -

    27 SWIG and Modula-3

    +

    29 SWIG and Modula-3

    @@ -1107,7 +1217,7 @@
    -

    28 SWIG and MzScheme/Racket

    +

    30 SWIG and MzScheme/Racket

    @@ -1119,7 +1229,7 @@
    -

    29 SWIG and Ocaml

    +

    31 SWIG and Ocaml

    @@ -1170,7 +1280,7 @@
    -

    30 SWIG and Octave

    +

    32 SWIG and Octave

    @@ -1206,7 +1316,7 @@
    -

    31 SWIG and Perl5

    +

    33 SWIG and Perl5

    -

    32 SWIG and PHP

    +

    34 SWIG and PHP

    @@ -1313,7 +1432,7 @@
    -

    33 SWIG and Pike

    +

    35 SWIG and Pike

    @@ -1337,7 +1456,7 @@
    -

    34 SWIG and Python

    +

    36 SWIG and Python

    -

    35 SWIG and R

    +

    37 SWIG and R

    @@ -1463,7 +1589,7 @@
    -

    36 SWIG and Ruby

    +

    38 SWIG and Ruby

    @@ -1597,7 +1723,7 @@
    -

    37 SWIG and Tcl

    +

    39 SWIG and Tcl

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

    38 Extending SWIG to support new languages

    +

    40 Extending SWIG to support new languages

    diff --git a/Doc/Manual/Contract.html b/Doc/Manual/Contract.html index de390fba4..35bc874ef 100644 --- a/Doc/Manual/Contract.html +++ b/Doc/Manual/Contract.html @@ -6,7 +6,7 @@ -

    12 Contracts

    +

    13 Contracts

      @@ -38,7 +38,7 @@ When one of the rules is violated by a script, a runtime exception is generated rather than having the program continue to execute.

      -

      12.1 The %contract directive

      +

      13.1 The %contract directive

      @@ -94,7 +94,7 @@ RuntimeError: Contract violation: require: (arg1>=0)

    -

    12.2 %contract and classes

    +

    13.2 %contract and classes

    @@ -173,7 +173,7 @@ specified for the derived class all must hold. In the above example, this means that both the arguments to Spam::bar must be positive.

    -

    12.3 Constant aggregation and %aggregate_check

    +

    13.3 Constant aggregation and %aggregate_check

    @@ -262,7 +262,7 @@ Regrettably, there is no automatic way to perform similar checks with enums valu release.

    -

    12.4 Notes

    +

    13.4 Notes

    diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index f420f42d6..a0a89c042 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -6,7 +6,7 @@ -

    11 Customization Features

    +

    12 Customization Features

      @@ -45,7 +45,7 @@ of exception handling is presented. Then, a more general-purpose customization mechanism known as "features" is described.

      -

      11.1 Exception handling with %exception

      +

      12.1 Exception handling with %exception

      @@ -100,7 +100,7 @@ for exception handling. That directive is deprecated--%exception provides the same functionality, but is substantially more flexible.

      -

      11.1.1 Handling exceptions in C code

      +

      12.1.1 Handling exceptions in C code

      @@ -166,7 +166,7 @@ Each target language has its own approach to creating a runtime error/exception and for Perl it is the croak method shown above.

      -

      11.1.2 Exception handling with longjmp()

      +

      12.1.2 Exception handling with longjmp()

      @@ -240,7 +240,7 @@ Note: This implementation is only intended to illustrate the general idea. To m modify it to handle nested try declarations.

      -

      11.1.3 Handling C++ exceptions

      +

      12.1.3 Handling C++ exceptions

      @@ -275,7 +275,7 @@ class OutOfMemory {};

    -

    11.1.4 Exception handlers for variables

    +

    12.1.4 Exception handlers for variables

    @@ -300,7 +300,7 @@ The %allowexception feature works like any other feature and so can be

  • -

    11.1.5 Defining different exception handlers

    +

    12.1.5 Defining different exception handlers

    @@ -437,7 +437,7 @@ declarations. However, it never really worked that well and the new %exception directive is much better.

    -

    11.1.6 Special variables for %exception

    +

    12.1.6 Special variables for %exception

    @@ -540,7 +540,7 @@ Below shows the expansions for the 1st of the overloaded something wrap -

    11.1.7 Using The SWIG exception library

    +

    12.1.7 Using The SWIG exception library

    @@ -595,7 +595,7 @@ SWIG_NullReferenceError The SWIG_exception() function can also be used in typemaps.

    -

    11.2 Object ownership and %newobject

    +

    12.2 Object ownership and %newobject

    @@ -752,7 +752,7 @@ char *strdup(const char *s); The results might not be what you expect.

    -

    11.3 Features and the %feature directive

    +

    12.3 Features and the %feature directive

    @@ -834,7 +834,7 @@ The following are all equivalent: The syntax in the first variation will generate the { } delimiters used whereas the other variations will not.

    -

    11.3.1 Feature attributes

    +

    12.3.1 Feature attributes

    @@ -875,7 +875,7 @@ In the following example, MyExceptionClass is the name of the Java clas Further details can be obtained from the Java exception handling section.

    -

    11.3.2 Feature flags

    +

    12.3.2 Feature flags

    @@ -973,7 +973,7 @@ in the swig.swg Library file. The following shows the alternative synta The concept of clearing features is discussed next.

    -

    11.3.3 Clearing features

    +

    12.3.3 Clearing features

    @@ -1066,7 +1066,7 @@ The three macros below show this for the "except" feature: -

    11.3.4 Features and default arguments

    +

    12.3.4 Features and default arguments

    @@ -1141,7 +1141,7 @@ specifying or not specifying default arguments in a feature is not applicable as in SWIG-1.3.23 when the approach to wrapping methods with default arguments was changed.

    -

    11.3.5 Feature example

    +

    12.3.5 Feature example

    diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html index 43fa69196..47dab50f1 100644 --- a/Doc/Manual/D.html +++ b/Doc/Manual/D.html @@ -6,7 +6,7 @@ -

    21 SWIG and D

    +

    22 SWIG and D

      @@ -41,7 +41,7 @@ -

      21.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?

      @@ -53,7 +53,7 @@

      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).

      -

      21.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:

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

      21.3 Typemaps

      +

      22.3 Typemaps

      -

      21.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 @@
    -

    21.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,7 +120,7 @@

    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.

    -

    21.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).

    @@ -130,7 +130,7 @@

    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).

    -

    21.3.4 din, dout, ddirectorin, ddirectorout

    +

    22.3.4 din, dout, ddirectorin, ddirectorout

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

    @@ -157,13 +157,13 @@ dtype DClass.method(dtype a) -

    21.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).

    -

    21.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.

    @@ -175,7 +175,7 @@

    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.

    -

    21.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.

    @@ -295,7 +295,7 @@ $importtype(AnotherInterface) -

    21.4 %features

    +

    22.4 %features

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

    @@ -325,7 +325,7 @@ struct A { -

    21.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 @@ struct A { -

    21.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 @@ struct A {

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

    -

    21.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 @@ struct A {

    -

    21.8 Other features

    +

    22.8 Other features

    -

    21.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.

    -

    21.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 @@ struct A {

    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 *).

    -

    21.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 @@ struct A {

    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.

    -

    21.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 @@ struct A {

    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.

    -

    21.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.

    -

    21.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 5ea4e51f4..00302d7b5 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -6,7 +6,7 @@ -

    38 Extending SWIG to support new languages

    +

    40 Extending SWIG to support new languages

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

      38.1 Introduction

      +

      40.1 Introduction

      @@ -91,7 +91,7 @@ Also, this chapter is not meant to be a hand-holding tutorial. As a starting po you should probably look at one of SWIG's existing modules.

      -

      38.2 Prerequisites

      +

      40.2 Prerequisites

      @@ -121,7 +121,7 @@ obvious, but almost all SWIG directives as well as the low-level generation of wrapper code are driven by C++ datatypes.

      -

      38.3 The Big Picture

      +

      40.3 The Big Picture

      @@ -158,7 +158,7 @@ role in making the system work. For example, both typemaps and declaration anno based on pattern matching and interact heavily with the underlying type system.

      -

      38.4 Execution Model

      +

      40.4 Execution Model

      @@ -203,7 +203,7 @@ latter stage of compilation. The next few sections briefly describe some of these stages.

      -

      38.4.1 Preprocessing

      +

      40.4.1 Preprocessing

      @@ -284,7 +284,7 @@ been expanded as well as everything else that goes into the low-level construction of the wrapper code.

      -

      38.4.2 Parsing

      +

      40.4.2 Parsing

      @@ -385,7 +385,7 @@ returning a foo and taking types a and b as arguments).

      -

      38.4.3 Parse Trees

      +

      40.4.3 Parse Trees

      @@ -640,7 +640,7 @@ $ swig -c++ -python -debug-module 4 example.i

    -

    38.4.4 Attribute namespaces

    +

    40.4.4 Attribute namespaces

    @@ -659,7 +659,7 @@ that matches the name of the target language. For example, python:foo perl:foo.

    -

    38.4.5 Symbol Tables

    +

    40.4.5 Symbol Tables

    @@ -750,7 +750,7 @@ example.i:5. Previous declaration is foo_i(int ) -

    38.4.6 The %feature directive

    +

    40.4.6 The %feature directive

    @@ -806,7 +806,7 @@ For example, the exception code above is simply stored without any modifications.

    -

    38.4.7 Code Generation

    +

    40.4.7 Code Generation

    @@ -928,7 +928,7 @@ public : The role of these functions is described shortly.

    -

    38.4.8 SWIG and XML

    +

    40.4.8 SWIG and XML

    @@ -941,7 +941,7 @@ internal data structures, it may be useful to keep XML in the back of your mind as a model.

    -

    38.5 Primitive Data Structures

    +

    40.5 Primitive Data Structures

    @@ -987,7 +987,7 @@ typedef Hash Typetab; -

    38.5.1 Strings

    +

    40.5.1 Strings

    @@ -1128,7 +1128,7 @@ Returns the number of replacements made (if any). -

    38.5.2 Hashes

    +

    40.5.2 Hashes

    @@ -1205,7 +1205,7 @@ Returns the list of hash table keys. -

    38.5.3 Lists

    +

    40.5.3 Lists

    @@ -1294,7 +1294,7 @@ If t is not a standard object, it is assumed to be a char * and is used to create a String object. -

    38.5.4 Common operations

    +

    40.5.4 Common operations

    The following operations are applicable to all datatypes. @@ -1349,7 +1349,7 @@ objects and report errors. Gets the line number associated with x. -

    38.5.5 Iterating over Lists and Hashes

    +

    40.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 +1394,7 @@ for (j = First(j); j.item; j= Next(j)) { -

    38.5.6 I/O

    +

    40.5.6 I/O

    Special I/O functions are used for all internal I/O. These operations @@ -1500,12 +1500,11 @@ Create a File object wrapper around an existing FILE * object.

    -int Close(String_or_FILE *f) +There's no explicit function to close a file, just call Delete(f) - +this decreases the reference count, and the file will be closed when the +reference count reaches zero.

    -
    -

    Closes a file. Has no effect on strings.

    -

    The use of the above I/O functions and strings play a critical role in SWIG. It is common to see small code fragments of code generated using code like this: @@ -1529,9 +1528,7 @@ Printf(f, "%s\n", s); Similarly, the preprocessor and parser all operate on string-files.

    -
    - -

    38.6 Navigating and manipulating parse trees

    +

    40.6 Navigating and manipulating parse trees

    Parse trees are built as collections of hash tables. Each node is a hash table in which @@ -1665,7 +1662,7 @@ Deletes a node from the parse tree. Deletion reconnects siblings and properly u the parent so that sibling nodes are unaffected. -

    38.7 Working with attributes

    +

    40.7 Working with attributes

    @@ -1782,7 +1779,7 @@ the attribute is optional. Swig_restore() must always be called after function. -

    38.8 Type system

    +

    40.8 Type system

    @@ -1791,7 +1788,7 @@ pointers, references, and pointers to members. A detailed discussion of type theory is impossible here. However, let's cover the highlights.

    -

    38.8.1 String encoding of types

    +

    40.8.1 String encoding of types

    @@ -1892,7 +1889,7 @@ make the final type, the two parts are just joined together using string concatenation.

    -

    38.8.2 Type construction

    +

    40.8.2 Type construction

    @@ -2061,7 +2058,7 @@ Returns the prefix of a type. For example, if ty is ty is unmodified. -

    38.8.3 Type tests

    +

    40.8.3 Type tests

    @@ -2148,7 +2145,7 @@ Checks if ty is a varargs type. Checks if ty is a templatized type. -

    38.8.4 Typedef and inheritance

    +

    40.8.4 Typedef and inheritance

    @@ -2250,7 +2247,7 @@ Fully reduces ty according to typedef rules. Resulting datatype will consist only of primitive typenames. -

    38.8.5 Lvalues

    +

    40.8.5 Lvalues

    @@ -2287,7 +2284,7 @@ Literal y; // type = 'Literal', ltype='p.char' -

    38.8.6 Output functions

    +

    40.8.6 Output functions

    @@ -2349,7 +2346,7 @@ SWIG, but is most commonly associated with type-descriptor objects that appear in wrappers (e.g., SWIGTYPE_p_double). -

    38.9 Parameters

    +

    40.9 Parameters

    @@ -2448,7 +2445,7 @@ included. Used to emit prototypes. Returns the number of required (non-optional) arguments in p. -

    38.10 Writing a Language Module

    +

    40.10 Writing a Language Module

    @@ -2463,7 +2460,7 @@ describes the creation of a minimal Python module. You should be able to extra this to other languages.

    -

    38.10.1 Execution model

    +

    40.10.1 Execution model

    @@ -2473,7 +2470,7 @@ the parsing of command line options, all aspects of code generation are controll different methods of the Language that must be defined by your module.

    -

    38.10.2 Starting out

    +

    40.10.2 Starting out

    @@ -2581,7 +2578,7 @@ that activates your module. For example, swig -python foo.i. The messages from your new module should appear.

    -

    38.10.3 Command line options

    +

    40.10.3 Command line options

    @@ -2640,7 +2637,7 @@ to mark the option as valid. If you forget to do this, SWIG will terminate wit unrecognized command line option error.

    -

    38.10.4 Configuration and preprocessing

    +

    40.10.4 Configuration and preprocessing

    @@ -2689,7 +2686,7 @@ an implementation file python.cxx and a configuration file python.swg.

    -

    38.10.5 Entry point to code generation

    +

    40.10.5 Entry point to code generation

    @@ -2747,7 +2744,7 @@ int Python::top(Node *n) { -

    38.10.6 Module I/O and wrapper skeleton

    +

    40.10.6 Module I/O and wrapper skeleton

    @@ -2761,8 +2758,8 @@ Within SWIG wrappers, there are five main sections. These are (in order)
  • begin: This section is a placeholder for users to put code at the beginning of the C/C++ wrapper file.
  • runtime: This section has most of the common SWIG runtime code.
  • header: This section holds declarations and inclusions from the .i file. -
  • wrapper: This section holds all the wrappering code. -
  • init: This section holds the module initalisation function +
  • wrapper: This section holds all the wrapper code. +
  • init: This section holds the module initialisation function (the entry point for the interpreter).

    @@ -2832,7 +2829,6 @@ int Python::top(Node *n) { Delete(f_header); Delete(f_wrappers); Delete(f_init); - Close(f_begin); Delete(f_begin); return SWIG_OK; @@ -2896,7 +2892,7 @@ functionWrapper : void Shape_y_set(Shape *self,double y) -

    38.10.7 Low-level code generators

    +

    40.10.7 Low-level code generators

    @@ -3005,7 +3001,7 @@ virtual int functionWrapper(Node *n) { /* write typemaps(in) */ .... - /* write constriants */ + /* write constraints */ .... /* Emit the function call */ @@ -3050,7 +3046,7 @@ but without the typemaps, there is still work to do.

    -

    38.10.8 Configuration files

    +

    40.10.8 Configuration files

    @@ -3194,7 +3190,7 @@ politely displays the ignoring language message. -

    38.10.9 Runtime support

    +

    40.10.9 Runtime support

    @@ -3203,7 +3199,7 @@ Discuss the kinds of functions typically needed for SWIG runtime support (e.g. the SWIG files that implement those functions.

    -

    38.10.10 Standard library files

    +

    40.10.10 Standard library files

    @@ -3222,7 +3218,7 @@ The following are the minimum that are usually supported: Please copy these and modify for any new language.

    -

    38.10.11 User examples

    +

    40.10.11 User examples

    @@ -3251,7 +3247,7 @@ during this process, see the section on .

    -

    38.10.12 Test driven development and the test-suite

    +

    40.10.12 Test driven development and the test-suite

    @@ -3310,7 +3306,7 @@ It is therefore essential that the runtime tests are written in a manner that di but error/exception out with an error message on stderr on failure.

    -

    38.10.12.1 Running the test-suite

    +

    40.10.12.1 Running the test-suite

    @@ -3350,10 +3346,10 @@ Note that if a runtime test is available, a message "(with run test)" is display

     $ make check-python-test-suite
     checking python test-suite
    -checking testcase argcargvtest (with run test) under python
    -checking testcase python_autodoc under python
    -checking testcase python_append (with run test) under python
    -checking testcase callback (with run test) under python
    +checking python testcase argcargvtest (with run test)
    +checking python testcase python_autodoc
    +checking python testcase python_append (with run test)
    +checking python testcase callback (with run test)
     

    @@ -3496,7 +3492,13 @@ The syntax for setting environment variables varies from one shell to the next, make ret_by_value.ctest SWIG_FEATURES="-debug-tmsearch" -

    38.10.13 Documentation

    +

    +There is also a special 'errors' test-suite which is a set of regression tests checking SWIG warning and error messages. +It can be run in the same way as the other language test-suites, replacing [lang] with errors, such as make check-errors-test-suite. +The test cases used and the way it works is described in Examples/test-suite/errors/Makefile.in. +

    + +

    40.10.13 Documentation

    @@ -3528,7 +3530,7 @@ Some topics that you'll want to be sure to address include: if available. -

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

    +

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

    @@ -3585,7 +3587,7 @@ should be added should there be an area not already covered by the existing tests.

    -

    38.10.15 Coding style guidelines

    +

    40.10.15 Coding style guidelines

    @@ -3609,7 +3611,7 @@ The generated C/C++ code should also follow this style as close as possible. How should be avoided as unlike the SWIG developers, users will never have consistent tab settings.

    -

    38.11 Debugging Options

    +

    40.11 Debugging Options

    @@ -3636,7 +3638,7 @@ There are various command line options which can aid debugging a SWIG interface The complete list of command line options for SWIG are available by running swig -help.

    -

    38.12 Guide to parse tree nodes

    +

    40.12 Guide to parse tree nodes

    @@ -4044,7 +4046,7 @@ extern "X" { ... } declaration. -

    38.13 Further Development Information

    +

    40.13 Further Development Information

    diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 7a55a4364..93b87a4a4 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -5,7 +5,7 @@ -

    22 SWIG and Go

    +

    23 SWIG and Go

      @@ -43,7 +43,7 @@ the Go programming language see golang.org.

      -

      22.1 Overview

      +

      23.1 Overview

      @@ -55,7 +55,7 @@ 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 under the names 6g, 8g, or 5g. The other +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. @@ -67,7 +67,7 @@ checking and runtime library are not used with Go. This should be borne in mind when reading the rest of the SWIG documentation.

      -

      22.2 Running SWIG with Go

      +

      23.2 Running SWIG with Go

      @@ -76,11 +76,11 @@ default SWIG will generate code for the gc compilers. To generate code for gccgo, you should also use the -gccgo option.

      -

      22.2.1 Additional Commandline Options

      +

      23.2.1 Additional Commandline Options

      -These are the command line options for SWIG's GO module. They can +These are the command line options for SWIG's Go module. They can also be seen by using:

      @@ -94,9 +94,9 @@ swig -go -help --intgo-type-size %lt;s%gt; +-intgosize <s> Set the size for the Go type int. This controls the size - that the C/C++ code expects to see. The %lt;s%gt; argument should + that the C/C++ code expects to see. The <s> argument should be 32 or 64. This option is currently required during the transition from Go 1.0 to Go 1.1, as the size of int on 64-bit x86 systems changes between those releases (from 32 bits to @@ -108,7 +108,7 @@ swig -go -help -gccgo Generate code for gccgo. The default is to generate code for - 6g/8g/5g. + the gc compiler. @@ -118,30 +118,39 @@ swig -go -help --soname %lt;name%gt; +-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. + + + +-soname <name> 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 - 6g/8g/5g; when using gccgo, the equivalent name will be taken from - the -soname option passed to the linker. + 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. + + + +-go-pkgpath <pkgpath> +When generating code for gccgo, set the pkgpath to use. This + corresponds to the -fgo-pkgpath option to gccgo. -go-prefix <prefix> When generating code for gccgo, set the prefix to use. This - corresponds to the -fgo-prefix option to gccgo. - - - --long-type-size <s> -Set the size for the C/C++ type long. This controls - whether long is converted to the Go type int32 - or int64. The <s> argument should be 32 or 64. + corresponds to the -fgo-prefix option to gccgo. + If -go-pkgpath is used, -go-prefix will be + ignored. -

      22.2.2 Go Output Files

      +

      23.2.2 Go Output Files

      When generating Go code, SWIG will generate the following @@ -165,28 +174,59 @@ 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: 6c, 8c, -or 5c. It should then be combined with the compiled MODULE.go using -gopack. This file will not be generated when using gccgo. +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.

    -A typical command sequence would look like this: +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
    +
    + +

    +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: +

    + +
    +% 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
    -% 6g example.go
    -% 6c example_gc.c
    -% gopack grc example.a example.6 example_gc.6
    -% 6g main.go  # your code, not generated by SWIG
    -% 6l main.6
    +% 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
     
    -

    22.3 A tour of basic C/C++ wrapping

    +

    23.3 A tour of basic C/C++ wrapping

    @@ -196,7 +236,7 @@ modifications have to occur. This section briefly covers the essential aspects of this wrapping.

    -

    22.3.1 Go Package Name

    +

    23.3.1 Go Package Name

    @@ -206,7 +246,7 @@ directive. You may override this by using SWIG's -package command line option.

    -

    22.3.2 Go Names

    +

    23.3.2 Go Names

    @@ -238,7 +278,7 @@ followed by that name, and the destructor will be named Delete followed by that name.

    -

    22.3.3 Go Constants

    +

    23.3.3 Go Constants

    @@ -246,7 +286,7 @@ C/C++ constants created via #define or the %constant directive become Go constants, declared with a const declaration. -

    22.3.4 Go Enumerations

    +

    23.3.4 Go Enumerations

    @@ -256,7 +296,7 @@ usual). The values of the enumeration will become variables in Go; code should avoid modifying those variables.

    -

    22.3.5 Go Classes

    +

    23.3.5 Go Classes

    @@ -334,7 +374,7 @@ returns a go interface. If the returned pointer can be null, you can check for this by calling the Swigcptr() method.

    -

    22.3.5.1 Go Class Inheritance

    +

    23.3.5.1 Go Class Inheritance

    @@ -346,7 +386,7 @@ Doing the reverse will require an explicit type assertion, which will be checked dynamically.

    -

    22.3.6 Go Templates

    +

    23.3.6 Go Templates

    @@ -354,7 +394,7 @@ In order to use C++ templates in Go, you must tell SWIG to create wrappers for a particular template instantation. To do this, use the %template directive. -

    22.3.7 Go Director Classes

    +

    23.3.7 Go Director Classes

    @@ -397,7 +437,7 @@ 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++.

    -

    22.3.8 Default Go primitive type mappings

    +

    23.3.8 Default Go primitive type mappings

    @@ -454,12 +494,12 @@ uses a given C/C++ type. long -int32 or int64, depending on -long-type-size +int64 unsigned long -uint32 or uint64, depending on -long-type-size +uint64 @@ -504,7 +544,7 @@ that typemap, or add new values, to control how C/C++ types are mapped into Go types.

    -

    22.3.9 Output arguments

    +

    23.3.9 Output arguments

    Because of limitations in the way output arguments are processed in swig, @@ -557,7 +597,7 @@ void f(char *output);

    -

    22.3.10 Adding additional go code

    +

    23.3.10 Adding additional go code

    Often the APIs generated by swig are not very natural in go, especially if @@ -626,9 +666,31 @@ func (arg SwigcptrWrapped_MyClass) GetAValue() (int, bool) { few, then you might as well define your own struct that includes the swig-wrapped object, instead of adding methods to the swig-generated object.

    -

    This only works if your wrappers do not need to import other go modules. -There is at present no way to insert import statements in the correct place -in swig-generated go. If you need to do that, you must put your go code -in a separate file.

    +

    If you need to import other go packages, you can do this with +%go_import. For example,

    +
    +
    +%go_import("fmt", _ "unusedPackage", rp "renamed/package")
    +
    +%insert(go_wrapper) %{
    +
    +func foo() {
    +  fmt.Println("Some string:", rp.GetString())
    +}
    +
    +// Importing the same package twice is permitted,
    +// Go code will be generated with only the first instance of the import.
    +%go_import("fmt")
    +
    +%insert(go_wrapper) %{
    +
    +func bar() {
    +  fmt.Println("Hello world!")
    +}
    +
    +%}
    +
    +
    + diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 17e3a3fab..4c1126c7f 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -8,7 +8,7 @@ -

    23 SWIG and Guile

    +

    24 SWIG and Guile

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

      This section details guile-specific support in SWIG. -

      23.1 Supported Guile Versions

      +

      24.1 Supported Guile Versions

      @@ -61,7 +61,7 @@ improved performance. This is currently not tested with swig so your mileage may vary. To be safe set environment variable GUILE_AUTO_COMPILE to 0 when using swig generated guile code. -

      23.2 Meaning of "Module"

      +

      24.2 Meaning of "Module"

      @@ -69,7 +69,7 @@ There are three different concepts of "module" involved, defined separately for SWIG, Guile, and Libtool. To avoid horrible confusion, we explicitly prefix the context, e.g., "guile-module". -

      23.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 @@ or the GH API. The GH interface to guile is deprecated. Read more about why in 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. -

      23.4 Linkage

      +

      24.4 Linkage

      @@ -88,7 +88,7 @@ Guile support is complicated by a lack of user community cohesiveness, which manifests in multiple shared-library usage conventions. A set of policies implementing a usage convention is called a linkage. -

      23.4.1 Simple Linkage

      +

      24.4.1 Simple Linkage

      @@ -193,7 +193,7 @@ placed between the define-module form and the SWIG_init via a preprocessor define to avoid symbol clashes. For this case, however, passive linkage is available. -

      23.4.2 Passive Linkage

      +

      24.4.2 Passive Linkage

      Passive linkage is just like simple linkage, but it generates an @@ -203,7 +203,7 @@ package name (see below).

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

      23.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 @@ Newer Guile versions have a shorthand procedure for this:

    -

    23.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 @@ option, SWIG generates an exported module initialization function with an appropriate name. -

    23.4.5 Hobbit4D Linkage

    +

    24.4.5 Hobbit4D Linkage

    @@ -295,7 +295,7 @@ my/lib/libfoo.so.X.Y.Z and friends. This scheme is still very experimental; the (hobbit4d link) conventions are not well understood.

    -

    23.5 Underscore Folding

    +

    24.5 Underscore Folding

    @@ -307,7 +307,7 @@ complained so far. %rename to specify the Guile name of the wrapped functions and variables (see CHANGES). -

    23.6 Typemaps

    +

    24.6 Typemaps

    @@ -399,7 +399,7 @@ constant will appear as a scheme variable. See Features and the %feature directive for info on how to apply the %feature.

    -

    23.7 Representation of pointers as smobs

    +

    24.7 Representation of pointers as smobs

    @@ -420,7 +420,7 @@ representing the expected pointer type. See also If the Scheme object passed was not a SWIG smob representing a compatible pointer, a wrong-type-arg exception is raised. -

    23.7.1 Smobs

    +

    24.7.1 Smobs

    @@ -439,7 +439,7 @@ structure describing this type. If a generated GOOPS module has been loaded, sm the corresponding GOOPS class.

    -

    23.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 @@ is exactly like described in 23.8 Exception Handling +

    24.8 Exception Handling

    @@ -479,7 +479,7 @@ mapping: The default when not specified here is to use "swig-error". See Lib/exception.i for details. -

    23.9 Procedure documentation

    +

    24.9 Procedure documentation

    If invoked with the command-line option -procdoc @@ -514,7 +514,7 @@ like this: typemap argument doc. See Lib/guile/typemaps.i for details. -

    23.10 Procedures with setters

    +

    24.10 Procedures with setters

    For global variables, SWIG creates a single wrapper procedure @@ -542,7 +542,7 @@ struct members, the procedures (struct-member-get pointer) and (struct-member-set pointer value) are not generated. -

    23.11 GOOPS Proxy Classes

    +

    24.11 GOOPS Proxy Classes

    SWIG can also generate classes and generic functions for use with @@ -688,7 +688,7 @@ Notice that <Foo> is used before it is defined. The fix is to just put th %import "foo.h" before the %inline block.

    -

    23.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 @@ guile-modules. For example,

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

    23.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 a8d15a5c2..19d59a4df 100644 --- a/Doc/Manual/Introduction.html +++ b/Doc/Manual/Introduction.html @@ -38,7 +38,7 @@ SWIG is a software development tool that simplifies the task of interfacing different languages to C and C++ programs. In a nutshell, SWIG is a compiler that takes C/C++ declarations and creates -the wrappers needed to access those declarations from other languages including +the wrappers needed to access those declarations from other languages including Perl, Python, Tcl, Ruby, Guile, and Java. SWIG normally requires no modifications to existing code and can often be used to build a usable interface in only a few minutes. Possible applications @@ -49,7 +49,7 @@ of SWIG include:

  • Building interpreted interfaces to existing C programs.
  • Rapid prototyping and application development.
  • Interactive debugging. -
  • Reengineering or refactoring of legacy software into a scripting language components. +
  • Reengineering or refactoring of legacy software into scripting language components.
  • Making a graphical user interface (using Tk for example).
  • Testing of C libraries and programs (using scripts).
  • Building high performance C modules for scripting languages. @@ -98,7 +98,7 @@ of other libraries).
  • Testing is time consuming (the compile/debug cycle).
  • Not easy to reconfigure or customize without recompilation.
  • Modularization can be tricky. -
  • Security concerns (buffer overflow for instance). +
  • Security concerns (buffer overflows for instance).

    To address these limitations, many programmers have arrived at the @@ -345,7 +345,7 @@ not only parses C++, it implements the full C++ type system and it is able to understand C++ semantics. SWIG generates its wrappers with full knowledge of this information. As a result, you will find SWIG to be just as capable of dealing with nasty corner cases as it is in -wrapping simple C++ code. In fact, SWIG is able handle C++ code that +wrapping simple C++ code. In fact, SWIG is able to handle C++ code that stresses the very limits of many C++ compilers. @@ -388,8 +388,8 @@ There is growing support for SWIG in some build tools, for example -

    24 SWIG and Java

    +

    25 SWIG and Java

  • Accessing protected members
  • Common customization features @@ -156,7 +157,7 @@ It covers most SWIG features, but certain low-level details are covered in less

    -

    24.1 Overview

    +

    25.1 Overview

    @@ -191,7 +192,7 @@ Various customisation tips and techniques using SWIG directives are covered. The latter sections cover the advanced techniques of using typemaps for complete control of the wrapping process.

    -

    24.2 Preliminaries

    +

    25.2 Preliminaries

    @@ -211,7 +212,7 @@ This is the commonly used method to load JNI code so your system will more than Android uses Java JNI and also works with SWIG. Please read the Android chapter in conjunction with this one if you are targeting Android.

    -

    24.2.1 Running SWIG

    +

    25.2.1 Running SWIG

    @@ -270,7 +271,7 @@ The following sections have further practical examples and details on how you mi compiling and using the generated files.

    -

    24.2.2 Additional Commandline Options

    +

    25.2.2 Additional Commandline Options

    @@ -307,7 +308,7 @@ swig -java -help Their use will become clearer by the time you have finished reading this section on SWIG and Java.

    -

    24.2.3 Getting the right header files

    +

    25.2.3 Getting the right header files

    @@ -322,7 +323,7 @@ They are usually in directories like this:

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

    -

    24.2.4 Compiling a dynamic module

    +

    25.2.4 Compiling a dynamic module

    @@ -331,8 +332,8 @@ Assuming you have code you need to link to in a file called example.c,

     $ swig -java example.i
    -$ gcc -c example_wrap.c  -I/usr/java/include -I/usr/java/include/solaris
    -$ gcc -c example.c
    +$ gcc -fPIC -c example_wrap.c -I/usr/java/include -I/usr/java/include/solaris
    +$ gcc -fPIC -c example.c
     $ ld -G example_wrap.o example.o -o libexample.so
     
    @@ -359,7 +360,7 @@ The name of the shared library output file is important. 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.

    -

    24.2.5 Using your module

    +

    25.2.5 Using your module

    @@ -394,7 +395,7 @@ $ If it doesn't work have a look at the following section which discusses problems loading the shared library.

    -

    24.2.6 Dynamic linking problems

    +

    25.2.6 Dynamic linking problems

    @@ -481,7 +482,7 @@ The following section also contains some C++ specific linking problems and solut

    -

    24.2.7 Compilation problems and compiling with C++

    +

    25.2.7 Compilation problems and compiling with C++

    @@ -492,8 +493,7 @@ compiler. For example:

     % swig -c++ -java example.i
     % g++ -c -fpic example.cxx
    -% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/
    -j2sdk1.4.1/include/linux
    +% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/j2sdk1.4.1/include/linux
     % g++ -shared example.o example_wrap.o -o libexample.so
     
    @@ -534,7 +534,7 @@ Finally make sure the version of JDK header files matches the version of Java th

    -

    24.2.8 Building on Windows

    +

    25.2.8 Building on Windows

    @@ -543,7 +543,7 @@ You will want to produce a DLL that can be loaded by the Java Virtual Machine. 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.

    -

    24.2.8.1 Running SWIG from Visual Studio

    +

    25.2.8.1 Running SWIG from Visual Studio

    @@ -582,7 +582,7 @@ To run the native code in the DLL (example.dll), make sure that it is in your pa If the library fails to load have a look at Dynamic linking problems.

    -

    24.2.8.2 Using NMAKE

    +

    25.2.8.2 Using NMAKE

    @@ -641,7 +641,7 @@ Of course you may want to make changes for it to work for C++ by adding in the -

    -

    24.3 A tour of basic C/C++ wrapping

    +

    25.3 A tour of basic C/C++ wrapping

    @@ -651,7 +651,7 @@ variables are wrapped with JavaBean type getters and setters and so forth. This section briefly covers the essential aspects of this wrapping.

    -

    24.3.1 Modules, packages and generated Java classes

    +

    25.3.1 Modules, packages and generated Java classes

    @@ -687,7 +687,7 @@ swig -java -package com.bloggs.swig -outdir com/bloggs/swig example.i SWIG won't create the directory, so make sure it exists beforehand.

    -

    24.3.2 Functions

    +

    25.3.2 Functions

    @@ -721,7 +721,7 @@ System.out.println(example.fact(4)); -

    24.3.3 Global variables

    +

    25.3.3 Global variables

    @@ -808,7 +808,7 @@ extern char *path; // Read-only (due to %immutable) -

    24.3.4 Constants

    +

    25.3.4 Constants

    @@ -948,7 +948,7 @@ Or if you decide this practice isn't so bad and your own class implements ex

    -

    24.3.5 Enumerations

    +

    25.3.5 Enumerations

    @@ -962,7 +962,7 @@ The final two approaches use simple integers for each enum item. Before looking at the various approaches for wrapping named C/C++ enums, anonymous enums are considered.

    -

    24.3.5.1 Anonymous enums

    +

    25.3.5.1 Anonymous enums

    @@ -1025,7 +1025,7 @@ As in the case of constants, you can access them through either the module class

    -

    24.3.5.2 Typesafe enums

    +

    25.3.5.2 Typesafe enums

    @@ -1119,7 +1119,7 @@ When upgrading to JDK 1.5 or later, proper Java enums could be used instead, wit The following section details proper Java enum generation.

    -

    24.3.5.3 Proper Java enums

    +

    25.3.5.3 Proper Java enums

    @@ -1172,7 +1172,7 @@ The additional support methods need not be generated if none of the enum items h Simpler Java enums for enums without initializers section.

    -

    24.3.5.4 Type unsafe enums

    +

    25.3.5.4 Type unsafe enums

    @@ -1220,7 +1220,7 @@ Note that unlike typesafe enums, this approach requires users to mostly use diff Thus the upgrade path to proper enums provided in JDK 1.5 is more painful.

    -

    24.3.5.5 Simple enums

    +

    25.3.5.5 Simple enums

    @@ -1239,7 +1239,7 @@ SWIG-1.3.21 and earlier versions wrapped all enums using this approach. 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.

    -

    24.3.6 Pointers

    +

    25.3.6 Pointers

    @@ -1327,7 +1327,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return a NULL pointer if the conversion can't be performed.

    -

    24.3.7 Structures

    +

    25.3.7 Structures

    @@ -1495,7 +1495,7 @@ x.setA(3); // Modify x.a - this is the same as b.f.a -

    24.3.8 C++ classes

    +

    25.3.8 C++ classes

    @@ -1558,7 +1558,7 @@ int bar = Spam.getBar(); -

    24.3.9 C++ inheritance

    +

    25.3.9 C++ inheritance

    @@ -1619,7 +1619,7 @@ Note that Java does not support multiple inheritance so any multiple inheritance A warning is given when multiple inheritance is detected and only the first base class is used.

    -

    24.3.10 Pointers, references, arrays and pass by value

    +

    25.3.10 Pointers, references, arrays and pass by value

    @@ -1674,7 +1674,7 @@ to hold the result and a pointer is returned (Java will release this memory when the returned object's finalizer is run by the garbage collector).

    -

    24.3.10.1 Null pointers

    +

    25.3.10.1 Null pointers

    @@ -1698,7 +1698,7 @@ For spam1 and spam4 above the Java null gets translat The converse also occurs, that is, NULL pointers are translated into null Java objects when returned from a C/C++ function.

    -

    24.3.11 C++ overloaded functions

    +

    25.3.11 C++ overloaded functions

    @@ -1813,7 +1813,7 @@ void spam(unsigned short); // Ignored -

    24.3.12 C++ default arguments

    +

    25.3.12 C++ default arguments

    @@ -1856,7 +1856,7 @@ Further details on default arguments and how to restore this approach are given

    -

    24.3.13 C++ namespaces

    +

    25.3.13 C++ namespaces

    @@ -1946,7 +1946,7 @@ If the resulting use of the nspace feature and hence packages results in a proxy 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.

    -

    24.3.14 C++ templates

    +

    25.3.14 C++ templates

    @@ -1995,7 +1995,7 @@ Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter.

    -

    24.3.15 C++ Smart Pointers

    +

    25.3.15 C++ Smart Pointers

    @@ -2079,7 +2079,7 @@ Foo f = p.__deref__(); // Returns underlying Foo * -

    24.4 Further details on the generated Java classes

    +

    25.4 Further details on the generated Java classes

    @@ -2094,7 +2094,7 @@ Finally enum classes are covered. First, the crucial intermediary JNI class is considered.

    -

    24.4.1 The intermediary JNI class

    +

    25.4.1 The intermediary JNI class

    @@ -2214,7 +2214,7 @@ If name is the same as modulename then the module class name g from modulename to modulenameModule.

    -

    24.4.1.1 The intermediary JNI class pragmas

    +

    25.4.1.1 The intermediary JNI class pragmas

    @@ -2296,7 +2296,7 @@ For example, let's change the intermediary JNI class access to just the default 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.

    -

    24.4.2 The Java module class

    +

    25.4.2 The Java module class

    @@ -2327,7 +2327,7 @@ example.egg(new Foo()); 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.

    -

    24.4.2.1 The Java module class pragmas

    +

    25.4.2.1 The Java module class pragmas

    @@ -2378,7 +2378,7 @@ See The intermediary JNI class pragmas secti

    -

    24.4.3 Java proxy classes

    +

    25.4.3 Java proxy classes

    @@ -2454,7 +2454,7 @@ int y = f.spam(5, new Foo()); -

    24.4.3.1 Memory management

    +

    25.4.3.1 Memory management

    @@ -2616,7 +2616,7 @@ and

    -

    24.4.3.2 Inheritance

    +

    25.4.3.2 Inheritance

    @@ -2732,7 +2732,7 @@ However, true cross language polymorphism can be achieved using the 24.4.3.3 Proxy classes and garbage collection +

    25.4.3.3 Proxy classes and garbage collection

    @@ -2815,7 +2815,7 @@ The section on Java typemaps details how to specify See the How to Handle Java Finalization's Memory-Retention Issues article for alternative approaches to managing memory by avoiding finalizers altogether.

    -

    24.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 +2937,7 @@ For example: Compatibility note: The generation of this additional parameter did not occur in versions prior to SWIG-1.3.30.

    -

    24.4.3.5 Single threaded applications and thread safety

    +

    25.4.3.5 Single threaded applications and thread safety

    @@ -3025,7 +3025,7 @@ for (int i=0; i<100000; i++) { -

    24.4.4 Type wrapper classes

    +

    25.4.4 Type wrapper classes

    @@ -3112,7 +3112,7 @@ public static void spam(SWIGTYPE_p_int x, SWIGTYPE_p_int y, int z) { ... } -

    24.4.5 Enum classes

    +

    25.4.5 Enum classes

    @@ -3121,7 +3121,7 @@ The Enumerations section discussed these but om The following sub-sections detail the various types of enum classes that can be generated.

    -

    24.4.5.1 Typesafe enum classes

    +

    25.4.5.1 Typesafe enum classes

    @@ -3205,7 +3205,7 @@ The swigValue method is used for marshalling in the other direction. The toString method is overridden so that the enum name is available.

    -

    24.4.5.2 Proper Java enum classes

    +

    25.4.5.2 Proper Java enum classes

    @@ -3283,7 +3283,7 @@ These needn't be generated if the enum being wrapped does not have any initializ Simpler Java enums for enums without initializers section describes how typemaps can be used to achieve this.

    -

    24.4.5.3 Type unsafe enum classes

    +

    25.4.5.3 Type unsafe enum classes

    @@ -3314,7 +3314,7 @@ public final class Beverage { -

    24.5 Cross language polymorphism using directors

    +

    25.5 Cross language polymorphism using directors

    @@ -3336,7 +3336,7 @@ The upshot is that C++ classes can be extended in Java and from C++ these extens 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.

    -

    24.5.1 Enabling directors

    +

    25.5.1 Enabling directors

    @@ -3404,7 +3404,7 @@ public: -

    24.5.2 Director classes

    +

    25.5.2 Director classes

    @@ -3431,7 +3431,7 @@ If the correct implementation is in Java, the Java API is used to call the metho

    -

    24.5.3 Overhead and code bloat

    +

    25.5.3 Overhead and code bloat

    @@ -3449,7 +3449,7 @@ This situation can be optimized by selectively enabling director methods (using

    -

    24.5.4 Simple directors example

    +

    25.5.4 Simple directors example

    @@ -3514,7 +3514,7 @@ DirectorDerived::upcall_method() invoked. -

    24.5.5 Director threading issues

    +

    25.5.5 Director threading issues

    @@ -3534,7 +3534,7 @@ Macros can be defined on the commandline when compiling your C++ code, or altern -

    24.5.6 Director performance tuning

    +

    25.5.6 Director performance tuning

    @@ -3555,8 +3555,315 @@ However, if all director methods are expected to usually be overridden by Java s 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

    -

    24.6 Accessing protected members

    + +

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

    + +

    +Converting Java exceptions into C++ exceptions can be done in two different ways using +the director:except feature. +In the simplest approach, a code block is attached to each director method to +handle the mapping of Java exceptions into C++ exceptions. +

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

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

    + +

    +Using the above approach to +write handlers for a large number of methods will require +repetitive duplication of the director:except feature code. +To mitigate this, an alternative approach is provided via typemaps in a +fashion analagous to +the "throws" typemap. The +"throws" typemap provides an approach to automatically map all the C++ +exceptions listed in a method's defined exceptions (either from +a C++ exception specification or a %catches +feature) into Java exceptions. +The "directorthrows" typemap provides the inverse mapping and should contain +code to convert a suitably matching Java exception into a C++ exception. +The example below converts a Java java.lang.IndexOutOfBoundsException exception +to the typemap's type, that is std::out_of_range: + +

    +
    +%typemap(directorthrows) std::out_of_range %{
    +  if (Swig::ExceptionMatches(jenv, $error, "java/lang/IndexOutOfBoundsException")) {
    +    throw std::out_of_range(Swig::JavaExceptionMessage(jenv, $error).message());
    +  }
    +%}
    +
    +
    + +

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

    + +
    +
    +%feature("director:except") %{
    +   jthrowable $error = jenv->ExceptionOccurred();
    +   if ($error) {
    +     jenv->ExceptionClear();
    +     $directorthrowshandlers
    +     throw Swig::DirectorException(jenv, $error);
    +   }
    +%}
    +
    +
    + +

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

    + +

    +Consider the following director method: +

    + +
    +
    +  ...
    +  virtual void doSomething(int index) throw (std::out_of_range);
    +  ...
    +
    +
    + +

    +When combined with the default director:except feature and the "directorthrows" typemap above, +the resulting code generated in the director method after calling up to Java will be: +

    + +
    +
    +jthrowable swigerror = jenv->ExceptionOccurred();
    +if (swigerror) {
    +  jenv->ExceptionClear();
    +  if (Swig::ExceptionMatches(jenv, swigerror, "java/lang/IndexOutOfBoundsException")) {
    +    throw std::out_of_range(Swig::JavaExceptionMessage(jenv, swigerror).message());
    +  }
    +  
    +  throw Swig::DirectorException(jenv, swigerror);
    +}
    +
    +
    + +

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

    + +

    Because the default code generation maps any unhandled Java exceptions to +Swig::DirectorException, any director methods that have exception +specifications may cause program termination. To simply ignore +unexpected exceptions, the default handling can be changed with: +

    + +
    +
    +%feature("director:except") %{
    +   jthrowable $error = jenv->ExceptionOccurred();
    +   if ($error) {
    +     jenv->ExceptionClear();
    +     $directorthrowshandlers
    +     return $null; // exception is ignored
    +   }
    +%}
    +
    +
    + +

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

    + +
    +
    +   throw std::runtime_error(Swig::JavaExceptionMessage(jenv, $error).message());
    +
    +
    + +

    In more complex situations, a separate director:except feature +may need to be attached to specific methods. +

    + +

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

    +
    +%module(directors="1") example
    +
    +%{
    +  #include <string>
    +  #include <stdexcept>
    +%}
    +
    +// Define exceptions in header section using std::runtime_error
    +%define DEFINE_EXCEPTION(NAME)
    +%{
    +  namespace MyNS {
    +    struct NAME : public std::runtime_error { NAME(const std::string &what) : runtime_error(what) {} };
    +  }
    +%}
    +%enddef
    +
    +// Expose C++ exceptions as Java Exceptions by changing the Java base class and providing a getMessage()
    +%define DECLARE_EXCEPTION(NAME)
    +%typemap(javabase) MyNS::NAME "java.lang.Exception";
    +%rename(getMessage) MyNS::NAME::what;
    +namespace MyNS {
    +  struct NAME {
    +    NAME(const std::string& what);
    +    const char * what();
    +  };
    +}
    +%enddef
    +
    +DEFINE_EXCEPTION(ExceptionA)
    +DEFINE_EXCEPTION(ExceptionB)
    +DEFINE_EXCEPTION(Unexpected)
    +
    +// Mark three methods to map director thrown exceptions.
    +%feature("director:except") MyClass::meth1(int);
    +%feature("director:except") MyClass::meth2;
    +%feature("director:except") meth3;
    +
    +%typemap(directorthrows) MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected %{
    +  if (Swig::ExceptionMatches(jenv, $error, "$packagepath/$javaclassname"))
    +    throw $1_type(Swig::JavaExceptionMessage(jenv, $error).message());
    +%}
    +
    +DECLARE_EXCEPTION(ExceptionA)
    +DECLARE_EXCEPTION(ExceptionB)
    +DECLARE_EXCEPTION(Unexpected)
    +
    +%catches(MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected) MyClass::meth2();
    +
    +%inline {
    +  class MyClass {
    +  public:
    +    virtual void meth1(int x) throw(MyNS::ExceptionA, MyNS::ExceptionB) = 0;
    +    virtual void meth2() = 0;   /* throws MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected */
    +    virtual void meth3(float x) throw(MyNS::Unexpected) = 0;
    +    virtual ~MyClass() {}
    +  };
    +}
    +
    +
    + +

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

    + +

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

    + +
    +
    +%javaexception("Exception") MyClass::myMethod %{
    +  try {
    +    $action
    +  } catch (Swig::DirectorException &e) {
    +    // raise/throw the Java exception that originally caused the DirectorException
    +    e.raiseJavaException(jenv);
    +    return $null;
    +  }
    +%}
    +
    +
    + +

    +See the Exception handling with %exception and %javaexception +section for more on converting C++ exceptions to Java exceptions. +

    + +

    25.6 Accessing protected members

    @@ -3652,7 +3959,7 @@ class MyProtectedBase extends ProtectedBase -

    24.7 Common customization features

    +

    25.7 Common customization features

    @@ -3664,7 +3971,7 @@ be awkward. This section describes some common SWIG features that are used to improve the interface to existing C/C++ code.

    -

    24.7.1 C/C++ helper functions

    +

    25.7.1 C/C++ helper functions

    @@ -3730,7 +4037,7 @@ hard to implement. It is possible to improve on this using Java code, typemaps, customization features as covered in later sections, but sometimes helper functions are a quick and easy solution to difficult cases.

    -

    24.7.2 Class extension with %extend

    +

    25.7.2 Class extension with %extend

    @@ -3793,7 +4100,7 @@ Vector(2,3,4) in any way---the extensions only show up in the Java interface.

    -

    24.7.3 Exception handling with %exception and %javaexception

    +

    25.7.3 Exception handling with %exception and %javaexception

    @@ -3952,7 +4259,7 @@ to raise exceptions. See the SWIG Library ch The typemap example Handling C++ exception specifications as Java exceptions provides further exception handling capabilities.

    -

    24.7.4 Method access with %javamethodmodifiers

    +

    25.7.4 Method access with %javamethodmodifiers

    @@ -3978,7 +4285,7 @@ protected static void protect_me() { -

    24.8 Tips and techniques

    +

    25.8 Tips and techniques

    @@ -3988,7 +4295,7 @@ strings and arrays. This chapter discusses the common techniques for solving these problems.

    -

    24.8.1 Input and output parameters using primitive pointers and references

    +

    25.8.1 Input and output parameters using primitive pointers and references

    @@ -4162,7 +4469,7 @@ void foo(Bar *OUTPUT); will not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

    -

    24.8.2 Simple pointers

    +

    25.8.2 Simple pointers

    @@ -4228,7 +4535,7 @@ System.out.println("3 + 4 = " + result); See the SWIG Library chapter for further details.

    -

    24.8.3 Wrapping C arrays with Java arrays

    +

    25.8.3 Wrapping C arrays with Java arrays

    @@ -4295,7 +4602,7 @@ Please be aware that the typemaps in this library are not efficient as all the e There is an alternative approach using the SWIG array library and this is covered in the next section.

    -

    24.8.4 Unbounded C Arrays

    +

    25.8.4 Unbounded C Arrays

    @@ -4440,7 +4747,7 @@ well suited for applications in which you need to create buffers, package binary data, etc.

    -

    24.8.5 Binary data vs Strings

    +

    25.8.5 Binary data vs Strings

    @@ -4484,7 +4791,7 @@ len: 5 data: 68 69 0 6a 6b -

    24.8.6 Overriding new and delete to allocate from Java heap

    +

    25.8.6 Overriding new and delete to allocate from Java heap

    @@ -4601,7 +4908,7 @@ model and use these functions in place of malloc and free in your own code.

    -

    24.9 Java typemaps

    +

    25.9 Java typemaps

    @@ -4622,7 +4929,7 @@ Before proceeding, it should be stressed that typemaps are not a required part of using SWIG---the default wrapping behavior is enough in most cases. Typemaps are only used if you want to change some aspect of the generated code. -

    24.9.1 Default primitive type mappings

    +

    25.9.1 Default primitive type mappings

    @@ -4774,7 +5081,7 @@ However, the mappings allow the full range of values for each C type from Java.

    -

    24.9.2 Default typemaps for non-primitive types

    +

    25.9.2 Default typemaps for non-primitive types

    @@ -4789,7 +5096,7 @@ So in summary, the C/C++ pointer to non-primitive types is cast into the 64 bit The Java type is either the proxy class or type wrapper class.

    -

    24.9.3 Sixty four bit JVMs

    +

    25.9.3 Sixty four bit JVMs

    @@ -4802,7 +5109,7 @@ Unfortunately it won't of course hold true for JNI code.

    -

    24.9.4 What is a typemap?

    +

    25.9.4 What is a typemap?

    @@ -4925,7 +5232,7 @@ int c = example.count('e',"Hello World"); -

    24.9.5 Typemaps for mapping C/C++ types to Java types

    +

    25.9.5 Typemaps for mapping C/C++ types to Java types

    @@ -5185,7 +5492,7 @@ These are listed below: -

    24.9.6 Java typemap attributes

    +

    25.9.6 Java typemap attributes

    @@ -5231,7 +5538,7 @@ The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes. Note that when the 'pre' or 'post' attributes are specified and the associated type is used in a constructor, a constructor helper function is generated. This is necessary as the Java proxy constructor wrapper makes a call to a support constructor using a this call. In Java the this call must be the first statement in the constructor body. The constructor body thus calls the helper function and the helper function instead makes the JNI call, ensuring the 'pre' code is called before the JNI call is made. There is a Date marshalling example showing 'pre', 'post' and 'pgcppname' attributes in action.

    -

    24.9.7 Java special variables

    +

    25.9.7 Java special variables

    @@ -5367,7 +5674,7 @@ can be wrapped with the Java equivalent, that is, static inner proxy classes.

    -$jniinput, $javacall and $packagepath
    +$error, $jniinput, $javacall and $packagepath
    These special variables are used in the directors typemaps. See Director specific typemaps for details.

    @@ -5382,7 +5689,7 @@ This special variable expands to the intermediary class name. Usually this is th unless the jniclassname attribute is specified in the %module directive.

    -

    24.9.8 Typemaps for both C and C++ compilation

    +

    25.9.8 Typemaps for both C and C++ compilation

    @@ -5419,7 +5726,7 @@ If you do not intend your code to be targeting both C and C++ then your typemaps

    -

    24.9.9 Java code typemaps

    +

    25.9.9 Java code typemaps

    @@ -5657,7 +5964,7 @@ to make the method and constructor public: -

    24.9.10 Director specific typemaps

    +

    25.9.10 Director specific typemaps

    @@ -5701,6 +6008,10 @@ is the package name passed from the SWIG command line and $javaclassname-package commandline option is not used to specify the package, then '$packagepath/' will be removed from the resulting output JNI field descriptor. Do not forget the terminating ';' for JNI field descriptors starting with 'L'. If the ';' is left out, Java will generate a "method not found" runtime error. +Note that the $packagepath substitution always uses the path separator '/' when expanded. +The $javaclassname expansion can be confusing as it is normally expanded using the '.' separator. +However, $javaclassname is expanded using the path separator '/' in typemap's "descriptor" attribute +as well as in the "directorthrows" typemap.

    @@ -5796,6 +6107,40 @@ The target method is the method in the Java proxy class which overrides the virt +

    %typemap(directorthrows)

    +
    + +

    +Conversion of Java exceptions to C++ exceptions in director method's exception handling. +This typemap is expected to test the $error special variable for a matching Java exception +and if successful convert and throw it into a C++ exception given by the typemap's type. +The $error special variable is of type jthrowable and is +substituted with a unique variable name in the generated code. +

    + +

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

    + +
    +
    +%typemap(directorthrows) std::out_of_range %{
    +  if (Swig::ExceptionMatches(jenv, $error, "java/lang/IndexOutOfBoundsException")) {
    +    throw std::out_of_range(Swig::JavaExceptionMessage(jenv, $error).message());
    +  }
    +%}
    +
    +
    + +

    +The utility function Swig::ExceptionMatches +and class Swig::JavaExceptionMessage are helpers available when using directors and are described +in the Java Exceptions from Directors section. +

    + +
    +

    %typemap(javapackage)

    @@ -5883,7 +6228,7 @@ The basic strategy here is to provide a default package typemap for the majority
    -

    24.10 Typemap Examples

    +

    25.10 Typemap Examples

    @@ -5893,7 +6238,7 @@ the SWIG library.

    -

    24.10.1 Simpler Java enums for enums without initializers

    +

    25.10.1 Simpler Java enums for enums without initializers

    @@ -5972,7 +6317,7 @@ This would be done by using the original versions of these typemaps in "enums.sw

    -

    24.10.2 Handling C++ exception specifications as Java exceptions

    +

    25.10.2 Handling C++ exception specifications as Java exceptions

    @@ -6097,7 +6442,7 @@ We could alternatively have used %rename to rename what() into

    -

    24.10.3 NaN Exception - exception handling for a particular type

    +

    25.10.3 NaN Exception - exception handling for a particular type

    @@ -6252,7 +6597,7 @@ If we were a martyr to the JNI cause, we could replace the succinct code within If we had, we would have put it in the "in" typemap which, like all JNI and Java typemaps, also supports the 'throws' attribute.

    -

    24.10.4 Converting Java String arrays to char **

    +

    25.10.4 Converting Java String arrays to char **

    @@ -6396,7 +6741,7 @@ Lastly the "jni", "jtype" and "jstype" typemaps are also required to specify what Java types to use.

    -

    24.10.5 Expanding a Java object to multiple arguments

    +

    25.10.5 Expanding a Java object to multiple arguments

    @@ -6478,7 +6823,7 @@ example.foo(new String[]{"red", "green", "blue", "white"}); -

    24.10.6 Using typemaps to return arguments

    +

    25.10.6 Using typemaps to return arguments

    @@ -6524,7 +6869,7 @@ int spam(double a, double b, double *out1, double *out2) { *out1 = a*10.0; *out2 = b*100.0; return status; -}; +} %} /* @@ -6596,7 +6941,7 @@ $ java runme 1 12.0 340.0 -

    24.10.7 Adding Java downcasts to polymorphic return types

    +

    25.10.7 Adding Java downcasts to polymorphic return types

    @@ -6802,7 +7147,7 @@ SWIG usually generates code which constructs the proxy classes using Java code a Note that the JNI code above uses a number of string lookups to call a constructor, whereas this would not occur using byte compiled Java code.

    -

    24.10.8 Adding an equals method to the Java classes

    +

    25.10.8 Adding an equals method to the Java classes

    @@ -6846,7 +7191,7 @@ System.out.println("foo1? " + foo1.equals(foo2)); -

    24.10.9 Void pointers and a common Java base class

    +

    25.10.9 Void pointers and a common Java base class

    @@ -6905,7 +7250,7 @@ This example contains some useful functionality which you may want in your code.

  • It also has a function which effectively implements a cast from the type of the proxy/type wrapper class to a void pointer. This is necessary for passing a proxy class or a type wrapper class to a function that takes a void pointer. -

    24.10.10 Struct pointer to pointer

    +

    25.10.10 Struct pointer to pointer

    @@ -7085,7 +7430,7 @@ The C functional interface has been completely morphed into an object-oriented i the Butler class would behave much like any pure Java class and feel more natural to Java users.

    -

    24.10.11 Memory management when returning references to member variables

    +

    25.10.11 Memory management when returning references to member variables

    @@ -7208,7 +7553,7 @@ public class Bike { Note the addReference call.

    -

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

    +

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

    @@ -7324,7 +7669,7 @@ The 'javacode' typemap simply adds in the specified code into the Java proxy cla -

    24.10.13 Date marshalling using the javain typemap and associated attributes

    +

    25.10.13 Date marshalling using the javain typemap and associated attributes

    @@ -7501,7 +7846,7 @@ A few things to note: -

    24.11 Living with Java Directors

    +

    25.11 Living with Java Directors

    @@ -7682,10 +8027,10 @@ public abstract class UserVisibleFoo extends Foo {

  • -

    24.12 Odds and ends

    +

    25.12 Odds and ends

    -

    24.12.1 JavaDoc comments

    +

    25.12.1 JavaDoc comments

    @@ -7741,7 +8086,7 @@ public class Barmy { -

    24.12.2 Functional interface without proxy classes

    +

    25.12.2 Functional interface without proxy classes

    @@ -7802,7 +8147,7 @@ All destructors have to be called manually for example the delete_Foo(foo) -

    24.12.3 Using your own JNI functions

    +

    25.12.3 Using your own JNI functions

    @@ -7852,7 +8197,7 @@ This directive is only really useful if you want to mix your own hand crafted JN

    -

    24.12.4 Performance concerns and hints

    +

    25.12.4 Performance concerns and hints

    @@ -7873,7 +8218,7 @@ However, you will have to be careful about memory management and make sure that This method normally calls the C++ destructor or free() for C code.

    -

    24.12.5 Debugging

    +

    25.12.5 Debugging

    @@ -7895,7 +8240,7 @@ The -verbose:jni and -verbose:gc are also useful options for monitoring code beh

    -

    24.13 Java Examples

    +

    25.13 Java Examples

    diff --git a/Doc/Manual/Javascript.html b/Doc/Manual/Javascript.html new file mode 100644 index 000000000..fc24e29c7 --- /dev/null +++ b/Doc/Manual/Javascript.html @@ -0,0 +1,976 @@ + + + + + + + + +

    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

    + + +

    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. +Javascript has gone beyond being a browser-based scripting language and with node.js, it is also used as a backend development language.

    +

    Native Javascript extensions can be used for applications that embed a web-browser view or that embed a Javascript engine (such as node.js). Extending a general purpose web-browser is not possible as this would be a severe security issue.

    +

    SWIG Javascript currently supports JavascriptCore, the Javascript engine used by Safari/Webkit, and v8, which is used by Chromium and node.js.

    +

    WebKit is a modern browser implementation available as open-source which can be embedded into an application. +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.1 Running SWIG

    + + +

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

    +
    +
    +%module example
    +%{
    +#include "example.h"
    +%}
    +int gcd(int x, int y);
    +extern double Foo;
    +
    +

    To build a Javascript module, run SWIG using the -javascript option and a desired target engine -jsc, -v8, or -node. The generator for node is essentially delegating to the v8 generator and adds some necessary preprocessor definitions.

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

    If building a C++ extension, add the -c++ option:

    +
    +
    +$ swig -c++ -javascript -jsc 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

    +
    +
    +bool example_initialize(JSGlobalContextRef context, JSObjectRef *exports)
    +
    +

    and for v8:

    +
    +
    +void example_initialize(v8::Handle<v8::Object> exports)
    +
    +

    +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

    + + +

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

    +

    The default interpreter is node.js as it is available on all platforms and convenient to use.

    +

    Running the examples with JavascriptCore requires libjavascriptcoregtk-1.0 to be installed, e.g., under Ubuntu with

    +
    +
    +$ sudo apt-get install libjavascriptcoregtk-1.0-dev
    +
    +

    Running with V8 requires libv8:

    +
    +
    +$ sudo apt-get install libv8-dev
    +
    +

    Examples can be run using

    +
    +
    +$ make check-javascript-examples ENGINE=jsc
    +
    +

    ENGINE can be node, jsc, or v8.

    +

    The test-suite can be run using

    +
    +
    +$ make check-javascript-test-suite ENGINE=jsc
    +
    + +

    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.

    + +
      +
    • Default optional arguments do not work for all targeted interpreters

    • +
    • Multiple output arguments do not work for JSC

    • +
    • C89 incompatibily: the JSC generator might still generate C89 violating code

    • +
    • long long is not supported

    • +
    • %native is not supported

    • +
    • Javascript callbacks are not supported

    • +
    • 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.

    + +

    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

    + + +

    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.

    +
    +
    +$ sudo add-apt-repository ppa:chris-lea/node.js
    +$ sudo apt-get update
    +$ sudo apt-get install nodejs
    +
    +

    As v8 is written in C++ and comes as a C++ library it is crucial to compile your module using the same compiler flags as used for building v8. To make things easier, node.js provides a build tool called node-gyp.

    +

    You have to install it using npm:

    +
    +
    +$ sudo npm install -g node-gyp
    +
    +

    node-gyp expects a configuration file named binding.gyp which is basically in JSON format and conforms to the same format that is used with Google's build-tool gyp.

    +

    binding.gyp:

    +
    +
    +{
    +  "targets": [
    +    {
    +      "target_name": "example",
    +      "sources": [ "example.cxx", "example_wrap.cxx" ]
    +    }
    +  ]
    +}
    +
    +

    First create the wrapper using SWIG:

    +
    +
    +$ swig -javascript -node -c++ example.cxx
    +
    +

    Then run node-gyp

    +
    +
    +$ node-gyp
    +
    +

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

    +
    +
    +require("./build/Release/example")
    +
    +

    A more detailed explanation is given in the Examples section.

    + +

    26.3.1.1 Troubleshooting

    + + +
      +
    • 'module' object has no attribute 'script_main'
    • +
    +

    This error happens when gyp is installed as a distribution package. It seems to be outdated. Removing it resolves the problem.

    +
    +
    +$ sudo apt-get remove gyp
    +
    + +

    26.3.2 Embedded Webkit

    + + +

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

    + +

    26.3.2.1 OSX

    + + +

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

    +

    An integration of a native extension 'example' would look like this:

    +
    +
    +#import "appDelegate.h"
    +
    +extern bool example_initialize(JSGlobalContextRef context, JSObjectRef* exports);
    +
    +
    +@implementation ExampleAppDelegate
    +
    +@synthesize webView;
    +
    +- (void)addGlobalObject:(JSContextRef) context:(NSString *)objectName:(JSObjectRef) theObject {
    +  JSObjectRef global = JSContextGetGlobalObject(context);
    +  JSStringRef objectJSName = JSStringCreateWithCFString( (CFStringRef) objectName )
    +  if ( objectJSName != NULL ) {
    +    JSObjectSetProperty(context, global, objectJSName, theObject, kJSPropertyAttributeReadOnly, NULL);
    +    JSStringRelease( objectJSName );
    +  }
    +}
    +
    +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    +
    +  // Start a webview with the bundled index.html file
    +  NSString *path = [[NSBundle mainBundle] bundlePath];
    +  NSString *url =  [NSString stringWithFormat: @"file://%@/Contents/Assets/index.html", path];
    +
    +  WebFrame *webframe = [webView mainFrame];
    +  JSGlobalContextRef context = [webframe globalContext];
    +
    +  JSObjectRef example;
    +  example_initialize(context, &example);
    +  [self addGlobalObject:context:@"example":example]
    +
    +  JSObjectSetProperty(context, global, JSStringRef propertyName, example, JSPropertyAttributes attributes, NULL);
    +
    +  [ [webView mainFrame] loadRequest:
    +    [NSURLRequest requestWithURL: [NSURL URLWithString:url] ]
    +  ];
    +}
    +
    +@end
    +
    + +

    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.

    +

    An integration of a native extension 'example' would look like this:

    +
    +
    +#include <gtk/gtk.h>
    +#include <webkit/webkit.h>
    +
    +extern bool example_initialize(JSGlobalContextRef context);
    +
    +int main(int argc, char* argv[])
    +{
    +    // Initialize GTK+
    +    gtk_init(&argc, &argv);
    +
    +    ...
    +
    +    // Create a browser instance
    +    WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
    +    WebFrame *webframe = webkit_web_view_get_main_frame(webView);
    +    JSGlobalContextRef context = webkit_web_frame_get_global_context(webFrame);
    +    JSObjectRef global = JSContextGetGlobalObject(context);
    +
    +    JSObjectRef exampleModule;
    +    example_initialize(context, &exampleModule);
    +    JSStringRef jsName = JSStringCreateWithUTF8CString("example");
    +    JSObjectSetProperty(context, global, jsName, exampleModule, kJSPropertyAttributeReadOnly, NULL);
    +    JSStringRelease(jsName);
    +
    +    ...
    +
    +    // Load a web page into the browser instance
    +    webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/");
    +
    +    ...
    +
    +    // Run the main GTK+ event loop
    +    gtk_main();
    +
    +    return 0;
    +}
    +
    + +

    26.3.3 Creating Applications with node-webkit

    + + +

    To get started with node-webkit there is a very informative set of wiki pages.

    +

    Similar to node.js, node-webkit is started from command line within a node.js project directory. +Native extensions are created in the very same way as for node.js, except that a customized gyp derivate has to be used: nw-gyp. +

    + +

    +A simple example would have the following structure: +

    + +
    +
    +- package.json
    +- app.html
    +- app.js
    +- node_modules
    +  / example
    +  ... (as known from node.js)
    +
    +
    + +

    +The configuration file essentially conforms to node.js syntax. +It has some extras to configure node-webkit. See the Manifest specification for more details. +

    + +

    + package.json: +

    +
    +
    +{
    +  "name": "example"
    +  "main": "app.html"
    +  "window": {
    +    "show": true,
    +    "width": 800,
    +    "height": 600
    +  }
    +}
    +
    + +

    +The 'main' property of package.json specifies a web-page to be rendered in +the main window.

    + +

    + app.html: +

    + +
    +
    +<html>
    +  <head>
    +    <script src="app.js"></script>
    +  </head>
    +  <body>
    +    <div>
    +      The greatest common divisor of
    +      <span id="x"></span> and
    +      <span id="y"></span> is
    +      <span id="z"></span>.
    +    </div>
    +  </body>
    +</html>
    +
    + +

    +As known from node.js one can use require to load javascript modules. +Additionally, node-webkit provides an API that allows to manipulate the window's menu, +open new windows, and many more things. +

    + +

    + app.js: +

    + +
    +
    window.onload = function() {
    +  var example = require("example");
    +  var x = 18;
    +  var y = 24;
    +  var z = example.gcd(x,y);
    +  document.querySelector('#x').innerHTML = x;
    +  document.querySelector('#y').innerHTML = y;
    +  document.querySelector('#z').innerHTML = z;
    +};
    +
    + +

    26.4 Examples

    + + +

    Some basic examples are shown here in more detail.

    + +

    26.4.1 Simple

    + + +

    The common example simple looks like this:

    +
    +
    +/* File : example.i */
    +%module example
    +
    +%inline %{
    +extern int    gcd(int x, int y);
    +extern double Foo;
    +%}
    +
    +

    To make this available as a node extension a binding.gyp has to be created:

    +
    +
    +{
    +  "targets": [
    +    {
    +      "target_name": "example",
    +      "sources": [ "example.cxx", "example_wrap.cxx" ]
    +    }
    +  ]
    +}
    +
    +

    Then node-gyp is used to build the extension:

    +
    +
    +$ node-gyp configure build
    +
    +

    From a 'nodejs` application the extension would be used like this:

    +
    +
    +// import the extension via require
    +var example = require("./build/Release/example");
    +
    +// calling the global method
    +var x = 42;
    +var y = 105;
    +var g = example.gcd(x,y);
    +
    +// Accessing the globak variable
    +var f = example.Foo;
    +example.Foo = 3.1415926;
    +
    +

    First the module example is loaded from the previously built extension. Global methods and variables are available in the scope of the module.

    + +

    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

    + + +

    The common example class defines three classes, Shape, Circle, and Square:

    +
    +
    +class Shape {
    +public:
    +  Shape() {
    +    nshapes++;
    +  }
    +  virtual ~Shape() {
    +    nshapes--;
    +  };
    +  double  x, y;
    +  void    move(double dx, double dy);
    +  virtual double area(void) = 0;
    +  virtual double perimeter(void) = 0;
    +  static  int nshapes;
    +};
    +
    +class Circle : public Shape {
    +private:
    +  double radius;
    +public:
    +  Circle(double r) : radius(r) { };
    +  virtual double area(void);
    +  virtual double perimeter(void);
    +};
    +
    +class Square : public Shape {
    +private:
    +  double width;
    +public:
    +  Square(double w) : width(w) { };
    +  virtual double area(void);
    +  virtual double perimeter(void);
    +};
    +
    +

    Circle and Square inherit from Shape. Shape has a static variable nshapes, a function move that can't be overridden (non-virtual), and two abstract functions area and perimeter (pure virtual) that must be overridden by the sub-classes.

    +

    A nodejs extension is built the same way as for the simple example.

    +

    In Javascript it can be used as follows:

    +
    +
    +var example = require("./build/Release/example");
    +
    +// local aliases for convenience
    +var Shape = example.Shape;
    +var Circle = example.Circle;
    +var Square = example.Square;
    +
    +// creating new instances using the 'new' operator
    +var c = new Circle(10);
    +var s = new Square(10);
    +
    +// accessing a static member
    +Shape.nshapes;
    +
    +// accessing member variables
    +c.x = 20;
    +c.y = 30;
    +s.x = -10;
    +s.y = 5;
    +
    +// calling some methods
    +c.area();
    +c.perimeter();
    +s.area();
    +s.perimeter();
    +
    +// instantiation of Shape is not permitted
    +new Shape();
    +
    +

    Running these commands in an interactive node shell results in the following output:

    +
    +
    +$ node -i
    +& var example = require("./build/Release/example");
    +undefined
    +& var Shape = example.Shape;
    +undefined
    +& var Circle = example.Circle;
    +undefined
    +& var Square = example.Square;
    +undefined
    +& var c = new Circle(10);
    +undefined
    +& var s = new Square(10);
    +undefined
    +& Shape.nshapes;
    +2
    +& c.x = 20;
    +20
    +& c.y = 30;
    +30
    +& s.x = -10;
    +-10
    +& s.y = 5;
    +5
    +& c.area();
    +314.1592653589793
    +& c.perimeter();
    +62.83185307179586
    +& s.area();
    +100
    +& s.perimeter();
    +40
    +& c.move(40, 40)
    +undefined
    +& c.x
    +60
    +& c.y
    +70
    +& new Shape()
    +Error: Class Shape can not be instantiated
    +at repl:1:2
    +at REPLServer.self.eval (repl.js:110:21)
    +at Interface.<anonymous> (repl.js:239:12)
    +at Interface.EventEmitter.emit (events.js:95:17)
    +at Interface._onLine (readline.js:202:10)
    +at Interface._line (readline.js:531:8)
    +at Interface._ttyWrite (readline.js:760:14)
    +at ReadStream.onkeypress (readline.js:99:10)
    +at ReadStream.EventEmitter.emit (events.js:98:17)
    +at emitKey (readline.js:1095:12)
    +
    +

    +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

    + + +

    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

    + + +

    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:

    +
    +
    +// module wide defines
    +
    +#define NAME "name"
    +...
    +
    +// ###############################
    +// #  Helper class declarations
    +
    +class JSEmitterState { ... };
    +
    +class Template { ... };
    +
    +// ###############################
    +// # JSEmitter declaration
    +
    +class JSEmitter { ... };
    +
    +// Emitter factory declarations
    +
    +JSEmitter *swig_javascript_create_JSCEmitter();
    +JSEmitter *swig_javascript_create_V8Emitter();
    +
    +// ###############################
    +// # Javascript module
    +
    +// Javascript module declaration
    +
    +class JAVASCRIPT:public Language { ... };
    +
    +// Javascript module implementation
    +
    +int JAVASCRIPT::functionWrapper(Node *n) { ... }
    +...
    +
    +// Module factory implementation
    +
    +static Language *new_swig_javascript() { ... }
    +
    +extern "C" Language *swig_javascript(void) { ... }
    +
    +// ###############################
    +// # JSEmitter base implementation
    +
    +JSEmitter::JSEmitter() { ... }
    +
    +Template JSEmitter::getTemplate(const String *name) { ... }
    +...
    +
    +// ###############################
    +// # JSCEmitter
    +
    +// JSCEmitter declaration
    +
    +class JSCEmitter: public JSEmitter { ... };
    +
    +// JSCEmitter implementation
    +
    +JSCEmitter::JSCEmitter() { ... }
    +
    +void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static) { ... }
    +...
    +
    +// JSCEmitter factory
    +
    +JSEmitter *swig_javascript_create_JSCEmitter() { ... }
    +
    +
    +// ###############################
    +// # V8Emitter
    +
    +// V8Emitter declaration
    +
    +class V8Emitter: public JSEmitter { ... };
    +
    +// V8Emitter implementation
    +
    +V8Emitter::V8Emitter() { ... }
    +
    +int V8Emitter::initialize(Node *n) { ... }
    +
    +// V8Emitter factory
    +
    +JSEmitter *swig_javascript_create_V8Emitter() { ... }
    +
    +
    +// ###############################
    +// # Helper implementation (JSEmitterState, Template)
    +
    +JSEmitterState::JSEmitterState() { ... }
    +...
    +
    +Template::Template(const String *code_) { ... }
    +...
    +
    + +

    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.

    +

    To track the originating code template for generated code you can run

    +
    +
    +$ swig -javascript -jsc -debug-codetemplates
    +
    +

    which wraps generated code with a descriptive comment

    +
    +
    +/* begin fragment("template_name") */
    +
    +...generated code ...
    +
    +/* end fragment("template_name") */
    +
    +

    The Template class is used like this:

    +
    +
    +Template t_register = getTemplate("jsv8_register_static_variable");
    +t_register.replace("$jsparent", state.clazz(NAME_MANGLED))
    +    .replace("$jsname", state.variable(NAME))
    +    .replace("$jsgetter", state.variable(GETTER))
    +    .replace("$jssetter", state.variable(SETTER))
    +    .trim().
    +    print(f_init_static_wrappers);
    +
    +

    A code template is registered with the JSEmitter via fragment(name, "template"), e.g.,

    +
    +
    +%fragment ("jsc_variable_declaration", "templates")
    +%{
    +  {"$jsname", $jsgetter, $jssetter, kJSPropertyAttributeNone},
    +%}
    +
    +

    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

    + + +

    The Javascript module delegates code generation to a JSEmitter instance. The following extract shows the essential interface:

    +
    +
    +class JSEmitter {
    +  ...
    +
    +  /**
    +   * Opens output files and temporary output DOHs.
    +   */
    +  virtual int initialize(Node *n);
    +
    +  /**
    +   * Writes all collected code into the output file(s).
    +   */
    +  virtual int dump(Node *n) = 0;
    +
    +  /**
    +   * Cleans up all open output DOHs.
    +   */
    +  virtual int close() = 0;
    +
    +  ...
    +
    +  /**
    +   * Invoked at the beginning of the classHandler.
    +   */
    +  virtual int enterClass(Node *);
    +
    +  /**
    +   * Invoked at the end of the classHandler.
    +   */
    +  virtual int exitClass(Node *) {
    +    return SWIG_OK;
    +  };
    +
    +  /**
    +   * Invoked at the beginning of the variableHandler.
    +   */
    +  virtual int enterVariable(Node *);
    +
    +  /**
    +   * Invoked at the end of the variableHandler.
    +   */
    +  virtual int exitVariable(Node *) {
    +    return SWIG_OK;
    +  };
    +
    +  /**
    +   * Invoked at the beginning of the functionHandler.
    +   */
    +  virtual int enterFunction(Node *);
    +
    +  /**
    +   * Invoked at the end of the functionHandler.
    +   */
    +  virtual int exitFunction(Node *) {
    +    return SWIG_OK;
    +  };
    +
    +  /**
    +   * Invoked by functionWrapper callback after call to Language::functionWrapper.
    +   */
    +  virtual int emitWrapperFunction(Node *n);
    +
    +  /**
    +   * Invoked from constantWrapper after call to Language::constantWrapper.
    +   **/
    +  virtual int emitConstant(Node *n);
    +
    +  /**
    +   * Registers a given code snippet for a given key name.
    +   *
    +   * This method is called by the fragmentDirective handler
    +   * of the JAVASCRIPT language module.
    +   **/
    +  int registerTemplate(const String *name, const String *code);
    +
    +  /**
    +   * Retrieve the code template registered for a given name.
    +   */
    +  Template getTemplate(const String *name);
    +
    +  State &getState();
    +
    +  ...
    +
    +}
    +
    +

    The module calls initialize, dump, and close from within the top method:

    +
    +
    +int JAVASCRIPT::top(Node *n) {
    +  emitter->initialize(n);
    +
    +  Language::top(n);
    +
    +  emitter->dump(n);
    +  emitter->close();
    +
    +  return SWIG_OK;
    +}
    +
    +

    The methods enterClass and exitClass are called from within the classHandler method:

    +
    +
    +int JAVASCRIPT::classHandler(Node *n) {
    +
    +  emitter->enterClass(n);
    +  Language::classHandler(n);
    +  emitter->exitClass(n);
    +
    +  return SWIG_OK;
    +}
    +
    +

    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

    + + +

    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.

    +
    +
    +class JSEmitterState {
    +
    +public:
    +
    +  JSEmitterState();
    +
    +  ~JSEmitterState();
    +
    +  DOH *global();
    +
    +  DOH *global(const char* key, DOH *initial = 0);
    +
    +  DOH *clazz(bool reset = false);
    +
    +  DOH *clazz(const char* key, DOH *initial = 0);
    +
    +  DOH *function(bool reset = false);
    +
    +  DOH *function(const char* key, DOH *initial = 0);
    +
    +  DOH *variable(bool reset = false);
    +
    +  DOH *variable(const char* key, DOH *initial = 0);
    +
    +  static int IsSet(DOH *val);
    +
    +  ...
    +};
    +
    +

    When entering a scope, such as in enterClass, the corresponding state is reset and new data is stored:

    +
    +
    +state.clazz(RESET);
    +state.clazz(NAME, Getattr(n, "sym:name"));
    +
    +

    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

    + + +

    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.

    +
    +
    +void script_exception_to_string(JSContextRef js_context,JSValueRef exception_value_ref,char* return_error_string, int return_error_string_max_length)
    +{
    +  JSObjectRef exception_object;
    +  JSValueRef value_ref;
    +  JSStringRef jsstring_property_name = NULL;
    +  JSValueRef temporary_exception = NULL;
    +  JSStringRef js_return_string = NULL;
    +  size_t bytes_needed;
    +  char* c_result_string = NULL;
    +  exception_object = JSValueToObject(js_context, exception_value_ref, NULL);
    +
    +  /* source url */
    +  strcpy(return_error_string,"[");
    +  jsstring_property_name = JSStringCreateWithUTF8CString("sourceURL");
    +  value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
    +  JSStringRelease(jsstring_property_name);
    +  js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
    +  bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
    +  c_result_string = (char*)calloc(bytes_needed, sizeof(char));
    +  JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
    +  JSStringRelease(js_return_string);
    +  strncat(return_error_string, c_result_string, return_error_string_max_length-1);
    +  free(c_result_string);
    +
    +  strncat(return_error_string, ":", return_error_string_max_length-1);
    +
    +  /* line number */
    +
    +  jsstring_property_name = JSStringCreateWithUTF8CString("line");
    +  value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
    +  JSStringRelease(jsstring_property_name);
    +  js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
    +  bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
    +  c_result_string = (char*)calloc(bytes_needed, sizeof(char));
    +  JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
    +  JSStringRelease(js_return_string);
    +  strncat(return_error_string, c_result_string, return_error_string_max_length-1);
    +  free(c_result_string);
    +
    +  strncat(return_error_string, "]", return_error_string_max_length-1);
    +
    +  /* error message */
    +
    +  jsstring_property_name = JSStringCreateWithUTF8CString("message");
    +  value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
    +  JSStringRelease(jsstring_property_name);
    +  if(NULL == value_ref)
    +  {
    +    strncat(return_error_string, "Unknown Error", return_error_string_max_length-1);
    +  }
    +  else
    +  {
    +    js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
    +    bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
    +    c_result_string = (char*)calloc(bytes_needed, sizeof(char));
    +    JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
    +    JSStringRelease(js_return_string);
    +    strncat(return_error_string, c_result_string, return_error_string_max_length-1);
    +    free(c_result_string);
    +  }
    +}
    +
    + +

    It would be used in the following way:

    +
    +
    +if(js_exception)
    +{
    +  char return_error_string[256];
    +  script_exception_to_string(js_context, js_exception, return_error_string, 256);
    +  printf("Compile error is %s", return_error_string);
    +}
    +
    + + + diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 1ae3c77a3..740988e71 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -6,7 +6,7 @@ -

    8 SWIG library

    +

    9 SWIG library

  • Utility Libraries
      @@ -58,7 +59,7 @@ Alternative libraries provide similar functionality. Please read this chapter carefully if you used the old libraries.

      -

      8.1 The %include directive and library search path

      +

      9.1 The %include directive and library search path

      @@ -90,7 +91,7 @@ Set the environment variable to hold an alternative library directory. The directories that are searched are displayed when using -verbose commandline option.

      -

      8.2 C Arrays and Pointers

      +

      9.2 C Arrays and Pointers

      @@ -102,7 +103,7 @@ pointers as class-like objects. Since these functions provide direct access to memory, their use is potentially unsafe and you should exercise caution.

      -

      8.2.1 cpointer.i

      +

      9.2.1 cpointer.i

      @@ -318,7 +319,7 @@ In this example, the function int_to_uint() would be used to cast type Note: When working with simple pointers, typemaps can often be used to provide more seamless operation.

      -

      8.2.2 carrays.i

      +

      9.2.2 carrays.i

      @@ -496,7 +497,7 @@ you should consider using a special array object rather than a bare pointer. used with types of char or char *.

      -

      8.2.3 cmalloc.i

      +

      9.2.3 cmalloc.i

      @@ -657,7 +658,7 @@ Now, in a script:

  • -

    8.2.4 cdata.i

    +

    9.2.4 cdata.i

    @@ -759,7 +760,7 @@ char *cdata_name(type* ptr, int nitems) Clearly they are unsafe.

    -

    8.3 C String Handling

    +

    9.3 C String Handling

    @@ -779,7 +780,7 @@ morality. The modules in this section provide basic functionality for manipulating raw C strings.

    -

    8.3.1 Default string handling

    +

    9.3.1 Default string handling

    @@ -820,7 +821,7 @@ interpreter and lead to a crash). Furthermore, the default behavior does not work well with binary data. Instead, strings are assumed to be NULL-terminated.

    -

    8.3.2 Passing binary data

    +

    9.3.2 Passing binary data

    @@ -862,7 +863,7 @@ In the wrapper function, the passed string will be expanded to a pointer and len The (char *STRING, int LENGTH) multi-argument typemap is also available in addition to (char *STRING, size_t LENGTH).

    -

    8.3.3 Using %newobject to release memory

    +

    9.3.3 Using %newobject to release memory

    @@ -903,7 +904,7 @@ however, you may need to provide your own "newfree" typemap for other types. See Object ownership and %newobject for more details.

    -

    8.3.4 cstring.i

    +

    9.3.4 cstring.i

    @@ -1363,7 +1364,7 @@ structure or class instead. -

    8.4 STL/C++ Library

    +

    9.4 STL/C++ Library

    @@ -1383,6 +1384,7 @@ The following table shows which C++ classes are supported and the equivalent SWI SWIG Interface library file + std::auto_ptr memory std_auto_ptr.i std::deque deque std_deque.i std::list list std_list.i std::map map std_map.i @@ -1400,7 +1402,7 @@ Please look for the library files in the appropriate language library directory.

    -

    8.4.1 std::string

    +

    9.4.1 std::string

    @@ -1484,7 +1486,7 @@ void foo(string s, const String &t); // std_string typemaps still applie -

    8.4.2 std::vector

    +

    9.4.2 std::vector

    @@ -1663,7 +1665,7 @@ if you want to make their head explode. details and the public API exposed to the interpreter vary.

    -

    8.4.3 STL exceptions

    +

    9.4.3 STL exceptions

    @@ -1713,13 +1715,28 @@ The %exception directive can be used by placing the following code befo Any thrown STL exceptions will then be gracefully handled instead of causing a crash.

    -

    8.4.4 shared_ptr smart pointer

    +

    9.4.4 shared_ptr smart pointer

    -Some target languages have support for handling the widely used boost::shared_ptr smart pointer. -This smart pointer is also available as std::tr1::shared_ptr before it becomes fully standardized as std::shared_ptr. -The boost_shared_ptr.i library provides support for boost::shared_ptr and std_shared_ptr.i provides support for std::shared_ptr, but if the following macro is defined as shown, it can be used for std::tr1::shared_ptr: +Some target languages have support for handling the shared_ptr reference counted smart pointer. +This smart pointer is available in the standard C++11 library as std::shared_ptr. +It was also in TR1 as std::tr1::shared_ptr before it was fully standardized. +Support for the widely used boost::shared_ptr is also available. +

    + +

    +In order to use std::shared_ptr, the std_shared_ptr.i library file should be included: +

    + +
    +
    +%include <std_shared_ptr.i>
    +
    +
    + +

    +The pre-standard std::tr1::shared_ptr can be used by including the following macro before including the std_shared_ptr.i library file:

    @@ -1729,6 +1746,16 @@ The boost_shared_ptr.i library provides support for boost::shared_p
    +

    +In order to use boost::shared_ptr, the boost_shared_ptr.i library file should be included: +

    + +
    +
    +%include <boost_shared_ptr.i>
    +
    +
    +

    You can only use one of these variants of shared_ptr in your interface file at a time. and all three variants must be used in conjunction with the %shared_ptr(T) macro, @@ -1872,12 +1899,64 @@ Adding the missing %shared_ptr macros will fix this: +

    Note: There is currently no support for %shared_ptr and the director feature. - -

    8.5 Utility Libraries

    +

    -

    8.5.1 exception.i

    +

    9.4.5 auto_ptr smart pointer

    + + +

    +While std::auto_ptr is deprecated in C++11, some existing code may +still be using it, so SWIG provides limited support for this class: +std_auto_ptr.i defines the typemaps which apply to the functions +returning objects of this type. Any other use of std_auto_ptr.i is not +directly supported. +

    + +

    +A typical example of use would be +

    +
    +
    +%include <std_auto_ptr.i>
    +
    +%auto_ptr(Klass)
    +%inline %{
    +class Klass {
    +public:
    +  // Factory function creating objects of this class:
    +  static std::auto_ptr<Klass> Create(int value) {
    +    return std::auto_ptr<Klass>(new Klass(value));
    +  }
    +
    +  int getValue() const { return m_value; }
    +
    +private:
    +  DerivedIntValue(int value) : m_value(value) {}
    +  int m_value;
    +};
    +%}
    +
    +
    + +

    +The returned objects can be used naturally from the target language, e.g. from +C#: +

    + +
    +
    +Klass k = Klass.Create(17);
    +int value = k.getValue();
    +
    +
    + +

    9.5 Utility Libraries

    + + +

    9.5.1 exception.i

    diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 01ff3a3ec..0b8d47846 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -6,7 +6,7 @@ -

    25 SWIG and Common Lisp

    +

    27 SWIG and Common Lisp

      @@ -41,7 +41,7 @@ Lisp, Common Foreign Function Interface(CFFI), CLisp and UFFI foreign function interfaces.

      -

      25.1 Allegro Common Lisp

      +

      27.1 Allegro Common Lisp

      @@ -50,7 +50,7 @@ here

      -

      25.2 Common Foreign Function Interface(CFFI)

      +

      27.2 Common Foreign Function Interface(CFFI)

      @@ -77,7 +77,7 @@ swig -cffi -module module-name file-name files and the various things which you can do with them.

      -

      25.2.1 Additional Commandline Options

      +

      27.2.1 Additional Commandline Options

      @@ -118,11 +118,11 @@ swig -cffi -help -

      25.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 - files. To illustrate the use of it, lets assume that we have a + files. To illustrate the use of it, let's assume that we have a file named test.h with the following C code:
      @@ -392,7 +392,7 @@ The feature intern_function ensures that all C names are
       
       
      -

      25.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 +568,7 @@ If you have any questions, suggestions, patches, etc., related to CFFI module feel free to contact us on the SWIG mailing list, and also please add a "[CFFI]" tag in the subject line. -

      25.2.4 Inserting user code into generated files

      +

      27.2.4 Inserting user code into generated files

      @@ -608,7 +608,7 @@ Note that the block %{ ... %} is effectively a shortcut for

      -

      25.3 CLISP

      +

      27.3 CLISP

      @@ -638,7 +638,7 @@ swig -clisp -module module-name file-name interface file for the CLISP module. The CLISP module tries to produce code which is both human readable and easily modifyable.

      -

      25.3.1 Additional Commandline Options

      +

      27.3.1 Additional Commandline Options

      @@ -671,7 +671,7 @@ and global variables will be created otherwise only definitions for
      -

      25.3.2 Details on CLISP bindings

      +

      27.3.2 Details on CLISP bindings

      @@ -795,7 +795,7 @@ struct bar {

    -

    25.4 UFFI

    +

    27.4 UFFI

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 88d26f385..61f19be68 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -6,7 +6,7 @@ -

    26 SWIG and Lua

    +

    28 SWIG and Lua

  • Typemaps -
  • Writing typemaps +
  • Writing typemaps
  • Customization of your Bindings @@ -73,14 +82,14 @@ Lua is an extension programming language designed to support general procedural 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

    -

    26.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 supports eLua and works with eLua 0.8. SWIG generated code for eLua has been tested on Stellaris ARM Cortex-M3 LM3S and Infineon TriCore. +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'.

    -

    26.2 Running SWIG

    +

    28.2 Running SWIG

    @@ -128,7 +137,7 @@ $ swig -lua -eluac example.i 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.

    -

    26.2.1 Additional command line options

    +

    28.2.1 Additional command line options

    @@ -159,9 +168,17 @@ swig -lua -help Do not register the module name as a global variable but return the module table from calls to require. + + -no-old-metatable-bindings + Disable backward compatibility: old-style binding names generations and a few other things. Explanations are included in appropriate later sections. + + + -squash-bases + Squashes symbols from all inheritance tree of a given class into itself. Emulates pre-SWIG3.0 inheritance. Insignificantly speeds things up, but increases memory consumption. + -

    26.2.2 Compiling and Linking and Interpreter

    +

    28.2.2 Compiling and Linking and Interpreter

    @@ -232,7 +249,7 @@ LUALIB_API int ( luaopen_mod )(lua_State *L ); More information on building and configuring eLua can be found here: http://www.eluaproject.net/doc/v0.8/en_building.html

    -

    26.2.3 Compiling a dynamic module

    +

    28.2.3 Compiling a dynamic module

    @@ -240,8 +257,8 @@ Most, but not all platforms support the dynamic loading of modules (Windows &

     $ swig -lua example.i -o example_wrap.c
    -$ gcc -I/usr/include/lua -c example_wrap.c -o example_wrap.o
    -$ gcc -c example.c -o example.o
    +$ gcc -fPIC -I/usr/include/lua -c example_wrap.c -o example_wrap.o
    +$ gcc -fPIC -c example.c -o example.o
     $ gcc -shared -I/usr/include/lua -L/usr/lib/lua example_wrap.o example.o -o example.so
     

    @@ -300,7 +317,7 @@ Is quite obvious (Go back and consult the Lua documents on how to enable loadlib -

    26.2.4 Using your module

    +

    28.2.4 Using your module

    @@ -318,19 +335,19 @@ $ ./my_lua >

  • -

    26.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.

    -

    26.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.

    -

    26.3.2 Functions

    +

    28.3.2 Functions

    @@ -349,7 +366,10 @@ creates a built-in function example.fact(n) that works exactly like you >

    -To avoid name collisions, SWIG create a Lua table which it keeps all the functions and global variables in. It is possible to copy the functions out of this and into the global environment with the following code. This can easily overwrite existing functions, so this must be used with care. +To avoid name collisions, SWIG create a Lua table which keeps all the functions, constants, classes and global variables in. +It is possible to copy the functions, constants and classes (but not variables) out of this and into the global environment with the following code. +This can easily overwrite existing functions, so this must be used with care. +This option is considered deprecated and will be removed in the near future.

     > for k,v in pairs(example) do _G[k]=v end
    @@ -368,7 +388,7 @@ It is also possible to rename the module with an assignment.
     24
     
    -

    26.3.3 Global variables

    +

    28.3.3 Global variables

    @@ -456,7 +476,7 @@ If you have used the -eluac option for your eLua module, you will have In general, functions of the form "variable_get()" and "variable_set()" are automatically generated by SWIG for use with -eluac.

    -

    26.3.4 Constants and enums

    +

    28.3.4 Constants and enums

    @@ -490,7 +510,64 @@ If you're using eLua and have used -elua or -eluac to generate > print(example.const.SCONST) Hello World -

    26.3.5 Pointers

    + +

    28.3.4.1 Constants/enums and classes/structures

    + + +

    +Enums are exported into a class table. For example, given some enums: +

    +
    %module example
    +enum Days { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };
    +struct Test {
    +    enum { TEST1 = 10, TEST2 = 20 };
    +#ifdef __cplusplus // There are no static members in C
    +    static const int ICONST = 12;
    +#endif
    +};
    +
    +

    +There is a slight difference in behaviour wrapping C and C++ code due to the different scoping rules of C and C++. +The wrapped C++ code is used as follows from Lua code: +

    +
    +> print(example.SUNDAY)
    +0
    +> print(example.Test.TEST1)
    +10
    +> print(example.Test.ICONST)
    +12
    +
    + +

    Enums within a C struct are in the global namespace and are used as follows from Lua

    +
    +> print(example.SUNDAY)
    +0
    +> -- See the difference here
    +> print(example.TEST1)
    +10
    +
    + +

    +Compatibility Note: Versions of SWIG prior to SWIG-3.0.0 did not generate the class table members above. +There is no change in the C wrappers, but +the following code was the only way to access these constants/enums when wrapping C++ member constants: +

    +
    +> print(example.Test_TEST1)
    +10
    +> print(example.Test_ICONST)
    +12
    +
    +

    +The old-style bindings are still generated in addition to the new ones. +If the -no-old-metatable-bindings option is used, then these old-style bindings are not generated. +

    +

    +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

    @@ -528,7 +605,7 @@ Lua enforces the integrity of its userdata, so it is virtually impossible to cor nil -

    26.3.6 Structures

    +

    28.3.6 Structures

    @@ -551,7 +628,7 @@ is used as follows:

    Similar access is provided for unions and the data members of C++ classes.
    -C structures are created using a function new_Point(), but for C++ classes are created using just the name Point(). +C structures can be created using a function new_Point(), and both C structures and C++ classes can be created using just the name Point().

    If you print out the value of p in the above example, you will see something like this: @@ -632,7 +709,7 @@ For eLua with the -eluac option, structure manipulation has to be perfo 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)

    -

    26.3.7 C++ classes

    +

    28.3.7 C++ classes

    @@ -676,12 +753,12 @@ public: };

    -In Lua, the static members can be accessed as follows: +In Lua, C++ static members can be accessed as follows:

    -> example.Spam_foo()            -- calling Spam::foo()
    -> a=example.Spam_bar            -- reading Spam::bar 
    -> example.Spam_bar=b            -- writing to Spam::bar
    +> example.Spam.foo()            -- calling Spam::foo()
    +> a=example.Spam.bar            -- reading Spam::bar 
    +> example.Spam.bar=b            -- writing to Spam::bar
     

    It is not (currently) possible to access static members of an instance: @@ -692,7 +769,22 @@ It is not (currently) possible to access static members of an instance: -- does NOT work -

    26.3.8 C++ inheritance

    +

    +Compatibility Note: In versions prior to SWIG-3.0.0 only the following names would work: +

    + +
    +> example.Spam_foo()            -- calling Spam::foo()
    +> a=example.Spam_bar            -- reading Spam::bar 
    +> example.Spam_bar=b            -- writing to Spam::bar
    +
    + +

    +Both style names are generated by default now. +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

    @@ -717,7 +809,7 @@ then the function spam() accepts a Foo pointer or a pointer to any clas

    It is safe to use multiple inheritance with SWIG.

    -

    26.3.9 Pointers, references, values, and arrays

    +

    28.3.9 Pointers, references, values, and arrays

    @@ -748,7 +840,7 @@ Foo spam7();

    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.

    -

    26.3.10 C++ overloaded functions

    +

    28.3.10 C++ overloaded functions

    @@ -834,7 +926,7 @@ Please refer to the "SWIG and C++" chapter for more information about overloadin

    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.

    -

    26.3.11 C++ operators

    +

    28.3.11 C++ operators

    @@ -898,10 +990,10 @@ The current list of operators which can be overloaded (and the alternative funct

  • __sub__ operator-
  • __mul__ operator *
  • __div__ operator/ -
  • __neg__ unary minus +
  • __unm__ unary minus
  • __call__ operator() (often used in functor classes)
  • __pow__ the exponential fn (no C++ equivalent, Lua uses ^) -
  • __concat__ the concatenation operator (SWIG maps C++'s ~ to Lua's ..) +
  • __concat__ the concatenation operator (Lua's ..)
  • __eq__ operator==
  • __lt__ operator<
  • __le__ operator<= @@ -945,8 +1037,30 @@ It is also possible to overload the operator[], but currently this cann void __setitem__(int i,double d); // i is the index, d is the data }; - -

    26.3.12 Class extension with %extend

    +

    +C++ operators are mapped to Lua predefined metafunctions. Class inherits from its bases the following list of metafunctions ( thus inheriting the folloging +operators and pseudo-operators):

    +
      +
    • __add__ +
    • __sub__ +
    • __mul__ +
    • __div__ +
    • __unm__ +
    • __mod__ +
    • __call__ +
    • __pow__ +
    • __concat__ +
    • __eq__ +
    • __lt__ +
    • __le__ +
    • __len__ +
    • __getitem__ +
    • __setitem__ +
    • __tostring used internally by Lua for tostring() function. __str__ is mapped to this function +
    +

    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

    @@ -981,7 +1095,7 @@ Now we extend it with some new code return tmp; } bool operator==(const Complex& c) - { return ($self->re()==c.re() && $self->im()==c.im();} + { return ($self->re()==c.re() && $self->im()==c.im());} };

    @@ -1002,7 +1116,7 @@ true 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).

    -

    26.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,

    @@ -1026,7 +1140,7 @@ char *foo();

    This will release the allocated memory.

    -

    26.3.14 C++ templates

    +

    28.3.14 C++ templates

    @@ -1061,7 +1175,7 @@ In Lua:

    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.

    -

    26.3.15 C++ Smart Pointers

    +

    28.3.15 C++ Smart Pointers

    @@ -1113,7 +1227,7 @@ If you ever need to access the underlying pointer returned by operator->( > f = p:__deref__() -- Returns underlying Foo * -

    26.3.16 C++ Exceptions

    +

    28.3.16 C++ Exceptions

    @@ -1256,13 +1370,164 @@ and the "Exception handling add exception specification to functions or globally (respectively).

    +

    28.3.17 Namespaces

    -

    26.4 Typemaps

    + +

    +Since SWIG-3.0.0 C++ namespaces are supported via the %nspace feature. +

    +

    Namespaces are mapped into Lua tables. Each of those tables contains names that were defined within appropriate namespace. Namespaces structure (a.k.a nested namespaces) is preserved. Consider the following C++ code: +

    +
    %module example
    +%nspace MyWorld::Nested::Dweller;
    +%nspace MyWorld::World;
    +
    +int module_function() { return 7; }
    +int module_variable = 9;
    +
    +namespace MyWorld {
    +  class World {
    +  public:
    +    World() : world_max_count(9) {}
    +    int create_world() { return 17; }
    +    const int world_max_count; // = 9
    +  };
    +  namespace Nested {
    +    class Dweller {
    +      public:
    +        enum Gender { MALE = 0, FEMALE = 1 };
    +        static int count() { return 19; }
    +    };
    +  }
    +}
    +
    + +

    +Now, from Lua usage is as follows: +

    + +
    +> print(example.module_function())
    +7
    +> print(example.module_variable)
    +9
    +> print(example.MyWorld.World():create_world())
    +17
    +> print(example.MyWorld.World.world_max_count)
    +9
    +> print(example.MyWorld.Nested.Dweller.MALE)
    +0
    +> print(example.MyWorld.Nested.Dweller.count())
    +19
    +>
    +
    +

    28.3.17.1 Compatibility Note

    + + +

    +If SWIG is running in a backwards compatible way, i.e. without the -no-old-metatable-bindings option, then additional old-style names are generated (notice the underscore): +

    +
    +9
    +> print(example.MyWorld.Nested.Dweller_MALE)
    +0
    +> print(example.MyWorld.Nested.Dweller_count())
    +11
    +>
    +
    + + +

    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 +to generate additional names for static functions, class static constants and class enums. +Those names are in a form $classname_$symbolname and are added to the scope surrounding the class. +If %nspace is enabled, then class namespace is taken as scope. If there is no namespace, or %nspace is disabled, +then module is considered a class namespace.

    +

    Consider the following C++ code

    +
    %module example
    +%nspace MyWorld::Test;
    +namespace MyWorld {
    +class Test {
    +  public:
    +  enum { TEST1 = 10, TEST2 }
    +  static const int ICONST = 12;
    +};
    +class Test2 {
    +  public:
    +  enum { TEST3 = 20, TEST4 }
    +  static const int ICONST2 = 23;
    +}
    +
    +

    When in backward compatible mode, in addition to the usual names, the following ones will be generated (notice the underscore):

    +
    +9
    +> print(example.MyWorld.Test_TEST1) -- Test has %nspace enabled
    +10
    +> print(example.MyWorld.Test_ICONST) -- Test has %nspace enabled
    +12
    +> print(example.Test2_TEST3) -- Test2 doesn't have %nspace enabled
    +20
    +> print(example.Test2_ICONST2) -- Test2 doesn't have %nspace enabled
    +23
    +>
    +
    +

    There is a slight difference with enums when in C mode. As per C standard, enums from C structures are exported to +surrounding scope without any prefixing. Pretending that Test2 is a struct, not class, that would be:

    +
    +> print(example.TEST3) -- NOT Test2_TEST3
    +20
    +>
    +
    + +

    28.3.17.3 Inheritance

    + + +

    The internal organization of inheritance has changed. +Consider the following C++ code:

    +
    %module example
    +class Base {
    +  public:
    +  int base_func()
    +};
    +class Derived : public Base {
    +  public:
    +  int derived_func()
    +}
    +
    +

    Lets assume for a moment that class member functions are stored in .fn table. Previously, when classes +were exported to Lua during module initialization, for every derived class all service tables ST(i.e. ".fn") +were squashed and added to corresponding derived class ST: Everything from .fn table of class Base +was copied to .fn table of class Derived and so on. This was a recursive procedure, so in the end the whole +inheritance tree of derived class was squashed into derived class.

    +

    That means that any changes done to class Base after module initialization wouldn't affect class Derived:

    +
    +base = example.Base()
    +der = example.Derived()
    +> print(base.base_func)
    +function: 0x1367940
    +> getmetatable(base)[".fn"].new_func = function (x) return x -- Adding new function to class Base (to class, not to an instance!)
    +> print(base.new_func) -- Checking this function
    +function
    +> print(der.new_func) -- Wouldn't work. Derived doesn't check Base any more.
    +nil
    +>
    +
    +

    This behaviour was changed. Now unless -squash-bases option is provided, Derived store a list of it's bases and if some symbol is not found in it's own service tables +then its bases are searched for it. Option -squash-bases will effectively return old behaviour. +

    +> print(der.new_func) -- Now it works
    +function
    +>
    +
    + +

    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

    -

    26.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:

    @@ -1290,7 +1555,7 @@ Received an integer : 6 720 -

    26.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.

    @@ -1343,7 +1608,7 @@ void swap(int *sx, int *sy);

    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).

    -

    26.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 @@ -1407,7 +1672,7 @@ and Lua tables to be 1..N, (the indexing follows the norm for the language). In

    Note: SWIG also can support arrays of pointers in a similar manner.

    -

    26.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:

    @@ -1441,7 +1706,7 @@ int Create_Math(iMath** pptr); // its creator (assume it mallocs) ptr=nil -- the iMath* will be GC'ed as normal -

    26.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.

    @@ -1450,7 +1715,7 @@ ptr=nil -- the iMath* will be GC'ed as normal

    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).

    -

    26.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.

    @@ -1463,7 +1728,7 @@ ptr=nil -- the iMath* will be GC'ed as normal (the syntax for the typecheck is different from the typemap, see typemaps for details).
  • -

    26.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.

    @@ -1512,7 +1777,7 @@ This macro, when called within the context of a SWIG wrapped function, will disp
    Similar to SWIG_fail_arg, except that it will display the swig_type_info information instead.
    -

    26.6 Customization of your Bindings

    +

    28.6 Customization of your Bindings

    @@ -1521,7 +1786,7 @@ This section covers adding of some small extra bits to your module to add the la -

    26.6.1 Writing your own custom wrappers

    +

    28.6.1 Writing your own custom wrappers

    @@ -1540,7 +1805,7 @@ int native_function(lua_State*L) // my native code 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.

    -

    26.6.2 Adding additional Lua code

    +

    28.6.2 Adding additional Lua code

    @@ -1578,7 +1843,7 @@ Good uses for this feature is adding of new code, or writing helper functions to See Examples/lua/arrays for an example of this code.

    -

    26.7 Details on the Lua binding

    +

    28.7 Details on the Lua binding

    @@ -1589,7 +1854,7 @@ See Examples/lua/arrays for an example of this code.

    -

    26.7.1 Binding global data into the module.

    +

    28.7.1 Binding global data into the module.

    @@ -1649,7 +1914,7 @@ end

    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)'.

    -

    26.7.2 Userdata and Metatables

    +

    28.7.2 Userdata and Metatables

    @@ -1729,7 +1994,7 @@ Note: Both the opaque structures (like the FILE*) and normal wrapped classes/str

    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.

    -

    26.7.3 Memory management

    +

    28.7.3 Memory management

    diff --git a/Doc/Manual/Makefile b/Doc/Manual/Makefile index 42149ba3a..5112afa33 100644 --- a/Doc/Manual/Makefile +++ b/Doc/Manual/Makefile @@ -75,4 +75,3 @@ linkchecker: @echo Note linkchecker versions prior to 6.1 do not work properly wrt anchors @echo ----------------------------------------------------------------------- linkchecker --config=./linkchecker.config index.html - diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index 065313fa2..ffbf6132d 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -5,7 +5,7 @@ -

    27 SWIG and Modula-3

    +

    29 SWIG and Modula-3

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

      -This chapter describes SWIG's support of +This chapter describes SWIG's support for Modula-3. You should be familiar with the basics @@ -54,7 +54,7 @@ especially typemaps.

      -

      27.1 Overview

      +

      29.1 Overview

      @@ -84,7 +84,7 @@ FFTW -

      27.1.1 Motivation

      +

      29.1.1 Motivation

      @@ -109,7 +109,7 @@ into exceptions.

      If the library API is ill designed -writing appropriate typemaps can be still time-consuming. +writing appropriate typemaps can still be time-consuming. E.g. C programmers are very creative to work-around missing data types like (real) enumerations and sets. You should turn such work-arounds back to the Modula-3 way @@ -120,21 +120,21 @@ otherwise you lose static safety and consistency. Without SWIG you would probably never consider trying to call C++ libraries from Modula-3, but with SWIG this is becomes feasible. SWIG can generate C wrappers to C++ functions and object methods -that may throw exceptions, and then wrap these C wrappers for Module-3. +that may throw exceptions, and then wrap these C wrappers for Modula-3. To make it complete you can then hide the C interface with Modula-3 classes and exceptions.

      SWIG allows you to call C and C++ libraries from Modula-3 (even with call back -functions), but it doesn't allow you to easily integrate a Module-3 module into +functions), but it doesn't allow you to easily integrate a Modula-3 module into a C/C++ project.

      -

      27.2 Conception

      +

      29.2 Conception

      -

      27.2.1 Interfaces to C libraries

      +

      29.2.1 Interfaces to C libraries

      @@ -283,7 +283,7 @@ and the principal type must be renamed (%typemap).

      -

      27.2.2 Interfaces to C++ libraries

      +

      29.2.2 Interfaces to C++ libraries

      @@ -384,10 +384,10 @@ There is no C++ library I wrote a SWIG interface for, so I'm not sure if this is possible or sensible, yet.

      -

      27.3 Preliminaries

      +

      29.3 Preliminaries

      -

      27.3.1 Compilers

      +

      29.3.1 Compilers

      @@ -400,7 +400,7 @@ For testing examples I use Critical Mass cm3.

      -

      27.3.2 Additional Commandline Options

      +

      29.3.2 Additional Commandline Options

      @@ -477,10 +477,10 @@ Instead generate templates for some basic typemaps. -

      27.4 Modula-3 typemaps

      +

      29.4 Modula-3 typemaps

      -

      27.4.1 Inputs and outputs

      +

      29.4.1 Inputs and outputs

      @@ -694,7 +694,7 @@ consist of the following parts: -

      27.4.2 Subranges, Enumerations, Sets

      +

      29.4.2 Subranges, Enumerations, Sets

      @@ -746,7 +746,7 @@ that I'd like to automate.

      -

      27.4.3 Objects

      +

      29.4.3 Objects

      @@ -759,7 +759,7 @@ is not really useful, yet.

      -

      27.4.4 Imports

      +

      29.4.4 Imports

      @@ -792,7 +792,7 @@ IMPORT M3toC;

    -

    27.4.5 Exceptions

    +

    29.4.5 Exceptions

    @@ -816,7 +816,7 @@ you should declare %typemap("m3wrapinconv:throws") blah * %{OSError.E%}.

    -

    27.4.6 Example

    +

    29.4.6 Example

    @@ -863,10 +863,10 @@ where almost everything is generated by a typemap: -

    27.5 More hints to the generator

    +

    29.5 More hints to the generator

    -

    27.5.1 Features

    +

    29.5.1 Features

    @@ -903,7 +903,7 @@ where almost everything is generated by a typemap:
    -

    27.5.2 Pragmas

    +

    29.5.2 Pragmas

    @@ -926,7 +926,7 @@ where almost everything is generated by a typemap:
    -

    27.6 Remarks

    +

    29.6 Remarks

      diff --git a/Doc/Manual/Modules.html b/Doc/Manual/Modules.html index 70b0f1181..551fd0750 100644 --- a/Doc/Manual/Modules.html +++ b/Doc/Manual/Modules.html @@ -6,7 +6,7 @@ -

      15 Working with Modules

      +

      16 Working with Modules

        @@ -23,7 +23,7 @@ -

        15.1 Modules Introduction

        +

        16.1 Modules Introduction

        @@ -77,7 +77,7 @@ where you want to create a collection of modules. Each module in the collection is created via separate invocations of SWIG.

        -

        15.2 Basics

        +

        16.2 Basics

        @@ -130,7 +130,7 @@ public:

        To create the wrapper properly, module derived_module needs to know about the base class and that its interface is covered in another module. The -line %import "base_module.i" lets SWIG know exactly that. Oftentimes +line %import "base_module.i" lets SWIG know exactly that. Often the .h file is passed to %import instead of the .i, which unfortunately doesn't work for all language modules. For example, Python requires the name of module that the base class exists in so that the proxy classes can fully inherit the @@ -176,7 +176,7 @@ in parallel from multiple threads as SWIG provides no locking - for more on that issue, read on.

        -

        15.3 The SWIG runtime code

        +

        16.3 The SWIG runtime code

        @@ -242,7 +242,7 @@ can peacefully coexist. So the type structures are separated by the is empty. Only modules compiled with the same pair will share type information.

        -

        15.4 External access to the runtime

        +

        16.4 External access to the runtime

        As described in The run-time type checker, @@ -279,7 +279,7 @@ SWIG_TYPE_TABLE to be the same as the module whose types you are trying to access.

        -

        15.5 A word of caution about static libraries

        +

        16.5 A word of caution about static libraries

        @@ -290,7 +290,7 @@ into it. This is very often NOT what you want and it can lead to unexpect behavior. When working with dynamically loadable modules, you should try to work exclusively with shared libraries.

        -

        15.6 References

        +

        16.6 References

        @@ -298,7 +298,7 @@ Due to the complexity of working with shared libraries and multiple modules, it an outside reference. John Levine's "Linkers and Loaders" is highly recommended.

        -

        15.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 3b49a2974..fadda5fc9 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -8,7 +8,7 @@ -

        28 SWIG and MzScheme/Racket

        +

        30 SWIG and MzScheme/Racket

          @@ -24,7 +24,7 @@

          This section contains information on SWIG's support of Racket, formally known as MzScheme. -

          28.1 Creating native structures

          +

          30.1 Creating native structures

          @@ -65,7 +65,7 @@ Then in scheme, you can use regular struct access procedures like

        -

        28.2 Simple example

        +

        30.2 Simple example

        @@ -166,7 +166,7 @@ Some points of interest:

      • 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.
      -

      28.3 External documentation

      +

      30.3 External documentation

      diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index 127be904d..aa6679f9a 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -6,7 +6,7 @@ -

      29 SWIG and Ocaml

      +

      31 SWIG and Ocaml

        @@ -80,7 +80,7 @@ If you're not familiar with the Objective Caml language, you can visit The Ocaml Website.

        -

        29.1 Preliminaries

        +

        31.1 Preliminaries

        @@ -99,7 +99,7 @@ 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.

        -

        29.1.1 Running SWIG

        +

        31.1.1 Running SWIG

        @@ -122,7 +122,7 @@ you will compile the file example_wrap.c with ocamlc or the resulting .ml and .mli files as well, and do the final link with -custom (not needed for native link).

        -

        29.1.2 Compiling the code

        +

        31.1.2 Compiling the code

        @@ -158,12 +158,12 @@ the user more freedom with respect to custom typing.

      -

      29.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. It's use is +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 @@ -234,7 +234,7 @@ let b = C_string (getenv "PATH") -

      29.1.4 Using your module

      +

      31.1.4 Using your module

      @@ -248,7 +248,7 @@ When linking any ocaml bytecode with your module, use the -custom option is not needed when you build native code.

      -

      29.1.5 Compilation problems and compiling with C++

      +

      31.1.5 Compilation problems and compiling with C++

      @@ -259,7 +259,7 @@ liberal with pointer types may not compile under the C++ compiler. Most code meant to be compiled as C++ will not have problems.

      -

      29.2 The low-level Ocaml/C interface

      +

      31.2 The low-level Ocaml/C interface

      @@ -310,7 +310,7 @@ type c_obj =

    • caml_val_ptr receives a void * and returns a c_obj.
    • caml_val_bool receives a C int and returns a c_obj representing - it's bool value.
    • + 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.
    • @@ -360,7 +360,7 @@ is that you must append them to the return list with swig_result = caml_list_a signature for a function that uses value in this way.

      -

      29.2.1 The generated module

      +

      31.2.1 The generated module

      @@ -394,7 +394,7 @@ it describes the output SWIG will generate for class definitions. -

      29.2.2 Enums

      +

      31.2.2 Enums

      @@ -457,7 +457,7 @@ val x : Enum_test.c_obj = C_enum `a

      -

      29.2.2.1 Enum typing in Ocaml

      +

      31.2.2.1 Enum typing in Ocaml

      @@ -470,10 +470,10 @@ functions imported from different modules. You must convert values to master values using the swig_val function before sharing them with another module.

      -

      29.2.3 Arrays

      +

      31.2.3 Arrays

      -

      29.2.3.1 Simple types of bounded arrays

      +

      31.2.3.1 Simple types of bounded arrays

      @@ -494,7 +494,7 @@ arrays of simple types with known bounds in your code, but this only works for arrays whose bounds are completely specified.

      -

      29.2.3.2 Complex and unbounded arrays

      +

      31.2.3.2 Complex and unbounded arrays

      @@ -507,7 +507,7 @@ SWIG can't predict which of these methods will be used in the array, so you have to specify it for yourself in the form of a typemap.

      -

      29.2.3.3 Using an object

      +

      31.2.3.3 Using an object

      @@ -521,7 +521,7 @@ Consider writing an object when the ending condition of your array is complex, such as using a required sentinel, etc.

      -

      29.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

      @@ -572,7 +572,7 @@ void printfloats( float *tab, int len ); -

      29.2.4 C++ Classes

      +

      31.2.4 C++ Classes

      @@ -615,7 +615,7 @@ the underlying pointer, so using create_[x]_from_ptr alters the returned value for the same object.

      -

      29.2.4.1 STL vector and string Example

      +

      31.2.4.1 STL vector and string Example

      @@ -695,7 +695,7 @@ baz # -

      29.2.4.2 C++ Class Example

      +

      31.2.4.2 C++ Class Example

      @@ -725,7 +725,7 @@ public: }; -

      29.2.4.3 Compiling the example

      +

      31.2.4.3 Compiling the example

      @@ -743,7 +743,7 @@ bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \
         -L$QTPATH/lib -cclib -lqt
       
      -

      29.2.4.4 Sample Session

      +

      31.2.4.4 Sample Session

      @@ -770,10 +770,10 @@ Assuming you have a working installation of QT, you will see a window
       containing the string "hi" in a button.  
       

      -

      29.2.5 Director Classes

      +

      31.2.5 Director Classes

      -

      29.2.5.1 Director Introduction

      +

      31.2.5.1 Director Introduction

      @@ -800,7 +800,7 @@ class foo { };

      -

      29.2.5.2 Overriding Methods in Ocaml

      +

      31.2.5.2 Overriding Methods in Ocaml

      @@ -828,7 +828,7 @@ In this example, I'll examine the objective caml code involved in providing an overloaded class. This example is contained in Examples/ocaml/shapes.

      -

      29.2.5.3 Director Usage Example

      +

      31.2.5.3 Director Usage Example

      @@ -887,7 +887,7 @@ in a more effortless style in ocaml, while leaving the "engine" part of the program in C++.

      -

      29.2.5.4 Creating director objects

      +

      31.2.5.4 Creating director objects

      @@ -928,7 +928,7 @@ object from causing a core dump, as long as the object is destroyed properly.

      -

      29.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      +

      31.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      @@ -939,7 +939,7 @@ well as a function return value in the same way you provide function arguments, and to receive arguments the same way you normally receive function returns.

      -

      29.2.5.6 directorin typemap

      +

      31.2.5.6 directorin typemap

      @@ -950,7 +950,7 @@ code receives when you are called. In general, a simple directorin typ can use the same body as a simple out typemap.

      -

      29.2.5.7 directorout typemap

      +

      31.2.5.7 directorout typemap

      @@ -961,7 +961,7 @@ for the same type, except when there are special requirements for object ownership, etc.

      -

      29.2.5.8 directorargout typemap

      +

      31.2.5.8 directorargout typemap

      @@ -978,7 +978,7 @@ In the event that you don't specify all of the necessary values, integral values will read zero, and struct or object returns have undefined results.

      -

      29.2.6 Exceptions

      +

      31.2.6 Exceptions

      diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 84c0a0f46..9c3489fb8 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -8,7 +8,7 @@ -

      30 SWIG and Octave

      +

      32 SWIG and Octave

        @@ -55,18 +55,15 @@ More information can be found at O 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).

        -

        30.1 Preliminaries

        +

        32.1 Preliminaries

        -The SWIG implemention was first based on Octave 2.9.12, so this is the minimum version required. Testing has only been done on Linux. +As of SWIG 3.0.0, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0. +Use of Octave versions older than 3.x.x is not recommended, as these versions are no longer tested with SWIG.

        -

        -As of SWIG 2.0.7, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, and 3.6.1. -

        - -

        30.2 Running SWIG

        +

        32.2 Running SWIG

        @@ -98,7 +95,7 @@ The -c++ option is also required when wrapping C++ code: 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.

        -

        30.2.1 Command-line options

        +

        32.2.1 Command-line options

        @@ -121,7 +118,7 @@ The special name "." loads C global variables into the module namespace, i.e. al The -opprefix options sets the prefix of the names of global/friend operator functions.

        -

        30.2.2 Compiling a dynamic module

        +

        32.2.2 Compiling a dynamic module

        @@ -148,7 +145,7 @@ $ mkoctfile example_wrap.cpp example.c

        octave:1> swigexample
        -

        30.2.3 Using your module

        +

        32.2.3 Using your module

        @@ -166,10 +163,10 @@ octave:4> swigexample.cvar.Foo=4; octave:5> swigexample.cvar.Foo ans = 4

      -

      30.3 A tour of basic C/C++ wrapping

      +

      32.3 A tour of basic C/C++ wrapping

      -

      30.3.1 Modules

      +

      32.3.1 Modules

      @@ -214,7 +211,7 @@ octave:4> swigexample.gcd(4,6) ans = 2 -

      30.3.2 Functions

      +

      32.3.2 Functions

      @@ -231,7 +228,7 @@ int fact(int n);

      octave:1> swigexample.fact(4)
       24 
      -

      30.3.3 Global variables

      +

      32.3.3 Global variables

      @@ -284,7 +281,7 @@ octave:2> swigexample.PI=3.142; octave:3> swigexample.PI ans = 3.1420 -

      30.3.4 Constants and enums

      +

      32.3.4 Constants and enums

      @@ -306,7 +303,7 @@ swigexample.SCONST="Hello World" swigexample.SUNDAY=0 .... -

      30.3.5 Pointers

      +

      32.3.5 Pointers

      @@ -332,7 +329,7 @@ octave:4> swigexample.fclose(f);

      - Simply printing the value of a wrapped C++ type will print it's typename. E.g., + Simply printing the value of a wrapped C++ type will print its typename. E.g.,

      octave:1> swigexample;
      @@ -353,7 +350,7 @@ octave:2> f=swigexample.fopen("not there","r");
       error: value on right hand side of assignment is undefined
       error: evaluating assignment expression near line 2, column 2 
      -

      30.3.6 Structures and C++ classes

      +

      32.3.6 Structures and C++ classes

      @@ -488,7 +485,7 @@ ans = 1 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.

      -

      30.3.7 C++ inheritance

      +

      32.3.7 C++ inheritance

      @@ -497,7 +494,7 @@ This information contains the full class hierarchy. When an indexing operation ( 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.

      -

      30.3.8 C++ overloaded functions

      +

      32.3.8 C++ overloaded functions

      @@ -507,7 +504,7 @@ The dispatch function selects which overload to call (if any) based on the passe typecheck typemaps are used to analyze each argument, as well as assign precedence. See the chapter on typemaps for details.

      -

      30.3.9 C++ operators

      +

      32.3.9 C++ operators

      @@ -611,7 +608,7 @@ On the C++ side, the default mappings are as follows: Octave can also utilise friend (i.e. non-member) operators with a simple %rename: see the example in the Examples/octave/operator directory.

      -

      30.3.10 Class extension with %extend

      +

      32.3.10 Class extension with %extend

      @@ -641,7 +638,7 @@ octave:3> printf("%s\n",a); octave:4> a.__str() 4 -

      30.3.11 C++ templates

      +

      32.3.11 C++ templates

      @@ -718,14 +715,14 @@ ans = -

      30.3.12 C++ Smart Pointers

      +

      32.3.12 C++ Smart Pointers

      C++ smart pointers are fully supported as in other modules.

      -

      30.3.13 Directors (calling Octave from C++ code)

      +

      32.3.13 Directors (calling Octave from C++ code)

      @@ -806,14 +803,14 @@ c-side routine called octave-side routine called -

      30.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.

      -

      30.3.15 Memory management

      +

      32.3.15 Memory management

      @@ -847,14 +844,14 @@ The %newobject directive may be used to control this behavior for pointers retur 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).

      -

      30.3.16 STL support

      +

      32.3.16 STL support

      Various STL library files are provided for wrapping STL containers.

      -

      30.3.17 Matrix typemaps

      +

      32.3.17 Matrix typemaps

      diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 49e8965fa..8bc7cbfd3 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -6,7 +6,7 @@ -

      31 SWIG and Perl5

      +

      33 SWIG and Perl5

      @@ -87,7 +96,7 @@ later. We're no longer testing regularly with older versions, but Perl 5.6 seems to mostly work, while older versions don't.

      -

      31.1 Overview

      +

      33.1 Overview

      @@ -108,7 +117,7 @@ described. Advanced customization features, typemaps, and other options are found near the end of the chapter.

      -

      31.2 Preliminaries

      +

      33.2 Preliminaries

      @@ -133,7 +142,7 @@ To build the module, you will need to compile the file example_wrap.c and link it with the rest of your program.

      -

      31.2.1 Getting the right header files

      +

      33.2.1 Getting the right header files

      @@ -165,7 +174,7 @@ $ perl -e 'use Config; print "$Config{archlib}\n";' -

      31.2.2 Compiling a dynamic module

      +

      33.2.2 Compiling a dynamic module

      @@ -198,7 +207,7 @@ the target should be named `example.so', `example.sl', or the appropriate dynamic module name on your system.

      -

      31.2.3 Building a dynamic module with MakeMaker

      +

      33.2.3 Building a dynamic module with MakeMaker

      @@ -232,7 +241,7 @@ the preferred approach to compilation. More information about MakeMaker can be found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen, and Randal Schwartz.

      -

      31.2.4 Building a static version of Perl

      +

      33.2.4 Building a static version of Perl

      @@ -301,7 +310,7 @@ added to it. Depending on your machine, you may need to link with additional libraries such as -lsocket, -lnsl, -ldl, etc.

      -

      31.2.5 Using the module

      +

      33.2.5 Using the module

      @@ -454,7 +463,7 @@ system configuration (this requires root access and you will need to read the man pages).

      -

      31.2.6 Compilation problems and compiling with C++

      +

      33.2.6 Compilation problems and compiling with C++

      @@ -484,8 +493,8 @@ Solaris, you often need to add an extra library -lCrun like this:

       $ swig -c++ -perl example.i
      -$ CC -c example.cxx
      -$ CC -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
      +$ CC -Kpic -c example.cxx
      +$ CC -Kpic -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
       $ CC -shared example.o example_wrap.o -o example.so -lCrun
       
      @@ -597,7 +606,7 @@ have to find the macro that conflicts and add an #undef into the .i file. Pleas any conflicting macros you find to swig-user mailing list.

      -

      31.2.7 Compiling for 64-bit platforms

      +

      33.2.7 Compiling for 64-bit platforms

      @@ -624,7 +633,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

      -

      31.3 Building Perl Extensions under Windows

      +

      33.3 Building Perl Extensions under Windows

      @@ -635,7 +644,7 @@ section assumes you are using SWIG with Microsoft Visual C++ although the procedure may be similar with other compilers.

      -

      31.3.1 Running SWIG from Developer Studio

      +

      33.3.1 Running SWIG from Developer Studio

      @@ -698,7 +707,7 @@ print "$a\n"; -

      31.3.2 Using other compilers

      +

      33.3.2 Using other compilers

      @@ -706,7 +715,7 @@ SWIG is known to work with Cygwin and may work with other compilers on Windows. For general hints and suggestions refer to the Windows chapter.

      -

      31.4 The low-level interface

      +

      33.4 The low-level interface

      @@ -716,7 +725,7 @@ can be used to control your application. However, it is also used to construct more user-friendly proxy classes as described in the next section.

      -

      31.4.1 Functions

      +

      33.4.1 Functions

      @@ -739,7 +748,7 @@ use example; $a = &example::fact(2); -

      31.4.2 Global variables

      +

      33.4.2 Global variables

      @@ -809,7 +818,7 @@ extern char *path; // Declared later in the input -

      31.4.3 Constants

      +

      33.4.3 Constants

      @@ -849,7 +858,7 @@ print example::FOO,"\n"; -

      31.4.4 Pointers

      +

      33.4.4 Pointers

      @@ -958,7 +967,7 @@ as XS and xsubpp. Given the advancement of the SWIG typesystem and the SWIG and XS, this is no longer supported.

      -

      31.4.5 Structures

      +

      33.4.5 Structures

      @@ -1092,7 +1101,7 @@ void Bar_f_set(Bar *b, Foo *val) { -

      31.4.6 C++ classes

      +

      33.4.6 C++ classes

      @@ -1157,7 +1166,7 @@ provides direct access to C++ objects. A higher level interface using Perl prox can be built using these low-level accessors. This is described shortly.

      -

      31.4.7 C++ classes and type-checking

      +

      33.4.7 C++ classes and type-checking

      @@ -1193,7 +1202,7 @@ If necessary, the type-checker also adjusts the value of the pointer (as is nece multiple inheritance is used).

      -

      31.4.8 C++ overloaded functions

      +

      33.4.8 C++ overloaded functions

      @@ -1237,7 +1246,7 @@ example::Spam_foo_d($s,3.14); Please refer to the "SWIG Basics" chapter for more information.

      -

      31.4.9 Operators

      +

      33.4.9 Operators

      @@ -1264,7 +1273,7 @@ The following C++ operators are currently supported by the Perl module:

    • operator or
    • -

      31.4.10 Modules and packages

      +

      33.4.10 Modules and packages

      @@ -1359,7 +1368,7 @@ print Foo::fact(4),"\n"; # Call a function in package FooBar --> -

      31.5 Input and output parameters

      +

      33.5 Input and output parameters

      @@ -1578,7 +1587,7 @@ print "$c\n"; Note: The REFERENCE feature is only currently supported for numeric types (integers and floating point).

      -

      31.6 Exception handling

      +

      33.6 Exception handling

      @@ -1743,7 +1752,7 @@ This is still supported, but it is deprecated. The newer %exception di functionality, but it has additional capabilities that make it more powerful.

      -

      31.7 Remapping datatypes with typemaps

      +

      33.7 Remapping datatypes with typemaps

      @@ -1760,7 +1769,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Perl interface.

      -

      31.7.1 A simple typemap example

      +

      33.7.1 A simple typemap example

      @@ -1864,7 +1873,7 @@ example::count("e","Hello World"); -

      31.7.2 Perl5 typemaps

      +

      33.7.2 Perl5 typemaps

      @@ -1969,7 +1978,7 @@ Return of C++ member data (all languages). Check value of input parameter. -

      31.7.3 Typemap variables

      +

      33.7.3 Typemap variables

      @@ -2040,7 +2049,7 @@ properly assigned. The Perl name of the wrapper function being created. -

      31.7.4 Useful functions

      +

      33.7.4 Useful functions

      @@ -2109,7 +2118,7 @@ int sv_isa(SV *, char *0; -

      31.8 Typemap Examples

      +

      33.8 Typemap Examples

      @@ -2118,7 +2127,7 @@ might look at the files "perl5.swg" and "typemaps.i" in the SWIG library.

      -

      31.8.1 Converting a Perl5 array to a char **

      +

      33.8.1 Converting a Perl5 array to a char **

      @@ -2210,7 +2219,7 @@ print @$b,"\n"; # Print it out -

      31.8.2 Return values

      +

      33.8.2 Return values

      @@ -2239,7 +2248,7 @@ can be done using the EXTEND() macro as in: } -

      31.8.3 Returning values from arguments

      +

      33.8.3 Returning values from arguments

      @@ -2293,7 +2302,7 @@ print "multout(7,13) = @r\n"; ($x,$y) = multout(7,13); -

      31.8.4 Accessing array structure members

      +

      33.8.4 Accessing array structure members

      @@ -2356,7 +2365,7 @@ the "in" typemap in the previous section would be used to convert an to copy the converted array into a C data structure.

      -

      31.8.5 Turning Perl references into C pointers

      +

      33.8.5 Turning Perl references into C pointers

      @@ -2421,7 +2430,7 @@ print "$c\n"; -

      31.8.6 Pointer handling

      +

      33.8.6 Pointer handling

      @@ -2500,7 +2509,7 @@ For example: -

      31.9 Proxy classes

      +

      33.9 Proxy classes

      @@ -2516,7 +2525,7 @@ to the underlying code. This section describes the implementation details of the proxy interface.

      -

      31.9.1 Preliminaries

      +

      33.9.1 Preliminaries

      @@ -2538,7 +2547,7 @@ SWIG creates a collection of high-level Perl wrappers. In your scripts, you wil high level wrappers. The wrappers, in turn, interact with the low-level procedural module.

      -

      31.9.2 Structure and class wrappers

      +

      33.9.2 Structure and class wrappers

      @@ -2664,7 +2673,7 @@ $v->DESTROY(); -

      31.9.3 Object Ownership

      +

      33.9.3 Object Ownership

      @@ -2751,7 +2760,7 @@ counting, garbage collection, or advanced features one might find in sophisticated languages.

      -

      31.9.4 Nested Objects

      +

      33.9.4 Nested Objects

      @@ -2804,7 +2813,7 @@ $p->{f}->{x} = 0.0; %${$p->{v}} = ( x=>0, y=>0, z=>0); -

      31.9.5 Proxy Functions

      +

      33.9.5 Proxy Functions

      @@ -2838,7 +2847,7 @@ This function replaces the original function, but operates in an identical manner.

      -

      31.9.6 Inheritance

      +

      33.9.6 Inheritance

      @@ -2914,7 +2923,7 @@ particular, inheritance of data members is extremely tricky (and I'm not even sure if it really works).

      -

      31.9.7 Modifying the proxy methods

      +

      33.9.7 Modifying the proxy methods

      @@ -2942,7 +2951,7 @@ public: }; -

      31.10 Adding additional Perl code

      +

      33.10 Adding additional Perl code

      @@ -2993,6 +3002,363 @@ set_transform($im, $a); +

      33.11 Cross language polymorphism

      + + +

      +Proxy classes provide a more natural, object-oriented way to access +extension classes. As described above, each proxy instance has an +associated C++ instance, and method calls to the proxy are passed to the +C++ instance transparently via C wrapper functions. +

      + +

      +This arrangement is asymmetric in the sense that no corresponding +mechanism exists to pass method calls down the inheritance chain from +C++ to Perl. In particular, if a C++ class has been extended in Perl +(by extending the proxy class), these extensions will not be visible +from C++ code. Virtual method calls from C++ are thus not able access +the lowest implementation in the inheritance chain. +

      + +

      +Changes have been made to SWIG to address this problem and +make the relationship between C++ classes and proxy classes more +symmetric. To achieve this goal, new classes called directors are +introduced at the bottom of the C++ inheritance chain. The job of the +directors is to route method calls correctly, either to C++ +implementations higher in the inheritance chain or to Perl +implementations lower in the inheritance chain. The upshot is that C++ +classes can be extended in Perl and from C++ these extensions look +exactly like native C++ classes. Neither C++ code nor Perl code needs +to know where a particular method is implemented: the combination of +proxy classes, director classes, and C wrapper functions takes care of +all the cross-language method routing transparently. +

      + +

      33.11.1 Enabling directors

      + + +

      +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
      +
      +
      + +

      +Without this option no director code will be generated. Second, you +must use the %feature("director") directive to tell SWIG which classes +and methods should get directors. The %feature directive can be applied +globally, to specific classes, and to specific methods, like this: +

      + +
      +
      +// generate directors for all classes that have virtual methods
      +%feature("director");         
      +
      +// generate directors for all virtual methods in class Foo
      +%feature("director") Foo;      
      +
      +
      + +

      +You can use the %feature("nodirector") directive to turn off +directors for specific classes or methods. So for example, +

      + +
      +
      +%feature("director") Foo;
      +%feature("nodirector") Foo::bar;
      +
      +
      + +

      +will generate directors for all virtual methods of class Foo except +bar(). +

      + +

      +Directors can also be generated implicitly through inheritance. +In the following, class Bar will get a director class that handles +the methods one() and two() (but not three()): +

      + +
      +
      +%feature("director") Foo;
      +class Foo {
      +public:
      +    Foo(int foo);
      +    virtual void one();
      +    virtual void two();
      +};
      +
      +class Bar: public Foo {
      +public:
      +    virtual void three();
      +};
      +
      +
      + +

      +then at the Perl side you can define +

      + +
      +
      +use mymodule;
      +
      +package MyFoo;
      +use base 'mymodule::Foo';
      +
      +sub one {
      +  print "one from Perl\n";
      +}
      +
      +
      + + +

      33.11.2 Director classes

      + + + + + +

      +For each class that has directors enabled, SWIG generates a new class +that derives from both the class in question and a special +Swig::Director class. These new classes, referred to as director +classes, can be loosely thought of as the C++ equivalent of the Perl +proxy classes. The director classes store a pointer to their underlying +Perl object and handle various issues related to object ownership. +

      + +

      +For simplicity let's ignore the Swig::Director class and refer to the +original C++ class as the director's base class. By default, a director +class extends all virtual methods in the inheritance chain of its base +class (see the preceding section for how to modify this behavior). +Thus all virtual method calls, whether they originate in C++ or in +Perl via proxy classes, eventually end up in at the implementation in +the director class. The job of the director methods is to route these +method calls to the appropriate place in the inheritance chain. By +"appropriate place" we mean the method that would have been called if +the C++ base class and its extensions in Perl were seamlessly +integrated. That seamless integration is exactly what the director +classes provide, transparently skipping over all the messy extension API +glue that binds the two languages together. +

      + +

      +In reality, the "appropriate place" is one of only two possibilities: +C++ or Perl. Once this decision is made, the rest is fairly easy. If +the correct implementation is in C++, then the lowest implementation of +the method in the C++ inheritance chain is called explicitly. If the +correct implementation is in Perl, the Perl API is used to call the +method of the underlying Perl object (after which the usual virtual +method resolution in Perl automatically finds the right +implementation). +

      + +

      +Now how does the director decide which language should handle the method call? +The basic rule is to handle the method in Perl, unless there's a good +reason not to. The reason for this is simple: Perl has the most +"extended" implementation of the method. This assertion is guaranteed, +since at a minimum the Perl proxy class implements the method. If the +method in question has been extended by a class derived from the proxy +class, that extended implementation will execute exactly as it should. +If not, the proxy class will route the method call into a C wrapper +function, expecting that the method will be resolved in C++. The wrapper +will call the virtual method of the C++ instance, and since the director +extends this the call will end up right back in the director method. Now +comes the "good reason not to" part. If the director method were to blindly +call the Perl method again, it would get stuck in an infinite loop. We avoid this +situation by adding special code to the C wrapper function that tells +the director method to not do this. The C wrapper function compares the +pointer to the Perl object that called the wrapper function to the +pointer stored by the director. If these are the same, then the C +wrapper function tells the director to resolve the method by calling up +the C++ inheritance chain, preventing an infinite loop. +

      + +

      +One more point needs to be made about the relationship between director +classes and proxy classes. When a proxy class instance is created in +Perl, SWIG creates an instance of the original C++ class. +This is exactly what happens without directors and +is true even if directors are enabled for the particular class in +question. When a class derived from a proxy class is created, +however, SWIG then creates an instance of the corresponding C++ director +class. The reason for this difference is that user-defined subclasses +may override or extend methods of the original class, so the director +class is needed to route calls to these methods correctly. For +unmodified proxy classes, all methods are ultimately implemented in C++ +so there is no need for the extra overhead involved with routing the +calls through Perl. +

      + +

      33.11.3 Ownership and object destruction

      + + +

      +Memory management issues are slightly more complicated with directors +than for proxy classes alone. Perl instances hold a pointer to the +associated C++ director object, and the director in turn holds a pointer +back to a Perl object. By default, proxy classes own their C++ +director object and take care of deleting it when they are garbage +collected. +

      + +

      +This relationship can be reversed by calling the special +DISOWN() method of the proxy class. After calling this +method the director +class increments the reference count of the Perl object. When the +director class is deleted it decrements the reference count. Assuming no +outstanding references to the Perl object remain, the Perl object +will be destroyed at the same time. This is a good thing, since +directors and proxies refer to each other and so must be created and +destroyed together. Destroying one without destroying the other will +likely cause your program to segfault. +

      + +

      +Also note that due to the proxy implementation, the DESTROY() +method on directors can be called for several reasons, many of which +have little to do with the teardown of an object instance. To help +disambiguate this, a second argument is added to the DESTROY() +call when a C++ director object is being released. So, to avoid running +your clean-up code when an object is not really going away, or after it +has already been reclaimed, it is suggested that custom destructors in +Perl subclasses looks something like: +

      + +
      +
      +sub DESTROY {
      +  my($self, $final) = @_;
      +  if($final) {
      +    # real teardown code
      +  }
      +  shift->SUPER::DESTROY(@_);
      +}
      +
      +
      + + +

      33.11.4 Exception unrolling

      + + +

      +With directors routing method calls to Perl, and proxies routing them +to C++, the handling of exceptions is an important concern. By default, the +directors ignore exceptions that occur during method calls that are +resolved in Perl. To handle such exceptions correctly, it is necessary +to temporarily translate them into C++ exceptions. This can be done with +the %feature("director:except") directive. The following code should +suffice in most cases: +

      + +
      +
      +%feature("director:except") {
      +    if ($error != NULL) {
      +        throw Swig::DirectorMethodException();
      +    }
      +}
      +
      +
      + +

      +This code will check the Perl error state after each method call from +a director into Perl, and throw a C++ exception if an error occurred. +This exception can be caught in C++ to implement an error handler. +

      + +

      +It may be the case that a method call originates in Perl, travels up +to C++ through a proxy class, and then back into Perl via a director +method. If an exception occurs in Perl at this point, it would be nice +for that exception to find its way back to the original caller. This can +be done by combining a normal %exception directive with the +director:except handler shown above. Here is an example of a +suitable exception handler: +

      + +
      +
      +%exception {
      +    try { $action }
      +    catch (Swig::DirectorException &e) { SWIG_fail; }
      +}
      +
      +
      + +

      +The class Swig::DirectorException used in this example is actually a +base class of Swig::DirectorMethodException, so it will trap this +exception. Because the Perl error state is still set when +Swig::DirectorMethodException is thrown, Perl will register the +exception as soon as the C wrapper function returns. +

      + +

      33.11.5 Overhead and code bloat

      + + +

      +Enabling directors for a class will generate a new director method for +every virtual method in the class' inheritance chain. This alone can +generate a lot of code bloat for large hierarchies. Method arguments +that require complex conversions to and from target language types can +result in large director methods. For this reason it is recommended that +you selectively enable directors only for specific classes that are +likely to be extended in Perl and used in C++. +

      + +

      +Compared to classes that do not use directors, the call routing in the +director methods does add some overhead. In particular, at least one +dynamic cast and one extra function call occurs per method call from +Perl. Relative to the speed of Perl execution this is probably +completely negligible. For worst case routing, a method call that +ultimately resolves in C++ may take one extra detour through Perl in +order to ensure that the method does not have an extended Perl +implementation. This could result in a noticeable overhead in some cases. +

      + +

      +Although directors make it natural to mix native C++ objects with Perl +objects (as director objects) via a common base class pointer, one +should be aware of the obvious fact that method calls to Perl objects +will be much slower than calls to C++ objects. This situation can be +optimized by selectively enabling director methods (using the %feature +directive) for only those methods that are likely to be extended in +Perl. +

      + +

      33.11.6 Typemaps

      + + +

      +Typemaps for input and output of most of the basic types from director +classes have been written. These are roughly the reverse of the usual +input and output typemaps used by the wrapper code. The typemap +operation names are 'directorin', 'directorout', and 'directorargout'. +The director code does not currently use any of the other kinds of typemaps. +It is not clear at this point which kinds are appropriate and +need to be supported. +

      + + diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 78ee6ea7f..7e5cccf6a 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -7,7 +7,7 @@ -

      32 SWIG and PHP

      +

      34 SWIG and PHP

        @@ -79,7 +79,7 @@ your extension into php directly, you will need the complete PHP source tree available.

        -

        32.1 Generating PHP Extensions

        +

        34.1 Generating PHP Extensions

        @@ -126,7 +126,7 @@ and it doesn't play nicely with package system. We don't recommend this approach, or provide explicit support for it.

        -

        32.1.1 Building a loadable extension

        +

        34.1.1 Building a loadable extension

        @@ -141,7 +141,7 @@ least work for Linux though): gcc -shared example_wrap.o -o example.so

      -

      32.1.2 Using PHP Extensions

      +

      34.1.2 Using PHP Extensions

      @@ -172,7 +172,7 @@ attempts to do the dl() call for you: include("example.php"); -

      32.2 Basic PHP interface

      +

      34.2 Basic PHP interface

      @@ -183,7 +183,7 @@ other symbols unless care is taken to %rename them. At present SWIG doesn't have support for the namespace feature added in PHP 5.3.

      -

      32.2.1 Constants

      +

      34.2.1 Constants

      @@ -260,7 +260,7 @@ is treated as true by the if test, when the value of the intended constant would be treated as false!

      -

      32.2.2 Global Variables

      +

      34.2.2 Global Variables

      @@ -309,7 +309,7 @@ undefined. At this time SWIG does not support custom accessor methods.

      -

      32.2.3 Functions

      +

      34.2.3 Functions

      @@ -362,7 +362,7 @@ print $s; # The value of $s was not changed. --> -

      32.2.4 Overloading

      +

      34.2.4 Overloading

      @@ -418,7 +418,7 @@ taking the integer argument.

      --> -

      32.2.5 Pointers and References

      +

      34.2.5 Pointers and References

      @@ -503,13 +503,20 @@ echo "The sum $in1 + $in2 = $result\n"; Because PHP has a native concept of reference, it may seem more natural to the PHP developer to use references to pass pointers. To enable this, one needs to include phppointers.i which defines the -named typemap REFERENCE. +named typemap REF.

      -However, this relies on call-time pass-by-reference, which has been -deprecated in PHP for some time, and was finally removed in PHP 5.4. -So you should avoid creating new wrappers which rely on this approach. +Prior to SWIG 3.0, the REF typemaps relied on PHP's call-time +pass-by-reference, which was deprecated in PHP 5.3 and removed in PHP 5.4. +So if you use these REF typemaps, you should ensure that SWIG≥3.0 is +used to generate wrappers from your interface file. +

      + +

      +In case you write your own typemaps, SWIG supports an attribute called +byref: if you set that, then SWIG will make sure that the generated +wrapper function will want the input parameter as a reference.

      @@ -532,7 +539,7 @@ include("example.php");
       $in1 = 3;
       $in2 = 5;
       $result = 0;
      -add(&$in1,&$in2,&$result);
      +add($in1,$in2,$result);
       
       echo "The sum $in1 + $in2 = $result\n";
       ?>
      @@ -556,7 +563,7 @@ PHP in a number of ways: by using unset on an existing
       variable, or assigning NULL to a variable.
       

      -

      32.2.6 Structures and C++ classes

      +

      34.2.6 Structures and C++ classes

      @@ -617,7 +624,7 @@ Would be used in the following way from PHP5: Member variables and methods are accessed using the -> operator.

      -

      32.2.6.1 Using -noproxy

      +

      34.2.6.1 Using -noproxy

      @@ -643,7 +650,7 @@ Complex_im_set($obj,$d); Complex_im_get($obj);

      -

      32.2.6.2 Constructors and Destructors

      +

      34.2.6.2 Constructors and Destructors

      @@ -684,7 +691,7 @@ the programmer can either reassign the variable or call unset($v)

      -

      32.2.6.3 Static Member Variables

      +

      34.2.6.3 Static Member Variables

      @@ -727,7 +734,7 @@ Ko::threats(10); echo "There have now been " . Ko::threats() . " threats\n"; -

      32.2.6.4 Static Member Functions

      +

      34.2.6.4 Static Member Functions

      @@ -749,7 +756,7 @@ Ko::threats(); -

      32.2.7 PHP Pragmas, Startup and Shutdown code

      +

      34.2.7 PHP Pragmas, Startup and Shutdown code

      @@ -837,7 +844,7 @@ The %rinit and %rshutdown statements are very similar but inse into the request init (PHP_RINIT_FUNCTION) and request shutdown (PHP_RSHUTDOWN_FUNCTION) code respectively.

      -

      32.3 Cross language polymorphism

      +

      34.3 Cross language polymorphism

      @@ -872,7 +879,7 @@ wrapper functions takes care of all the cross-language method routing transparently.

      -

      32.3.1 Enabling directors

      +

      34.3.1 Enabling directors

      @@ -961,7 +968,7 @@ class MyFoo extends Foo { -

      32.3.2 Director classes

      +

      34.3.2 Director classes

      @@ -1041,7 +1048,7 @@ so there is no need for the extra overhead involved with routing the calls through PHP.

      -

      32.3.3 Ownership and object destruction

      +

      34.3.3 Ownership and object destruction

      @@ -1097,7 +1104,7 @@ In this example, we are assuming that FooContainer will take care of deleting all the Foo pointers it contains at some point.

      -

      32.3.4 Exception unrolling

      +

      34.3.4 Exception unrolling

      @@ -1156,7 +1163,7 @@ Swig::DirectorMethodException is thrown, PHP will register the exception as soon as the C wrapper function returns.

      -

      32.3.5 Overhead and code bloat

      +

      34.3.5 Overhead and code bloat

      @@ -1189,7 +1196,7 @@ optimized by selectively enabling director methods (using the %feature directive) for only those methods that are likely to be extended in PHP.

      -

      32.3.6 Typemaps

      +

      34.3.6 Typemaps

      @@ -1203,7 +1210,7 @@ need to be supported.

      -

      32.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 8c1eb2d36..44c6930f8 100644 --- a/Doc/Manual/Pike.html +++ b/Doc/Manual/Pike.html @@ -6,7 +6,7 @@ -

      33 SWIG and Pike

      +

      35 SWIG and Pike

        @@ -46,10 +46,10 @@ least, make sure you read the "SWIG Basics" chapter.

        -

        33.1 Preliminaries

        +

        35.1 Preliminaries

        -

        33.1.1 Running SWIG

        +

        35.1.1 Running SWIG

        @@ -94,7 +94,7 @@ can use the -o option:

        $ swig -pike -o pseudonym.c example.i
        -

        33.1.2 Getting the right header files

        +

        35.1.2 Getting the right header files

        @@ -114,7 +114,7 @@ You're looking for files with the names global.h, program.h and so on.

        -

        33.1.3 Using your module

        +

        35.1.3 Using your module

        @@ -129,10 +129,10 @@ Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend) (1) Result: 24

      -

      33.2 Basic C/C++ Mapping

      +

      35.2 Basic C/C++ Mapping

      -

      33.2.1 Modules

      +

      35.2.1 Modules

      @@ -143,7 +143,7 @@ concerned), SWIG's %module directive doesn't really have any significance.

      -

      33.2.2 Functions

      +

      35.2.2 Functions

      @@ -168,7 +168,7 @@ exactly as you'd expect it to: (1) Result: 24 -

      33.2.3 Global variables

      +

      35.2.3 Global variables

      @@ -197,7 +197,7 @@ will result in two functions, Foo_get() and Foo_set(): (3) Result: 3.141590 -

      33.2.4 Constants and enumerated types

      +

      35.2.4 Constants and enumerated types

      @@ -205,7 +205,7 @@ Enumerated types in C/C++ declarations are wrapped as Pike constants, not as Pike enums.

      -

      33.2.5 Constructors and Destructors

      +

      35.2.5 Constructors and Destructors

      @@ -213,7 +213,7 @@ Constructors are wrapped as create() methods, and destructors are wrapped as destroy() methods, for Pike classes.

      -

      33.2.6 Static Members

      +

      35.2.6 Static Members

      diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html index d453fdb98..e188fc0be 100644 --- a/Doc/Manual/Preprocessor.html +++ b/Doc/Manual/Preprocessor.html @@ -6,7 +6,7 @@ -

      7 Preprocessing

      +

      8 Preprocessing

        @@ -37,7 +37,7 @@ However, a number of modifications and enhancements have been made. This chapter describes some of these modifications.

        -

        7.1 File inclusion

        +

        8.1 File inclusion

        @@ -63,7 +63,7 @@ By default, the #include is ignored unless you run SWIG with the is that you often don't want SWIG to try and wrap everything included in standard header system headers and auxiliary files. -

        7.2 File imports

        +

        8.2 File imports

        @@ -92,7 +92,7 @@ The -importall directive tells SWIG to follow all #include sta as imports. This might be useful if you want to extract type definitions from system header files without generating any wrappers. -

        7.3 Conditional Compilation

        +

        8.3 Conditional Compilation

        @@ -115,6 +115,9 @@ SWIGCLISP Defined when using CLISP SWIGCSHARP Defined when using C# SWIGGUILE Defined when using Guile SWIGJAVA Defined when using Java +SWIGJAVASCRIPT Defined when using Javascript +SWIG_JAVASCRIPT_JSC Defined when using Javascript for JavascriptCore +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 @@ -153,7 +156,7 @@ SWIG (except for the symbol `SWIG' which is only defined within the SWIG compiler).

        -

        7.4 Macro Expansion

        +

        8.4 Macro Expansion

        @@ -208,7 +211,7 @@ like #x. This is a non-standard SWIG extension.

      -

      7.5 SWIG Macros

      +

      8.5 SWIG Macros

      @@ -254,7 +257,7 @@ many of SWIG's advanced features and libraries are built using this mechanism (s support).

      -

      7.6 C99 and GNU Extensions

      +

      8.6 C99 and GNU Extensions

      @@ -310,14 +313,14 @@ interface building. However, they are used internally to implement a number of SWIG directives and are provided to make SWIG more compatible with C99 code.

      -

      7.7 Preprocessing and delimiters

      +

      8.7 Preprocessing and delimiters

      The preprocessor handles { }, " " and %{ %} delimiters differently.

      -

      7.7.1 Preprocessing and %{ ... %} & " ... " delimiters

      +

      8.7.1 Preprocessing and %{ ... %} & " ... " delimiters

      @@ -342,7 +345,7 @@ the contents of the %{ ... %} block are copied without modification to the output (including all preprocessor directives).

      -

      7.7.2 Preprocessing and { ... } delimiters

      +

      8.7.2 Preprocessing and { ... } delimiters

      @@ -384,7 +387,7 @@ to actually go into the wrapper file, prefix the preprocessor directives with % and leave the preprocessor directive in the code.

      -

      7.8 Preprocessor and Typemaps

      +

      8.8 Preprocessor and Typemaps

      @@ -455,7 +458,7 @@ would generate

      -

      7.9 Viewing preprocessor output

      +

      8.9 Viewing preprocessor output

      @@ -465,7 +468,7 @@ Instead the results after the preprocessor has run are displayed. This might be useful as an aid to debugging and viewing the results of macro expansions.

      -

      7.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 6a22738bc..8b4f42a43 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -6,7 +6,7 @@ -

      34 SWIG and Python

      +

      36 SWIG and Python

      @@ -135,7 +142,7 @@ very least, make sure you read the "SWIG Basics" chapter.

      -

      34.1 Overview

      +

      36.1 Overview

      @@ -162,10 +169,10 @@ described followed by a discussion of low-level implementation details.

      -

      34.2 Preliminaries

      +

      36.2 Preliminaries

      -

      34.2.1 Running SWIG

      +

      36.2.1 Running SWIG

      @@ -263,7 +270,7 @@ The following sections have further practical examples and details on how you might go about compiling and using the generated files.

      -

      34.2.2 Using distutils

      +

      36.2.2 Using distutils

      @@ -355,7 +362,7 @@ This same approach works on all platforms if the appropriate compiler is install can even build extensions to the standard Windows Python using MingGW)

      -

      34.2.3 Hand compiling a dynamic module

      +

      36.2.3 Hand compiling a dynamic module

      @@ -403,7 +410,7 @@ module actually consists of two files; socket.py and

      -

      34.2.4 Static linking

      +

      36.2.4 Static linking

      @@ -482,7 +489,7 @@ If using static linking, you might want to rely on a different approach (perhaps using distutils).

      -

      34.2.5 Using your module

      +

      36.2.5 Using your module

      @@ -639,7 +646,7 @@ system configuration (this requires root access and you will need to read the man pages).

      -

      34.2.6 Compilation of C++ extensions

      +

      36.2.6 Compilation of C++ extensions

      @@ -731,7 +738,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

      -

      34.2.7 Compiling for 64-bit platforms

      +

      36.2.7 Compiling for 64-bit platforms

      @@ -768,7 +775,7 @@ and -m64 allow you to choose the desired binary format for your python extension.

      -

      34.2.8 Building Python Extensions under Windows

      +

      36.2.8 Building Python Extensions under Windows

      @@ -897,7 +904,7 @@ SWIG Wiki.

      -

      34.3 A tour of basic C/C++ wrapping

      +

      36.3 A tour of basic C/C++ wrapping

      @@ -906,7 +913,7 @@ to your C/C++ code. Functions are wrapped as functions, classes are wrapped as This section briefly covers the essential aspects of this wrapping.

      -

      34.3.1 Modules

      +

      36.3.1 Modules

      @@ -919,7 +926,7 @@ module name, make sure you don't use the same name as a built-in Python command or standard module name.

      -

      34.3.2 Functions

      +

      36.3.2 Functions

      @@ -943,7 +950,7 @@ like you think it does: >>> -

      34.3.3 Global variables

      +

      36.3.3 Global variables

      @@ -1081,7 +1088,7 @@ that starts with a leading underscore. SWIG does not create cvar if there are no global variables in a module.

      -

      34.3.4 Constants and enums

      +

      36.3.4 Constants and enums

      @@ -1121,7 +1128,7 @@ other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.

      -

      34.3.5 Pointers

      +

      36.3.5 Pointers

      @@ -1262,7 +1269,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

      -

      34.3.6 Structures

      +

      36.3.6 Structures

      @@ -1451,7 +1458,7 @@ everything works just like you would expect. For example: -

      34.3.7 C++ classes

      +

      36.3.7 C++ classes

      @@ -1540,7 +1547,7 @@ they are accessed through cvar like this: -

      34.3.8 C++ inheritance

      +

      36.3.8 C++ inheritance

      @@ -1595,7 +1602,7 @@ then the function spam() accepts Foo * or a pointer to any cla It is safe to use multiple inheritance with SWIG.

      -

      34.3.9 Pointers, references, values, and arrays

      +

      36.3.9 Pointers, references, values, and arrays

      @@ -1656,7 +1663,7 @@ treated as a returning value, and it will follow the same allocation/deallocation process.

      -

      34.3.10 C++ overloaded functions

      +

      36.3.10 C++ overloaded functions

      @@ -1779,7 +1786,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      34.3.11 C++ operators

      +

      36.3.11 C++ operators

      @@ -1868,7 +1875,7 @@ Also, be aware that certain operators don't map cleanly to Python. For instance overloaded assignment operators don't map to Python semantics and will be ignored.

      -

      34.3.12 C++ namespaces

      +

      36.3.12 C++ namespaces

      @@ -1935,7 +1942,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      34.3.13 C++ templates

      +

      36.3.13 C++ templates

      @@ -1989,7 +1996,7 @@ Some more complicated examples will appear later.

      -

      34.3.14 C++ Smart Pointers

      +

      36.3.14 C++ Smart Pointers

      @@ -2073,7 +2080,7 @@ simply use the __deref__() method. For example: -

      34.3.15 C++ reference counted objects

      +

      36.3.15 C++ reference counted objects

      @@ -2082,7 +2089,7 @@ Python examples of memory management using referencing counting.

      -

      34.4 Further details on the Python class interface

      +

      36.4 Further details on the Python class interface

      @@ -2105,7 +2112,7 @@ the -builtin option are in the Built-in section.

      -

      34.4.1 Proxy classes

      +

      36.4.1 Proxy classes

      @@ -2194,7 +2201,7 @@ you can attach new Python methods to the class and you can even inherit from it by Python built-in types until Python 2.2).

      -

      34.4.2 Built-in Types

      +

      36.4.2 Built-in Types

      @@ -2238,7 +2245,7 @@ please refer to the python documentation:

      http://docs.python.org/extending/newtypes.html

      -

      34.4.2.1 Limitations

      +

      36.4.2.1 Limitations

      Use of the -builtin option implies a couple of limitations: @@ -2406,7 +2413,7 @@ assert(issubclass(B.Derived, A.Base)) -

      34.4.2.2 Operator overloads -- use them!

      +

      36.4.2.2 Operator overloads -- use them!

      The entire justification for the -builtin option is improved @@ -2507,7 +2514,7 @@ structs.

      -

      34.4.3 Memory management

      +

      36.4.3 Memory management

      NOTE: Although this section refers to proxy objects, everything here also applies @@ -2702,7 +2709,7 @@ It is also possible to deal with situations like this using typemaps--an advanced topic discussed later.

      -

      34.4.4 Python 2.2 and classic classes

      +

      36.4.4 Python 2.2 and classic classes

      @@ -2739,7 +2746,7 @@ class itself. In Python-2.1 and earlier, they have to be accessed as a global function or through an instance (see the earlier section).

      -

      34.5 Cross language polymorphism

      +

      36.5 Cross language polymorphism

      @@ -2773,7 +2780,7 @@ proxy classes, director classes, and C wrapper functions takes care of all the cross-language method routing transparently.

      -

      34.5.1 Enabling directors

      +

      36.5.1 Enabling directors

      @@ -2863,7 +2870,7 @@ class MyFoo(mymodule.Foo): -

      34.5.2 Director classes

      +

      36.5.2 Director classes

      @@ -2945,7 +2952,7 @@ so there is no need for the extra overhead involved with routing the calls through Python.

      -

      34.5.3 Ownership and object destruction

      +

      36.5.3 Ownership and object destruction

      @@ -3012,7 +3019,7 @@ deleting all the Foo pointers it contains at some point. Note that no hard references to the Foo objects remain in Python.

      -

      34.5.4 Exception unrolling

      +

      36.5.4 Exception unrolling

      @@ -3071,7 +3078,7 @@ Swig::DirectorMethodException is thrown, Python will register the exception as soon as the C wrapper function returns.

      -

      34.5.5 Overhead and code bloat

      +

      36.5.5 Overhead and code bloat

      @@ -3105,7 +3112,7 @@ directive) for only those methods that are likely to be extended in Python.

      -

      34.5.6 Typemaps

      +

      36.5.6 Typemaps

      @@ -3119,7 +3126,7 @@ need to be supported.

      -

      34.5.7 Miscellaneous

      +

      36.5.7 Miscellaneous

      @@ -3166,7 +3173,7 @@ methods that return const references.

      -

      34.6 Common customization features

      +

      36.6 Common customization features

      @@ -3179,7 +3186,7 @@ This section describes some common SWIG features that are used to improve your the interface to an extension module.

      -

      34.6.1 C/C++ helper functions

      +

      36.6.1 C/C++ helper functions

      @@ -3260,7 +3267,7 @@ hard to implement. It is possible to clean this up using Python code, typemaps, customization features as covered in later sections.

      -

      34.6.2 Adding additional Python code

      +

      36.6.2 Adding additional Python code

      @@ -3488,7 +3495,7 @@ The same applies for overloaded constructors.

      -

      34.6.3 Class extension with %extend

      +

      36.6.3 Class extension with %extend

      @@ -3577,7 +3584,7 @@ Vector(12,14,16) in any way---the extensions only show up in the Python interface.

      -

      34.6.4 Exception handling with %exception

      +

      36.6.4 Exception handling with %exception

      @@ -3703,7 +3710,7 @@ The language-independent exception.i library file can also be used to raise exceptions. See the SWIG Library chapter.

      -

      34.7 Tips and techniques

      +

      36.7 Tips and techniques

      @@ -3713,7 +3720,7 @@ strings, binary data, and arrays. This chapter discusses the common techniques solving these problems.

      -

      34.7.1 Input and output parameters

      +

      36.7.1 Input and output parameters

      @@ -3926,7 +3933,7 @@ void foo(Bar *OUTPUT); may not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

      -

      34.7.2 Simple pointers

      +

      36.7.2 Simple pointers

      @@ -3995,7 +4002,7 @@ If you replace %pointer_functions() by %pointer_class(type,name)SWIG Library chapter for further details.

      -

      34.7.3 Unbounded C Arrays

      +

      36.7.3 Unbounded C Arrays

      @@ -4057,7 +4064,7 @@ well suited for applications in which you need to create buffers, package binary data, etc.

      -

      34.7.4 String handling

      +

      36.7.4 String handling

      @@ -4126,7 +4133,7 @@ If you need to return binary data, you might use the also be used to extra binary data from arbitrary pointers.

      -

      34.8 Typemaps

      +

      36.8 Typemaps

      @@ -4143,7 +4150,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Python interface or if you want to elevate your guru status.

      -

      34.8.1 What is a typemap?

      +

      36.8.1 What is a typemap?

      @@ -4259,7 +4266,7 @@ parameter is omitted): -

      34.8.2 Python typemaps

      +

      36.8.2 Python typemaps

      @@ -4300,7 +4307,7 @@ a look at the SWIG library version 1.3.20 or so.

      -

      34.8.3 Typemap variables

      +

      36.8.3 Typemap variables

      @@ -4371,7 +4378,7 @@ properly assigned. The Python name of the wrapper function being created. -

      34.8.4 Useful Python Functions

      +

      36.8.4 Useful Python Functions

      @@ -4499,7 +4506,7 @@ write me -

      34.9 Typemap Examples

      +

      36.9 Typemap Examples

      @@ -4508,7 +4515,7 @@ might look at the files "python.swg" and "typemaps.i" in the SWIG library.

      -

      34.9.1 Converting Python list to a char **

      +

      36.9.1 Converting Python list to a char **

      @@ -4588,7 +4595,7 @@ memory allocation is used to allocate memory for the array, the the C function.

      -

      34.9.2 Expanding a Python object into multiple arguments

      +

      36.9.2 Expanding a Python object into multiple arguments

      @@ -4667,7 +4674,7 @@ to supply the argument count. This is automatically set by the typemap code. F -

      34.9.3 Using typemaps to return arguments

      +

      36.9.3 Using typemaps to return arguments

      @@ -4682,8 +4689,7 @@ int spam(double a, double b, double *out1, double *out2) { *out1 = result1; *out2 = result2; return status; -}; - +}

      @@ -4756,7 +4762,7 @@ function can now be used as follows: >>> -

      34.9.4 Mapping Python tuples into small arrays

      +

      36.9.4 Mapping Python tuples into small arrays

      @@ -4805,7 +4811,7 @@ array, such an approach would not be recommended for huge arrays, but for small structures, this approach works fine.

      -

      34.9.5 Mapping sequences to C arrays

      +

      36.9.5 Mapping sequences to C arrays

      @@ -4894,7 +4900,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) { -

      34.9.6 Pointer handling

      +

      36.9.6 Pointer handling

      @@ -4991,7 +4997,7 @@ class object (if applicable). -

      34.10 Docstring Features

      +

      36.10 Docstring Features

      @@ -5019,7 +5025,7 @@ of your users much simpler.

      -

      34.10.1 Module docstring

      +

      36.10.1 Module docstring

      @@ -5053,7 +5059,7 @@ layout of controls on a panel, etc. to be loaded from an XML file." -

      34.10.2 %feature("autodoc")

      +

      36.10.2 %feature("autodoc")

      @@ -5081,7 +5087,7 @@ four levels for autodoc controlled by the value given to the feature, %feature("autodoc", "level"). The four values for level are covered in the following sub-sections. -

      34.10.2.1 %feature("autodoc", "0")

      +

      36.10.2.1 %feature("autodoc", "0")

      @@ -5110,7 +5116,7 @@ def function_name(*args, **kwargs): -

      34.10.2.2 %feature("autodoc", "1")

      +

      36.10.2.2 %feature("autodoc", "1")

      @@ -5135,7 +5141,7 @@ def function_name(*args, **kwargs): -

      34.10.2.3 %feature("autodoc", "2")

      +

      36.10.2.3 %feature("autodoc", "2")

      @@ -5195,7 +5201,7 @@ def function_name(*args, **kwargs): -

      34.10.2.4 %feature("autodoc", "3")

      +

      36.10.2.4 %feature("autodoc", "3")

      @@ -5220,7 +5226,7 @@ def function_name(*args, **kwargs): -

      34.10.2.5 %feature("autodoc", "docstring")

      +

      36.10.2.5 %feature("autodoc", "docstring")

      @@ -5239,7 +5245,7 @@ void GetPosition(int* OUTPUT, int* OUTPUT); -

      34.10.3 %feature("docstring")

      +

      36.10.3 %feature("docstring")

      @@ -5271,13 +5277,70 @@ with more than one line. -

      34.11 Python Packages

      +

      36.11 Python Packages

      + + +

      Python has concepts of modules and packages. Modules are separate units of +code and may be grouped together to form a package. Packages may be nested, +that is they may contain subpackages. This leads to tree-like hierarchy, with +packages as intermediate nodes and modules as leaf nodes.

      + +

      The hierarchy of Python packages/modules follows the hierarchy of +*.py files found in a source tree (or, more generally, in the Python path). +Normally, the developer creates new module by placing a *.py file +somewhere under Python path; the module is then named after that *.py +file. A package is created by placing an __init__.py file within a +directory; the package is then named after that directory. For example, the +following source tree:

      + +
      +
      +mod1.py
      +pkg1/__init__.py
      +pkg1/mod2.py
      +pkg1/pkg2/__init__.py
      +pkg1/pkg2/mod3.py
      +
      +
      + +

      +defines the following Python packages and modules: +

      + +
      +
      +pkg1            # package
      +pkg1.pkg2       # package
      +mod1            # module
      +pkg1.mod2       # module
      +pkg1.pkg2.mod3  # module
      +
      +
      + +

      +The purpose of an __init__.py file is two-fold. First, the existence of +__init__.py in a directory informs the Python interpreter that this +directory contains a Python package. Second, the code in __init__.py is +loaded/executed automatically when the package is initialized (when it or its +submodule/subpackage gets import'ed). By default, SWIG generates +proxy Python code – one *.py file for each *.i +interface. The __init__.py files, however, are not generated by SWIG. +They should be created by other means. Both files (module *.py and +__init__.py) should be installed in appropriate destination +directories in order to obtain a desirable package/module hierarchy. +

      + +

      The way Python defines its modules and packages impacts SWIG users. Some +users may need to use special features such as the package option in the +%module directive or import related command line options. These are +explained in the following sections.

      + +

      36.11.1 Setting the Python package

      -Using the package option of the %module directive -allows you to specify what Python package that the module will be -living in when installed. +Using the package option in the %module directive allows you +to specify a Python package that the module will be in when installed.

      @@ -5290,15 +5353,330 @@ living in when installed. This is useful when the .i file is %imported by another .i file. By default SWIG will assume that the importer is able to find the importee with just the module name, but -if they live in separate Python packages then that won't work. +if they live in separate Python packages then this won't work. However if the importee specifies what its package is with the %module option then the Python code generated for the importer will use that package name when importing the other module -and also in base class declarations, etc. if the package name is -different than its own. +and in base class declarations, etc..

      -

      34.12 Python 3 Support

      +

      SWIG assumes that the package option provided to %module +together with the module name (that is, wx.xrc in the above +example) forms a fully qualified (absolute) name of a module (in Python terms). +This is important especially for Python 3, where absolute imports are used by +default. It's up to you to place the generated module files (.py, +.so) in appropriate subdirectories. For example, if you have an +interface file foo.i with: +

      + +
      +
      +%module(package="pkg1.pkg2") foo
      +
      +
      + +

      +then the resulting directory layout should be +

      + +
      +
      +pkg1/
      +pkg1/__init__.py
      +pkg1/pkg2/__init__.py
      +pkg1/pkg2/foo.py        # (generated by SWIG)
      +pkg1/pkg2/_foo.so       # (shared library built from C/C++ code generated by SWIG)
      +
      +
      + +

      36.11.2 Absolute and relative imports

      + + +

      Suppose, we have the following hierarchy of files:

      + +
      +
      +pkg1/
      +pkg1/__init__.py
      +pkg1/mod2.py
      +pkg1/pkg2/__init__.py
      +pkg1/pkg2/mod3.py
      +
      +
      + +

      Let the contents of pkg1/pkg2/mod3.py be

      +
      +
      +class M3: pass
      +
      +
      + +

      +We edit pkg1/mod2.py and want to import module +pkg1/pkg2/mod3.py in order to derive from class M3. We can +write appropriate Python code in several ways, for example: +

      + +
        +
      1. Using "import <>" syntax with absolute package name:

        +
        +
        +# pkg1/mod2.py
        +import pkg1.pkg2.mod3
        +class M2(pkg1.pkg2.mod3.M3): pass
        +
        +
        +
      2. + +
      3. Using "import <>" syntax with package name relative to + pkg1 (only in Python 2.7 and earlier):

        +
        +
        +# pkg1/mod2.py
        +import pkg2.mod3
        +class M2(pkg2.mod3.M3): pass
        +
        +
        +
      4. + +
      5. Using "from <> import <>" syntax (relative import + syntax, only in Python 2.5 and later):

        +
        +
        +# pkg1/mod2.py
        +from .pkg2 import mod3
        +class M2(mod3.M3): pass
        +
        +
        +
      6. + +
      7. Other variants, for example the following construction in order to + have the pkg2.mod3.M3 symbol available in mod2 as + in point 2 above (but now under Python 3):

        +
        +
        +# pkg1/mod2.py
        +from . import pkg2
        +from .pkg2 import mod3
        +class M2(pkg2.mod3.M3): pass
        +
        +
        +
      8. + +
      + +

      Now suppose we have mod2.i with

      + +
      +
      +// mod2.i
      +%module (package="pkg1") mod2
      +%import "mod3.i"
      +// ...
      +
      +
      + +

      and mod3.i with

      + +
      +
      +// mod3.i
      +%module (package="pkg1.pkg2") mod3
      +// ...
      +
      +
      + +

      By default, SWIG would generate mod2.py proxy file with +import directive as in point 1. This can be changed with the +-relativeimport command line option. The -relativeimport instructs +SWIG to organize imports as in point 2 (for Python 2.x) or as in point 4 (for +Python 3, that is when the -py3 command line option is enabled). In short, if you have +mod2.i and mod3.i as above, then without +-relativeimport SWIG will write

      + +
      +
      +import pkg1.pkg2.mod3
      +
      +
      + +

      to mod2.py proxy file, and with -relativeimport it will +write

      + +
      +
      +import pkg2.mod3
      +
      +
      + +

      if -py3 is not used, or

      + +
      +
      +from . import pkg2
      +import pkg1.pkg2.mod3
      +
      +
      + +

      when -py3 is used.

      + +

      You should avoid using relative imports and use absolute ones whenever +possible. There are some cases, however, when relative imports may be +necessary. The first example is, when some (legacy) Python code refers entities +imported by proxy files generated by SWIG, and it assumes that the proxy file +uses relative imports. Second case is, when one puts import directives in +__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

      + + +

      As you may know, there is an incompatibility in import semantics (for the +import <> syntax) between Python 2 and 3. In Python 2.4 and +earlier it is not clear whether

      + +
      +
      +import foo
      +
      +
      +

      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). +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 +

      + +
      +
      +from __future__ import absolute_import
      +
      +
      + +

      at the very beginning of his proxy *.py file. In SWIG, it may be +accomplished with %pythonbegin directive as follows:

      + +
      +
      +%pythonbegin %{
      +from __future__ import absolute_import
      +%}
      +
      +
      + +

      36.11.4 Importing from __init__.py

      + + +

      Imports in __init__.py are handy when you want to populate a +package's namespace with names imported from other modules. In SWIG based +projects this approach may also be used to split large pieces of code into +smaller modules, compile them in parallel and then re-assemble everything at +runtime by importing submodules' contents in __init__.py, for +example.

      + +

      Unfortunately import directives in __init__.py may cause problems, +especially if they refer to a package's submodules. This is caused by the way +Python initializes packages. If you spot problems with imports from +__init__.py try using -relativeimport option. Below we +explain in detail one issue, for which the -relativeimport workaround +may be helpful.

      + +

      Consider the following example (Python 3):

      + +
      +
      +pkg1/__init__.py        # (empty)
      +pkg1/pkg2/__init__.py   # (imports something from bar.py)
      +pkg1/pkg2/foo.py
      +pkg1/pkg2/bar.py        # (imports foo.py)
      +
      +
      + +

      If the file contents are:

      + +
        +
      • pkg1/pkg2/__init__.py:

        +
        +
        +# pkg1/pkg2/__init__.py
        +from .bar import Bar
        +
        +
        +
      • + +
      • pkg1/pkg2/foo.py:

        +
        +
        +# pkg1/pkg2/foo.py
        +class Foo: pass
        +
        +
        +
      • + +
      • pkg1/pkg2/bar.py:

        +
        +
        +# pkg1/pkg2/bar.py
        +import pkg1.pkg2.foo
        +class Bar(pkg1.pkg2.foo.Foo): pass
        +
        +
        +
      • +
      + +

      Now if one simply used import pkg1.pkg2, it will usually fail:

      + +
      +
      +>>> import pkg1.pkg2
      +Traceback (most recent call last):
      +  File "<stdin>", line 1, in <module>
      +  File "./pkg1/pkg2/__init__.py", line 2, in <module>
      +    from .bar import Bar
      +  File "./pkg1/pkg2/bar.py", line 3, in <module>
      +    class Bar(pkg1.pkg2.foo.Foo): pass
      +AttributeError: 'module' object has no attribute 'pkg2'
      +
      +
      + +

      Surprisingly, if we execute the import pkg1.pkg2 directive for the +second time, it succeeds. The reason seems to be following: when Python spots +the from .bar import Bar directive in pkg1/pkg2/__init__.py +it starts loading pkg1/pkg2/bar.py. This module imports +pkg1.pkg2.foo in turn and tries to use pkg1.pkg2.foo.Foo, but +the package pkg1 is not fully initialized yet (the initialization +procedure is actually in progress) and it seems like the effect of the already seen +import pkg1.pkg2.pkg3.foo is "delayed" or ignored. Exactly the +same may happen to a proxy module generated by SWIG.

      + +

      One workaround for this case is to use a relative +import in pkg1/pkg2/bar.py. If we change bar.py to be:

      + +
      +
      +from .pkg3 import foo
      +class Bar(foo.Foo): pass
      +
      +
      + +

      or

      + +
      +
      +from . import pkg3
      +from .pkg3 import foo
      +class Bar(pkg3.foo.Foo): pass
      +
      +
      + +

      then the example works again. With SWIG, you need to enable the +-relativeimport option in order to have the above workaround in +effect (note, that the Python 2 case also needs the -relativeimport +workaround).

      + + +

      36.12 Python 3 Support

      @@ -5325,7 +5703,7 @@ The following are Python 3.0 new features that are currently supported by SWIG.

      -

      34.12.1 Function annotation

      +

      36.12.1 Function annotation

      @@ -5358,7 +5736,7 @@ For detailed usage of function annotation, see PEP 3107.

      -

      34.12.2 Buffer interface

      +

      36.12.2 Buffer interface

      @@ -5510,7 +5888,7 @@ modify the buffer.

      -

      34.12.3 Abstract base classes

      +

      36.12.3 Abstract base classes

      @@ -5551,6 +5929,92 @@ For details of abstract base class, please see PEP 3119.

      +

      36.12.4 Byte string output conversion

      + + +

      +By default, any byte string (char* or std::string) returned +from C or C++ code is decoded to text as UTF-8. This decoding uses the +surrogateescape error handler under Python 3.1 or higher -- this +error handler decodes invalid byte sequences to high surrogate characters +in the range U+DC80 to U+DCFF. + +As an example, consider the following SWIG interface, which exposes a byte +string that cannot be completely decoded as UTF-8: +

      + +
      +%module example
      +
      +%include <std_string.i>
      +
      +%inline %{
      +
      +const char* non_utf8_c_str(void) {
      +        return "h\xe9llo w\xc3\xb6rld";
      +}
      +
      +%}
      +
      + +

      +When this method is called from Python 3, the return value is the following +text string: +

      + +
      +>>> s = example.non_utf8_c_str()
      +>>> s
      +'h\udce9llo wörld'
      +
      + +

      +Since the C string contains bytes that cannot be decoded as UTF-8, those raw +bytes are represented as high surrogate characters that can be used to obtain +the original byte sequence: +

      + +
      +>>> b = s.encode('utf-8', errors='surrogateescape')
      +>>> b
      +b'h\xe9llo w\xc3\xb6rld'
      +
      + +

      +One can then attempt a different encoding, if desired (or simply leave the +byte string as a raw sequence of bytes for use in binary protocols): +

      + +
      +>>> b.decode('latin-1')
      +'héllo wörld'
      +
      + +

      +Note, however, that text strings containing surrogate characters are rejected +with the default strict codec error handler. For example: +

      + +
      +>>> with open('test', 'w') as f:
      +...     print(s, file=f)
      +...
      +Traceback (most recent call last):
      +  File "<stdin>", line 2, in <module>
      +UnicodeEncodeError: 'utf-8' codec can't encode character '\udce9' in position 1: surrogates not allowed
      +
      + +

      +This requires the user to check most strings returned by SWIG bindings, but +the alternative is for a non-UTF8 byte string to be completely inaccessible +in Python 3 code. +

      + +

      +For more details about the surrogateescape error handler, please see +PEP 383. +

      + diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html index ceea32146..5de390eab 100644 --- a/Doc/Manual/R.html +++ b/Doc/Manual/R.html @@ -6,7 +6,7 @@ -

      35 SWIG and R

      +

      37 SWIG and R

        @@ -33,7 +33,7 @@ compile and run an R interface to QuantLib running on Mandriva Linux with gcc. The R bindings also work on Microsoft Windows using Visual C++.

        -

        35.1 Bugs

        +

        37.1 Bugs

        @@ -45,7 +45,7 @@ Currently the following features are not implemented or broken:

      • C Array wrappings
      -

      35.2 Using R and SWIG

      +

      37.2 Using R and SWIG

      @@ -119,7 +119,7 @@ Without it, inheritance of wrapped objects may fail. These two files can be loaded in any order

      -

      35.3 Precompiling large R files

      +

      37.3 Precompiling large R files

      In cases where the R file is large, one make save a lot of loading @@ -137,7 +137,7 @@ will save a large amount of loading time. -

      35.4 General policy

      +

      37.4 General policy

      @@ -146,7 +146,7 @@ wrapping over the underlying functions and rely on the R type system to provide R syntax.

      -

      35.5 Language conventions

      +

      37.5 Language conventions

      @@ -155,7 +155,7 @@ and [ are overloaded to allow for R syntax (one based indices and slices)

      -

      35.6 C++ classes

      +

      37.6 C++ classes

      @@ -167,7 +167,7 @@ keep track of the pointer object which removes the necessity for a lot of the proxy class baggage you see in other languages.

      -

      35.7 Enumerations

      +

      37.7 Enumerations

      diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 301631a20..cdebfe07b 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -7,7 +7,7 @@ -

      36 SWIG and Ruby

      +

      38 SWIG and Ruby

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

        This chapter describes SWIG's support of Ruby.

        -

        36.1 Preliminaries

        +

        38.1 Preliminaries

        SWIG 1.3 is known to work with Ruby versions 1.6 and later. @@ -159,7 +159,7 @@ read the "SWIG Basics" chapter. It is also assumed that the reader has a basic understanding of Ruby.

        -

        36.1.1 Running SWIG

        +

        38.1.1 Running SWIG

        To build a Ruby module, run SWIG using the -ruby @@ -183,7 +183,7 @@ if compiling a C++ extension) that contains all of the code needed to build a Ruby extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

        -

        36.1.2 Getting the right header files

        +

        38.1.2 Getting the right header files

        In order to compile the wrapper code, the compiler needs the ruby.h @@ -206,7 +206,7 @@ installed, you can run Ruby to find out. For example:

      -

      36.1.3 Compiling a dynamic module

      +

      38.1.3 Compiling a dynamic module

      Ruby extension modules are typically compiled into shared @@ -259,19 +259,27 @@ operating system would look something like this:

      $ swig -ruby example.i
      -$ gcc -c example.c
      -$ gcc -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
      +$ gcc -O2 -fPIC -c example.c
      +$ gcc -O2 -fPIC -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
       $ gcc -shared example.o example_wrap.o -o example.so
       
      -

      For other platforms it may be necessary to compile with the -fPIC -option to generate position-independent code. If in doubt, consult the +

      +The -fPIC option tells GCC to generate position-independent code (PIC) +which is required for most architectures (it's not vital on x86, but +still a good idea as it allows code pages from the library to be shared between +processes). Other compilers may need a different option specified instead of +-fPIC. +

      + +

      +If in doubt, consult the manual pages for your compiler and linker to determine the correct set of options. You might also check the SWIG Wiki for additional information.

      -

      36.1.4 Using your module

      +

      38.1.4 Using your module

      Ruby module names must be capitalized, @@ -301,7 +309,7 @@ begins with:

      will result in an extension module using the feature name "example" and Ruby module name "Example".

      -

      36.1.5 Static linking

      +

      38.1.5 Static linking

      An alternative approach to dynamic linking is to rebuild the @@ -316,7 +324,7 @@ finding the Ruby source, adding an entry to the ext/Setup file, adding your directory to the list of extensions in the file, and finally rebuilding Ruby.

      -

      36.1.6 Compilation of C++ extensions

      +

      38.1.6 Compilation of C++ extensions

      On most machines, C++ extension modules should be linked @@ -325,8 +333,8 @@ using the C++ compiler. For example:

       $ swig -c++ -ruby example.i
      -$ g++ -c example.cxx
      -$ g++ -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
      +$ g++ -fPIC -c example.cxx
      +$ g++ -fPIC -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
       $ g++ -shared example.o example_wrap.o -o example.so
       
      @@ -348,7 +356,7 @@ $libs = append_library($libs, "supc++") create_makefile('example')
      -

      36.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 @@ -373,7 +381,7 @@ order to build extensions, you may need to download the source distribution to the Ruby package, as you will need the Ruby header files.

      -

      36.2.1 Running SWIG from Developer Studio

      +

      38.2.1 Running SWIG from Developer Studio

      If you are developing your application within Microsoft @@ -437,13 +445,13 @@ Foo = 3.0 -

      36.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.

      -

      36.3.1 Modules

      +

      38.3.1 Modules

      The SWIG %module directive specifies @@ -515,7 +523,7 @@ option to wrap everything into the global module, take care that the names of your constants, classes and methods don't conflict with any of Ruby's built-in names.

      -

      36.3.2 Functions

      +

      38.3.2 Functions

      Global functions are wrapped as Ruby module methods. For @@ -549,7 +557,7 @@ irb(main):002:0> Example.fact(4) 24 -

      36.3.3 Variable Linking

      +

      38.3.3 Variable Linking

      C/C++ global variables are wrapped as a pair of singleton @@ -611,7 +619,7 @@ directive. For example:

      effect until it is explicitly disabled using %mutable.

      -

      36.3.4 Constants

      +

      38.3.4 Constants

      C/C++ constants are wrapped as module constants initialized @@ -639,7 +647,7 @@ irb(main):002:0> Example::PI 3.14159 -

      36.3.5 Pointers

      +

      38.3.5 Pointers

      "Opaque" pointers to arbitrary C/C++ types (i.e. types that @@ -663,7 +671,7 @@ returns an instance of an internally generated Ruby class:

      A NULL pointer is always represented by the Ruby nil object.

      -

      36.3.6 Structures

      +

      38.3.6 Structures

      C/C++ structs are wrapped as Ruby classes, with accessor @@ -768,7 +776,7 @@ void Bar_f_set(Bar *b, Foo *val) { } -

      36.3.7 C++ classes

      +

      38.3.7 C++ classes

      Like structs, C++ classes are wrapped by creating a new Ruby @@ -823,7 +831,7 @@ Ale 3 -

      36.3.8 C++ Inheritance

      +

      38.3.8 C++ Inheritance

      The SWIG type-checker is fully aware of C++ inheritance. @@ -976,7 +984,7 @@ inherit from both Base1 and Base2 (i.e. they exhibit "Duck Typing").

      -

      36.3.9 C++ Overloaded Functions

      +

      38.3.9 C++ Overloaded Functions

      C++ overloaded functions, methods, and constructors are @@ -1066,7 +1074,7 @@ arises--in this case, the first declaration takes precedence.

      Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      36.3.10 C++ Operators

      +

      38.3.10 C++ Operators

      For the most part, overloaded operators are handled @@ -1108,7 +1116,7 @@ c = Example.add_complex(a, b) is discussed in the section on operator overloading.

      -

      36.3.11 C++ namespaces

      +

      38.3.11 C++ namespaces

      SWIG is aware of C++ namespaces, but namespace names do not @@ -1165,7 +1173,7 @@ and create extension modules for each namespace separately. If your program utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      36.3.12 C++ templates

      +

      38.3.12 C++ templates

      C++ templates don't present a huge problem for SWIG. However, @@ -1207,7 +1215,7 @@ irb(main):004:0> p.second 4 -

      36.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 @@ -1300,7 +1308,7 @@ puts v shown in these examples. More details can be found in the SWIG and C++ chapter.

      -

      36.3.14 C++ STL Functors

      +

      38.3.14 C++ STL Functors

      Some containers in the STL allow you to modify their default @@ -1361,7 +1369,7 @@ b -

      36.3.15 C++ STL Iterators

      +

      38.3.15 C++ STL Iterators

      The STL is well known for the use of iterators. There @@ -1444,7 +1452,7 @@ i

      If you'd rather have STL classes without any iterators, you should define -DSWIG_NO_EXPORT_ITERATOR_METHODS when running swig.

      -

      36.3.16 C++ Smart Pointers

      +

      38.3.16 C++ Smart Pointers

      In certain C++ programs, it is common to use classes that @@ -1509,7 +1517,7 @@ method. For example:

      irb(main):004:0> f = p.__deref__() # Returns underlying Foo *
      -

      36.3.17 Cross-Language Polymorphism

      +

      38.3.17 Cross-Language Polymorphism

      SWIG's Ruby module supports cross-language polymorphism @@ -1518,7 +1526,7 @@ module. Rather than duplicate the information presented in the 36.3.17.1 Exception Unrolling +

      38.3.17.1 Exception Unrolling

      Whenever a C++ director class routes one of its virtual @@ -1541,7 +1549,7 @@ method is "wrapped" using the rb_rescue2() 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.

      -

      36.4 Naming

      +

      38.4 Naming

      Ruby has several common naming conventions. Constants are @@ -1579,7 +1587,7 @@ generated 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.

      -

      36.4.1 Defining Aliases

      +

      38.4.1 Defining Aliases

      It's a fairly common practice in the Ruby built-ins and @@ -1649,7 +1657,7 @@ matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      36.4.2 Predicate Methods

      +

      38.4.2 Predicate Methods

      Ruby methods that return a boolean value and end in a @@ -1698,7 +1706,7 @@ using SWIG's "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      36.4.3 Bang Methods

      +

      38.4.3 Bang Methods

      Ruby methods that modify an object in-place and end in an @@ -1730,7 +1738,7 @@ using SWIG's "features" mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      36.4.4 Getters and Setters

      +

      38.4.4 Getters and Setters

      Often times a C++ library will expose properties through @@ -1765,7 +1773,7 @@ irb(main):003:0> puts foo.value %rename("value=") Foo::setValue(int value); -

      36.5 Input and output parameters

      +

      38.5 Input and output parameters

      A common problem in some C programs is handling parameters @@ -1904,10 +1912,10 @@ void get_dimensions(Matrix *m, int *rows, int*columns);

      r, c = Example.get_dimensions(m)
      -

      36.6 Exception handling

      +

      38.6 Exception handling

      -

      36.6.1 Using the %exception directive

      +

      38.6.1 Using the %exception directive

      The SWIG %exception directive can be @@ -2016,7 +2024,7 @@ methods and functions named getitem and setitem. limited to C++ exception handling. See the chapter on Customization Features for more examples.

      -

      36.6.2 Handling Ruby Blocks

      +

      38.6.2 Handling Ruby Blocks

      One of the highlights of Ruby and most of its standard library @@ -2083,7 +2091,7 @@ a special in typemap, like:

      For more information on typemaps, see Typemaps.

      -

      36.6.3 Raising exceptions

      +

      38.6.3 Raising exceptions

      There are three ways to raise exceptions from C++ code to @@ -2240,7 +2248,7 @@ function. The first argument passed to rb_raise() is the exception type. You can raise a custom exception type or one of the built-in Ruby exception types.

      -

      36.6.4 Exception classes

      +

      38.6.4 Exception classes

      Starting with SWIG 1.3.28, the Ruby module supports the %exceptionclass @@ -2277,7 +2285,7 @@ end

      For another example look at swig/Examples/ruby/exception_class.

      -

      36.7 Typemaps

      +

      38.7 Typemaps

      This section describes how you can modify SWIG's default @@ -2292,7 +2300,7 @@ a required part of using SWIG---the default wrapping behavior is enough in most cases. Typemaps are only used if you want to change some aspect of the primitive C-Ruby interface.

      -

      36.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 @@ -2449,7 +2457,7 @@ to be used as follows (notice how the length parameter is omitted):

      2 -

      36.7.2 Typemap scope

      +

      38.7.2 Typemap scope

      Once defined, a typemap remains in effect for all of the @@ -2495,7 +2503,7 @@ where the class itself is defined. For example:

      }; -

      36.7.3 Copying a typemap

      +

      38.7.3 Copying a typemap

      A typemap is copied by using assignment. For example:

      @@ -2537,7 +2545,7 @@ rules as for %apply (char *buf, int len) { (char *buffer, int size) }; // Multiple arguments -

      36.7.4 Deleting a typemap

      +

      38.7.4 Deleting a typemap

      A typemap can be deleted by simply defining no code. For @@ -2562,7 +2570,7 @@ defined by typemaps, clearing a fundamental type like int will make that type unusable unless you also define a new set of typemaps immediately after the clear operation.

      -

      36.7.5 Placement of typemaps

      +

      38.7.5 Placement of typemaps

      Typemap declarations can be declared in the global scope, @@ -2633,13 +2641,13 @@ In this example, this is done using the class declaration class string .

      -

      36.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:

      -

      36.7.6.1 "in" typemap

      +

      38.7.6.1 "in" typemap

      Converts Ruby objects to input @@ -2706,7 +2714,7 @@ arguments to be specified. For example:

      At this time, only zero or one arguments may be converted.

      -

      36.7.6.2 "typecheck" typemap

      +

      38.7.6.2 "typecheck" typemap

      The "typecheck" typemap is used to support overloaded @@ -2728,7 +2736,7 @@ program uses overloaded methods, you should also define a collection of "typecheck" typemaps. More details about this follow in a later section on "Typemaps and Overloading."

      -

      36.7.6.3 "out" typemap

      +

      38.7.6.3 "out" typemap

      Converts return value of a C function @@ -2779,7 +2787,7 @@ version of the C datatype matched by the typemap.

      -

      36.7.6.4 "arginit" typemap

      +

      38.7.6.4 "arginit" typemap

      The "arginit" typemap is used to set the initial value of a @@ -2794,7 +2802,7 @@ applications. For example:

      } -

      36.7.6.5 "default" typemap

      +

      38.7.6.5 "default" typemap

      The "default" typemap is used to turn an argument into a @@ -2819,7 +2827,7 @@ arguments that follow must have default values. See the 36.7.6.6 "check" typemap +

      38.7.6.6 "check" typemap

      The "check" typemap is used to supply value checking code @@ -2834,7 +2842,7 @@ arguments have been converted. For example:

      } -

      36.7.6.7 "argout" typemap

      +

      38.7.6.7 "argout" typemap

      The "argout" typemap is used to return values from arguments. @@ -2888,7 +2896,7 @@ some function like SWIG_Ruby_AppendOutput.

      See the typemaps.i library for examples.

      -

      36.7.6.8 "freearg" typemap

      +

      38.7.6.8 "freearg" typemap

      The "freearg" typemap is used to cleanup argument data. It is @@ -2915,7 +2923,7 @@ This code is also placed into a special variable $cleanup that may be used in other typemaps whenever a wrapper function needs to abort prematurely.

      -

      36.7.6.9 "newfree" typemap

      +

      38.7.6.9 "newfree" typemap

      The "newfree" typemap is used in conjunction with the %newobject @@ -2939,7 +2947,7 @@ string *foo();

      See Object ownership and %newobject for further details.

      -

      36.7.6.10 "memberin" typemap

      +

      38.7.6.10 "memberin" typemap

      The "memberin" typemap is used to copy data from an @@ -2957,21 +2965,21 @@ example:

      already provides a default implementation for arrays, strings, and other objects.

      -

      36.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.

      -

      36.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.

      -

      36.7.6.13 "throws" typemap

      +

      38.7.6.13 "throws" typemap

      The "throws" typemap is only used when SWIG parses a C++ @@ -3012,7 +3020,7 @@ specification yet they do throw exceptions, SWIG cannot know how to deal with them. For a neat way to handle these, see the Exception handling with %exception section.

      -

      36.7.6.14 directorin typemap

      +

      38.7.6.14 directorin typemap

      Converts C++ objects in director @@ -3071,7 +3079,7 @@ referring to the class itself. -

      36.7.6.15 directorout typemap

      +

      38.7.6.15 directorout typemap

      Converts Ruby objects in director @@ -3144,7 +3152,7 @@ exception.

      -

      36.7.6.16 directorargout typemap

      +

      38.7.6.16 directorargout typemap

      Output argument processing in director @@ -3202,19 +3210,19 @@ referring to the instance of the class itself -

      36.7.6.17 ret typemap

      +

      38.7.6.17 ret typemap

      Cleanup of function return values

      -

      36.7.6.18 globalin typemap

      +

      38.7.6.18 globalin typemap

      Setting of C global variables

      -

      36.7.7 Typemap variables

      +

      38.7.7 Typemap variables

      @@ -3264,7 +3272,7 @@ so that their values can be properly assigned.

      The Ruby name of the wrapper function being created.
      -

      36.7.8 Useful Functions

      +

      38.7.8 Useful Functions

      When you write a typemap, you usually have to work directly @@ -3279,7 +3287,7 @@ stick to the swig functions instead of the native Ruby functions. That should help you avoid having to rewrite a lot of typemaps across multiple languages.

      -

      36.7.8.1 C Datatypes to Ruby Objects

      +

      38.7.8.1 C Datatypes to Ruby Objects

      @@ -3321,7 +3329,7 @@ SWIG_From_float(float)
      -

      36.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 @@ -3389,7 +3397,7 @@ versions do not, but return a status value to indicate success (SWIG_OK -

      36.7.8.3 Macros for VALUE

      +

      38.7.8.3 Macros for VALUE

      RSTRING_LEN(str)

      @@ -3412,7 +3420,7 @@ versions do not, but return a status value to indicate success (SWIG_OK
      pointer to array storage
      -

      36.7.8.4 Exceptions

      +

      38.7.8.4 Exceptions

      void rb_raise(VALUE exception, const char *fmt, @@ -3491,7 +3499,7 @@ message to standard error if Ruby was invoked with the -w flag. The given format string fmt and remaining arguments are interpreted as with printf(). -

      36.7.8.5 Iterators

      +

      38.7.8.5 Iterators

      void rb_iter_break()

      @@ -3537,14 +3545,14 @@ VALUE), VALUE value)

      Equivalent to Ruby's throw.
      -

      36.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.

      -

      36.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 @@ -3609,7 +3617,7 @@ array. Since dynamic memory allocation is used to allocate memory for the array, the "freearg" typemap is used to later release this memory after the execution of the C function.

      -

      36.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 @@ -3823,7 +3831,7 @@ memory leak. Fortunately, this typemap is a lot easier to write:

      program that uses the extension, can be found in the Examples/ruby/hashargs directory of the SWIG distribution.

      -

      36.7.12 Pointer handling

      +

      38.7.12 Pointer handling

      Occasionally, it might be necessary to convert pointer values @@ -3882,7 +3890,7 @@ For example:

      } -

      36.7.12.1 Ruby Datatype Wrapping

      +

      38.7.12.1 Ruby Datatype Wrapping

      VALUE Data_Wrap_Struct(VALUE class, void @@ -3909,7 +3917,7 @@ as above. type c-type from the data object obj and assigns that pointer to ptr. -

      36.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 @@ -4001,7 +4009,7 @@ STL with ruby, you are advised to use the standard swig STL library, which does much more than this. Refer to the section called the C++ Standard Template Library. -

      36.8 Docstring Features

      +

      38.8 Docstring Features

      @@ -4035,7 +4043,7 @@ generate ri documentation from a c wrap file, you could do:

      $ rdoc -r file_wrap.c -

      36.8.1 Module docstring

      +

      38.8.1 Module docstring

      @@ -4065,7 +4073,7 @@ layout of controls on a panel, etc. to be loaded from an XML file." %module(docstring=DOCSTRING) xrc -

      36.8.2 %feature("autodoc")

      +

      38.8.2 %feature("autodoc")

      Since SWIG does know everything about the function it wraps, @@ -4086,7 +4094,7 @@ several options for autodoc controlled by the value given to the feature, described below.

      -

      36.8.2.1 %feature("autodoc", "0")

      +

      38.8.2.1 %feature("autodoc", "0")

      @@ -4110,7 +4118,7 @@ Then Ruby code like this will be generated: ... -

      36.8.2.2 %feature("autodoc", "1")

      +

      38.8.2.2 %feature("autodoc", "1")

      @@ -4130,7 +4138,7 @@ this: ... -

      36.8.2.3 %feature("autodoc", "2")

      +

      38.8.2.3 %feature("autodoc", "2")

      @@ -4142,7 +4150,7 @@ parameter types with the "2" option will result in Ruby code like this:

      -

      36.8.2.4 %feature("autodoc", "3")

      +

      38.8.2.4 %feature("autodoc", "3")

      @@ -4163,7 +4171,7 @@ Parameters: bar - Bar -

      36.8.2.5 %feature("autodoc", "docstring")

      +

      38.8.2.5 %feature("autodoc", "docstring")

      @@ -4179,7 +4187,7 @@ generated string. For example: void GetPosition(int* OUTPUT, int* OUTPUT); -

      36.8.3 %feature("docstring")

      +

      38.8.3 %feature("docstring")

      @@ -4190,10 +4198,10 @@ docstring associated with classes, function or methods are output. If an item already has an autodoc string then it is combined with the docstring and they are output together.

      -

      36.9 Advanced Topics

      +

      38.9 Advanced Topics

      -

      36.9.1 Operator overloading

      +

      38.9.1 Operator overloading

      SWIG allows operator overloading with, by using the %extend @@ -4374,7 +4382,7 @@ separate method for handling inequality since Ruby parses the expression a != b as !(a == b).

      -

      36.9.2 Creating Multi-Module Packages

      +

      38.9.2 Creating Multi-Module Packages

      The chapter on Working @@ -4500,7 +4508,7 @@ irb(main):005:0> c.getX() 5.0 -

      36.9.3 Specifying Mixin Modules

      +

      38.9.3 Specifying Mixin Modules

      The Ruby language doesn't support multiple inheritance, but @@ -4567,7 +4575,7 @@ matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      36.10 Memory Management

      +

      38.10 Memory Management

      One of the most common issues in generating SWIG bindings for @@ -4590,7 +4598,7 @@ to C++ (or vice versa) depending on what function or methods are invoked. Clearly, developing a SWIG wrapper requires a thorough understanding of how the underlying library manages memory.

      -

      36.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 @@ -4622,7 +4630,7 @@ any memory has been allocated in creating the underlying C struct or C++ struct, then a "free" function must be defined that deallocates this memory.

      -

      36.10.2 Object Ownership

      +

      38.10.2 Object Ownership

      As described above, memory management depends on clearly @@ -4682,7 +4690,7 @@ public: C++ constructor, thus creating a new foo object. By default, SWIG will assign the new Ruby object a "free" function. When the Ruby object is garbage collected, the "free" function will be -called. It in turn will call Foo's destructor.

      +called. It in turn will call Foo's destructor.

      Next, consider this code:

      @@ -4767,7 +4775,7 @@ public:

      This code can be seen in swig/examples/ruby/tracking.

      -

      36.10.3 Object Tracking

      +

      38.10.3 Object Tracking

      The remaining parts of this section will use the class library @@ -4992,7 +5000,7 @@ However, if you implement your own free functions (see below) you may also have to call the SWIG_RubyRemoveTracking and RubyUnlinkObjects methods.

      -

      36.10.4 Mark Functions

      +

      38.10.4 Mark Functions

      With a bit more testing, we see that our class library still @@ -5121,7 +5129,7 @@ irb(main):016:0>

      This code can be seen in swig/examples/ruby/mark_function.

      -

      36.10.5 Free Functions

      +

      38.10.5 Free Functions

      By default, SWIG creates a "free" function that is called when @@ -5288,7 +5296,7 @@ been freed, and thus raises a runtime exception.

      This code can be seen in swig/examples/ruby/free_function.

      -

      36.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 f9ea5b2ef..bd929f7d4 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -224,7 +224,7 @@ $ swig -c++ -python -o example_wrap.cpp example.i

      The C/C++ output file created by SWIG often -contains everything that is needed to construct a extension module +contains everything that is needed to construct an extension module for the target scripting language. SWIG is not a stub compiler nor is it usually necessary to edit the output file (and if you look at the output, you probably won't want to). To build the final extension module, the @@ -233,7 +233,7 @@ program to create a shared library.

      -Many target languages will also generate proxy class files in the +For many target languages SWIG will also generate proxy class files in the target language. The default output directory for these language specific files is the same directory as the generated C/C++ file. This can be modified using the -outdir option. For example: @@ -484,7 +484,7 @@ Or in Python: Whenever possible, SWIG creates an interface that closely matches the underlying C/C++ code. However, due to subtle differences between languages, run-time environments, and semantics, it is not always possible to do so. The -next few sections describes various aspects of this mapping. +next few sections describe various aspects of this mapping.

      5.2.1 Basic Type Handling

      @@ -728,7 +728,7 @@ However, for the same conservative reasons even a constant with a simple cast wi
      -#define F_CONST (double) 5            // A floating pointer constant with cast
      +#define F_CONST (double) 5            // A floating point constant with cast
       
      @@ -750,7 +750,7 @@ enum values as assigned by the C compiler.

      The %constant directive is used to more precisely create constants corresponding to different C datatypes. Although it is not -usually not needed for simple values, it is more useful when working +usually needed for simple values, it is more useful when working with pointers and other more complex datatypes. Typically, %constant is only used when you want to add constants to the scripting language interface that are not defined in the original header file. @@ -868,7 +868,7 @@ from a scripting language to a C char *, the pointer usually points to string data stored inside the interpreter. It is almost always a really bad idea to modify this data. Furthermore, some languages may explicitly disallow it. For instance, in Python, -strings are supposed be immutable. If you violate this, you will probably +strings are supposed to be immutable. If you violate this, you will probably receive a vast amount of wrath when you unleash your module on the world.

      @@ -1483,7 +1483,7 @@ void transpose(double (*a)[20]);

      Like C, SWIG does not perform array bounds checking. It is up to the -user to make sure the pointer points a suitably allocated region of memory. +user to make sure the pointer points to a suitably allocated region of memory.

      @@ -1888,11 +1888,22 @@ and a more descriptive one, but the two functions are otherwise equivalent: pattern part is a regular expression in Perl syntax (as supported by the Perl Compatible Regular Expressions (PCRE)) library and the subst string - can contain back-references introduced by '\' or, as backslashes need - to be escaped in C strings, rather by "\\". For example, to remove - any alphabetic prefix before an underscore you could use the following directive: - %rename("regex:/(\\w+)_(.*)/\\2/") - Prefix_PrintPrint + can contain back-references of the form \N where N is a digit + from 0 to 9, or one of the following escape sequences: \l, \L, + \u, \U or \E. The back-references are replaced with the + contents of the corresponding capture group while the escape sequences perform the + case conversion in the substitution string: \l and \L convert to + the lower case, while \u and \U convert to the upper case. The + difference between the elements of each pair is that \l and \u + change the case of the next character only, while \L and \U do + it for all the remaining characters or until \E is encountered. + + Finally please notice that backslashes need to be escaped in C strings, so in + practice "\\" must be used in all these escape sequences. For example, + to remove any alphabetic prefix before an underscore and capitalize the remaining + part you could use the following directive: + %rename("regex:/(\\w+)_(.*)/\\u\\2/") + prefix_printPrint command:cmd @@ -2254,7 +2265,7 @@ disabled using %nocallback. When you do this, the interface now works

      Notice that when the function is used as a callback, special names -such as add_cb is used instead. To call the function +such as add_cb are used instead. To call the function normally, just use the original function name such as add().

      @@ -2300,7 +2311,7 @@ handle C++ are described in the next section. If SWIG encounters the definition of a structure or union, it creates a set of accessor functions. Although SWIG does not need structure definitions to build an interface, providing definitions -make it possible to access structure members. The accessor functions +makes it possible to access structure members. The accessor functions generated by SWIG simply take a pointer to an object and allow access to an individual member. For example, the declaration :

      @@ -2423,7 +2434,7 @@ vector_struct
      , SWIG knows that this is the same as Structures involving character strings require some care. SWIG assumes that all members of type char * have been dynamically allocated using malloc() and that they are NULL-terminated -ASCII strings. When such a member is modified, the previously contents +ASCII strings. When such a member is modified, the previous contents will be released, and the new contents allocated. For example :

      @@ -2508,7 +2519,7 @@ typedef struct Bar {
       

      When a structure member is wrapped, it is handled as a pointer, unless the %naturalvar directive is used where it is handled more like a C++ reference (see C++ Member data). -The accessors to the member variable as a pointer is effectively wrapped as follows: +The accessors to the member variable as a pointer are effectively wrapped as follows:

      @@ -2645,8 +2656,8 @@ struct Bar { // Default constructor generated.

      -Since ignoring the implicit or default destructors most of the times -produce memory leaks, SWIG will always try to generate them. If +Since ignoring the implicit or default destructors most of the time +produces memory leaks, SWIG will always try to generate them. If needed, however, you can selectively disable the generation of the default/implicit destructor by using %nodefaultdtor

      @@ -2676,7 +2687,7 @@ has now been enabled as the default behavior. Note: There are also the -nodefault option and %nodefault directive, which disable both the default or implicit destructor generation. This could lead to memory leaks across -the target languages, and is highly recommended you don't use them. +the target languages, and it is highly recommended you don't use them.

      @@ -3269,7 +3280,7 @@ initialization on module loading, you could write this:

      -This section describes the general approach for building interface +This section describes the general approach for building interfaces with SWIG. The specifics related to a particular scripting language are found in later chapters.

      @@ -3284,9 +3295,9 @@ of steps you can follow to make an interface for a C program :

      • Identify the functions that you want to wrap. It's probably not -necessary to access every single function in a C program--thus, a +necessary to access every single function of a C program--thus, a little forethought can dramatically simplify the resulting scripting -language interface. C header files are particularly good source for +language interface. C header files are a particularly good source for finding things to wrap.
      • Create a new interface file to describe the scripting language @@ -3331,7 +3342,7 @@ to the swig-devel mailing list or to

        -The preferred method of using SWIG is to generate separate interface +The preferred method of using SWIG is to generate a separate interface file. Suppose you have the following C header file :

        @@ -3425,7 +3436,7 @@ include certain header files by using a %{,%} block like this:
         #include <GL/glu.h>
         %}
         
        -// Put rest of declarations here
        +// Put the rest of the declarations here
         ...
         
        @@ -3467,7 +3478,7 @@ program that is more interactive. In many cases, the old or Tcl script.

        -Note: If some cases, you might be inclined to create a +Note: In some cases, you might be inclined to create a scripting language wrapper for main(). If you do this, the compilation will probably work and your module might even load correctly. The only trouble is that when you call your diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 2713725d7..f9558994b 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -185,7 +185,6 @@ The following C++ features are not currently supported:

        • Overloaded versions of certain operators (new, delete, etc.) -
        • Nested classes, see Nested classes for workarounds.

        @@ -217,7 +216,7 @@ to use the C++ compiler. For example:

         $ swig -c++ -tcl example.i
        -$ c++ -c example_wrap.cxx 
        +$ c++ -fPIC -c example_wrap.cxx 
         $ c++ example_wrap.o $(OBJS) -o example.so
         
        @@ -960,8 +959,9 @@ Similarly, all data attributes declared as const are wrapped as read-on

        +By default, SWIG uses the const reference typemaps for members that are primitive types. There are some subtle issues when wrapping data members that are -themselves classes. For instance, if you had another class like this, +not primitive types, such as classes. For instance, if you had another class like this,

        @@ -974,7 +974,8 @@ public:

        -then the low-level accessor to the items member actually uses pointers. For example: +then the low-level accessor to the items member actually uses pointers. +For example:

        @@ -999,31 +1000,7 @@ This can be somewhat unnatural for some types. For example, a user would expect the STL std::string class member variables to be wrapped as a string in the target language, rather than a pointer to this class. The const reference typemaps offer this type of marshalling, so there is a feature to tell SWIG to use the const reference typemaps rather than the pointer typemaps. -It is the %naturalvar directive and is used as follows: -

        - -
        -
        -// All List variables will use const List& typemaps
        -%naturalvar List;
        -
        -// Only Foo::myList will use const List& typemaps
        -%naturalvar Foo::myList;
        -struct Foo {
        -  List myList;
        -};
        -
        -// All variables will use const reference typemaps
        -%naturalvar;
        -
        -
        - -

        -The observant reader will notice that %naturalvar works like any other -feature flag directive, -except it can also be attached to class types. -The first of the example usages above show %naturalvar attaching to the List class. -Effectively this feature changes the way accessors are generated to the following: +It is the naturalvar feature and can be used to effectively change the way accessors are generated to the following:

        @@ -1038,15 +1015,45 @@ void Foo_items_set(Foo *self, const List &value) {

        -In fact it is generally a good idea to use this feature globally as the reference typemaps have extra NULL checking compared to the pointer typemaps. +The %naturalvar directive is a macro for, and hence equivalent to, %feature("naturalvar"). It can be used as follows: +

        + +
        +
        +// All List variables will use const List& typemaps
        +%naturalvar List;
        +
        +// Only Foo::myList will use const List& typemaps
        +%naturalvar Foo::myList;
        +struct Foo {
        +  List myList;
        +};
        +
        +// All non-primitive types will use const reference typemaps
        +%naturalvar;
        +
        +
        + +

        +The observant reader will notice that %naturalvar works like any other +feature flag directive but with some extra flexibility. +The first of the example usages above shows %naturalvar attaching to the myList's variable type, that is the List class. +The second usage shows %naturalvar attaching to the variable name. +Hence the naturalvar feature can be used on either the variable's name or type. +Note that using the naturalvar feature on a variable's name overrides any naturalvar feature attached to the variable's type. +

        + +

        +It is generally a good idea to use this feature globally as the reference typemaps have extra NULL checking compared to the pointer typemaps. A pointer can be NULL, whereas a reference cannot, so the extra checking ensures that the target language user does not pass in a value that translates to a NULL pointer and thereby preventing any potential NULL pointer dereferences. The %naturalvar feature will apply to global variables in addition to member variables in some language modules, eg C# and Java.

        -Other alternatives for turning this feature on globally are to use the swig -naturalvar commandline option -or the module mode option, %module(naturalvar=1) +The naturalvar behavior can also be turned on as a global setting via the -naturalvar commandline option +or the module mode option, %module(naturalvar=1). +However, any use of %feature("naturalvar") will override the global setting.

        @@ -1522,7 +1529,7 @@ multiple inheritance. spirit, and target language capabilities, as possible. In most cases, this means that SWIG will parse the non-public inheritance declarations, but that will have no effect in the generated code, -besides the implicit policies derived for constructor and +besides the implicit policies derived for constructors and destructors.

        @@ -4967,141 +4974,55 @@ public:

        -There is some support for nested structs and unions when wrapping C code, -see Nested structures for further details. -The added complexity of C++ compared to C means this approach does not work well for -C++ code (when using the -c++ command line option). -For C++, a nested class is treated much like an opaque pointer, so anything useful within the nested class, such as its -methods and variables, are not accessible from the target language. -True nested class support may be added to SWIG in the future, however, -until then some of the following workarounds can be applied to improve the situation. +If the target language supports the nested classes concept (like Java), the nested C++ classes +are wrapped as nested target language proxy classes. (In case of Java - "static" nested classes.) +Only public nested classes are wrapped. Otherwise there is little difference between nested and +normal classes.

        -

        -It might be possible to use partial class information as often you can accept that the nested class is not needed, -especially if it is not actually used in any methods you need from the target language. -Imagine you are wrapping the following Outer class which contains a nested class Inner. -The easiest thing to do is turn a blind eye to the warning that SWIG generates, or simply suppress it: +If the target language doesn't support nested classes directly, or the support is not implemented in the +language module (like for python currently), then the visible nested classes are moved to the same name +space as the containing class (nesting hierarchy is "flattened"). The same behaviour may be turned on for +C# and Java by the %feature ("flatnested"); If there is a class with the same name in the outer namespace +the inner class (or the global one) may be renamed or ignored:

        -%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::Inner;
        -
        -class Outer {
        -public:
        -  class Inner {
        -    public:
        -      ...
        -  };
        -  Inner getInner();
        -  void useInner(const Inner& inner);
        -  ...
        -};
        -
        -
        - -

        -Note that if Inner can be used as an opaque type, the default wrapping approach suffices. -For example, if the nested class does not need to be created from the target language, but can be obtained via a method -call, such as the getInner() method above, the returned value can then be passed around, such as passed into the -useInner() method. -

        - -

        -With some more effort the above situation can be improved somewhat and a nested class can be constructed and used -from the target language much like any other non-nested class. Assuming we have the Outer class in a header file: -

        - -
        -
        -// File outer.h
        -class Outer {
        -public:
        -  class Inner {
        -    public:
        -      int var;
        -      Inner(int v = 0) : var(v) {}
        -  };
        -  Inner getInner();
        -  void useInner(const Inner& inner);
        -};
        -
        -
        - -

        -The following interface file works around the nested class limitations by redefining the nested class as a global class. -A typedef for the compiler and the nestedworkaround -feature flag is also required in -order for the generated wrappers to compile. This flag simply removes all the type information from SWIG, so SWIG treats -the nested class as if it had not been parsed at all. -

        - -
        -
        -// File : example.i
        -%module example
        -
        -// Redefine nested class in global scope in order for SWIG to generate
        -// a proxy class. Only SWIG parses this definition.
        -class Inner {
        +%rename (Bar_Foo) Bar::Foo;
        +class Foo {};
        +class Bar {
           public:
        -    int var;
        -    Inner(int v = 0) : var(v) {}
        +  class Foo {};
         };
        -
        -%nestedworkaround Outer::Inner;
        -
        -%{
        -#include "outer.h"
        -%}
        -%include "outer.h"
        -
        -// We've fooled SWIG into thinking that Inner is a global class, so now we need
        -// to trick the C++ compiler into understanding this apparent global type.
        -%{
        -typedef Outer::Inner Inner;
        -%}
         
        -

        -The downside to this approach is a more complex interface file and having to maintain two definitions of Inner, -the real one and the one in the interface file that SWIG parses. -However, the upside is that all the methods/variables in the nested class are available from the target language -as a proxy class is generated instead of treating the nested class as an opaque type. -The proxy class can be constructed from the target language and passed into any methods accepting the nested class. -Also note that the original header file is parsed unmodified. -

        -Finally, conditional compilation can be used as a workaround to comment out nested class definitions in the actual headers, -assuming you are able to modify them. +Compatibility Note: +Prior to SWIG-3.0.0, there was limited nested class support. Nested classes were treated as opaque pointers. +However, there was a workaround for nested class support in these older versions requiring the user to replicate +the nested class in the global scope, adding in a typedef for the nested class in the global scope and +using the "nestedworkaround" feature on the nested class. This resulted in approximately the +same behaviour as the "flatnested" feature. With proper nested class support now available in SWIG-3.0.0, this +feature has been deprecated and no longer works requiring code changes. If you see the following warning:

        -
        +
        -// File outer.h
        -class Outer {
        -public:
        -#ifndef SWIG
        -  class Inner {
        -    public:
        -      ...
        -  };
        -#endif
        -  ...
        -};
        +example.i:8: Warning 126: The nestedworkaround feature is deprecated
         

        -This workaround used to be common when SWIG could not deal with nested classes particulary well. -This should just be a last resort for unusual corner cases now as SWIG can parse nested classes and even handle nested template classes fairly well. +consider using the "flatnested" feature discussed above which generates a non-nested proxy class, like the +"nestedworkaround" feature did. Alternatively, use the default nested class code generation, which may generate an +equivalent to a nested proxy class in the target language, depending on the target language support.

        -Compatibility Note: SWIG-1.3.40 and earlier versions did not have the nestedworkaround feature +SWIG-1.3.40 and earlier versions did not have the nestedworkaround feature and the generated code resulting from parsing nested classes did not always compile. Nested class warnings could also not be suppressed using %warnfilter.

        diff --git a/Doc/Manual/Scripting.html b/Doc/Manual/Scripting.html index e6a2eee24..c714fa0d7 100644 --- a/Doc/Manual/Scripting.html +++ b/Doc/Manual/Scripting.html @@ -293,7 +293,7 @@ A proxy class is a special kind of object that gets created in a scripting language to access a C/C++ class (or struct) in a way that looks like the original structure (that is, it proxies the real C++ class). For example, if you -have the following C definition :

        +have the following C++ definition :

         class Vector {
        @@ -334,12 +334,12 @@ Finally, in Tcl :
         
         
         Vector v
        -v configure -x 3 -y 4 -z 13
        +v configure -x 3 -y 4 -z -13
         
         

        -When proxy classes are used, two objects are at really work--one in +When proxy classes are used, two objects are really at work--one in the scripting language, and an underlying C/C++ object. Operations affect both objects equally and for all practical purposes, it appears as if you are simply manipulating a C/C++ object. @@ -353,7 +353,7 @@ The final step in using a scripting language with your C/C++ application is adding your extensions to the scripting language itself. There are two primary approaches for doing this. The preferred technique is to build a dynamically loadable -extension in the form a shared library. Alternatively, you can +extension in the form of a shared library. Alternatively, you can recompile the scripting language interpreter with your extensions added to it.

        @@ -364,21 +364,16 @@ added to it.

        To create a shared library or DLL, you often need to look at the manual pages for your compiler and linker. However, the procedure -for a few common machines is shown below:

        +for a few common platforms is shown below:

         # Build a shared library for Solaris
        -gcc -c example.c example_wrap.c -I/usr/local/include
        +gcc -fpic -c example.c example_wrap.c -I/usr/local/include
         ld -G example.o example_wrap.o -o example.so
         
         # Build a shared library for Linux
         gcc -fpic -c example.c example_wrap.c -I/usr/local/include
         gcc -shared example.o example_wrap.o -o example.so
        -
        -# Build a shared library for Irix
        -gcc -c example.c example_wrap.c -I/usr/local/include
        -ld -shared example.o example_wrap.o -o example.so
        -
         

        diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 195111424..bcae8139d 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

        SWIG-3.0 Documentation

        -Last update : SWIG-3.0.0 (in progress) +Last update : SWIG-3.0.2 (4 Jun 2014)

        Sections

        @@ -18,6 +18,7 @@ Last update : SWIG-3.0.0 (in progress)
      • Scripting
      • SWIG Basics (Read this!)
      • SWIG and C++
      • +
      • SWIG and C++11
      • The SWIG preprocessor
      • The SWIG library
      • Argument handling
      • @@ -41,6 +42,7 @@ Last update : SWIG-3.0.0 (in progress)
      • Go support
      • Guile support
      • Java support
      • +
      • Javascript support
      • Common Lisp support
      • Lua support
      • Modula3 support
      • diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index e6b3b4a43..c12701ac9 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -6,7 +6,7 @@ -

        37 SWIG and Tcl

        +

        39 SWIG and Tcl

          @@ -83,7 +83,7 @@ Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but this is no longer supported.

          -

          37.1 Preliminaries

          +

          39.1 Preliminaries

          @@ -109,7 +109,7 @@ build a Tcl extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

          -

          37.1.1 Getting the right header files

          +

          39.1.1 Getting the right header files

          @@ -127,7 +127,7 @@ this is the case, you should probably make a symbolic link so that tcl.h -

          37.1.2 Compiling a dynamic module

          +

          39.1.2 Compiling a dynamic module

          @@ -139,8 +139,8 @@ using commands like this (shown for Linux):

           $ swig -tcl example.i
          -$ gcc -c example.c
          -$ gcc -c example_wrap.c -I/usr/local/include
          +$ gcc -fPIC -c example.c
          +$ gcc -fPIC -c example_wrap.c -I/usr/local/include
           $ gcc -shared example.o example_wrap.o -o example.so
           
          @@ -163,7 +163,7 @@ The name of the module is specified using the %module directive or the -module command line option.

          -

          37.1.3 Static linking

          +

          39.1.3 Static linking

          @@ -229,7 +229,7 @@ minimal in most situations (and quite frankly not worth the extra hassle in the opinion of this author).

          -

          37.1.4 Using your module

          +

          39.1.4 Using your module

          @@ -357,7 +357,7 @@ to the default system configuration (this requires root access and you will need the man pages).

          -

          37.1.5 Compilation of C++ extensions

          +

          39.1.5 Compilation of C++ extensions

          @@ -374,8 +374,8 @@ compiler. For example:

           % swig -c++ -tcl example.i
          -% g++ -c example.cxx
          -% g++ -c example_wrap.cxx -I/usr/local/include
          +% g++ -fPIC -c example.cxx
          +% g++ -fPIC -c example_wrap.cxx -I/usr/local/include
           % g++ -shared example.o example_wrap.o -o example.so
           
          @@ -387,8 +387,8 @@ Solaris, you often need to add an extra library -lCrun like this:
           % swig -c++ -tcl example.i
          -% CC -c example.cxx
          -% CC -c example_wrap.cxx -I/usr/local/include
          +% CC -KPIC -c example.cxx
          +% CC -KPIC -c example_wrap.cxx -I/usr/local/include
           % CC -G example.o example_wrap.o -L/opt/SUNWspro/lib -o example.so -lCrun
           
          @@ -440,7 +440,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

          -

          37.1.6 Compiling for 64-bit platforms

          +

          39.1.6 Compiling for 64-bit platforms

          @@ -467,7 +467,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

          -

          37.1.7 Setting a package prefix

          +

          39.1.7 Setting a package prefix

          @@ -486,7 +486,7 @@ option will append the prefix to the name when creating a command and call it "Foo_bar".

          -

          37.1.8 Using namespaces

          +

          39.1.8 Using namespaces

          @@ -508,7 +508,7 @@ When the -namespace option is used, objects in the module are always accessed with the namespace name such as Foo::bar.

          -

          37.2 Building Tcl/Tk Extensions under Windows 95/NT

          +

          39.2 Building Tcl/Tk Extensions under Windows 95/NT

          @@ -519,7 +519,7 @@ covers the process of using SWIG with Microsoft Visual C++. although the procedure may be similar with other compilers.

          -

          37.2.1 Running SWIG from Developer Studio

          +

          39.2.1 Running SWIG from Developer Studio

          @@ -577,7 +577,7 @@ MSDOS > tclsh80 %

        -

        37.2.2 Using NMAKE

        +

        39.2.2 Using NMAKE

        @@ -640,7 +640,7 @@ to get you started. With a little practice, you'll be making lots of Tcl extensions.

        -

        37.3 A tour of basic C/C++ wrapping

        +

        39.3 A tour of basic C/C++ wrapping

        @@ -651,7 +651,7 @@ classes. This section briefly covers the essential aspects of this wrapping.

        -

        37.3.1 Modules

        +

        39.3.1 Modules

        @@ -685,7 +685,7 @@ To fix this, supply an extra argument to load like this:

      -

      37.3.2 Functions

      +

      39.3.2 Functions

      @@ -710,7 +710,7 @@ like you think it does: % -

      37.3.3 Global variables

      +

      39.3.3 Global variables

      @@ -790,7 +790,7 @@ extern char *path; // Read-only (due to %immutable) -

      37.3.4 Constants and enums

      +

      39.3.4 Constants and enums

      @@ -874,7 +874,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l conversion. This allows the global statement to be omitted.

      -

      37.3.5 Pointers

      +

      39.3.5 Pointers

      @@ -970,7 +970,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

      -

      37.3.6 Structures

      +

      39.3.6 Structures

      @@ -1252,7 +1252,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the memory management section that appears shortly.

      -

      37.3.7 C++ classes

      +

      39.3.7 C++ classes

      @@ -1319,7 +1319,7 @@ In Tcl, the static member is accessed as follows: -

      37.3.8 C++ inheritance

      +

      39.3.8 C++ inheritance

      @@ -1368,7 +1368,7 @@ For instance: It is safe to use multiple inheritance with SWIG.

      -

      37.3.9 Pointers, references, values, and arrays

      +

      39.3.9 Pointers, references, values, and arrays

      @@ -1422,7 +1422,7 @@ to hold the result and a pointer is returned (Tcl will release this memory when the return value is garbage collected).

      -

      37.3.10 C++ overloaded functions

      +

      39.3.10 C++ overloaded functions

      @@ -1545,7 +1545,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      37.3.11 C++ operators

      +

      39.3.11 C++ operators

      @@ -1647,7 +1647,7 @@ There are ways to make this operator appear as part of the class using the % Keep reading.

      -

      37.3.12 C++ namespaces

      +

      39.3.12 C++ namespaces

      @@ -1711,7 +1711,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      37.3.13 C++ templates

      +

      39.3.13 C++ templates

      @@ -1763,7 +1763,7 @@ More details can be found in the SWIG and C++ -

      37.3.14 C++ Smart Pointers

      +

      39.3.14 C++ Smart Pointers

      @@ -1847,7 +1847,7 @@ simply use the __deref__() method. For example: -

      37.4 Further details on the Tcl class interface

      +

      39.4 Further details on the Tcl class interface

      @@ -1860,7 +1860,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

      -

      37.4.1 Proxy classes

      +

      39.4.1 Proxy classes

      @@ -1925,7 +1925,7 @@ function. This allows objects to be encapsulated objects that look a lot like as shown in the last section.

      -

      37.4.2 Memory management

      +

      39.4.2 Memory management

      @@ -2113,7 +2113,7 @@ typemaps--an advanced topic discussed later.

      -

      37.5 Input and output parameters

      +

      39.5 Input and output parameters

      @@ -2301,7 +2301,7 @@ set c [lindex $dim 1] -

      37.6 Exception handling

      +

      39.6 Exception handling

      @@ -2435,7 +2435,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex See the chapter on "Customization Features" for more examples.

      -

      37.7 Typemaps

      +

      39.7 Typemaps

      @@ -2452,7 +2452,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Tcl interface.

      -

      37.7.1 What is a typemap?

      +

      39.7.1 What is a typemap?

      @@ -2569,7 +2569,7 @@ parameter is omitted): -

      37.7.2 Tcl typemaps

      +

      39.7.2 Tcl typemaps

      @@ -2707,7 +2707,7 @@ Initialize an argument to a value before any conversions occur. Examples of these methods will appear shortly.

      -

      37.7.3 Typemap variables

      +

      39.7.3 Typemap variables

      @@ -2778,7 +2778,7 @@ properly assigned. The Tcl name of the wrapper function being created. -

      37.7.4 Converting a Tcl list to a char **

      +

      39.7.4 Converting a Tcl list to a char **

      @@ -2840,7 +2840,7 @@ argv[2] = Larry 3 -

      37.7.5 Returning values in arguments

      +

      39.7.5 Returning values in arguments

      @@ -2882,7 +2882,7 @@ result, a Tcl function using these typemaps will work like this : % -

      37.7.6 Useful functions

      +

      39.7.6 Useful functions

      @@ -2959,7 +2959,7 @@ int Tcl_IsShared(Tcl_Obj *obj); -

      37.7.7 Standard typemaps

      +

      39.7.7 Standard typemaps

      @@ -3043,7 +3043,7 @@ work) -

      37.7.8 Pointer handling

      +

      39.7.8 Pointer handling

      @@ -3119,7 +3119,7 @@ For example: -

      37.8 Turning a SWIG module into a Tcl Package.

      +

      39.8 Turning a SWIG module into a Tcl Package.

      @@ -3191,7 +3191,7 @@ As a final note, most SWIG examples do not yet use the to use the load command instead.

      -

      37.9 Building new kinds of Tcl interfaces (in Tcl)

      +

      39.9 Building new kinds of Tcl interfaces (in Tcl)

      @@ -3290,7 +3290,7 @@ danger of blowing something up (although it is easily accomplished with an out of bounds array access).

      -

      37.9.1 Proxy classes

      +

      39.9.1 Proxy classes

      @@ -3411,7 +3411,7 @@ short, but clever Tcl script can be combined with SWIG to do many interesting things.

      -

      37.10 Tcl/Tk Stubs

      +

      39.10 Tcl/Tk Stubs

      diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 81e3fd1bb..cba524149 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -6,7 +6,7 @@ -

      10 Typemaps

      +

      11 Typemaps

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

        10.1 Introduction

        +

        11.1 Introduction

        @@ -112,7 +112,7 @@ to re-read the earlier chapters if you have found your way to this chapter with only a vague idea of what SWIG already does by default.

        -

        10.1.1 Type conversion

        +

        11.1.1 Type conversion

        @@ -205,7 +205,7 @@ to read the extension documentation for your favorite language to know how it works (an exercise left to the reader).

        -

        10.1.2 Typemaps

        +

        11.1.2 Typemaps

        @@ -306,7 +306,7 @@ parts of the generated wrapper functions. Because arbitrary code can be insert possible to completely change the way in which values are converted.

        -

        10.1.3 Pattern matching

        +

        11.1.3 Pattern matching

        @@ -408,7 +408,7 @@ In this case, a single input object is expanded into a pair of C arguments. Thi provides a hint to the unusual variable naming scheme involving $1, $2, and so forth.

        -

        10.1.4 Reusing typemaps

        +

        11.1.4 Reusing typemaps

        @@ -464,7 +464,7 @@ typedef int size_t; then SWIG already knows that the int typemaps apply. You don't have to do anything.

        -

        10.1.5 What can be done with typemaps?

        +

        11.1.5 What can be done with typemaps?

        @@ -576,7 +576,7 @@ typemaps that expand upon this list. For example, the Java module defines a var aspects of the Java bindings. Consult language specific documentation for further details.

        -

        10.1.6 What can't be done with typemaps?

        +

        11.1.6 What can't be done with typemaps?

        @@ -639,7 +639,7 @@ void wrap_foo(char *s, int x) {

      -

      10.1.7 Similarities to Aspect Oriented Programming

      +

      11.1.7 Similarities to Aspect Oriented Programming

      @@ -657,7 +657,7 @@ SWIG can also be viewed as has having a second set of aspects based around %exception are also cross-cutting concerns as they encapsulate code that can be used to add logging or exception handling to any function.

      -

      10.1.8 The rest of this chapter

      +

      11.1.8 The rest of this chapter

      @@ -677,14 +677,14 @@ of "The C Programming Language" by Kernighan and Ritchie or "The C++ Programming Language" by Stroustrup before going any further.

      -

      10.2 Typemap specifications

      +

      11.2 Typemap specifications

      This section describes the behavior of the %typemap directive itself.

      -

      10.2.1 Defining a typemap

      +

      11.2.1 Defining a typemap

      @@ -797,7 +797,7 @@ Admittedly, it's not the most readable syntax at first glance. However, the pur individual pieces will become clear.

      -

      10.2.2 Typemap scope

      +

      11.2.2 Typemap scope

      @@ -847,7 +847,7 @@ class Foo { -

      10.2.3 Copying a typemap

      +

      11.2.3 Copying a typemap

      @@ -905,7 +905,7 @@ The patterns for %apply follow the same rules as for %typemap. -

      10.2.4 Deleting a typemap

      +

      11.2.4 Deleting a typemap

      @@ -938,7 +938,7 @@ For example: after the clear operation.

      -

      10.2.5 Placement of typemaps

      +

      11.2.5 Placement of typemaps

      @@ -1018,7 +1018,7 @@ It should be noted that for scoping to work, SWIG has to know that stringclass string.

      -

      10.3 Pattern matching rules

      +

      11.3 Pattern matching rules

      @@ -1026,7 +1026,7 @@ The section describes the pattern matching rules by which C/C++ datatypes are as The matching rules can be observed in practice by using the debugging options also described.

      -

      10.3.1 Basic matching rules

      +

      11.3.1 Basic matching rules

      @@ -1125,7 +1125,7 @@ void F(int x[1000]); // int [ANY] rule (typemap 5) stripped all qualifiers in one step.

      -

      10.3.2 Typedef reductions matching

      +

      11.3.2 Typedef reductions matching

      @@ -1300,7 +1300,7 @@ void go(Struct aStruct); -

      10.3.3 Default typemap matching rules

      +

      11.3.3 Default typemap matching rules

      @@ -1438,7 +1438,7 @@ Finally the best way to view the typemap matching rules in action is via the -

      10.3.4 Multi-arguments typemaps

      +

      11.3.4 Multi-arguments typemaps

      @@ -1468,7 +1468,7 @@ but all subsequent arguments must match exactly.

      -

      10.3.5 Matching rules compared to C++ templates

      +

      11.3.5 Matching rules compared to C++ templates

      @@ -1627,7 +1627,7 @@ are similar to those for specialized template handling.

      -

      10.3.6 Debugging typemap pattern matching

      +

      11.3.6 Debugging typemap pattern matching

      @@ -1840,7 +1840,7 @@ Also the types may be displayed slightly differently - char const * and

    -

    10.4 Code generation rules

    +

    11.4 Code generation rules

    @@ -1848,7 +1848,7 @@ This section describes rules by which typemap code is inserted into the generated wrapper code.

    -

    10.4.1 Scope

    +

    11.4.1 Scope

    @@ -1926,7 +1926,7 @@ a block scope when it is emitted. This sometimes results in a less complicated Note that only the third of the three typemaps have the typemap code passed through the SWIG preprocessor.

    -

    10.4.2 Declaring new local variables

    +

    11.4.2 Declaring new local variables

    @@ -2077,7 +2077,7 @@ each type must have its own local variable declaration. -

    10.4.3 Special variables

    +

    11.4.3 Special variables

    @@ -2329,7 +2329,7 @@ Another approach, which only works for arrays is to use the $1_basetype -

    10.4.4 Special variable macros

    +

    11.4.4 Special variable macros

    @@ -2341,7 +2341,7 @@ it is done during the SWIG parsing/compilation stages. The following special variable macros are available across all language modules.

    -

    10.4.4.1 $descriptor(type)

    +

    11.4.4.1 $descriptor(type)

    @@ -2352,7 +2352,7 @@ For example, $descriptor(std::vector<int> *) will expand into Run-time type checker usage section.

    -

    10.4.4.2 $typemap(method, typepattern)

    +

    11.4.4.2 $typemap(method, typepattern)

    @@ -2409,7 +2409,7 @@ The result is the following expansion -

    10.5 Common typemap methods

    +

    11.5 Common typemap methods

    @@ -2417,7 +2417,7 @@ The set of typemaps recognized by a language module may vary. However, the following typemap methods are nearly universal:

    -

    10.5.1 "in" typemap

    +

    11.5.1 "in" typemap

    @@ -2477,7 +2477,7 @@ Usually numinputs is not specified, whereupon the default value is 1, t is the same as the old "ignore" typemap.

    -

    10.5.2 "typecheck" typemap

    +

    11.5.2 "typecheck" typemap

    @@ -2503,7 +2503,7 @@ If you define new "in" typemaps and your program uses overloaded method "typecheck" typemaps. More details about this follow in the Typemaps and overloading section.

    -

    10.5.3 "out" typemap

    +

    11.5.3 "out" typemap

    @@ -2534,7 +2534,7 @@ $symname - Name of function/method being wrapped 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.

    -

    10.5.4 "arginit" typemap

    +

    11.5.4 "arginit" typemap

    @@ -2553,7 +2553,7 @@ For example: -

    10.5.5 "default" typemap

    +

    11.5.5 "default" typemap

    @@ -2586,7 +2586,7 @@ See the Default/optional arguments sec for further information on default argument wrapping.

    -

    10.5.6 "check" typemap

    +

    11.5.6 "check" typemap

    @@ -2605,7 +2605,7 @@ converted. For example: -

    10.5.7 "argout" typemap

    +

    11.5.7 "argout" typemap

    @@ -2651,7 +2651,7 @@ return values are often appended to return value of the function. See the typemaps.i library file for examples.

    -

    10.5.8 "freearg" typemap

    +

    11.5.8 "freearg" typemap

    @@ -2684,7 +2684,7 @@ be used in other typemaps whenever a wrapper function needs to abort prematurely.

    -

    10.5.9 "newfree" typemap

    +

    11.5.9 "newfree" typemap

    @@ -2713,7 +2713,7 @@ string *foo(); See Object ownership and %newobject for further details.

    -

    10.5.10 "memberin" typemap

    +

    11.5.10 "memberin" typemap

    @@ -2735,7 +2735,7 @@ It is rarely necessary to write "memberin" typemaps---SWIG already provides a default implementation for arrays, strings, and other objects.

    -

    10.5.11 "varin" typemap

    +

    11.5.11 "varin" typemap

    @@ -2743,7 +2743,7 @@ The "varin" typemap is used to convert objects in the target language to C for t purposes of assigning to a C/C++ global variable. This is implementation specific.

    -

    10.5.12 "varout" typemap

    +

    11.5.12 "varout" typemap

    @@ -2751,7 +2751,7 @@ The "varout" typemap is used to convert a C/C++ object to an object in the targe language when reading a C/C++ global variable. This is implementation specific.

    -

    10.5.13 "throws" typemap

    +

    11.5.13 "throws" typemap

    @@ -2797,7 +2797,7 @@ Note that if your methods do not have an exception specification yet they do thr For a neat way to handle these, see the Exception handling with %exception section.

    -

    10.6 Some typemap examples

    +

    11.6 Some typemap examples

    @@ -2805,7 +2805,7 @@ This section contains a few examples. Consult language module documentation for more examples.

    -

    10.6.1 Typemaps for arrays

    +

    11.6.1 Typemaps for arrays

    @@ -3064,7 +3064,7 @@ Now, you will find that member access is quite nice: useless and has since been eliminated. To return structure members, simply use the "out" typemap.

    -

    10.6.2 Implementing constraints with typemaps

    +

    11.6.2 Implementing constraints with typemaps

    @@ -3112,7 +3112,7 @@ a NULL pointer. As a result, SWIG can often prevent a potential segmentation faults or other run-time problems by raising an exception rather than blindly passing values to the underlying C/C++ program.

    -

    10.7 Typemaps for multiple target languages

    +

    11.7 Typemaps for multiple target languages

    @@ -3142,7 +3142,7 @@ The example above also shows a common approach of issuing a warning for an as ye %typemap(ruby,in) int "$1 = NUM2INT($input);".

    -

    10.8 Optimal code generation when returning by value

    +

    11.8 Optimal code generation when returning by value

    @@ -3331,7 +3331,7 @@ example.i:7: Warning 475: optimal attribute usage in the out typemap. However, it doesn't always get it right, for example when $1 is within some commented out code.

    -

    10.9 Multi-argument typemaps

    +

    11.9 Multi-argument typemaps

    @@ -3598,7 +3598,7 @@ with non-consecutive C/C++ arguments; a workaround such as a helper function re- the arguments to make them consecutive will need to be written.

    -

    10.10 Typemap warnings

    +

    11.10 Typemap warnings

    @@ -3607,7 +3607,7 @@ See the information in the issuing warnings

    -

    10.11 Typemap fragments

    +

    11.11 Typemap fragments

    @@ -3860,7 +3860,7 @@ fragment usage unless a desire to really get to grips with some powerful but tricky macro and fragment usage that is used in parts of the SWIG typemap library.

    -

    10.11.1 Fragment type specialization

    +

    11.11.1 Fragment type specialization

    @@ -3893,7 +3893,7 @@ struct A { -

    10.11.2 Fragments and automatic typemap specialization

    +

    11.11.2 Fragments and automatic typemap specialization

    @@ -3939,7 +3939,7 @@ The interested (or very brave) reader can take a look at the fragments.swg file

    -

    10.12 The run-time type checker

    +

    11.12 The run-time type checker

    @@ -3956,7 +3956,7 @@ Requirements for the type system:

  • Store inheritance and type equivalence information and be able to correctly re-create the type pointer.
  • Share type information between modules.
  • -
  • Modules can be loaded in any order, irregardless of actual type +
  • Modules can be loaded in any order, regardless of actual type dependency.
  • Avoid the use of dynamically allocated memory, and library/system calls in general.
  • Provide a reasonably fast implementation, minimizing the lookup time for all @@ -3965,7 +3965,7 @@ language modules.
  • Modules can be unloaded from the type system.
  • -

    10.12.1 Implementation

    +

    11.12.1 Implementation

    @@ -4151,7 +4151,7 @@ structures rather than creating new ones. These swig_module_info structures are chained together in a circularly linked list.

    -

    10.12.2 Usage

    +

    11.12.2 Usage

    This section covers how to use these functions from typemaps. To learn how to @@ -4245,7 +4245,7 @@ probably just look at the output of SWIG to get a better sense for how types are managed.

    -

    10.13 Typemaps and overloading

    +

    11.13 Typemaps and overloading

    @@ -4556,7 +4556,7 @@ Subsequent "in" typemaps would then perform more extensive type-checking. -

    10.14 More about %apply and %clear

    +

    11.14 More about %apply and %clear

    @@ -4642,7 +4642,7 @@ example: -

    10.15 Passing data between typemaps

    +

    11.15 Passing data between typemaps

    @@ -4679,7 +4679,7 @@ sure that the typemaps sharing information have exactly the same types and names

    -

    10.16 C++ "this" pointer

    +

    11.16 C++ "this" pointer

    @@ -4739,7 +4739,7 @@ will also match the typemap. One work around is to create an interface file tha the method, but gives the argument a name other than self.

    -

    10.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 9564fe00b..dac1ad7bc 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -6,7 +6,7 @@ -

    13 Variable Length Arguments

    +

    14 Variable Length Arguments

      @@ -42,7 +42,7 @@ added in SWIG-1.3.12. Most other wrapper generation tools have wisely chosen to avoid this issue.

      -

      13.1 Introduction

      +

      14.1 Introduction

      @@ -139,7 +139,7 @@ List make_list(const char *s, ...) {

    -

    13.2 The Problem

    +

    14.2 The Problem

    @@ -232,7 +232,7 @@ can also support real varargs wrapping (with stack-frame manipulation) if you are willing to get hands dirty. Keep reading.

    -

    13.3 Default varargs support

    +

    14.3 Default varargs support

    @@ -301,7 +301,7 @@ Read on for further solutions.

    -

    13.4 Argument replacement using %varargs

    +

    14.4 Argument replacement using %varargs

    @@ -412,7 +412,7 @@ mixed argument types such as printf(). Providing general purpose wrappers to such functions presents special problems (covered shortly).

    -

    13.5 Varargs and typemaps

    +

    14.5 Varargs and typemaps

    @@ -589,7 +589,7 @@ really want to elevate your guru status and increase your job security, continue to the next section.

    -

    13.6 Varargs wrapping with libffi

    +

    14.6 Varargs wrapping with libffi

    @@ -841,7 +841,7 @@ provide an argument number for the first extra argument. This can be used to in values. Please consult the chapter on each language module for more details.

    -

    13.7 Wrapping of va_list

    +

    14.7 Wrapping of va_list

    @@ -895,7 +895,7 @@ int my_vprintf(const char *fmt, ...) { -

    13.8 C++ Issues

    +

    14.8 C++ Issues

    @@ -964,7 +964,7 @@ design or to provide an alternative interface using a helper function than it is fully general wrapper to a varargs C++ member function.

    -

    13.9 Discussion

    +

    14.9 Discussion

    diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index cf4c38d7e..99b89c425 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -6,7 +6,7 @@ -

    14 Warning Messages

    +

    15 Warning Messages

      @@ -35,7 +35,7 @@ -

      14.1 Introduction

      +

      15.1 Introduction

      @@ -55,7 +55,7 @@ where the generated wrapper code will probably compile, but it may not work like you expect.

      -

      14.2 Warning message suppression

      +

      15.2 Warning message suppression

      @@ -147,7 +147,7 @@ your interface. Ignore the warning messages at your own peril.

      -

      14.3 Enabling extra warnings

      +

      15.3 Enabling extra warnings

      @@ -220,7 +220,7 @@ that is, any warnings suppressed or added in %warnfilter, #pragma S or the -w option.

      -

      14.4 Issuing a warning message

      +

      15.4 Issuing a warning message

      @@ -274,7 +274,7 @@ example.i:24: Warning 901: You are really going to regret this usage of blah * s

    -

    14.5 Symbolic symbols

    +

    15.5 Symbolic symbols

    @@ -309,7 +309,7 @@ or -

    14.6 Commentary

    +

    15.6 Commentary

    @@ -326,7 +326,7 @@ no obvious recovery. There is no mechanism for suppressing error messages.

    -

    14.7 Warnings as errors

    +

    15.7 Warnings as errors

    @@ -335,7 +335,7 @@ option. This will cause SWIG to exit with a non successful exit code if a warning is encountered.

    -

    14.8 Message output format

    +

    15.8 Message output format

    @@ -354,10 +354,10 @@ $ swig -python -Fmicrosoft example.i example.i(4) : Syntax error in input. -

    14.9 Warning number reference

    +

    15.9 Warning number reference

    -

    14.9.1 Deprecated features (100-199)

    +

    15.9.1 Deprecated features (100-199)

      @@ -382,9 +382,10 @@ example.i(4) : Syntax error in input.
    • 119. Deprecated %typemap(ignore).
    • 120. Deprecated command line option (-runtime, -noruntime).
    • 121. Deprecated %name directive. +
    • 126. The 'nestedworkaround' feature is deprecated.
    -

    14.9.2 Preprocessor (200-299)

    +

    15.9.2 Preprocessor (200-299)

      @@ -396,7 +397,7 @@ example.i(4) : Syntax error in input.
    • 206. Unexpected tokens after #directive directive.
    -

    14.9.3 C/C++ Parser (300-399)

    +

    15.9.3 C/C++ Parser (300-399)

      @@ -473,7 +474,7 @@ example.i(4) : Syntax error in input.
    • 395. operator delete[] ignored.
    -

    14.9.4 Types and typemaps (400-499)

    +

    15.9.4 Types and typemaps (400-499)

      @@ -498,11 +499,13 @@ example.i(4) : Syntax error in input.
    • 471. Unable to use return type type in director method
    • 474. Method method usage of the optimal attribute ignored in the out typemap as the following cannot be used to generate optimal code: code
    • 475. Multiple calls to method might be generated due to optimal attribute usage in the out typemap. +
    • 476. Initialization using std::initializer_list. +
    • 477. No directorthrows typemap defined for type
    -

    14.9.5 Code generation (500-599)

    +

    15.9.5 Code generation (500-599)

      @@ -531,7 +534,7 @@ example.i(4) : Syntax error in input.
    • 523. Use of an illegal destructor name 'name' in %extend is deprecated, the destructor name should be 'name'.
    -

    14.9.6 Language module specific (700-899)

    +

    15.9.6 Language module specific (700-899)

      @@ -582,14 +585,14 @@ example.i(4) : Syntax error in input.
    • 871. Unrecognized pragma pragma. (Php).
    -

    14.9.7 User defined (900-999)

    +

    15.9.7 User defined (900-999)

    These numbers can be used by your own application.

    -

    14.10 History

    +

    15.10 History

    diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index c8467c78a..0685242ba 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -79,8 +79,8 @@ If you want to build your own swig.exe have a look at examples using Cygwin. diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index 40e227164..c5f655254 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -4,6 +4,7 @@ Windows.html Scripting.html SWIG.html SWIGPlus.html +CPlusPlus11.html Preprocessor.html Library.html Arguments.html @@ -22,6 +23,7 @@ D.html Go.html Guile.html Java.html +Javascript.html Lisp.html Lua.html Modula3.html diff --git a/Doc/Manual/index.html b/Doc/Manual/index.html index 30c69578f..fbe105a7e 100644 --- a/Doc/Manual/index.html +++ b/Doc/Manual/index.html @@ -1,10 +1,10 @@ -SWIG-2.0 Documentation +SWIG-3.0 Documentation -

    SWIG-2.0 Documentation

    +

    SWIG-3.0 Documentation

    The SWIG documentation is available in one of the following formats.
      diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 76a13cc9e..d78bdb1e1 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -14,17 +14,41 @@ # # 2. To use this makefile, set required variables, eg SRCS, INTERFACE, # INTERFACEDIR, INCLUDES, LIBS, TARGET, and do a -# $(MAKE) -f Makefile.template.in SRCS='$(SRCS)' \ +# $(MAKE) -f Makefile.template.in SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ # INCLUDES='$(INCLUDES) LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' \ # INTERFACEDIR='$(INTERFACEDIR)' TARGET='$(TARGET)' method # # 'method' describes what is being built. #--------------------------------------------------------------- +# Regenerate Makefile if Makefile.in or config.status have changed. +Makefile: @srcdir@/Makefile.in ../config.status + cd .. && $(SHELL) ./config.status Examples/Makefile + +# SRCDIR is the relative path to the current source directory +# - For in-source-tree builds, SRCDIR with be either '' or './', but +# '../' for the test suites that build in a subdir (e.g. C#, Java) +# - For out-of-source-tree builds, SRCDIR will be a relative +# path ending with a '/' + +# SRCDIR_SRCS, etc. are $(SRCS), etc. with $(SRCDIR) prepended +SRCDIR_SRCS = $(addprefix $(SRCDIR),$(SRCS)) +SRCDIR_CSRCS = $(addprefix $(SRCDIR),$(CSRCS)) +SRCDIR_CXXSRCS = $(addprefix $(SRCDIR),$(CXXSRCS)) + +ifeq (,$(SRCDIR)) +SRCDIR_INCLUDE = -I. +else +SRCDIR_INCLUDE = -I. -I$(SRCDIR) +endif + TARGET = CC = @CC@ CXX = @CXX@ -CFLAGS = @BOOST_CPPFLAGS@ @PLATFLAGS@ +CPPFLAGS = $(SRCDIR_INCLUDE) +CFLAGS = @PLATCFLAGS@ +CXXFLAGS = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@ +LDFLAGS = prefix = @prefix@ exec_prefix= @exec_prefix@ SRCS = @@ -32,7 +56,7 @@ INCLUDES = LIBS = INTERFACE = INTERFACEDIR = -INTERFACEPATH = $(INTERFACEDIR)$(INTERFACE) +INTERFACEPATH = $(SRCDIR)$(INTERFACEDIR)$(INTERFACE) SWIGOPT = SWIG = swig @@ -87,7 +111,7 @@ endif ################################################################## CPP_DLLIBS = #-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \ - -L/usr/local/lib -lg++ -lstdc++ -lgcc + -L/usr/local/lib -lg++ -lstdc++ -lgcc # Solaris workshop 5.0 # CPP_DLLIBS = -L/opt/SUNWspro/lib -lCrun @@ -125,39 +149,39 @@ TCL_DLNK = @TCLDYNAMICLINKING@ TCL_SO = @TCL_SO@ TCLLDSHARED = @TCLLDSHARED@ TCLCXXSHARED = @TCLCXXSHARED@ -TCL_SCRIPT = $(RUNME).tcl +TCL_SCRIPT = $(SRCDIR)$(RUNME).tcl # ----------------------------------------------------------- # Build a new version of the tclsh shell # ----------------------------------------------------------- -tclsh: $(SRCS) - $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i $(INTERFACEPATH) - $(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(TCL_INCLUDE) \ +tclsh: $(SRCDIR_SRCS) + $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(TCL_INCLUDE) \ $(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET) -tclsh_cpp: $(SRCS) - $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \ +tclsh_cpp: $(SRCDIR_SRCS) + $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \ $(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET) # ----------------------------------------------------------- # Build a Tcl dynamic loadable module (you might need to tweak this) # ----------------------------------------------------------- -tcl: $(SRCS) - $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(TCL_INCLUDE) - $(TCLLDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO) +tcl: $(SRCDIR_SRCS) + $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(TCL_INCLUDE) + $(TCLLDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO) # ----------------------------------------------------------- # Build a Tcl7.5 dynamic loadable module for C++ # ----------------------------------------------------------- -tcl_cpp: $(SRCS) - $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) - $(TCLCXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO) +tcl_cpp: $(SRCDIR_SRCS) + $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) + $(TCLCXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO) # ----------------------------------------------------------------- # Run Tcl example @@ -180,7 +204,7 @@ tcl_version: tcl_clean: rm -f *_wrap* *~ .~* mytclsh@EXEEXT@ rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ + rm -f *.@OBJEXT@ *$(TCL_SO) ################################################################## ##### PERL 5 ###### @@ -200,44 +224,44 @@ PERL5_CCCDLFLAGS = @PERL5CCCDLFLAGS@ PERL5_LDFLAGS = @PERL5LDFLAGS@ PERL = @PERL@ PERL5_LIB = -L$(PERL5_INCLUDE) -l@PERL5LIB@ @LIBS@ $(SYSLIBS) -PERL5_SCRIPT = $(RUNME).pl +PERL5_SCRIPT = $(SRCDIR)$(RUNME).pl # ---------------------------------------------------------------- # Build a Perl5 dynamically loadable module (C) # ---------------------------------------------------------------- -perl5: $(SRCS) - $(SWIG) -perl5 $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c -Dbool=char $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(PERL5_CCFLAGS) $(PERL5_CCCDLFLAGS) -I$(PERL5_INCLUDE) - $(LDSHARED) $(CFLAGS) $(PERL5_CCDLFLAGS) $(OBJS) $(IOBJS) $(PERL5_LDFLAGS) $(PERL5_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +perl5: $(SRCDIR_SRCS) + $(SWIG) -perl5 $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c -Dbool=char $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PERL5_CCFLAGS) $(PERL5_CCCDLFLAGS) -I$(PERL5_INCLUDE) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(PERL5_CCDLFLAGS) $(OBJS) $(IOBJS) $(PERL5_LDFLAGS) $(PERL5_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ---------------------------------------------------------------- # Build a Perl5 dynamically loadable module (C++) # ---------------------------------------------------------------- -perl5_cpp: $(SRCS) - $(SWIG) -perl5 -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) $(PERL5_CCCDLFLAGS) -I$(PERL5_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(PERL5_CCDLFLAGS) $(OBJS) $(IOBJS) $(PERL5_LDFLAGS) $(PERL5_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +perl5_cpp: $(SRCDIR_SRCS) + $(SWIG) -perl5 -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) $(PERL5_CCCDLFLAGS) -I$(PERL5_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(PERL5_CCDLFLAGS) $(OBJS) $(IOBJS) $(PERL5_LDFLAGS) $(PERL5_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ---------------------------------------------------------------- # Build a module from existing XS C source code. (ie. from xsubpp). # ---------------------------------------------------------------- -perl5_xs: $(SRCS) - $(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(INCLUDES) -I$(PERL5_INCLUDE) - $(LDSHARED) $(CFLAGS) $(OBJS) $(LIBS) -o $(TARGET)$(SO) +perl5_xs: $(SRCDIR_SRCS) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(INCLUDES) -I$(PERL5_INCLUDE) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o $(TARGET)$(SO) # ---------------------------------------------------------------- # Build a statically linked Perl5 executable # ---------------------------------------------------------------- -perl5_static: $(SRCS) - $(SWIG) -perl5 -static -lperlmain.i $(SWIGOPT) $(INTERFACEPATH) - $(CC) $(CFLAGS) -Dbool=char $(SRCS) $(ISRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) +perl5_static: $(SRCDIR_SRCS) + $(SWIG) -perl5 -static -lperlmain.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Dbool=char $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) -perl5_static_cpp: $(SRCS) - $(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) +perl5_static_cpp: $(SRCDIR_SRCS) + $(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) # ----------------------------------------------------------------- # Running a Perl5 example @@ -266,15 +290,17 @@ perl5_clean: ##### PYTHON ###### ################################################################## +PYTHON_FLAGS = + # Make sure these locate your Python installation ifeq (,$(PY3)) PYTHON_INCLUDE= $(DEFS) @PYINCLUDE@ PYTHON_LIB = @PYLIB@ - PYTHON = @PYTHON@ + PYTHON = @PYTHON@ $(PYTHON_FLAGS) else PYTHON_INCLUDE= $(DEFS) @PY3INCLUDE@ PYTHON_LIB = @PY3LIB@ - PYTHON = @PYTHON3@ + PYTHON = @PYTHON3@ $(PYTHON_FLAGS) endif # Extra Python specific linking options @@ -298,19 +324,19 @@ endif # Build a C dynamically loadable module # ---------------------------------------------------------------- -python: $(SRCS) - $(SWIGPYTHON) $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(PYTHON_INCLUDE) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO) +python: $(SRCDIR_SRCS) + $(SWIGPYTHON) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(PYTHON_INCLUDE) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO) # ----------------------------------------------------------------- # Build a C++ dynamically loadable module # ----------------------------------------------------------------- -python_cpp: $(SRCS) - $(SWIGPYTHON) -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(PYTHON_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO) +python_cpp: $(SRCDIR_SRCS) + $(SWIGPYTHON) -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(PYTHON_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO) # ----------------------------------------------------------------- # Build statically linked Python interpreter @@ -323,14 +349,14 @@ python_cpp: $(SRCS) TKINTER = PYTHON_LIBOPTS = $(PYTHON_LINK) @LIBS@ $(TKINTER) $(SYSLIBS) -python_static: $(SRCS) - $(SWIGPYTHON) -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CC) $(CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCS) $(INCLUDES) \ +python_static: $(SRCDIR_SRCS) + $(SWIGPYTHON) -lembed.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \ $(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET) -python_static_cpp: $(SRCS) - $(SWIGPYTHON) -c++ -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ +python_static_cpp: $(SRCDIR_SRCS) + $(SWIGPYTHON) -c++ -lembed.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \ $(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET) # ----------------------------------------------------------------- @@ -346,9 +372,15 @@ endif PY2TO3 = 2to3 `2to3 -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'` python_run: $(PYSCRIPT) + export PYTHONPATH=".:$$PYTHONPATH"; \ $(RUNTOOL) $(PYTHON) $(PYSCRIPT) $(RUNPIPE) -$(RUNME)3.py: $(RUNME).py +ifneq (,$(SRCDIR)) +$(RUNME).py: $(SRCDIR)$(RUNME).py + cp $< $@ +endif + +$(RUNME)3.py: $(SRCDIR)$(RUNME).py cp $< $@ $(PY2TO3) -w $@ >/dev/null 2>&1 @@ -367,9 +399,10 @@ python_clean: rm -rf __pycache__ rm -f *_wrap* *~ .~* mypython@EXEEXT@ *.pyc rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ *@PYTHON_SO@ + rm -f *.@OBJEXT@ *@SO@ *$(PYTHON_SO) rm -f $(TARGET).py - if [ -f $(RUNME).py ]; then rm -f $(RUNME)3.py $(RUNME)3.py.bak; fi + if test -f $(SRCDIR)$(RUNME).py; then rm -f $(RUNME)3.py $(RUNME)3.py.bak; fi + case "x$(SRCDIR)" in x|x./);; *) rm -f $(RUNME).py;; esac ################################################################## @@ -384,27 +417,27 @@ OCTAVE_CXX = $(DEFS) @OCTAVE_CPPFLAGS@ @OCTAVE_CXXFLAGS@ OCTAVE_DLNK = @OCTAVE_LDFLAGS@ OCTAVE_SO = @OCTAVE_SO@ -OCTAVE_SCRIPT = $(RUNME).m +OCTAVE_SCRIPT = $(SRCDIR)$(RUNME).m # ---------------------------------------------------------------- # Build a C dynamically loadable module # Note: Octave requires C++ compiler when compiling C wrappers # ---------------------------------------------------------------- -octave: $(SRCS) - $(SWIG) -octave $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(INCLUDES) $(OCTAVE_CXX) - $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CSRCS) $(INCLUDES) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) +octave: $(SRCDIR_SRCS) + $(SWIG) -octave $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(INCLUDES) $(OCTAVE_CXX) + $(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CSRCS) $(INCLUDES) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) # ----------------------------------------------------------------- # Build a C++ dynamically loadable module # ----------------------------------------------------------------- -octave_cpp: $(SRCS) - $(SWIG) -c++ -octave $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(OCTAVE_CXX) - $(CXXSHARED) -g $(CFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) +octave_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -octave $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(OCTAVE_CXX) + $(CXXSHARED) -g $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) # ----------------------------------------------------------------- # Running an Octave example @@ -428,7 +461,7 @@ octave_clean: rm -rf __pycache__ rm -f *_wrap* *~ .~* myoctave@EXEEXT@ *.pyc rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ *@OCTAVE_SO@ + rm -f *.@OBJEXT@ *@SO@ *$(OCTAVE_SO) ################################################################## ##### GUILE ###### @@ -441,21 +474,21 @@ GUILE_SO = @GUILE_SO@ GUILE_LIBS = @GUILE_LIBS@ GUILE_LIBOPTS = @LIBS@ $(SYSLIBS) GUILE_LIBPREFIX = lib -GUILE_SCRIPT = $(RUNME).scm +GUILE_SCRIPT = $(SRCDIR)$(RUNME).scm #------------------------------------------------------------------ # Build a dynamically loaded module with passive linkage #------------------------------------------------------------------ -guile: $(SRCS) - $(SWIG) -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCS) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO) +guile: $(SRCDIR_SRCS) + $(SWIG) -guile -Linkage passive $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(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): $(SRCS) - $(SWIG) -c++ -guile -Linkage passive $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) $(CPP_DLLIBS) -o $@ +$(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO): $(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 $@ guile_externalhdr: $(SWIG) -guile -external-runtime $(TARGET) @@ -464,34 +497,34 @@ guile_externalhdr: # Build Guile interpreter augmented with extra functions # ----------------------------------------------------------------- -guile_augmented: - $(SWIG) -guile $(SWIGOPT) $(INTERFACE) - $(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) -o $(TARGET) +guile_augmented: $(SRCDIR_SRCS) + $(SWIG) -guile $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) -o $(TARGET) # ----------------------------------------------------------------- # Build statically linked Guile interpreter # ----------------------------------------------------------------- -guile_static: $(SRCS) - $(SWIG) -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) $(INTERFACEPATH) - $(CC) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) \ +guile_static: $(SRCDIR_SRCS) + $(SWIG) -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \ -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \ $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile -guile_static_cpp: $(SRCS) - $(SWIG) -c++ -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ +guile_static_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \ -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \ $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile -guile_simple: $(SRCS) - $(SWIG) -guile -lguilemain.i -Linkage simple $(SWIGOPT) $(INTERFACEPATH) - $(CC) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) \ +guile_simple: $(SRCDIR_SRCS) + $(SWIG) -guile -lguilemain.i -Linkage simple $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \ $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile -guile_simple_cpp: $(SRCS) - $(SWIG) -c++ -guile -lguilemain.i -Linkage simple $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ +guile_simple_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -guile -lguilemain.i -Linkage simple $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \ $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile # ----------------------------------------------------------------- @@ -518,7 +551,7 @@ guile_version: guile_clean: rm -f *_wrap* *~ .~* my-guile@EXEEXT@ $(TARGET)@EXEEXT@ rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@GUILE_SO@ + rm -f *.@OBJEXT@ *$(GUILE_SO) ################################################################## ##### JAVA ###### @@ -537,39 +570,39 @@ JAVALDSHARED = @JAVALDSHARED@ JAVACXXSHARED = @JAVACXXSHARED@ JAVACFLAGS = @JAVACFLAGS@ JAVA = @JAVA@ -JAVAC = @JAVAC@ +JAVAC = @JAVAC@ -d . # ---------------------------------------------------------------- # Build a java dynamically loadable module (C) # ---------------------------------------------------------------- -java: $(SRCS) - $(SWIG) -java $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(JAVACFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(JAVA_INCLUDE) - $(JAVALDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) +java: $(SRCDIR_SRCS) + $(SWIG) -java $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(JAVACFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(JAVA_INCLUDE) + $(JAVALDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) # ---------------------------------------------------------------- # Build a java dynamically loadable module (C++) # ---------------------------------------------------------------- -java_cpp: $(SRCS) - $(SWIG) -java -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(JAVACFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JAVA_INCLUDE) - $(JAVACXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) +java_cpp: $(SRCDIR_SRCS) + $(SWIG) -java -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(JAVACFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JAVA_INCLUDE) + $(JAVACXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO) # ---------------------------------------------------------------- # Compile java files # ---------------------------------------------------------------- -java_compile: $(SRCS) - $(COMPILETOOL) $(JAVAC) $(JAVACFLAGS) $(JAVASRCS) +java_compile: $(SRCDIR_SRCS) + $(COMPILETOOL) $(JAVAC) $(JAVACFLAGS) $(addprefix $(SRCDIR),$(JAVASRCS)) # ----------------------------------------------------------------- # Run java example # ----------------------------------------------------------------- java_run: - env LD_LIBRARY_PATH=. $(RUNTOOL) $(JAVA) $(RUNME) $(RUNPIPE) + env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(JAVA) $(RUNME) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -588,6 +621,119 @@ java_clean: rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@JAVASO@ +################################################################## +##### JAVASCRIPT ###### +################################################################## + +# Note: These targets are also from within Makefiles in the Example directories. +# There is a common makefile, 'Examples/javascript/js_example.mk' to simplify +# create a configuration for a new example. + +ROOT_DIR = @ROOT_DIR@ +JSINCLUDES = @JSCOREINC@ @JSV8INC@ +JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@ +JSSO =@JSSO@ +JSLDSHARED = @JSLDSHARED@ +JSCXXSHARED = @JSCXXSHARED@ +NODEJS = @NODEJS@ +NODEGYP = @NODEGYP@ + +# ---------------------------------------------------------------- +# Creating and building Javascript wrappers +# ---------------------------------------------------------------- + +javascript_wrapper: + $(SWIG) -javascript $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH) + +javascript_wrapper_cpp: $(SRCDIR_SRCS) + $(SWIG) -javascript -c++ $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.cxx $(INTERFACEPATH) + +javascript_build: $(SRCDIR_SRCS) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(JSINCLUDES) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + +javascript_build_cpp: $(SRCDIR_SRCS) +ifeq (node,$(JSENGINE)) + sed -e 's|$$srcdir|./$(SRCDIR)|g' $(SRCDIR)binding.gyp.in > binding.gyp + $(NODEGYP) --loglevel=silent configure build 1>>/dev/null +else + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(JSINCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + +endif + +# These targets are used by the test-suite: + +javascript: $(SRCDIR_SRCS) javascript_custom_interpreter + $(SWIG) -javascript $(SWIGOPT) $(INTERFACEPATH) +ifeq (jsc, $(ENGINE)) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(JSINCLUDES) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +else # (v8 | node) # v8 and node must be compiled as c++ + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(JSINCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +endif + +javascript_cpp: $(SRCDIR_SRCS) javascript_custom_interpreter + $(SWIG) -javascript -c++ $(SWIGOPT) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(JSINCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + +# ----------------------------------------------------------------- +# Running a Javascript example +# ----------------------------------------------------------------- + +javascript_custom_interpreter: + (cd $(ROOT_DIR)/Tools/javascript && $(MAKE) JSENGINE='$(JSENGINE)') + +ifeq (node,$(JSENGINE)) +javascript_run: + env NODE_PATH=$$PWD:$(SRCDIR) $(RUNTOOL) $(NODEJS) $(SRCDIR)$(RUNME).js $(RUNPIPE) +else +javascript_run: javascript_custom_interpreter + $(RUNTOOL) $(ROOT_DIR)/Tools/javascript/javascript -$(JSENGINE) -L $(TARGET) $(SRCDIR)$(RUNME).js $(RUNPIPE) +endif + +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +javascript_version: +ifeq (, $(ENGINE)) + @if [ "$(NODEJS)" != "" ]; then \ + echo "Node.js: `($(NODEJS) --version)`"; \ + echo "node-gyp: `($(NODEGYP) --version)`"; \ + else \ + echo "Version depends on the interpreter"; \ + fi +endif +ifeq (node, $(ENGINE)) + echo "Node.js: `($(NODEJS) --version)`" + echo "node-gyp: `($(NODEGYP) --version)`" +endif +ifeq (jsc, $(ENGINE)) + @if [ "@JSCOREVERSION@" != "" ]; then \ + echo "@JSCOREVERSION@"; \ + else \ + echo "Unknown JavascriptCore version."; \ + fi +endif +ifeq (v8, $(ENGINE)) + echo "Unknown v8 version." +endif + +# ----------------------------------------------------------------- +# Cleaning the Javascript examples +# ----------------------------------------------------------------- + +javascript_clean: + rm -rf build + rm -f *_wrap* $(RUNME) + rm -f core @EXTRA_CLEAN@ + rm -f *.@OBJEXT@ *@JSSO@ *.$(SO) + rm -f binding.gyp example-gypcopy.cxx + cd $(ROOT_DIR)/Tools/javascript && $(MAKE) -s clean + ################################################################## ##### ANDROID ###### ################################################################## @@ -602,7 +748,7 @@ TARGETID = 1 # Build an Android dynamically loadable module (C) # ---------------------------------------------------------------- -android: $(SRCS) +android: $(SRCDIR_SRCS) $(ANDROID) $(SILENT_OPTION) update project --target $(TARGETID) --name $(PROJECTNAME) --path . $(SWIG) -java $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH) +$(ANDROID_NDK_BUILD) $(SILENT_PIPE) @@ -612,7 +758,7 @@ android: $(SRCS) # Build an Android dynamically loadable module (C++) # ---------------------------------------------------------------- -android_cpp: $(SRCS) +android_cpp: $(SRCDIR_SRCS) $(ANDROID) $(SILENT_OPTION) update project --target $(TARGETID) --name $(PROJECTNAME) --path . $(SWIG) -java -c++ $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.cpp $(INTERFACEPATH) +$(ANDROID_NDK_BUILD) $(SILENT_PIPE) @@ -638,7 +784,7 @@ android_version: # ----------------------------------------------------------------- android_clean: - ant -q -logfile /dev/null clean + test -n "$(SRCDIR)" && cd $(SRCDIR) ; ant -q -logfile /dev/null clean rm -f $(INTERFACEDIR)$(TARGET)_wrap.* rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java` rm -rf obj @@ -653,13 +799,11 @@ MODULA3_INCLUDE= @MODULA3INC@ # Build a modula3 dynamically loadable module (C) # ---------------------------------------------------------------- -modula3: $(SRCS) - $(SWIG) -modula3 $(SWIGOPT) $(INTERFACEPATH) -# $(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) \ -# $(OBJS) $(IOBJS) $(LIBS) +modula3: $(SRCDIR_SRCS) + $(SWIG) -modula3 $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) -modula3_cpp: $(SRCS) - $(SWIG) -modula3 -c++ $(SWIGOPT) $(INTERFACEPATH) +modula3_cpp: $(SRCDIR_SRCS) + $(SWIG) -modula3 -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) # ----------------------------------------------------------------- # Run modula3 example @@ -698,22 +842,22 @@ MZSCHEME_SCRIPT = $(RUNME).scm # Build a C/C++ dynamically loadable module # ---------------------------------------------------------------- -mzscheme: $(SRCS) - $(SWIG) -mzscheme $(SWIGOPT) $(INTERFACEPATH) - $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ISRCS) $(SRCS) +mzscheme: $(SRCDIR_SRCS) + $(SWIG) -mzscheme $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ISRCS) $(SRCDIR_SRCS) $(COMPILETOOL) $(MZC) --ld $(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) -mzscheme_cpp: $(SRCS) - $(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACEPATH) - $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) +mzscheme_cpp: $(SRCDIR_SRCS) + $(SWIG) -mzscheme -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) + $(CXXSHARED) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) # ----------------------------------------------------------------- # Run mzscheme example # ----------------------------------------------------------------- mzscheme_run: - env LD_LIBRARY_PATH=. $(RUNTOOL) $(MZSCHEME) -r $(MZSCHEME_SCRIPT) $(RUNPIPE) + env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(MZSCHEME) -r $(MZSCHEME_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -730,7 +874,7 @@ mzscheme_version: mzscheme_clean: rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ + rm -f *.@OBJEXT@ *$(MZSCHEME_SO) ################################################################## ##### Ocaml ##### @@ -753,10 +897,10 @@ OCAMLCORE=\ $(OCC) -I $(OCAMLP4WHERE) -pp "camlp4o pa_extend.cmo q_MLast.cmo" \ -c swigp4.ml -ocaml_static: $(SRCS) +ocaml_static: $(SRCDIR_SRCS) $(OCAMLCORE) - $(SWIG) -ocaml $(SWIGOPT) $(INTERFACEPATH) - $(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCS) + $(SWIG) -ocaml $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCDIR_SRCS) $(OCC) -g -c $(INTERFACE:%.i=%.mli) $(OCC) -g -c $(INTERFACE:%.i=%.ml) test -z "$(PROGFILE)" || test -f "$(PROGFILE)" && \ @@ -767,11 +911,11 @@ ocaml_static: $(SRCS) $(PROGFILE:%.ml=%.cmo) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)" -ocaml_dynamic: $(SRCS) +ocaml_dynamic: $(SRCDIR_SRCS) $(OCAMLCORE) - $(SWIG) -ocaml $(SWIGOPT) $(INTERFACEPATH) - $(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCS) - $(CXXSHARED) $(CFLAGS) $(CCSHARED) $(CFLAGS) -o $(INTERFACE:%.i=%@SO@) \ + $(SWIG) -ocaml $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCDIR_SRCS) + $(CXXSHARED) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(CCSHARED) -o $(INTERFACE:%.i=%@SO@) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) $(LIBS) $(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > \ $(INTERFACE:%.i=%_dynamic.ml) @@ -786,10 +930,10 @@ ocaml_dynamic: $(SRCS) -package dl -linkpkg \ $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -ocaml_static_toplevel: $(SRCS) +ocaml_static_toplevel: $(SRCDIR_SRCS) $(OCAMLCORE) - $(SWIG) -ocaml $(SWIGOPT) $(INTERFACEPATH) - $(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCS) + $(SWIG) -ocaml $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCDIR_SRCS) $(OCC) -g -c $(INTERFACE:%.i=%.mli) $(OCC) -g -c $(INTERFACE:%.i=%.ml) test -z "$(PROGFILE)" || test -f "$(PROGFILE)" && \ @@ -801,12 +945,12 @@ ocaml_static_toplevel: $(SRCS) $(INTERFACE:%.i=%.cmo) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)" -ocaml_static_cpp: $(SRCS) +ocaml_static_cpp: $(SRCDIR_SRCS) $(OCAMLCORE) - $(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ - $(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) + $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(OCC) -g -c $(INTERFACE:%.i=%.mli) $(OCC) -g -c $(INTERFACE:%.i=%.ml) test -z "$(PROGFILE)" || test -f "$(PROGFILE)" && \ @@ -818,12 +962,12 @@ ocaml_static_cpp: $(SRCS) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings' -ocaml_static_cpp_toplevel: $(SRCS) +ocaml_static_cpp_toplevel: $(SRCDIR_SRCS) $(OCAMLCORE) - $(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ - $(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) + $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(OCC) -g -c $(INTERFACE:%.i=%.mli) $(OCC) -g -c $(INTERFACE:%.i=%.ml) test -z "$(PROGFILE)" || test -f "$(PROGFILE)" && \ @@ -836,13 +980,13 @@ ocaml_static_cpp_toplevel: $(SRCS) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings' -ocaml_dynamic_cpp: $(SRCS) +ocaml_dynamic_cpp: $(SRCDIR_SRCS) $(OCAMLCORE) - $(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ - $(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) -ccopt -fPIC - $(CXXSHARED) $(CFLAGS) -o $(INTERFACE:%.i=%@SO@) \ + $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) -ccopt -fPIC + $(CXXSHARED) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $(INTERFACE:%.i=%@SO@) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ $(CPP_DLLIBS) $(LIBS) $(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > \ @@ -894,26 +1038,26 @@ RUBY_DLNK = @RUBYDYNAMICLINKING@ RUBY_LIBOPTS = @RUBYLINK@ @LIBS@ $(SYSLIBS) RUBY_SO = @RUBYSO@ RUBY = @RUBY@ -RUBY_SCRIPT = $(RUNME).rb +RUBY_SCRIPT = $(SRCDIR)$(RUNME).rb # ---------------------------------------------------------------- # Build a C dynamically loadable module # ---------------------------------------------------------------- -ruby: $(SRCS) - $(SWIG) -ruby $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(RUBY_CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(RUBY_INCLUDE) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(RUBY_SO) +ruby: $(SRCDIR_SRCS) + $(SWIG) -ruby $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(RUBY_CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(RUBY_INCLUDE) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(RUBY_SO) # ----------------------------------------------------------------- # Build a C++ dynamically loadable module # ----------------------------------------------------------------- -ruby_cpp: $(SRCS) - $(SWIG) -c++ -ruby $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(RUBY_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(RUBY_SO) +ruby_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -ruby $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(RUBY_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(RUBY_SO) # ----------------------------------------------------------------- # Build statically linked Ruby interpreter @@ -922,14 +1066,14 @@ ruby_cpp: $(SRCS) # library file # ----------------------------------------------------------------- -ruby_static: $(SRCS) - $(SWIG) -ruby -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CC) $(CFLAGS) $(RUBY_CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCS) $(INCLUDES) \ +ruby_static: $(SRCDIR_SRCS) + $(SWIG) -ruby -lembed.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(RUBY_CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \ $(RUBY_INCLUDE) $(LIBS) -L$(RUBY_LIB) $(RUBY_LIBOPTS) -o $(TARGET) -ruby_cpp_static: $(SRCS) - $(SWIG) -c++ -ruby -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ +ruby_cpp_static: $(SRCDIR_SRCS) + $(SWIG) -c++ -ruby -lembed.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \ $(RUBY_INCLUDE) $(LIBS) -L$(RUBY_LIB) $(RUBY_LIBOPTS) -o $(TARGET) # ----------------------------------------------------------------- @@ -953,7 +1097,7 @@ ruby_version: ruby_clean: rm -f *_wrap* *~ .~* myruby@EXEEXT@ *.pm rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ + rm -f *.@OBJEXT@ *$(RUBY_SO) ################################################################## ##### PHP ###### @@ -962,25 +1106,25 @@ ruby_clean: PHP = @PHP@ PHP_INCLUDE = @PHPINC@ PHP_SO = @PHP_SO@ -PHP_SCRIPT = $(RUNME).php +PHP_SCRIPT = $(SRCDIR)$(RUNME).php # ------------------------------------------------------------------- # Build a PHP dynamically loadable module (C) # ------------------------------------------------------------------- -php: $(SRCS) - $(SWIG) -php $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO) +php: $(SRCDIR_SRCS) + $(SWIG) -php $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO) # -------------------------------------------------------------------- # Build a PHP dynamically loadable module (C++) # -------------------------------------------------------------------- -php_cpp: $(SRCS) - $(SWIG) -php -cppext cxx -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO) +php_cpp: $(SRCDIR_SRCS) + $(SWIG) -php -cppext cxx -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO) # ----------------------------------------------------------------- # Running a PHP example @@ -1003,7 +1147,7 @@ php_version: php_clean: rm -f *_wrap* *~ .~* example.php php_example.h rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ + rm -f *.@OBJEXT@ *$(PHP_SO) ################################################################## ##### Pike ###### @@ -1022,19 +1166,19 @@ PIKE_SCRIPT = $(RUNME).pike # Build a C dynamically loadable module # ---------------------------------------------------------------- -pike: $(SRCS) - $(SWIG) -pike $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(PIKE_CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(PIKE_INCLUDE) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PIKE_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +pike: $(SRCDIR_SRCS) + $(SWIG) -pike $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(PIKE_CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(PIKE_INCLUDE) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(PIKE_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- # Build a C++ dynamically loadable module # ----------------------------------------------------------------- -pike_cpp: $(SRCS) - $(SWIG) -c++ -pike $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(PIKE_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PIKE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +pike_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -pike $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(PIKE_INCLUDE) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(PIKE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- # Build statically linked Pike interpreter @@ -1043,14 +1187,14 @@ pike_cpp: $(SRCS) # library file # ----------------------------------------------------------------- -pike_static: $(SRCS) - $(SWIG) -pike -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CC) $(CFLAGS) $(PIKE_CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCS) $(INCLUDES) \ +pike_static: $(SRCDIR_SRCS) + $(SWIG) -pike -lembed.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(PIKE_CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \ $(PIKE_INCLUDE) $(LIBS) -L$(PIKE_LIB) $(PIKE_LIBOPTS) -o $(TARGET) -pike_cpp_static: $(SRCS) - $(SWIG) -c++ -pike -lembed.i $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ +pike_cpp_static: $(SRCDIR_SRCS) + $(SWIG) -c++ -pike -lembed.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(PIKE_CFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \ $(PIKE_INCLUDE) $(LIBS) -L$(PIKE_LIB) $(PIKE_LIBOPTS) -o $(TARGET) # ----------------------------------------------------------------- @@ -1097,7 +1241,7 @@ CHICKEN_GENERATED_SCHEME = $(INTERFACE:.i=.scm) CHICKEN_COMPILED_SCHEME = $(INTERFACE:.i=_chicken.c) CHICKEN_COMPILED_OBJECT = $(CHICKEN_COMPILED_SCHEME:.c=.@OBJEXT@) -# flags for the main chicken sources (only used when compiling staticly) +# flags for the main chicken sources (only used when compiling statically) CHICKEN_COMPILED_MAIN = $(CHICKEN_MAIN:.scm=_chicken.c) CHICKEN_COMPILED_MAIN_OBJECT = $(CHICKEN_COMPILED_MAIN:.c=.@OBJEXT@) @@ -1106,24 +1250,24 @@ CHICKEN_COMPILED_MAIN_OBJECT = $(CHICKEN_COMPILED_MAIN:.c=.@OBJEXT@) # ----------------------------------------------------------------- # This is the old way to build chicken, but it does not work correctly with exceptions -chicken_direct: $(SRCS) +chicken_direct: $(SRCDIR_SRCS) $(SWIG) -chicken $(SWIGOPT) $(INCLUDE) $(INTERFACEPATH) $(CHICKEN) $(CHICKEN_GENERATED_SCHEME) $(CHICKENOPTS) \ -dynamic -feature chicken-compile-shared \ -output-file $(CHICKEN_COMPILED_SCHEME) - $(CC) -c $(CCSHARED) $(CFLAGS) $(CHICKEN_CFLAGS) \ - $(INCLUDES) $(CHICKEN_INCLUDE) $(ISRCS) $(SRCS) $(CHICKEN_COMPILED_SCHEME) - $(LDSHARED) $(CFLAGS) $(CHICKEN_COMPILED_OBJECT) $(OBJS) $(IOBJS) \ + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(CHICKEN_CFLAGS) \ + $(INCLUDES) $(CHICKEN_INCLUDE) $(ISRCS) $(SRCDIR_SRCS) $(CHICKEN_COMPILED_SCHEME) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(CHICKEN_COMPILED_OBJECT) $(OBJS) $(IOBJS) \ $(LIBS) $(CHICKEN_SHAREDLIBOPTS) -o $(LIBPREFIX)$(TARGET)$(SO) -chicken_direct_cpp: $(CXXSRCS) $(CHICKSRCS) +chicken_direct_cpp: $(SRCDIR_CXXSRCS) $(CHICKSRCS) $(SWIG) -c++ -chicken $(SWIGOPT) $(INCLUDE) $(INTERFACEPATH) $(CHICKEN) $(CHICKEN_GENERATED_SCHEME) $(CHICKENOPTS) \ -dynamic -feature chicken-compile-shared \ -output-file $(CHICKEN_COMPILED_SCHEME) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(CHICKEN_CFLAGS) \ - $(INCLUDES) $(CHICKEN_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(CHICKEN_COMPILED_SCHEME) - $(CXXSHARED) $(CFLAGS) $(CHICKEN_COMPILED_OBJECT) $(OBJS) $(IOBJS) \ + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(CHICKEN_CFLAGS) \ + $(INCLUDES) $(CHICKEN_INCLUDE) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(CHICKEN_COMPILED_SCHEME) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(CHICKEN_COMPILED_OBJECT) $(OBJS) $(IOBJS) \ $(LIBS) $(CPP_DLLIBS) $(CHICKEN_SHAREDLIBOPTS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- @@ -1131,28 +1275,28 @@ chicken_direct_cpp: $(CXXSRCS) $(CHICKSRCS) # ----------------------------------------------------------------- # The following two targets are also used by the test suite -chicken_static: $(SRCS) $(CHICKSRCS) +chicken_static: $(SRCDIR_SRCS) $(CHICKSRCS) $(SWIG) -chicken $(SWIGOPT) $(INCLUDE) $(INTERFACEPATH) $(CHICKEN) $(CHICKEN_GENERATED_SCHEME) $(CHICKENOPTS) \ -output-file $(CHICKEN_COMPILED_SCHEME) $(CHICKEN) $(CHICKEN_MAIN) $(CHICKENOPTS) \ -output-file $(CHICKEN_MAIN:.scm=_chicken.c) - $(CC) -c $(CCSHARED) $(CFLAGS) $(CHICKEN_CFLAGS) \ - $(INCLUDES) $(CHICKEN_INCLUDE) $(ISRCS) $(SRCS) \ + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(CHICKEN_CFLAGS) \ + $(INCLUDES) $(CHICKEN_INCLUDE) $(ISRCS) $(SRCDIR_SRCS) \ $(CHICKEN_COMPILED_SCHEME) $(CHICKEN_COMPILED_MAIN) - $(CC) $(CHICKEN_COMPILED_OBJECT) $(CHICKEN_COMPILED_MAIN_OBJECT) \ + $(CC) $(CFLAGS) $(LDFLAGS) $(CHICKEN_COMPILED_OBJECT) $(CHICKEN_COMPILED_MAIN_OBJECT) \ $(OBJS) $(IOBJS) $(LIBS) $(CHICKEN_SHAREDLIBOPTS) -o $(TARGET) -chicken_static_cpp: $(CXXSRCS) $(CHICKSRCS) +chicken_static_cpp: $(SRCDIR_CXXSRCS) $(CHICKSRCS) $(SWIG) -c++ -chicken $(SWIGOPT) $(INCLUDE) $(INTERFACEPATH) $(CHICKEN) $(CHICKEN_GENERATED_SCHEME) $(CHICKENOPTS) \ -output-file $(CHICKEN_COMPILED_SCHEME) $(CHICKEN) $(CHICKEN_MAIN) $(CHICKENOPTS) \ -output-file $(CHICKEN_MAIN:.scm=_chicken.c) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(CHICKEN_CFLAGS) \ - $(INCLUDES) $(CHICKEN_INCLUDE) $(ICXXSRCS) $(SRCS) $(CXXSRCS) \ + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(CHICKEN_CFLAGS) \ + $(INCLUDES) $(CHICKEN_INCLUDE) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) \ $(CHICKEN_COMPILED_SCHEME) $(CHICKEN_COMPILED_MAIN) - $(CXX) $(CHICKEN_COMPILED_OBJECT) $(CHICKEN_COMPILED_MAIN_OBJECT) \ + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(CHICKEN_COMPILED_OBJECT) $(CHICKEN_COMPILED_MAIN_OBJECT) \ $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) $(CHICKEN_SHAREDLIBOPTS) -o $(TARGET) # ---------------------------------------------------------------- @@ -1161,11 +1305,11 @@ chicken_static_cpp: $(CXXSRCS) $(CHICKSRCS) chicken: $(SWIG) -chicken $(SWIGOPT) $(INCLUDE) $(INTERFACEPATH) - $(COMPILETOOL) $(CHICKEN_CSC) -s `echo $(INCLUDES) | sed 's/-I/-C -I/g'` $(CHICKEN_GENERATED_SCHEME) $(SRCS) $(ISRCS) -o $(TARGET)$(SO) + $(COMPILETOOL) $(CHICKEN_CSC) -s `echo $(INCLUDES) | sed 's/-I/-C -I/g'` $(CHICKEN_GENERATED_SCHEME) $(SRCDIR_SRCS) $(ISRCS) -o $(TARGET)$(SO) chicken_cpp: $(SWIG) -c++ -chicken $(SWIGOPT) $(INCLUDE) $(INTERFACEPATH) - $(COMPILETOOL) $(CHICKEN_CSC) -s `echo $(INCLUDES) | sed 's/-I/-C -I/g'` $(CHICKEN_GENERATED_SCHEME) $(SRCS) $(ICXXSRCS) $(CXXSRCS) -o $(TARGET)$(SO) + $(COMPILETOOL) $(CHICKEN_CSC) -s `echo $(INCLUDES) | sed 's/-I/-C -I/g'` $(CHICKEN_GENERATED_SCHEME) $(SRCDIR_SRCS) $(ICXXSRCS) $(SRCDIR_CXXSRCS) -o $(TARGET)$(SO) chicken_externalhdr: $(SWIG) -chicken -external-runtime $(TARGET) @@ -1175,7 +1319,7 @@ chicken_externalhdr: # ----------------------------------------------------------------- chicken_run: - env LD_LIBRARY_PATH=. $(RUNTOOL) $(CHICKEN_CSI) $(CHICKEN_SCRIPT) $(RUNPIPE) + env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(CHICKEN_CSI) $(CHICKEN_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -1202,41 +1346,48 @@ CSHARP_DLNK = @CSHARPDYNAMICLINKING@ CSHARP_LIBPREFIX = @CSHARPLIBRARYPREFIX@ CSHARPCOMPILER = @CSHARPCOMPILER@ CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ +CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@ CSHARPCFLAGS = @CSHARPCFLAGS@ CSHARPSO = @CSHARPSO@ -CSHARP_RUNME = ./$(RUNME).exe +CSHARP_RUNME = $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) ./$(RUNME).exe # ---------------------------------------------------------------- # Build a CSharp dynamically loadable module (C) # ---------------------------------------------------------------- -csharp: $(SRCS) - $(SWIG) -csharp $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(CSHARPCFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO) +csharp: $(SRCDIR_SRCS) + $(SWIG) -csharp $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO) # ---------------------------------------------------------------- # Build a CSharp dynamically loadable module (C++) # ---------------------------------------------------------------- -csharp_cpp: $(SRCS) - $(SWIG) -csharp -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(CSHARPCFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO) +csharp_cpp: $(SRCDIR_SRCS) + $(SWIG) -csharp -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO) # ---------------------------------------------------------------- # Compile CSharp files # ---------------------------------------------------------------- -csharp_compile: $(SRCS) - $(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPSRCS) +ifneq (,$(SRCDIR)) +SRCDIR_CSHARPSRCS = $(addprefix $(SRCDIR),$(CSHARPSRCS)) +else +SRCDIR_CSHARPSRCS = +endif + +csharp_compile: $(SRCDIR_SRCS) + $(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPSRCS) $(SRCDIR_CSHARPSRCS) # ----------------------------------------------------------------- # Run CSharp example # ----------------------------------------------------------------- csharp_run: - env LD_LIBRARY_PATH=. $(RUNTOOL) $(CSHARP_RUNME) $(RUNPIPE) + env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(CSHARP_RUNME) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -1251,7 +1402,7 @@ csharp_version: # ----------------------------------------------------------------- csharp_clean: - rm -f *_wrap* *~ .~* runme runme.exe *.exe.mdb gc.log `find . -name \*.cs | grep -v runme.cs` + rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe *.exe.mdb gc.log `find . -name \*.cs | grep -v $(RUNME).cs` rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@CSHARPSO@ @@ -1268,7 +1419,7 @@ LUA_DLNK = @LUADYNAMICLINKING@ LUA_SO = @LUA_SO@ LUA = @LUABIN@ -LUA_SCRIPT = $(RUNME).lua +LUA_SCRIPT = $(SRCDIR)$(RUNME).lua # Extra code for lua static link LUA_INTERP = ../lua.c @@ -1277,32 +1428,32 @@ LUA_INTERP = ../lua.c # Build a C dynamically loadable module # ---------------------------------------------------------------- -lua: $(SRCS) - $(SWIG) -lua $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(LUA_INCLUDE) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) -o $(LIBPREFIX)$(TARGET)$(LUA_SO) +lua: $(SRCDIR_SRCS) + $(SWIG) -lua $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(LUA_INCLUDE) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) -o $(LIBPREFIX)$(TARGET)$(LUA_SO) # ----------------------------------------------------------------- # Build a C++ dynamically loadable module # ----------------------------------------------------------------- -lua_cpp: $(SRCS) - $(SWIG) -c++ -lua $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(LUA_INCLUDE) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(LUA_SO) +lua_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS) + $(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(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) # ----------------------------------------------------------------- # Build statically linked Lua interpreter # ----------------------------------------------------------------- -lua_static: $(SRCS) - $(SWIG) -lua -module example $(SWIGOPT) $(INTERFACEPATH) - $(CC) $(CFLAGS) $(ISRCS) $(SRCS) $(LUA_INTERP) $(INCLUDES) \ +lua_static: $(SRCDIR_SRCS) + $(SWIG) -lua -module example $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \ $(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET) -lua_static_cpp: $(SRCS) - $(SWIG) -c++ -lua -module example $(SWIGOPT) $(INTERFACEPATH) - $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(LUA_INTERP) $(INCLUDES) \ +lua_static_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS) + $(SWIG) -c++ -lua -module example $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \ $(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET) # ----------------------------------------------------------------- @@ -1313,7 +1464,7 @@ lua_run: $(RUNTOOL) $(LUA) $(LUA_SCRIPT) $(RUNPIPE) lua_embed_run: - $(RUNTOOL) ./$(TARGET) $(RUNPIPE) + $(RUNTOOL) ./$(TARGET) $(LUA_SCRIPT) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -1329,7 +1480,7 @@ lua_version: lua_clean: rm -f *_wrap* *~ .~* mylua@EXEEXT@ rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ + rm -f *.@OBJEXT@ *$(LUA_SO) ################################################################## ##### ALLEGRO CL ###### @@ -1338,15 +1489,15 @@ lua_clean: ALLEGROCL = @ALLEGROCLBIN@ ALLEGROCL_SCRIPT=$(RUNME).lisp -allegrocl: $(SRCS) - $(SWIG) -allegrocl -cwrap $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +allegrocl: $(SRCDIR_SRCS) + $(SWIG) -allegrocl -cwrap $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCDIR_SRCS) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) -allegrocl_cpp: $(SRCS) - $(SWIG) -c++ -allegrocl $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +allegrocl_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -allegrocl $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- # Run ALLEGRO CL example @@ -1378,11 +1529,11 @@ allegrocl_clean: CLISP = @CLISPBIN@ CLISP_SCRIPT=$(RUNME).lisp -clisp: $(SRCS) - $(SWIG) -clisp $(SWIGOPT) $(INTERFACEPATH) +clisp: $(SRCDIR_SRCS) + $(SWIG) -clisp $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) -clisp_cpp: $(SRCS) - $(SWIG) -c++ -clisp $(SWIGOPT) $(INTERFACEPATH) +clisp_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -clisp $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) # ----------------------------------------------------------------- # Run CLISP example @@ -1414,15 +1565,15 @@ clisp_clean: CFFI = @CFFIBIN@ CFFI_SCRIPT=$(RUNME).lisp -cffi: $(SRCS) - $(SWIG) -cffi $(SWIGOPT) $(INTERFACEPATH) -# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) -# $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +cffi: $(SRCDIR_SRCS) + $(SWIG) -cffi $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) +# $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCDIR_SRCS) +# $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) -cffi_cpp: $(SRCS) - $(SWIG) -c++ -cffi $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +cffi_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -cffi $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- # Run CFFI example @@ -1454,15 +1605,15 @@ cffi_clean: UFFI = @UFFIBIN@ UFFI_SCRIPT=$(RUNME).lisp -uffi: $(SRCS) - $(SWIG) -uffi $(SWIGOPT) $(INTERFACEPATH) -# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) -# $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +uffi: $(SRCDIR_SRCS) + $(SWIG) -uffi $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) +# $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCDIR_SRCS) +# $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) -uffi_cpp: $(SRCS) - $(SWIG) -c++ -uffi $(SWIGOPT) $(INTERFACEPATH) -# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) -# $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +uffi_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -uffi $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) +# $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) +# $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) # ----------------------------------------------------------------- # Run UFFI example @@ -1505,23 +1656,23 @@ R_SCRIPT=$(RUNME).R # Build a R dynamically loadable module (C) # ---------------------------------------------------------------- -r: $(SRCS) - $(SWIG) -r $(SWIGOPT) $(INTERFACEPATH) -ifneq ($(SRCS),) - $(CC) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES) +r: $(SRCDIR_SRCS) + $(SWIG) -r $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) +ifneq ($(SRCDIR_SRCS),) + $(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(R_CFLAGS) $(SRCDIR_SRCS) $(INCLUDES) endif - +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null ) + +( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null ) # ---------------------------------------------------------------- # Build a R dynamically loadable module (C++) # ---------------------------------------------------------------- -r_cpp: $(CXXSRCS) +r_cpp: $(SRCDIR_CXXSRCS) $(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) -ifneq ($(CXXSRCS),) - $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES) +ifneq ($(SRCDIR_CXXSRCS),) + $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(R_CFLAGS) $(SRCDIR_CXXSRCS) $(INCLUDES) endif - +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null ) + +( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null ) # ----------------------------------------------------------------- # Run R example @@ -1619,12 +1770,14 @@ scilab_clean: GO = @GO@ GOGCC = @GOGCC@ GO1 = @GO1@ +GO12 = @GO12@ +GO13 = @GO13@ GOC = @GOC@ GOOPT = @GOOPT@ 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` +GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` `if $(GO13) ; then echo -pack ; fi` GOSRCS = $(INTERFACE:.i=.go) GOCSRCS = $(INTERFACE:.i=_gc.c) @@ -1640,45 +1793,83 @@ GOGCOBJS = $(GOSRCS:.go=.$(GOOBJEXT)) GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@) # ---------------------------------------------------------------- -# Build a Go dynamically loadable module (C) +# Build a Go module (C) # ---------------------------------------------------------------- -go: $(SRCS) - $(SWIG) -go $(GOOPT) $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) - $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) - $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) - if ! $(GOGCC) ; then \ - $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ - $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ - fi - -# ---------------------------------------------------------------- -# Build a Go dynamically loadable module (C++) -# ---------------------------------------------------------------- - -go_cpp: $(SRCS) - $(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) - $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS) - if ! $(GOGCC) ; then \ - $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ - $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ - fi - -# ----------------------------------------------------------------- -# Running a Go example -# ----------------------------------------------------------------- - -go_run: runme.go - $(GO) $(GOCOMPILEARG) runme.go - if $(GOGCC) ; then \ - $(COMPILETOOL) $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(LIBPREFIX)$(TARGET)$(SO); \ +go: $(SRCDIR_SRCS) + $(SWIG) -go $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + if $(GO12) || $(GO13) || $(GOGCC); then \ + $(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \ else \ - $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ + $(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \ + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \ fi - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme $(RUNPIPE) + $(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); \ + rm -f $(GOPACKAGE); \ + if $(GO13); then \ + cp $(GOGCOBJS) $(GOPACKAGE); \ + $(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ + else \ + $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + 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) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CC)" -extldflags "$(CFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + else \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + fi; \ + fi + +# ---------------------------------------------------------------- +# Build a Go module (C++) +# ---------------------------------------------------------------- + +go_cpp: $(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); \ + 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); \ + rm -f $(GOPACKAGE); \ + if $(GO13); then \ + cp $(GOGCOBJS) $(GOPACKAGE); \ + $(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ + elif $(GO12); then \ + $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \ + else \ + $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + 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) -lstdc++; \ + elif $(GO12) || $(GO13); then \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CXX)" -extldflags "$(CXXFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + else \ + $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \ + fi; \ + fi + +# ----------------------------------------------------------------- +# Running Go example +# ----------------------------------------------------------------- + +go_run: + env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) ./$(RUNME) $(RUNPIPE) # ----------------------------------------------------------------- # Version display @@ -1692,7 +1883,7 @@ go_version: # ----------------------------------------------------------------- go_clean: - rm -f *_wrap* *_gc* .~* runme $(GOSRCS) + rm -f *_wrap* *_gc* .~* $(RUNME) $(GOSRCS) rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *.[568] *.a *@SO@ @@ -1720,19 +1911,19 @@ D_RUNME = ./$(RUNME) # Build a dynamically loadable D wrapper for a C module # ---------------------------------------------------------------- -d: $(SRCS) - $(SWIGD) $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) - $(LDSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO) +d: $(SRCDIR_SRCS) + $(SWIGD) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) + $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO) # ---------------------------------------------------------------- # Build a dynamically loadable D wrapper for a C++ module # ---------------------------------------------------------------- -d_cpp: $(SRCS) - $(SWIGD) -c++ $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO) +d_cpp: $(SRCDIR_SRCS) + $(SWIGD) -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO) # ---------------------------------------------------------------- # Compile D files @@ -1740,7 +1931,7 @@ d_cpp: $(SRCS) # Clear the DFLAGS environment variable for the compiler call itself # to work around a discrepancy in argument handling between DMD and LDC. -d_compile: $(SRCS) +d_compile: $(SRCDIR_SRCS) DFLAGS="" $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS) # ----------------------------------------------------------------- @@ -1763,6 +1954,6 @@ d_version: # ----------------------------------------------------------------- d_clean: - rm -f *_wrap* *~ .~* runme runme.exe `find . -name \*.d | grep -v runme.d` + rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe `find . -name \*.d | grep -v $(RUNME).d` rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ diff --git a/Examples/README b/Examples/README index 4dda3222d..eff0f2c98 100644 --- a/Examples/README +++ b/Examples/README @@ -1,24 +1,18 @@ SWIG Examples -The "perl5", "python", "tcl", "guile", "java", "mzscheme", "ruby", and -"chicken" directories contain a number of simple examples that are -primarily used for testing. +The subdirectories of "Examples" named after SWIG's language backends +contain a number of simple examples that are primarily used for testing. The file 'index.html' is the top of a hyperlinked document that contains information about all of the examples along with various notes related to each example. -The Examples directory is currently quite incomplete because it -is being reorganized. A more complete set of examples can be found -in the SWIG1.1p5 distribution (most of which should still work with -SWIG1.3). - Note: All of the examples rely upon the Makefile in this directory. You may need to edit it to reflect the configuration of your machine in case the configure script guesses incorrect settings. -*** Special note concering C++ *** +*** Special note concerning C++ *** The configure script is currently unable to handle all of the possible options for producing dynamically loadable C++ extensions. Here are diff --git a/Examples/android/class/Makefile b/Examples/android/class/Makefile index 6155d9494..574566623 100644 --- a/Examples/android/class/Makefile +++ b/Examples/android/class/Makefile @@ -3,9 +3,9 @@ SWIG = $(TOP)/../preinst-swig TARGET = example INTERFACE = example.i INTERFACEDIR = jni/ -PACKAGEDIR = src/org/swig +PACKAGEDIR = $(SRCDIR)src/org/swig PACKAGENAME= org.swig.classexample -SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample +SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample PROJECTNAME= SwigClass TARGETID = 1 #INSTALLOPTIONS = -s # To install on SD Card @@ -13,14 +13,14 @@ TARGETID = 1 check: build build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android_cpp install: - $(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean diff --git a/Examples/android/class/jni/example.cpp b/Examples/android/class/jni/example.cpp index d59cc7c32..7686159fa 100644 --- a/Examples/android/class/jni/example.cpp +++ b/Examples/android/class/jni/example.cpp @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/android/class/jni/example.h b/Examples/android/class/jni/example.h index 64b7684fa..0dff185b2 100644 --- a/Examples/android/class/jni/example.h +++ b/Examples/android/class/jni/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,16 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/android/extend/Makefile b/Examples/android/extend/Makefile index ec53013af..fb974d22c 100644 --- a/Examples/android/extend/Makefile +++ b/Examples/android/extend/Makefile @@ -3,9 +3,9 @@ SWIG = $(TOP)/../preinst-swig TARGET = example INTERFACE = example.i INTERFACEDIR = jni/ -PACKAGEDIR = src/org/swig +PACKAGEDIR = $(SRCDIR)src/org/swig PACKAGENAME= org.swig.extendexample -SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample +SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample PROJECTNAME= SwigExtend TARGETID = 1 #INSTALLOPTIONS = -s # To install on SD Card @@ -13,14 +13,14 @@ TARGETID = 1 check: build build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android_cpp install: - $(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean diff --git a/Examples/android/simple/Makefile b/Examples/android/simple/Makefile index 7e7ff40e1..2bf41968a 100644 --- a/Examples/android/simple/Makefile +++ b/Examples/android/simple/Makefile @@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig TARGET = example INTERFACE = example.i INTERFACEDIR = jni/ -PACKAGEDIR = src/org/swig +PACKAGEDIR = $(SRCDIR)src/org/swig PACKAGENAME= org.swig.simple SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/simple PROJECTNAME= SwigSimple @@ -13,14 +13,14 @@ TARGETID = 1 check: build build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \ PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android install: - $(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \ PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \ PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean diff --git a/Examples/chicken/class/Makefile b/Examples/chicken/class/Makefile index 1436d836f..a37ea4a85 100644 --- a/Examples/chicken/class/Makefile +++ b/Examples/chicken/class/Makefile @@ -1,12 +1,11 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig INTERFACE = example.i -SRCS = +SRCS = CXXSRCS = example.cxx TARGET = class INCLUDE = SWIGOPT = -CFLAGS = VARIANT = # uncomment the following lines to build a static exe (only pick one of the CHICKEN_MAIN lines) @@ -15,24 +14,24 @@ VARIANT = #VARIANT = _static check: build - $(MAKE) -f $(TOP)/Makefile CHICKEN_SCRIPT='runme-lowlevel.scm' chicken_run - $(MAKE) -f $(TOP)/Makefile CHICKEN_SCRIPT='runme-tinyclos.scm' chicken_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CHICKEN_SCRIPT='runme-lowlevel.scm' chicken_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CHICKEN_SCRIPT='runme-tinyclos.scm' chicken_run build: $(TARGET) $(TARGET)_proxy $(TARGET): $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp $(TARGET)_proxy: $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT) -proxy' TARGET='$(TARGET)_proxy' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp clean: - $(MAKE) -f $(TOP)/Makefile chicken_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean rm -f example.scm rm -f $(TARGET) diff --git a/Examples/chicken/class/example.cxx b/Examples/chicken/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/chicken/class/example.cxx +++ b/Examples/chicken/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/chicken/class/example.h b/Examples/chicken/class/example.h index 210ba989f..5bad31693 100644 --- a/Examples/chicken/class/example.h +++ b/Examples/chicken/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; enum SomeEnum { @@ -26,21 +26,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/chicken/class/example.i b/Examples/chicken/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/chicken/class/example.i +++ b/Examples/chicken/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/chicken/constants/Makefile b/Examples/chicken/constants/Makefile index 31e39d346..7167e866b 100644 --- a/Examples/chicken/constants/Makefile +++ b/Examples/chicken/constants/Makefile @@ -2,29 +2,28 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig INTERFACE = example.i SRCS = -CXXSRCS = +CXXSRCS = TARGET = constants INCLUDE = -SWIGOPT = -CFLAGS = -VARIANT = +SWIGOPT = +VARIANT = # uncomment the following two lines to build a static exe #CHICKEN_MAIN = runme.scm #VARIANT = _static check: build - $(MAKE) -f $(TOP)/Makefile chicken_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_run build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: - $(MAKE) -f $(TOP)/Makefile chicken_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean rm -f example.scm rm -f $(TARGET) diff --git a/Examples/chicken/multimap/Makefile b/Examples/chicken/multimap/Makefile index eba36169d..e8192e9cd 100644 --- a/Examples/chicken/multimap/Makefile +++ b/Examples/chicken/multimap/Makefile @@ -2,29 +2,28 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig INTERFACE = example.i SRCS = example.c -CXXSRCS = +CXXSRCS = TARGET = multimap INCLUDE = -SWIGOPT = -CFLAGS = -VARIANT = +SWIGOPT = +VARIANT = # uncomment the following two lines to build a static exe #CHICKEN_MAIN = runme.scm #VARIANT = _static check: build - $(MAKE) -f $(TOP)/Makefile chicken_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_run build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: - $(MAKE) -f $(TOP)/Makefile chicken_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean rm -f example.scm rm -f $(TARGET) diff --git a/Examples/chicken/overload/Makefile b/Examples/chicken/overload/Makefile index e15352ec5..a9647d93e 100644 --- a/Examples/chicken/overload/Makefile +++ b/Examples/chicken/overload/Makefile @@ -1,30 +1,29 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig INTERFACE = example.i -SRCS = +SRCS = CXXSRCS = example.cxx TARGET = overload INCLUDE = SWIGOPT = -proxy -unhideprimitive -CFLAGS = -VARIANT = +VARIANT = # uncomment the following lines to build a static exe #CHICKEN_MAIN = runme.scm #VARIANT = _static check: build - $(MAKE) -f $(TOP)/Makefile chicken_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_run build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp clean: - $(MAKE) -f $(TOP)/Makefile chicken_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean rm -f example.scm rm -f $(TARGET) diff --git a/Examples/chicken/simple/Makefile b/Examples/chicken/simple/Makefile index f8fb006a4..c07075efa 100644 --- a/Examples/chicken/simple/Makefile +++ b/Examples/chicken/simple/Makefile @@ -2,29 +2,28 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig INTERFACE = example.i SRCS = example.c -CXXSRCS = +CXXSRCS = TARGET = simple INCLUDE = -SWIGOPT = -CFLAGS = -VARIANT = +SWIGOPT = +VARIANT = # uncomment the following two lines to build a static exe #CHICKEN_MAIN = runme.scm #VARIANT = _static check: build - $(MAKE) -f $(TOP)/Makefile chicken_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_run build: $(TARGET) $(TARGET): $(INTERFACE) $(SRCS) - $(MAKE) -f $(TOP)/Makefile \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT) clean: - $(MAKE) -f $(TOP)/Makefile chicken_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' chicken_clean rm -f example.scm example-generic.scm example-clos.scm rm -f $(TARGET) diff --git a/Examples/csharp/arrays/Makefile b/Examples/csharp/arrays/Makefile index 65386f0dc..e5d733d35 100644 --- a/Examples/csharp/arrays/Makefile +++ b/Examples/csharp/arrays/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -unsafe -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -unsafe -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/arrays/example-cs.csproj b/Examples/csharp/arrays/example-cs.csproj new file mode 100644 index 000000000..422c76be3 --- /dev/null +++ b/Examples/csharp/arrays/example-cs.csproj @@ -0,0 +1,90 @@ + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + true + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + true + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + true + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + true + + + + Code + + + Code + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/arrays/example-vc.vcproj b/Examples/csharp/arrays/example-vc.vcproj new file mode 100644 index 000000000..d3ee58ec4 --- /dev/null +++ b/Examples/csharp/arrays/example-vc.vcproj @@ -0,0 +1,415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/csharp/arrays/example.sln b/Examples/csharp/arrays/example.sln new file mode 100644 index 000000000..234bd64d3 --- /dev/null +++ b/Examples/csharp/arrays/example.sln @@ -0,0 +1,38 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" + ProjectSection(ProjectDependencies) = postProject + {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Examples/csharp/callback/Makefile b/Examples/csharp/callback/Makefile index 340febc88..4f4c84b9a 100644 --- a/Examples/csharp/callback/Makefile +++ b/Examples/csharp/callback/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -debug -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/callback/example-cs.csproj b/Examples/csharp/callback/example-cs.csproj index ce5ccfd9a..14d43dcb2 100644 --- a/Examples/csharp/callback/example-cs.csproj +++ b/Examples/csharp/callback/example-cs.csproj @@ -1,99 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + + + Code + + + Code + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/callback/example-vc.vcproj b/Examples/csharp/callback/example-vc.vcproj index 5788bc9c7..5958945e9 100644 --- a/Examples/csharp/callback/example-vc.vcproj +++ b/Examples/csharp/callback/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,69 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + + + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/callback/example.sln b/Examples/csharp/callback/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/callback/example.sln +++ b/Examples/csharp/callback/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/check.list b/Examples/csharp/check.list index 5454d8531..a530a4b42 100644 --- a/Examples/csharp/check.list +++ b/Examples/csharp/check.list @@ -5,6 +5,7 @@ class enum extend funcptr +nested reference simple template diff --git a/Examples/csharp/class/Makefile b/Examples/csharp/class/Makefile index bc3ce8ce8..4f4c84b9a 100644 --- a/Examples/csharp/class/Makefile +++ b/Examples/csharp/class/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/class/example-cs.csproj b/Examples/csharp/class/example-cs.csproj index 8b105d7fc..4f6d66ae1 100644 --- a/Examples/csharp/class/example-cs.csproj +++ b/Examples/csharp/class/example-cs.csproj @@ -1,104 +1,89 @@ - - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + + Code + + + Code + + + Code + + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/class/example-vc.vcproj b/Examples/csharp/class/example-vc.vcproj index 5788bc9c7..ef870959e 100644 --- a/Examples/csharp/class/example-vc.vcproj +++ b/Examples/csharp/class/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/class/example.cxx b/Examples/csharp/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/csharp/class/example.cxx +++ b/Examples/csharp/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/csharp/class/example.h b/Examples/csharp/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/csharp/class/example.h +++ b/Examples/csharp/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/csharp/class/example.i b/Examples/csharp/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/csharp/class/example.i +++ b/Examples/csharp/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/csharp/class/example.sln b/Examples/csharp/class/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/class/example.sln +++ b/Examples/csharp/class/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/enum/Makefile b/Examples/csharp/enum/Makefile index bc3ce8ce8..4f4c84b9a 100644 --- a/Examples/csharp/enum/Makefile +++ b/Examples/csharp/enum/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/enum/example-cs.csproj b/Examples/csharp/enum/example-cs.csproj index 44face8ed..5c8bd3cc4 100644 --- a/Examples/csharp/enum/example-cs.csproj +++ b/Examples/csharp/enum/example-cs.csproj @@ -1,99 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + + Code + + + Code + + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/enum/example-vc.vcproj b/Examples/csharp/enum/example-vc.vcproj index 5788bc9c7..ef870959e 100644 --- a/Examples/csharp/enum/example-vc.vcproj +++ b/Examples/csharp/enum/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/enum/example.sln b/Examples/csharp/enum/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/enum/example.sln +++ b/Examples/csharp/enum/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/extend/Makefile b/Examples/csharp/extend/Makefile index bc3ce8ce8..4f4c84b9a 100644 --- a/Examples/csharp/extend/Makefile +++ b/Examples/csharp/extend/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/extend/example-cs.csproj b/Examples/csharp/extend/example-cs.csproj index 95923991b..68d202c58 100644 --- a/Examples/csharp/extend/example-cs.csproj +++ b/Examples/csharp/extend/example-cs.csproj @@ -1,104 +1,89 @@ - - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + + + Code + + + Code + + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/extend/example-vc.vcproj b/Examples/csharp/extend/example-vc.vcproj index 5788bc9c7..5958945e9 100644 --- a/Examples/csharp/extend/example-vc.vcproj +++ b/Examples/csharp/extend/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,69 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + + + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/extend/example.h b/Examples/csharp/extend/example.h index b27ab9711..ca1aed28f 100644 --- a/Examples/csharp/extend/example.h +++ b/Examples/csharp/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/csharp/extend/example.sln b/Examples/csharp/extend/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/extend/example.sln +++ b/Examples/csharp/extend/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/funcptr/Makefile b/Examples/csharp/funcptr/Makefile index 875ae0e71..99cdfa38a 100644 --- a/Examples/csharp/funcptr/Makefile +++ b/Examples/csharp/funcptr/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/funcptr/example-cs.csproj b/Examples/csharp/funcptr/example-cs.csproj index 5a107c528..d8c455927 100644 --- a/Examples/csharp/funcptr/example-cs.csproj +++ b/Examples/csharp/funcptr/example-cs.csproj @@ -1,94 +1,87 @@ - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/funcptr/example-vc.vcproj b/Examples/csharp/funcptr/example-vc.vcproj index 7ba8cbde1..d3ee58ec4 100644 --- a/Examples/csharp/funcptr/example-vc.vcproj +++ b/Examples/csharp/funcptr/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,45 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.c" + > + RelativePath="example_wrap.c" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.c" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.c" + /> + + + + + + diff --git a/Examples/csharp/funcptr/example.sln b/Examples/csharp/funcptr/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/funcptr/example.sln +++ b/Examples/csharp/funcptr/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/nested/Makefile b/Examples/csharp/nested/Makefile new file mode 100644 index 000000000..4f4c84b9a --- /dev/null +++ b/Examples/csharp/nested/Makefile @@ -0,0 +1,19 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = +CSHARPSRCS = *.cs +CSHARPFLAGS= -nologo -debug+ -out:runme.exe + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/nested/example-cs.csproj b/Examples/csharp/nested/example-cs.csproj new file mode 100644 index 000000000..b20ff231a --- /dev/null +++ b/Examples/csharp/nested/example-cs.csproj @@ -0,0 +1,87 @@ + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/nested/example-vc.vcproj b/Examples/csharp/nested/example-vc.vcproj new file mode 100644 index 000000000..ef870959e --- /dev/null +++ b/Examples/csharp/nested/example-vc.vcproj @@ -0,0 +1,415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/csharp/nested/example.cxx b/Examples/csharp/nested/example.cxx new file mode 100644 index 000000000..03bb74d9e --- /dev/null +++ b/Examples/csharp/nested/example.cxx @@ -0,0 +1,62 @@ +#include "example.h" + +int MotorCar::DesignOpinion::AceDesignCount = 0; +int MotorCar::DesignOpinion::TotalDesignCount = 0; + +int MotorCar::DesignOpinion::PercentScore() { + return AceDesignCount*100/TotalDesignCount; +} + +MotorCar::Wheels::Wheels(Shape shape, size_t count) : shape(shape), count(count) {} + +MotorCar::WindScreen::WindScreen(bool opaque) : opaque(opaque) {} + +MotorCar::MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) : name(name), wheels(wheels), windscreen(windscreen) {} + +MotorCar MotorCar::DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) { + MotorCar car = MotorCar(name, wheels, windscreen); + DesignOpinion::TotalDesignCount++; + if (car.wheels.Opinion().itrocks && car.windscreen.Opinion().itrocks) + DesignOpinion::AceDesignCount++; + return car; +} + +MotorCar::DesignOpinion MotorCar::Wheels::Opinion() { + DesignOpinion opinion; + opinion.itrocks = true; + if (shape == Square) { + opinion.itrocks = false; + opinion.reason = "you'll have a few issues with wheel rotation"; + } + if (count <= 2) { + opinion.reason += opinion.itrocks ? "" : " and "; + opinion.itrocks = false; + opinion.reason += "a few more wheels are needed for stability"; + } + if (opinion.itrocks) + opinion.reason = "your choice of wheels was top notch"; + + return opinion; +} + +MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() { + DesignOpinion opinion; + opinion.itrocks = !opaque; + opinion.reason = opinion.itrocks ? "the driver will have a commanding view out the window" : "you can't see out the windscreen"; + return opinion; +} + +std::string MotorCar::WillItWork() { + DesignOpinion wh = wheels.Opinion(); + DesignOpinion ws = windscreen.Opinion(); + std::string willit; + if (wh.itrocks && ws.itrocks) { + willit = "Great car design because " + wh.reason + " and " + ws.reason; + } else { + willit = "You need a rethink because "; + willit += wh.itrocks ? "" : wh.reason; + willit += (!wh.itrocks && !ws.itrocks) ? " and " : ""; + willit += ws.itrocks ? "" : ws.reason; + } + return willit; +} diff --git a/Examples/csharp/nested/example.h b/Examples/csharp/nested/example.h new file mode 100644 index 000000000..4fb107cb5 --- /dev/null +++ b/Examples/csharp/nested/example.h @@ -0,0 +1,48 @@ +#include + +/** Design a motor car from various components */ +struct MotorCar { + + /** Information about an opinion of the design of a car component */ + struct DesignOpinion { + bool itrocks; + std::string reason; + static int AceDesignCount; + static int TotalDesignCount; + static int PercentScore(); + }; + + /** Wheels component */ + struct Wheels { + enum Shape { Round, Square }; + Wheels(Shape shape, size_t count); + DesignOpinion Opinion(); + private: + Shape shape; + size_t count; + }; + + /** Windscreen component */ + struct WindScreen { + WindScreen(bool opaque); + DesignOpinion Opinion(); + private: + bool opaque; + }; + + /** Factory method for creating a car */ + static MotorCar DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + + std::string Name() { + return name; + } + + /** Get an overall opinion on the car design */ + std::string WillItWork(); + +private: + MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + std::string name; + Wheels wheels; + WindScreen windscreen; +}; diff --git a/Examples/csharp/nested/example.i b/Examples/csharp/nested/example.i new file mode 100644 index 000000000..c07c1521a --- /dev/null +++ b/Examples/csharp/nested/example.i @@ -0,0 +1,13 @@ +%module example + +// This example shows how wrappers for numerous aspects of C++ nested classes work: +// Nested static and instance variables and methods and nested enums + +%include + +%{ +#include "example.h" +%} + +%include "example.h" + diff --git a/Examples/csharp/nested/example.sln b/Examples/csharp/nested/example.sln new file mode 100644 index 000000000..234bd64d3 --- /dev/null +++ b/Examples/csharp/nested/example.sln @@ -0,0 +1,38 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" + ProjectSection(ProjectDependencies) = postProject + {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Examples/csharp/nested/runme.cs b/Examples/csharp/nested/runme.cs new file mode 100644 index 000000000..facaefdb7 --- /dev/null +++ b/Examples/csharp/nested/runme.cs @@ -0,0 +1,27 @@ +// This example illustrates how C++ classes can be used from C# using SWIG. +// The C# class gets mapped onto the C++ class and behaves as if it is a C# class. + +using System; + +public class runme +{ + static void Main() + { + MotorCar car1 = MotorCar.DesignFromComponents("Bumpy", new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 4), new MotorCar.WindScreen(false)); + MotorCar car2 = MotorCar.DesignFromComponents("Wobbly", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 2), new MotorCar.WindScreen(false)); + MotorCar car3 = MotorCar.DesignFromComponents("Batty", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(true)); + MotorCar car4 = MotorCar.DesignFromComponents("Spiffing", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(false)); + + Console.WriteLine("Expert opinion on " + car1.Name() + " : \n " + car1.WillItWork()); + Console.WriteLine("Expert opinion on " + car2.Name() + " : \n " + car2.WillItWork()); + Console.WriteLine("Expert opinion on " + car3.Name() + " : \n " + car3.WillItWork()); + Console.WriteLine("Expert opinion on " + car4.Name() + " : \n " + car4.WillItWork()); + + int count = MotorCar.DesignOpinion.AceDesignCount; + int total = MotorCar.DesignOpinion.TotalDesignCount; + int percent = MotorCar.DesignOpinion.PercentScore(); + Console.WriteLine("Overall opinion rating on car design is " + count + "/" + total + " = " + percent + "%"); + + Console.WriteLine("Single square wheel thoughts: " + new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 1).Opinion().reason); + } +} diff --git a/Examples/csharp/reference/Makefile b/Examples/csharp/reference/Makefile index bc3ce8ce8..4f4c84b9a 100644 --- a/Examples/csharp/reference/Makefile +++ b/Examples/csharp/reference/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/reference/example-cs.csproj b/Examples/csharp/reference/example-cs.csproj index a3efbe036..c8ad31839 100644 --- a/Examples/csharp/reference/example-cs.csproj +++ b/Examples/csharp/reference/example-cs.csproj @@ -1,99 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/reference/example-vc.vcproj b/Examples/csharp/reference/example-vc.vcproj index 5788bc9c7..ef870959e 100644 --- a/Examples/csharp/reference/example-vc.vcproj +++ b/Examples/csharp/reference/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,43 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.cxx" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/reference/example.cxx b/Examples/csharp/reference/example.cxx index 8a513bf49..9dbaed2ee 100644 --- a/Examples/csharp/reference/example.cxx +++ b/Examples/csharp/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/csharp/reference/example.sln b/Examples/csharp/reference/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/reference/example.sln +++ b/Examples/csharp/reference/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/simple/Makefile b/Examples/csharp/simple/Makefile index 875ae0e71..99cdfa38a 100644 --- a/Examples/csharp/simple/Makefile +++ b/Examples/csharp/simple/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/simple/example-cs.csproj b/Examples/csharp/simple/example-cs.csproj index 3d91f9a47..6138dd0ec 100644 --- a/Examples/csharp/simple/example-cs.csproj +++ b/Examples/csharp/simple/example-cs.csproj @@ -1,89 +1,86 @@ - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/simple/example-vc.vcproj b/Examples/csharp/simple/example-vc.vcproj index ec289c6eb..74b504671 100644 --- a/Examples/csharp/simple/example-vc.vcproj +++ b/Examples/csharp/simple/example-vc.vcproj @@ -10,14 +10,17 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -180,11 +351,11 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > @@ -206,6 +377,15 @@ Outputs="$(InputName)_wrap.c" /> + + + @@ -215,6 +395,15 @@ Outputs="$(InputName)_wrap.c" /> + + + diff --git a/Examples/csharp/simple/example.sln b/Examples/csharp/simple/example.sln index 3ebbba5c6..234bd64d3 100644 --- a/Examples/csharp/simple/example.sln +++ b/Examples/csharp/simple/example.sln @@ -1,5 +1,5 @@ Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C++ Express 2005 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} @@ -10,15 +10,27 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|Any CPU - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|Any CPU + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Examples/csharp/template/Makefile b/Examples/csharp/template/Makefile index 43243d6d5..2d0e07009 100644 --- a/Examples/csharp/template/Makefile +++ b/Examples/csharp/template/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/template/example-cs.csproj b/Examples/csharp/template/example-cs.csproj index bf17c141f..782aeacae 100644 --- a/Examples/csharp/template/example-cs.csproj +++ b/Examples/csharp/template/example-cs.csproj @@ -1,109 +1,90 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/template/example-vc.vcproj b/Examples/csharp/template/example-vc.vcproj index f7bbbcb62..f8a900096 100644 --- a/Examples/csharp/template/example-vc.vcproj +++ b/Examples/csharp/template/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,42 +348,61 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example_wrap.cxx" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + RelativePath="example.h" + > + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -c++ -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.cxx" + /> + + + + + + diff --git a/Examples/csharp/template/example.sln b/Examples/csharp/template/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/template/example.sln +++ b/Examples/csharp/template/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/csharp/variables/Makefile b/Examples/csharp/variables/Makefile index 875ae0e71..99cdfa38a 100644 --- a/Examples/csharp/variables/Makefile +++ b/Examples/csharp/variables/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i SWIGOPT = CSHARPSRCS = *.cs -CSHARPFLAGS= -nologo -out:runme.exe +CSHARPFLAGS= -nologo -debug+ -out:runme.exe check: build - $(MAKE) -f $(TOP)/Makefile csharp_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp - $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile clean: - $(MAKE) -f $(TOP)/Makefile csharp_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' csharp_clean diff --git a/Examples/csharp/variables/example-cs.csproj b/Examples/csharp/variables/example-cs.csproj index a73c879fb..d2ce17a6a 100644 --- a/Examples/csharp/variables/example-cs.csproj +++ b/Examples/csharp/variables/example-cs.csproj @@ -1,99 +1,88 @@ - - - - - - - - - - - - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A} + Debug + x86 + + + + + runme + + + JScript + Grid + IE50 + false + Exe + runme + OnBuildSuccess + + + + + + + + + true + bin\x86\Debug\ + DEBUG;TRACE + 285212672 + full + x86 + prompt + + + bin\x86\Release\ + TRACE + 285212672 + true + + + x86 + prompt + + + true + bin\x64\Debug\ + DEBUG;TRACE + 285212672 + full + x64 + prompt + + + bin\x64\Release\ + TRACE + 285212672 + true + + + x64 + prompt + + + + Code + + + Code + + + Code + + + + + + + + + copy runme.exe "$(SolutionDir)runme.exe" +echo Run the example from the root directory $(SolutionDir) and ensure example.dll is also in this directory + + diff --git a/Examples/csharp/variables/example-vc.vcproj b/Examples/csharp/variables/example-vc.vcproj index acd55a379..d3ee58ec4 100644 --- a/Examples/csharp/variables/example-vc.vcproj +++ b/Examples/csharp/variables/example-vc.vcproj @@ -1,110 +1,345 @@ + Keyword="Win32Proj" + > + Name="Win32" + /> + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + + + + + + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + Name="VCManagedResourceCompilerTool" + /> + + + ImportLibrary="$(OutDir)\example.lib" + TargetMachine="1" + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCWebDeploymentTool" + /> + Name="VCPostBuildEventTool" + Description="Copy unmanaged dll to root directory..." + CommandLine="echo on copy "$(OutDir)\example.dll" "$(SolutionDir)" @echo off " + /> + + + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + + + + + + + + + + + + + + + + @@ -113,42 +348,65 @@ + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + RelativePath="example.c" + > + RelativePath="example_wrap.c" + > + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + + + RelativePath=".\example.i" + > + Name="Debug|Win32" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.c" + /> + Name="Debug|x64" + > + CommandLine="echo Invoking SWIG... echo on ..\..\..\swig.exe -csharp "$(InputPath)" @echo off " + Outputs="$(InputName)_wrap.c" + /> + + + + + + diff --git a/Examples/csharp/variables/example.c b/Examples/csharp/variables/example.c index aa4ffe9b3..85685fe72 100644 --- a/Examples/csharp/variables/example.c +++ b/Examples/csharp/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + 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); } diff --git a/Examples/csharp/variables/example.sln b/Examples/csharp/variables/example.sln index 88995ffd3..234bd64d3 100644 --- a/Examples/csharp/variables/example.sln +++ b/Examples/csharp/variables/example.sln @@ -1,30 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" ProjectSection(ProjectDependencies) = postProject {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection EndProject Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET - {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 - {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.ActiveCfg = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|Win32.Build.0 = Debug|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.ActiveCfg = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug|x64.Build.0 = Debug|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.ActiveCfg = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|Win32.Build.0 = Release|x86 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.ActiveCfg = Release|x64 + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release|x64.Build.0 = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|Win32.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.ActiveCfg = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug|x64.Build.0 = Debug|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|Win32.Build.0 = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.ActiveCfg = Release|x64 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release|x64.Build.0 = Release|x64 EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal diff --git a/Examples/d/callback/Makefile b/Examples/d/callback/Makefile index eda18f13c..72edc17a5 100644 --- a/Examples/d/callback/Makefile +++ b/Examples/d/callback/Makefile @@ -15,13 +15,13 @@ DFLAGS = -ofrunme check: build cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run build: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ - $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile clean: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean diff --git a/Examples/d/class/Makefile b/Examples/d/class/Makefile index eda18f13c..72edc17a5 100644 --- a/Examples/d/class/Makefile +++ b/Examples/d/class/Makefile @@ -15,13 +15,13 @@ DFLAGS = -ofrunme check: build cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run build: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ - $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile clean: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean diff --git a/Examples/d/class/example.cxx b/Examples/d/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/d/class/example.cxx +++ b/Examples/d/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/d/class/example.h b/Examples/d/class/example.h index 0d4527e92..0dff185b2 100644 --- a/Examples/d/class/example.h +++ b/Examples/d/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,16 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/d/class/example.i b/Examples/d/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/d/class/example.i +++ b/Examples/d/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/d/constants/Makefile b/Examples/d/constants/Makefile index d537ce281..609c7f660 100644 --- a/Examples/d/constants/Makefile +++ b/Examples/d/constants/Makefile @@ -15,13 +15,13 @@ DFLAGS = -ofrunme check: build cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run build: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ - $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile clean: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean diff --git a/Examples/d/enum/Makefile b/Examples/d/enum/Makefile index eda18f13c..72edc17a5 100644 --- a/Examples/d/enum/Makefile +++ b/Examples/d/enum/Makefile @@ -15,13 +15,13 @@ DFLAGS = -ofrunme check: build cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run build: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ - $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile clean: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean diff --git a/Examples/d/extend/Makefile b/Examples/d/extend/Makefile index eda18f13c..72edc17a5 100644 --- a/Examples/d/extend/Makefile +++ b/Examples/d/extend/Makefile @@ -15,13 +15,13 @@ DFLAGS = -ofrunme check: build cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run build: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ - $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile clean: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean diff --git a/Examples/d/extend/example.h b/Examples/d/extend/example.h index 7ad93fbc1..7a8c04c33 100644 --- a/Examples/d/extend/example.h +++ b/Examples/d/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/d/funcptr/Makefile b/Examples/d/funcptr/Makefile index 2ba893ca7..6554c3c73 100644 --- a/Examples/d/funcptr/Makefile +++ b/Examples/d/funcptr/Makefile @@ -15,13 +15,13 @@ DFLAGS = -ofrunme check: build cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run build: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ - $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile clean: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean diff --git a/Examples/d/simple/Makefile b/Examples/d/simple/Makefile index a8808c9c5..f5eed3210 100644 --- a/Examples/d/simple/Makefile +++ b/Examples/d/simple/Makefile @@ -15,13 +15,13 @@ DFLAGS = -ofrunme check: build cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run build: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ - $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile clean: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean diff --git a/Examples/d/variables/Makefile b/Examples/d/variables/Makefile index a8808c9c5..f5eed3210 100644 --- a/Examples/d/variables/Makefile +++ b/Examples/d/variables/Makefile @@ -15,13 +15,13 @@ DFLAGS = -ofrunme check: build cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run build: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ - $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile clean: cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile d_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean diff --git a/Examples/d/variables/example.c b/Examples/d/variables/example.c index 1bf9c120f..f5356c755 100644 --- a/Examples/d/variables/example.c +++ b/Examples/d/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + 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); } diff --git a/Examples/go/callback/Makefile b/Examples/go/callback/Makefile index 7489f87dc..bf5275f14 100644 --- a/Examples/go/callback/Makefile +++ b/Examples/go/callback/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = callback.cxx TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/callback/example.cxx b/Examples/go/callback/callback.cxx similarity index 100% rename from Examples/go/callback/example.cxx rename to Examples/go/callback/callback.cxx diff --git a/Examples/go/class/Makefile b/Examples/go/class/Makefile index a099654f1..de067cdd8 100644 --- a/Examples/go/class/Makefile +++ b/Examples/go/class/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = class.cxx TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/class/class.cxx b/Examples/go/class/class.cxx new file mode 100644 index 000000000..f87c7ec8f --- /dev/null +++ b/Examples/go/class/class.cxx @@ -0,0 +1,28 @@ +/* File : class.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/go/class/example.h b/Examples/go/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/go/class/example.h +++ b/Examples/go/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/go/class/example.i b/Examples/go/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/go/class/example.i +++ b/Examples/go/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/go/class/index.html b/Examples/go/class/index.html index b39119d12..df93b5672 100644 --- a/Examples/go/class/index.html +++ b/Examples/go/class/index.html @@ -33,8 +33,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -45,7 +45,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -54,7 +54,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; diff --git a/Examples/go/constants/Makefile b/Examples/go/constants/Makefile index b45feb963..8fb07fd6b 100644 --- a/Examples/go/constants/Makefile +++ b/Examples/go/constants/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/enum/Makefile b/Examples/go/enum/Makefile index 7489f87dc..2e2f1b2bd 100644 --- a/Examples/go/enum/Makefile +++ b/Examples/go/enum/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = enum.cxx TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/enum/example.cxx b/Examples/go/enum/enum.cxx similarity index 100% rename from Examples/go/enum/example.cxx rename to Examples/go/enum/enum.cxx diff --git a/Examples/go/extend/Makefile b/Examples/go/extend/Makefile index 7489f87dc..290694210 100644 --- a/Examples/go/extend/Makefile +++ b/Examples/go/extend/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = extend.cxx TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/extend/example.h b/Examples/go/extend/example.h index b27ab9711..ca1aed28f 100644 --- a/Examples/go/extend/example.h +++ b/Examples/go/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/go/extend/example.cxx b/Examples/go/extend/extend.cxx similarity index 100% rename from Examples/go/extend/example.cxx rename to Examples/go/extend/extend.cxx diff --git a/Examples/go/funcptr/Makefile b/Examples/go/funcptr/Makefile index 452ea2118..82031c9d5 100644 --- a/Examples/go/funcptr/Makefile +++ b/Examples/go/funcptr/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = funcptr.c TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/funcptr/example.c b/Examples/go/funcptr/funcptr.c similarity index 100% rename from Examples/go/funcptr/example.c rename to Examples/go/funcptr/funcptr.c diff --git a/Examples/go/multimap/Makefile b/Examples/go/multimap/Makefile index 452ea2118..4d739162b 100644 --- a/Examples/go/multimap/Makefile +++ b/Examples/go/multimap/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = multimap.c TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/multimap/example.c b/Examples/go/multimap/multimap.c similarity index 100% rename from Examples/go/multimap/example.c rename to Examples/go/multimap/multimap.c diff --git a/Examples/go/pointer/Makefile b/Examples/go/pointer/Makefile index 452ea2118..9f1f3fda0 100644 --- a/Examples/go/pointer/Makefile +++ b/Examples/go/pointer/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = pointer.c TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/pointer/example.c b/Examples/go/pointer/pointer.c similarity index 100% rename from Examples/go/pointer/example.c rename to Examples/go/pointer/pointer.c diff --git a/Examples/go/reference/Makefile b/Examples/go/reference/Makefile index 7489f87dc..e136f6fae 100644 --- a/Examples/go/reference/Makefile +++ b/Examples/go/reference/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx +CXXSRCS = reference.cxx TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/reference/reference.cxx b/Examples/go/reference/reference.cxx new file mode 100644 index 000000000..9dbaed2ee --- /dev/null +++ b/Examples/go/reference/reference.cxx @@ -0,0 +1,46 @@ +/* File : example.cxx */ + +/* 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 "example.h" +#include +#include + +Vector operator+(const Vector &a, const Vector &b) { + Vector r; + r.x = a.x + b.x; + r.y = a.y + b.y; + r.z = a.z + b.z; + return r; +} + +char *Vector::print() { + static char temp[512]; + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); + return temp; +} + +VectorArray::VectorArray(int size) { + items = new Vector[size]; + maxsize = size; +} + +VectorArray::~VectorArray() { + delete [] items; +} + +Vector &VectorArray::operator[](int index) { + if ((index < 0) || (index >= maxsize)) { + printf("Panic! Array index out of bounds.\n"); + exit(1); + } + return items[index]; +} + +int VectorArray::size() { + return maxsize; +} + diff --git a/Examples/go/simple/Makefile b/Examples/go/simple/Makefile index 75f81bffe..5bc16549d 100644 --- a/Examples/go/simple/Makefile +++ b/Examples/go/simple/Makefile @@ -1,15 +1,15 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = simple.c TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/simple/example.c b/Examples/go/simple/simple.c similarity index 100% rename from Examples/go/simple/example.c rename to Examples/go/simple/simple.c diff --git a/Examples/go/template/Makefile b/Examples/go/template/Makefile index 9ee030479..a1d674836 100644 --- a/Examples/go/template/Makefile +++ b/Examples/go/template/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/template/index.html b/Examples/go/template/index.html index a14e3b29a..cf2b1337b 100644 --- a/Examples/go/template/index.html +++ b/Examples/go/template/index.html @@ -17,7 +17,7 @@ SWIG.

      The C++ Code

      -Lets take a templated function and a templated class as follows: +Let's take a templated function and a templated class as follows:
      diff --git a/Examples/go/variables/Makefile b/Examples/go/variables/Makefile
      index 452ea2118..d0da605e0 100644
      --- a/Examples/go/variables/Makefile
      +++ b/Examples/go/variables/Makefile
      @@ -1,16 +1,16 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = example.c
      +SRCS       = variables.c
       TARGET     = example
       INTERFACE  = example.i
       SWIGOPT    =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean
      diff --git a/Examples/go/variables/example.c b/Examples/go/variables/variables.c
      similarity index 97%
      rename from Examples/go/variables/example.c
      rename to Examples/go/variables/variables.c
      index aa4ffe9b3..05e17c8c5 100644
      --- a/Examples/go/variables/example.c
      +++ b/Examples/go/variables/variables.c
      @@ -51,7 +51,7 @@ void print_vars() {
         printf("dvar      = %g\n", dvar);
         printf("cvar      = %c\n", cvar);
         printf("strvar    = %s\n", strvar ? strvar : "(null)");
      -  printf("cstrvar   = %s\n", cstrvar ? cstrvar : "(null)");
      +  printf("cstrvar   = %s\n", cstrvar);
         printf("iptrvar   = %p\n", iptrvar);
         printf("name      = %s\n", name);
         printf("ptptr     = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
      diff --git a/Examples/guile/class/Makefile b/Examples/guile/class/Makefile
      index 8de4f292b..48426a8fb 100644
      --- a/Examples/guile/class/Makefile
      +++ b/Examples/guile/class/Makefile
      @@ -5,15 +5,15 @@ TARGET     = example
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile guile_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
      diff --git a/Examples/guile/class/example.cxx b/Examples/guile/class/example.cxx
      index 1e8e203dd..046304519 100644
      --- a/Examples/guile/class/example.cxx
      +++ b/Examples/guile/class/example.cxx
      @@ -1,4 +1,4 @@
      -/* File : example.c */
      +/* File : example.cxx */
       
       #include "example.h"
       #define M_PI 3.14159265358979323846
      @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
       
       int Shape::nshapes = 0;
       
      -double Circle::area(void) {
      +double Circle::area() {
         return M_PI*radius*radius;
       }
       
      -double Circle::perimeter(void) {
      +double Circle::perimeter() {
         return 2*M_PI*radius;
       }
       
      -double Square::area(void) {
      +double Square::area() {
         return width*width;
       }
       
      -double Square::perimeter(void) {
      +double Square::perimeter() {
         return 4*width;
       }
      diff --git a/Examples/guile/class/example.h b/Examples/guile/class/example.h
      index 0d4527e92..0dff185b2 100644
      --- a/Examples/guile/class/example.h
      +++ b/Examples/guile/class/example.h
      @@ -7,11 +7,11 @@ public:
         }
         virtual ~Shape() {
           nshapes--;
      -  };
      +  }
         double  x, y;
         void    move(double dx, double dy);
      -  virtual double area(void) = 0;
      -  virtual double perimeter(void) = 0;
      +  virtual double area() = 0;
      +  virtual double perimeter() = 0;
         static  int nshapes;
       };
       
      @@ -19,16 +19,16 @@ class Circle : public Shape {
       private:
         double radius;
       public:
      -  Circle(double r) : radius(r) { };
      -  virtual double area(void);
      -  virtual double perimeter(void);
      +  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(void);
      -  virtual double perimeter(void);
      +  Square(double w) : width(w) { }
      +  virtual double area();
      +  virtual double perimeter();
       };
      diff --git a/Examples/guile/constants/Makefile b/Examples/guile/constants/Makefile
      index d8a3cfebd..d3f58ebdc 100644
      --- a/Examples/guile/constants/Makefile
      +++ b/Examples/guile/constants/Makefile
      @@ -1,15 +1,15 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = my-guile
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
      diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile
      index a32210e65..53638c867 100644
      --- a/Examples/guile/matrix/Makefile
      +++ b/Examples/guile/matrix/Makefile
      @@ -5,11 +5,11 @@ TARGET     = matrix
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_augmented_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_augmented_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-lm' guile_augmented
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
      diff --git a/Examples/guile/matrix/runme.scm b/Examples/guile/matrix/runme.scm
      old mode 100755
      new mode 100644
      diff --git a/Examples/guile/multimap/Makefile b/Examples/guile/multimap/Makefile
      index 4ca82a3d3..b8f5e9b5a 100644
      --- a/Examples/guile/multimap/Makefile
      +++ b/Examples/guile/multimap/Makefile
      @@ -5,15 +5,15 @@ TARGET     = example
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile guile_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
      diff --git a/Examples/guile/multivalue/Makefile b/Examples/guile/multivalue/Makefile
      index 4ca82a3d3..b8f5e9b5a 100644
      --- a/Examples/guile/multivalue/Makefile
      +++ b/Examples/guile/multivalue/Makefile
      @@ -5,15 +5,15 @@ TARGET     = example
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile guile_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
      diff --git a/Examples/guile/port/Makefile b/Examples/guile/port/Makefile
      index d6ec0ac24..95a3a479f 100644
      --- a/Examples/guile/port/Makefile
      +++ b/Examples/guile/port/Makefile
      @@ -5,12 +5,12 @@ TARGET     = port
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
       	rm -f test.out
      diff --git a/Examples/guile/simple/Makefile b/Examples/guile/simple/Makefile
      index da4eb9015..517e41c64 100644
      --- a/Examples/guile/simple/Makefile
      +++ b/Examples/guile/simple/Makefile
      @@ -5,11 +5,11 @@ TARGET     = my-guile
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
      diff --git a/Examples/guile/std_vector/Makefile b/Examples/guile/std_vector/Makefile
      index fd7a8439a..d7f5de217 100644
      --- a/Examples/guile/std_vector/Makefile
      +++ b/Examples/guile/std_vector/Makefile
      @@ -5,15 +5,15 @@ TARGET     = example
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile guile_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
      diff --git a/Examples/java/callback/Makefile b/Examples/java/callback/Makefile
      index 8f274e7cb..13cfd1708 100644
      --- a/Examples/java/callback/Makefile
      +++ b/Examples/java/callback/Makefile
      @@ -7,12 +7,12 @@ SWIGOPT    =
       JAVASRCS   = *.java
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile java_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp
      -	$(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile java_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean
      diff --git a/Examples/java/check.list b/Examples/java/check.list
      index 9728342f2..825d04a6d 100644
      --- a/Examples/java/check.list
      +++ b/Examples/java/check.list
      @@ -7,6 +7,7 @@ extend
       funcptr
       multimap
       native
      +nested
       pointer
       reference
       simple
      diff --git a/Examples/java/class/Makefile b/Examples/java/class/Makefile
      index 8f274e7cb..13cfd1708 100644
      --- a/Examples/java/class/Makefile
      +++ b/Examples/java/class/Makefile
      @@ -7,12 +7,12 @@ SWIGOPT    =
       JAVASRCS   = *.java
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile java_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp
      -	$(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile java_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean
      diff --git a/Examples/java/class/example.cxx b/Examples/java/class/example.cxx
      index 1e8e203dd..046304519 100644
      --- a/Examples/java/class/example.cxx
      +++ b/Examples/java/class/example.cxx
      @@ -1,4 +1,4 @@
      -/* File : example.c */
      +/* File : example.cxx */
       
       #include "example.h"
       #define M_PI 3.14159265358979323846
      @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
       
       int Shape::nshapes = 0;
       
      -double Circle::area(void) {
      +double Circle::area() {
         return M_PI*radius*radius;
       }
       
      -double Circle::perimeter(void) {
      +double Circle::perimeter() {
         return 2*M_PI*radius;
       }
       
      -double Square::area(void) {
      +double Square::area() {
         return width*width;
       }
       
      -double Square::perimeter(void) {
      +double Square::perimeter() {
         return 4*width;
       }
      diff --git a/Examples/java/class/example.h b/Examples/java/class/example.h
      index 46d901361..0dff185b2 100644
      --- a/Examples/java/class/example.h
      +++ b/Examples/java/class/example.h
      @@ -7,11 +7,11 @@ public:
         }
         virtual ~Shape() {
           nshapes--;
      -  };
      -  double  x, y;   
      +  }
      +  double  x, y;
         void    move(double dx, double dy);
      -  virtual double area(void) = 0;
      -  virtual double perimeter(void) = 0;
      +  virtual double area() = 0;
      +  virtual double perimeter() = 0;
         static  int nshapes;
       };
       
      @@ -19,21 +19,16 @@ class Circle : public Shape {
       private:
         double radius;
       public:
      -  Circle(double r) : radius(r) { };
      -  virtual double area(void);
      -  virtual double perimeter(void);
      +  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(void);
      -  virtual double perimeter(void);
      +  Square(double w) : width(w) { }
      +  virtual double area();
      +  virtual double perimeter();
       };
      -
      -
      -
      -
      -  
      diff --git a/Examples/java/class/example.i b/Examples/java/class/example.i
      index 75700b305..fbdf7249f 100644
      --- a/Examples/java/class/example.i
      +++ b/Examples/java/class/example.i
      @@ -7,4 +7,3 @@
       
       /* Let's just grab the original header file here */
       %include "example.h"
      -
      diff --git a/Examples/java/class/index.html b/Examples/java/class/index.html
      index cf9130c62..b0a5e221d 100644
      --- a/Examples/java/class/index.html
      +++ b/Examples/java/class/index.html
      @@ -32,8 +32,8 @@ public:
         }
         virtual ~Shape() {
           nshapes--;
      -  };
      -  double  x, y;   
      +  }
      +  double  x, y;
         void    move(double dx, double dy);
         virtual double area() = 0;
         virtual double perimeter() = 0;
      @@ -44,7 +44,7 @@ class Circle : public Shape {
       private:
         double radius;
       public:
      -  Circle(double r) : radius(r) { };
      +  Circle(double r) : radius(r) { }
         virtual double area();
         virtual double perimeter();
       };
      @@ -53,7 +53,7 @@ class Square : public Shape {
       private:
         double width;
       public:
      -  Square(double w) : width(w) { };
      +  Square(double w) : width(w) { }
         virtual double area();
         virtual double perimeter();
       };
      @@ -146,50 +146,15 @@ Shape.setNshapes(13);       // Set a static data member
       
       
      • This high-level interface using proxy classes is not the only way to handle C++ code. -A low level interface using c functions to access member variables and member functions is the alternative SWIG -approach. This entails passing around the c pointer or c++ 'this' pointer and as such it is not difficult to crash the JVM. +A low level interface using C functions to access member variables and member functions is the alternative SWIG +approach. This entails passing around the C pointer or C++ 'this' pointer and as such it is not difficult to crash the JVM. The abstraction of the underlying pointer by the java proxy classes far better fits the java programming paradigm.

        -

      • SWIG *does* know how to properly perform upcasting of objects in an inheritance +
      • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). However Java classes can only derive from one base class so multiple inheritance is not implemented. Java classes can implement more than one interface so there is scope for improvement in the future. -

        -

      • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

        -

          -
        • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
          -
          -void foo(int a);  
          -%name(foo2) void foo(double a, double b);
          -
          -
          - -

          -

        • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
          -
          -%inline %{
          -    Vector *vector_add(Vector *a, Vector *b) {
          -          ... whatever ...
          -    }
          -%}
          -
          -
          - -

          -

        • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). - -

      diff --git a/Examples/java/constants/Makefile b/Examples/java/constants/Makefile index 97c5b673c..637ce0ead 100644 --- a/Examples/java/constants/Makefile +++ b/Examples/java/constants/Makefile @@ -1,18 +1,18 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/enum/Makefile b/Examples/java/enum/Makefile index 8f274e7cb..13cfd1708 100644 --- a/Examples/java/enum/Makefile +++ b/Examples/java/enum/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/extend/Makefile b/Examples/java/extend/Makefile index 8f274e7cb..13cfd1708 100644 --- a/Examples/java/extend/Makefile +++ b/Examples/java/extend/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/extend/example.h b/Examples/java/extend/example.h index b27ab9711..ca1aed28f 100644 --- a/Examples/java/extend/example.h +++ b/Examples/java/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/java/funcptr/Makefile b/Examples/java/funcptr/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/funcptr/Makefile +++ b/Examples/java/funcptr/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/multimap/Makefile b/Examples/java/multimap/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/multimap/Makefile +++ b/Examples/java/multimap/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/native/Makefile b/Examples/java/native/Makefile index 29d5a082a..fa67e48a4 100644 --- a/Examples/java/native/Makefile +++ b/Examples/java/native/Makefile @@ -1,18 +1,18 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/nested/Makefile b/Examples/java/nested/Makefile new file mode 100644 index 000000000..13cfd1708 --- /dev/null +++ b/Examples/java/nested/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = +JAVASRCS = *.java + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/nested/example.cxx b/Examples/java/nested/example.cxx new file mode 100644 index 000000000..03bb74d9e --- /dev/null +++ b/Examples/java/nested/example.cxx @@ -0,0 +1,62 @@ +#include "example.h" + +int MotorCar::DesignOpinion::AceDesignCount = 0; +int MotorCar::DesignOpinion::TotalDesignCount = 0; + +int MotorCar::DesignOpinion::PercentScore() { + return AceDesignCount*100/TotalDesignCount; +} + +MotorCar::Wheels::Wheels(Shape shape, size_t count) : shape(shape), count(count) {} + +MotorCar::WindScreen::WindScreen(bool opaque) : opaque(opaque) {} + +MotorCar::MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) : name(name), wheels(wheels), windscreen(windscreen) {} + +MotorCar MotorCar::DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) { + MotorCar car = MotorCar(name, wheels, windscreen); + DesignOpinion::TotalDesignCount++; + if (car.wheels.Opinion().itrocks && car.windscreen.Opinion().itrocks) + DesignOpinion::AceDesignCount++; + return car; +} + +MotorCar::DesignOpinion MotorCar::Wheels::Opinion() { + DesignOpinion opinion; + opinion.itrocks = true; + if (shape == Square) { + opinion.itrocks = false; + opinion.reason = "you'll have a few issues with wheel rotation"; + } + if (count <= 2) { + opinion.reason += opinion.itrocks ? "" : " and "; + opinion.itrocks = false; + opinion.reason += "a few more wheels are needed for stability"; + } + if (opinion.itrocks) + opinion.reason = "your choice of wheels was top notch"; + + return opinion; +} + +MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() { + DesignOpinion opinion; + opinion.itrocks = !opaque; + opinion.reason = opinion.itrocks ? "the driver will have a commanding view out the window" : "you can't see out the windscreen"; + return opinion; +} + +std::string MotorCar::WillItWork() { + DesignOpinion wh = wheels.Opinion(); + DesignOpinion ws = windscreen.Opinion(); + std::string willit; + if (wh.itrocks && ws.itrocks) { + willit = "Great car design because " + wh.reason + " and " + ws.reason; + } else { + willit = "You need a rethink because "; + willit += wh.itrocks ? "" : wh.reason; + willit += (!wh.itrocks && !ws.itrocks) ? " and " : ""; + willit += ws.itrocks ? "" : ws.reason; + } + return willit; +} diff --git a/Examples/java/nested/example.dsp b/Examples/java/nested/example.dsp new file mode 100644 index 000000000..f52544b95 --- /dev/null +++ b/Examples/java/nested/example.dsp @@ -0,0 +1,162 @@ +# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=example - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "example.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "example - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /out:"example.dll" /pdbtype:sept +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Desc=Java compile post-build step +PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java +# End Special Build Tool + +!ELSEIF "$(CFG)" == "example - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386 /out:"example.dll" +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Desc=Java compile post-build step +PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java +# End Special Build Tool + +!ENDIF + +# Begin Target + +# Name "example - Win32 Debug" +# Name "example - Win32 Release" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\example.cxx +# End Source File +# Begin Source File + +SOURCE=.\example_wrap.cxx +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\example.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# Begin Source File + +SOURCE=.\example.i + +!IF "$(CFG)" == "example - Win32 Debug" + +# Begin Custom Build +InputPath=.\example.i +InputName=example + +"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + echo In order to function correctly, please ensure the following environment variables are correctly set: + echo JAVA_INCLUDE: %JAVA_INCLUDE% + echo JAVA_BIN: %JAVA_BIN% + echo on + ..\..\..\swig.exe -c++ -java "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "example - Win32 Release" + +# Begin Custom Build +InputPath=.\example.i +InputName=example + +"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + echo In order to function correctly, please ensure the following environment variables are correctly set: + echo JAVA_INCLUDE: %JAVA_INCLUDE% + echo JAVA_BIN: %JAVA_BIN% + echo on + ..\..\..\swig.exe -c++ -java "$(InputPath)" + +# End Custom Build + +!ENDIF + +# End Source File +# End Target +# End Project diff --git a/Examples/java/nested/example.h b/Examples/java/nested/example.h new file mode 100644 index 000000000..4fb107cb5 --- /dev/null +++ b/Examples/java/nested/example.h @@ -0,0 +1,48 @@ +#include + +/** Design a motor car from various components */ +struct MotorCar { + + /** Information about an opinion of the design of a car component */ + struct DesignOpinion { + bool itrocks; + std::string reason; + static int AceDesignCount; + static int TotalDesignCount; + static int PercentScore(); + }; + + /** Wheels component */ + struct Wheels { + enum Shape { Round, Square }; + Wheels(Shape shape, size_t count); + DesignOpinion Opinion(); + private: + Shape shape; + size_t count; + }; + + /** Windscreen component */ + struct WindScreen { + WindScreen(bool opaque); + DesignOpinion Opinion(); + private: + bool opaque; + }; + + /** Factory method for creating a car */ + static MotorCar DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + + std::string Name() { + return name; + } + + /** Get an overall opinion on the car design */ + std::string WillItWork(); + +private: + MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + std::string name; + Wheels wheels; + WindScreen windscreen; +}; diff --git a/Examples/java/nested/example.i b/Examples/java/nested/example.i new file mode 100644 index 000000000..c07c1521a --- /dev/null +++ b/Examples/java/nested/example.i @@ -0,0 +1,13 @@ +%module example + +// This example shows how wrappers for numerous aspects of C++ nested classes work: +// Nested static and instance variables and methods and nested enums + +%include + +%{ +#include "example.h" +%} + +%include "example.h" + diff --git a/Examples/java/nested/runme.java b/Examples/java/nested/runme.java new file mode 100644 index 000000000..855dbea91 --- /dev/null +++ b/Examples/java/nested/runme.java @@ -0,0 +1,32 @@ +// This example illustrates wrapping of nested C++ classes + +public class runme { + static { + try { + System.loadLibrary("example"); + } 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[]) + { + MotorCar car1 = MotorCar.DesignFromComponents("Bumpy", new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 4), new MotorCar.WindScreen(false)); + MotorCar car2 = MotorCar.DesignFromComponents("Wobbly", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 2), new MotorCar.WindScreen(false)); + MotorCar car3 = MotorCar.DesignFromComponents("Batty", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(true)); + MotorCar car4 = MotorCar.DesignFromComponents("Spiffing", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(false)); + + System.out.println("Expert opinion on " + car1.Name() + " : \n " + car1.WillItWork()); + System.out.println("Expert opinion on " + car2.Name() + " : \n " + car2.WillItWork()); + System.out.println("Expert opinion on " + car3.Name() + " : \n " + car3.WillItWork()); + System.out.println("Expert opinion on " + car4.Name() + " : \n " + car4.WillItWork()); + + int count = MotorCar.DesignOpinion.getAceDesignCount(); + int total = MotorCar.DesignOpinion.getTotalDesignCount(); + int percent = MotorCar.DesignOpinion.PercentScore(); + System.out.println("Overall opinion rating on car design is " + count + "/" + total + " = " + percent + "%"); + + System.out.println("Single square wheel thoughts: " + new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 1).Opinion().getReason()); + } +} diff --git a/Examples/java/pointer/Makefile b/Examples/java/pointer/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/pointer/Makefile +++ b/Examples/java/pointer/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/reference/Makefile b/Examples/java/reference/Makefile index 8f274e7cb..13cfd1708 100644 --- a/Examples/java/reference/Makefile +++ b/Examples/java/reference/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/reference/example.cxx b/Examples/java/reference/example.cxx index 8a513bf49..9dbaed2ee 100644 --- a/Examples/java/reference/example.cxx +++ b/Examples/java/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/java/simple/Makefile b/Examples/java/simple/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/simple/Makefile +++ b/Examples/java/simple/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/template/Makefile b/Examples/java/template/Makefile index 97c5b673c..637ce0ead 100644 --- a/Examples/java/template/Makefile +++ b/Examples/java/template/Makefile @@ -1,18 +1,18 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/template/index.html b/Examples/java/template/index.html index f4408e568..31dba6d8e 100644 --- a/Examples/java/template/index.html +++ b/Examples/java/template/index.html @@ -16,7 +16,7 @@ This example illustrates how C++ templates can be used from Java using SWIG.

      The C++ Code

      -Lets take a templated function and a templated class as follows: +Let's take a templated function and a templated class as follows:
      diff --git a/Examples/java/typemap/Makefile b/Examples/java/typemap/Makefile
      index 29d5a082a..fa67e48a4 100644
      --- a/Examples/java/typemap/Makefile
      +++ b/Examples/java/typemap/Makefile
      @@ -1,18 +1,18 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       SWIGOPT    =
       JAVASRCS   = *.java
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile java_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java
      -	$(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile java_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean
      diff --git a/Examples/java/variables/Makefile b/Examples/java/variables/Makefile
      index e9e29f3a3..c0b1927ca 100644
      --- a/Examples/java/variables/Makefile
      +++ b/Examples/java/variables/Makefile
      @@ -7,12 +7,12 @@ SWIGOPT    =
       JAVASRCS   = *.java
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile java_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java
      -	$(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile java_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean
      diff --git a/Examples/java/variables/example.c b/Examples/java/variables/example.c
      index aa4ffe9b3..85685fe72 100644
      --- a/Examples/java/variables/example.c
      +++ b/Examples/java/variables/example.c
      @@ -51,10 +51,10 @@ void print_vars() {
         printf("dvar      = %g\n", dvar);
         printf("cvar      = %c\n", cvar);
         printf("strvar    = %s\n", strvar ? strvar : "(null)");
      -  printf("cstrvar   = %s\n", cstrvar ? cstrvar : "(null)");
      -  printf("iptrvar   = %p\n", iptrvar);
      +  printf("cstrvar   = %s\n", cstrvar);
      +  printf("iptrvar   = %p\n", (void *)iptrvar);
         printf("name      = %s\n", name);
      -  printf("ptptr     = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
      +  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);
       }
      diff --git a/Examples/javascript/check.list b/Examples/javascript/check.list
      new file mode 100644
      index 000000000..9707e77d4
      --- /dev/null
      +++ b/Examples/javascript/check.list
      @@ -0,0 +1,13 @@
      +class
      +constant
      +enum
      +exception
      +functor
      +nspace
      +operator
      +overload
      +pointer
      +#reference
      +simple
      +template
      +variables
      diff --git a/Examples/javascript/class/Makefile b/Examples/javascript/class/Makefile
      new file mode 100644
      index 000000000..54a8f7b03
      --- /dev/null
      +++ b/Examples/javascript/class/Makefile
      @@ -0,0 +1,3 @@
      +SRCS = example.cxx
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/class/binding.gyp.in b/Examples/javascript/class/binding.gyp.in
      new file mode 100644
      index 000000000..cb2b45e8f
      --- /dev/null
      +++ b/Examples/javascript/class/binding.gyp.in
      @@ -0,0 +1,9 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ "
      +
      +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/javascript/enum/example.h b/Examples/javascript/enum/example.h
      new file mode 100644
      index 000000000..9119cd9fc
      --- /dev/null
      +++ b/Examples/javascript/enum/example.h
      @@ -0,0 +1,13 @@
      +/* File : example.h */
      +
      +enum color { RED, BLUE, GREEN };
      +
      +class Foo {
      + public:
      +  Foo() { }
      +  enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 };
      +  void enum_test(speed s);
      +};
      +
      +void enum_test(color c, Foo::speed s);
      +
      diff --git a/Examples/javascript/enum/example.i b/Examples/javascript/enum/example.i
      new file mode 100644
      index 000000000..23ee8a822
      --- /dev/null
      +++ b/Examples/javascript/enum/example.i
      @@ -0,0 +1,11 @@
      +/* File : example.i */
      +%module example
      +
      +%{
      +#include "example.h"
      +%}
      +
      +/* Let's just grab the original header file here */
      +
      +%include "example.h"
      +
      diff --git a/Examples/javascript/enum/example.js b/Examples/javascript/enum/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/enum/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/enum/runme.js b/Examples/javascript/enum/runme.js
      new file mode 100644
      index 000000000..851d43c4b
      --- /dev/null
      +++ b/Examples/javascript/enum/runme.js
      @@ -0,0 +1,34 @@
      +var example = require("example");
      +
      +// ----- Object creation -----
      +
      +// Print out the value of some enums
      +console.log("*** color ***");
      +console.log("    RED    =" + example.RED);
      +console.log("    BLUE   =" + example.BLUE);
      +console.log("    GREEN  =" + example.GREEN);
      +
      +console.log("\n*** Foo::speed ***");
      +console.log("    Foo_IMPULSE   =" + example.Foo.IMPULSE);
      +console.log("    Foo_WARP      =" + example.Foo.WARP);
      +console.log("    Foo_LUDICROUS =" + example.Foo.LUDICROUS);
      +
      +console.log("\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.GREEN, example.Foo.LUDICROUS);
      +example.enum_test(1234,5678);
      +
      +console.log("\nTesting use of enum with class method");
      +f = new example.Foo();
      +
      +f.enum_test(example.Foo.IMPULSE);
      +f.enum_test(example.Foo.WARP);
      +f.enum_test(example.Foo.LUDICROUS);
      +
      +// enum value BLUE of enum color is accessed as property of cconst
      +console.log("example.BLUE= " + example.BLUE);
      +
      +// enum value LUDICROUS of enum Foo::speed is accessed as as property of cconst
      +console.log("example.speed.LUDICROUS= " + example.Foo.LUDICROUS); 
      diff --git a/Examples/javascript/example.mk b/Examples/javascript/example.mk
      new file mode 100644
      index 000000000..5a335bba4
      --- /dev/null
      +++ b/Examples/javascript/example.mk
      @@ -0,0 +1,27 @@
      +# Note: as a convention an example must be in a child directory of this.
      +# These paths are relative to such an example directory
      +
      +ifneq (, $(ENGINE))
      +	JSENGINE=$(ENGINE)
      +else
      +	JSENGINE=node
      +endif
      +
      +EXAMPLES_TOP=../..
      +SWIG_TOP=../../..
      +SWIG = $(SWIG_TOP)/preinst-swig
      +TARGET = example
      +INTERFACE = example.i
      +SWIGOPT=-$(JSENGINE)
      +
      +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)' \
      +	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
      +	$(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' JSENGINE='$(JSENGINE)' javascript_build_cpp
      +
      +clean:
      +	$(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' javascript_clean
      diff --git a/Examples/javascript/exception/Makefile b/Examples/javascript/exception/Makefile
      new file mode 100644
      index 000000000..54a8f7b03
      --- /dev/null
      +++ b/Examples/javascript/exception/Makefile
      @@ -0,0 +1,3 @@
      +SRCS = example.cxx
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/exception/binding.gyp.in b/Examples/javascript/exception/binding.gyp.in
      new file mode 100644
      index 000000000..2e97d9757
      --- /dev/null
      +++ b/Examples/javascript/exception/binding.gyp.in
      @@ -0,0 +1,30 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ "
      +#ifndef SWIG
      +struct A {
      +};
      +#endif
      +
      +class Exc {
      +public:
      +  Exc(int c, const char *m) {
      +    code = c;
      +    strncpy(msg,m,256);
      +  }
      +  int code;
      +  char msg[256];
      +};
      +
      +#if defined(_MSC_VER)
      +  #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
      +#endif
      +
      +class Test {
      +public:
      +  int simple() throw(int) {
      +      throw(37);
      +      return 1;
      +  }
      +  int message() throw(const char *) {
      +      throw("I died.");
      +      return 1;
      +  }
      +  int hosed() throw(Exc) {
      +      throw(Exc(42,"Hosed"));
      +      return 1;
      +  } 
      +  int unknown() throw(A*) {
      +      static A a;
      +      throw &a;
      +      return 1;
      +  }
      +  int multi(int x) throw(int, const char *, Exc) {
      +     if (x == 1) throw(37);
      +     if (x == 2) throw("Bleah!");
      +     if (x == 3) throw(Exc(42,"No-go-diggy-die"));
      +     return 1;
      +  }
      +};
      +
      +#if defined(_MSC_VER)
      +  #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
      +#endif
      +
      diff --git a/Examples/javascript/exception/example.i b/Examples/javascript/exception/example.i
      new file mode 100644
      index 000000000..08672c3a8
      --- /dev/null
      +++ b/Examples/javascript/exception/example.i
      @@ -0,0 +1,12 @@
      +/* File : example.i */
      +%module example
      +
      +%{
      +#include "example.h"
      +%}
      +
      +%include "std_string.i"
      +
      +/* Let's just grab the original header file here */
      +%include "example.h"
      +
      diff --git a/Examples/javascript/exception/example.js b/Examples/javascript/exception/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/exception/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/exception/runme.js b/Examples/javascript/exception/runme.js
      new file mode 100644
      index 000000000..43ce66d6d
      --- /dev/null
      +++ b/Examples/javascript/exception/runme.js
      @@ -0,0 +1,64 @@
      +var example = require("example");
      +
      +console.log("Trying to catch some exceptions.");
      +t = new example.Test();
      +try{
      +  t.unknown();
      +  throw -1;
      +} catch(error)
      +{
      +  if(error == -1) {
      +    console.log("t.unknown() didn't throw");
      +  } else {
      +    console.log("successfully catched throw in Test::unknown().");
      +  }
      +}
      +
      +try{
      +    t.simple();
      +    throw -1;
      +}
      +catch(error){
      +  if(error == -1) {
      +    console.log("t.simple() did not throw");
      +  } else {
      +    console.log("successfully catched throw in Test::simple().");
      +  }
      +}
      +
      +try{
      +  t.message();
      +  throw -1;
      +} catch(error){
      +  if(error == -1) {
      +    console.log("t.message() did not throw");
      +  } else {
      +    console.log("successfully catched throw in Test::message().");
      +  }
      +}
      +    
      +try{
      +  t.hosed();
      +  throw -1;
      +}
      +catch(error){ 
      +  if(error == -1) {
      +    console.log("t.hosed() did not throw");
      +  } else {
      +    console.log("successfully catched throw in Test::hosed().");
      +  }
      +}
      +
      +for (var i=1; i<4; i++) {
      +  try{
      +      t.multi(i);
      +      throw -1;
      +  }
      +  catch(error){
      +    if(error == -1) {
      +      console.log("t.multi(" + i + ") did not throw");
      +    } else {
      +      console.log("successfully catched throw in Test::multi().");
      +    }
      +  }
      +}    
      diff --git a/Examples/javascript/functor/Makefile b/Examples/javascript/functor/Makefile
      new file mode 100644
      index 000000000..0402f8d09
      --- /dev/null
      +++ b/Examples/javascript/functor/Makefile
      @@ -0,0 +1,3 @@
      +SRCS =
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/functor/binding.gyp.in b/Examples/javascript/functor/binding.gyp.in
      new file mode 100644
      index 000000000..59779aef4
      --- /dev/null
      +++ b/Examples/javascript/functor/binding.gyp.in
      @@ -0,0 +1,9 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ "example_wrap.cxx" ],
      +      "include_dirs": ["$srcdir"]
      +    }
      +  ]
      +}
      diff --git a/Examples/javascript/functor/example.i b/Examples/javascript/functor/example.i
      new file mode 100644
      index 000000000..0450c2124
      --- /dev/null
      +++ b/Examples/javascript/functor/example.i
      @@ -0,0 +1,25 @@
      +/* File : example.i */
      +%module example
      +
      +
      +%inline %{
      +// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
      +template class Sum {
      +   T res;
      +public:
      +   Sum(T i = 0) : res(i) { }
      +   void operator() (T x) { res += x; }
      +   T result() const { return res; }
      +};
      +
      +%}
      +
      +%rename(call)	*::operator();	// the fn call operator
      +
      +// Instantiate a few versions
      +%template(intSum) Sum;
      +%template(doubleSum) Sum;
      +
      +
      +
      +
      diff --git a/Examples/javascript/functor/example.js b/Examples/javascript/functor/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/functor/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/functor/runme.js b/Examples/javascript/functor/runme.js
      new file mode 100644
      index 000000000..28dc64320
      --- /dev/null
      +++ b/Examples/javascript/functor/runme.js
      @@ -0,0 +1,15 @@
      +var example = require("example");
      +
      +a = new example.intSum(0);
      +b = new example.doubleSum(100.0);
      +
      +// Use the objects.  They should be callable just like a normal
      +// javascript function.
      +
      +for (i=1;i<=100;i++) 
      +    a.call(i);                // Note: function call
      +    b.call(Math.sqrt(i));     // Note: function call
      +
      +console.log(a.result());
      +console.log(b.result());
      +
      diff --git a/Examples/javascript/nspace/Makefile b/Examples/javascript/nspace/Makefile
      new file mode 100644
      index 000000000..0402f8d09
      --- /dev/null
      +++ b/Examples/javascript/nspace/Makefile
      @@ -0,0 +1,3 @@
      +SRCS =
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/nspace/binding.gyp.in b/Examples/javascript/nspace/binding.gyp.in
      new file mode 100644
      index 000000000..59779aef4
      --- /dev/null
      +++ b/Examples/javascript/nspace/binding.gyp.in
      @@ -0,0 +1,9 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ "example_wrap.cxx" ],
      +      "include_dirs": ["$srcdir"]
      +    }
      +  ]
      +}
      diff --git a/Examples/javascript/nspace/example.h b/Examples/javascript/nspace/example.h
      new file mode 100644
      index 000000000..53066980a
      --- /dev/null
      +++ b/Examples/javascript/nspace/example.h
      @@ -0,0 +1,23 @@
      +#ifndef _example_guardian_
      +#define _example_guardian_
      +
      +int module_function() { return 7; }
      +int module_variable = 9;
      +
      +namespace MyWorld {
      +  class World {
      +  public:
      +    World() : world_max_count(9) {}
      +    int create_world() { return 17; }
      +    const int world_max_count; // = 9
      +  };
      +  namespace Nested {
      +    class Dweller {
      +      public:
      +        enum Gender { MALE = 0, FEMALE = 1 };
      +        static int count() { return 19; }
      +    };
      +  }
      +}
      +
      +#endif
      diff --git a/Examples/javascript/nspace/example.i b/Examples/javascript/nspace/example.i
      new file mode 100644
      index 000000000..c30f87fec
      --- /dev/null
      +++ b/Examples/javascript/nspace/example.i
      @@ -0,0 +1,10 @@
      +%module example
      +
      +%{
      +#include "example.h"
      +%}
      +
      +%nspace MyWorld::Nested::Dweller;
      +%nspace MyWorld::World;
      +
      +%include "example.h"
      diff --git a/Examples/javascript/nspace/example.js b/Examples/javascript/nspace/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/nspace/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/nspace/runme.js b/Examples/javascript/nspace/runme.js
      new file mode 100644
      index 000000000..fad73477d
      --- /dev/null
      +++ b/Examples/javascript/nspace/runme.js
      @@ -0,0 +1,50 @@
      +// File: runme.js
      +
      +// This file illustrates class C++ interface generated
      +// by SWIG.
      +
      +var example = require("example");
      +
      +// Calling a module function ( aka global function )
      +if (example.module_function() !== 7) {
      +  throw new Error("example.module_function() should equal 7");
      +}
      +console.log("example.module_function(): " + example.module_function());
      +
      +// Accessing a module (aka global) variable
      +if (example.module_variable !== 9) {
      +  throw new Error("example.module_variable should equal 9");
      +}
      +console.log("example.module_variable: " + example.module_variable);
      +
      +// Creating an instance of the class
      +var w1 = new example.MyWorld.World();
      +console.log("Creating class instance: w1 = new example.MyWorld.World(): " + w1);
      +
      +// Accessing class members
      +if (w1.create_world() !== 17) {
      +  throw new Error("w1.create_world() should equal 17");
      +}
      +console.log("w1.create_world() = " + w1.create_world());
      +
      +if (w1.world_max_count !== 9) {
      +  throw new Error("w1.world_max_count should equal 9");
      +}
      +console.log("w1.world_max_count = " + w1.world_max_count);
      +
      +// Accessing enums from class within namespace
      +if (example.MyWorld.Nested.Dweller.MALE !== 0) {
      +  throw new Error("example.MyWorld.Nested.Dweller.MALE should equal 0");
      +}
      +console.log("Accessing enums: ex.MyWorld.Nested.Dweller.MALE = " + example.MyWorld.Nested.Dweller.MALE);
      +
      +if (example.MyWorld.Nested.Dweller.FEMALE !== 1) {
      +  throw new Error("example.MyWorld.Nested.Dweller.FEMALE should equal 1");
      +}
      +console.log("Accessing enums: ex.MyWorld.Nested.Dweller.FEMALE = " + example.MyWorld.Nested.Dweller.FEMALE);
      +
      +// Accessing static member function
      +if (example.MyWorld.Nested.Dweller.count() !== 19) {
      +  throw new Error("example.MyWorld.Nested.Dweller.count() should equal 19");
      +}
      +console.log("Accessing static member function: ex.MyWorld.Nested.Dweller.count() = " + example.MyWorld.Nested.Dweller.count());
      diff --git a/Examples/javascript/operator/Makefile b/Examples/javascript/operator/Makefile
      new file mode 100644
      index 000000000..0402f8d09
      --- /dev/null
      +++ b/Examples/javascript/operator/Makefile
      @@ -0,0 +1,3 @@
      +SRCS =
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/operator/binding.gyp.in b/Examples/javascript/operator/binding.gyp.in
      new file mode 100644
      index 000000000..59779aef4
      --- /dev/null
      +++ b/Examples/javascript/operator/binding.gyp.in
      @@ -0,0 +1,9 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ "example_wrap.cxx" ],
      +      "include_dirs": ["$srcdir"]
      +    }
      +  ]
      +}
      diff --git a/Examples/javascript/operator/example.h b/Examples/javascript/operator/example.h
      new file mode 100644
      index 000000000..4da6a2307
      --- /dev/null
      +++ b/Examples/javascript/operator/example.h
      @@ -0,0 +1,36 @@
      +/* File : example.h */
      +#include 
      +
      +class Complex {
      +private:
      +  double rpart, ipart;
      +public:
      +  Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { }
      +  Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { }
      +  Complex &operator=(const Complex &c) {
      +    rpart = c.rpart;
      +    ipart = c.ipart;
      +    return *this;
      +  }
      +  Complex operator+(const Complex &c) const {
      +    return Complex(rpart+c.rpart, ipart+c.ipart);
      +  }
      +  Complex operator-(const Complex &c) const {
      +    return Complex(rpart-c.rpart, ipart-c.ipart);
      +  }
      +  Complex operator*(const Complex &c) const {
      +    return Complex(rpart*c.rpart - ipart*c.ipart,
      +		   rpart*c.ipart + c.rpart*ipart);
      +  }
      +  Complex operator-() const {
      +    return Complex(-rpart, -ipart);
      +  }
      +  
      +  double re() const { return rpart; }
      +  double im() const { return ipart; }
      +};
      +
      +
      +
      +
      +  
      diff --git a/Examples/javascript/operator/example.i b/Examples/javascript/operator/example.i
      new file mode 100644
      index 000000000..7a1bd45e1
      --- /dev/null
      +++ b/Examples/javascript/operator/example.i
      @@ -0,0 +1,34 @@
      +/* File : example.i */
      +%module example
      +#pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ
      +%{
      +#include "example.h"
      +%}
      +
      +/* This header file is a little tough to handle because it has overloaded
      +   operators and constructors.  We're going to try and deal with that here */
      +
      +/* This turns the copy constructor in a function ComplexCopy() that can
      +   be called */
      +
      +%rename(assign) Complex::operator=;
      +%rename(plus) Complex::operator+;
      +%rename(minus) Complex::operator-(const Complex &) const;
      +%rename(uminus) Complex::operator-() const;
      +%rename(times) Complex::operator*;
      +
      +/* Now grab the original header file */
      +%include "example.h"
      +
      +/* An output method that turns a complex into a short string */
      +%extend Complex {
      + char *toString() {
      +   static char temp[512];
      +   sprintf(temp,"(%g,%g)", $self->re(), $self->im());
      +   return temp;
      + }
      + static Complex* copy(const Complex& c) {
      +   return new Complex(c);
      + }
      +};
      +
      diff --git a/Examples/javascript/operator/example.js b/Examples/javascript/operator/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/operator/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/operator/runme.js b/Examples/javascript/operator/runme.js
      new file mode 100644
      index 000000000..f72ca1c28
      --- /dev/null
      +++ b/Examples/javascript/operator/runme.js
      @@ -0,0 +1,25 @@
      +var example = require("example");
      +
      +a = new example.Complex(2,3);
      +b = new example.Complex(-5,10);
      +
      +console.log ("a =" + a);
      +console.log ("b   =" + b);
      +
      +c = a.plus(b);
      +
      +console.log("c   =" + c);
      +console.log("a*b =" + a.times(b));
      +console.log("a-c =" + a.minus(c));
      +
      +e = example.Complex.copy(a.minus(c));
      +console.log("e   =" + e);
      +
      +// Big expression
      +f = a.plus(b).times(c.plus(b.times(e))).plus(a.uminus());
      +console.log("f   =" + f);
      +
      +
      +
      +
      +
      diff --git a/Examples/javascript/overload/Makefile b/Examples/javascript/overload/Makefile
      new file mode 100644
      index 000000000..0402f8d09
      --- /dev/null
      +++ b/Examples/javascript/overload/Makefile
      @@ -0,0 +1,3 @@
      +SRCS =
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/overload/binding.gyp.in b/Examples/javascript/overload/binding.gyp.in
      new file mode 100644
      index 000000000..59779aef4
      --- /dev/null
      +++ b/Examples/javascript/overload/binding.gyp.in
      @@ -0,0 +1,9 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ "example_wrap.cxx" ],
      +      "include_dirs": ["$srcdir"]
      +    }
      +  ]
      +}
      diff --git a/Examples/javascript/overload/example.h b/Examples/javascript/overload/example.h
      new file mode 100644
      index 000000000..2f112f1e1
      --- /dev/null
      +++ b/Examples/javascript/overload/example.h
      @@ -0,0 +1,28 @@
      +#include 
      +
      +void f() {
      +  std::cout << "Called f()." << std::endl;
      +}
      +
      +void f(int val) {
      +  std::cout << "Called f(int)." << std::endl;
      +}
      +void f(int val1, int val2) {
      +  std::cout << "Called f(int, int)." << std::endl;
      +}
      +
      +void f(const char* s) {
      +  std::cout << "Called f(const char*)." << std::endl;
      +}
      +
      +void f(bool val) {
      +  std::cout << "Called f(bool)." << std::endl;
      +}
      +
      +void f(long val) {
      +  std::cout << "Called f(long)." << std::endl;
      +}
      +
      +void f(double val) {
      +  std::cout << "Called f(double)." << std::endl;
      +}
      diff --git a/Examples/javascript/overload/example.i b/Examples/javascript/overload/example.i
      new file mode 100644
      index 000000000..b86689f8a
      --- /dev/null
      +++ b/Examples/javascript/overload/example.i
      @@ -0,0 +1,16 @@
      +/* File : example.i */
      +%module example
      +
      +%{
      +#include "example.h"
      +%}
      +
      +/*
      +  Note: overloading is implemented in a sloppy way currently
      +        i.e., only the number of arguments is taken into conideration
      +        for dispatching.
      +        To solve the problem one has to rename such conflicting methods.
      +*/
      +%rename(f_double) f(double val);
      +
      +%include "example.h"
      diff --git a/Examples/javascript/overload/example.js b/Examples/javascript/overload/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/overload/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/overload/runme.js b/Examples/javascript/overload/runme.js
      new file mode 100644
      index 000000000..1c23e3b6b
      --- /dev/null
      +++ b/Examples/javascript/overload/runme.js
      @@ -0,0 +1,9 @@
      +var example = require("example");
      +
      +example.f();
      +example.f(1);
      +example.f(1, 2);
      +example.f("bla");
      +example.f(false);
      +example.f(11111111111);
      +example.f_double(1.0);
      diff --git a/Examples/javascript/pointer/Makefile b/Examples/javascript/pointer/Makefile
      new file mode 100644
      index 000000000..54a8f7b03
      --- /dev/null
      +++ b/Examples/javascript/pointer/Makefile
      @@ -0,0 +1,3 @@
      +SRCS = example.cxx
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/pointer/binding.gyp.in b/Examples/javascript/pointer/binding.gyp.in
      new file mode 100644
      index 000000000..cb2b45e8f
      --- /dev/null
      +++ b/Examples/javascript/pointer/binding.gyp.in
      @@ -0,0 +1,9 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ " 0) {
      +    g = x;
      +    x = y % x;
      +    y = g;
      +  }
      +  return g;
      +}
      +
      +
      diff --git a/Examples/javascript/simple/example.i b/Examples/javascript/simple/example.i
      new file mode 100644
      index 000000000..24093b9bf
      --- /dev/null
      +++ b/Examples/javascript/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/javascript/simple/example.js b/Examples/javascript/simple/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/simple/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/simple/runme.js b/Examples/javascript/simple/runme.js
      new file mode 100644
      index 000000000..4abff0e2a
      --- /dev/null
      +++ b/Examples/javascript/simple/runme.js
      @@ -0,0 +1,26 @@
      +var example = require("example");
      +
      +/* Call our gcd() function */
      +
      +x = 42;
      +y = 105;
      +g = example.gcd(x,y);
      +console.log("GCD of x and y is=" + g);
      +
      +/* Manipulate the Foo global variable */
      +
      +/* Output its current value */
      +console.log("Global variable Foo=" + example.Foo);
      +
      +/* Change its value */
      +example.Foo = 3.1415926;
      +
      +/* See if the change took effect */
      +console.log("Variable Foo changed to=" + example.Foo);
      +
      +
      +
      +
      + 
      + 
      + 
      diff --git a/Examples/javascript/template/Makefile b/Examples/javascript/template/Makefile
      new file mode 100644
      index 000000000..0402f8d09
      --- /dev/null
      +++ b/Examples/javascript/template/Makefile
      @@ -0,0 +1,3 @@
      +SRCS =
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/template/binding.gyp.in b/Examples/javascript/template/binding.gyp.in
      new file mode 100644
      index 000000000..59779aef4
      --- /dev/null
      +++ b/Examples/javascript/template/binding.gyp.in
      @@ -0,0 +1,9 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ "example_wrap.cxx" ],
      +      "include_dirs": ["$srcdir"]
      +    }
      +  ]
      +}
      diff --git a/Examples/javascript/template/example.h b/Examples/javascript/template/example.h
      new file mode 100644
      index 000000000..7401df650
      --- /dev/null
      +++ b/Examples/javascript/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/javascript/template/example.i b/Examples/javascript/template/example.i
      new file mode 100644
      index 000000000..8f94c4da1
      --- /dev/null
      +++ b/Examples/javascript/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/javascript/template/example.js b/Examples/javascript/template/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/template/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/template/runme.js b/Examples/javascript/template/runme.js
      new file mode 100644
      index 000000000..af96ac7f9
      --- /dev/null
      +++ b/Examples/javascript/template/runme.js
      @@ -0,0 +1,30 @@
      +var example = require("example");
      +
      +//Call some templated functions
      +console.log(example.maxint(3,7));
      +console.log(example.maxdouble(3.14,2.18));
      +
      +// Create some class
      +
      +iv = new example.vecint(100);
      +dv = new example.vecdouble(1000);
      +
      +for(i=0;i<=100;i++)
      +      iv.setitem(i,2*i);
      +
      +for(i=0;i<=1000;i++)
      +      dv.setitem(i, 1.0/(i+1));
      +
      +sum = 0;
      +for(i=0;i<=100;i++)
      +      sum = sum + iv.getitem(i);
      +
      +console.log(sum);
      +
      +sum = 0.0;
      +for(i=0;i<=1000;i++)
      +      sum = sum + dv.getitem(i);
      +console.log(sum);
      +
      +delete iv;
      +delete dv;
      diff --git a/Examples/javascript/variables/Makefile b/Examples/javascript/variables/Makefile
      new file mode 100644
      index 000000000..54a8f7b03
      --- /dev/null
      +++ b/Examples/javascript/variables/Makefile
      @@ -0,0 +1,3 @@
      +SRCS = example.cxx
      +
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/javascript/variables/binding.gyp.in b/Examples/javascript/variables/binding.gyp.in
      new file mode 100644
      index 000000000..cb2b45e8f
      --- /dev/null
      +++ b/Examples/javascript/variables/binding.gyp.in
      @@ -0,0 +1,9 @@
      +{
      +  "targets": [
      +    {
      +      "target_name": "example",
      +      "sources": [ "
      +#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;
      +#ifdef __cplusplus // Note: for v8 this must be linkable with g++, without extern cstrvar is mangled
      +extern const char cstrvar[] = "Goodbye";
      +#else
      +const char cstrvar[] = "Goodbye";
      +#endif
      +const 
      +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;
      +}
      +
      +/* 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/javascript/variables/example.h b/Examples/javascript/variables/example.h
      new file mode 100644
      index 000000000..0f7e89594
      --- /dev/null
      +++ b/Examples/javascript/variables/example.h
      @@ -0,0 +1,6 @@
      +/* File: example.h */
      +
      +typedef struct {
      +  int x,y;
      +} Point;
      +
      diff --git a/Examples/javascript/variables/example.i b/Examples/javascript/variables/example.i
      new file mode 100644
      index 000000000..591b871ed
      --- /dev/null
      +++ b/Examples/javascript/variables/example.i
      @@ -0,0 +1,49 @@
      +/* File : example.i */
      +%module example
      +%{
      +#include "example.h"
      +%}
      +
      +/* 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 Point *new_Point(int x, int y);
      +extern char  *Point_print(Point *p);
      +extern void  pt_print();
      +%}
      +
      diff --git a/Examples/javascript/variables/example.js b/Examples/javascript/variables/example.js
      new file mode 100644
      index 000000000..2e7f83a06
      --- /dev/null
      +++ b/Examples/javascript/variables/example.js
      @@ -0,0 +1 @@
      +module.exports = require("build/Release/example");
      diff --git a/Examples/javascript/variables/runme.js b/Examples/javascript/variables/runme.js
      new file mode 100644
      index 000000000..a2b5f791c
      --- /dev/null
      +++ b/Examples/javascript/variables/runme.js
      @@ -0,0 +1,68 @@
      +var example = require("example");
      +
      +// Try to set the values of some global variables
      +example.ivar   =  42;
      +example.svar   = -31000;
      +example.lvar   =  65537;
      +example.uivar  =  123456;
      +example.usvar  =  61000;
      +example.ulvar  =  654321;
      +example.scvar  =  -13;
      +example.ucvar  =  251;
      +example.cvar   =  "S";
      +example.fvar   =  3.14159;
      +example.dvar   =  2.1828;
      +example.strvar =  "Hello World";
      +example.iptrvar= example.new_int(37);
      +example.ptptr  = example.new_Point(37,42);
      +example.name   = "Bill";
      +
      +// Now console.log out the values of the variables
      +console.log("Variables (values printed from Javascript)");
      +console.log("ivar      = " + example.ivar);
      +console.log("svar      = " + example.svar);
      +console.log("lvar      = " + example.lvar);
      +console.log("uivar     = " + example.uivar);
      +console.log("usvar     = " + example.usvar);
      +console.log("ulvar     = " + example.ulvar);
      +console.log("scvar     = " + example.scvar);
      +console.log("ucvar     = " + example.ucvar);
      +console.log("fvar      = " + example.fvar);
      +console.log("dvar      = " + example.dvar);
      +console.log("cvar      = " + example.cvar);
      +console.log("strvar    = " + example.strvar);
      +console.log("cstrvar   = " + example.cstrvar);
      +console.log("iptrvar   = " + example.iptrvar);
      +console.log("name      = " + example.name);
      +console.log("ptptr     = " + example.ptptr + ": " + example.Point_print(example.ptptr));
      +console.log("pt        = " + example.pt + ": " + example.Point_print(example.pt));
      +
      +
      +console.log("\nVariables (values printed from C)");
      +
      +example.print_vars();
      +
      +console.log("\nNow I'm going to try and modify some read only variables");
      +
      +console.log("Tring to set 'path'");
      +try{
      +    example.path = "Whoa!";
      +    console.log("Hey, what's going on?!?! This shouldn't work");
      +}
      +catch(e){
      +    console.log("Good.");
      +}
      +
      +console.log("Trying to set 'status'");
      +try{
      +    example.status = 0;
      +    console.log("Hey, what's going on?!?! This shouldn't work");
      +} catch(e){
      +    console.log("Good.");
      +}
      +
      +console.log("\nI'm going to try and update a structure variable.");
      +example.pt = example.ptptr;
      +console.log("The new value is: ");
      +example.pt_print();
      +console.log("You should see the value: " + example.Point_print(example.ptptr));
      diff --git a/Examples/lua/arrays/Makefile b/Examples/lua/arrays/Makefile
      index d398dffea..4191f7ec3 100644
      --- a/Examples/lua/arrays/Makefile
      +++ b/Examples/lua/arrays/Makefile
      @@ -5,15 +5,15 @@ TARGET     = example
       INTERFACE  = example.i
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/arrays/example.c b/Examples/lua/arrays/example.c
      index ed23738c8..da1bd755a 100644
      --- a/Examples/lua/arrays/example.c
      +++ b/Examples/lua/arrays/example.c
      @@ -13,7 +13,7 @@ void sort_int(int* arr, int len)
         qsort(arr, len, sizeof(int), compare_int);
       }
       
      -// ditto doubles
      +/* ditto doubles */
       int compare_double(const void * a, const void * b)
       {
         return (int)( *(double*)a - *(double*)b );
      diff --git a/Examples/lua/arrays/runme.lua b/Examples/lua/arrays/runme.lua
      index 7ab6dc42b..d0aa99813 100644
      --- a/Examples/lua/arrays/runme.lua
      +++ b/Examples/lua/arrays/runme.lua
      @@ -25,7 +25,7 @@ math.randomseed(0)  -- init random
       
       
       --[[ version 1: passing a C array to the code
      -lets test call sort_int()
      +let's test call sort_int()
       this requires a C array, so is the hardest to use]]
       ARRAY_SIZE=10
       arr=example.new_int(ARRAY_SIZE)
      diff --git a/Examples/lua/check.list b/Examples/lua/check.list
      index 6862e4478..87dfdcd08 100644
      --- a/Examples/lua/check.list
      +++ b/Examples/lua/check.list
      @@ -11,6 +11,7 @@ funcptr3
       functest
       functor
       import
      +nspace
       owner
       pointer
       simple
      diff --git a/Examples/lua/class/Makefile b/Examples/lua/class/Makefile
      index c39e8acdf..96308f0df 100644
      --- a/Examples/lua/class/Makefile
      +++ b/Examples/lua/class/Makefile
      @@ -6,15 +6,15 @@ INTERFACE  = example.i
       LIBS       = -lm
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/class/example.cxx b/Examples/lua/class/example.cxx
      index 1e8e203dd..046304519 100644
      --- a/Examples/lua/class/example.cxx
      +++ b/Examples/lua/class/example.cxx
      @@ -1,4 +1,4 @@
      -/* File : example.c */
      +/* File : example.cxx */
       
       #include "example.h"
       #define M_PI 3.14159265358979323846
      @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
       
       int Shape::nshapes = 0;
       
      -double Circle::area(void) {
      +double Circle::area() {
         return M_PI*radius*radius;
       }
       
      -double Circle::perimeter(void) {
      +double Circle::perimeter() {
         return 2*M_PI*radius;
       }
       
      -double Square::area(void) {
      +double Square::area() {
         return width*width;
       }
       
      -double Square::perimeter(void) {
      +double Square::perimeter() {
         return 4*width;
       }
      diff --git a/Examples/lua/class/example.h b/Examples/lua/class/example.h
      index 46d901361..0dff185b2 100644
      --- a/Examples/lua/class/example.h
      +++ b/Examples/lua/class/example.h
      @@ -7,11 +7,11 @@ public:
         }
         virtual ~Shape() {
           nshapes--;
      -  };
      -  double  x, y;   
      +  }
      +  double  x, y;
         void    move(double dx, double dy);
      -  virtual double area(void) = 0;
      -  virtual double perimeter(void) = 0;
      +  virtual double area() = 0;
      +  virtual double perimeter() = 0;
         static  int nshapes;
       };
       
      @@ -19,21 +19,16 @@ class Circle : public Shape {
       private:
         double radius;
       public:
      -  Circle(double r) : radius(r) { };
      -  virtual double area(void);
      -  virtual double perimeter(void);
      +  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(void);
      -  virtual double perimeter(void);
      +  Square(double w) : width(w) { }
      +  virtual double area();
      +  virtual double perimeter();
       };
      -
      -
      -
      -
      -  
      diff --git a/Examples/lua/class/example.i b/Examples/lua/class/example.i
      index 75700b305..fbdf7249f 100644
      --- a/Examples/lua/class/example.i
      +++ b/Examples/lua/class/example.i
      @@ -7,4 +7,3 @@
       
       /* Let's just grab the original header file here */
       %include "example.h"
      -
      diff --git a/Examples/lua/class/runme.lua b/Examples/lua/class/runme.lua
      index 2c3ad8ced..5d140defe 100644
      --- a/Examples/lua/class/runme.lua
      +++ b/Examples/lua/class/runme.lua
      @@ -53,7 +53,6 @@ print("\nGuess I'll clean up now")
       -- Note: this invokes the virtual destructor
       c=nil
       s=nil
      -s = 3
       
       -- call gc to make sure they are collected
       collectgarbage()
      diff --git a/Examples/lua/constants/Makefile b/Examples/lua/constants/Makefile
      index 51b83be2e..ae33cb182 100644
      --- a/Examples/lua/constants/Makefile
      +++ b/Examples/lua/constants/Makefile
      @@ -1,20 +1,20 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    = 
      +CXXSRCS    =
       TARGET     = example
       INTERFACE  = example.i
      -LIBS       = 
      +LIBS       =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/dual/Makefile b/Examples/lua/dual/Makefile
      index 12ee00a68..c86152a97 100644
      --- a/Examples/lua/dual/Makefile
      +++ b/Examples/lua/dual/Makefile
      @@ -1,21 +1,21 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
       TARGET     = dual
      -CXXSRCS    = example2_wrap.cxx
      +GENCXXSRCS = example2_wrap.cxx
       INTERFACE  = dual.i
       LUA_INTERP = dual.cpp
       
       # This is a little different to normal as we need to static link two modules and a custom interpreter
       # We need the external runtime, then swig examples2, and build the module as normal
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run
       
       build:
       	$(SWIG) -lua -external-runtime
      -	$(SWIG) -c++ -lua $(SWIGOPT) example2.i
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(SWIG) -c++ -lua $(SWIGOPT) -o $(GENCXXSRCS) $(SRCDIR)example2.i
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) GENCXXSRCS='$(GENCXXSRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
       	rm -f swigluarun.h $(TARGET)
      diff --git a/Examples/lua/dual/dual.cpp b/Examples/lua/dual/dual.cpp
      index d2a9ecaa9..2108a7275 100644
      --- a/Examples/lua/dual/dual.cpp
      +++ b/Examples/lua/dual/dual.cpp
      @@ -1,7 +1,7 @@
       /*
      -dual.cpp a test for multiple modules and multiple intrepreters staticly linked together.
      +dual.cpp a test for multiple modules and multiple interpreters statically linked together.
       
      -Earlier version of lua bindings for SWIG would fail if staticly linked.
      +Earlier version of lua bindings for SWIG would fail if statically linked.
       
       What is happening is as follows:
       example.i declares a type Foo
      @@ -28,7 +28,7 @@ both Foo and Bar.
       #include 
       #include 
       
      -// the 2 libraries which are wrappered via SWIG
      +// the 2 libraries which are wrapped via SWIG
       extern "C" int luaopen_example(lua_State*L);
       extern "C" int luaopen_example2(lua_State*L);
       
      @@ -36,19 +36,23 @@ extern "C" int luaopen_example2(lua_State*L);
       #define DEBUG2(X,Y) {printf(X,Y);fflush(stdout);}
       #define DEBUG3(X,Y,Z) {printf(X,Y,Z);fflush(stdout);}
       
      +#if LUA_VERSION_NUM > 501
      +#define lua_open luaL_newstate
      +#endif
      +
       void testModule(lua_State *L)
       {
         swig_type_info *pTypeInfo=0,*pTypeInfo2=0;
         swig_module_info *pModule=0;
         pModule=SWIG_GetModule(L);
      -  DEBUG2("  SWIG_GetModule() returns %p\n",pModule)
      +  DEBUG2("  SWIG_GetModule() returns %p\n", (void *)pModule)
         if(pModule==0) return;
         pTypeInfo = SWIG_TypeQuery(L,"Foo *");
         DEBUG2("  Type (Foo*) is %s\n",pTypeInfo==0?"unknown":"known");
      -  DEBUG3("    Module %p typeinfo(Foo*) %p\n",pModule,pTypeInfo);
      +  DEBUG3("    Module %p typeinfo(Foo*) %p\n", (void *)pModule, (void *)pTypeInfo);
         pTypeInfo2 = SWIG_TypeQuery(L,"Bar *");
         DEBUG2("  Type (Bar*) is %s\n",pTypeInfo2==0?"unknown":"known");
      -  DEBUG3("    Module %p typeinfo(Bar*) %p\n",pModule,pTypeInfo2);
      +  DEBUG3("    Module %p typeinfo(Bar*) %p\n", (void *)pModule, (void *)pTypeInfo2);
       }
       
       int main(int argc,char* argv[])
      diff --git a/Examples/lua/embed/Makefile b/Examples/lua/embed/Makefile
      index df1f8fa04..5e3a91893 100644
      --- a/Examples/lua/embed/Makefile
      +++ b/Examples/lua/embed/Makefile
      @@ -4,16 +4,17 @@ TARGET     = embed
       SRCS       = example.c
       INTERFACE  = example.i
       LUA_INTERP = embed.c
      +LIBS       = -lm
       
       # this is a little different to normal as we have our own special interpreter
       # which we want to static link
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
       	rm -f $(TARGET)
      diff --git a/Examples/lua/embed/embed.c b/Examples/lua/embed/embed.c
      index 9df168f94..1f10cc8e8 100644
      --- a/Examples/lua/embed/embed.c
      +++ b/Examples/lua/embed/embed.c
      @@ -1,9 +1,9 @@
      -/* embed.c a simple test for an embeded interpreter
      +/* embed.c a simple test for an embedded interpreter
        
       The idea is that we wrapper a few simple function (example.c)
       and write our own app to call it.
        
      -What it will do is load the wrappered lib, load runme.lua and then call some functions.
      +What it will do is load the wrapped lib, load runme.lua and then call some functions.
       To make life easier, all the printf's have either [C] or [Lua] at the start
       so you can see where they are coming from.
        
      @@ -13,19 +13,24 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua
       
       #include 
       #include 
      +#include 
       
       #include 
       #include 
       #include 
       
      +#if LUA_VERSION_NUM > 501
      +#define lua_open luaL_newstate
      +#endif
      +
       /* the SWIG wrappered library */
       extern int luaopen_example(lua_State*L);
       
       /* a really simple way of calling lua from C
        just give it a lua state & a string to execute
       Unfortunately lua keeps changing its API's.
      -In lua 5.0.X its lua_dostring()
      -In lua 5.1.X its luaL_dostring()
      +In lua 5.0.X it's lua_dostring()
      +In lua 5.1.X it's luaL_dostring()
       so we have a few extra compiles
       */
       int dostring(lua_State *L, char* str) {
      @@ -54,28 +59,32 @@ int main(int argc,char* argv[]) {
         luaopen_base(L);
         luaopen_string(L);
         luaopen_math(L);
      -  printf("[C] now loading the SWIG wrappered library\n");
      +  printf("[C] now loading the SWIG wrapped library\n");
         luaopen_example(L);
         printf("[C] all looks ok\n");
         printf("\n");
      -  printf("[C] lets load the file 'runme.lua'\n");
      +  if (argc != 2 || argv[1] == NULL || strlen(argv[1]) == 0) {
      +    printf("[C] ERROR: no lua file given on command line\n");
      +    exit(3);
      +  }
      +  printf("[C] let's load the file '%s'\n", argv[1]);
         printf("[C] any lua code in this file will be executed\n");
      -  if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) {
      +  if (luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, 0, 0)) {
           printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1));
           exit(3);
         }
         printf("[C] We are now back in C, all looks ok\n");
         printf("\n");
      -  printf("[C] lets call the function 'do_tests()'\n");
      +  printf("[C] let's call the function 'do_tests()'\n");
         ok=dostring(L,"do_tests()");
         printf("[C] We are back in C, the dostring() function returned %d\n",ok);
         printf("\n");
      -  printf("[C] Lets call lua again, but create an error\n");
      +  printf("[C] Let's call lua again, but create an error\n");
         ok=dostring(L,"no_such_function()");
         printf("[C] We are back in C, the dostring() function returned %d\n",ok);
         printf("[C] it should also have returned 1 and printed an error message\n");
         printf("\n");
      -  printf("[C] Lets call lua again, calling the greeting function\n");
      +  printf("[C] Let's call lua again, calling the greeting function\n");
         ok=dostring(L,"call_greeting()");
         printf("[C] This was C=>Lua=>C (getting a bit complex)\n");
         printf("\n");
      diff --git a/Examples/lua/embed/runme.lua b/Examples/lua/embed/runme.lua
      index e02fd1d55..a75f74000 100644
      --- a/Examples/lua/embed/runme.lua
      +++ b/Examples/lua/embed/runme.lua
      @@ -1,7 +1,7 @@
       print "[lua] This is runme.lua"
      --- test program for embeded lua
      --- we do not need to load the library, as it was already in the intrepreter
      --- but lets check anyway
      +-- test program for embedded lua
      +-- we do not need to load the library, as it was already in the interpreter
      +-- but let's check anyway
       assert(type(example)=='table',"Don't appear to have loaded the example module")
       
       -- a test function to run the tests
      diff --git a/Examples/lua/embed2/Makefile b/Examples/lua/embed2/Makefile
      index fc309ac7e..d30ba0942 100644
      --- a/Examples/lua/embed2/Makefile
      +++ b/Examples/lua/embed2/Makefile
      @@ -4,16 +4,17 @@ TARGET     = embed2
       SRCS       = example.c
       INTERFACE  = example.i
       LUA_INTERP = embed2.c
      +LIBS       = -lm
       
       # this is a little different to normal as we have our own special interpreter
       # which we want to static link
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
       	rm -f $(TARGET)
      diff --git a/Examples/lua/embed2/embed2.c b/Examples/lua/embed2/embed2.c
      index 8d28ee6ea..0ce9f8f7f 100644
      --- a/Examples/lua/embed2/embed2.c
      +++ b/Examples/lua/embed2/embed2.c
      @@ -1,9 +1,9 @@
      -/* embed2.c some more test for an embeded interpreter
      +/* embed2.c some more tests for an embedded interpreter
        
       This will go a bit further as it will pass values to and from the lua code.
       It uses less of the SWIG code, and more of the raw lua API's
        
      -What it will do is load the wrappered lib, load runme.lua and then call some functions.
      +What it will do is load the wrapped lib, load runme.lua and then call some functions.
       To make life easier, all the printf's have either [C] or [Lua] at the start
       so you can see where they are coming from.
        
      @@ -24,6 +24,7 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua
       
       #include 
       #include 
      +#include 
       
       #include 
       #include 
      @@ -31,13 +32,16 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua
       #include 
       #include 
       
      +#if LUA_VERSION_NUM > 501
      +#define lua_open luaL_newstate
      +#endif
       
      -/* the SWIG wrappered library */
      +/* the SWIG wrapped library */
       extern int luaopen_example(lua_State*L);
       
       /* This is an example of how to call the Lua function
           int add(int,int) 
      -  its very tedious, but gives you an idea of the issues involded.
      +  its very tedious, but gives you an idea of the issues involved.
         (look below for a better idea)
       */
       int call_add(lua_State *L,int a,int b,int* res) {
      @@ -46,11 +50,10 @@ int call_add(lua_State *L,int a,int b,int* res) {
         push a, push b, call 'add' check & return res
         */
         top=lua_gettop(L);  /* for later */
      -  lua_pushstring(L, "add");                                  /* function name */
      -  lua_gettable(L, LUA_GLOBALSINDEX);               /* function to be called */
      +  lua_getglobal(L, "add");               /* function to be called */
         if (!lua_isfunction(L,-1)) {
           printf("[C] error: cannot find function 'add'\n");
      -    lua_settop(L,top);  // reset
      +    lua_settop(L,top);
           return 0;
         }
         lua_pushnumber(L,a);
      @@ -58,25 +61,25 @@ int call_add(lua_State *L,int a,int b,int* res) {
         if (lua_pcall(L, 2, 1, 0) != 0)  /* call function with 2 arguments and 1 result */
         {
           printf("[C] error running function `add': %s\n",lua_tostring(L, -1));
      -    lua_settop(L,top);  // reset
      +    lua_settop(L,top);
           return 0;
         }
      -  // check results
      +  /* check results */
         if (!lua_isnumber(L,-1)) {
           printf("[C] error: returned value is not a number\n");
      -    lua_settop(L,top);  // reset
      +    lua_settop(L,top);
           return 0;
         }
         *res=(int)lua_tonumber(L,-1);
         lua_settop(L,top);  /* reset stack */
      -  return 1;   // ok
      +  return 1;
       }
       
       /* This is a variargs call function for calling from C into Lua.
       Original Code from Programming in Lua (PIL) by Roberto Ierusalimschy
       ISBN 85-903798-1-7 
       http://www.lua.org/pil/25.3.html
      -This has been modified slightly to make it compile, and its still a bit rough.
      +This has been modified slightly to make it compile, and it's still a bit rough.
       But it gives the idea of how to make it work.
       */
       int call_va (lua_State *L,const char *func, const char *sig, ...) {
      @@ -187,20 +190,24 @@ int main(int argc,char* argv[]) {
         luaopen_example(L);
         printf("[C] all looks ok\n");
         printf("\n");
      -  printf("[C] lets load the file 'runme.lua'\n");
      +  if (argc != 2 || argv[1] == NULL || strlen(argv[1]) == 0) {
      +    printf("[C] ERROR: no lua file given on command line\n");
      +    exit(3);
      +  }
      +  printf("[C] let's load the file '%s'\n", argv[1]);
         printf("[C] any lua code in this file will be executed\n");
      -  if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) {
      +  if (luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, 0, 0)) {
           printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1));
           exit(3);
         }
         printf("[C] We are now back in C, all looks ok\n");
         printf("\n");
      -  printf("[C] lets call the Lua function 'add(1,1)'\n");
      +  printf("[C] let's call the Lua function 'add(1,1)'\n");
         printf("[C] using the C function 'call_add'\n");
         ok=call_add(L,1,1,&res);
         printf("[C] the function returned %d with value %d\n",ok,res);
         printf("\n");
      -  printf("[C] lets do this rather easier\n");
      +  printf("[C] let's do this rather easier\n");
         printf("[C] we will call the same Lua function using a generic C function 'call_va'\n");
         ok=call_va(L,"add","ii>i",1,1,&res);
         printf("[C] the function returned %d with value %d\n",ok,res);
      diff --git a/Examples/lua/embed2/runme.lua b/Examples/lua/embed2/runme.lua
      index 73af9c5f2..9e7ab616c 100644
      --- a/Examples/lua/embed2/runme.lua
      +++ b/Examples/lua/embed2/runme.lua
      @@ -1,7 +1,7 @@
       print "[lua] This is runme.lua"
      --- test program for embeded lua
      --- we do not need to load the library, as it was already in the intrepreter
      --- but lets check anyway
      +-- test program for embedded lua
      +-- we do not need to load the library, as it was already in the interpreter
      +-- but let's check anyway
       assert(type(example)=='table',"Don't appear to have loaded the example module")
       
       -- note: we will copy the functions from example table into global
      diff --git a/Examples/lua/embed3/Makefile b/Examples/lua/embed3/Makefile
      index 8cfa97454..fc0026122 100644
      --- a/Examples/lua/embed3/Makefile
      +++ b/Examples/lua/embed3/Makefile
      @@ -9,13 +9,13 @@ LUA_INTERP = embed3.cpp
       # which we want to static link
       # we also need the external runtime, so we can get access to certain internals of SWIG
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run
       
       build:
       	$(SWIG) -c++ -lua $(SWIGOPT) -external-runtime swigluarun.h
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
       	rm -f swigluarun.h $(TARGET)
      diff --git a/Examples/lua/embed3/embed3.cpp b/Examples/lua/embed3/embed3.cpp
      index e5e0e0a7d..9be49add3 100644
      --- a/Examples/lua/embed3/embed3.cpp
      +++ b/Examples/lua/embed3/embed3.cpp
      @@ -1,4 +1,4 @@
      -/* embed3.cpp A C++ embeded interpreter
      +/* embed3.cpp A C++ embedded interpreter
        
       This will register a C++ class with Lua, and then call a Lua function
       passing C++ objects to this function.
      @@ -26,15 +26,19 @@ extern "C" {
       #include 
       #include 
       }
      -
      -/* The SWIG external runtime is generated by using.
      -swig -lua -externalruntime swigluarun.h
      -It contains useful function used by SWIG in its wrappering
      -SWIG_TypeQuery() SWIG_NewPointerObj()
      +
      +#if LUA_VERSION_NUM > 501
      +#define lua_open luaL_newstate
      +#endif
      +
      +/* The SWIG external runtime is generated by using.
      +swig -lua -externalruntime swigluarun.h
      +It contains useful function used by SWIG in its wrapper
      +SWIG_TypeQuery() SWIG_NewPointerObj()
       */
       #include "swigluarun.h"   // the SWIG external runtime
       
      -/* the SWIG wrappered library */
      +/* the SWIG wrapped library */
       extern "C" int luaopen_example(lua_State*L);
       
       // the code itself
      @@ -65,8 +69,7 @@ int call_onEvent(lua_State *L, Event e) {
         push a, push b, call 'add' check & return res
         */
         top = lua_gettop(L);  /* for later */
      -  lua_pushstring(L, "onEvent");                                  /* function name */
      -  lua_gettable(L, LUA_GLOBALSINDEX);               /* function to be called */
      +  lua_getglobal(L, "onEvent");               /* function to be called */
         if (!lua_isfunction(L, -1)) {
           printf("[C++] error: cannot find function 'OnEvent'\n");
           lua_settop(L, top);  // reset
      @@ -97,10 +100,10 @@ int main(int argc, char* argv[]) {
         luaopen_example(L);
         printf("[C++] all looks ok\n");
         printf("\n");
      -  printf("[C++] lets create an Engine and pass a pointer to Lua\n");
      +  printf("[C++] let's create an Engine and pass a pointer to Lua\n");
         Engine engine;
         /* this code will pass a pointer into lua, but C++ still owns the object
      -  this is a little tedious, to do, but lets do it
      +  this is a little tedious, to do, but let's do it
         we need to pass the pointer (obviously), the type name 
         and a flag which states if Lua should delete the pointer once its finished with it
         The type name is a class name string which is registered with SWIG
      @@ -110,16 +113,20 @@ int main(int argc, char* argv[]) {
         push_pointer(L,&engine,"Engine *",0);
         lua_setglobal(L, "pEngine");  // set as global variable
       
      -  printf("[C++] now lets load the file 'runme.lua'\n");
      +  if (argc != 2 || argv[1] == NULL || strlen(argv[1]) == 0) {
      +    printf("[C++] ERROR: no lua file given on command line\n");
      +    exit(3);
      +  }
      +  printf("[C++] now let's load the file '%s'\n", argv[1]);
         printf("[C++] any lua code in this file will be executed\n");
      -  if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) {
      -    printf("[C++] ERROR: cannot run lua file: %s", lua_tostring(L, -1));
      +  if (luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, 0, 0)) {
      +    printf("[C++] ERROR: cannot run lua file: %s",lua_tostring(L, -1));
           exit(3);
         }
         printf("[C++] We are now back in C++, all looks ok\n");
         printf("\n");
       
      -  printf("[C++] Lets call the Lua function onEvent(e)\n");
      +  printf("[C++] Let's call the Lua function onEvent(e)\n");
         printf("[C++] We will give it different events, as we wish\n");
         printf("[C++] Starting with STARTUP\n");
         Event ev;
      diff --git a/Examples/lua/embed3/example.h b/Examples/lua/embed3/example.h
      index 41c13e9c1..df189e34b 100644
      --- a/Examples/lua/embed3/example.h
      +++ b/Examples/lua/embed3/example.h
      @@ -13,7 +13,7 @@ public:
       };
       
       
      -/* We also want to pass some events to Lua, so lets have a few classes
      +/* We also want to pass some events to Lua, so let's have a few classes
       to do this.
       */
       class Event
      diff --git a/Examples/lua/embed3/runme.lua b/Examples/lua/embed3/runme.lua
      index 3a44bd2fc..8d5b1eada 100644
      --- a/Examples/lua/embed3/runme.lua
      +++ b/Examples/lua/embed3/runme.lua
      @@ -1,7 +1,7 @@
       print "[lua] This is runme.lua"
      --- test program for embeded lua
      --- we do not need to load the library, as it was already in the intrepreter
      --- but lets check anyway
      +-- test program for embedded lua
      +-- we do not need to load the library, as it was already in the interpreter
      +-- but let's check anyway
       
       assert(type(example)=='table',"Don't appear to have loaded the example module. Do not run this file directly, run the embed3 executable")
       
      @@ -13,12 +13,12 @@ else
       end
       
       
      --- the embed program expects a function void onEvent(Event)
      +-- the embedded program expects a function void onEvent(Event)
       -- this is it
       
       function onEvent(e)
           print("[Lua] onEvent with event",e.mType)
      -    -- lets do something with the Engine
      +    -- let's do something with the Engine
           -- nothing clever, but ...
           if e.mType==example.Event_STARTUP then
               pEngine:start()
      diff --git a/Examples/lua/exception/Makefile b/Examples/lua/exception/Makefile
      index 01bee5c6a..ac9c28b69 100644
      --- a/Examples/lua/exception/Makefile
      +++ b/Examples/lua/exception/Makefile
      @@ -1,20 +1,20 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    = 
      +CXXSRCS    =
       TARGET     = example
       INTERFACE  = example.i
       LIBS       = -lm
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/exception/runme.lua b/Examples/lua/exception/runme.lua
      index d8125caec..a798efca7 100644
      --- a/Examples/lua/exception/runme.lua
      +++ b/Examples/lua/exception/runme.lua
      @@ -70,7 +70,7 @@ function b()
           t:message()
       end
       print [[
      -Now lets call function a()
      +Now let's call function a()
        which calls b() 
        which calls into C++
        which will throw an exception!]]
      @@ -80,7 +80,7 @@ if ok then
       else
           print("  call failed with error:",res)
       end
      -print "Now lets do the same using xpcall(a,debug.traceback)"
      +print "Now let's do the same using xpcall(a,debug.traceback)"
       ok,res=xpcall(a,debug.traceback)
       if ok then 
           print "  that worked! Funny"
      diff --git a/Examples/lua/funcptr3/Makefile b/Examples/lua/funcptr3/Makefile
      index 00bfe7992..aeeaad469 100644
      --- a/Examples/lua/funcptr3/Makefile
      +++ b/Examples/lua/funcptr3/Makefile
      @@ -3,18 +3,18 @@ SWIG       = $(TOP)/../preinst-swig
       SRCS       = example.c
       TARGET     = example
       INTERFACE  = example.i
      -LIBS       = 
      +LIBS       =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/functest/Makefile b/Examples/lua/functest/Makefile
      index 00bfe7992..aeeaad469 100644
      --- a/Examples/lua/functest/Makefile
      +++ b/Examples/lua/functest/Makefile
      @@ -3,18 +3,18 @@ SWIG       = $(TOP)/../preinst-swig
       SRCS       = example.c
       TARGET     = example
       INTERFACE  = example.i
      -LIBS       = 
      +LIBS       =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/functest/example.i b/Examples/lua/functest/example.i
      index 631e0602d..9bb64cbf5 100644
      --- a/Examples/lua/functest/example.i
      +++ b/Examples/lua/functest/example.i
      @@ -1,13 +1,12 @@
       /* File : example.i */
       %module example
       
      -%include "typemaps.i" // you must have this for the typemaps for ptrs
      -// basic function testing
      -//
      +%include "typemaps.i"
      +
       %inline %{
      -extern int add1(int x, int y);              // return x+y -- basic function test
      -extern void add2(int x, int *INPUT, int *OUTPUT); // *z = x+*y  -- argin and argout test
      -extern int add3(int x, int y, int *OUTPUT);    // return x+y, *z=x-y -- returning 2 values
      -extern void add4(int x, int *INOUT);        // *y += x    -- INOUT dual purpose variable
      +extern int add1(int x, int y);              /* return x+y -- basic function test */
      +extern void add2(int x, int *INPUT, int *OUTPUT); /* *z = x+*y  -- argin and argout test */
      +extern int add3(int x, int y, int *OUTPUT);    /* return x+y, *z=x-y -- returning 2 values */
      +extern void add4(int x, int *INOUT);        /* *y += x    -- INOUT dual purpose variable */
       %}
       
      diff --git a/Examples/lua/functor/Makefile b/Examples/lua/functor/Makefile
      index 9220dfe51..e647fb2a8 100644
      --- a/Examples/lua/functor/Makefile
      +++ b/Examples/lua/functor/Makefile
      @@ -1,21 +1,21 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    = 
      +CXXSRCS    =
       TARGET     = example
       INTERFACE  = example.i
       LIBS       = -lm
      -SWIGOPT    = 
      +SWIGOPT    =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/import.lua b/Examples/lua/import.lua
      index b2a40b017..4a0f0d3da 100644
      --- a/Examples/lua/import.lua
      +++ b/Examples/lua/import.lua
      @@ -1,7 +1,7 @@
       -- import
       -- the lua 5.0 loading mechanism is rather poor & relies upon the loadlib() fn
       -- the lua 5.1 loading mechanism is simplicity itself
      --- for now we need a bridge which will use the correct verion
      +-- for now we need a bridge which will use the correct version
       
       function import_5_0(module)
       	-- imports the file into the program
      @@ -10,7 +10,7 @@ function import_5_0(module)
       	-- and look for the fn 'Example_Init()' (note the capitalisation)
       	if rawget(_G,module)~=nil then return end -- module appears to be loaded
       		
      -	-- capitialising the first letter
      +	-- capitalising the first letter
       	local c=string.upper(string.sub(module,1,1))
       	local fnname=c..string.sub(module,2).."_Init"
       	
      @@ -26,7 +26,7 @@ function import_5_0(module)
       	end
       	assert(lib,"error loading module:"..module)
       	
      -	lib() -- execute the function: initalising the lib
      +	lib() -- execute the function: initialising the lib
       	local m=rawget(_G,module)	-- gets the module object
       	assert(m~=nil,"no module table found")
       end
      @@ -39,4 +39,4 @@ if string.sub(_VERSION,1,7)=='Lua 5.0' then
       	import=import_5_0
       else
       	import=import_5_1
      -end
      \ No newline at end of file
      +end
      diff --git a/Examples/lua/import/Makefile b/Examples/lua/import/Makefile
      index 0bf47c1a5..8d64a21c6 100644
      --- a/Examples/lua/import/Makefile
      +++ b/Examples/lua/import/Makefile
      @@ -2,19 +2,19 @@ TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
       SWIGOPT    =
       LIBS       =
      - 
      +
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
       	LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' lua_cpp
      -	$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
       	LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' lua_cpp
      -	$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
       	LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' lua_cpp
      -	$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
       	LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' lua_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/nspace/Makefile b/Examples/lua/nspace/Makefile
      new file mode 100644
      index 000000000..17757c2ec
      --- /dev/null
      +++ b/Examples/lua/nspace/Makefile
      @@ -0,0 +1,19 @@
      +TOP        = ../..
      +SWIG       = $(TOP)/../preinst-swig
      +CXXSRCS    =
      +TARGET     = example
      +INTERFACE  = example.i
      +
      +check: build
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
      +
      +build:
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp
      +
      +static:
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static
      +
      +clean:
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/nspace/example.h b/Examples/lua/nspace/example.h
      new file mode 100644
      index 000000000..53066980a
      --- /dev/null
      +++ b/Examples/lua/nspace/example.h
      @@ -0,0 +1,23 @@
      +#ifndef _example_guardian_
      +#define _example_guardian_
      +
      +int module_function() { return 7; }
      +int module_variable = 9;
      +
      +namespace MyWorld {
      +  class World {
      +  public:
      +    World() : world_max_count(9) {}
      +    int create_world() { return 17; }
      +    const int world_max_count; // = 9
      +  };
      +  namespace Nested {
      +    class Dweller {
      +      public:
      +        enum Gender { MALE = 0, FEMALE = 1 };
      +        static int count() { return 19; }
      +    };
      +  }
      +}
      +
      +#endif
      diff --git a/Examples/lua/nspace/example.i b/Examples/lua/nspace/example.i
      new file mode 100644
      index 000000000..c30f87fec
      --- /dev/null
      +++ b/Examples/lua/nspace/example.i
      @@ -0,0 +1,10 @@
      +%module example
      +
      +%{
      +#include "example.h"
      +%}
      +
      +%nspace MyWorld::Nested::Dweller;
      +%nspace MyWorld::World;
      +
      +%include "example.h"
      diff --git a/Examples/lua/nspace/runme.lua b/Examples/lua/nspace/runme.lua
      new file mode 100644
      index 000000000..876814052
      --- /dev/null
      +++ b/Examples/lua/nspace/runme.lua
      @@ -0,0 +1,46 @@
      +-- file: runme.lua
      +
      +-- This file illustrates class C++ interface generated
      +-- by SWIG.
      +
      +---- importing ----
      +if string.sub(_VERSION,1,7)=='Lua 5.0' then
      +	-- lua5.0 doesnt have a nice way to do this
      +	lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
      +	assert(lib)()
      +else
      +	-- lua 5.1 does
      +	require('example')
      +end
      +
      +ex = example
      +
      +-- Calling a module function ( aka global function )
      +assert( ex.module_function() == 7 )
      +print("example.module_function(): ", ex.module_function())
      +
      +-- Accessing a module (aka global) variable
      +assert( ex.module_variable == 9 )
      +print("example.module_variable: ", ex.module_variable)
      +
      +-- Creating an instance of the class
      +w1 = ex.MyWorld.World()
      +print("Creating class instance: w1 = ex.MyWorld.World(): ", w1)
      +
      +-- Accessing class members 
      +assert( ex.MyWorld.World():create_world() == 17 )
      +print( "w1:create_world() = ", w1:create_world() )
      +assert( w1:create_world() == 17 )
      +print( "w1:world_max_count = ", w1.world_max_count )
      +assert( w1.world_max_count == 9 )
      +
      +-- Accessing enums from class within namespace
      +print( "Accessing enums: ex.MyWorld.Nested.Dweller.MALE = ", ex.MyWorld.Nested.Dweller.MALE )
      +assert( ex.MyWorld.Nested.Dweller.MALE == 0 )
      +print( "Accessing enums: ex.MyWorld.Nested.Dweller.FEMALE = ", ex.MyWorld.Nested.Dweller.FEMALE )
      +assert( ex.MyWorld.Nested.Dweller.FEMALE == 1 )
      +
      +-- Accessing static member function
      +print( "Accessing static member function: ex.MyWorld.Nested.Dweller.count() = ", ex.MyWorld.Nested.Dweller.count() )
      +assert( ex.MyWorld.Nested.Dweller.count() == 19 )
      +
      diff --git a/Examples/lua/owner/Makefile b/Examples/lua/owner/Makefile
      index c39e8acdf..96308f0df 100644
      --- a/Examples/lua/owner/Makefile
      +++ b/Examples/lua/owner/Makefile
      @@ -6,15 +6,15 @@ INTERFACE  = example.i
       LIBS       = -lm
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile lua_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile lua_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean
      diff --git a/Examples/lua/owner/example.cxx b/Examples/lua/owner/example.cxx
      index bce484aea..c2c073d79 100644
      --- a/Examples/lua/owner/example.cxx
      +++ b/Examples/lua/owner/example.cxx
      @@ -39,12 +39,15 @@ Square* createSquare(double w)
           return new Square(w);
       }
       
      -ShapeOwner::ShapeOwner() {printf("  ShapeOwner(%p)\n",this);}
      +ShapeOwner::ShapeOwner() {
      +  printf("  ShapeOwner(%p)\n", (void *)this);
      +}
      +
       ShapeOwner::~ShapeOwner()
       {
      -    printf("  ~ShapeOwner(%p)\n",this);
      -    for(unsigned i=0;ix : 0, ptptr ? ptptr->y : 0);
      +  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);
       }
      diff --git a/Examples/modula3/class/Makefile b/Examples/modula3/class/Makefile
      index 9976e6f80..2e2f37526 100644
      --- a/Examples/modula3/class/Makefile
      +++ b/Examples/modula3/class/Makefile
      @@ -1,6 +1,6 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       PLATFORM   = LINUXLIBC6
       INTERFACE  = example.i
      @@ -8,10 +8,10 @@ SWIGOPT    = -c++
       MODULA3SRCS = *.[im]3
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile modula3_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
       	m3ppinplace $(MODULA3SRCS)
       # compilation of example_wrap.cxx is started by cm3
      @@ -21,4 +21,4 @@ build:
       	cm3
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile modula3_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean
      diff --git a/Examples/modula3/class/example.cxx b/Examples/modula3/class/example.cxx
      index 1e8e203dd..046304519 100644
      --- a/Examples/modula3/class/example.cxx
      +++ b/Examples/modula3/class/example.cxx
      @@ -1,4 +1,4 @@
      -/* File : example.c */
      +/* File : example.cxx */
       
       #include "example.h"
       #define M_PI 3.14159265358979323846
      @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
       
       int Shape::nshapes = 0;
       
      -double Circle::area(void) {
      +double Circle::area() {
         return M_PI*radius*radius;
       }
       
      -double Circle::perimeter(void) {
      +double Circle::perimeter() {
         return 2*M_PI*radius;
       }
       
      -double Square::area(void) {
      +double Square::area() {
         return width*width;
       }
       
      -double Square::perimeter(void) {
      +double Square::perimeter() {
         return 4*width;
       }
      diff --git a/Examples/modula3/class/example.h b/Examples/modula3/class/example.h
      index 9c1f47995..0dff185b2 100644
      --- a/Examples/modula3/class/example.h
      +++ b/Examples/modula3/class/example.h
      @@ -1,44 +1,34 @@
       /* File : example.h */
       
      -class Shape
      -{
      +class Shape {
       public:
      -  Shape ()
      -  {
      +  Shape() {
           nshapes++;
         }
      -  virtual ~ Shape ()
      -  {
      +  virtual ~Shape() {
           nshapes--;
      -  };
      -  double x, y;
      -  void move (double dx, double dy);
      -  virtual double area (void) const = 0;
      -  virtual double perimeter (void) const = 0;
      -protected:
      -  static int 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
      -{
      +class Circle : public Shape {
       private:
         double radius;
       public:
      -    Circle (double r):radius (r)
      -  {
      -  };
      -  virtual double area (void) const;
      -  virtual double perimeter (void) const;
      +  Circle(double r) : radius(r) { }
      +  virtual double area();
      +  virtual double perimeter();
       };
       
      -class Square:public Shape
      -{
      +class Square : public Shape {
       private:
         double width;
       public:
      -    Square (double w):width (w)
      -  {
      -  };
      -  virtual double area (void) const;
      -  virtual double perimeter (void) const;
      +  Square(double w) : width(w) { }
      +  virtual double area();
      +  virtual double perimeter();
       };
      diff --git a/Examples/modula3/enum/Makefile b/Examples/modula3/enum/Makefile
      index a3b499823..3915e5405 100644
      --- a/Examples/modula3/enum/Makefile
      +++ b/Examples/modula3/enum/Makefile
      @@ -1,6 +1,6 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       CONSTNUMERIC = example_const
      @@ -8,18 +8,18 @@ SWIGOPT      = -c++
       MODULA3SRCS  = *.[im]3
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile modula3_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run
       
       build:
       	$(SWIG) -modula3 $(SWIGOPT) -module Example -generateconst $(CONSTNUMERIC) $(TARGET).h
       	$(CXX) -Wall $(CONSTNUMERIC).c -o $(CONSTNUMERIC)
       	$(CONSTNUMERIC) >$(CONSTNUMERIC).i
       
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
       	m3ppinplace $(MODULA3SRCS)
       	mv m3makefile $(MODULA3SRCS) src/
       	cm3
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile modula3_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean
      diff --git a/Examples/modula3/exception/Makefile b/Examples/modula3/exception/Makefile
      index 8d4525512..1dbf1a156 100644
      --- a/Examples/modula3/exception/Makefile
      +++ b/Examples/modula3/exception/Makefile
      @@ -8,15 +8,15 @@ MODULA3SRCS = *.[im]3
       MODULA3FLAGS= -o runme
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile modula3_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3_cpp
      -#	$(MAKE) -f $(TOP)/Makefile MODULA3SRCS='$(MODULA3SRCS)' MODULA3FLAGS='$(MODULA3FLAGS)' modula3_compile
      +#	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MODULA3SRCS='$(MODULA3SRCS)' MODULA3FLAGS='$(MODULA3FLAGS)' modula3_compile
       	m3ppinplace $(MODULA3SRCS)
       	mv m3makefile $(MODULA3SRCS) src/
       	cm3
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile modula3_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean
      diff --git a/Examples/modula3/reference/Makefile b/Examples/modula3/reference/Makefile
      index 62183931e..3b68fe822 100644
      --- a/Examples/modula3/reference/Makefile
      +++ b/Examples/modula3/reference/Makefile
      @@ -1,20 +1,20 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       SWIGOPT    = -c++
       MODULA3SRCS = *.[im]3
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile modula3_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
       	m3ppinplace $(MODULA3SRCS)
       	mv m3makefile $(MODULA3SRCS) src/
       	cm3
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile modula3_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean
      diff --git a/Examples/modula3/reference/example.cxx b/Examples/modula3/reference/example.cxx
      index 649b0169c..9dbaed2ee 100644
      --- a/Examples/modula3/reference/example.cxx
      +++ b/Examples/modula3/reference/example.cxx
      @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) {
       
       char *Vector::print() {
         static char temp[512];
      -  sprintf(temp,"Vector %x (%g,%g,%g)", (int)this, x,y,z);
      +  sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z);
         return temp;
       }
       
      diff --git a/Examples/modula3/simple/Makefile b/Examples/modula3/simple/Makefile
      index 6a0ca4f0e..2796b25f8 100644
      --- a/Examples/modula3/simple/Makefile
      +++ b/Examples/modula3/simple/Makefile
      @@ -1,20 +1,20 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       SWIGOPT    =
       MODULA3SRCS = *.[im]3
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile modula3_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
       	m3ppinplace $(MODULA3SRCS)
       	mv m3makefile $(MODULA3SRCS) src/
       	cm3
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile modula3_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean
      diff --git a/Examples/modula3/typemap/Makefile b/Examples/modula3/typemap/Makefile
      index 6a0ca4f0e..2796b25f8 100644
      --- a/Examples/modula3/typemap/Makefile
      +++ b/Examples/modula3/typemap/Makefile
      @@ -1,20 +1,20 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       SWIGOPT    =
       MODULA3SRCS = *.[im]3
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile modula3_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
       	m3ppinplace $(MODULA3SRCS)
       	mv m3makefile $(MODULA3SRCS) src/
       	cm3
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile modula3_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean
      diff --git a/Examples/mzscheme/multimap/Makefile b/Examples/mzscheme/multimap/Makefile
      index d1b4a3f39..ecf83fbeb 100644
      --- a/Examples/mzscheme/multimap/Makefile
      +++ b/Examples/mzscheme/multimap/Makefile
      @@ -3,13 +3,13 @@ SWIG       = $(TOP)/../preinst-swig
       SRCS       = example.c
       TARGET     = example
       INTERFACE  = example.i
      -SWIGOPT    = 
      +SWIGOPT    =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile mzscheme_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme
       clean:
      -	$(MAKE) -f $(TOP)/Makefile mzscheme_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean
      diff --git a/Examples/mzscheme/simple/Makefile b/Examples/mzscheme/simple/Makefile
      index d1b4a3f39..ecf83fbeb 100644
      --- a/Examples/mzscheme/simple/Makefile
      +++ b/Examples/mzscheme/simple/Makefile
      @@ -3,13 +3,13 @@ SWIG       = $(TOP)/../preinst-swig
       SRCS       = example.c
       TARGET     = example
       INTERFACE  = example.i
      -SWIGOPT    = 
      +SWIGOPT    =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile mzscheme_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run
       
       build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme
       clean:
      -	$(MAKE) -f $(TOP)/Makefile 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 28b91158a..75918a61e 100644
      --- a/Examples/mzscheme/std_vector/Makefile
      +++ b/Examples/mzscheme/std_vector/Makefile
      @@ -1,20 +1,20 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
      -SWIGOPT    = 
      +SWIGOPT    =
       
       GPP        = `which g++`
       MZC        = test -n "/usr/bin/mzc" && /usr/bin/mzc
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile mzscheme_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run
       
       build:
       	$(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACE)
       	$(MZC) --compiler $(GPP) ++ccf "-I." --cc example_wrap.cxx
      -	$(MZC) --linker $(GPP) --ld $(TARGET).so example_wrap.o 
      -	
      +	$(MZC) --linker $(GPP) --ld $(TARGET).so example_wrap.o
      +
       clean:
      -	$(MAKE) -f $(TOP)/Makefile mzscheme_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean
      diff --git a/Examples/ocaml/argout_ref/Makefile b/Examples/ocaml/argout_ref/Makefile
      index 4e12e3769..09893af65 100644
      --- a/Examples/ocaml/argout_ref/Makefile
      +++ b/Examples/ocaml/argout_ref/Makefile
      @@ -8,21 +8,21 @@ PROGFILE   = example_prog.ml
       OBJS       = example.o
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_cpp
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_dynamic_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean
      diff --git a/Examples/ocaml/contract/Makefile b/Examples/ocaml/contract/Makefile
      index 91d39247e..df5d6a6f5 100644
      --- a/Examples/ocaml/contract/Makefile
      +++ b/Examples/ocaml/contract/Makefile
      @@ -1,34 +1,34 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       MLFILE     = example.ml
       PROGFILE   = example_prog.ml
      -OBJS       = 
      +OBJS       =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_dynamic
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static
       
       toplevel:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_toplevel
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean
      diff --git a/Examples/ocaml/scoped_enum/Makefile b/Examples/ocaml/scoped_enum/Makefile
      index 4920e3b3b..794733971 100644
      --- a/Examples/ocaml/scoped_enum/Makefile
      +++ b/Examples/ocaml/scoped_enum/Makefile
      @@ -1,34 +1,34 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       MLFILE     = example.ml
       PROGFILE   = example_prog.ml
      -OBJS       = 
      +OBJS       =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_dynamic_cpp
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_cpp
       
       toplevel:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_cpp_toplevel
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean
      diff --git a/Examples/ocaml/shapes/Makefile b/Examples/ocaml/shapes/Makefile
      index 38230eb69..69102f3b1 100644
      --- a/Examples/ocaml/shapes/Makefile
      +++ b/Examples/ocaml/shapes/Makefile
      @@ -1,6 +1,6 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SWIGOPT    = 
      +SWIGOPT    =
       SRCS       = example.c
       TARGET     = example
       INTERFACE  = example.i
      @@ -9,27 +9,27 @@ PROGFILE   = example_prog.ml
       OBJS       = example.o
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static static_top
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_cpp
       
       static_top:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_cpp_toplevel
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)'
       	MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_dynamic_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean
      diff --git a/Examples/ocaml/simple/Makefile b/Examples/ocaml/simple/Makefile
      index 64c7256c1..49bf81c1e 100644
      --- a/Examples/ocaml/simple/Makefile
      +++ b/Examples/ocaml/simple/Makefile
      @@ -8,27 +8,27 @@ PROGFILE   = example_prog.ml
       OBJS       = example.o
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_dynamic
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static
       
       toplevel:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
       	PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_toplevel
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean
      diff --git a/Examples/ocaml/std_string/Makefile b/Examples/ocaml/std_string/Makefile
      index 0250cfd2d..8f8b2f684 100644
      --- a/Examples/ocaml/std_string/Makefile
      +++ b/Examples/ocaml/std_string/Makefile
      @@ -1,24 +1,24 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       PROGFILE   = runme.ml
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_dynamic_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean
      diff --git a/Examples/ocaml/std_vector/Makefile b/Examples/ocaml/std_vector/Makefile
      index 0250cfd2d..8f8b2f684 100644
      --- a/Examples/ocaml/std_vector/Makefile
      +++ b/Examples/ocaml/std_vector/Makefile
      @@ -1,24 +1,24 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       PROGFILE   = runme.ml
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_dynamic_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean
      diff --git a/Examples/ocaml/stl/Makefile b/Examples/ocaml/stl/Makefile
      index 545f3229a..e4cce4883 100644
      --- a/Examples/ocaml/stl/Makefile
      +++ b/Examples/ocaml/stl/Makefile
      @@ -1,34 +1,34 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       PROGFILE   = runme.ml
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp
       
       director:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp_director
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp
       
       toplevel:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp_toplevel
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean
      diff --git a/Examples/ocaml/string_from_ptr/Makefile b/Examples/ocaml/string_from_ptr/Makefile
      index f7b808934..294bdec83 100644
      --- a/Examples/ocaml/string_from_ptr/Makefile
      +++ b/Examples/ocaml/string_from_ptr/Makefile
      @@ -1,35 +1,35 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
       SWIGOPT    = -c++
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = foolib.i
       MLFILE     = foolib.ml
       PROGFILE   = example_prog.ml
      -OBJS       = 
      +OBJS       =
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static static_top
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_cpp
       
       static_top:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_static_cpp_toplevel
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)'
       	MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
       	ocaml_dynamic_cpp
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean
      diff --git a/Examples/ocaml/strings_test/Makefile b/Examples/ocaml/strings_test/Makefile
      index 14f55e0d9..b6b866669 100644
      --- a/Examples/ocaml/strings_test/Makefile
      +++ b/Examples/ocaml/strings_test/Makefile
      @@ -1,29 +1,29 @@
       TOP        = ../..
       SWIG       = $(TOP)/../preinst-swig
      -SRCS       = 
      +SRCS       =
       TARGET     = example
       INTERFACE  = example.i
       PROGFILE   = runme.ml
       
       check: build
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
       
       build: static top
       
       static:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp
       
       dynamic:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp
       
       top:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
       	PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
       	ocaml_static_cpp_toplevel
       
       clean:
      -	$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean
      diff --git a/Examples/octave/callback/Makefile b/Examples/octave/callback/Makefile
      index d38d7f896..3b746de2f 100644
      --- a/Examples/octave/callback/Makefile
      +++ b/Examples/octave/callback/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    = example.cxx
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS = example.cxx
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/class/Makefile b/Examples/octave/class/Makefile
      index d38d7f896..3b746de2f 100644
      --- a/Examples/octave/class/Makefile
      +++ b/Examples/octave/class/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    = example.cxx
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS = example.cxx
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/class/example.cxx b/Examples/octave/class/example.cxx
      index 1e8e203dd..046304519 100644
      --- a/Examples/octave/class/example.cxx
      +++ b/Examples/octave/class/example.cxx
      @@ -1,4 +1,4 @@
      -/* File : example.c */
      +/* File : example.cxx */
       
       #include "example.h"
       #define M_PI 3.14159265358979323846
      @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
       
       int Shape::nshapes = 0;
       
      -double Circle::area(void) {
      +double Circle::area() {
         return M_PI*radius*radius;
       }
       
      -double Circle::perimeter(void) {
      +double Circle::perimeter() {
         return 2*M_PI*radius;
       }
       
      -double Square::area(void) {
      +double Square::area() {
         return width*width;
       }
       
      -double Square::perimeter(void) {
      +double Square::perimeter() {
         return 4*width;
       }
      diff --git a/Examples/octave/class/example.h b/Examples/octave/class/example.h
      index 0d4527e92..0dff185b2 100644
      --- a/Examples/octave/class/example.h
      +++ b/Examples/octave/class/example.h
      @@ -7,11 +7,11 @@ public:
         }
         virtual ~Shape() {
           nshapes--;
      -  };
      +  }
         double  x, y;
         void    move(double dx, double dy);
      -  virtual double area(void) = 0;
      -  virtual double perimeter(void) = 0;
      +  virtual double area() = 0;
      +  virtual double perimeter() = 0;
         static  int nshapes;
       };
       
      @@ -19,16 +19,16 @@ class Circle : public Shape {
       private:
         double radius;
       public:
      -  Circle(double r) : radius(r) { };
      -  virtual double area(void);
      -  virtual double perimeter(void);
      +  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(void);
      -  virtual double perimeter(void);
      +  Square(double w) : width(w) { }
      +  virtual double area();
      +  virtual double perimeter();
       };
      diff --git a/Examples/octave/constants/Makefile b/Examples/octave/constants/Makefile
      index 03501bd81..acf4d0575 100644
      --- a/Examples/octave/constants/Makefile
      +++ b/Examples/octave/constants/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    =
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS =
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/contract/Makefile b/Examples/octave/contract/Makefile
      index 73e3962ed..413b64bbd 100644
      --- a/Examples/octave/contract/Makefile
      +++ b/Examples/octave/contract/Makefile
      @@ -1,15 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -SRCS       = example.c
      -TARGET     = swigexample
      -INTERFACE  = example.i
      +SRCS = example.c
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/enum/Makefile b/Examples/octave/enum/Makefile
      index d38d7f896..3b746de2f 100644
      --- a/Examples/octave/enum/Makefile
      +++ b/Examples/octave/enum/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    = example.cxx
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS = example.cxx
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/example.mk b/Examples/octave/example.mk
      new file mode 100644
      index 000000000..e0b1e4efb
      --- /dev/null
      +++ b/Examples/octave/example.mk
      @@ -0,0 +1,32 @@
      +# Note: as a convention an example must be in a child directory of this.
      +# These paths are relative to such an example directory
      +
      +TOP        = ../..
      +SWIG       = $(TOP)/../preinst-swig
      +TARGET     = swigexample
      +INTERFACE  = example.i
      +
      +check: build
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' octave_run
      +
      +build:
      +ifneq (,$(SRCS))
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
      +else
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      +endif
      +ifneq (,$(TARGET2)$(SWIGOPT2))
      +ifneq (,$(SRCS))
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
      +	SWIGOPT='$(SWIGOPT2)' TARGET='$(TARGET2)' INTERFACE='$(INTERFACE)' octave
      +else
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	SWIGOPT='$(SWIGOPT2)' TARGET='$(TARGET2)' INTERFACE='$(INTERFACE)' octave_cpp
      +endif
      +endif
      +
      +
      +clean:
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' octave_clean
      diff --git a/Examples/octave/extend/Makefile b/Examples/octave/extend/Makefile
      index d38d7f896..3b746de2f 100644
      --- a/Examples/octave/extend/Makefile
      +++ b/Examples/octave/extend/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    = example.cxx
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS = example.cxx
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/extend/example.h b/Examples/octave/extend/example.h
      index 9e15cf8e4..77a26ec95 100644
      --- a/Examples/octave/extend/example.h
      +++ b/Examples/octave/extend/example.h
      @@ -14,7 +14,7 @@ public:
       	virtual std::string getTitle() { return getPosition() + " " + getName(); }
       	virtual std::string getName() { return name; }
       	virtual std::string getPosition() const { return "Employee"; }
      -	virtual ~Employee() { printf("~Employee() @ %p\n", this); }
      +	virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); }
       };
       
       
      diff --git a/Examples/octave/funcptr/Makefile b/Examples/octave/funcptr/Makefile
      index 73e3962ed..413b64bbd 100644
      --- a/Examples/octave/funcptr/Makefile
      +++ b/Examples/octave/funcptr/Makefile
      @@ -1,15 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -SRCS       = example.c
      -TARGET     = swigexample
      -INTERFACE  = example.i
      +SRCS = example.c
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/funcptr2/Makefile b/Examples/octave/funcptr2/Makefile
      index 73e3962ed..413b64bbd 100644
      --- a/Examples/octave/funcptr2/Makefile
      +++ b/Examples/octave/funcptr2/Makefile
      @@ -1,15 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -SRCS       = example.c
      -TARGET     = swigexample
      -INTERFACE  = example.i
      +SRCS = example.c
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/functor/Makefile b/Examples/octave/functor/Makefile
      index 94fb96337..acf4d0575 100644
      --- a/Examples/octave/functor/Makefile
      +++ b/Examples/octave/functor/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    =
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS =
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/module_load/Makefile b/Examples/octave/module_load/Makefile
      index e388763bd..d2cd66e70 100644
      --- a/Examples/octave/module_load/Makefile
      +++ b/Examples/octave/module_load/Makefile
      @@ -1,18 +1,7 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -SRCS       = example.c
      -TARGET     = swigexample
      -INTERFACE  = example.i
      +SRCS     = example.c
      +TARGET   = swigexample
      +SWIGOPT  = -module swigexample
      +TARGET2  = swigexample2
      +SWIGOPT2 = -module swigexample2 -globals .
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	TARGET='$(TARGET)' SWIGOPT='-module $$(TARGET)' INTERFACE='$(INTERFACE)' octave
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	TARGET='$(TARGET)2' SWIGOPT='-module $$(TARGET) -globals .' INTERFACE='$(INTERFACE)' octave
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      -	rm -f $(TARGET).m
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/operator/Makefile b/Examples/octave/operator/Makefile
      index 94fb96337..acf4d0575 100644
      --- a/Examples/octave/operator/Makefile
      +++ b/Examples/octave/operator/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    =
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS =
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/pointer/Makefile b/Examples/octave/pointer/Makefile
      index 73e3962ed..413b64bbd 100644
      --- a/Examples/octave/pointer/Makefile
      +++ b/Examples/octave/pointer/Makefile
      @@ -1,15 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -SRCS       = example.c
      -TARGET     = swigexample
      -INTERFACE  = example.i
      +SRCS = example.c
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/reference/Makefile b/Examples/octave/reference/Makefile
      index d38d7f896..3b746de2f 100644
      --- a/Examples/octave/reference/Makefile
      +++ b/Examples/octave/reference/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    = example.cxx
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS = example.cxx
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/reference/example.cxx b/Examples/octave/reference/example.cxx
      index 9b72ca6a2..632a03a5b 100644
      --- a/Examples/octave/reference/example.cxx
      +++ b/Examples/octave/reference/example.cxx
      @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) {
       
       char *Vector::print() {
         static char temp[512];
      -  sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z);
      +  sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z);
         return temp;
       }
       
      diff --git a/Examples/octave/simple/Makefile b/Examples/octave/simple/Makefile
      index 73e3962ed..413b64bbd 100644
      --- a/Examples/octave/simple/Makefile
      +++ b/Examples/octave/simple/Makefile
      @@ -1,15 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -SRCS       = example.c
      -TARGET     = swigexample
      -INTERFACE  = example.i
      +SRCS = example.c
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/template/Makefile b/Examples/octave/template/Makefile
      index 94fb96337..acf4d0575 100644
      --- a/Examples/octave/template/Makefile
      +++ b/Examples/octave/template/Makefile
      @@ -1,17 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -CXXSRCS    =
      -TARGET     = swigexample
      -INTERFACE  = example.i
      -LIBS       = -lm
      -SWIGOPT    =
      +CXXSRCS =
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      -	SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/variables/Makefile b/Examples/octave/variables/Makefile
      index 73e3962ed..413b64bbd 100644
      --- a/Examples/octave/variables/Makefile
      +++ b/Examples/octave/variables/Makefile
      @@ -1,15 +1,3 @@
      -TOP        = ../..
      -SWIG       = $(TOP)/../preinst-swig
      -SRCS       = example.c
      -TARGET     = swigexample
      -INTERFACE  = example.i
      +SRCS = example.c
       
      -check: build
      -	$(MAKE) -f $(TOP)/Makefile octave_run
      -
      -build:
      -	$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
      -	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
      -
      -clean:
      -	$(MAKE) -f $(TOP)/Makefile octave_clean
      +include $(SRCDIR)../example.mk
      diff --git a/Examples/octave/variables/example.c b/Examples/octave/variables/example.c
      index 15dcc1b8e..a9102a9d5 100644
      --- a/Examples/octave/variables/example.c
      +++ b/Examples/octave/variables/example.c
      @@ -51,10 +51,10 @@ void print_vars() {
         printf("dvar      = %g\n", dvar);
         printf("cvar      = %c\n", cvar);
         printf("strvar    = %s\n", strvar ? strvar : "(null)");
      -  printf("cstrvar   = %s\n", cstrvar ? cstrvar : "(null)");
      -  printf("iptrvar   = %p\n", iptrvar);
      +  printf("cstrvar   = %s\n", cstrvar);
      +  printf("iptrvar   = %p\n", (void *)iptrvar);
         printf("name      = %s\n", name);
      -  printf("ptptr     = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
      +  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);
       }
      diff --git a/Examples/perl5/callback/Makefile b/Examples/perl5/callback/Makefile
      new file mode 100644
      index 000000000..0d1cc574f
      --- /dev/null
      +++ b/Examples/perl5/callback/Makefile
      @@ -0,0 +1,20 @@
      +TOP        = ../..
      +SWIG       = $(TOP)/../preinst-swig
      +CXXSRCS    = example.cxx
      +TARGET     = example
      +INTERFACE  = example.i
      +LIBS       = -lm
      +
      +check: build
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run
      +
      +build:
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp
      +
      +static:
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
      +	TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static
      +
      +clean:
      +	$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean
      diff --git a/Examples/perl5/callback/example.cxx b/Examples/perl5/callback/example.cxx
      new file mode 100644
      index 000000000..450d75608
      --- /dev/null
      +++ b/Examples/perl5/callback/example.cxx
      @@ -0,0 +1,4 @@
      +/* File : example.cxx */
      +
      +#include "example.h"
      +
      diff --git a/Examples/perl5/callback/example.h b/Examples/perl5/callback/example.h
      new file mode 100644
      index 000000000..1a0e8c432
      --- /dev/null
      +++ b/Examples/perl5/callback/example.h
      @@ -0,0 +1,23 @@
      +/* File : example.h */
      +
      +#include 
      +#include 
      +
      +class Callback {
      +public:
      +	virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
      +	virtual void run() { std::cout << "Callback::run()" << std::endl; }
      +};
      +
      +
      +class Caller {
      +private:
      +	Callback *_callback;
      +public:
      +	Caller(): _callback(0) {}
      +	~Caller() { delCallback(); }
      +	void delCallback() { delete _callback; _callback = 0; }
      +	void setCallback(Callback *cb) { delCallback(); _callback = cb; }
      +	void call() { if (_callback) _callback->run(); }
      +};
      +
      diff --git a/Examples/perl5/callback/example.i b/Examples/perl5/callback/example.i
      new file mode 100644
      index 000000000..5f9072e61
      --- /dev/null
      +++ b/Examples/perl5/callback/example.i
      @@ -0,0 +1,17 @@
      +/* File : example.i */
      +%module(directors="1") example
      +%{
      +#include "example.h"
      +%}
      +
      +%include "std_string.i"
      +
      +/* turn on director wrapping Callback */
      +%feature("director") Callback;
      +
      +/* Caller::setCallback(Callback *cb) gives ownership of the cb to the
      + * Caller object.  The wrapper code should understand this. */
      +%apply SWIGTYPE *DISOWN { Callback *cb }; 
      +
      +%include "example.h"
      +
      diff --git a/Examples/perl5/callback/index.html b/Examples/perl5/callback/index.html
      new file mode 100644
      index 000000000..82f5e972a
      --- /dev/null
      +++ b/Examples/perl5/callback/index.html
      @@ -0,0 +1,20 @@
      +
      +
      +SWIG:Examples:perl5:callback
      +
      +
      +
      +
      +
      +SWIG/Examples/perl/callback/
      +
      + +

      Implementing C++ callbacks in Perl

      + +

      +This example illustrates how to use directors to implement C++ callbacks. +

      + +
      + + diff --git a/Examples/perl5/callback/runme.pl b/Examples/perl5/callback/runme.pl new file mode 100644 index 000000000..54d86783a --- /dev/null +++ b/Examples/perl5/callback/runme.pl @@ -0,0 +1,48 @@ +# file: runme.pl + +# This file illustrates the cross language polymorphism using directors. + +use example; + + +{ + package PlCallback; + use base 'example::Callback'; + sub run { + print "PlCallback->run()\n"; + } +} + +# Create an Caller instance + +$caller = example::Caller->new(); + +# Add a simple C++ callback (caller owns the callback, so +# we disown it first by clearing the .thisown flag). + +print "Adding and calling a normal C++ callback\n"; +print "----------------------------------------\n"; + +$callback = example::Callback->new(); +$callback->DISOWN(); +$caller->setCallback($callback); +$caller->call(); +$caller->delCallback(); + +print "\n"; +print "Adding and calling a Perl callback\n"; +print "----------------------------------\n"; + +# Add a Perl callback (caller owns the callback, so we +# disown it first by calling DISOWN). + +$callback = PlCallback->new(); +$callback->DISOWN(); +$caller->setCallback($callback); +$caller->call(); +$caller->delCallback(); + +# All done. + +print "\n"; +print "perl exit\n"; diff --git a/Examples/perl5/check.list b/Examples/perl5/check.list index e15f02e18..dda849311 100644 --- a/Examples/perl5/check.list +++ b/Examples/perl5/check.list @@ -1,7 +1,9 @@ # see top-level Makefile.in +callback class constants constants2 +extend funcptr import java diff --git a/Examples/perl5/class/Makefile b/Examples/perl5/class/Makefile index 544d13642..0d1cc574f 100644 --- a/Examples/perl5/class/Makefile +++ b/Examples/perl5/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/class/example.cxx b/Examples/perl5/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/perl5/class/example.cxx +++ b/Examples/perl5/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/perl5/class/example.h b/Examples/perl5/class/example.h index b0671d583..fd6943541 100644 --- a/Examples/perl5/class/example.h +++ b/Examples/perl5/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,29 +19,24 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; typedef Square TSquare; class CFoo { public: - static Square MakeSquare(void) {return Square(4.0);}; - static TSquare MakeTSquare(void) {return Square(4.0);}; + static Square MakeSquare(void) {return Square(4.0);} + static TSquare MakeTSquare(void) {return Square(4.0);} }; - - - - - diff --git a/Examples/perl5/class/example.i b/Examples/perl5/class/example.i index 23ee8a822..fbdf7249f 100644 --- a/Examples/perl5/class/example.i +++ b/Examples/perl5/class/example.i @@ -6,6 +6,4 @@ %} /* Let's just grab the original header file here */ - %include "example.h" - diff --git a/Examples/perl5/class/index.html b/Examples/perl5/class/index.html index 58a50ad2e..b4f923b5a 100644 --- a/Examples/perl5/class/index.html +++ b/Examples/perl5/class/index.html @@ -32,8 +32,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +44,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +53,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -82,7 +82,7 @@ like this: Note: when creating a C++ extension, you must run SWIG with the -c++ option like this:
      -% swig -c++ -python example.i
      +% swig -c++ -perl example.i
       
      @@ -97,60 +97,45 @@ Click here to see a script that calls the C++ functions f
      -$c = example::new_Circle(10.0);
      +$c = new example::Circle(10.0);
       

      -

    • To access member data, a pair of accessor functions are used. -For example: +
    • You can access member data like so:
      -example::Shape_x_set($c,15);    # Set member data
      -$x = example::Shape_x_get($c);   # Get member data
      -
      -
      - -Note: when accessing member data, the name of the class in which -the data member is defined is used. For example Shape_x_get(). - -

      -

    • To invoke a member function, you simply do this - -
      -
      -print "The area is ", example::Shape_area($c);
      +$c->{x} = 15;    # Set member data
      +$x = $c->{x};    # Get member data
       

      -

    • Type checking knows about the inheritance structure of C++. For example: +
    • To invoke a member function, you simply do this:
      -example::Shape_area($c);       # Works (c is a Shape)
      -example::Circle_area($c);      # Works (c is a Circle)
      -example::Square_area($c);      # Fails (c is definitely not a Square)
      +print "The area is ", $c->area();
       

      -

    • To invoke a destructor, simply do this +
    • To invoke a destructor, simply do this:
      -example::delete_Shape($c);     # Deletes a shape
      +$c->DESTROY();   # Deletes a shape
       

      -

    • Static member variables are wrapped as C global variables. For example: +
    • Static member variables are wrapped like so:
      -$n = $example::Shape_nshapes;     # Get a static data member
      -$example::Shapes_nshapes = 13;   # Set a static data member
      +$n = $example::Shape::nshapes;    # Get a static data member
      +$example::Shapes::nshapes = 13;   # Set a static data member
       
      @@ -159,47 +144,11 @@ $example::Shapes_nshapes = 13; # Set a static data member

      General Comments

        -
      • This low-level interface is not the only way to handle C++ code. Proxy classes -provide a much higher-level interface. - -

        -

      • SWIG *does* know how to properly perform upcasting of objects in an inheritance +
      • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass an object of a derived class to any function involving a base class. -

        -

      • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

        -

          -
        • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
          -
          -void foo(int a);  
          -%name(foo2) void foo(double a, double b);
          -
          -
          - -

          -

        • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
          -
          -%inline %{
          -    Vector *vector_add(Vector *a, Vector *b) {
          -          ... whatever ...
          -    }
          -%}
          -
          -
          - -

          -

        • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). +
        • C++ Namespaces - %nspace isn't yet supported for Perl.
        diff --git a/Examples/perl5/class/runme.pl b/Examples/perl5/class/runme.pl index 076e1437b..e45e2b8ce 100644 --- a/Examples/perl5/class/runme.pl +++ b/Examples/perl5/class/runme.pl @@ -40,7 +40,7 @@ foreach $o ($c,$s) { print " $o\n"; print " area = ", $o->area(), "\n"; print " perimeter = ", $o->perimeter(), "\n"; - } +} # ----- Delete everything ----- diff --git a/Examples/perl5/constants/Makefile b/Examples/perl5/constants/Makefile index 899282913..b7b411534 100644 --- a/Examples/perl5/constants/Makefile +++ b/Examples/perl5/constants/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/constants2/Makefile b/Examples/perl5/constants2/Makefile index 2ed10d733..85dd13741 100644 --- a/Examples/perl5/constants2/Makefile +++ b/Examples/perl5/constants2/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i SWIGOPT = -const check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/extend/Makefile b/Examples/perl5/extend/Makefile new file mode 100644 index 000000000..0d1cc574f --- /dev/null +++ b/Examples/perl5/extend/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +LIBS = -lm + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/extend/example.cxx b/Examples/perl5/extend/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/perl5/extend/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/perl5/extend/example.h b/Examples/perl5/extend/example.h new file mode 100644 index 000000000..ca1aed28f --- /dev/null +++ b/Examples/perl5/extend/example.h @@ -0,0 +1,56 @@ +/* File : example.h */ + +#include +#include +#include +#include +#include + +class Employee { +private: + std::string name; +public: + Employee(const char* n): name(n) {} + virtual std::string getTitle() { return getPosition() + " " + getName(); } + virtual std::string getName() { return name; } + virtual std::string getPosition() const { return "Employee"; } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } +}; + + +class Manager: public Employee { +public: + Manager(const char* n): Employee(n) {} + virtual std::string getPosition() const { return "Manager"; } +}; + + +class EmployeeList { + std::vector list; +public: + EmployeeList() { + list.push_back(new Employee("Bob")); + list.push_back(new Employee("Jane")); + list.push_back(new Manager("Ted")); + } + void addEmployee(Employee *p) { + list.push_back(p); + std::cout << "New employee added. Current employees are:" << std::endl; + std::vector::iterator i; + for (i=list.begin(); i!=list.end(); i++) { + std::cout << " " << (*i)->getTitle() << std::endl; + } + } + const Employee *get_item(int i) { + return list[i]; + } + ~EmployeeList() { + std::vector::iterator i; + std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; + for (i=list.begin(); i!=list.end(); i++) { + delete *i; + } + std::cout << "~EmployeeList empty." << std::endl; + } +}; + diff --git a/Examples/perl5/extend/example.i b/Examples/perl5/extend/example.i new file mode 100644 index 000000000..f5e142b88 --- /dev/null +++ b/Examples/perl5/extend/example.i @@ -0,0 +1,20 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_vector.i" +%include "std_string.i" + +/* turn on director wrapping for Manager */ +%feature("director") Employee; +%feature("director") Manager; + +/* EmployeeList::addEmployee(Employee *p) gives ownership of the + * employee to the EmployeeList object. The wrapper code should + * understand this. */ +%apply SWIGTYPE *DISOWN { Employee *p }; + +%include "example.h" + diff --git a/Examples/perl5/extend/index.html b/Examples/perl5/extend/index.html new file mode 100644 index 000000000..e9d886bcf --- /dev/null +++ b/Examples/perl5/extend/index.html @@ -0,0 +1,19 @@ + + +SWIG:Examples:perl5:extend + + + + + +SWIG/Examples/perl5/extend/ +
        + +

        Extending a simple C++ class

        + +

        +This example illustrates the extending of a C++ class with cross language polymorphism. + +


        + + diff --git a/Examples/perl5/extend/runme.pl b/Examples/perl5/extend/runme.pl new file mode 100644 index 000000000..76ee849a4 --- /dev/null +++ b/Examples/perl5/extend/runme.pl @@ -0,0 +1,79 @@ +# file: runme.pl + +# This file illustrates the cross language polymorphism using directors. + +use example; + + +# CEO class, which overrides Employee::getPosition(). + +{ + package CEO; + use base 'example::Manager'; + sub getPosition { + return "CEO"; + } +} + + +# Create an instance of our employee extension class, CEO. The calls to +# getName() and getPosition() are standard, the call to getTitle() uses +# the director wrappers to call CEO->getPosition. $e = CEO->new("Alice") + +$e = CEO->new("Alice"); +print $e->getName(), " is a ", $e->getPosition(), "\n"; +printf "Just call her \"%s\"\n", $e->getTitle(); +print "----------------------\n"; + + +# 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 = example::EmployeeList->new(); + +# EmployeeList owns its items, so we must surrender ownership of objects +# we add. This involves calling the DISOWN method to tell the +# C++ director to start reference counting. + +$e->DISOWN(); +$list->addEmployee($e); +print "----------------------\n"; + +# Now we access the first four items in list (three are C++ objects that +# EmployeeList's constructor adds, the last is our CEO). The virtual +# methods of all these instances are treated the same. For items 0, 1, and +# 2, both all methods resolve in C++. For item 3, our CEO, getTitle calls +# getPosition which resolves in Perl. The call to getPosition is +# slightly different, however, from the $e->getPosition() call above, since +# now the object reference has been "laundered" by passing through +# EmployeeList as an Employee*. Previously, Perl resolved the call +# immediately in CEO, but now Perl thinks the object is an instance of +# class Employee (actually EmployeePtr). So the call passes through the +# Employee proxy class and on to the C wrappers and C++ director, +# eventually ending up back at the 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 Perl implementation +# in CEO. All this routing takes place transparently. + +print "(position, title) for items 0-3:\n"; + +printf " %s, \"%s\"\n", $list->get_item(0)->getPosition(), $list->get_item(0)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(1)->getPosition(), $list->get_item(1)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(2)->getPosition(), $list->get_item(2)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(3)->getPosition(), $list->get_item(3)->getTitle(); +print "----------------------\n"; + +# Time to delete the EmployeeList, which will delete all the Employee* +# items it contains. The last item is our CEO, which gets destroyed as its +# reference count goes to zero. The Perl destructor runs, and is still +# able to call self.getName() since the underlying C++ object still +# exists. After this destructor runs the remaining C++ destructors run as +# usual to destroy the object. + +undef $list; +print "----------------------\n"; + +# All done. + +print "perl exit\n"; diff --git a/Examples/perl5/funcptr/Makefile b/Examples/perl5/funcptr/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/funcptr/Makefile +++ b/Examples/perl5/funcptr/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/import/Makefile b/Examples/perl5/import/Makefile index baa8277fd..b31ab7952 100644 --- a/Examples/perl5/import/Makefile +++ b/Examples/perl5/import/Makefile @@ -4,17 +4,17 @@ SWIGOPT = LIBS = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='baseclass' INTERFACE='base.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' perl5_cpp clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/index.html b/Examples/perl5/index.html index db46023c4..23c8ff658 100644 --- a/Examples/perl5/index.html +++ b/Examples/perl5/index.html @@ -20,6 +20,8 @@ certain C declarations are turned into constants.
      • reference. C++ references.
      • pointer. Simple pointer handling.
      • funcptr. Pointers to functions. +
      • callback. C++ callbacks using directors. +
      • extend. Extending a simple C++ class.

      Compilation Issues

      diff --git a/Examples/perl5/inline/Makefile b/Examples/perl5/inline/Makefile index d544a6532..5c98748c1 100644 --- a/Examples/perl5/inline/Makefile +++ b/Examples/perl5/inline/Makefile @@ -1,6 +1,6 @@ run: - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean rm -rf _Inline diff --git a/Examples/perl5/java/Makefile b/Examples/perl5/java/Makefile index b007cfdbb..5eaea3212 100644 --- a/Examples/perl5/java/Makefile +++ b/Examples/perl5/java/Makefile @@ -1,22 +1,22 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run -build: Example.class - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \ +build: Example.class Example.h + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ CXXSHARED="gcj -fpic -shared Example.class" PERL5_CCFLAGS='' PERL5_EXP='' LIBS="-lstdc++" perl5_cpp clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean - rm -f *.class Example.h + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean + rm -f *.class Example.h -Example.class: Example.java - gcj -fPIC -C -c -g Example.java - gcjh Example +Example.class Example.h: $(SRCDIR)Example.java + gcj -d . -fPIC -C -c -g $(SRCDIR)Example.java + gcjh Example.class diff --git a/Examples/perl5/multimap/Makefile b/Examples/perl5/multimap/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/multimap/Makefile +++ b/Examples/perl5/multimap/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/multiple_inheritance/Makefile b/Examples/perl5/multiple_inheritance/Makefile index 18c3058f9..1fe5a51bb 100644 --- a/Examples/perl5/multiple_inheritance/Makefile +++ b/Examples/perl5/multiple_inheritance/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i -LIBS = +LIBS = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/pointer/Makefile b/Examples/perl5/pointer/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/pointer/Makefile +++ b/Examples/perl5/pointer/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/reference/Makefile b/Examples/perl5/reference/Makefile index d33dd89fe..a22f5a68d 100644 --- a/Examples/perl5/reference/Makefile +++ b/Examples/perl5/reference/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = -noproxy +SWIGOPT = -noproxy check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' SWIGOPT='$(SWIGOPT)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' SWIGOPT='$(SWIGOPT)' perl5_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/reference/example.cxx b/Examples/perl5/reference/example.cxx index 8a513bf49..9dbaed2ee 100644 --- a/Examples/perl5/reference/example.cxx +++ b/Examples/perl5/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/perl5/simple/Makefile b/Examples/perl5/simple/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/simple/Makefile +++ b/Examples/perl5/simple/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/value/Makefile b/Examples/perl5/value/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/value/Makefile +++ b/Examples/perl5/value/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/value/example.i b/Examples/perl5/value/example.i index 98fd60ed5..39663c6b8 100644 --- a/Examples/perl5/value/example.i +++ b/Examples/perl5/value/example.i @@ -26,7 +26,7 @@ Vector *new_Vector(double x, double y, double z) { } void vector_print(Vector *v) { - printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z); + printf("Vector %p = (%g, %g, %g)\n", (void *)v, v->x, v->y, v->z); } %} diff --git a/Examples/perl5/variables/Makefile b/Examples/perl5/variables/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/variables/Makefile +++ b/Examples/perl5/variables/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/variables/example.c b/Examples/perl5/variables/example.c index aa4ffe9b3..85685fe72 100644 --- a/Examples/perl5/variables/example.c +++ b/Examples/perl5/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + 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); } diff --git a/Examples/perl5/xmlstring/Makefile b/Examples/perl5/xmlstring/Makefile index df9dabd11..4f02d3ee4 100644 --- a/Examples/perl5/xmlstring/Makefile +++ b/Examples/perl5/xmlstring/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lxerces-c -lxerces-depdom -lm check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS=$(LIBS) CXX="g++ -g3" perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/xmlstring/xmlstring.i b/Examples/perl5/xmlstring/xmlstring.i index 3ef53169d..861e1b84d 100644 --- a/Examples/perl5/xmlstring/xmlstring.i +++ b/Examples/perl5/xmlstring/xmlstring.i @@ -93,6 +93,17 @@ SWIG_FromXMLChPtrAndSize(const XMLCh* input, size_t size) } } +%fragment("SWIG_XMLStringNLen","header") { +size_t +SWIG_XMLStringNLen(const XMLCh* s, size_t maxlen) +{ + const XMLCh *p; + for (p = s; maxlen-- && *p; p++) + ; + return p - s; +} +} + %init { if (!SWIG_UTF8Transcoder()) { croak("ERROR: XML::Xerces: INIT: Could not create UTF-8 transcoder"); @@ -106,6 +117,7 @@ SWIG_FromXMLChPtrAndSize(const XMLCh* input, size_t size) SWIG_AsXMLChPtrAndSize, SWIG_FromXMLChPtrAndSize, XERCES_CPP_NAMESPACE::XMLString::stringLen, + SWIG_XMLStringNLen, "", INT_MIN, INT_MAX); diff --git a/Examples/php/callback/Makefile b/Examples/php/callback/Makefile index 08b2710b2..3ad3999a5 100644 --- a/Examples/php/callback/Makefile +++ b/Examples/php/callback/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/class/Makefile b/Examples/php/class/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/class/Makefile +++ b/Examples/php/class/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/class/example.cxx b/Examples/php/class/example.cxx index f171f10e9..046304519 100644 --- a/Examples/php/class/example.cxx +++ b/Examples/php/class/example.cxx @@ -1,14 +1,7 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" -#include -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif - -int Shape::get_nshapes() { - return nshapes; -} +#define M_PI 3.14159265358979323846 /* Move the shape to a new location */ void Shape::move(double dx, double dy) { @@ -18,22 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -void Circle::set_radius( double r ) { - radius = r; -} - -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/php/class/example.h b/Examples/php/class/example.h index 02eaf7232..0dff185b2 100644 --- a/Examples/php/class/example.h +++ b/Examples/php/class/example.h @@ -10,10 +10,9 @@ public: } double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; - static int get_nshapes(); }; class Circle : public Shape { @@ -21,10 +20,8 @@ private: double radius; public: Circle(double r) : radius(r) { } - ~Circle() { } - void set_radius( double r ); - virtual double area(void); - virtual double perimeter(void); + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { @@ -32,7 +29,6 @@ private: double width; public: Square(double w) : width(w) { } - ~Square() { } - virtual double area(void); - virtual double perimeter(void); + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/php/class/example.i b/Examples/php/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/php/class/example.i +++ b/Examples/php/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/php/class/runme.php b/Examples/php/class/runme.php index 12b686052..99c253b46 100644 --- a/Examples/php/class/runme.php +++ b/Examples/php/class/runme.php @@ -14,7 +14,7 @@ print " Created square\n"; # ----- Access a static member ----- -print "\nA total of " . Shape::get_nshapes() . " shapes were created\n"; +print "\nA total of " . Shape::nshapes() . " shapes were created\n"; # ----- Member data access ----- @@ -54,7 +54,7 @@ $s = NULL; # the square. $o = NULL; -print Shape::get_nshapes() . " shapes remain\n"; +print Shape::nshapes() . " shapes remain\n"; print "Goodbye\n"; ?> diff --git a/Examples/php/constants/Makefile b/Examples/php/constants/Makefile index 3f24a3921..e5b49571e 100644 --- a/Examples/php/constants/Makefile +++ b/Examples/php/constants/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/cpointer/Makefile b/Examples/php/cpointer/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/cpointer/Makefile +++ b/Examples/php/cpointer/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/cpointer/example.c b/Examples/php/cpointer/example.c index 3326dec3e..04dd08df0 100644 --- a/Examples/php/cpointer/example.c +++ b/Examples/php/cpointer/example.c @@ -1,6 +1,6 @@ /* File : example.c */ -void add(double *x, double *y, double *result) { +void add(int *x, int *y, int *result) { *result = *x + *y; } diff --git a/Examples/php/disown/Makefile b/Examples/php/disown/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/disown/Makefile +++ b/Examples/php/disown/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/enum/Makefile b/Examples/php/enum/Makefile index 22f979d2f..2028d03c7 100644 --- a/Examples/php/enum/Makefile +++ b/Examples/php/enum/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = -noproxy check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/extend/Makefile b/Examples/php/extend/Makefile index 08b2710b2..3ad3999a5 100644 --- a/Examples/php/extend/Makefile +++ b/Examples/php/extend/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/extend/example.h b/Examples/php/extend/example.h index b27ab9711..ca1aed28f 100644 --- a/Examples/php/extend/example.h +++ b/Examples/php/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/php/funcptr/Makefile b/Examples/php/funcptr/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/funcptr/Makefile +++ b/Examples/php/funcptr/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/overloading/Makefile b/Examples/php/overloading/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/overloading/Makefile +++ b/Examples/php/overloading/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/pointer/Makefile b/Examples/php/pointer/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/pointer/Makefile +++ b/Examples/php/pointer/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/pointer/runme.php b/Examples/php/pointer/runme.php index 5e86de6a2..e79b23810 100644 --- a/Examples/php/pointer/runme.php +++ b/Examples/php/pointer/runme.php @@ -15,7 +15,7 @@ print " c = $c\n"; # Call the add() function wuth some pointers - add(&$a,&$b,&$c); + add($a,$b,$c); print " $a + $b = $c\n"; diff --git a/Examples/php/pragmas/Makefile b/Examples/php/pragmas/Makefile index 3f24a3921..e5b49571e 100644 --- a/Examples/php/pragmas/Makefile +++ b/Examples/php/pragmas/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/pragmas/runme.php b/Examples/php/pragmas/runme.php old mode 100755 new mode 100644 diff --git a/Examples/php/proxy/Makefile b/Examples/php/proxy/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/proxy/Makefile +++ b/Examples/php/proxy/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/reference/Makefile b/Examples/php/reference/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/reference/Makefile +++ b/Examples/php/reference/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/reference/example.cxx b/Examples/php/reference/example.cxx index 13e47eade..7ead7fbf6 100644 --- a/Examples/php/reference/example.cxx +++ b/Examples/php/reference/example.cxx @@ -19,23 +19,23 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::as_string() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } VectorArray::VectorArray(int size) { items = new Vector[size]; maxsize = size; - printf("VectorArray new: self=%p\n",this); + printf("VectorArray new: self=%p\n", (void *)this); } VectorArray::~VectorArray() { - printf("VectorArray delete: self=%p\n",this); + printf("VectorArray delete: self=%p\n", (void *)this); delete [] items; } Vector &VectorArray::operator[](int index) { - printf("VectorArray: read[%d] self=%p\n",index,this); + printf("VectorArray: read[%d] self=%p\n", index, (void *)this); if ((index < 0) || (index >= maxsize)) { printf("Panic! Array index out of bounds.\n"); exit(1); @@ -44,6 +44,6 @@ Vector &VectorArray::operator[](int index) { } int VectorArray::size() { - printf("VectorArray: size %d self=%p\n",maxsize,this); + printf("VectorArray: size %d self=%p\n", maxsize, (void *)this); return maxsize; } diff --git a/Examples/php/reference/example.i b/Examples/php/reference/example.i index d6122866b..a372439b1 100644 --- a/Examples/php/reference/example.i +++ b/Examples/php/reference/example.i @@ -37,7 +37,7 @@ public: /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { - printf("VectorArray extended get: %p %d\n",$self,index); + printf("VectorArray extended get: %p %d\n", (void *)$self, index); return (*$self)[index]; } void set(int index, Vector &a) { diff --git a/Examples/php/simple/Makefile b/Examples/php/simple/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/simple/Makefile +++ b/Examples/php/simple/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/simple/runme.php b/Examples/php/simple/runme.php old mode 100755 new mode 100644 diff --git a/Examples/php/sync/Makefile b/Examples/php/sync/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/sync/Makefile +++ b/Examples/php/sync/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/sync/example.cxx b/Examples/php/sync/example.cxx index 31ed2021b..0942279b2 100644 --- a/Examples/php/sync/example.cxx +++ b/Examples/php/sync/example.cxx @@ -10,4 +10,4 @@ void Sync::printer(void) { printf("The value of global x is %d\n", x); printf("The value of class s is %s\n", s); printf("The value of class x is %d\n", x); -}; +} diff --git a/Examples/php/value/Makefile b/Examples/php/value/Makefile index 449686784..3db7afec5 100644 --- a/Examples/php/value/Makefile +++ b/Examples/php/value/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = -noproxy check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/value/example.i b/Examples/php/value/example.i index 386fa3b84..20a453468 100644 --- a/Examples/php/value/example.i +++ b/Examples/php/value/example.i @@ -11,7 +11,7 @@ %inline %{ void vector_print(Vector *v) { - printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z); + printf("Vector %p = (%g, %g, %g)\n", (void *)v, v->x, v->y, v->z); } %} diff --git a/Examples/php/variables/Makefile b/Examples/php/variables/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/variables/Makefile +++ b/Examples/php/variables/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/variables/example.c b/Examples/php/variables/example.c index 3114c7c5f..d4c6d026d 100644 --- a/Examples/php/variables/example.c +++ b/Examples/php/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %c%c%c%c%c\n", name[0],name[1],name[2],name[3],name[4]); - printf("ptptr = %p %s\n", ptptr, Point_print( ptptr ) ); + printf("ptptr = %p %s\n", (void *)ptptr, Point_print( ptptr ) ); printf("pt = (%d, %d)\n", pt.x, pt.y); printf("status = %d\n", status); } diff --git a/Examples/pike/class/Makefile b/Examples/pike/class/Makefile index aadc47151..d8cf4ea7e 100644 --- a/Examples/pike/class/Makefile +++ b/Examples/pike/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/class/example.cxx b/Examples/pike/class/example.cxx index c7a3194a4..046304519 100644 --- a/Examples/pike/class/example.cxx +++ b/Examples/pike/class/example.cxx @@ -1,46 +1,28 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" - -#include - #define M_PI 3.14159265358979323846 -// Static member initializer -int Shape::nshapes = 0; - -// Constructor -Shape::Shape() { - nshapes++; -} - -// Move the shape to a new location +/* Move the shape to a new location */ void Shape::move(double dx, double dy) { x += dx; y += dy; } -// Destructor -Shape::~Shape() { - nshapes--; -} +int Shape::nshapes = 0; -// Circle area -double Circle::area() const { +double Circle::area() { return M_PI*radius*radius; } -// Circle perimeter -double Circle::perimeter() const { +double Circle::perimeter() { return 2*M_PI*radius; } -// Square area -double Square::area() const { +double Square::area() { return width*width; } -// Square perimeter -double Square::perimeter() const { +double Square::perimeter() { return 4*width; } diff --git a/Examples/pike/class/example.h b/Examples/pike/class/example.h index f74a4fefc..0dff185b2 100644 --- a/Examples/pike/class/example.h +++ b/Examples/pike/class/example.h @@ -2,12 +2,16 @@ class Shape { public: - Shape(); - virtual ~Shape(); - double x, y; + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + } + double x, y; void move(double dx, double dy); - virtual double area() const = 0; - virtual double perimeter() const = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -15,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area() const; - virtual double perimeter() const; + 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() const; - virtual double perimeter() const; + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/pike/class/example.i b/Examples/pike/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/pike/class/example.i +++ b/Examples/pike/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/pike/class/runme.pike b/Examples/pike/class/runme.pike old mode 100755 new mode 100644 diff --git a/Examples/pike/constants/Makefile b/Examples/pike/constants/Makefile index 9a882bd4d..736d30f03 100644 --- a/Examples/pike/constants/Makefile +++ b/Examples/pike/constants/Makefile @@ -1,19 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/constants/runme.pike b/Examples/pike/constants/runme.pike old mode 100755 new mode 100644 diff --git a/Examples/pike/enum/Makefile b/Examples/pike/enum/Makefile index aadc47151..d8cf4ea7e 100644 --- a/Examples/pike/enum/Makefile +++ b/Examples/pike/enum/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/overload/Makefile b/Examples/pike/overload/Makefile index 8d799efe1..f111b1137 100644 --- a/Examples/pike/overload/Makefile +++ b/Examples/pike/overload/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lstdc++ -lm check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/simple/Makefile b/Examples/pike/simple/Makefile index f58ed4e65..d7f6b209e 100644 --- a/Examples/pike/simple/Makefile +++ b/Examples/pike/simple/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/template/Makefile b/Examples/pike/template/Makefile index 73a31ee1a..da115c1d5 100644 --- a/Examples/pike/template/Makefile +++ b/Examples/pike/template/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/template/runme.pike b/Examples/pike/template/runme.pike old mode 100755 new mode 100644 diff --git a/Examples/python/callback/Makefile b/Examples/python/callback/Makefile index 21e88adc5..a4c4d2a69 100644 --- a/Examples/python/callback/Makefile +++ b/Examples/python/callback/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/callback/runme.py b/Examples/python/callback/runme.py index 026e9520b..ddb668407 100644 --- a/Examples/python/callback/runme.py +++ b/Examples/python/callback/runme.py @@ -42,7 +42,7 @@ print print "Adding and calling another Python callback" print "------------------------------------------" -# Lets do the same but use the weak reference this time. +# Let's do the same but use the weak reference this time. callback = PyCallback().__disown__() caller.setCallback(callback) diff --git a/Examples/python/check.list b/Examples/python/check.list index 7cfe437f0..e9e7c8357 100644 --- a/Examples/python/check.list +++ b/Examples/python/check.list @@ -13,6 +13,7 @@ funcptr2 functor import import_template +import_packages java #libffi multimap diff --git a/Examples/python/class/Makefile b/Examples/python/class/Makefile index e940c1f43..41cded284 100644 --- a/Examples/python/class/Makefile +++ b/Examples/python/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/class/example.cxx b/Examples/python/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/python/class/example.cxx +++ b/Examples/python/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/python/class/example.h b/Examples/python/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/python/class/example.h +++ b/Examples/python/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/python/class/example.i b/Examples/python/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/python/class/example.i +++ b/Examples/python/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/python/class/index.html b/Examples/python/class/index.html index 12c5eded1..2e1baa395 100644 --- a/Examples/python/class/index.html +++ b/Examples/python/class/index.html @@ -12,9 +12,7 @@

      Wrapping a simple C++ class

      -This example illustrates the most primitive form of C++ class wrapping performed -by SWIG. In this case, C++ classes are simply transformed into a collection of -C-style functions that provide access to class members. +This example illustrates wrapping a simple C++ class to give a Python class.

      The C++ Code

      @@ -32,8 +30,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +42,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +51,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -102,51 +100,34 @@ c = example.new_Circle(10.0)
    • -

    • To access member data, a pair of accessor functions are used. +
    • Member variables of the C++ class are wrapped as attributes of the Python class. For example:
      -example.Shape_x_set(c,15)    # Set member data
      -x = example.Shape_x_get(c)    # Get member data
      -
      -
      - -Note: when accessing member data, the name of the class in which -the member data was must be used. In this case, Shape_x_get() -and Shape_x_set() are used since 'x' was defined in Shape. - -

      -

    • To invoke a member function, you simply do this - -
      -
      -print "The area is ", example.Shape_area(c)
      +c.x = 15   # Set member data
      +x = c.x    # Get member data
       

      -

    • Type checking knows about the inheritance structure of C++. For example: +
    • Member function are invoked as you would expect:
      -example.Shape_area(c)       # Works (c is a Shape)
      -example.Circle_area(c)      # Works (c is a Circle)
      -example.Square_area(c)      # Fails (c is definitely not a Square)
      +print "The area is ", c.area()
       

      -

    • To invoke a destructor, simply do this +
    • To invoke a destructor, simply call del on the object:
      -example.delete_Shape(c)     # Deletes a shape
      +del c    # Deletes a shape
       
      -(Note: destructors are currently not inherited. This might change later). -

    • Static member variables are wrapped as C global variables. For example: @@ -162,52 +143,12 @@ example.cvar.Shapes_nshapes = 13 # Set a static data member

      General Comments

        -
      • This low-level interface is not the only way to handle C++ code. -Proxy classes provide a much higher-level interface. - -

        -

      • SWIG *does* know how to properly perform upcasting of objects in +
      • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass an object of a derived class to any function involving a base class. -

        -

      • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

        -

          -
        • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
          -
          -void foo(int a);  
          -%name(foo2) void foo(double a, double b);
          -
          -
          - -

          -

        • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
          -
          -%inline %{
          -    Vector *vector_add(Vector *a, Vector *b) {
          -          ... whatever ...
          -    }
          -%}
          -
          -
          - -

          -

        • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). - -

          -

        • Dave's snide remark: Like a large bottle of strong Tequilla, it's better to -use C++ in moderation. +
        • C++ Namespaces - %nspace isn't yet supported for Python.
        diff --git a/Examples/python/class/runme.py b/Examples/python/class/runme.py index f1272ae81..8f4f27eb9 100644 --- a/Examples/python/class/runme.py +++ b/Examples/python/class/runme.py @@ -38,6 +38,8 @@ 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 print "\nGuess I'll clean up now" @@ -45,7 +47,5 @@ print "\nGuess I'll clean up now" del c del s -s = 3 print example.cvar.Shape_nshapes,"shapes remain" print "Goodbye" - diff --git a/Examples/python/constants/Makefile b/Examples/python/constants/Makefile index 505f199de..8ec6e9cc9 100644 --- a/Examples/python/constants/Makefile +++ b/Examples/python/constants/Makefile @@ -1,19 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/contract/Makefile b/Examples/python/contract/Makefile index a44887736..fe1d9325e 100644 --- a/Examples/python/contract/Makefile +++ b/Examples/python/contract/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/docstrings/Makefile b/Examples/python/docstrings/Makefile index 51552f3cf..f471930dd 100644 --- a/Examples/python/docstrings/Makefile +++ b/Examples/python/docstrings/Makefile @@ -7,17 +7,17 @@ LIBS = -lm SWIGOPT = -O check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/enum/Makefile b/Examples/python/enum/Makefile index e940c1f43..41cded284 100644 --- a/Examples/python/enum/Makefile +++ b/Examples/python/enum/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/exception/Makefile b/Examples/python/exception/Makefile index b2b163e2e..ad3d49fe1 100644 --- a/Examples/python/exception/Makefile +++ b/Examples/python/exception/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/exceptproxy/Makefile b/Examples/python/exceptproxy/Makefile index 06bce6543..f406dfaf4 100644 --- a/Examples/python/exceptproxy/Makefile +++ b/Examples/python/exceptproxy/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/extend/Makefile b/Examples/python/extend/Makefile index 21e88adc5..a4c4d2a69 100644 --- a/Examples/python/extend/Makefile +++ b/Examples/python/extend/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/extend/example.h b/Examples/python/extend/example.h index b27ab9711..ca1aed28f 100644 --- a/Examples/python/extend/example.h +++ b/Examples/python/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/python/funcptr/Makefile b/Examples/python/funcptr/Makefile index df3bc86ff..222916fa1 100644 --- a/Examples/python/funcptr/Makefile +++ b/Examples/python/funcptr/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/funcptr2/Makefile b/Examples/python/funcptr2/Makefile index df3bc86ff..222916fa1 100644 --- a/Examples/python/funcptr2/Makefile +++ b/Examples/python/funcptr2/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/functor/Makefile b/Examples/python/functor/Makefile index 6ef158379..1234c310e 100644 --- a/Examples/python/functor/Makefile +++ b/Examples/python/functor/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/import/Makefile b/Examples/python/import/Makefile index f63e12271..d83dfeaa8 100644 --- a/Examples/python/import/Makefile +++ b/Examples/python/import/Makefile @@ -4,19 +4,19 @@ SWIGOPT = LIBS = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f foo.py bar.py spam.py base.py diff --git a/Examples/python/import_packages/Makefile b/Examples/python/import_packages/Makefile new file mode 100644 index 000000000..d5054fd22 --- /dev/null +++ b/Examples/python/import_packages/Makefile @@ -0,0 +1,45 @@ +TOP = ../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +import_packages_subdirs = \ + same_modnames1 \ + same_modnames2 \ + from_init1 \ + from_init2 \ + from_init3 \ + relativeimport1 \ + relativeimport1 + +check: build + if test "x$(SRCDIR)" != x; then \ + for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \ + cp "${SRCDIR}$$file" "$$file" || exit 1; \ + done; \ + fi; \ + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) check); \ + done + +build: + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \ + done + +static: + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \ + done + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + if test "x$(SRCDIR)" != x; then \ + for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \ + rm -f "$$file" || exit 1; \ + done; \ + fi; \ + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) clean); \ + done diff --git a/Examples/python/import_packages/README b/Examples/python/import_packages/README new file mode 100644 index 000000000..69fe3516e --- /dev/null +++ b/Examples/python/import_packages/README @@ -0,0 +1,2 @@ +These are actually regression tests for SF bug #1297 (GH issue #7). +See individual READMEs in subdirectories. diff --git a/Examples/python/import_packages/from_init1/Makefile b/Examples/python/import_packages/from_init1/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/from_init1/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/README b/Examples/python/import_packages/from_init1/README new file mode 100644 index 000000000..e7d7eca9e --- /dev/null +++ b/Examples/python/import_packages/from_init1/README @@ -0,0 +1,63 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/foo.i - Pkg2_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg2_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module (we + import Pkg2_Bar class, but it is not the clue, + the clue is the 'from' keyword) + +For example with python2.x the py2/pkg2/__init__.py imports Pkg2_Bar class +as follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig (swig 2.0.10, e.g.) to generate python import directives (SF bug #1297). +The generated file "py2/pkg2/bar.py" has following lines: + + import py2.pkg2.foo # [2] + class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo): # [3] + +but it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + +Traceback (most recent call last): + File "runme.py", line 3, in + import py2.pkg2 + File "py2/pkg2/__init__.py", line 7, in + from .bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo): + AttributeError: 'module' object has no attribute 'pkg2' + + +It seems like during the import [1], the sub-package pkg2 is not yet fully +initialized, so py2.pkg2 is not known. The above exception is raised at +line [3]. The problem disappears, for example, if we force swig to use relative +package names. + +If everything works well, the package py2.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init1/py2/Makefile b/Examples/python/import_packages/from_init1/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/py2/__init__.py b/Examples/python/import_packages/from_init1/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/Makefile b/Examples/python/import_packages/from_init1/py2/pkg2/Makefile new file mode 100644 index 000000000..1eb810e05 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/Makefile @@ -0,0 +1,20 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean:: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp new file mode 100644 index 000000000..b369161d3 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/foo.hpp" +struct Pkg2_Bar : Pkg2_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/bar.i b/Examples/python/import_packages/from_init1/py2/pkg2/bar.i new file mode 100644 index 000000000..0795a7751 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp b/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp new file mode 100644 index 000000000..fed8239f6 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_FOO_HPP +#define PY2_PKG2_FOO_HPP +struct Pkg2_Foo {}; +#endif /* PY2_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/foo.i b/Examples/python/import_packages/from_init1/py2/pkg2/foo.i new file mode 100644 index 000000000..37b2e1f82 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2") foo +%{ +#include "../../py2/pkg2/foo.hpp" +%} +%include "../../py2/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/from_init1/py3/Makefile b/Examples/python/import_packages/from_init1/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/py3/__init__.py b/Examples/python/import_packages/from_init1/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/Makefile b/Examples/python/import_packages/from_init1/py3/pkg2/Makefile new file mode 100644 index 000000000..1eb810e05 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/Makefile @@ -0,0 +1,20 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean:: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp new file mode 100644 index 000000000..d16463dff --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/foo.hpp" +struct Pkg2_Bar : Pkg2_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/bar.i b/Examples/python/import_packages/from_init1/py3/pkg2/bar.i new file mode 100644 index 000000000..8d8d627b9 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp b/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp new file mode 100644 index 000000000..c2469dc86 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_FOO_HPP +#define PY3_PKG2_FOO_HPP +struct Pkg2_Foo {}; +#endif /* PY3_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/foo.i b/Examples/python/import_packages/from_init1/py3/pkg2/foo.i new file mode 100644 index 000000000..76613b593 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2") foo +%{ +#include "../../py3/pkg2/foo.hpp" +%} +%include "../../py3/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/from_init1/runme.py b/Examples/python/import_packages/from_init1/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init1/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + 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 new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/from_init2/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/README b/Examples/python/import_packages/from_init2/README new file mode 100644 index 000000000..a0eb41839 --- /dev/null +++ b/Examples/python/import_packages/from_init2/README @@ -0,0 +1,81 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/foo.i - Pkg3_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module + +For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as +follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig to generate python import directives (SF bug #1297). The generated file +"py2/pkg2/bar.py" has following lines: + + import py2.pkg2.pkg3.foo # [2] + class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo): # [3] + +and it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + +Traceback (most recent call last): + File "runme.py", line 3, in + import py2.pkg2 + File "py2/pkg2/__init__.py", line 4, in + from bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo): +AttributeError: 'module' object has no attribute 'pkg2' + +It seems like during the import [1], the subpackage pkg2 is not yet fully +initialized, so pyX.pkg2 is not known. The above exception is raised at line [3]. +The problem disappears, for example, if we force swig to use relative package +names. + +The difference between this ('from_init2') case and the case +'from_init1' is that here it's not sufficient to import relative module +by just ignoring the package part of the fully qualified module name. IOW +it is not correct to force swig to put: + + import foo + class Pkg2_Bar(foo.Pkg3_Foo) + +into pyX/pkg2/bar.py (note, that this would work for 'from_init1' case). +The import directive shall be rather: + + import pkg3.foo + +for python 2.x and: + + from . import pkg3 + import pkg3.foo + +for python 3, and the class definition shall begin with: + + class Pkg2_Bar(pkg3.foo.Pkg3_Foo) + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init2/py2/Makefile b/Examples/python/import_packages/from_init2/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py2/__init__.py b/Examples/python/import_packages/from_init2/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/Makefile b/Examples/python/import_packages/from_init2/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp new file mode 100644 index 000000000..8f09cd5fa --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/bar.i b/Examples/python/import_packages/from_init2/py2/pkg2/bar.i new file mode 100644 index 000000000..28a4c906e --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..b6c89a431 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_FOO_HPP +#define PY2_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY2_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i new file mode 100644 index 000000000..ba32483d2 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3") foo +%{ +#include "../../../py2/pkg2/pkg3/foo.hpp" +%} +%include "../../../py2/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/from_init2/py3/Makefile b/Examples/python/import_packages/from_init2/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py3/__init__.py b/Examples/python/import_packages/from_init2/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/Makefile b/Examples/python/import_packages/from_init2/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp new file mode 100644 index 000000000..408d910d7 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/bar.i b/Examples/python/import_packages/from_init2/py3/pkg2/bar.i new file mode 100644 index 000000000..1468932ff --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..531721d36 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_FOO_HPP +#define PY3_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY3_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i new file mode 100644 index 000000000..c6ba529b7 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3") foo +%{ +#include "../../../py3/pkg2/pkg3/foo.hpp" +%} +%include "../../../py3/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/from_init2/runme.py b/Examples/python/import_packages/from_init2/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init2/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + 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 new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/from_init3/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/README b/Examples/python/import_packages/from_init3/README new file mode 100644 index 000000000..131d5894c --- /dev/null +++ b/Examples/python/import_packages/from_init3/README @@ -0,0 +1,67 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/pkg4/foo.i - Pkg4_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg4_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module + +For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as +follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig to generate python import directives (SF bug 1297). The generated file +"py2/pkg2/bar.py" has following lines: + + import py2.pkg2.pkg3.pkg4.foo # [2] + class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.P1_S1_S2_Foo): # [3] + +and it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + + Traceback (most recent call last): + File "runme.py", line 3, in + import py2.pkg2 + File "py2/pkg2/__init__.py", line 4, in + from bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.Pkg4_Foo): + AttributeError: 'module' object has no attribute 'pkg2' + +It seems like during the import [1], the subpackage pkg2 is not yet fully +initialized, so py2.pkg2 can't be used. The above exception is raised at +line [3]. The problem disappears, for example, if we force swig to use relative +package names. + +The difference between this ('from_init3') case and the case +'from_init2' is that here we import base class from module +pyX.pkg2.pkg3.pkg4.foo, which is nested deeper than it was in +'from_init2'. This is just to ensure, that two (and more) levels of +subpackages get imported correctly by generated python code, i.e, not only +'pkg3.foo' is handled properly (one-level subpackage) but the code works also +for 'pkg3.pkg4.foo', and so on. + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init3/py2/Makefile b/Examples/python/import_packages/from_init3/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/__init__.py b/Examples/python/import_packages/from_init3/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp new file mode 100644 index 000000000..20a00190a --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_HPP +#define PY2_PKG2_HPP +#include "../../py2/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY2_PKG2_HPP */ diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/bar.i b/Examples/python/import_packages/from_init3/py2/pkg2/bar.i new file mode 100644 index 000000000..0a932a2b9 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/pkg4/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..d6ae1b2bc --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb 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 new file mode 100644 index 000000000..286d90070 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/py2/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..2df933c59 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_PKG4 +#define PY2_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY2_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..311d7161c --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/from_init3/py3/Makefile b/Examples/python/import_packages/from_init3/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/__init__.py b/Examples/python/import_packages/from_init3/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp new file mode 100644 index 000000000..16fdd362e --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_HPP +#define PY3_PKG2_HPP +#include "../../py3/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY3_PKG2_HPP */ diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/bar.i b/Examples/python/import_packages/from_init3/py3/pkg2/bar.i new file mode 100644 index 000000000..3abbb05d3 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/pkg4/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..d6ae1b2bc --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb 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 new file mode 100644 index 000000000..286d90070 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..e24654c28 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_PKG4 +#define PY3_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY3_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..36c5f01ea --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/from_init3/runme.py b/Examples/python/import_packages/from_init3/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init3/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/relativeimport1/Makefile b/Examples/python/import_packages/relativeimport1/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/README b/Examples/python/import_packages/relativeimport1/README new file mode 100644 index 000000000..a99ef2426 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/README @@ -0,0 +1,22 @@ +This example tests the %import directive and -relativeimport swig option. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/foo.i - Pkg3_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo + +The code is processed by swig with -relativeimport flag. The runtime test +imports pyX.pkg2.bar module. + +If everything works well, the module pyX.pkg2.bar shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/relativeimport1/py2/Makefile b/Examples/python/import_packages/relativeimport1/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py2/__init__.py b/Examples/python/import_packages/relativeimport1/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/__init__.py b/Examples/python/import_packages/relativeimport1/py2/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp new file mode 100644 index 000000000..8f09cd5fa --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i new file mode 100644 index 000000000..28a4c906e --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..b6c89a431 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_FOO_HPP +#define PY2_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY2_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i new file mode 100644 index 000000000..ba32483d2 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3") foo +%{ +#include "../../../py2/pkg2/pkg3/foo.hpp" +%} +%include "../../../py2/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py3/Makefile b/Examples/python/import_packages/relativeimport1/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py3/__init__.py b/Examples/python/import_packages/relativeimport1/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/__init__.py b/Examples/python/import_packages/relativeimport1/py3/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp new file mode 100644 index 000000000..408d910d7 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i new file mode 100644 index 000000000..1468932ff --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..531721d36 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_FOO_HPP +#define PY3_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY3_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i new file mode 100644 index 000000000..c6ba529b7 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3") foo +%{ +#include "../../../py3/pkg2/pkg3/foo.hpp" +%} +%include "../../../py3/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport1/runme.py b/Examples/python/import_packages/relativeimport1/runme.py new file mode 100644 index 000000000..44ce8d1c4 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) with -relativeimport" +import sys +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" diff --git a/Examples/python/import_packages/relativeimport2/Makefile b/Examples/python/import_packages/relativeimport2/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/README b/Examples/python/import_packages/relativeimport2/README new file mode 100644 index 000000000..af2d2840b --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/README @@ -0,0 +1,22 @@ +This example tests the %import directive and -relativeimport option. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/pkg4/foo.i - Pkg4_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg4_Foo + +The difference between this ('relativeimport2') case and the case +'relativeimport1' is the "distance" between importer and importee. + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/relativeimport2/py2/Makefile b/Examples/python/import_packages/relativeimport2/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/__init__.py b/Examples/python/import_packages/relativeimport2/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp new file mode 100644 index 000000000..20a00190a --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_HPP +#define PY2_PKG2_HPP +#include "../../py2/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY2_PKG2_HPP */ diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i new file mode 100644 index 000000000..0a932a2b9 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/pkg4/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..d6ae1b2bc --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..286d90070 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/py2/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..2df933c59 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_PKG4 +#define PY2_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY2_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..311d7161c --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py3/Makefile b/Examples/python/import_packages/relativeimport2/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/__init__.py b/Examples/python/import_packages/relativeimport2/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +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 + +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 + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp new file mode 100644 index 000000000..16fdd362e --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_HPP +#define PY3_PKG2_HPP +#include "../../py3/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY3_PKG2_HPP */ diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i new file mode 100644 index 000000000..3abbb05d3 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/pkg4/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..d6ae1b2bc --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..286d90070 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..e24654c28 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_PKG4 +#define PY3_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY3_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..36c5f01ea --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport2/runme.py b/Examples/python/import_packages/relativeimport2/runme.py new file mode 100644 index 000000000..ac60eb630 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +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" diff --git a/Examples/python/import_packages/relativeimport2/runme3.py b/Examples/python/import_packages/relativeimport2/runme3.py new file mode 100644 index 000000000..4b0d112cf --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/runme3.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print("Testing %module(package=...) + python 'import' in __init__.py") +import sys +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") diff --git a/Examples/python/import_packages/same_modnames1/Makefile b/Examples/python/import_packages/same_modnames1/Makefile new file mode 100644 index 000000000..e05c13017 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/Makefile @@ -0,0 +1,20 @@ +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 + +static: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg1 && $(MAKE) clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/same_modnames1/README b/Examples/python/import_packages/same_modnames1/README new file mode 100644 index 000000000..ee3f8d6f7 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/README @@ -0,0 +1,26 @@ +This example tests the %import directive and working with multiple modules. + +There are two modules having same name but belonging to different packages. +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pkg1/foo.i - Pkg1_Foo class. + pkg2/foo.i - Pkg2_Foo class (derived from Pkg1_Foo). + +The pkg2/foo.i module uses %import to refer to pkg1/foo.i. + +If everything works well, the module pkg2.foo shall load properly. + +Unix: +----- +- Run make +- Run the test as described above. diff --git a/Examples/python/import_packages/same_modnames1/pkg1/Makefile b/Examples/python/import_packages/same_modnames1/pkg1/Makefile new file mode 100644 index 000000000..df1b30321 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/pkg1/__init__.py b/Examples/python/import_packages/same_modnames1/pkg1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp b/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp new file mode 100644 index 000000000..b07c983b3 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PKG1_FOO_HPP +#define PKG1_FOO_HPP +struct Pkg1_Foo{}; +#endif /* PKG1_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames1/pkg1/foo.i b/Examples/python/import_packages/same_modnames1/pkg1/foo.i new file mode 100644 index 000000000..9939f420a --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/foo.i @@ -0,0 +1,5 @@ +%module(package="pkg1") foo +%{ +#include "../pkg1/foo.hpp" +%} +%include "../pkg1/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames1/pkg2/Makefile b/Examples/python/import_packages/same_modnames1/pkg2/Makefile new file mode 100644 index 000000000..df1b30321 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/__init__.py b/Examples/python/import_packages/same_modnames1/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp b/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp new file mode 100644 index 000000000..72563a9d0 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp @@ -0,0 +1,5 @@ +#ifndef PKG2_FOO_HPP +#define PKG2_FOO_HPP +#include "../pkg1/foo.hpp" +struct Pkg2_Foo : public Pkg1_Foo{}; +#endif /* PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames1/pkg2/foo.i b/Examples/python/import_packages/same_modnames1/pkg2/foo.i new file mode 100644 index 000000000..3a1ce0198 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/foo.i @@ -0,0 +1,6 @@ +%module(package="pkg2") foo +%{ +#include "../pkg2/foo.hpp" +%} +%import "../pkg1/foo.i" +%include "../pkg2/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames1/runme.py b/Examples/python/import_packages/same_modnames1/runme.py new file mode 100644 index 000000000..923f0e0bb --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/runme.py @@ -0,0 +1,9 @@ +# Test import of same modules from different packages +print "Testing %module(package=...) + %import + same modules in different packages" +import pkg2.foo +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))) +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 new file mode 100644 index 000000000..770343a80 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/Makefile @@ -0,0 +1,20 @@ +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 + +static: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg1/pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg1 && $(MAKE) clean + cd pkg1/pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/same_modnames2/README b/Examples/python/import_packages/same_modnames2/README new file mode 100644 index 000000000..9b0233f8b --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/README @@ -0,0 +1,26 @@ +This example tests the %import directive and working with multiple modules. + +There are two modules having same name but belonging to different packages. +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pkg1/foo.i - Pkg1_Foo class + pkg1/pkg2/foo.i - Pkg2_Foo class derived from Pkg1_Foo + +The pkg1/pkg2/foo module uses %import to refer to pkg1/foo. + +If everything works well, the module pkg1.pkg2.foo shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/same_modnames2/pkg1/Makefile b/Examples/python/import_packages/same_modnames2/pkg1/Makefile new file mode 100644 index 000000000..df1b30321 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/__init__.py b/Examples/python/import_packages/same_modnames2/pkg1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp b/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp new file mode 100644 index 000000000..b07c983b3 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PKG1_FOO_HPP +#define PKG1_FOO_HPP +struct Pkg1_Foo{}; +#endif /* PKG1_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames2/pkg1/foo.i b/Examples/python/import_packages/same_modnames2/pkg1/foo.i new file mode 100644 index 000000000..9939f420a --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/foo.i @@ -0,0 +1,5 @@ +%module(package="pkg1") foo +%{ +#include "../pkg1/foo.hpp" +%} +%include "../pkg1/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile new file mode 100644 index 000000000..11e8573ad --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(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='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/__init__.py b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp new file mode 100644 index 000000000..1b4a1d558 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp @@ -0,0 +1,5 @@ +#ifndef PKG1_PKG2_FOO_HPP +#define PKG1_PKG2_FOO_HPP +#include "../../pkg1/foo.hpp" +struct Pkg2_Foo : public Pkg1_Foo{}; +#endif /* PKG1_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i new file mode 100644 index 000000000..1741b3799 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i @@ -0,0 +1,6 @@ +%module(package="pkg1.pkg2") foo +%{ +#include "../../pkg1/pkg2/foo.hpp" +%} +%import "../../pkg1/foo.i" +%include "../../pkg1/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames2/runme.py b/Examples/python/import_packages/same_modnames2/runme.py new file mode 100644 index 000000000..af8f78194 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/runme.py @@ -0,0 +1,7 @@ +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))) +print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo" diff --git a/Examples/python/import_template/Makefile b/Examples/python/import_template/Makefile index f63e12271..d83dfeaa8 100644 --- a/Examples/python/import_template/Makefile +++ b/Examples/python/import_template/Makefile @@ -4,19 +4,19 @@ SWIGOPT = LIBS = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f foo.py bar.py spam.py base.py diff --git a/Examples/python/index.html b/Examples/python/index.html index 37f4b55af..3bbdd66e8 100644 --- a/Examples/python/index.html +++ b/Examples/python/index.html @@ -56,8 +56,7 @@ Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
    • The politically "correct" way to compile a Python extension is to follow the steps -described at www.python.org -or in the most excellent (and shamelessly plugged) Python Essential Reference: +described at www.python.org:

        diff --git a/Examples/python/java/Makefile b/Examples/python/java/Makefile index 47b865dd1..4befa38ba 100644 --- a/Examples/python/java/Makefile +++ b/Examples/python/java/Makefile @@ -1,23 +1,23 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run -build: Example.class - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \ +build: Example.class Example.h + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ CXXSHARED="gcj -fpic -shared Example.class" DEFS='' LIBS="-lstdc++" python_cpp clean: - $(MAKE) -f $(TOP)/Makefile python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean rm -f $(TARGET).py rm -f *.class Example.h -Example.class: Example.java - gcj -fPIC -C -c -g Example.java - gcjh Example - +Example.class Example.h: $(SRCDIR)Example.java + gcj -d . -fPIC -C -c -g $(SRCDIR)Example.java + gcjh Example.class diff --git a/Examples/python/java/example.i b/Examples/python/java/example.i index 13d5b5e70..80e08870f 100644 --- a/Examples/python/java/example.i +++ b/Examples/python/java/example.i @@ -7,3 +7,7 @@ %include Example.h + +%extend Example { + ~Example() {} +} diff --git a/Examples/python/libffi/Makefile b/Examples/python/libffi/Makefile index e0620f62d..db5dfe138 100644 --- a/Examples/python/libffi/Makefile +++ b/Examples/python/libffi/Makefile @@ -1,19 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-L/usr/local/lib -lffi' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/multimap/Makefile b/Examples/python/multimap/Makefile index df3bc86ff..222916fa1 100644 --- a/Examples/python/multimap/Makefile +++ b/Examples/python/multimap/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/multimap/example.i b/Examples/python/multimap/example.i index 3f6fc3db3..cc2482cc8 100644 --- a/Examples/python/multimap/example.i +++ b/Examples/python/multimap/example.i @@ -98,7 +98,7 @@ extern int count(char *bytes, int len, char c); /* This example shows how to wrap a function that mutates a string */ /* Since str is modified, we make a copy of the Python object - so that we don't violate it's mutability */ + so that we don't violate its mutability */ %typemap(in) (char *str, int len) { %#if PY_VERSION_HEX >= 0x03000000 diff --git a/Examples/python/operator/Makefile b/Examples/python/operator/Makefile index 6ef158379..1234c310e 100644 --- a/Examples/python/operator/Makefile +++ b/Examples/python/operator/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/performance/constructor/Makefile b/Examples/python/performance/constructor/Makefile index 98a50ec29..8e65123cf 100644 --- a/Examples/python/performance/constructor/Makefile +++ b/Examples/python/performance/constructor/Makefile @@ -5,17 +5,17 @@ TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + $(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 CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/constructor/runme.py b/Examples/python/performance/constructor/runme.py index 23577a14d..274cbf85e 100644 --- a/Examples/python/performance/constructor/runme.py +++ b/Examples/python/performance/constructor/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/performance/func/Makefile b/Examples/python/performance/func/Makefile index 98a50ec29..8e65123cf 100644 --- a/Examples/python/performance/func/Makefile +++ b/Examples/python/performance/func/Makefile @@ -5,17 +5,17 @@ TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + $(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 CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/func/runme.py b/Examples/python/performance/func/runme.py index fd2fb175b..f9032b9d2 100644 --- a/Examples/python/performance/func/runme.py +++ b/Examples/python/performance/func/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/performance/harness.py b/Examples/python/performance/harness.py index 8e9b6041b..00f48e66a 100644 --- a/Examples/python/performance/harness.py +++ b/Examples/python/performance/harness.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys import time import imp diff --git a/Examples/python/performance/hierarchy/Makefile b/Examples/python/performance/hierarchy/Makefile index 98a50ec29..8e65123cf 100644 --- a/Examples/python/performance/hierarchy/Makefile +++ b/Examples/python/performance/hierarchy/Makefile @@ -5,17 +5,17 @@ TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + $(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 CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/hierarchy/runme.py b/Examples/python/performance/hierarchy/runme.py index 8a57da05e..9b22586a1 100644 --- a/Examples/python/performance/hierarchy/runme.py +++ b/Examples/python/performance/hierarchy/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/performance/hierarchy_operator/Makefile b/Examples/python/performance/hierarchy_operator/Makefile index 98a50ec29..8e65123cf 100644 --- a/Examples/python/performance/hierarchy_operator/Makefile +++ b/Examples/python/performance/hierarchy_operator/Makefile @@ -5,17 +5,17 @@ TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + $(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 CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/hierarchy_operator/runme.py b/Examples/python/performance/hierarchy_operator/runme.py index cf200362f..5a8c52557 100644 --- a/Examples/python/performance/hierarchy_operator/runme.py +++ b/Examples/python/performance/hierarchy_operator/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/performance/operator/Makefile b/Examples/python/performance/operator/Makefile index 98a50ec29..8e65123cf 100644 --- a/Examples/python/performance/operator/Makefile +++ b/Examples/python/performance/operator/Makefile @@ -5,17 +5,17 @@ TARGET = Simple INTERFACE = Simple.i build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + $(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 CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f $(TARGET)_*.py diff --git a/Examples/python/performance/operator/runme.py b/Examples/python/performance/operator/runme.py index 61a0e8edc..4a6031f48 100644 --- a/Examples/python/performance/operator/runme.py +++ b/Examples/python/performance/operator/runme.py @@ -1,5 +1,3 @@ -#!/usr/bin/env - import sys sys.path.append('..') import harness diff --git a/Examples/python/pointer/Makefile b/Examples/python/pointer/Makefile index df3bc86ff..222916fa1 100644 --- a/Examples/python/pointer/Makefile +++ b/Examples/python/pointer/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/reference/Makefile b/Examples/python/reference/Makefile index e940c1f43..41cded284 100644 --- a/Examples/python/reference/Makefile +++ b/Examples/python/reference/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/reference/example.cxx b/Examples/python/reference/example.cxx index 8a513bf49..9dbaed2ee 100644 --- a/Examples/python/reference/example.cxx +++ b/Examples/python/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/python/simple/Makefile b/Examples/python/simple/Makefile index df3bc86ff..222916fa1 100644 --- a/Examples/python/simple/Makefile +++ b/Examples/python/simple/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/smartptr/Makefile b/Examples/python/smartptr/Makefile index 140d482c9..19609353d 100644 --- a/Examples/python/smartptr/Makefile +++ b/Examples/python/smartptr/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/std_map/Makefile b/Examples/python/std_map/Makefile index 06bce6543..f406dfaf4 100644 --- a/Examples/python/std_map/Makefile +++ b/Examples/python/std_map/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/std_vector/Makefile b/Examples/python/std_vector/Makefile index 06bce6543..f406dfaf4 100644 --- a/Examples/python/std_vector/Makefile +++ b/Examples/python/std_vector/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/swigrun/Makefile b/Examples/python/swigrun/Makefile index fe9f64e94..94f7d04e0 100644 --- a/Examples/python/swigrun/Makefile +++ b/Examples/python/swigrun/Makefile @@ -4,20 +4,20 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: $(SWIG) -python -external-runtime - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f swigpyrun.h diff --git a/Examples/python/swigrun/example.cxx b/Examples/python/swigrun/example.cxx index 25906a559..2d2471301 100644 --- a/Examples/python/swigrun/example.cxx +++ b/Examples/python/swigrun/example.cxx @@ -9,7 +9,7 @@ Manager* convert_to_Manager(PyObject *py_obj) { Manager* c_ptr; swig_type_info *ty = SWIG_TypeQuery("Manager *"); - printf("manager ty %p \n", ty); + printf("manager ty %p \n", (void *)ty); if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty, 0) == -1) { c_ptr = 0; } else { diff --git a/Examples/python/swigrun/example.h b/Examples/python/swigrun/example.h index 69e6fe4de..e89f7baaa 100644 --- a/Examples/python/swigrun/example.h +++ b/Examples/python/swigrun/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/python/template/Makefile b/Examples/python/template/Makefile index 06bce6543..f406dfaf4 100644 --- a/Examples/python/template/Makefile +++ b/Examples/python/template/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/varargs/Makefile b/Examples/python/varargs/Makefile index 505f199de..8ec6e9cc9 100644 --- a/Examples/python/varargs/Makefile +++ b/Examples/python/varargs/Makefile @@ -1,19 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/variables/Makefile b/Examples/python/variables/Makefile index df3bc86ff..222916fa1 100644 --- a/Examples/python/variables/Makefile +++ b/Examples/python/variables/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/variables/example.c b/Examples/python/variables/example.c index aa4ffe9b3..85685fe72 100644 --- a/Examples/python/variables/example.c +++ b/Examples/python/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + 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); } diff --git a/Examples/r/class/Makefile b/Examples/r/class/Makefile index 8a64f49a9..3e5d6a6ca 100644 --- a/Examples/r/class/Makefile +++ b/Examples/r/class/Makefile @@ -5,11 +5,11 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile r_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' r_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r_cpp clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' r_clean diff --git a/Examples/r/class/example.cxx b/Examples/r/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/r/class/example.cxx +++ b/Examples/r/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/r/class/example.h b/Examples/r/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/r/class/example.h +++ b/Examples/r/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/r/class/example.i b/Examples/r/class/example.i index 4654d269f..fbdf7249f 100644 --- a/Examples/r/class/example.i +++ b/Examples/r/class/example.i @@ -1,9 +1,9 @@ /* File : example.i */ %module example -%inline %{ +%{ #include "example.h" %} + +/* Let's just grab the original header file here */ %include "example.h" - - diff --git a/Examples/r/simple/Makefile b/Examples/r/simple/Makefile index 8a8e0e1c1..5cc41530c 100644 --- a/Examples/r/simple/Makefile +++ b/Examples/r/simple/Makefile @@ -5,11 +5,11 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile r_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' r_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' r_clean diff --git a/Examples/ruby/class/Makefile b/Examples/ruby/class/Makefile index ef267bc44..516f842d7 100644 --- a/Examples/ruby/class/Makefile +++ b/Examples/ruby/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/class/example.cxx b/Examples/ruby/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/ruby/class/example.cxx +++ b/Examples/ruby/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/ruby/class/example.h b/Examples/ruby/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/ruby/class/example.h +++ b/Examples/ruby/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/ruby/class/example.i b/Examples/ruby/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/ruby/class/example.i +++ b/Examples/ruby/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/ruby/class/index.html b/Examples/ruby/class/index.html index 67eeac9ad..927c00190 100644 --- a/Examples/ruby/class/index.html +++ b/Examples/ruby/class/index.html @@ -12,9 +12,7 @@

        Wrapping a simple C++ class

        -This example illustrates C++ class wrapping performed by SWIG. -C++ classes are simply transformed into Ruby classes that provide methods to -access class members. +This example illustrates wrapping a simple C++ class to give a Ruby class.

        The C++ Code

        @@ -32,8 +30,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +42,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +51,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -122,10 +120,8 @@ print "The area is ", c.area, "\n"

    -

  • When a instance of Ruby level wrapper class is garbage collected by +
  • When a instance of Ruby level wrapper class is garbage collected by the Ruby interpreter, the corresponding C++ destructor is automatically invoked. -(Note: destructors are currently not inherited. This might change later. -Until then, use -make_default).

  • Static member variables are wrapped as Ruby class accessor methods. @@ -144,53 +140,14 @@ Shapes.nshapes = 13 # Set a static data member
    • Ruby module of SWIG differs from other language modules in wrapping C++ -interfaces. They provides lower-level interfaces and optional higher-level +interfaces. They provide lower-level interfaces and optional higher-level interfaces know as proxy classes. Ruby module needs no such redundancy due to Ruby's sophisticated extension API. -

      -

    • SWIG *does* know how to properly perform upcasting of objects in +
    • SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy except for multiple inheritance. -

      -

    • A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -

      -

        -
      • Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
        -
        -void foo(int a);  
        -%name(foo2) void foo(double a, double b);
        -
        -
        - -

        -

      • Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
        -
        -%inline %{
        -    Vector *vector_add(Vector *a, Vector *b) {
        -          ... whatever ...
        -    }
        -%}
        -
        -
        - -

        -

      • Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). - -
      -

      - -

    • Dave's snide remark: Like a large bottle of strong Tequilla, it's better to -use C++ in moderation. +
    • C++ Namespaces - %nspace isn't yet supported for Ruby.
    diff --git a/Examples/ruby/class/runme.rb b/Examples/ruby/class/runme.rb index de73bcd46..971e149d5 100644 --- a/Examples/ruby/class/runme.rb +++ b/Examples/ruby/class/runme.rb @@ -45,5 +45,9 @@ end # Notice how the Shape#area() and Shape#perimeter() functions really # invoke the appropriate virtual method on each object. +# Remove references to the object and force a garbage collection run. +c = s = o = nil +GC.start() + print "\n", Example::Shape.nshapes," shapes remain\n" print "Goodbye\n" diff --git a/Examples/ruby/constants/Makefile b/Examples/ruby/constants/Makefile index e0f6a03ae..561d5fd84 100644 --- a/Examples/ruby/constants/Makefile +++ b/Examples/ruby/constants/Makefile @@ -1,19 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/constants/runme.rb b/Examples/ruby/constants/runme.rb old mode 100755 new mode 100644 diff --git a/Examples/ruby/enum/Makefile b/Examples/ruby/enum/Makefile index ef267bc44..516f842d7 100644 --- a/Examples/ruby/enum/Makefile +++ b/Examples/ruby/enum/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/exception_class/Makefile b/Examples/ruby/exception_class/Makefile index 46bb7995d..6723a2a7c 100644 --- a/Examples/ruby/exception_class/Makefile +++ b/Examples/ruby/exception_class/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/free_function/Makefile b/Examples/ruby/free_function/Makefile index ef267bc44..516f842d7 100644 --- a/Examples/ruby/free_function/Makefile +++ b/Examples/ruby/free_function/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/funcptr/Makefile b/Examples/ruby/funcptr/Makefile index ddbc1ae30..15b39cf0d 100644 --- a/Examples/ruby/funcptr/Makefile +++ b/Examples/ruby/funcptr/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/funcptr2/Makefile b/Examples/ruby/funcptr2/Makefile index ddbc1ae30..15b39cf0d 100644 --- a/Examples/ruby/funcptr2/Makefile +++ b/Examples/ruby/funcptr2/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/functor/Makefile b/Examples/ruby/functor/Makefile index 662baa110..348bd66e3 100644 --- a/Examples/ruby/functor/Makefile +++ b/Examples/ruby/functor/Makefile @@ -5,15 +5,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/hashargs/Makefile b/Examples/ruby/hashargs/Makefile index cee97f28e..59a36c0dd 100644 --- a/Examples/ruby/hashargs/Makefile +++ b/Examples/ruby/hashargs/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/hashargs/runme.rb b/Examples/ruby/hashargs/runme.rb old mode 100755 new mode 100644 diff --git a/Examples/ruby/import/Makefile b/Examples/ruby/import/Makefile index fc6a9f10f..b5d06bdd7 100644 --- a/Examples/ruby/import/Makefile +++ b/Examples/ruby/import/Makefile @@ -2,19 +2,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = - + check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/import_template/Makefile b/Examples/ruby/import_template/Makefile index fc6a9f10f..b5d06bdd7 100644 --- a/Examples/ruby/import_template/Makefile +++ b/Examples/ruby/import_template/Makefile @@ -2,19 +2,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = - + check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' ruby_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' ruby_cpp clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/index.html b/Examples/ruby/index.html index f04146e56..4f4aa0ad2 100644 --- a/Examples/ruby/index.html +++ b/Examples/ruby/index.html @@ -1,4 +1,4 @@ - + SWIG:Examples:ruby diff --git a/Examples/ruby/java/Makefile b/Examples/ruby/java/Makefile index c06bfb7bf..7d611abd2 100644 --- a/Examples/ruby/java/Makefile +++ b/Examples/ruby/java/Makefile @@ -1,23 +1,22 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run -build: Example.class - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \ +build: Example.class Example.h + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ CXXSHARED="gcj -fpic -shared Example.class" LIBS="-lstdc++" DEFS='' ruby_cpp clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean rm -f *.class Example.h -Example.class: Example.java - gcj -fPIC -C -c -g Example.java - gcjh Example - +Example.class Example.h: $(SRCDIR)Example.java + gcj -d . -fPIC -C -c -g $(SRCDIR)Example.java + gcjh Example.class diff --git a/Examples/ruby/mark_function/Makefile b/Examples/ruby/mark_function/Makefile index ef267bc44..516f842d7 100644 --- a/Examples/ruby/mark_function/Makefile +++ b/Examples/ruby/mark_function/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/multimap/Makefile b/Examples/ruby/multimap/Makefile index ddbc1ae30..15b39cf0d 100644 --- a/Examples/ruby/multimap/Makefile +++ b/Examples/ruby/multimap/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/multimap/runme.rb b/Examples/ruby/multimap/runme.rb old mode 100755 new mode 100644 diff --git a/Examples/ruby/operator/Makefile b/Examples/ruby/operator/Makefile index c7a21d0a4..bdcf52646 100644 --- a/Examples/ruby/operator/Makefile +++ b/Examples/ruby/operator/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/overloading/Makefile b/Examples/ruby/overloading/Makefile index ef267bc44..516f842d7 100644 --- a/Examples/ruby/overloading/Makefile +++ b/Examples/ruby/overloading/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/pointer/Makefile b/Examples/ruby/pointer/Makefile index ddbc1ae30..15b39cf0d 100644 --- a/Examples/ruby/pointer/Makefile +++ b/Examples/ruby/pointer/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/reference/Makefile b/Examples/ruby/reference/Makefile index ef267bc44..516f842d7 100644 --- a/Examples/ruby/reference/Makefile +++ b/Examples/ruby/reference/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/reference/example.cxx b/Examples/ruby/reference/example.cxx index 8a513bf49..9dbaed2ee 100644 --- a/Examples/ruby/reference/example.cxx +++ b/Examples/ruby/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/ruby/simple/Makefile b/Examples/ruby/simple/Makefile index ddbc1ae30..15b39cf0d 100644 --- a/Examples/ruby/simple/Makefile +++ b/Examples/ruby/simple/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/simple/runme.rb b/Examples/ruby/simple/runme.rb old mode 100755 new mode 100644 diff --git a/Examples/ruby/std_vector/Makefile b/Examples/ruby/std_vector/Makefile index f7b148062..370bd8fb6 100644 --- a/Examples/ruby/std_vector/Makefile +++ b/Examples/ruby/std_vector/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/template/Makefile b/Examples/ruby/template/Makefile index f7b148062..370bd8fb6 100644 --- a/Examples/ruby/template/Makefile +++ b/Examples/ruby/template/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/value/Makefile b/Examples/ruby/value/Makefile index ddbc1ae30..15b39cf0d 100644 --- a/Examples/ruby/value/Makefile +++ b/Examples/ruby/value/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/value/example.i b/Examples/ruby/value/example.i index 98fd60ed5..39663c6b8 100644 --- a/Examples/ruby/value/example.i +++ b/Examples/ruby/value/example.i @@ -26,7 +26,7 @@ Vector *new_Vector(double x, double y, double z) { } void vector_print(Vector *v) { - printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z); + printf("Vector %p = (%g, %g, %g)\n", (void *)v, v->x, v->y, v->z); } %} diff --git a/Examples/ruby/variables/Makefile b/Examples/ruby/variables/Makefile index ddbc1ae30..15b39cf0d 100644 --- a/Examples/ruby/variables/Makefile +++ b/Examples/ruby/variables/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile ruby_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ruby static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_static clean: - $(MAKE) -f $(TOP)/Makefile ruby_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' ruby_clean diff --git a/Examples/ruby/variables/example.c b/Examples/ruby/variables/example.c index aa4ffe9b3..85685fe72 100644 --- a/Examples/ruby/variables/example.c +++ b/Examples/ruby/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + 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); } diff --git a/Examples/tcl/class/Makefile b/Examples/tcl/class/Makefile index db6149cb3..aacf30e04 100644 --- a/Examples/tcl/class/Makefile +++ b/Examples/tcl/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile tcl_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile tcl_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' tcl_clean diff --git a/Examples/tcl/class/example.cxx b/Examples/tcl/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/tcl/class/example.cxx +++ b/Examples/tcl/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -double Circle::area(void) { +double Circle::area() { return M_PI*radius*radius; } -double Circle::perimeter(void) { +double Circle::perimeter() { return 2*M_PI*radius; } -double Square::area(void) { +double Square::area() { return width*width; } -double Square::perimeter(void) { +double Square::perimeter() { return 4*width; } diff --git a/Examples/tcl/class/example.h b/Examples/tcl/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/tcl/class/example.h +++ b/Examples/tcl/class/example.h @@ -7,11 +7,11 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -19,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area(void); - virtual double perimeter(void); + 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(void); - virtual double perimeter(void); + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/tcl/class/example.i b/Examples/tcl/class/example.i index 23ee8a822..fbdf7249f 100644 --- a/Examples/tcl/class/example.i +++ b/Examples/tcl/class/example.i @@ -6,6 +6,4 @@ %} /* Let's just grab the original header file here */ - %include "example.h" - diff --git a/Examples/tcl/class/index.html b/Examples/tcl/class/index.html index fd8cfe502..16dbeea4f 100644 --- a/Examples/tcl/class/index.html +++ b/Examples/tcl/class/index.html @@ -32,8 +32,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +44,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +53,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -91,10 +91,10 @@ Note: when creating a C++ extension, you must run SWIG with the -c++ op SWIG performs two forms of C++ wrapping-- a low level interface and a high level widget-like interface.
    • -Click here to see a script that calls the C++ functions using the +Click here to see a script that calls the C++ functions using the low-level interface.
    • -Click here to see a the same script written with the high-level +Click here to see the same script written with the high-level interface.
    @@ -225,47 +225,15 @@ set Shapes_nshapes 13 # Set a static data member

    General Comments