diff --git a/.gitignore b/.gitignore index 5ca7dac0d..78b72338f 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ CCache/config.h CCache/config.log CCache/config.status Examples/Makefile +Examples/d/example.mk Examples/guile/Makefile Examples/test-suite/*/Makefile Examples/xml/Makefile @@ -137,6 +138,7 @@ Examples/test-suite/uffi/*/ # Octave generated files swigexample*.oct +Examples/test-suite/octave/*.oct # Python generated files, based on: # https://github.com/github/gitignore/blob/master/Python.gitignore @@ -145,10 +147,11 @@ swigexample*.oct /__pycache__/ # Scilab generated files -builder.sce loader.sce -cleaner.sce -gw_*.c + +# Go generated files +*.[5689] +*_gc.c # Scratch directories Examples/scratch diff --git a/.travis.yml b/.travis.yml index 12ee779b7..5e00eea8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,60 @@ env: - SWIGLANG= matrix: include: + - compiler: gcc + env: SWIGLANG=csharp + - compiler: gcc + env: SWIGLANG=d + - 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=-j3 # 3.2 + - compiler: gcc + env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8 + - 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=python SWIG_FEATURES=-builtin + - compiler: gcc + env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 + - compiler: gcc + env: SWIGLANG=ruby - compiler: gcc env: SWIGLANG=scilab + - compiler: gcc + env: SWIGLANG=tcl allow_failures: - # None + # Occasional gcc internal compiler error + - compiler: gcc + env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8 before_install: - date -u - uname -a @@ -18,21 +68,25 @@ before_install: - time sudo apt-get -qq install libboost-dev - if test -z "$SWIGLANG"; then sudo apt-get -qq install yodl; fi - if test "$SWIGLANG" = "csharp"; then sudo apt-get -qq install mono-devel; fi + - if test "$SWIGLANG" = "d"; then wget http://downloads.dlang.org/releases/2014/dmd_2.066.0-0_amd64.deb; sudo dpkg -i dmd_2.066.0-0_amd64.deb; fi - if test "$SWIGLANG" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed - if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "node"; then sudo apt-get install -qq rlwrap python-software-properties && echo 'yes' | sudo add-apt-repository ppa:chris-lea/node.js && sudo apt-get -qq update && sudo apt-get install -qq nodejs && sudo npm install -g node-gyp; fi - if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "jsc"; then sudo apt-get install -qq libwebkitgtk-dev; fi - if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "v8"; then sudo apt-get install -qq libv8-dev; fi - if test "$SWIGLANG" = "guile"; then sudo apt-get -qq install guile-2.0-dev; fi - if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi - - if test "$SWIGLANG" = "octave"; 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" = "octave" -a -z "$VER"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi + - if test "$SWIGLANG" = "octave" -a "$VER"; then sudo add-apt-repository -y ppa:kwwette/octaves && sudo apt-get -qq update && sudo apt-get -qq install liboctave${VER}-dev; fi - if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi + - if test "$SWIGLANG" = "python"; then git clone https://github.com/jcrocholl/pep8.git && pushd pep8 && git checkout tags/1.5.7 && python ./setup.py build && sudo python ./setup.py install && popd; fi - if test "$SWIGLANG" = "python" -a "$PY3" -a -z "$VER"; then sudo apt-get install -qq python3-dev; fi - if test "$SWIGLANG" = "python" -a "$VER"; then sudo add-apt-repository -y ppa:fkrull/deadsnakes && sudo apt-get -qq update && sudo apt-get -qq install python${VER}-dev && export CONFIGOPTS="--with-python${PY3}=python${VER}"; fi + - if test "$SWIGLANG" = "scilab"; then sudo apt-get -qq install scilab; fi - if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. - declare -A CFLAGS_EXAMPLES && CFLAGS_EXAMPLES=( ["csharp"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" + ["d"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" ["go"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" ["guile"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" ["java"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" @@ -48,6 +102,7 @@ before_install: ) - declare -A CXXFLAGS_EXAMPLES && CXXFLAGS_EXAMPLES=( ["csharp"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" + ["d"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" ["go"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" ["guile"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type" ["java"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type" diff --git a/ANNOUNCE b/ANNOUNCE index 58de2fe10..e3792cc95 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 3.0.2 (4 Jun 2014) *** +*** ANNOUNCE: SWIG 3.0.5 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-3.0.2, the latest SWIG release. +We're pleased to announce SWIG-3.0.5, the latest SWIG release. What is SWIG? ============= @@ -21,11 +21,11 @@ Availability ============ The release is available for download on Sourceforge at - http://prdownloads.sourceforge.net/swig/swig-3.0.2.tar.gz + http://prdownloads.sourceforge.net/swig/swig-3.0.5.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-3.0.2.zip + http://prdownloads.sourceforge.net/swig/swigwin-3.0.5.zip Please report problems with this release to the swig-devel mailing list, details at http://www.swig.org/mail.html. diff --git a/CHANGES b/CHANGES index 1cfedc31e..9c64f9c75 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,200 @@ 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.4 (14 Jan 2015) +=========================== + +2015-01-12: olly + [PHP] Fix segfault in director upcall check when using PHP built with + ZTS enabled. Fixes #155, reported by Pierre Labastie. + +2015-01-12: vadz + [Python] Fix #294 #296 - Regression introduced in SWIG-3.0.3 when + wrapping functions with default arguments. Invalid or missing default + arguments were sometimes being generated into the python layer. + +2015-01-08: olly + Allow C++11 "explicit constexpr". Fixes github issue #284 reported + by Pawel Tomulik. Also handle "constexpr explicit" and "constexpr + static". + +2015-01-08: olly + When reporting an error for a construct which hasn't been + terminated when the end of the file is reached, report it at the + start line rather than "EOF" as then tools like editors and IDEs + will take you to a generally more useful place for fixing the + problem. + +2015-01-08: olly + Improve error messages for a few cases which previously gave the + one of the cryptic catch-all errors "Syntax error in input". + +2015-01-08: olly + Provide -cppext as a general command line option for setting the + extension used for generated C++ files (previously it was specific + to the PHP backend). Deprecate the equivalent -suffix option + provided by the Ocaml backend, but continue to support that for + now. + +Version 3.0.3 (30 Dec 2014) +=========================== + +2014-12-27: wsfulton + Fix #280 - abort using all default template parameters within other template + parameters. + +2014-12-27: talby + [Perl] Issue #282 perl5 archlib vs archlibexp + [Perl] tidy "warning: duplicate 'extern' declaration specifier" when building generated code + under clang + +2014-12-18: wsfulton + Add support for %constant and structs/classes - issue #272 + +2014-12-09: wsfulton + Fix #245 - regression (since swig-3.0.0) in templated constructors. + Templated constructors could not be instantiated - they were incorrectly ignored with a warning 504: + "Function: xyz must have a return type. Ignored." + +2014-12-07: wsfulton + Add support for C++11 strongly typed enumerations. + +2014-11-21: wsfulton + [Java C#] Fix multiply defined error when using %rename of enum items when using the "simple enum" + wrappers. + +2014-10-28: vadz + [Python] Patch #201 The generated .py file no longer uses *args for all Python parameters. + Instead, the parameters are named using the C++ parameter names. + +2014-10-24: timotheecour + [D] Patch #204 Use core.atomic.atomicOp to mutate shared variables + +2014-10-21: wsfulton + Fix issue #242 - Use of the "kwargs" feature no longer automatically turns on the + "compactdefaultargs" feature if the target language does not support kwargs. + Only Java and Python support kwargs, so this affects all the other languages. + + *** POTENTIAL INCOMPATIBILITY *** + +2014-10-10: diorcety + [Python] Patch #232 Fix property access using directors + +2014-10-06: wsfulton + [Python] Fixes when using -builtin and std::vector/std::list wrappers to allow deletion + of single elements, such as 'del vec[0]'. + +2014-09-30: oliverb + [Javascript] Merge patch #216 by Richie765 - Added support for many versions of v8 javascript. + +2014-09-30: oliverb + [Javascript] Merge patch #195 by zittix - Fixed JSClassRef declaration not using the static one. + +2014-09-30: ianlancetaylor + [Go] In configure script, require Go 1.1 or later. + +2014-09-30: wsfulton + [Python] Patch #207 - Fix No module error with -relativeimport when using single + header file import. + +2014-09-27: wsfulton + Patch #208 - Initialise newly created array when using array_functions in the + carrays.i library (C++ usage). + +2014-09-27: wsfulton + [Ruby] Patch #187 - Fix crash on shutdown of the Ruby interpreter if more than one + module was loaded at a time when data is being shared between modules. + +2014-09-27: wsfulton + [Java] Patch #168 - Fix leak in Java director string handling after the Java + upcall when called from a native thread. + +2014-09-25: ianlancetaylor + [Go] Adjust generated code to work with upcoming Go 1.4 + release. + +2014-09-23: wsfulton + [Python] Add patch from Thomas Maslach to fix crash in wrappers when using -threads in + the STL iterators (SwigPyIterator destructor). + +2014-09-17: wsfulton + [C#] Merge patch #229 from contre - Add bool array types to arrays_csharp.i + +2014-09-12: olly + [PHP] Add support for specifying any PHP interfaces a wrapped class + implements, e.g.: %typemap("phpinterfaces") MyIterator "Iterator"; + +2014-09-11: olly + [PHP] Fix throwing a PHP exception through C++ from a subclassed + director method - PHP NULL gets returned by the subclassed method + in this case, so the directorout typemap needs to allow that (at + least if an exception is active). + +2014-09-09: ianlancetaylor + [Go] Add goargout typemap. + +2014-09-09: olly + [PHP] Fix segmentation faults with directors in PHP >= 5.4, and + reenable runme tests for director_basic testcase. Fix from + pavel-charvat in issue#164. + +2014-09-05: ianlancetaylor + [Go] Add imtype, goin, goout, godirectorin, and + godirectorout typemaps, to support writing Go code to + convert between types. + +2014-09-02: olly + [Python] Fix regression in indentation of python code produced with + -modern, introduced by changes in #188. Reported by fabiencastan + in #218. + +2014-09-01: olly + Issue an error for unknown SWIG preprocessor directives, rather + than quietly ignoring them. Reported by jrhelsey in issue#217. + + *** POTENTIAL INCOMPATIBILITY *** + +2014-08-15: talby + [Perl] Include guard fix for nested modules from Anthony Heading (SF Patch #350). + +2014-08-04: wsfulton + [C#] Merge patch #200 from gpetrou - Changed CSharp license header to include auto-generated + tag so that StyleCop ignores the files. + +2014-08-04: wsfulton + [Java] Merge patch #198 from Yuval Kashtan - Support for java.nio.ByteBuffer mapping to + unsigned char * in various.i in NIOBUFFER typemaps. + +2014-07-14: ianlancetaylor + [Go] Change struct definition to use void *, not uint8, so + that the type is recorded as possibly containing + pointers. This ensures that the 1.3 garbage collector + does not collect pointers passed to C++ code. + +2014-07-01: wsfulton + Fix SF Bug #1375 - Expansion of the $parentclassname special variable incorrectly contains + brackets in the expanded name. + +Version 3.0.2 (4 Jun 2014) +========================== + +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. + +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 *** + Version 3.0.1 (27 May 2014) =========================== @@ -20,7 +214,7 @@ Version 3.0.1 (27 May 2014) 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 + Add #166 - 'make check' now works out of source. This required the 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. @@ -1001,13 +1195,13 @@ Version 2.0.9 (16 December 2012) 2012-10-11: wsfulton Most of the special variables available for use in %exception are now also available for expansion in - %extend blocks. These are: $name $symname $overname $decl $fulldecl $parentname $parentsymname, see docs + %extend blocks. These are: $name $symname $overname $decl $fulldecl $parentclassname $parentclasssymname, see docs on "Class extension" in SWIGPlus.html. Patch based on submission from Kris Thielemans. 2012-10-10: wsfulton Additional new special variables in %exception are expanded as follows: - $parentname - The parent class name (if any) for a method. - $parentsymname - The target language parent class name (if any) for a method. + $parentclassname - The parent class name (if any) for a method. + $parentclasssymname - The target language parent class name (if any) for a method. 2012-10-08: iant [Go] Generating Go code now requires using the -intgosize option to @@ -1602,7 +1796,7 @@ Version 2.0.5 (19 April 2012) -tmsearch and -tmused. 2011-08-26: wsfulton - [C#, D] Fix %callback which was generating uncompileable code. + [C#, D] Fix %callback which was generating uncompilable code. 2011-08-25: wsfulton Fix constructors in named typedef class declarations as reported by Gregory Bronner: @@ -1841,7 +2035,7 @@ Version 2.0.4 (21 May 2011) PySlice_GetIndices, which changed signatures in python3.2. 2011-04-07: wsfulton - Fix wrapping of const array typedefs which were generating uncompileable code as + Fix wrapping of const array typedefs which were generating uncompilable code as reported by Karl Wette. 2011-04-03: szager @@ -2068,8 +2262,8 @@ Version 2.0.2 (20 February 2011) Fix handling of multiple regex-using %renames attached to the same declaration. For example, now - %rename("%(regex/^Set(.*)/put\\1/)s") ""; - %rename("%(regex/^Get(.*)/get\\1/)s") ""; + %rename("%(regex:/^Set(.*)/put\\1/)s") ""; + %rename("%(regex:/^Get(.*)/get\\1/)s") ""; works as expected whereas before only the last anonymous rename was taken into account. @@ -2279,7 +2473,7 @@ Version 2.0.1 (4 October 2010) in this case). 2010-06-03: wsfulton - Fix uncompileable code when %rename results in two enum items + Fix uncompilable code when %rename results in two enum items with the same name. Reported by Vadim Zeitlin. Version 2.0.0 (2 June 2010) @@ -2792,7 +2986,7 @@ Version 2.0.0 (2 June 2010) Fix #2310483 - function pointer typedef within extern "C" block. 2009-11-13: wsfulton - Fix usage of nested template classes within templated classes so that compileable code + Fix usage of nested template classes within templated classes so that compilable code is generated. 2009-11-13: olly @@ -2800,7 +2994,7 @@ Version 2.0.0 (2 June 2010) wasn't being used. Patch from gverbruggen in SF#2892647. 2009-11-12: wsfulton - Fix usage of nested template classes so that compileable code is generated - the nested + Fix usage of nested template classes so that compilable code is generated - the nested template class is now treated like a normal nested classes, that is, as an opaque type unless the nestedworkaround feature is used. @@ -2826,7 +3020,7 @@ Version 2.0.0 (2 June 2010) 2009-11-11: wsfulton There were a number of C++ cases where nested classes/structs/unions were being handled - as if C code was being parsed which would oftentimes lead to uncompileable code as an + as if C code was being parsed which would oftentimes lead to uncompilable code as an attempt was made to wrap the nested structs like it is documented for C code. Now all nested structs/classes/unions are ignored in C++ mode, as was always documented. However, there is an improvement as usage of nested structs/classes/unions is now always treated @@ -2838,7 +3032,7 @@ Version 2.0.0 (2 June 2010) Fix R for -fcompact and add std_map.i 2009-11-08: wsfulton - Fix inconsistency for nested structs/unions/classes. Uncompileable code was being + Fix inconsistency for nested structs/unions/classes. Uncompilable code was being generated when inner struct and union declarations were used as types within the inner struct. The inner struct/union is now treated as a forward declaration making the behaviour the same as an inner class. (C++ code), eg: @@ -2852,7 +3046,7 @@ Version 2.0.0 (2 June 2010) Ignored nested class/struct warnings now display the name of the ignored class/struct. 2009-11-07: wsfulton - Bug #1514681 - Fix nested template classes within a namespace generated uncompileable + Bug #1514681 - Fix nested template classes within a namespace generated uncompilable code and introduced strange side effects to other wrapper code especially code after the nested template class. Note that nested template classes are still ignored. @@ -2878,8 +3072,8 @@ Version 2.0.0 (2 June 2010) and in template parameter specializations: struct S {}; - template struct X { void a() {}; }; - template <> struct X { void b() {}; }; + template struct X { void a() {} }; + template <> struct X { void b() {} }; %template(MyTConcrete) X< ::S >; plus probably some other corner case usage of ::. @@ -3707,7 +3901,7 @@ Version 1.3.36 (24 June 2008) 06/19/2008: wsfulton [Java, C#] C# and Java keywords will be renamed instead of just issuing a warning - and then generating uncompileable code. Warning 314 gives the new name when a + and then generating uncompilable code. Warning 314 gives the new name when a keyword is found. 06/19/2008: wsfulton @@ -4150,7 +4344,7 @@ Version 1.3.34 (27 February 2008) 11/30/2007: wsfulton Fix using statements using a base class method where the methods were overloaded. Depending on the order of the using statements and method declarations, these - were previously generating uncompileable wrappers, eg: + were previously generating uncompilable wrappers, eg: struct Derived : Base { virtual void funk(); @@ -4288,7 +4482,7 @@ Version 1.3.32 (November 15, 2007) %attributeref(Class, AttributeType, AttributeName, AccessorMethod) 10/16/2007: olly - [Tcl] Fix several ocurrences of "warning: deprecated conversion + [Tcl] Fix several occurrences of "warning: deprecated conversion from string constant to 'char*'" from GCC 4.2 in generated C/C++ code. @@ -5238,7 +5432,7 @@ Version 1.3.30 (November 13, 2006) 10/03/2006: wsfulton [Ruby] Fix #1527885 - Overloaded director virtual methods sometimes produced - uncompileable code when used with the director:except feature. + uncompilable code when used with the director:except feature. 10/03/2006: wsfulton Directors: Directors are output in the order in which they are declared in @@ -9436,7 +9630,7 @@ Version 1.3.23 (November 11, 2004) wrapper method only and not the extra overloaded methods that SWIG generates. For example: - %feature("except") void hello(int i=0, double d=0.0); + %feature("except") hello(int i=0, double d=0.0); void hello(int i=0, double d=0.0); will apply the feature to all three wrapper methods, that is: @@ -9447,7 +9641,7 @@ Version 1.3.23 (November 11, 2004) If the default arguments are not specified in the feature: - %feature("except") void hello(int i, double d); + %feature("except") hello(int i, double d); void hello(int i=0, double d=0.0); then the feature will only apply to this wrapper method: @@ -10822,7 +11016,7 @@ Version 1.3.22 (September 4, 2004) ... } - Previously, none of BIG, LARGE or BAR would have produced compileable code + Previously, none of BIG, LARGE or BAR would have produced compilable code when using %javaconst(1). 06/27/2004: wsfulton @@ -20214,13 +20408,13 @@ Version 1.3.6 (July 9, 2001) class TestClass { public: - TestClass() {}; - TestClass(int a) {}; - ~TestClass() {}; - unsigned long xyz(short k) {}; - unsigned long xyz(int n) {}; - static void static_func() {}; - static void static_func(int a) {}; + TestClass() {} + TestClass(int a) {} + ~TestClass() {} + unsigned long xyz(short k) {} + unsigned long xyz(int n) {} + static void static_func() {} + static void static_func(int a) {} }; void delete_TestClass(int a); diff --git a/CHANGES.current b/CHANGES.current index bb8bbdc41..780524c83 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,22 +2,20 @@ 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.2 (4 Jun 2014) +Version 3.0.5 (in progress) =========================== -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. +2015-01-23: olly + [PHP] When wrapping a returned resource as an object, check if all + cases wrap it in the same class, and if so eliminate the pointless + switch statement wrapper we previously generated. -2014-06-02: vkalinin - Fix #183 - %extend and unnamed nested structs +2015-01-22: wsfulton + [Octave] Merge patch #297 for SF bug #1277 - Octave shared_ptr support -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. +2015-01-15: wsfulton + [Python] Merge patch #250 - Fixes for using %constant and objects (non-primitive types) -2014-05-24: kwwette - [Octave] Remove deprecated -global/-noglobal command-line arguments - - *** POTENTIAL INCOMPATIBILITY *** +2015-01-15: wsfulton + [C# Go] Merge patch #308 and fix #307 - C++11 strongly typed enum support + in directors diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html index e62139797..2890e2415 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -56,7 +56,7 @@ Add the SDK tools and NDK tools to your path and create a directory somewhere fo
 $ export PATH=$HOME/android/android-sdk-linux_x86/tools:$HOME/android/android-sdk-linux_x86/platform-tools:$HOME/android/android-ndk-r6b:$PATH
 $ mkdir AndroidApps 
-$ cd AnrdoidApps
+$ cd AndroidApps
 
diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index ce9174254..b7e1d638c 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -495,59 +495,59 @@ struct DerivedStruct : BaseStruct {

7.2.13 Strongly typed enumerations

-

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

+

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

 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:

+

+Strongly typed enums are often used to avoid name clashes such as the following: +

-class Color {
-  enum class PrintingColors : unsigned int {
-    Cyan, Magenta, Yellow, Black
+struct Color {
+  enum class RainbowColors : unsigned int {
+    Red, Orange, Yellow, Green, Blue, Indigo, Violet
   };
   
-  enum class BasicColors {
-    Red, Green, Blue
+  enum class WarmColors {
+    Yellow, Orange, Red
   };
-  
-  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
+  // Note normal enum
+  enum PrimeColors {
+    Red=100, Green, Blue
   };
 };
 

-Expect to see this improved in a future version of SWIG. +There are various ways that the target languages handle enums, so it is not possible to precisely state how they are handled in this section. +However, generally, most scripting languages mangle in the strongly typed enumeration's class name, +but do not use any additional mangling for normal enumerations. For example, in Python, the following code

+
+print Color.RainbowColors_Red, Color.WarmColors_Red, Color.Red
+
+ +

+results in +

+ +
+0 2 100
+
+ +

+The strongly typed languages often wrap normal enums into an enum class and so treat normal enums and strongly typed enums the same. +The equivalent in Java is: +

+ +
+System.out.println(Color.RainbowColors.Red.swigValue() + " " + Color.WarmColors.Red.swigValue() + " " + Color.PrimeColors.Red.swigValue());
+
+

7.2.14 Double angle brackets

@@ -611,6 +611,7 @@ The following is an example of an alias template:
 template< typename T1, typename T2, int >
 class SomeType {
+public:
   T1 a;
   T2 b;
   int c;
diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html
index 7f53423fc..ba49fa004 100644
--- a/Doc/Manual/CSharp.html
+++ b/Doc/Manual/CSharp.html
@@ -1075,6 +1075,7 @@ try {
   $action
 } catch (std::out_of_range e) {
   SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what());
+  return $null;
 }
 %}
 
diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html
index 4dd454352..51d4edaa4 100644
--- a/Doc/Manual/Contents.html
+++ b/Doc/Manual/Contents.html
@@ -841,6 +841,7 @@
 
@@ -1415,6 +1418,7 @@
 
  • Constructors and Destructors
  • Static Member Variables
  • Static Member Functions +
  • Specifying Implemented Interfaces
  • PHP Pragmas, Startup and Shutdown code diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index a0a89c042..8e26a7e8a 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -485,12 +485,12 @@ variables are replaced with. -$parentname +$parentclassname The parent class name (if any) for a method. -$parentsymname +$parentclasssymname The target language parent class name (if any) for a method. @@ -547,7 +547,7 @@ Below shows the expansions for the 1st of the overloaded something wrap The exception.i library file provides support for creating language independent exceptions in your interfaces. To use it, simply put an "%include exception.i" in your interface file. This -creates a function SWIG_exception() that can be used to raise +provides a function SWIG_exception() that can be used to raise common scripting language exceptions in a portable manner. For example :

    @@ -1082,7 +1082,7 @@ For example:
     
     
    -%feature("except") void hello(int i=0, double d=0.0) { ... }
    +%feature("except") hello(int i=0, double d=0.0) { ... }
     void hello(int i=0, double d=0.0);
     
    @@ -1105,7 +1105,7 @@ If the default arguments are not specified in the feature:
    -%feature("except") void hello(int i, double d) { ... }
    +%feature("except") hello(int i, double d) { ... }
     void hello(int i=0, double d=0.0);
     
    diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 93b87a4a4..9a6de9598 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -10,6 +10,7 @@ @@ -67,7 +70,22 @@ checking and runtime library are not used with Go. This should be borne in mind when reading the rest of the SWIG documentation.

    -

    23.2 Running SWIG with Go

    +

    23.2 Examples

    + + +

    +Working examples can be found here: +

    + +

    +The examples in the 2nd link are shipped with the SWIG distribution under the Examples/go directory. +

    + + +

    23.3 Running SWIG with Go

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

    -

    23.2.1 Additional Commandline Options

    +

    23.3.1 Additional Commandline Options

    @@ -150,7 +168,7 @@ swig -go -help -

    23.2.2 Go Output Files

    +

    23.3.2 Go Output Files

    When generating Go code, SWIG will generate the following @@ -226,7 +244,7 @@ this: % go tool 6l main.6

    -

    23.3 A tour of basic C/C++ wrapping

    +

    23.4 A tour of basic C/C++ wrapping

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

    -

    23.3.1 Go Package Name

    +

    23.4.1 Go Package Name

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

    -

    23.3.2 Go Names

    +

    23.4.2 Go Names

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

    -

    23.3.3 Go Constants

    +

    23.4.3 Go Constants

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

    23.3.4 Go Enumerations

    +

    23.4.4 Go Enumerations

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

    -

    23.3.5 Go Classes

    +

    23.4.5 Go Classes

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

    -

    23.3.5.1 Go Class Inheritance

    +

    23.4.5.1 Go Class Memory Management

    + + +

    +Calling NewClassName for some C++ class ClassName +will allocate memory using the C++ memory allocator. This memory will +not be automatically freed by Go's garbage collector as the object ownership is +not tracked. When you are done with the C++ object you must free it manually +using DeleteClassName. +

    + +

    +A common technique is to store the C++ object into a Go object, and +use the Go function runtime.SetFinalizer to free the C++ object when +the Go object is freed. It is strongly recommended to read the +runtime.SetFinalizer +documentation before using this technique to understand its limitations. +For example, if the SWIG package is imported as "wrap": +

    +
    +
    +type GoClassName struct {
    +	w wrap.ClassName
    +}
    +
    +func NewGoClassName() *GoClassName {
    +	r := &GoClassName{wrap.NewClassName()}
    +	runtime.SetFinalizer(r,
    +		func(r *GoClassName) {
    +			wrap.DeleteClassName(r.w)
    +		})
    +	return r
    +}
    +
    +
    + +

    23.4.5.2 Go Class Inheritance

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

    -

    23.3.6 Go Templates

    +

    23.4.6 Go Templates

    @@ -394,7 +448,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. -

    23.3.7 Go Director Classes

    +

    23.4.7 Go Director Classes

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

    -

    23.3.8 Default Go primitive type mappings

    +

    23.4.8 Default Go primitive type mappings

    @@ -544,7 +598,7 @@ that typemap, or add new values, to control how C/C++ types are mapped into Go types.

    -

    23.3.9 Output arguments

    +

    23.4.9 Output arguments

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

  • -

    23.3.10 Adding additional go code

    +

    23.4.10 Adding additional go code

    Often the APIs generated by swig are not very natural in go, especially if @@ -692,5 +746,144 @@ func bar() { +

    23.4.11 Go typemaps

    + + +

    +You can use the %typemap directive to modify SWIG's default +wrapping behavior for specific C/C++ types. You need to be familiar +with the material in the general +"Typemaps" chapter. That chapter +explains how to define a typemap. This section describes some +specific typemaps used for Go. +

    + +

    +In general type conversion code may be written either in C/C++ or in +Go. The choice to make normally depends on where memory should be +allocated. To allocate memory controlled by the Go garbage collector, +write Go code. To allocate memory in the C/C++ heap, write C code. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TypemapDescription
    gotype +The Go type to use for a C++ type. This type will appear in the +generated Go wrapper function. If this is not defined SWIG will use a +default as described above. +
    imtype +An intermediate Go type used by the "goin", "goout", "godirectorin", +and "godirectorout" typemaps. If this typemap is not defined for a +C/C++ type, the gotype typemape will be used. This is useful when +gotype is best converted to C/C++ using Go code. +
    goin +Go code to convert from gotype to imtype when calling a C/C++ +function. SWIG will then internally convert imtype to a C/C++ type +and pass it down. If this is not defined no conversion is done. +
    in +C/C++ code to convert the internally generated C/C++ type, based on +imtype, into the C/C++ type that a function call expects. If this is +not defined the value will simply be cast to the desired type. +
    out +C/C++ code to convert the C/C++ type that a function call returns into +the internally generated C/C++ type, based on imtype, that will be +returned to Go. If this is not defined the value will simply be cast +to the desired type. +
    goout +Go code to convert a value returned from a C/C++ function from imtype +to gotype. If this is not defined no conversion is done. +
    argout +C/C++ code to adjust an argument value when returning from a function. +This is called after the real C/C++ function has run. This uses the +internally generated C/C++ type, based on imtype. This is only useful +for a pointer type of some sort. If this is not defined nothing will +be done. +
    goargout +Go code to adjust an argument value when returning from a function. +This is called after the real C/C++ function has run. The value will +be in imtype. This is only useful for a pointer type of some sort. +If this is not defined nothing will be done. +
    directorin +C/C++ code to convert the C/C++ type used to call a director method +into the internally generated C/C++ type, based on imtype, that will +be passed to Go. If this is not defined the value will simply be cast +to the desired type. +
    godirectorin +Go code to convert a value used to call a director method from imtype +to gotype. If this is not defined no conversion is done. +
    godirectorout +Go code to convert a value returned from a director method from gotype +to imtype. If this is not defined no conversion is done. +
    directorout +C/C++ code to convert a value returned from a director method from the +internally generated C/C++ type, based on imtype, into the type that +the method should return If this is not defined the value will simply +be cast to the desired type. +
    + diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index fb8e5d694..3a4f7ee5d 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -358,7 +358,7 @@ more aggressive from gcc-4.0 onwards and will result in code that fails with str

    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.

    +The name of the module is specified using the %module directive or -module command line option.

    25.2.5 Using your module

    @@ -2441,7 +2441,7 @@ It also contains all the methods in the C++ class it is proxying plus getters an member variables. These functions call the native methods in the intermediary JNI class. The advantage of having this extra layer is the type safety that the proxy class functions offer. It adds static type checking which leads to fewer surprises at runtime. -For example, you can see that if you attempt to use the spam() +For example, you can see that if you attempt to use the spam() function it will only compile when the parameters passed are an int and a Foo. From a user's point of view, it makes the class work as if it were a Java class:

    @@ -4173,8 +4173,8 @@ void *malloc(size_t nbytes);

    If no declaration name is given to %exception, it is applied to all wrapper functions. -The $action is a SWIG special variable and is replaced by the C/C++ function call being wrapped. -The return $null; handles all native method return types, namely those that have a void return and those that do not. +The $action is a SWIG special variable and is replaced by the C/C++ function call being wrapped. +The return $null; handles all native method return types, namely those that have a void return and those that do not. This is useful for typemaps that will be used in native method returning all return types. See the section on Java special variables for further explanation. @@ -5490,6 +5490,15 @@ These are listed below: Use for mapping NULL terminated arrays of C strings to Java String arrays + +unsigned char * +NIOBUFFER +various.i +input
    output +java.nio.Buffer +Use for mapping directly allocated buffers to c/c++. useful with directors and long lived memory objects + +

    25.9.6 Java typemap attributes

    @@ -5570,7 +5579,7 @@ This special variable is usually used for making calls to a function in the inte

    -$null
    +$null
    Used in input typemaps to return early from JNI functions that have either void or a non-void return type. Example:

    diff --git a/Doc/Manual/Javascript.html b/Doc/Manual/Javascript.html index fc24e29c7..cae199048 100644 --- a/Doc/Manual/Javascript.html +++ b/Doc/Manual/Javascript.html @@ -88,6 +88,12 @@ $ swig -javascript -jsc example.i
     $ swig -c++ -javascript -jsc example.i
    +

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

    +

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

    +
    +
    +$ swig -c++ -javascript -v8 -DV8_VERSION=0x032530 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

    @@ -129,6 +135,11 @@ $ make check-javascript-examples ENGINE=jsc
     $ make check-javascript-test-suite ENGINE=jsc
    +

    You can specify a specific V8 version for running the examples and tests

    +
    +
    +$ make check-javascript-examples V8_VERSION=0x032530 ENGINE=v8
    +

    26.2.3 Known Issues

    @@ -184,7 +195,7 @@ $ sudo npm install -g node-gyp

    First create the wrapper using SWIG:

    -$ swig -javascript -node -c++ example.cxx
    +$ swig -javascript -node -c++ example.i

    Then run node-gyp

    @@ -467,7 +478,7 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); virtual double area(void) = 0; @@ -479,7 +490,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(void); virtual double perimeter(void); }; @@ -488,7 +499,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(void); virtual double perimeter(void); }; @@ -765,7 +776,7 @@ class JSEmitter { */ virtual int exitClass(Node *) { return SWIG_OK; - }; + } /** * Invoked at the beginning of the variableHandler. @@ -777,7 +788,7 @@ class JSEmitter { */ virtual int exitVariable(Node *) { return SWIG_OK; - }; + } /** * Invoked at the beginning of the functionHandler. @@ -789,7 +800,7 @@ class JSEmitter { */ virtual int exitFunction(Node *) { return SWIG_OK; - }; + } /** * Invoked by functionWrapper callback after call to Language::functionWrapper. diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 9c3489fb8..46a8941c2 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -59,8 +59,8 @@ Also, there are a dozen or so examples in the Examples/octave directory, and hun

    -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 3.0.3, the Octave module has been tested with Octave versions 3.2.4, 3.4.3, 3.6.4, and 3.8.1. +Use of older Octave versions is not recommended, as these versions are no longer tested with SWIG.

    32.2 Running SWIG

    diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 7e5cccf6a..623adb68a 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -29,6 +29,7 @@
  • Constructors and Destructors
  • Static Member Variables
  • Static Member Functions +
  • Specifying Implemented Interfaces
  • PHP Pragmas, Startup and Shutdown code @@ -113,9 +114,7 @@ more detail in section 27.2.6.

    The usual (and recommended) way is to build the extension as a separate dynamically loaded module (which is supported by all modern operating -systems). You can then specify that this be loaded -automatically in php.ini or load it explicitly for any script which -needs it. +systems).

    @@ -137,16 +136,16 @@ least work for Linux though):

    -	gcc `php-config --includes` -fpic -c example_wrap.c
    -	gcc -shared example_wrap.o -o example.so
    +	gcc `php-config --includes` -fpic -c example_wrap.c example.c
    +	gcc -shared example_wrap.o example.o -o example.so
     

    34.1.2 Using PHP Extensions

    -To test the extension from a PHP script, you need to load it first. You -can load it for every script by adding this line to the [PHP] section of +To test the extension from a PHP script, you first need to tell PHP to +load it. To do this, add a line like this to the [PHP] section of php.ini:

    @@ -155,8 +154,14 @@ can load it for every script by adding this line to the [PHP] section o

    -Alternatively, you can load it explicitly only for scripts which need it -by adding this line to the start of each such PHP script:: +If the module is in PHP's default extension directory, you can omit the path. +

    + +

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

    @@ -164,14 +169,25 @@ by adding this line to the start of each such PHP script::
     

    -SWIG also generates a php module, which -attempts to do the dl() call for you: +But note that this doesn't work when running PHP through a webserver in PHP5.3 +and later - you'll need to use extension in php.ini as +described above. +

    + +

    +The PHP module which SWIG generates will also attempt to do the dl() +call for you if the extension isn't already loaded:

     	include("example.php");
     
    +

    +This PHP module also defines the PHP classes for the wrapped API, so you'll +almost certainly want to include it anyway. +

    +

    34.2 Basic PHP interface

    @@ -220,9 +236,9 @@ echo "E = " . E . "\n";

    There's one peculiarity of how constants work in PHP which it is useful to note (this is not specific to SWIG though) - if you try to use an undeclared -constant, PHP will issue a warning and then expand the constant to a string -version of the constant's name. The warning will often be missed though as -if you're using PHP in a webserver, it will probably end up in error.log or +constant, PHP will emit a notice and then expand the constant to a string +version of the constant's name. Unfortunately it is easy to miss the notice +if you're using PHP in a webserver, as it will probably end up in error.log or similar.

    @@ -756,6 +772,24 @@ Ko::threats(); +

    34.2.6.5 Specifying Implemented Interfaces

    + + +

    +PHP supports the concept of abstract interfaces which a class can implement. +Since SWIG 3.0.3, you can tell SWIG that a wrapped class (for example +MyIterator) implements the Iterator interface like +so: +

    + +
    +%typemap("phpinterfaces") MyIterator "Iterator";
    +
    + +

    +If there are multiple interfaces, just list them separated by commas. +

    +

    34.2.7 PHP Pragmas, Startup and Shutdown code

    diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 8b4f42a43..eb102aa3e 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -194,7 +194,7 @@ int fact(int n);

    -The #define SWIG_FILE_WITH_INIT line inserts a macro that specifies that the +The #define SWIG_FILE_WITH_INIT line inserts a macro that specifies that the resulting C file should be built as a python extension, inserting the module init code. This .i file wraps the following simple C file:

    @@ -395,7 +395,7 @@ of the module prefixed by an underscore. If the name of your module is "_example.so" or "_examplemodule.so". The name of the module is specified using the %module directive or the - -module command line option. +-module command line option.

    @@ -783,8 +783,8 @@ Building a SWIG extension to Python under Windows is roughly similar to the process used with Unix. Using the distutils, it is essentially identical. If you have the same version of the MS compiler that Python was built with (the python2.4 and python2.5 distributed by python.org -are built with Visual Studio 2003), the standard python setup.py -build should just work. +are built with Visual Studio 2003), the standard python setup.py +build should just work.

    @@ -3368,6 +3368,18 @@ print("Loading", "Whizz", "Bang", sep=' ... ') +

    When using %pythoncode and %pythonbegin you generally +want to make sure that the block is delimited by %{ and %}. +If you delimit it with { and } then any lines with a +leading # will be handled by SWIG as preprocessor directives, when +you probably meant them as Python comments. Prior to SWIG 3.0.3, invalid +preprocessor directives were silently ignored, so generally using the wrong +delimiters resulted in such comments not appearing in the generated output +(though a comment starting with a valid preprocessor directive could cause +problems, for example: # error handling). SWIG 3.0.3 and later report +an error for invalid preprocessor directives, so you may have to update +existing interface files to delimit blocks of Python code correctly.

    +

    Sometimes you may want to replace or modify the wrapper function that SWIG creates in the proxy .py file. The Python module in SWIG provides some features that enable you to do this. First, to diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index cdebfe07b..e78447b92 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -147,7 +147,7 @@

    38.1 Preliminaries

    -

    SWIG 1.3 is known to work with Ruby versions 1.6 and later. +

    SWIG 3.0 is known to work with Ruby versions 1.8 and later. Given the choice, you should use the latest stable version of Ruby. You should also determine if your system supports shared libraries and dynamic loading. SWIG will work with or without dynamic loading, but @@ -191,7 +191,7 @@ header file. This file is usually contained in a directory such as

    /usr/lib/ruby/1.8/x86_64-linux-gnu/ruby.h
    -/usr/local/lib/ruby/1.6/i686-linux/ruby.h
    +/usr/include/ruby-2.1.0/ruby.h
     
    @@ -201,8 +201,14 @@ installed, you can run Ruby to find out. For example:

    $ ruby -e 'puts $:.join("\n")'
    -/usr/local/lib/ruby/site_ruby/1.6 /usr/local/lib/ruby/site_ruby/1.6/i686-linux
    -/usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/1.6 /usr/local/lib/ruby/1.6/i686-linux .
    +/usr/local/lib/site_ruby/2.1.0
    +/usr/local/lib/x86_64-linux-gnu/site_ruby
    +/usr/local/lib/site_ruby
    +/usr/lib/ruby/vendor_ruby/2.1.0
    +/usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.1.0
    +/usr/lib/ruby/vendor_ruby
    +/usr/lib/ruby/2.1.0
    +/usr/lib/x86_64-linux-gnu/ruby/2.1.0
     
    @@ -260,7 +266,7 @@ operating system would look something like this:

    $ swig -ruby example.i
     $ gcc -O2 -fPIC -c example.c
    -$ gcc -O2 -fPIC -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
    +$ gcc -O2 -fPIC -c example_wrap.c -I/usr/include/ruby-2.1.0
     $ gcc -shared example.o example_wrap.o -o example.so
     
    @@ -334,7 +340,7 @@ using the C++ compiler. For example:

     $ swig -c++ -ruby example.i
     $ g++ -fPIC -c example.cxx
    -$ g++ -fPIC -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i686-linux
    +$ g++ -fPIC -c example_wrap.cxx -I/usr/include/ruby-2.1.0
     $ g++ -shared example.o example_wrap.o -o example.so
     
    @@ -685,7 +691,7 @@ For example, this struct declaration:

    gets wrapped as a Vector class, with -Ruby instance methods x, x=, +Ruby instance methods x, x=, y and y=. These methods can be used to access structure data from Ruby as follows:

    @@ -1313,7 +1319,7 @@ chapter.

    Some containers in the STL allow you to modify their default behavior by using so called functors or function objects. -Functors are often just a very simple struct with operator() +Functors are often just a very simple struct with operator() redefined or an actual C/C++ function. This allows you, for example, to always keep the sort order of a STL container to your liking.

    @@ -1327,7 +1333,7 @@ this includes std::set, std::multiset and std::multimap.

    -

    The functors in swig are called swig::UnaryFunction +

    The functors in swig are called swig::UnaryFunction and swig::BinaryFunction. For C++ predicates (ie. functors that must return bool as a result) swig::UnaryPredicate @@ -1380,8 +1386,8 @@ values they point at, while the non-const iterators can both read and modify the values.

    The Ruby STL wrappings support both type of iterators by using -a proxy class in-between. This proxy class is swig::Iterator or -swig::ConstIterator. Derived from them are template +a proxy class in-between. This proxy class is swig::Iterator or +swig::ConstIterator. Derived from them are template classes that need to be initialized with the actual iterator for the container you are wrapping and often times with the beginning and ending points of the iteration range.

    @@ -1450,7 +1456,7 @@ i -

    If you'd rather have STL classes without any iterators, you should define -DSWIG_NO_EXPORT_ITERATOR_METHODS when running swig.

    +

    If you'd rather have STL classes without any iterators, you should define -DSWIG_NO_EXPORT_ITERATOR_METHODS when running swig.

    38.3.16 C++ Smart Pointers

    @@ -2823,7 +2829,7 @@ not support optional arguments, such as Java and C#, effectively ignore the value specified by this typemap as all arguments must be given.

    Once a default typemap has been applied to an argument, all -arguments that follow must have default values. See the +arguments that follow must have default values. See the Default/optional arguments section for further information on default argument wrapping.

    @@ -3017,7 +3023,7 @@ catch(char const *_e) {

    Note that if your methods do not have an exception specification yet they do throw exceptions, SWIG cannot know how to -deal with them. For a neat way to handle these, see the Exception +deal with them. For a neat way to handle these, see the Exception handling with %exception section.

    38.7.6.14 directorin typemap

    @@ -4466,7 +4472,7 @@ and then type make to build the shared library:

    $ ruby extconf.rb
     creating Makefile
     $ make
    -g++ -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.7/i686-linux \
    +g++ -fPIC -g -O2 -I. -I/usr/include/ruby-2.1.0 \
     -I. -c shape_wrap.cxx
     gcc -shared -L/usr/local/lib -o shape.so shape_wrap.o -L. \
     -lruby -lruby -lc
    @@ -4997,7 +5003,7 @@ object from its underlying C++ object.

    In general, you will only need to use the SWIG_RubyInstanceFor, which is required for implementing mark functions as shown below. However, if you implement your own free functions (see below) you may -also have to call the SWIG_RubyRemoveTracking and RubyUnlinkObjects +also have to call the SWIG_RubyRemoveTracking and RubyUnlinkObjects methods.

    38.10.4 Mark Functions

    @@ -5351,7 +5357,7 @@ used for callbacks, for example.

    To solve the problem, SWIG can now generate code with director functions containing the optional macros SWIG_INIT_STACK and SWIG_RELEASE_STACK. These macros will try to force Ruby to -reinitiliaze the beginning of the stack the first time a +reinitialize the beginning of the stack the first time a director function is called. This will lead Ruby to measure and not collect any VALUE objects defined from that point on.

    diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index bd929f7d4..4c33aeab8 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -138,6 +138,7 @@ can be obtained by typing swig -help or swig -xml Generate XML wrappers -c++ Enable C++ parsing +-cppext ext Change file extension of C++ generated files to ext (default is cxx, except for PHP which uses cpp) -Dsymbol Define a preprocessor symbol -Fstandard Display error/warning messages in commonly used format -Fmicrosoft Display error/warning messages in Microsoft format @@ -146,7 +147,7 @@ can be obtained by typing swig -help or swig -lfile Include a SWIG library file. -module name Set the name of the SWIG module -o outfile Name of output file --outcurrentdir Set default output dir to current dir instead of input file's path +-outcurrentdir Set default output dir to current dir instead of input file's path -outdir dir Set language specific files output directory -pcreversion Display PCRE version information -swiglib Show location of SWIG library @@ -1046,7 +1047,7 @@ def filecopy(source,target):

    -In this case f1, f2, and buffer are all +In this case f1, f2, and buffer are all opaque objects containing C pointers. It doesn't matter what value they contain--our program works just fine without this knowledge.

    @@ -1711,7 +1712,7 @@ wrapping a header file like this:

    -%rename applies a renaming operation to all future +%rename applies a renaming operation to all future occurrences of a name. The renaming applies to functions, variables, class and structure names, member functions, and member data. For example, if you had two-dozen C++ classes, all with a member function @@ -3316,7 +3317,7 @@ Most importantly, define a type before it is used! A C compiler will tell you if the full type information is not available if it is needed, whereas SWIG will usually not warn or error out as it is designed to work without full type information. However, if type information is not specified -correctly, the wrappers can be sub-optimal and even result in uncompileable C/C++ code. +correctly, the wrappers can be sub-optimal and even result in uncompilable C/C++ code.

  • If your program has a main() function, you may need to rename it (read on). diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index f9558994b..eeca0291c 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -1184,15 +1184,17 @@ public:

    -This produces uncompileable wrapper code because default values in C++ are +This produces uncompilable wrapper code because default values in C++ are evaluated in the same scope as the member function whereas SWIG evaluates them in the scope of a wrapper function (meaning that the values have to be public).

    -This feature is automatically turned on when wrapping C code with default arguments -and whenever keyword arguments (kwargs) are specified for either C or C++ code. +The compactdefaultargs feature is automatically turned on when wrapping C code with default arguments. +Some target languages will also automatically turn on this feature +if the keyword arguments feature (kwargs) is specified for either C or C++ functions, and the target language supports kwargs, +the compactdefaultargs feature is also automatically turned on. Keyword arguments are a language feature of some scripting languages, for example Ruby and Python. SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used.

    @@ -1203,7 +1205,7 @@ SWIG is unable to support kwargs when wrapping overloaded methods, so the defaul

    SWIG wraps class members that are public following the C++ conventions, i.e., by explicit public declaration or by the use of - the using directive. In general, anything specified in a + the using directive. In general, anything specified in a private or protected section will be ignored, although the internal code generator sometimes looks at the contents of the private and protected sections so that it can properly generate code for default @@ -2798,7 +2800,7 @@ public:

    -This code adds a __str__ method to our class for producing a +This code adds a __str__ method to our class for producing a string representation of the object. In Python, such a method would allow us to print the value of an object using the print command. @@ -2847,12 +2849,12 @@ struct Derived : Base {

    The following special variables are expanded if used within a %extend block: -$name, $symname, $overname, $decl, $fulldecl, $parentname and $parentsymname. +$name, $symname, $overname, $decl, $fulldecl, $parentclassname and $parentclasssymname. The Special variables section provides more information each of these special variables.

    -The %extend directive follows all of the same conventions +The %extend directive follows all of the same conventions as its use with C structures. Please refer to the Adding member functions to C structures section for further details.

    @@ -3565,7 +3567,7 @@ It is also possible to separate these declarations from the template class. For template<class T> class List { ... public: - List() { }; + List() { } T get(int index); ... }; @@ -3612,18 +3614,52 @@ and the second will take two integer arguments.

    -Needless to say, SWIG's template support provides plenty of -opportunities to break the universe. That said, an important final -point is that SWIG does not perform extensive error checking of -templates! Specifically, SWIG does not perform type checking nor -does it check to see if the actual contents of the template -declaration make any sense. Since the C++ compiler will hopefully -check this when it compiles the resulting wrapper file, there is no -practical reason for SWIG to duplicate this functionality (besides, -none of the SWIG developers are masochistic enough to want to -implement this right now). +Needless to say, SWIG's template support provides plenty of opportunities to +break the universe. That said, an important final point is that SWIG does +not perform extensive error checking of templates! Specifically, SWIG does +not perform type checking nor does it check to see if the actual contents of the +template declaration make any sense. Since the C++ compiler checks this when it +compiles the resulting wrapper file, there is no practical reason for SWIG to +duplicate this functionality.

    + +

    +As SWIG's template support does not perform type checking %template +can be used as early as after a template declaration. You can, and rarely have +to, use %template before the template parameters have been declared. +For example: +

    + +
    +
    +template <class T> class OuterTemplateClass {};
    +
    +// The nested class OuterClass::InnerClass inherits from the template class
    +// OuterTemplateClass<OuterClass::InnerStruct> and thus the template needs
    +// to be expanded with %template before the OuterClass declaration.
    +%template(OuterTemplateClass_OuterClass__InnerStruct)
    +    OuterTemplateClass<OuterClass::InnerStruct>
    +
    +
    +// Don't forget to use %feature("flatnested") for OuterClass::InnerStruct and
    +// OuterClass::InnerClass if the target language doesn't support nested classes.
    +class OuterClass {
    +    public:
    +        // Forward declarations:
    +        struct InnerStruct;
    +        class InnerClass;
    +};
    +
    +struct OuterClass::InnerStruct {};
    +
    +// Expanding the template at this point with %template is too late as the
    +// OuterClass::InnerClass declaration is processed inside OuterClass.
    +
    +class OuterClass::InnerClass : public OuterTemplateClass<InnerStruct> {};
    +
    +
    +

    Compatibility Note: The first implementation of template support relied heavily on macro expansion in the preprocessor. Templates have been more tightly integrated into @@ -4998,6 +5034,12 @@ class Bar { +

    +If a nested class, within an outer class, has to be used as a template parameter within the outer class, then the template will +have to be instantiated with %template before the beginning of the outer class. +An example can be found in the +Templates section. +

    Compatibility Note: diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index bcae8139d..666069264 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-3.0 Documentation

    -Last update : SWIG-3.0.2 (4 Jun 2014) +Last update : SWIG-3.0.5 (in progress)

    Sections

    diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index c12701ac9..45218f303 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -160,7 +160,7 @@ of the module. If the name of your SWIG module is "example", the name of the corresponding object file should be "example.so". The name of the module is specified using the %module directive or the - -module command line option. + -module command line option.

    39.1.3 Static linking

    @@ -504,7 +504,7 @@ name, but you can override it using the -prefix option.

    -When the -namespace option is used, objects in the module +When the -namespace option is used, objects in the module are always accessed with the namespace name such as Foo::bar.

    @@ -1283,7 +1283,7 @@ you can use it in Tcl like this: % x insert Lager % x get 1 Stout -% puts [l cget -length] +% puts [x cget -length] 3 % @@ -2365,7 +2365,7 @@ Tcl extension by specifying the following in an interface file : $action // Gets substituted by actual function call } catch (RangeError) { - Tcl_SetStringObj(tcl_result,"Array index out-of-bounds"); + Tcl_SetResult(interp, (char *)"Array index out-of-bounds", TCL_STATIC); return TCL_ERROR; } } @@ -2384,7 +2384,7 @@ exception handler to only apply to specific methods like this: $action } catch (RangeError) { - Tcl_SetStringObj(tcl_result,"Array index out-of-bounds"); + Tcl_SetResult(interp, (char *)"Array index out-of-bounds", TCL_STATIC); return TCL_ERROR; } } @@ -2394,7 +2394,7 @@ exception handler to only apply to specific methods like this: $action } catch (RangeError) { - Tcl_SetStringObj(tcl_result,"Array index out-of-bounds"); + Tcl_SetResult(interp, (char *)"Array index out-of-bounds", TCL_STATIC); return TCL_ERROR; } } @@ -2419,7 +2419,7 @@ For example: $action } catch (RangeError) { - Tcl_SetStringObj(tcl_result,"Array index out-of-bounds"); + Tcl_SetResult(interp, (char *)"Array index out-of-bounds", TCL_STATIC); return TCL_ERROR; } } @@ -2921,7 +2921,6 @@ int Tcl_GetDoubleFromObj(Tcl_Interp *, Tcl_Obj *o, double *dp);
     Tcl_Obj  *Tcl_NewStringObj(char *str, int len);
    -void      Tcl_SetStringObj(Tcl_Obj *obj, char *str, int len);
     char     *Tcl_GetStringFromObj(Tcl_Obj *obj, int *len);
     void      Tcl_AppendToObj(Tcl_Obj *obj, char *str, int len);
     
    @@ -3037,9 +3036,10 @@ work)
    -%typemap(out) char * {
    -   Tcl_SetStringObj($result,$1);
    +%typemap(out,noblock=1,fragment="SWIG_FromCharPtr") char *, const char * {
    +  Tcl_SetObjResult(interp,SWIG_FromCharPtr((const char *)$1));
     }
    +
     
    diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index cba524149..040244d45 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -2050,6 +2050,22 @@ wrap_foo() {
    +

    There is an exception: if the variable name starts with the _global_ prefix, +the argument number is not appended. Such variables can be used throughout the generated +wrapper function. For example, the above typemap could be rewritten to use _global_temp +instead of temp and the generated code would then contain a single _global_temp variable +instead of temp1, temp2 and temp3: +

    + +
    +
    +%typemap(in) std::string * (std::string _global_temp) {
    + ... as above ...
    +}
    +
    +
    + +

    Some typemaps do not recognize local variables (or they may simply not apply). At this time, only typemaps that apply to argument conversion support this (input typemaps such as the "in" typemap). @@ -3360,7 +3376,7 @@ list of strings like this:

    -To do this, you not only need to map a list of strings to char *argv[], but the +To do this, you not only need to map a list of strings to char *argv[], but the value of int argc is implicitly determined by the length of the list. Using only simple typemaps, this type of conversion is possible, but extremely painful. Multi-argument typemaps help in this situation. diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 99b89c425..fda162615 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -349,9 +349,9 @@ These can be overridden using command line options, for example:

     $ swig -python -Fstandard example.i
    -example.i:4: Syntax error in input.
    +example.i:4: Syntax error in input(1).
     $ swig -python -Fmicrosoft example.i
    -example.i(4) : Syntax error in input.
    +example.i(4) : Syntax error in input(1).
     

    15.9 Warning number reference

    diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 66ec276be..7ac291cbf 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -130,6 +130,7 @@ OBJS = $(SRCS:.c=.@OBJEXT@) $(CXXSRCS:.cxx=.@OBJEXT@) distclean: rm -f Makefile + rm -f d/example.mk rm -f xml/Makefile ################################################################## @@ -595,7 +596,7 @@ java_cpp: $(SRCDIR_SRCS) # ---------------------------------------------------------------- java_compile: $(SRCDIR_SRCS) - $(COMPILETOOL) $(JAVAC) $(JAVACFLAGS) $(addprefix $(SRCDIR),$(JAVASRCS)) + $(COMPILETOOL) $(JAVAC) $(addprefix $(SRCDIR),$(JAVASRCS)) # ----------------------------------------------------------------- # Run java example @@ -632,9 +633,6 @@ java_clean: ROOT_DIR = @ROOT_DIR@ JSINCLUDES = @JSCOREINC@ @JSV8INC@ JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@ -JSSO =@JSSO@ -JSLDSHARED = @JSLDSHARED@ -JSCXXSHARED = @JSCXXSHARED@ NODEJS = @NODEJS@ NODEGYP = @NODEGYP@ @@ -730,7 +728,7 @@ javascript_clean: rm -rf build rm -f *_wrap* $(RUNME) rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@JSSO@ *.$(SO) + rm -f *.@OBJEXT@ *@SO@ rm -f binding.gyp example-gypcopy.cxx cd $(ROOT_DIR)/Tools/javascript && $(MAKE) -s clean @@ -738,10 +736,10 @@ javascript_clean: ##### ANDROID ###### ################################################################## -ANDROID = android -ANDROID_NDK_BUILD = ndk-build -ANDROID_ADB = adb -ANT = ant +ANDROID = @ANDROID@ +ANDROID_NDK_BUILD = @NDKBUILD@ +ANDROID_ADB = @ADB@ +ANT = @ANT@ TARGETID = 1 # ---------------------------------------------------------------- @@ -784,7 +782,7 @@ android_version: # ----------------------------------------------------------------- android_clean: - test -n "$(SRCDIR)" && cd $(SRCDIR) ; 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 @@ -1095,7 +1093,7 @@ ruby_version: # ----------------------------------------------------------------- ruby_clean: - rm -f *_wrap* *~ .~* myruby@EXEEXT@ *.pm + rm -f *_wrap* *~ .~* myruby@EXEEXT@ rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *$(RUBY_SO) @@ -1396,6 +1394,7 @@ csharp_run: # Version check below also works with MS csc.exe which does not understand --version csharp_version: $(CSHARPCOMPILER) --version | head -n 1 + if test -n "$(CSHARPCILINTERPRETER)" ; then "$(CSHARPCILINTERPRETER)" --version ; fi # ----------------------------------------------------------------- # Cleaning the CSharp examples @@ -1924,7 +1923,7 @@ d_compile: $(SRCDIR_SRCS) # ----------------------------------------------------------------- d_run: - $(RUNTOOL) $(D_RUNME) $(RUNPIPE) + env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(D_RUNME) $(RUNPIPE) # ----------------------------------------------------------------- # Version display diff --git a/Examples/contract/simple_cxx/example.h b/Examples/contract/simple_cxx/example.h index 64b7684fa..de708bb7b 100644 --- a/Examples/contract/simple_cxx/example.h +++ b/Examples/contract/simple_cxx/example.h @@ -7,7 +7,7 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); virtual double area(void) = 0; @@ -19,7 +19,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(void); virtual double perimeter(void); }; @@ -28,7 +28,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(void); virtual double perimeter(void); }; diff --git a/Examples/csharp/reference/example.h b/Examples/csharp/reference/example.h index 4915adb1b..bcfcfb72f 100644 --- a/Examples/csharp/reference/example.h +++ b/Examples/csharp/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/csharp/reference/example.i b/Examples/csharp/reference/example.i index 6daa3b1f4..173143d79 100644 --- a/Examples/csharp/reference/example.i +++ b/Examples/csharp/reference/example.i @@ -29,7 +29,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { @@ -40,7 +40,3 @@ public: } } }; - - - - diff --git a/Examples/d/callback/Makefile b/Examples/d/callback/Makefile index 72edc17a5..ad84231e1 100644 --- a/Examples/d/callback/Makefile +++ b/Examples/d/callback/Makefile @@ -1,27 +1 @@ -ifeq (2,$(D_VERSION)) - WORKING_DIR = d2/ -else - WORKING_DIR = d1/ -endif - -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx -EXTRA_LDFLAGS = example.o example_wrap.o -TARGET = example_wrap -SWIGOPT = -DSRCS = *.d -DFLAGS = -ofrunme - -check: build - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run - -build: - cd $(WORKING_DIR); \ - $(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 SRCDIR='$(SRCDIR)' d_clean +include ../example.mk diff --git a/Examples/d/class/Makefile b/Examples/d/class/Makefile index 72edc17a5..ad84231e1 100644 --- a/Examples/d/class/Makefile +++ b/Examples/d/class/Makefile @@ -1,27 +1 @@ -ifeq (2,$(D_VERSION)) - WORKING_DIR = d2/ -else - WORKING_DIR = d1/ -endif - -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx -EXTRA_LDFLAGS = example.o example_wrap.o -TARGET = example_wrap -SWIGOPT = -DSRCS = *.d -DFLAGS = -ofrunme - -check: build - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run - -build: - cd $(WORKING_DIR); \ - $(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 SRCDIR='$(SRCDIR)' d_clean +include ../example.mk diff --git a/Examples/d/constants/Makefile b/Examples/d/constants/Makefile index 609c7f660..ad84231e1 100644 --- a/Examples/d/constants/Makefile +++ b/Examples/d/constants/Makefile @@ -1,27 +1 @@ -ifeq (2,$(D_VERSION)) - WORKING_DIR = d2/ -else - WORKING_DIR = d1/ -endif - -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -EXTRA_CFLAGS = -I../ example_wrap.c -EXTRA_LDFLAGS = example_wrap.o -TARGET = example_wrap -SWIGOPT = -DSRCS = *.d -DFLAGS = -ofrunme - -check: build - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run - -build: - cd $(WORKING_DIR); \ - $(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 SRCDIR='$(SRCDIR)' d_clean +include ../example.mk diff --git a/Examples/d/constants/example.d b/Examples/d/constants/example.d deleted file mode 100644 index 7448d0ad9..000000000 --- a/Examples/d/constants/example.d +++ /dev/null @@ -1,23 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.41 - * - * Do not make changes to this file unless you know what you are doing--modify - * the SWIG interface file instead. - * ----------------------------------------------------------------------------- */ - -module example; - -static import example_wrap; - -static import tango.stdc.stringz; - -public const int ICONST = 42; -public const double FCONST = 2.1828; -public const char CCONST = 'x'; -public const char CCONST2 = '\n'; -public const char[] SCONST = "Hello World"; -public const char[] SCONST2 = "\"Hello World\""; -public const double EXPR = 42+3*(2.1828); -public const int iconst = 37; -public const double fconst = 3.14; diff --git a/Examples/d/enum/Makefile b/Examples/d/enum/Makefile index 72edc17a5..ad84231e1 100644 --- a/Examples/d/enum/Makefile +++ b/Examples/d/enum/Makefile @@ -1,27 +1 @@ -ifeq (2,$(D_VERSION)) - WORKING_DIR = d2/ -else - WORKING_DIR = d1/ -endif - -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx -EXTRA_LDFLAGS = example.o example_wrap.o -TARGET = example_wrap -SWIGOPT = -DSRCS = *.d -DFLAGS = -ofrunme - -check: build - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run - -build: - cd $(WORKING_DIR); \ - $(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 SRCDIR='$(SRCDIR)' d_clean +include ../example.mk diff --git a/Examples/d/example.mk.in b/Examples/d/example.mk.in new file mode 100644 index 000000000..a1d9a85fc --- /dev/null +++ b/Examples/d/example.mk.in @@ -0,0 +1,59 @@ +# +# Common Makefile code for building D examples. +# +# We actually need to configure this to gain access to the default D version to +# use when D_VERSION is not set. Using Examples/Makefile.in is not enough, as +# the location of the source files (d1/ or d2/) depends on it. The alternative +# would be to add the functionality specific to Examples/d (as opposed to the +# test suite) directly to Examples/Makefile.in. +# +# This file is supposed to be included from a Makefile in the subdirectory +# corresponding to a specific example. +# + +ifeq (,$(D_VERSION)) + D_VERSION = @DDEFAULTVERSION@ +endif + +ifeq (1,$(D_VERSION)) + VERSION_DIR = d1/ +else + VERSION_DIR = d2/ +endif + +EXAMPLES_TOP = ../../.. +SWIG_TOP = ../../../.. +SWIG = $(SWIG_TOP)/preinst-swig +EXTRA_CFLAGS = +EXTRA_CXXFLAGS = +EXTRA_LDFLAGS = +TARGET = example_wrap +SWIGOPT = -outcurrentdir +DFLAGS = -ofrunme + +ifeq (,$(SRCDIR)) +DSRCS = *.d +else +DSRCS = *.d $(addprefix ../$(SRCDIR)$(VERSION_DIR),runme.d) +endif + + +check: build + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' d_run + +build: + mkdir -p $(VERSION_DIR) + if [ -f $(SRCDIR)example.cxx ]; then \ + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CXXFLAGS='$(EXTRA_CXXFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' CXXSRCS='example.cxx' d_cpp; \ + elif [ -f $(SRCDIR)example.c ]; then \ + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' SRCS='example.c' d; \ + else \ + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' SRCS='' d; \ + fi + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean: + if [ -d $(VERSION_DIR) ]; then \ + $(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' d_clean; \ + fi + test -f $(VERSION_DIR)runme.d || rm -rf $(VERSION_DIR) # Only delete dir if out of source diff --git a/Examples/d/extend/Makefile b/Examples/d/extend/Makefile index 72edc17a5..ad84231e1 100644 --- a/Examples/d/extend/Makefile +++ b/Examples/d/extend/Makefile @@ -1,27 +1 @@ -ifeq (2,$(D_VERSION)) - WORKING_DIR = d2/ -else - WORKING_DIR = d1/ -endif - -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx -EXTRA_LDFLAGS = example.o example_wrap.o -TARGET = example_wrap -SWIGOPT = -DSRCS = *.d -DFLAGS = -ofrunme - -check: build - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run - -build: - cd $(WORKING_DIR); \ - $(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 SRCDIR='$(SRCDIR)' d_clean +include ../example.mk diff --git a/Examples/d/funcptr/Makefile b/Examples/d/funcptr/Makefile index 6554c3c73..ad84231e1 100644 --- a/Examples/d/funcptr/Makefile +++ b/Examples/d/funcptr/Makefile @@ -1,27 +1 @@ -ifeq (2,$(D_VERSION)) - WORKING_DIR = d2/ -else - WORKING_DIR = d1/ -endif - -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -EXTRA_CFLAGS = -I../ ../example.c example_wrap.c -EXTRA_LDFLAGS = example.o example_wrap.o -TARGET = example_wrap -SWIGOPT = -DSRCS = *.d -DFLAGS = -ofrunme - -check: build - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run - -build: - cd $(WORKING_DIR); \ - $(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 SRCDIR='$(SRCDIR)' d_clean +include ../example.mk diff --git a/Examples/d/simple/Makefile b/Examples/d/simple/Makefile index f5eed3210..ad84231e1 100644 --- a/Examples/d/simple/Makefile +++ b/Examples/d/simple/Makefile @@ -1,27 +1 @@ -ifeq (2,$(D_VERSION)) - WORKING_DIR = d2/ -else - WORKING_DIR = d1/ -endif - -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -EXTRA_CFLAGS = -I../ ../example.c example_wrap.c -EXTRA_LDFLAGS = example.o example_wrap.o -TARGET = example_wrap -SWIGOPT = -DSRCS = *.d -DFLAGS = -ofrunme - -check: build - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run - -build: - cd $(WORKING_DIR); \ - $(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 SRCDIR='$(SRCDIR)' d_clean +include ../example.mk diff --git a/Examples/d/variables/Makefile b/Examples/d/variables/Makefile index f5eed3210..ad84231e1 100644 --- a/Examples/d/variables/Makefile +++ b/Examples/d/variables/Makefile @@ -1,27 +1 @@ -ifeq (2,$(D_VERSION)) - WORKING_DIR = d2/ -else - WORKING_DIR = d1/ -endif - -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -EXTRA_CFLAGS = -I../ ../example.c example_wrap.c -EXTRA_LDFLAGS = example.o example_wrap.o -TARGET = example_wrap -SWIGOPT = -DSRCS = *.d -DFLAGS = -ofrunme - -check: build - cd $(WORKING_DIR); \ - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run - -build: - cd $(WORKING_DIR); \ - $(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 SRCDIR='$(SRCDIR)' d_clean +include ../example.mk diff --git a/Examples/go/reference/example.h b/Examples/go/reference/example.h index 4915adb1b..bcfcfb72f 100644 --- a/Examples/go/reference/example.h +++ b/Examples/go/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/go/reference/example.i b/Examples/go/reference/example.i index 1cf19c82c..173143d79 100644 --- a/Examples/go/reference/example.i +++ b/Examples/go/reference/example.i @@ -29,7 +29,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { diff --git a/Examples/java/reference/example.h b/Examples/java/reference/example.h index 4915adb1b..bcfcfb72f 100644 --- a/Examples/java/reference/example.h +++ b/Examples/java/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/java/reference/example.i b/Examples/java/reference/example.i index 6daa3b1f4..173143d79 100644 --- a/Examples/java/reference/example.i +++ b/Examples/java/reference/example.i @@ -29,7 +29,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { @@ -40,7 +40,3 @@ public: } } }; - - - - diff --git a/Examples/javascript/example.mk b/Examples/javascript/example.mk index 5a335bba4..cb8a33efd 100644 --- a/Examples/javascript/example.mk +++ b/Examples/javascript/example.mk @@ -7,12 +7,18 @@ else JSENGINE=node endif +ifneq (, $(V8_VERSION)) + JSV8_VERSION=$(V8_VERSION) +else + JSV8_VERSION=0x031110 +endif + EXAMPLES_TOP=../.. SWIG_TOP=../../.. SWIG = $(SWIG_TOP)/preinst-swig TARGET = example INTERFACE = example.i -SWIGOPT=-$(JSENGINE) +SWIGOPT=-$(JSENGINE) -DV8_VERSION=$(JSV8_VERSION) check: build $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' JSENGINE='$(JSENGINE)' TARGET='$(TARGET)' javascript_run diff --git a/Examples/javascript/reference/example.h b/Examples/javascript/reference/example.h index 4915adb1b..bcfcfb72f 100644 --- a/Examples/javascript/reference/example.h +++ b/Examples/javascript/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/javascript/reference/example.i b/Examples/javascript/reference/example.i index 1cf19c82c..173143d79 100644 --- a/Examples/javascript/reference/example.i +++ b/Examples/javascript/reference/example.i @@ -29,7 +29,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { diff --git a/Examples/javascript/template/runme.js b/Examples/javascript/template/runme.js index af96ac7f9..6a29fa77c 100644 --- a/Examples/javascript/template/runme.js +++ b/Examples/javascript/template/runme.js @@ -9,20 +9,20 @@ console.log(example.maxdouble(3.14,2.18)); iv = new example.vecint(100); dv = new example.vecdouble(1000); -for(i=0;i<=100;i++) +for(i=0;i<100;i++) iv.setitem(i,2*i); -for(i=0;i<=1000;i++) +for(i=0;i<1000;i++) dv.setitem(i, 1.0/(i+1)); sum = 0; -for(i=0;i<=100;i++) +for(i=0;i<100;i++) sum = sum + iv.getitem(i); console.log(sum); sum = 0.0; -for(i=0;i<=1000;i++) +for(i=0;i<1000;i++) sum = sum + dv.getitem(i); console.log(sum); diff --git a/Examples/lua/embed2/runme.lua b/Examples/lua/embed2/runme.lua index 9e7ab616c..6e93164c0 100644 --- a/Examples/lua/embed2/runme.lua +++ b/Examples/lua/embed2/runme.lua @@ -3,25 +3,25 @@ print "[lua] This is runme.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 --- this will help us later -for k,v in pairs(example) do _G[k]=v end --- our add function +-- note: we will copy the functions from example table into global +-- this will help us later +for k,v in pairs(example) do _G[k]=v end + +-- our add function -- we will be calling this from C -function add(a,b) - print("[lua] this is function add(",a,b,")") - c=a+b - print("[lua] returning",c) - return c +function add(a,b) + print("[lua] this is function add(",a,b,")") + c=a+b + print("[lua] returning",c) + return c end -function append(a,b) - print("[lua] this is function append(",a,b,")") - c=a..b - print("[lua] returning",c) - return c +function append(a,b) + print("[lua] this is function append(",a,b,")") + c=a..b + print("[lua] returning",c) + return c end diff --git a/Examples/lua/import/base.h b/Examples/lua/import/base.h index fec0f329c..ff6fecdd3 100644 --- a/Examples/lua/import/base.h +++ b/Examples/lua/import/base.h @@ -1,7 +1,7 @@ class Base { public: - Base() { }; - virtual ~Base() { }; + Base() { } + virtual ~Base() { } virtual const char * A() const { return "Base::A"; } diff --git a/Examples/lua/owner/example.h b/Examples/lua/owner/example.h index 320bb2569..9101c6330 100644 --- a/Examples/lua/owner/example.h +++ b/Examples/lua/owner/example.h @@ -8,7 +8,7 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); virtual double area(void) = 0; @@ -20,7 +20,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(void); virtual double perimeter(void); }; @@ -29,7 +29,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(void); virtual double perimeter(void); }; diff --git a/Examples/modula3/reference/example.h b/Examples/modula3/reference/example.h index 0a9cd447f..7b4ba8fb8 100644 --- a/Examples/modula3/reference/example.h +++ b/Examples/modula3/reference/example.h @@ -4,8 +4,8 @@ struct Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } Vector operator+(const Vector &b) const; char *print(); }; diff --git a/Examples/octave/callback/example.i b/Examples/octave/callback/example.i index 3192904db..50ef5096d 100644 --- a/Examples/octave/callback/example.i +++ b/Examples/octave/callback/example.i @@ -1,5 +1,8 @@ /* File : example.i */ %module(directors="1") swigexample + +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/class/example.i b/Examples/octave/class/example.i index b109bcb78..52e9fd3bf 100644 --- a/Examples/octave/class/example.i +++ b/Examples/octave/class/example.i @@ -1,6 +1,8 @@ /* File : example.i */ %module swigexample +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/constants/example.i b/Examples/octave/constants/example.i index 405974b44..ab42a6b21 100644 --- a/Examples/octave/constants/example.i +++ b/Examples/octave/constants/example.i @@ -1,6 +1,8 @@ /* File : example.i */ %module swigexample +%feature("autodoc", 1); + /* A few preprocessor macros */ #define ICONST 42 diff --git a/Examples/octave/contract/example.i b/Examples/octave/contract/example.i index 78c459efc..8976607b2 100644 --- a/Examples/octave/contract/example.i +++ b/Examples/octave/contract/example.i @@ -1,6 +1,8 @@ /* File : example.i */ %module swigexample +%feature("autodoc", 1); + %contract gcd(int x, int y) { require: x >= 0; diff --git a/Examples/octave/enum/example.i b/Examples/octave/enum/example.i index cee9af471..084bab06b 100644 --- a/Examples/octave/enum/example.i +++ b/Examples/octave/enum/example.i @@ -1,6 +1,8 @@ /* File : example.i */ %module swigexample +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/extend/example.i b/Examples/octave/extend/example.i index 953c2f314..3b9ac53c4 100644 --- a/Examples/octave/extend/example.i +++ b/Examples/octave/extend/example.i @@ -1,5 +1,8 @@ /* File : example.i */ %module(directors="1") swigexample + +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/funcptr/example.i b/Examples/octave/funcptr/example.i index 163a1991b..c6fcfe781 100644 --- a/Examples/octave/funcptr/example.i +++ b/Examples/octave/funcptr/example.i @@ -1,5 +1,8 @@ /* File : example.i */ %module swigexample + +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/funcptr2/example.i b/Examples/octave/funcptr2/example.i index 33378a1c1..bbe50fb8f 100644 --- a/Examples/octave/funcptr2/example.i +++ b/Examples/octave/funcptr2/example.i @@ -1,5 +1,8 @@ /* File : example.i */ %module swigexample + +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/functor/example.i b/Examples/octave/functor/example.i index ade20c56c..0c21a8ed6 100644 --- a/Examples/octave/functor/example.i +++ b/Examples/octave/functor/example.i @@ -1,6 +1,7 @@ /* File : example.i */ %module swigexample +%feature("autodoc", 1); %inline %{ // From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514 diff --git a/Examples/octave/module_load/example.i b/Examples/octave/module_load/example.i index fd074d4f2..bd0e39937 100644 --- a/Examples/octave/module_load/example.i +++ b/Examples/octave/module_load/example.i @@ -1,5 +1,8 @@ /* File : example.i */ /* module name given on cmdline */ + +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/operator/example.i b/Examples/octave/operator/example.i index a2d97731d..7fad8e609 100644 --- a/Examples/octave/operator/example.i +++ b/Examples/octave/operator/example.i @@ -1,6 +1,10 @@ /* File : example.i */ %module swigexample + +%feature("autodoc", 1); + #pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ + %{ #include "example.h" %} diff --git a/Examples/octave/pointer/example.i b/Examples/octave/pointer/example.i index 545e3ada4..8b9e0f134 100644 --- a/Examples/octave/pointer/example.i +++ b/Examples/octave/pointer/example.i @@ -1,6 +1,8 @@ /* File : example.i */ %module swigexample +%feature("autodoc", 1); + %{ extern void add(int *, int *, int *); extern void sub(int *, int *, int *); diff --git a/Examples/octave/reference/example.h b/Examples/octave/reference/example.h index 697afafe0..bcfcfb72f 100644 --- a/Examples/octave/reference/example.h +++ b/Examples/octave/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; diff --git a/Examples/octave/reference/example.i b/Examples/octave/reference/example.i index da09800c0..0aa733451 100644 --- a/Examples/octave/reference/example.i +++ b/Examples/octave/reference/example.i @@ -4,6 +4,8 @@ %module swigexample +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/simple/example.i b/Examples/octave/simple/example.i index 127bfcd84..a3006f282 100644 --- a/Examples/octave/simple/example.i +++ b/Examples/octave/simple/example.i @@ -1,6 +1,8 @@ /* File : example.i */ %module swigexample +%feature("autodoc", 1); + %inline %{ extern int gcd(int x, int y); extern double Foo; diff --git a/Examples/octave/template/example.i b/Examples/octave/template/example.i index cfff18ded..3c57f3884 100644 --- a/Examples/octave/template/example.i +++ b/Examples/octave/template/example.i @@ -1,6 +1,8 @@ /* File : example.i */ %module swigexample +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/octave/variables/example.i b/Examples/octave/variables/example.i index 3e11495ad..9d8b03ec2 100644 --- a/Examples/octave/variables/example.i +++ b/Examples/octave/variables/example.i @@ -1,5 +1,8 @@ /* File : example.i */ %module swigexample + +%feature("autodoc", 1); + %{ #include "example.h" %} diff --git a/Examples/perl5/import/base.h b/Examples/perl5/import/base.h index 5a266f68c..c0b47956b 100644 --- a/Examples/perl5/import/base.h +++ b/Examples/perl5/import/base.h @@ -2,8 +2,8 @@ class Base { public: - Base() { }; - virtual ~Base() { }; + Base() { } + virtual ~Base() { } virtual void A() { printf("I'm Base::A\n"); } diff --git a/Examples/perl5/reference/example.h b/Examples/perl5/reference/example.h index 4915adb1b..bcfcfb72f 100644 --- a/Examples/perl5/reference/example.h +++ b/Examples/perl5/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/perl5/reference/example.i b/Examples/perl5/reference/example.i index 6daa3b1f4..173143d79 100644 --- a/Examples/perl5/reference/example.i +++ b/Examples/perl5/reference/example.i @@ -29,7 +29,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { @@ -40,7 +40,3 @@ public: } } }; - - - - diff --git a/Examples/php/disown/example.h b/Examples/php/disown/example.h index 985bc333d..e9f96743f 100644 --- a/Examples/php/disown/example.h +++ b/Examples/php/disown/example.h @@ -9,7 +9,7 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); virtual double area(void) = 0; @@ -22,8 +22,8 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - ~Circle() { }; + Circle(double r) : radius(r) { } + ~Circle() { } void set_radius( double r ); virtual double area(void); virtual double perimeter(void); @@ -33,7 +33,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } ~Square() { } virtual double area(void); virtual double perimeter(void); @@ -44,7 +44,7 @@ private: typedef std::vector::iterator iterator; std::vector shapes; public: - ShapeContainer() : shapes() {}; + ShapeContainer() : shapes() {} ~ShapeContainer(); void addShape( Shape *s ); }; diff --git a/Examples/php/proxy/example.h b/Examples/php/proxy/example.h index 361dff898..0683f07f3 100644 --- a/Examples/php/proxy/example.h +++ b/Examples/php/proxy/example.h @@ -9,7 +9,7 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); virtual double area(void) = 0; @@ -22,8 +22,8 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - ~Circle() { }; + Circle(double r) : radius(r) { } + ~Circle() { } void set_radius( double r ); virtual double area(void); virtual double perimeter(void); @@ -33,7 +33,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } ~Square() { } virtual double area(void); virtual double perimeter(void); diff --git a/Examples/php/reference/example.h b/Examples/php/reference/example.h index 1b88cbf5c..353b88835 100644 --- a/Examples/php/reference/example.h +++ b/Examples/php/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *as_string(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/php/reference/example.i b/Examples/php/reference/example.i index a372439b1..df1459921 100644 --- a/Examples/php/reference/example.i +++ b/Examples/php/reference/example.i @@ -1,10 +1,6 @@ /* File : example.i */ -/* This example has nothing to do with references but the name is used by all - * the other languages so it's hard to rename to something more meaningful. - * - * Mostly it shows how to use %extend. - */ +/* This file has a few "typical" uses of C++ references. */ %module example @@ -33,8 +29,8 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - - /* This wrapper provides an alternative to the [] operator */ + + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { printf("VectorArray extended get: %p %d\n", (void *)$self, index); diff --git a/Examples/python/check.list b/Examples/python/check.list index e9e7c8357..a43a5fca0 100644 --- a/Examples/python/check.list +++ b/Examples/python/check.list @@ -24,7 +24,6 @@ simple smartptr std_vector std_map -swigrun template varargs variables diff --git a/Examples/python/exception/example.i b/Examples/python/exception/example.i index 08672c3a8..817c5221c 100644 --- a/Examples/python/exception/example.i +++ b/Examples/python/exception/example.i @@ -10,3 +10,12 @@ /* Let's just grab the original header file here */ %include "example.h" +%inline %{ +// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} + diff --git a/Examples/python/exception/runme.py b/Examples/python/exception/runme.py index 718707861..9e9241194 100644 --- a/Examples/python/exception/runme.py +++ b/Examples/python/exception/runme.py @@ -20,10 +20,17 @@ try: except RuntimeError,e: print e.args[0] -try: - t.hosed() -except example.Exc,e: - print e.code, e.msg +if not example.is_python_builtin(): + try: + t.hosed() + except example.Exc,e: + print e.code, e.msg +else: + try: + t.hosed() + except BaseException,e: + # Throwing builtin classes as exceptions not supported (-builtin option) + print e for i in range(1,4): try: diff --git a/Examples/python/exceptproxy/example.i b/Examples/python/exceptproxy/example.i index 4a1e0bae9..0a46afbb6 100644 --- a/Examples/python/exceptproxy/example.i +++ b/Examples/python/exceptproxy/example.i @@ -109,6 +109,12 @@ %template(doubleQueue) Queue; - - +%inline %{ +// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/python/exceptproxy/runme.py b/Examples/python/exceptproxy/runme.py index a2ae55584..07e4b0a7f 100644 --- a/Examples/python/exceptproxy/runme.py +++ b/Examples/python/exceptproxy/runme.py @@ -1,10 +1,16 @@ # file: runme.py import example +if example.is_python_builtin(): + print "Skipping example: -builtin option does not support %exceptionclass" + exit(0) + q = example.intQueue(10) print "Inserting items into intQueue" +print type(example.FullError) + try: for i in range(0,100): q.enqueue(i) diff --git a/Examples/python/import/base.h b/Examples/python/import/base.h index 5a266f68c..c0b47956b 100644 --- a/Examples/python/import/base.h +++ b/Examples/python/import/base.h @@ -2,8 +2,8 @@ class Base { public: - Base() { }; - virtual ~Base() { }; + Base() { } + virtual ~Base() { } virtual void A() { printf("I'm Base::A\n"); } diff --git a/Examples/python/import_packages/Makefile b/Examples/python/import_packages/Makefile index d5054fd22..dfd46d05c 100644 --- a/Examples/python/import_packages/Makefile +++ b/Examples/python/import_packages/Makefile @@ -11,7 +11,8 @@ import_packages_subdirs = \ from_init2 \ from_init3 \ relativeimport1 \ - relativeimport1 + relativeimport2 \ + relativeimport3 check: build if test "x$(SRCDIR)" != x; then \ diff --git a/Examples/python/import_packages/from_init1/runme.py b/Examples/python/import_packages/from_init1/runme.py index c23a085fa..bbe092bab 100644 --- a/Examples/python/import_packages/from_init1/runme.py +++ b/Examples/python/import_packages/from_init1/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) + python 'import' in __init__.py" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + if sys.version_info < (3,0): import py2.pkg2 print " Finished importing py2.pkg2" diff --git a/Examples/python/import_packages/from_init2/runme.py b/Examples/python/import_packages/from_init2/runme.py index c23a085fa..bbe092bab 100644 --- a/Examples/python/import_packages/from_init2/runme.py +++ b/Examples/python/import_packages/from_init2/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) + python 'import' in __init__.py" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + if sys.version_info < (3,0): import py2.pkg2 print " Finished importing py2.pkg2" diff --git a/Examples/python/import_packages/from_init3/runme.py b/Examples/python/import_packages/from_init3/runme.py index c23a085fa..bbe092bab 100644 --- a/Examples/python/import_packages/from_init3/runme.py +++ b/Examples/python/import_packages/from_init3/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) + python 'import' in __init__.py" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + if sys.version_info < (3,0): import py2.pkg2 print " Finished importing py2.pkg2" diff --git a/Examples/python/import_packages/relativeimport1/runme.py b/Examples/python/import_packages/relativeimport1/runme.py index 44ce8d1c4..99b6e513e 100644 --- a/Examples/python/import_packages/relativeimport1/runme.py +++ b/Examples/python/import_packages/relativeimport1/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) with -relativeimport" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) with -relativeimport" + if sys.version_info < (3,0): import py2.pkg2.bar print " Finished importing py2.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/runme.py b/Examples/python/import_packages/relativeimport2/runme.py index ac60eb630..f0ab6c446 100644 --- a/Examples/python/import_packages/relativeimport2/runme.py +++ b/Examples/python/import_packages/relativeimport2/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) + python 'import' in __init__.py" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + if sys.version_info < (3,0): import py2.pkg2.bar print " Finished importing py2.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/runme3.py b/Examples/python/import_packages/relativeimport2/runme3.py deleted file mode 100644 index 4b0d112cf..000000000 --- a/Examples/python/import_packages/relativeimport2/runme3.py +++ /dev/null @@ -1,9 +0,0 @@ -# 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/relativeimport3/Makefile b/Examples/python/import_packages/relativeimport3/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/README b/Examples/python/import_packages/relativeimport3/README new file mode 100644 index 000000000..a99ef2426 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py2/Makefile b/Examples/python/import_packages/relativeimport3/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py2/__init__.py b/Examples/python/import_packages/relativeimport3/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport3/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport3/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py2/pkg2/__init__.py b/Examples/python/import_packages/relativeimport3/py2/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport3/py2/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport3/py2/pkg2/bar.hpp new file mode 100644 index 000000000..8f09cd5fa --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py2/pkg2/bar.i b/Examples/python/import_packages/relativeimport3/py2/pkg2/bar.i new file mode 100644 index 000000000..6f4690b25 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import (module="foo", package="py2.pkg2.pkg3") "../../py2/pkg2/pkg3/foo.hpp" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..b6c89a431 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py2/pkg2/pkg3/foo.i b/Examples/python/import_packages/relativeimport3/py2/pkg2/pkg3/foo.i new file mode 100644 index 000000000..ba32483d2 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py3/Makefile b/Examples/python/import_packages/relativeimport3/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py3/__init__.py b/Examples/python/import_packages/relativeimport3/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport3/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport3/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py3/pkg2/__init__.py b/Examples/python/import_packages/relativeimport3/py3/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport3/py3/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport3/py3/pkg2/bar.hpp new file mode 100644 index 000000000..408d910d7 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py3/pkg2/bar.i b/Examples/python/import_packages/relativeimport3/py3/pkg2/bar.i new file mode 100644 index 000000000..157c62e2c --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import (module="foo", package="py3.pkg2.pkg3") "../../py3/pkg2/pkg3/foo.hpp" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..531721d36 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/py3/pkg2/pkg3/foo.i b/Examples/python/import_packages/relativeimport3/py3/pkg2/pkg3/foo.i new file mode 100644 index 000000000..c6ba529b7 --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/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/relativeimport3/runme.py b/Examples/python/import_packages/relativeimport3/runme.py new file mode 100644 index 000000000..99b6e513e --- /dev/null +++ b/Examples/python/import_packages/relativeimport3/runme.py @@ -0,0 +1,13 @@ +import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) with -relativeimport" + +if sys.version_info < (3,0): + import py2.pkg2.bar + print " Finished importing py2.pkg2.bar" +else: + import py3.pkg2.bar + print " Finished importing py3.pkg2.bar" diff --git a/Examples/python/import_packages/same_modnames1/runme.py b/Examples/python/import_packages/same_modnames1/runme.py index 923f0e0bb..7bec1ec1e 100644 --- a/Examples/python/import_packages/same_modnames1/runme.py +++ b/Examples/python/import_packages/same_modnames1/runme.py @@ -1,5 +1,9 @@ +import os.path + # Test import of same modules from different packages -print "Testing %module(package=...) + %import + same modules in different packages" +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + import pkg2.foo print " Finished importing pkg2.foo" diff --git a/Examples/python/import_packages/same_modnames2/runme.py b/Examples/python/import_packages/same_modnames2/runme.py index af8f78194..eec6121eb 100644 --- a/Examples/python/import_packages/same_modnames2/runme.py +++ b/Examples/python/import_packages/same_modnames2/runme.py @@ -1,3 +1,8 @@ +import os.path + +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + import pkg1.pkg2.foo print " Finished importing pkg1.pkg2.foo" diff --git a/Examples/python/import_template/base.h b/Examples/python/import_template/base.h index c755a6f9d..8faafb3d7 100644 --- a/Examples/python/import_template/base.h +++ b/Examples/python/import_template/base.h @@ -2,8 +2,8 @@ template class Base { public: - Base() { }; - virtual ~Base() { }; + Base() { } + virtual ~Base() { } virtual void A() { printf("I'm Base::A\n"); } diff --git a/Examples/python/reference/example.h b/Examples/python/reference/example.h index 4915adb1b..bcfcfb72f 100644 --- a/Examples/python/reference/example.h +++ b/Examples/python/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/python/reference/example.i b/Examples/python/reference/example.i index 8c95b3213..8af8397ec 100644 --- a/Examples/python/reference/example.i +++ b/Examples/python/reference/example.i @@ -31,7 +31,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { @@ -42,7 +42,3 @@ public: } } }; - - - - diff --git a/Examples/python/smartptr/example.h b/Examples/python/smartptr/example.h index c0f9b1d57..c18e7eaf4 100644 --- a/Examples/python/smartptr/example.h +++ b/Examples/python/smartptr/example.h @@ -7,7 +7,7 @@ public: } virtual ~Shape() { nshapes--; - }; + } double x, y; void move(double dx, double dy); virtual double area() = 0; @@ -19,7 +19,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(); }; diff --git a/Examples/python/swigrun/Makefile b/Examples/python/swigrun/Makefile deleted file mode 100644 index 94f7d04e0..000000000 --- a/Examples/python/swigrun/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx -TARGET = example -INTERFACE = example.i -LIBS = -lm -SWIGOPT = - -check: build - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run - -build: - $(SWIG) -python -external-runtime - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp - -static: - $(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 SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean - rm -f swigpyrun.h diff --git a/Examples/python/swigrun/example.cxx b/Examples/python/swigrun/example.cxx deleted file mode 100644 index 2d2471301..000000000 --- a/Examples/python/swigrun/example.cxx +++ /dev/null @@ -1,20 +0,0 @@ -/* File : example.cxx */ - -#include -#include "swigpyrun.h" -#include "example.h" - - -Manager* convert_to_Manager(PyObject *py_obj) -{ - Manager* c_ptr; - swig_type_info *ty = SWIG_TypeQuery("Manager *"); - printf("manager ty %p \n", (void *)ty); - if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty, 0) == -1) { - c_ptr = 0; - } else { - Py_XINCREF(py_obj); - } - return c_ptr; -} - diff --git a/Examples/python/swigrun/example.h b/Examples/python/swigrun/example.h deleted file mode 100644 index e89f7baaa..000000000 --- a/Examples/python/swigrun/example.h +++ /dev/null @@ -1,58 +0,0 @@ -/* 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; - } -}; - -Manager* convert_to_Manager(PyObject *obj); - diff --git a/Examples/python/swigrun/example.i b/Examples/python/swigrun/example.i deleted file mode 100644 index c8ec32e09..000000000 --- a/Examples/python/swigrun/example.i +++ /dev/null @@ -1,15 +0,0 @@ -/* 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; - -%include "example.h" - diff --git a/Examples/python/swigrun/runme.py b/Examples/python/swigrun/runme.py deleted file mode 100644 index abcd96463..000000000 --- a/Examples/python/swigrun/runme.py +++ /dev/null @@ -1,28 +0,0 @@ -# file: runme.py - -# This file illustrates the cross language polymorphism using directors. - -import example - - -# CEO class, which overrides Employee::getPosition(). - -class CEO(example.Manager): - def __init__(self, name): - example.Manager.__init__(self, name) - def getPosition(self): - return "CEO" - def __del__(self): - print "CEO.__del__(),", self.getName() - # for proxy class extensions that are not "disowned" and - # define a __del__ method, it is very important to call the - # base class __del__. otherwise the c++ objects will never - # be deleted. - example.Manager.__del__(self) - - - - -e = CEO("Alice") -m = example.convert_to_Manager(e) -print m diff --git a/Examples/ruby/reference/example.h b/Examples/ruby/reference/example.h index 4915adb1b..bcfcfb72f 100644 --- a/Examples/ruby/reference/example.h +++ b/Examples/ruby/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/ruby/reference/example.i b/Examples/ruby/reference/example.i index 6daa3b1f4..173143d79 100644 --- a/Examples/ruby/reference/example.i +++ b/Examples/ruby/reference/example.i @@ -29,7 +29,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { @@ -40,7 +40,3 @@ public: } } }; - - - - diff --git a/Examples/tcl/reference/example.h b/Examples/tcl/reference/example.h index 4915adb1b..bcfcfb72f 100644 --- a/Examples/tcl/reference/example.h +++ b/Examples/tcl/reference/example.h @@ -4,8 +4,8 @@ class Vector { private: double x,y,z; public: - Vector() : x(0), y(0), z(0) { }; - Vector(double x, double y, double z) : x(x), y(y), z(z) { }; + Vector() : x(0), y(0), z(0) { } + Vector(double x, double y, double z) : x(x), y(y), z(z) { } friend Vector operator+(const Vector &a, const Vector &b); char *print(); }; @@ -20,7 +20,3 @@ public: Vector &operator[](int); int size(); }; - - - - diff --git a/Examples/tcl/reference/example.i b/Examples/tcl/reference/example.i index 6daa3b1f4..173143d79 100644 --- a/Examples/tcl/reference/example.i +++ b/Examples/tcl/reference/example.i @@ -29,7 +29,7 @@ public: VectorArray(int maxsize); ~VectorArray(); int size(); - + /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { @@ -40,7 +40,3 @@ public: } } }; - - - - diff --git a/Examples/test-suite/allowexcept.i b/Examples/test-suite/allowexcept.i index 37b01cd75..c901295df 100644 --- a/Examples/test-suite/allowexcept.i +++ b/Examples/test-suite/allowexcept.i @@ -21,7 +21,7 @@ UVW Bar::static_member_variable; %} -// Now test the allowexcept feature by making the usual $action uncompileable and ensuring the %exception is picked up +// Now test the allowexcept feature by making the usual $action uncompilable and ensuring the %exception is picked up struct XYZ { }; diff --git a/Examples/test-suite/autodoc.i b/Examples/test-suite/autodoc.i index 599a3f12f..d85899756 100644 --- a/Examples/test-suite/autodoc.i +++ b/Examples/test-suite/autodoc.i @@ -133,3 +133,11 @@ typedef int Integer; void banana(S *a, const struct tagS *b, int c, Integer d) {} %} +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 05cb8cbd7..6376bc79d 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -86,6 +86,7 @@ Makefile: $(srcdir)/Makefile.in ../../../config.status CPP_TEST_BROKEN += \ constants \ cpp_broken \ + director_nested_class \ exception_partial_info \ extend_variable \ li_std_vector_ptr \ @@ -142,6 +143,7 @@ CPP_TEST_CASES += \ class_scope_weird \ compactdefaultargs \ const_const_2 \ + constant_directive \ constant_pointers \ constover \ constructor_copy \ @@ -172,6 +174,7 @@ CPP_TEST_CASES += \ director_abstract \ director_alternating \ director_basic \ + director_property \ director_binary_string \ director_classes \ director_classic \ @@ -248,6 +251,7 @@ CPP_TEST_CASES += \ insert_directive \ keyword_rename \ kind \ + kwargs_feature \ langobj \ li_attribute \ li_attribute_template \ @@ -295,6 +299,7 @@ CPP_TEST_CASES += \ nested_directors \ nested_comment \ nested_scope \ + nested_template_base \ nested_workaround \ newobject1 \ null_pointer \ @@ -309,6 +314,7 @@ CPP_TEST_CASES += \ overload_extend \ overload_method \ overload_numeric \ + overload_polymorphic \ overload_rename \ overload_return_type \ overload_simple \ @@ -379,6 +385,7 @@ CPP_TEST_CASES += \ template_classes \ template_const_ref \ template_construct \ + template_templated_constructors \ template_default \ template_default2 \ template_default_arg \ @@ -510,6 +517,7 @@ CPP11_TEST_CASES = \ cpp11_decltype \ cpp11_default_delete \ cpp11_delegating_constructors \ + cpp11_director_enums \ cpp11_explicit_conversion_operators \ cpp11_final_override \ cpp11_function_objects \ @@ -526,6 +534,7 @@ CPP11_TEST_CASES = \ cpp11_rvalue_reference3 \ cpp11_sizeof_object \ cpp11_static_assert \ + cpp11_strongly_typed_enumerations \ cpp11_thread_local \ cpp11_template_double_brackets \ cpp11_template_explicit \ @@ -538,7 +547,6 @@ CPP11_TEST_CASES = \ # Broken C++11 test cases. CPP11_TEST_BROKEN = \ # cpp11_hash_tables \ # not fully implemented yet -# cpp11_strongly_typed_enumerations \ # SWIG not quite getting this right yet in all langs # cpp11_variadic_templates \ # Broken for some languages (such as Java) # cpp11_reference_wrapper \ # No typemaps diff --git a/Examples/test-suite/constant_directive.i b/Examples/test-suite/constant_directive.i new file mode 100644 index 000000000..8204720d6 --- /dev/null +++ b/Examples/test-suite/constant_directive.i @@ -0,0 +1,28 @@ +%module constant_directive + +// %constant and struct +%{ + struct Type1 { + Type1(int val = 0) : val(val) {} + int val; + }; + static Type1 TYPE1_CONSTANT1(1); + static Type1 TYPE1_CONST2(2); + static Type1 TYPE1_CONST3(3); +%} + +struct Type1 { + Type1(int val = 0) : val(val) {} + int val; +}; + +%inline %{ +Type1 getType1Instance() { return Type1(111); } +%} + +%constant Type1 TYPE1_CONSTANT1; +%constant Type1 TYPE1_CONSTANT2 = TYPE1_CONST2; +%constant Type1 *TYPE1_CONSTANT3 = &TYPE1_CONST3; + +%constant int TYPE_INT = 0; + diff --git a/Examples/test-suite/cpp11_constexpr.i b/Examples/test-suite/cpp11_constexpr.i index 412b8132a..d91107cc6 100644 --- a/Examples/test-suite/cpp11_constexpr.i +++ b/Examples/test-suite/cpp11_constexpr.i @@ -18,6 +18,12 @@ struct ConstExpressions { static const int LLL = 300; constexpr int MMM() { return 400; } constexpr const int NNN() { return 500; } + // Regression tests for support added in SWIG 3.0.4: + static constexpr const int JJJ1 = 101; + constexpr static int KKK1 = 201; + // Regression tests for https://github.com/swig/swig/issues/284 : + explicit constexpr ConstExpressions(int) { } + constexpr explicit ConstExpressions(double) { } }; %} diff --git a/Examples/test-suite/cpp11_director_enums.i b/Examples/test-suite/cpp11_director_enums.i new file mode 100644 index 000000000..420b3c8c9 --- /dev/null +++ b/Examples/test-suite/cpp11_director_enums.i @@ -0,0 +1,14 @@ +%module(directors="1") cpp11_director_enums + +%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Cpp11DirectorEnumsCallback::g; + +%director Cpp11DirectorEnumsCallback; + +%inline %{ +enum class Color { Red, Green, Blue=10 }; +struct Cpp11DirectorEnumsCallback { + virtual Color f(Color c) = 0; + virtual const Color & g(const Color &c) = 0; + virtual ~Cpp11DirectorEnumsCallback() {} +}; +%} diff --git a/Examples/test-suite/cpp11_function_objects.i b/Examples/test-suite/cpp11_function_objects.i index fb75edea6..e80f60a2f 100644 --- a/Examples/test-suite/cpp11_function_objects.i +++ b/Examples/test-suite/cpp11_function_objects.i @@ -3,25 +3,31 @@ Function objects are objects which overload the operator() function. The std::function does not provide any seamless support in the target languages yet. */ -%module cpp11_function_objects +%module(directors="1") cpp11_function_objects %rename(__call__) Test::operator(); +%feature("director") Test; + %inline %{ -struct Test { +class Test { +public: int value; - void operator()(int x, int y) { + virtual void operator()(int x, int y) { value=x+y; } Test() : value(0) {} -} test; + virtual ~Test() {} +}; + +Test test; #include std::function pF = test; -int testit1(Test new_test, int a, int b) { - pF = new_test; +int testit1(Test &new_test, int a, int b) { + pF = std::ref(new_test); pF(a, b); return new_test.value; } diff --git a/Examples/test-suite/cpp11_strongly_typed_enumerations.i b/Examples/test-suite/cpp11_strongly_typed_enumerations.i index ed466369e..3a4ee107a 100644 --- a/Examples/test-suite/cpp11_strongly_typed_enumerations.i +++ b/Examples/test-suite/cpp11_strongly_typed_enumerations.i @@ -1,11 +1,9 @@ -/* This testcase checks whether SWIG produces the correct wrapper for the - strongly typed enums. Enums with the same type are comparable. Enum classes - require support for nested classes. */ +// This testcase checks whether SWIG produces the correct wrappers for strongly typed enums. + %module cpp11_strongly_typed_enumerations -%warnfilter(302) Val1; -%warnfilter(302) Val2; -%warnfilter(302) Val3; -%warnfilter(302) Val4; + +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Class1::Struct1; +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Class2::Struct1; /* Forward declarations (illegally accepted by SWIG - oh well!) */ enum Enum1 : short; @@ -17,15 +15,19 @@ enum : unsigned short; enum class Enum1 { Val1, Val2, - Val3 = 100, - Val4 /* = 101 */ + Val3 = 13, + Val4, + Val5a = 13, + Val6a }; enum class Enum2 : short { Val1, Val2, - Val3 = 100, - Val4 + Val3 = 23, + Val4, + Val5b = 23, + Val6b }; %} @@ -39,24 +41,24 @@ enum class Enum5; // Legal in C++11, because enum class declarati enum class Enum6 : unsigned int; // Legal C++11. enum Enum4 : unsigned int { - Val1, Val2, Val3 = 100, Val4 + Val1, Val2, Val3 = 43, Val4 }; enum class Enum5 { - Val1, Val2, Val3 = 100, Val4 + Val1, Val2, Val3 = 53, Val4 }; enum class Enum6 : unsigned int { - Val1, Val2, Val3 = 300, Val4 + Val1, Val2, Val3 = 63, Val4 }; typedef enum class Enum7 : unsigned int { - Val1, Val2, Val3 = 300, Val4 + Val1, Val2, Val3 = 73, Val4 } Enum7td; // enum inherits from non-primitive type enum class Enum8 : size_t { - Val1, Val2, Val3 = 300, Val4 + Val1, Val2, Val3 = 83, Val4 }; template struct TType { @@ -64,7 +66,7 @@ template struct TType { }; enum class Enum10 : TType::type_name { - Val1, Val2, Val3 = 300, Val4 + Val1, Val2, Val3 = 103, Val4 }; // forward declaration, no definition of enum @@ -73,15 +75,144 @@ struct UseEnum11 { Enum11 myenum11; }; -/* -TODO -enum class MyClass {AAA, BBB, CCC}; -namespace Space { -enum MyEnum {XXX, YYY, ZZZ}; -} -struct SSS { - MyClass m; +class Class1 +{ +public: + enum class Enum12 + { + Val1 = 1121, + Val2 = 1122, + Val3, + Val4, + Val5c = 1121, + Val6c + }; + + enum Enum13 + { + Val1 = 1131, + Val2 = 1132, + Val3, + Val4, + Val5d = 1131, + Val6d + }; + + enum class Enum14 + { + Val1 = 1141, + Val2 = 1142, + Val3, + Val4, + Val5e = 1141, + Val6e + }; + + struct Struct1 + { + enum class Enum12 + { + Val1 = 3121, + Val2 = 3122, + Val3, + Val4, + Val5f = 3121, + Val6f + }; + + enum Enum13 + { + Val1 = 3131, + Val2 = 3132, + Val3, + Val4, + }; + + enum class Enum14 + { + Val1 = 3141, + Val2 = 3142, + Val3, + Val4, + Val5g = 3141, + Val6g + }; + }; + Enum1 class1Test1(Enum1 e) { return e; } + Enum12 class1Test2(Enum12 e) { return e; } + Struct1::Enum12 class1Test3(Struct1::Enum12 e) { return e; } }; -*/ + +class Class2 +{ +public: + enum class Enum12 + { + Val1 = 2121, + Val2 = 2122, + Val3, + Val4, + Val5h = 2121, + Val6h + }; + + enum Enum13 + { + Val1 = 2131, + Val2 = 2132, + Val3, + Val4, + Val5i = 2131, + Val6i + }; + + enum class Enum14 + { + Val1 = 2141, + Val2 = 2142, + Val3, + Val4, + Val5j = 2141, + Val6j + }; + + struct Struct1 + { + enum class Enum12 + { + Val1 = 4121, + Val2 = 4122, + Val3, + Val4, + Val5k = 4121, + Val6k + }; + + enum Enum13 + { + Val1 = 4131, + Val2 = 4132, + Val3, + Val4, + Val5l = 4131, + Val6l + }; + + enum class Enum14 + { + Val1 = 4141, + Val2 = 4142, + Val3, + Val4, + Val5m = 4141, + Val6m + }; + }; +}; + +Enum1 globalTest1(Enum1 e) { return e; } +Class1::Enum12 globalTest2(Class1::Enum12 e) { return e; } +Class1::Struct1::Enum12 globalTest3(Class1::Struct1::Enum12 e) { return e; } + %} diff --git a/Examples/test-suite/cpp11_strongly_typed_enumerations_simple.i b/Examples/test-suite/cpp11_strongly_typed_enumerations_simple.i new file mode 100644 index 000000000..3848d2940 --- /dev/null +++ b/Examples/test-suite/cpp11_strongly_typed_enumerations_simple.i @@ -0,0 +1,5 @@ +%module cpp11_strongly_typed_enumerations_simple + +%include + +%include "cpp11_strongly_typed_enumerations.i" diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 7bec108eb..292c751e4 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -28,6 +28,9 @@ CPP_TEST_CASES = \ intermediary_classname \ li_boost_intrusive_ptr +CPP11_TEST_CASES = \ + cpp11_strongly_typed_enumerations_simple \ + include $(srcdir)/../common.mk # Overridden variables here diff --git a/Examples/test-suite/csharp/cpp11_strongly_typed_enumerations_runme.cs b/Examples/test-suite/csharp/cpp11_strongly_typed_enumerations_runme.cs new file mode 100644 index 000000000..f2c25e7a2 --- /dev/null +++ b/Examples/test-suite/csharp/cpp11_strongly_typed_enumerations_runme.cs @@ -0,0 +1,169 @@ +using System; +using cpp11_strongly_typed_enumerationsNamespace; + +public class cpp11_strongly_typed_enumerations_runme { + + public static int enumCheck(int actual, int expected) { + if (actual != expected) + throw new ApplicationException("Enum value mismatch. Expected " + expected + " Actual: " + actual); + return expected + 1; + } + + public static void Main() { + int val = 0; + val = enumCheck((int)Enum1.Val1, val); + val = enumCheck((int)Enum1.Val2, val); + val = enumCheck((int)Enum1.Val3, 13); + val = enumCheck((int)Enum1.Val4, val); + val = enumCheck((int)Enum1.Val5a, 13); + val = enumCheck((int)Enum1.Val6a, val); + + val = 0; + val = enumCheck((int)Enum2.Val1, val); + val = enumCheck((int)Enum2.Val2, val); + val = enumCheck((int)Enum2.Val3, 23); + val = enumCheck((int)Enum2.Val4, val); + val = enumCheck((int)Enum2.Val5b, 23); + val = enumCheck((int)Enum2.Val6b, val); + + val = 0; + val = enumCheck((int)Enum4.Val1, val); + val = enumCheck((int)Enum4.Val2, val); + val = enumCheck((int)Enum4.Val3, 43); + val = enumCheck((int)Enum4.Val4, val); + + val = 0; + val = enumCheck((int)Enum5.Val1, val); + val = enumCheck((int)Enum5.Val2, val); + val = enumCheck((int)Enum5.Val3, 53); + val = enumCheck((int)Enum5.Val4, val); + + val = 0; + val = enumCheck((int)Enum6.Val1, val); + val = enumCheck((int)Enum6.Val2, val); + val = enumCheck((int)Enum6.Val3, 63); + val = enumCheck((int)Enum6.Val4, val); + + val = 0; + val = enumCheck((int)Enum7td.Val1, val); + val = enumCheck((int)Enum7td.Val2, val); + val = enumCheck((int)Enum7td.Val3, 73); + val = enumCheck((int)Enum7td.Val4, val); + + val = 0; + val = enumCheck((int)Enum8.Val1, val); + val = enumCheck((int)Enum8.Val2, val); + val = enumCheck((int)Enum8.Val3, 83); + val = enumCheck((int)Enum8.Val4, val); + + val = 0; + val = enumCheck((int)Enum10.Val1, val); + val = enumCheck((int)Enum10.Val2, val); + val = enumCheck((int)Enum10.Val3, 103); + val = enumCheck((int)Enum10.Val4, val); + + val = 0; + val = enumCheck((int)Class1.Enum12.Val1, 1121); + val = enumCheck((int)Class1.Enum12.Val2, 1122); + val = enumCheck((int)Class1.Enum12.Val3, val); + val = enumCheck((int)Class1.Enum12.Val4, val); + val = enumCheck((int)Class1.Enum12.Val5c, 1121); + val = enumCheck((int)Class1.Enum12.Val6c, val); + + val = 0; + val = enumCheck((int)Class1.Enum13.Val1, 1131); + val = enumCheck((int)Class1.Enum13.Val2, 1132); + val = enumCheck((int)Class1.Enum13.Val3, val); + val = enumCheck((int)Class1.Enum13.Val4, val); + val = enumCheck((int)Class1.Enum13.Val5d, 1131); + val = enumCheck((int)Class1.Enum13.Val6d, val); + + val = 0; + val = enumCheck((int)Class1.Enum14.Val1, 1141); + val = enumCheck((int)Class1.Enum14.Val2, 1142); + val = enumCheck((int)Class1.Enum14.Val3, val); + val = enumCheck((int)Class1.Enum14.Val4, val); + val = enumCheck((int)Class1.Enum14.Val5e, 1141); + val = enumCheck((int)Class1.Enum14.Val6e, val); + + val = 0; + val = enumCheck((int)Class1.Struct1.Enum12.Val1, 3121); + val = enumCheck((int)Class1.Struct1.Enum12.Val2, 3122); + val = enumCheck((int)Class1.Struct1.Enum12.Val3, val); + val = enumCheck((int)Class1.Struct1.Enum12.Val4, val); + val = enumCheck((int)Class1.Struct1.Enum12.Val5f, 3121); + val = enumCheck((int)Class1.Struct1.Enum12.Val6f, val); + + val = 0; + val = enumCheck((int)Class1.Struct1.Enum13.Val1, 3131); + val = enumCheck((int)Class1.Struct1.Enum13.Val2, 3132); + val = enumCheck((int)Class1.Struct1.Enum13.Val3, val); + val = enumCheck((int)Class1.Struct1.Enum13.Val4, val); + + val = 0; + val = enumCheck((int)Class1.Struct1.Enum14.Val1, 3141); + val = enumCheck((int)Class1.Struct1.Enum14.Val2, 3142); + val = enumCheck((int)Class1.Struct1.Enum14.Val3, val); + val = enumCheck((int)Class1.Struct1.Enum14.Val4, val); + val = enumCheck((int)Class1.Struct1.Enum14.Val5g, 3141); + val = enumCheck((int)Class1.Struct1.Enum14.Val6g, val); + + val = 0; + val = enumCheck((int)Class2.Enum12.Val1, 2121); + val = enumCheck((int)Class2.Enum12.Val2, 2122); + val = enumCheck((int)Class2.Enum12.Val3, val); + val = enumCheck((int)Class2.Enum12.Val4, val); + val = enumCheck((int)Class2.Enum12.Val5h, 2121); + val = enumCheck((int)Class2.Enum12.Val6h, val); + + val = 0; + val = enumCheck((int)Class2.Enum13.Val1, 2131); + val = enumCheck((int)Class2.Enum13.Val2, 2132); + val = enumCheck((int)Class2.Enum13.Val3, val); + val = enumCheck((int)Class2.Enum13.Val4, val); + val = enumCheck((int)Class2.Enum13.Val5i, 2131); + val = enumCheck((int)Class2.Enum13.Val6i, val); + + val = 0; + val = enumCheck((int)Class2.Enum14.Val1, 2141); + val = enumCheck((int)Class2.Enum14.Val2, 2142); + val = enumCheck((int)Class2.Enum14.Val3, val); + val = enumCheck((int)Class2.Enum14.Val4, val); + val = enumCheck((int)Class2.Enum14.Val5j, 2141); + val = enumCheck((int)Class2.Enum14.Val6j, val); + + val = 0; + val = enumCheck((int)Class2.Struct1.Enum12.Val1, 4121); + val = enumCheck((int)Class2.Struct1.Enum12.Val2, 4122); + val = enumCheck((int)Class2.Struct1.Enum12.Val3, val); + val = enumCheck((int)Class2.Struct1.Enum12.Val4, val); + val = enumCheck((int)Class2.Struct1.Enum12.Val5k, 4121); + val = enumCheck((int)Class2.Struct1.Enum12.Val6k, val); + + val = 0; + val = enumCheck((int)Class2.Struct1.Enum13.Val1, 4131); + val = enumCheck((int)Class2.Struct1.Enum13.Val2, 4132); + val = enumCheck((int)Class2.Struct1.Enum13.Val3, val); + val = enumCheck((int)Class2.Struct1.Enum13.Val4, val); + val = enumCheck((int)Class2.Struct1.Enum13.Val5l, 4131); + val = enumCheck((int)Class2.Struct1.Enum13.Val6l, val); + + val = 0; + val = enumCheck((int)Class2.Struct1.Enum14.Val1, 4141); + val = enumCheck((int)Class2.Struct1.Enum14.Val2, 4142); + val = enumCheck((int)Class2.Struct1.Enum14.Val3, val); + val = enumCheck((int)Class2.Struct1.Enum14.Val4, val); + val = enumCheck((int)Class2.Struct1.Enum14.Val5m, 4141); + val = enumCheck((int)Class2.Struct1.Enum14.Val6m, val); + + Class1 class1 = new Class1(); + enumCheck((int)class1.class1Test1(Enum1.Val5a), 13); + enumCheck((int)class1.class1Test2(Class1.Enum12.Val5c), 1121); + enumCheck((int)class1.class1Test3(Class1.Struct1.Enum12.Val5f), 3121); + + enumCheck((int)cpp11_strongly_typed_enumerations.globalTest1(Enum1.Val5a), 13); + enumCheck((int)cpp11_strongly_typed_enumerations.globalTest2(Class1.Enum12.Val5c), 1121); + enumCheck((int)cpp11_strongly_typed_enumerations.globalTest3(Class1.Struct1.Enum12.Val5f), 3121); + } +} + diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in index 37a944b09..3333df110 100644 --- a/Examples/test-suite/d/Makefile.in +++ b/Examples/test-suite/d/Makefile.in @@ -5,8 +5,12 @@ LANGUAGE = d srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -top_builddir = @top_builddir@ +top_srcdir = ../@top_srcdir@ +top_builddir = ../@top_builddir@ + +ifeq (,$(D_VERSION)) + D_VERSION = @DDEFAULTVERSION@ +endif ifeq (2,$(D_VERSION)) VERSIONSUFFIX = .2 @@ -22,10 +26,9 @@ CPP_TEST_CASES = \ include $(srcdir)/../common.mk -# Override some variables from common.mk: - +# Overridden variables here +SRCDIR = ../$(srcdir)/ TARGETSUFFIX = _wrap - SWIGOPT+=-splitproxy -package $* # Rules for the different types of tests diff --git a/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d index 0027aad05..028929543 100644 --- a/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d +++ b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d @@ -2,6 +2,7 @@ module li_boost_shared_ptr_runme; import core.memory; import core.thread; +import core.time; import std.conv; import std.exception; import std.stdio; @@ -31,15 +32,6 @@ void main() { if (TRACE) writeln("---> NEARLY FINISHED <---"); - // Try to get the GC to collect everything not referenced anymore. - int countdown = 100; - while (--countdown) { - GC.collect(); - if (Klass.getTotal_count() == 1) - break; - Thread.sleep(100); - } - // A single remaining instance expected: the global variable (GlobalValue). if (Klass.getTotal_count() != 1) throw new Exception("Klass.total_count=" ~ to!string(Klass.getTotal_count())); @@ -55,9 +47,15 @@ void main() { } void runTest() { + // We want to check whether all the C++ Klass instances have been properly + // destructed after the tests have run. However, as it is legal for the GC + // to leave an object around even if it is unreachable, use deterministic + // memory management here. + import std.typecons : scoped; + // simple shared_ptr usage - created in C++ { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); string val = k.getValue(); verifyValue("me oh my", val); verifyCount(1, k); @@ -73,7 +71,7 @@ void runTest() { // pass by shared_ptr { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = smartpointertest(k); string val = kret.getValue(); verifyValue("me oh my smartpointertest", val); @@ -83,7 +81,7 @@ void runTest() { // pass by shared_ptr pointer { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = smartpointerpointertest(k); string val = kret.getValue(); verifyValue("me oh my smartpointerpointertest", val); @@ -93,7 +91,7 @@ void runTest() { // pass by shared_ptr reference { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = smartpointerreftest(k); string val = kret.getValue(); verifyValue("me oh my smartpointerreftest", val); @@ -103,7 +101,7 @@ void runTest() { // pass by shared_ptr pointer reference { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = smartpointerpointerreftest(k); string val = kret.getValue(); verifyValue("me oh my smartpointerpointerreftest", val); @@ -113,7 +111,7 @@ void runTest() { // const pass by shared_ptr { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = constsmartpointertest(k); string val = kret.getValue(); verifyValue("me oh my", val); @@ -123,7 +121,7 @@ void runTest() { // const pass by shared_ptr pointer { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = constsmartpointerpointertest(k); string val = kret.getValue(); verifyValue("me oh my", val); @@ -133,7 +131,7 @@ void runTest() { // const pass by shared_ptr reference { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = constsmartpointerreftest(k); string val = kret.getValue(); verifyValue("me oh my", val); @@ -143,7 +141,7 @@ void runTest() { // pass by value { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = valuetest(k); string val = kret.getValue(); verifyValue("me oh my valuetest", val); @@ -153,7 +151,7 @@ void runTest() { // pass by pointer { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = pointertest(k); string val = kret.getValue(); verifyValue("me oh my pointertest", val); @@ -163,7 +161,7 @@ void runTest() { // pass by reference { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = reftest(k); string val = kret.getValue(); verifyValue("me oh my reftest", val); @@ -173,7 +171,7 @@ void runTest() { // pass by pointer reference { - auto k = new Klass("me oh my"); + auto k = scoped!Klass("me oh my"); auto kret = pointerreftest(k); string val = kret.getValue(); verifyValue("me oh my pointerreftest", val); @@ -215,7 +213,7 @@ void runTest() { ////////////////////////////////// Derived classes //////////////////////////////////////// // derived pass by shared_ptr { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = derivedsmartptrtest(k); string val = kret.getValue(); verifyValue("me oh my derivedsmartptrtest-Derived", val); @@ -224,7 +222,7 @@ void runTest() { } // derived pass by shared_ptr pointer { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = derivedsmartptrpointertest(k); string val = kret.getValue(); verifyValue("me oh my derivedsmartptrpointertest-Derived", val); @@ -233,7 +231,7 @@ void runTest() { } // derived pass by shared_ptr ref { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = derivedsmartptrreftest(k); string val = kret.getValue(); verifyValue("me oh my derivedsmartptrreftest-Derived", val); @@ -242,7 +240,7 @@ void runTest() { } // derived pass by shared_ptr pointer ref { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = derivedsmartptrpointerreftest(k); string val = kret.getValue(); verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val); @@ -251,7 +249,7 @@ void runTest() { } // derived pass by pointer { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = derivedpointertest(k); string val = kret.getValue(); verifyValue("me oh my derivedpointertest-Derived", val); @@ -260,7 +258,7 @@ void runTest() { } // derived pass by ref { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = derivedreftest(k); string val = kret.getValue(); verifyValue("me oh my derivedreftest-Derived", val); @@ -271,7 +269,7 @@ void runTest() { ////////////////////////////////// Derived and base class mixed //////////////////////////////////////// // pass by shared_ptr (mixed) { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = smartpointertest(k); string val = kret.getValue(); verifyValue("me oh my smartpointertest-Derived", val); @@ -281,7 +279,7 @@ void runTest() { // pass by shared_ptr pointer (mixed) { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = smartpointerpointertest(k); string val = kret.getValue(); verifyValue("me oh my smartpointerpointertest-Derived", val); @@ -291,7 +289,7 @@ void runTest() { // pass by shared_ptr reference (mixed) { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = smartpointerreftest(k); string val = kret.getValue(); verifyValue("me oh my smartpointerreftest-Derived", val); @@ -301,7 +299,7 @@ void runTest() { // pass by shared_ptr pointer reference (mixed) { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = smartpointerpointerreftest(k); string val = kret.getValue(); verifyValue("me oh my smartpointerpointerreftest-Derived", val); @@ -311,7 +309,7 @@ void runTest() { // pass by value (mixed) { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = valuetest(k); string val = kret.getValue(); verifyValue("me oh my valuetest", val); // note slicing @@ -321,7 +319,7 @@ void runTest() { // pass by pointer (mixed) { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = pointertest(k); string val = kret.getValue(); verifyValue("me oh my pointertest-Derived", val); @@ -331,7 +329,7 @@ void runTest() { // pass by ref (mixed) { - auto k = new KlassDerived("me oh my"); + auto k = scoped!KlassDerived("me oh my"); auto kret = reftest(k); string val = kret.getValue(); verifyValue("me oh my reftest-Derived", val); @@ -341,7 +339,7 @@ void runTest() { // 3rd derived class { - auto k = new Klass3rdDerived("me oh my"); + auto k = scoped!Klass3rdDerived("me oh my"); string val = k.getValue(); verifyValue("me oh my-3rdDerived", val); verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values @@ -353,128 +351,140 @@ void runTest() { ////////////////////////////////// Member variables //////////////////////////////////////// // smart pointer by value { - auto m = new MemberVariables(); - auto k = new Klass("smart member value"); - m.SmartMemberValue = k; - string val = k.getValue(); - verifyValue("smart member value", val); - verifyCount(2, k); + auto k = scoped!Klass("smart member value"); + Klass kmember; - auto kmember = m.SmartMemberValue; - val = kmember.getValue(); - verifyValue("smart member value", val); - verifyCount(3, kmember); - verifyCount(3, k); + { + auto m = scoped!MemberVariables(); + m.SmartMemberValue = k; + string val = k.getValue(); + verifyValue("smart member value", val); + verifyCount(2, k); - delete m; + kmember = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member value", val); + verifyCount(3, kmember); + verifyCount(3, k); + } verifyCount(2, kmember); verifyCount(2, k); } // smart pointer by pointer { - auto m = new MemberVariables(); - auto k = new Klass("smart member pointer"); - m.SmartMemberPointer = k; - string val = k.getValue(); - verifyValue("smart member pointer", val); - verifyCount(1, k); + auto k = scoped!Klass("smart member pointer"); + Klass kmember; - auto kmember = m.SmartMemberPointer; - val = kmember.getValue(); - verifyValue("smart member pointer", val); - verifyCount(2, kmember); - verifyCount(2, k); + { + auto m = scoped!MemberVariables(); + m.SmartMemberPointer = k; + string val = k.getValue(); + verifyValue("smart member pointer", val); + verifyCount(1, k); - delete m; + kmember = m.SmartMemberPointer; + val = kmember.getValue(); + verifyValue("smart member pointer", val); + verifyCount(2, kmember); + verifyCount(2, k); + } verifyCount(2, kmember); verifyCount(2, k); } // smart pointer by reference { - auto m = new MemberVariables(); - auto k = new Klass("smart member reference"); - m.SmartMemberReference = k; - string val = k.getValue(); - verifyValue("smart member reference", val); - verifyCount(2, k); + auto k = scoped!Klass("smart member reference"); + Klass kmember; - auto kmember = m.SmartMemberReference; - val = kmember.getValue(); - verifyValue("smart member reference", val); - verifyCount(3, kmember); - verifyCount(3, k); + { + auto m = scoped!MemberVariables(); + m.SmartMemberReference = k; + string val = k.getValue(); + verifyValue("smart member reference", val); + verifyCount(2, k); - // The C++ reference refers to SmartMemberValue... - auto kmemberVal = m.SmartMemberValue; - val = kmember.getValue(); - verifyValue("smart member reference", val); - verifyCount(4, kmemberVal); - verifyCount(4, kmember); - verifyCount(4, k); + kmember = m.SmartMemberReference; + val = kmember.getValue(); + verifyValue("smart member reference", val); + verifyCount(3, kmember); + verifyCount(3, k); - delete m; + // The C++ reference refers to SmartMemberValue... + auto kmemberVal = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member reference", val); + verifyCount(4, kmemberVal); + verifyCount(4, kmember); + verifyCount(4, k); + } verifyCount(3, kmember); verifyCount(3, k); } // plain by value { - auto m = new MemberVariables(); - auto k = new Klass("plain member value"); - m.MemberValue = k; - string val = k.getValue(); - verifyValue("plain member value", val); - verifyCount(1, k); + auto k = scoped!Klass("plain member value"); + Klass kmember; - auto kmember = m.MemberValue; - val = kmember.getValue(); - verifyValue("plain member value", val); - verifyCount(1, kmember); - verifyCount(1, k); + { + auto m = scoped!MemberVariables(); + m.MemberValue = k; + string val = k.getValue(); + verifyValue("plain member value", val); + verifyCount(1, k); - delete m; + kmember = m.MemberValue; + val = kmember.getValue(); + verifyValue("plain member value", val); + verifyCount(1, kmember); + verifyCount(1, k); + } verifyCount(1, kmember); verifyCount(1, k); } // plain by pointer { - auto m = new MemberVariables(); - auto k = new Klass("plain member pointer"); - m.MemberPointer = k; - string val = k.getValue(); - verifyValue("plain member pointer", val); - verifyCount(1, k); + auto k = scoped!Klass("plain member pointer"); + Klass kmember; - auto kmember = m.MemberPointer; - val = kmember.getValue(); - verifyValue("plain member pointer", val); - verifyCount(1, kmember); - verifyCount(1, k); + { + auto m = scoped!MemberVariables(); + m.MemberPointer = k; + string val = k.getValue(); + verifyValue("plain member pointer", val); + verifyCount(1, k); - delete m; + kmember = m.MemberPointer; + val = kmember.getValue(); + verifyValue("plain member pointer", val); + verifyCount(1, kmember); + verifyCount(1, k); + } verifyCount(1, kmember); verifyCount(1, k); } // plain by reference { - auto m = new MemberVariables(); - auto k = new Klass("plain member reference"); - m.MemberReference = k; - string val = k.getValue(); - verifyValue("plain member reference", val); - verifyCount(1, k); + auto k = scoped!Klass("plain member reference"); + Klass kmember; - auto kmember = m.MemberReference; - val = kmember.getValue(); - verifyValue("plain member reference", val); - verifyCount(1, kmember); - verifyCount(1, k); + { + auto m = scoped!MemberVariables(); + m.MemberReference = k; + string val = k.getValue(); + verifyValue("plain member reference", val); + verifyCount(1, k); - delete m; + kmember = m.MemberReference; + val = kmember.getValue(); + verifyValue("plain member reference", val); + verifyCount(1, kmember); + verifyCount(1, k); + } verifyCount(1, kmember); verifyCount(1, k); @@ -482,7 +492,7 @@ void runTest() { // null member variables { - auto m = new MemberVariables(); + auto m = scoped!MemberVariables(); // shared_ptr by value auto k = m.SmartMemberValue; @@ -504,7 +514,7 @@ void runTest() { auto kglobal = GlobalSmartValue; enforce(kglobal is null, "expected null"); - auto k = new Klass("smart global value"); + auto k = scoped!Klass("smart global value"); GlobalSmartValue = k; verifyCount(2, k); @@ -520,7 +530,7 @@ void runTest() { { Klass kglobal; - auto k = new Klass("global value"); + auto k = scoped!Klass("global value"); GlobalValue = k; verifyCount(1, k); @@ -538,7 +548,7 @@ void runTest() { auto kglobal = GlobalPointer; enforce(kglobal is null, "expected null"); - auto k = new Klass("global pointer"); + auto k = scoped!Klass("global pointer"); GlobalPointer = k; verifyCount(1, k); @@ -553,7 +563,7 @@ void runTest() { { Klass kglobal; - auto k = new Klass("global reference"); + auto k = scoped!Klass("global reference"); GlobalReference = k; verifyCount(1, k); diff --git a/Examples/test-suite/default_args.i b/Examples/test-suite/default_args.i index 839d28e3e..bcb8766a8 100644 --- a/Examples/test-suite/default_args.i +++ b/Examples/test-suite/default_args.i @@ -13,6 +13,27 @@ %inline %{ #include + // All kinds of numbers: hex, octal (which pose special problems to Python), negative... + void trickyvalue1(int first, int pos = -1) {} + void trickyvalue2(int first, unsigned rgb = 0xabcdef) {} + void trickyvalue3(int first, int mode = 0644) {} + + void doublevalue1(int first, double num = 0.0e-1) {} + void doublevalue2(int first, double num = -0.0E2) {} + + // Long long arguments are not handled at Python level currently but still work. + void seek(long long offset = 0LL) {} + void seek2(unsigned long long offset = 0ULL) {} + void seek3(long offset = 0L) {} + void seek4(unsigned long offset = 0UL) {} + void seek5(unsigned long offset = 0U) {} + void seek6(unsigned long offset = 02U) {} + void seek7(unsigned long offset = 00U) {} + void seek8(unsigned long offset = 1U) {} + void seek9(long offset = 1L) {} + void seekA(long long offset = 1LL) {} + void seekB(unsigned long long offset = 1ULL) {} + // Anonymous arguments int anonymous(int = 7771); int anonymous(int x) { return x; } @@ -29,6 +50,12 @@ bool blah(speed s = FAST, flavor f = SWEET) { return (s == FAST && f == SWEET); }; }; + // using base class enum in a derived class + class DerivedEnumClass : public EnumClass { + public: + void accelerate(speed s = SLOW) { } + }; + // casts const char * casts1(const char *m = (const char *) NULL) { char *ret = NULL; @@ -199,6 +226,7 @@ namespace Space { struct Klass { int val; Klass(int val = -1) : val(val) {} + static Klass inc(int n = 1, const Klass& k = Klass()) { return Klass(k.val + n); } }; Klass constructorcall(const Klass& k = Klass()) { return k; } diff --git a/Examples/test-suite/default_constructor.i b/Examples/test-suite/default_constructor.i index 091adff20..f7fc8cfa6 100644 --- a/Examples/test-suite/default_constructor.i +++ b/Examples/test-suite/default_constructor.i @@ -168,5 +168,11 @@ public: } }; - +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/test-suite/director_abstract.i b/Examples/test-suite/director_abstract.i index cc9dca55a..7dfcc8984 100644 --- a/Examples/test-suite/director_abstract.i +++ b/Examples/test-suite/director_abstract.i @@ -156,7 +156,7 @@ namespace ns class Example3 { protected: - /* the default constructor is always emitter, even when protected, + /* the default constructor is always emitted, even when protected, having another public constructor, and 'dirprot' is not used. This is just for Java compatibility */ Example3() diff --git a/Examples/test-suite/director_exception.i b/Examples/test-suite/director_exception.i index 3fd3e563c..2559ae566 100644 --- a/Examples/test-suite/director_exception.i +++ b/Examples/test-suite/director_exception.i @@ -1,5 +1,7 @@ %module(directors="1") director_exception +%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) return_const_char_star; + %{ #if defined(_MSC_VER) @@ -106,7 +108,7 @@ Foo *launder(Foo *f) { %} %feature("director") Bar; - +%feature("director") ReturnAllTypes; %inline %{ struct Exception1 @@ -132,4 +134,28 @@ Foo *launder(Foo *f) { virtual std::string pang() throw () { return "Bar::pang()"; } }; + // Class to allow regression testing SWIG/PHP not checking if an exception + // had been thrown in directorout typemaps. + class ReturnAllTypes + { + public: + int call_int() { return return_int(); } + double call_double() { return return_double(); } + const char * call_const_char_star() { return return_const_char_star(); } + std::string call_std_string() { return return_std_string(); } + Bar call_Bar() { return return_Bar(); } + + virtual int return_int() { return 0; } + virtual double return_double() { return 0.0; } + virtual const char * return_const_char_star() { return ""; } + virtual std::string return_std_string() { return std::string(); } + virtual Bar return_Bar() { return Bar(); } + virtual ~ReturnAllTypes() {} + }; + +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif %} diff --git a/Examples/test-suite/director_keywords.i b/Examples/test-suite/director_keywords.i index 473786c00..53f36a8f6 100644 --- a/Examples/test-suite/director_keywords.i +++ b/Examples/test-suite/director_keywords.i @@ -1,13 +1,16 @@ // Checks if collisions of argument names with target language keywords are -// resolved properly when directors are used (currently only »abstract« for -// C#, D and Java is checked). +// resolved properly when directors are used %module(directors="1") director_keywords +%warnfilter(SWIGWARN_PARSE_KEYWORD); + %feature("director") Foo; %inline %{ struct Foo { virtual ~Foo() {} - virtual void bar(int abstract) {} + virtual void check_abstract(int abstract) {} // for Java, C#, D... + virtual void check_self(int self) {} // self for Python + virtual void check_from(int from) {} // for Python }; %} diff --git a/Examples/test-suite/director_nested_class.i b/Examples/test-suite/director_nested_class.i new file mode 100644 index 000000000..f3d627f3c --- /dev/null +++ b/Examples/test-suite/director_nested_class.i @@ -0,0 +1,25 @@ +%module(directors="1") director_nested_class + + +%feature("director") DirectorOuter::DirectorInner; +%feature("director") DirectorOuter::DirectorInner::DirectorInnerInner; + +%inline %{ +struct DirectorOuter { + struct DirectorInner { + virtual ~DirectorInner() {} + virtual int vmethod(int input) const = 0; + struct DirectorInnerInner { + DirectorInnerInner(DirectorInner *din = 0) {} + virtual ~DirectorInnerInner() {} + virtual int innervmethod(int input) const = 0; + }; + }; + static int callMethod(const DirectorInner &di, int value) { + return di.vmethod(value); + } + static int callInnerInnerMethod(const DirectorInner::DirectorInnerInner &di, int value) { + return di.innervmethod(value); + } +}; +%} diff --git a/Examples/test-suite/director_nestedmodule.i b/Examples/test-suite/director_nestedmodule.i new file mode 100644 index 000000000..4e304340f --- /dev/null +++ b/Examples/test-suite/director_nestedmodule.i @@ -0,0 +1,29 @@ +%module(directors="1") "director::nestedmodule" + +%{ +#include + +class Foo { + public: + virtual ~Foo() {} + virtual std::string ping() { return "Foo::ping()"; } + virtual std::string pong() { return "Foo::pong();" + ping(); } + + static Foo* get_self(Foo *slf) {return slf;} +}; + +%} + +%include + +%feature("director") Foo; + + +class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + virtual std::string pong(); + + static Foo* get_self(Foo *slf); +}; diff --git a/Examples/test-suite/director_property.i b/Examples/test-suite/director_property.i new file mode 100644 index 000000000..3363c3c4f --- /dev/null +++ b/Examples/test-suite/director_property.i @@ -0,0 +1,151 @@ +%module(directors="1") director_property + +%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) MyClass::pmethod; + +%{ + #include + + class Foo { + private: + std::string a; + public: + virtual ~Foo() {} + virtual std::string ping() { return "Foo::ping()"; } + virtual std::string pong() { return "Foo::pong();" + ping(); } + virtual std::string getA() { return this->a; } + virtual void setA(std::string a) { this->a = a; } + + static Foo* get_self(Foo *slf) {return slf;} + + }; + + %} + + %include + + %feature("director") Foo; + + + class Foo { + public: + virtual ~Foo(); + virtual std::string ping(); + virtual std::string pong(); + virtual std::string getA(); + virtual void setA(std::string a); + + static Foo* get_self(Foo *slf); + + }; + + %{ + #include + %} + %feature("director") A; + + // basic renaming + %rename(rg) A::gg; + %feature("nodirector") hi::A1::gg; + + %inline %{ + + struct A{ + A(std::complex i, double d=0.0) {} + A(int i, bool j=false) {} + virtual ~A() {} + + virtual int f(int i=0) {return i;} + virtual int gg(int i=0) {return i;} + }; + + namespace hi { + + struct A1 : public A { + A1(std::complex i, double d=0.0) : A(i, d) {} + A1(int i, bool j=false) : A(i, j) {} + + virtual int ff(int i = 0) {return i;} + }; + } + + + %} + + + %feature("director") MyClass; + + %inline %{ + + typedef void VoidType; + + struct Bar + { + int x; + Bar(int _x = 0) : x(_x) + { + } + }; + + + +class MyClass { +public: + MyClass(int a = 0) + { + } + + virtual void method(VoidType *) + { + } + + virtual ~MyClass() + { + } + + virtual Bar vmethod(Bar b) + { + b.x += 13; + return b; + } + + virtual Bar* pmethod(Bar *b) + { + b->x += 12; + return b; + } + + Bar cmethod(const Bar &b) + { + return vmethod(b); + } + + static MyClass *get_self(MyClass *c) + { + return c; + } + + static Bar * call_pmethod(MyClass *myclass, Bar *b) { + return myclass->pmethod(b); + } +}; + +template +class MyClassT { +public: + MyClassT(int a = 0) + { + } + + virtual void method(VoidType *) + { + } + + virtual ~MyClassT() + { + } + +}; + +%} + +%template(MyClassT_i) MyClassT; diff --git a/Examples/test-suite/enum_rename.i b/Examples/test-suite/enum_rename.i index 0cab4d0d8..23e100db9 100644 --- a/Examples/test-suite/enum_rename.i +++ b/Examples/test-suite/enum_rename.i @@ -2,7 +2,7 @@ %warnfilter(SWIGWARN_PARSE_REDEFINED) S_May; -// %rename using regex can do the equivalent of these two renames, which was resulting in uncompileable code +// %rename using regex can do the equivalent of these two renames, which was resulting in uncompilable code %rename(May) M_May; %rename(May) S_May; diff --git a/Examples/test-suite/enum_thorough.i b/Examples/test-suite/enum_thorough.i index ec31c2787..3ece5471b 100644 --- a/Examples/test-suite/enum_thorough.i +++ b/Examples/test-suite/enum_thorough.i @@ -277,6 +277,18 @@ OldNameStruct::doublenametag renameTest6(OldNameStruct::doublenametag e) OldNameStruct::singlename renameTest7(OldNameStruct::singlename e) { return e; } %} +%rename(Clash1_di1) Clash1::di1; +%rename(Clash1_di2) Clash1::di2; +%rename(Clash1_di3) Clash1::di3; +%inline %{ +namespace Clash1 { + enum DuplicateItems1 { di1, di2 = 10, di3 }; +} +namespace Clash2 { + enum DuplicateItems2 { di1, di2 = 10, di3 }; +} +%} + %inline %{ struct TreesClass { enum trees {oak, fir, pine }; diff --git a/Examples/test-suite/errors/.gitignore b/Examples/test-suite/errors/.gitignore new file mode 100644 index 000000000..22ca11947 --- /dev/null +++ b/Examples/test-suite/errors/.gitignore @@ -0,0 +1,4 @@ +*.newerr +cpp_recursive_typedef.py +cpp_shared_ptr.py +xxx.py diff --git a/Examples/test-suite/errors/c_extra_rblock.stderr b/Examples/test-suite/errors/c_extra_rblock.stderr index 82877023a..be14eee4c 100644 --- a/Examples/test-suite/errors/c_extra_rblock.stderr +++ b/Examples/test-suite/errors/c_extra_rblock.stderr @@ -1 +1 @@ -c_extra_rblock.i:5: Error: Syntax error in input(1). +c_extra_rblock.i:5: Error: Syntax error. Extraneous '%}' diff --git a/Examples/test-suite/errors/c_missing_semi.stderr b/Examples/test-suite/errors/c_missing_semi.stderr index 791b959ca..18befaa1b 100644 --- a/Examples/test-suite/errors/c_missing_semi.stderr +++ b/Examples/test-suite/errors/c_missing_semi.stderr @@ -1 +1 @@ -c_missing_semi.i:3: Error: Syntax error in input(1). +c_missing_semi.i:3: Error: Syntax error - possibly a missing semicolon. diff --git a/Examples/test-suite/errors/cpp_extra_brackets.stderr b/Examples/test-suite/errors/cpp_extra_brackets.stderr index 12bb1f327..f1fabc78d 100644 --- a/Examples/test-suite/errors/cpp_extra_brackets.stderr +++ b/Examples/test-suite/errors/cpp_extra_brackets.stderr @@ -1 +1 @@ -cpp_extra_brackets.i:5: Error: Syntax error in input(3). +cpp_extra_brackets.i:5: Error: Unexpected ')'. diff --git a/Examples/test-suite/errors/pp_constant.i b/Examples/test-suite/errors/pp_constant.i index 2be108e83..c29f4c86d 100644 --- a/Examples/test-suite/errors/pp_constant.i +++ b/Examples/test-suite/errors/pp_constant.i @@ -29,7 +29,9 @@ comment */ %constant int ddd=; #define E1 1234 -#/*C comment*/define E2 1234 +// This case doesn't actually work, but appeared to before we gave an error +// for unknown preprocessor directives. +// #/*C comment*/define E2 1234 #define E3 1234 %constant int eee=; diff --git a/Examples/test-suite/errors/pp_constant.stderr b/Examples/test-suite/errors/pp_constant.stderr index 9c79ec2be..54a87edfe 100644 --- a/Examples/test-suite/errors/pp_constant.stderr +++ b/Examples/test-suite/errors/pp_constant.stderr @@ -2,7 +2,7 @@ pp_constant.i:9: Warning 305: Bad constant value (ignored). pp_constant.i:15: Warning 305: Bad constant value (ignored). pp_constant.i:23: Warning 305: Bad constant value (ignored). pp_constant.i:29: Warning 305: Bad constant value (ignored). -pp_constant.i:35: Warning 305: Bad constant value (ignored). -pp_constant.i:42: Warning 305: Bad constant value (ignored). -pp_constant.i:46: Warning 305: Bad constant value (ignored). -pp_constant.i:49: Warning 305: Bad constant value (ignored). +pp_constant.i:37: Warning 305: Bad constant value (ignored). +pp_constant.i:44: Warning 305: Bad constant value (ignored). +pp_constant.i:48: Warning 305: Bad constant value (ignored). +pp_constant.i:51: Warning 305: Bad constant value (ignored). diff --git a/Examples/test-suite/errors/pp_missing_enddef.stderr b/Examples/test-suite/errors/pp_missing_enddef.stderr index bb4ea3c75..c461699e6 100644 --- a/Examples/test-suite/errors/pp_missing_enddef.stderr +++ b/Examples/test-suite/errors/pp_missing_enddef.stderr @@ -1 +1 @@ -pp_missing_enddef.i:EOF: Error: Missing %enddef for macro starting on line 3 +pp_missing_enddef.i:3: Error: Missing %enddef for macro starting here diff --git a/Examples/test-suite/errors/pp_missing_endif.stderr b/Examples/test-suite/errors/pp_missing_endif.stderr index 0bbfad7f2..4db4021aa 100644 --- a/Examples/test-suite/errors/pp_missing_endif.stderr +++ b/Examples/test-suite/errors/pp_missing_endif.stderr @@ -1 +1 @@ -pp_missing_endif.i:EOF: Error: Missing #endif for conditional starting on line 3 +pp_missing_endif.i:3: Error: Missing #endif for conditional starting here diff --git a/Examples/test-suite/errors/pp_missing_endoffile.i b/Examples/test-suite/errors/pp_missing_endoffile.i new file mode 100644 index 000000000..2074495a8 --- /dev/null +++ b/Examples/test-suite/errors/pp_missing_endoffile.i @@ -0,0 +1,7 @@ +%module xxx +/* %beginfile and %endoffile are internal directives inserted when %include is + * used. Users should never use them directly, but test coverage for this + * error message still seems useful to have. + */ +%includefile "dummy.i" %beginfile + diff --git a/Examples/test-suite/errors/pp_missing_endoffile.stderr b/Examples/test-suite/errors/pp_missing_endoffile.stderr new file mode 100644 index 000000000..7269f2e92 --- /dev/null +++ b/Examples/test-suite/errors/pp_missing_endoffile.stderr @@ -0,0 +1 @@ +pp_missing_endoffile.i:6: Error: Missing %endoffile for file inclusion block starting here diff --git a/Examples/test-suite/errors/pp_missing_rblock.stderr b/Examples/test-suite/errors/pp_missing_rblock.stderr index 8f4a54c0a..f00457d73 100644 --- a/Examples/test-suite/errors/pp_missing_rblock.stderr +++ b/Examples/test-suite/errors/pp_missing_rblock.stderr @@ -1 +1 @@ -pp_missing_rblock.i:EOF: Error: Unterminated %{ ... %} block starting on line 3 +pp_missing_rblock.i:3: Error: Unterminated %{ ... %} block diff --git a/Examples/test-suite/errors/pp_unknowndirective.i b/Examples/test-suite/errors/pp_unknowndirective.i new file mode 100644 index 000000000..659a997d3 --- /dev/null +++ b/Examples/test-suite/errors/pp_unknowndirective.i @@ -0,0 +1,7 @@ +%module xxx + +/* This used to give the rather cryptic "Syntax error in input(1)." prior to + * SWIG 3.0.4. This testcase checks that the improved message is actually + * issued. + */ +%remane("typo") tyop; diff --git a/Examples/test-suite/errors/pp_unknowndirective.stderr b/Examples/test-suite/errors/pp_unknowndirective.stderr new file mode 100644 index 000000000..d0d5e249f --- /dev/null +++ b/Examples/test-suite/errors/pp_unknowndirective.stderr @@ -0,0 +1 @@ +pp_unknowndirective.i:7: Error: Unknown directive '%remane'. diff --git a/Examples/test-suite/errors/pp_unknowndirective2.i b/Examples/test-suite/errors/pp_unknowndirective2.i new file mode 100644 index 000000000..889e6c5b2 --- /dev/null +++ b/Examples/test-suite/errors/pp_unknowndirective2.i @@ -0,0 +1,11 @@ +%module xxx + +#ifdef FOO +long long i; +/* Check we get an error for an unknown directive (this should be #elif). + * Unknown directives were silently ignored by SWIG < 3.0.3. */ +#elsif defined(BAR) +long i; +#else +int i; +#endif diff --git a/Examples/test-suite/errors/pp_unknowndirective2.stderr b/Examples/test-suite/errors/pp_unknowndirective2.stderr new file mode 100644 index 000000000..70afa670c --- /dev/null +++ b/Examples/test-suite/errors/pp_unknowndirective2.stderr @@ -0,0 +1 @@ +pp_unknowndirective2.i:7: Error: Unknown SWIG preprocessor directive: elsif (if this is a block of target language code, delimit it with %{ and %}) diff --git a/Examples/test-suite/errors/pp_unterm_char.stderr b/Examples/test-suite/errors/pp_unterm_char.stderr index 4386e933d..147e3859d 100644 --- a/Examples/test-suite/errors/pp_unterm_char.stderr +++ b/Examples/test-suite/errors/pp_unterm_char.stderr @@ -1 +1 @@ -pp_unterm_char.i:EOF: Error: Unterminated character constant starting at line 4 +pp_unterm_char.i:4: Error: Unterminated character constant diff --git a/Examples/test-suite/errors/pp_unterm_comment.stderr b/Examples/test-suite/errors/pp_unterm_comment.stderr index 4ff34230c..ab1edac14 100644 --- a/Examples/test-suite/errors/pp_unterm_comment.stderr +++ b/Examples/test-suite/errors/pp_unterm_comment.stderr @@ -1 +1 @@ -pp_unterm_comment.i:EOF: Error: Unterminated comment starting on line 3 +pp_unterm_comment.i:3: Error: Unterminated comment diff --git a/Examples/test-suite/errors/pp_unterm_string.stderr b/Examples/test-suite/errors/pp_unterm_string.stderr index 16b4034f3..14e110ebb 100644 --- a/Examples/test-suite/errors/pp_unterm_string.stderr +++ b/Examples/test-suite/errors/pp_unterm_string.stderr @@ -1 +1 @@ -pp_unterm_string.i:EOF: Error: Unterminated string constant starting at line 4 +pp_unterm_string.i:4: Error: Unterminated string constant diff --git a/Examples/test-suite/errors/pp_unterminated_block.i b/Examples/test-suite/errors/pp_unterminated_block.i new file mode 100644 index 000000000..99f5f0bc2 --- /dev/null +++ b/Examples/test-suite/errors/pp_unterminated_block.i @@ -0,0 +1,5 @@ +%module xxx + +%{ +int foo(int x); + diff --git a/Examples/test-suite/errors/pp_unterminated_block.stderr b/Examples/test-suite/errors/pp_unterminated_block.stderr new file mode 100644 index 000000000..03c16a45f --- /dev/null +++ b/Examples/test-suite/errors/pp_unterminated_block.stderr @@ -0,0 +1 @@ +pp_unterminated_block.i:3: Error: Unterminated %{ ... %} block diff --git a/Examples/test-suite/exception_order.i b/Examples/test-suite/exception_order.i index 4dd13858a..bca745c7e 100644 --- a/Examples/test-suite/exception_order.i +++ b/Examples/test-suite/exception_order.i @@ -125,6 +125,13 @@ } }; int A::sfoovar = 1; + +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif + %} %template(ET_i) ET; diff --git a/Examples/test-suite/exception_partial_info.i b/Examples/test-suite/exception_partial_info.i index 37b87ef50..47b046735 100644 --- a/Examples/test-suite/exception_partial_info.i +++ b/Examples/test-suite/exception_partial_info.i @@ -1,6 +1,6 @@ %module exception_partial_info -// This produced compileable code for Tcl, Python in 1.3.27, fails in 1.3.29 +// This produced compilable code for Tcl, Python in 1.3.27, fails in 1.3.29 %{ #if defined(_MSC_VER) diff --git a/Examples/test-suite/extend_default.i b/Examples/test-suite/extend_default.i index 097b5332e..d4a015f55 100644 --- a/Examples/test-suite/extend_default.i +++ b/Examples/test-suite/extend_default.i @@ -93,7 +93,7 @@ struct OverAfter { // %extend overrides the class definition %extend Override { int over(int a) { return a*a; } // SWIG should give a warning then choose this one over the real one - int overload(int a) { return a*a; } // Similarly, but this one generated uncompileable code in SWIG-1.3.22 + int overload(int a) { return a*a; } // Similarly, but this one generated uncompilable code in SWIG-1.3.22 } %inline %{ struct Override { diff --git a/Examples/test-suite/extend_special_variables.i b/Examples/test-suite/extend_special_variables.i index dd68e7531..1f218a8b9 100644 --- a/Examples/test-suite/extend_special_variables.i +++ b/Examples/test-suite/extend_special_variables.i @@ -19,3 +19,19 @@ struct ForExtension { }; %} + +%inline %{ +namespace Space { + template class ExtendTemplate {}; +} +%} + +%extend Space::ExtendTemplate +{ + void extending() { + $parentclassname tmp; + (void)tmp; + } +} + +%template(ExtendTemplateInt) Space::ExtendTemplate; diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 5d8343be1..4480ecf1f 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -24,6 +24,10 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ +CPP_TEST_CASES = \ + go_inout \ + go_director_inout + include $(srcdir)/../common.mk .SUFFIXES: .cpptest .ctest .multicpptest diff --git a/Examples/test-suite/go/argout_runme.go b/Examples/test-suite/go/argout_runme.go new file mode 100644 index 000000000..5f7017e73 --- /dev/null +++ b/Examples/test-suite/go/argout_runme.go @@ -0,0 +1,41 @@ +package main + +import wrap "./argout" + +func main() { + ip := wrap.New_intp() + wrap.Intp_assign(ip, 42) + if r := wrap.Incp(ip); r != 42 { + panic(r) + } + if r := wrap.Intp_value(ip); r != 43 { + panic(r) + } + + p := wrap.New_intp() + wrap.Intp_assign(p, 2) + if r := wrap.Incp(p); r != 2 { + panic(r) + } + if r := wrap.Intp_value(p); r != 3 { + panic(r) + } + + r := wrap.New_intp() + wrap.Intp_assign(r, 7) + if r := wrap.Incr(r); r != 7 { + panic(r) + } + if r := wrap.Intp_value(r); r != 8 { + panic(r) + } + + tr := wrap.New_intp() + wrap.Intp_assign(tr, 4) + if r := wrap.Inctr(tr); r != 4 { + panic(r) + } + if r := wrap.Intp_value(tr); r != 5 { + panic(r) + } +} diff --git a/Examples/test-suite/go/cpp11_strongly_typed_enumerations_runme.go b/Examples/test-suite/go/cpp11_strongly_typed_enumerations_runme.go new file mode 100644 index 000000000..f4b84b1ee --- /dev/null +++ b/Examples/test-suite/go/cpp11_strongly_typed_enumerations_runme.go @@ -0,0 +1,171 @@ +package main + +import "fmt" +import . "./cpp11_strongly_typed_enumerations" + +func enumCheck(actual int, expected int) int { + if actual != expected { + panic(fmt.Sprintf("Enum value mismatch. Expected: %d Actual: %d", expected, actual)) + } + return expected + 1 +} + +func main() { + var val = 0 + val = enumCheck(int(Enum1_Val1), val) + val = enumCheck(int(Enum1_Val2), val) + val = enumCheck(int(Enum1_Val3), 13) + val = enumCheck(int(Enum1_Val4), val) + val = enumCheck(int(Enum1_Val5a), 13) + val = enumCheck(int(Enum1_Val6a), val) + + val = 0 + val = enumCheck(int(Enum2_Val1), val) + val = enumCheck(int(Enum2_Val2), val) + val = enumCheck(int(Enum2_Val3), 23) + val = enumCheck(int(Enum2_Val4), val) + val = enumCheck(int(Enum2_Val5b), 23) + val = enumCheck(int(Enum2_Val6b), val) + + val = 0 + val = enumCheck(int(Val1), val) + val = enumCheck(int(Val2), val) + val = enumCheck(int(Val3), 43) + val = enumCheck(int(Val4), val) + + val = 0 + val = enumCheck(int(Enum5_Val1), val) + val = enumCheck(int(Enum5_Val2), val) + val = enumCheck(int(Enum5_Val3), 53) + val = enumCheck(int(Enum5_Val4), val) + + val = 0 + val = enumCheck(int(Enum6_Val1), val) + val = enumCheck(int(Enum6_Val2), val) + val = enumCheck(int(Enum6_Val3), 63) + val = enumCheck(int(Enum6_Val4), val) + + val = 0 + val = enumCheck(int(Enum7td_Val1), val) + val = enumCheck(int(Enum7td_Val2), val) + val = enumCheck(int(Enum7td_Val3), 73) + val = enumCheck(int(Enum7td_Val4), val) + + val = 0 + val = enumCheck(int(Enum8_Val1), val) + val = enumCheck(int(Enum8_Val2), val) + val = enumCheck(int(Enum8_Val3), 83) + val = enumCheck(int(Enum8_Val4), val) + + val = 0 + val = enumCheck(int(Enum10_Val1), val) + val = enumCheck(int(Enum10_Val2), val) + val = enumCheck(int(Enum10_Val3), 103) + val = enumCheck(int(Enum10_Val4), val) + + val = 0 + val = enumCheck(int(Class1Enum12_Val1), 1121) + val = enumCheck(int(Class1Enum12_Val2), 1122) + val = enumCheck(int(Class1Enum12_Val3), val) + val = enumCheck(int(Class1Enum12_Val4), val) + val = enumCheck(int(Class1Enum12_Val5c), 1121) + val = enumCheck(int(Class1Enum12_Val6c), val) + + val = 0 + val = enumCheck(int(Class1Val1), 1131) + val = enumCheck(int(Class1Val2), 1132) + val = enumCheck(int(Class1Val3), val) + val = enumCheck(int(Class1Val4), val) + val = enumCheck(int(Class1Val5d), 1131) + val = enumCheck(int(Class1Val6d), val) + + val = 0 + val = enumCheck(int(Class1Enum14_Val1), 1141) + val = enumCheck(int(Class1Enum14_Val2), 1142) + val = enumCheck(int(Class1Enum14_Val3), val) + val = enumCheck(int(Class1Enum14_Val4), val) + val = enumCheck(int(Class1Enum14_Val5e), 1141) + val = enumCheck(int(Class1Enum14_Val6e), val) + + // Requires nested class support to work + //val = 0 + //val = enumCheck(int(Class1Struct1Enum12_Val1), 3121) + //val = enumCheck(int(Class1Struct1Enum12_Val2), 3122) + //val = enumCheck(int(Class1Struct1Enum12_Val3), val) + //val = enumCheck(int(Class1Struct1Enum12_Val4), val) + //val = enumCheck(int(Class1Struct1Enum12_Val5f), 3121) + //val = enumCheck(int(Class1Struct1Enum12_Val6f), val) + // + //val = 0 + //val = enumCheck(int(Class1Struct1Val1), 3131) + //val = enumCheck(int(Class1Struct1Val2), 3132) + //val = enumCheck(int(Class1Struct1Val3), val) + //val = enumCheck(int(Class1Struct1Val4), val) + // + //val = 0 + //val = enumCheck(int(Class1Struct1Enum14_Val1), 3141) + //val = enumCheck(int(Class1Struct1Enum14_Val2), 3142) + //val = enumCheck(int(Class1Struct1Enum14_Val3), val) + //val = enumCheck(int(Class1Struct1Enum14_Val4), val) + //val = enumCheck(int(Class1Struct1Enum14_Val5g), 3141) + //val = enumCheck(int(Class1Struct1Enum14_Val6g), val) + + val = 0 + val = enumCheck(int(Class2Enum12_Val1), 2121) + val = enumCheck(int(Class2Enum12_Val2), 2122) + val = enumCheck(int(Class2Enum12_Val3), val) + val = enumCheck(int(Class2Enum12_Val4), val) + val = enumCheck(int(Class2Enum12_Val5h), 2121) + val = enumCheck(int(Class2Enum12_Val6h), val) + + val = 0 + val = enumCheck(int(Class2Val1), 2131) + val = enumCheck(int(Class2Val2), 2132) + val = enumCheck(int(Class2Val3), val) + val = enumCheck(int(Class2Val4), val) + val = enumCheck(int(Class2Val5i), 2131) + val = enumCheck(int(Class2Val6i), val) + + val = 0 + val = enumCheck(int(Class2Enum14_Val1), 2141) + val = enumCheck(int(Class2Enum14_Val2), 2142) + val = enumCheck(int(Class2Enum14_Val3), val) + val = enumCheck(int(Class2Enum14_Val4), val) + val = enumCheck(int(Class2Enum14_Val5j), 2141) + val = enumCheck(int(Class2Enum14_Val6j), val) + + // Requires nested class support to work + //val = 0 + //val = enumCheck(int(Class2Struct1Enum12_Val1), 4121) + //val = enumCheck(int(Class2Struct1Enum12_Val2), 4122) + //val = enumCheck(int(Class2Struct1Enum12_Val3), val) + //val = enumCheck(int(Class2Struct1Enum12_Val4), val) + //val = enumCheck(int(Class2Struct1Enum12_Val5k), 4121) + //val = enumCheck(int(Class2Struct1Enum12_Val6k), val) + // + //val = 0 + //val = enumCheck(int(Class2Struct1Val1), 4131) + //val = enumCheck(int(Class2Struct1Val2), 4132) + //val = enumCheck(int(Class2Struct1Val3), val) + //val = enumCheck(int(Class2Struct1Val4), val) + //val = enumCheck(int(Class2Struct1Val5l), 4131) + //val = enumCheck(int(Class2Struct1Val6l), val) + // + //val = 0 + //val = enumCheck(int(Class2Struct1Enum14_Val1), 4141) + //val = enumCheck(int(Class2Struct1Enum14_Val2), 4142) + //val = enumCheck(int(Class2Struct1Enum14_Val3), val) + //val = enumCheck(int(Class2Struct1Enum14_Val4), val) + //val = enumCheck(int(Class2Struct1Enum14_Val5m), 4141) + //val = enumCheck(int(Class2Struct1Enum14_Val6m), val) + + class1 := NewClass1() + enumCheck(int(class1.Class1Test1(Enum1_Val5a)), 13) + enumCheck(int(class1.Class1Test2(Class1Enum12_Val5c)), 1121) + //enumCheck(int(class1.Class1Test3(Class1Struct1Enum12_Val5f)), 3121) + + enumCheck(int(GlobalTest1(Enum1_Val5a)), 13) + enumCheck(int(GlobalTest2(Class1Enum12_Val5c)), 1121) + //enumCheck(int(GlobalTest3(Class1Struct1Enum12_Val5f)), 3121) + +} diff --git a/Examples/test-suite/go/go_director_inout_runme.go b/Examples/test-suite/go/go_director_inout_runme.go new file mode 100644 index 000000000..9b9df318e --- /dev/null +++ b/Examples/test-suite/go/go_director_inout_runme.go @@ -0,0 +1,32 @@ +package main + +import ( + wrap "./go_director_inout" +) + +type GoMyClass struct {} + +func (p *GoMyClass) Adjust(m map[string]interface{}) wrap.GoRetStruct { + s := "" + for k, v := range m { + s += k + "," + v.(string) + ";" + } + return wrap.GoRetStruct{s} +} + +func main() { + a := wrap.NewDirectorMyClass(&GoMyClass{}) + m := map[string]interface{}{ + "first": "second", + } + s := a.Adjust(m) + if s.Str != "first,second;" { + panic(s) + } + + a = wrap.NewDirectorMyClass(nil) + s = a.Adjust(m) + if s.Str != `{"first":"second"}` { + panic(s.Str) + } +} diff --git a/Examples/test-suite/go/go_inout_runme.go b/Examples/test-suite/go/go_inout_runme.go new file mode 100644 index 000000000..13c429b87 --- /dev/null +++ b/Examples/test-suite/go/go_inout_runme.go @@ -0,0 +1,43 @@ +package main + +import ( + "encoding/json" + "fmt" + "reflect" + + "./go_inout" +) + +type S struct { + A int + B string + C float64 +} + +func (p *S) MarshalJSON() ([]byte, error) { + return json.Marshal(*p) +} + +func main() { + v := &S{12, "hi", 34.5} + m := go_inout.Same(v) + want := map[string]interface{}{ + // The type of A changes from int to float64 because + // JSON has no ints. + "A": float64(12), + "B": "hi", + "C": 34.5, + } + if !reflect.DeepEqual(m, want) { + fmt.Println("got", m, "want", want) + panic(m) + } + + a := []string{"a", "bc", "def"} + go_inout.DoubleArray(&a) + dwant := []string{"a", "bc", "def", "aa", "bcbc", "defdef"} + if !reflect.DeepEqual(a, dwant) { + fmt.Println("got", a, "want", dwant) + panic(a) + } +} diff --git a/Examples/test-suite/go/overload_polymorphic_runme.go b/Examples/test-suite/go/overload_polymorphic_runme.go new file mode 100644 index 000000000..1720e1a4d --- /dev/null +++ b/Examples/test-suite/go/overload_polymorphic_runme.go @@ -0,0 +1,11 @@ +package main + +import "./overload_polymorphic" + +func main(){ + t := overload_polymorphic.NewDerived() + + if overload_polymorphic.Test(t) != 0 { + panic("failed") + } +} diff --git a/Examples/test-suite/go_director_inout.i b/Examples/test-suite/go_director_inout.i new file mode 100644 index 000000000..af59e313c --- /dev/null +++ b/Examples/test-suite/go_director_inout.i @@ -0,0 +1,121 @@ +// Test the goin and goout typemaps for directors. + +%module(directors="1") go_director_inout + +%{ +#include +%} + +%inline +%{ + +struct MyStruct { + std::string str; +}; + +struct RetStruct { + std::string str; +}; + +%} + +%go_import("encoding/json") + +%insert(go_header) +%{ + +type GoRetStruct struct { + Str string +} + +%} + +%typemap(gotype) RetStruct "GoRetStruct" + +%typemap(imtype) RetStruct "string" + +%typemap(goin) RetStruct +%{ + $result = $input.Str +%} + +%typemap(in) RetStruct +%{ + $result.str.assign($input.p, $input.n); +%} + +%typemap(out) RetStruct +%{ + $result = _swig_makegostring($1.str.data(), $1.str.length()); +%} + +%typemap(goout) RetStruct +%{ + $result = GoRetStruct{Str: $input} +%} + +%typemap(godirectorout) RetStruct +%{ + $result = $input.Str +%} + +%typemap(directorout) RetStruct +%{ + $result.str.assign($input.p, $input.n); +%} + +%typemap(godirectorin) RetStruct +%{ +%} + +%typemap(gotype) MyStruct "map[string]interface{}" + +%typemap(imtype) MyStruct "string" + +%typemap(goin) MyStruct +%{ + if b, err := json.Marshal($input); err != nil { + panic(err) + } else { + $result = string(b) + } +%} + +%typemap(directorin) MyStruct +%{ + $input = _swig_makegostring($1.str.data(), $1.str.length()); +%} + +%typemap(out) MyStruct +%{ + $result = _swig_makegostring($1.str.data(), $1.str.length()); +%} + +%typemap(godirectorin) MyStruct +%{ + if err := json.Unmarshal([]byte($input), &$result); err != nil { + panic(err) + } +%} + +%typemap(in) MyStruct +%{ + $1.str.assign($input.p, $input.n); +%} + +%feature("director") MyClass; + +%inline +%{ + +class MyClass { + public: + virtual ~MyClass() {} + virtual RetStruct Adjust(MyStruct s) { + RetStruct r; + r.str = s.str; + return r; + } +}; + +%} diff --git a/Examples/test-suite/go_inout.i b/Examples/test-suite/go_inout.i new file mode 100644 index 000000000..510ed68e0 --- /dev/null +++ b/Examples/test-suite/go_inout.i @@ -0,0 +1,199 @@ +// Test the goin, goout, and goargout typemaps. + +%module go_inout + +%{ +#include +#include +#include +%} + +%inline +%{ + +struct MyStruct { + std::string str; +}; + +struct RetStruct { + std::string str; +}; + +%} + +// Write a typemap that calls C++ by converting in and out of JSON. + +%go_import("encoding/json", "bytes", "encoding/binary") + +%insert(go_header) +%{ + +type In json.Marshaler + +%} + +%typemap(gotype) MyStruct "In" + +%typemap(imtype) MyStruct "string" + +%typemap(goin) MyStruct +%{ + { + b, err := $input.MarshalJSON() + if err != nil { + panic(err) + } + $result = string(b) + } +%} + +%typemap(in) MyStruct +%{ + $1.str.assign($input.p, $input.n); +%} + +%typemap(gotype) RetStruct "map[string]interface{}" + +%typemap(imtype) RetStruct "string" + +%typemap(out) RetStruct +%{ + $result = _swig_makegostring($1.str.data(), $1.str.length()); +%} + +%typemap(goout) RetStruct +%{ + if err := json.Unmarshal([]byte($1), &$result); err != nil { + panic(err) + } +%} + +%inline +%{ + +RetStruct Same(MyStruct s) +{ + RetStruct r; + r.str = s.str; + return r; +} + +%} + +%inline +%{ + +struct MyArray { + std::vector strings; +}; + +static uint64_t getuint64(const char* s) { + uint64_t ret = 0; + for (int i = 0; i < 8; i++, s++) { + ret |= static_cast(*s) << i * 8; + } + return ret; +} + +static void putuint64(std::string *s, size_t off, uint64_t v) { + for (int i = 0; i < 8; i++) { + (*s)[off + i] = (v >> (i * 8)) & 0xff; + } +} + +%} + +%typemap(gotype) MyArray* "*[]string" + +%typemap(imtype) MyArray* "*string" + +// Encode the slice as a single string, with length prefixes. +%typemap(goin) MyArray* +%{ + { + var buf bytes.Buffer + bin := binary.LittleEndian + var b [8]byte + bin.PutUint64(b[:], uint64(len(*$input))) + buf.Write(b[:]) + for _, s := range *$input { + bin.PutUint64(b[:], uint64(len(s))) + buf.Write(b[:]) + buf.WriteString(s) + } + str := buf.String() + $result = &str + } +%} + +// Unpack the string holding the packed slice. +%typemap(in) MyArray* (MyArray t) +%{ + { + _gostring_ *s = $input; + const char *p = static_cast(s->p); + uint64_t len = getuint64(p); + p += 8; + t.strings.resize(len); + for (uint64_t i = 0; i < len; i++) { + uint64_t slen = getuint64(p); + p += 8; + t.strings[i].assign(p, slen); + p += slen; + } + $1 = &t; + } +%} + +// Pack the vector into a string. +%typemap(argout) MyArray* +%{ + { + size_t tot = 8; + std::vector::const_iterator p; + for (p = $1->strings.begin(); p != $1->strings.end(); ++p) { + tot += 8 + p->size(); + } + std::string str; + str.resize(tot); + putuint64(&str, 0, $1->strings.size()); + size_t off = 8; + for (p = $1->strings.begin(); p != $1->strings.end(); ++p) { + putuint64(&str, off, p->size()); + off += 8; + str.replace(off, p->size(), *p); + off += p->size(); + } + *$input = _swig_makegostring(str.data(), str.size()); + } +%} + +// Unpack the string into a []string. +%typemap(goargout) MyArray* +%{ + { + str := *$input + bin := binary.LittleEndian + size := bin.Uint64([]byte(str[:8])) + str = str[8:] + r := make([]string, size) + for i := range r { + len := bin.Uint64([]byte(str[:8])) + str = str[8:] + r[i] = str[:len] + str = str[len:] + } + *$1 = r + } + +%} + +%inline +%{ +void DoubleArray(MyArray* v) { + size_t size = v->strings.size(); + for (size_t i = 0; i < size; i++) { + v->strings.push_back(v->strings[i] + v->strings[i]); + } +} +%} diff --git a/Examples/test-suite/import_nomodule.i b/Examples/test-suite/import_nomodule.i index 4fd5cbf65..60ef7e0f6 100644 --- a/Examples/test-suite/import_nomodule.i +++ b/Examples/test-suite/import_nomodule.i @@ -8,7 +8,7 @@ %import "import_nomodule.h" -#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) && !defined(SWIGD) +#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGPYTHON_BUILTIN) /** * The proxy class does not have Bar derived from Foo, yet an instance of Bar @@ -40,3 +40,10 @@ class Bar : public Foo { }; #endif +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index dd6c74a51..310f1a773 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -40,6 +40,9 @@ CPP_TEST_CASES = \ java_typemaps_typewrapper # li_boost_intrusive_ptr +CPP11_TEST_CASES = \ + cpp11_strongly_typed_enumerations_simple \ + include $(srcdir)/../common.mk # Overridden variables here diff --git a/Examples/test-suite/java/constant_directive_runme.java b/Examples/test-suite/java/constant_directive_runme.java new file mode 100644 index 000000000..b5135a499 --- /dev/null +++ b/Examples/test-suite/java/constant_directive_runme.java @@ -0,0 +1,22 @@ +import constant_directive.*; + +public class constant_directive_runme { + + static { + try { + System.loadLibrary("constant_directive"); + } 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[]) { + if (constant_directive.TYPE1_CONSTANT1.getVal() != 1) + throw new RuntimeException("fail"); + if (constant_directive.TYPE1_CONSTANT2.getVal() != 2) + throw new RuntimeException("fail"); + if (constant_directive.TYPE1_CONSTANT3.getVal() != 3) + throw new RuntimeException("fail"); + } +} diff --git a/Examples/test-suite/java/cpp11_strongly_typed_enumerations_runme.java b/Examples/test-suite/java/cpp11_strongly_typed_enumerations_runme.java new file mode 100644 index 000000000..3e0b3f651 --- /dev/null +++ b/Examples/test-suite/java/cpp11_strongly_typed_enumerations_runme.java @@ -0,0 +1,176 @@ +import cpp11_strongly_typed_enumerations.*; + +public class cpp11_strongly_typed_enumerations_runme { + + static { + try { + System.loadLibrary("cpp11_strongly_typed_enumerations"); + } 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 int enumCheck(int actual, int expected) { + if (actual != expected) + throw new RuntimeException("Enum value mismatch. Expected " + expected + " Actual: " + actual); + return expected + 1; + } + + public static void main(String argv[]) { + int val = 0; + val = enumCheck(Enum1.Val1.swigValue(), val); + val = enumCheck(Enum1.Val2.swigValue(), val); + val = enumCheck(Enum1.Val3.swigValue(), 13); + val = enumCheck(Enum1.Val4.swigValue(), val); + val = enumCheck(Enum1.Val5a.swigValue(), 13); + val = enumCheck(Enum1.Val6a.swigValue(), val); + + val = 0; + val = enumCheck(Enum2.Val1.swigValue(), val); + val = enumCheck(Enum2.Val2.swigValue(), val); + val = enumCheck(Enum2.Val3.swigValue(), 23); + val = enumCheck(Enum2.Val4.swigValue(), val); + val = enumCheck(Enum2.Val5b.swigValue(), 23); + val = enumCheck(Enum2.Val6b.swigValue(), val); + + val = 0; + val = enumCheck(Enum4.Val1.swigValue(), val); + val = enumCheck(Enum4.Val2.swigValue(), val); + val = enumCheck(Enum4.Val3.swigValue(), 43); + val = enumCheck(Enum4.Val4.swigValue(), val); + + val = 0; + val = enumCheck(Enum5.Val1.swigValue(), val); + val = enumCheck(Enum5.Val2.swigValue(), val); + val = enumCheck(Enum5.Val3.swigValue(), 53); + val = enumCheck(Enum5.Val4.swigValue(), val); + + val = 0; + val = enumCheck(Enum6.Val1.swigValue(), val); + val = enumCheck(Enum6.Val2.swigValue(), val); + val = enumCheck(Enum6.Val3.swigValue(), 63); + val = enumCheck(Enum6.Val4.swigValue(), val); + + val = 0; + val = enumCheck(Enum7td.Val1.swigValue(), val); + val = enumCheck(Enum7td.Val2.swigValue(), val); + val = enumCheck(Enum7td.Val3.swigValue(), 73); + val = enumCheck(Enum7td.Val4.swigValue(), val); + + val = 0; + val = enumCheck(Enum8.Val1.swigValue(), val); + val = enumCheck(Enum8.Val2.swigValue(), val); + val = enumCheck(Enum8.Val3.swigValue(), 83); + val = enumCheck(Enum8.Val4.swigValue(), val); + + val = 0; + val = enumCheck(Enum10.Val1.swigValue(), val); + val = enumCheck(Enum10.Val2.swigValue(), val); + val = enumCheck(Enum10.Val3.swigValue(), 103); + val = enumCheck(Enum10.Val4.swigValue(), val); + + val = 0; + val = enumCheck(Class1.Enum12.Val1.swigValue(), 1121); + val = enumCheck(Class1.Enum12.Val2.swigValue(), 1122); + val = enumCheck(Class1.Enum12.Val3.swigValue(), val); + val = enumCheck(Class1.Enum12.Val4.swigValue(), val); + val = enumCheck(Class1.Enum12.Val5c.swigValue(), 1121); + val = enumCheck(Class1.Enum12.Val6c.swigValue(), val); + + val = 0; + val = enumCheck(Class1.Enum13.Val1.swigValue(), 1131); + val = enumCheck(Class1.Enum13.Val2.swigValue(), 1132); + val = enumCheck(Class1.Enum13.Val3.swigValue(), val); + val = enumCheck(Class1.Enum13.Val4.swigValue(), val); + val = enumCheck(Class1.Enum13.Val5d.swigValue(), 1131); + val = enumCheck(Class1.Enum13.Val6d.swigValue(), val); + + val = 0; + val = enumCheck(Class1.Enum14.Val1.swigValue(), 1141); + val = enumCheck(Class1.Enum14.Val2.swigValue(), 1142); + val = enumCheck(Class1.Enum14.Val3.swigValue(), val); + val = enumCheck(Class1.Enum14.Val4.swigValue(), val); + val = enumCheck(Class1.Enum14.Val5e.swigValue(), 1141); + val = enumCheck(Class1.Enum14.Val6e.swigValue(), val); + + val = 0; + val = enumCheck(Class1.Struct1.Enum12.Val1.swigValue(), 3121); + val = enumCheck(Class1.Struct1.Enum12.Val2.swigValue(), 3122); + val = enumCheck(Class1.Struct1.Enum12.Val3.swigValue(), val); + val = enumCheck(Class1.Struct1.Enum12.Val4.swigValue(), val); + val = enumCheck(Class1.Struct1.Enum12.Val5f.swigValue(), 3121); + val = enumCheck(Class1.Struct1.Enum12.Val6f.swigValue(), val); + + val = 0; + val = enumCheck(Class1.Struct1.Enum13.Val1.swigValue(), 3131); + val = enumCheck(Class1.Struct1.Enum13.Val2.swigValue(), 3132); + val = enumCheck(Class1.Struct1.Enum13.Val3.swigValue(), val); + val = enumCheck(Class1.Struct1.Enum13.Val4.swigValue(), val); + + val = 0; + val = enumCheck(Class1.Struct1.Enum14.Val1.swigValue(), 3141); + val = enumCheck(Class1.Struct1.Enum14.Val2.swigValue(), 3142); + val = enumCheck(Class1.Struct1.Enum14.Val3.swigValue(), val); + val = enumCheck(Class1.Struct1.Enum14.Val4.swigValue(), val); + val = enumCheck(Class1.Struct1.Enum14.Val5g.swigValue(), 3141); + val = enumCheck(Class1.Struct1.Enum14.Val6g.swigValue(), val); + + val = 0; + val = enumCheck(Class2.Enum12.Val1.swigValue(), 2121); + val = enumCheck(Class2.Enum12.Val2.swigValue(), 2122); + val = enumCheck(Class2.Enum12.Val3.swigValue(), val); + val = enumCheck(Class2.Enum12.Val4.swigValue(), val); + val = enumCheck(Class2.Enum12.Val5h.swigValue(), 2121); + val = enumCheck(Class2.Enum12.Val6h.swigValue(), val); + + val = 0; + val = enumCheck(Class2.Enum13.Val1.swigValue(), 2131); + val = enumCheck(Class2.Enum13.Val2.swigValue(), 2132); + val = enumCheck(Class2.Enum13.Val3.swigValue(), val); + val = enumCheck(Class2.Enum13.Val4.swigValue(), val); + val = enumCheck(Class2.Enum13.Val5i.swigValue(), 2131); + val = enumCheck(Class2.Enum13.Val6i.swigValue(), val); + + val = 0; + val = enumCheck(Class2.Enum14.Val1.swigValue(), 2141); + val = enumCheck(Class2.Enum14.Val2.swigValue(), 2142); + val = enumCheck(Class2.Enum14.Val3.swigValue(), val); + val = enumCheck(Class2.Enum14.Val4.swigValue(), val); + val = enumCheck(Class2.Enum14.Val5j.swigValue(), 2141); + val = enumCheck(Class2.Enum14.Val6j.swigValue(), val); + + val = 0; + val = enumCheck(Class2.Struct1.Enum12.Val1.swigValue(), 4121); + val = enumCheck(Class2.Struct1.Enum12.Val2.swigValue(), 4122); + val = enumCheck(Class2.Struct1.Enum12.Val3.swigValue(), val); + val = enumCheck(Class2.Struct1.Enum12.Val4.swigValue(), val); + val = enumCheck(Class2.Struct1.Enum12.Val5k.swigValue(), 4121); + val = enumCheck(Class2.Struct1.Enum12.Val6k.swigValue(), val); + + val = 0; + val = enumCheck(Class2.Struct1.Enum13.Val1.swigValue(), 4131); + val = enumCheck(Class2.Struct1.Enum13.Val2.swigValue(), 4132); + val = enumCheck(Class2.Struct1.Enum13.Val3.swigValue(), val); + val = enumCheck(Class2.Struct1.Enum13.Val4.swigValue(), val); + val = enumCheck(Class2.Struct1.Enum13.Val5l.swigValue(), 4131); + val = enumCheck(Class2.Struct1.Enum13.Val6l.swigValue(), val); + + val = 0; + val = enumCheck(Class2.Struct1.Enum14.Val1.swigValue(), 4141); + val = enumCheck(Class2.Struct1.Enum14.Val2.swigValue(), 4142); + val = enumCheck(Class2.Struct1.Enum14.Val3.swigValue(), val); + val = enumCheck(Class2.Struct1.Enum14.Val4.swigValue(), val); + val = enumCheck(Class2.Struct1.Enum14.Val5m.swigValue(), 4141); + val = enumCheck(Class2.Struct1.Enum14.Val6m.swigValue(), val); + + Class1 class1 = new Class1(); + enumCheck(class1.class1Test1(Enum1.Val5a).swigValue(), 13); + enumCheck(class1.class1Test2(Class1.Enum12.Val5c).swigValue(), 1121); + enumCheck(class1.class1Test3(Class1.Struct1.Enum12.Val5f).swigValue(), 3121); + + enumCheck(cpp11_strongly_typed_enumerations.globalTest1(Enum1.Val5a).swigValue(), 13); + enumCheck(cpp11_strongly_typed_enumerations.globalTest2(Class1.Enum12.Val5c).swigValue(), 1121); + enumCheck(cpp11_strongly_typed_enumerations.globalTest3(Class1.Struct1.Enum12.Val5f).swigValue(), 3121); + } +} diff --git a/Examples/test-suite/java/cpp11_strongly_typed_enumerations_simple_runme.java b/Examples/test-suite/java/cpp11_strongly_typed_enumerations_simple_runme.java new file mode 100644 index 000000000..b50e94893 --- /dev/null +++ b/Examples/test-suite/java/cpp11_strongly_typed_enumerations_simple_runme.java @@ -0,0 +1,176 @@ +import cpp11_strongly_typed_enumerations_simple.*; + +public class cpp11_strongly_typed_enumerations_simple_runme { + + static { + try { + System.loadLibrary("cpp11_strongly_typed_enumerations_simple"); + } 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 int enumCheck(int actual, int expected) { + if (actual != expected) + throw new RuntimeException("Enum value mismatch. Expected " + expected + " Actual: " + actual); + return expected + 1; + } + + public static void main(String argv[]) { + int val = 0; + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum1_Val1, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum1_Val2, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum1_Val3, 13); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum1_Val4, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum1_Val5a, 13); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum1_Val6a, val); + + val = 0; + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum2_Val1, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum2_Val2, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum2_Val3, 23); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum2_Val4, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum2_Val5b, 23); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum2_Val6b, val); + + val = 0; + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Val1, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Val2, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Val3, 43); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Val4, val); + + val = 0; + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum5_Val1, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum5_Val2, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum5_Val3, 53); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum5_Val4, val); + + val = 0; + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum6_Val1, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum6_Val2, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum6_Val3, 63); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum6_Val4, val); + + val = 0; + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum7td_Val1, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum7td_Val2, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum7td_Val3, 73); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum7td_Val4, val); + + val = 0; + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum8_Val1, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum8_Val2, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum8_Val3, 83); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum8_Val4, val); + + val = 0; + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum10_Val1, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum10_Val2, val); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum10_Val3, 103); + val = enumCheck(cpp11_strongly_typed_enumerations_simple.Enum10_Val4, val); + + val = 0; + val = enumCheck(Class1.Enum12_Val1, 1121); + val = enumCheck(Class1.Enum12_Val2, 1122); + val = enumCheck(Class1.Enum12_Val3, val); + val = enumCheck(Class1.Enum12_Val4, val); + val = enumCheck(Class1.Enum12_Val5c, 1121); + val = enumCheck(Class1.Enum12_Val6c, val); + + val = 0; + val = enumCheck(Class1.Val1, 1131); + val = enumCheck(Class1.Val2, 1132); + val = enumCheck(Class1.Val3, val); + val = enumCheck(Class1.Val4, val); + val = enumCheck(Class1.Val5d, 1131); + val = enumCheck(Class1.Val6d, val); + + val = 0; + val = enumCheck(Class1.Enum14_Val1, 1141); + val = enumCheck(Class1.Enum14_Val2, 1142); + val = enumCheck(Class1.Enum14_Val3, val); + val = enumCheck(Class1.Enum14_Val4, val); + val = enumCheck(Class1.Enum14_Val5e, 1141); + val = enumCheck(Class1.Enum14_Val6e, val); + + val = 0; + val = enumCheck(Class1.Struct1.Enum12_Val1, 3121); + val = enumCheck(Class1.Struct1.Enum12_Val2, 3122); + val = enumCheck(Class1.Struct1.Enum12_Val3, val); + val = enumCheck(Class1.Struct1.Enum12_Val4, val); + val = enumCheck(Class1.Struct1.Enum12_Val5f, 3121); + val = enumCheck(Class1.Struct1.Enum12_Val6f, val); + + val = 0; + val = enumCheck(Class1.Struct1.Val1, 3131); + val = enumCheck(Class1.Struct1.Val2, 3132); + val = enumCheck(Class1.Struct1.Val3, val); + val = enumCheck(Class1.Struct1.Val4, val); + + val = 0; + val = enumCheck(Class1.Struct1.Enum14_Val1, 3141); + val = enumCheck(Class1.Struct1.Enum14_Val2, 3142); + val = enumCheck(Class1.Struct1.Enum14_Val3, val); + val = enumCheck(Class1.Struct1.Enum14_Val4, val); + val = enumCheck(Class1.Struct1.Enum14_Val5g, 3141); + val = enumCheck(Class1.Struct1.Enum14_Val6g, val); + + val = 0; + val = enumCheck(Class2.Enum12_Val1, 2121); + val = enumCheck(Class2.Enum12_Val2, 2122); + val = enumCheck(Class2.Enum12_Val3, val); + val = enumCheck(Class2.Enum12_Val4, val); + val = enumCheck(Class2.Enum12_Val5h, 2121); + val = enumCheck(Class2.Enum12_Val6h, val); + + val = 0; + val = enumCheck(Class2.Val1, 2131); + val = enumCheck(Class2.Val2, 2132); + val = enumCheck(Class2.Val3, val); + val = enumCheck(Class2.Val4, val); + val = enumCheck(Class2.Val5i, 2131); + val = enumCheck(Class2.Val6i, val); + + val = 0; + val = enumCheck(Class2.Enum14_Val1, 2141); + val = enumCheck(Class2.Enum14_Val2, 2142); + val = enumCheck(Class2.Enum14_Val3, val); + val = enumCheck(Class2.Enum14_Val4, val); + val = enumCheck(Class2.Enum14_Val5j, 2141); + val = enumCheck(Class2.Enum14_Val6j, val); + + val = 0; + val = enumCheck(Class2.Struct1.Enum12_Val1, 4121); + val = enumCheck(Class2.Struct1.Enum12_Val2, 4122); + val = enumCheck(Class2.Struct1.Enum12_Val3, val); + val = enumCheck(Class2.Struct1.Enum12_Val4, val); + val = enumCheck(Class2.Struct1.Enum12_Val5k, 4121); + val = enumCheck(Class2.Struct1.Enum12_Val6k, val); + + val = 0; + val = enumCheck(Class2.Struct1.Val1, 4131); + val = enumCheck(Class2.Struct1.Val2, 4132); + val = enumCheck(Class2.Struct1.Val3, val); + val = enumCheck(Class2.Struct1.Val4, val); + val = enumCheck(Class2.Struct1.Val5l, 4131); + val = enumCheck(Class2.Struct1.Val6l, val); + + val = 0; + val = enumCheck(Class2.Struct1.Enum14_Val1, 4141); + val = enumCheck(Class2.Struct1.Enum14_Val2, 4142); + val = enumCheck(Class2.Struct1.Enum14_Val3, val); + val = enumCheck(Class2.Struct1.Enum14_Val4, val); + val = enumCheck(Class2.Struct1.Enum14_Val5m, 4141); + val = enumCheck(Class2.Struct1.Enum14_Val6m, val); + + Class1 class1 = new Class1(); + enumCheck(class1.class1Test1(cpp11_strongly_typed_enumerations_simple.Enum1_Val5a), 13); + enumCheck(class1.class1Test2(Class1.Enum12_Val5c), 1121); + enumCheck(class1.class1Test3(Class1.Struct1.Enum12_Val5f), 3121); + + enumCheck(cpp11_strongly_typed_enumerations_simple.globalTest1(cpp11_strongly_typed_enumerations_simple.Enum1_Val5a), 13); + enumCheck(cpp11_strongly_typed_enumerations_simple.globalTest2(Class1.Enum12_Val5c), 1121); + enumCheck(cpp11_strongly_typed_enumerations_simple.globalTest3(Class1.Struct1.Enum12_Val5f), 3121); + } +} diff --git a/Examples/test-suite/java/director_nested_class_runme.java b/Examples/test-suite/java/director_nested_class_runme.java new file mode 100644 index 000000000..5144413b7 --- /dev/null +++ b/Examples/test-suite/java/director_nested_class_runme.java @@ -0,0 +1,41 @@ + +import director_nested_class.*; + +public class director_nested_class_runme { + + static { + try { + System.loadLibrary("director_nested_class"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + + director_nested_class_Derived d = new director_nested_class_Derived(); + + if (DirectorOuter.callMethod(d, 999) != 9990) { + throw new RuntimeException("callMethod(999) failed"); + } + + director_nested_class_DerivedInnerInner dinner = new director_nested_class_DerivedInnerInner(); + + if (DirectorOuter.callInnerInnerMethod(dinner, 999) != 999000) { + throw new RuntimeException("callMethod(999) failed"); + } + } +} + +class director_nested_class_Derived extends DirectorOuter.DirectorInner { + public int vmethod(int input) { + return input * 10; + } +} + +class director_nested_class_DerivedInnerInner extends DirectorOuter.DirectorInner.DirectorInnerInner { + public int innervmethod(int input) { + return input * 1000; + } +} diff --git a/Examples/test-suite/java/java_director_runme.java b/Examples/test-suite/java/java_director_runme.java index 812e791f4..2167d2621 100644 --- a/Examples/test-suite/java/java_director_runme.java +++ b/Examples/test-suite/java/java_director_runme.java @@ -53,7 +53,7 @@ public class java_director_runme { }; int actualCount = Quux.instances(); if (actualCount != expectedCount) - throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount); + System.err.println("GC failed to run (java_director). Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't } /* Test Quux1's director disconnect method rename */ diff --git a/Examples/test-suite/java/java_lib_various_runme.java b/Examples/test-suite/java/java_lib_various_runme.java index 203a30ec2..6d9e13e31 100644 --- a/Examples/test-suite/java/java_lib_various_runme.java +++ b/Examples/test-suite/java/java_lib_various_runme.java @@ -83,6 +83,25 @@ public class java_lib_various_runme { if (byjove[i] != b[i]) throw new RuntimeException("By jove, it failed: [" + new String(b) + "]"); } + + // NIOBUFFER typemap check + java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocateDirect(10); + java_lib_various.niobuffer_fill_hello(buf); + if ( + (char)buf.get(0) != 'h' || + (char)buf.get(1) != 'e' || + (char)buf.get(2) != 'l' || + (char)buf.get(3) != 'l' || + (char)buf.get(4) != 'o' + ) + throw new RuntimeException( + "nio test failed: " + + (char)buf.get(0) + + (char)buf.get(1) + + (char)buf.get(2) + + (char)buf.get(3) + + (char)buf.get(4) + ); } } diff --git a/Examples/test-suite/java/kwargs_feature_runme.java b/Examples/test-suite/java/kwargs_feature_runme.java new file mode 100644 index 000000000..ba742d9ec --- /dev/null +++ b/Examples/test-suite/java/kwargs_feature_runme.java @@ -0,0 +1,23 @@ +import kwargs_feature.*; + +public class kwargs_feature_runme { + + static { + try { + System.loadLibrary("kwargs_feature"); + } 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[]) { + // Check normal overloading still works (no compactdefaultargs) if the kwargs feature is used, + // as the kwargs feature is not supported + Foo f = new Foo(99); + if (f.foo() != 1) + throw new RuntimeException("It went wrong"); + if (Foo.statfoo(2) != 2) + throw new RuntimeException("It went wrong"); + } +} diff --git a/Examples/test-suite/java/li_boost_shared_ptr_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_runme.java index aa355c86a..64c356f8e 100644 --- a/Examples/test-suite/java/li_boost_shared_ptr_runme.java +++ b/Examples/test-suite/java/li_boost_shared_ptr_runme.java @@ -59,7 +59,7 @@ public class li_boost_shared_ptr_runme { } int actualCount = Klass.getTotal_count(); if (actualCount != expectedCount) - throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount); + System.err.println("GC failed to run (li_boost_shared_ptr). Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't } int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count(); diff --git a/Examples/test-suite/java/li_std_auto_ptr_runme.java b/Examples/test-suite/java/li_std_auto_ptr_runme.java index db34fb529..50ed113a4 100644 --- a/Examples/test-suite/java/li_std_auto_ptr_runme.java +++ b/Examples/test-suite/java/li_std_auto_ptr_runme.java @@ -43,7 +43,7 @@ public class li_std_auto_ptr_runme { } int actualCount = Klass.getTotal_count(); if (actualCount != expectedCount) - throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount); + System.err.println("GC failed to run (li_std_auto_ptr 1). Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't } if (!k2.getLabel().equals("second")) @@ -62,7 +62,7 @@ public class li_std_auto_ptr_runme { }; int actualCount = Klass.getTotal_count(); if (actualCount != expectedCount) - throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount); + System.err.println("GC failed to run (li_std_auto_ptr 2). Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't } } } diff --git a/Examples/test-suite/java/nested_template_base_runme.java b/Examples/test-suite/java/nested_template_base_runme.java new file mode 100644 index 000000000..8404afe04 --- /dev/null +++ b/Examples/test-suite/java/nested_template_base_runme.java @@ -0,0 +1,27 @@ +import nested_template_base.*; + +public class nested_template_base_runme { + + static { + try { + System.loadLibrary("nested_template_base"); + } 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[]) { + OuterC.InnerS ois = new OuterC.InnerS(123); + OuterC.InnerC oic = new OuterC.InnerC(); + + // Check base method is available + if (oic.outer(ois).getVal() != 123) + throw new RuntimeException("Wrong value calling outer"); + + // Check non-derived class using base class + if (oic.innerc().outer(ois).getVal() != 123) + throw new RuntimeException("Wrong value calling innerc"); + + } +} diff --git a/Examples/test-suite/java/smart_pointer_const_overload_runme.java b/Examples/test-suite/java/smart_pointer_const_overload_runme.java index bb4ae2c8f..9c10dedb2 100644 --- a/Examples/test-suite/java/smart_pointer_const_overload_runme.java +++ b/Examples/test-suite/java/smart_pointer_const_overload_runme.java @@ -41,7 +41,7 @@ public class smart_pointer_const_overload_runme { Assert(f.getAccess() == MUTABLE_ACCESS); // Test static method - b.stat(); + b.statMethod(); Assert(f.getAccess() == CONST_ACCESS); diff --git a/Examples/test-suite/java/template_default_class_parms_runme.java b/Examples/test-suite/java/template_default_class_parms_runme.java index 406915b82..0a6571fa8 100644 --- a/Examples/test-suite/java/template_default_class_parms_runme.java +++ b/Examples/test-suite/java/template_default_class_parms_runme.java @@ -45,6 +45,11 @@ public class template_default_class_parms_runme { foo.setTType(a); a = foo.method(a); } + + { + MapDefaults md = new MapDefaults(); + md.test_func(10, 20, new DefaultNodeType()); + } } } diff --git a/Examples/test-suite/java/template_templated_constructors_runme.java b/Examples/test-suite/java/template_templated_constructors_runme.java new file mode 100644 index 000000000..cd3f31d21 --- /dev/null +++ b/Examples/test-suite/java/template_templated_constructors_runme.java @@ -0,0 +1,26 @@ + +import template_templated_constructors.*; + +public class template_templated_constructors_runme { + + static { + try { + System.loadLibrary("template_templated_constructors"); + } 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[]) { + TConstructor1 t1 = new TConstructor1(123); + TConstructor2 t2a = new TConstructor2(); + TConstructor2 t2b = new TConstructor2(123); + + TClass1Int tc1 = new TClass1Int(123.4); + TClass2Int tc2a = new TClass2Int(); + TClass2Int tc2b = new TClass2Int(123.4); + + } +} + diff --git a/Examples/test-suite/java/template_typedef_typedef_runme.java b/Examples/test-suite/java/template_typedef_typedef_runme.java index f5f368561..5a3af0099 100644 --- a/Examples/test-suite/java/template_typedef_typedef_runme.java +++ b/Examples/test-suite/java/template_typedef_typedef_runme.java @@ -12,13 +12,13 @@ public class template_typedef_typedef_runme { } public static void main(String argv[]) { - ObjectBase ob1 = new ObjectBase(); - ob1.getBlabla1(new ObjectBase()); + Object1Base ob1 = new Object1Base(); + ob1.getBlabla1(new Object1Base()); Object2Base ob2 = new Object2Base(); ob2.getBlabla2(new Object2Base()); Factory factory = new Factory(); - factory.getBlabla3(new ObjectBase()); + factory.getBlabla3(new Object1Base()); factory.getBlabla4(new Object2Base()); } } diff --git a/Examples/test-suite/java_lib_various.i b/Examples/test-suite/java_lib_various.i index 716ae9139..180d07569 100644 --- a/Examples/test-suite/java_lib_various.i +++ b/Examples/test-suite/java_lib_various.i @@ -8,6 +8,7 @@ %apply char **STRING_ARRAY { char **languages }; %apply char *BYTE { char *chars }; %apply char **STRING_OUT { char **string_ptr }; +%apply unsigned char *NIOBUFFER { unsigned char *buf }; %typemap(freearg) char **languages "" // don't delete memory when setting global variable %{ @@ -47,5 +48,8 @@ void char_ptr_ptr_out(char **string_ptr) { *string_ptr = ret; } +void niobuffer_fill_hello(unsigned char *buf) { + sprintf ((char*)buf,"hello"); +} %} diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index b6e946de2..83b15f822 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -6,6 +6,8 @@ LANGUAGE = javascript NODEGYP = @NODEGYP@ NODEJS = @NODEJS@ SCRIPTSUFFIX = _runme.js +OBJEXT = @OBJEXT@ +SO = @SO@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ @@ -19,8 +21,16 @@ else JSENGINE=node endif +ifneq (, $(V8_VERSION)) + JSV8_VERSION=$(V8_VERSION) +else + JSV8_VERSION=0x031110 +endif + include $(srcdir)/../common.mk +SWIGOPT += -DV8_VERSION=$(JSV8_VERSION) + _setup = \ if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ echo "$(ACTION)ing $(LANGUAGE) ($(JSENGINE)) testcase $* (with run test)" ; \ @@ -108,10 +118,10 @@ endif %.clean: @rm -rf $* - @rm -f $*_wrap.* $*.so $*.o + @rm -f $*_wrap.* $*$(SO) $*.$(OBJEXT) clean: - for ext in _wrap.cxx _wrap.o .so; do \ + for ext in _wrap.cxx _wrap.$(OBJEXT) $(SO); do \ rm -f clientdata_prop_a$${ext} clientdata_prop_b$${ext}; \ rm -f imports_a$${ext} imports_b$${ext}; \ rm -f import_stl_a$${ext} import_stl_b$${ext}; \ diff --git a/Examples/test-suite/javascript/cpp11_strongly_typed_enumerations_runme.js b/Examples/test-suite/javascript/cpp11_strongly_typed_enumerations_runme.js new file mode 100644 index 000000000..ad9d4e883 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_strongly_typed_enumerations_runme.js @@ -0,0 +1,165 @@ +var cpp11_strongly_typed_enumerations = require("cpp11_strongly_typed_enumerations"); + +function enumCheck(actual, expected) { + if (actual != expected) { + throw new Error("Enum value mismatch. Expected: " + expected + " Actual: " + actual); + } + return expected + 1; +} + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val3, 13); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val5a, 13); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val6a, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val3, 23); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val5b, 23); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val6b, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Val3, 43); +val = enumCheck(cpp11_strongly_typed_enumerations.Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val3, 53); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val3, 63); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val3, 73); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val3, 83); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val3, 103); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val1, 1121); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val2, 1122); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val5c, 1121); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val6c, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val1, 1131); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val2, 1132); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val5d, 1131); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val6d, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val1, 1141); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val2, 1142); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val5e, 1141); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val6e, val); + +// Requires nested class support to work +//val = 0; +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val1, 3121); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val2, 3122); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val3, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val4, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val5f, 3121); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val6f, val); +// +//val = 0; +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Val1, 3131); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Val2, 3132); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Val3, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Val4, val); +// +//val = 0; +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val1, 3141); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val2, 3142); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val3, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val4, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val5g, 3141); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val6g, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val1, 2121); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val2, 2122); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val5h, 2121); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val6h, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val1, 2131); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val2, 2132); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val5i, 2131); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val6i, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val1, 2141); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val2, 2142); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val5j, 2141); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val6j, val); + +// Requires nested class support to work +//val = 0; +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum12_Val1, 4121); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum12_Val2, 4122); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum12_Val3, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum12_Val4, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum12_Val5k, 4121); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum12_Val6k, val); +// +//val = 0; +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Val1, 4131); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Val2, 4132); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Val3, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Val4, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Val5l, 4131); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Val6l, val); +// +//val = 0; +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum14_Val1, 4141); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum14_Val2, 4142); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum14_Val3, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum14_Val4, val); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum14_Val5m, 4141); +//val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1_Enum14_Val6m, val); + +class1 = new cpp11_strongly_typed_enumerations.Class1(); +enumCheck(class1.class1Test1(cpp11_strongly_typed_enumerations.Enum1_Val5a), 13); +enumCheck(class1.class1Test2(cpp11_strongly_typed_enumerations.Class1.Enum12_Val5c), 1121); +//enumCheck(class1.class1Test3(cpp11_strongly_typed_enumerations.Class1.Struct1_Enum12_Val5f), 3121); + +enumCheck(cpp11_strongly_typed_enumerations.globalTest1(cpp11_strongly_typed_enumerations.Enum1_Val5a), 13); +enumCheck(cpp11_strongly_typed_enumerations.globalTest2(cpp11_strongly_typed_enumerations.Class1.Enum12_Val5c), 1121); +//enumCheck(globalTest3(cpp11_strongly_typed_enumerations.Class1.Struct1_Enum12_Val5f), 3121); diff --git a/Examples/test-suite/kwargs_feature.i b/Examples/test-suite/kwargs_feature.i index 87153109a..a8d1c38d8 100644 --- a/Examples/test-suite/kwargs_feature.i +++ b/Examples/test-suite/kwargs_feature.i @@ -1,7 +1,7 @@ %module kwargs_feature %nocopyctor; -%kwargs; +%feature("kwargs"); %rename(myDel) del; %inline @@ -35,9 +35,7 @@ virtual ~Foo() { } - }; - %} @@ -64,8 +62,7 @@ // Functions %inline %{ - int foo(int a = 1, int b = 0) {return a + b; } - + int foo_fn(int a = 1, int b = 0) {return a + b; } template T templatedfunction(T a = 1, T b = 0) { return a + b; } %} @@ -73,10 +70,8 @@ %template(templatedfunction) templatedfunction; -// Deafult args with references -%inline -%{ - +// Default args with references +%inline %{ typedef int size_type; struct Hello @@ -84,13 +79,10 @@ static const size_type hello = 3; }; - - - int rfoo( const size_type& x = Hello::hello, const Hello& y = Hello() ) + int rfoo( int n = 0, const size_type& x = Hello::hello, const Hello& y = Hello() ) { - return x; + return n - x; } - %} %{ const int Hello::hello; @@ -104,9 +96,7 @@ int foo_kw(int from = 1, int except = 2) {return from + except; } - int foo_nu(int from = 1, int = 0) {return from; } int foo_mm(int min = 1, int max = 2) {return min + max; } - %} diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index 134e1b3dc..cccef1d57 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -44,7 +44,7 @@ # define SWIG_SHARED_PTR_NAMESPACE SwigBoost #endif -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_std_except_as_class.i b/Examples/test-suite/li_std_except_as_class.i index 0400c9a82..01ed1f07c 100644 --- a/Examples/test-suite/li_std_except_as_class.i +++ b/Examples/test-suite/li_std_except_as_class.i @@ -23,3 +23,11 @@ void test_domain_error() throw(std::domain_error) %include void test_domain_error() throw(std::domain_error) { throw std::domain_error("std::domain_error"); } + +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/test-suite/li_std_string_extra.i b/Examples/test-suite/li_std_string_extra.i index aa758532a..6bef12ff4 100644 --- a/Examples/test-suite/li_std_string_extra.i +++ b/Examples/test-suite/li_std_string_extra.i @@ -49,6 +49,12 @@ std::basic_string,std::allocator > test_value_ return x; } +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif + %} %include "li_std_string.i" diff --git a/Examples/test-suite/li_std_wstring.i b/Examples/test-suite/li_std_wstring.i index e0ecde53b..80f860338 100644 --- a/Examples/test-suite/li_std_wstring.i +++ b/Examples/test-suite/li_std_wstring.i @@ -92,6 +92,12 @@ void test_throw() throw(std::wstring){ #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) #endif +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif + %} diff --git a/Examples/test-suite/li_swigtype_inout.i b/Examples/test-suite/li_swigtype_inout.i index 9d7e9a4c6..136c9fa9e 100644 --- a/Examples/test-suite/li_swigtype_inout.i +++ b/Examples/test-suite/li_swigtype_inout.i @@ -13,28 +13,28 @@ #include struct XXX { XXX(int v) : value(v) { - if (debug) std::cout << "Default Constructor " << value << " " << this << std::endl; + if (debugging) std::cout << "Default Constructor " << value << " " << this << std::endl; count++; } XXX(const XXX &other) { value = other.value; - if (debug) std::cout << "Copy Constructor " << value << " " << this << std::endl; + if (debugging) std::cout << "Copy Constructor " << value << " " << this << std::endl; count++; } XXX& operator=(const XXX &other) { value = other.value; - if (debug) std::cout << "Assignment operator " << value << " " << this << std::endl; + if (debugging) std::cout << "Assignment operator " << value << " " << this << std::endl; return *this; } ~XXX() { - if (debug) std::cout << "Destructor " << value << " " << this << std::endl; + if (debugging) std::cout << "Destructor " << value << " " << this << std::endl; count--; } void showInfo() { - if (debug) std::cout << "Info " << value << " " << this << std::endl; + if (debugging) std::cout << "Info " << value << " " << this << std::endl; } int value; - static const bool debug = false; + static const bool debugging = false; static int count; }; int XXX::count = 0; diff --git a/Examples/test-suite/lua/cpp11_strongly_typed_enumerations_runme.lua b/Examples/test-suite/lua/cpp11_strongly_typed_enumerations_runme.lua new file mode 100644 index 000000000..983e25aa2 --- /dev/null +++ b/Examples/test-suite/lua/cpp11_strongly_typed_enumerations_runme.lua @@ -0,0 +1,174 @@ +require("import") -- the import fn +import("cpp11_strongly_typed_enumerations") -- import lib + +-- catch "undefined" global variables +local env = _ENV -- Lua 5.2 +if not env then env = getfenv () end -- Lua 5.1 +setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) + +function enumCheck(actual, expected) + if not (actual == expected) then + error("Enum value mismatch. Expected: "..expected.." Actual: "..actual) + end + return expected + 1 +end + +--val = 0 +--val = enumCheck(cpp11_strongly_typed_enumerations.cpp11_strongly_typed_enumerations.Enum1_Val1, val) +local val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val1, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val2, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val3, 13) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val4, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val5a, 13) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val6a, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val1, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val2, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val3, 23) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val4, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val5b, 23) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val6b, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Val1, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Val2, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Val3, 43) +val = enumCheck(cpp11_strongly_typed_enumerations.Val4, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val1, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val2, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val3, 53) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val4, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val1, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val2, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val3, 63) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val4, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val1, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val2, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val3, 73) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val4, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val1, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val2, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val3, 83) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val4, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val1, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val2, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val3, 103) +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val4, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val1, 1121) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val2, 1122) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val3, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val4, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val5c, 1121) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum12_Val6c, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val1, 1131) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val2, 1132) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val3, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val4, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val5d, 1131) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Val6d, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val1, 1141) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val2, 1142) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val3, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val4, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val5e, 1141) +val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Enum14_Val6e, val) + +-- Requires nested class support to work +--val = 0 +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val1, 3121) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val2, 3122) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val3, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val4, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val5f, 3121) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val6f, val) +-- +--val = 0 +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Val1, 3131) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Val2, 3132) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Val3, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Val4, val) +-- +--val = 0 +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val1, 3141) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val2, 3142) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val3, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val4, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val5g, 3141) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum14_Val6g, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val1, 2121) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val2, 2122) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val3, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val4, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val5h, 2121) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum12_Val6h, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val1, 2131) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val2, 2132) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val3, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val4, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val5i, 2131) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Val6i, val) + +val = 0 +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val1, 2141) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val2, 2142) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val3, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val4, val) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val5j, 2141) +val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Enum14_Val6j, val) + +-- Requires nested class support to work +--val = 0 +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum12_Val1, 4121) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum12_Val2, 4122) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum12_Val3, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum12_Val4, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum12_Val5k, 4121) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum12_Val6k, val) +-- +--val = 0 +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Val1, 4131) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Val2, 4132) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Val3, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Val4, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Val5l, 4131) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Val6l, val) +-- +--val = 0 +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum14_Val1, 4141) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum14_Val2, 4142) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum14_Val3, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum14_Val4, val) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum14_Val5m, 4141) +--val = enumCheck(cpp11_strongly_typed_enumerations.Class2.Struct1.Enum14_Val6m, val) + +class1 = cpp11_strongly_typed_enumerations.Class1() +enumCheck(class1:class1Test1(cpp11_strongly_typed_enumerations.Enum1_Val5a), 13) +enumCheck(class1:class1Test2(cpp11_strongly_typed_enumerations.Class1.Enum12_Val5c), 1121) +--enumCheck(class1:class1Test3(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val5f), 3121) + +enumCheck(cpp11_strongly_typed_enumerations.globalTest1(cpp11_strongly_typed_enumerations.Enum1_Val5a), 13) +enumCheck(cpp11_strongly_typed_enumerations.globalTest2(cpp11_strongly_typed_enumerations.Class1.Enum12_Val5c), 1121) +--enumCheck(globalTest3(cpp11_strongly_typed_enumerations.Class1.Struct1.Enum12_Val5f), 3121) + diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index 396adb638..a8de84b49 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -77,6 +77,9 @@ struct Outer { struct { Integer b; }; +#else + Integer a; + Integer b; #endif union { @@ -192,6 +195,9 @@ struct Outer { public: Integer yy; }; +#else + Integer xx; + Integer yy; #endif /////////////////////////////////////////// diff --git a/Examples/test-suite/nested_scope.i b/Examples/test-suite/nested_scope.i index 789478361..bd66eec73 100644 --- a/Examples/test-suite/nested_scope.i +++ b/Examples/test-suite/nested_scope.i @@ -26,4 +26,42 @@ namespace ns { #endif }; } + class Outer1 { + struct Nested1; + public: + struct Nested2; +#ifdef __clang__ + struct Nested2 { + int data; + }; +#endif + template class AbstractClass; + class Real; + }; +#ifndef __clang__ + struct Outer1::Nested2 { + int data; + }; +#endif + + class Klass { + public: + template class AbstractClass; + class Real; + }; + + template class Klass::AbstractClass { + public: + virtual void Method() = 0; + virtual ~AbstractClass() {} + }; +%} + +%template(abstract_int) Klass::AbstractClass ; + +%inline %{ + class Klass::Real : public AbstractClass { + public: + virtual void Method() {} + }; %} diff --git a/Examples/test-suite/nested_template_base.i b/Examples/test-suite/nested_template_base.i new file mode 100644 index 000000000..0b0272224 --- /dev/null +++ b/Examples/test-suite/nested_template_base.i @@ -0,0 +1,38 @@ +%module nested_template_base + +%inline %{ + template class OuterT { + public: + T outer(T t) { return t; } + }; +%} + +// The %template goes after OuterT and before OuterC as OuterC::InnerC's base is handled inside OuterC +%template(OuterTInnerS) OuterT; + +#if !defined(SWIGCSHARP) && !defined(SWIGJAVA) +%feature("flatnested") OuterC::InnerS; +%feature("flatnested") OuterC::InnerC; +#endif + + +%inline %{ + class OuterC { + public: + struct InnerS; + class InnerC; + }; + + struct OuterC::InnerS { + int val; + InnerS(int val = 0) : val(val) {} + }; + + + class OuterC::InnerC : public OuterT { + public: + OuterT& innerc() { + return *this; + } + }; +%} diff --git a/Examples/test-suite/octave/cpp11_strongly_typed_enumerations_runme.m b/Examples/test-suite/octave/cpp11_strongly_typed_enumerations_runme.m new file mode 100644 index 000000000..f66d3d569 --- /dev/null +++ b/Examples/test-suite/octave/cpp11_strongly_typed_enumerations_runme.m @@ -0,0 +1,166 @@ +cpp11_strongly_typed_enumerations + +function newvalue = enumCheck(actual, expected) + if (actual != expected); + error("Enum value mismatch. Expected: %d Actual: %d", expected, actual); + endif + newvalue = expected + 1; +end + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val3, 13); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val5a, 13); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum1_Val6a, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val3, 23); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val5b, 23); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum2_Val6b, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Val3, 43); +val = enumCheck(cpp11_strongly_typed_enumerations.Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val3, 53); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum5_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val3, 63); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum6_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val3, 73); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum7td_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val3, 83); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum8_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val1, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val2, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val3, 103); +val = enumCheck(cpp11_strongly_typed_enumerations.Enum10_Val4, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum12_Val1, 1121); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum12_Val2, 1122); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum12_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum12_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum12_Val5c, 1121); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum12_Val6c, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Val1, 1131); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Val2, 1132); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Val5d, 1131); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Val6d, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum14_Val1, 1141); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum14_Val2, 1142); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum14_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum14_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum14_Val5e, 1141); +val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Enum14_Val6e, val); + +# Requires nested class support to work +#val = 0; +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum12_Val1, 3121); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum12_Val2, 3122); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum12_Val3, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum12_Val4, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum12_Val5f, 3121); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum12_Val6f, val); +# +#val = 0; +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Val1, 3131); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Val2, 3132); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Val3, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Val4, val); +# +#val = 0; +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum14_Val1, 3141); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum14_Val2, 3142); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum14_Val3, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum14_Val4, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum14_Val5g, 3141); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class1_Struct1.Enum14_Val6g, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum12_Val1, 2121); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum12_Val2, 2122); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum12_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum12_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum12_Val5h, 2121); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum12_Val6h, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Val1, 2131); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Val2, 2132); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Val5i, 2131); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Val6i, val); + +val = 0; +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum14_Val1, 2141); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum14_Val2, 2142); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum14_Val3, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum14_Val4, val); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum14_Val5j, 2141); +val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Enum14_Val6j, val); + +# Requires nested class support to work +#val = 0; +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum12_Val1, 4121); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum12_Val2, 4122); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum12_Val3, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum12_Val4, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum12_Val5k, 4121); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum12_Val6k, val); +# +#val = 0; +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Val1, 4131); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Val2, 4132); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Val3, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Val4, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Val5l, 4131); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Val6l, val); +# +#val = 0; +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum14_Val1, 4141); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum14_Val2, 4142); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum14_Val3, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum14_Val4, val); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum14_Val5m, 4141); +#val = enumCheck(cpp11_strongly_typed_enumerations.Class2_Struct1_Enum14_Val6m, val); + +class1 = Class1(); +enumCheck(class1.class1Test1(cpp11_strongly_typed_enumerations.Enum1_Val5a), 13); +enumCheck(class1.class1Test2(cpp11_strongly_typed_enumerations.Class1_Enum12_Val5c), 1121); +#enumCheck(class1.class1Test3(cpp11_strongly_typed_enumerations.Class1_Struct1_Enum12_Val5f), 3121); + +enumCheck(cpp11_strongly_typed_enumerations.globalTest1(cpp11_strongly_typed_enumerations.Enum1_Val5a), 13); +enumCheck(cpp11_strongly_typed_enumerations.globalTest2(cpp11_strongly_typed_enumerations.Class1_Enum12_Val5c), 1121); +#enumCheck(globalTest3(cpp11_strongly_typed_enumerations.Class1_Struct1_Enum12_Val5f), 3121); + diff --git a/Examples/test-suite/octave/director_detect_runme.m b/Examples/test-suite/octave/director_detect_runme.m index f2d8c8dd2..21925712a 100644 --- a/Examples/test-suite/octave/director_detect_runme.m +++ b/Examples/test-suite/octave/director_detect_runme.m @@ -1,7 +1,7 @@ director_detect -global MyBar=@(val=2) \ - subclass(director_detect.Bar(),'val',val,@get_value,@get_class,@just_do_it,@clone); +global MyBar=@(val=2) subclass(director_detect.Bar(),'val',val,@get_value,@get_class,@just_do_it,@clone); + function val=get_value(self) self.val = self.val + 1; val = self.val; diff --git a/Examples/test-suite/octave/li_boost_shared_ptr_runme.m b/Examples/test-suite/octave/li_boost_shared_ptr_runme.m new file mode 100644 index 000000000..a9f4a82c0 --- /dev/null +++ b/Examples/test-suite/octave/li_boost_shared_ptr_runme.m @@ -0,0 +1,566 @@ +1; +li_boost_shared_ptr; + +function verifyValue(expected, got) + if (expected ~= got) + error("verify value failed.");% Expected: ", expected, " Got: ", got) + end +endfunction + +function verifyCount(expected, k) + got = use_count(k); + if (expected ~= got) + error("verify use_count failed. Expected: %d Got: %d ", expected, got); + end +endfunction + +function runtest() + li_boost_shared_ptr; # KTTODO this needs to be here at present. Global module failure? + # simple shared_ptr usage - created in C++ + k = Klass("me oh my"); + val = k.getValue(); + verifyValue("me oh my", val) + verifyCount(1, k) + + # simple shared_ptr usage - not created in C++ + k = factorycreate(); + val = k.getValue(); + verifyValue("factorycreate", val) + verifyCount(1, k) + + # pass by shared_ptr + k = Klass("me oh my"); + kret = smartpointertest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointertest", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr pointer + k = Klass("me oh my"); + kret = smartpointerpointertest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerpointertest", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr reference + k = Klass("me oh my"); + kret = smartpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerreftest", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr pointer reference + k = Klass("me oh my"); + kret = smartpointerpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerpointerreftest", val) + verifyCount(2, k) + verifyCount(2, kret) + + # const pass by shared_ptr + k = Klass("me oh my"); + kret = constsmartpointertest(k); + val = kret.getValue(); + verifyValue("me oh my", val) + verifyCount(2, k) + verifyCount(2, kret) + + # const pass by shared_ptr pointer + k = Klass("me oh my"); + kret = constsmartpointerpointertest(k); + val = kret.getValue(); + verifyValue("me oh my", val) + verifyCount(2, k) + verifyCount(2, kret) + + # const pass by shared_ptr reference + k = Klass("me oh my"); + kret = constsmartpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by value + k = Klass("me oh my"); + kret = valuetest(k); + val = kret.getValue(); + verifyValue("me oh my valuetest", val) + verifyCount(1, k) + verifyCount(1, kret) + + # pass by pointer + k = Klass("me oh my"); + kret = pointertest(k); + val = kret.getValue(); + verifyValue("me oh my pointertest", val) + verifyCount(1, k) + verifyCount(1, kret) + + # pass by reference + k = Klass("me oh my"); + kret = reftest(k); + val = kret.getValue(); + verifyValue("me oh my reftest", val) + verifyCount(1, k) + verifyCount(1, kret) + + # pass by pointer reference + k = Klass("me oh my"); + kret = pointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my pointerreftest", val) + verifyCount(1, k) + verifyCount(1, kret) + + # null tests + #KTODO None not defined + # k = None; + + # if (smartpointertest(k) ~= None) + # error("return was not null") + # end + + # if (smartpointerpointertest(k) ~= None) + # error("return was not null") + # end + + # if (smartpointerreftest(k) ~= None) + # error("return was not null") + # end + + # if (smartpointerpointerreftest(k) ~= None) + # error("return was not null") + # end + + # if (nullsmartpointerpointertest(None) ~= "null pointer") + # error("not null smartpointer pointer") + # end + + # # try: + # # valuetest(k) + # # error("Failed to catch null pointer") + # # except ValueError: + # # pass + + # if (pointertest(k) ~= None) + # error("return was not null") + # end + + # # try: + # # reftest(k) + # # error("Failed to catch null pointer") + # # except ValueError: + # # pass + + # $owner + k = pointerownertest(); + val = k.getValue(); + verifyValue("pointerownertest", val) + verifyCount(1, k) + k = smartpointerpointerownertest(); + val = k.getValue(); + verifyValue("smartpointerpointerownertest", val) + verifyCount(1, k) + + # //////////////////////////////// Derived class //////////////////////////////////////// + # derived pass by shared_ptr + k = KlassDerived("me oh my"); + kret = derivedsmartptrtest(k); + val = kret.getValue(); + verifyValue("me oh my derivedsmartptrtest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # derived pass by shared_ptr pointer + k = KlassDerived("me oh my"); + kret = derivedsmartptrpointertest(k); + val = kret.getValue(); + verifyValue("me oh my derivedsmartptrpointertest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # derived pass by shared_ptr ref + k = KlassDerived("me oh my"); + kret = derivedsmartptrreftest(k); + val = kret.getValue(); + verifyValue("me oh my derivedsmartptrreftest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # derived pass by shared_ptr pointer ref + k = KlassDerived("me oh my"); + kret = derivedsmartptrpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # derived pass by pointer + k = KlassDerived("me oh my"); + kret = derivedpointertest(k); + val = kret.getValue(); + verifyValue("me oh my derivedpointertest-Derived", val) + verifyCount(1, k) + verifyCount(1, kret) + + # derived pass by ref + k = KlassDerived("me oh my"); + kret = derivedreftest(k); + val = kret.getValue(); + verifyValue("me oh my derivedreftest-Derived", val) + verifyCount(1, k) + verifyCount(1, kret) + + # //////////////////////////////// Derived and base class mixed //////////////////////////////////////// + # pass by shared_ptr (mixed) + k = KlassDerived("me oh my"); + kret = smartpointertest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointertest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr pointer (mixed) + k = KlassDerived("me oh my"); + kret = smartpointerpointertest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerpointertest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr reference (mixed) + k = KlassDerived("me oh my"); + kret = smartpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerreftest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by shared_ptr pointer reference (mixed) + k = KlassDerived("me oh my"); + kret = smartpointerpointerreftest(k); + val = kret.getValue(); + verifyValue("me oh my smartpointerpointerreftest-Derived", val) + verifyCount(2, k) + verifyCount(2, kret) + + # pass by value (mixed) + k = KlassDerived("me oh my"); + kret = valuetest(k); + val = kret.getValue(); + verifyValue("me oh my valuetest", val) # note slicing + verifyCount(1, k) + verifyCount(1, kret) + + # pass by pointer (mixed) + k = KlassDerived("me oh my"); + kret = pointertest(k); + val = kret.getValue(); + verifyValue("me oh my pointertest-Derived", val) + verifyCount(1, k) + verifyCount(1, kret) + # pass by ref (mixed) + k = KlassDerived("me oh my"); + kret = reftest(k); + val = kret.getValue(); + verifyValue("me oh my reftest-Derived", val) + verifyCount(1, k) + verifyCount(1, kret) + + # //////////////////////////////// Overloading tests //////////////////////////////////////// + # Base class + k = Klass("me oh my"); + verifyValue(overload_rawbyval(k), "rawbyval") + verifyValue(overload_rawbyref(k), "rawbyref") + verifyValue(overload_rawbyptr(k), "rawbyptr") + verifyValue(overload_rawbyptrref(k), "rawbyptrref") + + verifyValue(overload_smartbyval(k), "smartbyval") + verifyValue(overload_smartbyref(k), "smartbyref") + verifyValue(overload_smartbyptr(k), "smartbyptr") + verifyValue(overload_smartbyptrref(k), "smartbyptrref") + + # Derived class + k = KlassDerived("me oh my"); + verifyValue(overload_rawbyval(k), "rawbyval") + verifyValue(overload_rawbyref(k), "rawbyref") + verifyValue(overload_rawbyptr(k), "rawbyptr") + verifyValue(overload_rawbyptrref(k), "rawbyptrref") + + verifyValue(overload_smartbyval(k), "smartbyval") + verifyValue(overload_smartbyref(k), "smartbyref") + verifyValue(overload_smartbyptr(k), "smartbyptr") + verifyValue(overload_smartbyptrref(k), "smartbyptrref") + + # 3rd derived class + k = Klass3rdDerived("me oh my"); + val = k.getValue(); + verifyValue("me oh my-3rdDerived", val) + verifyCount(1, k) + + val = test3rdupcast(k); + verifyValue("me oh my-3rdDerived", val) + verifyCount(1, k) + + # //////////////////////////////// Member variables //////////////////////////////////////// + # smart pointer by value + m = MemberVariables(); + k = Klass("smart member value"); + m.SmartMemberValue = k; + val = k.getValue(); + verifyValue("smart member value", val) + verifyCount(2, k) + + kmember = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member value", val) + verifyCount(3, kmember) + verifyCount(3, k) + + clear m + verifyCount(2, kmember) + verifyCount(2, k) + + # smart pointer by pointer + m = MemberVariables(); + k = Klass("smart member pointer"); + m.SmartMemberPointer = k; + val = k.getValue(); + verifyValue("smart member pointer", val) + verifyCount(1, k) + + kmember = m.SmartMemberPointer; + val = kmember.getValue(); + verifyValue("smart member pointer", val) + verifyCount(2, kmember) + verifyCount(2, k) + + clear m + verifyCount(2, kmember) + verifyCount(2, k) + + # smart pointer by reference + m = MemberVariables(); + k = Klass("smart member reference"); + m.SmartMemberReference = k; + val = k.getValue(); + verifyValue("smart member reference", val) + verifyCount(2, k) + + kmember = m.SmartMemberReference; + val = kmember.getValue(); + verifyValue("smart member reference", val) + verifyCount(3, kmember) + verifyCount(3, k) + + # The C++ reference refers to SmartMemberValue... + kmemberVal = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member reference", val) + verifyCount(4, kmemberVal) + verifyCount(4, kmember) + verifyCount(4, k) + + clear m + verifyCount(3, kmemberVal) + verifyCount(3, kmember) + verifyCount(3, k) + + # plain by value + m = MemberVariables(); + k = Klass("plain member value"); + m.MemberValue = k; + val = k.getValue(); + verifyValue("plain member value", val) + verifyCount(1, k) + + kmember = m.MemberValue; + val = kmember.getValue(); + verifyValue("plain member value", val) + verifyCount(1, kmember) + verifyCount(1, k) + + clear m + verifyCount(1, kmember) + verifyCount(1, k) + + # plain by pointer + m = MemberVariables(); + k = Klass("plain member pointer"); + m.MemberPointer = k; + val = k.getValue(); + verifyValue("plain member pointer", val) + verifyCount(1, k) + + kmember = m.MemberPointer; + val = kmember.getValue(); + verifyValue("plain member pointer", val) + verifyCount(1, kmember) + verifyCount(1, k) + + clear m + verifyCount(1, kmember) + verifyCount(1, k) + + # plain by reference + m = MemberVariables(); + k = Klass("plain member reference"); + m.MemberReference = k; + val = k.getValue(); + verifyValue("plain member reference", val) + verifyCount(1, k) + + kmember = m.MemberReference; + val = kmember.getValue(); + verifyValue("plain member reference", val) + verifyCount(1, kmember) + verifyCount(1, k) + + clear m + verifyCount(1, kmember) + verifyCount(1, k) + + # null member variables + m = MemberVariables(); + + # shared_ptr by value + k = m.SmartMemberValue; + #KTODO None not defined + # if (k ~= None) + # error("expected null") + # end + + # m.SmartMemberValue = None + # k = m.SmartMemberValue + # if (k ~= None) + # error("expected null") + # end + # verifyCount(0, k) + + # # plain by value + # # try: + # # m.MemberValue = None + # # error("Failed to catch null pointer") + # # except ValueError: + # # pass + + # # ////////////////////////////////// Global variables //////////////////////////////////////// + # # smart pointer + # kglobal = cvar.GlobalSmartValue + # if (kglobal ~= None) + # error("expected null") + # end + + k = Klass("smart global value"); + cvar.GlobalSmartValue = k; + verifyCount(2, k) + + kglobal = cvar.GlobalSmartValue; + val = kglobal.getValue(); + verifyValue("smart global value", val) + verifyCount(3, kglobal) + verifyCount(3, k) + verifyValue("smart global value", cvar.GlobalSmartValue.getValue()) + #KTTODO cvar.GlobalSmartValue = None + + # plain value + k = Klass("global value"); + cvar.GlobalValue = k; + verifyCount(1, k) + + kglobal = cvar.GlobalValue; + val = kglobal.getValue(); + verifyValue("global value", val) + verifyCount(1, kglobal) + verifyCount(1, k) + verifyValue("global value", cvar.GlobalValue.getValue()) + + # try: + # cvar.GlobalValue = None + # error("Failed to catch null pointer") + # except ValueError: + # pass + + # plain pointer + kglobal = cvar.GlobalPointer; + #KTODO if (kglobal ~= None) + #KTODO error("expected null") + #KTODO end + + k = Klass("global pointer"); + cvar.GlobalPointer = k; + verifyCount(1, k) + + kglobal = cvar.GlobalPointer; + val = kglobal.getValue(); + verifyValue("global pointer", val) + verifyCount(1, kglobal) + verifyCount(1, k) + #KTODO cvar.GlobalPointer = None + + # plain reference + kglobal; + k = Klass("global reference"); + cvar.GlobalReference = k; + verifyCount(1, k) + + kglobal = cvar.GlobalReference; + val = kglobal.getValue(); + verifyValue("global reference", val) + verifyCount(1, kglobal) + verifyCount(1, k) + + # try: + # cvar.GlobalReference = None + # error("Failed to catch null pointer") + # except ValueError: + # pass + + # ////////////////////////////////// Templates //////////////////////////////////////// + pid = PairIntDouble(10, 20.2); + if (pid.baseVal1 ~= 20 || pid.baseVal2 ~= 40.4) + error("Base values wrong") + end + if (pid.val1 ~= 10 || pid.val2 ~= 20.2) + error("Derived Values wrong") + end + +endfunction + +debug = false;%true; + + if (debug) + fprintf( "Started\n" ) + end + + cvar.debug_shared = debug; + + # Change loop count to run for a long time to monitor memory + loopCount = 1; #5000 + for i=0:loopCount + runtest() + end + + # Expect 1 instance - the one global variable (GlobalValue) + #KTTODO next fails, possibly because we commented GlobalSmartValue=None + #if (Klass.getTotal_count() ~= 1) + # error("Klass.total_count=%d", Klass.getTotal_count()) + #end + + wrapper_count = shared_ptr_wrapper_count() ; + #KTTODO next fails as NOT_COUNTING not in octave name space, so we hard-wire it here + #if (wrapper_count ~= NOT_COUNTING) + if (wrapper_count ~= -123456) + # Expect 1 instance - the one global variable (GlobalSmartValue) + if (wrapper_count ~= 1) + error("shared_ptr wrapper count=%s", wrapper_count) + end + end + + if (debug) + fprintf( "Finished\n" ) + end diff --git a/Examples/test-suite/overload_polymorphic.i b/Examples/test-suite/overload_polymorphic.i new file mode 100644 index 000000000..a1f123b9d --- /dev/null +++ b/Examples/test-suite/overload_polymorphic.i @@ -0,0 +1,22 @@ +%module overload_polymorphic + +%inline %{ + +class Base { +public: + Base(){} + virtual ~Base(){} +}; + +class Derived : public Base { +public: + Derived(){} + virtual ~Derived(){} +}; + + + +int test(Base* base){ return 0;} +int test(int hello){ return 1; } + +%} diff --git a/Examples/test-suite/perl5/Makefile.in b/Examples/test-suite/perl5/Makefile.in index a4628ddcb..ccd12d6e4 100644 --- a/Examples/test-suite/perl5/Makefile.in +++ b/Examples/test-suite/perl5/Makefile.in @@ -17,6 +17,7 @@ CPP_TEST_CASES += \ li_cstring \ li_cdata_carrays \ li_reference \ + director_nestedmodule \ C_TEST_CASES += \ li_cdata \ diff --git a/Examples/test-suite/perl5/cpp11_strongly_typed_enumerations_runme.pl b/Examples/test-suite/perl5/cpp11_strongly_typed_enumerations_runme.pl new file mode 100644 index 000000000..db19bbfa6 --- /dev/null +++ b/Examples/test-suite/perl5/cpp11_strongly_typed_enumerations_runme.pl @@ -0,0 +1,168 @@ +use strict; +use warnings; +use Test::More tests => 78; +BEGIN { use_ok('cpp11_strongly_typed_enumerations') } +require_ok('cpp11_strongly_typed_enumerations'); + +sub enumCheck { my($actual, $expected) = @_; + is($actual, $expected); + return $expected + 1; +} + +my $val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum1_Val1, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum1_Val2, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum1_Val3, 13); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum1_Val4, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum1_Val5a, 13); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum1_Val6a, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum2_Val1, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum2_Val2, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum2_Val3, 23); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum2_Val4, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum2_Val5b, 23); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum2_Val6b, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Val1, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Val2, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Val3, 43); +$val = enumCheck($cpp11_strongly_typed_enumerations::Val4, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum5_Val1, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum5_Val2, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum5_Val3, 53); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum5_Val4, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum6_Val1, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum6_Val2, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum6_Val3, 63); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum6_Val4, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum7td_Val1, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum7td_Val2, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum7td_Val3, 73); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum7td_Val4, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum8_Val1, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum8_Val2, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum8_Val3, 83); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum8_Val4, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum10_Val1, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum10_Val2, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum10_Val3, 103); +$val = enumCheck($cpp11_strongly_typed_enumerations::Enum10_Val4, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum12_Val1, 1121); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum12_Val2, 1122); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum12_Val3, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum12_Val4, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum12_Val5c, 1121); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum12_Val6c, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Val1, 1131); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Val2, 1132); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Val3, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Val4, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Val5d, 1131); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Val6d, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum14_Val1, 1141); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum14_Val2, 1142); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum14_Val3, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum14_Val4, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum14_Val5e, 1141); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Enum14_Val6e, $val); + +# Requires nested class support to work +#$val = 0; +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum12_Val1, 3121); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum12_Val2, 3122); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum12_Val3, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum12_Val4, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum12_Val5f, 3121); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum12_Val6f, $val); +# +#$val = 0; +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Val1, 3131); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Val2, 3132); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Val3, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Val4, $val); +# +#$val = 0; +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum14_Val1, 3141); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum14_Val2, 3142); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum14_Val3, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum14_Val4, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum14_Val5g, 3141); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum14_Val6g, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum12_Val1, 2121); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum12_Val2, 2122); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum12_Val3, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum12_Val4, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum12_Val5h, 2121); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum12_Val6h, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Val1, 2131); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Val2, 2132); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Val3, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Val4, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Val5i, 2131); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Val6i, $val); + +$val = 0; +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum14_Val1, 2141); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum14_Val2, 2142); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum14_Val3, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum14_Val4, $val); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum14_Val5j, 2141); +$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Enum14_Val6j, $val); + +# Requires nested class support to work +#$val = 0; +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum12_Val1, 4121); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum12_Val2, 4122); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum12_Val3, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum12_Val4, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum12_Val5k, 4121); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum12_Val6k, $val); +# +#$val = 0; +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Val1, 4131); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Val2, 4132); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Val3, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Val4, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Val5l, 4131); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Val6l, $val); +# +#$val = 0; +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum14_Val1, 4141); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum14_Val2, 4142); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum14_Val3, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum14_Val4, $val); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum14_Val5m, 4141); +#$val = enumCheck($cpp11_strongly_typed_enumerations::Class2::Struct1::Enum14_Val6m, $val); + +my $class1 = cpp11_strongly_typed_enumerations::Class1->new(); +enumCheck($class1->class1Test1($cpp11_strongly_typed_enumerations::Enum1_Val5a), 13); +enumCheck($class1->class1Test2($cpp11_strongly_typed_enumerations::Class1::Enum12_Val5c), 1121); +#enumCheck($class1->class1Test3($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum12_Val5f), 3121); + +enumCheck(cpp11_strongly_typed_enumerations::globalTest1($cpp11_strongly_typed_enumerations::Enum1_Val5a), 13); +enumCheck(cpp11_strongly_typed_enumerations::globalTest2($cpp11_strongly_typed_enumerations::Class1::Enum12_Val5c), 1121); +#enumCheck(cpp11_strongly_typed_enumerations::globalTest3($cpp11_strongly_typed_enumerations::Class1::Struct1::Enum12_Val5f), 3121); + diff --git a/Examples/test-suite/php/Makefile.in b/Examples/test-suite/php/Makefile.in index 00ccac325..c3f8af5cb 100644 --- a/Examples/test-suite/php/Makefile.in +++ b/Examples/test-suite/php/Makefile.in @@ -10,6 +10,7 @@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ CPP_TEST_CASES += \ + php_iterator \ php_namewarn_rename \ include $(srcdir)/../common.mk diff --git a/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php b/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php new file mode 100644 index 000000000..bee59b209 --- /dev/null +++ b/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php @@ -0,0 +1,169 @@ +class1Test1(Enum1_Val5a), 13); +enumCheck($class1->class1Test2(Class1::Enum12_Val5c), 1121); +#enumCheck($class1.class1Test3(Class1::Struct1.Enum12_Val5f), 3121); + +enumCheck(globalTest1(Enum1_Val5a), 13); +enumCheck(globalTest2(Class1::Enum12_Val5c), 1121); +#enumCheck(globalTest3(Class1::Struct1.Enum12_Val5f), 3121); + +?> diff --git a/Examples/test-suite/php/director_basic_runme.php b/Examples/test-suite/php/director_basic_runme.php index 1458725f1..de6b50502 100644 --- a/Examples/test-suite/php/director_basic_runme.php +++ b/Examples/test-suite/php/director_basic_runme.php @@ -3,7 +3,6 @@ require "tests.php"; require "director_basic.php"; -/* Removed until runtime error is fixed, see https://github.com/swig/swig/issues/164 // No new functions check::functions(array(foo_ping,foo_pong,foo_get_self,a_f,a_rg,a1_ff,myclass_method,myclass_vmethod,myclass_pmethod,myclass_cmethod,myclass_get_self,myclass_call_pmethod,myclasst_i_method)); // No new classes @@ -54,7 +53,6 @@ $cc->method($b); check::equal($bc->x, 34, "bc failed"); check::equal($bd->x, 16, "bd failed"); -*/ check::done(); ?> diff --git a/Examples/test-suite/php/director_exception_runme.php b/Examples/test-suite/php/director_exception_runme.php index 33e6e9b52..8b852c2ce 100644 --- a/Examples/test-suite/php/director_exception_runme.php +++ b/Examples/test-suite/php/director_exception_runme.php @@ -4,9 +4,9 @@ require "tests.php"; require "director_exception.php"; // No new functions -check::functions(array(foo_ping,foo_pong,launder,bar_ping,bar_pong,bar_pang)); +check::functions(array(foo_ping,foo_pong,launder,bar_ping,bar_pong,bar_pang,returnalltypes_return_int,returnalltypes_return_double,returnalltypes_return_const_char_star,returnalltypes_return_std_string,returnalltypes_return_bar,returnalltypes_call_int,returnalltypes_call_double,returnalltypes_call_const_char_star,returnalltypes_call_std_string,returnalltypes_call_bar,is_python_builtin)); // No new classes -check::classes(array(director_exception,Foo,Exception1,Exception2,Base,Bar)); +check::classes(array(director_exception,Foo,Exception1,Exception2,Base,Bar,ReturnAllTypes)); // now new vars check::globals(array()); @@ -74,5 +74,54 @@ try { } catch (Exception1 $e1) { } +// Check that we can throw exceptions from director methods (this didn't used +// to work in all cases, as the exception gets "set" in PHP and the method +// then returns PHP NULL, which the directorout template may fail to convert. + +class Bad extends ReturnAllTypes { + function return_int() { throw new Exception("bad int"); } + function return_double() { throw new Exception("bad double"); } + function return_const_char_star() { throw new Exception("bad const_char_star"); } + function return_std_string() { throw new Exception("bad std_string"); } + function return_Bar() { throw new Exception("bad Bar"); } +} + +$bad = new Bad(); + +try { + $bad->call_int(); + check::fail("Exception wasn't propagated from Bad::return_int()"); +} catch (Exception $e) { + check::equal($e->getMessage(), "bad int", "propagated exception incorrect"); +} + +try { + $bad->call_double(); + check::fail("Exception wasn't propagated from Bad::return_double()"); +} catch (Exception $e) { + check::equal($e->getMessage(), "bad double", "propagated exception incorrect"); +} + +try { + $bad->call_const_char_star(); + check::fail("Exception wasn't propagated from Bad::return_const_char_star()"); +} catch (Exception $e) { + check::equal($e->getMessage(), "bad const_char_star", "propagated exception incorrect"); +} + +try { + $bad->call_std_string(); + check::fail("Exception wasn't propagated from Bad::return_std_string()"); +} catch (Exception $e) { + check::equal($e->getMessage(), "bad std_string", "propagated exception incorrect"); +} + +try { + $bad->call_Bar(); + check::fail("Exception wasn't propagated from Bad::return_Bar()"); +} catch (Exception $e) { + check::equal($e->getMessage(), "bad Bar", "propagated exception incorrect"); +} + check::done(); ?> diff --git a/Examples/test-suite/php/director_thread_runme.php b/Examples/test-suite/php/director_thread_runme.php index 8df25d969..809dec3e2 100644 --- a/Examples/test-suite/php/director_thread_runme.php +++ b/Examples/test-suite/php/director_thread_runme.php @@ -3,6 +3,9 @@ require "tests.php"; require "director_thread.php"; +# Fails in a ZTS-build of PHP - see: https://github.com/swig/swig/pull/155 +exit(0); + // No new functions check::functions(array(millisecondsleep,foo_stop,foo_run,foo_do_foo)); // No new classes diff --git a/Examples/test-suite/php/exception_order_runme.php b/Examples/test-suite/php/exception_order_runme.php index a83598170..acb83561a 100644 --- a/Examples/test-suite/php/exception_order_runme.php +++ b/Examples/test-suite/php/exception_order_runme.php @@ -2,7 +2,7 @@ require "tests.php"; require "exception_order.php"; -check::functions(array(a_foo,a_bar,a_foobar,a_barfoo)); +check::functions(array(a_foo,a_bar,a_foobar,a_barfoo,is_python_builtin)); check::classes(array(A,E1,E2,E3,exception_order,ET_i,ET_d)); check::globals(array(efoovar,foovar,cfoovar,a_sfoovar,a_foovar,a_efoovar)); diff --git a/Examples/test-suite/php/import_nomodule_runme.php b/Examples/test-suite/php/import_nomodule_runme.php index 84191fba9..41836ba0f 100644 --- a/Examples/test-suite/php/import_nomodule_runme.php +++ b/Examples/test-suite/php/import_nomodule_runme.php @@ -3,7 +3,7 @@ require "tests.php"; require "import_nomodule.php"; // No new functions -check::functions(array(create_foo,delete_foo,test1)); +check::functions(array(create_foo,delete_foo,test1,is_python_builtin)); // No new classes check::classes(array(import_nomodule,Bar)); // now new vars diff --git a/Examples/test-suite/php/php_iterator_runme.php b/Examples/test-suite/php/php_iterator_runme.php new file mode 100644 index 000000000..d69a5b385 --- /dev/null +++ b/Examples/test-suite/php/php_iterator_runme.php @@ -0,0 +1,24 @@ + $v) { + $s .= "($k=>$v)"; +} +check::equal($s, '(0=>2)(1=>3)(2=>4)', 'Simple iteration failed'); + +check::done(); +?> diff --git a/Examples/test-suite/php/threads_exception_runme.php b/Examples/test-suite/php/threads_exception_runme.php index 31148a1e1..9e4d04e10 100644 --- a/Examples/test-suite/php/threads_exception_runme.php +++ b/Examples/test-suite/php/threads_exception_runme.php @@ -4,9 +4,9 @@ require "tests.php"; require "threads_exception.php"; // Check functions -check::functions(array(test_simple,test_message,test_hosed,test_unknown,test_multi)); +check::functions(array(test_simple,test_message,test_hosed,test_unknown,test_multi,is_python_builtin)); // Check classes. -check::classes(array(Exc,Test)); +check::classes(array(Exc,Test,threads_exception)); // Chek globals. check::globals(array(exc_code,exc_msg)); diff --git a/Examples/test-suite/php_iterator.i b/Examples/test-suite/php_iterator.i new file mode 100644 index 000000000..43ab68b55 --- /dev/null +++ b/Examples/test-suite/php_iterator.i @@ -0,0 +1,20 @@ +/* php_iterator.i - PHP-specific testcase for wrapping to a PHP Iterator */ +%module php_iterator + +%typemap("phpinterfaces") MyIterator "Iterator"; + +%inline %{ + +class MyIterator { + int i, from, to; +public: + MyIterator(int from_, int to_) + : i(from_), from(from_), to(to_) { } + void rewind() { i = from; } + bool valid() const { return i != to; } + int key() const { return i - from; } + int current() const { return i; } + void next() { ++i; } +}; + +%} diff --git a/Examples/test-suite/preproc.i b/Examples/test-suite/preproc.i index e052bff28..779c41e97 100644 --- a/Examples/test-suite/preproc.i +++ b/Examples/test-suite/preproc.i @@ -346,3 +346,20 @@ int method(struct TypeNameTraits tnt) { return tnt.val; } %} + +/* Null directive */ +# /* comment 1 */ +# // comment 2 +# /** comment 3 */ +# /* comment 4 */ /*comment 5*/ +# /** comment 6 +# +# more comment 6 */ +# +# +# +int methodX(int x); +%{ +int methodX(int x) { return x+100; } +%} + diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i index 7507d632c..ef5c35e12 100644 --- a/Examples/test-suite/preproc_constants.i +++ b/Examples/test-suite/preproc_constants.i @@ -85,6 +85,8 @@ /// constant assignment in enum #if defined(SWIGCSHARP) %csconstvalue("1<<2") kValue; +#elif defined(SWIGD) +%dconstvalue("1<<2") kValue; #endif %{ diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 9673d7da1..82a0e9db1 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -10,6 +10,8 @@ endif LANGUAGE = python PYTHON = $(PYBIN) +PEP8 = @PEP8@ +PEP8_FLAGS = --ignore=E402,E501,E30,W291,W391 #*_runme.py for Python 2.x, *_runme3.py for Python 3.x PY2SCRIPTSUFFIX = _runme.py @@ -38,7 +40,6 @@ CPP_TEST_CASES += \ inout \ inplaceadd \ input \ - kwargs_feature \ li_cstring \ li_cwstring \ li_factory \ @@ -85,19 +86,6 @@ C_TEST_CASES += \ include $(srcdir)/../common.mk -BUILTIN_BROKEN = \ - default_constructor.cpptest \ - director_exception.cpptest \ - exception_order.cpptest \ - li_std_string_extra.cpptest \ - li_std_wstring.cpptest \ - python_abstractbase.cpptest \ - threads_exception.cpptest - -BUILTIN_NOT_BROKEN = $(filter-out $(BUILTIN_BROKEN),$(NOT_BROKEN_TEST_CASES)) - -builtin-check : $(BUILTIN_NOT_BROKEN) - # Overridden variables here SCRIPTDIR = . LIBS = -L. @@ -111,21 +99,25 @@ VALGRIND_OPT += --suppressions=pythonswig.supp +$(convert_testcase) $(setup) +$(swig_and_compile_cpp) + $(check_pep8) $(run_testcase) %.ctest: +$(convert_testcase) $(setup) +$(swig_and_compile_c) + $(check_pep8) $(run_testcase) %.multicpptest: +$(convert_testcase) $(setup) +$(swig_and_compile_multi_cpp) + $(check_pep8_multi_cpp) $(run_testcase) + # Runs the testcase. A testcase is only run if # a file is found which has _runme.py (or _runme3.py for Python 3) appended after the testcase name. @@ -133,6 +125,18 @@ py_runme = $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) py2_runme = $(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX) py3_runme = $(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX) +check_pep8 = \ + if [ -n "$(PEP8)" ]; then \ + $(PEP8) $(PEP8_FLAGS) $(SCRIPTPREFIX)$*.py;\ + fi + +check_pep8_multi_cpp = \ + if [ -n "$(PEP8)" ]; then \ + for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \ + $(PEP8) $(PEP8_FLAGS) $$f.py; \ + done \ + fi + run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(py_runme) run_testcase = \ diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index 5776ad3ef..756b85904 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -1,15 +1,26 @@ from autodoc import * import sys -def check(got, expected): - if expected != got: - raise RuntimeError("\n" + "Expected: [" + str(expected) + "]\n" + "Got : [" + str(got) + "]") +def check(got, expected, expected_builtin = None, skip = False): + if not skip: + expect = expected + if is_python_builtin() and expected_builtin != None: + expect = expected_builtin + if expect != got: + raise RuntimeError("\n" + "Expected: [" + str(expect) + "]\n" + "Got : [" + str(got) + "]") -check(A.__doc__, "Proxy of C++ A class") +skip = True # skip builtin check - the autodoc is missing, but it probably should not be + +check(A.__doc__, "Proxy of C++ A class", "::A") check(A.funk.__doc__, "just a string") -check(A.func0.__doc__, "func0(self, arg2, hello) -> int") -check(A.func1.__doc__, "func1(A self, short arg2, Tuple hello) -> int") -check(A.func2.__doc__, "\n" +check(A.func0.__doc__, +"func0(self, arg2, hello) -> int", +"func0(arg2, hello) -> int") +check(A.func1.__doc__, +"func1(A self, short arg2, Tuple hello) -> int", +"func1(short arg2, Tuple hello) -> int") +check(A.func2.__doc__, +"\n" " func2(self, arg2, hello) -> int\n" "\n" " Parameters:\n" @@ -17,8 +28,18 @@ check(A.func2.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func2(arg2, hello) -> int\n" +"\n" +"Parameters:\n" +" arg2: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func3.__doc__, "\n" +check(A.func3.__doc__, +"\n" " func3(A self, short arg2, Tuple hello) -> int\n" "\n" " Parameters:\n" @@ -26,19 +47,41 @@ check(A.func3.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func3(short arg2, Tuple hello) -> int\n" +"\n" +"Parameters:\n" +" arg2: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func0default.__doc__, "\n" +check(A.func0default.__doc__, +"\n" " func0default(self, e, arg3, hello, f=2) -> int\n" " func0default(self, e, arg3, hello) -> int\n" " " +, +"\n" +"func0default(e, arg3, hello, f=2) -> int\n" +"func0default(e, arg3, hello) -> int\n" +"" ) -check(A.func1default.__doc__, "\n" +check(A.func1default.__doc__, +"\n" " func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" " func1default(A self, A e, short arg3, Tuple hello) -> int\n" " " +, +"\n" +"func1default(A e, short arg3, Tuple hello, double f=2) -> int\n" +"func1default(A e, short arg3, Tuple hello) -> int\n" +"" ) -check(A.func2default.__doc__, "\n" +check(A.func2default.__doc__, +"\n" " func2default(self, e, arg3, hello, f=2) -> int\n" "\n" " Parameters:\n" @@ -55,8 +98,27 @@ check(A.func2default.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func2default(e, arg3, hello, f=2) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +" f: double\n" +"\n" +"func2default(e, arg3, hello) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func3default.__doc__, "\n" +check(A.func3default.__doc__, +"\n" " func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" "\n" " Parameters:\n" @@ -73,19 +135,50 @@ check(A.func3default.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func3default(A e, short arg3, Tuple hello, double f=2) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +" f: double\n" +"\n" +"func3default(A e, short arg3, Tuple hello) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func0static.__doc__, "\n" +check(A.func0static.__doc__, +"\n" " func0static(e, arg2, hello, f=2) -> int\n" " func0static(e, arg2, hello) -> int\n" " " +, +"\n" +"func0static(e, arg2, hello, f=2) -> int\n" +"func0static(e, arg2, hello) -> int\n" +"" ) -check(A.func1static.__doc__, "\n" +check(A.func1static.__doc__, +"\n" " func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" " func1static(A e, short arg2, Tuple hello) -> int\n" " " +, +"\n" +"func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" +"func1static(A e, short arg2, Tuple hello) -> int\n" +"" ) -check(A.func2static.__doc__, "\n" +check(A.func2static.__doc__, +"\n" " func2static(e, arg2, hello, f=2) -> int\n" "\n" " Parameters:\n" @@ -102,8 +195,27 @@ check(A.func2static.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func2static(e, arg2, hello, f=2) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg2: short\n" +" hello: int tuple[2]\n" +" f: double\n" +"\n" +"func2static(e, arg2, hello) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg2: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func3static.__doc__, "\n" +check(A.func3static.__doc__, +"\n" " func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" "\n" " Parameters:\n" @@ -120,31 +232,65 @@ check(A.func3static.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg2: short\n" +" hello: int tuple[2]\n" +" f: double\n" +"\n" +"func3static(A e, short arg2, Tuple hello) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg2: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) if sys.version_info[0:2] > (2, 4): # Python 2.4 does not seem to work - check(A.variable_a.__doc__, "A_variable_a_get(self) -> int") - check(A.variable_b.__doc__, "A_variable_b_get(A self) -> int") - check(A.variable_c.__doc__, "\n" + check(A.variable_a.__doc__, + "A_variable_a_get(self) -> int", + "A.variable_a" + ) + check(A.variable_b.__doc__, + "A_variable_b_get(A self) -> int", + "A.variable_b" + ) + check(A.variable_c.__doc__, + "\n" "A_variable_c_get(self) -> int\n" "\n" "Parameters:\n" " self: A *\n" "\n" + , + "A.variable_c" ) - check(A.variable_d.__doc__, "\n" + check(A.variable_d.__doc__, + "\n" "A_variable_d_get(A self) -> int\n" "\n" "Parameters:\n" " self: A *\n" "\n" + , + "A.variable_d" ) -check(B.__doc__, "Proxy of C++ B class") -check(C.__init__.__doc__, "__init__(self, a, b, h) -> C") -check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D") -check(E.__init__.__doc__, "\n" +check(B.__doc__, +"Proxy of C++ B class", +"::B" +) +check(C.__init__.__doc__, "__init__(self, a, b, h) -> C", None, skip) +check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D", None, skip) +check(E.__init__.__doc__, +"\n" " __init__(self, a, b, h) -> E\n" "\n" " Parameters:\n" @@ -153,8 +299,10 @@ check(E.__init__.__doc__, "\n" " h: enum Hola\n" "\n" " " +, None, skip ) -check(F.__init__.__doc__, "\n" +check(F.__init__.__doc__, +"\n" " __init__(F self, int a, int b, Hola h) -> F\n" "\n" " Parameters:\n" @@ -163,14 +311,23 @@ check(F.__init__.__doc__, "\n" " h: enum Hola\n" "\n" " " +, None, skip ) -check(B.funk.__doc__, "funk(B self, int c, int d) -> int") +check(B.funk.__doc__, +"funk(B self, int c, int d) -> int", +"funk(int c, int d) -> int") check(funk.__doc__, "funk(A e, short arg2, int c, int d) -> int") -check(funkdefaults.__doc__, "\n" +check(funkdefaults.__doc__, +"\n" " funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" " funkdefaults(A e, short arg2, int c, int d) -> int\n" " " +, +"\n" +"funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" +"funkdefaults(A e, short arg2, int c, int d) -> int\n" +"" ) check(func_input.__doc__, "func_input(int * INPUT) -> int") diff --git a/Examples/test-suite/python/constant_directive_runme.py b/Examples/test-suite/python/constant_directive_runme.py new file mode 100644 index 000000000..48f85ce8a --- /dev/null +++ b/Examples/test-suite/python/constant_directive_runme.py @@ -0,0 +1,15 @@ +import constant_directive + +if not isinstance(constant_directive.TYPE1_CONSTANT1,constant_directive.Type1): + raise RuntimeError("Failure: TYPE1_CONSTANT1 type: {}".format(type(constant_directive.TYPE1_CONSTANT1))) +if not isinstance(constant_directive.getType1Instance(),constant_directive.Type1): + raise RuntimeError("Failure: getType1Instance() type: {}".format(type(constant_directive.getType1Instance()))) + +if constant_directive.TYPE1_CONSTANT1.val != 1: + raise RuntimeError("constant_directive.TYPE1_CONSTANT1.val is %r (should be 1)" % constant_directive.TYPE1_CONSTANT1.val) + +if constant_directive.TYPE1_CONSTANT2.val != 2: + raise RuntimeError("constant_directive.TYPE1_CONSTANT2.val is %r (should be 2)" % constant_directive.TYPE1_CONSTANT2.val) + +if constant_directive.TYPE1_CONSTANT3.val != 3: + raise RuntimeError("constant_directive.TYPE1_CONSTANT3.val is %r (should be 3)" % constant_directive.TYPE1_CONSTANT3.val) diff --git a/Examples/test-suite/python/cpp11_function_objects_runme.py b/Examples/test-suite/python/cpp11_function_objects_runme.py index aac7f9c5f..5a63b632b 100644 --- a/Examples/test-suite/python/cpp11_function_objects_runme.py +++ b/Examples/test-suite/python/cpp11_function_objects_runme.py @@ -1,6 +1,13 @@ import cpp11_function_objects import sys +class Test1(cpp11_function_objects.Test): + def __init__(self): + cpp11_function_objects.Test.__init__(self) + + def __call__(self, a, b): + self.value = a * b + t = cpp11_function_objects.Test() if t.value != 0: raise RuntimeError("Runtime cpp11_function_objects failed. t.value should be 0, but is " + str(t.value)) @@ -10,3 +17,7 @@ t(1,2) # adds numbers and sets value if t.value != 3: raise RuntimeError("Runtime cpp11_function_objects failed. t.value not changed - should be 3, but is " + str(t.value)) +t2 = Test1() +a = cpp11_function_objects.testit1(t2, 4,3) +if a != 12: + raise RuntimeError("Runtime cpp11_function_objects failed. t.value not changed - should be 12, but is " + str(a)) diff --git a/Examples/test-suite/python/cpp11_strongly_typed_enumerations_runme.py b/Examples/test-suite/python/cpp11_strongly_typed_enumerations_runme.py new file mode 100644 index 000000000..6509ba873 --- /dev/null +++ b/Examples/test-suite/python/cpp11_strongly_typed_enumerations_runme.py @@ -0,0 +1,164 @@ +from cpp11_strongly_typed_enumerations import * + +def enumCheck(actual, expected): + if actual != expected: + raise RuntimeError("Enum value mismatch. Expected " + str(expected) + " Actual: " + str(actual)) + return expected + 1 + +val = 0 +val = enumCheck(Enum1_Val1, val) +val = enumCheck(Enum1_Val2, val) +val = enumCheck(Enum1_Val3, 13) +val = enumCheck(Enum1_Val4, val) +val = enumCheck(Enum1_Val5a, 13) +val = enumCheck(Enum1_Val6a, val) + +val = 0 +val = enumCheck(Enum2_Val1, val) +val = enumCheck(Enum2_Val2, val) +val = enumCheck(Enum2_Val3, 23) +val = enumCheck(Enum2_Val4, val) +val = enumCheck(Enum2_Val5b, 23) +val = enumCheck(Enum2_Val6b, val) + +val = 0 +val = enumCheck(Val1, val) +val = enumCheck(Val2, val) +val = enumCheck(Val3, 43) +val = enumCheck(Val4, val) + +val = 0 +val = enumCheck(Enum5_Val1, val) +val = enumCheck(Enum5_Val2, val) +val = enumCheck(Enum5_Val3, 53) +val = enumCheck(Enum5_Val4, val) + +val = 0 +val = enumCheck(Enum6_Val1, val) +val = enumCheck(Enum6_Val2, val) +val = enumCheck(Enum6_Val3, 63) +val = enumCheck(Enum6_Val4, val) + +val = 0 +val = enumCheck(Enum7td_Val1, val) +val = enumCheck(Enum7td_Val2, val) +val = enumCheck(Enum7td_Val3, 73) +val = enumCheck(Enum7td_Val4, val) + +val = 0 +val = enumCheck(Enum8_Val1, val) +val = enumCheck(Enum8_Val2, val) +val = enumCheck(Enum8_Val3, 83) +val = enumCheck(Enum8_Val4, val) + +val = 0 +val = enumCheck(Enum10_Val1, val) +val = enumCheck(Enum10_Val2, val) +val = enumCheck(Enum10_Val3, 103) +val = enumCheck(Enum10_Val4, val) + +val = 0 +val = enumCheck(Class1.Enum12_Val1, 1121) +val = enumCheck(Class1.Enum12_Val2, 1122) +val = enumCheck(Class1.Enum12_Val3, val) +val = enumCheck(Class1.Enum12_Val4, val) +val = enumCheck(Class1.Enum12_Val5c, 1121) +val = enumCheck(Class1.Enum12_Val6c, val) + +val = 0 +val = enumCheck(Class1.Val1, 1131) +val = enumCheck(Class1.Val2, 1132) +val = enumCheck(Class1.Val3, val) +val = enumCheck(Class1.Val4, val) +val = enumCheck(Class1.Val5d, 1131) +val = enumCheck(Class1.Val6d, val) + +val = 0 +val = enumCheck(Class1.Enum14_Val1, 1141) +val = enumCheck(Class1.Enum14_Val2, 1142) +val = enumCheck(Class1.Enum14_Val3, val) +val = enumCheck(Class1.Enum14_Val4, val) +val = enumCheck(Class1.Enum14_Val5e, 1141) +val = enumCheck(Class1.Enum14_Val6e, val) + +# Requires nested class support to work +#val = 0 +#val = enumCheck(Class1.Struct1.Enum12_Val1, 3121) +#val = enumCheck(Class1.Struct1.Enum12_Val2, 3122) +#val = enumCheck(Class1.Struct1.Enum12_Val3, val) +#val = enumCheck(Class1.Struct1.Enum12_Val4, val) +#val = enumCheck(Class1.Struct1.Enum12_Val5f, 3121) +#val = enumCheck(Class1.Struct1.Enum12_Val6f, val) +# +#val = 0 +#val = enumCheck(Class1.Struct1.Val1, 3131) +#val = enumCheck(Class1.Struct1.Val2, 3132) +#val = enumCheck(Class1.Struct1.Val3, val) +#val = enumCheck(Class1.Struct1.Val4, val) +# +#val = 0 +#val = enumCheck(Class1.Struct1.Enum14_Val1, 3141) +#val = enumCheck(Class1.Struct1.Enum14_Val2, 3142) +#val = enumCheck(Class1.Struct1.Enum14_Val3, val) +#val = enumCheck(Class1.Struct1.Enum14_Val4, val) +#val = enumCheck(Class1.Struct1.Enum14_Val5g, 3141) +#val = enumCheck(Class1.Struct1.Enum14_Val6g, val) + +val = 0 +val = enumCheck(Class2.Enum12_Val1, 2121) +val = enumCheck(Class2.Enum12_Val2, 2122) +val = enumCheck(Class2.Enum12_Val3, val) +val = enumCheck(Class2.Enum12_Val4, val) +val = enumCheck(Class2.Enum12_Val5h, 2121) +val = enumCheck(Class2.Enum12_Val6h, val) + +val = 0 +val = enumCheck(Class2.Val1, 2131) +val = enumCheck(Class2.Val2, 2132) +val = enumCheck(Class2.Val3, val) +val = enumCheck(Class2.Val4, val) +val = enumCheck(Class2.Val5i, 2131) +val = enumCheck(Class2.Val6i, val) + +val = 0 +val = enumCheck(Class2.Enum14_Val1, 2141) +val = enumCheck(Class2.Enum14_Val2, 2142) +val = enumCheck(Class2.Enum14_Val3, val) +val = enumCheck(Class2.Enum14_Val4, val) +val = enumCheck(Class2.Enum14_Val5j, 2141) +val = enumCheck(Class2.Enum14_Val6j, val) + +# Requires nested class support to work +#val = 0 +#val = enumCheck(Class2.Struct1.Enum12_Val1, 4121) +#val = enumCheck(Class2.Struct1.Enum12_Val2, 4122) +#val = enumCheck(Class2.Struct1.Enum12_Val3, val) +#val = enumCheck(Class2.Struct1.Enum12_Val4, val) +#val = enumCheck(Class2.Struct1.Enum12_Val5k, 4121) +#val = enumCheck(Class2.Struct1.Enum12_Val6k, val) +# +#val = 0 +#val = enumCheck(Class2.Struct1.Val1, 4131) +#val = enumCheck(Class2.Struct1.Val2, 4132) +#val = enumCheck(Class2.Struct1.Val3, val) +#val = enumCheck(Class2.Struct1.Val4, val) +#val = enumCheck(Class2.Struct1.Val5l, 4131) +#val = enumCheck(Class2.Struct1.Val6l, val) +# +#val = 0 +#val = enumCheck(Class2.Struct1.Enum14_Val1, 4141) +#val = enumCheck(Class2.Struct1.Enum14_Val2, 4142) +#val = enumCheck(Class2.Struct1.Enum14_Val3, val) +#val = enumCheck(Class2.Struct1.Enum14_Val4, val) +#val = enumCheck(Class2.Struct1.Enum14_Val5m, 4141) +#val = enumCheck(Class2.Struct1.Enum14_Val6m, val) + +class1 = Class1() +enumCheck(class1.class1Test1(Enum1_Val5a), 13) +enumCheck(class1.class1Test2(Class1.Enum12_Val5c), 1121) +#enumCheck(class1.class1Test3(Class1.Struct1.Enum12_Val5f), 3121) + +enumCheck(globalTest1(Enum1_Val5a), 13) +enumCheck(globalTest2(Class1.Enum12_Val5c), 1121) +#enumCheck(globalTest3(Class1.Struct1.Enum12_Val5f), 3121) + diff --git a/Examples/test-suite/python/default_args_runme.py b/Examples/test-suite/python/default_args_runme.py index 091a92376..f24e825ad 100644 --- a/Examples/test-suite/python/default_args_runme.py +++ b/Examples/test-suite/python/default_args_runme.py @@ -1,64 +1,90 @@ -import default_args +# Note that this test is also used by python_default_args_runme.py hence the use of __main__ and the run function + +def run(module_name): + default_args = __import__(module_name) + ec = default_args.EnumClass() + if not ec.blah(): + raise RuntimeError("EnumClass::blah() default arguments don't work") + + de = default_args.DerivedEnumClass() + de.accelerate() + de.accelerate(default_args.EnumClass.SLOW) + + if default_args.Statics_staticMethod() != 60: + raise RuntimeError + + if default_args.cfunc1(1) != 2: + raise RuntimeError + + if default_args.cfunc2(1) != 3: + raise RuntimeError + + if default_args.cfunc3(1) != 4: + raise RuntimeError -if default_args.Statics_staticMethod() != 60: - raise RuntimeError - -if default_args.cfunc1(1) != 2: - raise RuntimeError + f = default_args.Foo() -if default_args.cfunc2(1) != 3: - raise RuntimeError - -if default_args.cfunc3(1) != 4: - raise RuntimeError + f.newname() + f.newname(1) -f = default_args.Foo() + try: + f = default_args.Foo(1) + error = 1 + except: + error = 0 + if error: raise RuntimeError("Foo::Foo ignore is not working") -f.newname() -f.newname(1) + try: + f = default_args.Foo(1,2) + error = 1 + except: + error = 0 + if error: raise RuntimeError("Foo::Foo ignore is not working") + try: + f = default_args.Foo(1,2,3) + error = 1 + except: + error = 0 + if error: raise RuntimeError("Foo::Foo ignore is not working") -try: - f = default_args.Foo(1) - error = 1 -except: - error = 0 -if error: raise RuntimeError,"Foo::Foo ignore is not working" + try: + m = f.meth(1) + error = 1 + except: + error = 0 + if error: raise RuntimeError("Foo::meth ignore is not working") -try: - f = default_args.Foo(1,2) - error = 1 -except: - error = 0 -if error: raise RuntimeError,"Foo::Foo ignore is not working" + try: + m = f.meth(1,2) + error = 1 + except: + error = 0 + if error: raise RuntimeError("Foo::meth ignore is not working") -try: - f = default_args.Foo(1,2,3) - error = 1 -except: - error = 0 -if error: raise RuntimeError,"Foo::Foo ignore is not working" + try: + m = f.meth(1,2,3) + error = 1 + except: + error = 0 + if error: raise RuntimeError("Foo::meth ignore is not working") -try: - m = f.meth(1) - error = 1 -except: - error = 0 -if error: raise RuntimeError,"Foo::meth ignore is not working" + if default_args.Klass.inc(100, default_args.Klass(22)).val != 122: + raise RuntimeError("Klass::inc failed") -try: - m = f.meth(1,2) - error = 1 -except: - error = 0 -if error: raise RuntimeError,"Foo::meth ignore is not working" + if default_args.Klass.inc(100).val != 99: + raise RuntimeError("Klass::inc failed") -try: - m = f.meth(1,2,3) - error = 1 -except: - error = 0 -if error: raise RuntimeError,"Foo::meth ignore is not working" + if default_args.Klass.inc().val != 0: + raise RuntimeError("Klass::inc failed") + + default_args.trickyvalue1(10); default_args.trickyvalue1(10, 10) + default_args.trickyvalue2(10); default_args.trickyvalue2(10, 10) + default_args.trickyvalue3(10); default_args.trickyvalue3(10, 10) + default_args.seek(); default_args.seek(10) + +if __name__=="__main__": + run('default_args') diff --git a/Examples/test-suite/python/default_constructor_runme.py b/Examples/test-suite/python/default_constructor_runme.py index 59b130559..e6532031b 100644 --- a/Examples/test-suite/python/default_constructor_runme.py +++ b/Examples/test-suite/python/default_constructor_runme.py @@ -1,8 +1,10 @@ +import _default_constructor + # This test is expected to fail with -builtin option. # It uses the old static syntax (e.g., dc.new_A() rather than dc.A()), # which is not provided with the -builtin option. - -import _default_constructor +if _default_constructor.is_python_builtin(): + exit(0) dc = _default_constructor diff --git a/Examples/test-suite/python/director_exception_runme.py b/Examples/test-suite/python/director_exception_runme.py index 510845a5a..de3ef22a5 100644 --- a/Examples/test-suite/python/director_exception_runme.py +++ b/Examples/test-suite/python/director_exception_runme.py @@ -68,14 +68,13 @@ if not ok: # This is expected to fail with -builtin option # Throwing builtin classes as exceptions not supported -try: - raise Exception2() -except Exception2: - pass +if not is_python_builtin(): + try: + raise Exception2() + except Exception2: + pass -# This is expected to fail with -builtin option -# Throwing builtin classes as exceptions not supported -try: - raise Exception1() -except Exception1: - pass + try: + raise Exception1() + except Exception1: + pass diff --git a/Examples/test-suite/python/director_keywords_runme.py b/Examples/test-suite/python/director_keywords_runme.py new file mode 100644 index 000000000..03a50206a --- /dev/null +++ b/Examples/test-suite/python/director_keywords_runme.py @@ -0,0 +1,5 @@ +from director_keywords import * + +f = Foo() +f.check_self(20) + diff --git a/Examples/test-suite/python/director_property_runme.py b/Examples/test-suite/python/director_property_runme.py new file mode 100644 index 000000000..303e53b67 --- /dev/null +++ b/Examples/test-suite/python/director_property_runme.py @@ -0,0 +1,18 @@ +import director_property + +class PyFoo(director_property.Foo): + a = property(director_property.Foo.getA, director_property.Foo.setA) + + def ping(self): + return "PyFoo::ping()" + + +foo = PyFoo() + +foo.setA("BLABLA") +if foo.getA() != "BLABLA": + raise RuntimeError + +foo.a = "BIBI" +if foo.a != "BIBI": + raise RuntimeError diff --git a/Examples/test-suite/python/exception_order_runme.py b/Examples/test-suite/python/exception_order_runme.py index 38b53eb0c..8f095eb98 100644 --- a/Examples/test-suite/python/exception_order_runme.py +++ b/Examples/test-suite/python/exception_order_runme.py @@ -2,6 +2,8 @@ from exception_order import * # This test is expected to fail with -builtin option. # Throwing builtin classes as exceptions not supported +if is_python_builtin(): + exit(0) a = A() diff --git a/Examples/test-suite/python/import_nomodule_runme.py b/Examples/test-suite/python/import_nomodule_runme.py index ba0abfd9a..efcff9c48 100644 --- a/Examples/test-suite/python/import_nomodule_runme.py +++ b/Examples/test-suite/python/import_nomodule_runme.py @@ -1,5 +1,10 @@ from import_nomodule import * +# This test is expected to fail with -builtin option. +# The base class is needed for the builtin class hierarchy +if is_python_builtin(): + exit(0) + f = create_Foo() test1(f,42) delete_Foo(f) diff --git a/Examples/test-suite/python/kwargs_feature_runme.py b/Examples/test-suite/python/kwargs_feature_runme.py index 5539e211d..37457c976 100644 --- a/Examples/test-suite/python/kwargs_feature_runme.py +++ b/Examples/test-suite/python/kwargs_feature_runme.py @@ -44,14 +44,14 @@ if BarInt_sbar(b=2) != 3: if templatedfunction(b=2) != 3: raise RuntimeError -if foo(a=1,b=2) != 3: +if foo_fn(a=1,b=2) != 3: raise RuntimeError -if foo(b=2) != 3: +if foo_fn(b=2) != 3: raise RuntimeError -#Funtions with keywords +#Functions with keywords if foo_kw(_from=2) != 4: raise RuntimeError @@ -65,3 +65,17 @@ if foo_mm(min=2) != 4: if foo_mm(max=3) != 4: raise RuntimeError +#Default args with references + +if rfoo(n=123) != 120: + raise RuntimeError + +if rfoo(x=10) != -10: + raise RuntimeError + +if rfoo(n=11, x=22) != -11: + raise RuntimeError + +if rfoo(x=11, n=22) != 11: + raise RuntimeError + diff --git a/Examples/test-suite/python/li_std_except_as_class_runme.py b/Examples/test-suite/python/li_std_except_as_class_runme.py index 386a878bf..a86e7a562 100644 --- a/Examples/test-suite/python/li_std_except_as_class_runme.py +++ b/Examples/test-suite/python/li_std_except_as_class_runme.py @@ -1,9 +1,19 @@ from li_std_except_as_class import * -# std::domain_error hierarchy -try: test_domain_error() -except domain_error: pass -try: test_domain_error() -except logic_error: pass -try: test_domain_error() -except exception: pass +# This test is expected to fail with -builtin option. +# Throwing builtin classes as exceptions not supported +if is_python_builtin(): + try: test_domain_error() + except RuntimeError: pass + try: test_domain_error() + except RuntimeError: pass + try: test_domain_error() + except RuntimeError: pass +else: + # std::domain_error hierarchy + try: test_domain_error() + except domain_error: pass + try: test_domain_error() + except logic_error: pass + try: test_domain_error() + except exception: pass diff --git a/Examples/test-suite/python/li_std_string_extra_runme.py b/Examples/test-suite/python/li_std_string_extra_runme.py index 9e9e3d2c3..503d09eb5 100644 --- a/Examples/test-suite/python/li_std_string_extra_runme.py +++ b/Examples/test-suite/python/li_std_string_extra_runme.py @@ -56,14 +56,13 @@ if a + " world" != "hello world": # This is expected to fail with -builtin option # Reverse operators not supported in builtin types -if "hello" + b != "hello world": - raise RuntimeError, "bad string mapping" +if not li_std_string_extra.is_python_builtin(): + if "hello" + b != "hello world": + raise RuntimeError, "bad string mapping" -# This is expected to fail with -builtin option -# Reverse operators not supported in builtin types -c = "hello" + b -if c.find_last_of("l") != 9: - raise RuntimeError, "bad string mapping" + c = "hello" + b + if c.find_last_of("l") != 9: + raise RuntimeError, "bad string mapping" s = "hello world" diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py index fecc527e0..a467ae8bc 100644 --- a/Examples/test-suite/python/li_std_wstring_runme.py +++ b/Examples/test-suite/python/li_std_wstring_runme.py @@ -60,13 +60,14 @@ if a + " world" != "hello world": raise RuntimeError("bad string mapping") # This is expected to fail if -builtin is used -if "hello" + b != "hello world": - raise RuntimeError("bad string mapping") +# Reverse operators not supported in builtin types +if not li_std_wstring.is_python_builtin(): + if "hello" + b != "hello world": + raise RuntimeError("bad string mapping") -# This is expected to fail if -builtin is used -c = "hello" + b -if c.find_last_of("l") != 9: - raise RuntimeError("bad string mapping") + c = "hello" + b + if c.find_last_of("l") != 9: + raise RuntimeError("bad string mapping") s = "hello world" diff --git a/Examples/test-suite/python/nested_template_base_runme.py b/Examples/test-suite/python/nested_template_base_runme.py new file mode 100644 index 000000000..3d54b8391 --- /dev/null +++ b/Examples/test-suite/python/nested_template_base_runme.py @@ -0,0 +1,13 @@ +from nested_template_base import * + + +ois = InnerS(123); +oic = InnerC(); + +# Check base method is available +if (oic.outer(ois).val != 123): + raise RuntimeError("Wrong value calling outer"); + +# Check non-derived class using base class +if (oic.innerc().outer(ois).val != 123): + raise RuntimeError("Wrong value calling innerc"); diff --git a/Examples/test-suite/python/preproc_runme.py b/Examples/test-suite/python/preproc_runme.py index c989294b6..3049f00ab 100644 --- a/Examples/test-suite/python/preproc_runme.py +++ b/Examples/test-suite/python/preproc_runme.py @@ -12,3 +12,5 @@ if preproc.defined != 1: if 2*preproc.one != preproc.two: raise RuntimeError +if preproc.methodX(99) != 199: + raise RuntimeError diff --git a/Examples/test-suite/python/python_abstractbase_runme3.py b/Examples/test-suite/python/python_abstractbase_runme3.py index 94dee3ff7..9b189964d 100644 --- a/Examples/test-suite/python/python_abstractbase_runme3.py +++ b/Examples/test-suite/python/python_abstractbase_runme3.py @@ -3,6 +3,8 @@ from collections import * # This is expected to fail with -builtin option # Builtin types can't inherit from pure-python abstract bases +if is_python_builtin(): + exit(0) assert issubclass(Mapii, MutableMapping) assert issubclass(Multimapii, MutableMapping) diff --git a/Examples/test-suite/python/python_append_runme.py b/Examples/test-suite/python/python_append_runme.py index 41cebad58..54d7a3e00 100644 --- a/Examples/test-suite/python/python_append_runme.py +++ b/Examples/test-suite/python/python_append_runme.py @@ -1,11 +1,16 @@ from python_append import * + +# test not relevant for -builtin +if is_python_builtin(): + exit(0) + t=Test() t.func() t.static_func() if grabpath() != os.path.dirname(mypath): - raise RuntimeError + raise RuntimeError("grabpath failed") if grabstaticpath() != os.path.basename(mypath): - raise RuntimeError + raise RuntimeError("grabstaticpath failed") diff --git a/Examples/test-suite/python/python_threads_runme.py b/Examples/test-suite/python/python_threads_runme.py new file mode 100644 index 000000000..d00e2458f --- /dev/null +++ b/Examples/test-suite/python/python_threads_runme.py @@ -0,0 +1,10 @@ +from python_threads import * + +action = ActionGroup() +count = 1 +for child in action.GetActionList(): + if child.val != count: + raise RuntimeError("Expected: " + str(count) + " got: " + str(child.val)) + count = count + 1 + +# Was seg faulting at the end here diff --git a/Examples/test-suite/python/smart_pointer_const_overload_runme.py b/Examples/test-suite/python/smart_pointer_const_overload_runme.py index f1be315a5..098e5b4c3 100644 --- a/Examples/test-suite/python/smart_pointer_const_overload_runme.py +++ b/Examples/test-suite/python/smart_pointer_const_overload_runme.py @@ -56,7 +56,7 @@ def test(b, f): raise RuntimeError # Test static method - b.stat() + b.statMethod() if f.access != CONST_ACCESS: raise RuntimeError diff --git a/Examples/test-suite/python/threads_exception_runme.py b/Examples/test-suite/python/threads_exception_runme.py index d4b8855fc..6fe6947ec 100644 --- a/Examples/test-suite/python/threads_exception_runme.py +++ b/Examples/test-suite/python/threads_exception_runme.py @@ -20,15 +20,16 @@ except RuntimeError,e: # This is expected fail with -builtin option # Throwing builtin classes as exceptions not supported -try: - t.hosed() -except threads_exception.Exc,e: - code = e.code - if code != 42: - raise RuntimeError, "bad... code: %d" % code - msg = e.msg - if msg != "Hosed": - raise RuntimeError, "bad... msg: '%s' len: %d" % (msg, len(msg)) +if not threads_exception.is_python_builtin(): + try: + t.hosed() + except threads_exception.Exc,e: + code = e.code + if code != 42: + raise RuntimeError, "bad... code: %d" % code + msg = e.msg + if msg != "Hosed": + raise RuntimeError, "bad... msg: '%s' len: %d" % (msg, len(msg)) for i in range(1,4): try: diff --git a/Examples/test-suite/python_abstractbase.i b/Examples/test-suite/python_abstractbase.i index f72688237..65f3d9931 100644 --- a/Examples/test-suite/python_abstractbase.i +++ b/Examples/test-suite/python_abstractbase.i @@ -16,3 +16,11 @@ namespace std %template(IntVector) vector; %template(IntList) list; } + +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/test-suite/python_append.i b/Examples/test-suite/python_append.i index e263c392b..f37a6c199 100644 --- a/Examples/test-suite/python_append.i +++ b/Examples/test-suite/python_append.i @@ -5,22 +5,22 @@ Testcase to test %pythonprepend and %pythonappend %pythoncode %pythonbegin %module python_append %pythoncode %{ - mypath = os.path.dirname("/a/b/c/d.txt") - funcpath = None - staticfuncpath = None - def grabpath(): +mypath = os.path.dirname("/a/b/c/d.txt") +funcpath = None +staticfuncpath = None +def grabpath(): return funcpath - def grabstaticpath(): +def grabstaticpath(): return staticfuncpath %} %pythonappend Test::func %{ - funcpath = os.path.dirname(funcpath) +funcpath = os.path.dirname(funcpath) %} %pythonprepend Test::func %{ - global funcpath - funcpath = mypath +global funcpath +funcpath = mypath %} %pythonappend Test::static_func %{ @@ -29,9 +29,9 @@ pass %} %pythonprepend Test::static_func { - global staticfuncpath - staticfuncpath = mypath - pass +global staticfuncpath +staticfuncpath = mypath +pass } %pythonbegin %{ @@ -46,5 +46,10 @@ public: void func() {}; }; +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif %} diff --git a/Examples/test-suite/python_nondynamic.i b/Examples/test-suite/python_nondynamic.i index 26c69644d..54a3f28ca 100644 --- a/Examples/test-suite/python_nondynamic.i +++ b/Examples/test-suite/python_nondynamic.i @@ -1,7 +1,7 @@ %module python_nondynamic /* - Use the %pythonnondynamic directuve to make the wrapped class a + Use the %pythonnondynamic directive to make the wrapped class a nondynamic one, ie, a python class that doesn't dynamically add new attributes. Hence, for the class diff --git a/Examples/test-suite/python_threads.i b/Examples/test-suite/python_threads.i new file mode 100644 index 000000000..08eddef11 --- /dev/null +++ b/Examples/test-suite/python_threads.i @@ -0,0 +1,40 @@ +%module(threads=1) python_threads + +%include + +%inline %{ +struct Action { + int val; + Action(int val = 0) : val(val) {} +}; +%} + +%template(VectorActionPtr) std::vector; + +%inline %{ +#include +#include +template struct myStlVector : public std::vector { +}; +typedef myStlVector ActionList; + +%} + +%template(ActionList) myStlVector; + +%inline %{ +class ActionGroup +{ +public: + ActionList &GetActionList () const { + static ActionList list; + list.push_back(new Action(1)); + list.push_back(new Action(2)); + list.push_back(new Action(3)); + list.push_back(new Action(4)); + return list; + } +}; +%} + + diff --git a/Examples/test-suite/r_overload_array.i b/Examples/test-suite/r_overload_array.i index 1474661c4..aa714dfdb 100644 --- a/Examples/test-suite/r_overload_array.i +++ b/Examples/test-suite/r_overload_array.i @@ -1,7 +1,8 @@ %module r_overload_array -%include "stl.i" -# this tests the situation in which there is a scalar function -# corresponding with a vector one + +%include +// this tests the situation in which there is a scalar function +// corresponding with a vector one %inline %{ class Foo { diff --git a/Examples/test-suite/ruby/Makefile.in b/Examples/test-suite/ruby/Makefile.in index 1a6875360..ae4995882 100644 --- a/Examples/test-suite/ruby/Makefile.in +++ b/Examples/test-suite/ruby/Makefile.in @@ -11,7 +11,6 @@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ CPP_TEST_CASES = \ - kwargs_feature \ li_cdata \ li_cstring \ li_factory \ diff --git a/Examples/test-suite/ruby/cpp11_strongly_typed_enumerations_runme.rb b/Examples/test-suite/ruby/cpp11_strongly_typed_enumerations_runme.rb new file mode 100644 index 000000000..897a44281 --- /dev/null +++ b/Examples/test-suite/ruby/cpp11_strongly_typed_enumerations_runme.rb @@ -0,0 +1,177 @@ +#!/usr/bin/env ruby +# +# Put description here +# +# +# +# +# + +require 'swig_assert' + +require 'cpp11_strongly_typed_enumerations' + +include Cpp11_strongly_typed_enumerations + +def enumCheck(actual, expected) + raise RuntimeError,"Enum value mismatch. Expected #{expected} Actual: #{actual}" if actual != expected + return expected + 1 +end + +val = 0 +val = enumCheck(Enum1_Val1, val) +val = enumCheck(Enum1_Val2, val) +val = enumCheck(Enum1_Val3, 13) +val = enumCheck(Enum1_Val4, val) +val = enumCheck(Enum1_Val5a, 13) +val = enumCheck(Enum1_Val6a, val) + +val = 0 +val = enumCheck(Enum2_Val1, val) +val = enumCheck(Enum2_Val2, val) +val = enumCheck(Enum2_Val3, 23) +val = enumCheck(Enum2_Val4, val) +val = enumCheck(Enum2_Val5b, 23) +val = enumCheck(Enum2_Val6b, val) + +val = 0 +val = enumCheck(Val1, val) +val = enumCheck(Val2, val) +val = enumCheck(Val3, 43) +val = enumCheck(Val4, val) + +val = 0 +val = enumCheck(Enum5_Val1, val) +val = enumCheck(Enum5_Val2, val) +val = enumCheck(Enum5_Val3, 53) +val = enumCheck(Enum5_Val4, val) + +val = 0 +val = enumCheck(Enum6_Val1, val) +val = enumCheck(Enum6_Val2, val) +val = enumCheck(Enum6_Val3, 63) +val = enumCheck(Enum6_Val4, val) + +val = 0 +val = enumCheck(Enum7td_Val1, val) +val = enumCheck(Enum7td_Val2, val) +val = enumCheck(Enum7td_Val3, 73) +val = enumCheck(Enum7td_Val4, val) + +val = 0 +val = enumCheck(Enum8_Val1, val) +val = enumCheck(Enum8_Val2, val) +val = enumCheck(Enum8_Val3, 83) +val = enumCheck(Enum8_Val4, val) + +val = 0 +val = enumCheck(Enum10_Val1, val) +val = enumCheck(Enum10_Val2, val) +val = enumCheck(Enum10_Val3, 103) +val = enumCheck(Enum10_Val4, val) + +val = 0 +val = enumCheck(Class1::Enum12_Val1, 1121) +val = enumCheck(Class1::Enum12_Val2, 1122) +val = enumCheck(Class1::Enum12_Val3, val) +val = enumCheck(Class1::Enum12_Val4, val) +val = enumCheck(Class1::Enum12_Val5c, 1121) +val = enumCheck(Class1::Enum12_Val6c, val) + +val = 0 +val = enumCheck(Class1::Val1, 1131) +val = enumCheck(Class1::Val2, 1132) +val = enumCheck(Class1::Val3, val) +val = enumCheck(Class1::Val4, val) +val = enumCheck(Class1::Val5d, 1131) +val = enumCheck(Class1::Val6d, val) + +val = 0 +val = enumCheck(Class1::Enum14_Val1, 1141) +val = enumCheck(Class1::Enum14_Val2, 1142) +val = enumCheck(Class1::Enum14_Val3, val) +val = enumCheck(Class1::Enum14_Val4, val) +val = enumCheck(Class1::Enum14_Val5e, 1141) +val = enumCheck(Class1::Enum14_Val6e, val) + +# Requires nested class support to work +#val = 0 +#val = enumCheck(Class1::Struct1.Enum12_Val1, 3121) +#val = enumCheck(Class1::Struct1.Enum12_Val2, 3122) +#val = enumCheck(Class1::Struct1.Enum12_Val3, val) +#val = enumCheck(Class1::Struct1.Enum12_Val4, val) +#val = enumCheck(Class1::Struct1.Enum12_Val5f, 3121) +#val = enumCheck(Class1::Struct1.Enum12_Val6f, val) +# +#val = 0 +#val = enumCheck(Class1::Struct1.Val1, 3131) +#val = enumCheck(Class1::Struct1.Val2, 3132) +#val = enumCheck(Class1::Struct1.Val3, val) +#val = enumCheck(Class1::Struct1.Val4, val) +# +#val = 0 +#val = enumCheck(Class1::Struct1.Enum14_Val1, 3141) +#val = enumCheck(Class1::Struct1.Enum14_Val2, 3142) +#val = enumCheck(Class1::Struct1.Enum14_Val3, val) +#val = enumCheck(Class1::Struct1.Enum14_Val4, val) +#val = enumCheck(Class1::Struct1.Enum14_Val5g, 3141) +#val = enumCheck(Class1::Struct1.Enum14_Val6g, val) + +val = 0 +val = enumCheck(Class2::Enum12_Val1, 2121) +val = enumCheck(Class2::Enum12_Val2, 2122) +val = enumCheck(Class2::Enum12_Val3, val) +val = enumCheck(Class2::Enum12_Val4, val) +val = enumCheck(Class2::Enum12_Val5h, 2121) +val = enumCheck(Class2::Enum12_Val6h, val) + +val = 0 +val = enumCheck(Class2::Val1, 2131) +val = enumCheck(Class2::Val2, 2132) +val = enumCheck(Class2::Val3, val) +val = enumCheck(Class2::Val4, val) +val = enumCheck(Class2::Val5i, 2131) +val = enumCheck(Class2::Val6i, val) + +val = 0 +val = enumCheck(Class2::Enum14_Val1, 2141) +val = enumCheck(Class2::Enum14_Val2, 2142) +val = enumCheck(Class2::Enum14_Val3, val) +val = enumCheck(Class2::Enum14_Val4, val) +val = enumCheck(Class2::Enum14_Val5j, 2141) +val = enumCheck(Class2::Enum14_Val6j, val) + +# Requires nested class support to work +#val = 0 +#val = enumCheck(Class2::Struct1.Enum12_Val1, 4121) +#val = enumCheck(Class2::Struct1.Enum12_Val2, 4122) +#val = enumCheck(Class2::Struct1.Enum12_Val3, val) +#val = enumCheck(Class2::Struct1.Enum12_Val4, val) +#val = enumCheck(Class2::Struct1.Enum12_Val5k, 4121) +#val = enumCheck(Class2::Struct1.Enum12_Val6k, val) +# +#val = 0 +#val = enumCheck(Class2::Struct1.Val1, 4131) +#val = enumCheck(Class2::Struct1.Val2, 4132) +#val = enumCheck(Class2::Struct1.Val3, val) +#val = enumCheck(Class2::Struct1.Val4, val) +#val = enumCheck(Class2::Struct1.Val5l, 4131) +#val = enumCheck(Class2::Struct1.Val6l, val) +# +#val = 0 +#val = enumCheck(Class2::Struct1.Enum14_Val1, 4141) +#val = enumCheck(Class2::Struct1.Enum14_Val2, 4142) +#val = enumCheck(Class2::Struct1.Enum14_Val3, val) +#val = enumCheck(Class2::Struct1.Enum14_Val4, val) +#val = enumCheck(Class2::Struct1.Enum14_Val5m, 4141) +#val = enumCheck(Class2::Struct1.Enum14_Val6m, val) + +class1 = Class1.new +enumCheck(class1.class1Test1(Enum1_Val5a), 13) +enumCheck(class1.class1Test2(Class1::Enum12_Val5c), 1121) +#enumCheck(class1.class1Test3(Class1::Struct1.Enum12_Val5f), 3121) + +enumCheck(globalTest1(Enum1_Val5a), 13) +enumCheck(globalTest2(Class1::Enum12_Val5c), 1121) +#enumCheck(globalTest3(Class1::Struct1.Enum12_Val5f), 3121) + diff --git a/Examples/test-suite/smart_pointer_const_overload.i b/Examples/test-suite/smart_pointer_const_overload.i index e3b000b52..75a137b73 100644 --- a/Examples/test-suite/smart_pointer_const_overload.i +++ b/Examples/test-suite/smart_pointer_const_overload.i @@ -34,7 +34,7 @@ struct Foo { Foo() : x(0), xp(&x), y(0), yp(&y), access(0) { } int getx() const { return x; } void setx(int x_) { x = x_; } - static void stat() {} + static void statMethod() {} }; %} diff --git a/Examples/test-suite/tcl/cpp11_strongly_typed_enumerations_runme.tcl b/Examples/test-suite/tcl/cpp11_strongly_typed_enumerations_runme.tcl new file mode 100644 index 000000000..5132101ad --- /dev/null +++ b/Examples/test-suite/tcl/cpp11_strongly_typed_enumerations_runme.tcl @@ -0,0 +1,172 @@ + +if [ catch { load ./cpp11_strongly_typed_enumerations[info sharedlibextension] cpp11_strongly_typed_enumerations} err_msg ] { + puts stderr "Could not load shared object:\n$err_msg" +} + +proc enumCheck {actual expected} { + if {$actual != $expected} { + error "Enum value mismatch. Expected $expected. Actual: $actual" + } + return [expr $expected + 1] +} + +#set val 0 +#set val [enumCheck $Enum1_Val1 $val] +#set val [enumCheck $Enum1_Val2 $val] + +set val 0 +set val [enumCheck $Enum1_Val1 $val] +set val [enumCheck $Enum1_Val2 $val] +set val [enumCheck $Enum1_Val3 13] +set val [enumCheck $Enum1_Val4 $val] +set val [enumCheck $Enum1_Val5a 13] +set val [enumCheck $Enum1_Val6a $val] + +set val 0 +set val [enumCheck $Enum2_Val1 $val] +set val [enumCheck $Enum2_Val2 $val] +set val [enumCheck $Enum2_Val3 23] +set val [enumCheck $Enum2_Val4 $val] +set val [enumCheck $Enum2_Val5b 23] +set val [enumCheck $Enum2_Val6b $val] + +set val 0 +set val [enumCheck $Val1 $val] +set val [enumCheck $Val2 $val] +set val [enumCheck $Val3 43] +set val [enumCheck $Val4 $val] + +set val 0 +set val [enumCheck $Enum5_Val1 $val] +set val [enumCheck $Enum5_Val2 $val] +set val [enumCheck $Enum5_Val3 53] +set val [enumCheck $Enum5_Val4 $val] + +set val 0 +set val [enumCheck $Enum6_Val1 $val] +set val [enumCheck $Enum6_Val2 $val] +set val [enumCheck $Enum6_Val3 63] +set val [enumCheck $Enum6_Val4 $val] + +set val 0 +set val [enumCheck $Enum7td_Val1 $val] +set val [enumCheck $Enum7td_Val2 $val] +set val [enumCheck $Enum7td_Val3 73] +set val [enumCheck $Enum7td_Val4 $val] + +set val 0 +set val [enumCheck $Enum8_Val1 $val] +set val [enumCheck $Enum8_Val2 $val] +set val [enumCheck $Enum8_Val3 83] +set val [enumCheck $Enum8_Val4 $val] + +set val 0 +set val [enumCheck $Enum10_Val1 $val] +set val [enumCheck $Enum10_Val2 $val] +set val [enumCheck $Enum10_Val3 103] +set val [enumCheck $Enum10_Val4 $val] + +set val 0 +set val [enumCheck $Class1_Enum12_Val1 1121] +set val [enumCheck $Class1_Enum12_Val2 1122] +set val [enumCheck $Class1_Enum12_Val3 $val] +set val [enumCheck $Class1_Enum12_Val4 $val] +set val [enumCheck $Class1_Enum12_Val5c 1121] +set val [enumCheck $Class1_Enum12_Val6c $val] + +set val 0 +set val [enumCheck $Class1_Val1 1131] +set val [enumCheck $Class1_Val2 1132] +set val [enumCheck $Class1_Val3 $val] +set val [enumCheck $Class1_Val4 $val] +set val [enumCheck $Class1_Val5d 1131] +set val [enumCheck $Class1_Val6d $val] + +set val 0 +set val [enumCheck $Class1_Enum14_Val1 1141] +set val [enumCheck $Class1_Enum14_Val2 1142] +set val [enumCheck $Class1_Enum14_Val3 $val] +set val [enumCheck $Class1_Enum14_Val4 $val] +set val [enumCheck $Class1_Enum14_Val5e 1141] +set val [enumCheck $Class1_Enum14_Val6e $val] + +# Requires nested class support to work +#set val 0 +#set val [enumCheck $Class1_Struct1_Enum12_Val1 3121] +#set val [enumCheck $Class1_Struct1_Enum12_Val2 3122] +#set val [enumCheck $Class1_Struct1_Enum12_Val3 $val] +#set val [enumCheck $Class1_Struct1_Enum12_Val4 $val] +#set val [enumCheck $Class1_Struct1_Enum12_Val5f 3121] +#set val [enumCheck $Class1_Struct1_Enum12_Val6f $val] +# +#set val 0 +#set val [enumCheck $Class1_Struct1_Val1 3131] +#set val [enumCheck $Class1_Struct1_Val2 3132] +#set val [enumCheck $Class1_Struct1_Val3 $val] +#set val [enumCheck $Class1_Struct1_Val4 $val] +# +#set val 0 +#set val [enumCheck $Class1_Struct1_Enum14_Val1 3141] +#set val [enumCheck $Class1_Struct1_Enum14_Val2 3142] +#set val [enumCheck $Class1_Struct1_Enum14_Val3 $val] +#set val [enumCheck $Class1_Struct1_Enum14_Val4 $val] +#set val [enumCheck $Class1_Struct1_Enum14_Val5g 3141] +#set val [enumCheck $Class1_Struct1_Enum14_Val6g $val] + +set val 0 +set val [enumCheck $Class2_Enum12_Val1 2121] +set val [enumCheck $Class2_Enum12_Val2 2122] +set val [enumCheck $Class2_Enum12_Val3 $val] +set val [enumCheck $Class2_Enum12_Val4 $val] +set val [enumCheck $Class2_Enum12_Val5h 2121] +set val [enumCheck $Class2_Enum12_Val6h $val] + +set val 0 +set val [enumCheck $Class2_Val1 2131] +set val [enumCheck $Class2_Val2 2132] +set val [enumCheck $Class2_Val3 $val] +set val [enumCheck $Class2_Val4 $val] +set val [enumCheck $Class2_Val5i 2131] +set val [enumCheck $Class2_Val6i $val] + +set val 0 +set val [enumCheck $Class2_Enum14_Val1 2141] +set val [enumCheck $Class2_Enum14_Val2 2142] +set val [enumCheck $Class2_Enum14_Val3 $val] +set val [enumCheck $Class2_Enum14_Val4 $val] +set val [enumCheck $Class2_Enum14_Val5j 2141] +set val [enumCheck $Class2_Enum14_Val6j $val] + +# Requires nested class support to work +#set val 0 +#set val [enumCheck $Class2_Struct1_Enum12_Val1 4121] +#set val [enumCheck $Class2_Struct1_Enum12_Val2 4122] +#set val [enumCheck $Class2_Struct1_Enum12_Val3 $val] +#set val [enumCheck $Class2_Struct1_Enum12_Val4 $val] +#set val [enumCheck $Class2_Struct1_Enum12_Val5k 4121] +#set val [enumCheck $Class2_Struct1_Enum12_Val6k $val] +# +#set val 0 +#set val [enumCheck $Class2_Struct1_Val1 4131] +#set val [enumCheck $Class2_Struct1_Val2 4132] +#set val [enumCheck $Class2_Struct1_Val3 $val] +#set val [enumCheck $Class2_Struct1_Val4 $val] +#set val [enumCheck $Class2_Struct1_Val5l 4131] +#set val [enumCheck $Class2_Struct1_Val6l $val] +# +#set val 0 +#set val [enumCheck $Class2_Struct1_Enum14_Val1 4141] +#set val [enumCheck $Class2_Struct1_Enum14_Val2 4142] +#set val [enumCheck $Class2_Struct1_Enum14_Val3 $val] +#set val [enumCheck $Class2_Struct1_Enum14_Val4 $val] +#set val [enumCheck $Class2_Struct1_Enum14_Val5m 4141] +#set val [enumCheck $Class2_Struct1_Enum14_Val6m $val] + +set class1 [Class1] +enumCheck [$class1 class1Test1 $Enum1_Val5a] 13 +enumCheck [$class1 class1Test2 $Class1_Enum12_Val5c] 1121 +#enumCheck [$class1 class1Test3 $Class1_Struct1_Enum12_Val5f] 3121 + +enumCheck [globalTest1 $Enum1_Val5a] 13 +enumCheck [globalTest2 $Class1_Enum12_Val5c] 1121 +#enumCheck [globalTest3 $Class1_Struct1_Enum12_Val5f] 3121 diff --git a/Examples/test-suite/template_default_class_parms.i b/Examples/test-suite/template_default_class_parms.i index cd37269d3..e5a8c9d49 100644 --- a/Examples/test-suite/template_default_class_parms.i +++ b/Examples/test-suite/template_default_class_parms.i @@ -31,3 +31,49 @@ namespace Space { %template(FooAnotherType) Space::Foo; %template() Space::ATemplate<>; + + +// Github issue #280 segfault +%inline %{ +namespace Teuchos { + class Describable {}; +} +namespace KokkosClassic { + namespace DefaultNode { + struct DefaultNodeType {}; + }; +} + +namespace Tpetra { + template + class Map : public Teuchos::Describable { + public: + typedef LocalOrdinal local_ordinal_type; + typedef GlobalOrdinal global_ordinal_type; + typedef Node node_type; + void test_func(LocalOrdinal, GlobalOrdinal, Node) {} + }; +} +%} + +#ifdef SWIGJAVA +// Fixes still required for other languages +%template(MapDefaults) Tpetra::Map<>; +#endif + +%inline %{ +namespace Details { + template < class LO = ::Tpetra::Map<>::local_ordinal_type, + class GO = typename ::Tpetra::Map::global_ordinal_type, + class NT = typename ::Tpetra::Map::node_type > + class Transfer : public Teuchos::Describable { + public: + void transfer_func(LO, GO, NT) {} + }; +} +%} + +// Below is not resolving correctly yet +//%template(TransferDefaults) Details::Transfer<>; diff --git a/Examples/test-suite/template_templated_constructors.i b/Examples/test-suite/template_templated_constructors.i new file mode 100644 index 000000000..ee9df94bb --- /dev/null +++ b/Examples/test-suite/template_templated_constructors.i @@ -0,0 +1,47 @@ +%module template_templated_constructors + +%inline %{ +namespace ConstructSpace { + +class TConstructor1 { +public: + template TConstructor1(T val) {} + ~TConstructor1() {} +}; + +class TConstructor2 { +public: + TConstructor2() {} + template TConstructor2(T val) {} + ~TConstructor2() {} +}; + +template class TClass1 { +public: + template TClass1(Y t) {} +}; + +template class TClass2 { +public: + TClass2() {} + template TClass2(Y t) {} +}; + +} +%} + +%extend ConstructSpace::TConstructor1 { + %template(TConstructor1) TConstructor1; +} + +%template(TConstructor2) ConstructSpace::TConstructor2::TConstructor2; + +%template(TClass1Int) ConstructSpace::TClass1; +%extend ConstructSpace::TClass1 { + %template(TClass1Int) TClass1; +} + +%template(TClass2Int) ConstructSpace::TClass2; +%extend ConstructSpace::TClass2 { + %template(TClass2Int) TClass2; +} diff --git a/Examples/test-suite/template_typedef_typedef.i b/Examples/test-suite/template_typedef_typedef.i index 30077c484..ac96b2db8 100644 --- a/Examples/test-suite/template_typedef_typedef.i +++ b/Examples/test-suite/template_typedef_typedef.i @@ -1,7 +1,7 @@ %module template_typedef_typedef // Github issue #50 -// The Object2::getBlabla2 and Object::getBlabla1 functions were not resolving to the correct template types +// The Object2::getBlabla2 and Object1::getBlabla1 functions were not resolving to the correct template types %inline%{ @@ -20,7 +20,7 @@ namespace TT{ }; }; template - class Object:public T { + class Object1:public T { public: void getBlabla1(typename T::ABCD::CC1 c) { }; @@ -29,7 +29,7 @@ namespace TT{ class Factory { public: - typedef TT::Object CC1; + typedef TT::Object1 CC1; typedef TT::Object2 CC2; void getBlabla4(CC2 c) { }; @@ -38,6 +38,6 @@ class Factory { }; %} -%template(ObjectBase) TT::Object; +%template(Object1Base) TT::Object1; %template(Object2Base) TT::Object2; diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i index b374f0ce6..caa79c78e 100644 --- a/Examples/test-suite/threads_exception.i +++ b/Examples/test-suite/threads_exception.i @@ -52,4 +52,10 @@ public: return 1; } }; + +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif %} diff --git a/Examples/test-suite/throw_exception.i b/Examples/test-suite/throw_exception.i index d03e49cba..480925513 100644 --- a/Examples/test-suite/throw_exception.i +++ b/Examples/test-suite/throw_exception.i @@ -22,15 +22,15 @@ %inline %{ -class Error { +class CError { }; -void test_is_Error(Error *r) {} +void test_is_Error(CError *r) {} namespace Namespace { - typedef Error ErrorTypedef; - typedef const Error& ErrorRef; - typedef const Error* ErrorPtr; + typedef CError ErrorTypedef; + typedef const CError& ErrorRef; + typedef const CError* ErrorPtr; typedef int IntArray[10]; enum EnumTest { enum1, enum2 }; } @@ -42,26 +42,26 @@ public: void test_msg() throw(const char *) { throw "Dead"; } - void test_cls() throw(Error) { - throw Error(); + void test_cls() throw(CError) { + throw CError(); } - void test_cls_ptr() throw(Error *) { - static Error StaticError; + void test_cls_ptr() throw(CError *) { + static CError StaticError; throw &StaticError; } - void test_cls_ref() throw(Error &) { - static Error StaticError; + void test_cls_ref() throw(CError &) { + static CError StaticError; throw StaticError; } void test_cls_td() throw(Namespace::ErrorTypedef) { - throw Error(); + throw CError(); } void test_cls_ptr_td() throw(Namespace::ErrorPtr) { - static Error StaticError; + static CError StaticError; throw &StaticError; } void test_cls_ref_td() throw(Namespace::ErrorRef) { - static Error StaticError; + static CError StaticError; throw StaticError; } void test_array() throw(Namespace::IntArray) { @@ -74,10 +74,10 @@ public: void test_enum() throw(Namespace::EnumTest) { throw Namespace::enum2; } - void test_multi(int x) throw(int, const char *, Error) { + void test_multi(int x) throw(int, const char *, CError) { if (x == 1) throw 37; if (x == 2) throw "Dead"; - if (x == 3) throw Error(); + if (x == 3) throw CError(); } }; diff --git a/Examples/test-suite/typemap_directorout.i b/Examples/test-suite/typemap_directorout.i index 4a85bd47c..79d0f8d94 100644 --- a/Examples/test-suite/typemap_directorout.i +++ b/Examples/test-suite/typemap_directorout.i @@ -23,7 +23,7 @@ #ifdef SWIGD %typemap(ddirectorout) MyType & %{ WILL_NOT_COMPILE %} %typemap(ddirectorout) MyType &USEME = SWIGTYPE &; -%typemap(ddirectorout) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $typemap(ddirectorout, MyType &USEME) /* special end */ %} +%typemap(ddirectorout, nativepointer="cast(void*)$dcall") MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $typemap(ddirectorout, MyType &USEME) /* special end */ %} #endif #ifdef SWIGJAVA diff --git a/Examples/test-suite/typemap_variables.i b/Examples/test-suite/typemap_variables.i index 421fc61c0..b1ae24fdf 100644 --- a/Examples/test-suite/typemap_variables.i +++ b/Examples/test-suite/typemap_variables.i @@ -16,7 +16,7 @@ // For Javascript V8 we can not use '0' for out typemaps #if defined(SWIG_JAVASCRIPT_V8) %header %{ -#define OUT_NULL_VALUE v8::Null() +#define OUT_NULL_VALUE SWIGV8_NULL() %} #else %header %{ diff --git a/Lib/carrays.i b/Lib/carrays.i index f125105aa..201c17cac 100644 --- a/Lib/carrays.i +++ b/Lib/carrays.i @@ -22,7 +22,7 @@ %{ static TYPE *new_##NAME(int nelements) { %} #ifdef __cplusplus -%{ return new TYPE[nelements]; %} +%{ return new TYPE[nelements](); %} #else %{ return (TYPE *) calloc(nelements,sizeof(TYPE)); %} #endif diff --git a/Lib/csharp/arrays_csharp.i b/Lib/csharp/arrays_csharp.i index 174a2823e..237067a88 100644 --- a/Lib/csharp/arrays_csharp.i +++ b/Lib/csharp/arrays_csharp.i @@ -103,6 +103,7 @@ CSHARP_ARRAYS(long long, long) CSHARP_ARRAYS(unsigned long long, ulong) CSHARP_ARRAYS(float, float) CSHARP_ARRAYS(double, double) +CSHARP_ARRAYS(bool, bool) %define CSHARP_ARRAYS_FIXED( CTYPE, CSTYPE ) @@ -134,4 +135,5 @@ CSHARP_ARRAYS_FIXED(long long, long) CSHARP_ARRAYS_FIXED(unsigned long long, ulong) CSHARP_ARRAYS_FIXED(float, float) CSHARP_ARRAYS_FIXED(double, double) +CSHARP_ARRAYS_FIXED(bool, bool) diff --git a/Lib/csharp/enums.swg b/Lib/csharp/enums.swg index 9b4acefc0..5cc265476 100644 --- a/Lib/csharp/enums.swg +++ b/Lib/csharp/enums.swg @@ -18,7 +18,7 @@ %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE & %{ static $*1_ltype temp = ($*1_ltype)$input; $result = &temp; %} -%typemap(directorin) const enum SWIGTYPE & "$input = $1;" +%typemap(directorin) const enum SWIGTYPE & "$input = (int)$1;" %typemap(csdirectorin) const enum SWIGTYPE & "($*csclassname)$iminput" %typemap(csdirectorout) const enum SWIGTYPE & "(int)$cscall" @@ -51,7 +51,7 @@ %typemap(out) enum SWIGTYPE %{ $result = (int)$1; %} %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} -%typemap(directorin) enum SWIGTYPE "$input = $1;" +%typemap(directorin) enum SWIGTYPE "$input = (int)$1;" %typemap(csdirectorin) enum SWIGTYPE "($csclassname)$iminput" %typemap(csdirectorout) enum SWIGTYPE "(int)$cscall" diff --git a/Lib/csharp/enumsimple.swg b/Lib/csharp/enumsimple.swg index 484443652..24e4bcf18 100644 --- a/Lib/csharp/enumsimple.swg +++ b/Lib/csharp/enumsimple.swg @@ -20,7 +20,7 @@ %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE & %{ static $*1_ltype temp = ($*1_ltype)$input; $result = &temp; %} -%typemap(directorin) const enum SWIGTYPE & "$input = $1;" +%typemap(directorin) const enum SWIGTYPE & "$input = (int)$1;" %typemap(csdirectorin) const enum SWIGTYPE & "$iminput" %typemap(csdirectorout) const enum SWIGTYPE & "$cscall" @@ -53,7 +53,7 @@ %typemap(out) enum SWIGTYPE %{ $result = (int)$1; %} %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} -%typemap(directorin) enum SWIGTYPE "$input = $1;" +%typemap(directorin) enum SWIGTYPE "$input = (int)$1;" %typemap(csdirectorin) enum SWIGTYPE "$iminput" %typemap(csdirectorout) enum SWIGTYPE "$cscall" diff --git a/Lib/csharp/enumtypesafe.swg b/Lib/csharp/enumtypesafe.swg index b7079343c..fd6801730 100644 --- a/Lib/csharp/enumtypesafe.swg +++ b/Lib/csharp/enumtypesafe.swg @@ -19,7 +19,7 @@ %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE & %{ static $*1_ltype temp = ($*1_ltype)$input; $result = &temp; %} -%typemap(directorin) const enum SWIGTYPE & "$input = $1;" +%typemap(directorin) const enum SWIGTYPE & "$input = (int)$1;" %typemap(csdirectorin) const enum SWIGTYPE & "$*csclassname.swigToEnum($iminput)" %typemap(csdirectorout) const enum SWIGTYPE & "$cscall.swigValue" @@ -52,7 +52,7 @@ %typemap(out) enum SWIGTYPE %{ $result = (int)$1; %} %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} -%typemap(directorin) enum SWIGTYPE "$input = $1;" +%typemap(directorin) enum SWIGTYPE "$input = (int)$1;" %typemap(csdirectorin) enum SWIGTYPE "$csclassname.swigToEnum($iminput)" %typemap(csdirectorout) enum SWIGTYPE "$cscall.swigValue" diff --git a/Lib/d/boost_shared_ptr.i b/Lib/d/boost_shared_ptr.i index bfa2aa646..5c171555e 100644 --- a/Lib/d/boost_shared_ptr.i +++ b/Lib/d/boost_shared_ptr.i @@ -152,7 +152,7 @@ public this(void* cObject, bool ownCObject) { swigCMemOwn = ownCObject; } -public static void* swigGetCPtr($dclassname obj) { +public static void* swigGetCPtr(typeof(this) obj) { return (obj is null) ? null : obj.swigCPtr; } %} @@ -167,7 +167,7 @@ public this(void* cObject, bool ownCObject) { swigCMemOwn = ownCObject; } -public static void* swigGetCPtr($dclassname obj) { +public static void* swigGetCPtr(typeof(this) obj) { return (obj is null) ? null : obj.swigCPtr; } %} diff --git a/Lib/d/dclassgen.swg b/Lib/d/dclassgen.swg index ceaf50727..68910b412 100644 --- a/Lib/d/dclassgen.swg +++ b/Lib/d/dclassgen.swg @@ -72,7 +72,7 @@ public this(void* cObject, bool ownCObject) { swigCMemOwn = ownCObject; } -public static void* swigGetCPtr($dclassname obj) { +public static void* swigGetCPtr(typeof(this) obj) { return (obj is null) ? null : obj.swigCPtr; } @@ -88,7 +88,7 @@ public this(void* cObject, bool ownCObject) { swigCPtr = cObject; } -public static void* swigGetCPtr($dclassname obj) { +public static void* swigGetCPtr(typeof(this) obj) { return (obj is null) ? null : obj.swigCPtr; } @@ -111,7 +111,7 @@ protected this() { swigCPtr = null; } -public static void* swigGetCPtr($dclassname obj) { +public static void* swigGetCPtr(typeof(this) obj) { return (obj is null) ? null : obj.swigCPtr; } @@ -134,7 +134,7 @@ protected this() { swigCPtr = null; } -package static char* swigGetCMemberPtr($dclassname obj) { +package static char* swigGetCMemberPtr(typeof(this) obj) { return (obj is null) ? null : obj.swigCPtr; } diff --git a/Lib/d/denums.swg b/Lib/d/denums.swg index 5917da90d..3f8124662 100644 --- a/Lib/d/denums.swg +++ b/Lib/d/denums.swg @@ -16,10 +16,10 @@ %typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE "" %typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %} -%typemap(out) enum SWIGTYPE %{ $result = $1; %} +%typemap(out) enum SWIGTYPE %{ $result = (int)$1; %} %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} -%typemap(directorin) enum SWIGTYPE "$input = $1;" +%typemap(directorin) enum SWIGTYPE "$input = (int)$1;" %typemap(ddirectorin) enum SWIGTYPE "cast($dclassname)$winput" %typemap(ddirectorout) enum SWIGTYPE "cast(int)$dcall" @@ -43,9 +43,9 @@ %typemap(in) const enum SWIGTYPE & ($*1_ltype temp) %{ temp = ($*1_ltype)$input; $1 = &temp; %} -%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %} +%typemap(out) const enum SWIGTYPE & %{ $result = (int)*$1; %} -%typemap(directorin) const enum SWIGTYPE & "$input = $1;" +%typemap(directorin) const enum SWIGTYPE & "$input = (int)$1;" %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE & %{ static $*1_ltype temp = ($*1_ltype)$input; $result = &temp; %} diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg index 7a2f4fddc..786ca6e66 100644 --- a/Lib/d/dhead.swg +++ b/Lib/d/dhead.swg @@ -93,31 +93,26 @@ private class SwigExceptionHelper { static void setException(char* message) { auto exception = new object.Exception(tango.stdc.stringz.fromStringz(message).dup); - exception.next = SwigPendingException.retrieve(); SwigPendingException.set(exception); } static void setIllegalArgumentException(char* message) { auto exception = new tango.core.Exception.IllegalArgumentException(tango.stdc.stringz.fromStringz(message).dup); - exception.next = SwigPendingException.retrieve(); SwigPendingException.set(exception); } static void setIllegalElementException(char* message) { auto exception = new tango.core.Exception.IllegalElementException(tango.stdc.stringz.fromStringz(message).dup); - exception.next = SwigPendingException.retrieve(); SwigPendingException.set(exception); } static void setIOException(char* message) { auto exception = new tango.core.Exception.IOException(tango.stdc.stringz.fromStringz(message).dup); - exception.next = SwigPendingException.retrieve(); SwigPendingException.set(exception); } static void setNoSuchElementException(char* message) { auto exception = new tango.core.Exception.NoSuchElementException(tango.stdc.stringz.fromStringz(message).dup); - exception.next = SwigPendingException.retrieve(); SwigPendingException.set(exception); } } @@ -125,51 +120,31 @@ private class SwigExceptionHelper { package class SwigPendingException { public: static this() { - m_sPendingCount = 0; m_sPendingException = new ThreadLocalData(null); } static bool isPending() { - bool pending = false; - if (m_sPendingCount > 0) { - if (m_sPendingException.val !is null) { - pending = true; - } - } - return pending; + return m_sPendingException.val !is null; } static void set(object.Exception e) { - if (m_sPendingException.val !is null) { - throw new object.Exception("FATAL: An earlier pending exception from C/C++ code " ~ - "was missed and thus not thrown (" ~ m_sPendingException.val.classinfo.name ~ - ": " ~ m_sPendingException.val.msg ~ ")!", e); + auto pending = m_sPendingException.val; + if (pending !is null) { + e.next = pending; + throw new object.Exception("FATAL: An earlier pending exception from C/C++ " ~ + "code was missed and thus not thrown (" ~ pending.classinfo.name ~ ": " ~ + pending.msg ~ ")!", e); } - m_sPendingException.val = e; - synchronized { - ++m_sPendingCount; - } } static object.Exception retrieve() { - object.Exception e = null; - if (m_sPendingCount > 0) { - if (m_sPendingException.val !is null) { - e = m_sPendingException.val; - m_sPendingException.val = null; - synchronized { - --m_sPendingCount; - } - } - } + auto e = m_sPendingException.val; + m_sPendingException.val = null; return e; } private: - // The pending exception counter is stored thread-global. - static int m_sPendingCount; - // The reference to the pending exception (if any) is stored thread-local. alias tango.core.Thread.ThreadLocal!(object.Exception) ThreadLocalData; static ThreadLocalData m_sPendingException; @@ -195,8 +170,7 @@ private class SwigExceptionHelper { } static void setException(const char* message) { - auto exception = new object.Exception(std.conv.to!string(message).idup); - exception.next = SwigPendingException.retrieve(); + auto exception = new object.Exception(std.conv.to!string(message)); SwigPendingException.set(exception); } } @@ -204,51 +178,31 @@ private class SwigExceptionHelper { package struct SwigPendingException { public: static this() { - m_sPendingCount = 0; m_sPendingException = null; } static bool isPending() { - bool pending = false; - if (m_sPendingCount > 0) { - if (m_sPendingException !is null) { - pending = true; - } - } - return pending; + return m_sPendingException !is null; } static void set(object.Exception e) { if (m_sPendingException !is null) { + e.next = m_sPendingException; throw new object.Exception("FATAL: An earlier pending exception from C/C++ code " ~ "was missed and thus not thrown (" ~ m_sPendingException.classinfo.name ~ ": " ~ m_sPendingException.msg ~ ")!", e); } m_sPendingException = e; - synchronized { - ++m_sPendingCount; - } } static object.Exception retrieve() { - object.Exception e = null; - if (m_sPendingCount > 0) { - if (m_sPendingException !is null) { - e = m_sPendingException; - m_sPendingException = null; - synchronized { - --m_sPendingCount; - } - } - } + auto e = m_sPendingException; + m_sPendingException = null; return e; } private: - // The pending exception counter is stored thread-global. - static shared int m_sPendingCount; - // The reference to the pending exception (if any) is stored thread-local. static object.Exception m_sPendingException; } diff --git a/Lib/go/go.swg b/Lib/go/go.swg index 0c03ae576..e0ad5d147 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -225,13 +225,13 @@ %{ $1 = *($&1_ltype)&$input; %} %typemap(out) SWIGTYPE * -%{ *($&1_ltype)&$result = $1; %} +%{ *($&1_ltype)&$result = ($1_ltype)$1; %} %typemap(directorin) SWIGTYPE * -%{ $input = ($1_ltype)$1; %} +%{ *($&1_ltype)&$input = ($1_ltype)$1; %} %typemap(directorout) SWIGTYPE * -%{ $result = ($1_ltype)$input; %} +%{ $result = *($&1_ltype)&$input; %} %apply SWIGTYPE * { SWIGTYPE *const } @@ -379,7 +379,7 @@ %{ $result = (intgo)$1; %} %typemap(directorin) enum SWIGTYPE -%{ $input = ($1_ltype)$1; %} +%{ $input = (intgo)$1; %} %typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %} diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index bbc602b0d..ef64186b7 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -57,12 +57,21 @@ swiggo_size_assert(double, 8) extern "C" { #endif extern void crosscall2(void (*fn)(void *, int), void *, int); +extern char* _cgo_topofstack(void) __attribute__ ((weak)); extern void _cgo_allocate(void *, int); extern void _cgo_panic(void *, int); #ifdef __cplusplus } #endif +static char *_swig_topofstack() { + if (_cgo_topofstack) { + return _cgo_topofstack(); + } else { + return 0; + } +} + static void *_swig_goallocate(size_t len) { struct { size_t len; @@ -89,11 +98,11 @@ static void _swig_gopanic(const char *p) { #include "runtime.h" #include "cgocall.h" -#ifdef _64BIT -#define SWIG_PARM_SIZE 8 -#else -#define SWIG_PARM_SIZE 4 -#endif +#pragma dataflag 16 +static void *cgocall = runtime·cgocall; +#pragma dataflag 16 +void *·_cgo_runtime_cgocall = &cgocall; + %} #else @@ -194,6 +203,10 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) { %go_import("unsafe", _ "runtime/cgo") +%insert(go_header) %{ +var _cgo_runtime_cgocall func(unsafe.Pointer, uintptr) +%} + #else %go_import("syscall", "unsafe") @@ -212,6 +225,16 @@ type _ unsafe.Pointer %} +/* Swig_always_false is used to conditionally assign parameters to + Swig_escape_val so that the compiler thinks that they escape. We + only assign them if Swig_always_false is true, which it never is. + We export the variable so that the compiler doesn't realize that it + is never set. */ +%insert(go_header) %{ +var Swig_escape_always_false bool +var Swig_escape_val interface{} +%} + /* Function pointers are translated by the code in go.cxx into _swig_fnptr. Member pointers are translated to _swig_memberptr. */ diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index d818613e7..a01e73f64 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -172,11 +172,11 @@ } * (int *) &($1) = scm_to_int($input); } -%typemap(out) enum SWIGTYPE { $result = scm_from_long($1); } -%typemap(varout) enum SWIGTYPE { $result = scm_from_long($1); } +%typemap(out) enum SWIGTYPE { $result = scm_from_long((int)$1); } +%typemap(varout) enum SWIGTYPE { $result = scm_from_long((int)$1); } %typemap(throws) enum SWIGTYPE { scm_throw(scm_from_locale_symbol((char *) "swig-exception"), - scm_listify(scm_from_long($1), SCM_UNDEFINED)); + scm_listify(scm_from_long((int)$1), SCM_UNDEFINED)); } /* The SIMPLE_MAP_WITH_EXPR macro below defines the whole set of diff --git a/Lib/java/director.swg b/Lib/java/director.swg index 819ad903d..031cdf2a9 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -100,6 +100,22 @@ namespace Swig { bool weak_global_; }; + /* Local JNI reference deleter */ + class LocalRefGuard { + JNIEnv *jenv_; + jobject jobj_; + + // non-copyable + LocalRefGuard(const LocalRefGuard &); + LocalRefGuard &operator=(const LocalRefGuard &); + public: + LocalRefGuard(JNIEnv *jenv, jobject jobj): jenv_(jenv), jobj_(jobj) {} + ~LocalRefGuard() { + if (jobj_) + jenv_->DeleteLocalRef(jobj_); + } + }; + /* director base class */ class Director { /* pointer to Java virtual machine */ @@ -152,6 +168,7 @@ namespace Swig { JNIEnvWrapper jnienv(this) ; JNIEnv *jenv = jnienv.getJNIEnv() ; jobject jobj = swig_self_.get(jenv); + LocalRefGuard ref_deleter(jenv, jobj); #if defined(DEBUG_DIRECTOR_OWNED) std::cout << "Swig::Director::disconnect_director_self(" << jobj << ")" << std::endl; #endif @@ -164,7 +181,6 @@ namespace Swig { jenv->CallVoidMethod(jobj, disconn_meth); } } - jenv->DeleteLocalRef(jobj); } public: @@ -379,6 +395,5 @@ namespace Swig { } return matches; } - } diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 3d4d83730..98524e85e 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -400,11 +400,13 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { } %typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char * { - $input = 0; + $input = 0; if ($1) { $input = JCALL1(NewStringUTF, jenv, (const char *)$1); if (!$input) return $null; } + Swig::LocalRefGuard $1_refguard(jenv, $input); +// boohoo } %typemap(freearg, noblock=1) char * { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)$1); } @@ -731,6 +733,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { $input = JCALL1(NewStringUTF, jenv, (const char *)$1); if (!$input) return $null; } + Swig::LocalRefGuard $1_refguard(jenv, $input); } %typemap(argout) char[ANY], char[] "" diff --git a/Lib/java/std_string.i b/Lib/java/std_string.i index 5ad7d30bc..830a89611 100644 --- a/Lib/java/std_string.i +++ b/Lib/java/std_string.i @@ -49,7 +49,8 @@ class string; jenv->ReleaseStringUTFChars($input, $1_pstr); %} %typemap(directorin,descriptor="Ljava/lang/String;") string -%{ $input = jenv->NewStringUTF($1.c_str()); %} +%{ $input = jenv->NewStringUTF($1.c_str()); + Swig::LocalRefGuard $1_refguard(jenv, $input); %} %typemap(out) string %{ $result = jenv->NewStringUTF($1.c_str()); %} @@ -98,7 +99,8 @@ class string; jenv->ReleaseStringUTFChars($input, $1_pstr); %} %typemap(directorin,descriptor="Ljava/lang/String;") const string & -%{ $input = jenv->NewStringUTF($1.c_str()); %} +%{ $input = jenv->NewStringUTF($1.c_str()); + Swig::LocalRefGuard $1_refguard(jenv, $input); %} %typemap(out) const string & %{ $result = jenv->NewStringUTF($1->c_str()); %} diff --git a/Lib/java/various.i b/Lib/java/various.i index 7ba7a5eb3..bfcf346d3 100644 --- a/Lib/java/various.i +++ b/Lib/java/various.i @@ -92,6 +92,7 @@ * The returned string appears in the 1st element of the passed in Java String array. * * Example usage wrapping: + * %apply char **STRING_OUT { char **string_out }; * void foo(char **string_out); * * Java usage: @@ -154,3 +155,40 @@ /* Prevent default freearg typemap from being used */ %typemap(freearg) char *BYTE "" +/* + * unsigned char *NIOBUFFER typemaps. + * This is for mapping Java nio buffers to C char arrays. + * It is useful for performance critical code as it reduces the memory copy an marshaling overhead. + * Note: The Java buffer has to be allocated with allocateDirect. + * + * Example usage wrapping: + * %apply unsigned char *NIOBUFFER { unsigned char *buf }; + * void foo(unsigned char *buf); + * + * Java usage: + * java.nio.ByteBuffer b = ByteBuffer.allocateDirect(20); + * modulename.foo(b); + */ +%typemap(jni) unsigned char *NIOBUFFER "jobject" +%typemap(jtype) unsigned char *NIOBUFFER "java.nio.ByteBuffer" +%typemap(jstype) unsigned char *NIOBUFFER "java.nio.ByteBuffer" +%typemap(javain, + pre=" assert $javainput.isDirect() : \"Buffer must be allocated direct.\";") unsigned char *NIOBUFFER "$javainput" +%typemap(javaout) unsigned char *NIOBUFFER { + return $jnicall; +} +%typemap(in) unsigned char *NIOBUFFER { + $1 = (unsigned char *) JCALL1(GetDirectBufferAddress, jenv, $input); + if ($1 == NULL) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unable to get address of a java.nio.ByteBuffer direct byte buffer. Buffer must be a direct buffer and not a non-direct buffer."); + } +} +%typemap(memberin) unsigned char *NIOBUFFER { + if ($input) { + $1 = $input; + } else { + $1 = 0; + } +} +%typemap(freearg) unsigned char *NIOBUFFER "" + diff --git a/Lib/javascript/jsc/javascriptcode.swg b/Lib/javascript/jsc/javascriptcode.swg index c18902fce..672df8677 100644 --- a/Lib/javascript/jsc/javascriptcode.swg +++ b/Lib/javascript/jsc/javascriptcode.swg @@ -354,7 +354,7 @@ static JSStaticFunction $jsmangledname_functions[] = { $jsmangledname_objectDefinition.staticValues = $jsmangledname_values; $jsmangledname_objectDefinition.staticFunctions = $jsmangledname_functions; $jsclass_inheritance - JSClassRef $jsmangledname_classRef = JSClassCreate(&$jsmangledname_objectDefinition); + $jsmangledname_classRef = JSClassCreate(&$jsmangledname_objectDefinition); SWIGTYPE_$jsmangledtype->clientdata = $jsmangledname_classRef; %} diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg index 67a81146e..12db9b4ab 100644 --- a/Lib/javascript/v8/javascriptcode.swg +++ b/Lib/javascript/v8/javascriptcode.swg @@ -8,8 +8,9 @@ * ----------------------------------------------------------------------------- */ %fragment("js_ctor", "templates") %{ -SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { - v8::HandleScope scope; +static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + v8::Handle self = args.Holder(); $jslocals if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper."); @@ -20,7 +21,7 @@ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { goto fail; fail: - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } %} @@ -31,10 +32,11 @@ fail: * ----------------------------------------------------------------------------- */ %fragment ("js_veto_ctor", "templates") %{ -SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { - v8::HandleScope scope; +static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated"); - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } %} @@ -46,8 +48,9 @@ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { * ----------------------------------------------------------------------------- */ %fragment ("js_ctor_dispatcher", "templates") %{ -SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { - v8::HandleScope scope; +static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + OverloadErrorHandler errorHandler; v8::Handle self; @@ -58,7 +61,7 @@ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for construction of $jsmangledname"); fail: - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } %} @@ -71,8 +74,9 @@ fail: * - $jsmangledtype: mangled type of class * ----------------------------------------------------------------------------- */ %fragment("js_overloaded_ctor", "templates") %{ -SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler) { - v8::HandleScope scope; +static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args, V8ErrorHandler &SWIGV8_ErrorHandler) { + SWIGV8_HANDLESCOPE(); + v8::Handle self = args.Holder(); $jslocals if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper."); @@ -83,7 +87,7 @@ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8 goto fail; fail: - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } %} @@ -98,10 +102,10 @@ fail: %{ if(args.Length() == $jsargcount) { errorHandler.err.Clear(); -#if SWIG_V8_VERSION < 0x031900 +#if (SWIG_V8_VERSION < 0x031903) self = $jswrapper(args, errorHandler); if(errorHandler.err.IsEmpty()) { - return scope.Close(self); + SWIGV8_ESCAPE(self); } #else $jswrapper(args, errorHandler); @@ -120,13 +124,18 @@ fail: %fragment ("js_dtor", "templates") %{ -#if (SWIG_V8_VERSION < 0x031900) -void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) -{ +#if (SWIG_V8_VERSION < 0x031710) +static void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); +#elif (SWIG_V8_VERSION < 0x031900) +static void $jswrapper(v8::Isolate *isolate, v8::Persistent object, void *parameter) { + SWIGV8_Proxy *proxy = static_cast(parameter); +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +static void $jswrapper(v8::Isolate *isolate, v8::Persistent *object, SWIGV8_Proxy *proxy) { #else -void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWIGV8_Proxy *proxy) -{ +static void $jswrapper(const v8::WeakCallbackData &data) { + v8::Local object = data.GetValue(); + SWIGV8_Proxy *proxy = data.GetParameter(); #endif if(proxy->swigCMemOwn && proxy->swigCObject) { @@ -138,8 +147,11 @@ void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWI delete proxy; object.Clear(); -#if (SWIG_V8_VERSION < 0x031900) + +#if (SWIG_V8_VERSION < 0x031710) object.Dispose(); +#elif (SWIG_V8_VERSION < 0x031900) + object.Dispose(isolate); #elif (SWIG_V8_VERSION < 0x032100) object->Dispose(isolate); #else @@ -156,26 +168,36 @@ void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWI * ----------------------------------------------------------------------------- */ %fragment ("js_dtoroverride", "templates") %{ -#if (SWIG_V8_VERSION < 0x031900) -void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) -{ +#if (SWIG_V8_VERSION < 0x031710) +static void $jswrapper(v8::Persistent object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); +#elif (SWIG_V8_VERSION < 0x031900) +static void $jswrapper(v8::Isolate *isolate, v8::Persistent object, void *parameter) { + SWIGV8_Proxy *proxy = static_cast(parameter); +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +static void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object> *object, SWIGV8_Proxy *proxy) { #else -void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWIGV8_Proxy *proxy) -{ +static void $jswrapper(const v8::WeakCallbackData &data) { + v8::Local object = data.GetValue(); + SWIGV8_Proxy *proxy = data.GetParameter(); #endif + if(proxy->swigCMemOwn && proxy->swigCObject) { $jstype arg1 = ($jstype)proxy->swigCObject; ${destructor_action} } delete proxy; -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031710) object.Dispose(); +#elif (SWIG_V8_VERSION < 0x031900) + object.Dispose(isolate); #elif (SWIG_V8_VERSION < 0x032100) object->Dispose(isolate); -#else +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) object->Dispose(); +#else + object.Clear(); #endif } %} @@ -188,8 +210,9 @@ void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWI * ----------------------------------------------------------------------------- */ %fragment("js_getter", "templates") %{ -SwigV8ReturnValue $jswrapper(v8::Local property, const SwigV8PropertyCallbackInfo& info) { - v8::HandleScope scope; +static SwigV8ReturnValue $jswrapper(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + v8::Handle jsresult; $jslocals $jscode @@ -197,7 +220,7 @@ SwigV8ReturnValue $jswrapper(v8::Local property, const SwigV8Propert goto fail; fail: - SWIGV8_RETURN_INFO(v8::Undefined(), info); + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); } %} @@ -209,9 +232,10 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("js_setter", "templates") %{ -void $jswrapper(v8::Local property, v8::Local value, - const SwigV8PropertyCallbackInfoVoid& info) { - v8::HandleScope scope; +static void $jswrapper(v8::Local property, v8::Local value, + const SwigV8PropertyCallbackInfoVoid &info) { + SWIGV8_HANDLESCOPE(); + $jslocals $jscode goto fail; @@ -228,8 +252,9 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("js_function", "templates") %{ -SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { - v8::HandleScope scope; +static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + v8::Handle jsresult; $jslocals if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper."); @@ -239,7 +264,7 @@ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { goto fail; fail: - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } %} @@ -252,8 +277,9 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("js_function_dispatcher", "templates") %{ -SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { - v8::HandleScope scope; +static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + v8::Handle jsresult; OverloadErrorHandler errorHandler; $jscode @@ -262,7 +288,7 @@ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { goto fail; fail: - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } %} @@ -274,9 +300,10 @@ fail: * ----------------------------------------------------------------------------- */ %fragment ("js_overloaded_function", "templates") %{ -SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler) +static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args, V8ErrorHandler &SWIGV8_ErrorHandler) { - v8::HandleScope scope; + SWIGV8_HANDLESCOPE(); + v8::Handle jsresult; $jslocals $jscode @@ -284,7 +311,7 @@ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8 goto fail; fail: - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } %} @@ -299,10 +326,10 @@ fail: if(args.Length() == $jsargcount) { errorHandler.err.Clear(); -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031903) jsresult = $jswrapper(args, errorHandler); if(errorHandler.err.IsEmpty()) { - return scope.Close(jsresult); + SWIGV8_ESCAPE(jsresult); } #else $jswrapper(args, errorHandler); @@ -330,12 +357,9 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_define_class_template", "templates") %{ + /* Name: $jsmangledname, Type: $jsmangledtype, Dtor: $jsdtor */ v8::Handle $jsmangledname_class = SWIGV8_CreateClassTemplate("$jsmangledname"); -#if (SWIG_V8_VERSION < 0x031900) - $jsmangledname_clientData.class_templ = v8::Persistent::New($jsmangledname_class); -#else - $jsmangledname_clientData.class_templ.Reset(v8::Isolate::GetCurrent(), $jsmangledname_class); -#endif + SWIGV8_SET_CLASS_TEMPL($jsmangledname_clientData.class_templ, $jsmangledname_class); $jsmangledname_clientData.dtor = $jsdtor; if (SWIGTYPE_$jsmangledtype->clientdata == 0) { SWIGTYPE_$jsmangledtype->clientdata = &$jsmangledname_clientData; @@ -352,11 +376,11 @@ fail: %{ if (SWIGTYPE_p$jsbaseclass->clientdata && !(static_cast(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ.IsEmpty())) { -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031903) $jsmangledname_class->Inherit(static_cast(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ); #else $jsmangledname_class->Inherit( - v8::Handle::New( + v8::Local::New( v8::Isolate::GetCurrent(), static_cast(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ) ); @@ -379,6 +403,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_create_class_instance", "templates") %{ + /* Class: $jsname ($jsmangledname) */ v8::Handle $jsmangledname_class_0 = SWIGV8_CreateClassTemplate("$jsname"); $jsmangledname_class_0->SetCallHandler($jsctor); $jsmangledname_class_0->Inherit($jsmangledname_class); @@ -394,7 +419,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_register_class", "templates") %{ - $jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj); + $jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj); %} /* ----------------------------------------------------------------------------- @@ -403,7 +428,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_create_namespace", "templates") %{ - v8::Handle $jsmangledname_obj = v8::Object::New(); + v8::Handle $jsmangledname_obj = SWIGV8_OBJECT_NEW(); %} /* ----------------------------------------------------------------------------- @@ -414,7 +439,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_register_namespace", "templates") %{ - $jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj); + $jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj); %} /* ----------------------------------------------------------------------------- diff --git a/Lib/javascript/v8/javascriptcomplex.swg b/Lib/javascript/v8/javascriptcomplex.swg index 70c5baffb..683b972bc 100644 --- a/Lib/javascript/v8/javascriptcomplex.swg +++ b/Lib/javascript/v8/javascriptcomplex.swg @@ -15,12 +15,13 @@ SWIGINTERNINLINE v8::Handle SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c) { - v8::HandleScope scope; - v8::Local vals = v8::Array::New(2); + SWIGV8_HANDLESCOPE_ESC(); + + v8::Local vals = SWIGV8_ARRAY_NEW(2); vals->Set(0, SWIG_From(double)(Real(c))); vals->Set(1, SWIG_From(double)(Imag(c))); - return scope.Close(vals); + SWIGV8_ESCAPE(vals); } } %enddef @@ -33,7 +34,7 @@ SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c) SWIGINTERN int SWIG_AsVal_dec(Type) (v8::Handle o, Type* val) { - v8::HandleScope scope; + SWIGV8_HANDLESCOPE(); if (o->IsArray()) { v8::Handle array = v8::Handle::Cast(o); @@ -75,7 +76,7 @@ SWIG_AsVal_dec(Type) (v8::Handle o, Type* val) SWIGINTERN int SWIG_AsVal_dec(Type) (v8::Handle o, Type* val) { - v8::HandleScope scope; + SWIGV8_HANDLESCOPE(); if (o->IsArray()) { v8::Handle array = v8::Handle::Cast(o); diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index f6303cced..969225401 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -1,7 +1,7 @@ %insert(runtime) %{ // Note: since 3.19 there are new CallBack types, since 03.21.9 the old ones have been removed -#if SWIG_V8_VERSION < 0x031900 +#if (SWIG_V8_VERSION < 0x031903) typedef v8::InvocationCallback SwigV8FunctionCallback; typedef v8::AccessorGetter SwigV8AccessorGetterCallback; typedef v8::AccessorSetter SwigV8AccessorSetterCallback; @@ -17,20 +17,21 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfoVoid; * Creates a class template for a class with specified initialization function. */ SWIGRUNTIME v8::Handle SWIGV8_CreateClassTemplate(const char* symbol) { - v8::HandleScope scope; - v8::Local class_templ = v8::FunctionTemplate::New(); - class_templ->SetClassName(v8::String::NewSymbol(symbol)); + SWIGV8_HANDLESCOPE_ESC(); + + v8::Local class_templ = SWIGV8_FUNCTEMPLATE_NEW_VOID(); + class_templ->SetClassName(SWIGV8_SYMBOL_NEW(symbol)); v8::Handle inst_templ = class_templ->InstanceTemplate(); inst_templ->SetInternalFieldCount(1); v8::Handle equals_templ = class_templ->PrototypeTemplate(); - equals_templ->Set(v8::String::NewSymbol("equals"), v8::FunctionTemplate::New(_SWIGV8_wrap_equals)); + equals_templ->Set(SWIGV8_SYMBOL_NEW("equals"), SWIGV8_FUNCTEMPLATE_NEW(_SWIGV8_wrap_equals)); v8::Handle cptr_templ = class_templ->PrototypeTemplate(); - cptr_templ->Set(v8::String::NewSymbol("getCPtr"), v8::FunctionTemplate::New(_wrap_getCPtr)); + cptr_templ->Set(SWIGV8_SYMBOL_NEW("getCPtr"), SWIGV8_FUNCTEMPLATE_NEW(_wrap_getCPtr)); - return scope.Close(class_templ); + SWIGV8_ESCAPE(class_templ); } /** @@ -39,7 +40,7 @@ SWIGRUNTIME v8::Handle SWIGV8_CreateClassTemplate(const ch SWIGRUNTIME void SWIGV8_AddMemberFunction(v8::Handle class_templ, const char* symbol, SwigV8FunctionCallback _func) { v8::Handle proto_templ = class_templ->PrototypeTemplate(); - proto_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)); + proto_templ->Set(SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)); } /** @@ -48,7 +49,7 @@ SWIGRUNTIME void SWIGV8_AddMemberFunction(v8::Handle class SWIGRUNTIME void SWIGV8_AddMemberVariable(v8::Handle class_templ, const char* symbol, SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) { v8::Handle proto_templ = class_templ->InstanceTemplate(); - proto_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter); + proto_templ->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter); } /** @@ -56,7 +57,7 @@ SWIGRUNTIME void SWIGV8_AddMemberVariable(v8::Handle class */ SWIGRUNTIME void SWIGV8_AddStaticFunction(v8::Handle obj, const char* symbol, const SwigV8FunctionCallback& _func) { - obj->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction()); + obj->Set(SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction()); } /** @@ -64,7 +65,7 @@ SWIGRUNTIME void SWIGV8_AddStaticFunction(v8::Handle obj, const char */ SWIGRUNTIME void SWIGV8_AddStaticVariable(v8::Handle obj, const char* symbol, SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) { - obj->SetAccessor(v8::String::NewSymbol(symbol), getter, setter); + obj->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter); } SWIGRUNTIME void JS_veto_set_variable(v8::Local property, v8::Local value, diff --git a/Lib/javascript/v8/javascriptinit.swg b/Lib/javascript/v8/javascriptinit.swg index b428d4af9..34befa7ce 100644 --- a/Lib/javascript/v8/javascriptinit.swg +++ b/Lib/javascript/v8/javascriptinit.swg @@ -4,16 +4,16 @@ SWIGRUNTIME void SWIG_V8_SetModule(void *, swig_module_info *swig_module) { - v8::Local global_obj = v8::Context::GetCurrent()->Global(); - v8::Local mod = v8::External::New(swig_module); + v8::Local global_obj = SWIGV8_CURRENT_CONTEXT()->Global(); + v8::Local mod = SWIGV8_EXTERNAL_NEW(swig_module); assert(!mod.IsEmpty()); - global_obj->SetHiddenValue(v8::String::New("swig_module_info_data"), mod); + global_obj->SetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data"), mod); } SWIGRUNTIME swig_module_info * SWIG_V8_GetModule(void *) { - v8::Local global_obj = v8::Context::GetCurrent()->Global(); - v8::Local moduleinfo = global_obj->GetHiddenValue(v8::String::New("swig_module_info_data")); + v8::Local global_obj = SWIGV8_CURRENT_CONTEXT()->Global(); + v8::Local moduleinfo = global_obj->GetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data")); if (moduleinfo.IsEmpty()) { @@ -61,7 +61,8 @@ void SWIGV8_INIT (v8::Handle exports, v8::Handle /*modul { SWIG_InitializeModule(static_cast(&exports)); - v8::HandleScope scope; + SWIGV8_HANDLESCOPE(); + v8::Handle exports_obj = exports; %} @@ -81,11 +82,7 @@ void SWIGV8_INIT (v8::Handle exports, v8::Handle /*modul %fragment("js_initializer", "templates") %{ // a class template for creating proxies of undefined types -#if (SWIG_V8_VERSION < 0x031900) - SWIGV8_SWIGTYPE_Proxy_class_templ = v8::Persistent::New(SWIGV8_CreateClassTemplate("SwigProxy")); -#else - SWIGV8_SWIGTYPE_Proxy_class_templ.Reset(v8::Isolate::GetCurrent(), SWIGV8_CreateClassTemplate("SwigProxy")); -#endif + SWIGV8_SET_CLASS_TEMPL(SWIGV8_SWIGTYPE_Proxy_class_templ, SWIGV8_CreateClassTemplate("SwigProxy")); /* create objects for namespaces */ $jsv8nspaces diff --git a/Lib/javascript/v8/javascriptprimtypes.swg b/Lib/javascript/v8/javascriptprimtypes.swg index 706a799b7..fe826b863 100644 --- a/Lib/javascript/v8/javascriptprimtypes.swg +++ b/Lib/javascript/v8/javascriptprimtypes.swg @@ -9,7 +9,7 @@ SWIGINTERNINLINE v8::Handle SWIG_From_dec(bool)(bool value) { - return v8::Boolean::New(value); + return SWIGV8_BOOLEAN_NEW(value); } } @@ -33,7 +33,7 @@ int SWIG_AsVal_dec(bool)(v8::Handle obj, bool *val) SWIGINTERNINLINE v8::Handle SWIG_From_dec(int)(int value) { - return v8::Int32::New(value); + return SWIGV8_INT32_NEW(value); } } @@ -56,7 +56,7 @@ int SWIG_AsVal_dec(int)(v8::Handle valRef, int* val) SWIGINTERNINLINE v8::Handle SWIG_From_dec(long)(long value) { - return v8::Number::New(value); + return SWIGV8_NUMBER_NEW(value); } } @@ -82,7 +82,7 @@ SWIGINTERNINLINE v8::Handle SWIG_From_dec(unsigned long)(unsigned long value) { return (value > LONG_MAX) ? - v8::Integer::NewFromUnsigned(value) : v8::Integer::New(%numeric_cast(value,long)); + SWIGV8_INTEGER_NEW_UNS(value) : SWIGV8_INTEGER_NEW(%numeric_cast(value,long)); } } @@ -116,7 +116,7 @@ int SWIG_AsVal_dec(unsigned long)(v8::Handle obj, unsigned long *val) SWIGINTERNINLINE v8::Handle SWIG_From_dec(long long)(long long value) { - return v8::Number::New(value); + return SWIGV8_NUMBER_NEW(value); } } @@ -146,7 +146,7 @@ SWIGINTERNINLINE v8::Handle SWIG_From_dec(unsigned long long)(unsigned long long value) { return (value > LONG_MAX) ? - v8::Integer::NewFromUnsigned(value) : v8::Integer::New(%numeric_cast(value,long)); + SWIGV8_INTEGER_NEW_UNS(value) : SWIGV8_INTEGER_NEW(%numeric_cast(value,long)); } } @@ -179,7 +179,7 @@ int SWIG_AsVal_dec(unsigned long long)(v8::Handle obj, unsigned long SWIGINTERN v8::Handle SWIG_From_dec(double) (double val) { - return v8::Number::New(val); + return SWIGV8_NUMBER_NEW(val); } } diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index f200f1520..b37059cca 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -1,3 +1,96 @@ +/* --------------------------------------------------------------------------- + * These typedefs and defines are used to deal with v8 API changes + * + * ---------------------------------------------------------------------------*/ + +// First v8 version that uses "SetWeak" and not "MakeWeak" + +#define SWIGV8_SETWEAK_VERSION 0x032224 + +#if (SWIG_V8_VERSION < 0x031803) +#define SWIGV8_STRING_NEW2(cstr, len) v8::String::New(cstr, len) +#else +#define SWIGV8_STRING_NEW2(cstr, len) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::String::kNormalString, len) +#endif + +#if (SWIG_V8_VERSION < 0x031903) +typedef v8::Handle SwigV8ReturnValue; +typedef v8::Arguments SwigV8Arguments; +typedef v8::AccessorInfo SwigV8PropertyCallbackInfo; +#define SWIGV8_RETURN(val) return scope.Close(val) +#define SWIGV8_RETURN_INFO(val, info) return scope.Close(val) +#else +typedef void SwigV8ReturnValue; +typedef v8::FunctionCallbackInfo SwigV8Arguments; +typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; +#define SWIGV8_RETURN(val) args.GetReturnValue().Set(val); return +#define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return +#endif + +#if (SWIG_V8_VERSION < 0x032117) +#define SWIGV8_HANDLESCOPE() v8::HandleScope scope +#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope +#define SWIGV8_ESCAPE(val) return scope.Close(val) +#elif (SWIG_V8_VERSION < 0x032224) +#define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); +#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope(v8::Isolate::GetCurrent()); +#define SWIGV8_ESCAPE(val) return scope.Close(val) +#else +#define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); +#define SWIGV8_HANDLESCOPE_ESC() v8::EscapableHandleScope scope(v8::Isolate::GetCurrent()); +#define SWIGV8_ESCAPE(val) return scope.Escape(val) +#endif + +#if (SWIG_V8_VERSION < 0x032224) +#define SWIGV8_ADJUST_MEMORY(size) v8::V8::AdjustAmountOfExternalAllocatedMemory(size) +#define SWIGV8_CURRENT_CONTEXT() v8::Context::GetCurrent() +#define SWIGV8_THROW_EXCEPTION(err) v8::ThrowException(err) +#define SWIGV8_STRING_NEW(str) v8::String::New(str) +#define SWIGV8_SYMBOL_NEW(sym) v8::String::NewSymbol(sym) +#else +#define SWIGV8_ADJUST_MEMORY(size) v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(size) +#define SWIGV8_CURRENT_CONTEXT() v8::Isolate::GetCurrent()->GetCurrentContext() +#define SWIGV8_THROW_EXCEPTION(err) v8::Isolate::GetCurrent()->ThrowException(err) +#define SWIGV8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str) +#define SWIGV8_SYMBOL_NEW(sym) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym) +#endif + +#if (SWIG_V8_VERSION < 0x032318) +#define SWIGV8_ARRAY_NEW() v8::Array::New() +#define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(bool) +#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(val) +#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(func) +#define SWIGV8_FUNCTEMPLATE_NEW_VOID() v8::FunctionTemplate::New() +#define SWIGV8_INT32_NEW(num) v8::Int32::New(num) +#define SWIGV8_INTEGER_NEW(num) v8::Integer::New(num) +#define SWIGV8_INTEGER_NEW_UNS(num) v8::Integer::NewFromUnsigned(num) +#define SWIGV8_NUMBER_NEW(num) v8::Number::New(num) +#define SWIGV8_OBJECT_NEW() v8::Object::New() +#define SWIGV8_UNDEFINED() v8::Undefined() +#define SWIGV8_NULL() v8::Null() +#else +#define SWIGV8_ARRAY_NEW() v8::Array::New(v8::Isolate::GetCurrent()) +#define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(v8::Isolate::GetCurrent(), bool) +#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(v8::Isolate::GetCurrent(), val) +#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(v8::Isolate::GetCurrent(), func) +#define SWIGV8_FUNCTEMPLATE_NEW_VOID() v8::FunctionTemplate::New(v8::Isolate::GetCurrent()) +#define SWIGV8_INT32_NEW(num) v8::Int32::New(v8::Isolate::GetCurrent(), num) +#define SWIGV8_INTEGER_NEW(num) v8::Integer::New(v8::Isolate::GetCurrent(), num) +#define SWIGV8_INTEGER_NEW_UNS(num) v8::Integer::NewFromUnsigned(v8::Isolate::GetCurrent(), num) +#define SWIGV8_NUMBER_NEW(num) v8::Number::New(v8::Isolate::GetCurrent(), num) +#define SWIGV8_OBJECT_NEW() v8::Object::New(v8::Isolate::GetCurrent()) +#define SWIGV8_UNDEFINED() v8::Undefined(v8::Isolate::GetCurrent()) +#define SWIGV8_NULL() v8::Null(v8::Isolate::GetCurrent()) +#endif + +#if (SWIG_V8_VERSION < 0x031710) +#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ = v8::Persistent::New(class); +#elif (SWIG_V8_VERSION < 0x031900) +#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ = v8::Persistent::New(v8::Isolate::GetCurrent(), class); +#else +#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ.Reset(v8::Isolate::GetCurrent(), class); +#endif + /* --------------------------------------------------------------------------- * Error handling * @@ -8,8 +101,8 @@ #define SWIG_fail goto fail #define SWIGV8_OVERLOAD false -void SWIG_V8_Raise(const char* msg) { - v8::ThrowException(v8::Exception::Error(v8::String::New(msg))); +static void SWIG_V8_Raise(const char *msg) { + SWIGV8_THROW_EXCEPTION(v8::Exception::Error(SWIGV8_STRING_NEW(msg))); } /* @@ -28,42 +121,25 @@ void SWIG_V8_Raise(const char* msg) { class V8ErrorHandler { public: virtual ~V8ErrorHandler() {} - virtual void error(int code, const char* msg) { + virtual void error(int code, const char *msg) { SWIG_V8_Raise(msg); } }; // this is used in usually -V8ErrorHandler SWIGV8_ErrorHandler; +static V8ErrorHandler SWIGV8_ErrorHandler; // instances of this are used in overloaded functions class OverloadErrorHandler: public V8ErrorHandler { public: - virtual void error(int code, const char* msg) { - err = v8::Exception::Error(v8::String::New(msg)); + virtual void error(int code, const char *msg) { + err = v8::Exception::Error(SWIGV8_STRING_NEW(msg)); if(code != SWIG_TypeError) { - v8::ThrowException(err); + SWIGV8_THROW_EXCEPTION(err); } } v8::Handle err; }; -// Note: these typedefs and defines are used to deal with v8 API changes since version 3.19.00 - -#if (SWIG_V8_VERSION < 0x031900) -typedef v8::Handle SwigV8ReturnValue; -typedef v8::Arguments SwigV8Arguments; -typedef v8::AccessorInfo SwigV8PropertyCallbackInfo; -#define SWIGV8_RETURN(val) return scope.Close(val) -#define SWIGV8_RETURN_INFO(val, info) return scope.Close(val) -#else -typedef void SwigV8ReturnValue; -typedef v8::FunctionCallbackInfo SwigV8Arguments; -typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; -#define SWIGV8_RETURN(val) args.GetReturnValue().Set(val); return -#define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return -#endif - - /* --------------------------------------------------------------------------- * Basic Proxy object * @@ -76,20 +152,29 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; class SWIGV8_Proxy { public: SWIGV8_Proxy(): swigCMemOwn(false), swigCObject(0), info(0) { - v8::V8::AdjustAmountOfExternalAllocatedMemory(SWIGV8_AVG_OBJ_SIZE); + SWIGV8_ADJUST_MEMORY(SWIGV8_AVG_OBJ_SIZE); }; ~SWIGV8_Proxy() { -#if (SWIG_V8_VERSION < 0x031900 || SWIG_V8_VERSION >= 0x032100) +#if (SWIG_V8_VERSION < 0x031710) handle.ClearWeak(); handle.Dispose(); -#else +#elif (SWIG_V8_VERSION < 0x032100) handle.ClearWeak(v8::Isolate::GetCurrent()); handle.Dispose(v8::Isolate::GetCurrent()); +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) + handle.ClearWeak(); + handle.Dispose(); +#else + handle.ClearWeak(); + handle.Reset(); #endif +#if (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) handle.Clear(); - v8::V8::AdjustAmountOfExternalAllocatedMemory(-SWIGV8_AVG_OBJ_SIZE); +#endif + + SWIGV8_ADJUST_MEMORY(-SWIGV8_AVG_OBJ_SIZE); } bool swigCMemOwn; @@ -102,21 +187,25 @@ class SWIGV8_ClientData { public: v8::Persistent class_templ; -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031710) void (*dtor) (v8::Persistent< v8::Value> object, void *parameter); -#else +#elif (SWIG_V8_VERSION < 0x031900) + void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Value> object, void *parameter); +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy); +#else + void (*dtor) (const v8::WeakCallbackData &data); #endif }; -v8::Persistent SWIGV8_SWIGTYPE_Proxy_class_templ; +static v8::Persistent SWIGV8_SWIGTYPE_Proxy_class_templ; -int SWIG_V8_ConvertInstancePtr(v8::Handle objRef, void** ptr, swig_type_info *info, int flags) { - v8::HandleScope scope; +static int SWIG_V8_ConvertInstancePtr(v8::Handle objRef, void **ptr, swig_type_info *info, int flags) { + SWIGV8_HANDLESCOPE(); if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031511) v8::Handle cdataRef = objRef->GetInternalField(0); SWIGV8_Proxy *cdata = static_cast(v8::External::Unwrap(cdataRef)); #else @@ -143,20 +232,24 @@ int SWIG_V8_ConvertInstancePtr(v8::Handle objRef, void** ptr, swig_t return SWIG_OK; } -#if (SWIG_V8_VERSION < 0x031900) -void SWIGV8_Proxy_DefaultDtor(v8::Persistent< v8::Value > object, void *parameter) -#else -void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy) -#endif -{ -#if (SWIG_V8_VERSION < 0x031900) + +#if (SWIG_V8_VERSION < 0x031710) +static void SWIGV8_Proxy_DefaultDtor(v8::Persistent< v8::Value > object, void *parameter) { SWIGV8_Proxy *proxy = static_cast(parameter); +#elif (SWIG_V8_VERSION < 0x031900) +static void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Value > object, void *parameter) { + SWIGV8_Proxy *proxy = static_cast(parameter); +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +static void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy) { +#else +static void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackData &data) { + SWIGV8_Proxy *proxy = data.GetParameter(); #endif delete proxy; } -int SWIG_V8_GetInstancePtr(v8::Handle valRef, void** ptr) { +static int SWIG_V8_GetInstancePtr(v8::Handle valRef, void **ptr) { if(!valRef->IsObject()) { return SWIG_TypeError; } @@ -164,7 +257,7 @@ int SWIG_V8_GetInstancePtr(v8::Handle valRef, void** ptr) { if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031511) v8::Handle cdataRef = objRef->GetInternalField(0); SWIGV8_Proxy *cdata = static_cast(v8::External::Unwrap(cdataRef)); #else @@ -180,46 +273,66 @@ int SWIG_V8_GetInstancePtr(v8::Handle valRef, void** ptr) { return SWIG_OK; } -void SWIGV8_SetPrivateData(v8::Handle obj, void* ptr, swig_type_info *info, int flags) { - SWIGV8_Proxy* cdata = new SWIGV8_Proxy(); +static void SWIGV8_SetPrivateData(v8::Handle obj, void *ptr, swig_type_info *info, int flags) { + SWIGV8_Proxy *cdata = new SWIGV8_Proxy(); cdata->swigCObject = ptr; cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0; cdata->info = info; -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031511) obj->SetPointerInInternalField(0, cdata); - cdata->handle = v8::Persistent::New(obj); #else obj->SetAlignedPointerInInternalField(0, cdata); +#endif + +#if (SWIG_V8_VERSION < 0x031710) + cdata->handle = v8::Persistent::New(obj); +#elif (SWIG_V8_VERSION < 0x031900) + cdata->handle = v8::Persistent::New(v8::Isolate::GetCurrent(), obj); +#else cdata->handle.Reset(v8::Isolate::GetCurrent(), obj); #endif -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031710) // clientdata must be set for owned data as we need to register the dtor if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); } else { cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor); } - cdata->handle.MarkIndependent(); -#else +#elif (SWIG_V8_VERSION < 0x031918) if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); } else { cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, SWIGV8_Proxy_DefaultDtor); } +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) + if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { + cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); + } else { + cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor); + } +#else + if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { + cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); + } else { + cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor); + } +#endif -#if (SWIG_V8_VERSION < 0x032100) +#if (SWIG_V8_VERSION < 0x031710) + cdata->handle.MarkIndependent(); +#elif (SWIG_V8_VERSION < 0x032100) cdata->handle.MarkIndependent(v8::Isolate::GetCurrent()); #else cdata->handle.MarkIndependent(); #endif -#endif } -int SWIG_V8_ConvertPtr(v8::Handle valRef, void** ptr, swig_type_info *info, int flags) { - v8::HandleScope scope; +static int SWIG_V8_ConvertPtr(v8::Handle valRef, void **ptr, swig_type_info *info, int flags) { + SWIGV8_HANDLESCOPE(); + /* special case: JavaScript null => C NULL pointer */ if(valRef->IsNull()) { *ptr=0; @@ -232,34 +345,41 @@ int SWIG_V8_ConvertPtr(v8::Handle valRef, void** ptr, swig_type_info return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags); } -v8::Handle SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) { - v8::HandleScope scope; +static v8::Handle SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) { + SWIGV8_HANDLESCOPE_ESC(); + v8::Handle class_templ; if (ptr == NULL) { - return scope.Close(v8::Null()); +#if (SWIG_V8_VERSION < 0x031903) + SWIGV8_ESCAPE(SWIGV8_NULL()); +#else + v8::Local result = SWIGV8_NULL(); + SWIGV8_ESCAPE(result); +#endif } -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031903) if(info->clientdata != 0) { class_templ = ((SWIGV8_ClientData*) info->clientdata)->class_templ; } else { class_templ = SWIGV8_SWIGTYPE_Proxy_class_templ; } #else - v8::Isolate *iso = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); if(info->clientdata != 0) { - class_templ = v8::Handle::New(iso, ((SWIGV8_ClientData*) info->clientdata)->class_templ); + class_templ = v8::Local::New(isolate, ((SWIGV8_ClientData*) info->clientdata)->class_templ); } else { - class_templ = v8::Handle::New(iso, SWIGV8_SWIGTYPE_Proxy_class_templ); + class_templ = v8::Local::New(isolate, SWIGV8_SWIGTYPE_Proxy_class_templ); } #endif - v8::Handle result = class_templ->InstanceTemplate()->NewInstance(); +// v8::Handle result = class_templ->InstanceTemplate()->NewInstance(); + v8::Local result = class_templ->InstanceTemplate()->NewInstance(); SWIGV8_SetPrivateData(result, ptr, info, flags); - return scope.Close(result); + SWIGV8_ESCAPE(result); } #define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_V8_ConvertPtr(obj, ptr, info, flags) @@ -273,12 +393,9 @@ v8::Handle SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int #define SWIG_GetInstancePtr(obj, ptr) SWIG_V8_GetInstancePtr(obj, ptr) -#if (SWIG_V8_VERSION < 0x031900) -v8::Handle _SWIGV8_wrap_equals(const v8::Arguments &args) { -#else -void _SWIGV8_wrap_equals(const v8::FunctionCallbackInfo& args) { -#endif - v8::HandleScope scope; +static SwigV8ReturnValue _SWIGV8_wrap_equals(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + v8::Handle jsresult; void *arg1 = (void *) 0 ; void *arg2 = (void *) 0 ; @@ -298,20 +415,17 @@ void _SWIGV8_wrap_equals(const v8::FunctionCallbackInfo& args) { } result = (bool)(arg1 == arg2); - jsresult = v8::Boolean::New(result); + jsresult = SWIGV8_BOOLEAN_NEW(result); SWIGV8_RETURN(jsresult); goto fail; fail: - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } -#if (SWIG_V8_VERSION < 0x031900) -v8::Handle _wrap_getCPtr(const v8::Arguments &args) { -#else -void _wrap_getCPtr(const v8::FunctionCallbackInfo& args) { -#endif - v8::HandleScope scope; +static SwigV8ReturnValue _wrap_getCPtr(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + v8::Handle jsresult; void *arg1 = (void *) 0 ; long result; @@ -323,12 +437,12 @@ void _wrap_getCPtr(const v8::FunctionCallbackInfo& args) { } result = (long)arg1; - jsresult = v8::Number::New(result); + jsresult = SWIGV8_NUMBER_NEW(result); SWIGV8_RETURN(jsresult); goto fail; fail: - SWIGV8_RETURN(v8::Undefined()); + SWIGV8_RETURN(SWIGV8_UNDEFINED()); } /* --------------------------------------------------------------------------- @@ -343,7 +457,7 @@ public: ~SwigV8PackedData() { }; - void* data; + void *data; size_t size; swig_type_info *type; @@ -352,22 +466,24 @@ public: SWIGRUNTIMEINLINE int SwigV8Packed_Check(v8::Handle valRef) { - v8::HandleScope scope; + SWIGV8_HANDLESCOPE(); + v8::Handle objRef = valRef->ToObject(); if(objRef->InternalFieldCount() < 1) return false; - v8::Handle flag = objRef->GetHiddenValue(v8::String::New("__swig__packed_data__")); + v8::Handle flag = objRef->GetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__")); return (flag->IsBoolean() && flag->BooleanValue()); } SWIGRUNTIME -swig_type_info* SwigV8Packed_UnpackData(v8::Handle valRef, void *ptr, size_t size) { +swig_type_info *SwigV8Packed_UnpackData(v8::Handle valRef, void *ptr, size_t size) { if (SwigV8Packed_Check(valRef)) { - v8::HandleScope scope; + SWIGV8_HANDLESCOPE(); + SwigV8PackedData *sobj; v8::Handle objRef = valRef->ToObject(); -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031511) v8::Handle cdataRef = objRef->GetInternalField(0); sobj = static_cast(v8::External::Unwrap(cdataRef)); #else @@ -395,57 +511,82 @@ int SWIGV8_ConvertPacked(v8::Handle valRef, void *ptr, size_t sz, swi return SWIG_OK; } -#if (SWIG_V8_VERSION < 0x031900) -void _wrap_SwigV8PackedData_delete(v8::Persistent< v8::Value > object, void *parameter) -{ +#if (SWIG_V8_VERSION < 0x031710) +static void _wrap_SwigV8PackedData_delete(v8::Persistent< v8::Value > object, void *parameter) { SwigV8PackedData *cdata = static_cast(parameter); +#elif (SWIG_V8_VERSION < 0x031900) +static void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent object, void *parameter) { + SwigV8PackedData *cdata = static_cast(parameter); +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) +static void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent *object, SwigV8PackedData *cdata) { #else -void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SwigV8PackedData *cdata) -{ +static void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData &data) { + v8::Local object = data.GetValue(); + SwigV8PackedData *cdata = data.GetParameter(); #endif delete cdata; -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031710) object.Clear(); object.Dispose(); +#elif (SWIG_V8_VERSION < 0x031900) + object.Clear(); + object.Dispose(isolate); #elif (SWIG_V8_VERSION < 0x032100) object->Dispose(isolate); -#else +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) object->Dispose(); +#else + object.Clear(); #endif } SWIGRUNTIME v8::Handle SWIGV8_NewPackedObj(void *data, size_t size, swig_type_info *type) { - v8::HandleScope scope; + SWIGV8_HANDLESCOPE_ESC(); - SwigV8PackedData* cdata = new SwigV8PackedData(data, size, type); - v8::Handle obj = v8::Object::New(); + SwigV8PackedData *cdata = new SwigV8PackedData(data, size, type); +// v8::Handle obj = SWIGV8_OBJECT_NEW(); + v8::Local obj = SWIGV8_OBJECT_NEW(); - obj->SetHiddenValue(v8::String::New("__swig__packed_data__"), v8::Boolean::New(true)); + obj->SetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"), SWIGV8_BOOLEAN_NEW(true)); -#if (SWIG_V8_VERSION < 0x031900) +#if (SWIG_V8_VERSION < 0x031511) obj->SetPointerInInternalField(0, cdata); - cdata->handle = v8::Persistent::New(obj); #else obj->SetAlignedPointerInInternalField(0, cdata); +#endif + +#if (SWIG_V8_VERSION < 0x031710) + cdata->handle = v8::Persistent::New(obj); +#elif (SWIG_V8_VERSION < 0x031900) + cdata->handle = v8::Persistent::New(v8::Isolate::GetCurrent(), obj); +#else cdata->handle.Reset(v8::Isolate::GetCurrent(), obj); #endif -#if (SWIG_V8_VERSION < 0x031900) + +#if (SWIG_V8_VERSION < 0x031710) cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete); - cdata->handle.MarkIndependent(); -#else +#elif (SWIG_V8_VERSION < 0x031918) cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete); -# if (SWIG_V8_VERSION < 0x032100) - cdata->handle.MarkIndependent(v8::Isolate::GetCurrent()); -# else - cdata->handle.MarkIndependent(); -# endif +#elif (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) + cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete); +#else + cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete); +// v8::V8::SetWeak(&cdata->handle, cdata, _wrap_SwigV8PackedData_delete); #endif - return scope.Close(obj); +#if (SWIG_V8_VERSION < 0x031710) + cdata->handle.MarkIndependent(); +#elif (SWIG_V8_VERSION < 0x032100) + cdata->handle.MarkIndependent(v8::Isolate::GetCurrent()); +#else + cdata->handle.MarkIndependent(); +#endif + + SWIGV8_ESCAPE(obj); } #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIGV8_ConvertPacked(obj, ptr, sz, ty) @@ -458,13 +599,23 @@ v8::Handle SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf * ---------------------------------------------------------------------------*/ SWIGRUNTIME + +#if (SWIG_V8_VERSION < 0x031903) v8::Handle SWIGV8_AppendOutput(v8::Handle result, v8::Handle obj) { - v8::HandleScope scope; +#else +v8::Handle SWIGV8_AppendOutput(v8::Local result, v8::Handle obj) { +#endif + SWIGV8_HANDLESCOPE_ESC(); + if (result->IsUndefined()) { - result = v8::Array::New(); + result = SWIGV8_ARRAY_NEW(); } +#if (SWIG_V8_VERSION < 0x031903) v8::Handle arr = v8::Handle::Cast(result); +#else + v8::Local arr = v8::Local::Cast(result); +#endif arr->Set(arr->Length(), obj); - return scope.Close(arr); + SWIGV8_ESCAPE(arr); } diff --git a/Lib/javascript/v8/javascriptstrings.swg b/Lib/javascript/v8/javascriptstrings.swg index 69b6836a8..65ba20e5a 100644 --- a/Lib/javascript/v8/javascriptstrings.swg +++ b/Lib/javascript/v8/javascriptstrings.swg @@ -47,13 +47,13 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size) if (carray) { if (size > INT_MAX) { // TODO: handle extra long strings - return v8::Undefined(); + return SWIGV8_UNDEFINED(); } else { - v8::Handle js_str = v8::String::New(carray, size); + v8::Handle js_str = SWIGV8_STRING_NEW2(carray, size); return js_str; } } else { - return v8::Undefined(); + return SWIGV8_UNDEFINED(); } } } diff --git a/Lib/javascript/v8/javascripttypemaps.swg b/Lib/javascript/v8/javascripttypemaps.swg index 90317a1c7..4601698e0 100644 --- a/Lib/javascript/v8/javascripttypemaps.swg +++ b/Lib/javascript/v8/javascripttypemaps.swg @@ -26,7 +26,7 @@ /* Javascript types */ #define SWIG_Object v8::Handle -#define VOID_Object v8::Undefined() +#define VOID_Object SWIGV8_UNDEFINED() /* Overload of the output/constant/exception/dirout handling */ diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index 60e418596..892d15798 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -44,6 +44,9 @@ %typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { SWIG_LUA_CONSTTAB_POINTER("$symname",$value, $1_descriptor) } +%typemap(consttab) SWIGTYPE + { SWIG_LUA_CONSTTAB_POINTER("$symname",&$value, $&1_descriptor) } + // member function pointers %typemap(consttab) SWIGTYPE (CLASS::*) { SWIG_LUA_CONSTTAB_BINARY("$symname", sizeof($type),&$value, $1_descriptor) } diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 8803c66f6..d9124887d 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -1161,7 +1161,7 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss) #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* Merges two tables */ -SWIGINTERN int SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source) +SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source) { /* iterating */ lua_pushnil(L); @@ -1177,7 +1177,7 @@ SWIGINTERN int SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int sour } /* Merges two tables with given name. original - index of target metatable, base - index of source metatable */ -SWIGINTERN int SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base) +SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base) { /* push original[name], then base[name] */ lua_pushstring(L,name); @@ -1192,7 +1192,7 @@ SWIGINTERN int SWIG_Lua_merge_tables(lua_State *L, const char* name, int origina } /* Function takes all symbols from base and adds it to derived class. It's just a helper. */ -SWIGINTERN int SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls) +SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls) { /* There is one parameter - original, i.e. 'derived' class metatable */ assert(lua_istable(L,-1)); @@ -1206,7 +1206,7 @@ SWIGINTERN int SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls } /* Function squashes all symbols from 'clss' bases into itself */ -SWIGINTERN int SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss) +SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss) { int i; SWIG_Lua_get_class_metatable(L,clss->fqname); diff --git a/Lib/octave/boost_shared_ptr.i b/Lib/octave/boost_shared_ptr.i index 93b1a896f..052d48bb0 100644 --- a/Lib/octave/boost_shared_ptr.i +++ b/Lib/octave/boost_shared_ptr.i @@ -29,7 +29,8 @@ } } %typemap(out) CONST TYPE { - %set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } %typemap(varin) CONST TYPE { @@ -47,7 +48,8 @@ } } %typemap(varout) CONST TYPE { - %set_varoutput(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } // plain pointer diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index dc9b6b6e6..b5c3e5d86 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -578,26 +578,40 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); swig_member_const_iterator swig_members_begin() { return members.begin(); } swig_member_const_iterator swig_members_end() { return members.end(); } - void *cast(swig_type_info *type, int *_own, int flags) { + int cast(void **vptr, swig_type_info *type, int *_own, int flags) { + int res = SWIG_ERROR; if (_own) *_own = own; if (flags &SWIG_POINTER_DISOWN) own = 0; - if (!type && types.size()) - return types[0].second.ptr; + if (!type && types.size()) { + if(vptr) + *vptr = types[0].second.ptr; + return SWIG_OK; + } for (unsigned int j = 0; j < types.size(); ++j) - if (type == types[j].first) - return types[j].second.ptr; + if (type == types[j].first) { + if(vptr) + *vptr = types[j].second.ptr; + return SWIG_OK; + } for (unsigned int j = 0; j < types.size(); ++j) { swig_cast_info *tc = SWIG_TypeCheck(types[j].first->name, type); if (!tc) continue; - int newmemory = 0; - void *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory); - assert(!newmemory); // newmemory handling not yet implemented - return vptr; + if(vptr) { + int newmemory = 0; + *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(_own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ + if (_own) + *_own = *_own | SWIG_CAST_NEW_MEMORY; + } + } + res = SWIG_OK; + break; } - return 0; + return res; } bool is_owned() const { @@ -1327,12 +1341,7 @@ SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_t return SWIG_ERROR; octave_swig_ref *osr = static_cast < octave_swig_ref *>(ov.internal_rep()); octave_swig_type *ost = osr->get_ptr(); - void *vptr = ost->cast(type, own, flags); - if (!vptr) - return SWIG_ERROR; - if (ptr) - *ptr = vptr; - return SWIG_OK; + return ost->cast(ptr, type, own, flags); } SWIGRUNTIME octave_value SWIG_Octave_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { diff --git a/Lib/octave/std_shared_ptr.i b/Lib/octave/std_shared_ptr.i new file mode 100644 index 000000000..df873679c --- /dev/null +++ b/Lib/octave/std_shared_ptr.i @@ -0,0 +1,2 @@ +#define SWIG_SHARED_PTR_NAMESPACE std +%include diff --git a/Lib/perl5/perlinit.swg b/Lib/perl5/perlinit.swg index d9ffa9bf8..cdb73d53a 100644 --- a/Lib/perl5/perlinit.swg +++ b/Lib/perl5/perlinit.swg @@ -21,7 +21,7 @@ SWIGEXPORT void SWIG_init (CV *cv, CPerlObj *); %init %{ -#ifdef __cplusplus +#if defined(__cplusplus) && ! defined(XSPROTO) extern "C" #endif diff --git a/Lib/php/const.i b/Lib/php/const.i index 329b0cf07..061ba99a2 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -14,7 +14,7 @@ signed char, bool, enum SWIGTYPE - "SWIG_LONG_CONSTANT($symname, $value);"; + "SWIG_LONG_CONSTANT($symname, ($1_type)$value);"; %typemap(consttab) float, double diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 06eeb73b0..92c149999 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -98,8 +98,7 @@ namespace Swig { TSRMLS_SET_CTX(swig_zts_ctx); } - bool swig_is_overridden_method(char *cname, char *lc_fname) { - TSRMLS_FETCH_FROM_CTX(swig_zts_ctx); + static bool swig_is_overridden_method(char *cname, char *lc_fname TSRMLS_DC) { zend_class_entry **ce; zend_function *mptr; diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index 56f921434..4f21c5cbf 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -34,7 +34,7 @@ zval *z_var; MAKE_STD_ZVAL(z_var); z_var->type = IS_LONG; - z_var->value.lval = $1; + z_var->value.lval = (long)$1; zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL); } diff --git a/Lib/php/php.swg b/Lib/php/php.swg index afa047ef6..8b5fb7be3 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -93,10 +93,12 @@ %typemap(directorout) SWIGTYPE ($&1_ltype tmp) { - if(SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + /* If exit was via exception, PHP NULL is returned so skip the conversion. */ + if (!EG(exception)) { + if(SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + $result = *tmp; } - $result = *tmp; } %typemap(in) SWIGTYPE *, diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index 14f37d2ff..36e535f52 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -625,6 +625,28 @@ PHPBN2(MYSQLI_SERVER_PUBLIC_KEY); /* Added in PHP 5.6 */ PHPBN2(LDAP_ESCAPE_DN); PHPBN2(LDAP_ESCAPE_FILTER); +PHPBN2(OPENSSL_DEFAULT_STREAM_CIPHERS); +PHPBN2(STREAM_CRYPTO_METHOD_ANY_CLIENT); +PHPBN2(STREAM_CRYPTO_METHOD_ANY_SERVER); +PHPBN2(STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT); +PHPBN2(STREAM_CRYPTO_METHOD_TLSv1_0_SERVER); +PHPBN2(STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT); +PHPBN2(STREAM_CRYPTO_METHOD_TLSv1_1_SERVER); +PHPBN2(STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT); +PHPBN2(STREAM_CRYPTO_METHOD_TLSv1_2_SERVER); +PHPBN2(PGSQL_CONNECT_ASYNC); +PHPBN2(PGSQL_CONNECTION_AUTH_OK); +PHPBN2(PGSQL_CONNECTION_AWAITING_RESPONSE); +PHPBN2(PGSQL_CONNECTION_MADE); +PHPBN2(PGSQL_CONNECTION_SETENV); +PHPBN2(PGSQL_CONNECTION_SSL_STARTUP); +PHPBN2(PGSQL_CONNECTION_STARTED); +PHPBN2(PGSQL_DML_ESCAPE); +PHPBN2(PGSQL_POLLING_ACTIVE); +PHPBN2(PGSQL_POLLING_FAILED); +PHPBN2(PGSQL_POLLING_OK); +PHPBN2(PGSQL_POLLING_READING); +PHPBN2(PGSQL_POLLING_WRITING); /* Class names reserved by PHP (case insensitive) */ PHPCN(directory); diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 6d922bcad..00d8bc560 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -153,7 +153,7 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject } Z_SET_REFCOUNT_P(z, 1); Z_SET_ISREF_P(z); - zend_hash_update(HASH_OF(z), (char*)"_cPtr", sizeof("_cPtr"), (void*)&resource, sizeof(zval), NULL); + zend_hash_update(HASH_OF(z), (char*)"_cPtr", sizeof("_cPtr"), (void*)&resource, sizeof(zval*), NULL); } return; } diff --git a/Lib/pointer.i b/Lib/pointer.i index 8015317d7..ea8e535ab 100644 --- a/Lib/pointer.i +++ b/Lib/pointer.i @@ -4,7 +4,7 @@ %echo "pointer.i is deprecated. Use cpointer.i instead." -%echo "See http://www.swig.org/Doc1.3/Library.html" +%echo "See http://www.swig.org/Doc3.0/Library.html" diff --git a/Lib/python/pyclasses.swg b/Lib/python/pyclasses.swg index b73ebdbb8..9d6299ff1 100644 --- a/Lib/python/pyclasses.swg +++ b/Lib/python/pyclasses.swg @@ -72,27 +72,35 @@ namespace swig { SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; } SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) { if (initial_ref) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; } } SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(item._obj); Py_XDECREF(_obj); _obj = item._obj; + SWIG_PYTHON_THREAD_END_BLOCK; return *this; } ~SwigPtr_PyObject() { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XDECREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; } operator PyObject *() const diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index dcada87c7..e5543cd6b 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -710,7 +710,8 @@ namespace swig #if defined(SWIGPYTHON_BUILTIN) %feature("python:slot", "tp_iter", functype="getiterfunc") iterator; #else - %pythoncode {def __iter__(self): return self.iterator()} + %pythoncode {def __iter__(self): + return self.iterator()} #endif } @@ -873,6 +874,13 @@ namespace swig *(swig::getpos(self,i)) = x; } +#if defined(SWIGPYTHON_BUILTIN) + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(difference_type i) throw (std::out_of_range) { + self->erase(swig::getpos(self,i)); + } +#endif + void append(const value_type& x) { self->push_back(x); } @@ -891,6 +899,13 @@ namespace swig *(swig::getpos(self,i)) = x; } +#if defined(SWIGPYTHON_BUILTIN) + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(difference_type i) throw (std::out_of_range) { + self->erase(swig::getpos(self,i)); + } +#endif + void append(value_type x) { self->push_back(x); } diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index b44c2c893..47d3d9700 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -375,6 +375,7 @@ SWIG_init(void) { PyObject *public_interface, *public_symbol; PyObject *this_descr; PyObject *thisown_descr; + PyObject *self = 0; int i; (void)builtin_pytype; @@ -382,6 +383,7 @@ SWIG_init(void) { (void)builtin_basetype; (void)tuple; (void)static_getset; + (void)self; /* metatype is used to implement static member variables. */ metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type); @@ -401,6 +403,7 @@ SWIG_init(void) { #else m = Py_InitModule((char *) SWIG_name, SwigMethods); #endif + md = d = PyModule_GetDict(m); (void)md; diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index f93594c4c..110c431fe 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -344,7 +344,8 @@ namespace swig %feature("python:slot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__; #else %extend SwigPyIterator { - %pythoncode {def __iter__(self): return self} + %pythoncode {def __iter__(self): + return self} } #endif diff --git a/Lib/python/pythonkw.swg b/Lib/python/pythonkw.swg index 8ad0ef11b..2f76a664a 100644 --- a/Lib/python/pythonkw.swg +++ b/Lib/python/pythonkw.swg @@ -130,7 +130,7 @@ PYTHONKW(None); /* 'self' is also a bad Name */ -PYTHONBN(self); +PYTHONKW(self); #undef PYTHONBN #undef PYTHONKW diff --git a/Lib/python/pyuserdir.swg b/Lib/python/pyuserdir.swg index d3c3eb188..00aec07d5 100644 --- a/Lib/python/pyuserdir.swg +++ b/Lib/python/pyuserdir.swg @@ -185,7 +185,6 @@ These methods "may be called" if needed. #define %clearpythonappend %feature("pythonappend","") - /* ------------------------------------------------------------------------- */ /* %extend_smart_pointer extend the smart pointer support. diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 66ed68da5..58902bca4 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -176,10 +176,14 @@ #else %extend { - %pythoncode {def __iter__(self): return self.key_iterator()} - %pythoncode {def iterkeys(self): return self.key_iterator()} - %pythoncode {def itervalues(self): return self.value_iterator()} - %pythoncode {def iteritems(self): return self.iterator()} + %pythoncode {def __iter__(self): + return self.key_iterator()} + %pythoncode {def iterkeys(self): + return self.key_iterator()} + %pythoncode {def itervalues(self): + return self.value_iterator()} + %pythoncode {def iteritems(self): + return self.iterator()} } #endif diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index 782969574..73d47e198 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -176,18 +176,20 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c) %define %swig_pair_methods(pair...) #if !defined(SWIGPYTHON_BUILTIN) %extend { -%pythoncode {def __len__(self): return 2 -def __repr__(self): return str((self.first, self.second)) +%pythoncode {def __len__(self): + return 2 +def __repr__(self): + return str((self.first, self.second)) def __getitem__(self, index): - if not (index % 2): - return self.first - else: - return self.second + if not (index % 2): + return self.first + else: + return self.second def __setitem__(self, index, val): - if not (index % 2): - self.first = val - else: - self.second = val} + if not (index % 2): + self.first = val + else: + self.second = val} } #endif %enddef diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i index b456035e2..737468234 100644 --- a/Lib/python/std_unordered_map.i +++ b/Lib/python/std_unordered_map.i @@ -231,10 +231,14 @@ return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); } - %pythoncode {def __iter__(self): return self.key_iterator()} - %pythoncode {def iterkeys(self): return self.key_iterator()} - %pythoncode {def itervalues(self): return self.value_iterator()} - %pythoncode {def iteritems(self): return self.iterator()} + %pythoncode {def __iter__(self): + return self.key_iterator()} + %pythoncode {def iterkeys(self): + return self.key_iterator()} + %pythoncode {def itervalues(self): + return self.value_iterator()} + %pythoncode {def iteritems(self): + return self.iterator()} } %enddef diff --git a/Lib/r/rfragments.swg b/Lib/r/rfragments.swg index afb75c3c1..2ec8f867f 100644 --- a/Lib/r/rfragments.swg +++ b/Lib/r/rfragments.swg @@ -153,7 +153,7 @@ SWIG_strdup(const char *str) } } -# This is modified from the R header files +//# This is modified from the R header files %fragment("SWIG_FromCharPtrAndSize","header") { diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 9e5aa7b6d..22639f2d0 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -149,34 +149,22 @@ string &, std::string & %typemap(scoerceout) enum SWIGTYPE *const %{ $result = enumToInteger($result, "$R_class"); %} -#%typemap(scoerceout) SWIGTYPE -# %{ class($result) <- "$&R_class"; %} +%typemap(scoerceout) SEXP %{ %} -#%typemap(scoerceout) SWIGTYPE & -# %{ class($result) <- "$R_class"; %} - -#%typemap(scoerceout) SWIGTYPE * -# %{ class($result) <- "$R_class"; %} - -#%typemap(scoerceout) SWIGTYPE *const -# %{ class($result) <- "$R_class"; %} - - %typemap(scoerceout) SEXP %{ %} - - %typemap(scoerceout) SWIGTYPE - %{ $result <- new("$&R_class", ref=$result); %} +%typemap(scoerceout) SWIGTYPE + %{ $result <- new("$&R_class", ref=$result); %} - %typemap(scoerceout) SWIGTYPE & - %{ $result <- new("$R_class", ref=$result) ; %} +%typemap(scoerceout) SWIGTYPE & + %{ $result <- new("$R_class", ref=$result) ; %} - %typemap(scoerceout) SWIGTYPE && - %{ $result <- new("$R_class", ref=$result) ; %} +%typemap(scoerceout) SWIGTYPE && + %{ $result <- new("$R_class", ref=$result) ; %} - %typemap(scoerceout) SWIGTYPE * - %{ $result <- new("$R_class", ref=$result) ; %} +%typemap(scoerceout) SWIGTYPE * + %{ $result <- new("$R_class", ref=$result) ; %} - %typemap(scoerceout) SWIGTYPE *const - %{ $result <- new("$R_class", ref=$result) ; %} +%typemap(scoerceout) SWIGTYPE *const + %{ $result <- new("$R_class", ref=$result) ; %} /* Override the SWIGTYPE * above. */ diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg index 5537136af..f7b51bdcc 100644 --- a/Lib/ruby/rubyclasses.swg +++ b/Lib/ruby/rubyclasses.swg @@ -37,9 +37,6 @@ %fragment("GC_VALUE_definition","header") { namespace swig { class SwigGCReferences { - // Hash of all GC_VALUE's currently in use - static SwigGCReferences s_references; - VALUE _hash; SwigGCReferences() : _hash(Qnil) { @@ -50,13 +47,18 @@ namespace swig { } static void EndProcHandler(VALUE) { // Ruby interpreter ending - _hash can no longer be accessed. + SwigGCReferences &s_references = instance(); s_references._hash = Qnil; } public: static SwigGCReferences& instance() { + // Hash of all GC_VALUE's currently in use + static SwigGCReferences s_references; + return s_references; } static void initialize() { + SwigGCReferences &s_references = instance(); if (s_references._hash == Qnil) { rb_set_end_proc(&EndProcHandler, Qnil); s_references._hash = rb_hash_new(); @@ -81,13 +83,13 @@ namespace swig { if (BUILTIN_TYPE(obj) == T_NONE) return; if (_hash != Qnil) { - VALUE val = rb_hash_aref(s_references._hash, obj); + VALUE val = rb_hash_aref(_hash, obj); unsigned n = FIXNUM_P(val) ? NUM2UINT(val) : 1; --n; if (n) - rb_hash_aset(s_references._hash, obj, INT2NUM(n)); + rb_hash_aset(_hash, obj, INT2NUM(n)); else - rb_hash_delete(s_references._hash, obj); + rb_hash_delete(_hash, obj); } } }; @@ -302,8 +304,6 @@ namespace swig { ID GC_VALUE::lshift_id = rb_intern("<<"); ID GC_VALUE::rshift_id = rb_intern(">>"); - SwigGCReferences SwigGCReferences::s_references; - typedef GC_VALUE LANGUAGE_OBJ; } // namespace swig diff --git a/Lib/std/std_ios.i b/Lib/std/std_ios.i index 75484f3de..db83c7abf 100644 --- a/Lib/std/std_ios.i +++ b/Lib/std/std_ios.i @@ -242,17 +242,19 @@ namespace std { // 27.4.5.1 basic_ios constructors basic_ios(); private: - ios_base(const ios_base&); + basic_ios(const basic_ios&); - ios_base& - operator=(const ios_base&); + basic_ios& + operator=(const basic_ios&); }; } namespace std { + typedef basic_ios ios; %template(ios) basic_ios; #if defined(SWIG_WCHAR) + typedef basic_ios wios; %template(wios) basic_ios; #endif } diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg index 69e368ac1..cb72c36eb 100644 --- a/Lib/swiginit.swg +++ b/Lib/swiginit.swg @@ -55,7 +55,7 @@ SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; - int found, init; + int init; /* check to see if the circular list has been setup, if not, set it up */ if (swig_module.next==0) { @@ -74,22 +74,18 @@ SWIG_InitializeModule(void *clientdata) { /* This is the first module loaded for this interpreter */ /* so set the swig module into the interpreter */ SWIG_SetModule(clientdata, &swig_module); - module_head = &swig_module; } else { /* the interpreter has loaded a SWIG module, but has it loaded this one? */ - found=0; iter=module_head; do { if (iter==&swig_module) { - found=1; - break; + /* Our module is already in the list, so there's nothing more to do. */ + return; } iter=iter->next; } while (iter!= module_head); - /* if the is found in the list, then all is done and we may leave */ - if (found) return; - /* otherwise we must add out module into the list */ + /* otherwise we must add our module into the list */ swig_module.next = module_head->next; module_head->next = &swig_module; } diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i index 78f6e3276..ade2b0ad1 100644 --- a/Lib/tcl/std_map.i +++ b/Lib/tcl/std_map.i @@ -1,7 +1,5 @@ // // SWIG typemaps for std::map -// Luigi Ballabio -// Jan. 2003 // // Common implementation diff --git a/Lib/typemaps/attribute.swg b/Lib/typemaps/attribute.swg index f06c8c0f3..988113991 100644 --- a/Lib/typemaps/attribute.swg +++ b/Lib/typemaps/attribute.swg @@ -137,7 +137,7 @@ // // Define SWIG_ATTRIBUTE_TEMPLATE if you want to use templates instead of macros for the C++ get and set wrapper methods -// Does not always generate compileable code, use at your peril! +// Does not always generate compilable code, use at your peril! // //#define SWIG_ATTRIBUTE_TEMPLATE diff --git a/README b/README index 746bad7e1..cbfc708ea 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 3.0.2 (4 Jun 2014) +Version: 3.0.5 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, diff --git a/RELEASENOTES b/RELEASENOTES index 38fbe60e7..2aff1d265 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,15 @@ and CHANGES files. Release Notes ============= +SWIG-3.0.4 summary: +- Python regression fix when wrapping C++ default arguments. +- Improved error messages. + +SWIG-3.0.3 summary: +- Add support for C++11 strongly typed enumerations. +- Numerous bug fixes and minor enhancements for C#, D, Go, Java, + Javascript, PHP, Perl and Python wrappers. + SWIG-3.0.2 summary: - Bug fix during install and a couple of other minor changes. diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index 5a0d52d23..84a486fb7 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -27,6 +27,7 @@ extern "C" { extern int cparse_cplusplus; extern int cparse_cplusplusout; extern int cparse_start_line; + extern String *cparse_unknown_directive; extern void Swig_cparse_cplusplus(int); extern void Swig_cparse_cplusplusout(int); diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index de00e2b1f..d86c4590a 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -40,6 +40,9 @@ int cparse_cplusplus = 0; /* Generate C++ compatible code when wrapping C code */ int cparse_cplusplusout = 0; +/* To allow better error reporting */ +String *cparse_unknown_directive = 0; + /* Private vars */ static int scan_init = 0; static int num_brace = 0; @@ -147,7 +150,7 @@ String *get_raw_text_balanced(int startchar, int endchar) { * friend ostream& operator<<(ostream&, const char *s); * * or - * friend ostream& operator<<(ostream&, const char *s) { }; + * friend ostream& operator<<(ostream&, const char *s) { } * * ------------------------------------------------------------------------- */ @@ -801,8 +804,11 @@ int yylex(void) { if (strcmp(yytext, "inline") == 0) return (yylex()); - /* SWIG directives */ } else { + Delete(cparse_unknown_directive); + cparse_unknown_directive = NULL; + + /* SWIG directives */ if (strcmp(yytext, "%module") == 0) return (MODULE); if (strcmp(yytext, "%insert") == 0) @@ -878,6 +884,9 @@ int yylex(void) { } if (strcmp(yytext, "%warn") == 0) return (WARN); + + /* Note down the apparently unknown directive for error reporting. */ + cparse_unknown_directive = Swig_copy_string(yytext); } /* Have an unknown identifier, as a last step, we'll do a typedef lookup on it. */ diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 4ce8f0e6d..1fb759081 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -59,6 +59,7 @@ static int compact_default_args = 0; static int template_reduce = 0; static int cparse_externc = 0; int ignore_nested_classes = 0; +int kwargs_supported = 0; /* ----------------------------------------------------------------------------- * Assist Functions * ----------------------------------------------------------------------------- */ @@ -1017,7 +1018,7 @@ static Node *nested_forward_declaration(const char *storage, const char *kind, S } } - if (!GetFlag(currentOuterClass, "nested")) { + if (!currentOuterClass || !GetFlag(currentOuterClass, "nested")) { if (nn && Equal(nodeType(nn), "classforward")) { Node *n = nn; SWIG_WARN_NODE_BEGIN(n); @@ -1177,7 +1178,7 @@ static void default_arguments(Node *n) { if (compact_default_args || is_cfunction(function) || GetFlag(function,"feature:compactdefaultargs") - || GetFlag(function,"feature:kwargs")) { + || (GetFlag(function,"feature:kwargs") && kwargs_supported)) { ParmList *p = Getattr(function,"parms"); if (p) Setattr(p,"compactdefargs", "1"); /* mark parameters for special handling */ @@ -1509,7 +1510,11 @@ declaration : swig_directive { $$ = $1; } | SEMI { $$ = 0; } | error { $$ = 0; - Swig_error(cparse_file, cparse_line,"Syntax error in input(1).\n"); + if (cparse_unknown_directive) { + Swig_error(cparse_file, cparse_line, "Unknown directive '%s'.\n", cparse_unknown_directive); + } else { + Swig_error(cparse_file, cparse_line, "Syntax error in input(1).\n"); + } exit(1); } /* Out of class constructor/destructor declarations */ @@ -1880,6 +1885,7 @@ include_directive: includetype options string BEGINFILE { Node *nint = new_node("import"); Node *mnode = new_node("module"); Setattr(mnode,"name", mname); + Setattr(mnode,"options",$2); appendChild(nint,mnode); Delete(mnode); appendChild(nint,firstChild($$)); @@ -2502,6 +2508,7 @@ types_directive : TYPES LPAREN parms RPAREN stringbracesemi { template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN valparms GREATERTHAN SEMI { Parm *p, *tp; Node *n; + Node *outer_class = currentOuterClass; Symtab *tscope = 0; int specialized = 0; int variadic = 0; @@ -2514,6 +2521,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va if (!inclass) { $5 = resolve_create_node_scope($5); } + if (nscope_inner && Strcmp(nodeType(nscope_inner), "class") == 0) { + outer_class = nscope_inner; + } /* We use the new namespace entry 'nscope' only to @@ -2646,7 +2656,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Setattr(templnode,"sym:typename","1"); } /* for now, nested %template is allowed only in the same scope as the template declaration */ - if ($3 && !(nnisclass && ((currentOuterClass && (currentOuterClass != Getattr(nn, "nested:outer"))) + if ($3 && !(nnisclass && ((outer_class && (outer_class != Getattr(nn, "nested:outer"))) ||(extendmode && current_class && (current_class != Getattr(nn, "nested:outer")))))) { /* Comment this out for 1.3.28. We need to @@ -2675,9 +2685,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Setfile(templnode,cparse_file); Setline(templnode,cparse_line); Delete(temparms); - if (currentOuterClass) { + if (outer_class && nnisclass) { SetFlag(templnode, "nested"); - Setattr(templnode, "nested:outer", currentOuterClass); + Setattr(templnode, "nested:outer", outer_class); } add_symbols_copy(templnode); @@ -3014,6 +3024,15 @@ c_decl_tail : SEMI { skip_balanced('{','}'); $$ = 0; } + | error { + $$ = 0; + if (yychar == RPAREN) { + Swig_error(cparse_file, cparse_line, "Unexpected ')'.\n"); + } else { + Swig_error(cparse_file, cparse_line, "Syntax error - possibly a missing semicolon.\n"); + } + exit(1); + } ; initializer : def_args { @@ -3449,8 +3468,14 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { nscope = Getattr($$, "nested:nscope"); Delattr($$, "nested:innerscope"); Delattr($$, "nested:nscope"); - if (nscope_inner && Strcmp(nodeType(nscope_inner), "class") == 0) /* actual parent class for this class */ - Setattr($$, "nested:outer", nscope_inner); + if (nscope_inner && Strcmp(nodeType(nscope_inner), "class") == 0) { /* actual parent class for this class */ + Node* forward_declaration = Swig_symbol_clookup_no_inherit(Getattr($$,"name"), Getattr(nscope_inner, "symtab")); + if (forward_declaration) { + Setattr($$, "access", Getattr(forward_declaration, "access")); + } + Setattr($$, "nested:outer", nscope_inner); + SetFlag($$, "nested"); + } if (!currentOuterClass) inclass = 0; cscope = Getattr($$, "prev_symtab"); @@ -3529,6 +3554,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { } else if (nscope_inner) { /* this is tricky */ /* we add the declaration in the original namespace */ + if (Strcmp(nodeType(nscope_inner), "class") == 0 && cparse_cplusplus && ignore_nested_classes && !GetFlag($$, "feature:flatnested")) + $$ = nested_forward_declaration($1, $2, $3, Copy($3), $9); appendChild(nscope_inner, $$); Swig_symbol_setscope(Getattr(nscope_inner, "symtab")); Delete(Namespaceprefix); @@ -4007,7 +4034,9 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { Swig_symbol_setscope(cscope); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); - if (error) $$ = 0; + if (error || (nscope_inner && Strcmp(nodeType(nscope_inner), "class") == 0)) { + $$ = 0; + } if (currentOuterClass) template_parameters = Getattr(currentOuterClass, "template_parameters"); else @@ -4651,7 +4680,10 @@ storage_class : EXTERN { $$ = "extern"; } | FRIEND { $$ = "friend"; } | EXPLICIT { $$ = "explicit"; } | CONSTEXPR { $$ = "constexpr"; } + | EXPLICIT CONSTEXPR { $$ = "explicit constexpr"; } + | CONSTEXPR EXPLICIT { $$ = "explicit constexpr"; } | STATIC CONSTEXPR { $$ = "static constexpr"; } + | CONSTEXPR STATIC { $$ = "static constexpr"; } | THREAD_LOCAL { $$ = "thread_local"; } | THREAD_LOCAL STATIC { $$ = "static thread_local"; } | STATIC THREAD_LOCAL { $$ = "static thread_local"; } diff --git a/Source/DOH/string.c b/Source/DOH/string.c index 3e02e05d1..cfc6c70f6 100644 --- a/Source/DOH/string.c +++ b/Source/DOH/string.c @@ -181,10 +181,10 @@ static int String_hash(DOH *so) { return s->hashkey; } else { register char *c = s->str; - register int len = s->len > 50 ? 50 : s->len; - register int h = 0; - register int mlen = len >> 2; - register int i = mlen; + register unsigned int len = s->len > 50 ? 50 : s->len; + register unsigned int h = 0; + register unsigned int mlen = len >> 2; + register unsigned int i = mlen; for (; i; --i) { h = (h << 5) + *(c++); h = (h << 5) + *(c++); @@ -195,7 +195,7 @@ static int String_hash(DOH *so) { h = (h << 5) + *(c++); } h &= 0x7fffffff; - s->hashkey = h; + s->hashkey = (int)h; return h; } } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index d30bd18c5..3b1e03560 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -627,9 +627,11 @@ public: * ----------------------------------------------------------------------------- */ void emitBanner(File *f) { - Printf(f, "/* ----------------------------------------------------------------------------\n"); - Swig_banner_target_lang(f, " *"); - Printf(f, " * ----------------------------------------------------------------------------- */\n\n"); + Printf(f, "//------------------------------------------------------------------------------\n"); + Printf(f, "// \n"); + Printf(f, "//\n"); + Swig_banner_target_lang(f, "//"); + Printf(f, "//------------------------------------------------------------------------------\n\n"); } /*----------------------------------------------------------------------- @@ -717,7 +719,7 @@ public: String *overloaded_name = getOverloadedName(n); if (!Getattr(n, "sym:overloaded")) { - if (!addSymbol(Getattr(n, "sym:name"), n, imclass_name)) + if (!addSymbol(symname, n, imclass_name)) return SWIG_ERROR; } @@ -912,21 +914,10 @@ public: String *null_attribute = 0; // Now write code to make the function call if (!native_function_flag) { - if (Cmp(nodeType(n), "constant") == 0) { - // Wrapping a constant hack - Swig_save("functionWrapper", n, "wrap:action", NIL); - - // below based on Swig_VargetToFunction() - SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); - Setattr(n, "wrap:action", NewStringf("%s = (%s)(%s);", Swig_cresult_name(), SwigType_lstr(ty, 0), Getattr(n, "value"))); - } Swig_director_emit_dynamic_cast(n, f); String *actioncode = emit_action(n); - if (Cmp(nodeType(n), "constant") == 0) - Swig_restore(n); - /* Return value if necessary */ if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) { canThrow(n, "out", n); @@ -1088,15 +1079,13 @@ public: return ret; } - String *getCurrentScopeName(String *nspace) - { + String *getCurrentScopeName(String *nspace) { String *scope = 0; if (nspace || getCurrentClass()) { scope = NewString(""); if (nspace) Printf(scope, "%s", nspace); - if (Node* cls = getCurrentClass()) - { + if (Node* cls = getCurrentClass()) { if (Node *outer = Getattr(cls, "nested:outer")) { String *outerClassesPrefix = Copy(Getattr(outer, "sym:name")); for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { @@ -1266,6 +1255,7 @@ public: int unnamedinstance = GetFlag(parent, "unnamedinstance"); String *parent_name = Getattr(parent, "name"); String *nspace = getNSpace(); + String *newsymname = 0; String *tmpValue; // Strange hack from parent method @@ -1290,14 +1280,20 @@ public: { EnumFeature enum_feature = decodeEnumFeature(parent); + if ((enum_feature == SimpleEnum) && GetFlag(parent, "scopedenum")) { + newsymname = Swig_name_member(0, Getattr(parent, "sym:name"), symname); + symname = newsymname; + } + // Add to language symbol table String *scope = 0; if (unnamedinstance || !parent_name || enum_feature == SimpleEnum) { - if (proxy_class_name) { + String *enumClassPrefix = getEnumClassPrefix(); + if (enumClassPrefix) { scope = NewString(""); if (nspace) Printf(scope, "%s.", nspace); - Printf(scope, "%s", proxy_class_name); + Printf(scope, "%s", enumClassPrefix); } else { scope = Copy(module_class_name); } @@ -1308,7 +1304,7 @@ public: else Printf(scope, ".%s", Getattr(parent, "sym:name")); } - if (!addSymbol(name, n, scope)) + if (!addSymbol(symname, n, scope)) return SWIG_ERROR; const String *csattributes = Getattr(n, "feature:cs:attributes"); @@ -1380,6 +1376,7 @@ public: Delete(scope); } + Delete(newsymname); Delete(tmpValue); Swig_restore(n); return SWIG_OK; @@ -3053,6 +3050,16 @@ public: // Use the C syntax to make a true C# constant and hope that it compiles as C# code value = Getattr(n, "enumvalue") ? Copy(Getattr(n, "enumvalue")) : Copy(Getattr(n, "enumvalueex")); } else { + String *newsymname = 0; + if (!getCurrentClass() || !proxy_flag) { + String *enumClassPrefix = getEnumClassPrefix(); + if (enumClassPrefix) { + // A global scoped enum + newsymname = Swig_name_member(0, enumClassPrefix, symname); + symname = newsymname; + } + } + // Get the enumvalue from a PINVOKE call if (!getCurrentClass() || !cparse_cplusplus || !proxy_flag) { // Strange hack to change the name @@ -3061,7 +3068,7 @@ public: value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); } else { memberconstantHandler(n); - value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), Swig_name_member(0, proxy_class_name, symname))); + value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), Swig_name_member(0, getEnumClassPrefix(), symname))); } } } @@ -3198,43 +3205,6 @@ public: Delete(replacementname); } - /* ----------------------------------------------------------------------------- - * makeParameterName() - * - * Inputs: - * n - Node - * p - parameter node - * arg_num - parameter argument number - * setter - set this flag when wrapping variables - * Return: - * arg - a unique parameter name - * ----------------------------------------------------------------------------- */ - - String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter) { - - String *arg = 0; - String *pn = Getattr(p, "name"); - - // Use C parameter name unless it is a duplicate or an empty parameter name - int count = 0; - ParmList *plist = Getattr(n, "parms"); - while (plist) { - if ((Cmp(pn, Getattr(plist, "name")) == 0)) - count++; - plist = nextSibling(plist); - } - String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0; - arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn); - - if (setter && Cmp(arg, "self") != 0) { - // Note that in C# properties, the input variable name is always called 'value' - Delete(arg); - arg = NewString("value"); - } - - return arg; - } - /* ----------------------------------------------------------------------------- * emitTypeWrapperClass() * ----------------------------------------------------------------------------- */ @@ -4283,6 +4253,10 @@ public: Delete(dirclassname); } + /*---------------------------------------------------------------------- + * nestedClassesSupport() + *--------------------------------------------------------------------*/ + NestedClassSupport nestedClassesSupport() const { return NCS_Full; } diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 419828ea1..8546372ea 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -803,24 +803,24 @@ public: // Emit each enum item. Language::enumDeclaration(n); - if (!GetFlag(n, "nonempty")) { - // Do not wrap empty enums; the resulting D code would be illegal. - Delete(proxy_enum_code); - return SWIG_NOWRAP; - } - - // Finish the enum. - if (typemap_lookup_type) { - Printv(proxy_enum_code, - lookupCodeTypemap(n, "dcode", typemap_lookup_type, WARN_NONE), // Extra D code - "\n}\n", NIL); + if (GetFlag(n, "nonempty")) { + // Finish the enum. + if (typemap_lookup_type) { + Printv(proxy_enum_code, + lookupCodeTypemap(n, "dcode", typemap_lookup_type, WARN_NONE), // Extra D code + "\n}\n", NIL); + } else { + // Handle anonymous enums. + Printv(proxy_enum_code, "\n}\n", NIL); + } + Replaceall(proxy_enum_code, "$dclassname", symname); } else { - // Handle anonymous enums. - Printv(proxy_enum_code, "\n}\n", NIL); + // D enum declarations must have at least one member to be legal, so emit + // an alias to int instead (their ctype/imtype is always int). + Delete(proxy_enum_code); + proxy_enum_code = NewStringf("\nalias int %s;\n", symname); } - Replaceall(proxy_enum_code, "$dclassname", symname); - const String* imports = lookupCodeTypemap(n, "dimports", typemap_lookup_type, WARN_NONE); String* imports_trimmed; @@ -1701,21 +1701,10 @@ public: String *null_attribute = 0; // Now write code to make the function call if (!native_function_flag) { - if (Cmp(nodeType(n), "constant") == 0) { - // Wrapping a constant hack - Swig_save("functionWrapper", n, "wrap:action", NIL); - - // below based on Swig_VargetToFunction() - SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); - Setattr(n, "wrap:action", NewStringf("%s = (%s) %s;", Swig_cresult_name(), SwigType_lstr(ty, 0), Getattr(n, "value"))); - } Swig_director_emit_dynamic_cast(n, f); String *actioncode = emit_action(n); - if (Cmp(nodeType(n), "constant") == 0) - Swig_restore(n); - /* Return value if necessary */ if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) { canThrow(n, "out", n); @@ -2594,7 +2583,7 @@ private: const_String_or_char_ptr wrapper_function_name) { // TODO: Add support for static linking here. - Printf(im_dmodule_code, "extern(C) %s function%s %s;\n", return_type, + Printf(im_dmodule_code, "SwigExternC!(%s function%s) %s;\n", return_type, parameters, d_name); Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL); Replaceall(wrapper_loader_bind_code, "$function", d_name); @@ -2850,7 +2839,7 @@ private: // polymorphic call or an explicit method call. Needed to prevent infinite // recursion when calling director methods. Node *explicit_n = Getattr(n, "explicitcallnode"); - if (explicit_n) { + if (explicit_n && Swig_directorclass(getCurrentClass())) { String *ex_overloaded_name = getOverloadedName(explicit_n); String *ex_intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, ex_overloaded_name); @@ -4299,40 +4288,8 @@ private: return proxyname; } - /* --------------------------------------------------------------------------- - * D::makeParameterName() - * - * Inputs: - * n - Node - * p - parameter node - * arg_num - parameter argument number - * setter - set this flag when wrapping variables - * Return: - * arg - a unique parameter name - * --------------------------------------------------------------------------- */ String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter) const { - String *arg = 0; - String *pn = Getattr(p, "name"); - - // Use C parameter name unless it is a duplicate or an empty parameter name - int count = 0; - ParmList *plist = Getattr(n, "parms"); - while (plist) { - if ((Cmp(pn, Getattr(plist, "name")) == 0)) - count++; - plist = nextSibling(plist); - } - String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0; - arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn); - - if (setter && Cmp(arg, "self") != 0) { - // In theory, we could use the normal parameter name for setter functions. - // Unfortunately, it is set to "Class::VariableName" for static public - // members by the parser, which is not legal D syntax. Thus, we just force - // it to "value". - Delete(arg); - arg = NewString("value"); - } + String *arg = Language::makeParameterName(n, p, arg_num, setter); if (split_proxy_dmodule && Strncmp(arg, package, Len(arg)) == 0) { // If we are in split proxy mode and the argument is named like the target diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index e84109faf..eac83a5a5 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -822,14 +822,13 @@ private: assert(result); - bool needs_wrapper; - int r = goFunctionWrapper(n, name, go_name, overname, wname, base, parms, result, is_static, &needs_wrapper); + int r = goFunctionWrapper(n, name, go_name, overname, wname, base, parms, result, is_static); if (r != SWIG_OK) { return r; } if (!gccgo_flag) { - r = gcFunctionWrapper(n, name, go_name, overname, wname, parms, result, is_static, needs_wrapper); + r = gcFunctionWrapper(wname); if (r != SWIG_OK) { return r; } @@ -862,12 +861,24 @@ private: * base class. * ---------------------------------------------------------------------- */ - int goFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static, bool *p_needs_wrapper) { + int goFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { Wrapper *dummy = NewWrapper(); emit_attach_parmmaps(parms, dummy); + + Parm *p = parms; + int parm_count = emit_num_arguments(parms); + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + Swig_cparm_name(p, i); + p = nextParm(p); + } + Swig_typemap_attach_parms("default", parms, dummy); Swig_typemap_attach_parms("gotype", parms, dummy); - int parm_count = emit_num_arguments(parms); + Swig_typemap_attach_parms("goin", parms, dummy); + Swig_typemap_attach_parms("goargout", parms, dummy); + Swig_typemap_attach_parms("imtype", parms, dummy); + int required_count = emit_num_required(parms); String *receiver = class_receiver; @@ -884,30 +895,44 @@ private: receiver = NULL; } + String *goout = Swig_typemap_lookup("goout", n, "swig_r", NULL); + bool add_to_interface = (interfaces && !is_constructor && !is_destructor && !is_static && !overname && checkFunctionVisibility(n, NULL)); bool needs_wrapper = (gccgo_flag || receiver || is_constructor || is_destructor || parm_count > required_count); - // See whether any of the function parameters are represented by - // interface values When calling the C++ code, we need to convert - // back to a uintptr. - if (!needs_wrapper) { - Parm *p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *ty = Getattr(p, "type"); - if (goTypeIsInterface(p, ty)) { - needs_wrapper = true; - break; - } - p = nextParm(p); - } + bool has_goout = false; + if (goout) { + has_goout = true; } - if (goTypeIsInterface(n, result)) { + + // See whether any of the function parameters are represented by + // interface values. When calling the C++ code, we need to convert + // back to a uintptr. + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + String *ty = Getattr(p, "type"); + if (Getattr(p, "tmap:goargout")) { + has_goout = true; + needs_wrapper = true; + } else if (goTypeIsInterface(p, ty) || Getattr(p, "tmap:goin")) { + needs_wrapper = true; + } + + if (paramNeedsEscape(p)) { + needs_wrapper = true; + } + + p = nextParm(p); + } + if (goTypeIsInterface(n, result) || goout != NULL) { needs_wrapper = true; } - *p_needs_wrapper = needs_wrapper; + if (!gccgo_flag) { + Printv(f_go_wrappers, "var ", wname, " unsafe.Pointer\n\n", NULL); + } // If this is a method, first declare the C function we will call. // If we do not need a wrapper, then we will only be writing a @@ -920,25 +945,25 @@ private: Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); } + bool arg = false; Printv(f_go_wrappers, "func ", wrapper_name, "(", NULL); if (parm_count > required_count) { - Printv(f_go_wrappers, "int", NULL); + Printv(f_go_wrappers, argName(&arg), " int", NULL); } Parm *p = getParm(parms); - Swig_cparm_name(p, 0); int i = 0; if (is_destructor) { if (parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } - Printv(f_go_wrappers, "uintptr", NULL); + Printv(f_go_wrappers, argName(&arg), " uintptr", NULL); ++i; p = nextParm(p); } else if (receiver && (base || !is_constructor)) { if (parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } - Printv(f_go_wrappers, receiver, NULL); + Printv(f_go_wrappers, argName(&arg), " ", receiver, NULL); if (!base) { ++i; p = nextParm(p); @@ -946,27 +971,37 @@ private: } for (; i < parm_count; ++i) { p = getParm(p); - // Give the parameter a name we will use below. - Swig_cparm_name(p, i); if (i > 0 || (base && receiver) || parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } String *tm = goWrapperType(p, Getattr(p, "type"), false); - Printv(f_go_wrappers, tm, NULL); + Printv(f_go_wrappers, argName(&arg), " ", tm, NULL); Delete(tm); p = nextParm(p); } Printv(f_go_wrappers, ")", NULL); if (is_constructor) { - Printv(f_go_wrappers, " ", class_receiver, NULL); + Printv(f_go_wrappers, " (", argName(&arg), " ", class_receiver, ")", NULL); } else { if (SwigType_type(result) != T_VOID) { String *tm = goWrapperType(n, result, true); - Printv(f_go_wrappers, " ", tm, NULL); + Printv(f_go_wrappers, " (", argName(&arg), " ", tm, ")", NULL); Delete(tm); } } + if (!gccgo_flag) { + Printv(f_go_wrappers, " {\n", NULL); + if (arg) { + Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&base))\n", NULL); + } else { + Printv(f_go_wrappers, "\tvar _swig_p uintptr\n", NULL); + } + Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); + Printv(f_go_wrappers, "\treturn\n", NULL); + Printv(f_go_wrappers, "}", NULL); + } + Printv(f_go_wrappers, "\n\n", NULL); } @@ -978,16 +1013,23 @@ private: Printv(f_go_wrappers, "func ", NULL); - Parm *p = parms; + p = parms; int pi = 0; // Add the receiver if this is a method. + String *first = NULL; if (receiver) { Printv(f_go_wrappers, "(", NULL); if (base && receiver) { Printv(f_go_wrappers, "_swig_base", NULL); + if (first == NULL) { + first = NewString("_swig_base"); + } } else { Printv(f_go_wrappers, Getattr(p, "lname"), NULL); + if (first == NULL) { + first = Copy(Getattr(p, "lname")); + } p = nextParm(p); ++pi; } @@ -1015,6 +1057,9 @@ private: if (pi == 0 && is_destructor) { String *cl = exportedName(class_name); Printv(parm_print, Getattr(p, "lname"), " ", cl, NULL); + if (first == NULL) { + first = Copy(Getattr(p, "lname")); + } Delete(cl); } else { if (pi > (receiver && !base ? 1 : 0)) { @@ -1022,10 +1067,14 @@ private: } if (pi >= required_count) { Printv(parm_print, "_swig_args ...interface{}", NULL); + if (first == NULL) { + first = NewString("_swig_args"); + } break; } - if (needs_wrapper) { - Printv(parm_print, Getattr(p, "lname"), " ", NULL); + Printv(parm_print, Getattr(p, "lname"), " ", NULL); + if (first == NULL) { + first = Copy(Getattr(p, "lname")); } String *tm = goType(p, Getattr(p, "type")); Printv(parm_print, tm, NULL); @@ -1039,12 +1088,18 @@ private: // Write out the result type. if (is_constructor) { String *cl = exportedName(class_name); - Printv(parm_print, " ", cl, NULL); + Printv(parm_print, " (_swig_ret ", cl, ")", NULL); + if (first == NULL) { + first = NewString("_swig_ret"); + } Delete(cl); } else { if (SwigType_type(result) != T_VOID) { String *tm = goType(n, result); - Printv(parm_print, " ", tm, NULL); + Printv(parm_print, " (_swig_ret ", tm, ")", NULL); + if (first == NULL) { + first = NewString("_swig_ret"); + } Delete(tm); } } @@ -1077,46 +1132,49 @@ private: } } + String *call = NewString(""); + + bool need_return_var = SwigType_type(result) != T_VOID && ((gccgo_flag && is_constructor) || has_goout); + if (need_return_var) { + Printv(f_go_wrappers, "\tvar swig_r ", NULL); + if (is_constructor) { + String *cl = exportedName(class_name); + Printv(f_go_wrappers, cl, NULL); + Delete(cl); + } else { + Printv(f_go_wrappers, goImType(n, result), NULL); + } + Printv(f_go_wrappers, "\n", NULL); + } + if (gccgo_flag) { - if (!is_constructor) { - Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); - } else { - // For a constructor the wrapper function will return a - // uintptr but we will return an interface. We want to - // convert the uintptr to the interface after calling - // SwigCgocallDone, so that we don't try to allocate memory - // while the Go scheduler can't see us. - Printv(f_go_wrappers, "\tvar done bool\n", NULL); - Printv(f_go_wrappers, "\tdefer func() {\n", NULL); - Printv(f_go_wrappers, "\t\tif !done {\n", NULL); - Printv(f_go_wrappers, "\t\t\tSwigCgocallDone()\n", NULL); - Printv(f_go_wrappers, "\t\t}\n", NULL); - Printv(f_go_wrappers, "\t}()\n", NULL); - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); + if (has_goout || is_constructor) { + Printv(call, "\tfunc() {\n", NULL); } + Printv(call, "\tdefer SwigCgocallDone()\n", NULL); + Printv(call, "\tSwigCgocall()\n", NULL); } - Printv(f_go_wrappers, "\t", NULL); + Printv(call, "\t", NULL); if (SwigType_type(result) != T_VOID) { - if (gccgo_flag && is_constructor) { - Printv(f_go_wrappers, "swig_r := ", NULL); + if (need_return_var) { + Printv(call, "swig_r = ", NULL); } else { - Printv(f_go_wrappers, "return ", NULL); + Printv(call, "return ", NULL); } } - Printv(f_go_wrappers, wrapper_name, "(", NULL); + Printv(call, wrapper_name, "(", NULL); if (parm_count > required_count) { - Printv(f_go_wrappers, "len(_swig_args)", NULL); + Printv(call, "len(_swig_args)", NULL); } if (base && receiver) { if (parm_count > required_count) { - Printv(f_go_wrappers, ", ", NULL); + Printv(call, ", ", NULL); } - Printv(f_go_wrappers, "_swig_base", NULL); + Printv(call, "_swig_base", NULL); } Parm *p = parms; @@ -1124,29 +1182,82 @@ private: p = getParm(p); if (i > 0 || (base && receiver) || parm_count > required_count) { - Printv(f_go_wrappers, ", ", NULL); + Printv(call, ", ", NULL); } - Printv(f_go_wrappers, Getattr(p, "lname"), NULL); - // If this is a destructor, then the C function expects the - // C++ value, and we have the interface. We need to get the - // C++ value. The same is true for a type represented as an - // interface. - if ((i == 0 && is_destructor) || ((i > 0 || !receiver || base || is_constructor) && goTypeIsInterface(p, Getattr(p, "type")))) { - Printv(f_go_wrappers, ".Swigcptr()", NULL); + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + + String *goin = Getattr(p, "tmap:goin"); + if (goin == NULL) { + Printv(call, ln, NULL); + if ((i == 0 && is_destructor) || ((i > 0 || !receiver || base || is_constructor) && goTypeIsInterface(p, pt))) { + Printv(call, ".Swigcptr()", NULL); + } + Setattr(p, "emit:goinput", ln); + } else { + String *ivar = NewString(""); + Printf(ivar, "_swig_i_%d", i); + String *itm = goImType(p, pt); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, NULL); + goin = Copy(goin); + Replaceall(goin, "$input", ln); + Replaceall(goin, "$result", ivar); + Printv(f_go_wrappers, goin, NULL); + Delete(goin); + Printv(call, ivar, NULL); + Setattr(p, "emit:goinput", ivar); + } + + // If the parameter has an argout or freearg typemap, make + // sure that it escapes. + if (paramNeedsEscape(p)) { + Printv(f_go_wrappers, "\tif Swig_escape_always_false {\n", NULL); + Printv(f_go_wrappers, "\t\tSwig_escape_val = ", Getattr(p, "emit:goinput"), "\n", NULL); + Printv(f_go_wrappers, "\t}\n", NULL); } p = nextParm(p); } - Printv(f_go_wrappers, ")\n", NULL); + Printv(call, ")\n", NULL); - if (gccgo_flag && is_constructor) { - Printv(f_go_wrappers, "\tSwigCgocallDone()\n", NULL); - Printv(f_go_wrappers, "\tdone = true\n", NULL); - Printv(f_go_wrappers, "\treturn swig_r\n", NULL); + if (gccgo_flag && (has_goout || is_constructor)) { + Printv(call, "\t}()\n", NULL); + } + + Printv(f_go_wrappers, call, NULL); + Delete(call); + + goargout(parms, parm_count); + + if (need_return_var) { + if (goout == NULL) { + Printv(f_go_wrappers, "\treturn swig_r\n", NULL); + } else { + String *tm = goType(n, result); + Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); + Replaceall(goout, "$input", "swig_r"); + Replaceall(goout, "$result", "swig_r_1"); + Printv(f_go_wrappers, goout, NULL); + Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); + } } Printv(f_go_wrappers, "}\n", NULL); + } else if (!gccgo_flag) { + // We don't need a wrapper. If we're using gccgo, the function + // declaration is all we need--it has a //extern comment to + // GCC-compiled wrapper. If we're not using gccgo, we need to + // call the GCC-compiled wrapper here. + Printv(f_go_wrappers, " {\n", NULL); + if (first == NULL) { + Printv(f_go_wrappers, "\tvar _swig_p uintptr\n", NULL); + } else { + Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&", first, "))\n", NULL); + } + Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); + Printv(f_go_wrappers, "\treturn\n", NULL); + Printv(f_go_wrappers, "}", NULL); } Printv(f_go_wrappers, "\n", NULL); @@ -1157,118 +1268,72 @@ private: return SWIG_OK; } + /* ---------------------------------------------------------------------- + * argName() + * + * A helper for goFunctionWrapper to output the first argument name + * as "base" and all others as "_". + * ---------------------------------------------------------------------- */ + + const char *argName(bool *arg) { + if (*arg) { + return "_"; + } + *arg = true; + return "base"; + } + + /* ---------------------------------------------------------------------- + * paramNeedsEscape() + * + * A helper for goFunctionWrapper that returns whether a parameter + * needs to explicitly escape. This is true if the parameter has a + * non-empty argout or freearg typemap, because in those cases the + * Go argument might be or contain a pointer. We need to ensure + * that that pointer does not oint into the stack, which means that + * it needs to escape. + * ---------------------------------------------------------------------- */ + bool paramNeedsEscape(Parm *p) { + String *argout = Getattr(p, "tmap:argout"); + String *freearg = Getattr(p, "tmap:freearg"); + if ((!argout || Len(argout) == 0) && (!freearg || Len(freearg) == 0)) { + return false; + } + // If a C++ type is represented as an interface type in Go, then + // we don't care whether it escapes, because we know that the + // pointer is a C++ pointer. + if (goTypeIsInterface(p, Getattr(p, "type"))) { + return false; + } + return true; + } + /* ---------------------------------------------------------------------- * gcFunctionWrapper() * * This is used for 6g/8g, not for gccgo. Write out the function - * wrapper which will be compiled with 6c/8c. + * redirector that will be compiled with 6c/8c. This used to write + * out a real function wrapper, but that has moved into Go code. * ---------------------------------------------------------------------- */ - int gcFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, ParmList *parms, SwigType *result, bool is_static, bool needs_wrapper) { + int gcFunctionWrapper(String *wname) { Wrapper *f = NewWrapper(); Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"\"\n", NULL); Printv(f->def, "#pragma cgo_import_static ", wname, "\n", NULL); - Printv(f->def, "extern void (*", wname, ")(void*);\n", NULL); - Printv(f->def, "static void (*x", wname, ")(void*) = ", wname, ";\n", NULL); - Printv(f->def, "\n", NULL); - Printv(f->def, "void\n", NULL); - - Wrapper *dummy = NewWrapper(); - emit_attach_parmmaps(parms, dummy); - Swig_typemap_attach_parms("default", parms, dummy); - Swig_typemap_attach_parms("gosize", parms, dummy); - int parm_count = emit_num_arguments(parms); - int required_count = emit_num_required(parms); - - String *parm_size = NewString(""); - - if (parm_count > required_count) { - Append(parm_size, "SWIG_PARM_SIZE"); - } - - if (class_receiver && !is_static) { - if (Len(parm_size) > 0) { - Append(parm_size, " + "); - } - Append(parm_size, "SWIG_PARM_SIZE"); - } - - Parm *p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - addGcTypeSize(p, Getattr(p, "type"), parm_size); - p = nextParm(p); - } - - if (SwigType_type(result) != T_VOID) { - addGcTypeSize(n, result, parm_size); - } - - if (Len(parm_size) == 0) { - Append(parm_size, "1"); - } - - String *fn_name; - if (!needs_wrapper) { - fn_name = Copy(go_name); - if (overname) { - Append(fn_name, overname); - } - } else { - fn_name = buildGoWrapperName(name, overname); - } - + Printv(f->def, "extern void ", wname, "(void*);\n", NULL); + // Declare this as a uintptr, since it is not a pointer into the + // Go heap. // \xc2\xb7 is UTF-8 for U+00B7 which is Unicode 'Middle Dot' - Printv(f->def, "\xc2\xb7", fn_name, "(struct { uint8 x[", parm_size, "];} p)", NULL); - - Delete(fn_name); - Delete(parm_size); - - Printv(f->code, "{\n", NULL); - Printv(f->code, "\truntime\xc2\xb7" "cgocall(x", wname, ", &p);\n", NULL); - Printv(f->code, "}\n", NULL); - Printv(f->code, "\n", NULL); + Printv(f->def, "uintptr \xc2\xb7", wname, " = (uintptr)", wname, ";\n", NULL); Wrapper_print(f, f_gc_wrappers); DelWrapper(f); - DelWrapper(dummy); return SWIG_OK; } - /* ---------------------------------------------------------------------- - * getGcTypeSize() - * - * Return the size to use when passing a type from 6g/8g to 6c/8c. - * ---------------------------------------------------------------------- */ - - String *addGcTypeSize(Node *n, SwigType *type, String *orig) { - if (Len(orig) > 0) { - Append(orig, " + "); - } - - String *go = goType(n, type); - if (Cmp(go, "string") == 0) { - // A string has a pointer and a length. - Append(orig, "(2 * SWIG_PARM_SIZE)"); - } else if (Strncmp(go, "[]", 2) == 0) { - // A slice has a pointer, a length, and a capacity. - Append(orig, "(3 * SWIG_PARM_SIZE)"); - } else if (Strcmp(go, "float64") == 0) { - Append(orig, "8"); - } else if (Strcmp(go, "complex64") == 0) { - Append(orig, "8"); - } else if (Strcmp(go, "complex128") == 0) { - Append(orig, "16"); - } else { - Append(orig, "SWIG_PARM_SIZE"); - } - - return orig; - } - /* ---------------------------------------------------------------------- * gccFunctionWrapper() * @@ -1315,11 +1380,19 @@ private: Parm *p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); + String *ln = Getattr(p, "lname"); SwigType *pt = Getattr(p, "type"); String *ct = gcCTypeForGoValue(p, pt, ln); Printv(f->code, "\t\t\t", ct, ";\n", NULL); Delete(ct); + + String *gn = NewStringf("_swig_go_%d", i); + ct = gcCTypeForGoValue(p, pt, gn); + Setattr(p, "emit:input", gn); + Wrapper_add_local(f, gn, ct); + Delete(ct); + p = nextParm(p); } if (SwigType_type(result) != T_VOID) { @@ -1329,27 +1402,39 @@ private: Delete(ln); Printv(f->code, "\t\t", ct, ";\n", NULL); Delete(ct); + + ln = NewString("_swig_go_result"); + ct = gcCTypeForGoValue(n, result, ln); + Wrapper_add_local(f, "_swig_go_result", ct); + Delete(ct); + Delete(ln); } Printv(f->code, "\t} *swig_a = (struct swigargs *) swig_v;\n", NULL); Printv(f->code, "\n", NULL); - // Copy the input arguments out of the structure into the - // parameter variables. - + // Copy the input arguments out of the structure into the Go local + // variables. p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); + String *ln = Getattr(p, "lname"); + String *gn = Getattr(p, "emit:input"); + Printv(f->code, "\t", gn, " = swig_a->", ln, ";\n", NULL); + p = nextParm(p); + } + // Apply the in typemaps. + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); String *tm = Getattr(p, "tmap:in"); if (!tm) { Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { - String *ln = Getattr(p, "lname"); - String *input = NewString(""); - Printv(input, "swig_a->", ln, NULL); - Replaceall(tm, "$input", input); - Setattr(p, "emit:input", input); + tm = Copy(tm); + String *gn = Getattr(p, "emit:input"); + Replaceall(tm, "$input", gn); if (i < required_count) { Printv(f->code, "\t", tm, "\n", NULL); } else { @@ -1357,6 +1442,7 @@ private: Printv(f->code, "\t\t", tm, "\n", NULL); Printv(f->code, "\t}\n", NULL); } + Delete(tm); } p = nextParm(p); } @@ -1464,9 +1550,9 @@ private: Delete(fndef); if (SwigType_type(result) != T_VOID) { - String *ln = NewString("go_result"); + String *ln = NewString("_swig_go_result"); String *ct = gccgoCTypeForGoValue(n, result, ln); - Wrapper_add_local(f, "go_result", ct); + Wrapper_add_local(f, "_swig_go_result", ct); Delete(ct); Delete(ln); } @@ -1486,6 +1572,7 @@ private: String *ln = Getattr(p, "lname"); String *pn = NewString("g"); Append(pn, ln); + tm = Copy(tm); Replaceall(tm, "$input", pn); Setattr(p, "emit:input", pn); if (i < required_count) { @@ -1495,6 +1582,7 @@ private: Printv(f->code, " ", tm, "\n", NULL); Printv(f->code, " }\n", NULL); } + Delete(tm); } p = nextParm(p); @@ -1513,7 +1601,7 @@ private: cleanupFunction(n, f, parms); if (SwigType_type(result) != T_VOID) { - Printv(f->code, " return go_result;\n", NULL); + Printv(f->code, " return _swig_go_result;\n", NULL); } Printv(f->code, "}\n", NULL); @@ -1543,20 +1631,26 @@ private: if (!tm) { p = nextSibling(p); } else { + tm = Copy(tm); Replaceall(tm, "$input", Getattr(p, "emit:input")); Printv(f->code, tm, "\n\n", NULL); + Delete(tm); p = Getattr(p, "tmap:check:next"); } } } /* ----------------------------------------------------------------------- - * getGoAction() + * emitGoAction() * - * Get the action of the function. This is used for C/C++ function. + * Emit the action of the function. This is used for the C/C++ function. * ----------------------------------------------------------------------- */ void emitGoAction(Node *n, List *base, ParmList *parms, SwigType *result, Wrapper *f) { + if (!gccgo_flag && SwigType_type(result) != T_VOID) { + Wrapper_add_local(f, "swig_stktop", "char *swig_stktop"); + Printv(f->code, "\tswig_stktop = _swig_topofstack();\n", NULL); + } String *actioncode; if (!base || isStatic(n)) { Swig_director_emit_dynamic_cast(n, f); @@ -1593,12 +1687,7 @@ private: if (!tm) { Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s\n", SwigType_str(result, 0)); } else { - if (!gccgo_flag) { - static const String *swig_a_result = NewStringf("swig_a->%s", Swig_cresult_name()); - Replaceall(tm, "$result", swig_a_result); - } else { - Replaceall(tm, "$result", "go_result"); - } + Replaceall(tm, "$result", "_swig_go_result"); if (GetFlag(n, "feature:new")) { Replaceall(tm, "$owner", "1"); } else { @@ -1608,6 +1697,14 @@ private: Delete(tm); } + if (!gccgo_flag && SwigType_type(result) != T_VOID) { + // If the function called back into the Go code, the stack might + // have been copied. We need to adjust swig_a accordingly here. + // This is what cgo does. + Printv(f->code, "\tswig_a = (struct swigargs*)((char*)swig_a + (_swig_topofstack() - swig_stktop));\n", NULL); + Printv(f->code, "\tswig_a->", Swig_cresult_name(), " = ", "_swig_go_result;\n", NULL); + } + Swig_restore(n); } @@ -1626,14 +1723,42 @@ private: if (!tm) { p = nextSibling(p); } else { + tm = Copy(tm); Replaceall(tm, "$result", Swig_cresult_name()); Replaceall(tm, "$input", Getattr(p, "emit:input")); Printv(f->code, tm, "\n", NULL); + Delete(tm); p = Getattr(p, "tmap:argout:next"); } } } + /* ----------------------------------------------------------------------- + * goargout() + * + * Handle Go argument output code if any. This is used for the Go + * function. This assumes that each parameter has an "emit:goinput" + * property with the name to use to refer to that parameter. + * ----------------------------------------------------------------------- */ + + void goargout(ParmList *parms, int parm_count) { + Parm *p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + String *tm = Getattr(p, "tmap:goargout"); + if (!tm) { + p = nextSibling(p); + } else { + tm = Copy(tm); + Replaceall(tm, "$result", "swig_r"); + Replaceall(tm, "$input", Getattr(p, "emit:goinput")); + Printv(f_go_wrappers, tm, NULL); + Delete(tm); + p = Getattr(p, "tmap:goargout:next"); + } + } + } + /* ----------------------------------------------------------------------- * freearg() * @@ -1650,8 +1775,10 @@ private: if (!tm) { p = nextSibling(p); } else { + tm = Copy(tm); Replaceall(tm, "$input", Getattr(p, "emit:input")); Printv(ret, tm, "\n", NULL); + Delete(tm); p = Getattr(p, "tmap:freearg:next"); } } @@ -1835,12 +1962,26 @@ private: if (!is_public(n)) { return SWIG_OK; } - if (Getattr(parentNode(n), "unnamed")) { + + Swig_require("enumvalueDeclaration", n, "*sym:name", NIL); + Node *parent = parentNode(n); + + if (Getattr(parent, "unnamed")) { Setattr(n, "type", NewString("int")); } else { - Setattr(n, "type", Getattr(parentNode(n), "enumtype")); + Setattr(n, "type", Getattr(parent, "enumtype")); } - return goComplexConstant(n, Getattr(n, "type")); + + if (GetFlag(parent, "scopedenum")) { + String *symname = Getattr(n, "sym:name"); + symname = Swig_name_member(0, Getattr(parent, "sym:name"), symname); + Setattr(n, "sym:name", symname); + Delete(symname); + } + + int ret = goComplexConstant(n, Getattr(n, "type")); + Swig_restore(n); + return ret; } /* ----------------------------------------------------------------------- @@ -2047,7 +2188,7 @@ private: } Append(f_go_wrappers, interfaces); - Printf(f_go_wrappers, "}\n\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); Delete(interfaces); interfaces = NULL; @@ -2640,6 +2781,7 @@ private: DelWrapper(dummy); Swig_typemap_attach_parms("gotype", parms, NULL); + Swig_typemap_attach_parms("imtype", parms, NULL); int parm_count = emit_num_arguments(parms); String *func_name = NewString("NewDirector"); @@ -2666,7 +2808,9 @@ private: if (!is_ignored) { // Declare the C++ wrapper. - if (gccgo_flag) { + if (!gccgo_flag) { + Printv(f_go_wrappers, "var ", wname, " unsafe.Pointer\n\n", NULL); + } else { Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); } @@ -2674,18 +2818,28 @@ private: if (overname) { Printv(f_go_wrappers, overname, NULL); } - Printv(f_go_wrappers, "(*", director_struct_name, NULL); + Printv(f_go_wrappers, "(_swig_director *", director_struct_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); String *tm = goType(p, Getattr(p, "type")); - Printv(f_go_wrappers, ", ", tm, NULL); + Printv(f_go_wrappers, ", _ ", tm, NULL); Delete(tm); p = nextParm(p); } - Printv(f_go_wrappers, ") ", go_type_name, "\n\n", NULL); + Printv(f_go_wrappers, ") (_swig_ret ", go_type_name, ")", NULL); + + if (!gccgo_flag) { + Printv(f_go_wrappers, " {\n", NULL); + Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&_swig_director))\n", NULL); + Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); + Printv(f_go_wrappers, "\treturn\n", NULL); + Printv(f_go_wrappers, "}", NULL); + } + + Printv(f_go_wrappers, "\n\n", NULL); Printv(f_go_wrappers, "func ", func_with_over_name, "(v interface{}", NULL); @@ -2754,8 +2908,7 @@ private: Setattr(n, "wrap:action", action); if (!gccgo_flag) { - int r = gcFunctionWrapper(n, fn_name, fn_name, overname, wname, - first_parm, result, is_static, false); + int r = gcFunctionWrapper(wname); if (r != SWIG_OK) { return r; } @@ -3075,6 +3228,7 @@ private: DelWrapper(dummy); Swig_typemap_attach_parms("gotype", parms, NULL); + Swig_typemap_attach_parms("imtype", parms, NULL); int parm_count = emit_num_arguments(parms); SwigType *result = Getattr(n, "type"); @@ -3122,6 +3276,9 @@ private: Swig_typemap_attach_parms("directorin", parms, w); Swig_typemap_attach_parms("directorargout", parms, w); + Swig_typemap_attach_parms("godirectorin", parms, w); + Swig_typemap_attach_parms("goin", parms, dummy); + Swig_typemap_attach_parms("goargout", parms, dummy); if (!is_ignored) { // We use an interface to see if this method is defined in Go. @@ -3155,17 +3312,19 @@ private: // Declare the upcall function, which calls the method on the // parent class. - if (gccgo_flag) { + if (!gccgo_flag) { + Printv(f_go_wrappers, "var ", upcall_wname, " unsafe.Pointer\n\n", NULL); + } else { Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL); } - Printv(f_go_wrappers, "func ", upcall_gc_name, "(", go_type_name, NULL); + Printv(f_go_wrappers, "func ", upcall_gc_name, "(_swig_ptr ", go_type_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); String *tm = goWrapperType(p, Getattr(p, "type"), false); - Printv(f_go_wrappers, ", ", tm, NULL); + Printv(f_go_wrappers, ", _ ", tm, NULL); Delete(tm); p = nextParm(p); } @@ -3174,11 +3333,19 @@ private: if (SwigType_type(result) != T_VOID) { String *tm = goWrapperType(n, result, true); - Printv(f_go_wrappers, " ", tm, NULL); + Printv(f_go_wrappers, " (_swig_ret ", tm, ")", NULL); Delete(tm); } - Printv(f_go_wrappers, "\n", NULL); + if (!gccgo_flag) { + Printv(f_go_wrappers, " {\n", NULL); + Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&_swig_ptr))\n", NULL); + Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", upcall_wname, ", _swig_p)\n", NULL); + Printv(f_go_wrappers, "\treturn\n", NULL); + Printv(f_go_wrappers, "}", NULL); + } + + Printv(f_go_wrappers, "\n\n", NULL); } // Define the method on the director class in Go. @@ -3234,29 +3401,98 @@ private: if (GetFlag(n, "abstract")) { Printv(f_go_wrappers, "\tpanic(\"call to pure virtual method\")\n", NULL); } else { - if (gccgo_flag) { - Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); - } - - Printv(f_go_wrappers, "\t", NULL); + bool has_goout = false; + String *goout = NULL; if (SwigType_type(result) != T_VOID) { - Printv(f_go_wrappers, "return ", NULL); + Printv(f_go_wrappers, "\tvar swig_r ", goImType(n, result), "\n", NULL); + goout = Swig_typemap_lookup("goout", n, "swig_r", NULL); + if (goout) { + has_goout = true; + } } - Printv(f_go_wrappers, upcall_gc_name, "(swig_p.", go_type_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); - SwigType *pt = Getattr(p, "type"); - Printv(f_go_wrappers, ", ", Getattr(p, "lname"), NULL); - if (goTypeIsInterface(p, pt)) { - Printv(f_go_wrappers, ".Swigcptr()", NULL); + if (Getattr(p, "tmap:goargout")) { + has_goout = true; } p = nextParm(p); } - Printv(f_go_wrappers, ")\n", NULL); + String *call = NewString(""); + + if (gccgo_flag) { + if (has_goout) { + Printv(call, "\tfunc() {\n", NULL); + } + Printv(call, "\tdefer SwigCgocallDone()\n", NULL); + Printv(call, "\tSwigCgocall()\n", NULL); + } + + Printv(call, "\t", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(call, "swig_r = ", NULL); + } + Printv(call, upcall_gc_name, "(swig_p.", go_type_name, NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + Printv(call, ", ", NULL); + p = getParm(p); + SwigType *pt = Getattr(p, "type"); + + String *ln = Getattr(p, "lname"); + + // This is an ordinary call from Go to C++, so adjust using + // the goin typemap. + String *goin = Getattr(p, "tmap:goin"); + if (goin == NULL) { + Printv(call, ln, NULL); + if (goTypeIsInterface(p, pt)) { + Printv(call, ".Swigcptr()", NULL); + } + Setattr(p, "emit:goinput", ln); + } else { + String *ivar = NewString(""); + Printf(ivar, "_swig_i_%d", i); + String *itm = goImType(p, pt); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, NULL); + goin = Copy(goin); + Replaceall(goin, "$input", ln); + Replaceall(goin, "$result", ivar); + Printv(f_go_wrappers, goin, NULL); + Delete(goin); + Printv(call, ivar, NULL); + Setattr(p, "emit:goinput", ivar); + } + + p = nextParm(p); + } + + Printv(call, ")\n", NULL); + + if (gccgo_flag && has_goout) { + Printv(call, "\t}()\n", NULL); + } + + Printv(f_go_wrappers, call, NULL); + Delete(call); + + goargout(parms, parm_count); + + if (SwigType_type(result) != T_VOID) { + if (goout == NULL) { + Printv(f_go_wrappers, "\treturn swig_r\n", NULL); + } else { + String *tm = goType(n, result); + Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); + Replaceall(goout, "$input", "swig_r"); + Replaceall(goout, "$result", "swig_r_1"); + Printv(f_go_wrappers, goout, NULL); + Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); + } + } } Printv(f_go_wrappers, "}\n\n", NULL); @@ -3341,7 +3577,7 @@ private: if (!gccgo_flag) { // Write the upcall wrapper function. This is compiled by gc // and calls the C++ function. - int r = gcFunctionWrapper(n, upcall_name, upcall_name, overname, upcall_wname, first_parm, result, is_static, true); + int r = gcFunctionWrapper(upcall_wname); if (r != SWIG_OK) { return r; } @@ -3389,29 +3625,86 @@ private: Printv(f_go_wrappers, " {\n", NULL); - if (gccgo_flag) { - Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); + String *goout = NULL; + if (SwigType_type(result) != T_VOID) { + Printv(f_go_wrappers, "\tvar swig_r ", goImType(n, result), "\n", NULL); + goout = Swig_typemap_lookup("goout", n, "swig_r", NULL); } - Printv(f_go_wrappers, "\t", NULL); - if (SwigType_type(result) != T_VOID) { - Printv(f_go_wrappers, "return ", NULL); + String *call = NewString(""); + + if (gccgo_flag) { + if (goout != NULL) { + Printv(call, "\tfunc() {\n", NULL); + } + Printv(call, "\tdefer SwigCgocallDone()\n", NULL); + Printv(call, "\tSwigCgocall()\n", NULL); } - Printv(f_go_wrappers, upcall_gc_name, "(p.(*", director_struct_name, ").", go_type_name, NULL); + + Printv(call, "\t", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(call, "swig_r = ", NULL); + } + Printv(call, upcall_gc_name, "(p.(*", director_struct_name, ").", go_type_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { + Printv(call, ", ", NULL); p = getParm(p); SwigType *pt = Getattr(p, "type"); - Printv(f_go_wrappers, ", ", Getattr(p, "lname"), NULL); + + String *ln = Copy(Getattr(p, "lname")); if (goTypeIsInterface(p, pt)) { - Printv(f_go_wrappers, ".Swigcptr()", NULL); + Printv(ln, ".Swigcptr()", NULL); } + + String *goin = Getattr(p, "tmap:goin"); + if (goin == NULL) { + Printv(call, ln, NULL); + Setattr(p, "emit:goinput", ln); + } else { + String *ivar = NewString(""); + Printf(ivar, "_swig_i_%d", i); + String *itm = goImType(p, pt); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, NULL); + goin = Copy(goin); + Replaceall(goin, "$input", ln); + Replaceall(goin, "$result", ivar); + Printv(f_go_wrappers, goin, NULL); + Delete(goin); + Printv(call, ivar, NULL); + Setattr(p, "emit:goinput", ivar); + } + + Delete(ln); + p = nextParm(p); } - Printv(f_go_wrappers, ")\n", NULL); + Printv(call, ")\n", NULL); + + if (gccgo_flag && goout != NULL) { + Printv(call, "\t}()\n", NULL); + } + + Printv(f_go_wrappers, call, NULL); + Delete(call); + + goargout(parms, parm_count); + + if (SwigType_type(result) != T_VOID) { + if (goout == NULL) { + Printv(f_go_wrappers, "\treturn swig_r\n", NULL); + } else { + String *tm = goType(n, result); + Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); + Replaceall(goout, "$input", "swig_r"); + Replaceall(goout, "$result", "swig_r_1"); + Printv(f_go_wrappers, goout, NULL); + Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); + } + } + Printv(f_go_wrappers, "}\n\n", NULL); } @@ -3437,34 +3730,53 @@ private: } Printv(f_go_wrappers, "{\n", NULL); - if (gccgo_flag) { - Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL); - Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL); - } - - Printv(f_go_wrappers, "\t", NULL); - if (is_ignored) { - Printv(f_go_wrappers, "return\n", NULL); + Printv(f_go_wrappers, "\treturn\n", NULL); } else { bool result_is_interface = false; + String *goout = NULL; if (SwigType_type(result) != T_VOID) { - Printv(f_go_wrappers, "return ", NULL); result_is_interface = goTypeIsInterface(NULL, result); + Printv(f_go_wrappers, "\tvar swig_r ", NULL); + if (!result_is_interface) { + Printv(f_go_wrappers, goType(n, result), NULL); + } else { + Printv(f_go_wrappers, result_wrapper, NULL); + } + Printv(f_go_wrappers, "\n", NULL); + goout = Swig_typemap_lookup("godirectorout", n, "swig_r", NULL); + } + + String *call = NewString(""); + + if (gccgo_flag) { + if (goout != NULL) { + Printv(call, "\tfunc() {\n", NULL); + } + Printv(call, "\tSwigCgocallBack()\n", NULL); + Printv(call, "\tdefer SwigCgocallBackDone()\n", NULL); + } + + Printv(call, "\t", NULL); + + if (SwigType_type(result) != T_VOID) { + Printv(call, "swig_r = ", NULL); if (result_is_interface) { - Printv(f_go_wrappers, result_wrapper, "(", NULL); + Printv(call, result_wrapper, "(", NULL); } } - Printv(f_go_wrappers, "p.", go_with_over_name, "(", NULL); + Printv(call, "p.", go_with_over_name, "(", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); if (i > 0) { - Printv(f_go_wrappers, ", ", NULL); + Printv(call, ", ", NULL); } SwigType *pt = Getattr(p, "type"); + String *ln = NewString(""); + // If the Go representation is an interface type class, then // we are receiving a uintptr, and must convert to the // interface. @@ -3473,26 +3785,64 @@ private: // Passing is_result as true to goWrapperType gives us the // name of the Go type we need to convert to an interface. String *wt = goWrapperType(p, pt, true); - Printv(f_go_wrappers, wt, "(", NULL); + Printv(ln, wt, "(", NULL); Delete(wt); } - Printv(f_go_wrappers, Getattr(p, "lname"), NULL); + Printv(ln, Getattr(p, "lname"), NULL); if (is_interface) { - Printv(f_go_wrappers, ")", NULL); + Printv(ln, ")", NULL); } + String *goin = Getattr(p, "tmap:godirectorin"); + if (goin == NULL) { + Printv(call, ln, NULL); + } else { + String *ivar = NewString(""); + Printf(ivar, "_swig_i_%d", i); + String *itm = goType(p, pt); + Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, NULL); + goin = Copy(goin); + Replaceall(goin, "$input", ln); + Replaceall(goin, "$result", ivar); + Printv(f_go_wrappers, goin, NULL); + Delete(goin); + Printv(call, ivar, NULL); + Delete(ivar); + } + + Delete(ln); + p = nextParm(p); } - Printv(f_go_wrappers, ")", NULL); + Printv(call, ")", NULL); if (result_is_interface) { - Printv(f_go_wrappers, ".Swigcptr())", NULL); + Printv(call, ".Swigcptr())", NULL); + } + Printv(call, "\n", NULL); + + if (gccgo_flag && goout != NULL) { + Printv(call, "\t}()\n", NULL); } - Printv(f_go_wrappers, "\n", NULL); + Printv(f_go_wrappers, call, NULL); + Delete(call); + + if (SwigType_type(result) != T_VOID) { + if (goout == NULL) { + Printv(f_go_wrappers, "\treturn swig_r\n", NULL); + } else { + String *tm = goImType(n, result); + Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); + Replaceall(goout, "$input", "swig_r"); + Replaceall(goout, "$result", "swig_r_1"); + Printv(f_go_wrappers, goout, NULL); + Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); + } + } } Printv(f_go_wrappers, "}\n\n", NULL); @@ -3610,6 +3960,7 @@ private: Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { + tm = Copy(tm); String *ln = Getattr(p, "lname"); String *input = NewString(""); Printv(input, "swig_a.", ln, NULL); @@ -3618,12 +3969,28 @@ private: Replaceall(tm, "$owner", "0"); Delete(input); Printv(w->code, "\t", tm, "\n", NULL); + Delete(tm); } p = Getattr(p, "tmap:directorin:next"); } Printv(w->code, " crosscall2(", callback_wname, ", &swig_a, (int) sizeof swig_a);\n", NULL); + /* Marshal outputs */ + for (p = parms; p;) { + String *tm; + if ((tm = Getattr(p, "tmap:directorargout"))) { + tm = Copy(tm); + Replaceall(tm, "$result", "jresult"); + Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } + } + if (SwigType_type(result) != T_VOID) { String *result_str = NewString("c_result"); String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); @@ -3672,7 +4039,7 @@ private: String *pn = NewString("g"); Append(pn, Getattr(p, "lname")); - Setattr(p, "emit:input", pn); + Setattr(p, "emit:directorinput", pn); String *tm = gccgoCTypeForGoValue(n, Getattr(p, "type"), pn); Wrapper_add_local(w, pn, tm); @@ -3683,9 +4050,11 @@ private: Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { + tm = Copy(tm); Replaceall(tm, "$input", pn); Replaceall(tm, "$owner", 0); Printv(w->code, " ", tm, "\n", NULL); + Delete(tm); Printv(args, ", ", pn, NULL); } @@ -3699,6 +4068,21 @@ private: } Printv(w->code, callback_wname, "(go_val", args, ");\n", NULL); + /* Marshal outputs */ + for (p = parms; p;) { + String *tm; + if ((tm = Getattr(p, "tmap:directorargout"))) { + tm = Copy(tm); + Replaceall(tm, "$result", "jresult"); + Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } + } + if (SwigType_type(result) != T_VOID) { String *result_str = NewString("c_result"); String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); @@ -3717,19 +4101,6 @@ private: Delete(result_str); } } - - /* Marshal outputs */ - for (p = parms; p;) { - String *tm; - if ((tm = Getattr(p, "tmap:directorargout"))) { - Replaceall(tm, "$result", "jresult"); - Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); - Printv(w->code, tm, "\n", NIL); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } - } } else { assert(is_pure_virtual); Printv(w->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n", NULL); @@ -4057,7 +4428,7 @@ private: } fn = i + 1; - Printf(f_go_wrappers, "\t\tif _, ok := a[%d].(%s); !ok {\n", j, tm); + Printf(f_go_wrappers, "\t\tif _, ok := a[%d].(%s); !ok {\n", j, goType(pj, Getattr(pj, "type"))); Printf(f_go_wrappers, "\t\t\tgoto check_%d\n", fn); Printv(f_go_wrappers, "\t\t}\n", NULL); } @@ -4462,7 +4833,19 @@ private: * ---------------------------------------------------------------------- */ String *goType(Node *n, SwigType *type) { - return goTypeWithInfo(n, type, NULL); + return goTypeWithInfo(n, type, false, NULL); + } + + /* ---------------------------------------------------------------------- + * goImType() + * + * Given a SWIG type, return a string for the intermediate Go type + * to pass to C/C++. This is like goType except that it looks for + * an imtype typemap entry first. + * ---------------------------------------------------------------------- */ + + String *goImType(Node *n, SwigType *type) { + return goTypeWithInfo(n, type, true, NULL); } /* ---------------------------------------------------------------------- @@ -4470,6 +4853,8 @@ private: * * Like goType, but return some more information. * + * If use_imtype is true, this look for a imtype typemap entry. + * * If the p_is_interface parameter is not NULL, this sets * *p_is_interface to indicate whether this type is going to be * represented by a Go interface type. These are cases where the Go @@ -4477,24 +4862,39 @@ private: * forth with C/C++. * ---------------------------------------------------------------------- */ - String *goTypeWithInfo(Node *n, SwigType *type, bool *p_is_interface) { + String *goTypeWithInfo(Node *n, SwigType *type, bool use_imtype, bool *p_is_interface) { if (p_is_interface) { *p_is_interface = false; } - String *ret; - if (n && Cmp(type, Getattr(n, "type")) == 0) { - ret = NULL; - if (Strcmp(Getattr(n, "nodeType"), "parm") == 0) { - ret = Getattr(n, "tmap:gotype"); + String *ret = NULL; + if (use_imtype) { + if (n && Cmp(type, Getattr(n, "type")) == 0) { + if (Strcmp(Getattr(n, "nodeType"), "parm") == 0) { + ret = Getattr(n, "tmap:imtype"); + } + if (!ret) { + ret = Swig_typemap_lookup("imtype", n, "", NULL); + } + } else { + Parm *p = NewParm(type, "goImType", n); + ret = Swig_typemap_lookup("imtype", p, "", NULL); + Delete(p); } - if (!ret) { - ret = Swig_typemap_lookup("gotype", n, "", NULL); + } + if (!ret) { + if (n && Cmp(type, Getattr(n, "type")) == 0) { + if (Strcmp(Getattr(n, "nodeType"), "parm") == 0) { + ret = Getattr(n, "tmap:gotype"); + } + if (!ret) { + ret = Swig_typemap_lookup("gotype", n, "", NULL); + } + } else { + Parm *p = NewParm(type, "goType", n); + ret = Swig_typemap_lookup("gotype", p, "", NULL); + Delete(p); } - } else { - Parm *p = NewParm(type, "goType", n); - ret = Swig_typemap_lookup("gotype", p, "", NULL); - Delete(p); } if (ret && Strstr(ret, "$gotypename") != 0) { @@ -4563,7 +4963,7 @@ private: ret = NewString("uintptr"); } else { bool is_interface; - String *base = goTypeWithInfo(n, r, &is_interface); + String *base = goTypeWithInfo(n, r, false, &is_interface); // At the Go level, an unknown or class type is handled as an // interface wrapping a pointer. This means that if a @@ -4627,12 +5027,12 @@ private: if (add_pointer) { SwigType_add_pointer(r); } - ret = goTypeWithInfo(n, r, p_is_interface); + ret = goTypeWithInfo(n, r, false, p_is_interface); Delete(r); } else if (SwigType_isqualifier(t)) { SwigType *r = Copy(t); SwigType_del_qualifier(r); - ret = goTypeWithInfo(n, r, p_is_interface); + ret = goTypeWithInfo(n, r, false, p_is_interface); Delete(r); } else if (SwigType_isvarargs(t)) { ret = NewString("[]interface{}"); @@ -4658,7 +5058,7 @@ private: String *goWrapperType(Node *n, SwigType *type, bool is_result) { bool is_interface; - String *ret = goTypeWithInfo(n, type, &is_interface); + String *ret = goTypeWithInfo(n, type, true, &is_interface); // If this is an interface, we want to pass the real type. if (is_interface) { @@ -4742,7 +5142,18 @@ private: String *gcCTypeForGoValue(Node *n, SwigType *type, String *name) { bool is_interface; - String *gt = goTypeWithInfo(n, type, &is_interface); + String *gt = goTypeWithInfo(n, type, true, &is_interface); + + String *tail = NewString(""); + SwigType *t = SwigType_typedef_resolve_all(type); + if (!SwigType_isreference(t)) { + while (Strncmp(gt, "*", 1) == 0) { + Replace(gt, "*", "", DOH_REPLACE_FIRST); + Printv(tail, "*", NULL); + } + } + Delete(t); + bool is_string = Strcmp(gt, "string") == 0; bool is_slice = Strncmp(gt, "[]", 2) == 0; bool is_function = Strcmp(gt, "_swig_fnptr") == 0; @@ -4770,18 +5181,21 @@ private: if (is_string) { // Note that we don't turn a reference to a string into a // pointer to a string. Strings are immutable anyhow. - ret = NewString("_gostring_ "); - Append(ret, name); + ret = NewString(""); + Printv(ret, "_gostring_", tail, " ", name, NULL); + Delete(tail); return ret; } else if (is_slice) { // Slices are always passed as a _goslice_, whether or not references // are involved. - ret = NewString("_goslice_ "); - Append(ret, name); + ret = NewString(""); + Printv(ret, "_goslice_", tail, " ", name, NULL); + Delete(tail); return ret; } else if (is_function || is_member) { - ret = NewString("void *"); - Append(ret, name); + ret = NewString(""); + Printv(ret, "void*", tail, " ", name, NULL); + Delete(tail); return ret; } else if (is_complex64) { ret = NewString("_Complex float "); @@ -4798,6 +5212,7 @@ private: SwigType_add_pointer(t); ret = SwigType_lstr(t, name); Delete(t); + Delete(tail); return ret; } else { SwigType *t = SwigType_typedef_resolve_all(type); @@ -4821,6 +5236,7 @@ private: } Delete(q); Delete(t); + Delete(tail); return ret; } } @@ -4853,14 +5269,17 @@ private: } else if (is_float64) { ret = NewString("double "); } else { + Delete(tail); return SwigType_lstr(type, name); } } + Append(ret, tail); if (SwigType_isreference(type)) { Append(ret, "* "); } Append(ret, name); + Delete(tail); return ret; } @@ -4885,7 +5304,7 @@ private: bool goTypeIsInterface(Node *n, SwigType *type) { bool is_interface; - Delete(goTypeWithInfo(n, type, &is_interface)); + Delete(goTypeWithInfo(n, type, false, &is_interface)); return is_interface; } diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index a9e51fd1b..1c135b53d 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -1350,7 +1350,7 @@ public: Printv(f_header, tm, "\n", NIL); } else { // Create variable and assign it a value - Printf(f_header, "static %s = %s;\n", SwigType_str(type, var_name), rvalue); + Printf(f_header, "static %s = (%s)(%s);\n", SwigType_str(type, var_name), SwigType_str(type, 0), rvalue); } { /* Hack alert: will cleanup later -- Dave */ diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 9e16bb422..82ecb41a4 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -209,7 +209,7 @@ public: String *symname = Copy(Getattr(n, "sym:name")); if (symname && !GetFlag(n, "feature:flatnested")) { for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { - Push(symname, "."); + Push(symname, jnidescriptor ? "$" : "."); Push(symname, Getattr(outer_class, "sym:name")); } } @@ -838,7 +838,7 @@ public: bool is_destructor = (Cmp(Getattr(n, "nodeType"), "destructor") == 0); if (!Getattr(n, "sym:overloaded")) { - if (!addSymbol(Getattr(n, "sym:name"), n, imclass_name)) + if (!addSymbol(symname, n, imclass_name)) return SWIG_ERROR; } @@ -1039,26 +1039,15 @@ public: } } + // Now write code to make the function call if (!native_function_flag) { - if (Cmp(nodeType(n), "constant") == 0) { - // Wrapping a constant hack - Swig_save("functionWrapper", n, "wrap:action", NIL); - // below based on Swig_VargetToFunction() - SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); - Setattr(n, "wrap:action", NewStringf("%s = (%s)(%s);", Swig_cresult_name(), SwigType_lstr(ty, 0), Getattr(n, "value"))); - } - - // Now write code to make the function call Swig_director_emit_dynamic_cast(n, f); String *actioncode = emit_action(n); // Handle exception classes specified in the "except" feature's "throws" attribute addThrows(n, "feature:except", n); - if (Cmp(nodeType(n), "constant") == 0) - Swig_restore(n); - /* Return value if necessary */ if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) { addThrows(n, "tmap:out", n); @@ -1194,15 +1183,13 @@ public: return ret; } - String *getCurrentScopeName(String *nspace) - { + String *getCurrentScopeName(String *nspace) { String *scope = 0; if (nspace || getCurrentClass()) { scope = NewString(""); if (nspace) Printf(scope, "%s", nspace); - if (Node* cls = getCurrentClass()) - { + if (Node* cls = getCurrentClass()) { if (Node *outer = Getattr(cls, "nested:outer")) { String *outerClassesPrefix = Copy(Getattr(outer, "sym:name")); for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) { @@ -1370,6 +1357,7 @@ public: int unnamedinstance = GetFlag(parent, "unnamedinstance"); String *parent_name = Getattr(parent, "name"); String *nspace = getNSpace(); + String *newsymname = 0; String *tmpValue; // Strange hack from parent method @@ -1394,14 +1382,20 @@ public: { EnumFeature enum_feature = decodeEnumFeature(parent); + if ((enum_feature == SimpleEnum) && GetFlag(parent, "scopedenum")) { + newsymname = Swig_name_member(0, Getattr(parent, "sym:name"), symname); + symname = newsymname; + } + // Add to language symbol table String *scope = 0; if (unnamedinstance || !parent_name || enum_feature == SimpleEnum) { - if (proxy_class_name) { + String *enumClassPrefix = getEnumClassPrefix(); + if (enumClassPrefix) { scope = NewString(""); if (nspace) Printf(scope, "%s.", nspace); - Printf(scope, "%s", proxy_class_name); + Printf(scope, "%s", enumClassPrefix); } else { scope = Copy(constants_interface_name); } @@ -1412,7 +1406,7 @@ public: else Printf(scope, ".%s", Getattr(parent, "sym:name")); } - if (!addSymbol(name, n, scope)) + if (!addSymbol(symname, n, scope)) return SWIG_ERROR; if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) { @@ -1466,6 +1460,7 @@ public: Delete(scope); } + Delete(newsymname); Delete(tmpValue); Swig_restore(n); return SWIG_OK; @@ -2268,7 +2263,7 @@ public: Printf(imcall, "swigCPtr"); String *this_type = Copy(getClassType()); - String *name = NewString("self"); + String *name = NewString("jself"); String *qualifier = Getattr(n, "qualifier"); if (qualifier) SwigType_push(this_type, qualifier); @@ -2959,6 +2954,16 @@ public: // Use the C syntax to make a true Java constant and hope that it compiles as Java code value = Getattr(n, "enumvalue") ? Copy(Getattr(n, "enumvalue")) : Copy(Getattr(n, "enumvalueex")); } else { + String *newsymname = 0; + if (!getCurrentClass() || !proxy_flag) { + String *enumClassPrefix = getEnumClassPrefix(); + if (enumClassPrefix) { + // A global scoped enum + newsymname = Swig_name_member(0, enumClassPrefix, symname); + symname = newsymname; + } + } + // Get the enumvalue from a JNI call if (!getCurrentClass() || !cparse_cplusplus || !proxy_flag) { // Strange hack to change the name @@ -2967,8 +2972,9 @@ public: value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); } else { memberconstantHandler(n); - value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), Swig_name_member(0, proxy_class_name, symname))); + value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), Swig_name_member(0, getEnumClassPrefix(), symname))); } + Delete(newsymname); } } return value; @@ -3115,44 +3121,6 @@ public: Delete(replacementname); } - /* ----------------------------------------------------------------------------- - * makeParameterName() - * - * Inputs: - * n - Node - * p - parameter node - * arg_num - parameter argument number - * setter - set this flag when wrapping variables - * Return: - * arg - a unique parameter name - * ----------------------------------------------------------------------------- */ - - String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter) { - - String *arg = 0; - String *pn = Getattr(p, "name"); - - // Use C parameter name unless it is a duplicate or an empty parameter name - int count = 0; - ParmList *plist = Getattr(n, "parms"); - while (plist) { - if ((Cmp(pn, Getattr(plist, "name")) == 0)) - count++; - plist = nextSibling(plist); - } - String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0; - arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn); - - if (setter && Cmp(arg, "self") != 0) { - // Note that for setters the parameter name is always set but sometimes includes C++ - // scope resolution, so we need to strip off the scope resolution to make a valid name. - Delete(arg); - arg = NewString("value"); //Swig_scopename_last(pn); - } - - return arg; - } - /* ----------------------------------------------------------------------------- * emitTypeWrapperClass() * ----------------------------------------------------------------------------- */ @@ -3670,7 +3638,6 @@ public: * --------------------------------------------------------------- */ int classDirectorMethod(Node *n, Node *parent, String *super) { - String *classname = Getattr(parent, "sym:name"); String *c_classname = Getattr(parent, "name"); String *name = Getattr(n, "name"); String *symname = Getattr(n, "sym:name"); @@ -3704,14 +3671,7 @@ public: String *imcall_args = NewString(""); int classmeth_off = curr_class_dmethod - first_class_dmethod; bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - String *qualified_classname = Copy(classname); - String *nspace = getNSpace(); - - if (nspace && package) - Insert(qualified_classname, 0, NewStringf("%s.%s.", package, nspace)); - else if(nspace) - Insert(qualified_classname, 0, NewStringf("%s.", nspace)); - + String *qualified_classname = getProxyName(getClassName()); // Kludge Alert: functionWrapper sets sym:overload properly, but it // isn't at this point, so we have to manufacture it ourselves. At least @@ -3772,7 +3732,7 @@ public: /* Create the intermediate class wrapper */ tm = Swig_typemap_lookup("jtype", n, "", 0); if (tm) { - Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, qualified_classname); + Printf(callback_def, " public static %s %s(%s jself", tm, imclass_dmethod, qualified_classname); } else { Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0)); } @@ -3834,7 +3794,6 @@ public: } Delete(adjustedreturntypeparm); - Delete(qualified_classname); Swig_director_parms_fixup(l); @@ -3889,7 +3848,7 @@ public: Printf(w->code, "if (swigjobj && jenv->IsSameObject(swigjobj, NULL) == JNI_FALSE) {\n"); } - /* Start the Java field descriptor for the intermediate class's upcall (insert self object) */ + /* Start the Java field descriptor for the intermediate class's upcall (insert jself object) */ Parm *tp = NewParmNode(c_classname, n); String *jdesc; @@ -4100,7 +4059,7 @@ public: /* Emit the intermediate class's upcall to the actual class */ - String *upcall = NewStringf("self.%s(%s)", symname, imcall_args); + String *upcall = NewStringf("jself.%s(%s)", symname, imcall_args); // Handle exception classes specified in the "except" feature's "throws" attribute addThrows(n, "feature:except", n); @@ -4475,18 +4434,15 @@ public: * ------------------------------------------------------------ */ int classDirectorEnd(Node *n) { - String *classname = Getattr(n, "sym:name"); + String *full_classname = Getattr(n, "name"); + String *classname = getProxyName(full_classname, true); String *director_classname = directorClassName(n); String *internal_classname; Wrapper *w = NewWrapper(); - if (Len(package_path) > 0 && Len(getNSpace()) > 0) - internal_classname = NewStringf("%s/%s/%s", package_path, getNSpace(), classname); - else if (Len(package_path) > 0) + if (Len(package_path) > 0) internal_classname = NewStringf("%s/%s", package_path, classname); - else if (Len(getNSpace()) > 0) - internal_classname = NewStringf("%s/%s", getNSpace(), classname); else internal_classname = NewStringf("%s", classname); @@ -4598,6 +4554,7 @@ public: /*---------------------------------------------------------------------- * extraDirectorProtectedCPPMethodsRequired() *--------------------------------------------------------------------*/ + bool extraDirectorProtectedCPPMethodsRequired() const { return false; } @@ -4623,6 +4580,10 @@ public: Setattr(n, "director:ctor", class_ctor); } + /*---------------------------------------------------------------------- + * nestedClassesSupport() + *--------------------------------------------------------------------*/ + NestedClassSupport nestedClassesSupport() const { return NCS_Full; } diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index 8b7a74037..0c3f02a75 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -1231,18 +1231,27 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) { // substract the extension "sym:overname", String *wrap_name = NewString(Getattr(n, "wrap:name")); String *overname = Getattr(n, "sym:overname"); + + Node *methodclass = Swig_methodclass(n); + String *class_name = Getattr(methodclass, "sym:name"); + int l1 = Len(wrap_name); int l2 = Len(overname); Delslice(wrap_name, l1 - l2, l1); - Setattr(n, "wrap:name", wrap_name); - state.function(WRAPPER_NAME, wrap_name); + String *new_string = NewStringf("%s_%s", class_name, wrap_name); + String *final_wrap_name = Swig_name_wrapper(new_string); + + Setattr(n, "wrap:name", final_wrap_name); + state.function(WRAPPER_NAME, final_wrap_name); + + t_function.replace("$jslocals", wrapper->locals) .replace("$jscode", wrapper->code); // call this here, to replace all variables - t_function.replace("$jswrapper", wrap_name) + t_function.replace("$jswrapper", final_wrap_name) .replace("$jsname", state.function(NAME)) .pretty_print(f_wrappers); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 5ea79f0ab..3efd4e425 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -57,7 +57,9 @@ extern "C" { /* Some status variables used during parsing */ static int InClass = 0; /* Parsing C++ or not */ static String *ClassName = 0; /* This is the real name of the current class */ +static String *EnumClassName = 0; /* Enum class name */ static String *ClassPrefix = 0; /* Class prefix */ +static String *EnumClassPrefix = 0; /* Prefix for strongly typed enums (including ClassPrefix) */ static String *NSpace = 0; /* Namespace for the nspace feature */ static String *ClassType = 0; /* Fully qualified type name to use */ static String *DirectorClassName = 0; /* Director name of the current class */ @@ -1650,10 +1652,24 @@ int Language::enumDeclaration(Node *n) { String *oldNSpace = NSpace; NSpace = Getattr(n, "sym:nspace"); + String *oldEnumClassPrefix = EnumClassPrefix; + if (GetFlag(n, "scopedenum")) { + assert(Getattr(n, "sym:name")); + assert(Getattr(n, "name")); + EnumClassPrefix = ClassPrefix ? NewStringf("%s_", ClassPrefix) : NewString(""); + Printv(EnumClassPrefix, Getattr(n, "sym:name"), NIL); + EnumClassName = Copy(Getattr(n, "name")); + } if (!ImportMode) { emit_children(n); } + if (GetFlag(n, "scopedenum")) { + Delete(EnumClassName); + EnumClassName = 0; + Delete(EnumClassPrefix); + EnumClassPrefix = oldEnumClassPrefix; + } NSpace = oldNSpace; return SWIG_OK; @@ -1667,7 +1683,7 @@ int Language::enumvalueDeclaration(Node *n) { if (CurrentClass && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; - Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL); + Swig_require("enumvalueDeclaration", n, "*name", "*sym:name", "?value", NIL); String *value = Getattr(n, "value"); String *name = Getattr(n, "name"); String *tmpValue; @@ -1678,6 +1694,13 @@ int Language::enumvalueDeclaration(Node *n) { tmpValue = NewString(name); Setattr(n, "value", tmpValue); + Node *parent = parentNode(n); + if (GetFlag(parent, "scopedenum")) { + String *symname = Swig_name_member(0, Getattr(parent, "sym:name"), Getattr(n, "sym:name")); + Setattr(n, "sym:name", symname); + Delete(symname); + } + if (!CurrentClass || !cparse_cplusplus) { Setattr(n, "name", tmpValue); /* for wrapping of enums in a namespace when emit_action is used */ constantWrapper(n); @@ -1716,16 +1739,19 @@ int Language::memberconstantHandler(Node *n) { Setattr(n, "feature:except", Getattr(n, "feature:exceptvar")); } + String *enumvalue_symname = Getattr(n, "enumvalueDeclaration:sym:name"); // Only set if a strongly typed enum String *name = Getattr(n, "name"); String *symname = Getattr(n, "sym:name"); String *value = Getattr(n, "value"); - String *mrename = Swig_name_member(0, ClassPrefix, symname); + String *mrename = Swig_name_member(0, EnumClassPrefix, enumvalue_symname ? enumvalue_symname : symname); Setattr(n, "sym:name", mrename); String *new_name = 0; if (Extend) new_name = Copy(value); + else if (EnumClassName) + new_name = NewStringf("%s::%s", isNonVirtualProtectedAccess(n) ? DirectorClassName : EnumClassName, name); else new_name = NewStringf("%s::%s", isNonVirtualProtectedAccess(n) ? DirectorClassName : ClassName, name); Setattr(n, "name", new_name); @@ -2043,7 +2069,7 @@ int Language::classDirectorConstructors(Node *n) { needed, since there is a public constructor already defined. (scottm) This code is needed here to make the director_abstract + - test generate compileable code (Example2 in director_abastract.i). + test generate compilable code (Example2 in director_abastract.i). (mmatus) This is very strange, since swig compiled with gcc3.2.3 doesn't need it here.... @@ -2369,6 +2395,7 @@ int Language::classDeclaration(Node *n) { int oldInClass = InClass; String *oldClassType = ClassType; String *oldClassPrefix = ClassPrefix; + String *oldEnumClassPrefix = EnumClassPrefix; String *oldClassName = ClassName; String *oldDirectorClassName = DirectorClassName; String *oldNSpace = NSpace; @@ -2410,6 +2437,7 @@ int Language::classDeclaration(Node *n) { Push(ClassPrefix, "_"); Push(ClassPrefix, Getattr(outerClass, "sym:name")); } + EnumClassPrefix = Copy(ClassPrefix); if (strip) { ClassType = Copy(name); } else { @@ -2477,6 +2505,8 @@ int Language::classDeclaration(Node *n) { CurrentClass = oldCurrentClass; Delete(ClassType); ClassType = oldClassType; + Delete(EnumClassPrefix); + EnumClassPrefix = oldEnumClassPrefix; Delete(ClassPrefix); ClassPrefix = oldClassPrefix; Delete(ClassName); @@ -2664,7 +2694,8 @@ int Language::constructorDeclaration(Node *n) { String *scope = Swig_scopename_check(ClassName) ? Swig_scopename_prefix(ClassName) : 0; String *actual_name = scope ? NewStringf("%s::%s", scope, name) : NewString(name); Delete(scope); - if (!Equal(actual_name, expected_name) && !SwigType_istemplate(expected_name)) { + if (!Equal(actual_name, expected_name) && !SwigType_istemplate(expected_name) && !SwigType_istemplate(actual_name)) { + // Checking templates is skipped but they ought to be checked... they are just somewhat more tricky to check correctly bool illegal_name = true; if (Extend) { // Check for typedef names used as a constructor name in %extend. This is deprecated except for anonymous @@ -2962,6 +2993,12 @@ int Language::variableWrapper(Node *n) { Delattr(n,"varset"); Delattr(n,"varget"); + String *newsymname = 0; + if (!CurrentClass && EnumClassPrefix) { + newsymname = Swig_name_member(0, EnumClassPrefix, symname); + symname = newsymname; + } + /* If no way to set variables. We simply create functions */ int assignable = is_assignable(n); int flags = use_naturalvar_mode(n); @@ -3019,6 +3056,7 @@ int Language::variableWrapper(Node *n) { functionWrapper(n); Delattr(n, "varget"); Swig_restore(n); + Delete(newsymname); return SWIG_OK; } @@ -3499,6 +3537,45 @@ int Language::is_smart_pointer() const { return SmartPointer; } +/* ----------------------------------------------------------------------------- + * Language::makeParameterName() + * + * Inputs: + * n - Node + * p - parameter node + * arg_num - parameter argument number + * setter - set this flag when wrapping variables + * Return: + * arg - a unique parameter name + * ----------------------------------------------------------------------------- */ +String *Language::makeParameterName(Node *n, Parm *p, int arg_num, bool setter) const { + + String *arg = 0; + String *pn = Getattr(p, "name"); + + // Use C parameter name unless it is a duplicate or an empty parameter name + int count = 0; + ParmList *plist = Getattr(n, "parms"); + while (plist) { + if ((Cmp(pn, Getattr(plist, "name")) == 0)) + count++; + plist = nextSibling(plist); + } + String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0; + arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn); + + if (setter && Cmp(arg, "self") != 0) { + // Some languages (C#) insist on calling the input variable "value" while + // others (D, Java) could, in principle, use something different but this + // would require more work, and so we just use "value" for them too. + // For setters the parameter name sometimes includes C++ scope resolution which needs removing. + Delete(arg); + arg = NewString("value"); + } + + return arg; +} + /* ----------------------------------------------------------------------------- * Language::() * ----------------------------------------------------------------------------- */ @@ -3517,9 +3594,22 @@ bool Language::extraDirectorProtectedCPPMethodsRequired() const { return true; } +/* ----------------------------------------------------------------------------- + * Language::nestedClassesSupport() + * ----------------------------------------------------------------------------- */ + Language::NestedClassSupport Language::nestedClassesSupport() const { return NCS_Unknown; } + +/* ----------------------------------------------------------------------------- + * Language::kwargsSupport() + * ----------------------------------------------------------------------------- */ + +bool Language::kwargsSupport() const { + return false; +} + /* ----------------------------------------------------------------------------- * Language::is_wrapping_class() * ----------------------------------------------------------------------------- */ @@ -3560,6 +3650,14 @@ String *Language::getClassPrefix() const { return ClassPrefix; } +/* ----------------------------------------------------------------------------- + * Language::getEnumClassPrefix() + * ----------------------------------------------------------------------------- */ + +String *Language::getEnumClassPrefix() const { + return EnumClassPrefix; +} + /* ----------------------------------------------------------------------------- * Language::getClassType() * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 46e21fb91..8211fb317 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -1184,10 +1184,12 @@ public: if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; - Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL); + Swig_require("enumvalueDeclaration", n, "*name", "?value", "*sym:name", NIL); + String *symname = Getattr(n, "sym:name"); String *value = Getattr(n, "value"); String *name = Getattr(n, "name"); String *tmpValue; + Node *parent = parentNode(n); if (value) tmpValue = NewString(value); @@ -1196,6 +1198,13 @@ public: Setattr(n, "value", tmpValue); Setattr(n, "name", tmpValue); /* for wrapping of enums in a namespace when emit_action is used */ + + if (GetFlag(parent, "scopedenum")) { + symname = Swig_name_member(0, Getattr(parent, "sym:name"), symname); + Setattr(n, "sym:name", symname); + Delete(symname); + } + int result = constantWrapper(n); Delete(tmpValue); diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 47d0d374b..aa0d7d589 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -50,6 +50,7 @@ int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime extern "C" { extern String *ModuleName; extern int ignore_nested_classes; + extern int kwargs_supported; } /* usage string split into multiple parts otherwise string is too big for some compilers */ @@ -62,6 +63,8 @@ static const char *usage1 = (const char *) "\ -co - Check out of the SWIG library\n\ -copyctor - Automatically generate copy constructors wherever possible\n\ -cpperraswarn - Treat the preprocessor #error statement as #warning (default)\n\ + -cppext - Change file extension of generated C++ files to \n\ + (default is cxx, except for PHP which uses cpp)\n\ -copyright - Display copyright notices\n\ -debug-classes - Display information about the classes found in the interface\n\ -debug-module - Display module parse tree at stages 1-4, is a csv list of stages\n\ @@ -79,6 +82,9 @@ static const char *usage1 = (const char *) "\ -directors - Turn on director mode for all the classes, mainly for testing\n\ -dirprot - Turn on wrapping of protected members for director classes (default)\n\ -D - Define a symbol (for conditional compilation)\n\ +"; + +static const char *usage2 = (const char *) "\ -E - Preprocess only, does not generate wrapper code\n\ -external-runtime [file] - Export the SWIG runtime stack\n\ -fakeversion - Make SWIG fake the program version number to \n\ @@ -86,9 +92,6 @@ static const char *usage1 = (const char *) "\ -features - Set global features, where is a comma separated list of\n\ features, eg -features directors,autodoc=1\n\ If no explicit value is given to the feature, a default of 1 is used\n\ -"; - -static const char *usage2 = (const char *) "\ -fastdispatch - Enable fast dispatch mode to produce faster overload dispatcher code\n\ -Fmicrosoft - Display error/warning messages in Microsoft format\n\ -Fstandard - Display error/warning messages in commonly used format\n\ @@ -100,6 +103,9 @@ static const char *usage2 = (const char *) "\ -importall - Follow all #include statements as imports\n\ -includeall - Follow all #include statements\n\ -l - Include SWIG library file \n\ +"; + +static const char *usage3 = (const char *) "\ -macroerrors - Report errors inside macros\n\ -makedefault - Create default constructors/destructors (the default)\n\ -M - List all dependencies\n\ @@ -119,10 +125,10 @@ static const char *usage2 = (const char *) "\ -noexcept - Do not wrap exception specifiers\n\ -nofastdispatch - Disable fast dispatch mode (default)\n\ -nopreprocess - Skip the preprocessor step\n\ + -notemplatereduce - Disable reduction of the typedefs in templates\n\ "; -static const char *usage3 = (const char *) "\ - -notemplatereduce - Disable reduction of the typedefs in templates\n\ +static const char *usage4 = (const char *) "\ -O - Enable the optimization options: \n\ -fastdispatch -fvirtual \n\ -o - Set name of the output file to \n\ @@ -677,6 +683,15 @@ void SWIG_getoptions(int argc, char *argv[]) { } else if (strcmp(argv[i], "-nocpperraswarn") == 0) { Preprocessor_error_as_warning(0); Swig_mark_arg(i); + } else if (strcmp(argv[i], "-cppext") == 0) { + Swig_mark_arg(i); + if (argv[i + 1]) { + SWIG_config_cppext(argv[i + 1]); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } } else if ((strcmp(argv[i], "-debug-typemap") == 0) || (strcmp(argv[i], "-debug_typemap") == 0) || (strcmp(argv[i], "-tm_debug") == 0)) { tm_debug = 1; Swig_mark_arg(i); @@ -850,6 +865,7 @@ void SWIG_getoptions(int argc, char *argv[]) { fputs(usage1, stdout); fputs(usage2, stdout); fputs(usage3, stdout); + fputs(usage4, stdout); Swig_mark_arg(i); help = 1; } @@ -904,6 +920,8 @@ int SWIG_main(int argc, char *argv[], Language *l) { // Inform the parser if the nested classes should be ignored unless explicitly told otherwise via feature:flatnested ignore_nested_classes = l->nestedClassesSupport() == Language::NCS_Unknown ? 1 : 0; + kwargs_supported = l->kwargsSupport() ? 1 : 0; + // Create Library search directories // Check for SWIG_LIB environment variable diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index db5d0981b..d9a0c922b 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -1407,25 +1407,12 @@ MODULA3(): } } - if (Cmp(nodeType(n), "constant") == 0) { - // Wrapping a constant hack - Swig_save("functionWrapper", n, "wrap:action", NIL); - - // below based on Swig_VargetToFunction() - SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); - Setattr(n, "wrap:action", NewStringf("%s = (%s)(%s);", Swig_cresult_name(), SwigType_lstr(ty, 0), Getattr(n, "value"))); - } - Setattr(n, "wrap:name", wname); // Now write code to make the function call if (!native_function_flag) { String *actioncode = emit_action(n); - if (Cmp(nodeType(n), "constant") == 0) { - Swig_restore(n); - } - /* Return value if necessary */ String *tm; if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) { @@ -3621,35 +3608,6 @@ MODULA3(): return substitution_performed; } - /* ----------------------------------------------------------------------------- - * makeParameterName() - * - * Inputs: - * n - Node - * p - parameter node - * arg_num - parameter argument number - * Return: - * arg - a unique parameter name - * ----------------------------------------------------------------------------- */ - - String *makeParameterName(Node *n, Parm *p, int arg_num) { - - // Use C parameter name unless it is a duplicate or an empty parameter name - String *pn = Getattr(p, "name"); - int count = 0; - ParmList *plist = Getattr(n, "parms"); - while (plist) { - if ((Cmp(pn, Getattr(plist, "name")) == 0)) - count++; - plist = nextSibling(plist); - } - String *arg = (!pn || (count > 1)) ? NewStringf("arg%d", - arg_num) : Copy(Getattr(p, - "name")); - - return arg; - } - /* ----------------------------------------------------------------------------- * attachParameterNames() * diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index f1ec8a8cf..ac73c1f0c 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -19,7 +19,7 @@ static const char *usage = "\ Ocaml Options (available with -ocaml)\n\ -oldvarnames - Old intermediary method names for variable wrappers\n\ -prefix - Set a prefix to be prepended to all names\n\ - -suffix - Change .cxx to something else\n\ + -suffix - Deprecated alias for general option -cppext\n\ -where - Emit library location\n\ \n"; @@ -114,6 +114,7 @@ public: } } else if (strcmp(argv[i], "-suffix") == 0) { if (argv[i + 1]) { + Printf(stderr, "swig: warning: -suffix option deprecated. SWIG 3.0.4 and later provide a -cppext option which should be used instead.\n"); SWIG_config_cppext(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); @@ -1350,9 +1351,6 @@ public: /* * Modified polymorphism code for Ocaml language module. - * Original: - * C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose - * * * TODO * diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 12903166c..236598c1f 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -19,8 +19,10 @@ static String *op_prefix = 0; static const char *usage = "\ Octave Options (available with -octave)\n\ + -cppcast - Enable C++ casting operators (default)\n\ -globals - Set used to access C global variables [default: 'cvar']\n\ Use '.' to load C global variables into module namespace\n\ + -nocppcast - Disable C++ casting operators\n\ -opprefix - Prefix for global operator functions [default: 'op_']\n\ \n"; @@ -90,6 +92,8 @@ public: } virtual void main(int argc, char *argv[]) { + int cppcast = 1; + for (int i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-help") == 0) { @@ -112,6 +116,12 @@ public: } else { Swig_arg_error(); } + } else if (strcmp(argv[i], "-cppcast") == 0) { + cppcast = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nocppcast") == 0) { + cppcast = 0; + Swig_mark_arg(i); } } } @@ -120,6 +130,8 @@ public: global_name = NewString("cvar"); if (!op_prefix) op_prefix = NewString("op_"); + if(cppcast) + Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); SWIG_library_directory("octave"); Preprocessor_define("SWIGOCTAVE 1", 0); @@ -952,7 +964,26 @@ public: SwigType *t = Copy(Getattr(n, "name")); SwigType_add_pointer(t); + String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) + SwigType *smart = 0; + if (smartptr) { + SwigType *cpt = Swig_cparse_type(smartptr); + if (cpt) { + smart = SwigType_typedef_resolve_all(cpt); + Delete(cpt); + } else { + // TODO: report line number of where the feature comes from + Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, class_name); + } + } String *wrap_class = NewStringf("&_wrap_class_%s", class_name); + if(smart){ + SwigType_add_pointer(smart); + SwigType_remember_clientdata(smart, wrap_class); + } + Delete(smart); + Delete(smartptr); + //String *wrap_class = NewStringf("&_wrap_class_%s", class_name); SwigType_remember_clientdata(t, wrap_class); int use_director = Swig_directorclass(n); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index ff504d461..224c4852e 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -342,11 +342,18 @@ public: Node *options = Getattr(mod, "options"); module = Copy(Getattr(n,"name")); + String *underscore_module = Copy(module); + Replaceall(underscore_module,":","_"); + + if (verbose > 0) { + fprintf(stdout, "top: using namespace_module: %s\n", Char(namespace_module)); + } + if (directorsEnabled()) { Swig_banner(f_directors_h); Printf(f_directors_h, "\n"); - Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module); - Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module); + Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", underscore_module); + Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", underscore_module); if (dirprot_mode()) { Printf(f_directors_h, "#include \n"); Printf(f_directors_h, "#include \n\n"); @@ -379,13 +386,6 @@ public: fprintf(stdout, "top: No package found\n"); } } - String *underscore_module = Copy(module); - Replaceall(underscore_module,":","_"); - - if (verbose > 0) { - fprintf(stdout, "top: using namespace_module: %s\n", Char(namespace_module)); - } - /* If we're in blessed mode, change the package name to "packagec" */ if (blessed) { @@ -2178,12 +2178,12 @@ public: SwigType_add_pointer(ptype); String *mangle = SwigType_manglestr(ptype); - Wrapper_add_local(w, "self", "SV *self"); - Printf(w->code, "self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE%s, SWIG_SHADOW);\n", mangle); - Printf(w->code, "sv_bless(self, gv_stashpv(swig_get_class(), 0));\n"); + Wrapper_add_local(w, "swigself", "SV *swigself"); + Printf(w->code, "swigself = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE%s, SWIG_SHADOW);\n", mangle); + Printf(w->code, "sv_bless(swigself, gv_stashpv(swig_get_class(), 0));\n"); Delete(mangle); Delete(ptype); - Append(pstack, "XPUSHs(self);\n"); + Append(pstack, "XPUSHs(swigself);\n"); } Parm *p; diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index b07c82d3b..e6105eb3e 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -44,7 +44,6 @@ static const char *usage = "\ PHP Options (available with -php)\n\ - -cppext - Change C++ file extension to (default is cpp)\n\ -noproxy - Don't generate proxy classes.\n\ -prefix - Prepend to all class names in PHP wrappers\n\ \n"; @@ -221,15 +220,6 @@ public: } else { Swig_arg_error(); } - } else if (strcmp(argv[i], "-cppext") == 0) { - if (argv[i + 1]) { - SWIG_config_cppext(argv[i + 1]); - Swig_mark_arg(i); - Swig_mark_arg(i + 1); - i++; - } else { - Swig_arg_error(); - } } else if ((strcmp(argv[i], "-noshadow") == 0) || (strcmp(argv[i], "-noproxy") == 0)) { shadow = 0; Swig_mark_arg(i); @@ -836,13 +826,6 @@ public: Delete(args); args = NULL; } - if (is_member_director(n)) { - Wrapper_add_local(f, "director", "Swig::Director *director = 0"); - Printf(f->code, "director = dynamic_cast(arg1);\n"); - Wrapper_add_local(f, "upcall", "bool upcall = false"); - Printf(f->code, "upcall = !director->swig_is_overridden_method((char *)\"%s%s\", (char *)\"%s\");\n", - prefix, Swig_class_name(Swig_methodclass(n)), name); - } // This generated code may be called: // 1) as an object method, or @@ -931,6 +914,12 @@ public: Delete(source); } + if (is_member_director(n)) { + Wrapper_add_local(f, "upcall", "bool upcall = false"); + Printf(f->code, "upcall = !Swig::Director::swig_is_overridden_method((char *)\"%s%s\", (char *)\"%s\" TSRMLS_CC);\n", + prefix, Swig_class_name(Swig_methodclass(n)), name); + } + Swig_director_emit_dynamic_cast(n, f); /* Insert constraint checking code */ @@ -1278,7 +1267,7 @@ public: break; char *p; errno = 0; - int n = strtol(Char(value), &p, 0); + long n = strtol(Char(value), &p, 0); Clear(value); if (errno || *p) { Append(value, "?"); @@ -1293,10 +1282,11 @@ public: case T_SCHAR: case T_SHORT: case T_INT: - case T_LONG: { + case T_LONG: + case T_LONGLONG: { char *p; errno = 0; - unsigned int n = strtol(Char(value), &p, 0); + long n = strtol(Char(value), &p, 0); (void) n; if (errno || *p) { Clear(value); @@ -1307,7 +1297,8 @@ public: case T_UCHAR: case T_USHORT: case T_UINT: - case T_ULONG: { + case T_ULONG: + case T_ULONGLONG: { char *p; errno = 0; unsigned int n = strtoul(Char(value), &p, 0); @@ -1319,7 +1310,8 @@ public: break; } case T_FLOAT: - case T_DOUBLE:{ + case T_DOUBLE: + case T_LONGDOUBLE: { char *p; errno = 0; /* FIXME: strtod is locale dependent... */ @@ -1338,13 +1330,6 @@ public: } break; } - case T_REFERENCE: - case T_RVALUE_REFERENCE: - case T_USER: - case T_ARRAY: - Clear(value); - Append(value, "?"); - break; case T_STRING: if (Len(value) < 2) { // How can a string (including "" be less than 2 characters?) @@ -1393,6 +1378,11 @@ public: } break; } + default: + /* Safe default */ + Clear(value); + Append(value, "?"); + break; } if (!arg_values[argno]) { @@ -1741,7 +1731,8 @@ public: } } else { Printf(output, "\t\tif (!is_resource($r)) return $r;\n"); - Printf(output, "\t\tswitch (get_resource_type($r)) {\n"); + String *wrapobj = NULL; + String *common = NULL; Iterator i = First(ret_types); while (i.item) { SwigType *ret_type = i.item; @@ -1761,22 +1752,43 @@ public: continue; } } - Printf(output, "\t\t"); - if (i.item) { - Printf(output, "case '%s': ", mangled); - } else { - Printf(output, "default: "); - } const char *classname = GetChar(class_node, "sym:name"); if (!classname) classname = GetChar(class_node, "name"); + String * action = NewStringEmpty(); if (classname) - Printf(output, "return new %s%s($r);\n", prefix, classname); + Printf(action, "return new %s%s($r);\n", prefix, classname); else - Printf(output, "return $r;\n"); + Printf(action, "return $r;\n"); + if (!wrapobj) { + wrapobj = NewString("\t\tswitch (get_resource_type($r)) {\n"); + common = action; + } else { + if (common && Cmp(common, action) != 0) { + Delete(common); + common = NULL; + } + } + Printf(wrapobj, "\t\t"); + if (i.item) { + Printf(wrapobj, "case '%s': ", mangled); + } else { + Printf(wrapobj, "default: "); + } + Printv(wrapobj, action, NIL); + if (action != common) Delete(action); Delete(mangled); } - Printf(output, "\t\t}\n"); + Printf(wrapobj, "\t\t}\n"); + if (common) { + // All cases have the same action, so eliminate the switch + // wrapper. + Printf(output, "\t\t%s", common); + Delete(common); + } else { + Printv(output, wrapobj, NIL); + } + Delete(wrapobj); } } else { if (non_void_return) { @@ -2045,6 +2057,17 @@ done: } else if (GetFlag(n, "feature:exceptionclass")) { Append(s_phpclasses, "extends Exception "); } + { + Node *node = NewHash(); + Setattr(node, "type", Getattr(n, "name")); + Setfile(node, Getfile(n)); + Setline(node, Getline(n)); + String * interfaces = Swig_typemap_lookup("phpinterfaces", node, "", 0); + if (interfaces) { + Printf(s_phpclasses, "implements %s ", interfaces); + } + Delete(node); + } Printf(s_phpclasses, "{\n\tpublic $%s=null;\n", SWIG_PTR); if (!baseclass) { // Only store this in the base class (NB !baseclass means we *are* @@ -2622,12 +2645,12 @@ done: Printf(w->code, "zval *args[%d];\n", idx); } Printf(w->code, "zval *%s, funcname;\n", Swig_cresult_name()); - Printf(w->code, "MAKE_STD_ZVAL(%s);\n", Swig_cresult_name()); - const char * funcname = GetChar(n, "sym:name"); - Printf(w->code, "ZVAL_STRINGL(&funcname, (char *)\"%s\", %d, 0);\n", funcname, strlen(funcname)); Append(w->code, "if (!swig_self) {\n"); Append(w->code, " SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");"); Append(w->code, "}\n\n"); + Printf(w->code, "MAKE_STD_ZVAL(%s);\n", Swig_cresult_name()); + const char * funcname = GetChar(n, "sym:name"); + Printf(w->code, "ZVAL_STRINGL(&funcname, (char *)\"%s\", %d, 0);\n", funcname, strlen(funcname)); /* wrap complex arguments to zvals */ Printv(w->code, wrap_args, NIL); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 06c1c4868..7a9547a1a 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -17,6 +17,8 @@ static int treduce = SWIG_cparse_template_reduce(0); #include +#include +#include #define PYSHADOW_MEMBER 0x2 #define WARN_PYTHON_MULTIPLE_INH 405 @@ -807,7 +809,7 @@ public: Printv(f_shadow, "\nfrom sys import version_info\n", NULL); if (!builtin && fastproxy) { - Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL); + Printv(f_shadow, "if version_info >= (3, 0, 0):\n", NULL); Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module); Printv(f_shadow, "else:\n", NULL); Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL); @@ -822,7 +824,7 @@ public: * isn't available in python 2.4 or earlier, so we have to write some * code conditional on the python version. */ - Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL); + Printv(f_shadow, "if version_info >= (2, 6, 0):\n", NULL); Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL); Printv(f_shadow, tab8, "from os.path import dirname\n", NULL); Printv(f_shadow, tab8, "import imp\n", NULL); @@ -852,40 +854,45 @@ public: Printf(f_shadow, "from %s import *\n", module); } if (modern || !classic) { - Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL); + Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n\n", NULL); } /* if (!modern) */ /* always needed, a class can be forced to be no-modern, such as an exception */ { // Python-2.2 object hack Printv(f_shadow, - "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n", - tab4, "if (name == \"thisown\"): return self.this.own(value)\n", - tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n", + "\n", "def _swig_setattr_nondynamic(self, class_type, name, value, static=1):\n", + tab4, "if (name == \"thisown\"):\n", tab8, "return self.this.own(value)\n", + tab4, "if (name == \"this\"):\n", tab8, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n", #ifdef USE_THISOWN - tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n", + tab4, tab8, "if hasattr(value,\"thisown\"):\n", tab8, tab8, "self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n", #endif - tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n", + tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name, None)\n", tab4, "if method:\n", tab4, tab4, "return method(self, value)\n", #ifdef USE_THISOWN tab4, "if (not static) or (name == \"thisown\"):\n", #else tab4, "if (not static):\n", #endif - tab4, tab4, "self.__dict__[name] = value\n", + tab4, tab4, "object.__setattr__(self, name, value)\n", tab4, "else:\n", tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", - "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL); + "\n", "def _swig_setattr(self, class_type, name, value):\n", tab4, "return _swig_setattr_nondynamic(self, class_type, name, value, 0)\n\n", NIL); Printv(f_shadow, - "def _swig_getattr(self,class_type,name):\n", - tab4, "if (name == \"thisown\"): return self.this.own()\n", - tab4, "method = class_type.__swig_getmethods__.get(name,None)\n", - tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL); + "\n", "def _swig_getattr_nondynamic(self, class_type, name, static=1):\n", + tab4, "if (name == \"thisown\"):\n", tab8, "return self.this.own()\n", + tab4, "method = class_type.__swig_getmethods__.get(name, None)\n", + tab4, "if method:\n", tab8, "return method(self)\n", + tab4, "if (not static):\n", + tab4, tab4, "return object.__getattr__(self, name)\n", + tab4, "else:\n", + tab4, tab4, "raise AttributeError(name)\n\n", + "def _swig_getattr(self, class_type, name):\n", tab4, "return _swig_getattr_nondynamic(self, class_type, name, 0)\n\n", NIL); Printv(f_shadow, - "def _swig_repr(self):\n", - tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n", - tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); + "\n", "def _swig_repr(self):\n", + tab4, "try:\n", tab8, "strthis = \"proxy of \" + self.this.__repr__()\n", + tab4, "except:\n", tab8, "strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); if (!classic) { /* Usage of types.ObjectType is deprecated. @@ -895,19 +902,19 @@ public: // "import types\n", "try:\n", // " _object = types.ObjectType\n", - " _object = object\n", " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", + tab4, "_object = object\n", tab4, "_newclass = 1\n", "except AttributeError:\n", tab4, "class _object:\n", tab8, "pass\n", tab4, "_newclass = 0\n", // "del types\n", "\n\n", NIL); } } if (modern) { - Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n", + Printv(f_shadow, "\n", "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self, name, value):\n", #ifdef USE_THISOWN - tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n", + tab4, tab4, "if hasattr(self, name) or (name in (\"this\", \"thisown\")):\n", #else - tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n", + tab4, tab4, "if (name == \"thisown\"):\n", tab8, tab4, "return self.this.own(value)\n", tab4, tab4, "if hasattr(self, name) or (name == \"this\"):\n", #endif - tab4, tab4, tab4, "set(self,name,value)\n", + tab4, tab4, tab4, "set(self, name, value)\n", tab4, tab4, "else:\n", tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL); } @@ -1523,6 +1530,21 @@ public: return ds; } + virtual String *makeParameterName(Node *n, Parm *p, int arg_num, bool = false) const { + // For the keyword arguments, we want to preserve the names as much as possible, + // so we only minimally rename them in Swig_name_make(), e.g. replacing "keyword" + // with "_keyword" if they have any name at all. + if (check_kwargs(n)) { + String *name = Getattr(p, "name"); + if (name) + return Swig_name_make(p, 0, name, 0, 0); + } + + // For the other cases use the general function which replaces arguments whose + // names clash with keywords with (less useful) "argN". + return Language::makeParameterName(n, p, arg_num); + } + /* ----------------------------------------------------------------------------- * addMissingParameterNames() * For functions that have not had nameless parameters set in the Language class. @@ -1534,13 +1556,14 @@ public: * The "lname" attribute in each parameter in plist will be contain a parameter name * ----------------------------------------------------------------------------- */ - void addMissingParameterNames(ParmList *plist, int arg_offset) { + void addMissingParameterNames(Node *n, ParmList *plist, int arg_offset) { Parm *p = plist; int i = arg_offset; while (p) { if (!Getattr(p, "lname")) { - String *pname = Swig_cparm_name(p, i); - Delete(pname); + String *name = makeParameterName(n, p, i); + Setattr(p, "lname", name); + Delete(name); } i++; p = nextSibling(p); @@ -1563,14 +1586,18 @@ public: Parm *pnext; - int lines = 0; - int start_arg_num = is_wrapping_class() ? 1 : 0; - const int maxwidth = 80; + // Normally we start counting auto-generated argument names from 1, but we should do it from 2 + // if the first argument is "self", i.e. if we're handling a non-static member function. + int arg_num = 1; + if (is_wrapping_class()) { + if (Cmp(Getattr(n, "storage"), "static") != 0) + arg_num++; + } if (calling) func_annotation = false; - addMissingParameterNames(plist, start_arg_num); // for $1_name substitutions done in Swig_typemap_attach_parms + addMissingParameterNames(n, plist, arg_num); // for $1_name substitutions done in Swig_typemap_attach_parms Swig_typemap_attach_parms("in", plist, 0); Swig_typemap_attach_parms("doc", plist, 0); @@ -1579,7 +1606,7 @@ public: return doc; } - for (p = plist; p; p = pnext) { + for (p = plist; p; p = pnext, arg_num++) { String *tm = Getattr(p, "tmap:in"); if (tm) { @@ -1602,25 +1629,22 @@ public: } // Note: the generated name should be consistent with that in kwnames[] - name = name ? name : Getattr(p, "name"); - name = name ? name : Getattr(p, "lname"); - name = Swig_name_make(p, 0, name, 0, 0); // rename parameter if a keyword + String *made_name = 0; + if (!name) { + name = made_name = makeParameterName(n, p, arg_num); + } type = type ? type : Getattr(p, "type"); value = value ? value : Getattr(p, "value"); - if (SwigType_isvarargs(type)) + if (SwigType_isvarargs(type)) { + Delete(made_name); break; + } if (Len(doc)) { // add a comma to the previous one if any Append(doc, ", "); - - // Do we need to wrap a long line? - if ((Len(doc) - lines * maxwidth) > maxwidth) { - Printf(doc, "\n%s", tab4); - lines += 1; - } } // Do the param type too? @@ -1637,22 +1661,16 @@ public: } // Write the function annotation if (func_annotation) - Printf(doc, " : '%s'", type_str); + Printf(doc, ": '%s'", type_str); // Write default value if (value && !calling) { String *new_value = convertValue(value, Getattr(p, "type")); - if (new_value) { - value = new_value; - } else { - Node *lookup = Swig_symbol_clookup(value, 0); - if (lookup) - value = Getattr(lookup, "sym:name"); - } - Printf(doc, "=%s", value); + if (new_value) + Printf(doc, "=%s", new_value); } Delete(type_str); - Delete(name); + Delete(made_name); } if (pdocs) Setattr(n, "feature:pdocs", pdocs); @@ -1798,58 +1816,192 @@ public: return doc; } + /* ------------------------------------------------------------ + * convertDoubleValue() + * Check if the given string looks like a decimal floating point constant + * and return it if it does, otherwise return NIL. + * ------------------------------------------------------------ */ + String *convertDoubleValue(String *v) { + const char *const s = Char(v); + char *end; + + double value = strtod(s, &end); + (void) value; + if (errno != ERANGE && end != s) { + // An added complication: at least some versions of strtod() recognize + // hexadecimal floating point numbers which don't exist in Python, so + // detect them ourselves and refuse to convert them (this can't be done + // without loss of precision in general). + // + // Also don't accept neither "NAN" nor "INFINITY" (both of which + // conveniently contain "n"). + if (strpbrk(s, "xXnN")) + return NIL; + + // Disregard optional "f" suffix, it can be just dropped in Python as it + // uses doubles for everything anyhow. + for (char* p = end; *p != '\0'; ++p) { + switch (*p) { + case 'f': + case 'F': + break; + + default: + return NIL; + } + } + + // Avoid unnecessary string allocation in the common case when we don't + // need to remove any suffix. + return *end == '\0' ? v : NewStringWithSize(s, end - s); + } + + return NIL; + } + /* ------------------------------------------------------------ * convertValue() - * Check if string v can be a Python value literal, - * (eg. number or string), or translate it to a Python literal. + * Check if string v can be a Python value literal or a + * constant. Return NIL if it isn't. * ------------------------------------------------------------ */ String *convertValue(String *v, SwigType *t) { - if (v && Len(v) > 0) { - char fc = (Char(v))[0]; - if (('0' <= fc && fc <= '9') || '\'' == fc || '"' == fc) { - /* number or string (or maybe NULL pointer) */ - if (SwigType_ispointer(t) && Strcmp(v, "0") == 0) - return NewString("None"); - else - return v; + const char *const s = Char(v); + char *end; + + // Check if this is a number in any base. + long value = strtol(s, &end, 0); + (void) value; + if (end != s) { + if (errno == ERANGE) { + // There was an overflow, we could try representing the value as Python + // long integer literal, but for now don't bother with it. + return NIL; } - if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) - return NewString("True"); - if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) - return NewString("False"); - if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0) - return SwigType_ispointer(t) ? NewString("None") : NewString("0"); + + if (*end != '\0') { + // If there is a suffix after the number, we can safely ignore any + // combination of "l" and "u", but not anything else (again, stuff like + // "LL" could be handled, but we don't bother to do it currently). + bool seen_long = false; + for (char* p = end; *p != '\0'; ++p) { + switch (*p) { + case 'l': + case 'L': + // Bail out on "LL". + if (seen_long) + return NIL; + seen_long = true; + break; + + case 'u': + case 'U': + break; + + default: + // Except that our suffix could actually be the fractional part of + // a floating point number, so we still have to check for this. + return convertDoubleValue(v); + } + } + } + + // Deal with the values starting with 0 first as they can be octal or + // hexadecimal numbers or even pointers. + if (s[0] == '0') { + if (Len(v) == 1) { + // This is just a lone 0, but it needs to be represented differently + // in Python depending on whether it's a zero or a null pointer. + if (SwigType_ispointer(t)) + return NewString("None"); + else + return v; + } else if (s[1] == 'x' || s[1] == 'X') { + // This must have been a hex number, we can use it directly in Python, + // so nothing to do here. + } else { + // This must have been an octal number, we have to change its prefix + // to be "0o" in Python 3 only (and as long as we still support Python + // 2.5, this can't be done unconditionally). + if (py3) { + if (end - s > 1) { + String *res = NewString("0o"); + Append(res, NewStringWithSize(s + 1, end - s - 1)); + return res; + } + } + } + } + + // Avoid unnecessary string allocation in the common case when we don't + // need to remove any suffix. + return *end == '\0' ? v : NewStringWithSize(s, end - s); } - return 0; + + // Check if this is a floating point number (notice that it wasn't + // necessarily parsed as a long above, consider e.g. ".123"). + if (String *res = convertDoubleValue(v)) { + return res; + } + + if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) + return NewString("True"); + if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) + return NewString("False"); + if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0) + return SwigType_ispointer(t) ? NewString("None") : NewString("0"); + + // This could also be an enum type, default value of which could be + // representable in Python if it doesn't include any scope (which could, + // but currently is not, translated). + if (!Strchr(s, ':')) { + Node *lookup = Swig_symbol_clookup(v, 0); + if (lookup) { + if (Cmp(Getattr(lookup, "nodeType"), "enumitem") == 0) + return Getattr(lookup, "sym:name"); + } + } + + return NIL; } + /* ------------------------------------------------------------ - * is_primitive_defaultargs() - * Check if all the default args have primitive type. - * (So we can generate proper parameter list with default - * values..) + * is_representable_as_pyargs() + * Check if the function parameters default argument values + * can be represented in Python. + * + * If this method returns false, the parameters will be translated + * to a generic "*args" which allows us to deal with default values + * at C++ code level where they can always be handled. * ------------------------------------------------------------ */ - bool is_primitive_defaultargs(Node *n) { + bool is_representable_as_pyargs(Node *n) { + bool is_representable = true; + ParmList *plist = CopyParmList(Getattr(n, "parms")); Parm *p; Parm *pnext; - Swig_typemap_attach_parms("in", plist, 0); for (p = plist; p; p = pnext) { + pnext = NIL; String *tm = Getattr(p, "tmap:in"); if (tm) { pnext = Getattr(p, "tmap:in:next"); if (checkAttribute(p, "tmap:in:numinputs", "0")) { continue; } - } else { + } + if (!pnext) { pnext = nextSibling(p); } - String *type = Getattr(p, "type"); - String *value = Getattr(p, "value"); - if (!convertValue(value, type)) - return false; + if (String *value = Getattr(p, "value")) { + String *type = Getattr(p, "type"); + if (!convertValue(value, type)) { + is_representable = false; + break; + } + } } - return true; + + return is_representable; } @@ -1892,7 +2044,7 @@ public: n = nn; /* For overloaded function, just use *args */ - if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || !is_primitive_defaultargs(n)) { + if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || !is_representable_as_pyargs(n)) { String *parms = NewString(""); if (in_class) Printf(parms, "self, "); @@ -2012,7 +2164,7 @@ public: if (ret) ret = SwigType_str(ret, 0); } - return (ret && py3) ? NewStringf(" -> \"%s\" ", ret) + return (ret && py3) ? NewStringf(" -> \"%s\"", ret) : NewString(""); } @@ -2029,15 +2181,15 @@ public: /* Make a wrapper function to insert the code into */ Printv(f_dest, "\ndef ", name, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); if (have_docstring(n)) - Printv(f_dest, " ", docstring(n, AUTODOC_FUNC, tab4), "\n", NIL); + Printv(f_dest, tab4, docstring(n, AUTODOC_FUNC, tab4), "\n", NIL); if (have_pythonprepend(n)) - Printv(f_dest, pythoncode(pythonprepend(n), " "), "\n", NIL); + Printv(f_dest, pythoncode(pythonprepend(n), tab4), "\n", NIL); if (have_pythonappend(n)) { - Printv(f_dest, " val = ", funcCall(name, callParms), "\n", NIL); - Printv(f_dest, pythoncode(pythonappend(n), " "), "\n", NIL); - Printv(f_dest, " return val\n", NIL); + Printv(f_dest, tab4 "val = ", funcCall(name, callParms), "\n", NIL); + Printv(f_dest, pythoncode(pythonappend(n), tab4), "\n", NIL); + Printv(f_dest, tab4 "return val\n", NIL); } else { - Printv(f_dest, " return ", funcCall(name, callParms), "\n", NIL); + Printv(f_dest, tab4 "return ", funcCall(name, callParms), "\n", NIL); } if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) { @@ -2052,7 +2204,7 @@ public: * check if using kwargs is allowed for this Node * ------------------------------------------------------------ */ - int check_kwargs(Node *n) { + int check_kwargs(Node *n) const { return (use_kw || GetFlag(n, "feature:kwargs")) && !GetFlag(n, "memberset") && !GetFlag(n, "memberget"); } @@ -2154,7 +2306,7 @@ public: Append(f->code, "--argc;\n"); } - Replaceall(dispatch, "$args", "self,args"); + Replaceall(dispatch, "$args", "self, args"); Printv(f->code, dispatch, "\n", NIL); @@ -2431,7 +2583,6 @@ public: } SwigType *pt = Getattr(p, "type"); - String *pn = Getattr(p, "name"); String *ln = Getattr(p, "lname"); bool parse_from_tuple = (i > 0 || !add_self); if (SwigType_type(pt) == T_VARARGS) { @@ -2453,18 +2604,9 @@ public: /* Keyword argument handling */ if (allow_kwargs && parse_from_tuple) { - if (Len(pn)) { - String *tmp = 0; - String *name = pn; - if (!Getattr(p, "hidden")) { - name = tmp = Swig_name_make(p, 0, pn, 0, 0); // rename parameter if a keyword - } - Printf(kwargs, "(char *) \"%s\",", name); - if (tmp) - Delete(tmp); - } else { - Printf(kwargs, "(char *)\"arg%d\",", i + 1); - } + String *name = makeParameterName(n, p, i + 1); + Printf(kwargs, "(char *) \"%s\",", name); + Delete(name); } /* Look for an input typemap */ @@ -2595,7 +2737,6 @@ public: /* Insert cleanup code */ for (p = l; p;) { - // if (!checkAttribute(p,"tmap:in:numinputs","0") && !Getattr(p,"tmap:in:parse")) { if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) { if (Getattr(p, "tmap:freearg:implicitconv")) { const char *convflag = "0"; @@ -3153,7 +3294,32 @@ public: Replaceall(tm, "$source", value); Replaceall(tm, "$target", name); Replaceall(tm, "$value", value); - Printf(f_init, "%s\n", tm); + if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (!in_class || !Getattr(n, "feature:python:callback"))) { + // Generate method which registers the new constant + Printf(f_wrappers, "SWIGINTERN PyObject *%s_swigconstant(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", iname); + Printf(f_wrappers, tab2 "PyObject *module;\n", tm); + if (modernargs) { + if (fastunpack) { + Printf(f_wrappers, tab2 "if (!SWIG_Python_UnpackTuple(args,(char*)\"swigconstant\", 1, 1,&module)) return NULL;\n"); + } else { + Printf(f_wrappers, tab2 "if (!PyArg_UnpackTuple(args,(char*)\"swigconstant\", 1, 1,&module)) return NULL;\n"); + } + } else { + Printf(f_wrappers, tab2 "if (!PyArg_ParseTuple(args,(char*)\"O:swigconstant\", &module)) return NULL;\n"); + } + Printf(f_wrappers, tab2 "PyObject *d = PyModule_GetDict(module);\n"); + Printf(f_wrappers, tab2 "if (!d) return NULL;\n"); + Printf(f_wrappers, tab2 "%s\n", tm); + Printf(f_wrappers, tab2 "return SWIG_Py_Void();\n"); + Printf(f_wrappers, "}\n\n\n"); + + // Register the method in SwigMethods array + String *cname = NewStringf("%s_swigconstant", iname); + add_method(cname, cname, 0); + Delete(cname); + } else { + Printf(f_init, "%s\n", tm); + } Delete(tm); have_tm = 1; } @@ -3168,9 +3334,13 @@ public: if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { if (!in_class) { + Printv(f_shadow, "\n",NIL); + Printv(f_shadow, module, ".", iname, "_swigconstant(",module,")\n", NIL); Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL); } else { if (!(Getattr(n, "feature:python:callback"))) { + Printv(f_shadow_stubs, "\n",NIL); + Printv(f_shadow_stubs, module, ".", iname, "_swigconstant(", module, ")\n", NIL); Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL); } } @@ -3203,7 +3373,7 @@ public: * BEGIN C++ Director Class modifications * ------------------------------------------------------------------------- */ - /* C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose + /* C++/Python polymorphism demo code * * TODO * @@ -3901,7 +4071,7 @@ public: Printv(base_class, bname, NIL); b = Next(b); if (b.item) { - Putc(',', base_class); + Printv(base_class, ", ", NIL); } } } @@ -3922,7 +4092,7 @@ public: String *abcs = Getattr(n, "feature:python:abc"); if (py3 && abcs) { if (Len(base_class)) { - Putc(',', base_class); + Printv(base_class, ", ", NIL); } Printv(base_class, abcs, NIL); } @@ -3957,7 +4127,7 @@ public: if (!modern) { Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL); if (Len(base_class)) { - Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class); + Printv(f_shadow, tab4, "for _s in [", base_class, "]:\n", tab8, "__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))\n", NIL); } if (!GetFlag(n, "feature:python:nondynamic")) { @@ -3968,7 +4138,7 @@ public: Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL); if (Len(base_class)) { - Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class); + Printv(f_shadow, tab4, "for _s in [", base_class, "]:\n", tab8, "__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))\n", NIL); } Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL); @@ -4056,7 +4226,7 @@ public: Delete(realct); if (!have_constructor) { if (!builtin) - Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", + Printv(f_shadow_file, "\n", tab4, "def __init__(self, *args, **kwargs):\n", tab8, "raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstracts") ? " - class is abstract" : ""), "\")\n", NIL); } else if (fastinit && !builtin) { @@ -4094,12 +4264,12 @@ public: Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL); if (!modern) { Printv(f_shadow_file, - tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); + tab8, "try:\n", tab8, tab4, "self.this.append(this)\n", + tab8, "except:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); } else { Printv(f_shadow_file, - tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); + tab8, "try:\n", tab8, tab4, "self.this.append(this)\n", + tab8, "except:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); } } @@ -4108,7 +4278,7 @@ public: List *shadow_list = Getattr(n, "shadow_methods"); for (int i = 0; i < Len(shadow_list); ++i) { String *symname = Getitem(shadow_list, i); - Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), + Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s, None, %s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name); } } @@ -4223,12 +4393,11 @@ public: String *callParms = make_pyParmList(n, true, true, allow_kwargs); if (!have_addtofunc(n)) { if (!fastproxy || olddefs) { - Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); - Printv(f_shadow, " return ", funcCall(fullname, callParms), "\n", NIL); + Printv(f_shadow, "\n", tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); + Printv(f_shadow, tab8, "return ", funcCall(fullname, callParms), "\n", NIL); } } else { - Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); - Printv(f_shadow, "\n", NIL); + Printv(f_shadow, "\n", tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); if (have_docstring(n)) Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); if (have_pythonprepend(n)) { @@ -4314,7 +4483,7 @@ public: int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; String *parms = make_pyParmList(n, false, false, kw); String *callParms = make_pyParmList(n, false, true, kw); - Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); + Printv(f_shadow, "\n", tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); if (have_docstring(n)) Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); if (have_pythonprepend(n)) @@ -4326,7 +4495,9 @@ public: } else { Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); } - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL); + if (!modern) + Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL); + Printv(f_shadow, tab4, symname, " = staticmethod(", symname, ")\n", NIL); if (!modern) { Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL); @@ -4338,7 +4509,9 @@ public: NIL); } if (!classic) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), + if (!modern) + Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL); + Printv(f_shadow, tab4, symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); } } @@ -4427,7 +4600,7 @@ public: Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); } - Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); + Printv(f_shadow, "\n", tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); if (have_docstring(n)) Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); if (have_pythonprepend(n)) @@ -4438,7 +4611,7 @@ public: } else { Printv(f_shadow, tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", - tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); + tab8, "try:\n", tab8, tab4, "self.this.append(this)\n", tab8, "except:\n", tab8, tab4, "self.this = this\n", NIL); } if (have_pythonappend(n)) Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); @@ -4524,7 +4697,7 @@ public: Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL); if (!have_pythonprepend(n) && !have_pythonappend(n)) { if (proxydel) { - Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL); + Printv(f_shadow, tab4, "__del__ = lambda self: None\n", NIL); } return SWIG_OK; } @@ -4535,7 +4708,7 @@ public: Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); #ifdef USE_THISOWN Printv(f_shadow, tab8, "try:\n", NIL); - Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL); + Printv(f_shadow, tab8, tab4, "if self.thisown:", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL); Printv(f_shadow, tab8, "except: pass\n", NIL); #else #endif @@ -4573,11 +4746,12 @@ public: Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); } if (!classic) { - if (!assignable) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); - } else { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); - } + if (!modern) + Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL); + Printv(f_shadow, tab4, symname, " = _swig_property(", module, ".", getname, NIL); + if (assignable) + Printv(f_shadow, ", ", module, ".", setname, NIL); + Printv(f_shadow, ")\n", NIL); } Delete(mname); Delete(setname); @@ -4646,11 +4820,12 @@ public: Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); } if (!classic && !builtin) { - if (!assignable) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); - } else { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); - } + if (!modern) + Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL); + Printv(f_shadow, tab4, symname, " = _swig_property(", module, ".", getname, NIL); + if (assignable) + Printv(f_shadow, ", ", module, ".", setname, NIL); + Printv(f_shadow, ")\n", NIL); } String *getter = Getattr(n, "pybuiltin:getter"); String *setter = Getattr(n, "pybuiltin:setter"); @@ -4776,6 +4951,13 @@ public: return NewString("swigpyrun.h"); } + /*---------------------------------------------------------------------- + * kwargsSupport() + *--------------------------------------------------------------------*/ + + bool kwargsSupport() const { + return true; + } }; /* --------------------------------------------------------------- @@ -4813,6 +4995,16 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { int idx; bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; + if (builtin) { + // Rename any wrapped parameters called 'self' as the generated code contains a variable with same name + Parm *p; + for (p = l; p; p = nextSibling(p)) { + String *arg = Getattr(p, "name"); + if (arg && Cmp(arg, "self") == 0) + Delattr(p, "name"); + } + } + if (Cmp(storage, "virtual") == 0) { if (Cmp(value, "0") == 0) { pure_virtual = true; diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 6aeaae5a1..310e89b82 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -3426,6 +3426,14 @@ public: String *defaultExternalRuntimeFilename() { return NewString("swigrubyrun.h"); } + + /*---------------------------------------------------------------------- + * kwargsSupport() + *--------------------------------------------------------------------*/ + + bool kwargsSupport() const { + return true; + } }; /* class RUBY */ /* ----------------------------------------------------------------------------- diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx index 9e93bdf1e..b7b5d66ee 100644 --- a/Source/Modules/swigmain.cxx +++ b/Source/Modules/swigmain.cxx @@ -182,11 +182,6 @@ int main(int margc, char **margv) { } else if (strcmp(argv[i], "-nolang") == 0) { dl = new Language; Swig_mark_arg(i); - } else if ((strcmp(argv[i], "-dnone") == 0) || - (strcmp(argv[i], "-dhtml") == 0) || - (strcmp(argv[i], "-dlatex") == 0) || (strcmp(argv[i], "-dascii") == 0) || (strcmp(argv[i], "-stat") == 0)) { - Printf(stderr, "swig: Warning. %s option deprecated.\n", argv[i]); - Swig_mark_arg(i); } else if ((strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0)) { if (strcmp(argv[i], "--help") == 0) strcpy(argv[i], "-help"); diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 63b91bae5..a30fdf8fa 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -291,12 +291,18 @@ protected: /* Return the current class prefix */ String *getClassPrefix() const; + /* Return the current enum class prefix */ + String *getEnumClassPrefix() const; + /* Fully qualified type name to use */ String *getClassType() const; /* Return true if the current method is part of a smart-pointer */ int is_smart_pointer() const; + /* Return the name to use for the given parameter. */ + virtual String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter = false) const; + /* Some language modules require additional wrappers for virtual methods not declared in sub-classes */ virtual bool extraDirectorProtectedCPPMethodsRequired() const; @@ -315,6 +321,9 @@ public: */ virtual NestedClassSupport nestedClassesSupport() const; + /* Returns true if the target language supports key word arguments (kwargs) */ + virtual bool kwargsSupport() const; + protected: /* Identifies if a protected members that are generated when the allprotected option is used. This does not include protected virtual methods as they are turned on with the dirprot option. */ diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index baadf7132..ac912f49e 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1376,12 +1376,12 @@ String *Preprocessor_parse(String *s) { else if (c == '\"') { start_line = Getline(s); if (skip_tochar(s, '\"', chunk) < 0) { - Swig_error(Getfile(s), -1, "Unterminated string constant starting at line %d\n", start_line); + Swig_error(Getfile(s), start_line, "Unterminated string constant\n"); } } else if (c == '\'') { start_line = Getline(s); if (skip_tochar(s, '\'', chunk) < 0) { - Swig_error(Getfile(s), -1, "Unterminated character constant starting at line %d\n", start_line); + Swig_error(Getfile(s), start_line, "Unterminated character constant\n"); } } else if (c == '/') state = 30; /* Comment */ @@ -1768,6 +1768,10 @@ String *Preprocessor_parse(String *s) { } } else if (Equal(id, kpp_level)) { Swig_error(Getfile(s), Getline(id), "cpp debug: level = %d, startlevel = %d\n", level, start_level); + } else if (Equal(id, "")) { + /* Null directive */ + } else { + Swig_error(Getfile(s), Getline(id), "Unknown SWIG preprocessor directive: %s (if this is a block of target language code, delimit it with %%{ and %%})\n", id); } for (i = 0; i < cpp_lines; i++) Putc('\n', ns); @@ -2004,21 +2008,21 @@ String *Preprocessor_parse(String *s) { } } while (level > 0) { - Swig_error(Getfile(s), -1, "Missing #endif for conditional starting on line %d\n", cond_lines[level - 1]); + Swig_error(Getfile(s), cond_lines[level - 1], "Missing #endif for conditional starting here\n"); level--; } if (state == 120) { - Swig_error(Getfile(s), -1, "Missing %%endoffile for file inclusion block starting on line %d\n", start_line); + Swig_error(Getfile(s), start_line, "Missing %%endoffile for file inclusion block starting here\n"); } if (state == 150) { Seek(value, 0, SEEK_SET); - Swig_error(Getfile(s), -1, "Missing %%enddef for macro starting on line %d\n", Getline(value)); + Swig_error(Getfile(s), Getline(value), "Missing %%enddef for macro starting here\n", Getline(value)); } if ((state >= 105) && (state < 107)) { - Swig_error(Getfile(s), -1, "Unterminated %%{ ... %%} block starting on line %d\n", start_line); + Swig_error(Getfile(s), start_line, "Unterminated %%{ ... %%} block\n"); } if ((state >= 30) && (state < 40)) { - Swig_error(Getfile(s), -1, "Unterminated comment starting on line %d\n", start_line); + Swig_error(Getfile(s), start_line, "Unterminated comment\n"); } copy_location(s, chunk); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index d15c2e12f..9da4e0829 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -869,7 +869,7 @@ void Swig_replace_special_variables(Node *n, Node *parentnode, String *code) { String *parentclassname = 0; if (parentclass) parentclassname = Getattr(parentclass, "name"); - Replaceall(code, "$parentclassname", parentclassname ? parentclassname : ""); + Replaceall(code, "$parentclassname", parentclassname ? SwigType_str(parentclassname, "") : ""); } } @@ -1614,7 +1614,14 @@ int Swig_VargetToFunction(Node *n, int flags) { Delete(mangled); Delete(sname); } else { - String *nname = SwigType_namestr(name); + String *nname = 0; + if (Equal(nodeType(n), "constant")) { + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); + nname = NewStringf("(%s)", value); + } else { + nname = SwigType_namestr(name); + } call = Swig_wrapped_var_assign(type, nname, varcref); cres = Swig_cresult(ty, Swig_cresult_name(), call); Setattr(n, "wrap:action", cres); diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index d8c3f7f3f..b0d608c9e 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -824,6 +824,9 @@ static int look(Scanner *s) { state = 7; } else if (c == '=') { return SWIG_TOKEN_MODEQUAL; + } else if (c == '}') { + Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '%%}'\n"); + exit(1); } else { retract(s, 1); return SWIG_TOKEN_PERCENT; diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index e77f818de..2202f61c6 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -1875,15 +1875,15 @@ ParmList *Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Delete(ntq); ntq = ty; } - /* Printf(stderr,"value %s %s %s\n",value,ntr,ntq); */ cp = NewParmWithoutFileLineInfo(ntq, 0); - if (lp) - set_nextSibling(lp, cp); - else - expandedparms = CopyParm(cp); + if (lp) { + set_nextSibling(lp, cp); + Delete(cp); + } else { + expandedparms = cp; + } lp = cp; tp = nextSibling(tp); - Delete(cp); Delete(nt); Delete(ntq); } else { diff --git a/Tools/javascript/Makefile.in b/Tools/javascript/Makefile.in index f65be2826..1eec5bc1e 100644 --- a/Tools/javascript/Makefile.in +++ b/Tools/javascript/Makefile.in @@ -26,15 +26,18 @@ LINKFLAGS = @JSINTERPRETERLINKFLAGS@ ROOT_DIR = @ROOT_DIR@ JSINCLUDES = @JSCOREINC@ @JSV8INC@ JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@ -JSLIBRARYPREFIX = @JSLIBRARYPREFIX@ -JSSO =@JSSO@ -JSLDSHARED = @JSLDSHARED@ -JSCXXSHARED = @JSCXXSHARED@ JSV8ENABLED = @JSV8ENABLED@ JSCENABLED = @JSCENABLED@ srcdir = @srcdir@ + +ifneq (, $(V8_VERSION)) + JSV8_VERSION=$(V8_VERSION) +else + JSV8_VERSION=0x031110 +endif + # Regenerate Makefile if Makefile.in or config.status have changed. Makefile: $(srcdir)/Makefile.in ../../config.status cd ../.. && $(SHELL) ./config.status Tools/javascript/Makefile @@ -42,7 +45,7 @@ Makefile: $(srcdir)/Makefile.in ../../config.status # These settings are provided by 'configure' (see '/configure.in') ifeq (1, $(JSV8ENABLED)) JS_INTERPRETER_SRC_V8 = v8_shell.cxx -JS_INTERPRETER_ENABLE_V8 = -DENABLE_V8 +JS_INTERPRETER_ENABLE_V8 = -DENABLE_V8 -DSWIG_V8_VERSION=$(JSV8_VERSION) -DV8_DEPRECATION_WARNINGS endif ifeq (1, $(JSCENABLED)) diff --git a/Tools/javascript/v8_shell.cxx b/Tools/javascript/v8_shell.cxx index 4c6334f2f..7016e9c31 100644 --- a/Tools/javascript/v8_shell.cxx +++ b/Tools/javascript/v8_shell.cxx @@ -1,313 +1,388 @@ -#include -#include -#include -#include -#include - -#include -#include - -#include "js_shell.h" - -typedef int (*V8ExtensionInitializer) (v8::Handle module); - -class V8Shell: public JSShell { - -public: - V8Shell(); - - virtual ~V8Shell(); - - virtual bool RunScript(const std::string& scriptPath); - - virtual bool RunShell(); - - -protected: - - virtual bool InitializeEngine(); - - virtual bool ExecuteScript(const std::string& source, const std::string& scriptPath); - - virtual bool DisposeEngine(); - -private: - - v8::Handle Import(const std::string& moduleName); - - v8::Persistent CreateShellContext(); - - void ReportException(v8::TryCatch* handler); - - static v8::Handle Print(const v8::Arguments& args); - - static v8::Handle Require(const v8::Arguments& args); - - static v8::Handle Quit(const v8::Arguments& args); - - static v8::Handle Version(const v8::Arguments& args); - - static const char* ToCString(const v8::String::Utf8Value& value); - - virtual bool _ExecuteScript(const std::string& source, const std::string& scriptPath); - -protected: - - v8::Persistent context; -}; - -#ifdef __GNUC__ -#include -#define LOAD_SYMBOL(handle, name) dlsym(handle, name) -#else -#error "implement dll loading" -#endif - -V8Shell::V8Shell(){} - -V8Shell::~V8Shell() {} - -bool V8Shell::RunScript(const std::string& scriptPath) { - - if (!context.IsEmpty()) { - context.Dispose(); - } - - std::string source = ReadFile(scriptPath); - - context = CreateShellContext(); - if (context.IsEmpty()) { - printf("Could not create context.\n"); - return false; - } - context->Enter(); - - bool success = _ExecuteScript(source, scriptPath); - - context->Exit(); - context.Dispose(); - v8::V8::Dispose(); - - return true; -} - -bool V8Shell::_ExecuteScript(const std::string& source, const std::string& scriptPath) { - v8::HandleScope scope; - - // Store a pointer to this shell for later use - v8::Handle global = context->Global(); - v8::Local __shell__ = v8::External::New((void*) (long) this); - global->SetHiddenValue(v8::String::New("__shell__"), __shell__); - - // Node.js compatibility: make `print` available as `console.log()` - ExecuteScript("var console = {}; console.log = print;", ""); - - if(!ExecuteScript(source, scriptPath)) { - return false; - } - - return true; -} - -bool V8Shell::RunShell() { - - if (!context.IsEmpty()) { - context.Dispose(); - } - - context = CreateShellContext(); - if (context.IsEmpty()) { - printf("Could not create context.\n"); - return false; - } - - context->Enter(); - - v8::Context::Scope context_scope(context); - - ExecuteScript("var console = {}; console.log = print;", ""); - - static const int kBufferSize = 1024; - while (true) { - char buffer[kBufferSize]; - printf("> "); - char* str = fgets(buffer, kBufferSize, stdin); - if (str == NULL) break; - std::string source(str); - ExecuteScript(source, "(shell)"); - } - printf("\n"); - - context->Exit(); - context.Dispose(); - v8::V8::Dispose(); - - return true; -} - - -bool V8Shell::InitializeEngine() { - return true; -} - -bool V8Shell::ExecuteScript(const std::string& source, const std::string& name) { - v8::HandleScope handle_scope; - v8::TryCatch try_catch; - v8::Handle script = v8::Script::Compile(v8::String::New(source.c_str()), v8::String::New(name.c_str())); - - // Stop if script is empty - if (script.IsEmpty()) { - // Print errors that happened during compilation. - ReportException(&try_catch); - return false; - } - - v8::Handle result = script->Run(); - - // Print errors that happened during execution. - if (try_catch.HasCaught()) { - ReportException(&try_catch); - return false; - } else { - return true; - } -} - -bool V8Shell::DisposeEngine() { - return true; -} - -v8::Persistent V8Shell::CreateShellContext() { - v8::HandleScope scope; - - // Create a template for the global object. - v8::Handle global = v8::ObjectTemplate::New(); - - // Bind global functions - global->Set(v8::String::New("print"), v8::FunctionTemplate::New(V8Shell::Print)); - global->Set(v8::String::New("quit"), v8::FunctionTemplate::New(V8Shell::Quit)); - global->Set(v8::String::New("require"), v8::FunctionTemplate::New(V8Shell::Require)); - global->Set(v8::String::New("version"), v8::FunctionTemplate::New(V8Shell::Version)); - - v8::Persistent _context = v8::Context::New(NULL, global); - - return _context; -} - -v8::Handle V8Shell::Import(const std::string& module_path) -{ - v8::HandleScope scope; - - HANDLE library; - std::string module_name = LoadModule(module_path, &library); - - std::string symname = std::string(module_name).append("_initialize"); - - V8ExtensionInitializer init_function = reinterpret_cast((long) LOAD_SYMBOL(library, symname.c_str())); - - if(init_function == 0) { - printf("Could not find initializer function."); - return v8::Undefined(); - } - - v8::Local module = v8::Object::New(); - init_function(module); - return scope.Close(module); -} - -v8::Handle V8Shell::Print(const v8::Arguments& args) { - bool first = true; - for (int i = 0; i < args.Length(); i++) { - v8::HandleScope handle_scope; - if (first) { - first = false; - } else { - printf(" "); - } - v8::String::Utf8Value str(args[i]); - const char* cstr = V8Shell::ToCString(str); - printf("%s", cstr); - } - printf("\n"); - fflush(stdout); - return v8::Undefined(); -} - -v8::Handle V8Shell::Require(const v8::Arguments& args) { - v8::HandleScope scope; - - if (args.Length() != 1) { - printf("Illegal arguments for `require`"); - }; - - v8::String::Utf8Value str(args[0]); - const char* cstr = V8Shell::ToCString(str); - std::string moduleName(cstr); - - v8::Local global = v8::Context::GetCurrent()->Global(); - v8::Local hidden = global->GetHiddenValue(v8::String::New("__shell__")); - v8::Local __shell__ = v8::Local::Cast(hidden); - V8Shell* _this = (V8Shell*) (long) __shell__->Value(); - - v8::Handle module = _this->Import(moduleName); - - return scope.Close(module); -} - -v8::Handle V8Shell::Quit(const v8::Arguments& args) { - int exit_code = args[0]->Int32Value(); - fflush(stdout); - fflush(stderr); - exit(exit_code); - return v8::Undefined(); -} - -v8::Handle V8Shell::Version(const v8::Arguments& args) { - return v8::String::New(v8::V8::GetVersion()); -} - -void V8Shell::ReportException(v8::TryCatch* try_catch) { - v8::HandleScope handle_scope; - v8::String::Utf8Value exception(try_catch->Exception()); - const char* exception_string = V8Shell::ToCString(exception); - v8::Handle message = try_catch->Message(); - if (message.IsEmpty()) { - // V8 didn't provide any extra information about this error; just - // print the exception. - printf("%s\n", exception_string); - } else { - // Print (filename):(line number): (message). - v8::String::Utf8Value filename(message->GetScriptResourceName()); - const char* filename_string = V8Shell::ToCString(filename); - int linenum = message->GetLineNumber(); - printf("%s:%i: %s\n", filename_string, linenum, exception_string); - // Print line of source code. - v8::String::Utf8Value sourceline(message->GetSourceLine()); - const char* sourceline_string = V8Shell::ToCString(sourceline); - printf("%s\n", sourceline_string); - // Print wavy underline (GetUnderline is deprecated). - int start = message->GetStartColumn(); - for (int i = 0; i < start; i++) { - printf(" "); - } - int end = message->GetEndColumn(); - for (int i = start; i < end; i++) { - printf("^"); - } - printf("\n"); - v8::String::Utf8Value stack_trace(try_catch->StackTrace()); - if (stack_trace.length() > 0) { - const char* stack_trace_string = V8Shell::ToCString(stack_trace); - printf("%s\n", stack_trace_string); - } - } -} - -// Extracts a C string from a V8 Utf8Value. -const char* V8Shell::ToCString(const v8::String::Utf8Value& value) { - return *value ? *value : ""; -} - -JSShell* V8Shell_Create() { - return new V8Shell(); -} +#include +#include +#include +#include +#include + +#include +#include + +#include "js_shell.h" + +typedef int (*V8ExtensionInitializer) (v8::Handle module); + +// Note: these typedefs and defines are used to deal with v8 API changes since version 3.19.00 + +#if (SWIG_V8_VERSION < 0x031903) +typedef v8::Handle SwigV8ReturnValue; +typedef v8::Arguments SwigV8Arguments; +typedef v8::AccessorInfo SwigV8PropertyCallbackInfo; +#define SWIGV8_RETURN(val) return scope.Close(val) +#define SWIGV8_RETURN_INFO(val, info) return scope.Close(val) +#else +typedef void SwigV8ReturnValue; +typedef v8::FunctionCallbackInfo SwigV8Arguments; +typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; +#define SWIGV8_RETURN(val) args.GetReturnValue().Set(val); return +#define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return +#endif + + +#if (SWIG_V8_VERSION < 0x032117) +#define SWIGV8_HANDLESCOPE() v8::HandleScope scope +#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope +#define SWIGV8_ESCAPE(val) return scope.Close(val) +#elif (SWIG_V8_VERSION < 0x032318) +#define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); +#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope(v8::Isolate::GetCurrent()); +#define SWIGV8_ESCAPE(val) return scope.Close(val) +#else +#define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); +#define SWIGV8_HANDLESCOPE_ESC() v8::EscapableHandleScope scope(v8::Isolate::GetCurrent()); +#define SWIGV8_ESCAPE(val) return scope.Escape(val) +#endif + +#if (SWIG_V8_VERSION < 0x032318) +#define SWIGV8_CURRENT_CONTEXT() v8::Context::GetCurrent() +#define SWIGV8_STRING_NEW(str) v8::String::New(str) +#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(func) +#define SWIGV8_OBJECT_NEW() v8::Object::New() +#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(val) +#define SWIGV8_UNDEFINED() v8::Undefined() +#else +#define SWIGV8_CURRENT_CONTEXT() v8::Isolate::GetCurrent()->GetCurrentContext() +#define SWIGV8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str) +#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(v8::Isolate::GetCurrent(), func) +#define SWIGV8_OBJECT_NEW() v8::Object::New(v8::Isolate::GetCurrent()) +#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(v8::Isolate::GetCurrent(), val) +#define SWIGV8_UNDEFINED() v8::Undefined(v8::Isolate::GetCurrent()) +#endif + + +#if (SWIG_V8_VERSION < 0x031900) +typedef v8::Persistent SwigV8Context; +#else +typedef v8::Local SwigV8Context; +#endif + +class V8Shell: public JSShell { + +public: + V8Shell(); + + virtual ~V8Shell(); + + virtual bool RunScript(const std::string &scriptPath); + + virtual bool RunShell(); + + +protected: + + virtual bool InitializeEngine(); + + virtual bool ExecuteScript(const std::string &source, const std::string &scriptPath); + + virtual bool DisposeEngine(); + +private: + + v8::Handle Import(const std::string &moduleName); + + SwigV8Context CreateShellContext(); + + void ReportException(v8::TryCatch *handler); + + static SwigV8ReturnValue Print(const SwigV8Arguments &args); + + static SwigV8ReturnValue Require(const SwigV8Arguments &args); + + static SwigV8ReturnValue Quit(const SwigV8Arguments &args); + + static SwigV8ReturnValue Version(const SwigV8Arguments &args); + + static const char* ToCString(const v8::String::Utf8Value &value); + +}; + +#ifdef __GNUC__ +#include +#define LOAD_SYMBOL(handle, name) dlsym(handle, name) +#else +#error "implement dll loading" +#endif + +V8Shell::V8Shell() {} + +V8Shell::~V8Shell() {} + +bool V8Shell::RunScript(const std::string &scriptPath) { + std::string source = ReadFile(scriptPath); + + v8::Isolate *isolate = v8::Isolate::New(); + v8::Isolate::Scope isolate_scope(isolate); + + SWIGV8_HANDLESCOPE(); + + SwigV8Context context = CreateShellContext(); + + if (context.IsEmpty()) { + printf("Could not create context.\n"); + return false; + } + + context->Enter(); + + // Store a pointer to this shell for later use + + v8::Handle global = context->Global(); + v8::Local __shell__ = SWIGV8_EXTERNAL_NEW((void*) (long) this); + + global->SetHiddenValue(SWIGV8_STRING_NEW("__shell__"), __shell__); + + // Node.js compatibility: make `print` available as `console.log()` + ExecuteScript("var console = {}; console.log = print;", ""); + + bool success = ExecuteScript(source, scriptPath); + + // Cleanup + + context->Exit(); + +#if (SWIG_V8_VERSION < 0x031710) + context.Dispose(); +#elif (SWIG_V8_VERSION < 0x031900) + context.Dispose(v8::Isolate::GetCurrent()); +#else +// context.Dispose(); +#endif + +// v8::V8::Dispose(); + + return success; +} + +bool V8Shell::RunShell() { + SWIGV8_HANDLESCOPE(); + + SwigV8Context context = CreateShellContext(); + + if (context.IsEmpty()) { + printf("Could not create context.\n"); + return false; + } + + context->Enter(); + + v8::Context::Scope context_scope(context); + + ExecuteScript("var console = {}; console.log = print;", ""); + + static const int kBufferSize = 1024; + while (true) { + char buffer[kBufferSize]; + printf("> "); + char *str = fgets(buffer, kBufferSize, stdin); + if (str == NULL) break; + std::string source(str); + ExecuteScript(source, "(shell)"); + } + printf("\n"); + + // Cleanup + + context->Exit(); + +#if (SWIG_V8_VERSION < 0x031710) + context.Dispose(); +#elif (SWIG_V8_VERSION < 0x031900) + context.Dispose(v8::Isolate::GetCurrent()); +#else +// context.Dispose(); +#endif + +// v8::V8::Dispose(); + + return true; +} + + +bool V8Shell::InitializeEngine() { + return true; +} + +bool V8Shell::ExecuteScript(const std::string &source, const std::string &name) { + SWIGV8_HANDLESCOPE(); + + v8::TryCatch try_catch; + v8::Handle script = v8::Script::Compile(SWIGV8_STRING_NEW(source.c_str()), SWIGV8_STRING_NEW(name.c_str())); + + // Stop if script is empty + if (script.IsEmpty()) { + // Print errors that happened during compilation. + ReportException(&try_catch); + return false; + } + + v8::Handle result = script->Run(); + + // Print errors that happened during execution. + if (try_catch.HasCaught()) { + ReportException(&try_catch); + return false; + } else { + return true; + } +} + +bool V8Shell::DisposeEngine() { + return true; +} + +SwigV8Context V8Shell::CreateShellContext() { + // Create a template for the global object. + v8::Handle global = v8::ObjectTemplate::New(); + + // Bind global functions + global->Set(SWIGV8_STRING_NEW("print"), SWIGV8_FUNCTEMPLATE_NEW(V8Shell::Print)); + global->Set(SWIGV8_STRING_NEW("quit"), SWIGV8_FUNCTEMPLATE_NEW(V8Shell::Quit)); + global->Set(SWIGV8_STRING_NEW("require"), SWIGV8_FUNCTEMPLATE_NEW(V8Shell::Require)); + global->Set(SWIGV8_STRING_NEW("version"), SWIGV8_FUNCTEMPLATE_NEW(V8Shell::Version)); + +#if (SWIG_V8_VERSION < 0x031900) + SwigV8Context context = v8::Context::New(NULL, global); + return context; +#else + SwigV8Context context = v8::Context::New(v8::Isolate::GetCurrent(), NULL, global); + return context; +#endif +} + +v8::Handle V8Shell::Import(const std::string &module_path) +{ + SWIGV8_HANDLESCOPE_ESC(); + + HANDLE library; + std::string module_name = LoadModule(module_path, &library); + + std::string symname = std::string(module_name).append("_initialize"); + + V8ExtensionInitializer init_function = reinterpret_cast((long) LOAD_SYMBOL(library, symname.c_str())); + + if(init_function == 0) { + printf("Could not find initializer function."); + + return SWIGV8_UNDEFINED(); + } + + v8::Local module = SWIGV8_OBJECT_NEW(); + init_function(module); + + SWIGV8_ESCAPE(module); +} + +SwigV8ReturnValue V8Shell::Print(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + + bool first = true; + for (int i = 0; i < args.Length(); i++) { + + if (first) { + first = false; + } else { + printf(" "); + } + v8::String::Utf8Value str(args[i]); + const char *cstr = V8Shell::ToCString(str); + printf("%s", cstr); + } + printf("\n"); + fflush(stdout); + + SWIGV8_RETURN(SWIGV8_UNDEFINED()); +} + +SwigV8ReturnValue V8Shell::Require(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + + if (args.Length() != 1) { + printf("Illegal arguments for `require`"); + }; + + v8::String::Utf8Value str(args[0]); + const char *cstr = V8Shell::ToCString(str); + std::string moduleName(cstr); + + v8::Local global = SWIGV8_CURRENT_CONTEXT()->Global(); + + v8::Local hidden = global->GetHiddenValue(SWIGV8_STRING_NEW("__shell__")); + v8::Local __shell__ = v8::Local::Cast(hidden); + V8Shell *_this = (V8Shell *) (long) __shell__->Value(); + + v8::Handle module = _this->Import(moduleName); + + SWIGV8_RETURN(module); +} + +SwigV8ReturnValue V8Shell::Quit(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + + int exit_code = args[0]->Int32Value(); + fflush(stdout); + fflush(stderr); + exit(exit_code); + + SWIGV8_RETURN(SWIGV8_UNDEFINED()); +} + +SwigV8ReturnValue V8Shell::Version(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + SWIGV8_RETURN(SWIGV8_STRING_NEW(v8::V8::GetVersion())); +} + +void V8Shell::ReportException(v8::TryCatch *try_catch) { + SWIGV8_HANDLESCOPE(); + + v8::String::Utf8Value exception(try_catch->Exception()); + const char *exception_string = V8Shell::ToCString(exception); + v8::Handle message = try_catch->Message(); + if (message.IsEmpty()) { + // V8 didn't provide any extra information about this error; just + // print the exception. + printf("%s\n", exception_string); + } else { + // Print (filename):(line number): (message). + v8::String::Utf8Value filename(message->GetScriptResourceName()); + const char *filename_string = V8Shell::ToCString(filename); + int linenum = message->GetLineNumber(); + printf("%s:%i: %s\n", filename_string, linenum, exception_string); + // Print line of source code. + v8::String::Utf8Value sourceline(message->GetSourceLine()); + const char *sourceline_string = V8Shell::ToCString(sourceline); + printf("%s\n", sourceline_string); + // Print wavy underline (GetUnderline is deprecated). + int start = message->GetStartColumn(); + for (int i = 0; i < start; i++) { + printf(" "); + } + int end = message->GetEndColumn(); + for (int i = start; i < end; i++) { + printf("^"); + } + printf("\n"); + v8::String::Utf8Value stack_trace(try_catch->StackTrace()); + if (stack_trace.length() > 0) { + const char *stack_trace_string = V8Shell::ToCString(stack_trace); + printf("%s\n", stack_trace_string); + } + } +} + +// Extracts a C string from a V8 Utf8Value. +const char *V8Shell::ToCString(const v8::String::Utf8Value &value) { + return *value ? *value : ""; +} + +JSShell *V8Shell_Create() { + return new V8Shell(); +} diff --git a/Tools/obs-buildlogs.py b/Tools/obs-buildlogs.py new file mode 100755 index 000000000..eaf0f613b --- /dev/null +++ b/Tools/obs-buildlogs.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import os +import subprocess +import argparse +import glob + +def remove_old_files(): + files = glob.glob("*.log") + for file in files: + os.remove(file) + +def download(): + repos = subprocess.Popen(['osc', 'repositories'], stdout=subprocess.PIPE) + for line in repos.stdout: + command = ['osc', 'buildlog', '--last'] + line.split() + filename = "-".join(line.split()) + ".log" + print "Downloading logs using: {}".format(" ".join(command)) + buildlog = subprocess.Popen(command, stdout=subprocess.PIPE) + + print("Writing log to {}".format(filename)) + file = open(filename, "w") + if buildlog.stderr != None: + print("Errors: {}".format(buildlog.stderr)) + for log_line in buildlog.stdout: + file.write(log_line) + + print("Finished") + +parser = argparse.ArgumentParser(description="Download OpenBuild logs using osc. All the logs for each architecture from the last completed builds are downloaded and stored as .log files. Must be run from a working copy that is already checked out, eg after running obs-update.") +args = parser.parse_args() + +remove_old_files() +download() diff --git a/configure.ac b/configure.ac index cca4fd00a..6e1a16f73 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl The macros which aren't shipped with the autotools are stored in the dnl Tools/config directory in .m4 files. -AC_INIT([swig],[3.0.2],[http://www.swig.org]) +AC_INIT([swig],[3.0.5],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed @@ -791,7 +791,7 @@ AC_SUBST(PY3INCLUDE) AC_SUBST(PY3LIB) AC_SUBST(PY3LINK) AC_SUBST(PYTHON3DYNAMICLINKING) - +AC_CHECK_PROGS(PEP8, pep8) #---------------------------------------------------------------- # Look for Perl5 @@ -821,7 +821,7 @@ fi # perl -MExtUtils::Embed -e ccopts AC_MSG_CHECKING(for Perl5 header files) if test -n "$PERL"; then - PERL5DIR=`($PERL -e 'use Config; print $Config{archlib}, "\n";') 2>/dev/null` + PERL5DIR=`($PERL -MConfig -le 'print $Config{archlibexp}') 2>/dev/null` if test -n "$PERL5DIR" ; then dirs="$PERL5DIR $PERL5DIR/CORE" PERL5EXT=none @@ -939,25 +939,43 @@ fi if test -n "$OCTAVE"; then AC_MSG_CHECKING([for Octave preprocessor flags]) OCTAVE_CPPFLAGS= - for n in CPPFLAGS INCFLAGS; do - OCTAVE_CPPFLAGS="${OCTAVE_CPPFLAGS} "`unset CPPFLAGS; ${mkoctfile} -p $n` + for var in CPPFLAGS INCFLAGS ALL_CXXFLAGS; do + for flag in `env - ${mkoctfile} -p ${var}`; do + case ${flag} in + -D*|-I*) OCTAVE_CPPFLAGS="${OCTAVE_CPPFLAGS} ${flag}";; + *) ;; + esac + done done AC_MSG_RESULT([$OCTAVE_CPPFLAGS]) AC_MSG_CHECKING([for Octave compiler flags]) OCTAVE_CXXFLAGS= - for n in ALL_CXXFLAGS; do - OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} "`unset CXXFLAGS; ${mkoctfile} -p $n` + for var in ALL_CXXFLAGS; do + for flag in `env - ${mkoctfile} -p ${var}`; do + case ${flag} in + -g*|-W*) OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} ${flag}";; + *) ;; + esac + done done + save_CXXFLAGS="${CXXFLAGS}" + CXXFLAGS="-Werror -O0" + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],[]) + ],[ + OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} -O0" + ]) + CXXFLAGS="${save_CXXFLAGS}" AC_MSG_RESULT([$OCTAVE_CXXFLAGS]) AC_MSG_CHECKING([for Octave linker flags]) OCTAVE_LDFLAGS= - for n in RDYNAMIC_FLAG LFLAGS RLD_FLAG OCTAVE_LIBS LIBS; do - OCTAVE_LDFLAGS="${OCTAVE_LDFLAGS} "`${mkoctfile} -p $n` + for var in RDYNAMIC_FLAG LFLAGS RLD_FLAG OCTAVE_LIBS LIBS; do + OCTAVE_LDFLAGS="${OCTAVE_LDFLAGS} "`env - ${mkoctfile} -p ${var}` done AC_MSG_RESULT([$OCTAVE_LDFLAGS]) for octave_opt in --silent --norc --no-history --no-window-system; do AC_MSG_CHECKING([if Octave option '${octave_opt}' is supported]) - octave_out=`${OCTAVE} ${octave_opt} /dev/null 2>&1 | sed -n '1{/unrecognized/p}'` + octave_out=`${OCTAVE} ${octave_opt} /dev/null 2>&1 | sed -n '1p' | sed -n '/unrecognized/p'` AS_IF([test "x${octave_out}" = x],[ AC_MSG_RESULT([yes]) OCTAVE="${OCTAVE} ${octave_opt}" @@ -1191,28 +1209,15 @@ else # General Javascript settings shared by JSC and V8 #---------------------------------------------------------------- - case $host in - *-*-cygwin* | *-*-mingw*) - JSLIBRARYPREFIX="" - ;; - *) - JSLIBRARYPREFIX="lib" - ;; - esac - case $host in *-*-darwin*) JSSO=".dylib" - JSLDSHARED='$(CC) -dynamiclib' - JSCXXSHARED='$(CXX) -dynamiclib' # HACK: didn't manage to get dynamic module loading working with a g++ compiled interpreter JSINTERPRETERCXX='c++' JSINTERPRETERLINKFLAGS='-g -Wl,-search_paths_first -Wl,-headerpad_max_install_names' ;; *) JSSO=$SO - JSLDSHARED='$(LDSHARED)' - JSCXXSHARED='$(CXXSHARED)' JSINTERPRETERCXX='$(CXX)' JSINTERPRETERLINKFLAGS='-ldl' ;; @@ -1273,39 +1278,21 @@ else # check for JavaScriptCore/Webkit libraries AC_ARG_WITH(jscorelib,[ --with-jsclib =path Set location of the JavaScriptCore/Webkit library directory],[JSCORELIB="-L$withval"], [JSCORELIB=]) - AC_MSG_CHECKING(for JavaScriptCore/Webkit library) - # look for the library when not provided - if test -z "$JSCORELIB"; then - case $host in - *-*-linux*) - if test -n "$PKGCONFIG"; then - dirs="/usr/lib64/ /usr/local/lib64/ /usr/lib/ /usr/local/lib/" - for i in $dirs ; do - if test -r $i/libjavascriptcoregtk-1.0.so; then - AC_MSG_RESULT($i) - JSCORELIB="-L$i -ljavascriptcoregtk-1.0" - JSCOREVERSION=`$PKGCONFIG --modversion javascriptcoregtk-1.0` - break - fi - done - fi - - if test -z "$JSCORELIB"; then - AC_MSG_RESULT(not found) - JSCENABLED= - else - JSCOREDYNAMICLINKING="$JSCORELIB" - JSCENABLED=1 - fi - ;; - *-*-darwin*) - JSCOREDYNAMICLINKING="-framework JavaScriptCore" + if test -z "$JSCORELIB" -a -n "$PKGCONFIG"; then + AC_MSG_CHECKING(for JavaScriptCore/Webkit library) + if pkg-config javascriptcoregtk-1.0; then + JSCORELIB=`$PKGCONFIG --libs javascriptcoregtk-1.0` + JSCOREVERSION=`$PKGCONFIG --modversion javascriptcoregtk-1.0` + fi + if test -z "$JSCORELIB"; then + AC_MSG_RESULT(not found) + JSCENABLED= + else + AC_MSG_RESULT([$JSCORELIB]) + JSCOREDYNAMICLINKING="$JSCORELIB" JSCENABLED=1 - ;; - *) - ;; - esac + fi fi #---------------------------------------------------------------- @@ -1314,7 +1301,7 @@ else # check for include files AC_MSG_CHECKING(for V8 Javascript v8.h) - AC_ARG_WITH(jsv8inc, [ --with-v8inc=path Set location of Javascript v8 include directory], [JSV8INCDIR="$withval"]) + AC_ARG_WITH(jsv8inc, [ --with-jsv8inc=path Set location of Javascript v8 include directory], [JSV8INCDIR="$withval"]) # if not include dir is specified we try to find if test -z "$JSV8INCDIR"; then @@ -1347,11 +1334,11 @@ else # check for V8 library AC_MSG_CHECKING(for V8 Javascript library) - AC_ARG_WITH(jsv8lib,[ --with-v8lib=path Set location of V8 Javascript library directory],[JSV8LIBDIR="$withval"], [JSV8LIB=]) + AC_ARG_WITH(jsv8lib,[ --with-jsv8lib=path Set location of V8 Javascript library directory],[JSV8LIBDIR="$withval"], [JSV8LIB=]) v8libdirs="$JSV8LIBDIR /usr/lib64/ /usr/local/lib64/ /usr/lib/ /usr/local/lib/" for d in $v8libdirs ; do - if test -r $d/libv8.so; then + if test -r $d/libv8$JSSO; then JSV8LIBDIR=$d JSV8LIB="-L$d -lv8" break @@ -1370,7 +1357,7 @@ else # linking options case $host in *-*-darwin*) - JSV8DYNAMICLINKING="" # TODO: add osx configuration + JSV8DYNAMICLINKING="$JSV8LIB" ;; *-*-linux*) JSV8DYNAMICLINKING="$JSV8LIB" @@ -1382,11 +1369,6 @@ else fi -AC_SUBST(JSLIBRARYPREFIX) -AC_SUBST(JSSO) -AC_SUBST(JSLDSHARED) -AC_SUBST(JSCXXSHARED) - AC_SUBST(JSINTERPRETERCXX) AC_SUBST(JSINTERPRETERLINKFLAGS) @@ -1593,6 +1575,7 @@ AC_ARG_WITH(ruby, AS_HELP_STRING([--without-ruby], [Disable Ruby]) AS_HELP_STRING([--with-ruby=path], [Set location of Ruby executable]),[ RUBYBIN="$withval"], [RUBYBIN=yes]) # First, check for "--without-ruby" or "--with-ruby=no". +RUBYSO=$SO if test x"${RUBYBIN}" = xno -o x"${with_alllang}" = xno ; then AC_MSG_NOTICE([Disabling Ruby]) RUBY= @@ -1611,7 +1594,7 @@ if test -n "$RUBY"; then # Try Ruby1.9+ first RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyhdrdir"]] || $rubyhdrdir') 2>/dev/null` if test x"$RUBYDIR" = x"" || test x"$RUBYDIR" = x"nil"; then - RUBYDIR=`($RUBY -rmkmf -e 'print Config::CONFIG[["archdir"]] || $archdir') 2>/dev/null` + RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["archdir"]] || $archdir') 2>/dev/null` else RUBYARCH=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["arch"]] || $arch') 2>/dev/null` fi @@ -1636,13 +1619,13 @@ if test -n "$RUBY"; then # Find library and path for linking. AC_MSG_CHECKING(for Ruby library) RUBYLIB="" - rb_libdir=`($RUBY -rrbconfig -e 'print Config::CONFIG[["libdir"]]') 2>/dev/null` - rb_bindir=`($RUBY -rrbconfig -e 'print Config::CONFIG[["bindir"]]') 2>/dev/null` + rb_libdir=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["libdir"]]') 2>/dev/null` + rb_bindir=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["bindir"]]') 2>/dev/null` dirs="$dirs $rb_libdir $rb_bindir" - rb_libruby=`($RUBY -rrbconfig -e 'print Config::CONFIG[["LIBRUBY_A"]]') 2>/dev/null` + rb_libruby=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["LIBRUBY_A"]]') 2>/dev/null` RUBYLINK=`($RUBY -rrbconfig -e ' - c = Config::CONFIG + c = RbConfig::CONFIG if c.has_key? "LIBRUBYARG_STATIC" # 1.8.x if c[["LIBRUBY"]] == c[["LIBRUBY_A"]] link = c[["LIBRUBYARG_STATIC"]] @@ -1688,11 +1671,11 @@ if test -n "$RUBY"; then case $host in *-*-mingw*) ;; # do nothing, the default windows libraries are already included - *) RUBYLINK="$RUBYLINK `($RUBY -rrbconfig -e 'print Config::CONFIG[["LIBS"]]') 2>/dev/null`";; + *) RUBYLINK="$RUBYLINK `($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["LIBS"]]') 2>/dev/null`";; esac - RUBYCCDLFLAGS=`($RUBY -rrbconfig -e 'print Config::CONFIG[["CCDLFLAGS"]]') 2>/dev/null` - RUBYSO=.`($RUBY -rrbconfig -e 'print Config::CONFIG[["DLEXT"]]') 2>/dev/null` + RUBYCCDLFLAGS=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["CCDLFLAGS"]]') 2>/dev/null` + RUBYSO=.`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["DLEXT"]]') 2>/dev/null` else AC_MSG_RESULT(could not figure out how to run ruby) fi @@ -2164,86 +2147,86 @@ fi # check version: we need Lua 5.x if test "$LUABIN"; then - AC_MSG_CHECKING(Lua version) - # if version 5.x - LUAV5=`$LUABIN -e 'if string.sub(_VERSION,5,5)=="5" then print "1" end'` - # if not version 5.0 - LUAV51=`$LUABIN -e 'if string.sub(_VERSION,5,7)~="5.0" then print "1" end'` + AC_MSG_CHECKING(Lua version) + # if version 5.x + LUAV5=`$LUABIN -e 'if string.sub(_VERSION,5,5)=="5" then print "1" end'` + # if not version 5.0 + LUAV51=`$LUABIN -e 'if string.sub(_VERSION,5,7)~="5.0" then print "1" end'` - if test -z "$LUAV5"; then - AC_MSG_WARN(Not Lua 5.x, SWIG does not support this version of Lua) - LUABIN="" - elif test -z "$LUAV51"; then - AC_MSG_RESULT(Lua 5.0.x) - else - AC_MSG_RESULT(Lua 5.1 or later) - fi -fi - -if test "$LUABIN"; then - AC_MSG_CHECKING(whether Lua dynamic loading is enabled) - # using Lua to check Lua - # lua 5.0 & 5.1 have different fn names - if test -z "$LUAV51"; then - LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=loadlib("no_such_lib","") if c~="absent" then print "1" end'` - else - LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=package.loadlib("no_such_lib","") if c~="absent" then print "1" end'` - fi - - if test -z "$LUADYNAMICLOADLIB"; then - AC_MSG_RESULT(no) - else - AC_MSG_RESULT(yes) - fi -fi - -# look for the header files & set LUAFLAGS accordingly -# will clear LUABIN if not present -if test -n "$LUAINCLUDE"; then - AC_CHECK_FILE($LUAINCLUDE/lua.h,[LUAFLAGS="$ISYSTEM$LUAINCLUDE"],[LUABIN=]) -else - LUA_OK="1" - AC_CHECK_HEADER(lua.h,[LUAFLAGS=""],[LUA_OK=""]) - # if we didn't get it, going to have to look elsewhere (the hard way) - if test -z "$LUA_OK"; then - AC_MSG_CHECKING(for lua.h in other locations) - # note: Debian/Ubuntu seem to like /usr/include/lua5.1/lua.h - # The ordering of the include directories to search should match - # the ordering of libraries to search in the library test below. - inc=/usr/include - dirs="$inc/lua5.2 $inc/lua5.1 $inc/lua51 $inc/lua5.0 $inc/lua50 /usr/local/include" - for i in $dirs; do - #echo "$i" - if test -r $i/lua.h; then - AC_MSG_RESULT($i/lua.h) - LUAFLAGS="$ISYSTEM$i" - break - fi - done - if test -z "$LUAFLAGS"; then - AC_MSG_RESULT(not found) - LUABIN="" # clear the bin - fi + if test -z "$LUAV5"; then + AC_MSG_WARN(Not Lua 5.x, SWIG does not support this version of Lua) + LUABIN="" + elif test -z "$LUAV51"; then + AC_MSG_RESULT(Lua 5.0.x) + else + AC_MSG_RESULT(Lua 5.1 or later) fi fi -# look for the library files & set LUALINK accordingly -# will clear LUABIN if not present -lua_save_LIBS=$LIBS # the code seems to disrupt LIBS, so saving +if test "$LUABIN"; then + AC_MSG_CHECKING(whether Lua dynamic loading is enabled) + # using Lua to check Lua + # lua 5.0 & 5.1 have different fn names + if test -z "$LUAV51"; then + LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=loadlib("no_such_lib","") if c~="absent" then print "1" end'` + else + LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=package.loadlib("no_such_lib","") if c~="absent" then print "1" end'` + fi -if test -n "$LUALIB"; then - AC_CHECK_FILE($LUALIB/liblua.a,[LUALINK="-L$LUALIB -llua"],[LUABIN=]) -else - AC_SEARCH_LIBS(lua_close, [lua lua5.2 lua5.1 lua51 lua5.0 lua50], [LUALINK="-l$ac_lib"],[LUABIN=]) + if test -z "$LUADYNAMICLOADLIB"; then + AC_MSG_RESULT(no) + else + AC_MSG_RESULT(yes) + fi + + # look for the header files & set LUAFLAGS accordingly + # will clear LUABIN if not present + if test -n "$LUAINCLUDE"; then + AC_CHECK_FILE($LUAINCLUDE/lua.h,[LUAFLAGS="$ISYSTEM$LUAINCLUDE"],[LUABIN=]) + else + LUA_OK="1" + AC_CHECK_HEADER(lua.h,[LUAFLAGS=""],[LUA_OK=""]) + # if we didn't get it, going to have to look elsewhere (the hard way) + if test -z "$LUA_OK"; then + AC_MSG_CHECKING(for lua.h in other locations) + # note: Debian/Ubuntu seem to like /usr/include/lua5.1/lua.h + # The ordering of the include directories to search should match + # the ordering of libraries to search in the library test below. + inc=/usr/include + dirs="$inc/lua5.2 $inc/lua5.1 $inc/lua51 $inc/lua5.0 $inc/lua50 /usr/local/include" + for i in $dirs; do + #echo "$i" + if test -r $i/lua.h; then + AC_MSG_RESULT($i/lua.h) + LUAFLAGS="$ISYSTEM$i" + break + fi + done + if test -z "$LUAFLAGS"; then + AC_MSG_RESULT(not found) + LUABIN="" # clear the bin + fi + fi + fi + + # look for the library files & set LUALINK accordingly + # will clear LUABIN if not present + lua_save_LIBS=$LIBS # the code seems to disrupt LIBS, so saving + + if test -n "$LUALIB"; then + AC_CHECK_FILE($LUALIB/liblua.a,[LUALINK="-L$LUALIB -llua"],[LUABIN=]) + else + AC_SEARCH_LIBS(lua_close, [lua lua5.2 lua5.1 lua51 lua5.0 lua50], [LUALINK="-l$ac_lib"],[LUABIN=]) + fi + + # adding lualib for lua 5.0 + if test -z "$LUAV51"; then # extra for lua 5.0 + LUALINK="$LUALINK -llualib" + fi + + LIBS=$lua_save_LIBS # restore LIBS fi -# adding lualib for lua 5.0 -if test -z "$LUAV51"; then # extra for lua 5.0 - LUALINK="$LUALINK -llualib" -fi - -LIBS=$lua_save_LIBS # restore LIBS - fi # if not disabled AC_SUBST(LUADYNAMICLINKING) @@ -2381,17 +2364,24 @@ else GOVERSIONOPTION=version GOC=$(sh -c "$(go env) && echo \$GOCHAR")c go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //') + AC_MSG_CHECKING([whether go version is too old]) case $go_version in - go1.0*) GOOPT="-intgosize 32" ;; - *) if test "$GOC" = "6c"; then - GOOPT="-intgosize 64" - else - GOOPT="-intgosize 32" - fi - ;; + go1.0* | go1 ) + AC_MSG_RESULT([yes - minimum version is 1.1]) + GO= + GOOPT="-intgosize 32" + ;; + *) + AC_MSG_RESULT([no]) + if test "$GOC" = "6c"; then + GOOPT="-intgosize 64" + else + GOOPT="-intgosize 32" + fi + ;; esac case $go_version in - go1.0* | go1.1*) + go1.0* | go1 | go1.1*) GOOPT="$GOOPT -use-shlib" ;; go1.2*) @@ -2405,14 +2395,17 @@ else GOC=`echo $GO | sed -e 's/g/c/'` GOVERSIONOPTION=-V AC_MSG_CHECKING([whether Go ($GO) version is too old]) - go_version=`$GO $GOVERSIONOPTION 2>/dev/null | sed -e 's/.*version.* \([[0-9]]*\).*/\1/'` - go_min_version=7077 - if test "$go_version" != "" -a "$go_version" -lt $go_min_version; then - AC_MSG_RESULT([yes - minimum version is $go_min_version]) - GO= - else - AC_MSG_RESULT([no]) - fi + AC_MSG_RESULT([yes - minimum version is 1.1]) + GO= + dnl Old code retained for now in case we implement an option for it. + dnl go_version=`$GO $GOVERSIONOPTION 2>/dev/null | sed -e 's/.*version.* \([[0-9]]*\).*/\1/'` + dnl go_min_version=7077 + dnl if test "$go_version" != "" -a "$go_version" -lt $go_min_version; then + dnl AC_MSG_RESULT([yes - minimum version is $go_min_version]) + dnl GO= + dnl else + dnl AC_MSG_RESULT([no]) + dnl fi GOOPT="-intgosize 32" GO12=false GO13=false @@ -2743,6 +2736,7 @@ AC_CONFIG_FILES([ Makefile swig.spec Examples/Makefile + Examples/d/example.mk Examples/xml/Makefile Examples/test-suite/errors/Makefile Examples/test-suite/chicken/Makefile diff --git a/preinst-swig.in b/preinst-swig.in index 0f49e2e5e..384593ce1 100755 --- a/preinst-swig.in +++ b/preinst-swig.in @@ -4,4 +4,4 @@ srcdir=`cd "$builddir" && cd '@srcdir@' && pwd` SWIG_LIB=$srcdir/Lib #SWIG_LIB=`cygpath -w $srcdir/Lib` # For native Windows version of SWIG export SWIG_LIB -exec "$builddir/swig" $* +exec "$builddir/swig" "$@"