From 931628f8b245ecbed4a3f020715bff123cacd1b1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 28 Feb 2010 00:09:20 +0000 Subject: [PATCH 001/203] Remove the svn/cvs Id string in the headers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11877 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Devel/engineering.html | 17 ++++++++++------- Makefile.in | 2 +- Source/CParse/cparse.h | 2 -- Source/Modules/swigmod.h | 2 -- Source/Preprocessor/preprocessor.h | 2 -- Source/Swig/swig.h | 2 -- Source/Swig/swigfile.h | 2 -- Source/Swig/swigopt.h | 2 -- Source/Swig/swigparm.h | 2 -- Source/Swig/swigscan.h | 2 -- Source/Swig/swigtree.h | 2 -- Source/Swig/swigwrap.h | 2 -- 12 files changed, 11 insertions(+), 28 deletions(-) diff --git a/Doc/Devel/engineering.html b/Doc/Devel/engineering.html index 5ccfb7858..7dfef2ad3 100644 --- a/Doc/Devel/engineering.html +++ b/Doc/Devel/engineering.html @@ -119,22 +119,25 @@ are case-insensitive on Windows so this convention will prevent you from inadver creating two files that differ in case-only.

-Each file should include a short abstract, author information, copyright information, and +Each file should include a short abstract, license information and a SVN revision tag like this:

 /* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
+ * This file is part of SWIG, which is licensed as a whole under version 3 
+ * (or any later version) of the GNU General Public License. Some additional
+ * terms also apply to certain portions of SWIG. The full details of the SWIG
+ * license and copyrights can be found in the LICENSE and COPYRIGHT files
+ * included with the SWIG source code as distributed by the SWIG developers
+ * and at http://www.swig.org/legal.html.
  *
- * cwrap.c
+ * xxx.c
  *
- * This file defines a variety of wrapping rules for C/C++ handling including
- * the naming of local variables, calling conventions, and so forth.
+ * This file defines ...
  * ----------------------------------------------------------------------------- */
 
-char cvsroot_cwrap_c[] = "$Id$";
+static char cvs[] = "$Id$ xxx.c";
 
 #include "swig.h"
 
diff --git a/Makefile.in b/Makefile.in
index bdfec746e..6effe59b9 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,5 +1,5 @@
 #######################################################################
-# $Id$
+# SWIG top level Makefile
 #######################################################################
 
 .PHONY: ccache source swig
diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h
index ddc5d05dc..922bbfcdc 100644
--- a/Source/CParse/cparse.h
+++ b/Source/CParse/cparse.h
@@ -11,8 +11,6 @@
  * SWIG parser module.
  * ----------------------------------------------------------------------------- */
 
-/* $Id$ */
-
 #ifndef SWIG_CPARSE_H_
 #define SWIG_CPARSE_H_
 
diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h
index 813c56cb9..a6b5234d4 100644
--- a/Source/Modules/swigmod.h
+++ b/Source/Modules/swigmod.h
@@ -11,8 +11,6 @@
  * Main header file for SWIG modules.
  * ----------------------------------------------------------------------------- */
 
-/* $Id$ */
-
 #ifndef SWIG_SWIGMOD_H_
 #define SWIG_SWIGMOD_H_
 
diff --git a/Source/Preprocessor/preprocessor.h b/Source/Preprocessor/preprocessor.h
index 8f98dae15..b08ff31b9 100644
--- a/Source/Preprocessor/preprocessor.h
+++ b/Source/Preprocessor/preprocessor.h
@@ -11,8 +11,6 @@
  * SWIG preprocessor module.
  * ----------------------------------------------------------------------------- */
 
-/* $Id$ */
-
 #ifndef SWIG_PREPROCESSOR_H_
 #define SWIG_PREPROCESSOR_H_
 
diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h
index 6aff97955..ec5ecb271 100644
--- a/Source/Swig/swig.h
+++ b/Source/Swig/swig.h
@@ -11,8 +11,6 @@
  * Header file for the SWIG core.
  * ----------------------------------------------------------------------------- */
 
-/* $Id$ */
-
 #ifndef SWIGCORE_H_
 #define SWIGCORE_H_
 
diff --git a/Source/Swig/swigfile.h b/Source/Swig/swigfile.h
index 632e821e2..cdf23cddc 100644
--- a/Source/Swig/swigfile.h
+++ b/Source/Swig/swigfile.h
@@ -11,8 +11,6 @@
  * File handling functions in the SWIG core
  * ----------------------------------------------------------------------------- */
 
-/* $Id: swig.h 9603 2006-12-05 21:47:01Z beazley $ */
-
 extern List   *Swig_add_directory(const_String_or_char_ptr dirname);
 extern void    Swig_push_directory(const_String_or_char_ptr dirname);
 extern void    Swig_pop_directory(void);
diff --git a/Source/Swig/swigopt.h b/Source/Swig/swigopt.h
index 586f8bbc4..543bfb819 100644
--- a/Source/Swig/swigopt.h
+++ b/Source/Swig/swigopt.h
@@ -11,8 +11,6 @@
  * Header file for the SWIG command line processing functions
  * ----------------------------------------------------------------------------- */
 
-/* $Id: swig.h 9622 2006-12-19 03:49:17Z beazley $ */
-
  extern void  Swig_init_args(int argc, char **argv);
  extern void  Swig_mark_arg(int n);
  extern int   Swig_check_marked(int n);
diff --git a/Source/Swig/swigparm.h b/Source/Swig/swigparm.h
index 060225f6b..70a39390e 100644
--- a/Source/Swig/swigparm.h
+++ b/Source/Swig/swigparm.h
@@ -12,8 +12,6 @@
  * parameter lists.  
  * ----------------------------------------------------------------------------- */
 
-/* $Id: swig.h 9629 2006-12-30 18:27:47Z beazley $ */
-
 /* Individual parameters */
 extern Parm	 *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node);
 extern Parm      *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name);
diff --git a/Source/Swig/swigscan.h b/Source/Swig/swigscan.h
index d52124c60..b07812fbe 100644
--- a/Source/Swig/swigscan.h
+++ b/Source/Swig/swigscan.h
@@ -11,8 +11,6 @@
  * C/C++ scanner. 
  * ----------------------------------------------------------------------------- */
 
-/* $Id: swig.h 9633 2007-01-10 23:43:07Z beazley $ */
-
 typedef struct Scanner Scanner;
 
 extern Scanner     *NewScanner(void);
diff --git a/Source/Swig/swigtree.h b/Source/Swig/swigtree.h
index 6799398c9..5decb79e3 100644
--- a/Source/Swig/swigtree.h
+++ b/Source/Swig/swigtree.h
@@ -13,8 +13,6 @@
  * and function names are meant to be similar.
  * ----------------------------------------------------------------------------- */
 
-/* $Id: swig.h 9622 2006-12-19 03:49:17Z beazley $ */
-
 /* Macros to traverse the DOM tree */
 
 #define  nodeType(x)               Getattr(x,"nodeType")
diff --git a/Source/Swig/swigwrap.h b/Source/Swig/swigwrap.h
index b1f596f72..e44cb5344 100644
--- a/Source/Swig/swigwrap.h
+++ b/Source/Swig/swigwrap.h
@@ -11,8 +11,6 @@
  * Functions related to wrapper objects.
  * ----------------------------------------------------------------------------- */
 
-/* $Id: swig.h 9635 2007-01-12 01:44:16Z beazley $ */
-
 typedef struct Wrapper {
     Hash *localh;
     String *def;

From 9c541c340ad9103836fbdbed9658d84c9eccbef5 Mon Sep 17 00:00:00 2001
From: William S Fulton 
Date: Sun, 28 Feb 2010 00:16:39 +0000
Subject: [PATCH 002/203] remove final vestiges of gifplot example

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11878 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
 Doc/Devel/internals.html  |  5 ++--
 Doc/Manual/Chicken.html   |  3 +-
 Doc/Manual/Extending.html | 10 ++-----
 Examples/README           |  4 +--
 Examples/guile/README     |  3 --
 Examples/index.html       |  6 ----
 Examples/s-exp/uffi.lisp  | 61 ---------------------------------------
 7 files changed, 6 insertions(+), 86 deletions(-)

diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html
index 63a8626ff..5f774c095 100644
--- a/Doc/Devel/internals.html
+++ b/Doc/Devel/internals.html
@@ -76,9 +76,8 @@ to code).
 Examples
 This subdir tree contains examples of using SWIG w/ different
 scripting languages, including makefiles.  Typically, there are the
-"simple" and "matrix" examples, w/ some languages offering additional
-examples.  The GIFPlot example has its own set of per-language
-subdirectories.  See the README more index.html file in each directory
+"simple" and "class" examples, w/ some languages offering additional
+examples.  See the README more index.html file in each directory
 for more info.  [FIXME: Ref SWIG user manual.]
 
 
diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html
index 98372a0f7..d1d83aafa 100644
--- a/Doc/Manual/Chicken.html
+++ b/Doc/Manual/Chicken.html
@@ -86,8 +86,7 @@
 
       

You may want to look at any of the examples in Examples/chicken/ - or Examples/GIFPlot/Chicken for the basic steps to run SWIG - CHICKEN. + directory for the basic steps to run SWIG CHICKEN.

19.1.1 Running SWIG in C mode

diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index cc40024e6..bdf5e8478 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3090,8 +3090,6 @@ The nickname is used in four places: usagetransform "skip" tag(none) Examples/ subdir name(none) -Examples/GIFPlot/ subdir name - capitalize (upcase first letter) Examples/test-suite/ subdir name(none) @@ -3159,8 +3157,8 @@ skip-qux = $(skip-qux99)

Lastly, you need to modify each of check-aliveness, -check-examples, check-test-suite, -check-gifplot (all targets) and lib-languages (var). +check-examples, check-test-suite +and lib-languages (var). Use the nickname for these, not the alias. Note that you can do this even before you have any tests or examples set up; the Makefile rules do some sanity checking and skip around @@ -3175,10 +3173,6 @@ and look to the existing languages for examples.

Do cp ../python/check.list . and modify to taste. One subdir per line. -
Examples/GIFPlot/Qux99/check.list -
Do cp ../Python/check.list . and modify to taste. -One subdir per line. -
Lib/qux99/extra-install.list
If you add your language to the top-level Makefile.in var lib-languages, then make install will install diff --git a/Examples/README b/Examples/README index 0747547cb..4dda3222d 100644 --- a/Examples/README +++ b/Examples/README @@ -2,9 +2,7 @@ SWIG Examples The "perl5", "python", "tcl", "guile", "java", "mzscheme", "ruby", and "chicken" directories contain a number of simple examples that are -primarily used for testing. The "GIFPlot" directory contains a more -complicated example that illustrates some of SWIG's more advanced -capabilities. +primarily used for testing. The file 'index.html' is the top of a hyperlinked document that contains information about all of the examples along with various diff --git a/Examples/guile/README b/Examples/guile/README index acec7773b..7d726619e 100644 --- a/Examples/guile/README +++ b/Examples/guile/README @@ -12,6 +12,3 @@ std_vector -- C++ STL vector and vector Note that the examples in this directory build a special version of Guile which includes the wrapped functions in the top-level module. -If you want to put the wrapped functions into an own module, -statically or dynamically linked, see the Examples/GIFPlot/Guile -directory. diff --git a/Examples/index.html b/Examples/index.html index f8b614a89..66885b6a0 100644 --- a/Examples/index.html +++ b/Examples/index.html @@ -46,12 +46,6 @@ language: If your target platform is Windows, make sure you also see the Windows page in the main manual. -

Real Life

- -The GIFPlot directory contains examples that illustrate the use of SWIG with -a moderately complex C library for creating GIF images. Many of these -examples illustrate more advanced SWIG features. - diff --git a/Examples/s-exp/uffi.lisp b/Examples/s-exp/uffi.lisp index 5ddb4c20f..253f85aba 100644 --- a/Examples/s-exp/uffi.lisp +++ b/Examples/s-exp/uffi.lisp @@ -312,67 +312,6 @@ is no representation." ;; Test instances -#|| - -#+ignore -(defvar *gifplot-interface* - (run-swig (merge-pathnames "Examples/GIFPlot/Interface/gifplot.i" - *swig-source-directory*) - :directory-search-list (list (merge-pathnames "Examples/GIFPlot/Interface/" *swig-source-directory*)))) - -(defvar *simple-gifplot-interface* - (run-swig (merge-pathnames "Examples/GIFPlot/Include/gifplot.h" - *swig-source-directory*) - :directory-search-list (list (merge-pathnames "Examples/GIFPlot/Interface/" *swig-source-directory*)) - :module "gifplot")) - -(defvar *cplex-glue-directory* #p"/home/mkoeppe/cvs/cplex-glue/") - -(defvar *cplex-glue-interface* - (run-swig (merge-pathnames "cplex.i" *cplex-glue-directory*) - :directory-search-list (list (merge-pathnames "Lib/guile" - *swig-source-directory*) - *cplex-glue-directory*) - :ignore-errors t)) - - - -(require 'uffi) - -;;(let ((*uffi-primitive-type-alist* (cons '("Pixel" . :unsigned-int) *uffi-default-primitive-type-alist*))) -;; (eval (cons 'progn (compute-uffi-definitions *simple-gifplot-interface*)))) - - -(with-open-file (f "/tmp/swig-uffi.lisp" :direction :output - :if-exists :supersede) - (let ((*uffi-definitions* '()) - (*uffi-output* f) - (*uffi-primitive-type-alist* - (cons '("Pixel" . :unsigned-int) *uffi-default-primitive-type-alist*))) - (apply 'handle-node *simple-gifplot-interface*))) - -#+cplex -(with-open-file (f "/tmp/swig-uffi.lisp" :direction :output) - (let ((*uffi-definitions* '()) - (*uffi-output* f) - (*uffi-primitive-type-alist* - (cons '("Pixel" . :unsigned-int) *uffi-default-primitive-type-alist*))) - (apply 'handle-node *cplex-glue-interface*))) - -(compile-file "/tmp/swig-uffi.lisp") - -(uffi:load-foreign-library (merge-pathnames "Examples/GIFPlot/libgifplot.a" - *swig-source-directory*)) - -(load "/tmp/swig-uffi.lisp") - -(load (merge-pathnames "Examples/GIFPlot/Common-Lisp/full/runme.lisp" *swig-source-directory*)) - -(action (namestring (merge-pathnames "Examples/GIFPlot/Common-Lisp/full/cmap" - *swig-source-directory*))) - -||# - ;;; Link to SWIG itself #|| From d0ecd9cb517279d46f66d52aa81b01f196ba6c9d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 28 Feb 2010 00:26:20 +0000 Subject: [PATCH 003/203] Correct svn Id git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11879 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Devel/engineering.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Devel/engineering.html b/Doc/Devel/engineering.html index 7dfef2ad3..2e78fbe35 100644 --- a/Doc/Devel/engineering.html +++ b/Doc/Devel/engineering.html @@ -137,7 +137,7 @@ a SVN revision tag like this: * This file defines ... * ----------------------------------------------------------------------------- */ -static char cvs[] = "$Id$ xxx.c"; +static char cvs[] = "$Id$"; #include "swig.h" From faf8fee8772c8d26ce184854aede993edc728676 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 4 Mar 2010 18:27:23 +0000 Subject: [PATCH 004/203] minor comment added git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11894 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/extend_template.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/extend_template.i b/Examples/test-suite/extend_template.i index a39ac546d..265c87675 100644 --- a/Examples/test-suite/extend_template.i +++ b/Examples/test-suite/extend_template.i @@ -1,5 +1,5 @@ %module extend_template -%module xxx +%module xxx // should be ignored namespace oss { // this doesn't %extend Foo<0> { int test1(int x) { return x; } From 24422112920c58b433ba39df4cd8d5e51f7dce09 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 4 Mar 2010 18:28:23 +0000 Subject: [PATCH 005/203] unnecessary cast removed git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11895 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 9622ce9f3..1990a66c6 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3729,7 +3729,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Setattr(classes,scpname,$$); Delete(scpname); } else { - Swig_symbol_setscopename((char*)""); + Swig_symbol_setscopename(""); } } appendChild($$,$5); From 1253657bb43075c6862ad8205805864f9dae44ce Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 4 Mar 2010 21:27:23 +0000 Subject: [PATCH 006/203] Add improved namespace support - the nspace feature, working for Java only at the moment. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11896 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 30 ++- Examples/test-suite/common.mk | 1 + Examples/test-suite/java/Makefile.in | 23 +-- Examples/test-suite/nspace.i | 93 +++++++++ Source/Modules/chicken.cxx | 6 +- Source/Modules/csharp.cxx | 30 +-- Source/Modules/java.cxx | 275 +++++++++++++++++++-------- Source/Modules/lang.cxx | 62 +++--- Source/Modules/lua.cxx | 14 +- Source/Modules/modula3.cxx | 10 +- Source/Modules/octave.cxx | 18 +- Source/Modules/perl5.cxx | 28 +-- Source/Modules/pike.cxx | 8 +- Source/Modules/python.cxx | 60 +++--- Source/Modules/ruby.cxx | 4 +- Source/Modules/swigmod.h | 5 +- Source/Modules/tcl8.cxx | 12 +- Source/Modules/typepass.cxx | 15 ++ Source/Swig/cwrap.c | 57 +++--- Source/Swig/misc.c | 51 +++++ Source/Swig/naming.c | 68 +++++-- Source/Swig/swig.h | 26 ++- Source/Swig/symbol.c | 15 ++ 23 files changed, 645 insertions(+), 266 deletions(-) create mode 100644 Examples/test-suite/nspace.i diff --git a/CHANGES.current b/CHANGES.current index 902308847..ec0473bee 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,34 @@ -Version 1.3.41 (in progress) +Version 2.0.0 (in progress) ============================ +2010-03-04: wsfulton + Added the nspace feature. This adds some improved namespace support. Currently only Java + is supported for target languages, where C++ namespaces are automatically translated into + Java packages. The feature only applies to classes,struct,unions and enums declared within + a namespace. Methods and variables declared in namespaces still effectively have their + namespaces flattened. Example usage: + + %feature(nspace) Outer::Inner1::Color; + %feature(nspace) Outer::Inner2::Color; + + namespace Outer { + namespace Inner1 { + struct Color { + ... + }; + } + namespace Inner2 { + struct Color { + ... + }; + } + } + + For Java, the -package option is also required when using the nspace feature. Say + we use -package com.myco, the two classes can then be accessed as follows from Java: + + com.myco.Outer.Inner1.Color and com.myco.Outer.Inner2.Color. + 2010-02-27: wsfulton [Python] Remove -dirvtable from the optimizations included by -O as it this option currently leads to memory leaks as reported by Johan Blake. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index d15451aca..2b4ab0701 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -242,6 +242,7 @@ CPP_TEST_CASES += \ namespace_typemap \ namespace_union \ namespace_virtual_method \ + nspace \ naturalvar \ nested_class \ nested_comment \ diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 5c96ca154..119b50868 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -37,26 +37,27 @@ CPP_TEST_CASES = \ include $(srcdir)/../common.mk # Overridden variables here -SWIGOPT += -package $* +JAVA_PACKAGE = $* +SWIGOPT += -package $(JAVA_PACKAGE) INTERFACEDIR = ../../ # Custom tests - tests with additional commandline options -# none! +nspace.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests %.cpptest: $(setup) - +(cd $* && $(swig_and_compile_cpp)) + +(cd $(JAVA_PACKAGE) && $(swig_and_compile_cpp)) $(run_testcase) %.ctest: $(setup) - +(cd $* && $(swig_and_compile_c)) + +(cd $(JAVA_PACKAGE) && $(swig_and_compile_c)) $(run_testcase) %.multicpptest: $(setup) - +(cd $* && $(swig_and_compile_multi_cpp)) + +(cd $(JAVA_PACKAGE) && $(swig_and_compile_multi_cpp)) $(run_testcase) # Makes a directory for the testcase if it does not exist @@ -66,24 +67,24 @@ setup = \ else \ echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ fi; \ - if [ ! -d $* ]; then \ - mkdir $*; \ + if [ ! -d $(JAVA_PACKAGE) ]; then \ + mkdir $(JAVA_PACKAGE); \ fi # Compiles java files then runs the testcase. A testcase is only run if # a file is found which has _runme.java appended after the testcase name. # Note Java uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows, SHLIB_PATH on HPUX and DYLD_LIBRARY_PATH on Mac OS X. run_testcase = \ - cd $* && $(COMPILETOOL) $(JAVAC) -classpath . *.java && cd .. && \ + cd $(JAVA_PACKAGE) && $(COMPILETOOL) $(JAVAC) -classpath . `find . -name "*.java"` && cd .. && \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ $(COMPILETOOL) $(JAVAC) -classpath . -d . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ - env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_LIBRARY_PATH="$*:$$DYLD_LIBRARY_PATH" $(RUNTOOL) $(JAVA) -classpath . $*_runme; \ + env LD_LIBRARY_PATH="$(JAVA_PACKAGE):$$LD_LIBRARY_PATH" PATH="$(JAVA_PACKAGE):$$PATH" SHLIB_PATH="$(JAVA_PACKAGE):$$SHLIB_PATH" DYLD_LIBRARY_PATH="$(JAVA_PACKAGE):$$DYLD_LIBRARY_PATH" $(RUNTOOL) $(JAVA) -classpath . $*_runme; \ fi # Clean: remove testcase directories %.clean: - @if [ -d $* ]; then \ - rm -rf $*; \ + @if [ -d $(JAVA_PACKAGE) ]; then \ + rm -rf $(JAVA_PACKAGE); \ fi clean: diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i new file mode 100644 index 000000000..26a3273b2 --- /dev/null +++ b/Examples/test-suite/nspace.i @@ -0,0 +1,93 @@ +// Test the nspace feature +%module nspace + +#if defined(SWIGJAVA) +SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) +%pragma(java) jniclassclassmodifiers = "public class" + +%feature("nspace"); +%feature("nspace", "0") Outer::Inner2::NoNSpacePlease; + +%copyctor; +%ignore Outer::Inner2::Color::Color(); + +%inline %{ + +namespace Outer { + class nspace { + }; + namespace Inner1 { + enum Channel { + Diffuse, + Specular = 0x10, + Transmission1 + }; + + struct Color { + static Color* create() { return new Color(); } + + enum Channel { + Diffuse, + Specular = 0x20, + Transmission + }; + + int instanceMemberVariable; + static int staticMemberVariable; + void colorInstanceMethod(double d) {} + static void colorStaticMethod(double d) {} + }; // Color + int Color::staticMemberVariable = 0; + + Color namespaceFunction(Color k) { return k; } + int namespaceVar = 0; + } // Inner1 + + namespace Inner2 { + enum Channel { + Diffuse, + Specular /* = 0x30*/, + Transmission2 + }; + + struct Color { + Color() : instanceMemberVariable(0) {} + static Color* create() { return new Color(); } + + enum Channel { + Diffuse, + Specular/* = 0x40*/, + Transmission + }; + + int instanceMemberVariable; + static int staticMemberVariable; + void colorInstanceMethod(double d) {} + static void colorStaticMethod(double d) {} + }; // Color + int Color::staticMemberVariable = 0; + class NoNSpacePlease {}; + } // Inner2 + + class SomeClass { + public: + Inner1::Color::Channel GetInner1ColorChannel() { return Inner1::Color::Transmission; } + Inner2::Color::Channel GetInner2ColorChannel() { return Inner2::Color::Transmission; } + Inner1::Channel GetInner1Channel() { return Inner1::Transmission1; } + Inner2::Channel GetInner2Channel() { return Inner2::Transmission2; } + }; // SomeClass + +} // Outer + +namespace Outer { + struct MyWorldPart2 {}; +} + +struct GlobalClass { + void gmethod() {} +}; + +void test_classes(Outer::SomeClass c, Outer::Inner2::Color cc) {} +%} + +#endif diff --git a/Source/Modules/chicken.cxx b/Source/Modules/chicken.cxx index 1d9e9c620..9cac92dcb 100644 --- a/Source/Modules/chicken.cxx +++ b/Source/Modules/chicken.cxx @@ -1152,9 +1152,9 @@ int CHICKEN::membervariableHandler(Node *n) { //String *getfunc = NewStringf("%s-%s-get", short_class_name, proc); //String *setfunc = NewStringf("%s-%s-set", short_class_name, proc); - String *getfunc = Swig_name_get(Swig_name_member(c_class_name, iname)); + String *getfunc = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, c_class_name, iname)); Replaceall(getfunc, "_", "-"); - String *setfunc = Swig_name_set(Swig_name_member(c_class_name, iname)); + String *setfunc = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, c_class_name, iname)); Replaceall(setfunc, "_", "-"); Printv(clos_class_defines, " (list '", proc, " ':swig-virtual ':swig-get ", chickenPrimitiveName(getfunc), NIL); @@ -1201,7 +1201,7 @@ int CHICKEN::constructorHandler(Node *n) { has_constructor_args = 1; String *iname = Getattr(n, "sym:name"); - constructor_name = Swig_name_construct(iname); + constructor_name = Swig_name_construct(NSPACE_TODO, iname); Replaceall(constructor_name, "_", "-"); return SWIG_OK; } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index d813c2e56..6d3d09ea4 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -162,7 +162,7 @@ public: /* ----------------------------------------------------------------------------- * getProxyName() * - * Test to see if a type corresponds to something wrapped with a proxy class + * Test to see if a type corresponds to something wrapped with a proxy class. * Return NULL if not otherwise the proxy class name * ----------------------------------------------------------------------------- */ @@ -1033,7 +1033,7 @@ public: */ if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Capitalize the first letter in the variable in the getter/setter function name - bool getter_flag = Cmp(symname, Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) != 0; + bool getter_flag = Cmp(symname, Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, proxy_class_name, variable_name))) != 0; String *getter_setter_name = NewString(""); if (!getter_flag) @@ -1381,13 +1381,13 @@ public: if (classname_substituted_flag) { if (SwigType_isenum(t)) { // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) - Printf(constants_code, "(%s)%s.%s();\n", return_type, imclass_name, Swig_name_get(symname)); + Printf(constants_code, "(%s)%s.%s();\n", return_type, imclass_name, Swig_name_get(NSPACE_TODO, symname)); } else { // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(symname)); + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(NSPACE_TODO, symname)); } } else - Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(symname)); + Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(NSPACE_TODO, symname)); // Each constant and enum value is wrapped with a separate PInvoke function call SetFlag(n, "feature:immutable"); @@ -1862,7 +1862,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(NSPACE_TODO, proxy_class_name, overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -1882,7 +1882,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(NSPACE_TODO, proxy_class_name, overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -1962,7 +1962,7 @@ public: if (wrapping_member_flag && !enum_constant_flag) { // Properties - setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, proxy_class_name, variable_name))) == 0); if (setter_flag) Swig_typemap_attach_parms("csvarin", l, NULL); } @@ -2132,7 +2132,7 @@ public: Node *explicit_n = Getattr(n, "explicitcallnode"); if (explicit_n) { String *ex_overloaded_name = getOverloadedName(explicit_n); - String *ex_intermediary_function_name = Swig_name_member(proxy_class_name, ex_overloaded_name); + String *ex_intermediary_function_name = Swig_name_member(NSPACE_TODO, proxy_class_name, ex_overloaded_name); String *ex_imcall = Copy(imcall); Replaceall(ex_imcall, "$imfuncname", ex_intermediary_function_name); @@ -2250,7 +2250,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *mangled_overname = Swig_name_construct(overloaded_name); + String *mangled_overname = Swig_name_construct(NSPACE_TODO, overloaded_name); String *imcall = NewString(""); const String *csattributes = Getattr(n, "feature:cs:attributes"); @@ -2451,7 +2451,7 @@ public: String *symname = Getattr(n, "sym:name"); if (proxy_flag) { - Printv(destructor_call, imclass_name, ".", Swig_name_destroy(symname), "(swigCPtr)", NIL); + Printv(destructor_call, imclass_name, ".", Swig_name_destroy(NSPACE_TODO, symname), "(swigCPtr)", NIL); } return SWIG_OK; } @@ -2577,7 +2577,7 @@ public: if (proxy_flag && global_variable_flag) { // Capitalize the first letter in the variable to create the getter/setter function name func_name = NewString(""); - setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(variable_name)) == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(NSPACE_TODO, variable_name)) == 0); if (setter_flag) Printf(func_name, "set"); else @@ -2848,10 +2848,10 @@ public: // Strange hack to change the name Setattr(n, "name", Getattr(n, "value")); /* for wrapping of enums in a namespace when emit_action is used */ constantWrapper(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(symname)); + value = NewStringf("%s.%s()", imclass_name, Swig_name_get(NSPACE_TODO, symname)); } else { memberconstantHandler(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(Swig_name_member(proxy_class_name, symname))); + value = NewStringf("%s.%s()", imclass_name, Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, proxy_class_name, symname))); } } } @@ -3279,7 +3279,7 @@ public: // we're consistent with the sym:overload name in functionWrapper. (?? when // does the overloaded method name get set?) - imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(classname, overloaded_name)); + imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(NSPACE_TODO, classname, overloaded_name)); if (returntype) { diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 7a9d739f1..1bb9532ee 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -56,7 +56,9 @@ class JAVA:public Language { String *proxy_class_def; String *proxy_class_code; String *module_class_code; - String *proxy_class_name; + String *proxy_class_name; // proxy class name + String *full_proxy_class_name;// fully qualified proxy class name when using nspace feature, otherwise same as proxy_class_name + String *full_imclass_name; // fully qualified intermediary class name when using nspace feature, otherwise same as imclass_name String *variable_name; //Name of a variable being wrapped String *proxy_class_constants_code; String *module_class_constants_code; @@ -125,6 +127,8 @@ public: proxy_class_code(NULL), module_class_code(NULL), proxy_class_name(NULL), + full_proxy_class_name(NULL), + full_imclass_name(NULL), variable_name(NULL), proxy_class_constants_code(NULL), module_class_constants_code(NULL), @@ -157,19 +161,35 @@ public: /* ----------------------------------------------------------------------------- * getProxyName() * - * Test to see if a type corresponds to something wrapped with a proxy class - * Return NULL if not otherwise the proxy class name + * Test to see if a type corresponds to something wrapped with a proxy class. + * Return NULL if not otherwise the proxy class name, fully qualified with + * package name if the nspace feature is used. * ----------------------------------------------------------------------------- */ String *getProxyName(SwigType *t) { - if (proxy_flag) { - Node *n = classLookup(t); - if (n) { - return Getattr(n, "sym:name"); - } - } - return NULL; - } + String *proxyname = NULL; + if (proxy_flag) { + Node *n = classLookup(t); + if (n) { + proxyname = Getattr(n, "proxyname"); + if (!proxyname) { + String *nspace = Getattr(n, "sym:nspace"); + String *symname = Getattr(n, "sym:name"); + if (nspace) { + if (Len(package) > 0) + proxyname = NewStringf("%s.%s.%s", package, nspace, symname); + else + proxyname = NewStringf("%s.%s", nspace, symname); + } else { + proxyname = Copy(symname); + } + Setattr(n, "proxyname", proxyname); + Delete(proxyname); + } + } + } + return proxyname; + } /* ----------------------------------------------------------------------------- * makeValidJniName() @@ -410,7 +430,7 @@ public: Replaceall(package_path, ".", "/"); } String *jniname = makeValidJniName(imclass_name); - Printf(wrapper_name, "Java_%s%s_%%f", Char(jnipackage), jniname); + Printf(wrapper_name, "Java_%s%s_%%f", jnipackage, jniname); Delete(jniname); Swig_name_register("wrapper", Char(wrapper_name)); @@ -1099,7 +1119,7 @@ public: */ if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Capitalize the first letter in the variable to create a JavaBean type getter/setter function name - bool getter_flag = Cmp(symname, Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) != 0; + bool getter_flag = Cmp(symname, Swig_name_set(getNSpace(), Swig_name_member(0, proxy_class_name, variable_name))) != 0; String *getter_setter_name = NewString(""); if (!getter_flag) @@ -1167,6 +1187,24 @@ public: if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (proxy_flag && !is_wrapping_class()) { + // Global enums / enums in a namespace + String *nspace = Getattr(n, "sym:nspace"); + assert(!full_imclass_name); + + if (!nspace) { + full_imclass_name = NewStringf("%s", imclass_name); + } else { + if (Len(package) > 0) { + full_imclass_name = NewStringf("%s.%s", package, imclass_name); + } else { + full_imclass_name = NewStringf("%s", imclass_name); + Printf(stderr, "The nspace feature used on %s is not supported unless a package is specified with -package - Java does not support types declared in the unnamed package accessing types declared in a package.\n", Getattr(n, "name")); + SWIG_exit(EXIT_FAILURE); + } + } + } + enum_code = NewString(""); String *symname = Getattr(n, "sym:name"); String *constants_code = (proxy_flag && is_wrapping_class())? proxy_class_constants_code : module_class_constants_code; @@ -1224,7 +1262,9 @@ public: Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL); } else { // Global enums are defined in their own file - String *filen = NewStringf("%s%s.java", SWIG_output_directory(), symname); + String *nspace = Getattr(n, "sym:nspace"); + String *output_directory = outputDirectory(nspace); + String *filen = NewStringf("%s%s.java", output_directory, symname); File *f_enum = NewFile(filen, "w", SWIG_output_files()); if (!f_enum) { FileErrorDisplay(filen); @@ -1237,14 +1277,21 @@ public: // Start writing out the enum file emitBanner(f_enum); - if (Len(package) > 0) - Printf(f_enum, "package %s;\n", package); + if (Len(package) > 0 || nspace) { + Printf(f_enum, "package "); + if (Len(package) > 0) + Printv(f_enum, package, nspace ? "." : "", NIL); + if (nspace) + Printv(f_enum, nspace, NIL); + Printf(f_enum, ";\n"); + } Printv(f_enum, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE), // Import statements "\n", enum_code, "\n", NIL); Printf(f_enum, "\n"); Close(f_enum); + Delete(output_directory); } } else { // Wrap C++ enum with simple constant @@ -1257,6 +1304,11 @@ public: Delete(enum_code); enum_code = NULL; + + if (proxy_flag && !is_wrapping_class()) { + Delete(full_imclass_name); + full_imclass_name = 0; + } } return SWIG_OK; } @@ -1418,13 +1470,13 @@ public: if (classname_substituted_flag) { if (SwigType_isenum(t)) { // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) - Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, imclass_name, Swig_name_get(symname)); + Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, imclass_name, Swig_name_get(getNSpace(), symname)); } else { // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(symname)); + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(getNSpace(), symname)); } } else - Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(symname)); + Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(getNSpace(), symname)); // Each constant and enum value is wrapped with a separate JNI function call SetFlag(n, "feature:immutable"); @@ -1691,16 +1743,18 @@ public: /* Also insert the swigTakeOwnership and swigReleaseOwnership methods */ if (feature_director) { String *destruct_jnicall, *release_jnicall, *take_jnicall; + String *changeown_method_name = Swig_name_member(getNSpace(), proxy_class_name, "change_ownership"); destruct_jnicall = NewStringf("%s()", destruct_methodname); - release_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, false)", imclass_name, proxy_class_name); - take_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, true)", imclass_name, proxy_class_name); + release_jnicall = NewStringf("%s.%s(this, swigCPtr, false)", full_imclass_name, changeown_method_name); + take_jnicall = NewStringf("%s.%s(this, swigCPtr, true)", full_imclass_name, changeown_method_name); emitCodeTypemap(n, false, typemap_lookup_type, "directordisconnect", "methodname", destruct_jnicall); emitCodeTypemap(n, false, typemap_lookup_type, "directorowner_release", "methodname", release_jnicall); emitCodeTypemap(n, false, typemap_lookup_type, "directorowner_take", "methodname", take_jnicall); Delete(destruct_jnicall); + Delete(changeown_method_name); Delete(release_jnicall); Delete(take_jnicall); } @@ -1719,14 +1773,14 @@ public: Replaceall(proxy_class_def, "$module", module_class_name); Replaceall(proxy_class_code, "$module", module_class_name); - Replaceall(proxy_class_def, "$imclassname", imclass_name); - Replaceall(proxy_class_code, "$imclassname", imclass_name); + Replaceall(proxy_class_def, "$imclassname", full_imclass_name); + Replaceall(proxy_class_code, "$imclassname", full_imclass_name); // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { Printv(imclass_cppcasts_code, " public final static native long SWIG$javaclassnameUpcast(long jarg1);\n", NIL); - Replaceall(imclass_cppcasts_code, "$javaclassname", proxy_class_name); + Replaceall(imclass_cppcasts_code, "$javaclassname", full_proxy_class_name); Printv(upcasts_code, "SWIGEXPORT jlong JNICALL Java_$jnipackage$imimclass_SWIG$imclazznameUpcast", @@ -1735,7 +1789,7 @@ public: " (void)jenv;\n" " (void)jcls;\n" " *($cbaseclass **)&baseptr = *($cclass **)&jarg1;\n" " return baseptr;\n" "}\n", "\n", NIL); String *imimclass = makeValidJniName(imclass_name); - String *imclazzname = makeValidJniName(proxy_class_name); + String *imclazzname = makeValidJniName(full_proxy_class_name); Replaceall(upcasts_code, "$cbaseclass", c_baseclass); Replaceall(upcasts_code, "$imclazzname", imclazzname); Replaceall(upcasts_code, "$cclass", c_classname); @@ -1757,21 +1811,37 @@ public: File *f_proxy = NULL; if (proxy_flag) { proxy_class_name = NewString(Getattr(n, "sym:name")); + String *nspace = getNSpace(); - if (!addSymbol(proxy_class_name, n)) + if (!nspace) { + full_proxy_class_name = NewStringf("%s", proxy_class_name); + full_imclass_name = NewStringf("%s", imclass_name); + if (Cmp(proxy_class_name, imclass_name) == 0) { + Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); + } + + if (Cmp(proxy_class_name, module_class_name) == 0) { + Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); + } + } else { + if (Len(package) > 0) { + full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); + full_imclass_name = NewStringf("%s.%s", package, imclass_name); + } else { + full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); + full_imclass_name = NewStringf("%s", imclass_name); + Printf(stderr, "The nspace feature used on %s is not supported unless a package is specified with -package - Java does not support types declared in the unnamed package accessing types declared in a package.\n", Getattr(n, "name")); + SWIG_exit(EXIT_FAILURE); + } + } + + if (!addSymbol(proxy_class_name, n, nspace)) return SWIG_ERROR; - if (Cmp(proxy_class_name, imclass_name) == 0) { - Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); - SWIG_exit(EXIT_FAILURE); - } - - if (Cmp(proxy_class_name, module_class_name) == 0) { - Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); - SWIG_exit(EXIT_FAILURE); - } - - String *filen = NewStringf("%s%s.java", SWIG_output_directory(), proxy_class_name); + String *output_directory = outputDirectory(nspace); + String *filen = NewStringf("%s%s.java", output_directory, proxy_class_name); f_proxy = NewFile(filen, "w", SWIG_output_files()); if (!f_proxy) { FileErrorDisplay(filen); @@ -1784,8 +1854,14 @@ public: // Start writing out the proxy class file emitBanner(f_proxy); - if (Len(package) > 0) - Printf(f_proxy, "package %s;\n", package); + if (Len(package) > 0 || nspace) { + Printf(f_proxy, "package "); + if (Len(package) > 0) + Printv(f_proxy, package, nspace ? "." : "", NIL); + if (nspace) + Printv(f_proxy, nspace, NIL); + Printf(f_proxy, ";\n"); + } Clear(proxy_class_def); Clear(proxy_class_code); @@ -1793,6 +1869,7 @@ public: destructor_call = NewString(""); destructor_throws_clause = NewString(""); proxy_class_constants_code = NewString(""); + Delete(output_directory); } Language::classHandler(n); @@ -1804,9 +1881,9 @@ public: Replaceall(proxy_class_def, "$module", module_class_name); Replaceall(proxy_class_code, "$module", module_class_name); Replaceall(proxy_class_constants_code, "$module", module_class_name); - Replaceall(proxy_class_def, "$imclassname", imclass_name); - Replaceall(proxy_class_code, "$imclassname", imclass_name); - Replaceall(proxy_class_constants_code, "$imclassname", imclass_name); + Replaceall(proxy_class_def, "$imclassname", full_imclass_name); + Replaceall(proxy_class_code, "$imclassname", full_imclass_name); + Replaceall(proxy_class_constants_code, "$imclassname", full_imclass_name); Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); // Write out all the constants @@ -1848,6 +1925,10 @@ public: Delete(proxy_class_name); proxy_class_name = NULL; + Delete(full_proxy_class_name); + full_proxy_class_name = NULL; + Delete(full_imclass_name); + full_imclass_name = NULL; Delete(destructor_call); destructor_call = NULL; Delete(destructor_throws_clause); @@ -1869,7 +1950,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -1891,7 +1972,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -1967,7 +2048,7 @@ public: if (wrapping_member_flag && !enum_constant_flag) { // For wrapping member variables (Javabean setter) - setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), Swig_name_member(0, proxy_class_name, variable_name))) == 0); } /* Start generating the proxy function */ @@ -1978,7 +2059,7 @@ public: Printf(function_code, "static "); Printf(function_code, "%s %s(", return_type, proxy_function_name); - Printv(imcall, imclass_name, ".$imfuncname(", NIL); + Printv(imcall, full_imclass_name, ".$imfuncname(", NIL); if (!static_flag) { Printf(imcall, "swigCPtr"); @@ -2121,7 +2202,7 @@ public: Node *explicit_n = Getattr(n, "explicitcallnode"); if (explicit_n) { String *ex_overloaded_name = getOverloadedName(explicit_n); - String *ex_intermediary_function_name = Swig_name_member(proxy_class_name, ex_overloaded_name); + String *ex_intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, ex_overloaded_name); String *ex_imcall = Copy(imcall); Replaceall(ex_imcall, "$imfuncname", ex_intermediary_function_name); @@ -2183,7 +2264,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *mangled_overname = Swig_name_construct(overloaded_name); + String *mangled_overname = Swig_name_construct(getNSpace(), overloaded_name); String *imcall = NewString(""); const String *methodmods = Getattr(n, "feature:java:methodmodifiers"); @@ -2195,7 +2276,7 @@ public: Printf(function_code, " %s %s(", methodmods, proxy_class_name); Printf(helper_code, " static private %s SwigConstruct%s(", im_return_type, proxy_class_name); - Printv(imcall, imclass_name, ".", mangled_overname, "(", NIL); + Printv(imcall, full_imclass_name, ".", mangled_overname, "(", NIL); /* Attach the non-standard typemaps to the parameter list */ Swig_typemap_attach_parms("in", l, NULL); @@ -2368,7 +2449,7 @@ public: String *symname = Getattr(n, "sym:name"); if (proxy_flag) { - Printv(destructor_call, imclass_name, ".", Swig_name_destroy(symname), "(swigCPtr)", NIL); + Printv(destructor_call, full_imclass_name, ".", Swig_name_destroy(getNSpace(), symname), "(swigCPtr)", NIL); generateThrowsClause(n, destructor_throws_clause); } return SWIG_OK; @@ -2476,7 +2557,7 @@ public: if (proxy_flag && global_variable_flag) { // Capitalize the first letter in the variable to create a JavaBean type getter/setter function name func_name = NewString(""); - setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(variable_name)) == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), variable_name)) == 0); if (setter_flag) Printf(func_name, "set"); else @@ -2681,10 +2762,10 @@ public: // Strange hack to change the name Setattr(n, "name", Getattr(n, "value")); /* for wrapping of enums in a namespace when emit_action is used */ constantWrapper(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(symname)); + value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); } else { memberconstantHandler(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(Swig_name_member(proxy_class_name, symname))); + value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), Swig_name_member(getNSpace(), proxy_class_name, symname))); } } } @@ -2698,28 +2779,44 @@ public: * ----------------------------------------------------------------------------- */ String *getEnumName(SwigType *t, bool jnidescriptor) { - Node *enum_name = NULL; + Node *enumname = NULL; Node *n = enumLookup(t); if (n) { - String *symname = Getattr(n, "sym:name"); - if (symname) { - // Add in class scope when referencing enum if not a global enum - String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); - String *proxyname = 0; - if (scopename_prefix) { - proxyname = getProxyName(scopename_prefix); + enumname = Getattr(n, "enumname"); + if (!enumname || jnidescriptor) { + String *symname = Getattr(n, "sym:name"); + if (symname) { + // Add in class scope when referencing enum if not a global enum + String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); + String *proxyname = 0; + if (scopename_prefix) { + proxyname = getProxyName(scopename_prefix); + } + if (proxyname) { + const char *class_separator = jnidescriptor ? "$" : "."; + enumname = NewStringf("%s%s%s", proxyname, class_separator, symname); + } else { + // global enum or enum in a namespace + String *nspace = Getattr(n, "sym:nspace"); + if (nspace) { + if (Len(package) > 0) + enumname = NewStringf("%s.%s.%s", package, nspace, symname); + else + enumname = NewStringf("%s.%s", nspace, symname); + } else { + enumname = Copy(symname); + } + } + if (!jnidescriptor) { // not cached + Setattr(n, "enumname", enumname); + Delete(enumname); + } + Delete(scopename_prefix); } - if (proxyname) { - const char *class_separator = jnidescriptor ? "$" : "."; - enum_name = NewStringf("%s%s%s", proxyname, class_separator, symname); - } else { - enum_name = NewStringf("%s", symname); - } - Delete(scopename_prefix); } } - return enum_name; + return enumname; } /* ----------------------------------------------------------------------------- @@ -3004,10 +3101,10 @@ public: if (Cmp(jtype, "long") == 0) { if (proxy_flag) { if (!GetFlag(p, "tmap:jtype:nopgcpp") && !nopgcpp_flag) { - Node *n = classLookup(t); - if (n) { + String *proxyname = getProxyName(t); + if (proxyname) { // Found a struct/class parameter passed by value, reference, pointer, or pointer reference - proxyClassName = Getattr(n, "sym:name"); + proxyClassName = proxyname; } else { // Look for proxy class parameters passed to C++ layer using non-default typemaps, ie not one of above types String *jstype = NewString(Getattr(p, "tmap:jstype")); @@ -3045,6 +3142,30 @@ public: return proxyClassName; } + /* ----------------------------------------------------------------------------- + * outputDirectory() + * + * Return the directory to use for generating Java classes/enums and create the + * subdirectory (does not create if language specific outdir does not exist). + * ----------------------------------------------------------------------------- */ + + String *outputDirectory(String *nspace) { + String *output_directory = Copy(SWIG_output_directory()); + if (nspace) { + String *nspace_subdirectory = Copy(nspace); + Replaceall(nspace_subdirectory, ".", SWIG_FILE_DELIMITER); + String *newdir_error = Swig_new_subdirectory(output_directory, nspace_subdirectory); + if (newdir_error) { + Printf(stderr, "%s\n", newdir_error); + Delete(newdir_error); + SWIG_exit(EXIT_FAILURE); + } + Printv(output_directory, nspace_subdirectory, SWIG_FILE_DELIMITER, 0); + Delete(nspace_subdirectory); + } + return output_directory; + } + /*---------------------------------------------------------------------- * Start of director methods *--------------------------------------------------------------------*/ @@ -3155,13 +3276,13 @@ public: // Output the director connect method: String *jni_imclass_name = makeValidJniName(imclass_name); String *norm_name = SwigType_namestr(Getattr(n, "name")); - String *swig_director_connect = NewStringf("%s_director_connect", proxy_class_name); + String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); String *swig_director_connect_jni = makeValidJniName(swig_director_connect); String *sym_name = Getattr(n, "sym:name"); Wrapper *code_wrap; Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean mem_own, boolean weak_global);\n", - swig_director_connect, proxy_class_name); + swig_director_connect, full_proxy_class_name); code_wrap = NewWrapper(); Printf(code_wrap->def, @@ -3183,10 +3304,10 @@ public: Delete(swig_director_connect); // Output the swigReleaseOwnership, swigTakeOwnership methods: - String *changeown_method_name = NewStringf("%s_change_ownership", proxy_class_name); + String *changeown_method_name = Swig_name_member(getNSpace(), proxy_class_name, "change_ownership"); String *changeown_jnimethod_name = makeValidJniName(changeown_method_name); - Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean take_or_release);\n", changeown_method_name, proxy_class_name); + Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean take_or_release);\n", changeown_method_name, full_proxy_class_name); code_wrap = NewWrapper(); Printf(code_wrap->def, @@ -3342,7 +3463,7 @@ public: // we're consistent with the sym:overload name in functionWrapper. (?? when // does the overloaded method name get set?) - imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(classname, overloaded_name)); + imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name)); if (returntype) { diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index a22c06dd0..2ccefb619 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -60,6 +60,7 @@ extern "C" { static int InClass = 0; /* Parsing C++ or not */ static String *ClassName = 0; /* This is the real name of the current class */ static String *ClassPrefix = 0; /* Class prefix */ +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 */ int Abstract = 0; @@ -1198,7 +1199,7 @@ int Language::memberfunctionHandler(Node *n) { Setline(cbn, Getline(n)); memberconstantHandler(cbn); - Setattr(n, "feature:callback:name", Swig_name_member(ClassPrefix, cbname)); + Setattr(n, "feature:callback:name", Swig_name_member(NSpace, ClassPrefix, cbname)); Delete(cb); Delete(cbn); @@ -1211,7 +1212,7 @@ int Language::memberfunctionHandler(Node *n) { } } - String *fname = Swig_name_member(ClassPrefix, symname); + String *fname = Swig_name_member(NSpace, ClassPrefix, symname); if (Extend && SmartPointer) { if (!Getattr(n, "classname")) { Setattr(n, "classname", Getattr(CurrentClass, "allocate:smartpointerbase")); @@ -1236,7 +1237,7 @@ int Language::memberfunctionHandler(Node *n) { if (GetFlag(n, "explicitcall")) DirectorExtraCall = CWRAP_DIRECTOR_ONE_CALL; - Swig_MethodToFunction(n, ClassType, Getattr(n, "template") ? SmartPointer : Extend | SmartPointer | DirectorExtraCall, director_type, + Swig_MethodToFunction(n, NSpace, ClassType, Getattr(n, "template") ? SmartPointer : Extend | SmartPointer | DirectorExtraCall, director_type, is_member_director(CurrentClass, n)); Setattr(n, "sym:name", fname); @@ -1272,10 +1273,10 @@ int Language::staticmemberfunctionHandler(Node *n) { cname = NewStringf("%s::%s", sname, name); } else { String *mname = Swig_name_mangle(ClassName); - cname = Swig_name_member(mname, name); + cname = Swig_name_member(NSpace, mname, name); Delete(mname); } - mrename = Swig_name_member(ClassPrefix, symname); + mrename = Swig_name_member(NSpace, ClassPrefix, symname); if (Extend) { String *code = Getattr(n, "code"); @@ -1299,7 +1300,7 @@ int Language::staticmemberfunctionHandler(Node *n) { if (cb) { String *cbname = NewStringf(cb, symname); - Setattr(n, "feature:callback:name", Swig_name_member(ClassPrefix, cbname)); + Setattr(n, "feature:callback:name", Swig_name_member(NSpace, ClassPrefix, cbname)); Setattr(n, "feature:callback:staticname", name); } Delattr(n, "storage"); @@ -1380,9 +1381,9 @@ int Language::membervariableHandler(Node *n) { SwigType *type = Getattr(n, "type"); if (!AttributeFunctionGet) { - String *mname = Swig_name_member(ClassPrefix, symname); - String *mrename_get = Swig_name_get(mname); - String *mrename_set = Swig_name_set(mname); + String *mname = Swig_name_member(0, ClassPrefix, symname); + String *mrename_get = Swig_name_get(NSpace, mname); + String *mrename_set = Swig_name_set(NSpace, mname); Delete(mname); /* Create a function to set the value of the variable */ @@ -1493,7 +1494,7 @@ int Language::membervariableHandler(Node *n) { cpp_member_func(Char(gname), Char(gname), type, 0); Delete(ActionFunc); } else { - String *cname = Swig_name_get(name); + String *cname = Swig_name_get(NSpace, name); cpp_member_func(Char(cname), Char(gname), type, 0); Delete(cname); } @@ -1506,7 +1507,7 @@ int Language::membervariableHandler(Node *n) { cpp_member_func(Char(gname), Char(gname), vty, p); Delete(ActionFunc); } else { - String *cname = Swig_name_set(name); + String *cname = Swig_name_set(NSpace, name); cpp_member_func(Char(cname), Char(gname), vty, p); Delete(cname); } @@ -1534,7 +1535,7 @@ int Language::staticmembervariableHandler(Node *n) { String *cname, *mrename; /* Create the variable name */ - mrename = Swig_name_member(ClassPrefix, symname); + mrename = Swig_name_member(0, ClassPrefix, symname); cname = NewStringf("%s::%s", classname, name); Setattr(n, "sym:name", mrename); @@ -1676,7 +1677,7 @@ int Language::memberconstantHandler(Node *n) { String *symname = Getattr(n, "sym:name"); String *value = Getattr(n, "value"); - String *mrename = Swig_name_member(ClassPrefix, symname); + String *mrename = Swig_name_member(NSpace, ClassPrefix, symname); Setattr(n, "sym:name", mrename); String *new_name = 0; @@ -1908,7 +1909,7 @@ int Language::classDirectorDisown(Node *n) { Node *disown = NewHash(); String *mrename; String *symname = Getattr(n, "sym:name"); - mrename = Swig_name_disown(symname); //Getattr(n, "name")); + mrename = Swig_name_disown(NSpace, symname); String *type = NewString(ClassType); String *name = NewString("self"); SwigType_add_pointer(type); @@ -2315,6 +2316,7 @@ int Language::classDeclaration(Node *n) { String *name = Getattr(n, "name"); String *tdname = Getattr(n, "tdname"); String *symname = Getattr(n, "sym:name"); + String *symnspace = Getattr(n, "sym:nspace"); char *classname = tdname ? Char(tdname) : Char(name); char *iname = Char(symname); @@ -2343,6 +2345,7 @@ int Language::classDeclaration(Node *n) { ClassName = NewString(classname); ClassPrefix = NewString(iname); + NSpace = symnspace; if (strip) { ClassType = NewString(classname); } else { @@ -2403,6 +2406,7 @@ int Language::classDeclaration(Node *n) { Language::classHandler(n); } + NSpace = 0; InClass = 0; CurrentClass = 0; Delete(ClassType); @@ -2635,7 +2639,7 @@ static String *get_director_ctor_code(Node *n, String *director_ctor_code, Strin int Language::constructorHandler(Node *n) { Swig_require("constructorHandler", n, "?name", "*sym:name", "?type", "?parms", NIL); String *symname = Getattr(n, "sym:name"); - String *mrename = Swig_name_construct(symname); + String *mrename = Swig_name_construct(NSpace, symname); String *nodeType = Getattr(n, "nodeType"); int constructor = (!Cmp(nodeType, "constructor")); List *abstract = 0; @@ -2647,7 +2651,7 @@ int Language::constructorHandler(Node *n) { Setattr(n, "handled_as_constructor", "1"); } - Swig_ConstructorToFunction(n, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend); + Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend); Setattr(n, "sym:name", mrename); functionWrapper(n); Delete(mrename); @@ -2664,12 +2668,12 @@ int Language::constructorHandler(Node *n) { int Language::copyconstructorHandler(Node *n) { Swig_require("copyconstructorHandler", n, "?name", "*sym:name", "?type", "?parms", NIL); String *symname = Getattr(n, "sym:name"); - String *mrename = Swig_name_copyconstructor(symname); + String *mrename = Swig_name_copyconstructor(NSpace, symname); List *abstract = 0; String *director_ctor = get_director_ctor_code(n, director_ctor_code, director_prot_ctor_code, abstract); - Swig_ConstructorToFunction(n, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend); + Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend); Setattr(n, "sym:name", mrename); functionWrapper(n); Delete(mrename); @@ -2739,9 +2743,9 @@ int Language::destructorHandler(Node *n) { if (csymname && (*csymname == '~')) csymname += 1; - mrename = Swig_name_destroy(csymname); + mrename = Swig_name_destroy(NSpace, csymname); - Swig_DestructorToFunction(n, ClassType, CPlusPlus, Extend); + Swig_DestructorToFunction(n, NSpace, ClassType, CPlusPlus, Extend); Setattr(n, "sym:name", mrename); functionWrapper(n); Delete(mrename); @@ -2844,7 +2848,7 @@ int Language::variableWrapper(Node *n) { String *tm = Swig_typemap_lookup("globalin", n, name, 0); Swig_VarsetToFunction(n, flags); - String *sname = Swig_name_set(symname); + String *sname = Swig_name_set(NSpace, symname); Setattr(n, "sym:name", sname); Delete(sname); @@ -2879,7 +2883,7 @@ int Language::variableWrapper(Node *n) { } Swig_VargetToFunction(n, flags); - String *gname = Swig_name_get(symname); + String *gname = Swig_name_get(NSpace, symname); Setattr(n, "sym:name", gname); Delete(gname); functionWrapper(n); @@ -2922,11 +2926,11 @@ void Language::main(int argc, char *argv[]) { * Returns 1 if the symbol is added successfully. * Prints an error message and returns 0 if a conflict occurs. * The scope is optional for target languages and if supplied must be a fully - * resolved scope and the symbol s must not contain any scope qualifiers. + * qualified scope and the symbol s must not contain any scope qualifiers. * ----------------------------------------------------------------------------- */ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) { - Hash *symbols = Getattr(symtabs, scope); + Hash *symbols = Getattr(symtabs, scope ? scope : ""); if (!symbols) { // New scope which has not been added by the target language - lazily created. symbols = NewHash(); @@ -3306,7 +3310,7 @@ bool Language::extraDirectorProtectedCPPMethodsRequired() const { * Language::is_wrapping_class() * ----------------------------------------------------------------------------- */ -int Language::is_wrapping_class() { +int Language::is_wrapping_class() const { return InClass; } @@ -3318,6 +3322,14 @@ Node *Language::getCurrentClass() const { return CurrentClass; } +/* ----------------------------------------------------------------------------- + * Language::getNSpace() + * ----------------------------------------------------------------------------- */ + +String *Language::getNSpace() const { + return NSpace; +} + /* ----------------------------------------------------------------------------- * Language::getClassName() * ----------------------------------------------------------------------------- */ diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 4640d9ed7..d240d3d6f 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -758,7 +758,7 @@ public: current=NO_CPP; // normally SWIG will generate 2 wrappers, a get and a set // but in certain scenarios (immutable, or if its arrays), it will not - String *getName = Swig_name_wrapper(Swig_name_get(iname)); + String *getName = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, iname)); String *setName = 0; // checking whether it can be set to or not appears to be a very error prone issue // I refered to the Language::variableWrapper() to find this out @@ -770,7 +770,7 @@ public: Delete(tm); if (assignable) { - setName = Swig_name_wrapper(Swig_name_set(iname)); + setName = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, iname)); } else { // how about calling a 'this is not settable' error message? setName = NewString("SWIG_Lua_set_immutable"); // error message @@ -790,7 +790,6 @@ public: // REPORT("constantWrapper", n); String *name = Getattr(n, "name"); String *iname = Getattr(n, "sym:name"); - //String *nsname = !nspace ? Copy(iname) : NewStringf("%s::%s",ns_name,iname); String *nsname = Copy(iname); SwigType *type = Getattr(n, "type"); String *rawval = Getattr(n, "rawval"); @@ -799,7 +798,6 @@ public: if (!addSymbol(iname, n)) return SWIG_ERROR; - //if (nspace) Setattr(n,"sym:name",nsname); /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { @@ -997,7 +995,7 @@ public: Printv(f_wrappers, "static swig_lua_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); if (have_constructor) { - Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(constructor_name))); + Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name))); Delete(constructor_name); constructor_name = 0; } else { @@ -1043,7 +1041,7 @@ public: current = NO_CPP; realname = iname ? iname : name; - rname = Swig_name_wrapper(Swig_name_member(class_name, realname)); + rname = Swig_name_wrapper(Swig_name_member(NSPACE_TODO, class_name, realname)); if (!Getattr(n, "sym:nextSibling")) { Printv(s_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); } @@ -1063,9 +1061,9 @@ public: current = MEMBER_VAR; Language::membervariableHandler(n); current = NO_CPP; - gname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name, symname))); + gname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); if (!GetFlag(n, "feature:immutable")) { - sname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name, symname))); + sname = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); } else { //sname = NewString("0"); sname = NewString("SWIG_Lua_set_immutable"); // error message diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index d1e10b974..252e92a7d 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -2620,7 +2620,7 @@ MODULA3(): if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(NSPACE_TODO, proxy_class_name, overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -2641,7 +2641,7 @@ MODULA3(): if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(NSPACE_TODO, proxy_class_name, overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -2699,7 +2699,7 @@ MODULA3(): if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Properties - setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, proxy_class_name, variable_name))) == 0); } @@ -2844,7 +2844,7 @@ MODULA3(): String *imcall = NewString(""); Printf(proxy_class_code, " %s %s(", Getattr(n, "feature:modula3:methodmodifiers"), proxy_class_name); - Printv(imcall, " : this(", m3raw_name, ".", Swig_name_construct(overloaded_name), "(", NIL); + Printv(imcall, " : this(", m3raw_name, ".", Swig_name_construct(NSPACE_TODO, overloaded_name), "(", NIL); /* Attach the non-standard typemaps to the parameter list */ Swig_typemap_attach_parms("in", l, NULL); @@ -2935,7 +2935,7 @@ MODULA3(): String *symname = Getattr(n, "sym:name"); if (proxy_flag) { - Printv(destructor_call, m3raw_name, ".", Swig_name_destroy(symname), "(swigCPtr)", NIL); + Printv(destructor_call, m3raw_name, ".", Swig_name_destroy(NSPACE_TODO, symname), "(swigCPtr)", NIL); } return SWIG_OK; } diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index ab001a48b..16adddcce 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -701,8 +701,8 @@ public: Wrapper *getf = NewWrapper(); Wrapper *setf = NewWrapper(); - String *getname = Swig_name_get(iname); - String *setname = Swig_name_set(iname); + String *getname = Swig_name_get(NSPACE_TODO, iname); + String *setname = Swig_name_set(NSPACE_TODO, iname); Printf(setf->def, "static octave_value_list _wrap_%s(const octave_value_list& args,int nargout) {", setname); Printf(setf->def, "if (!SWIG_check_num_args(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname); @@ -882,7 +882,7 @@ public: Printv(f_wrappers, "static swig_octave_class _wrap_class_", class_name, " = {\"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); Printv(f_wrappers, Swig_directorclass(n) ? "1," : "0,", NIL); if (have_constructor) { - String *cname = Swig_name_construct(constructor_name); + String *cname = Swig_name_construct(NSPACE_TODO, constructor_name); String *wcname = Swig_name_wrapper(cname); String *tname = texinfo_name(n); Printf(f_wrappers, "%s,%s,", wcname, tname); @@ -915,7 +915,7 @@ public: String *name = Getattr(n, "name"); String *iname = GetChar(n, "sym:name"); String *realname = iname ? iname : name; - String *rname = Swig_name_wrapper(Swig_name_member(class_name, realname)); + String *rname = Swig_name_wrapper(Swig_name_member(NSPACE_TODO, class_name, realname)); if (!Getattr(n, "sym:nextSibling")) { String *tname = texinfo_name(n); @@ -936,9 +936,9 @@ public: assert(s_members_tab); assert(class_name); String *symname = Getattr(n, "sym:name"); - String *getname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name, symname))); + String *getname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); String *setname = GetFlag(n, "feature:immutable") ? - NewString("octave_set_immutable") : Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name, symname))); + NewString("octave_set_immutable") : Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); assert(s_members_tab); Printf(s_members_tab, "{\"%s\",0,%s,%s,0,0},\n", symname, getname, setname); @@ -988,7 +988,7 @@ public: String *name = Getattr(n, "name"); String *iname = GetChar(n, "sym:name"); String *realname = iname ? iname : name; - String *rname = Swig_name_wrapper(Swig_name_member(class_name, realname)); + String *rname = Swig_name_wrapper(Swig_name_member(NSPACE_TODO, class_name, realname)); if (!Getattr(n, "sym:nextSibling")) { String *tname = texinfo_name(n); @@ -1014,9 +1014,9 @@ public: assert(s_members_tab); assert(class_name); String *symname = Getattr(n, "sym:name"); - String *getname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name, symname))); + String *getname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); String *setname = GetFlag(n, "feature:immutable") ? - NewString("octave_set_immutable") : Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name, symname))); + NewString("octave_set_immutable") : Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); assert(s_members_tab); Printf(s_members_tab, "{\"%s\",0,%s,%s,1,0},\n", symname, getname, setname); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 4c7dba1eb..4be759194 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -840,8 +840,8 @@ public: SwigType *t = Getattr(n, "type"); Wrapper *getf, *setf; String *tm; - String *getname = Swig_name_get(iname); - String *setname = Swig_name_set(iname); + String *getname = Swig_name_get(NSPACE_TODO, iname); + String *setname = Swig_name_set(NSPACE_TODO, iname); String *get_name = Swig_name_wrapper(getname); String *set_name = Swig_name_wrapper(setname); @@ -1432,12 +1432,12 @@ public: if (Getattr(n, "feature:shadow")) { String *plcode = perlcode(Getattr(n, "feature:shadow"), 0); - String *plaction = NewStringf("%s::%s", cmodule, Swig_name_member(class_name, symname)); + String *plaction = NewStringf("%s::%s", cmodule, Swig_name_member(NSPACE_TODO, class_name, symname)); Replaceall(plcode, "$action", plaction); Delete(plaction); Printv(pcode, plcode, NIL); } else { - Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name, symname), ";\n", NIL); + Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(NSPACE_TODO, class_name, symname), ";\n", NIL); } } return SWIG_OK; @@ -1462,8 +1462,8 @@ public: if (blessed) { - Printv(pcode, "*swig_", symname, "_get = *", cmodule, "::", Swig_name_get(Swig_name_member(class_name, symname)), ";\n", NIL); - Printv(pcode, "*swig_", symname, "_set = *", cmodule, "::", Swig_name_set(Swig_name_member(class_name, symname)), ";\n", NIL); + Printv(pcode, "*swig_", symname, "_get = *", cmodule, "::", Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)), ";\n", NIL); + Printv(pcode, "*swig_", symname, "_set = *", cmodule, "::", Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname)), ";\n", NIL); /* Now we need to generate a little Perl code for this */ @@ -1501,7 +1501,7 @@ public: if ((blessed) && (!Getattr(n, "sym:nextSibling"))) { if (Getattr(n, "feature:shadow")) { String *plcode = perlcode(Getattr(n, "feature:shadow"), 0); - String *plaction = NewStringf("%s::%s", module, Swig_name_member(class_name, symname)); + String *plaction = NewStringf("%s::%s", module, Swig_name_member(NSPACE_TODO, class_name, symname)); Replaceall(plcode, "$action", plaction); Delete(plaction); Printv(pcode, plcode, NIL); @@ -1511,12 +1511,12 @@ public: Printf(pcode, "sub new {\n"); } else { /* Constructor doesn't match classname so we'll just use the normal name */ - Printv(pcode, "sub ", Swig_name_construct(symname), " {\n", NIL); + Printv(pcode, "sub ", Swig_name_construct(NSPACE_TODO, symname), " {\n", NIL); } Printv(pcode, tab4, "my $pkg = shift;\n", - tab4, "my $self = ", cmodule, "::", Swig_name_construct(symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL); + tab4, "my $self = ", cmodule, "::", Swig_name_construct(NSPACE_TODO, symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL); have_constructor = 1; } @@ -1536,7 +1536,7 @@ public: if (blessed) { if (Getattr(n, "feature:shadow")) { String *plcode = perlcode(Getattr(n, "feature:shadow"), 0); - String *plaction = NewStringf("%s::%s", module, Swig_name_member(class_name, symname)); + String *plaction = NewStringf("%s::%s", module, Swig_name_member(NSPACE_TODO, class_name, symname)); Replaceall(plcode, "$action", plaction); Delete(plaction); Printv(pcode, plcode, NIL); @@ -1548,7 +1548,7 @@ public: tab4, "return unless defined $self;\n", tab4, "delete $ITERATORS{$self};\n", tab4, "if (exists $OWNER{$self}) {\n", - tab8, cmodule, "::", Swig_name_destroy(symname), "($self);\n", tab8, "delete $OWNER{$self};\n", tab4, "}\n}\n\n", NIL); + tab8, cmodule, "::", Swig_name_destroy(NSPACE_TODO, symname), "($self);\n", tab8, "delete $OWNER{$self};\n", tab4, "}\n}\n\n", NIL); have_destructor = 1; } } @@ -1566,7 +1566,7 @@ public: member_func = 0; if ((blessed) && (!Getattr(n, "sym:nextSibling"))) { String *symname = Getattr(n, "sym:name"); - Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name, symname), ";\n", NIL); + Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(NSPACE_TODO, class_name, symname), ";\n", NIL); } return SWIG_OK; } @@ -1579,7 +1579,7 @@ public: Language::staticmembervariableHandler(n); if (blessed) { String *symname = Getattr(n, "sym:name"); - Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name, symname), ";\n", NIL); + Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(NSPACE_TODO, class_name, symname), ";\n", NIL); } return SWIG_OK; } @@ -1598,7 +1598,7 @@ public: blessed = oldblessed; if (blessed) { - Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name, symname), ";\n", NIL); + Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(NSPACE_TODO, class_name, symname), ";\n", NIL); } return SWIG_OK; } diff --git a/Source/Modules/pike.cxx b/Source/Modules/pike.cxx index 6913596d3..51758ae46 100644 --- a/Source/Modules/pike.cxx +++ b/Source/Modules/pike.cxx @@ -766,7 +766,7 @@ public: /* Create a function to set the values of the (mutable) variables */ if (need_setter) { Wrapper *wrapper = NewWrapper(); - String *setter = Swig_name_member(getClassPrefix(), "`->="); + String *setter = Swig_name_member(NSPACE_TODO, getClassPrefix(), "`->="); String *wname = Swig_name_wrapper(setter); Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL); Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n"); @@ -775,7 +775,7 @@ public: while (i.item) { if (!GetFlag(i.item, "feature:immutable")) { name = Getattr(i.item, "name"); - funcname = Swig_name_wrapper(Swig_name_set(Swig_name_member(getClassPrefix(), name))); + funcname = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, getClassPrefix(), name))); Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name); Printf(wrapper->code, "%s(args);\n", funcname); Printf(wrapper->code, "return;\n"); @@ -805,7 +805,7 @@ public: /* Create a function to get the values of the (mutable) variables */ Wrapper *wrapper = NewWrapper(); - String *getter = Swig_name_member(getClassPrefix(), "`->"); + String *getter = Swig_name_member(NSPACE_TODO, getClassPrefix(), "`->"); String *wname = Swig_name_wrapper(getter); Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL); Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n"); @@ -813,7 +813,7 @@ public: i = First(membervariables); while (i.item) { name = Getattr(i.item, "name"); - funcname = Swig_name_wrapper(Swig_name_get(Swig_name_member(getClassPrefix(), name))); + funcname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, getClassPrefix(), name))); Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name); Printf(wrapper->code, "%s(args);\n", funcname); Printf(wrapper->code, "return;\n"); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index bafd567e0..3215d29aa 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1866,7 +1866,7 @@ public: && ((shadow & PYSHADOW_MEMBER))) { String *nname = Getattr(n, "sym:name"); String *sname = Getattr(getCurrentClass(), "sym:name"); - String *cname = Swig_name_construct(sname); + String *cname = Swig_name_construct(NSPACE_TODO, sname); handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); Delete(cname); } @@ -2437,8 +2437,8 @@ public: } } - String *getname = Swig_name_get(iname); - String *setname = Swig_name_set(iname); + String *getname = Swig_name_get(NSPACE_TODO, iname); + String *setname = Swig_name_set(NSPACE_TODO, iname); String *vargetname = NewStringf("Swig_var_%s", getname); String *varsetname = NewStringf("Swig_var_%s", setname); @@ -2771,7 +2771,7 @@ public: shadow = oldshadow; if (shadow) { String *symname = Getattr(n, "sym:name"); - String *mrename = Swig_name_disown(symname); //Getattr(n, "name")); + String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name")); Printv(f_shadow, tab4, "def __disown__(self):\n", NIL); #ifdef USE_THISOWN Printv(f_shadow, tab8, "self.thisown = 0\n", NIL); @@ -3029,7 +3029,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(class_name, symname), class_name); + 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); } } Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); @@ -3093,7 +3093,7 @@ public: } if (Getattr(n, "feature:shadow")) { String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_member(class_name, symname)); + String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname)); Replaceall(pycode, "$action", pyaction); Delete(pyaction); Printv(f_shadow, pycode, "\n", NIL); @@ -3105,7 +3105,7 @@ public: if (!have_addtofunc(n)) { if (!fastproxy || olddefs) { Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); - Printv(f_shadow, " return ", funcCall(Swig_name_member(class_name, symname), callParms), "\n", NIL); + Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); } } else { Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL); @@ -3118,11 +3118,11 @@ public: } if (have_pythonappend(n)) { fproxy = 0; - Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(class_name, symname), callParms), "\n", NIL); + Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); Printv(f_shadow, tab8, "return val\n\n", NIL); } else { - Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(class_name, symname), callParms), "\n\n", NIL); + Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); } } } @@ -3163,11 +3163,11 @@ public: if (have_pythonprepend(n)) Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); if (have_pythonappend(n)) { - Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(class_name, symname), callParms), "\n", NIL); + Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); Printv(f_shadow, tab8, "return val\n\n", NIL); } else { - Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(class_name, symname), callParms), "\n\n", NIL); + 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); @@ -3177,10 +3177,10 @@ public: } else { if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(class_name, symname), "\n", NIL); + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); } if (!classic) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(class_name, symname), ")\n", NIL); + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); } } } @@ -3235,7 +3235,7 @@ public: if (!have_constructor) { String *nname = Getattr(n, "sym:name"); String *sname = Getattr(getCurrentClass(), "sym:name"); - String *cname = Swig_name_construct(sname); + String *cname = Swig_name_construct(NSPACE_TODO, sname); handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); Delete(cname); } @@ -3243,7 +3243,7 @@ public: if (!have_constructor && handled_as_init) { if (Getattr(n, "feature:shadow")) { String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(symname)); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); Replaceall(pycode, "$action", pyaction); Delete(pyaction); Printv(f_shadow, pycode, "\n", NIL); @@ -3274,10 +3274,10 @@ public: Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); Printv(f_shadow, pass_self, NIL); if (fastinit) { - Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(symname), callParms), ")\n", NIL); + Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); } else { Printv(f_shadow, - tab8, "this = ", funcCall(Swig_name_construct(symname), callParms), "\n", + 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); } if (have_pythonappend(n)) @@ -3291,7 +3291,7 @@ public: if (Getattr(n, "feature:shadow")) { String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(symname)); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); Replaceall(pycode, "$action", pyaction); Delete(pyaction); Printv(f_shadow_stubs, pycode, "\n", NIL); @@ -3305,7 +3305,7 @@ public: Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); if (have_pythonprepend(n)) Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); - Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(symname), callParms), "\n", NIL); + Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL); #ifdef USE_THISOWN Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); #endif @@ -3335,13 +3335,13 @@ public: if (shadow) { if (Getattr(n, "feature:shadow")) { String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(symname)); + String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname)); Replaceall(pycode, "$action", pyaction); Delete(pyaction); Printv(f_shadow, pycode, "\n", NIL); Delete(pycode); } else { - Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(symname), "\n", NIL); + 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); @@ -3355,7 +3355,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(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 @@ -3382,9 +3382,9 @@ public: shadow = oldshadow; if (shadow) { - String *mname = Swig_name_member(class_name, symname); - String *setname = Swig_name_set(mname); - String *getname = Swig_name_get(mname); + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); + String *setname = Swig_name_set(NSPACE_TODO, mname); + String *getname = Swig_name_get(NSPACE_TODO, mname); if (shadow) { int assignable = is_assignable(n); if (!modern) { @@ -3419,15 +3419,15 @@ public: if (shadow && !GetFlag(n, "wrappedasconstant")) { String *symname = Getattr(n, "sym:name"); if (GetFlag(n, "hasconsttype")) { - String *mname = Swig_name_member(class_name, symname); + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname); Delete(mname); } else { - String *mname = Swig_name_member(class_name, symname); - String *getname = Swig_name_get(mname); + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); + String *getname = Swig_name_get(NSPACE_TODO, mname); String *wrapgetname = Swig_name_wrapper(getname); String *vargetname = NewStringf("Swig_var_%s", getname); - String *setname = Swig_name_set(mname); + String *setname = Swig_name_set(NSPACE_TODO, mname); String *wrapsetname = Swig_name_wrapper(setname); String *varsetname = NewStringf("Swig_var_%s", setname); @@ -3490,7 +3490,7 @@ public: shadow = oldshadow; if (shadow) { - Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(class_name, symname), "\n", NIL); + Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); } return SWIG_OK; } diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 82808b154..043df02f2 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -2115,7 +2115,7 @@ public: /* create getter */ int addfail = 0; - String *getname = Swig_name_get(iname); + String *getname = Swig_name_get(NSPACE_TODO, iname); getfname = Swig_name_wrapper(getname); Setattr(n, "wrap:name", getfname); Printv(getf->def, "SWIGINTERN VALUE\n", getfname, "(", NIL); @@ -2150,7 +2150,7 @@ public: Printf(f_wrappers, "%s", docs); Delete(docs); - String *setname = Swig_name_set(iname); + String *setname = Swig_name_set(NSPACE_TODO, iname); setfname = Swig_name_wrapper(setname); Setattr(n, "wrap:name", setfname); Printv(setf->def, "SWIGINTERN VALUE\n", setfname, "(VALUE self, ", NIL); diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index a6b5234d4..016ccc8d4 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -265,7 +265,7 @@ protected: void allow_overloading(int val = 1); /* Wrapping class query */ - int is_wrapping_class(); + int is_wrapping_class() const; /* Return the node for the current class */ Node *getCurrentClass() const; @@ -273,6 +273,9 @@ protected: /* Return C++ mode */ int getCPlusMode() const; + /* Return the namespace for the class/enum - the nspace feature */ + String *getNSpace() const; + /* Return the real name of the current class */ String *getClassName() const; diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 94191abcc..b6b4c6965 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -573,7 +573,7 @@ public: /* Create a function for getting a variable */ int addfail = 0; getf = NewWrapper(); - String *getname = Swig_name_get(iname); + String *getname = Swig_name_get(NSPACE_TODO, iname); String *getfname = Swig_name_wrapper(getname); Setattr(n, "wrap:name", getfname); Printv(getf->def, "SWIGINTERN const char *", getfname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2, int flags) {", NIL); @@ -605,7 +605,7 @@ public: /* Try to create a function setting a variable */ if (is_assignable(n)) { setf = NewWrapper(); - setname = Swig_name_set(iname); + setname = Swig_name_set(NSPACE_TODO, iname); setfname = Swig_name_wrapper(setname); Setattr(n, "wrap:name", setfname); if (setf) { @@ -951,7 +951,7 @@ public: Printv(f_wrappers, "static swig_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); if (have_constructor) { - Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(constructor_name))); + Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(NSPACE_TODO, constructor_name))); Delete(constructor_name); constructor_name = 0; } else { @@ -989,7 +989,7 @@ public: Language::memberfunctionHandler(n); realname = iname ? iname : name; - rname = Swig_name_wrapper(Swig_name_member(class_name, realname)); + rname = Swig_name_wrapper(Swig_name_member(NSPACE_TODO, class_name, realname)); if (!Getattr(n, "sym:nextSibling")) { Printv(methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); } @@ -1082,11 +1082,11 @@ public: Language::membervariableHandler(n); Printv(attr_tab, tab4, "{ \"-", symname, "\",", NIL); - rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name, symname))); + rname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); Printv(attr_tab, rname, ", ", NIL); Delete(rname); if (!GetFlag(n, "feature:immutable")) { - rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name, symname))); + rname = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname))); Printv(attr_tab, rname, "},\n", NIL); Delete(rname); } else { diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 8d4ddda11..a975e350c 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -36,6 +36,7 @@ class TypePass:private Dispatcher { Node *module; int importmode; String *nsname; + String *nssymname; Hash *classhash; List *normalize; @@ -296,6 +297,7 @@ class TypePass:private Dispatcher { inclass = 0; normalize = 0; nsname = 0; + nssymname = 0; classhash = Getattr(n, "classes"); emit_children(n); normalize_list(); @@ -415,6 +417,10 @@ class TypePass:private Dispatcher { Setattr(n, "tdname", tdname); } } + if (nssymname) { + if (GetFlag(n, "feature:nspace")) + Setattr(n, "sym:nspace", nssymname); + } SwigType_new_scope(scopename); SwigType_attach_symtab(Getattr(n, "symtab")); @@ -535,7 +541,9 @@ class TypePass:private Dispatcher { } } String *oldnsname = nsname; + String *oldnssymname = nssymname; nsname = Swig_symbol_qualified(Getattr(n, "symtab")); + nssymname = Swig_symbol_qualified_language_scopename(Getattr(n, "symtab")); symtab = Swig_symbol_setscope(Getattr(n, "symtab")); emit_children(n); Swig_symbol_setscope(symtab); @@ -557,6 +565,8 @@ class TypePass:private Dispatcher { } normalize = olist; + Delete(nssymname); + nssymname = oldnssymname; Delete(nsname); nsname = oldnsname; return SWIG_OK; @@ -734,6 +744,11 @@ class TypePass:private Dispatcher { } Setattr(n, "enumtype", enumtype); + if (nssymname) { + if (GetFlag(n, "feature:nspace")) + Setattr(n, "sym:nspace", nssymname); + } + // This block of code is for dealing with %ignore on an enum item where the target language // attempts to use the C enum value in the target language itself and expects the previous enum value // to be one more than the previous value... the previous enum item might not exist if it is ignored! diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 4fe7236c5..539ae6e18 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -782,7 +782,7 @@ int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parm * Converts a C++ method node to a function accessor function. * ----------------------------------------------------------------------------- */ -int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director) { +int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int flags, SwigType *director_type, int is_director) { String *name, *qualifier; ParmList *parms; SwigType *type; @@ -896,7 +896,7 @@ int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *direc String *defaultargs = Getattr(n, "defaultargs"); String *code = Getattr(n, "code"); String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname; - String *membername = Swig_name_member(cname, name); + String *membername = Swig_name_member(nspace, cname, name); String *mangled = Swig_name_mangle(membername); int is_smart_pointer = flags & CWRAP_SMART_POINTER; @@ -1009,7 +1009,7 @@ Node *Swig_directormap(Node *module, String *type) { * This function creates a C wrapper for a C constructor function. * ----------------------------------------------------------------------------- */ -int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) { +int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) { ParmList *parms; Parm *prefix_args; Parm *p; @@ -1049,7 +1049,7 @@ int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparis String *cres; String *defaultargs = Getattr(n, "defaultargs"); String *code = Getattr(n, "code"); - String *membername = Swig_name_construct(classname); + String *membername = Swig_name_construct(nspace, classname); String *mangled = Swig_name_mangle(membername); /* Check if the constructor is overloaded. If so, and it has code attached, we append an extra suffix @@ -1153,7 +1153,7 @@ int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparis * This function creates a C wrapper for a destructor function. * ----------------------------------------------------------------------------- */ -int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) { +int Swig_DestructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int cplus, int flags) { SwigType *type; Parm *p; @@ -1170,7 +1170,7 @@ int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) String *cres; String *call; String *membername, *mangled, *code; - membername = Swig_name_destroy(classname); + membername = Swig_name_destroy(nspace, classname); mangled = Swig_name_mangle(membername); code = Getattr(n, "code"); if (code) { @@ -1219,10 +1219,7 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags) { SwigType *ty; SwigType *type; SwigType *void_type = NewString("void"); - String *membername; - String *mangled; String *self = 0; - String *sname; int varcref = flags & CWRAP_NATURAL_VAR; @@ -1236,10 +1233,6 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags) { name = Getattr(n, "name"); type = Getattr(n, "type"); - sname = Swig_name_set(name); - membername = Swig_name_member(classname, sname); - mangled = Swig_name_mangle(membername); - t = NewString(classname); SwigType_add_pointer(t); parms = NewParm(t, "self", n); @@ -1262,6 +1255,11 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags) { String *call; String *cres; String *code = Getattr(n, "code"); + + String *sname = Swig_name_set(0, name); + String *membername = Swig_name_member(0, classname, sname); + String *mangled = Swig_name_mangle(membername); + if (code) { /* I don't think this ever gets run - WSF */ Swig_add_extension_code(n, mangled, parms, void_type, code, cparse_cplusplus, "self"); @@ -1269,8 +1267,12 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags) { call = Swig_cfunction_call(mangled, parms); cres = NewStringf("%s;", call); Setattr(n, "wrap:action", cres); - Delete(call); + Delete(cres); + Delete(call); + Delete(mangled); + Delete(membername); + Delete(sname); } else { String *call = Swig_cmemberset_call(name, type, self, varcref); String *cres = NewStringf("%s;", call); @@ -1283,9 +1285,6 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags) { Delete(parms); Delete(ty); Delete(void_type); - Delete(membername); - Delete(sname); - Delete(mangled); Delete(self); return SWIG_OK; } @@ -1302,10 +1301,7 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) { SwigType *t; SwigType *ty; SwigType *type; - String *membername; - String *mangled; String *self = 0; - String *gname; int varcref = flags & CWRAP_NATURAL_VAR; @@ -1325,10 +1321,6 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) { name = Getattr(n, "name"); type = Getattr(n, "type"); - gname = Swig_name_get(name); - membername = Swig_name_member(classname, gname); - mangled = Swig_name_mangle(membername); - t = NewString(classname); SwigType_add_pointer(t); parms = NewParm(t, "self", n); @@ -1340,8 +1332,12 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) { if (flags & CWRAP_EXTEND) { String *call; String *cres; - String *code = Getattr(n, "code"); + + String *gname = Swig_name_get(0, name); + String *membername = Swig_name_member(0, classname, gname); + String *mangled = Swig_name_mangle(membername); + if (code) { /* I don't think this ever gets run - WSF */ Swig_add_extension_code(n, mangled, parms, ty, code, cparse_cplusplus, "self"); @@ -1349,8 +1345,12 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) { call = Swig_cfunction_call(mangled, parms); cres = Swig_cresult(ty, "result", call); Setattr(n, "wrap:action", cres); + Delete(cres); Delete(call); + Delete(mangled); + Delete(membername); + Delete(gname); } else { String *call = Swig_cmemberget_call(name, type, self, varcref); String *cres = Swig_cresult(ty, "result", call); @@ -1362,9 +1362,6 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) { Setattr(n, "parms", parms); Delete(parms); Delete(ty); - Delete(membername); - Delete(gname); - Delete(mangled); return SWIG_OK; } @@ -1390,7 +1387,7 @@ int Swig_VarsetToFunction(Node *n, int flags) { parms = NewParm(ty, name, n); if (flags & CWRAP_EXTEND) { - String *sname = Swig_name_set(name); + String *sname = Swig_name_set(0, name); String *mangled = Swig_name_mangle(sname); String *call = Swig_cfunction_call(mangled, parms); String *cres = NewStringf("%s;", call); @@ -1444,7 +1441,7 @@ int Swig_VargetToFunction(Node *n, int flags) { ty = Swig_wrapped_var_type(type, varcref); if (flags & CWRAP_EXTEND) { - String *sname = Swig_name_get(name); + String *sname = Swig_name_get(0, name); String *mangled = Swig_name_mangle(sname); call = Swig_cfunction_call(mangled, 0); cres = Swig_cresult(ty, "result", call); diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 19050fd51..7085f3b4a 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -17,6 +17,9 @@ char cvsroot_misc_c[] = "$Id$"; #include #include #include +#include +#include + static char *fake_version = 0; @@ -135,6 +138,54 @@ String *Swig_strip_c_comments(const String *s) { return stripped; } +/* ----------------------------------------------------------------------------- + * Swig_new_subdirectory() + * + * Create the subdirectory only if the basedirectory already exists as a directory. + * basedirectory can be NULL or empty to indicate current directory. + * ----------------------------------------------------------------------------- */ + +String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) { + String *error = 0; + struct stat st; + int current_directory = basedirectory ? (Len(basedirectory) == 0 ? 1 : 0) : 0; + + if (current_directory || ((stat(Char(basedirectory), &st) == 0) && S_ISDIR(st.st_mode))) { + Iterator it; + String *dir = basedirectory ? NewString(basedirectory) : NewString(""); + List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX); + + for (it = First(subdirs); it.item; it = Next(it)) { + int statdir; + String *subdirectory = it.item; + Printf(dir, "%s", subdirectory); + statdir = stat(Char(dir), &st); + if (statdir == 0) { + Printf(dir, SWIG_FILE_DELIMITER); + if (S_ISDIR(st.st_mode)) { + continue; + } else { + error = NewStringf("Cannot create directory %s", dir); + break; + } + } else { +#ifdef _WIN32 + int result = mkdir(Char(dir)); +#else + int result = mkdir(Char(dir), 0777); +#endif + Printf(dir, SWIG_FILE_DELIMITER); + if (result != 0 && errno != EEXIST) { + error = NewStringf("Cannot create directory %s", dir); + break; + } + } + } + } else { + error = NewStringf("Cannot create subdirectory %s under the base directory %s", subdirectory, basedirectory); + } + return error; +} /* ----------------------------------------------------------------------------- * Swig_filename_correct() diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 08c4f6b5d..07e42f2d4 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -9,6 +9,15 @@ * naming.c * * Functions for generating various kinds of names during code generation. + * + * Swig_name_register is used to register a format string for generating names. + * The format string makes use of the following format specifiers: + * + * %c - class name is substituted + * %f - function name is substituted + * %m - member name is substituted + * %n - namespace is substituted + * %v - variable name is substituted * ----------------------------------------------------------------------------- */ char cvsroot_naming_c[] = "$Id$"; @@ -125,6 +134,23 @@ static int name_mangle(String *r) { return special; } +/* ----------------------------------------------------------------------------- + * replace_nspace() + * + * Mangles in the namespace from nspace by replacing %n in name if nspace feature required. + * ----------------------------------------------------------------------------- */ + +static void replace_nspace(String *name, const_String_or_char_ptr nspace) { + if (nspace) { + String *namspace = NewStringf("%s_", nspace); + Replaceall(namspace, NSPACE_SEPARATOR, "_"); + Replace(name, "%n", namspace, DOH_REPLACE_ANY); + Delete(namspace); + } else { + Replace(name, "%n", "", DOH_REPLACE_ANY); + } +} + /* ----------------------------------------------------------------------------- * Swig_name_mangle() * @@ -172,7 +198,7 @@ String *Swig_name_wrapper(const_String_or_char_ptr fname) { * Returns the name of a class method. * ----------------------------------------------------------------------------- */ -String *Swig_name_member(const_String_or_char_ptr classname, const_String_or_char_ptr mname) { +String *Swig_name_member(const_String_or_char_ptr nspace, const_String_or_char_ptr classname, const_String_or_char_ptr membername) { String *r; String *f; String *rclassname; @@ -184,7 +210,7 @@ String *Swig_name_member(const_String_or_char_ptr classname, const_String_or_cha naming_hash = NewHash(); f = Getattr(naming_hash, "member"); if (!f) { - Append(r, "%c_%m"); + Append(r, "%n%c_%m"); } else { Append(r, f); } @@ -192,8 +218,9 @@ String *Swig_name_member(const_String_or_char_ptr classname, const_String_or_cha if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { cname = strchr(cname, ' ') + 1; } + replace_nspace(r, nspace); Replace(r, "%c", cname, DOH_REPLACE_ANY); - Replace(r, "%m", mname, DOH_REPLACE_ANY); + Replace(r, "%m", membername, DOH_REPLACE_ANY); /* name_mangle(r); */ Delete(rclassname); return r; @@ -205,7 +232,7 @@ String *Swig_name_member(const_String_or_char_ptr classname, const_String_or_cha * Returns the name of the accessor function used to get a variable. * ----------------------------------------------------------------------------- */ -String *Swig_name_get(const_String_or_char_ptr vname) { +String *Swig_name_get(const_String_or_char_ptr nspace, const_String_or_char_ptr vname) { String *r; String *f; @@ -218,10 +245,12 @@ String *Swig_name_get(const_String_or_char_ptr vname) { naming_hash = NewHash(); f = Getattr(naming_hash, "get"); if (!f) { - Append(r, "%v_get"); + Append(r, "%n%v_get"); } else { Append(r, f); } + + replace_nspace(r, nspace); Replace(r, "%v", vname, DOH_REPLACE_ANY); /* name_mangle(r); */ return r; @@ -233,7 +262,7 @@ String *Swig_name_get(const_String_or_char_ptr vname) { * Returns the name of the accessor function used to set a variable. * ----------------------------------------------------------------------------- */ -String *Swig_name_set(const_String_or_char_ptr vname) { +String *Swig_name_set(const_String_or_char_ptr nspace, const_String_or_char_ptr vname) { String *r; String *f; @@ -242,10 +271,12 @@ String *Swig_name_set(const_String_or_char_ptr vname) { naming_hash = NewHash(); f = Getattr(naming_hash, "set"); if (!f) { - Append(r, "%v_set"); + Append(r, "%n%v_set"); } else { Append(r, f); } + + replace_nspace(r, nspace); Replace(r, "%v", vname, DOH_REPLACE_ANY); /* name_mangle(r); */ return r; @@ -257,7 +288,7 @@ String *Swig_name_set(const_String_or_char_ptr vname) { * Returns the name of the accessor function used to create an object. * ----------------------------------------------------------------------------- */ -String *Swig_name_construct(const_String_or_char_ptr classname) { +String *Swig_name_construct(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) { String *r; String *f; String *rclassname; @@ -269,7 +300,7 @@ String *Swig_name_construct(const_String_or_char_ptr classname) { naming_hash = NewHash(); f = Getattr(naming_hash, "construct"); if (!f) { - Append(r, "new_%c"); + Append(r, "new_%n%c"); } else { Append(r, f); } @@ -278,6 +309,8 @@ String *Swig_name_construct(const_String_or_char_ptr classname) { if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { cname = strchr(cname, ' ') + 1; } + + replace_nspace(r, nspace); Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; @@ -290,7 +323,7 @@ String *Swig_name_construct(const_String_or_char_ptr classname) { * Returns the name of the accessor function used to copy an object. * ----------------------------------------------------------------------------- */ -String *Swig_name_copyconstructor(const_String_or_char_ptr classname) { +String *Swig_name_copyconstructor(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) { String *r; String *f; String *rclassname; @@ -302,7 +335,7 @@ String *Swig_name_copyconstructor(const_String_or_char_ptr classname) { naming_hash = NewHash(); f = Getattr(naming_hash, "copy"); if (!f) { - Append(r, "copy_%c"); + Append(r, "copy_%n%c"); } else { Append(r, f); } @@ -312,6 +345,7 @@ String *Swig_name_copyconstructor(const_String_or_char_ptr classname) { cname = strchr(cname, ' ') + 1; } + replace_nspace(r, nspace); Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; @@ -323,7 +357,7 @@ String *Swig_name_copyconstructor(const_String_or_char_ptr classname) { * Returns the name of the accessor function used to destroy an object. * ----------------------------------------------------------------------------- */ -String *Swig_name_destroy(const_String_or_char_ptr classname) { +String *Swig_name_destroy(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) { String *r; String *f; String *rclassname; @@ -334,7 +368,7 @@ String *Swig_name_destroy(const_String_or_char_ptr classname) { naming_hash = NewHash(); f = Getattr(naming_hash, "destroy"); if (!f) { - Append(r, "delete_%c"); + Append(r, "delete_%n%c"); } else { Append(r, f); } @@ -343,6 +377,8 @@ String *Swig_name_destroy(const_String_or_char_ptr classname) { if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { cname = strchr(cname, ' ') + 1; } + + replace_nspace(r, nspace); Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; @@ -355,7 +391,7 @@ String *Swig_name_destroy(const_String_or_char_ptr classname) { * Returns the name of the accessor function used to disown an object. * ----------------------------------------------------------------------------- */ -String *Swig_name_disown(const_String_or_char_ptr classname) { +String *Swig_name_disown(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) { String *r; String *f; String *rclassname; @@ -366,7 +402,7 @@ String *Swig_name_disown(const_String_or_char_ptr classname) { naming_hash = NewHash(); f = Getattr(naming_hash, "disown"); if (!f) { - Append(r, "disown_%c"); + Append(r, "disown_%n%c"); } else { Append(r, f); } @@ -375,6 +411,8 @@ String *Swig_name_disown(const_String_or_char_ptr classname) { if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { cname = strchr(cname, ' ') + 1; } + + replace_nspace(r, nspace); Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index ec5ecb271..b3cb0f158 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -35,6 +35,10 @@ extern "C" { #define SWIG_ERROR 0 #define SWIG_NOWRAP 0 +/* Global macros */ +#define NSPACE_SEPARATOR "." /* Namespace separator for the nspace feature - this should be changed to a target language configurable variable */ +#define NSPACE_TODO 0 /* temporary TODO hack */ + /* Short names for common data types */ typedef DOH String; @@ -212,6 +216,7 @@ extern "C" { extern void Swig_symbol_setscopename(const_String_or_char_ptr name); extern String *Swig_symbol_getscopename(void); extern String *Swig_symbol_qualifiedscopename(Symtab *symtab); + extern String *Swig_symbol_qualified_language_scopename(Symtab *symtab); extern Symtab *Swig_symbol_newscope(void); extern Symtab *Swig_symbol_setscope(Symtab *); extern Symtab *Swig_symbol_getscope(const_String_or_char_ptr symname); @@ -259,13 +264,13 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern void Swig_name_unregister(const_String_or_char_ptr method); extern String *Swig_name_mangle(const_String_or_char_ptr s); extern String *Swig_name_wrapper(const_String_or_char_ptr fname); - extern String *Swig_name_member(const_String_or_char_ptr classname, const_String_or_char_ptr mname); - extern String *Swig_name_get(const_String_or_char_ptr vname); - extern String *Swig_name_set(const_String_or_char_ptr vname); - extern String *Swig_name_construct(const_String_or_char_ptr classname); - extern String *Swig_name_copyconstructor(const_String_or_char_ptr classname); - extern String *Swig_name_destroy(const_String_or_char_ptr classname); - extern String *Swig_name_disown(const_String_or_char_ptr classname); + extern String *Swig_name_member(const_String_or_char_ptr nspace, const_String_or_char_ptr classname, const_String_or_char_ptr membername); + extern String *Swig_name_get(const_String_or_char_ptr nspace, const_String_or_char_ptr vname); + extern String *Swig_name_set(const_String_or_char_ptr nspace, const_String_or_char_ptr vname); + extern String *Swig_name_construct(const_String_or_char_ptr nspace, const_String_or_char_ptr classname); + extern String *Swig_name_copyconstructor(const_String_or_char_ptr nspace, const_String_or_char_ptr classname); + extern String *Swig_name_destroy(const_String_or_char_ptr nspace, const_String_or_char_ptr classname); + extern String *Swig_name_disown(const_String_or_char_ptr nspace, const_String_or_char_ptr classname); extern void Swig_naming_init(void); extern void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash *namewrn); @@ -296,6 +301,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern void Swig_banner(File *f); extern void Swig_banner_target_lang(File *f, const_String_or_char_ptr commentchar); extern String *Swig_strip_c_comments(const String *s); + extern String *Swig_new_subdirectory(String *basedirectory, String *subdirectory); extern void Swig_filename_correct(String *filename); extern String *Swig_filename_escape(String *filename); extern void Swig_filename_unescape(String *filename); @@ -346,9 +352,9 @@ extern int ParmList_is_compactdefargs(ParmList *p); /* --- Transformations --- */ - extern int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director); - extern int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags); - extern int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags); + extern int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int flags, SwigType *director_type, int is_director); + extern int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags); + extern int Swig_DestructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int cplus, int flags); extern int Swig_MembersetToFunction(Node *n, String *classname, int flags); extern int Swig_MembergetToFunction(Node *n, String *classname, int flags); extern int Swig_VargetToFunction(Node *n, int flags); diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 73a136a4a..b5e114683 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -353,6 +353,21 @@ String *Swig_symbol_qualifiedscopename(Symtab *symtab) { return result; } +/* ----------------------------------------------------------------------------- + * Swig_symbol_qualified_language_scopename() + * + * Get the fully qualified C scopename of a symbol table but using a language + * specific separator for the scopenames. Basically the same as + * Swig_symbol_qualifiedscopename() but using the different separator. + * ----------------------------------------------------------------------------- */ + +String *Swig_symbol_qualified_language_scopename(Symtab *n) { + /* TODO: fix for %rename to work */ + String *result = Swig_symbol_qualifiedscopename(n); + Replaceall(result, "::", NSPACE_SEPARATOR); + return result; +} + /* ----------------------------------------------------------------------------- * Swig_symbol_newscope() * From d399c1a04cd7300ee164b28eeaee6431f5e60431 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 4 Mar 2010 21:45:26 +0000 Subject: [PATCH 007/203] DohDelete and DohCopy assertions called if not a DOH object git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11897 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/base.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/DOH/base.c b/Source/DOH/base.c index 245004f87..36ceb7ae3 100644 --- a/Source/DOH/base.c +++ b/Source/DOH/base.c @@ -30,12 +30,15 @@ void DohDelete(DOH *obj) { if (!obj) return; -#if SWIG_DEBUG_DELETE if (!DohCheck(b)) { +#if SWIG_DEBUG_DELETE fputs("DOH: Fatal error. Attempt to delete a non-doh object.\n", stderr); abort(); - } +#else + assert(0); #endif + return; + } if (b->flag_intern) return; assert(b->refcount > 0); @@ -62,6 +65,15 @@ DOH *DohCopy(const DOH *obj) { if (!obj) return 0; + if (!DohCheck(b)) { +#if SWIG_DEBUG_DELETE + fputs("DOH: Fatal error. Attempt to copy a non-doh object.\n", stderr); + abort(); +#else + assert(0); +#endif + return 0; + } objinfo = b->type; if (objinfo->doh_copy) { DohBase *bc = (DohBase *) (objinfo->doh_copy) (b); From d7695d4f10498909907590de17d116b098625f59 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 5 Mar 2010 03:43:41 +0000 Subject: [PATCH 008/203] Fix typo. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11898 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- COPYRIGHT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COPYRIGHT b/COPYRIGHT index 45f9d6b45..0e660ba3a 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -29,7 +29,7 @@ Past SWIG developers and major contributors include: Charlie Savage (cfis@interserv.com) (Ruby) Thien-Thi Nguyen (ttn@glug.org) (build/test/misc) Richard Palmer (richard@magicality.org) (PHP) - Sam Liddicott - Anonova Ltd (saml@liddicott.com) (PHP) + Sam Liddicott - Ananova Ltd (saml@liddicott.com) (PHP) Tim Hockin - Sun Microsystems (thockin@sun.com) (PHP) Kevin Ruland (PHP) Shibukawa Yoshiki (Japanese Translation) From cfcafc807a435c6c9afccda2cc5ef8d99cded9d6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 5 Mar 2010 18:37:05 +0000 Subject: [PATCH 009/203] Add java run test for nspace test and extend the test a bit git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11899 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/java/nspace_runme.java | 64 ++++++++++++++++++++++ Examples/test-suite/nspace.i | 14 ++++- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/java/nspace_runme.java diff --git a/Examples/test-suite/java/nspace_runme.java b/Examples/test-suite/java/nspace_runme.java new file mode 100644 index 000000000..ca83b7d04 --- /dev/null +++ b/Examples/test-suite/java/nspace_runme.java @@ -0,0 +1,64 @@ +// This tests changes the package name from nspace to nspacePackage as javac can't seem to resolve classes and packages having the same name +public class nspace_runme { + + static { + try { + System.loadLibrary("nspace"); + } 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[]) { + // constructors and destructors + nspacePackage.Outer.Inner1.Color color1 = new nspacePackage.Outer.Inner1.Color(); + nspacePackage.Outer.Inner1.Color color = new nspacePackage.Outer.Inner1.Color(color1); + color1.delete(); + color1 = null; + + // class methods + color.colorInstanceMethod(20.0); + nspacePackage.Outer.Inner1.Color.colorStaticMethod(20.0); + nspacePackage.Outer.Inner1.Color created = nspacePackage.Outer.Inner1.Color.create(); + + // class enums + nspacePackage.Outer.SomeClass someClass = new nspacePackage.Outer.SomeClass(); + nspacePackage.Outer.Inner1.Color.Channel channel = someClass.GetInner1ColorChannel(); + if (channel != nspacePackage.Outer.Inner1.Color.Channel.Transmission) + throw new RuntimeException("Transmission wrong"); + + // static member variables + nspacePackage.Outer.Inner1.Color.setStaticMemberVariable(789); + if (nspacePackage.Outer.Inner1.Color.getStaticMemberVariable() != 789) + throw new RuntimeException("static member variable failed"); + + // instance member variables + color.setInstanceMemberVariable(123); + if (color.getInstanceMemberVariable() != 123) + throw new RuntimeException("instance member variable failed"); + + // Same class different namespaces + nspacePackage.Outer.Inner1.Color col1 = new nspacePackage.Outer.Inner1.Color(); + nspacePackage.Outer.Inner2.Color col2 = nspacePackage.Outer.Inner2.Color.create(); + col2.colors(col1, col1, col2, col2, col2); + + // check globals in a namespace don't get mangled with the nspacePackage option + nspacePackage.nspace.namespaceFunction(color); + nspacePackage.nspace.setNamespaceVar(111); + if (nspacePackage.nspace.getNamespaceVar() != 111) + throw new RuntimeException("global var failed"); + + // global enums + nspacePackage.Outer.Inner1.Channel outerChannel1 = someClass.GetInner1Channel(); + if (outerChannel1 != nspacePackage.Outer.Inner1.Channel.Transmission1) + throw new RuntimeException("Transmission1 wrong"); + nspacePackage.Outer.Inner2.Channel outerChannel2 = someClass.GetInner2Channel(); + if (outerChannel2 != nspacePackage.Outer.Inner2.Channel.Transmission2) + throw new RuntimeException("Transmission2 wrong"); + + // turn feature off / ignoring + nspacePackage.Outer.nspace ns = new nspacePackage.Outer.nspace(); + nspacePackage.NoNSpacePlease nons = new nspacePackage.NoNSpacePlease(); + } +} diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index 26a3273b2..eb63f342d 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -4,9 +4,13 @@ #if defined(SWIGJAVA) SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) %pragma(java) jniclassclassmodifiers = "public class" +#endif -%feature("nspace"); -%feature("nspace", "0") Outer::Inner2::NoNSpacePlease; +// nspace feature only supported by these languages +#if defined(SWIGJAVA) || defined(SWIGCSHARP) + +%nspace; +%nonspace Outer::Inner2::NoNSpacePlease; %copyctor; %ignore Outer::Inner2::Color::Color(); @@ -64,6 +68,11 @@ namespace Outer { static int staticMemberVariable; void colorInstanceMethod(double d) {} static void colorStaticMethod(double d) {} + void colors(const Inner1::Color& col1a, + const Outer::Inner1::Color& col1b, + const Color &col2a, + const Inner2::Color& col2b, + const Outer::Inner2::Color& col2c) {} }; // Color int Color::staticMemberVariable = 0; class NoNSpacePlease {}; @@ -91,3 +100,4 @@ void test_classes(Outer::SomeClass c, Outer::Inner2::Color cc) {} %} #endif + From 8e1f9274cc53b754aac2781ca6fe2b4ce05cd6a1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 00:11:40 +0000 Subject: [PATCH 010/203] remove weave python example - license is unclear git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11902 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/python/weave/Makefile | 22 - Examples/python/weave/README | 25 - Examples/python/weave/example.h | 18 - Examples/python/weave/example.i | 15 - Examples/python/weave/runme.py | 72 - Examples/python/weave/swigptr2.py | 3556 ----------------------------- 6 files changed, 3708 deletions(-) delete mode 100644 Examples/python/weave/Makefile delete mode 100644 Examples/python/weave/README delete mode 100644 Examples/python/weave/example.h delete mode 100644 Examples/python/weave/example.i delete mode 100644 Examples/python/weave/runme.py delete mode 100644 Examples/python/weave/swigptr2.py diff --git a/Examples/python/weave/Makefile b/Examples/python/weave/Makefile deleted file mode 100644 index 88f95c095..000000000 --- a/Examples/python/weave/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = example -INTERFACE = example.i -LIBS = -lm -SWIGOPT = - -all:: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp - -static:: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static - -clean:: - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py - -check: all - $(MAKE) -f $(TOP)/Makefile python_run diff --git a/Examples/python/weave/README b/Examples/python/weave/README deleted file mode 100644 index a616a4f46..000000000 --- a/Examples/python/weave/README +++ /dev/null @@ -1,25 +0,0 @@ -This directory contains a simple example to test weave support for -SWIG wrapped objects. - -The weave package provides tools for including C/C++ code in Python -code. This offers both another level of optimization to those who need -it, and an easy way to modify and extend any supported extension -libraries. Weave automatically builds an extension module from the -given C/C++ code and runs that. This can result in very significant -speedups (of upto 500x) depending on the problem. Weave also supports -inlining SWIG-1.3.x wrapped objects. - -The example in this directory requires that weave be installed. Weave -is distributed as part of SciPy (http://www.scipy.org). More -information on Weave may be had from here: - - http://www.scipy.org/documentation/weave - -As of November 22, 2004, this example only works with weave from CVS. -If there is a more recent release of SciPy after this date, it should -work fine. - - -Also, you need to replace the weave file swigptr2.py by the one -provided here. - diff --git a/Examples/python/weave/example.h b/Examples/python/weave/example.h deleted file mode 100644 index d09d60850..000000000 --- a/Examples/python/weave/example.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _EXAMPLE_H -#define _EXAMPLE_H - -class Foo { - public: - int x; -}; - -class Bar { - public: - int y; -}; - -class FooBar : public Foo, public Bar { - public: - int z; -}; -#endif diff --git a/Examples/python/weave/example.i b/Examples/python/weave/example.i deleted file mode 100644 index 5d71eaa93..000000000 --- a/Examples/python/weave/example.i +++ /dev/null @@ -1,15 +0,0 @@ -%module(directors="1") example - -%{ -#include "example.h" -%} - -%include "std_vector.i" - -%director Foo; -%director Bar; -%include "example.h" - - -%template(VectorBar) std::vector; -%template(VectorFoo) std::vector; diff --git a/Examples/python/weave/runme.py b/Examples/python/weave/runme.py deleted file mode 100644 index 529b4fc4b..000000000 --- a/Examples/python/weave/runme.py +++ /dev/null @@ -1,72 +0,0 @@ -""" -Test weave support for SWIG wrapped objects. - -This example requires that one has weave installed. Weave is -distributed as part of SciPy (http://www.scipy.org). More information -on Weave may be had from here: - - http://www.scipy.org/documentation/weave - -As of November 22, 2004, this only works with weave from CVS. If -there is a more recent release of SciPy after this date, it should -work fine. - -""" - -import example -import weave -from weave import converters -from weave import swig2_spec - -# Weave does not support swig2 by default (yet). So add this to the -# list of default converters to test. -converters.default.insert(0, swig2_spec.swig2_converter()) - -def test(): - """ A simple test case for weave.""" - a = example.Foo() - a.x = 1 - b = example.Bar() - b.y = 2 - c = example.FooBar() - c.x = 1 - c.y = 2 - c.z = 3 - v = example.VectorBar() - v.append(b) - v.append(c) - d = v[0] - e = v[1] - v = example.VectorFoo() - v.append(a) - v.append(c) - f = v[0] - g = v[1] - - code = """ - std::cout << a->x << std::endl; - assert(a->x == 1); - std::cout << b->y << std::endl; - assert(b->y == 2); - std::cout << c->x << std::endl; - std::cout << c->y << std::endl; - std::cout << c->z << std::endl; - assert(c->x == 1); - assert(c->y == 2); - assert(c->z == 3); - std::cout << d->y << std::endl; - assert(d->y == 2); - std::cout << e->y << std::endl; - assert(e->y == 2); - std::cout << f->x << std::endl; - assert(f->x == 1); - std::cout << g->x << std::endl; - assert(g->x == 1); - """ - weave.inline(code, ['a', 'b', 'c', 'd', 'e', 'f', 'g'], - include_dirs=['.'], - headers=['"example.h"'], - verbose=2) - -if __name__ == "__main__": - test() diff --git a/Examples/python/weave/swigptr2.py b/Examples/python/weave/swigptr2.py deleted file mode 100644 index 7ffe0fb65..000000000 --- a/Examples/python/weave/swigptr2.py +++ /dev/null @@ -1,3556 +0,0 @@ -# This code allows one to use SWIG wrapped objects from weave. This -# code is specific to SWIG-1.3 and above where things are different. -# The code is basically all copied out from the SWIG wrapper code but -# it has been hand edited for brevity. -# -# Prabhu Ramachandran - -###################################################################### -# This is for SWIG-1.3.x where x < 22. -# Essentially, SWIG_RUNTIME_VERSION was not yet used. -swigptr2_code_v0 = """ - -#include "Python.h" - -/*************************************************************** -*- c -*- - * python/precommon.swg - * - * Rename all exported symbols from common.swg, to avoid symbol - * clashes if multiple interpreters are included - * - ************************************************************************/ - -#define SWIG_TypeCheck SWIG_Python_TypeCheck -#define SWIG_TypeCast SWIG_Python_TypeCast -#define SWIG_TypeName SWIG_Python_TypeName -#define SWIG_TypeQuery SWIG_Python_TypeQuery -#define SWIG_PackData SWIG_Python_PackData -#define SWIG_UnpackData SWIG_Python_UnpackData - - -/*********************************************************************** - * common.swg - * - * This file contains generic SWIG runtime support for pointer - * type checking as well as a few commonly used macros to control - * external linkage. - * - * Author : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (c) 1999-2000, The University of Chicago - * - * This file may be freely redistributed without license or fee provided - * this copyright message remains intact. - ************************************************************************/ - -#include - -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if defined(_MSC_VER) || defined(__GNUC__) -# if defined(STATIC_LINKED) -# define SWIGEXPORT(a) a -# define SWIGIMPORT(a) extern a -# else -# define SWIGEXPORT(a) __declspec(dllexport) a -# define SWIGIMPORT(a) extern a -# endif -# else -# if defined(__BORLANDC__) -# define SWIGEXPORT(a) a _export -# define SWIGIMPORT(a) a _export -# else -# define SWIGEXPORT(a) a -# define SWIGIMPORT(a) a -# endif -# endif -#else -# define SWIGEXPORT(a) a -# define SWIGIMPORT(a) a -#endif - -#ifdef SWIG_GLOBAL -# define SWIGRUNTIME(a) SWIGEXPORT(a) -#else -# define SWIGRUNTIME(a) static a -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void *(*swig_converter_func)(void *); -typedef struct swig_type_info *(*swig_dycast_func)(void **); - -typedef struct swig_type_info { - const char *name; - swig_converter_func converter; - const char *str; - void *clientdata; - swig_dycast_func dcast; - struct swig_type_info *next; - struct swig_type_info *prev; -} swig_type_info; - -#ifdef SWIG_NOINCLUDE - -SWIGIMPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *); -SWIGIMPORT(void *) SWIG_TypeCast(swig_type_info *, void *); -SWIGIMPORT(const char *) SWIG_TypeName(const swig_type_info *); -SWIGIMPORT(swig_type_info *) SWIG_TypeQuery(const char *); -SWIGIMPORT(char *) SWIG_PackData(char *, void *, int); -SWIGIMPORT(char *) SWIG_UnpackData(char *, void *, int); - -#else - -static swig_type_info *swig_type_list = 0; - -/* Check the typename */ -SWIGRUNTIME(swig_type_info *) -SWIG_TypeCheck(char *c, swig_type_info *ty) { - swig_type_info *s; - if (!ty) return 0; /* Void pointer */ - s = ty->next; /* First element always just a name */ - do { - if (strcmp(s->name,c) == 0) { - if (s == ty->next) return s; - /* Move s to the top of the linked list */ - s->prev->next = s->next; - if (s->next) { - s->next->prev = s->prev; - } - /* Insert s as second element in the list */ - s->next = ty->next; - if (ty->next) ty->next->prev = s; - ty->next = s; - s->prev = ty; - return s; - } - s = s->next; - } while (s && (s != ty->next)); - return 0; -} - -/* Cast a pointer up an inheritance hierarchy */ -SWIGRUNTIME(void *) -SWIG_TypeCast(swig_type_info *ty, void *ptr) { - if ((!ty) || (!ty->converter)) return ptr; - return (*ty->converter)(ptr); -} - -/* Return the name associated with this type */ -SWIGRUNTIME(const char *) -SWIG_TypeName(const swig_type_info *ty) { - return ty->name; -} - -/* - Compare two type names skipping the space characters, therefore - "char*" == "char *" and "Class" == "Class", etc. - - Return 0 when the two name types are equivalent, as in - strncmp, but skipping ' '. -*/ -static int -SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return *f1 - *f2; - } - return (l1 - f1) - (l2 - f2); -} - -/* - Check type equivalence in a name list like ||... -*/ -static int -SWIG_TypeEquiv(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0; - if (*ne) ++ne; - } - return equiv; -} - - -/* Search for a swig_type_info structure */ -SWIGRUNTIME(swig_type_info *) -SWIG_TypeQuery(const char *name) { - swig_type_info *ty = swig_type_list; - while (ty) { - if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty; - if (ty->name && (strcmp(name,ty->name) == 0)) return ty; - ty = ty->prev; - } - return 0; -} - -/* Pack binary data into a string */ -SWIGRUNTIME(char *) -SWIG_PackData(char *c, void *ptr, int sz) { - static char hex[17] = "0123456789abcdef"; - int i; - unsigned char *u = (unsigned char *) ptr; - register unsigned char uu; - for (i = 0; i < sz; i++,u++) { - uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* Unpack binary data from a string */ -SWIGRUNTIME(char *) -SWIG_UnpackData(char *c, void *ptr, int sz) { - register unsigned char uu = 0; - register int d; - unsigned char *u = (unsigned char *) ptr; - int i; - for (i = 0; i < sz; i++, u++) { - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - *u = uu; - } - return c; -} - -#endif - -#ifdef __cplusplus -} -#endif - -/*********************************************************************** - * python.swg - * - * This file contains the runtime support for Python modules - * and includes code for managing global variables and pointer - * type checking. - * - * Author : David Beazley (beazley@cs.uchicago.edu) - ************************************************************************/ - -#include "Python.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SWIG_PY_INT 1 -#define SWIG_PY_FLOAT 2 -#define SWIG_PY_STRING 3 -#define SWIG_PY_POINTER 4 -#define SWIG_PY_BINARY 5 - -/* Flags for pointer conversion */ - -#define SWIG_POINTER_EXCEPTION 0x1 -#define SWIG_POINTER_DISOWN 0x2 - -/* Exception handling in wrappers */ -#define SWIG_fail goto fail - -/* Constant information structure */ -typedef struct swig_const_info { - int type; - char *name; - long lvalue; - double dvalue; - void *pvalue; - swig_type_info **ptype; -} swig_const_info; - -/* Common SWIG API */ -#define SWIG_ConvertPtr(obj, pp, type, flags) \ - SWIG_Python_ConvertPtr(obj, pp, type, flags) -#define SWIG_NewPointerObj(p, type, flags) \ - SWIG_Python_NewPointerObj(p, type, flags) -#define SWIG_MustGetPtr(p, type, argnum, flags) \ - SWIG_Python_MustGetPtr(p, type, argnum, flags) - - -typedef double (*py_objasdbl_conv)(PyObject *obj); - -#ifdef SWIG_NOINCLUDE - -SWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int); -SWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own); -SWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info *, int, int); - -#else - - -/* Convert a pointer value */ -SWIGRUNTIME(int) -SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) { - swig_type_info *tc; - char *c = 0; - static PyObject *SWIG_this = 0; - int newref = 0; - PyObject *pyobj = 0; - - if (!obj) return 0; - if (obj == Py_None) { - *ptr = 0; - return 0; - } -#ifdef SWIG_COBJECT_TYPES - if (!(PyCObject_Check(obj))) { - if (!SWIG_this) - SWIG_this = PyString_FromString("this"); - pyobj = obj; - obj = PyObject_GetAttr(obj,SWIG_this); - newref = 1; - if (!obj) goto type_error; - if (!PyCObject_Check(obj)) { - Py_DECREF(obj); - goto type_error; - } - } - *ptr = PyCObject_AsVoidPtr(obj); - c = (char *) PyCObject_GetDesc(obj); - if (newref) Py_DECREF(obj); - goto cobject; -#else - if (!(PyString_Check(obj))) { - if (!SWIG_this) - SWIG_this = PyString_FromString("this"); - pyobj = obj; - obj = PyObject_GetAttr(obj,SWIG_this); - newref = 1; - if (!obj) goto type_error; - if (!PyString_Check(obj)) { - Py_DECREF(obj); - goto type_error; - } - } - c = PyString_AsString(obj); - /* Pointer values must start with leading underscore */ - if (*c != '_') { - *ptr = (void *) 0; - if (strcmp(c,"NULL") == 0) { - if (newref) { Py_DECREF(obj); } - return 0; - } else { - if (newref) { Py_DECREF(obj); } - goto type_error; - } - } - c++; - c = SWIG_UnpackData(c,ptr,sizeof(void *)); - if (newref) { Py_DECREF(obj); } -#endif - -#ifdef SWIG_COBJECT_TYPES -cobject: -#endif - - if (ty) { - tc = SWIG_TypeCheck(c,ty); - if (!tc) goto type_error; - *ptr = SWIG_TypeCast(tc,(void*) *ptr); - } - - if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) { - PyObject *zero = PyInt_FromLong(0); - PyObject_SetAttrString(pyobj,(char*)"thisown",zero); - Py_DECREF(zero); - } - return 0; - -type_error: - PyErr_Clear(); - if (flags & SWIG_POINTER_EXCEPTION) { - if (ty && c) { - PyErr_Format(PyExc_TypeError, - "Type error. Got %s, expected %s", - c, ty->name); - } else { - PyErr_SetString(PyExc_TypeError,"Expected a pointer"); - } - } - return -1; -} - -/* Convert a pointer value, signal an exception on a type mismatch */ -SWIGRUNTIME(void *) -SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { - void *result; - SWIG_Python_ConvertPtr(obj, &result, ty, flags | SWIG_POINTER_EXCEPTION); - return result; -} - -/* Create a new pointer object */ -SWIGRUNTIME(PyObject *) -SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) { - PyObject *robj; - if (!ptr) { - Py_INCREF(Py_None); - return Py_None; - } -#ifdef SWIG_COBJECT_TYPES - robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, (char *) type->name, NULL); -#else - { - char result[1024]; - char *r = result; - *(r++) = '_'; - r = SWIG_PackData(r,&ptr,sizeof(void *)); - strcpy(r,type->name); - robj = PyString_FromString(result); - } -#endif - if (!robj || (robj == Py_None)) return robj; - if (type->clientdata) { - PyObject *inst; - PyObject *args = Py_BuildValue((char*)"(O)", robj); - Py_DECREF(robj); - inst = PyObject_CallObject((PyObject *) type->clientdata, args); - Py_DECREF(args); - if (inst) { - if (own) { - PyObject *n = PyInt_FromLong(1); - PyObject_SetAttrString(inst,(char*)"thisown",n); - Py_DECREF(n); - } - robj = inst; - } - } - return robj; -} - -#endif - -#ifdef __cplusplus -} -#endif - -""" - - -###################################################################### -# This is for SWIG-1.3.x where x >= 23. -# SWIG_RUNTIME_VERSION == "1" - -# All this does is to include (cut/paste): -# and -swigptr2_code_v1 = """ -/*********************************************************************** - * swigrun.swg - * - * This file contains generic CAPI SWIG runtime support for pointer - * type checking. - * - ************************************************************************/ - -/* This should only be incremented when either the layout of swig_type_info changes, - or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "1" - -/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ -#ifdef SWIG_TYPE_TABLE -#define SWIG_QUOTE_STRING(x) #x -#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) -#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) -#else -#define SWIG_TYPE_TABLE_NAME -#endif - -#include - -#ifndef SWIGINLINE -#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) -# define SWIGINLINE inline -#else -# define SWIGINLINE -#endif -#endif - -/* - You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for - creating a static or dynamic library from the swig runtime code. - In 99.9% of the cases, swig just needs to declare them as 'static'. - - But only do this if is strictly necessary, ie, if you have problems - with your compiler or so. -*/ -#ifndef SWIGRUNTIME -#define SWIGRUNTIME static -#endif -#ifndef SWIGRUNTIMEINLINE -#define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void *(*swig_converter_func)(void *); -typedef struct swig_type_info *(*swig_dycast_func)(void **); - -typedef struct swig_type_info { - const char *name; - swig_converter_func converter; - const char *str; - void *clientdata; - swig_dycast_func dcast; - struct swig_type_info *next; - struct swig_type_info *prev; -} swig_type_info; - -/* - Compare two type names skipping the space characters, therefore - "char*" == "char *" and "Class" == "Class", etc. - - Return 0 when the two name types are equivalent, as in - strncmp, but skipping ' '. -*/ -SWIGRUNTIME int -SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return *f1 - *f2; - } - return (l1 - f1) - (l2 - f2); -} - -/* - Check type equivalence in a name list like ||... -*/ -SWIGRUNTIME int -SWIG_TypeEquiv(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0; - if (*ne) ++ne; - } - return equiv; -} - -/* - Register a type mapping with the type-checking -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeRegisterTL(swig_type_info **tl, swig_type_info *ti) { - swig_type_info *tc, *head, *ret, *next; - /* Check to see if this type has already been registered */ - tc = *tl; - while (tc) { - /* check simple type equivalence */ - int typeequiv = (strcmp(tc->name, ti->name) == 0); - /* check full type equivalence, resolving typedefs */ - if (!typeequiv) { - /* only if tc is not a typedef (no '|' on it) */ - if (tc->str && ti->str && !strstr(tc->str,"|")) { - typeequiv = SWIG_TypeEquiv(ti->str,tc->str); - } - } - if (typeequiv) { - /* Already exists in the table. Just add additional types to the list */ - if (ti->clientdata) tc->clientdata = ti->clientdata; - head = tc; - next = tc->next; - goto l1; - } - tc = tc->prev; - } - head = ti; - next = 0; - - /* Place in list */ - ti->prev = *tl; - *tl = ti; - - /* Build linked lists */ - l1: - ret = head; - tc = ti + 1; - /* Patch up the rest of the links */ - while (tc->name) { - head->next = tc; - tc->prev = head; - head = tc; - tc++; - } - if (next) next->prev = head; - head->next = next; - - return ret; -} - -/* - Check the typename -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeCheck(const char *c, swig_type_info *ty) { - swig_type_info *s; - if (!ty) return 0; /* Void pointer */ - s = ty->next; /* First element always just a name */ - do { - if (strcmp(s->name,c) == 0) { - if (s == ty->next) return s; - /* Move s to the top of the linked list */ - s->prev->next = s->next; - if (s->next) { - s->next->prev = s->prev; - } - /* Insert s as second element in the list */ - s->next = ty->next; - if (ty->next) ty->next->prev = s; - ty->next = s; - s->prev = ty; - return s; - } - s = s->next; - } while (s && (s != ty->next)); - return 0; -} - -/* - Cast a pointer up an inheritance hierarchy -*/ -SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_type_info *ty, void *ptr) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr); -} - -/* - Dynamic pointer casting. Down an inheritance hierarchy -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { - swig_type_info *lastty = ty; - if (!ty || !ty->dcast) return ty; - while (ty && (ty->dcast)) { - ty = (*ty->dcast)(ptr); - if (ty) lastty = ty; - } - return lastty; -} - -/* - Return the name associated with this type -*/ -SWIGRUNTIMEINLINE const char * -SWIG_TypeName(const swig_type_info *ty) { - return ty->name; -} - -/* - Return the pretty name associated with this type, - that is an unmangled type name in a form presentable to the user. -*/ -SWIGRUNTIME const char * -SWIG_TypePrettyName(const swig_type_info *type) { - /* The "str" field contains the equivalent pretty names of the - type, separated by vertical-bar characters. We choose - to print the last name, as it is often (?) the most - specific. */ - if (type->str != NULL) { - const char *last_name = type->str; - const char *s; - for (s = type->str; *s; s++) - if (*s == '|') last_name = s+1; - return last_name; - } - else - return type->name; -} - -/* - Search for a swig_type_info structure -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeQueryTL(swig_type_info *tl, const char *name) { - swig_type_info *ty = tl; - while (ty) { - if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty; - if (ty->name && (strcmp(name,ty->name) == 0)) return ty; - ty = ty->prev; - } - return 0; -} - -/* - Set the clientdata field for a type -*/ -SWIGRUNTIME void -SWIG_TypeClientDataTL(swig_type_info *tl, swig_type_info *ti, void *clientdata) { - swig_type_info *tc, *equiv; - if (ti->clientdata) return; - /* if (ti->clientdata == clientdata) return; */ - ti->clientdata = clientdata; - equiv = ti->next; - while (equiv) { - if (!equiv->converter) { - tc = tl; - while (tc) { - if ((strcmp(tc->name, equiv->name) == 0)) - SWIG_TypeClientDataTL(tl,tc,clientdata); - tc = tc->prev; - } - } - equiv = equiv->next; - } -} - -/* - Pack binary data into a string -*/ -SWIGRUNTIME char * -SWIG_PackData(char *c, void *ptr, size_t sz) { - static char hex[17] = "0123456789abcdef"; - unsigned char *u = (unsigned char *) ptr; - const unsigned char *eu = u + sz; - register unsigned char uu; - for (; u != eu; ++u) { - uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* - Unpack binary data from a string -*/ -SWIGRUNTIME const char * -SWIG_UnpackData(const char *c, void *ptr, size_t sz) { - register unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register int d = *(c++); - register unsigned char uu = 0; - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - else - return (char *) 0; - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - else - return (char *) 0; - *u = uu; - } - return c; -} - -/* - This function will propagate the clientdata field of type to any new - swig_type_info structures that have been added into the list of - equivalent types. It is like calling SWIG_TypeClientData(type, - clientdata) a second time. -*/ -SWIGRUNTIME void -SWIG_PropagateClientDataTL(swig_type_info *tl, swig_type_info *type) { - swig_type_info *equiv = type->next; - swig_type_info *tc; - if (!type->clientdata) return; - while (equiv) { - if (!equiv->converter) { - tc = tl; - while (tc) { - if ((strcmp(tc->name, equiv->name) == 0) && !tc->clientdata) - SWIG_TypeClientDataTL(tl,tc, type->clientdata); - tc = tc->prev; - } - } - equiv = equiv->next; - } -} - -/* - Pack 'void *' into a string buffer. -*/ -SWIGRUNTIME char * -SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { - char *r = buff; - if ((2*sizeof(void *) + 2) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,&ptr,sizeof(void *)); - if (strlen(name) + 1 > (bsz - (r - buff))) return 0; - strcpy(r,name); - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - *ptr = (void *) 0; - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sizeof(void *)); -} - -SWIGRUNTIME char * -SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { - char *r = buff; - size_t lname = (name ? strlen(name) : 0); - if ((2*sz + 2 + lname) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,ptr,sz); - if (lname) { - strncpy(r,name,lname+1); - } else { - *r = 0; - } - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - memset(ptr,0,sz); - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sz); -} - -#ifdef __cplusplus -} -#endif - -/*********************************************************************** - * pyrun.swg - * - * This file contains the runtime support for Python modules - * and includes code for managing global variables and pointer - * type checking. - * - * Author : David Beazley (beazley@cs.uchicago.edu) - ************************************************************************/ - -/* Common SWIG API */ -#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags) -#define SWIG_NewPointerObj(p, type, flags) SWIG_Python_NewPointerObj(p, type, flags) -#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) - - -/* Python-specific SWIG API */ -#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags) -#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - - -/* ----------------------------------------------------------------------------- - * Pointer declarations - * ----------------------------------------------------------------------------- */ -/* - Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent - C/C++ pointers in the python side. Very useful for debugging, but - not always safe. -*/ -#if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES) -# define SWIG_COBJECT_TYPES -#endif - -/* Flags for pointer conversion */ -#define SWIG_POINTER_EXCEPTION 0x1 -#define SWIG_POINTER_DISOWN 0x2 - - -#ifdef __cplusplus -extern "C" { -#endif - -/* ----------------------------------------------------------------------------- - * Create a new pointer string - * ----------------------------------------------------------------------------- */ - -#ifndef SWIG_BUFFER_SIZE -#define SWIG_BUFFER_SIZE 1024 -#endif - -#if defined(SWIG_COBJECT_TYPES) -#if !defined(SWIG_COBJECT_PYTHON) -/* ----------------------------------------------------------------------------- - * Implements a simple Swig Object type, and use it instead of PyCObject - * ----------------------------------------------------------------------------- */ - -typedef struct { - PyObject_HEAD - void *ptr; - const char *desc; -} PySwigObject; - -/* Declarations for objects of type PySwigObject */ - -SWIGRUNTIME int -PySwigObject_print(PySwigObject *v, FILE *fp, int flags) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result))) { - fputs("", fp); - return 0; - } else { - return 1; - } -} - -SWIGRUNTIME PyObject * -PySwigObject_repr(PySwigObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ? - PyString_FromFormat("", result) : 0; -} - -SWIGRUNTIME PyObject * -PySwigObject_str(PySwigObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ? - PyString_FromString(result) : 0; -} - -SWIGRUNTIME PyObject * -PySwigObject_long(PySwigObject *v) -{ - return PyLong_FromUnsignedLong((unsigned long) v->ptr); -} - -SWIGRUNTIME PyObject * -PySwigObject_oct(PySwigObject *v) -{ - char buf[100]; - unsigned long x = (unsigned long)v->ptr; - if (x == 0) - strcpy(buf, "0"); - else - PyOS_snprintf(buf, sizeof(buf), "0%lo", x); - return PyString_FromString(buf); -} - -SWIGRUNTIME PyObject * -PySwigObject_hex(PySwigObject *v) -{ - char buf[100]; - PyOS_snprintf(buf, sizeof(buf), "0x%lx", (unsigned long)v->ptr); - return PyString_FromString(buf); -} - -SWIGRUNTIME int -PySwigObject_compare(PySwigObject *v, PySwigObject *w) -{ - int c = strcmp(v->desc, w->desc); - if (c) { - return c; - } else { - void *i = v->ptr; - void *j = w->ptr; - return (i < j) ? -1 : (i > j) ? 1 : 0; - } -} - -SWIGRUNTIME void -PySwigObject_dealloc(PySwigObject *self) -{ - PyObject_DEL(self); -} - -SWIGRUNTIME PyTypeObject* -PySwigObject_GetType() { - static char PySwigObject_Type__doc__[] = - "Swig object carries a C/C++ instance pointer"; - - static PyNumberMethods PySwigObject_as_number = { - (binaryfunc)0, /*nb_add*/ - (binaryfunc)0, /*nb_subtract*/ - (binaryfunc)0, /*nb_multiply*/ - (binaryfunc)0, /*nb_divide*/ - (binaryfunc)0, /*nb_remainder*/ - (binaryfunc)0, /*nb_divmod*/ - (ternaryfunc)0,/*nb_power*/ - (unaryfunc)0, /*nb_negative*/ - (unaryfunc)0, /*nb_positive*/ - (unaryfunc)0, /*nb_absolute*/ - (inquiry)0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - (coercion)0, /*nb_coerce*/ - (unaryfunc)PySwigObject_long, /*nb_int*/ - (unaryfunc)PySwigObject_long, /*nb_long*/ - (unaryfunc)0, /*nb_float*/ - (unaryfunc)PySwigObject_oct, /*nb_oct*/ - (unaryfunc)PySwigObject_hex, /*nb_hex*/ -#if PY_VERSION_HEX >= 0x02000000 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ -#endif - }; - - static PyTypeObject PySwigObject_Type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /*ob_size*/ - "PySwigObject", /*tp_name*/ - sizeof(PySwigObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)PySwigObject_dealloc, /*tp_dealloc*/ - (printfunc)PySwigObject_print, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - (cmpfunc)PySwigObject_compare, /*tp_compare*/ - (reprfunc)PySwigObject_repr, /*tp_repr*/ - &PySwigObject_as_number, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - (hashfunc)0, /*tp_hash*/ - (ternaryfunc)0, /*tp_call*/ - (reprfunc)PySwigObject_str, /*tp_str*/ - /* Space for future expansion */ - 0L,0L,0L,0L, - PySwigObject_Type__doc__, /* Documentation string */ -#if PY_VERSION_HEX >= 0x02000000 - 0, /* tp_traverse */ - 0, /* tp_clear */ -#endif -#if PY_VERSION_HEX >= 0x02010000 - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#endif -#if PY_VERSION_HEX >= 0x02020000 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - - return &PySwigObject_Type; -} - -SWIGRUNTIME PyObject * -PySwigObject_FromVoidPtrAndDesc(void *ptr, const char *desc) -{ - PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_GetType()); - if (self == NULL) return NULL; - self->ptr = ptr; - self->desc = desc; - return (PyObject *)self; -} - -SWIGRUNTIMEINLINE void * -PySwigObject_AsVoidPtr(PyObject *self) -{ - return ((PySwigObject *)self)->ptr; -} - -SWIGRUNTIMEINLINE const char * -PySwigObject_GetDesc(PyObject *self) -{ - return ((PySwigObject *)self)->desc; -} - -SWIGRUNTIMEINLINE int -PySwigObject_Check(PyObject *op) { - return ((op)->ob_type == PySwigObject_GetType()) - || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0); -} - -/* ----------------------------------------------------------------------------- - * Implements a simple Swig Packed type, and use it instead of string - * ----------------------------------------------------------------------------- */ - -typedef struct { - PyObject_HEAD - void *pack; - const char *desc; - size_t size; -} PySwigPacked; - -SWIGRUNTIME int -PySwigPacked_print(PySwigPacked *v, FILE *fp, int flags) -{ - char result[SWIG_BUFFER_SIZE]; - fputs("pack, v->size, 0, sizeof(result))) { - fputs("at ", fp); - fputs(result, fp); - } - fputs(v->desc,fp); - fputs(">", fp); - return 0; -} - -SWIGRUNTIME PyObject * -PySwigPacked_repr(PySwigPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { - return PyString_FromFormat("", result, v->desc); - } else { - return PyString_FromFormat("", v->desc); - } -} - -SWIGRUNTIME PyObject * -PySwigPacked_str(PySwigPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ - return PyString_FromFormat("%s%s", result, v->desc); - } else { - return PyString_FromFormat("%s", v->desc); - } -} - -SWIGRUNTIME int -PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w) -{ - int c = strcmp(v->desc, w->desc); - if (c) { - return c; - } else { - size_t i = v->size; - size_t j = w->size; - int s = (i < j) ? -1 : (i > j) ? 1 : 0; - return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); - } -} - -SWIGRUNTIME void -PySwigPacked_dealloc(PySwigPacked *self) -{ - free(self->pack); - PyObject_DEL(self); -} - -SWIGRUNTIME PyTypeObject* -PySwigPacked_GetType() { - static char PySwigPacked_Type__doc__[] = - "Swig object carries a C/C++ instance pointer"; - - static PyTypeObject PySwigPacked_Type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /*ob_size*/ - "PySwigPacked", /*tp_name*/ - sizeof(PySwigPacked), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)PySwigPacked_dealloc, /*tp_dealloc*/ - (printfunc)PySwigPacked_print, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - (cmpfunc)PySwigPacked_compare, /*tp_compare*/ - (reprfunc)PySwigPacked_repr, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - (hashfunc)0, /*tp_hash*/ - (ternaryfunc)0, /*tp_call*/ - (reprfunc)PySwigPacked_str, /*tp_str*/ - /* Space for future expansion */ - 0L,0L,0L,0L, - PySwigPacked_Type__doc__, /* Documentation string */ -#if PY_VERSION_HEX >= 0x02000000 - 0, /* tp_traverse */ - 0, /* tp_clear */ -#endif -#if PY_VERSION_HEX >= 0x02010000 - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#endif -#if PY_VERSION_HEX >= 0x02020000 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - - return &PySwigPacked_Type; -} - -SWIGRUNTIME PyObject * -PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc) -{ - PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_GetType()); - if (self == NULL) { - return NULL; - } else { - void *pack = malloc(size); - memcpy(pack, ptr, size); - self->pack = pack; - self->desc = desc; - self->size = size; - return (PyObject *) self; - } -} - -SWIGRUNTIMEINLINE const char * -PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size) -{ - PySwigPacked *self = (PySwigPacked *)obj; - if (self->size != size) return 0; - memcpy(ptr, self->pack, size); - return self->desc; -} - -SWIGRUNTIMEINLINE const char * -PySwigPacked_GetDesc(PyObject *self) -{ - return ((PySwigPacked *)self)->desc; -} - -SWIGRUNTIMEINLINE int -PySwigPacked_Check(PyObject *op) { - return ((op)->ob_type == PySwigPacked_GetType()) - || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0); -} - -#else -/* ----------------------------------------------------------------------------- - * Use the old Python PyCObject instead of PySwigObject - * ----------------------------------------------------------------------------- */ - -#define PySwigObject_GetDesc(obj) PyCObject_GetDesc(obj) -#define PySwigObject_Check(obj) PyCObject_Check(obj) -#define PySwigObject_AsVoidPtr(obj) PyCObject_AsVoidPtr(obj) -#define PySwigObject_FromVoidPtrAndDesc(p, d) PyCObject_FromVoidPtrAndDesc(p, d, NULL) - -#endif - -#endif - -/* ----------------------------------------------------------------------------- - * errors manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIME void -SWIG_Python_TypeError(const char *type, PyObject *obj) -{ - if (type) { -#if defined(SWIG_COBJECT_TYPES) - if (PySwigObject_Check(obj)) { - const char *otype = (const char *) PySwigObject_GetDesc(obj); - if (otype) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received", - type, otype); - return; - } - } else -#endif - { - const char *otype = (obj ? obj->ob_type->tp_name : 0); - if (otype) { - PyObject *str = PyObject_Str(obj); - const char *cstr = str ? PyString_AsString(str) : 0; - if (cstr) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", - type, otype, cstr); - } else { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", - type, otype); - } - Py_DECREF(str); - return; - } - } - PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); - } else { - PyErr_Format(PyExc_TypeError, "unexpected type is received"); - } -} - -SWIGRUNTIMEINLINE void -SWIG_Python_NullRef(const char *type) -{ - if (type) { - PyErr_Format(PyExc_TypeError, "null reference of type '%s' was received",type); - } else { - PyErr_Format(PyExc_TypeError, "null reference was received"); - } -} - -SWIGRUNTIME int -SWIG_Python_AddErrMesg(const char* mesg, int infront) -{ - if (PyErr_Occurred()) { - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - PyErr_Fetch(&type, &value, &traceback); - if (value) { - PyObject *old_str = PyObject_Str(value); - Py_XINCREF(type); - PyErr_Clear(); - if (infront) { - PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str)); - } else { - PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); - } - Py_DECREF(old_str); - } - return 1; - } else { - return 0; - } -} - -SWIGRUNTIME int -SWIG_Python_ArgFail(int argnum) -{ - if (PyErr_Occurred()) { - /* add information about failing argument */ - char mesg[256]; - sprintf(mesg, "argument number %d:", argnum); - return SWIG_Python_AddErrMesg(mesg, 1); - } else { - return 0; - } -} - - -/* ----------------------------------------------------------------------------- - * pointers/data manipulation - * ----------------------------------------------------------------------------- */ - -/* Convert a pointer value */ -SWIGRUNTIME int -SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) { - swig_type_info *tc; - const char *c = 0; - static PyObject *SWIG_this = 0; - int newref = 0; - PyObject *pyobj = 0; - void *vptr; - - if (!obj) return 0; - if (obj == Py_None) { - *ptr = 0; - return 0; - } - -#ifdef SWIG_COBJECT_TYPES - if (!(PySwigObject_Check(obj))) { - if (!SWIG_this) - SWIG_this = PyString_FromString("this"); - pyobj = obj; - obj = PyObject_GetAttr(obj,SWIG_this); - newref = 1; - if (!obj) goto type_error; - if (!PySwigObject_Check(obj)) { - Py_DECREF(obj); - goto type_error; - } - } - vptr = PySwigObject_AsVoidPtr(obj); - c = (const char *) PySwigObject_GetDesc(obj); - if (newref) { Py_DECREF(obj); } - goto type_check; -#else - if (!(PyString_Check(obj))) { - if (!SWIG_this) - SWIG_this = PyString_FromString("this"); - pyobj = obj; - obj = PyObject_GetAttr(obj,SWIG_this); - newref = 1; - if (!obj) goto type_error; - if (!PyString_Check(obj)) { - Py_DECREF(obj); - goto type_error; - } - } - c = PyString_AS_STRING(obj); - /* Pointer values must start with leading underscore */ - c = SWIG_UnpackVoidPtr(c, &vptr, ty->name); - if (newref) { Py_DECREF(obj); } - if (!c) goto type_error; -#endif - -type_check: - - if (ty) { - tc = SWIG_TypeCheck(c,ty); - if (!tc) goto type_error; - *ptr = SWIG_TypeCast(tc,vptr); - } - - if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) { - PyObject_SetAttrString(pyobj,(char*)"thisown",Py_False); - } - return 0; - -type_error: - PyErr_Clear(); - if (pyobj && !obj) { - obj = pyobj; - if (PyCFunction_Check(obj)) { - /* here we get the method pointer for callbacks */ - char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); - c = doc ? strstr(doc, "swig_ptr: ") : 0; - if (c) { - c = SWIG_UnpackVoidPtr(c + 10, &vptr, ty->name); - if (!c) goto type_error; - goto type_check; - } - } - } - if (flags & SWIG_POINTER_EXCEPTION) { - if (ty) { - SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); - } else { - SWIG_Python_TypeError("C/C++ pointer", obj); - } - } - return -1; -} - -/* Convert a pointer value, signal an exception on a type mismatch */ -SWIGRUNTIME void * -SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { - void *result; - if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { - PyErr_Clear(); - if (flags & SWIG_POINTER_EXCEPTION) { - SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); - SWIG_Python_ArgFail(argnum); - } - } - return result; -} - -/* Convert a packed value value */ -SWIGRUNTIME int -SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty, int flags) { - swig_type_info *tc; - const char *c = 0; - -#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON) - c = PySwigPacked_UnpackData(obj, ptr, sz); -#else - if ((!obj) || (!PyString_Check(obj))) goto type_error; - c = PyString_AS_STRING(obj); - /* Pointer values must start with leading underscore */ - c = SWIG_UnpackDataName(c, ptr, sz, ty->name); -#endif - if (!c) goto type_error; - if (ty) { - tc = SWIG_TypeCheck(c,ty); - if (!tc) goto type_error; - } - return 0; - -type_error: - PyErr_Clear(); - if (flags & SWIG_POINTER_EXCEPTION) { - if (ty) { - SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); - } else { - SWIG_Python_TypeError("C/C++ packed data", obj); - } - } - return -1; -} - -/* Create a new array object */ -SWIGRUNTIME PyObject * -SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) { - PyObject *robj = 0; - if (!ptr) { - Py_INCREF(Py_None); - return Py_None; - } -#ifdef SWIG_COBJECT_TYPES - robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)type->name); -#else - { - char result[SWIG_BUFFER_SIZE]; - robj = SWIG_PackVoidPtr(result, ptr, type->name, sizeof(result)) ? - PyString_FromString(result) : 0; - } -#endif - if (!robj || (robj == Py_None)) return robj; - if (type->clientdata) { - PyObject *inst; - PyObject *args = Py_BuildValue((char*)"(O)", robj); - Py_DECREF(robj); - inst = PyObject_CallObject((PyObject *) type->clientdata, args); - Py_DECREF(args); - if (inst) { - if (own) { - PyObject_SetAttrString(inst,(char*)"thisown",Py_True); - } - robj = inst; - } - } - return robj; -} - -SWIGRUNTIME PyObject * -SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { - PyObject *robj = 0; - if (!ptr) { - Py_INCREF(Py_None); - return Py_None; - } -#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON) - robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *)type->name); -#else - { - char result[SWIG_BUFFER_SIZE]; - robj = SWIG_PackDataName(result, ptr, sz, type->name, sizeof(result)) ? - PyString_FromString(result) : 0; - } -#endif - return robj; -} - -/* -----------------------------------------------------------------------------* - * Get type list - * -----------------------------------------------------------------------------*/ - -#ifdef SWIG_LINK_RUNTIME -void *SWIG_ReturnGlobalTypeList(void *); -#endif - -SWIGRUNTIME swig_type_info ** -SWIG_Python_GetTypeListHandle() { - static void *type_pointer = (void *)0; - /* first check if module already created */ - if (!type_pointer) { -#ifdef SWIG_LINK_RUNTIME - type_pointer = SWIG_ReturnGlobalTypeList((void *)0); -#else - type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); - if (PyErr_Occurred()) { - PyErr_Clear(); - type_pointer = (void *)0; - } - } -#endif - return (swig_type_info **) type_pointer; -} - -/* - Search for a swig_type_info structure - */ -SWIGRUNTIMEINLINE swig_type_info * -SWIG_Python_GetTypeList() { - swig_type_info **tlh = SWIG_Python_GetTypeListHandle(); - return tlh ? *tlh : (swig_type_info*)0; -} - -#define SWIG_Runtime_GetTypeList SWIG_Python_GetTypeList - -#ifdef __cplusplus -} -#endif - -/* -----------------------------------------------------------------------------* - Standard SWIG API for use inside user code. - - You need to include in your code as follow: - -#include // or using your favorite language -#include -#include // or using your favorite language -#include - - * -----------------------------------------------------------------------------*/ - -SWIGRUNTIMEINLINE swig_type_info * -SWIG_Runtime_TypeQuery(const char *name) { - swig_type_info *tl = SWIG_Runtime_GetTypeList(); - return SWIG_TypeQueryTL(tl, name); -} - -SWIGRUNTIMEINLINE swig_type_info * -SWIG_Runtime_TypeRegister(swig_type_info *ti) { - swig_type_info *tl = SWIG_Runtime_GetTypeList(); - return SWIG_TypeRegisterTL(&tl, ti); -} - -SWIGRUNTIMEINLINE void -SWIG_Runtime_TypeClientData(swig_type_info *ti, void *clientdata) { - swig_type_info *tl = SWIG_Runtime_GetTypeList(); - SWIG_TypeClientDataTL(tl, ti, clientdata); -} - -SWIGRUNTIMEINLINE void -SWIG_Runtime_PropagateClientData(swig_type_info *type) { - swig_type_info *tl = SWIG_Runtime_GetTypeList(); - SWIG_PropagateClientDataTL(tl, type); -} - -#define SWIG_GetTypeList() SWIG_Runtime_GetTypeList() -#define SWIG_TypeQuery(name) SWIG_Runtime_TypeQuery(name) -#define SWIG_TypeRegister(ti) SWIG_Runtime_TypeRegister(ti) -#define SWIG_TypeClientData(ti, cd) SWIG_Runtime_TypeClientData(ti, cd) -#define SWIG_PropagateClientData(ti) SWIG_Runtime_PropagateClientData(ti) - -""" - -###################################################################### -# This is for SWIG-1.3.x where x >= 25. -# SWIG_RUNTIME_VERSION == "2" - -# All this does is to include the contents of the file generated by -# this command: -# swig -python -external-runtime -swigptr2_code_v2 = """ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.28 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -/*********************************************************************** - * - * This section contains generic SWIG labels for method/variable - * declarations/attributes, and other compiler dependent labels. - * - ************************************************************************/ - -/* template workaround for compilers that cannot correctly implement the C++ standard */ -#ifndef SWIGTEMPLATEDISAMBIGUATOR -# if defined(__SUNPRO_CC) -# if (__SUNPRO_CC <= 0x560) -# define SWIGTEMPLATEDISAMBIGUATOR template -# else -# define SWIGTEMPLATEDISAMBIGUATOR -# endif -# else -# define SWIGTEMPLATEDISAMBIGUATOR -# endif -#endif - -/* inline attribute */ -#ifndef SWIGINLINE -# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) -# define SWIGINLINE inline -# else -# define SWIGINLINE -# endif -#endif - -/* attribute recognised by some compilers to avoid 'unused' warnings */ -#ifndef SWIGUNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -# elif defined(__ICC) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -#endif - -#ifndef SWIGUNUSEDPARM -# ifdef __cplusplus -# define SWIGUNUSEDPARM(p) -# else -# define SWIGUNUSEDPARM(p) p SWIGUNUSED -# endif -#endif - -/* internal SWIG method */ -#ifndef SWIGINTERN -# define SWIGINTERN static SWIGUNUSED -#endif - -/* internal inline SWIG method */ -#ifndef SWIGINTERNINLINE -# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE -#endif - -/* exporting methods for Windows DLLs */ -#ifndef SWIGEXPORT -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if defined(STATIC_LINKED) -# define SWIGEXPORT -# else -# define SWIGEXPORT __declspec(dllexport) -# endif -# else -# define SWIGEXPORT -# endif -#endif - -/* calling conventions for Windows */ -#ifndef SWIGSTDCALL -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# define SWIGSTDCALL __stdcall -# else -# define SWIGSTDCALL -# endif -#endif - - -/* Errors in SWIG */ -#define SWIG_UnknownError -1 -#define SWIG_IOError -2 -#define SWIG_RuntimeError -3 -#define SWIG_IndexError -4 -#define SWIG_TypeError -5 -#define SWIG_DivisionByZero -6 -#define SWIG_OverflowError -7 -#define SWIG_SyntaxError -8 -#define SWIG_ValueError -9 -#define SWIG_SystemError -10 -#define SWIG_AttributeError -11 -#define SWIG_MemoryError -12 -#define SWIG_NullReferenceError -13 - - - -/*********************************************************************** - * swigrun.swg - * - * This file contains generic CAPI SWIG runtime support for pointer - * type checking. - * - ************************************************************************/ - -/* This should only be incremented when either the layout of swig_type_info changes, - or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "2" - -/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ -#ifdef SWIG_TYPE_TABLE -# define SWIG_QUOTE_STRING(x) #x -# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) -# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) -#else -# define SWIG_TYPE_TABLE_NAME -#endif - -/* - You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for - creating a static or dynamic library from the swig runtime code. - In 99.9% of the cases, swig just needs to declare them as 'static'. - - But only do this if is strictly necessary, ie, if you have problems - with your compiler or so. -*/ - -#ifndef SWIGRUNTIME -# define SWIGRUNTIME SWIGINTERN -#endif - -#ifndef SWIGRUNTIMEINLINE -# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE -#endif - -/* Generic buffer size */ -#ifndef SWIG_BUFFER_SIZE -# define SWIG_BUFFER_SIZE 1024 -#endif - -/* Flags for pointer conversions */ -#define SWIG_POINTER_DISOWN 0x1 - -/* Flags for new pointer objects */ -#define SWIG_POINTER_OWN 0x1 - - -/* - Flags/methods for returning states. - - The swig conversion methods, as ConvertPtr, return and integer - that tells if the conversion was successful or not. And if not, - an error code can be returned (see swigerrors.swg for the codes). - - Use the following macros/flags to set or process the returning - states. - - In old swig versions, you usually write code as: - - if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { - // success code - } else { - //fail code - } - - Now you can be more explicit as: - - int res = SWIG_ConvertPtr(obj,vptr,ty.flags); - if (SWIG_IsOK(res)) { - // success code - } else { - // fail code - } - - that seems to be the same, but now you can also do - - Type *ptr; - int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); - if (SWIG_IsOK(res)) { - // success code - if (SWIG_IsNewObj(res) { - ... - delete *ptr; - } else { - ... - } - } else { - // fail code - } - - I.e., now SWIG_ConvertPtr can return new objects and you can - identify the case and take care of the deallocation. Of course that - requires also to SWIG_ConvertPtr to return new result values, as - - int SWIG_ConvertPtr(obj, ptr,...) { - if () { - if () { - *ptr = ; - return SWIG_NEWOBJ; - } else { - *ptr = ; - return SWIG_OLDOBJ; - } - } else { - return SWIG_BADOBJ; - } - } - - Of course, returning the plain '0(success)/-1(fail)' still works, but you can be - more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the - swig errors code. - - Finally, if the SWIG_CASTRANK_MODE is enabled, the result code - allows to return the 'cast rank', for example, if you have this - - int food(double) - int fooi(int); - - and you call - - food(1) // cast rank '1' (1 -> 1.0) - fooi(1) // cast rank '0' - - just use the SWIG_AddCast()/SWIG_CheckState() - - - */ -#define SWIG_OK (0) -#define SWIG_ERROR (-1) -#define SWIG_IsOK(r) (r >= 0) - -/* The CastRankLimit says how many bits are used for the cast rank */ -#define SWIG_CASTRANKLIMIT (1 << 8) -/* The NewMask denotes the object was created (using new/malloc) */ -#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) -/* The TmpMask is for in/out typemaps that use temporal objects */ -#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) -/* Simple returning values */ -#define SWIG_BADOBJ (SWIG_ERROR) -#define SWIG_OLDOBJ (SWIG_OK) -#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) -#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) -/* Check, add and del mask methods */ -#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) -#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) -#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) -#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) -#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) -#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) - - -/* Cast-Rank Mode */ -#if defined(SWIG_CASTRANK_MODE) -# ifndef SWIG_TypeRank -# define SWIG_TypeRank unsigned long -# endif -# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ -# define SWIG_MAXCASTRANK (2) -# endif -# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) -# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) -SWIGINTERNINLINE int SWIG_AddCast(int r) { - return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; -} -SWIGINTERNINLINE int SWIG_CheckState(int r) { - return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; -} -#else /* no cast-rank mode */ -# define SWIG_AddCast -# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) -#endif - - - - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void *(*swig_converter_func)(void *); -typedef struct swig_type_info *(*swig_dycast_func)(void **); - -/* Structure to store inforomation on one type */ -typedef struct swig_type_info { - const char *name; /* mangled name of this type */ - const char *str; /* human readable name of this type */ - swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ - struct swig_cast_info *cast; /* linked list of types that can cast into this type */ - void *clientdata; /* language specific type data */ - int owndata; /* flag if the structure owns the clientdata */ -} swig_type_info; - -/* Structure to store a type and conversion function used for casting */ -typedef struct swig_cast_info { - swig_type_info *type; /* pointer to type that is equivalent to this type */ - swig_converter_func converter; /* function to cast the void pointers */ - struct swig_cast_info *next; /* pointer to next cast in linked list */ - struct swig_cast_info *prev; /* pointer to the previous cast */ -} swig_cast_info; - -/* Structure used to store module information - * Each module generates one structure like this, and the runtime collects - * all of these structures and stores them in a circularly linked list.*/ -typedef struct swig_module_info { - swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ - size_t size; /* Number of types in this module */ - struct swig_module_info *next; /* Pointer to next element in circularly linked list */ - swig_type_info **type_initial; /* Array of initially generated type structures */ - swig_cast_info **cast_initial; /* Array of initially generated casting structures */ - void *clientdata; /* Language specific module data */ -} swig_module_info; - -/* - Compare two type names skipping the space characters, therefore - "char*" == "char *" and "Class" == "Class", etc. - - Return 0 when the two name types are equivalent, as in - strncmp, but skipping ' '. -*/ -SWIGRUNTIME int -SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return (int)(*f1 - *f2); - } - return (l1 - f1) - (l2 - f2); -} - -/* - Check type equivalence in a name list like ||... - Return 0 if not equal, 1 if equal -*/ -SWIGRUNTIME int -SWIG_TypeEquiv(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; - if (*ne) ++ne; - } - return equiv; -} - -/* - Check type equivalence in a name list like ||... - Return 0 if equal, -1 if nb < tb, 1 if nb > tb -*/ -SWIGRUNTIME int -SWIG_TypeCompare(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; - if (*ne) ++ne; - } - return equiv; -} - - -/* think of this as a c++ template<> or a scheme macro */ -#define SWIG_TypeCheck_Template(comparison, ty) \ - if (ty) { \ - swig_cast_info *iter = ty->cast; \ - while (iter) { \ - if (comparison) { \ - if (iter == ty->cast) return iter; \ - /* Move iter to the top of the linked list */ \ - iter->prev->next = iter->next; \ - if (iter->next) \ - iter->next->prev = iter->prev; \ - iter->next = ty->cast; \ - iter->prev = 0; \ - if (ty->cast) ty->cast->prev = iter; \ - ty->cast = iter; \ - return iter; \ - } \ - iter = iter->next; \ - } \ - } \ - return 0 - -/* - Check the typename -*/ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheck(const char *c, swig_type_info *ty) { - SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty); -} - -/* Same as previous function, except strcmp is replaced with a pointer comparison */ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { - SWIG_TypeCheck_Template(iter->type == from, into); -} - -/* - Cast a pointer up an inheritance hierarchy -*/ -SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr); -} - -/* - Dynamic pointer casting. Down an inheritance hierarchy -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { - swig_type_info *lastty = ty; - if (!ty || !ty->dcast) return ty; - while (ty && (ty->dcast)) { - ty = (*ty->dcast)(ptr); - if (ty) lastty = ty; - } - return lastty; -} - -/* - Return the name associated with this type -*/ -SWIGRUNTIMEINLINE const char * -SWIG_TypeName(const swig_type_info *ty) { - return ty->name; -} - -/* - Return the pretty name associated with this type, - that is an unmangled type name in a form presentable to the user. -*/ -SWIGRUNTIME const char * -SWIG_TypePrettyName(const swig_type_info *type) { - /* The "str" field contains the equivalent pretty names of the - type, separated by vertical-bar characters. We choose - to print the last name, as it is often (?) the most - specific. */ - if (!type) return NULL; - if (type->str != NULL) { - const char *last_name = type->str; - const char *s; - for (s = type->str; *s; s++) - if (*s == '|') last_name = s+1; - return last_name; - } - else - return type->name; -} - -/* - Set the clientdata field for a type -*/ -SWIGRUNTIME void -SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { - swig_cast_info *cast = ti->cast; - /* if (ti->clientdata == clientdata) return; */ - ti->clientdata = clientdata; - - while (cast) { - if (!cast->converter) { - swig_type_info *tc = cast->type; - if (!tc->clientdata) { - SWIG_TypeClientData(tc, clientdata); - } - } - cast = cast->next; - } -} -SWIGRUNTIME void -SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { - SWIG_TypeClientData(ti, clientdata); - ti->owndata = 1; -} - -/* - Search for a swig_type_info structure only by mangled name - Search is a O(log #types) - - We start searching at module start, and finish searching when start == end. - Note: if start == end at the beginning of the function, we go all the way around - the circular list. -*/ -SWIGRUNTIME swig_type_info * -SWIG_MangledTypeQueryModule(swig_module_info *start, - swig_module_info *end, - const char *name) { - swig_module_info *iter = start; - do { - if (iter->size) { - register size_t l = 0; - register size_t r = iter->size - 1; - do { - /* since l+r >= 0, we can (>> 1) instead (/ 2) */ - register size_t i = (l + r) >> 1; - const char *iname = iter->types[i]->name; - if (iname) { - register int compare = strcmp(name, iname); - if (compare == 0) { - return iter->types[i]; - } else if (compare < 0) { - if (i) { - r = i - 1; - } else { - break; - } - } else if (compare > 0) { - l = i + 1; - } - } else { - break; /* should never happen */ - } - } while (l <= r); - } - iter = iter->next; - } while (iter != end); - return 0; -} - -/* - Search for a swig_type_info structure for either a mangled name or a human readable name. - It first searches the mangled names of the types, which is a O(log #types) - If a type is not found it then searches the human readable names, which is O(#types). - - We start searching at module start, and finish searching when start == end. - Note: if start == end at the beginning of the function, we go all the way around - the circular list. -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeQueryModule(swig_module_info *start, - swig_module_info *end, - const char *name) { - /* STEP 1: Search the name field using binary search */ - swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); - if (ret) { - return ret; - } else { - /* STEP 2: If the type hasn't been found, do a complete search - of the str field (the human readable name) */ - swig_module_info *iter = start; - do { - register size_t i = 0; - for (; i < iter->size; ++i) { - if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) - return iter->types[i]; - } - iter = iter->next; - } while (iter != end); - } - - /* neither found a match */ - return 0; -} - -/* - Pack binary data into a string -*/ -SWIGRUNTIME char * -SWIG_PackData(char *c, void *ptr, size_t sz) { - static const char hex[17] = "0123456789abcdef"; - register const unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register unsigned char uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* - Unpack binary data from a string -*/ -SWIGRUNTIME const char * -SWIG_UnpackData(const char *c, void *ptr, size_t sz) { - register unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register char d = *(c++); - register unsigned char uu; - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - else - return (char *) 0; - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - else - return (char *) 0; - *u = uu; - } - return c; -} - -/* - Pack 'void *' into a string buffer. -*/ -SWIGRUNTIME char * -SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { - char *r = buff; - if ((2*sizeof(void *) + 2) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,&ptr,sizeof(void *)); - if (strlen(name) + 1 > (bsz - (r - buff))) return 0; - strcpy(r,name); - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - *ptr = (void *) 0; - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sizeof(void *)); -} - -SWIGRUNTIME char * -SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { - char *r = buff; - size_t lname = (name ? strlen(name) : 0); - if ((2*sz + 2 + lname) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,ptr,sz); - if (lname) { - strncpy(r,name,lname+1); - } else { - *r = 0; - } - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - memset(ptr,0,sz); - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sz); -} - -#ifdef __cplusplus -} -#endif - -/*********************************************************************** - * pyrun.swg - * - * This file contains the runtime support for Python modules - * and includes code for managing global variables and pointer - * type checking. - * - * Author : David Beazley (beazley@cs.uchicago.edu) - ************************************************************************/ - -/* Common SWIG API */ - -/* for raw pointers */ -#define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) -#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) -#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) -#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags) -#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) -#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) -#define swig_owntype int - -/* for raw packed data */ -#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - -/* for class or struct pointers */ -#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) -#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) - -/* for C or C++ function pointers */ -#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) -#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0) - -/* for C++ member pointers, ie, member methods */ -#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - - -/* Runtime API */ - -#define SWIG_GetModule(clientdata) SWIG_Python_GetModule() -#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) -#define SWIG_NewClientData(obj) PySwigClientData_New(obj) - -/* A functor is a function object with one single object argument */ -#if PY_VERSION_HEX >= 0x02020000 -#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); -#else -#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); -#endif - -/* Error manipulation */ -#define SWIG_SetErrorObj(type, obj) {SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetObject(type, obj); SWIG_PYTHON_THREAD_END_BLOCK; } -#define SWIG_SetErrorMsg(type, msg) {SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetString(type, msg); SWIG_PYTHON_THREAD_END_BLOCK; } -#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) -#define SWIG_Error(code, msg) SWIG_SetErrorMsg(SWIG_Python_ErrorType(code), msg) -#define SWIG_fail goto fail - - -/* - Helper for static pointer initialization for both C and C++ code, for example - static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); -*/ -#ifdef __cplusplus -#define SWIG_STATIC_POINTER(var) var -#else -#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var -#endif - -/* ----------------------------------------------------------------------------- - * Pointer declarations - * ----------------------------------------------------------------------------- */ - -/* Flags for new pointer objects */ -#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) -#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) - -#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) - -/* For backward compatibility only */ -#define SWIG_POINTER_EXCEPTION 0 - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* Safe Py_None and Py_Void accessors */ - -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# ifndef SWIG_PYTHON_NO_SAFE_NONE -# ifndef SWIG_PYTHON_SAFE_NONE -# define SWIG_PYTHON_SAFE_NONE -# endif -# endif -#endif - -#ifdef SWIG_PYTHON_SAFE_NONE -SWIGRUNTIMEINLINE PyObject * -_SWIG_Py_None(void) -{ - PyObject *none = Py_BuildValue(""); - Py_DECREF(none); - return none; -} -SWIGRUNTIME PyObject * -SWIG_Py_None(void) -{ - static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); - return none; -} -# ifdef Py_None -# undef Py_None -# define Py_None SWIG_Py_None() -# endif -#endif - -SWIGRUNTIMEINLINE PyObject * -SWIG_Py_Void(void) -{ - PyObject *none = Py_None; - Py_INCREF(none); - return none; -} - -/* Append a value to the result obj */ - -SWIGINTERN PyObject* -SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyList_Check(result)) { - PyObject *o2 = result; - result = PyList_New(1); - PyList_SetItem(result, 0, o2); - } - PyList_Append(result,obj); - Py_DECREF(obj); - } - return result; -} - -SWIGINTERN int -SWIG_Python_UnpackTuple(PyObject *args, const char *name, int min, int max, PyObject **objs) -{ - if (!PyTuple_Check(args)) { - PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); - return 0; - } else { - register int l = PyTuple_GET_SIZE(args); - if (l < min) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at least "), min, l); - return 0; - } else if (l > max) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at most "), max, l); - return 0; - } else { - register int i; - for (i = 0; i < l; ++i) { - objs[i] = PyTuple_GET_ITEM(args, i); - } - for (; l < max; ++l) { - objs[l] = 0; - } - return i + 1; - } - } -} - -/* PySwigClientData */ - -typedef struct { - PyObject *klass; - PyObject *newraw; - PyObject *newargs; - PyObject *destroy; - int delargs; - int implicitconv; -} PySwigClientData; - -SWIGRUNTIMEINLINE int -SWIG_Python_CheckImplicit(swig_type_info *ty) -{ - PySwigClientData *data = (PySwigClientData *)ty->clientdata; - return data ? data->implicitconv : 0; -} - - -SWIGRUNTIME PySwigClientData * -PySwigClientData_New(PyObject* obj) -{ - if (!obj) { - return 0; - } else { - PySwigClientData *data = (PySwigClientData *)malloc(sizeof(PySwigClientData)); - /* the klass element */ - data->klass = obj; - Py_INCREF(obj); - /* the newraw method and newargs arguments used to create a new raw instance */ - if (PyClass_Check(obj)) { - data->newraw = 0; - data->newargs = obj; - Py_INCREF(obj); - } else { -#if (PY_VERSION_HEX < 0x02020000) - data->newraw = 0; - data->newargs = obj; - Py_INCREF(obj); -#else - data->newraw = PyObject_GetAttrString((PyObject*)&PyBaseObject_Type, "__new__"); - Py_INCREF(data->newraw); - data->newargs = PyTuple_New(1); - PyTuple_SetItem(data->newargs, 0, obj); - Py_INCREF(data->newargs); -#endif - } - /* the destroy method, aka as the C++ delete method */ - data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__"); - if (PyErr_Occurred()) { - PyErr_Clear(); - data->destroy = 0; - } - if (data->destroy) { - Py_INCREF(data->destroy); - int flags = PyCFunction_GET_FLAGS(data->destroy); -#ifdef METH_O - data->delargs = !(flags & (METH_O)); -#else - data->delargs = 0; -#endif - } else { - data->delargs = 0; - } - data->implicitconv = 0; - return data; - } -} - -SWIGRUNTIME void -PySwigClientData_Del(PySwigClientData* data) -{ - Py_XDECREF(data->klass); - Py_XDECREF(data->newraw); - Py_XDECREF(data->newargs); - Py_XDECREF(data->destroy); - free(data); -} - -/* =============== PySwigObject =====================*/ - -typedef struct { - PyObject_HEAD - void *ptr; - swig_type_info *ty; - int own; - PyObject *next; -} PySwigObject; - -SWIGRUNTIME PyObject * -PySwigObject_long(PySwigObject *v) -{ - return PyLong_FromVoidPtr(v->ptr); -} - -SWIGRUNTIME PyObject * -PySwigObject_format(const char* fmt, PySwigObject *v) -{ - PyObject *res = NULL; - PyObject *args = PyTuple_New(1); - if (args) { - if (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0) { - PyObject *ofmt = PyString_FromString(fmt); - if (ofmt) { - res = PyString_Format(ofmt,args); - Py_DECREF(ofmt); - } - Py_DECREF(args); - } - } - return res; -} - -SWIGRUNTIME PyObject * -PySwigObject_oct(PySwigObject *v) -{ - return PySwigObject_format("%o",v); -} - -SWIGRUNTIME PyObject * -PySwigObject_hex(PySwigObject *v) -{ - return PySwigObject_format("%x",v); -} - -SWIGRUNTIME PyObject * -PySwigObject_repr(PySwigObject *v) -{ - const char *name = SWIG_TypePrettyName(v->ty); - PyObject *hex = PySwigObject_hex(v); - PyObject *repr = PyString_FromFormat("", name, PyString_AsString(hex)); - Py_DECREF(hex); - if (v->next) { - PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next); - PyString_ConcatAndDel(&repr,nrep); - } - return repr; -} - -SWIGRUNTIME int -PySwigObject_print(PySwigObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - PyObject *repr = PySwigObject_repr(v); - if (repr) { - fputs(PyString_AsString(repr), fp); - Py_DECREF(repr); - return 0; - } else { - return 1; - } -} - -SWIGRUNTIME PyObject * -PySwigObject_str(PySwigObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? - PyString_FromString(result) : 0; -} - -SWIGRUNTIME int -PySwigObject_compare(PySwigObject *v, PySwigObject *w) -{ - void *i = v->ptr; - void *j = w->ptr; - return (i < j) ? -1 : ((i > j) ? 1 : 0); -} - -SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); - -SWIGRUNTIME PyTypeObject* -PySwigObject_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); - return type; -} - -SWIGRUNTIMEINLINE int -PySwigObject_Check(PyObject *op) { - return ((op)->ob_type == PySwigObject_type()) - || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0); -} - - -SWIGRUNTIME PyObject * -PySwigObject_New(void *ptr, swig_type_info *ty, int own); - -SWIGRUNTIME void -PySwigObject_dealloc(PyObject *v) -{ - PySwigObject *sobj = (PySwigObject *) v; - PyObject *next = sobj->next; - if (sobj->own) { - swig_type_info *ty = sobj->ty; - PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; - PyObject *destroy = data ? data->destroy : 0; - if (destroy) { - /* destroy is always a VARARGS method */ - PyObject *res; - if (data->delargs) { - /* we need to create a temporal object to carry the destroy operation */ - PyObject *tmp = PySwigObject_New(sobj->ptr, ty, 0); - res = SWIG_Python_CallFunctor(destroy, tmp); - Py_DECREF(tmp); - } else { - PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); - PyObject *mself = PyCFunction_GET_SELF(destroy); - res = ((*meth)(mself, v)); - } - Py_XDECREF(res); - } else { - const char *name = SWIG_TypePrettyName(ty); -#if (PY_VERSION_HEX >= 0x02020000) - PyObject *wrn = PyString_FromFormat("swig/python detected a memory leak of type '%s'.", name); - PyErr_Warn(PyExc_RuntimeWarning, PyString_AsString(wrn)); - Py_DECREF(wrn); -#else - printf("swig/python detected a memory leak of type '%s'.", name); -#endif - } - } - Py_XDECREF(next); - PyObject_DEL(v); -} - -SWIGRUNTIME PyObject* -PySwigObject_append(PyObject* v, PyObject* next) -{ - PySwigObject *sobj = (PySwigObject *) v; -#ifndef METH_O - PyObject *tmp = 0; - if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; - next = tmp; -#endif - if (!PySwigObject_Check(next)) { - return NULL; - } - sobj->next = next; - Py_INCREF(next); - return SWIG_Py_Void(); -} - -SWIGRUNTIME PyObject* -#ifdef METH_NOARGS -PySwigObject_next(PyObject* v) -#else -PySwigObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *) v; - if (sobj->next) { - Py_INCREF(sobj->next); - return sobj->next; - } else { - return SWIG_Py_Void(); - } -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -PySwigObject_disown(PyObject *v) -#else -PySwigObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *)v; - sobj->own = 0; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -PySwigObject_acquire(PyObject *v) -#else -PySwigObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *)v; - sobj->own = SWIG_POINTER_OWN; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -PySwigObject_own(PyObject *v, PyObject *args) -{ - PyObject *val = 0; -#if (PY_VERSION_HEX < 0x02020000) - if (!PyArg_ParseTuple(args,(char *)"O:own",&val)) -#else - if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) -#endif - { - return NULL; - } - else - { - PySwigObject *sobj = (PySwigObject *)v; - PyObject *obj = sobj->own ? Py_True : Py_False; - if (val) { -#ifdef METH_NOARGS - if (PyObject_IsTrue(val)) { - PySwigObject_acquire(v); - } else { - PySwigObject_disown(v); - } -#else - if (PyObject_IsTrue(val)) { - PySwigObject_acquire(v,args); - } else { - PySwigObject_disown(v,args); - } -#endif - } - Py_INCREF(obj); - return obj; - } -} - -SWIGRUNTIME PyTypeObject* -_PySwigObject_type(void) { - static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; - static PyMethodDef -#ifdef METH_O - swigobject_methods[] = { - {"disown", (PyCFunction)PySwigObject_disown, METH_NOARGS, "releases ownership of the pointer"}, - {"acquire", (PyCFunction)PySwigObject_acquire, METH_NOARGS, "aquires ownership of the pointer"}, - {"own", (PyCFunction)PySwigObject_own, METH_VARARGS, "returns/sets ownership of the pointer"}, - {"append", (PyCFunction)PySwigObject_append, METH_O, "appends another 'this' object"}, - {"next", (PyCFunction)PySwigObject_next, METH_NOARGS, "returns the next 'this' object"}, - {0, 0, 0, 0} - }; -#else - swigobject_methods[] = { - {"disown", (PyCFunction)PySwigObject_disown, METH_VARARGS, "releases ownership of the pointer"}, - {"acquire", (PyCFunction)PySwigObject_acquire, METH_VARARGS, "aquires ownership of the pointer"}, - {"own", (PyCFunction)PySwigObject_own, METH_VARARGS, "returns/sets ownership of the pointer"}, - {"append", (PyCFunction)PySwigObject_append, METH_VARARGS, "appends another 'this' object"}, - {"next", (PyCFunction)PySwigObject_next, METH_VARARGS, "returns the next 'this' object"}, - {0, 0, 0, 0} - }; -#endif - - static PyNumberMethods PySwigObject_as_number = { - (binaryfunc)0, /*nb_add*/ - (binaryfunc)0, /*nb_subtract*/ - (binaryfunc)0, /*nb_multiply*/ - (binaryfunc)0, /*nb_divide*/ - (binaryfunc)0, /*nb_remainder*/ - (binaryfunc)0, /*nb_divmod*/ - (ternaryfunc)0,/*nb_power*/ - (unaryfunc)0, /*nb_negative*/ - (unaryfunc)0, /*nb_positive*/ - (unaryfunc)0, /*nb_absolute*/ - (inquiry)0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - (coercion)0, /*nb_coerce*/ - (unaryfunc)PySwigObject_long, /*nb_int*/ - (unaryfunc)PySwigObject_long, /*nb_long*/ - (unaryfunc)0, /*nb_float*/ - (unaryfunc)PySwigObject_oct, /*nb_oct*/ - (unaryfunc)PySwigObject_hex, /*nb_hex*/ -#if PY_VERSION_HEX >= 0x02020000 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ -#elif PY_VERSION_HEX >= 0x02000000 - 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ -#endif - }; - - static PyTypeObject pyswigobject_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - (char *)"PySwigObject", /* tp_name */ - sizeof(PySwigObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PySwigObject_dealloc, /* tp_dealloc */ - (printfunc)PySwigObject_print, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)PySwigObject_compare, /* tp_compare */ - (reprfunc)PySwigObject_repr, /* tp_repr */ - &PySwigObject_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)PySwigObject_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigobject_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0, /* tp_iter */ - 0, /* tp_iternext */ - swigobject_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - PyObject_Del, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - pyswigobject_type = tmp; - pyswigobject_type.ob_type = &PyType_Type; - type_init = 1; - } - return &pyswigobject_type; -} - -SWIGRUNTIME PyObject * -PySwigObject_New(void *ptr, swig_type_info *ty, int own) -{ - PySwigObject *sobj = PyObject_NEW(PySwigObject, PySwigObject_type()); - if (sobj) { - sobj->ptr = ptr; - sobj->ty = ty; - sobj->own = own; - sobj->next = 0; - } - return (PyObject *)sobj; -} - -/* ----------------------------------------------------------------------------- - * Implements a simple Swig Packed type, and use it instead of string - * ----------------------------------------------------------------------------- */ - -typedef struct { - PyObject_HEAD - void *pack; - swig_type_info *ty; - size_t size; -} PySwigPacked; - -SWIGRUNTIME int -PySwigPacked_print(PySwigPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - char result[SWIG_BUFFER_SIZE]; - fputs("pack, v->size, 0, sizeof(result))) { - fputs("at ", fp); - fputs(result, fp); - } - fputs(v->ty->name,fp); - fputs(">", fp); - return 0; -} - -SWIGRUNTIME PyObject * -PySwigPacked_repr(PySwigPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { - return PyString_FromFormat("", result, v->ty->name); - } else { - return PyString_FromFormat("", v->ty->name); - } -} - -SWIGRUNTIME PyObject * -PySwigPacked_str(PySwigPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ - return PyString_FromFormat("%s%s", result, v->ty->name); - } else { - return PyString_FromString(v->ty->name); - } -} - -SWIGRUNTIME int -PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w) -{ - size_t i = v->size; - size_t j = w->size; - int s = (i < j) ? -1 : ((i > j) ? 1 : 0); - return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); -} - -SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); - -SWIGRUNTIME PyTypeObject* -PySwigPacked_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); - return type; -} - -SWIGRUNTIMEINLINE int -PySwigPacked_Check(PyObject *op) { - return ((op)->ob_type == _PySwigPacked_type()) - || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0); -} - -SWIGRUNTIME void -PySwigPacked_dealloc(PyObject *v) -{ - if (PySwigPacked_Check(v)) { - PySwigPacked *sobj = (PySwigPacked *) v; - free(sobj->pack); - } - PyObject_DEL(v); -} - -SWIGRUNTIME PyTypeObject* -_PySwigPacked_type(void) { - static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; - static PyTypeObject pyswigpacked_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - (char *)"PySwigPacked", /* tp_name */ - sizeof(PySwigPacked), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PySwigPacked_dealloc, /* tp_dealloc */ - (printfunc)PySwigPacked_print, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)PySwigPacked_compare, /* tp_compare */ - (reprfunc)PySwigPacked_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)PySwigPacked_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigpacked_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - PyObject_Del, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - pyswigpacked_type = tmp; - pyswigpacked_type.ob_type = &PyType_Type; - type_init = 1; - } - return &pyswigpacked_type; -} - -SWIGRUNTIME PyObject * -PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty) -{ - PySwigPacked *sobj = PyObject_NEW(PySwigPacked, PySwigPacked_type()); - if (sobj) { - void *pack = malloc(size); - if (pack) { - memcpy(pack, ptr, size); - sobj->pack = pack; - sobj->ty = ty; - sobj->size = size; - } else { - PyObject_DEL((PyObject *) sobj); - sobj = 0; - } - } - return (PyObject *) sobj; -} - -SWIGRUNTIME swig_type_info * -PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size) -{ - if (PySwigPacked_Check(obj)) { - PySwigPacked *sobj = (PySwigPacked *)obj; - if (sobj->size != size) return 0; - memcpy(ptr, sobj->pack, size); - return sobj->ty; - } else { - return 0; - } -} - -/* ----------------------------------------------------------------------------- - * pointers/data manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIME PyObject * -_SWIG_This(void) -{ - static PyObject *_this = 0; - if (!_this) { - _this = PyString_FromString("this"); - } - return _this; -} - -SWIGRUNTIME PyObject * -SWIG_This(void) -{ - static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); - return swig_this; -} - -/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ - -SWIGRUNTIME PySwigObject * -SWIG_Python_GetSwigThis(PyObject *pyobj) -{ - if (PySwigObject_Check(pyobj)) { - return (PySwigObject *) pyobj; - } else { - PyObject *obj = 0; -#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && !(PY_VERSION_HEX < 0x02020000)) - if (PyInstance_Check(pyobj)) { - obj = _PyInstance_Lookup(pyobj, SWIG_This()); - } else { - PyObject **dictptr = _PyObject_GetDictPtr(pyobj); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; - } -#ifdef PyWeakref_CheckProxy - else if (PyWeakref_CheckProxy(pyobj)) { - PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); - return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; - } -#endif - if (!obj) { - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } - } - } -#else - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } -#endif - return (PySwigObject *)obj; - } -} - - -/* Acquire a pointer value */ - -SWIGRUNTIME int -SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own) { - PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); - if (sobj) { - int oldown = sobj->own; - sobj->own = own; - return oldown; - } - } - return 0; -} - -/* Convert a pointer value */ - -SWIGRUNTIME int -SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { - if (!obj) return SWIG_ERROR; - if (obj == Py_None) { - if (ptr) *ptr = 0; - return SWIG_OK; - } else { - PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); - while (sobj) { - void *vptr = sobj->ptr; - if (ty) { - swig_type_info *to = sobj->ty; - if (to == ty) { - /* no type cast needed */ - if (ptr) *ptr = vptr; - break; - } else { - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) { - sobj = (PySwigObject *)sobj->next; - } else { - if (ptr) *ptr = SWIG_TypeCast(tc,vptr); - break; - } - } - } else { - if (ptr) *ptr = vptr; - break; - } - } - if (sobj) { - if (own) *own = sobj->own; - if (flags & SWIG_POINTER_DISOWN) { - sobj->own = 0; - } - return SWIG_OK; - } else { - int res = SWIG_ERROR; - if (flags & SWIG_POINTER_IMPLICIT_CONV) { - PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; - if (data && !data->implicitconv) { - PyObject *klass = data->klass; - if (klass) { - PyObject *impconv; - data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ - impconv = SWIG_Python_CallFunctor(klass, obj); - data->implicitconv = 0; - if (PyErr_Occurred()) { - PyErr_Clear(); - impconv = 0; - } - if (impconv) { - PySwigObject *sobj = SWIG_Python_GetSwigThis(impconv); - if (sobj) { - void *vptr; - res = SWIG_Python_ConvertPtrAndOwn((PyObject*)sobj, &vptr, ty, 0, 0); - if (SWIG_IsOK(res)) { - if (ptr) { - *ptr = vptr; - /* transfer the ownership to 'ptr' */ - sobj->own = 0; - res = SWIG_AddNewMask(SWIG_AddCast(res)); - } else { - res = SWIG_AddCast(res); - } - } - } - Py_DECREF(impconv); - } - } - } - } - return res; - } - } -} - -/* Convert a function ptr value */ - -SWIGRUNTIME int -SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { - if (!PyCFunction_Check(obj)) { - return SWIG_ConvertPtr(obj, ptr, ty, 0); - } else { - void *vptr = 0; - - /* here we get the method pointer for callbacks */ - char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); - const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; - if (desc) { - desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; - if (!desc) return SWIG_ERROR; - } - if (ty) { - swig_cast_info *tc = SWIG_TypeCheck(desc,ty); - if (!tc) return SWIG_ERROR; - *ptr = SWIG_TypeCast(tc,vptr); - } else { - *ptr = vptr; - } - return SWIG_OK; - } -} - -/* Convert a packed value value */ - -SWIGRUNTIME int -SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { - swig_type_info *to = PySwigPacked_UnpackData(obj, ptr, sz); - if (!to) return SWIG_ERROR; - if (ty) { - if (to != ty) { - /* check type cast? */ - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) return SWIG_ERROR; - } - } - return SWIG_OK; -} - -/* ----------------------------------------------------------------------------- - * Create a new pointer object - * ----------------------------------------------------------------------------- */ - -/* - Create a new instance object, whitout calling __init__, and set the - 'this' attribute. -*/ - -SWIGRUNTIME PyObject* -SWIG_Python_NewShadowInstance(PySwigClientData *data, PyObject *swig_this) -{ -#if (PY_VERSION_HEX >= 0x02020000) - PyObject *inst = 0; - PyObject *newraw = data->newraw; - if (newraw) { - inst = PyObject_Call(newraw, data->newargs, NULL); - if (inst) { -#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - PyDict_SetItem(dict, SWIG_This(), swig_this); - } - } -#else - PyObject *key = SWIG_This(); - PyObject_SetAttr(inst, key, swig_this); -#endif - } - } else { - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); - } - return inst; -#else - PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); - if (inst == NULL) { - return NULL; - } - inst->in_class = (PyClassObject *)data->newargs; - Py_INCREF(inst->in_class); - inst->in_dict = PyDict_New(); - if (inst->in_dict == NULL) { - Py_DECREF(inst); - return NULL; - } - PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); - return (PyObject *) inst; -#endif -} - -/* Create a new pointer object */ - -SWIGRUNTIME PyObject * -SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { - if (!ptr) { - return SWIG_Py_Void(); - } else { - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - PyObject *robj = PySwigObject_New(ptr, type, own); - PySwigClientData *clientdata = type ? (PySwigClientData *)(type->clientdata) : 0; - if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { - PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); - if (inst) { - Py_DECREF(robj); - robj = inst; - } - } - return robj; - } -} - -/* Create a new packed object */ - -SWIGRUNTIMEINLINE PyObject * -SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { - return ptr ? PySwigPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); -} - -/* -----------------------------------------------------------------------------* - * Get type list - * -----------------------------------------------------------------------------*/ - -#ifdef SWIG_LINK_RUNTIME -void *SWIG_ReturnGlobalTypeList(void *); -#endif - -SWIGRUNTIME swig_module_info * -SWIG_Python_GetModule(void) { - static void *type_pointer = (void *)0; - /* first check if module already created */ - if (!type_pointer) { -#ifdef SWIG_LINK_RUNTIME - type_pointer = SWIG_ReturnGlobalTypeList((void *)0); -#else - type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); - if (PyErr_Occurred()) { - PyErr_Clear(); - type_pointer = (void *)0; - } -#endif - } - return (swig_module_info *) type_pointer; -} - -#if PY_MAJOR_VERSION < 2 -/* PyModule_AddObject function was introduced in Python 2.0. The following function - is copied out of Python/modsupport.c in python version 2.3.4 */ -SWIGINTERN int -PyModule_AddObject(PyObject *m, char *name, PyObject *o) -{ - PyObject *dict; - if (!PyModule_Check(m)) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs module as first arg"); - return SWIG_ERROR; - } - if (!o) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs non-NULL value"); - return SWIG_ERROR; - } - - dict = PyModule_GetDict(m); - if (dict == NULL) { - /* Internal error -- modules must have a dict! */ - PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", - PyModule_GetName(m)); - return SWIG_ERROR; - } - if (PyDict_SetItemString(dict, name, o)) - return SWIG_ERROR; - Py_DECREF(o); - return SWIG_OK; -} -#endif - -SWIGRUNTIME void -SWIG_Python_DestroyModule(void *vptr) -{ - swig_module_info *swig_module = (swig_module_info *) vptr; - swig_type_info **types = swig_module->types; - size_t i; - for (i =0; i < swig_module->size; ++i) { - swig_type_info *ty = types[i]; - if (ty->owndata) { - PySwigClientData *data = (PySwigClientData *) ty->clientdata; - if (data) PySwigClientData_Del(data); - ty->clientdata = 0; - } - } - Py_DECREF(SWIG_This()); -} - -SWIGRUNTIME void -SWIG_Python_SetModule(swig_module_info *swig_module) { - static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ - - PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - swig_empty_runtime_method_table); - PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); - if (pointer && module) { - PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); - } else { - Py_XDECREF(pointer); - } -} - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - -/* -----------------------------------------------------------------------------* - Standard SWIG API for use inside user code. - - Don't include this file directly, run the command - swig -python -external-runtime - Also, read the Modules chapter of the SWIG Manual. - - * -----------------------------------------------------------------------------*/ - -#ifdef SWIG_MODULE_CLIENTDATA_TYPE - -SWIGRUNTIMEINLINE swig_type_info * -SWIG_TypeQuery(SWIG_MODULE_CLIENTDATA_TYPE clientdata, const char *name) { - swig_module_info *module = SWIG_GetModule(clientdata); - return SWIG_TypeQueryModule(module, module, name); -} - -SWIGRUNTIMEINLINE swig_type_info * -SWIG_MangledTypeQuery(SWIG_MODULE_CLIENTDATA_TYPE clientdata, const char *name) { - swig_module_info *module = SWIG_GetModule(clientdata); - return SWIG_MangledTypeQueryModule(module, module, name); -} - -#else - -SWIGRUNTIMEINLINE swig_type_info * -SWIG_TypeQuery(const char *name) { - swig_module_info *module = SWIG_GetModule(NULL); - return SWIG_TypeQueryModule(module, module, name); -} - -SWIGRUNTIMEINLINE swig_type_info * -SWIG_MangledTypeQuery(const char *name) { - swig_module_info *module = SWIG_GetModule(NULL); - return SWIG_MangledTypeQueryModule(module, module, name); -} - -#endif - -""" From 73d24ca59e3a714a934d02058e9411ebda906e59 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 00:51:32 +0000 Subject: [PATCH 011/203] Fix html errors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11904 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Typemaps.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 14623b37d..c815b31d0 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -34,7 +34,7 @@
  • Typedef reductions
  • Default typemaps
  • Mixed default typemaps -
  • Multi-arguments typemaps +
  • Multi-arguments typemaps
  • Debugging typemap pattern matching
  • Code generation rules @@ -1406,7 +1406,7 @@ Expect to see them being used more and more within the various libraries in late

    -

    10.3.5 Multi-arguments typemaps

    +

    10.3.5 Multi-arguments typemaps

    @@ -1543,7 +1543,7 @@ SWIGINTERN PyObject *_wrap_foo(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {

    Searches for multi-argument typemaps are not mentioned unless a matching multi-argument typemap does actually exist. -For example, the output for the code in the previous section is as follows: +For example, the output for the code in the previous section is as follows:

    @@ -1623,6 +1623,8 @@ example.i:21: Typemap for void set_value (out) : %typemap(out) void

    The following observations about what is displayed can be noted (the same applies for -debug-tmsearch): +

    +
    • The relevant typemap is shown, but for typemap copying, the appropriate %typemap or %apply is displayed, for example, the "check" and "in" typemaps.
    • @@ -1633,7 +1635,7 @@ The typemap modifiers are not shown, eg the noblock=1 modifier in the " The exact %apply statement might look different to what is in the actual code. For example, the const char* another_value is not shown as it is not relevant here. Also the types may be displayed slightly differently - char const * and not const char*. -

      +

    10.4 Code generation rules

    From 51d433ee0ab0f677bbf20b4321369b82e3c91f02 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 19:09:10 +0000 Subject: [PATCH 012/203] fix nspace error message for Java git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11919 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/java.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 1bb9532ee..50b80dc8b 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1199,7 +1199,7 @@ public: full_imclass_name = NewStringf("%s.%s", package, imclass_name); } else { full_imclass_name = NewStringf("%s", imclass_name); - Printf(stderr, "The nspace feature used on %s is not supported unless a package is specified with -package - Java does not support types declared in the unnamed package accessing types declared in a package.\n", Getattr(n, "name")); + Printf(stderr, "The nspace feature used on %s is not supported unless a package is specified with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.\n", Getattr(n, "name")); SWIG_exit(EXIT_FAILURE); } } @@ -1832,7 +1832,7 @@ public: } else { full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); full_imclass_name = NewStringf("%s", imclass_name); - Printf(stderr, "The nspace feature used on %s is not supported unless a package is specified with -package - Java does not support types declared in the unnamed package accessing types declared in a package.\n", Getattr(n, "name")); + Printf(stderr, "The nspace feature used on %s is not supported unless a package is specified with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.\n", Getattr(n, "name")); SWIG_exit(EXIT_FAILURE); } } From b6b99bb1486d9709378bd37333c4c930affe5ad3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 19:11:32 +0000 Subject: [PATCH 013/203] Add nspace feature for C# and add documentation on nspace git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11920 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 + Doc/Manual/CSharp.html | 5 + Doc/Manual/Contents.html | 9 +- Doc/Manual/Java.html | 13 +- Doc/Manual/SWIGPlus.html | 96 +++++++- Examples/test-suite/csharp/Makefile.in | 4 +- Examples/test-suite/csharp/nspace_runme.cs | 60 +++++ Lib/swig.swg | 5 + Source/Modules/csharp.cxx | 263 +++++++++++++++------ 9 files changed, 371 insertions(+), 87 deletions(-) create mode 100644 Examples/test-suite/csharp/nspace_runme.cs diff --git a/CHANGES.current b/CHANGES.current index ec0473bee..1e9704783 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-03-06: wsfulton + [C#] Added the nspace feature for C#. Documentation for the nspace feature is now available. + 2010-03-04: wsfulton Added the nspace feature. This adds some improved namespace support. Currently only Java is supported for target languages, where C++ namespaces are automatically translated into diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 324be63ec..3281bc268 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -102,6 +102,11 @@ namespace com.bloggs.widget { Note that by default, the generated C# classes have no namespace and the module name is unrelated to namespaces. The module name is just like in Java and is merely used to name some of the generated classes.
  • +
  • +The nspace feature is also supported as described in this general section with a C# example. +Unlike Java which requires the use of the -package option when using the nspace feature, the -namespace option is not mandatory for C#. +
  • +
  • The -dllimport <name> commandline option specifies the name of the DLL for the DllImport attribute for every PInvoke method. If this commandline option is not given, the DllImport DLL name is the same as the module name. This option is useful for when one wants to invoke SWIG multiple times on different modules, yet compile all the resulting code into a single DLL.
  • diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 0cda0b8f4..266d8210c 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -229,7 +229,10 @@
  • Wrapping overloaded operators
  • Class extension
  • Templates -
  • Namespaces +
  • Namespaces +
  • Renaming templated types in namespaces
  • Exception specifications
  • Exception handling with %catches @@ -237,7 +240,7 @@
  • Smart pointers and operator->()
  • Using declarations and inheritance
  • Nested classes -
  • A brief rant about const-correctness +
  • A brief rant about const-correctness
  • Where to go for more information @@ -349,7 +352,7 @@
  • Typedef reductions
  • Default typemaps
  • Mixed default typemaps -
  • Multi-arguments typemaps +
  • Multi-arguments typemaps
  • Debugging typemap pattern matching
  • Code generation rules diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 7869c5269..7ae802998 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -1852,7 +1852,9 @@ Further details on default arguments and how to restore this approach are given

    -SWIG is aware of C++ namespaces, but namespace names do not appear in +SWIG is aware of named C++ namespaces and they can be mapped to Java packages, however, +the default wrapping flattens the namespaces, effectively ignoring them. +So by default, the namespace names do not appear in the module nor do namespaces result in a module that is broken up into submodules or packages. For example, if you have a file like this,

    @@ -1908,6 +1910,15 @@ symbols separate, consider wrapping them as separate SWIG modules. Each SWIG module can be placed into a separate package.

    +

    +The default behaviour described above can be improved via the nspace feature. +Note that it only works for classes, structs, unions and enums declared within a named C++ namespace. +When the nspace feature is used, the C++ namespaces are converted into Java packages of the same name. +Proxy classes are thus declared within a package and this proxy makes numerous calls to the JNI intermediary class which is declared in the unnamed package by default. +As Java does not support types declared in a named package accessing types declared in an unnamed package, the -package commandline option described earlier must be used to provide a parent package. +So if SWIG is run using the -package com.myco option, a wrapped class, MyWorld::Material::Color, can then be accessed as com.myco.MyWorld.Material.Color. +

    +

    21.3.14 C++ templates

    diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index d1498224f..bcded9166 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -48,7 +48,10 @@
  • Wrapping overloaded operators
  • Class extension
  • Templates -
  • Namespaces +
  • Namespaces +
  • Renaming templated types in namespaces
  • Exception specifications
  • Exception handling with %catches @@ -3647,12 +3650,16 @@ as the class name. For example: Similar changes apply to typemaps and other customization features.

    -

    6.19 Namespaces

    +

    6.19 Namespaces

    -Support for C++ namespaces is a relatively late addition to SWIG, -first appearing in SWIG-1.3.12. Before describing the implementation, +Support for C++ namespaces is comprehensive, but by default simple, however, +some target languages can turn on more advanced namespace support via the +nspace feature, described later. +Code within unnamed namespaces is ignored as there is no external +access to symbols declared within the unnamed namespace. +Before detailing the default implementation for named namespaces, it is worth noting that the semantics of C++ namespaces is extremely non-trivial--especially with regard to the C++ type system and class machinery. At a most basic level, namespaces are sometimes used to @@ -4092,6 +4099,87 @@ with any namespace awareness. In the future, language modules may or may not p more advanced namespace support.

    +

    6.19.1 The nspace feature for namespaces

    + + +

    +Some target languages provide support for the nspace feature. +The feature can be applied to any class, struct, union or enum declared within a named namespace. +The feature wraps the type within the target language specific concept of a namespace, +for example, a Java package or C# namespace. +Please see the language specific sections to see if the target language you are interested in supports the nspace feature. +

    + +

    +The feature is demonstrated below for C# using the following example: +

    + +
    +
    +%feature("nspace") MyWorld::Material::Color;
    +%nspace MyWorld::Wrapping::Color; // %nspace is a macro for %feature("nspace")
    +
    +namespace MyWorld {
    +  namespace Material {
    +    class Color {
    +    ...
    +    };
    +  }
    +  namespace Wrapping {
    +    class Color {
    +    ...
    +    };
    +  }
    +}
    +
    +
    + +

    +Without the nspace feature directives above or %rename, you would get the following warning resulting in just one of the Color classes being available for use from the target language: +

    + +
    +
    +example.i:9: Error: 'Color' is multiply defined in the generated target language module.
    +example.i:5: Error: Previous declaration of 'Color'
    +
    +
    + +

    +With the nspace feature the two Color classes are wrapped into the equivalent C# namespaces. +A fully qualified constructor call of each these two types in C# is then: +

    + +
    +
    +MyWorld.Material.Color materialColor = new MyWorld.Material.Color();
    +MyWorld.Wrapping.Color wrappingColor = new MyWorld.Wrapping.Color();
    +
    +
    + +

    +Note that the nspace feature does not apply to variables and functions simply declared in a namespace. For example, the following symbols cannot co-exist in the target language without renaming. This may change in a future version. +

    + +
    +
    +namespace MyWorld {
    +  namespace Material {
    +    int quantity;
    +    void dispatch();
    +  }
    +  namespace Wrapping {
    +    int quantity;
    +    void dispatch();
    +  }
    +}
    +
    +
    + +

    +Compatibility Note: The nspace feature was first introduced in SWIG-2.0.0. +

    +

    6.20 Renaming templated types in namespaces

    diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 1545eb30d..0f44b3335 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -70,13 +70,13 @@ run_testcase = \ $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` \ - $*$(CSHARPPATHSEPARATOR)*.cs' csharp_compile && \ + `find $* -name "*.cs"`' csharp_compile && \ env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ else \ cd $* && \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -t:module -out:$*.netmodule' \ - CSHARPSRCS='*.cs' csharp_compile && cd .. ; \ + CSHARPSRCS='`find . -name "*.cs"`' csharp_compile && cd .. ; \ fi # Clean: remove testcase directories diff --git a/Examples/test-suite/csharp/nspace_runme.cs b/Examples/test-suite/csharp/nspace_runme.cs new file mode 100644 index 000000000..91baf6a0f --- /dev/null +++ b/Examples/test-suite/csharp/nspace_runme.cs @@ -0,0 +1,60 @@ +using System; + +public class runme +{ + static void Main() + { + // constructors and destructors + nspaceNamespace.Outer.Inner1.Color color1 = new nspaceNamespace.Outer.Inner1.Color(); + nspaceNamespace.Outer.Inner1.Color color = new nspaceNamespace.Outer.Inner1.Color(color1); + color1.Dispose(); + color1 = null; + + // class methods + color.colorInstanceMethod(20.0); + nspaceNamespace.Outer.Inner1.Color.colorStaticMethod(20.0); + nspaceNamespace.Outer.Inner1.Color created = nspaceNamespace.Outer.Inner1.Color.create(); + created.Dispose(); + + // class enums + nspaceNamespace.Outer.SomeClass someClass = new nspaceNamespace.Outer.SomeClass(); + nspaceNamespace.Outer.Inner1.Color.Channel channel = someClass.GetInner1ColorChannel(); + if (channel != nspaceNamespace.Outer.Inner1.Color.Channel.Transmission) + throw new ApplicationException("Transmission wrong"); + + // static member variables + nspaceNamespace.Outer.Inner1.Color.staticMemberVariable = 789; + if (nspaceNamespace.Outer.Inner1.Color.staticMemberVariable != 789) + throw new ApplicationException("static member variable failed"); + + // instance member variables + color.instanceMemberVariable = 123; + if (color.instanceMemberVariable != 123) + throw new ApplicationException("instance member variable failed"); + + // check globals in a namespace don't get mangled with the nspaceNamespace option + nspaceNamespace.nspace.namespaceFunction(color); + nspaceNamespace.nspace.namespaceVar = 111; + if (nspaceNamespace.nspace.namespaceVar != 111) + throw new ApplicationException("global var failed"); + + // Same class different namespaces + nspaceNamespace.Outer.Inner1.Color col1 = new nspaceNamespace.Outer.Inner1.Color(); + nspaceNamespace.Outer.Inner2.Color col2 = nspaceNamespace.Outer.Inner2.Color.create(); + col2.colors(col1, col1, col2, col2, col2); + + // global enums + nspaceNamespace.Outer.Inner1.Channel outerChannel1 = someClass.GetInner1Channel(); + if (outerChannel1 != nspaceNamespace.Outer.Inner1.Channel.Transmission1) + throw new ApplicationException("Transmission1 wrong"); + nspaceNamespace.Outer.Inner2.Channel outerChannel2 = someClass.GetInner2Channel(); + if (outerChannel2 != nspaceNamespace.Outer.Inner2.Channel.Transmission2) + throw new ApplicationException("Transmission2 wrong"); + + // turn feature off / ignoring + nspaceNamespace.Outer.nspace ns = new nspaceNamespace.Outer.nspace(); + ns.Dispose(); + nspaceNamespace.NoNSpacePlease nons = new nspaceNamespace.NoNSpacePlease(); + nons.Dispose(); + } +} diff --git a/Lib/swig.swg b/Lib/swig.swg index af7fa6a30..ec903533c 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -156,6 +156,11 @@ #define %nonaturalvar %feature("naturalvar","0") #define %clearnaturalvar %feature("naturalvar","") +/* nspace directives */ +#define %nspace %feature("nspace") +#define %nonspace %feature("nspace","0") +#define %clearnspace %feature("nspace","") + /* valuewrapper directives */ #define %valuewrapper %feature("valuewrapper") #define %clearvaluewrapper %feature("valuewrapper","") diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 6d3d09ea4..0dbed4d1e 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -54,7 +54,9 @@ class CSHARP:public Language { String *proxy_class_def; String *proxy_class_code; String *module_class_code; - String *proxy_class_name; + String *proxy_class_name; // proxy class name + String *full_proxy_class_name;// fully qualified proxy class name when using nspace feature, otherwise same as proxy_class_name + String *full_imclass_name; // fully qualified intermediary class name when using nspace feature, otherwise same as imclass_name String *variable_name; //Name of a variable being wrapped String *proxy_class_constants_code; String *module_class_constants_code; @@ -125,6 +127,8 @@ public: proxy_class_code(NULL), module_class_code(NULL), proxy_class_name(NULL), + full_proxy_class_name(NULL), + full_imclass_name(NULL), variable_name(NULL), proxy_class_constants_code(NULL), module_class_constants_code(NULL), @@ -163,18 +167,34 @@ public: * getProxyName() * * Test to see if a type corresponds to something wrapped with a proxy class. - * Return NULL if not otherwise the proxy class name + * Return NULL if not otherwise the proxy class name, fully qualified with + * a namespace if the nspace feature is used. * ----------------------------------------------------------------------------- */ String *getProxyName(SwigType *t) { - if (proxy_flag) { - Node *n = classLookup(t); - if (n) { - return Getattr(n, "sym:name"); - } - } - return NULL; - } + String *proxyname = NULL; + if (proxy_flag) { + Node *n = classLookup(t); + if (n) { + proxyname = Getattr(n, "proxyname"); + if (!proxyname) { + String *nspace = Getattr(n, "sym:nspace"); + String *symname = Getattr(n, "sym:name"); + if (nspace) { + if (Len(namespce) > 0) + proxyname = NewStringf("%s.%s.%s", namespce, nspace, symname); + else + proxyname = NewStringf("%s.%s", nspace, symname); + } else { + proxyname = Copy(symname); + } + Setattr(n, "proxyname", proxyname); + Delete(proxyname); + } + } + } + return proxyname; + } /* ----------------------------------------------------------------------------- * directorClassName() @@ -419,7 +439,7 @@ public: // Start writing out the intermediary class file emitBanner(f_im); - addOpenNamespace(namespce, f_im); + addOpenNamespace(namespce, 0, f_im); if (imclass_imports) Printf(f_im, "%s\n", imclass_imports); @@ -443,7 +463,7 @@ public: // Finish off the class Printf(f_im, "}\n"); - addCloseNamespace(namespce, f_im); + addCloseNamespace(namespce, 0, f_im); Close(f_im); } @@ -463,7 +483,7 @@ public: // Start writing out the module class file emitBanner(f_module); - addOpenNamespace(namespce, f_module); + addOpenNamespace(namespce, 0, f_module); if (module_imports) Printf(f_module, "%s\n", module_imports); @@ -495,7 +515,7 @@ public: // Finish off the class Printf(f_module, "}\n"); - addCloseNamespace(namespce, f_module); + addCloseNamespace(namespce, 0, f_module); Close(f_module); } @@ -1033,7 +1053,7 @@ public: */ if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Capitalize the first letter in the variable in the getter/setter function name - bool getter_flag = Cmp(symname, Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, proxy_class_name, variable_name))) != 0; + bool getter_flag = Cmp(symname, Swig_name_set(getNSpace(), Swig_name_member(0, proxy_class_name, variable_name))) != 0; String *getter_setter_name = NewString(""); if (!getter_flag) @@ -1106,6 +1126,22 @@ public: if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (proxy_flag && !is_wrapping_class()) { + // Global enums / enums in a namespace + String *nspace = Getattr(n, "sym:nspace"); + assert(!full_imclass_name); + + if (!nspace) { + full_imclass_name = NewStringf("%s", imclass_name); + } else { + if (Len(namespce) > 0) { + full_imclass_name = NewStringf("%s.%s", namespce, imclass_name); + } else { + full_imclass_name = NewStringf("%s", imclass_name); + } + } + } + enum_code = NewString(""); String *symname = Getattr(n, "sym:name"); String *constants_code = (proxy_flag && is_wrapping_class())? proxy_class_constants_code : module_class_constants_code; @@ -1163,7 +1199,9 @@ public: Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL); } else { // Global enums are defined in their own file - String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), symname); + String *nspace = Getattr(n, "sym:nspace"); + String *output_directory = outputDirectory(nspace); + String *filen = NewStringf("%s%s.cs", output_directory, symname); File *f_enum = NewFile(filen, "w", SWIG_output_files()); if (!f_enum) { FileErrorDisplay(filen); @@ -1176,14 +1214,14 @@ public: // Start writing out the enum file emitBanner(f_enum); - addOpenNamespace(namespce, f_enum); + addOpenNamespace(namespce, nspace, f_enum); Printv(f_enum, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements "\n", enum_code, "\n", NIL); - addCloseNamespace(namespce, f_enum); - + addCloseNamespace(namespce, nspace, f_enum); Close(f_enum); + Delete(output_directory); } } else { // Wrap C++ enum with simple constant @@ -1196,6 +1234,11 @@ public: Delete(enum_code); enum_code = NULL; + + if (proxy_flag && !is_wrapping_class()) { + Delete(full_imclass_name); + full_imclass_name = 0; + } } return SWIG_OK; } @@ -1381,13 +1424,13 @@ public: if (classname_substituted_flag) { if (SwigType_isenum(t)) { // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) - Printf(constants_code, "(%s)%s.%s();\n", return_type, imclass_name, Swig_name_get(NSPACE_TODO, symname)); + Printf(constants_code, "(%s)%s.%s();\n", return_type, imclass_name, Swig_name_get(getNSpace(), symname)); } else { // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(NSPACE_TODO, symname)); + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(getNSpace(), symname)); } } else - Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(NSPACE_TODO, symname)); + Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(getNSpace(), symname)); // Each constant and enum value is wrapped with a separate PInvoke function call SetFlag(n, "feature:immutable"); @@ -1641,7 +1684,8 @@ public: Printf(proxy_class_code, " if (SwigDerivedClassHasMethod(\"%s\", swigMethodTypes%s))\n", method, methid); Printf(proxy_class_code, " swigDelegate%s = new SwigDelegate%s_%s(SwigDirector%s);\n", methid, proxy_class_name, methid, overname); } - Printf(proxy_class_code, " %s.%s_director_connect(swigCPtr", imclass_name, proxy_class_name); + String *director_connect_method_name = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); + Printf(proxy_class_code, " %s.%s(swigCPtr", imclass_name, director_connect_method_name); for (i = first_class_dmethod; i < curr_class_dmethod; ++i) { UpcallData *udata = Getitem(dmethods_seq, i); String *methid = Getattr(udata, "class_methodidx"); @@ -1703,6 +1747,7 @@ public: director_method_types = NULL; Delete(director_connect_parms); director_connect_parms = NULL; + Delete(director_connect_method_name); } Delete(attributes); @@ -1719,8 +1764,8 @@ public: Replaceall(proxy_class_def, "$module", module_class_name); Replaceall(proxy_class_code, "$module", module_class_name); - Replaceall(proxy_class_def, "$imclassname", imclass_name); - Replaceall(proxy_class_code, "$imclassname", imclass_name); + Replaceall(proxy_class_def, "$imclassname", full_imclass_name); + Replaceall(proxy_class_code, "$imclassname", full_imclass_name); Replaceall(proxy_class_def, "$dllimport", dllimport); Replaceall(proxy_class_code, "$dllimport", dllimport); @@ -1749,24 +1794,38 @@ public: virtual int classHandler(Node *n) { + String *nspace = getNSpace(); File *f_proxy = NULL; if (proxy_flag) { proxy_class_name = NewString(Getattr(n, "sym:name")); - if (!addSymbol(proxy_class_name, n)) + if (!nspace) { + full_proxy_class_name = NewStringf("%s", proxy_class_name); + full_imclass_name = NewStringf("%s", imclass_name); + if (Cmp(proxy_class_name, imclass_name) == 0) { + Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); + } + + if (Cmp(proxy_class_name, module_class_name) == 0) { + Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); + } + } else { + if (Len(namespce) > 0) { + full_proxy_class_name = NewStringf("%s.%s.%s", namespce, nspace, proxy_class_name); + full_imclass_name = NewStringf("%s.%s", namespce, imclass_name); + } else { + full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); + full_imclass_name = NewStringf("%s", imclass_name); + } + } + + if (!addSymbol(proxy_class_name, n, nspace)) return SWIG_ERROR; - if (Cmp(proxy_class_name, imclass_name) == 0) { - Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); - SWIG_exit(EXIT_FAILURE); - } - - if (Cmp(proxy_class_name, module_class_name) == 0) { - Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); - SWIG_exit(EXIT_FAILURE); - } - - String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), proxy_class_name); + String *output_directory = outputDirectory(nspace); + String *filen = NewStringf("%s%s.cs", output_directory, proxy_class_name); f_proxy = NewFile(filen, "w", SWIG_output_files()); if (!f_proxy) { FileErrorDisplay(filen); @@ -1779,7 +1838,7 @@ public: // Start writing out the proxy class file emitBanner(f_proxy); - addOpenNamespace(namespce, f_proxy); + addOpenNamespace(namespce, nspace, f_proxy); Clear(proxy_class_def); Clear(proxy_class_code); @@ -1797,9 +1856,9 @@ public: Replaceall(proxy_class_def, "$module", module_class_name); Replaceall(proxy_class_code, "$module", module_class_name); Replaceall(proxy_class_constants_code, "$module", module_class_name); - Replaceall(proxy_class_def, "$imclassname", imclass_name); - Replaceall(proxy_class_code, "$imclassname", imclass_name); - Replaceall(proxy_class_constants_code, "$imclassname", imclass_name); + Replaceall(proxy_class_def, "$imclassname", full_imclass_name); + Replaceall(proxy_class_code, "$imclassname", full_imclass_name); + Replaceall(proxy_class_constants_code, "$imclassname", full_imclass_name); Replaceall(proxy_class_def, "$dllimport", dllimport); Replaceall(proxy_class_code, "$dllimport", dllimport); Replaceall(proxy_class_constants_code, "$dllimport", dllimport); @@ -1811,7 +1870,7 @@ public: Printv(f_proxy, proxy_class_constants_code, NIL); Printf(f_proxy, "}\n"); - addCloseNamespace(namespce, f_proxy); + addCloseNamespace(namespce, nspace, f_proxy); Close(f_proxy); f_proxy = NULL; @@ -1844,6 +1903,10 @@ public: Delete(proxy_class_name); proxy_class_name = NULL; + Delete(full_proxy_class_name); + full_proxy_class_name = NULL; + Delete(full_imclass_name); + full_imclass_name = NULL; Delete(destructor_call); destructor_call = NULL; Delete(proxy_class_constants_code); @@ -1862,7 +1925,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(NSPACE_TODO, proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -1882,7 +1945,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *intermediary_function_name = Swig_name_member(NSPACE_TODO, proxy_class_name, overloaded_name); + String *intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, overloaded_name); Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); @@ -1962,7 +2025,7 @@ public: if (wrapping_member_flag && !enum_constant_flag) { // Properties - setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, proxy_class_name, variable_name))) == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), Swig_name_member(0, proxy_class_name, variable_name))) == 0); if (setter_flag) Swig_typemap_attach_parms("csvarin", l, NULL); } @@ -2005,7 +2068,7 @@ public: Printf(function_code, "static "); Printf(function_code, "%s %s(", return_type, proxy_function_name); - Printv(imcall, imclass_name, ".$imfuncname(", NIL); + Printv(imcall, full_imclass_name, ".$imfuncname(", NIL); if (!static_flag) Printf(imcall, "swigCPtr"); @@ -2132,7 +2195,7 @@ public: Node *explicit_n = Getattr(n, "explicitcallnode"); if (explicit_n) { String *ex_overloaded_name = getOverloadedName(explicit_n); - String *ex_intermediary_function_name = Swig_name_member(NSPACE_TODO, proxy_class_name, ex_overloaded_name); + String *ex_intermediary_function_name = Swig_name_member(getNSpace(), proxy_class_name, ex_overloaded_name); String *ex_imcall = Copy(imcall); Replaceall(ex_imcall, "$imfuncname", ex_intermediary_function_name); @@ -2250,7 +2313,7 @@ public: if (proxy_flag) { String *overloaded_name = getOverloadedName(n); - String *mangled_overname = Swig_name_construct(NSPACE_TODO, overloaded_name); + String *mangled_overname = Swig_name_construct(getNSpace(), overloaded_name); String *imcall = NewString(""); const String *csattributes = Getattr(n, "feature:cs:attributes"); @@ -2270,7 +2333,7 @@ public: Printf(function_code, " %s %s(", methodmods, proxy_class_name); Printf(helper_code, " static private %s SwigConstruct%s(", im_return_type, proxy_class_name); - Printv(imcall, imclass_name, ".", mangled_overname, "(", NIL); + Printv(imcall, full_imclass_name, ".", mangled_overname, "(", NIL); /* Attach the non-standard typemaps to the parameter list */ Swig_typemap_attach_parms("in", l, NULL); @@ -2451,7 +2514,7 @@ public: String *symname = Getattr(n, "sym:name"); if (proxy_flag) { - Printv(destructor_call, imclass_name, ".", Swig_name_destroy(NSPACE_TODO, symname), "(swigCPtr)", NIL); + Printv(destructor_call, full_imclass_name, ".", Swig_name_destroy(getNSpace(), symname), "(swigCPtr)", NIL); } return SWIG_OK; } @@ -2577,7 +2640,7 @@ public: if (proxy_flag && global_variable_flag) { // Capitalize the first letter in the variable to create the getter/setter function name func_name = NewString(""); - setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(NSPACE_TODO, variable_name)) == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), variable_name)) == 0); if (setter_flag) Printf(func_name, "set"); else @@ -2848,10 +2911,10 @@ public: // Strange hack to change the name Setattr(n, "name", Getattr(n, "value")); /* for wrapping of enums in a namespace when emit_action is used */ constantWrapper(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(NSPACE_TODO, symname)); + value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); } else { memberconstantHandler(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, proxy_class_name, symname))); + value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), Swig_name_member(getNSpace(), proxy_class_name, symname))); } } } @@ -2863,26 +2926,41 @@ public: * ----------------------------------------------------------------------------- */ String *getEnumName(SwigType *t) { - Node *enum_name = NULL; + Node *enumname = NULL; Node *n = enumLookup(t); if (n) { - String *symname = Getattr(n, "sym:name"); - if (symname) { - // Add in class scope when referencing enum if not a global enum - String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); - String *proxyname = 0; - if (scopename_prefix) { - proxyname = getProxyName(scopename_prefix); + enumname = Getattr(n, "enumname"); + if (!enumname) { + String *symname = Getattr(n, "sym:name"); + if (symname) { + // Add in class scope when referencing enum if not a global enum + String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); + String *proxyname = 0; + if (scopename_prefix) { + proxyname = getProxyName(scopename_prefix); + } + if (proxyname) { + enumname = NewStringf("%s.%s", proxyname, symname); + } else { + // global enum or enum in a namespace + String *nspace = Getattr(n, "sym:nspace"); + if (nspace) { + if (Len(namespce) > 0) + enumname = NewStringf("%s.%s.%s", namespce, nspace, symname); + else + enumname = NewStringf("%s.%s", nspace, symname); + } else { + enumname = Copy(symname); + } + } + Setattr(n, "enumname", enumname); + Delete(enumname); + Delete(scopename_prefix); } - if (proxyname) - enum_name = NewStringf("%s.%s", proxyname, symname); - else - enum_name = NewStringf("%s", symname); - Delete(scopename_prefix); } } - return enum_name; + return enumname; } /* ----------------------------------------------------------------------------- @@ -3019,7 +3097,7 @@ public: // Start writing out the type wrapper class file emitBanner(f_swigtype); - addOpenNamespace(namespce, f_swigtype); + addOpenNamespace(namespce, 0, f_swigtype); // Pure C# baseclass and interfaces const String *pure_baseclass = typemapLookup(n, "csbase", type, WARN_NONE); @@ -3048,7 +3126,7 @@ public: Printv(f_swigtype, swigtype, NIL); - addCloseNamespace(namespce, f_swigtype); + addCloseNamespace(namespce, 0, f_swigtype); Close(f_swigtype); Delete(swigtype); @@ -3123,22 +3201,53 @@ public: * addOpenNamespace() * ----------------------------------------------------------------------------- */ - void addOpenNamespace(String *namspace, File *file) { - if (namspace) - if (Len(namspace) > 0) - Printf(file, "namespace %s {\n", namspace); + void addOpenNamespace(const String *namspace, const String *nspace, File *file) { + if (namspace) { + if (Len(namspace) > 0 || nspace) { + Printf(file, "namespace "); + if (Len(namspace) > 0) + Printv(file, namspace, nspace ? "." : "", NIL); + if (nspace) + Printv(file, nspace, NIL); + Printf(file, " {\n"); + } + } } /* ----------------------------------------------------------------------------- * addCloseNamespace() * ----------------------------------------------------------------------------- */ - void addCloseNamespace(String *namspace, File *file) { + void addCloseNamespace(const String *namspace, const String *nspace, File *file) { if (namspace) - if (Len(namspace) > 0) + if (Len(namspace) > 0 || nspace) Printf(file, "\n}\n"); } + /* ----------------------------------------------------------------------------- + * outputDirectory() + * + * Return the directory to use for generating Java classes/enums and create the + * subdirectory (does not create if language specific outdir does not exist). + * ----------------------------------------------------------------------------- */ + + String *outputDirectory(String *nspace) { + String *output_directory = Copy(SWIG_output_directory()); + if (nspace) { + String *nspace_subdirectory = Copy(nspace); + Replaceall(nspace_subdirectory, ".", SWIG_FILE_DELIMITER); + String *newdir_error = Swig_new_subdirectory(output_directory, nspace_subdirectory); + if (newdir_error) { + Printf(stderr, "%s\n", newdir_error); + Delete(newdir_error); + SWIG_exit(EXIT_FAILURE); + } + Printv(output_directory, nspace_subdirectory, SWIG_FILE_DELIMITER, 0); + Delete(nspace_subdirectory); + } + return output_directory; + } + /*---------------------------------------------------------------------- * Start of director methods *--------------------------------------------------------------------*/ @@ -3189,7 +3298,7 @@ public: // Output the director connect method: String *norm_name = SwigType_namestr(Getattr(n, "name")); - String *swig_director_connect = NewStringf("%s_director_connect", proxy_class_name); + String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); String *sym_name = Getattr(n, "sym:name"); Wrapper *code_wrap; @@ -3279,7 +3388,7 @@ public: // we're consistent with the sym:overload name in functionWrapper. (?? when // does the overloaded method name get set?) - imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(NSPACE_TODO, classname, overloaded_name)); + imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name)); if (returntype) { From 9006dc90ce5c87b384e14929d155adecaa9b5a46 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 19:35:25 +0000 Subject: [PATCH 014/203] Correctly mangle the html section names to prevent name clashes in the pdf document git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11921 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/CSharp.html | 6 +++--- Doc/Manual/Chicken.html | 12 ++++++------ Doc/Manual/Contents.html | 16 ++++++++-------- Doc/Manual/Customization.html | 18 +++++++++--------- Doc/Manual/Guile.html | 4 ++-- Doc/Manual/Java.html | 6 +++--- Doc/Manual/Library.html | 2 +- Doc/Manual/Lisp.html | 2 +- Doc/Manual/Lua.html | 2 +- Doc/Manual/Modula3.html | 4 ++-- Doc/Manual/Modules.html | 4 ++-- Doc/Manual/Perl5.html | 2 +- Doc/Manual/Ruby.html | 8 ++++---- Doc/Manual/SWIG.html | 4 ++-- Doc/Manual/SWIGPlus.html | 10 +++++----- Doc/Manual/Typemaps.html | 8 ++++---- Doc/Manual/Warnings.html | 2 +- 17 files changed, 55 insertions(+), 55 deletions(-) diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 3281bc268..34d441b35 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -310,7 +310,7 @@ The directorinattributes and directoroutattributes typemap att
  • Support for attaching C# attributes to wrapped methods, variables and enum values. -This is done using the %csattributes feature, see %feature directives. +This is done using the %csattributes feature, see %feature directives. Note that C# attributes are attached to proxy classes and enums using the csattributes typemap. For example, imagine we have a custom attribute class, ThreadSafeAttribute, for labelling thread safety. The following SWIG code shows how to attach this C# attribute to some methods and the class declaration itself: @@ -729,7 +729,7 @@ It is possible to throw a C# Exception from C/C++ code. SWIG already provides the framework for throwing C# exceptions if it is able to detect that a C++ exception could be thrown. Automatically detecting that a C++ exception could be thrown is only possible when a C++ exception specification is used, see Exception specifications. -The Exception handling with %exception section details the %exception feature. +The Exception handling with %exception section details the %exception feature. Customised code for handling exceptions with or without a C++ exception specification is possible and the details follow. However anyone wishing to do this should be familiar with the contents of the sections referred to above.

    @@ -1005,7 +1005,7 @@ Actually it will issue this warning for any function beginning with SWIG_CSh

    Let's consider a similar, but more common example that throws a C++ exception from within a wrapped function. -We can use %exception as mentioned in Exception handling with %exception. +We can use %exception as mentioned in Exception handling with %exception.

    diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html index d1d83aafa..693e08e62 100644 --- a/Doc/Manual/Chicken.html +++ b/Doc/Manual/Chicken.html @@ -35,7 +35,7 @@
  • Typemaps
  • Pointers
  • Unsupported features and known problems
  • -

    18.4.3 C# exception example using exception specifications

    +

    18.4.3 C# exception example using exception specifications

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

    -

    18.4.4 Custom C# ApplicationException example

    +

    18.4.4 Custom C# ApplicationException example

    @@ -1256,7 +1256,7 @@ try { -

    18.5 C# Directors

    +

    18.5 C# Directors

    @@ -1266,10 +1266,10 @@ Essentially, it enables unmanaged C++ code to call back into managed code for vi

    The following sections provide information on the C# director implementation and contain most of the information required to use the C# directors. -However, the Java directors section should also be read in order to gain more insight into directors. +However, the Java directors section should also be read in order to gain more insight into directors.

    -

    18.5.1 Directors example

    +

    18.5.1 Directors example

    @@ -1390,7 +1390,7 @@ CSharpDerived - UIntMethod(123) -

    18.5.2 Directors implementation

    +

    18.5.2 Directors implementation

    @@ -1576,7 +1576,7 @@ void SwigDirector_Base::BaseBoolMethod(Base const &b, bool flag) { -

    18.5.3 Director caveats

    +

    18.5.3 Director caveats

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

    -

    18.6 C# Typemap examples

    +

    18.6 C# Typemap examples

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

    18.6.1 Memory management when returning references to member variables

    +

    18.6.1 Memory management when returning references to member variables

    This example shows how to prevent premature garbage collection of objects when the underlying C++ class returns a pointer or reference to a member variable. -The example is a direct equivalent to this Java equivalent. +The example is a direct equivalent to this Java equivalent.

    @@ -1756,11 +1756,11 @@ public class Bike : IDisposable { Note the addReference call.

    -

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

    +

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

    -The example is a direct equivalent to this Java equivalent. +The example is a direct equivalent to this Java equivalent. Managing memory can be tricky when using C++ and C# proxy classes. The previous example shows one such case and this example looks at memory management for a class passed to a C++ method which expects the object to remain in scope after the function has returned. Consider the following two C++ classes: @@ -1875,14 +1875,14 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class. -

    18.6.3 Date marshalling using the csin typemap and associated attributes

    +

    18.6.3 Date marshalling using the csin typemap and associated attributes

    -The NaN Exception example is a simple example of the "javain" typemap and its 'pre' attribute. +The NaN Exception example is a simple example of the "javain" typemap and its 'pre' attribute. This example demonstrates how a C++ date class, say CDate, can be mapped onto the standard .NET date class, System.DateTime by using the 'pre', 'post' and 'pgcppname' attributes of the "csin" typemap (the C# equivalent to the "javain" typemap). -The example is an equivalent to the Java Date marshalling example. +The example is an equivalent to the Java Date marshalling example. The idea is that the System.DateTime is used wherever the C++ API uses a CDate. Let's assume the code being wrapped is as follows:

    @@ -2159,7 +2159,7 @@ public class example { -

    18.6.4 A date example demonstrating marshalling of C# properties

    +

    18.6.4 A date example demonstrating marshalling of C# properties

    @@ -2260,7 +2260,7 @@ Some points to note: -

    18.6.5 Turning wrapped classes into partial classes

    +

    18.6.5 Turning wrapped classes into partial classes

    @@ -2360,7 +2360,7 @@ demonstrating that the class contains methods calling both unmanaged code - The following example is an alternative approach to adding managed code to the generated proxy class.

    -

    18.6.6 Extending proxy classes with additional C# code

    +

    18.6.6 Extending proxy classes with additional C# code

    diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 6ef9acf89..b5fda3b8d 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -623,35 +623,35 @@

    @@ -735,139 +735,139 @@
    @@ -957,38 +957,38 @@ diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index 2d1486b89..48f1fd476 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -854,7 +854,7 @@ In the following example, MyExceptionClass is the name of the Java clas

    -Further details can be obtained from the Java exception handling section. +Further details can be obtained from the Java exception handling section.

    11.3.2 Feature flags

    diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 5b457030e..902657220 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -9,139 +9,139 @@
    @@ -154,7 +154,7 @@ It covers most SWIG features, but certain low-level details are covered in less

    -

    21.1 Overview

    +

    21.1 Overview

    @@ -181,7 +181,7 @@ However, the "SWIG Basics" chapter will be a useful

    This chapter starts with a few practicalities on running SWIG and compiling the generated code. If you are looking for the minimum amount to read, have a look at the sections up to and including the -tour of basic C/C++ wrapping section which explains how to call the various C/C++ code constructs from Java. +tour of basic C/C++ wrapping section which explains how to call the various C/C++ code constructs from Java. Following this section are details of the C/C++ code and Java classes that SWIG generates. Due to the complexities of C and C++ there are different ways in which C/C++ code could be wrapped and called from Java. SWIG is a powerful tool and the rest of the chapter details how the default code wrapping can be tailored. @@ -189,7 +189,7 @@ Various customisation tips and techniques using SWIG directives are covered. The latter sections cover the advanced techniques of using typemaps for complete control of the wrapping process.

    -

    21.2 Preliminaries

    +

    21.2 Preliminaries

    @@ -205,7 +205,7 @@ Run make -k check from the SWIG root directory after installing SWIG on The Java module requires your system to support shared libraries and dynamic loading. This is the commonly used method to load JNI code so your system will more than likely support this.

    -

    21.2.1 Running SWIG

    +

    21.2.1 Running SWIG

    @@ -254,7 +254,7 @@ It is also possible to change the output directo

    -The module name, specified with %module, determines the name of various generated classes as discussed later. +The module name, specified with %module, determines the name of various generated classes as discussed later. Note that the module name does not define a Java package and by default, the generated Java classes do not have a Java package. The -package option described below can specify a Java package name to use.

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

    -

    21.2.2 Additional Commandline Options

    +

    21.2.2 Additional Commandline Options

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

    -

    21.2.3 Getting the right header files

    +

    21.2.3 Getting the right header files

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

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

    -

    21.2.4 Compiling a dynamic module

    +

    21.2.4 Compiling a dynamic module

    @@ -344,15 +344,15 @@ is a useful reference for compiling on different platforms.

    Important
    If you are going to use optimisations turned on with gcc (for example -O2), ensure you also compile with -fno-strict-aliasing. The GCC optimisations have become -more aggressive from gcc-4.0 onwards and will result in code that fails with strict aliasing optimisations turned on. See the C/C++ to Java typemaps section for more details. +more aggressive from gcc-4.0 onwards and will result in code that fails with strict aliasing optimisations turned on. See the C/C++ to Java typemaps section for more details.

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

    -

    21.2.5 Using your module

    +

    21.2.5 Using your module

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

    -

    21.2.6 Dynamic linking problems

    +

    21.2.6 Dynamic linking problems

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

    -

    21.2.7 Compilation problems and compiling with C++

    +

    21.2.7 Compilation problems and compiling with C++

    @@ -527,7 +527,7 @@ Finally make sure the version of JDK header files matches the version of Java th

    -

    21.2.8 Building on Windows

    +

    21.2.8 Building on Windows

    @@ -536,7 +536,7 @@ You will want to produce a DLL that can be loaded by the Java Virtual Machine. This section covers the process of using SWIG with Microsoft Visual C++ 6 although the procedure may be similar with other compilers. In order for everything to work, you will need to have a JDK installed on your machine in order to read the JNI header files.

    -

    21.2.8.1 Running SWIG from Visual Studio

    +

    21.2.8.1 Running SWIG from Visual Studio

    @@ -572,10 +572,10 @@ When doing a build, any changes made to the interface file will result in SWIG b

    The Java classes that SWIG output should also be compiled into .class files. To run the native code in the DLL (example.dll), make sure that it is in your path then run your Java program which uses it, as described in the previous section. -If the library fails to load have a look at Dynamic linking problems. +If the library fails to load have a look at Dynamic linking problems.

    -

    21.2.8.2 Using NMAKE

    +

    21.2.8.2 Using NMAKE

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

    -

    21.3 A tour of basic C/C++ wrapping

    +

    21.3 A tour of basic C/C++ wrapping

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

    -

    21.3.1 Modules, packages and generated Java classes

    +

    21.3.1 Modules, packages and generated Java classes

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

    -

    21.3.2 Functions

    +

    21.3.2 Functions

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

    21.3.3 Global variables

    +

    21.3.3 Global variables

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

    21.3.4 Constants

    +

    21.3.4 Constants

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

    -

    21.3.5 Enumerations

    +

    21.3.5 Enumerations

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

    -

    21.3.5.1 Anonymous enums

    +

    21.3.5.1 Anonymous enums

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

    -

    21.3.5.2 Typesafe enums

    +

    21.3.5.2 Typesafe enums

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

    -See Typesafe enum classes to see the omitted support methods. +See Typesafe enum classes to see the omitted support methods. Note that the enum item with an initializer (LAGER) is initialized with the enum value obtained via a JNI call. However, as with anonymous enums and constants, use of the %javaconst directive is strongly recommended to change this behaviour:

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

    -

    21.3.5.3 Proper Java enums

    +

    21.3.5.3 Proper Java enums

    @@ -1152,19 +1152,19 @@ public enum Beverage {

    -See Proper Java enum classes to see the omitted support methods. +See Proper Java enum classes to see the omitted support methods. The generated Java enum has numerous additional methods to support enums with initializers, such as LAGER above. Note that as with the typesafe enum pattern, enum items with initializers are by default initialized with the enum value obtained via a JNI call. However, this is not the case above as we have used the recommended %javaconst(1) to avoid the JNI call. -The %javaconstvalue(value) directive covered in the Constants section can also be used for proper Java enums. +The %javaconstvalue(value) directive covered in the Constants section can also be used for proper Java enums.

    The additional support methods need not be generated if none of the enum items have initializers and this is covered later in the -Simpler Java enums for enums without initializers section. +Simpler Java enums for enums without initializers section.

    -

    21.3.5.4 Type unsafe enums

    +

    21.3.5.4 Type unsafe enums

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

    As is the case previously, the default is %javaconst(0) as not all C/C++ values will compile as Java code. However, again it is recommended to add in a %javaconst(1) directive. -and the %javaconstvalue(value) directive covered in the Constants section can also be used for type unsafe enums. +and the %javaconstvalue(value) directive covered in the Constants section can also be used for type unsafe enums. Note that global enums are generated into a Java class within whatever package you are using. C++ enums defined within a C++ class are generated into a static final inner Java class within the Java proxy class.

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

    -

    21.3.5.5 Simple enums

    +

    21.3.5.5 Simple enums

    @@ -1221,7 +1221,7 @@ Each enum item is also wrapped as a static final integer. However, these integers are not generated into a class named after the C/C++ enum. Instead, global enums are generated into the constants interface. Also, enums defined in a C++ class have their enum items generated directly into the Java proxy class rather than an inner class within the Java proxy class. -In fact, this approach is effectively wrapping the enums as if they were anonymous enums and the resulting code is as per anonymous enums. +In fact, this approach is effectively wrapping the enums as if they were anonymous enums and the resulting code is as per anonymous enums. The implementation is in the "enumsimple.swg" file.

    @@ -1231,7 +1231,7 @@ SWIG-1.3.21 and earlier versions wrapped all enums using this approach. The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.

    -

    21.3.6 Pointers

    +

    21.3.6 Pointers

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

    -

    21.3.7 Structures

    +

    21.3.7 Structures

    @@ -1428,8 +1428,8 @@ to by b.x. In this example, 16 integers would be copied. Like C, SWI no assumptions about bounds checking---if you pass a bad pointer, you may get a segmentation fault or access violation. The default wrapping makes it hard to set or get just one element of the array and so array access from Java is somewhat limited. -This can be changed easily though by using the approach outlined later in the Wrapping C arrays with Java arrays and -Unbounded C Arrays sections. +This can be changed easily though by using the approach outlined later in the Wrapping C arrays with Java arrays and +Unbounded C Arrays sections.

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

    21.3.8 C++ classes

    +

    21.3.8 C++ classes

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

    21.3.9 C++ inheritance

    +

    21.3.9 C++ inheritance

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

    -

    21.3.10 Pointers, references, arrays and pass by value

    +

    21.3.10 Pointers, references, arrays and pass by value

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

    -

    21.3.10.1 Null pointers

    +

    21.3.10.1 Null pointers

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

    -

    21.3.11 C++ overloaded functions

    +

    21.3.11 C++ overloaded functions

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

    21.3.12 C++ default arguments

    +

    21.3.12 C++ default arguments

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

    -

    21.3.13 C++ namespaces

    +

    21.3.13 C++ namespaces

    @@ -1919,7 +1919,7 @@ As Java does not support types declared in a named package accessing types decla So if SWIG is run using the -package com.myco option, a wrapped class, MyWorld::Material::Color, can then be accessed as com.myco.MyWorld.Material.Color.

    -

    21.3.14 C++ templates

    +

    21.3.14 C++ templates

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

    -

    21.3.15 C++ Smart Pointers

    +

    21.3.15 C++ Smart Pointers

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

    21.4 Further details on the generated Java classes

    +

    21.4 Further details on the generated Java classes

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

    -

    21.4.1 The intermediary JNI class

    +

    21.4.1 The intermediary JNI class

    @@ -2154,7 +2154,7 @@ class exampleJNI {

    This class contains the complete Java - C/C++ interface so all function calls go via this class. -As this class acts as a go-between for all JNI calls to C/C++ code from the Java proxy classes, type wrapper classes and module class, it is known as the intermediary JNI class. +As this class acts as a go-between for all JNI calls to C/C++ code from the Java proxy classes, type wrapper classes and module class, it is known as the intermediary JNI class.

    @@ -2163,14 +2163,14 @@ This approach leads to minimal JNI code which makes for better performance as JN SWIG favours generating Java code over JNI code as Java code is compiled into byte code and avoids the costly string operations needed in JNI code. This approach has a downside though as the proxy class might get collected before the native method has completed. You might notice above that there is an additional parameters with a underscore postfix, eg jarg1_. -These are added in order to prevent premature garbage collection when marshalling proxy classes. +These are added in order to prevent premature garbage collection when marshalling proxy classes.

    The functions in the intermediary JNI class cannot be accessed outside of its package. Access to them is gained through the module class for globals otherwise the appropriate proxy class.

    - +

    The name of the intermediary JNI class can be changed from its default, that is, the module name with JNI appended after it. The module directive attribute jniclassname is used to achieve this: @@ -2187,7 +2187,7 @@ If name is the same as modulename then the module class name g from modulename to modulenameModule.

    -

    21.4.1.1 The intermediary JNI class pragmas

    +

    21.4.1.1 The intermediary JNI class pragmas

    @@ -2266,7 +2266,7 @@ For example, let's change the intermediary JNI class access to public. All the methods in the intermediary JNI class will then be callable outside of the package as the method modifiers are public by default.

    -

    21.4.2 The Java module class

    +

    21.4.2 The Java module class

    @@ -2297,7 +2297,7 @@ example.egg(new Foo()); The primary reason for having the module class wrapping the calls in the intermediary JNI class is to implement static type checking. In this case only a Foo can be passed to the egg function, whereas any long can be passed to the egg function in the intermediary JNI class.

    -

    21.4.2.1 The Java module class pragmas

    +

    21.4.2.1 The Java module class pragmas

    @@ -2344,11 +2344,11 @@ The pragma code appears in the generated module class like this:

    -See The intermediary JNI class pragmas section for further details on using pragmas. +See The intermediary JNI class pragmas section for further details on using pragmas.

    -

    21.4.3 Java proxy classes

    +

    21.4.3 Java proxy classes

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

    21.4.3.1 Memory management

    +

    21.4.3.1 Memory management

    @@ -2518,7 +2518,7 @@ you're lucky, you will only get a segmentation fault. To work around this, the ownership flag of o needs changing to false. The ownership flag is a private member variable of the proxy class so this is not possible without some customization of the proxy class. This can be achieved by using a typemap to customise the proxy class with pure Java code as detailed later in the section on -Java typemaps. +Java typemaps.

    @@ -2580,13 +2580,13 @@ Obj obj = Factory.createObj(); // obj.swigCMemOwn = true; Some memory management issues are quite tricky to fix and may only be noticeable after using for a long time. One such issue is premature garbage collection of an object created from Java and resultant usage from C++ code. The section on typemap examples cover two such scenarios, -Memory management for objects passed to the C++ layer +Memory management for objects passed to the C++ layer and -Memory management when returning references to member variables +Memory management when returning references to member variables

    -

    21.4.3.2 Inheritance

    +

    21.4.3.2 Inheritance

    @@ -2698,11 +2698,11 @@ This is a necessity as C++ compilers are free to implement pointers in the inher It is of course possible to extend Base using your own Java classes. If Derived is provided by the C++ code, you could for example add in a pure Java class Extended derived from Base. There is a caveat and that is any C++ code will not know about your pure Java class Extended so this type of derivation is restricted. -However, true cross language polymorphism can be achieved using the directors feature. +However, true cross language polymorphism can be achieved using the directors feature.

    -

    21.4.3.3 Proxy classes and garbage collection

    +

    21.4.3.3 Proxy classes and garbage collection

    @@ -2776,7 +2776,7 @@ The SWIG generated code ensures that the memory is not deleted twice, in the eve

    Write your own object manager in Java. You could derive all SWIG classes from a single base class which could track which objects have had their finalizers run, then call the rest of them on program termination. -The section on Java typemaps details how to specify a pure Java base class. +The section on Java typemaps details how to specify a pure Java base class.

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

    -

    21.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

    +

    21.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

    @@ -2894,7 +2894,7 @@ The implementation for this extra parameter generation requires the "jtype" type

    The additional parameter does impose a slight performance overhead and the parameter generation can be suppressed globally with the -nopgcpp commandline option. -More selective suppression is possible with the 'nopgcpp' attribute in the "jtype" Java typemap. +More selective suppression is possible with the 'nopgcpp' attribute in the "jtype" Java typemap. The attribute is a flag and so should be set to "1" to enable the suppression, or it can be omitted or set to "0" to disable. For example:

    @@ -2907,7 +2907,7 @@ For example: Compatibility note: The generation of this additional parameter did not occur in versions prior to SWIG-1.3.30.

    -

    21.4.3.5 Single threaded applications and thread safety

    +

    21.4.3.5 Single threaded applications and thread safety

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

    21.4.4 Type wrapper classes

    +

    21.4.4 Type wrapper classes

    @@ -3024,7 +3024,7 @@ public class SWIGTYPE_p_int { The methods do not have public access, so by default it is impossible to do anything with objects of this class other than pass them around. The methods in the class are part of the inner workings of SWIG. If you need to mess around with pointers you will have to use some typemaps specific to the Java module to achieve this. -The section on Java typemaps details how to modify the generated code. +The section on Java typemaps details how to modify the generated code.

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

    21.4.5 Enum classes

    +

    21.4.5 Enum classes

    SWIG can generate three types of enum classes. -The Enumerations section discussed these but omitted all the details. +The Enumerations section discussed these but omitted all the details. The following sub-sections detail the various types of enum classes that can be generated.

    -

    21.4.5.1 Typesafe enum classes

    +

    21.4.5.1 Typesafe enum classes

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

    -

    21.4.5.2 Proper Java enum classes

    +

    21.4.5.2 Proper Java enum classes

    @@ -3250,10 +3250,10 @@ The next variable is in the SwigNext inner class rather than i Marshalling between Java enums and the C/C++ enum integer value is handled via the swigToEnum and swigValue methods. All the constructors and methods in the Java enum are required just to handle C/C++ enums with initializers. These needn't be generated if the enum being wrapped does not have any initializers and the -Simpler Java enums for enums without initializers section describes how typemaps can be used to achieve this. +Simpler Java enums for enums without initializers section describes how typemaps can be used to achieve this.

    -

    21.4.5.3 Type unsafe enum classes

    +

    21.4.5.3 Type unsafe enum classes

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

    21.5 Cross language polymorphism using directors

    +

    21.5 Cross language polymorphism using directors

    @@ -3306,7 +3306,7 @@ The upshot is that C++ classes can be extended in Java and from C++ these extens Neither C++ code nor Java code needs to know where a particular method is implemented: the combination of proxy classes, director classes, and C wrapper functions transparently takes care of all the cross-language method routing.

    -

    21.5.1 Enabling directors

    +

    21.5.1 Enabling directors

    @@ -3377,7 +3377,7 @@ public: -

    21.5.2 Director classes

    +

    21.5.2 Director classes

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

    -

    21.5.3 Overhead and code bloat

    +

    21.5.3 Overhead and code bloat

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

    -

    21.5.4 Simple directors example

    +

    21.5.4 Simple directors example

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

    21.5.5 Director threading issues

    +

    21.5.5 Director threading issues

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

    21.6 Accessing protected members

    +

    21.6 Accessing protected members

    @@ -3603,7 +3603,7 @@ class MyProtectedBase extends ProtectedBase -

    21.7 Common customization features

    +

    21.7 Common customization features

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

    -

    21.7.1 C/C++ helper functions

    +

    21.7.1 C/C++ helper functions

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

    -

    21.7.2 Class extension with %extend

    +

    21.7.2 Class extension with %extend

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

    -

    21.7.3 Exception handling with %exception and %javaexception

    +

    21.7.3 Exception handling with %exception and %javaexception

    @@ -3821,7 +3821,7 @@ The $action is a SWIG special variable and is replaced by the C/C++ f 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. +Java special variables for further explanation.

    @@ -3900,10 +3900,10 @@ It is however possible to write JNI calls which will compile under both C and C+

    The language-independent exception.i library file can also be used to raise exceptions. See the SWIG Library chapter. -The typemap example Handling C++ exception specifications as Java exceptions provides further exception handling capabilities. +The typemap example Handling C++ exception specifications as Java exceptions provides further exception handling capabilities.

    -

    21.7.4 Method access with %javamethodmodifiers

    +

    21.7.4 Method access with %javamethodmodifiers

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

    21.8 Tips and techniques

    +

    21.8 Tips and techniques

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

    -

    21.8.1 Input and output parameters using primitive pointers and references

    +

    21.8.1 Input and output parameters using primitive pointers and references

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

    -

    21.8.2 Simple pointers

    +

    21.8.2 Simple pointers

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

    -

    21.8.3 Wrapping C arrays with Java arrays

    +

    21.8.3 Wrapping C arrays with Java arrays

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

    -

    21.8.4 Unbounded C Arrays

    +

    21.8.4 Unbounded C Arrays

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

    -

    21.8.5 Overriding new and delete to allocate from Java heap

    +

    21.8.5 Overriding new and delete to allocate from Java heap

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

    -

    21.9 Java typemaps

    +

    21.9 Java typemaps

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

    21.9.1 Default primitive type mappings

    +

    21.9.1 Default primitive type mappings

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

    -

    21.9.3 Sixty four bit JVMs

    +

    21.9.3 Sixty four bit JVMs

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

    -

    21.9.4 What is a typemap?

    +

    21.9.4 What is a typemap?

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

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

    +

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

    @@ -4886,7 +4886,7 @@ The most important of these implement the mapping of C/C++ types to Java types: These are Java code typemaps which transform the type used in the Java intermediary JNI class (as specified in the "jtype" typemap) to the Java type used in the Java module class, proxy classes and type wrapper classes (as specified in the "jstype" typemap). This typemap provides the conversion for the parameters in the director methods when calling up from C++ to Java. - See Director typemaps. + See Director typemaps. @@ -4895,7 +4895,7 @@ The most important of these implement the mapping of C/C++ types to Java types: These are Java code typemaps which transform the type used in the Java module class, proxy classes and type wrapper classes (as specified in the "jstype" typemap) to the type used in the Java intermediary JNI class (as specified in the "jtype" typemap). This typemap provides the conversion for the return type in the director methods when returning from the C++ to Java upcall. - See Director typemaps. + See Director typemaps. @@ -4903,7 +4903,7 @@ The most important of these implement the mapping of C/C++ types to Java types: Conversion from C++ type to jni type for director methods. These are C++ typemaps which convert the parameters used in the C++ director method to the appropriate JNI intermediary type. The conversion is done in JNI code prior to calling the Java function from the JNI code. - See Director typemaps. + See Director typemaps. @@ -4911,7 +4911,7 @@ The most important of these implement the mapping of C/C++ types to Java types: Conversion from jni type to C++ type for director methods. These are C++ typemaps which convert the JNI return type used in the C++ director method to the appropriate C++ return type. The conversion is done in JNI code after calling the Java function from the JNI code. - See Director typemaps. + See Director typemaps. @@ -4989,12 +4989,12 @@ SWIGEXPORT jlong JNICALL Java_exampleJNI_FooBar(JNIEnv *jenv, jclass jcls,

    If you are using gcc as your C compiler, you might get a "dereferencing type-punned pointer will break strict-aliasing rules" warning about this. -Please see Compiling a dynamic module to avoid runtime problems with these strict aliasing rules. +Please see Compiling a dynamic module to avoid runtime problems with these strict aliasing rules.

    The default code generated by SWIG for the Java module comes from the typemaps in the "java.swg" library file which implements the -Default primitive type mappings and +Default primitive type mappings and Default typemaps for non-primitive types covered earlier. There are other type mapping typemaps in the Java library. These are listed below: @@ -5092,7 +5092,7 @@ These are listed below: -

    21.9.6 Java typemap attributes

    +

    21.9.6 Java typemap attributes

    @@ -5102,7 +5102,7 @@ There are a few additional typemap attributes that the Java module supports.

    The first of these is the 'throws' attribute. The throws attribute is optional and specified after the typemap name and contains one or more comma separated classes for adding to the throws clause for any methods that use that typemap. -It is analogous to the %javaexception feature's throws attribute. +It is analogous to the %javaexception feature's throws attribute.

    @@ -5114,7 +5114,7 @@ It is analogous to the %javaexception feature'

    The attribute is necessary for supporting Java checked exceptions and can be added to just about any typemap. The list of typemaps include all the C/C++ (JNI) typemaps in the "Typemaps" chapter and the -Java specific typemaps listed in the previous section, barring +Java specific typemaps listed in the previous section, barring the "jni", "jtype" and "jstype" typemaps as they could never contain code to throw an exception.

    @@ -5122,23 +5122,23 @@ the "jni", "jtype" and "jstype" typemaps as they could never contain code to thr The throws clause is generated for the proxy method as well as the JNI method in the JNI intermediary class. If a method uses more than one typemap and each of those typemaps have classes specified in the throws clause, the union of the exception classes is added to the throws clause ensuring there are no duplicate classes. -See the NaN exception example for further usage. +See the NaN exception example for further usage.

    -The "jtype" typemap has the optional 'nopgcpp' attribute which can be used to suppress the generation of the premature garbage collection prevention parameter. +The "jtype" typemap has the optional 'nopgcpp' attribute which can be used to suppress the generation of the premature garbage collection prevention parameter.

    -The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes. These are used for generating code before and after the JNI call in the proxy class or module class. The 'pre' attribute contains code that is generated before the JNI call and the 'post' attribute contains code generated after the JNI call. The 'pgcppname' attribute is used to change the premature garbage collection prevention parameter name passed to the JNI function. This is sometimes needed when the 'pre' typemap creates a temporary variable which is then passed to the JNI function. +The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes. These are used for generating code before and after the JNI call in the proxy class or module class. The 'pre' attribute contains code that is generated before the JNI call and the 'post' attribute contains code generated after the JNI call. The 'pgcppname' attribute is used to change the premature garbage collection prevention parameter name passed to the JNI function. This is sometimes needed when the 'pre' typemap creates a temporary variable which is then passed to the JNI function.

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

    -

    21.9.7 Java special variables

    +

    21.9.7 Java special variables

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

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

    @@ -5278,10 +5278,10 @@ This special variable expands to the module name, as specified by %module $imclassname
    This special variable expands to the intermediary class name. Usually this is the same as '$moduleJNI', -unless the jniclassname attribute is specified in the %module directive. +unless the jniclassname attribute is specified in the %module directive.

    -

    21.9.8 Typemaps for both C and C++ compilation

    +

    21.9.8 Typemaps for both C and C++ compilation

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

    -

    21.9.9 Java code typemaps

    +

    21.9.9 Java code typemaps

    @@ -5517,7 +5517,7 @@ For the typemap to be used in all type wrapper classes, all the different types Again this is the same that is in "java.swg", barring the method modifier for getCPtr.

    -

    21.9.10 Director specific typemaps

    +

    21.9.10 Director specific typemaps

    @@ -5543,7 +5543,7 @@ For example, integers are converted as follows:

    $input is the SWIG name of the JNI temporary variable passed to Java in the upcall. The descriptor="I" will put an I into the JNI field descriptor that identifies the Java method that will be called from C++. -For more about JNI field descriptors and their importance, refer to the JNI documentation mentioned earlier. +For more about JNI field descriptors and their importance, refer to the JNI documentation mentioned earlier. A typemap for C character strings is:

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

    21.10 Typemap Examples

    +

    21.10 Typemap Examples

    @@ -5752,11 +5752,11 @@ the SWIG library.

    -

    21.10.1 Simpler Java enums for enums without initializers

    +

    21.10.1 Simpler Java enums for enums without initializers

    -The default Proper Java enums approach to wrapping enums is somewhat verbose. +The default Proper Java enums approach to wrapping enums is somewhat verbose. This is to handle all possible C/C++ enums, in particular enums with initializers. The generated code can be simplified if the enum being wrapped does not have any initializers.

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

    -

    21.10.2 Handling C++ exception specifications as Java exceptions

    +

    21.10.2 Handling C++ exception specifications as Java exceptions

    @@ -5899,7 +5899,7 @@ If, however, we wanted to throw a checked exception, say java.io.IOException

    -Note that this typemap uses the 'throws' typemap attribute to ensure a throws clause is generated. +Note that this typemap uses the 'throws' typemap attribute to ensure a throws clause is generated. The generated proxy method then specifies the checked exception by containing java.io.IOException in the throws clause:

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

    -

    21.10.3 NaN Exception - exception handling for a particular type

    +

    21.10.3 NaN Exception - exception handling for a particular type

    @@ -6056,13 +6056,13 @@ public class example {

    -See the Date marshalling example for an example using further "javain" typemap attributes. +See the Date marshalling example for an example using further "javain" typemap attributes.

    If we decide that what we actually want is a checked exception instead of a runtime exception, we can change this easily enough. The proxy method that uses float as an input, must then add the exception class to the throws clause. -SWIG can handle this as it supports the 'throws' typemap attribute for specifying classes for the throws clause. +SWIG can handle this as it supports the 'throws' typemap attribute for specifying classes for the throws clause. Thus we can modify the pragma and the typemap for the throws clause:

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

    -

    21.10.4 Converting Java String arrays to char **

    +

    21.10.4 Converting Java String arrays to char **

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

    -

    21.10.5 Expanding a Java object to multiple arguments

    +

    21.10.5 Expanding a Java object to multiple arguments

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

    21.10.6 Using typemaps to return arguments

    +

    21.10.6 Using typemaps to return arguments

    @@ -6455,7 +6455,7 @@ $ java runme 1 12.0 340.0 -

    21.10.7 Adding Java downcasts to polymorphic return types

    +

    21.10.7 Adding Java downcasts to polymorphic return types

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

    -

    21.10.8 Adding an equals method to the Java classes

    +

    21.10.8 Adding an equals method to the Java classes

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

    21.10.9 Void pointers and a common Java base class

    +

    21.10.9 Void pointers and a common Java base class

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

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

    21.10.10 Struct pointer to pointer

    +

    21.10.10 Struct pointer to pointer

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

    -

    21.10.11 Memory management when returning references to member variables

    +

    21.10.11 Memory management when returning references to member variables

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

    -

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

    +

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

    @@ -7183,11 +7183,11 @@ The 'javacode' typemap simply adds in the specified code into the Java proxy cla -

    21.10.13 Date marshalling using the javain typemap and associated attributes

    +

    21.10.13 Date marshalling using the javain typemap and associated attributes

    -The NaN Exception example is a simple example of the "javain" typemap and its 'pre' attribute. +The NaN Exception example is a simple example of the "javain" typemap and its 'pre' attribute. This example demonstrates how a C++ date class, say CDate, can be mapped onto the standard Java date class, java.util.GregorianCalendar by using the 'pre', 'post' and 'pgcppname' attributes of the "javain" typemap. The idea is that the GregorianCalendar is used wherever the C++ API uses a CDate. @@ -7354,13 +7354,13 @@ A few things to note: more local variables with the same name would be generated.

  • The use of the "javain" typemap causes a constructor helper function (SwigConstructAction) to be generated. This allows Java code to be called before the JNI call and is required as the Java compiler won't compile code inserted before the 'this' call. -
  • The 'pgcppname' attribute is used to modify the object being passed as the premature garbage collection prevention parameter (the 2nd and 4th parameters in the JNI calls). +
  • The 'pgcppname' attribute is used to modify the object being passed as the premature garbage collection prevention parameter (the 2nd and 4th parameters in the JNI calls). -

    21.11 Living with Java Directors

    +

    21.11 Living with Java Directors

    @@ -7541,10 +7541,10 @@ public abstract class UserVisibleFoo extends Foo {

  • -

    21.12 Odds and ends

    +

    21.12 Odds and ends

    -

    21.12.1 JavaDoc comments

    +

    21.12.1 JavaDoc comments

    @@ -7600,7 +7600,7 @@ public class Barmy { -

    21.12.2 Functional interface without proxy classes

    +

    21.12.2 Functional interface without proxy classes

    @@ -7661,7 +7661,7 @@ All destructors have to be called manually for example the delete_Foo(foo) -

    21.12.3 Using your own JNI functions

    +

    21.12.3 Using your own JNI functions

    @@ -7711,7 +7711,7 @@ This directive is only really useful if you want to mix your own hand crafted JN

    -

    21.12.4 Performance concerns and hints

    +

    21.12.4 Performance concerns and hints

    @@ -7732,7 +7732,7 @@ However, you will have to be careful about memory management and make sure that This method normally calls the C++ destructor or free() for C code.

    -

    21.12.5 Debugging

    +

    21.12.5 Debugging

    @@ -7754,7 +7754,7 @@ The -verbose:jni and -verbose:gc are also useful options for monitoring code beh

    -

    21.13 Examples

    +

    21.13 Examples

    diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index 70d99c305..6ed36cf45 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -9,38 +9,38 @@

    @@ -57,7 +57,7 @@ especially typemaps.

    -

    24.1 Overview

    +

    24.1 Overview

    @@ -90,7 +90,7 @@ So the introduction got a bit longer than it should ... ;-)

    -

    24.1.1 Why not scripting ?

    +

    24.1.1 Why not scripting ?

    @@ -126,7 +126,7 @@ are not advantages of the language itself but can be provided by function libraries.

    -

    24.1.2 Why Modula-3 ?

    +

    24.1.2 Why Modula-3 ?

    @@ -166,7 +166,7 @@ it's statically typed, too.

    -

    24.1.3 Why C / C++ ?

    +

    24.1.3 Why C / C++ ?

    @@ -179,7 +179,7 @@ Even more fortunately even non-C libraries may provide C header files. This is where SWIG becomes helpful.

    -

    24.1.4 Why SWIG ?

    +

    24.1.4 Why SWIG ?

    @@ -252,10 +252,10 @@ integrate Modula-3 code into a C / C++ project.

    -

    24.2 Conception

    +

    24.2 Conception

    -

    24.2.1 Interfaces to C libraries

    +

    24.2.1 Interfaces to C libraries

    @@ -404,7 +404,7 @@ and the principal type must be renamed (%typemap).

    -

    24.2.2 Interfaces to C++ libraries

    +

    24.2.2 Interfaces to C++ libraries

    @@ -477,8 +477,8 @@ Is it possible to sub-class C++ classes with Modula-3 code? This issue is addressed by directors, a feature that was experimentally added to some Language modules like -Java and -Python. +Java and +Python.

  • How to manage storage with the garbage collector of Modula-3? @@ -505,10 +505,10 @@ There is no C++ library I wrote a SWIG interface for, so I'm not sure if this is possible or sensible, yet.

    -

    24.3 Preliminaries

    +

    24.3 Preliminaries

    -

    24.3.1 Compilers

    +

    24.3.1 Compilers

    @@ -522,7 +522,7 @@ For testing examples I use Critical Mass cm3.

    -

    24.3.2 Additional Commandline Options

    +

    24.3.2 Additional Commandline Options

    @@ -599,10 +599,10 @@ Instead generate templates for some basic typemaps. -

    24.4 Modula-3 typemaps

    +

    24.4 Modula-3 typemaps

    -

    24.4.1 Inputs and outputs

    +

    24.4.1 Inputs and outputs

    @@ -818,7 +818,7 @@ consist of the following parts: -

    24.4.2 Subranges, Enumerations, Sets

    +

    24.4.2 Subranges, Enumerations, Sets

    @@ -870,7 +870,7 @@ that I'd like to automate.

    -

    24.4.3 Objects

    +

    24.4.3 Objects

    @@ -883,7 +883,7 @@ is not really useful, yet.

    -

    24.4.4 Imports

    +

    24.4.4 Imports

    @@ -918,7 +918,7 @@ IMPORT M3toC; -

    24.4.5 Exceptions

    +

    24.4.5 Exceptions

    @@ -942,7 +942,7 @@ you should declare %typemap("m3wrapinconv:throws") blah * %{OSError.E%}.

    -

    24.4.6 Example

    +

    24.4.6 Example

    @@ -989,10 +989,10 @@ where almost everything is generated by a typemap: -

    24.5 More hints to the generator

    +

    24.5 More hints to the generator

    -

    24.5.1 Features

    +

    24.5.1 Features

    @@ -1029,7 +1029,7 @@ where almost everything is generated by a typemap:
    -

    24.5.2 Pragmas

    +

    24.5.2 Pragmas

    @@ -1052,7 +1052,7 @@ where almost everything is generated by a typemap:
    -

    24.6 Remarks

    +

    24.6 Remarks

      From 03634e6c9b78f68d7b55ede04364971d74cac0ad Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 23:22:40 +0000 Subject: [PATCH 016/203] Add linkchecker target for checking html links git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11923 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Makefile | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Makefile b/Doc/Manual/Makefile index 4c907791b..7db42322c 100644 --- a/Doc/Manual/Makefile +++ b/Doc/Manual/Makefile @@ -9,6 +9,7 @@ # validation. # # Additional html validation can be done using the validate target. +# Additional link checking can be done using the linkchecker target. # # Note the # and " are escaped @@ -28,9 +29,9 @@ CCache.html: ../../CCache/ccache.yo # it is just used as a primitive HTML checker. # CCache.html is generated by yodl2html and has a few insignificant problems, so we don't put it through tidy check: - tidy -errors --gnu-emacs yes -quiet index.html - tidy -errors --gnu-emacs yes -quiet Sections.html - all=`sed '/^#/d' chapters | grep -v CCache.html`; for a in $$all; do tidy -errors --gnu-emacs yes -quiet $$a; done; + tidy -errors --gnu-emacs yes -quiet index.html + tidy -errors --gnu-emacs yes -quiet Sections.html + all=`sed '/^#/d' chapters | grep -v CCache.html`; for a in $$all; do tidy -errors --gnu-emacs yes -quiet $$a; done; generate: swightml.book swigpdf.book htmldoc --batch swightml.book || true @@ -60,11 +61,15 @@ clean-baks: rm -f *.bak test: - grep "href=\".*\.html\"" index.html - grep "href=\".*\.html\"" Sections.html - all=`sed '/^#/d' chapters`; for a in $$all; do grep -l "href=\".*\.html\"" $$a; done; + grep "href=\".*\.html\"" index.html + grep "href=\".*\.html\"" Sections.html + all=`sed '/^#/d' chapters`; for a in $$all; do grep -l "href=\".*\.html\"" $$a; done; # Validating using the WDG offline validator - http://www.htmlhelp.com/tools/validator/offline/ validate: - all=`sed '/^#/d' chapters`; for a in $$all; do validate --emacs $$a; done; + all=`sed '/^#/d' chapters`; for a in $$all; do validate --emacs $$a; done; + +# Link checking using linkchecker (can take a while - 30 mins) +linkchecker: + linkchecker --anchors Contents.html From 673ce4551e54c62f9d4494e791ec52211b39a056 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 6 Mar 2010 23:23:43 +0000 Subject: [PATCH 017/203] Fix numerous broken links reported by linkchecker git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11924 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Allegrocl.html | 2 +- Doc/Manual/CSharp.html | 2 +- Doc/Manual/Chicken.html | 8 ++++---- Doc/Manual/Contents.html | 6 +++--- Doc/Manual/Customization.html | 2 +- Doc/Manual/Extending.html | 6 +++--- Doc/Manual/Guile.html | 2 +- Doc/Manual/Java.html | 8 ++++---- Doc/Manual/Lisp.html | 8 ++++---- Doc/Manual/Lua.html | 4 ++-- Doc/Manual/Modula3.html | 4 ++-- Doc/Manual/Mzscheme.html | 2 +- Doc/Manual/Php.html | 2 +- Doc/Manual/Preprocessor.html | 4 ++-- Doc/Manual/Python.html | 2 +- Doc/Manual/Ruby.html | 20 ++++++++++---------- Doc/Manual/SWIG.html | 4 ++-- Doc/Manual/Sections.html | 10 +++------- 18 files changed, 46 insertions(+), 50 deletions(-) diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html index cf70f6c27..5cedee26b 100644 --- a/Doc/Manual/Allegrocl.html +++ b/Doc/Manual/Allegrocl.html @@ -8,7 +8,7 @@ -

      17 SWIG and Allegro Common Lisp

      +

      17 SWIG and Allegro Common Lisp

        diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index d489ebf09..fd2ef981f 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -54,7 +54,7 @@ The wrapper code implementation uses C# and the Platform Invoke (PInvoke) interf The PInvoke interface has been chosen over Microsoft's Managed C++ interface as it is portable to both Microsoft Windows and non-Microsoft platforms. PInvoke is part of the ECMA/ISO C# specification. It is also better suited for robust production environments due to the Managed C++ flaw called the -Mixed DLL Loading Problem. +Mixed DLL Loading Problem. SWIG C# works equally well on non-Microsoft operating systems such as Linux, Solaris and Apple Mac using Mono and Portable.NET.

        diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html index 693e08e62..006b648d6 100644 --- a/Doc/Manual/Chicken.html +++ b/Doc/Manual/Chicken.html @@ -262,7 +262,7 @@ inside the %exception blocks. SWIG_exception will throw a list consisting of the code (as an integer) and the message. Both of these will throw an exception using (abort), which can be handled by (handle-exceptions). See - Chicken manual on Exceptions + the Chicken manual on Exceptions and SFRI-12. Since the exception values are thrown directly, if (condition-case) is used to catch an exception the exception will come through in the val () case.

        @@ -416,8 +416,8 @@ $ csc -sv modname.scm modname_wrap.c modname_impl.c -o modname.so

      This library can then be loaded by scheme code with the (require 'modname) function. -See -Loading-extension-libraries in the eval unit inside the CHICKEN manual for more information.

      +See the +Loading-extension-libraries in the eval unit inside the CHICKEN manual for more information.

      Another alternative is to run SWIG normally and create a scheme file that contains (declare (uses modname)) and then compile that file into the shared library as well. For example, inside the mod_load.scm file,

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

      In situations where a C or C++ function will assume ownership of a pointer, and thus chicken should no longer garbage collect it, SWIG provides the DISOWN input typemap. - After applying this typemap (see the Typemaps chapter for more information on how to apply typemaps), + After applying this typemap (see the Typemaps chapter for more information on how to apply typemaps), any pointer that gets passed in will no longer be garbage collected. An object is disowned by passing the SWIG_POINTER_DISOWN flag to SWIG_ConvertPtr. Warning: Since the lifetime of the object is now controlled by the underlying code, the object might diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index b5fda3b8d..5bd3210bf 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -122,7 +122,7 @@

    • Running SWIG
    • Advanced Topics @@ -1588,7 +1588,7 @@
    • Entry point to code generation
    • Module I/O and wrapper skeleton
    • Low-level code generators -
    • Configuration files +
    • Configuration files
    • Runtime support
    • Standard library files
    • User examples diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index 48f1fd476..734067475 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -773,7 +773,7 @@ involving %feature:

      -The name matching rules outlined in the Ambiguity resolution and renaming +The name matching rules outlined in the Ambiguity resolution and renaming section applies to all %feature directives. In fact the the %rename directive is just a special form of %feature. The matching rules mean that features are very flexible and can be applied with diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index bdf5e8478..ff8751540 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -54,7 +54,7 @@

    • Entry point to code generation
    • Module I/O and wrapper skeleton
    • Low-level code generators -
    • Configuration files +
    • Configuration files
    • Runtime support
    • Standard library files
    • User examples @@ -3049,7 +3049,7 @@ but without the typemaps, there is still work to do.

      -

      35.10.8 Configuration files

      +

      35.10.8 Configuration files

      @@ -3246,7 +3246,7 @@ These can be found, for example for Python, in

      By default, all of the examples are built and run when the user types make check. To ensure that your examples are automatically run -during this process, see the section on configuration +during this process, see the section on configuration files.

      diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index c39abcb46..cc063c436 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -69,7 +69,7 @@ SCM interface is the default. The SCM and GH interface differ greatly in how th pointers and have completely different run-time code. See below for more info.

      The GH interface to guile is deprecated. Read more about why in the -Guile manual. +Guile manual. The idea of the GH interface was to provide a high level API that other languages and projects could adopt. This was a good idea, but didn't pan out well for general development. But for the specific, minimal uses that the SWIG typemaps put the GH interface to use is ideal for diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 902657220..4753fbce7 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -254,7 +254,7 @@ It is also possible to change the output directo

      -The module name, specified with %module, determines the name of various generated classes as discussed later. +The module name, specified with %module, determines the name of various generated classes as discussed later. Note that the module name does not define a Java package and by default, the generated Java classes do not have a Java package. The -package option described below can specify a Java package name to use.

      @@ -3894,7 +3894,7 @@ public class FooClass {

      The examples above first use the C JNI calling syntax then the C++ JNI calling syntax. The C++ calling syntax will not compile as C and also vice versa. -It is however possible to write JNI calls which will compile under both C and C++ and is covered in the Typemaps for both C and C++ compilation section. +It is however possible to write JNI calls which will compile under both C and C++ and is covered in the Typemaps for both C and C++ compilation section.

      @@ -5126,11 +5126,11 @@ See the NaN exception example for furt

      -The "jtype" typemap has the optional 'nopgcpp' attribute which can be used to suppress the generation of the premature garbage collection prevention parameter. +The "jtype" typemap has the optional 'nopgcpp' attribute which can be used to suppress the generation of the premature garbage collection prevention parameter.

      -The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes. These are used for generating code before and after the JNI call in the proxy class or module class. The 'pre' attribute contains code that is generated before the JNI call and the 'post' attribute contains code generated after the JNI call. The 'pgcppname' attribute is used to change the premature garbage collection prevention parameter name passed to the JNI function. This is sometimes needed when the 'pre' typemap creates a temporary variable which is then passed to the JNI function. +The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes. These are used for generating code before and after the JNI call in the proxy class or module class. The 'pre' attribute contains code that is generated before the JNI call and the 'post' attribute contains code generated after the JNI call. The 'pgcppname' attribute is used to change the premature garbage collection prevention parameter name passed to the JNI function. This is sometimes needed when the 'pre' typemap creates a temporary variable which is then passed to the JNI function.

      diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 0f1b45721..aa62250b9 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -6,7 +6,7 @@ -

      22 SWIG and Common Lisp

      +

      22 SWIG and Common Lisp

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

        Allegro Common Lisp support in SWIG has been updated to include support for both C and C++. You can read about the interface - here + here

        22.2 Common Foreign Function Interface(CFFI)

        @@ -96,14 +96,14 @@ swig -cffi -help -generate-typedef -If this option is given then defctype will be used to generate +If this option is given then defctype will be used to generate
        shortcuts according to the typedefs in the input. -[no]cwrap -Turn on or turn off generation of an intermediate C file when +Turn on or turn off generation of an intermediate C file when
        creating a C interface. By default this is only done for C++ code. diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 382e03fb6..53687d3de 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -6,7 +6,7 @@ -

        23 SWIG and Lua

        +

        23 SWIG and Lua

          @@ -1210,7 +1210,7 @@ extern void sort_double(double* arr, int len);

          There are basically two ways that SWIG can deal with this. The first way, uses the <carrays.i> library to create an array in C/C++ then this can be filled within Lua and passed into the function. It works, but its a bit tedious. -More details can be found in the carrays.i documention.

          +More details can be found in the carrays.i documention.

          The second and more intuitive way, would be to pass a Lua table directly into the function, and have SWIG automatically convert between Lua-table and C-array. Within the <typemaps.i> file there are typemaps ready written to perform this task. To use them is again a matter of using %appy in the correct manner.

          diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index 6ed36cf45..228c181c0 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -54,7 +54,7 @@ You should be familiar with the basics of SWIG, especially -typemaps. +typemaps.

          24.1 Overview

          @@ -1022,7 +1022,7 @@ where almost everything is generated by a typemap: This is necessary in the cases where it was defined by a non-trivial C expression. This feature is used by the - -generateconst option. + -generateconst option. In future it may be generalized to other kind of values such as strings. diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html index 9413bb010..008e3aeb3 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -8,7 +8,7 @@ -

          25 SWIG and MzScheme

          +

          25 SWIG and MzScheme

            diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index b9dcb83c5..fbe31b9e3 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -413,7 +413,7 @@ Although PHP does not support overloading functions natively, swig will generate dispatch functions which will use %typecheck typemaps to allow overloading. This dispatch function's operation and precedence is described in Wrapping +href="SWIGPlus.html#SWIGPlus_overloaded_methods">Wrapping Overloaded Functions and Methods.

            diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html index 2dd79dac5..d7917c41a 100644 --- a/Doc/Manual/Preprocessor.html +++ b/Doc/Manual/Preprocessor.html @@ -81,7 +81,7 @@ Such information generally includes type declarations (e.g., typedef) a C++ classes that might be used as base-classes for class declarations in the interface. The use of %import is also important when SWIG is used to generate extensions as a collection of related modules. This is an advanced topic and is described -in later in the Working with Modules chapter. +in later in the Working with Modules chapter.

            @@ -377,7 +377,7 @@ SWIG will strip the extra % and leave the preprocessor directive in the

            -Typemaps support a special attribute called noblock where the { ... } delimiters can be used, +Typemaps support a special attribute called noblock where the { ... } delimiters can be used, but the delimiters are not actually generated into the code. The effect is then similar to using "" or %{ %} delimiters but the code is run through the preprocessor. For example:

            diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index b22a7e30e..e898fb359 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2513,7 +2513,7 @@ in Python-2.2, an entirely new type of class system was introduced. This new-style class system offers many enhancements including static member functions, properties (managed attributes), and class methods. Details about all of these changes can be found on www.python.org and is not repeated here. +href="http://www.python.org">www.python.org and is not repeated here.

            diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index c10702559..8684c355f 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -142,7 +142,7 @@

        • Advanced Topics @@ -1317,7 +1317,7 @@ this code:

          If you want to set an array member, you will need to supply a -"memberin" typemap described in the section on typemaps. +"memberin" typemap described in the section on typemaps. As a special case, SWIG does generate code to set array members of type char (allowing you to store a Ruby string in the structure).

          @@ -1956,7 +1956,7 @@ example:

          More details about wrapping C++ operators into Ruby operators -is discussed in the section +is discussed in the section on operator overloading.

          @@ -2877,7 +2877,7 @@ method. For example:

          SWIG's Ruby module supports cross-language polymorphism (a.k.a. the "directors" feature) similar to that for SWIG's Python -module. Rather than duplicate the information presented in the Python chapter, this +module. Rather than duplicate the information presented in the Python chapter, this section just notes the differences that you need to be aware of when using this feature with Ruby.

          @@ -6089,7 +6089,7 @@ a function. For example:

          -

          See Object +

          See Object ownership and %newobject for further details.

          @@ -7099,8 +7099,8 @@ being created.
        • When you write a typemap, you usually have to work directly with Ruby objects. The following functions may prove to be useful. -(These functions plus many more can be found in Programming -Ruby, by David Thomas and Andrew Hunt.) 

          +(These functions plus many more can be found in Programming +Ruby book, by David Thomas and Andrew Hunt.) 

          In addition, we list equivalent functions that SWIG defines, which provide a language neutral conversion (these functions are defined for each swig language supported).  If you are trying to create a swig @@ -8510,7 +8510,7 @@ docstring and they are output together.

          32.9 Advanced Topics

          -

          32.9.1 Operator overloading

          +

          32.9.1 Operator overloading

          SWIG allows operator overloading with, by using the %extend @@ -9530,7 +9530,7 @@ parses the expression a != b as !(a == b).

          32.9.2 Creating Multi-Module Packages

          -

          The chapter on Working +

          The chapter on Working with Modules discusses the basics of creating multi-module extensions with SWIG, and in particular the considerations for sharing runtime type information among the different modules.

          @@ -10050,7 +10050,7 @@ above. For example:

          In this case, the default SWIG behavior for calling member functions is incorrect. The Ruby object should assume ownership of the returned object. This can be done by using the %newobject directive. -See +See Object ownership and %newobject for more information.

          diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 0479f30d7..9ad450425 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -13,7 +13,7 @@
        • Running SWIG
          • Input format -
          • SWIG Output +
          • SWIG Output
          • Comments
          • C Preprocessor
          • SWIG Directives @@ -193,7 +193,7 @@ semantics in SWIG is analogous to that of the declarations section used in input files to parser generation tools such as yacc or bison.

            -

            5.1.2 SWIG Output

            +

            5.1.2 SWIG Output

            diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index ab47ed8ee..e26e4d31d 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -41,13 +41,13 @@ to help!).

            Language Module Documentation

            - From 978dd1f48f8e8760dcb8189e45e952a8bd567dec Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Mar 2010 07:35:06 +0000 Subject: [PATCH 018/203] Windows portability fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11925 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp/Makefile.in | 8 +++----- Source/Swig/misc.c | 6 +++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 0f44b3335..13a4d114f 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -69,14 +69,12 @@ run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ - CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` \ - `find $* -name "*.cs"`' csharp_compile && \ + CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \ env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ else \ - cd $* && \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ + $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -t:module -out:$*.netmodule' \ - CSHARPSRCS='`find . -name "*.cs"`' csharp_compile && cd .. ; \ + CSHARPSRCS='`find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile; \ fi # Clean: remove testcase directories diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 7085f3b4a..9a2a33278 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -20,6 +20,10 @@ char cvsroot_misc_c[] = "$Id$"; #include #include +#ifdef _WIN32 +#include +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif static char *fake_version = 0; @@ -170,7 +174,7 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) { } } else { #ifdef _WIN32 - int result = mkdir(Char(dir)); + int result = _mkdir(Char(dir)); #else int result = mkdir(Char(dir), 0777); #endif From 83391b135d0b9b39ae4fea6c23e5794993e1f473 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Mar 2010 20:46:21 +0000 Subject: [PATCH 019/203] .netmodule files are generated in the subdirectories again git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11926 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp/Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 13a4d114f..35ca41fb0 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -72,9 +72,10 @@ run_testcase = \ CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \ env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ else \ + cd $* && \ $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -t:module -out:$*.netmodule' \ - CSHARPSRCS='`find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile; \ + CSHARPSRCS='`find . -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile; \ fi # Clean: remove testcase directories From c1cce1bc98cc052f368ce5de1047061983a8bfdf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Mar 2010 20:48:11 +0000 Subject: [PATCH 020/203] The intermediary JNI class modifiers are now public by default. The proxy class pointer constructor and getCPtr() methods are also now public git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11927 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 10 ++++++++++ Doc/Manual/Java.html | 33 ++++++++++++++++++++------------- Examples/test-suite/nspace.i | 5 ----- Lib/java/java.swg | 4 ++-- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 1e9704783..baf364a47 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,16 @@ Version 2.0.0 (in progress) ============================ +2010-03-06: wsfulton + [Java] The intermediary JNI class modifiers are now public by default meaning these + intermediary low level functions are now accessible by default from outside any package + used. The proxy class pointer constructor and getCPtr() methods are also now public. + These are needed in order for the nspace option to work without any other mods. + The previous default of protected access can be restored using: + + SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE) + %pragma(java) jniclassclassmodifiers = "class" + 2010-03-06: wsfulton [C#] Added the nspace feature for C#. Documentation for the nspace feature is now available. diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 4753fbce7..0984b2ecf 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -2253,17 +2253,17 @@ The jniclasscode pragma is quite useful for adding in a static block fo

            Pragmas will take either "" or %{ %} as delimiters. -For example, let's change the intermediary JNI class access to public. +For example, let's change the intermediary JNI class access to just the default package-private access.

            -%pragma(java) jniclassclassmodifiers="public class"
            +%pragma(java) jniclassclassmodifiers="class"
             

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

            21.4.2 The Java module class

            @@ -2368,7 +2368,7 @@ public class Foo { swigCPtr = cPtr; } - protected static long getCPtr(Foo obj) { + public static long getCPtr(Foo obj) { return (obj == null) ? 0 : obj.swigCPtr; } @@ -2619,7 +2619,7 @@ public class Base { swigCPtr = cPtr; } - protected static long getCPtr(Base obj) { + public static long getCPtr(Base obj) { return (obj == null) ? 0 : obj.swigCPtr; } @@ -2659,7 +2659,7 @@ public class Derived extends Base { swigCPtr = cPtr; } - protected static long getCPtr(Derived obj) { + public static long getCPtr(Derived obj) { return (obj == null) ? 0 : obj.swigCPtr; } @@ -2938,7 +2938,7 @@ public class Test { swigCPtr = cPtr; } - protected static long getCPtr(Test obj) { + public static long getCPtr(Test obj) { return (obj == null) ? 0 : obj.swigCPtr; } @@ -5459,9 +5459,9 @@ The "javaimports" typemap is ignored if the enum class is wrapped by an inner Ja

            The defaults can be overridden to tailor these classes. -Here is an example which will change the getCPtr method and constructor from the default protected access to public access. -This has a practical application if you are invoking SWIG more than once and generating the wrapped classes into different packages in each invocation. -If the classes in one package are using the classes in another package, then these methods need to be public. +Here is an example which will change the getCPtr method and constructor from the default public access to protected access. +If the classes in one package are not using the classes in another package, then these methods need not be public and removing access to these low level implementation details, is a good thing. +If you are invoking SWIG more than once and generating the wrapped classes into different packages in each invocation, then you cannot do this as you will then have different packages.

            @@ -5470,12 +5470,12 @@ If the classes in one package are using the classes in another package, then the private long swigCPtr; protected boolean swigCMemOwn; - public $javaclassname(long cPtr, boolean cMemoryOwn) { + protected $javaclassname(long cPtr, boolean cMemoryOwn) { swigCMemOwn = cMemoryOwn; swigCPtr = cPtr; } - public static long getCPtr($javaclassname obj) { + protected static long getCPtr($javaclassname obj) { return (obj == null) ? 0 : obj.swigCPtr; } %} @@ -5483,12 +5483,19 @@ If the classes in one package are using the classes in another package, then the

            -The typemap code is the same that is in "java.swg", barring the two method modifiers. +The typemap code is the same that is in "java.swg", barring the last two method modifiers. Note that SWIGTYPE will target all proxy classes, but not the type wrapper classes. Also the above typemap is only used for proxy classes that are potential base classes. To target proxy classes that are derived from a wrapped class as well, the "javabody_derived" typemap should also be overridden. +There is a macro in java.swg that implements this and the above can instead be implemented using:

            +
            +
            +SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE)
            +
            +
            +

            For the typemap to be used in all type wrapper classes, all the different types that type wrapper classes could be used for should be targeted:

            diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index eb63f342d..14be0aa20 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -1,11 +1,6 @@ // Test the nspace feature %module nspace -#if defined(SWIGJAVA) -SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) -%pragma(java) jniclassclassmodifiers = "public class" -#endif - // nspace feature only supported by these languages #if defined(SWIGJAVA) || defined(SWIGCSHARP) diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 6173502ca..f37cba77a 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -1085,7 +1085,7 @@ /* Set the default for SWIGTYPE: pointer constructor is protected, getCPtr is protected. Season to your own taste! */ -SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE) +SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) // Typewrapper classes %typemap(javabody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ @@ -1195,7 +1195,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) #define %nojavaexception %feature("except","0",throws="") #define %clearjavaexception %feature("except","",throws="") -%pragma(java) jniclassclassmodifiers="class" +%pragma(java) jniclassclassmodifiers="public class" %pragma(java) moduleclassmodifiers="public class" /* Some ANSI C typemaps */ From 9dd30264f6e3d37e551871c4adc9e28069e6fd27 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Mar 2010 22:26:17 +0000 Subject: [PATCH 021/203] fix last commit git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11928 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 35ca41fb0..afb29dfbf 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -73,7 +73,7 @@ run_testcase = \ env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ else \ cd $* && \ - $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -t:module -out:$*.netmodule' \ CSHARPSRCS='`find . -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile; \ fi From deafe98dc4d4fc1b0683f950cfffeb2ea519f45b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Mar 2010 23:02:53 +0000 Subject: [PATCH 022/203] Test %extend and nspace feature git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11929 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + .../test-suite/csharp/nspace_extend_runme.cs | 39 +++++++++++++++ Examples/test-suite/java/Makefile.in | 1 + .../test-suite/java/nspace_extend_runme.java | 44 ++++++++++++++++ Examples/test-suite/nspace_extend.i | 50 +++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 Examples/test-suite/csharp/nspace_extend_runme.cs create mode 100644 Examples/test-suite/java/nspace_extend_runme.java create mode 100644 Examples/test-suite/nspace_extend.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 2b4ab0701..db162487f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -243,6 +243,7 @@ CPP_TEST_CASES += \ namespace_union \ namespace_virtual_method \ nspace \ + nspace_extend \ naturalvar \ nested_class \ nested_comment \ diff --git a/Examples/test-suite/csharp/nspace_extend_runme.cs b/Examples/test-suite/csharp/nspace_extend_runme.cs new file mode 100644 index 000000000..addee7fe5 --- /dev/null +++ b/Examples/test-suite/csharp/nspace_extend_runme.cs @@ -0,0 +1,39 @@ +using System; + +public class runme +{ + static void Main() + { + { + // constructors and destructors + nspace_extendNamespace.Outer.Inner1.Color color1 = new nspace_extendNamespace.Outer.Inner1.Color(); + nspace_extendNamespace.Outer.Inner1.Color color = new nspace_extendNamespace.Outer.Inner1.Color(color1); + color1.Dispose(); + color1 = null; + + // class methods + color.colorInstanceMethod(20.0); + nspace_extendNamespace.Outer.Inner1.Color.colorStaticMethod(20.0); + nspace_extendNamespace.Outer.Inner1.Color created = nspace_extendNamespace.Outer.Inner1.Color.create(); + created.Dispose(); + } + { + // constructors and destructors + nspace_extendNamespace.Outer.Inner2.Color color2 = new nspace_extendNamespace.Outer.Inner2.Color(); + nspace_extendNamespace.Outer.Inner2.Color color = new nspace_extendNamespace.Outer.Inner2.Color(color2); + color2.Dispose(); + color2 = null; + + // class methods + color.colorInstanceMethod(20.0); + nspace_extendNamespace.Outer.Inner2.Color.colorStaticMethod(20.0); + nspace_extendNamespace.Outer.Inner2.Color created = nspace_extendNamespace.Outer.Inner2.Color.create(); + created.Dispose(); + + // Same class different namespaces + nspace_extendNamespace.Outer.Inner1.Color col1 = new nspace_extendNamespace.Outer.Inner1.Color(); + nspace_extendNamespace.Outer.Inner2.Color col2 = nspace_extendNamespace.Outer.Inner2.Color.create(); + col2.colors(col1, col1, col2, col2, col2); + } + } +} diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 119b50868..3cb7c0c53 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -43,6 +43,7 @@ INTERFACEDIR = ../../ # Custom tests - tests with additional commandline options nspace.%: JAVA_PACKAGE = $*Package +nspace_extend.%: JAVA_PACKAGE = $*Package # Rules for the different types of tests %.cpptest: diff --git a/Examples/test-suite/java/nspace_extend_runme.java b/Examples/test-suite/java/nspace_extend_runme.java new file mode 100644 index 000000000..3e44673d1 --- /dev/null +++ b/Examples/test-suite/java/nspace_extend_runme.java @@ -0,0 +1,44 @@ +// This tests changes the package name from nspace to nspacePackage as javac can't seem to resolve classes and packages having the same name +public class nspace_extend_runme { + + static { + try { + System.loadLibrary("nspace_extend"); + } 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[]) { + { + // constructors and destructors + nspace_extendPackage.Outer.Inner1.Color color1 = new nspace_extendPackage.Outer.Inner1.Color(); + nspace_extendPackage.Outer.Inner1.Color color = new nspace_extendPackage.Outer.Inner1.Color(color1); + color1.delete(); + color1 = null; + + // class methods + color.colorInstanceMethod(20.0); + nspace_extendPackage.Outer.Inner1.Color.colorStaticMethod(20.0); + nspace_extendPackage.Outer.Inner1.Color created = nspace_extendPackage.Outer.Inner1.Color.create(); + } + { + // constructors and destructors + nspace_extendPackage.Outer.Inner2.Color color2 = new nspace_extendPackage.Outer.Inner2.Color(); + nspace_extendPackage.Outer.Inner2.Color color = new nspace_extendPackage.Outer.Inner2.Color(color2); + color2.delete(); + color2 = null; + + // class methods + color.colorInstanceMethod(20.0); + nspace_extendPackage.Outer.Inner2.Color.colorStaticMethod(20.0); + nspace_extendPackage.Outer.Inner2.Color created = nspace_extendPackage.Outer.Inner2.Color.create(); + + // Same class different namespaces + nspace_extendPackage.Outer.Inner1.Color col1 = new nspace_extendPackage.Outer.Inner1.Color(); + nspace_extendPackage.Outer.Inner2.Color col2 = nspace_extendPackage.Outer.Inner2.Color.create(); + col2.colors(col1, col1, col2, col2, col2); + } + } +} diff --git a/Examples/test-suite/nspace_extend.i b/Examples/test-suite/nspace_extend.i new file mode 100644 index 000000000..7f7ba01f8 --- /dev/null +++ b/Examples/test-suite/nspace_extend.i @@ -0,0 +1,50 @@ +// Test the nspace feature and %extend +%module nspace_extend + +// nspace feature only supported by these languages +#if defined(SWIGJAVA) || defined(SWIGCSHARP) + +%nspace; + +%extend Outer::Inner1::Color { + Color() { return new Outer::Inner1::Color(); } + virtual ~Color() { delete $self; } + static Color* create() { return new Outer::Inner1::Color(); } + Color(const Color& other) { return new Outer::Inner1::Color(other); } + + void colorInstanceMethod(double d) {} + static void colorStaticMethod(double d) {} +} + +%inline %{ + +namespace Outer { + namespace Inner1 { + struct Color { + }; + } + + namespace Inner2 { + struct Color { + }; + } +} +%} + +#endif + +%extend Outer::Inner2::Color { + Color() { return new Outer::Inner2::Color(); } + ~Color() { delete $self; } + static Color* create() { return new Outer::Inner2::Color(); } + Color(const Color& other) { return new Outer::Inner2::Color(other); } + + void colorInstanceMethod(double d) {} + static void colorStaticMethod(double d) {} + void colors(const Inner1::Color& col1a, + const Outer::Inner1::Color& col1b, + const Color &col2a, + const Inner2::Color& col2b, + const Outer::Inner2::Color& col2c) {} +} + From 96f98795116fbf5b176ea5f299f15d0e469c23f4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 9 Mar 2010 21:15:34 +0000 Subject: [PATCH 023/203] Fixes for nspace and derived classes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11930 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/CSharp.html | 1 + Doc/Manual/Java.html | 8 ++++++ Examples/test-suite/csharp/nspace_runme.cs | 6 ++++ Examples/test-suite/java/nspace_runme.java | 6 ++++ Examples/test-suite/nspace.i | 12 ++++++++ Lib/csharp/csharp.swg | 2 +- Lib/java/java.swg | 2 +- Source/Modules/csharp.cxx | 22 ++++++++++----- Source/Modules/java.cxx | 32 ++++++++++++---------- 9 files changed, 67 insertions(+), 24 deletions(-) diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index fd2ef981f..21b319e29 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -206,6 +206,7 @@ jniclassinterfaces -> imclassinterfaces $javaclassname -> $csclassname $&javaclassname -> $&csclassname $*javaclassname -> $*csclassname +$javaclazzname -> $csclazzname $javainput -> $csinput $jnicall -> $imcall
        diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 0984b2ecf..5b61955ab 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -5161,6 +5161,14 @@ If the type does not have an associated proxy class, it expands to the type wrap SWIGTYPE_p_unsigned_short is generated when wrapping unsigned short *.

        +

        +$javaclazzname
        +This special variable works like $javaclassname, but expands the fully qualified C++ class into the package name, +if used by the nspace feature, and the proxy class name, mangled for use as a function name. +For example, Namespace1::Namespace2::Klass is expanded into Namespace1_Namespace2_Klass_. +This special variable is usually used for making calls to a function in the intermediary JNI class, as they are mangled with this prefix. +

        +

        $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/Examples/test-suite/csharp/nspace_runme.cs b/Examples/test-suite/csharp/nspace_runme.cs index 91baf6a0f..7ced06a04 100644 --- a/Examples/test-suite/csharp/nspace_runme.cs +++ b/Examples/test-suite/csharp/nspace_runme.cs @@ -56,5 +56,11 @@ public class runme ns.Dispose(); nspaceNamespace.NoNSpacePlease nons = new nspaceNamespace.NoNSpacePlease(); nons.Dispose(); + + // Derived class + nspaceNamespace.Outer.Inner3.Blue blue3 = new nspaceNamespace.Outer.Inner3.Blue(); + blue3.blueInstanceMethod(); + nspaceNamespace.Outer.Inner4.Blue blue4 = new nspaceNamespace.Outer.Inner4.Blue(); + blue4.blueInstanceMethod(); } } diff --git a/Examples/test-suite/java/nspace_runme.java b/Examples/test-suite/java/nspace_runme.java index ca83b7d04..a50bb9ae9 100644 --- a/Examples/test-suite/java/nspace_runme.java +++ b/Examples/test-suite/java/nspace_runme.java @@ -60,5 +60,11 @@ public class nspace_runme { // turn feature off / ignoring nspacePackage.Outer.nspace ns = new nspacePackage.Outer.nspace(); nspacePackage.NoNSpacePlease nons = new nspacePackage.NoNSpacePlease(); + + // Derived class + nspacePackage.Outer.Inner3.Blue blue3 = new nspacePackage.Outer.Inner3.Blue(); + blue3.blueInstanceMethod(); + nspacePackage.Outer.Inner4.Blue blue4 = new nspacePackage.Outer.Inner4.Blue(); + blue4.blueInstanceMethod(); } } diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index 14be0aa20..82f6e1101 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -73,6 +73,18 @@ namespace Outer { class NoNSpacePlease {}; } // Inner2 + // Derived class + namespace Inner3 { + struct Blue : Inner2::Color { + void blueInstanceMethod() {} + }; + } + namespace Inner4 { + struct Blue : Inner2::Color { + void blueInstanceMethod() {} + }; + } + class SomeClass { public: Inner1::Color::Channel GetInner1ColorChannel() { return Inner1::Color::Transmission; } diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 204cf4b2f..1f58db48d 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -841,7 +841,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(csbody_derived) SWIGTYPE %{ private HandleRef swigCPtr; - internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclassnameUpcast(cPtr), cMemoryOwn) { + internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGUpcast(cPtr), cMemoryOwn) { swigCPtr = new HandleRef(this, cPtr); } diff --git a/Lib/java/java.swg b/Lib/java/java.swg index f37cba77a..ad7c8074d 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -1072,7 +1072,7 @@ private long swigCPtr; PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { - super($imclassname.SWIG$javaclassnameUpcast(cPtr), cMemoryOwn); + super($imclassname.$javaclazznameSWIGUpcast(cPtr), cMemoryOwn); swigCPtr = cPtr; } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 0dbed4d1e..55de14285 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1753,6 +1753,8 @@ public: Delete(attributes); Delete(destruct); + String *csclazzname = Swig_name_member(getNSpace(), proxy_class_name, ""); // mangled full proxy class name + // Emit extra user code Printv(proxy_class_def, typemapLookup(n, "cscode", typemap_lookup_type, WARN_NONE), // extra C# code "\n", NIL); @@ -1770,21 +1772,27 @@ public: Replaceall(proxy_class_def, "$dllimport", dllimport); Replaceall(proxy_class_code, "$dllimport", dllimport); + Replaceall(proxy_class_def, "$csclazzname", csclazzname); + Replaceall(proxy_class_code, "$csclazzname", csclazzname); + // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { - Printv(imclass_cppcasts_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"CSharp_", proxy_class_name, "Upcast", "\")]\n", NIL); - Printf(imclass_cppcasts_code, " public static extern IntPtr $csclassnameUpcast(IntPtr objectRef);\n"); + String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGUpcast"); + String *wname = Swig_name_wrapper(upcast_method); + + Printv(imclass_cppcasts_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); + Printf(imclass_cppcasts_code, " public static extern IntPtr %s(IntPtr jarg1);\n", upcast_method); Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name); Printv(upcasts_code, - "SWIGEXPORT $cbaseclass * SWIGSTDCALL CSharp_$imclazznameUpcast", - "($cclass *objectRef) {\n", " return ($cbaseclass *)objectRef;\n" "}\n", "\n", NIL); + "SWIGEXPORT ", c_baseclass, " * SWIGSTDCALL ", wname, + "(", c_classname, " *jarg1) {\n", " return (", c_baseclass, " *)jarg1;\n" "}\n", "\n", NIL); - Replaceall(upcasts_code, "$cbaseclass", c_baseclass); - Replaceall(upcasts_code, "$imclazzname", proxy_class_name); - Replaceall(upcasts_code, "$cclass", c_classname); + Delete(wname); + Delete(upcast_method); } + Delete(csclazzname); Delete(baseclass); } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 50b80dc8b..7315bd9a5 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1762,6 +1762,8 @@ public: Delete(attributes); Delete(destruct); + String *javaclazzname = Swig_name_member(getNSpace(), proxy_class_name, ""); // mangled full proxy class name + // Emit extra user code Printv(proxy_class_def, typemapLookup(n, "javacode", typemap_lookup_type, WARN_NONE), // extra Java code "\n", NIL); @@ -1776,29 +1778,29 @@ public: Replaceall(proxy_class_def, "$imclassname", full_imclass_name); Replaceall(proxy_class_code, "$imclassname", full_imclass_name); + Replaceall(proxy_class_def, "$javaclazzname", javaclazzname); + Replaceall(proxy_class_code, "$javaclazzname", javaclazzname); + // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { - Printv(imclass_cppcasts_code, " public final static native long SWIG$javaclassnameUpcast(long jarg1);\n", NIL); + String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGUpcast"); + String *jniname = makeValidJniName(upcast_method); + String *wname = Swig_name_wrapper(jniname); - Replaceall(imclass_cppcasts_code, "$javaclassname", full_proxy_class_name); + Printf(imclass_cppcasts_code, " public final static native long %s(long jarg1);\n", upcast_method); Printv(upcasts_code, - "SWIGEXPORT jlong JNICALL Java_$jnipackage$imimclass_SWIG$imclazznameUpcast", - "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n", + "SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n", " jlong baseptr = 0;\n" - " (void)jenv;\n" " (void)jcls;\n" " *($cbaseclass **)&baseptr = *($cclass **)&jarg1;\n" " return baseptr;\n" "}\n", "\n", NIL); + " (void)jenv;\n" " (void)jcls;\n" " *(", c_baseclassname, " **)&baseptr = *(", c_classname, " **)&jarg1;\n" + " return baseptr;\n" + "}\n", "\n", NIL); - String *imimclass = makeValidJniName(imclass_name); - String *imclazzname = makeValidJniName(full_proxy_class_name); - Replaceall(upcasts_code, "$cbaseclass", c_baseclass); - Replaceall(upcasts_code, "$imclazzname", imclazzname); - Replaceall(upcasts_code, "$cclass", c_classname); - Replaceall(upcasts_code, "$jnipackage", jnipackage); - Replaceall(upcasts_code, "$imimclass", imimclass); - - Delete(imclazzname); - Delete(imimclass); + Delete(wname); + Delete(jniname); + Delete(upcast_method); } + Delete(javaclazzname); Delete(baseclass); } From bce282fa0cbe5f5e5c0a5e30f1376a8973320e1a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 10 Mar 2010 07:29:16 +0000 Subject: [PATCH 024/203] Minor tweaks git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11931 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/java/java.swg | 2 +- Source/Modules/csharp.cxx | 20 ++++++++++++++------ Source/Modules/java.cxx | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Lib/java/java.swg b/Lib/java/java.swg index ad7c8074d..2dfbe59f2 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -1132,7 +1132,7 @@ SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) */ %define SWIG_PROXY_CONSTRUCTOR(OWNERSHIP, WEAKREF, TYPENAME...) -%typemap(javaconstruct,directorconnect="\n $imclassname.$javaclassname_director_connect(this, swigCPtr, swigCMemOwn, WEAKREF);") TYPENAME { +%typemap(javaconstruct,directorconnect="\n $imclassname.$javaclazznamedirector_connect(this, swigCPtr, swigCMemOwn, WEAKREF);") TYPENAME { this($imcall, OWNERSHIP);$directorconnect } %enddef diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 55de14285..8b8cbaa43 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -803,7 +803,7 @@ public: return SWIG_OK; } - Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"CSharp_", overloaded_name, "\")]\n", NIL); + Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); if (im_outattributes) Printf(imclass_class_code, " %s\n", im_outattributes); @@ -1887,14 +1887,16 @@ public: downcasts, making the constructorHandler() a bad place (because ABCs don't get to have constructors emitted.) */ if (GetFlag(n, "feature:javadowncast")) { + String *downcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGDowncast"); + String *wname = Swig_name_wrapper(downcast_method); + String *norm_name = SwigType_namestr(Getattr(n, "name")); - Printf(imclass_class_code, " public final static native %s downcast%s(long cPtrBase, boolean cMemoryOwn);\n", proxy_class_name, proxy_class_name); + Printf(imclass_class_code, " public final static native %s %s(long cPtrBase, boolean cMemoryOwn);\n", proxy_class_name, downcast_method); Wrapper *dcast_wrap = NewWrapper(); - Printf(dcast_wrap->def, "SWIGEXPORT jobject SWIGSTDCALL CSharp_downcast%s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", - proxy_class_name); + Printf(dcast_wrap->def, "SWIGEXPORT jobject SWIGSTDCALL %s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", wname); Printf(dcast_wrap->code, " Swig::Director *director = (Swig::Director *) 0;\n"); Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); @@ -1905,6 +1907,10 @@ public: Wrapper_print(dcast_wrap, f_wrappers); DelWrapper(dcast_wrap); + + Delete(norm_name); + Delete(wname); + Delete(downcast_method); } emitDirectorExtraMethods(n); @@ -3307,14 +3313,15 @@ public: // Output the director connect method: String *norm_name = SwigType_namestr(Getattr(n, "name")); String *swig_director_connect = Swig_name_member(getNSpace(), proxy_class_name, "director_connect"); + String *wname = Swig_name_wrapper(swig_director_connect); String *sym_name = Getattr(n, "sym:name"); Wrapper *code_wrap; - Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"CSharp_", swig_director_connect, "\")]\n", NIL); + Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); Printf(imclass_class_code, " public static extern void %s(HandleRef jarg1", swig_director_connect); code_wrap = NewWrapper(); - Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL CSharp_%s(void *objarg", swig_director_connect); + Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname); Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name); Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); @@ -3343,6 +3350,7 @@ public: Wrapper_print(code_wrap, f_wrappers); DelWrapper(code_wrap); + Delete(wname); Delete(swig_director_connect); } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 7315bd9a5..2bceae83f 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1792,7 +1792,7 @@ public: Printv(upcasts_code, "SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n", " jlong baseptr = 0;\n" - " (void)jenv;\n" " (void)jcls;\n" " *(", c_baseclassname, " **)&baseptr = *(", c_classname, " **)&jarg1;\n" + " (void)jenv;\n" " (void)jcls;\n" " *(", c_baseclass, " **)&baseptr = *(", c_classname, " **)&jarg1;\n" " return baseptr;\n" "}\n", "\n", NIL); @@ -1901,16 +1901,17 @@ public: downcasts, making the constructorHandler() a bad place (because ABCs don't get to have constructors emitted.) */ if (GetFlag(n, "feature:javadowncast")) { - String *jni_imclass_name = makeValidJniName(imclass_name); - String *jni_class_name = makeValidJniName(proxy_class_name); + String *downcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGDowncast"); + String *jniname = makeValidJniName(downcast_method); + String *wname = Swig_name_wrapper(jniname); + String *norm_name = SwigType_namestr(Getattr(n, "name")); - Printf(imclass_class_code, " public final static native %s downcast%s(long cPtrBase, boolean cMemoryOwn);\n", proxy_class_name, proxy_class_name); + Printf(imclass_class_code, " public final static native %s %s(long cPtrBase, boolean cMemoryOwn);\n", proxy_class_name, downcast_method); Wrapper *dcast_wrap = NewWrapper(); - Printf(dcast_wrap->def, "SWIGEXPORT jobject JNICALL Java_%s%s_downcast%s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", - jnipackage, jni_imclass_name, jni_class_name); + Printf(dcast_wrap->def, "SWIGEXPORT jobject JNICALL %s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", wname); Printf(dcast_wrap->code, " Swig::Director *director = (Swig::Director *) 0;\n"); Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); @@ -1921,6 +1922,11 @@ public: Wrapper_print(dcast_wrap, f_wrappers); DelWrapper(dcast_wrap); + + Delete(norm_name); + Delete(wname); + Delete(jniname); + Delete(downcast_method); } emitDirectorExtraMethods(n); From ebe21075f9c08a8555d0aadc67acecda8701c3be Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 10 Mar 2010 07:30:22 +0000 Subject: [PATCH 025/203] update package builds with more generic version numbers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11932 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/mkdist.py | 6 +++--- Tools/mkrelease.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 0e2eafa79..9e25d3827 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -# This script builds a swig-1.3 distribution. -# Usage : mkdist.py version, where version should be 1.3.x +# This script builds a swig-x.y.z distribution. +# Usage : mkdist.py version, where version should be x.y.z import sys import string @@ -16,7 +16,7 @@ try: version = sys.argv[1] dirname = "swig-" + version except: - print "Usage: mkdist.py version, where version should be 1.3.x" + print "Usage: mkdist.py version, where version should be x.y.z" sys.exit(1) # Check name matches normal unix conventions diff --git a/Tools/mkrelease.py b/Tools/mkrelease.py index b719c470e..4b5e7e2e1 100755 --- a/Tools/mkrelease.py +++ b/Tools/mkrelease.py @@ -18,7 +18,7 @@ try: username = sys.argv[2] except: print "Usage: python mkrelease.py version username" - print "where version should be 1.3.x and username is your SF username" + print "where version should be x.y.z and username is your SF username" sys.exit(1) print "Looking for rsync" From 8d227bce62f9514bf97409727729bb025a813e6e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 10 Mar 2010 07:50:32 +0000 Subject: [PATCH 026/203] Slightly efficiency improvements for packages/namespaces/ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11933 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 53 ++++++++++++++++++++------------------- Source/Modules/java.cxx | 35 +++++++++++++------------- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 8b8cbaa43..341937308 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -181,7 +181,7 @@ public: String *nspace = Getattr(n, "sym:nspace"); String *symname = Getattr(n, "sym:name"); if (nspace) { - if (Len(namespce) > 0) + if (namespce) proxyname = NewStringf("%s.%s.%s", namespce, nspace, symname); else proxyname = NewStringf("%s.%s", nspace, symname); @@ -239,6 +239,10 @@ public: if (argv[i + 1]) { namespce = NewString(""); Printf(namespce, argv[i + 1]); + if (Len(namespce) == 0) { + Delete(namespce); + namespce = 0; + } Swig_mark_arg(i); Swig_mark_arg(i + 1); i++; @@ -378,8 +382,6 @@ public: dmethods_table = NewHash(); n_dmethods = 0; n_directors = 0; - if (!namespce) - namespce = NewString(""); if (!dllimport) dllimport = Copy(module_class_name); @@ -439,7 +441,7 @@ public: // Start writing out the intermediary class file emitBanner(f_im); - addOpenNamespace(namespce, 0, f_im); + addOpenNamespace(0, f_im); if (imclass_imports) Printf(f_im, "%s\n", imclass_imports); @@ -463,7 +465,7 @@ public: // Finish off the class Printf(f_im, "}\n"); - addCloseNamespace(namespce, 0, f_im); + addCloseNamespace(0, f_im); Close(f_im); } @@ -483,7 +485,7 @@ public: // Start writing out the module class file emitBanner(f_module); - addOpenNamespace(namespce, 0, f_module); + addOpenNamespace(0, f_module); if (module_imports) Printf(f_module, "%s\n", module_imports); @@ -515,7 +517,7 @@ public: // Finish off the class Printf(f_module, "}\n"); - addCloseNamespace(namespce, 0, f_module); + addCloseNamespace(0, f_module); Close(f_module); } @@ -1134,7 +1136,7 @@ public: if (!nspace) { full_imclass_name = NewStringf("%s", imclass_name); } else { - if (Len(namespce) > 0) { + if (namespce) { full_imclass_name = NewStringf("%s.%s", namespce, imclass_name); } else { full_imclass_name = NewStringf("%s", imclass_name); @@ -1214,12 +1216,12 @@ public: // Start writing out the enum file emitBanner(f_enum); - addOpenNamespace(namespce, nspace, f_enum); + addOpenNamespace(nspace, f_enum); Printv(f_enum, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements "\n", enum_code, "\n", NIL); - addCloseNamespace(namespce, nspace, f_enum); + addCloseNamespace(nspace, f_enum); Close(f_enum); Delete(output_directory); } @@ -1820,7 +1822,7 @@ public: SWIG_exit(EXIT_FAILURE); } } else { - if (Len(namespce) > 0) { + if (namespce) { full_proxy_class_name = NewStringf("%s.%s.%s", namespce, nspace, proxy_class_name); full_imclass_name = NewStringf("%s.%s", namespce, imclass_name); } else { @@ -1846,7 +1848,7 @@ public: // Start writing out the proxy class file emitBanner(f_proxy); - addOpenNamespace(namespce, nspace, f_proxy); + addOpenNamespace(nspace, f_proxy); Clear(proxy_class_def); Clear(proxy_class_code); @@ -1878,7 +1880,7 @@ public: Printv(f_proxy, proxy_class_constants_code, NIL); Printf(f_proxy, "}\n"); - addCloseNamespace(namespce, nspace, f_proxy); + addCloseNamespace(nspace, f_proxy); Close(f_proxy); f_proxy = NULL; @@ -2959,7 +2961,7 @@ public: // global enum or enum in a namespace String *nspace = Getattr(n, "sym:nspace"); if (nspace) { - if (Len(namespce) > 0) + if (namespce) enumname = NewStringf("%s.%s.%s", namespce, nspace, symname); else enumname = NewStringf("%s.%s", nspace, symname); @@ -3111,7 +3113,7 @@ public: // Start writing out the type wrapper class file emitBanner(f_swigtype); - addOpenNamespace(namespce, 0, f_swigtype); + addOpenNamespace(0, f_swigtype); // Pure C# baseclass and interfaces const String *pure_baseclass = typemapLookup(n, "csbase", type, WARN_NONE); @@ -3140,7 +3142,7 @@ public: Printv(f_swigtype, swigtype, NIL); - addCloseNamespace(namespce, 0, f_swigtype); + addCloseNamespace(0, f_swigtype); Close(f_swigtype); Delete(swigtype); @@ -3215,12 +3217,12 @@ public: * addOpenNamespace() * ----------------------------------------------------------------------------- */ - void addOpenNamespace(const String *namspace, const String *nspace, File *file) { - if (namspace) { - if (Len(namspace) > 0 || nspace) { + void addOpenNamespace(const String *nspace, File *file) { + if (namespce) { + if (namespce || nspace) { Printf(file, "namespace "); - if (Len(namspace) > 0) - Printv(file, namspace, nspace ? "." : "", NIL); + if (namespce) + Printv(file, namespce, nspace ? "." : "", NIL); if (nspace) Printv(file, nspace, NIL); Printf(file, " {\n"); @@ -3232,9 +3234,9 @@ public: * addCloseNamespace() * ----------------------------------------------------------------------------- */ - void addCloseNamespace(const String *namspace, const String *nspace, File *file) { - if (namspace) - if (Len(namspace) > 0 || nspace) + void addCloseNamespace(const String *nspace, File *file) { + if (namespce) + if (namespce || nspace) Printf(file, "\n}\n"); } @@ -3303,8 +3305,7 @@ public: /*---------------------------------------------------------------------- * emitDirectorExtraMethods() * - * This is where the director connect method is - * generated. + * This is where the director connect method is generated. *--------------------------------------------------------------------*/ void emitDirectorExtraMethods(Node *n) { if (!Swig_directorclass(n)) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 2bceae83f..65bb440f3 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -176,7 +176,7 @@ public: String *nspace = Getattr(n, "sym:nspace"); String *symname = Getattr(n, "sym:name"); if (nspace) { - if (Len(package) > 0) + if (package) proxyname = NewStringf("%s.%s.%s", package, nspace, symname); else proxyname = NewStringf("%s.%s", nspace, symname); @@ -234,6 +234,10 @@ public: if (argv[i + 1]) { package = NewString(""); Printf(package, argv[i + 1]); + if (Len(package) == 0) { + Delete(package); + package = 0; + } Swig_mark_arg(i); Swig_mark_arg(i + 1); i++; @@ -390,8 +394,6 @@ public: dmethods_table = NewHash(); n_dmethods = 0; n_directors = 0; - if (!package) - package = NewString(""); jnipackage = NewString(""); package_path = NewString(""); @@ -420,7 +422,7 @@ public: String *wrapper_name = NewString(""); - if (Len(package)) { + if (package) { String *jniname = makeValidJniName(package); Printv(jnipackage, jniname, NIL); Delete(jniname); @@ -467,7 +469,7 @@ public: // Start writing out the intermediary class file emitBanner(f_im); - if (Len(package) > 0) + if (package) Printf(f_im, "package %s;\n", package); if (imclass_imports) @@ -518,7 +520,7 @@ public: // Start writing out the module class file emitBanner(f_module); - if (Len(package) > 0) + if (package) Printf(f_module, "package %s;\n", package); if (module_imports) @@ -570,7 +572,7 @@ public: // Start writing out the Java constants interface file emitBanner(f_module); - if (Len(package) > 0) + if (package) Printf(f_module, "package %s;\n", package); if (module_imports) @@ -1195,7 +1197,7 @@ public: if (!nspace) { full_imclass_name = NewStringf("%s", imclass_name); } else { - if (Len(package) > 0) { + if (package) { full_imclass_name = NewStringf("%s.%s", package, imclass_name); } else { full_imclass_name = NewStringf("%s", imclass_name); @@ -1277,9 +1279,9 @@ public: // Start writing out the enum file emitBanner(f_enum); - if (Len(package) > 0 || nspace) { + if (package || nspace) { Printf(f_enum, "package "); - if (Len(package) > 0) + if (package) Printv(f_enum, package, nspace ? "." : "", NIL); if (nspace) Printv(f_enum, nspace, NIL); @@ -1828,7 +1830,7 @@ public: SWIG_exit(EXIT_FAILURE); } } else { - if (Len(package) > 0) { + if (package) { full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); full_imclass_name = NewStringf("%s.%s", package, imclass_name); } else { @@ -1856,9 +1858,9 @@ public: // Start writing out the proxy class file emitBanner(f_proxy); - if (Len(package) > 0 || nspace) { + if (package || nspace) { Printf(f_proxy, "package "); - if (Len(package) > 0) + if (package) Printv(f_proxy, package, nspace ? "." : "", NIL); if (nspace) Printv(f_proxy, nspace, NIL); @@ -2807,7 +2809,7 @@ public: // global enum or enum in a namespace String *nspace = Getattr(n, "sym:nspace"); if (nspace) { - if (Len(package) > 0) + if (package) enumname = NewStringf("%s.%s.%s", package, nspace, symname); else enumname = NewStringf("%s.%s", nspace, symname); @@ -2963,7 +2965,7 @@ public: // Start writing out the type wrapper class file emitBanner(f_swigtype); - if (Len(package) > 0) + if (package) Printf(f_swigtype, "package %s;\n", package); // Pure Java baseclass and interfaces @@ -3274,8 +3276,7 @@ public: /*---------------------------------------------------------------------- * emitDirectorExtraMethods() * - * This is where the $javaclassname_director_connect is - * generated. + * This is where the director connect method is generated. *--------------------------------------------------------------------*/ void emitDirectorExtraMethods(Node *n) { if (!Swig_directorclass(n)) From 48533467451c63fc25bde65e8bc1cdea3665c3f7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 10 Mar 2010 08:07:39 +0000 Subject: [PATCH 027/203] remove duplicate special variable replacement git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11934 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 32 +++++++++++++------------------- Source/Modules/java.cxx | 29 +++++++++++++---------------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 341937308..f3025603c 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1755,28 +1755,10 @@ public: Delete(attributes); Delete(destruct); - String *csclazzname = Swig_name_member(getNSpace(), proxy_class_name, ""); // mangled full proxy class name - // Emit extra user code Printv(proxy_class_def, typemapLookup(n, "cscode", typemap_lookup_type, WARN_NONE), // extra C# code "\n", NIL); - // Substitute various strings into the above template - Replaceall(proxy_class_code, "$csclassname", proxy_class_name); - Replaceall(proxy_class_def, "$csclassname", proxy_class_name); - - Replaceall(proxy_class_def, "$module", module_class_name); - Replaceall(proxy_class_code, "$module", module_class_name); - - Replaceall(proxy_class_def, "$imclassname", full_imclass_name); - Replaceall(proxy_class_code, "$imclassname", full_imclass_name); - - Replaceall(proxy_class_def, "$dllimport", dllimport); - Replaceall(proxy_class_code, "$dllimport", dllimport); - - Replaceall(proxy_class_def, "$csclazzname", csclazzname); - Replaceall(proxy_class_code, "$csclazzname", csclazzname); - // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGUpcast"); @@ -1794,7 +1776,6 @@ public: Delete(wname); Delete(upcast_method); } - Delete(csclazzname); Delete(baseclass); } @@ -1863,12 +1844,24 @@ public: emitProxyClassDefAndCPPCasts(n); + String *csclazzname = Swig_name_member(getNSpace(), proxy_class_name, ""); // mangled full proxy class name + + Replaceall(proxy_class_def, "$csclassname", proxy_class_name); + Replaceall(proxy_class_code, "$csclassname", proxy_class_name); + Replaceall(proxy_class_constants_code, "$csclassname", proxy_class_name); + + Replaceall(proxy_class_def, "$csclazzname", csclazzname); + Replaceall(proxy_class_code, "$csclazzname", csclazzname); + Replaceall(proxy_class_constants_code, "$csclazzname", csclazzname); + Replaceall(proxy_class_def, "$module", module_class_name); Replaceall(proxy_class_code, "$module", module_class_name); Replaceall(proxy_class_constants_code, "$module", module_class_name); + Replaceall(proxy_class_def, "$imclassname", full_imclass_name); Replaceall(proxy_class_code, "$imclassname", full_imclass_name); Replaceall(proxy_class_constants_code, "$imclassname", full_imclass_name); + Replaceall(proxy_class_def, "$dllimport", dllimport); Replaceall(proxy_class_code, "$dllimport", dllimport); Replaceall(proxy_class_constants_code, "$dllimport", dllimport); @@ -1917,6 +1910,7 @@ public: emitDirectorExtraMethods(n); + Delete(csclazzname); Delete(proxy_class_name); proxy_class_name = NULL; Delete(full_proxy_class_name); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 65bb440f3..ebba67106 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1764,25 +1764,10 @@ public: Delete(attributes); Delete(destruct); - String *javaclazzname = Swig_name_member(getNSpace(), proxy_class_name, ""); // mangled full proxy class name - // Emit extra user code Printv(proxy_class_def, typemapLookup(n, "javacode", typemap_lookup_type, WARN_NONE), // extra Java code "\n", NIL); - // Substitute various strings into the above template - Replaceall(proxy_class_code, "$javaclassname", proxy_class_name); - Replaceall(proxy_class_def, "$javaclassname", proxy_class_name); - - Replaceall(proxy_class_def, "$module", module_class_name); - Replaceall(proxy_class_code, "$module", module_class_name); - - Replaceall(proxy_class_def, "$imclassname", full_imclass_name); - Replaceall(proxy_class_code, "$imclassname", full_imclass_name); - - Replaceall(proxy_class_def, "$javaclazzname", javaclazzname); - Replaceall(proxy_class_code, "$javaclazzname", javaclazzname); - // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGUpcast"); @@ -1802,7 +1787,6 @@ public: Delete(jniname); Delete(upcast_method); } - Delete(javaclazzname); Delete(baseclass); } @@ -1882,12 +1866,24 @@ public: emitProxyClassDefAndCPPCasts(n); + String *javaclazzname = Swig_name_member(getNSpace(), proxy_class_name, ""); // mangled full proxy class name + + Replaceall(proxy_class_def, "$javaclassname", proxy_class_name); + Replaceall(proxy_class_code, "$javaclassname", proxy_class_name); + Replaceall(proxy_class_constants_code, "$javaclassname", proxy_class_name); + + Replaceall(proxy_class_def, "$javaclazzname", javaclazzname); + Replaceall(proxy_class_code, "$javaclazzname", javaclazzname); + Replaceall(proxy_class_constants_code, "$javaclazzname", javaclazzname); + Replaceall(proxy_class_def, "$module", module_class_name); Replaceall(proxy_class_code, "$module", module_class_name); Replaceall(proxy_class_constants_code, "$module", module_class_name); + Replaceall(proxy_class_def, "$imclassname", full_imclass_name); Replaceall(proxy_class_code, "$imclassname", full_imclass_name); Replaceall(proxy_class_constants_code, "$imclassname", full_imclass_name); + Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); // Write out all the constants @@ -1933,6 +1929,7 @@ public: emitDirectorExtraMethods(n); + Delete(javaclazzname); Delete(proxy_class_name); proxy_class_name = NULL; Delete(full_proxy_class_name); From 541bc7d43539486f8d32497af904ad4916d382b9 Mon Sep 17 00:00:00 2001 From: Mikel Bancroft Date: Wed, 10 Mar 2010 19:38:24 +0000 Subject: [PATCH 028/203] [allegrocl] Use fully qualified symbol name for cl::identity git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11935 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Source/Modules/allegrocl.cxx | 7 +------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index baf364a47..7b18af4c7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-03-10: mutandiz (Mikel Bancroft) + [allegrocl] Use fully qualified symbol name of cl::identity in emit_defun(). + 2010-03-06: wsfulton [Java] The intermediary JNI class modifiers are now public by default meaning these intermediary low level functions are now accessible by default from outside any package diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index 3c6e86cc5..de4a7bfa9 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1669,13 +1669,8 @@ int ALLEGROCL::top(Node *n) { Printf(f_clhead, "(in-package :%s)\n", module_name); - // Swig_print_tree(n); - Language::top(n); - // SwigType_emit_type_table(f_runtime,f_cxx_wrapper); - - // Swig_print_tree(n); #ifdef ALLEGROCL_TYPE_DEBUG dump_linked_types(stderr); #endif @@ -2538,7 +2533,7 @@ int ALLEGROCL::emit_defun(Node *n, File *fcl) { // NewStringf("(push (swig-ff-call%s) ACL_result)", wrap->locals))); String *ldestructor = Copy(lclass); if (ff_foreign_ptr) - Replaceall(ldestructor, ldestructor, "identity"); + Replaceall(ldestructor, ldestructor, "cl::identity"); else Replaceall(ldestructor, ":type :class", ":type :destructor"); Replaceall(wrap->code, "$ldestructor", ldestructor); From 7af8eb954b6f1dcbf4fe2dd6888e8d4f22b04906 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 10 Mar 2010 22:00:14 +0000 Subject: [PATCH 029/203] add some missing nspace support git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11936 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 4 ++-- Source/Modules/java.cxx | 4 ++-- Source/Modules/modula3.cxx | 4 ++-- Source/Modules/ocaml.cxx | 4 ++-- Source/Modules/pike.cxx | 4 ++-- Source/Modules/ruby.cxx | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index f3025603c..0ee47c708 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -411,8 +411,8 @@ public: Swig_name_register("wrapper", "CSharp_%f"); if (old_variable_names) { - Swig_name_register("set", "set_%v"); - Swig_name_register("get", "get_%v"); + Swig_name_register("set", "set_%n%v"); + Swig_name_register("get", "get_%n%v"); } Printf(f_wrappers, "\n#ifdef __cplusplus\n"); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index ebba67106..b8a0dd9a5 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -437,8 +437,8 @@ public: Swig_name_register("wrapper", Char(wrapper_name)); if (old_variable_names) { - Swig_name_register("set", "set_%v"); - Swig_name_register("get", "get_%v"); + Swig_name_register("set", "set_%n%v"); + Swig_name_register("get", "get_%n%v"); } Delete(wrapper_name); diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index 252e92a7d..fb928a898 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -972,8 +972,8 @@ MODULA3(): Swig_name_register("wrapper", "Modula3_%f"); if (old_variable_names) { - Swig_name_register("set", "set_%v"); - Swig_name_register("get", "get_%v"); + Swig_name_register("set", "set_%n%v"); + Swig_name_register("get", "get_%n%v"); } Printf(f_wrappers, "\n#ifdef __cplusplus\n"); diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 41c30c858..7aa7286e9 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -265,8 +265,8 @@ public: Swig_register_filebyname("class_ctors", f_class_ctors); if (old_variable_names) { - Swig_name_register("set", "%v__set__"); - Swig_name_register("get", "%v__get__"); + Swig_name_register("set", "%n%v__set__"); + Swig_name_register("get", "%n%v__get__"); } Swig_banner(f_begin); diff --git a/Source/Modules/pike.cxx b/Source/Modules/pike.cxx index 51758ae46..bd1edec62 100644 --- a/Source/Modules/pike.cxx +++ b/Source/Modules/pike.cxx @@ -159,8 +159,8 @@ public: Printf(f_header, "#define SWIG_name \"%s\"\n\n", module); /* Change naming scheme for constructors and destructors */ - Swig_name_register("construct", "%c_create"); - Swig_name_register("destroy", "%c_destroy"); + Swig_name_register("construct", "%n%c_create"); + Swig_name_register("destroy", "%n%c_destroy"); /* Current wrap type */ current = NO_CPP; diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 043df02f2..0ed175945 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -2578,7 +2578,7 @@ public: /* First wrap the allocate method */ current = CONSTRUCTOR_ALLOCATE; - Swig_name_register("construct", "%c_allocate"); + Swig_name_register("construct", "%n%c_allocate"); Language::constructorHandler(n); @@ -2613,7 +2613,7 @@ public: Delete(docs); current = CONSTRUCTOR_INITIALIZE; - Swig_name_register("construct", "new_%c"); + Swig_name_register("construct", "new_%n%c"); Language::constructorHandler(n); /* Restore original parameter list */ @@ -2635,7 +2635,7 @@ public: /* First wrap the allocate method */ current = CONSTRUCTOR_ALLOCATE; - Swig_name_register("construct", "%c_allocate"); + Swig_name_register("construct", "%n%n%c_allocate"); return Language::copyconstructorHandler(n); } From 7ed1528349066c1257fb59812e40c5be4a0033d5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Mar 2010 00:05:31 +0000 Subject: [PATCH 030/203] nspace fixes and adding in missing symbols in language symbol tables for Java and C# git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11937 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp/nspace_runme.cs | 18 ++++-- Examples/test-suite/java/nspace_runme.java | 18 ++++-- Examples/test-suite/nspace.i | 37 +++++------- Source/Modules/csharp.cxx | 69 ++++++++++++++++++---- Source/Modules/java.cxx | 68 +++++++++++++++++---- Source/Modules/lang.cxx | 19 ++++-- 6 files changed, 174 insertions(+), 55 deletions(-) diff --git a/Examples/test-suite/csharp/nspace_runme.cs b/Examples/test-suite/csharp/nspace_runme.cs index 7ced06a04..9cf593857 100644 --- a/Examples/test-suite/csharp/nspace_runme.cs +++ b/Examples/test-suite/csharp/nspace_runme.cs @@ -22,16 +22,26 @@ public class runme if (channel != nspaceNamespace.Outer.Inner1.Color.Channel.Transmission) throw new ApplicationException("Transmission wrong"); - // static member variables - nspaceNamespace.Outer.Inner1.Color.staticMemberVariable = 789; - if (nspaceNamespace.Outer.Inner1.Color.staticMemberVariable != 789) - throw new ApplicationException("static member variable failed"); + // class anonymous enums + int val1 = nspaceNamespace.Outer.Inner1.Color.ColorEnumVal1; + int val2 = nspaceNamespace.Outer.Inner1.Color.ColorEnumVal2; + if (val1 != 0 || val2 != 0x22) + throw new ApplicationException("ColorEnumVal wrong"); // instance member variables color.instanceMemberVariable = 123; if (color.instanceMemberVariable != 123) throw new ApplicationException("instance member variable failed"); + // static member variables + nspaceNamespace.Outer.Inner1.Color.staticMemberVariable = 789; + if (nspaceNamespace.Outer.Inner1.Color.staticMemberVariable != 789) + throw new ApplicationException("static member variable failed"); + if (nspaceNamespace.Outer.Inner1.Color.staticConstMemberVariable != 222) + throw new ApplicationException("static const member variable failed"); + if (nspaceNamespace.Outer.Inner1.Color.staticConstEnumMemberVariable != nspaceNamespace.Outer.Inner1.Color.Channel.Transmission) + throw new ApplicationException("static const enum member variable failed"); + // check globals in a namespace don't get mangled with the nspaceNamespace option nspaceNamespace.nspace.namespaceFunction(color); nspaceNamespace.nspace.namespaceVar = 111; diff --git a/Examples/test-suite/java/nspace_runme.java b/Examples/test-suite/java/nspace_runme.java index a50bb9ae9..9800e79cd 100644 --- a/Examples/test-suite/java/nspace_runme.java +++ b/Examples/test-suite/java/nspace_runme.java @@ -28,16 +28,26 @@ public class nspace_runme { if (channel != nspacePackage.Outer.Inner1.Color.Channel.Transmission) throw new RuntimeException("Transmission wrong"); - // static member variables - nspacePackage.Outer.Inner1.Color.setStaticMemberVariable(789); - if (nspacePackage.Outer.Inner1.Color.getStaticMemberVariable() != 789) - throw new RuntimeException("static member variable failed"); + // class anonymous enums + int val1 = nspacePackage.Outer.Inner1.Color.ColorEnumVal1; + int val2 = nspacePackage.Outer.Inner1.Color.ColorEnumVal2; + if (val1 != 0 || val2 != 0x22) + throw new RuntimeException("ColorEnumVal wrong"); // instance member variables color.setInstanceMemberVariable(123); if (color.getInstanceMemberVariable() != 123) throw new RuntimeException("instance member variable failed"); + // static member variables + nspacePackage.Outer.Inner1.Color.setStaticMemberVariable(789); + if (nspacePackage.Outer.Inner1.Color.getStaticMemberVariable() != 789) + throw new RuntimeException("static member variable failed"); + if (nspacePackage.Outer.Inner1.Color.staticConstMemberVariable != 222) + throw new RuntimeException("static const member variable failed"); + if (nspacePackage.Outer.Inner1.Color.staticConstEnumMemberVariable != nspacePackage.Outer.Inner1.Color.Channel.Transmission) + throw new RuntimeException("static const enum member variable failed"); + // Same class different namespaces nspacePackage.Outer.Inner1.Color col1 = new nspacePackage.Outer.Inner1.Color(); nspacePackage.Outer.Inner2.Color col2 = nspacePackage.Outer.Inner2.Color.create(); diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index 82f6e1101..4e4e461c0 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -10,29 +10,27 @@ %copyctor; %ignore Outer::Inner2::Color::Color(); +#define CONSTANT100 100 + %inline %{ namespace Outer { class nspace { }; namespace Inner1 { - enum Channel { - Diffuse, - Specular = 0x10, - Transmission1 - }; + enum Channel { Diffuse, Specular = 0x10, Transmission1 }; + enum { ColorEnumVal1, ColorEnumVal2 = 0x11, ColorEnumVal3 }; struct Color { static Color* create() { return new Color(); } - enum Channel { - Diffuse, - Specular = 0x20, - Transmission - }; + enum Channel { Diffuse, Specular = 0x20, Transmission }; + enum { ColorEnumVal1, ColorEnumVal2 = 0x22, ColorEnumVal3 }; int instanceMemberVariable; static int staticMemberVariable; + static const int staticConstMemberVariable = 222; + static const Channel staticConstEnumMemberVariable = Transmission; void colorInstanceMethod(double d) {} static void colorStaticMethod(double d) {} }; // Color @@ -43,24 +41,19 @@ namespace Outer { } // Inner1 namespace Inner2 { - enum Channel { - Diffuse, - Specular /* = 0x30*/, - Transmission2 - }; + enum Channel { Diffuse, Specular = 0x30, Transmission2 }; struct Color { Color() : instanceMemberVariable(0) {} static Color* create() { return new Color(); } - enum Channel { - Diffuse, - Specular/* = 0x40*/, - Transmission - }; + enum Channel { Diffuse, Specular = 0x40, Transmission }; + enum { ColorEnumVal1, ColorEnumVal2 = 0x33, ColorEnumVal3 }; int instanceMemberVariable; static int staticMemberVariable; + static const int staticConstMemberVariable = 333; + static const Channel staticConstEnumMemberVariable = Transmission; void colorInstanceMethod(double d) {} static void colorStaticMethod(double d) {} void colors(const Inner1::Color& col1a, @@ -85,8 +78,8 @@ namespace Outer { }; } - class SomeClass { - public: + class SomeClass { + public: Inner1::Color::Channel GetInner1ColorChannel() { return Inner1::Color::Transmission; } Inner2::Color::Channel GetInner2ColorChannel() { return Inner2::Color::Transmission; } Inner1::Channel GetInner1Channel() { return Inner1::Transmission1; } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 0ee47c708..4fb5699b8 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1128,9 +1128,9 @@ public: if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + String *nspace = Getattr(n, "sym:nspace"); // NSpace/getNSpace() only works during Language::enumDeclaration call if (proxy_flag && !is_wrapping_class()) { // Global enums / enums in a namespace - String *nspace = Getattr(n, "sym:nspace"); assert(!full_imclass_name); if (!nspace) { @@ -1153,6 +1153,17 @@ public: if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum + String *scope = 0; + if (nspace || proxy_class_name) { + scope = NewString(""); + if (nspace) + Printf(scope, "%s", nspace); + if (proxy_class_name) + Printv(scope, nspace ? "." : "", proxy_class_name, NIL); + } + if (!addSymbol(symname, n, scope)) + return SWIG_ERROR; + // Pure C# baseclass and interfaces const String *pure_baseclass = typemapLookup(n, "csbase", typemap_lookup_type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "csinterfaces", typemap_lookup_type, WARN_NONE); @@ -1166,6 +1177,7 @@ public: Printv(enum_code, typemapLookup(n, "csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really) " ", symname, (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces ", " : "", pure_interfaces, " {\n", NIL); + Delete(scope); } else { // Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums of any sort if (symname && !Getattr(n, "unnamedinstance")) @@ -1201,7 +1213,6 @@ public: Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL); } else { // Global enums are defined in their own file - String *nspace = Getattr(n, "sym:nspace"); String *output_directory = outputDirectory(nspace); String *filen = NewStringf("%s%s.cs", output_directory, symname); File *f_enum = NewFile(filen, "w", SWIG_output_files()); @@ -1260,6 +1271,7 @@ public: Node *parent = parentNode(n); int unnamedinstance = GetFlag(parent, "unnamedinstance"); String *parent_name = Getattr(parent, "name"); + String *nspace = getNSpace(); String *tmpValue; // Strange hack from parent method @@ -1272,6 +1284,29 @@ public: { EnumFeature enum_feature = decodeEnumFeature(parent); + + // Add to language symbol table + String *scope = 0; + if (unnamedinstance || !parent_name || enum_feature == SimpleEnum) { + if (proxy_class_name) { + scope = NewString(""); + if (nspace) + Printf(scope, "%s.", nspace); + Printf(scope, "%s", proxy_class_name); + } else { + scope = Copy(module_class_name); + } + } else { + scope = NewString(""); + if (nspace) + Printf(scope, "%s.", nspace); + if (proxy_class_name) + Printf(scope, "%s.", proxy_class_name); + Printf(scope, "%s",Getattr(parent, "sym:name")); + } + if (!addSymbol(name, n, scope)) + return SWIG_ERROR; + const String *csattributes = Getattr(n, "feature:cs:attributes"); if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) { @@ -1336,6 +1371,7 @@ public: Setattr(parent, "enumvalues", Copy(symname)); else Printv(enumvalues, ", ", symname, NIL); + Delete(scope); } Delete(tmpValue); @@ -1365,9 +1401,21 @@ public: bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0); const String *itemname = (proxy_flag && wrapping_member_flag) ? variable_name : symname; - String *scope = proxy_flag && wrapping_member_flag ? proxy_class_name : module_class_name; - if (!addSymbol(itemname, n, scope)) - return SWIG_ERROR; + if (!is_enum_item) { + String *scope = 0; + if (proxy_class_name) { + String *nspace = getNSpace(); + scope = NewString(""); + if (nspace) + Printf(scope, "%s.", nspace); + Printf(scope, "%s", proxy_class_name); + } else { + scope = Copy(module_class_name); + } + if (!addSymbol(itemname, n, scope)) + return SWIG_ERROR; + Delete(scope); + } // The %csconst feature determines how the constant value is obtained int const_feature_flag = GetFlag(n, "feature:cs:const"); @@ -1426,13 +1474,14 @@ public: if (classname_substituted_flag) { if (SwigType_isenum(t)) { // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) - Printf(constants_code, "(%s)%s.%s();\n", return_type, imclass_name, Swig_name_get(getNSpace(), symname)); + Printf(constants_code, "(%s)%s.%s();\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname)); } else { // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(getNSpace(), symname)); + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname)); } - } else - Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(getNSpace(), symname)); + } else { + Printf(constants_code, "%s.%s();\n", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); + } // Each constant and enum value is wrapped with a separate PInvoke function call SetFlag(n, "feature:immutable"); @@ -2924,7 +2973,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(getNSpace(), proxy_class_name, symname))); + value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), Swig_name_member(0, proxy_class_name, symname))); } } } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index b8a0dd9a5..229e65379 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1189,9 +1189,9 @@ public: if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + String *nspace = Getattr(n, "sym:nspace"); // NSpace/getNSpace() only works during Language::enumDeclaration call if (proxy_flag && !is_wrapping_class()) { // Global enums / enums in a namespace - String *nspace = Getattr(n, "sym:nspace"); assert(!full_imclass_name); if (!nspace) { @@ -1216,6 +1216,17 @@ public: if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum + String *scope = 0; + if (nspace || proxy_class_name) { + scope = NewString(""); + if (nspace) + Printf(scope, "%s", nspace); + if (proxy_class_name) + Printv(scope, nspace ? "." : "", proxy_class_name, NIL); + } + if (!addSymbol(symname, n, scope)) + return SWIG_ERROR; + // Pure Java baseclass and interfaces const String *pure_baseclass = typemapLookup(n, "javabase", typemap_lookup_type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE); @@ -1229,6 +1240,7 @@ public: Replaceall(enum_code, "$static ", "static "); else Replaceall(enum_code, "$static ", ""); + Delete(scope); } else { // Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums of any sort if (symname && !Getattr(n, "unnamedinstance")) @@ -1264,7 +1276,6 @@ public: Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL); } else { // Global enums are defined in their own file - String *nspace = Getattr(n, "sym:nspace"); String *output_directory = outputDirectory(nspace); String *filen = NewStringf("%s%s.java", output_directory, symname); File *f_enum = NewFile(filen, "w", SWIG_output_files()); @@ -1330,6 +1341,7 @@ public: Node *parent = parentNode(n); int unnamedinstance = GetFlag(parent, "unnamedinstance"); String *parent_name = Getattr(parent, "name"); + String *nspace = getNSpace(); String *tmpValue; // Strange hack from parent method @@ -1343,6 +1355,28 @@ public: { EnumFeature enum_feature = decodeEnumFeature(parent); + // Add to language symbol table + String *scope = 0; + if (unnamedinstance || !parent_name || enum_feature == SimpleEnum) { + if (proxy_class_name) { + scope = NewString(""); + if (nspace) + Printf(scope, "%s.", nspace); + Printf(scope, "%s", proxy_class_name); + } else { + scope = Copy(constants_interface_name); + } + } else { + scope = NewString(""); + if (nspace) + Printf(scope, "%s.", nspace); + if (proxy_class_name) + Printf(scope, "%s.", proxy_class_name); + Printf(scope, "%s",Getattr(parent, "sym:name")); + } + if (!addSymbol(name, n, scope)) + return SWIG_ERROR; + if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) { // Wrap (non-anonymous) C/C++ enum with a proper Java enum // Emit the enum item. @@ -1389,6 +1423,7 @@ public: Setattr(parent, "enumvalues", Copy(symname)); else Printv(enumvalues, ", ", symname, NIL); + Delete(scope); } Delete(tmpValue); @@ -1418,9 +1453,21 @@ public: bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0); const String *itemname = (proxy_flag && wrapping_member_flag) ? variable_name : symname; - String *scope = proxy_flag && wrapping_member_flag ? proxy_class_name : constants_interface_name; - if (!addSymbol(itemname, n, scope)) - return SWIG_ERROR; + if (!is_enum_item) { + String *scope = 0; + if (proxy_class_name) { + String *nspace = getNSpace(); + scope = NewString(""); + if (nspace) + Printf(scope, "%s.", nspace); + Printf(scope, "%s", proxy_class_name); + } else { + scope = Copy(constants_interface_name); + } + if (!addSymbol(itemname, n, scope)) + return SWIG_ERROR; + Delete(scope); + } // The %javaconst feature determines how the constant value is obtained int const_feature_flag = GetFlag(n, "feature:java:const"); @@ -1472,13 +1519,14 @@ public: if (classname_substituted_flag) { if (SwigType_isenum(t)) { // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) - Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, imclass_name, Swig_name_get(getNSpace(), symname)); + Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname)); } else { // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(getNSpace(), symname)); + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname)); } - } else - Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(getNSpace(), symname)); + } else { + Printf(constants_code, "%s.%s();\n", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); + } // Each constant and enum value is wrapped with a separate JNI function call SetFlag(n, "feature:immutable"); @@ -2772,7 +2820,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(getNSpace(), proxy_class_name, symname))); + value = NewStringf("%s.%s()", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), Swig_name_member(0, proxy_class_name, symname))); } } } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 2ccefb619..778c8e5ba 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1612,9 +1612,15 @@ int Language::externDeclaration(Node *n) { * ---------------------------------------------------------------------- */ int Language::enumDeclaration(Node *n) { + String *oldNSpace = NSpace; + NSpace = Getattr(n, "sym:nspace"); + if (!ImportMode) { emit_children(n); } + + NSpace = oldNSpace; + return SWIG_OK; } @@ -1677,7 +1683,7 @@ int Language::memberconstantHandler(Node *n) { String *symname = Getattr(n, "sym:name"); String *value = Getattr(n, "value"); - String *mrename = Swig_name_member(NSpace, ClassPrefix, symname); + String *mrename = Swig_name_member(0, ClassPrefix, symname); Setattr(n, "sym:name", mrename); String *new_name = 0; @@ -2316,7 +2322,6 @@ int Language::classDeclaration(Node *n) { String *name = Getattr(n, "name"); String *tdname = Getattr(n, "tdname"); String *symname = Getattr(n, "sym:name"); - String *symnspace = Getattr(n, "sym:nspace"); char *classname = tdname ? Char(tdname) : Char(name); char *iname = Char(symname); @@ -2345,7 +2350,6 @@ int Language::classDeclaration(Node *n) { ClassName = NewString(classname); ClassPrefix = NewString(iname); - NSpace = symnspace; if (strip) { ClassType = NewString(classname); } else { @@ -2357,6 +2361,8 @@ int Language::classDeclaration(Node *n) { InClass = 1; CurrentClass = n; + String *oldNSpace = NSpace; + NSpace = Getattr(n, "sym:nspace"); /* Call classHandler() here */ if (!ImportMode) { @@ -2406,7 +2412,7 @@ int Language::classDeclaration(Node *n) { Language::classHandler(n); } - NSpace = 0; + NSpace = oldNSpace; InClass = 0; CurrentClass = 0; Delete(ClassType); @@ -2944,7 +2950,10 @@ int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr } else { Node *c = Getattr(symbols, s); if (c && (c != n)) { - Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module.\n", s); + if (scope) + Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module in scope %s.\n", s, scope); + else + Swig_error(input_file, line_number, "'%s' is multiply defined in the generated target language module.\n", s); Swig_error(Getfile(c), Getline(c), "Previous declaration of '%s'\n", s); return 0; } From 780e71e509ca48cadc0b67dd3c862802d6e3676c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Mar 2010 00:24:00 +0000 Subject: [PATCH 031/203] minor ruby cleanup git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11938 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/ruby.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 0ed175945..ce89f9c63 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -2621,7 +2621,7 @@ public: Swig_restore(n); /* Done */ - Swig_name_unregister((const_String_or_char_ptr ) "construct"); + Swig_name_unregister("construct"); current = NO_CPP; klass->constructor_defined = 1; return SWIG_OK; @@ -2635,7 +2635,7 @@ public: /* First wrap the allocate method */ current = CONSTRUCTOR_ALLOCATE; - Swig_name_register("construct", "%n%n%c_allocate"); + Swig_name_register("construct", "%n%c_allocate"); return Language::copyconstructorHandler(n); } From bbf225ef6390438d637096514c409cf51495f408 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Mar 2010 09:54:07 +0000 Subject: [PATCH 032/203] Minor changes to error message for Java when -package is missing with nspace git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11943 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Java.html | 9 ++++++++- Source/Modules/java.cxx | 9 ++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 5b61955ab..857363840 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -1916,9 +1916,16 @@ Note that it only works for classes, structs, unions and enums declared within a When the nspace feature is used, the C++ namespaces are converted into Java packages of the same name. Proxy classes are thus declared within a package and this proxy makes numerous calls to the JNI intermediary class which is declared in the unnamed package by default. As Java does not support types declared in a named package accessing types declared in an unnamed package, the -package commandline option described earlier must be used to provide a parent package. -So if SWIG is run using the -package com.myco option, a wrapped class, MyWorld::Material::Color, can then be accessed as com.myco.MyWorld.Material.Color. +So if SWIG is run using the -package com.myco option, a wrapped class, MyWorld::Material::Color, can then be accessed as com.myco.MyWorld.Material.Color. If you don't specify a package, you will get the following error message:

        +
        +
        +example.i:16: Error: The nspace feature used on 'MyWorld::Material::Color' is not supported unless a package is specified
        +with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.
        +
        +
        +

        21.3.14 C++ templates

        diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 229e65379..924d11941 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1200,8 +1200,8 @@ public: if (package) { full_imclass_name = NewStringf("%s.%s", package, imclass_name); } else { - full_imclass_name = NewStringf("%s", imclass_name); - Printf(stderr, "The nspace feature used on %s is not supported unless a package is specified with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.\n", Getattr(n, "name")); + String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString(""); + Swig_error(Getfile(n), Getline(n), "The nspace feature used on '%s' is not supported unless a package is specified with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); SWIG_exit(EXIT_FAILURE); } } @@ -1866,9 +1866,8 @@ public: full_proxy_class_name = NewStringf("%s.%s.%s", package, nspace, proxy_class_name); full_imclass_name = NewStringf("%s.%s", package, imclass_name); } else { - full_proxy_class_name = NewStringf("%s.%s", nspace, proxy_class_name); - full_imclass_name = NewStringf("%s", imclass_name); - Printf(stderr, "The nspace feature used on %s is not supported unless a package is specified with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.\n", Getattr(n, "name")); + String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString(""); + Swig_error(Getfile(n), Getline(n), "The nspace feature used on '%s' is not supported unless a package is specified with -package - Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); SWIG_exit(EXIT_FAILURE); } } From 4f88d641af21c5bcfb9477370f6693a6c9711139 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Mar 2010 22:28:24 +0000 Subject: [PATCH 033/203] Better handling of file paths containing multiple path separators. Fix recent regression incorrectly detecting a directory on Windows when the output directory is not the current directory. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11944 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Source/Modules/main.cxx | 23 ++++++++++++----------- Source/Swig/misc.c | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 7b18af4c7..b680f87fc 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-03-13: wsfulton + Improve handling of file names and directories containing double/multiple path separators. + 2010-03-10: mutandiz (Mikel Bancroft) [allegrocl] Use fully qualified symbol name of cl::identity in emit_defun(). diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 86f279a67..2ad1665f6 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -281,20 +281,21 @@ static unsigned int decode_numbers_list(String *numlist) { // ----------------------------------------------------------------------------- // Sets the output directory for language specific (proxy) files if not set and -// adds trailing file separator if necessary. +// corrects the directory name and adds trailing file separator if necessary. // ----------------------------------------------------------------------------- -static void set_outdir(const String *c_wrapper_file_dir) { +static void configure_outdir(const String *c_wrapper_file_dir) { + + // Use the C wrapper file's directory if the output directory has not been set by user + if (!outdir || Len(outdir) == 0) + outdir = NewString(c_wrapper_file_dir); + + Swig_filename_correct(outdir); // Add file delimiter if not present in output directory name - if (outdir && Len(outdir) != 0) { - const char *outd = Char(outdir); - if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMITER), SWIG_FILE_DELIMITER) != 0) - Printv(outdir, SWIG_FILE_DELIMITER, NIL); - } - // Use the C wrapper file's directory if the output directory has not been set by user - if (!outdir) - outdir = NewString(c_wrapper_file_dir); + const char *outd = Char(outdir); + if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMITER), SWIG_FILE_DELIMITER) != 0) + Printv(outdir, SWIG_FILE_DELIMITER, NIL); } /* This function sets the name of the configuration file */ @@ -1221,7 +1222,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { } else { Setattr(top, "outfile_h", outfile_name_h); } - set_outdir(Swig_file_dirname(Getattr(top, "outfile"))); + configure_outdir(Swig_file_dirname(Getattr(top, "outfile"))); if (Swig_contract_mode_get()) { Swig_contracts(top); } diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 9a2a33278..8c480cc7c 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -22,7 +22,7 @@ char cvsroot_misc_c[] = "$Id$"; #ifdef _WIN32 #include -#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#define S_ISDIR(mode) (((mode) & S_IFDIR) == S_IFDIR) #endif static char *fake_version = 0; @@ -142,6 +142,26 @@ String *Swig_strip_c_comments(const String *s) { return stripped; } +/* ----------------------------------------------------------------------------- + * is_directory() + * ----------------------------------------------------------------------------- */ +static int is_directory(String *directory) { + int last = Len(directory) - 1; + int statres; + struct stat st; + char *dir = Char(directory); + if (dir[last] == SWIG_FILE_DELIMITER[0]) { + /* remove trailing slash - can cause S_ISDIR to fail on Windows, at least */ + dir[last] = 0; + statres = stat(dir, &st); + dir[last] = SWIG_FILE_DELIMITER[0]; + } else { + statres = stat(dir, &st); + } + Printf(stdout, "is_directory %d %s\n", (statres == 0 && S_ISDIR(st.st_mode)), dir); + return (statres == 0 && S_ISDIR(st.st_mode)); +} + /* ----------------------------------------------------------------------------- * Swig_new_subdirectory() * @@ -154,7 +174,7 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) { struct stat st; int current_directory = basedirectory ? (Len(basedirectory) == 0 ? 1 : 0) : 0; - if (current_directory || ((stat(Char(basedirectory), &st) == 0) && S_ISDIR(st.st_mode))) { + if (current_directory || is_directory(basedirectory)) { Iterator it; String *dir = basedirectory ? NewString(basedirectory) : NewString(""); List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX); @@ -186,7 +206,7 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) { } } } else { - error = NewStringf("Cannot create subdirectory %s under the base directory %s", subdirectory, basedirectory); + error = NewStringf("Cannot create subdirectory %s under the base directory %s. Either the base does not exist as a directory or it is not readable.", subdirectory, basedirectory); } return error; } @@ -194,7 +214,8 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) { /* ----------------------------------------------------------------------------- * Swig_filename_correct() * - * Corrects filenames on non-unix systems + * Corrects filename paths by removing duplicate delimeters and on non-unix + * systems use the correct delimeter across the whole name. * ----------------------------------------------------------------------------- */ void Swig_filename_correct(String *filename) { @@ -207,6 +228,9 @@ void Swig_filename_correct(String *filename) { /* accept Windows path separator in addition to Unix path separator */ Replaceall(filename, "\\", SWIG_FILE_DELIMITER); #endif + /* remove all duplicate file name delimiters */ + while (Replaceall(filename, SWIG_FILE_DELIMITER SWIG_FILE_DELIMITER, SWIG_FILE_DELIMITER)) { + } } /* ----------------------------------------------------------------------------- @@ -218,7 +242,9 @@ void Swig_filename_correct(String *filename) { String *Swig_filename_escape(String *filename) { String *adjusted_filename = Copy(filename); #if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */ - Replaceall(adjusted_filename, "\\\\", "\\"); /* remove double '\' in case any already present */ + /* remove all double '\' in case any already present */ + while (Replaceall(adjusted_filename, "\\\\", "\\")) { + } Replaceall(adjusted_filename, "\\", "\\\\"); #endif return adjusted_filename; From e81bfb86c00565ac0bd79917f9fcfcb41b718a9f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Mar 2010 23:08:02 +0000 Subject: [PATCH 034/203] Correct file and line number display for some error messages, these now also result in exiting with an error. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11945 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Source/Modules/csharp.cxx | 4 ++-- Source/Modules/java.cxx | 32 ++++++++++++++++---------------- Source/Modules/modula3.cxx | 2 +- Source/Modules/perl5.cxx | 4 ++-- Source/Modules/php.cxx | 6 +++--- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index b680f87fc..883963f27 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-03-13: wsfulton + [Java] Some very old deprecated pragma warnings are now errors. + 2010-03-13: wsfulton Improve handling of file names and directories containing double/multiple path separators. diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 4fb5699b8..38679dfba 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -712,7 +712,7 @@ public: Swig_restore(n); native_function_flag = false; } else { - Printf(stderr, "%s : Line %d. No return type for %%native method %s.\n", input_file, line_number, Getattr(n, "wrap:name")); + Swig_error(input_file, line_number, "No return type for %%native method %s.\n", Getattr(n, "wrap:name")); } return SWIG_OK; @@ -1586,7 +1586,7 @@ public: Delete(module_interfaces); module_interfaces = Copy(strvalue); } else { - Printf(stderr, "%s : Line %d. Unrecognized pragma.\n", input_file, line_number); + Swig_error(input_file, line_number, "Unrecognized pragma.\n"); } Delete(strvalue); } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 924d11941..d2338bd0f 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -785,7 +785,7 @@ public: Swig_restore(n); native_function_flag = false; } else { - Printf(stderr, "%s : Line %d. No return type for %%native method %s.\n", input_file, line_number, Getattr(n, "wrap:name")); + Swig_error(input_file, line_number, "No return type for %%native method %s.\n", Getattr(n, "wrap:name")); } return SWIG_OK; @@ -1630,37 +1630,37 @@ public: Delete(module_interfaces); module_interfaces = Copy(strvalue); } else if (Strcmp(code, "moduleimport") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use the moduleimports pragma.\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use the moduleimports pragma.\n"); } else if (Strcmp(code, "moduleinterface") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use the moduleinterfaces pragma.\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use the moduleinterfaces pragma.\n"); } else if (Strcmp(code, "modulemethodmodifiers") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%javamethodmodifiers.\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%javamethodmodifiers.\n"); } else if (Strcmp(code, "allshadowimport") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javaimports).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javaimports).\n"); } else if (Strcmp(code, "allshadowcode") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javacode).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javacode).\n"); } else if (Strcmp(code, "allshadowbase") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javabase).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javabase).\n"); } else if (Strcmp(code, "allshadowinterface") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javainterfaces).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javainterfaces).\n"); } else if (Strcmp(code, "allshadowclassmodifiers") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javaclassmodifiers).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javaclassmodifiers).\n"); } else if (proxy_flag) { if (Strcmp(code, "shadowcode") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javacode).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javacode).\n"); } else if (Strcmp(code, "shadowimport") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javaimports).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javaimports).\n"); } else if (Strcmp(code, "shadowbase") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javabase).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javabase).\n"); } else if (Strcmp(code, "shadowinterface") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javainterfaces).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javainterfaces).\n"); } else if (Strcmp(code, "shadowclassmodifiers") == 0) { - Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %%typemap(javaclassmodifiers).\n", input_file, line_number); + Swig_error(input_file, line_number, "Deprecated pragma. Please use %%typemap(javaclassmodifiers).\n"); } else { - Printf(stderr, "%s : Line %d. Unrecognized pragma.\n", input_file, line_number); + Swig_error(input_file, line_number, "Unrecognized pragma.\n"); } } else { - Printf(stderr, "%s : Line %d. Unrecognized pragma.\n", input_file, line_number); + Swig_error(input_file, line_number, "Unrecognized pragma.\n"); } Delete(strvalue); } diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index fb928a898..fc26dff85 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -1196,7 +1196,7 @@ MODULA3(): Swig_restore(n); native_function_flag = false; } else { - Printf(stderr, "%s : Line %d. No return type for %%native method %s.\n", input_file, line_number, Getattr(n, "wrap:name")); + Swig_error(input_file, line_number, "No return type for %%native method %s.\n", Getattr(n, "wrap:name")); } return SWIG_OK; diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 4be759194..f6ea029fe 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -1631,7 +1631,7 @@ public: if (value) { FILE *f = Swig_include_open(value); if (!f) { - Printf(stderr, "%s : Line %d. Unable to locate file %s\n", input_file, line_number, value); + Swig_error(input_file, line_number, "Unable to locate file %s\n", value); } else { char buffer[4096]; while (fgets(buffer, 4095, f)) { @@ -1641,7 +1641,7 @@ public: fclose(f); } } else { - Printf(stderr, "%s : Line %d. Unrecognized pragma.\n", input_file, line_number); + Swig_error(input_file, line_number, "Unrecognized pragma.\n"); } } } diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index c44e7c6ce..09eb21dcd 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1788,7 +1788,7 @@ done: Replaceall(tm, "$target", name); Printf(s_vinit, "%s\n", tm); } else { - Printf(stderr, "%s: Line %d, Unable to link with type %s\n", input_file, line_number, SwigType_str(t, 0)); + Swig_error(input_file, line_number, "Unable to link with type %s\n", SwigType_str(t, 0)); } /* Now generate PHP -> C sync blocks */ @@ -1798,7 +1798,7 @@ done: Replaceall(tm, "$symname", iname); Printf(f_c->code, "%s\n", tm); } else { - Printf(stderr,"%s: Line %d, Unable to link with type %s\n", input_file, line_number, SwigType_str(t, 0)); + Swig_error(input_file, line_number, "Unable to link with type %s\n", SwigType_str(t, 0)); } */ /* Now generate C -> PHP sync blocks */ @@ -1810,7 +1810,7 @@ done: Replaceall(tm, "$symname", iname); Printf(f_php->code, "%s\n", tm); } else { - Printf(stderr,"%s: Line %d, Unable to link with type %s\n", input_file, line_number, SwigType_str(t, 0)); + Swig_error(input_file, line_number, "Unable to link with type %s\n", SwigType_str(t, 0)); } } */ From c5b25bde5a5b12a51487b0b6c1451c11b8291456 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Mar 2010 23:24:15 +0000 Subject: [PATCH 035/203] Fix incorrect current directory handling from last commit git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11946 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/main.cxx | 58 ++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 2ad1665f6..f0e941f22 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -197,11 +197,11 @@ enum { STAGE1=1, STAGE2=2, STAGE3=4, STAGE4=8, STAGEOVERFLOW=16 }; static List *libfiles = 0; static List *all_output_files = 0; -// ----------------------------------------------------------------------------- -// check_suffix() -// -// Checks the suffix of a file to see if we should emit extern declarations. -// ----------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- + * check_suffix() + * + * Checks the suffix of a file to see if we should emit extern declarations. + * ----------------------------------------------------------------------------- */ static int check_suffix(String *filename) { const char *name = Char(filename); @@ -216,10 +216,11 @@ static int check_suffix(String *filename) { return 0; } -// ----------------------------------------------------------------------------- -// install_opts(int argc, char *argv[]) -// Install all command line options as preprocessor symbols -// ----------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- + * install_opts() + * + * Install all command line options as preprocessor symbols + * ----------------------------------------------------------------------------- */ static void install_opts(int argc, char *argv[]) { int i; @@ -255,11 +256,12 @@ static void install_opts(int argc, char *argv[]) { } } -// ----------------------------------------------------------------------------- -// decode_numbers_list(String *numlist) -// Decode comma separated list into a binary number of the inputs or'd together -// eg list="1,4" will return (2^0 || 2^3) = 0x1001 -// ----------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- + * decode_numbers_list() + * + * Decode comma separated list into a binary number of the inputs or'd together + * eg list="1,4" will return (2^0 || 2^3) = 0x1001 + * ----------------------------------------------------------------------------- */ static unsigned int decode_numbers_list(String *numlist) { unsigned int decoded_number = 0; @@ -279,10 +281,10 @@ static unsigned int decode_numbers_list(String *numlist) { return decoded_number; } -// ----------------------------------------------------------------------------- -// Sets the output directory for language specific (proxy) files if not set and -// corrects the directory name and adds trailing file separator if necessary. -// ----------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- + * Sets the output directory for language specific (proxy) files if not set and + * corrects the directory name and adds trailing file separator if necessary. + * ----------------------------------------------------------------------------- */ static void configure_outdir(const String *c_wrapper_file_dir) { @@ -292,10 +294,12 @@ static void configure_outdir(const String *c_wrapper_file_dir) { Swig_filename_correct(outdir); - // Add file delimiter if not present in output directory name - const char *outd = Char(outdir); - if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMITER), SWIG_FILE_DELIMITER) != 0) - Printv(outdir, SWIG_FILE_DELIMITER, NIL); + // Add trailing file delimiter if not present in output directory name + if (Len(outdir) > 0) { + const char *outd = Char(outdir); + if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMITER), SWIG_FILE_DELIMITER) != 0) + Printv(outdir, SWIG_FILE_DELIMITER, NIL); + } } /* This function sets the name of the configuration file */ @@ -1291,11 +1295,11 @@ int SWIG_main(int argc, char *argv[], Language *l) { return Swig_error_count(); } -// -------------------------------------------------------------------------- -// SWIG_exit(int exit_code) -// -// Cleanup and either freeze or exit -// -------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- + * SWIG_exit() + * + * Cleanup and either freeze or exit + * ----------------------------------------------------------------------------- */ void SWIG_exit(int exit_code) { while (freeze) { From cd317b3f1c1f668b318b4cced2497370cf823889 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 13 Mar 2010 23:39:46 +0000 Subject: [PATCH 036/203] Java/C# constants fix after last nspace commit git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11947 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 2 +- Source/Modules/java.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 38679dfba..8abc3307e 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1477,7 +1477,7 @@ public: Printf(constants_code, "(%s)%s.%s();\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname)); } else { // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname)); + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); } } else { Printf(constants_code, "%s.%s();\n", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index d2338bd0f..5fecf8208 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1522,7 +1522,7 @@ public: Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname)); } else { // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, full_imclass_name, Swig_name_get(getNSpace(), symname)); + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); } } else { Printf(constants_code, "%s.%s();\n", full_imclass_name ? full_imclass_name : imclass_name, Swig_name_get(getNSpace(), symname)); From 163d15e2e388fbdba3a3c76da7ad49dccfcead7c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 16 Mar 2010 22:20:41 +0000 Subject: [PATCH 037/203] remove debug printout git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11948 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/misc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 8c480cc7c..f845d1a03 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -158,7 +158,6 @@ static int is_directory(String *directory) { } else { statres = stat(dir, &st); } - Printf(stdout, "is_directory %d %s\n", (statres == 0 && S_ISDIR(st.st_mode)), dir); return (statres == 0 && S_ISDIR(st.st_mode)); } From 31485a7b3b1ab157c8b14f49d07123aedccb0cdd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 17 Mar 2010 19:35:45 +0000 Subject: [PATCH 038/203] Fix nspace when no -namespace is used (for C#) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11949 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 8abc3307e..f70403326 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3261,15 +3261,13 @@ public: * ----------------------------------------------------------------------------- */ void addOpenNamespace(const String *nspace, File *file) { - if (namespce) { - if (namespce || nspace) { - Printf(file, "namespace "); - if (namespce) - Printv(file, namespce, nspace ? "." : "", NIL); - if (nspace) - Printv(file, nspace, NIL); - Printf(file, " {\n"); - } + if (namespce || nspace) { + Printf(file, "namespace "); + if (namespce) + Printv(file, namespce, nspace ? "." : "", NIL); + if (nspace) + Printv(file, nspace, NIL); + Printf(file, " {\n"); } } @@ -3278,9 +3276,8 @@ public: * ----------------------------------------------------------------------------- */ void addCloseNamespace(const String *nspace, File *file) { - if (namespce) - if (namespce || nspace) - Printf(file, "\n}\n"); + if (namespce || nspace) + Printf(file, "\n}\n"); } /* ----------------------------------------------------------------------------- From ff0426355b613cb4b734f7dbfd12244a8488c0db Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 31 Mar 2010 06:15:49 +0000 Subject: [PATCH 039/203] Fix typo in rename message git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11955 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/ocaml/ocamlkw.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ocaml/ocamlkw.swg b/Lib/ocaml/ocamlkw.swg index 9b9096e2b..92d822219 100644 --- a/Lib/ocaml/ocamlkw.swg +++ b/Lib/ocaml/ocamlkw.swg @@ -2,7 +2,7 @@ #define OCAML_OCAMLKW_SWG_ /* Warnings for Ocaml keywords */ -#define OCAMLKW(x) %namewarn("314: '" #x "' is a ocaml keyword and it will properly renamed") #x +#define OCAMLKW(x) %namewarn("314: '" #x "' is an ocaml keyword and it will be appropriately renamed") #x /* from From 15dfd9f0e7470d8a3f23f9155ce0b9eb8ac97859 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 31 Mar 2010 19:14:34 +0000 Subject: [PATCH 040/203] minor formatting change git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11956 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pydocs.swg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/python/pydocs.swg b/Lib/python/pydocs.swg index 0091a30b9..862339da7 100644 --- a/Lib/python/pydocs.swg +++ b/Lib/python/pydocs.swg @@ -3,13 +3,13 @@ #ifdef SWIG_DOC_DOXYGEN_STYLE %typemap(doc) SWIGTYPE "@param $1_name $1_type value"; -%typemap(doc) SWIGTYPE* "@param $1_name $1_type value"; -%typemap(doc) const SWIGTYPE& "@param $1_name $1_type value"; +%typemap(doc) SWIGTYPE * "@param $1_name $1_type value"; +%typemap(doc) const SWIGTYPE & "@param $1_name $1_type value"; %typemap(doc) enum SWIGTYPE "@param $1_name enum $1_type value"; #else %typemap(doc) SWIGTYPE "$1_name: $1_type value"; -%typemap(doc) SWIGTYPE* "$1_name: $1_type value"; -%typemap(doc) const SWIGTYPE& "$1_name: $1_type value"; +%typemap(doc) SWIGTYPE * "$1_name: $1_type value"; +%typemap(doc) const SWIGTYPE & "$1_name: $1_type value"; %typemap(doc) enum SWIGTYPE "$1_name: enum $1_type value"; %typemap(doc) SWIGTYPE *INOUT "$1_name: $1_type input/ouput value"; From b1c594078628ca7b5e57aa63ea117e1cd281ec80 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 1 Apr 2010 18:12:48 +0000 Subject: [PATCH 041/203] test case fix for languages that don't support the nspace feature git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11957 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/nspace_extend.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/nspace_extend.i b/Examples/test-suite/nspace_extend.i index 7f7ba01f8..88f40bc69 100644 --- a/Examples/test-suite/nspace_extend.i +++ b/Examples/test-suite/nspace_extend.i @@ -31,8 +31,6 @@ namespace Outer { } %} -#endif - %extend Outer::Inner2::Color { Color() { return new Outer::Inner2::Color(); } ~Color() { delete $self; } @@ -48,3 +46,5 @@ namespace Outer { const Outer::Inner2::Color& col2c) {} } +#endif + From bdb136d611286df89ba94b04170259d75c51e9f8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 1 Apr 2010 18:26:37 +0000 Subject: [PATCH 042/203] Change typemap matching rules for the default type (SWIGTYPE) to follow template partial specialization type deduction. Fixes some containers of const pointers. SWIGTYPE*& typemps removed and replaced with SWIGTYPE *const&. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11958 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 70 ++++++++ Examples/test-suite/constant_pointers.i | 4 +- Examples/test-suite/global_namespace.i | 8 +- Examples/test-suite/java_pgcpp.i | 14 +- Examples/test-suite/li_boost_intrusive_ptr.i | 4 +- Examples/test-suite/li_boost_shared_ptr.i | 4 +- Examples/test-suite/pointer_reference.i | 4 +- Lib/allegrocl/allegrocl.swg | 6 + Lib/cffi/cffi.swg | 5 + Lib/chicken/chicken.swg | 10 ++ Lib/csharp/boost_shared_ptr.i | 8 +- Lib/csharp/csharp.swg | 26 +-- Lib/guile/std_map.i | 2 +- Lib/guile/std_vector.i | 2 +- Lib/guile/typemaps.i | 6 + Lib/java/boost_intrusive_ptr.i | 16 +- Lib/java/boost_shared_ptr.i | 8 +- Lib/java/java.swg | 26 +-- Lib/lua/lua.swg | 2 +- Lib/lua/luatypemaps.swg | 11 +- Lib/modula3/modula3.swg | 7 + Lib/mzscheme/typemaps.i | 7 + Lib/ocaml/std_map.i | 2 +- Lib/ocaml/typemaps.i | 8 + Lib/octave/boost_shared_ptr.i | 16 +- Lib/perl5/perltypemaps.swg | 5 +- Lib/perl5/std_map.i | 2 +- Lib/php/php.swg | 21 ++- Lib/php/std_map.i | 2 +- Lib/pike/pike.swg | 6 + Lib/python/boost_shared_ptr.i | 16 +- Lib/python/pytypemaps.swg | 2 +- Lib/r/rtype.swg | 14 +- Lib/tcl/std_map.i | 2 +- Lib/tcl/tcltypemaps.swg | 3 +- Lib/typemaps/swigtype.swg | 22 ++- Source/Modules/lang.cxx | 34 ++-- Source/Swig/stype.c | 180 +++++++++++++++++++ Source/Swig/swig.h | 2 + Source/Swig/typemap.c | 6 +- Source/Swig/typeobj.c | 6 + 41 files changed, 477 insertions(+), 122 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 883963f27..0be45290b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,76 @@ Version 2.0.0 (in progress) ============================ +2010-04-01: wsfulton + Numerous subtle typemap matching rule fixes when using the default type. The typemap + matching rules are to take a type and find the best default typemap (SWIGTYPE, SWIGTYPE* etc), + then look for the next best match by reducing the chosen default type. The type reduction + now follows C++ template partial specialization matching rules. + + Below are the set of changes made showing the default type reduction + along with the old reduced type and the new version of the reduced type: + + SWIGTYPE const &[ANY] + new: SWIGTYPE const &[] + old: SWIGTYPE (&)[ANY] + + SWIGTYPE *const [ANY] + new: SWIGTYPE const [ANY] + old: SWIGTYPE *[ANY] + + SWIGTYPE const *const [ANY] + new: SWIGTYPE *const [ANY] + old: SWIGTYPE const *[ANY] + + SWIGTYPE const *const & + new: SWIGTYPE *const & + old: SWIGTYPE const *& + + SWIGTYPE *const * + new: SWIGTYPE const * + old: SWIGTYPE ** + + SWIGTYPE *const & + new: SWIGTYPE const & + old: SWIGTYPE *& + + Additionally, a const SWIGTYPE lookup is used now for any constant type. Some examples, where + T is some reduced type, eg int, struct Foo: + + T const + new: SWIGTYPE const + old: SWIGTYPE + + T *const + new: SWIGTYPE *const + old: SWIGTYPE * + + T const[] + new: SWIGTYPE const[] + old: SWIGTYPE[] + + enum T const + new: enum SWIGTYPE const + old: enum SWIGTYPE + + T (*const )[] + new: SWIGTYPE (*const )[] + old: SWIGTYPE (*)[] + + Reminder: the typemap matching rules can now be seen for any types being wrapped by using + either the -debug-tmsearch or -debug-tmused options. + + In practice this leads to some subtle matching rule changes and the majority of users + won't notice any changes, except in the prime area of motivation for this change: Improve + STL containers of const pointers and passing const pointers by reference. This is fixed + because many of the STL containers use a type 'T const&' as parameters and when T is + a const pointer, for example, 'K const*', then the full type is 'K const*const&'. This + means that the 'SWIGTYPE *const&' typemaps now match when T is either a non-const or + const pointer. Furthermore, some target languages incorrectly had 'SWIGTYPE *&' typemaps + when these should have been 'SWIGTYPE *const&'. These have been corrected (Java, C#, Lua, PHP). + + *** POTENTIAL INCOMPATIBILITY *** + 2010-03-13: wsfulton [Java] Some very old deprecated pragma warnings are now errors. diff --git a/Examples/test-suite/constant_pointers.i b/Examples/test-suite/constant_pointers.i index c2344fb6a..277d3cc75 100644 --- a/Examples/test-suite/constant_pointers.i +++ b/Examples/test-suite/constant_pointers.i @@ -70,6 +70,8 @@ public: void ret6(int*& a) {} int*& ret7() {return GlobalIntPtr;} + void ret8(int*const& a) {} + int*const& ret9() {return GlobalIntPtr;} ReturnValuesTest() : int3(NULL) {} private: ReturnValuesTest& operator=(const ReturnValuesTest&); @@ -112,7 +114,7 @@ int* const globalRet2() {return &GlobalInt;} return b; } - B const*& cbar(B const*& b) { + B *const& cbar(B *const& b) { return b; } } diff --git a/Examples/test-suite/global_namespace.i b/Examples/test-suite/global_namespace.i index 31dbb9e59..7b575614f 100644 --- a/Examples/test-suite/global_namespace.i +++ b/Examples/test-suite/global_namespace.i @@ -11,8 +11,8 @@ class Klass6 {}; class Klass7 {}; struct KlassMethods { - static void methodA(::Klass1 v, const ::Klass2 cv, const ::Klass3 *cp, ::Klass4 *p, const ::Klass5 &cr, ::Klass6 &r, ::Klass7*& pr) {} - static void methodB( Klass1 v, const Klass2 cv, const Klass3 *cp, Klass4 *p, const Klass5 &cr, Klass6 &r, Klass7*& pr) {} + static void methodA(::Klass1 v, const ::Klass2 cv, const ::Klass3 *cp, ::Klass4 *p, const ::Klass5 &cr, ::Klass6 &r, ::Klass7*const& pr) {} + static void methodB( Klass1 v, const Klass2 cv, const Klass3 *cp, Klass4 *p, const Klass5 &cr, Klass6 &r, Klass7*const& pr) {} }; %} @@ -28,8 +28,8 @@ class XYZ7 {}; } struct XYZMethods { - static void methodA(::Space::XYZ1 v, const ::Space::XYZ2 cv, const ::Space::XYZ3 *cp, ::Space::XYZ4 *p, const ::Space::XYZ5 &cr, ::Space::XYZ6 &r, ::Space::XYZ7*& pr) {} - static void methodB( Space::XYZ1 v, const Space::XYZ2 cv, const Space::XYZ3 *cp, Space::XYZ4 *p, const Space::XYZ5 &cr, Space::XYZ6 &r, Space::XYZ7*& pr) {} + static void methodA(::Space::XYZ1 v, const ::Space::XYZ2 cv, const ::Space::XYZ3 *cp, ::Space::XYZ4 *p, const ::Space::XYZ5 &cr, ::Space::XYZ6 &r, ::Space::XYZ7*const& pr) {} + static void methodB( Space::XYZ1 v, const Space::XYZ2 cv, const Space::XYZ3 *cp, Space::XYZ4 *p, const Space::XYZ5 &cr, Space::XYZ6 &r, Space::XYZ7*const& pr) {} }; %} diff --git a/Examples/test-suite/java_pgcpp.i b/Examples/test-suite/java_pgcpp.i index 6a50ffe72..6bfef9316 100644 --- a/Examples/test-suite/java_pgcpp.i +++ b/Examples/test-suite/java_pgcpp.i @@ -16,21 +16,21 @@ %typemap(jstype) Space::Classic ** " Classic " %typemap(javain) Space::Classic ** "Classic.getCPtr($javainput)" -// Default typemaps for pass by value, ref, pointer and pointer reference should use pgcpp +// Default typemaps for pass by value, ref, pointer and pointer const reference should use pgcpp %inline %{ namespace Space { struct Classic { Classic() {} - Classic(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {} - Classic(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5, bool b) {} + Classic(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {} + Classic(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5, bool b) {} - void method(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {} - void methodconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5) {} + void method(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {} + void methodconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5) {} }; - void function(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {} - void functionconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5) {} + void function(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {} + void functionconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5) {} } %} diff --git a/Examples/test-suite/li_boost_intrusive_ptr.i b/Examples/test-suite/li_boost_intrusive_ptr.i index 7c37e6843..47b64682a 100644 --- a/Examples/test-suite/li_boost_intrusive_ptr.i +++ b/Examples/test-suite/li_boost_intrusive_ptr.i @@ -295,7 +295,7 @@ Klass& reftest(Klass& k) { k.append(" reftest"); return k; } -Klass*& pointerreftest(Klass*& k) { +Klass *const& pointerreftest(Klass *const& k) { k->append(" pointerreftest"); return k; } @@ -334,7 +334,7 @@ std::string overload_rawbyptr(int i) { return "int"; } std::string overload_rawbyptr(Klass *k) { return "rawbyptr"; } std::string overload_rawbyptrref(int i) { return "int"; } -std::string overload_rawbyptrref(Klass *&k) { return "rawbyptrref"; } +std::string overload_rawbyptrref(Klass *const&k) { return "rawbyptrref"; } diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index f992a3c08..7a9468e4f 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -222,7 +222,7 @@ Klass& reftest(Klass& k) { k.append(" reftest"); return k; } -Klass*& pointerreftest(Klass*& k) { +Klass *const& pointerreftest(Klass *const& k) { k->append(" pointerreftest"); return k; } @@ -275,7 +275,7 @@ std::string overload_rawbyptr(int i) { return "int"; } std::string overload_rawbyptr(Klass *k) { return "rawbyptr"; } std::string overload_rawbyptrref(int i) { return "int"; } -std::string overload_rawbyptrref(Klass *&k) { return "rawbyptrref"; } +std::string overload_rawbyptrref(Klass *const&k) { return "rawbyptrref"; } diff --git a/Examples/test-suite/pointer_reference.i b/Examples/test-suite/pointer_reference.i index b7c605429..c57a32374 100644 --- a/Examples/test-suite/pointer_reference.i +++ b/Examples/test-suite/pointer_reference.i @@ -29,10 +29,10 @@ struct Struct { static Struct *pInstance; }; -void set(Struct *& s) { +void set(Struct *const& s) { Struct::instance = *s; } -Struct *& get() { +Struct *const& get() { return Struct::pInstance; } %} diff --git a/Lib/allegrocl/allegrocl.swg b/Lib/allegrocl/allegrocl.swg index 266303113..cc23a1f90 100644 --- a/Lib/allegrocl/allegrocl.swg +++ b/Lib/allegrocl/allegrocl.swg @@ -219,6 +219,12 @@ $body)" %typemap(lispclass) wchar_t* "cl:string"; ////////////////////////////////////////////////////////////// +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* name conversion for overloaded operators. */ #ifdef __cplusplus %rename(__add__) *::operator+; diff --git a/Lib/cffi/cffi.swg b/Lib/cffi/cffi.swg index c832e00d2..6ac82f45e 100644 --- a/Lib/cffi/cffi.swg +++ b/Lib/cffi/cffi.swg @@ -130,6 +130,11 @@ %typemap(lispclass) double "cl:number"; %typemap(lispclass) char * "cl:string"; +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } %{ diff --git a/Lib/chicken/chicken.swg b/Lib/chicken/chicken.swg index 68f022570..112780499 100644 --- a/Lib/chicken/chicken.swg +++ b/Lib/chicken/chicken.swg @@ -679,6 +679,16 @@ $result = C_SCHEME_UNDEFINED; %apply unsigned long { size_t }; +/* ------------------------------------------------------------ + * Various + * ------------------------------------------------------------ */ + +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* ------------------------------------------------------------ * Overloaded operator support * ------------------------------------------------------------ */ diff --git a/Lib/csharp/boost_shared_ptr.i b/Lib/csharp/boost_shared_ptr.i index 52ac510ce..86a62c33c 100644 --- a/Lib/csharp/boost_shared_ptr.i +++ b/Lib/csharp/boost_shared_ptr.i @@ -44,10 +44,10 @@ %{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %} // plain pointer by reference -%typemap(in) CONST TYPE *& ($*1_ltype temp = 0) -%{ temp = (((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0); +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0) +%{ temp = (TYPE *)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0); $1 = &temp; %} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& %{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %} // shared_ptr by value @@ -138,7 +138,7 @@ PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode return ret; } -%typemap(csout, excode=SWIGEXCODE) CONST TYPE *& { +%typemap(csout, excode=SWIGEXCODE) TYPE *CONST& { IntPtr cPtr = $imcall; PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode return ret; diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 1f58db48d..57998b9db 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -522,6 +522,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIGTYPE, SWIGTYPE *, SWIGTYPE &, + SWIGTYPE *const&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" @@ -782,24 +783,21 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { } %} /* Pointer reference typemaps */ -%typemap(ctype) SWIGTYPE *& "void *" -%typemap(imtype, out="IntPtr") SWIGTYPE *& "HandleRef" -%typemap(cstype) SWIGTYPE *& "$*csclassname" -%typemap(csin) SWIGTYPE *& "$*csclassname.getCPtr($csinput)" -%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *& { +%typemap(ctype) SWIGTYPE *const& "void *" +%typemap(imtype, out="IntPtr") SWIGTYPE *const& "HandleRef" +%typemap(cstype) SWIGTYPE *const& "$*csclassname" +%typemap(csin) SWIGTYPE *const& "$*csclassname.getCPtr($csinput)" +%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *const& { IntPtr cPtr = $imcall; $*csclassname ret = (cPtr == IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode return ret; } -%typemap(in) SWIGTYPE *& ($*1_ltype temp = 0) +%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) %{ temp = ($*1_ltype)$input; - $1 = &temp; %} -%typemap(out) SWIGTYPE *& + $1 = ($1_ltype)&temp; %} +%typemap(out) SWIGTYPE *const& %{ $result = (void *)*$1; %} -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } - /* Marshal C/C++ pointer to IntPtr */ %typemap(ctype) void *VOID_INT_PTR "void *" %typemap(imtype) void *VOID_INT_PTR "IntPtr" @@ -953,6 +951,12 @@ using System.Runtime.InteropServices; %apply unsigned long { size_t }; %apply const unsigned long & { const size_t & }; +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* csharp keywords */ %include diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index 19c863096..600075ebe 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -224,7 +224,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& __getitem__(const K& key) throw (std::out_of_range) { + const T& __getitem__(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/guile/std_vector.i b/Lib/guile/std_vector.i index 6801daee8..6a5e8ae36 100644 --- a/Lib/guile/std_vector.i +++ b/Lib/guile/std_vector.i @@ -208,7 +208,7 @@ namespace std { self->pop_back(); return x; } - T& ref(int i) throw (std::out_of_range) { + const T& ref(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && i *smartarg = 0) %{ +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ // plain pointer by reference - temp = ((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); + temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); $1 = &temp; %} -%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE *& %{ +%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") TYPE *CONST& %{ // plain pointer by reference(out) #if ($owner) if (*$1) { @@ -246,7 +246,7 @@ long cPtr = $jnicall; return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true); } -%typemap(javaout) CONST TYPE *& { +%typemap(javaout) TYPE *CONST& { long cPtr = $jnicall; return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true); } @@ -353,10 +353,10 @@ %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %} // plain pointer by reference -%typemap(in) CONST TYPE *& ($*1_ltype temp = 0) -%{ temp = ((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0) +%{ temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); $1 = &temp; %} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %} %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{ @@ -396,7 +396,7 @@ long cPtr = $jnicall; return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true); } -%typemap(javaout) CONST TYPE *& { +%typemap(javaout) TYPE *CONST& { long cPtr = $jnicall; return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true); } diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i index 38262f20c..1c74a2453 100644 --- a/Lib/java/boost_shared_ptr.i +++ b/Lib/java/boost_shared_ptr.i @@ -44,10 +44,10 @@ %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %} // plain pointer by reference -%typemap(in) CONST TYPE *& ($*1_ltype temp = 0) -%{ temp = ((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0) +%{ temp = (TYPE *)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); $1 = &temp; %} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %} // shared_ptr by value @@ -132,7 +132,7 @@ long cPtr = $jnicall; return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true); } -%typemap(javaout) CONST TYPE *& { +%typemap(javaout) TYPE *CONST& { long cPtr = $jnicall; return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true); } diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 2dfbe59f2..0fadf1604 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -897,6 +897,7 @@ SWIGTYPE, SWIGTYPE *, SWIGTYPE &, + SWIGTYPE *const&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" @@ -1025,23 +1026,20 @@ } /* Pointer reference typemaps */ -%typemap(jni) SWIGTYPE *& "jlong" -%typemap(jtype) SWIGTYPE *& "long" -%typemap(jstype) SWIGTYPE *& "$*javaclassname" -%typemap(javain) SWIGTYPE *& "$*javaclassname.getCPtr($javainput)" -%typemap(javaout) SWIGTYPE *& { +%typemap(jni) SWIGTYPE *const& "jlong" +%typemap(jtype) SWIGTYPE *const& "long" +%typemap(jstype) SWIGTYPE *const& "$*javaclassname" +%typemap(javain) SWIGTYPE *const& "$*javaclassname.getCPtr($javainput)" +%typemap(javaout) SWIGTYPE *const& { long cPtr = $jnicall; return (cPtr == 0) ? null : new $*javaclassname(cPtr, $owner); } -%typemap(in) SWIGTYPE *& ($*1_ltype temp = 0) +%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) %{ temp = *($1_ltype)&$input; - $1 = &temp; %} -%typemap(out) SWIGTYPE *& + $1 = ($1_ltype)&temp; %} +%typemap(out) SWIGTYPE *const& %{ *($1_ltype)&$result = *$1; %} -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } - /* Typemaps used for the generation of proxy and type wrapper class code */ %typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(javaclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" @@ -1203,6 +1201,12 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) %apply unsigned long { size_t }; %apply const unsigned long & { const size_t & }; +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* java keywords */ %include diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index c3f5cecc5..5218bf0a8 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -40,7 +40,7 @@ %typemap(consttab) long long, unsigned long long { SWIG_LUA_STRING, (char *) "$symname", 0, 0, (void *)"$value", 0} -%typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] +%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE [] { SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor} // member function pointers diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 401541267..58f42eea1 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -167,11 +167,11 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} // Also needed for object ptrs by const ref // eg A* const& ref_pointer(A* const& a); // found in mixed_types.i -%typemap(in,checkfn="lua_isuserdata") SWIGTYPE *&($*ltype temp) +%typemap(in,checkfn="lua_isuserdata") SWIGTYPE *const&($*ltype temp) %{temp=($*ltype)SWIG_MustGetPtr(L,$input,$*descriptor,0,$argnum,"$symname"); -$1=&temp;%} +$1=($1_ltype)&temp;%} -%typemap(out) SWIGTYPE *& +%typemap(out) SWIGTYPE *const& %{SWIG_NewPointerObj(L,*$1,$*descriptor,$owner); SWIG_arg++; %} @@ -335,7 +335,7 @@ parmeters match which function // Also needed for object ptrs by const ref // eg const A* ref_pointer(A* const& a); // found in mixed_types.i -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE* const & +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const& { void *ptr; if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $*descriptor, 0)) { @@ -352,6 +352,9 @@ parmeters match which function // Array reference typemaps %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + // size_t (which is just a unsigned long) %apply unsigned long { size_t }; %apply const unsigned long & { const size_t & }; diff --git a/Lib/modula3/modula3.swg b/Lib/modula3/modula3.swg index 599a12e5a..3affdd0de 100644 --- a/Lib/modula3/modula3.swg +++ b/Lib/modula3/modula3.swg @@ -745,3 +745,10 @@ FROM BlaBla IMPORT Bla; /* Some ANSI C typemaps */ %apply unsigned long { size_t }; + +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + diff --git a/Lib/mzscheme/typemaps.i b/Lib/mzscheme/typemaps.i index b9f22440c..f12513df8 100644 --- a/Lib/mzscheme/typemaps.i +++ b/Lib/mzscheme/typemaps.i @@ -349,3 +349,10 @@ REF_MAP(double, SCHEME_REALP, scheme_real_to_double, } +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + + diff --git a/Lib/ocaml/std_map.i b/Lib/ocaml/std_map.i index f202e74ed..d7bf1e0f7 100644 --- a/Lib/ocaml/std_map.i +++ b/Lib/ocaml/std_map.i @@ -29,7 +29,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(const K& key) throw (std::out_of_range) { + const T& get(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i index 39544de94..e5458a3e2 100644 --- a/Lib/ocaml/typemaps.i +++ b/Lib/ocaml/typemaps.i @@ -314,3 +314,11 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val); %swig_enum_out(out) %swig_enum_out(varout) %swig_enum_out(directorin) + + +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + diff --git a/Lib/octave/boost_shared_ptr.i b/Lib/octave/boost_shared_ptr.i index 2a3c1532f..d702108a6 100644 --- a/Lib/octave/boost_shared_ptr.i +++ b/Lib/octave/boost_shared_ptr.i @@ -143,7 +143,7 @@ // plain pointer by reference // Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance -%typemap(in) CONST TYPE *& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { @@ -158,15 +158,15 @@ } $1 = &temp; } -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& { +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(varin) CONST TYPE *& %{ +%typemap(varin) TYPE *CONST& %{ #error "varin typemap not implemented" %} -%typemap(varout) CONST TYPE *& %{ +%typemap(varout) TYPE *CONST& %{ #error "varout typemap not implemented" %} @@ -283,10 +283,10 @@ // Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting // function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) - CONST TYPE, - CONST TYPE &, - CONST TYPE *, - CONST TYPE *&, + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg index a59f84689..540974476 100644 --- a/Lib/perl5/perltypemaps.swg +++ b/Lib/perl5/perltypemaps.swg @@ -75,7 +75,7 @@ %include /* ------------------------------------------------------------ - * Perl extra typemaps + * Perl extra typemaps / typemap overrides * ------------------------------------------------------------ */ %typemap(varout,type="$1_descriptor") SWIGTYPE *, SWIGTYPE [] @@ -90,3 +90,6 @@ %typemap(varout,type="$1_descriptor") SWIGTYPE (CLASS::*) { SWIG_MakePackedObj($result, (void *) &$1, sizeof($1_type), $1_descriptor); } + +%typemap(varout) SWIGTYPE *const = SWIGTYPE *; + diff --git a/Lib/perl5/std_map.i b/Lib/perl5/std_map.i index b19414597..ab0d3816d 100644 --- a/Lib/perl5/std_map.i +++ b/Lib/perl5/std_map.i @@ -30,7 +30,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(const K& key) throw (std::out_of_range) { + const T& get(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/php/php.swg b/Lib/php/php.swg index feeb9c5df..ff4001d7e 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -115,12 +115,12 @@ } } -%typemap(in) SWIGTYPE *& ($*ltype temp) +%typemap(in) SWIGTYPE *const& ($*ltype temp) { if(SWIG_ConvertPtr(*$input, (void **) &temp, $*1_descriptor, 0) < 0) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); } - $1 = &temp; + $1 = ($1_ltype)&temp; } %typemap(in) SWIGTYPE *DISOWN @@ -339,7 +339,7 @@ SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); %} -%typemap(out) SWIGTYPE *& +%typemap(out) SWIGTYPE *const& %{ SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner); %} @@ -394,10 +394,6 @@ SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1_name), $&1_descriptor, 2); } -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } - - %typemap(out) void ""; %typemap(out) char [ANY] @@ -441,10 +437,11 @@ _v = (SWIG_ConvertPtr(*$input, (void **)&tmp, $&1_descriptor, 0) >= 0); } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, +%typecheck(SWIG_TYPECHECK_POINTER) + SWIGTYPE *, SWIGTYPE [], SWIGTYPE &, - SWIGTYPE *& + SWIGTYPE *const& { void *tmp; _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0); @@ -478,6 +475,12 @@ SWIG_PHP_Error(E_ERROR, (char *)$1); %} +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* php keywords */ %include diff --git a/Lib/php/std_map.i b/Lib/php/std_map.i index cfb82f44c..b6b417da7 100644 --- a/Lib/php/std_map.i +++ b/Lib/php/std_map.i @@ -29,7 +29,7 @@ namespace std { unsigned int size() const; void clear(); %extend { - T& get(const K& key) throw (std::out_of_range) { + const T& get(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/pike/pike.swg b/Lib/pike/pike.swg index 2ba27671e..0cfec52b0 100644 --- a/Lib/pike/pike.swg +++ b/Lib/pike/pike.swg @@ -264,6 +264,12 @@ extern "C" { } } +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* ------------------------------------------------------------ * Overloaded operator support * ------------------------------------------------------------ */ diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index d5dffcda9..59a3a9298 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -151,7 +151,7 @@ // plain pointer by reference // Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance -%typemap(in) CONST TYPE *& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { @@ -166,15 +166,15 @@ } $1 = &temp; } -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& { +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(varin) CONST TYPE *& %{ +%typemap(varin) TYPE *CONST& %{ #error "varin typemap not implemented" %} -%typemap(varout) CONST TYPE *& %{ +%typemap(varout) TYPE *CONST& %{ #error "varout typemap not implemented" %} @@ -291,10 +291,10 @@ // Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting // function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) - CONST TYPE, - CONST TYPE &, - CONST TYPE *, - CONST TYPE *&, + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index e8df069ef..817ed1d90 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -61,7 +61,7 @@ /* ------------------------------------------------------------ - * Python extra typemaps + * Python extra typemaps / typemap overrides * ------------------------------------------------------------ */ /* Get the address of the 'python self' object */ diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index ee01d07d7..5103e43db 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -29,8 +29,10 @@ %typemap("rtype") bool, bool * "logical"; %typemap("rtype") enum SWIGTYPE "character"; %typemap("rtype") enum SWIGTYPE * "character"; +%typemap("rtype") enum SWIGTYPE *const "character"; %typemap("rtype") enum SWIGTYPE & "character"; %typemap("rtype") SWIGTYPE * "$R_class"; +%typemap("rtype") SWIGTYPE *const "$R_class"; %typemap("rtype") SWIGTYPE & "$R_class"; %typemap("rtype") SWIGTYPE "$&R_class"; @@ -65,13 +67,15 @@ %{ $input = enumToInteger($input, "$R_class"); %} %typemap(scoercein) enum SWIGTYPE * %{ $input = enumToInteger($input, "$R_class"); %} +%typemap(scoercein) enum SWIGTYPE *const + %{ $input = enumToInteger($input, "$R_class"); %} -%typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE & +%typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE & %{ %} /* -%typemap(scoercein) SWIGTYPE * +%typemap(scoercein) SWIGTYPE *, SWIGTYPE *const %{ $input = coerceIfNotSubclass($input, "$R_class") %} %typemap(scoercein) SWIGTYPE & @@ -115,6 +119,9 @@ string &, std::string & %typemap(scoerceout) enum SWIGTYPE * %{ $result = enumToInteger($result, "$R_class"); %} +%typemap(scoerceout) enum SWIGTYPE *const + %{ $result = enumToInteger($result, "$R_class"); %} + %typemap(scoerceout) SWIGTYPE %{ class($result) <- "$&R_class"; %} @@ -125,6 +132,9 @@ string &, std::string & %typemap(scoerceout) SWIGTYPE * %{ class($result) <- "$R_class"; %} +%typemap(scoerceout) SWIGTYPE *const + %{ class($result) <- "$R_class"; %} + /* Override the SWIGTYPE * above. */ %typemap(scoerceout) char, char *, diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i index 006a62efd..9d27e0f39 100644 --- a/Lib/tcl/std_map.i +++ b/Lib/tcl/std_map.i @@ -31,7 +31,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(const K& key) throw (std::out_of_range) { + const T& get(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/tcl/tcltypemaps.swg b/Lib/tcl/tcltypemaps.swg index 7199e674c..d93c8869b 100644 --- a/Lib/tcl/tcltypemaps.swg +++ b/Lib/tcl/tcltypemaps.swg @@ -61,7 +61,7 @@ /* ------------------------------------------------------------ - * Tcl extra typemaps + * Tcl extra typemaps / typemap overrides * ------------------------------------------------------------ */ #if 1 @@ -84,6 +84,7 @@ %typemap(out) SWIGTYPE = SWIGTYPE INSTANCE; %typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE; +%typemap(out) SWIGTYPE *const = SWIGTYPE *; %typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE; %typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[]; %typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE; diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index 15f2f9b41..f57766962 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -21,15 +21,15 @@ %typemap(freearg) SWIGTYPE [] ""; -%typemap(in, noblock=1) SWIGTYPE* const& (void *argp = 0, int res = 0, $*ltype temp) { +%typemap(in, noblock=1) SWIGTYPE *const& (void *argp = 0, int res = 0, $*1_ltype temp) { res = SWIG_ConvertPtr($input, &argp, $*descriptor, $disown | %convertptr_flags); if (!SWIG_IsOK(res)) { %argument_fail(res, "$*ltype", $symname, $argnum); } temp = %reinterpret_cast(argp, $*ltype); - $1 = &temp; + $1 = %reinterpret_cast(&temp, $1_ltype); } -%typemap(freearg) SWIGTYPE* const& ""; +%typemap(freearg) SWIGTYPE *const& ""; /* Reference */ @@ -106,7 +106,7 @@ %set_output(SWIG_NewPointerObj(%as_voidptr($1), $descriptor, $owner | %newpointer_flags)); } -%typemap(out, noblock=1) SWIGTYPE* const& { +%typemap(out, noblock=1) SWIGTYPE *const& { %set_output(SWIG_NewPointerObj(%as_voidptr(*$1), $*descriptor, $owner | %newpointer_flags)); } @@ -299,6 +299,12 @@ $1 = SWIG_CheckState(res); } +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE *const& { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $descriptor, 0); + $1 = SWIG_CheckState(res); +} + %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE & { void *vptr = 0; int res = SWIG_ConvertPtr($input, &vptr, $descriptor, 0); @@ -337,7 +343,7 @@ /* directorin */ -%typemap(directorin,noblock=1) SWIGTYPE*, SWIGTYPE* const& { +%typemap(directorin,noblock=1) SWIGTYPE *, SWIGTYPE *const& { $input = SWIG_NewPointerObj(%as_voidptr($1_name), $descriptor, %newpointer_flags); } @@ -345,7 +351,7 @@ $input = SWIG_NewPointerObj(%as_voidptr(&$1_name), $&descriptor, %newpointer_flags); } -%typemap(directorin,noblock=1) SWIGTYPE& { +%typemap(directorin,noblock=1) SWIGTYPE & { $input = SWIG_NewPointerObj(%as_voidptr(&$1_name), $descriptor, %newpointer_flags); } @@ -407,7 +413,7 @@ * --- Constants --- * ------------------------------------------------------------ */ -%typemap(constcode,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []{ +%typemap(constcode,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { %set_constant("$symname", SWIG_NewPointerObj(%as_voidptr($value),$descriptor,%newpointer_flags)); } @@ -547,6 +553,7 @@ } #endif +%apply SWIGTYPE * { SWIGTYPE *const } /* ------------------------------------------------------------ * --- Special typemaps --- @@ -602,3 +609,4 @@ %typemap(varout,noblock=1) SWIGTYPE INSTANCE { %set_varoutput(SWIG_NewInstanceObj(%as_voidptr(&$1), $&1_descriptor, %newinstance_flags)); } + diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 778c8e5ba..2bfddc764 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3014,8 +3014,6 @@ Node *Language::classLookup(SwigType *s) { Symtab *stab = 0; SwigType *ty1 = SwigType_typedef_resolve_all(s); SwigType *ty2 = SwigType_strip_qualifiers(ty1); - Delete(ty1); - ty1 = 0; String *base = SwigType_base(ty2); @@ -3052,11 +3050,18 @@ Node *Language::classLookup(SwigType *s) { if (n) { /* Found a match. Look at the prefix. We only allow the cases where where we want a proxy class for the particular type */ - if ((Len(prefix) == 0) || // simple type (pass by value) - (Strcmp(prefix, "p.") == 0) || // pointer - (Strcmp(prefix, "r.") == 0) || // reference - (Strcmp(prefix, "r.p.") == 0) || // pointer by reference - SwigType_prefix_is_simple_1D_array(prefix)) { // Simple 1D array (not arrays of pointers/references) + bool acceptable_prefix = + (Len(prefix) == 0) || // simple type (pass by value) + (Strcmp(prefix, "p.") == 0) || // pointer + (Strcmp(prefix, "r.") == 0) || // reference + SwigType_prefix_is_simple_1D_array(prefix); // Simple 1D array (not arrays of pointers/references) + // Also accept pointer by const reference, not non-const pointer reference + if (!acceptable_prefix && (Strcmp(prefix, "r.p.") == 0)) { + Delete(prefix); + prefix = SwigType_prefix(ty1); + acceptable_prefix = (Strncmp(prefix, "r.q(const", 9) == 0); + } + if (acceptable_prefix) { SwigType *cs = Copy(s); Setattr(classtypes, cs, n); Delete(cs); @@ -3064,9 +3069,10 @@ Node *Language::classLookup(SwigType *s) { n = 0; } } - Delete(ty2); - Delete(base); Delete(prefix); + Delete(base); + Delete(ty2); + Delete(ty1); } if (n && (GetFlag(n, "feature:ignore") || Getattr(n, "feature:onlychildren"))) { n = 0; @@ -3092,10 +3098,6 @@ Node *Language::enumLookup(SwigType *s) { SwigType *lt = SwigType_ltype(s); SwigType *ty1 = SwigType_typedef_resolve_all(lt); SwigType *ty2 = SwigType_strip_qualifiers(ty1); - Delete(lt); - Delete(ty1); - lt = 0; - ty1 = 0; String *base = SwigType_base(ty2); @@ -3134,9 +3136,11 @@ Node *Language::enumLookup(SwigType *s) { n = 0; } } - Delete(ty2); - Delete(base); Delete(prefix); + Delete(base); + Delete(ty2); + Delete(ty1); + Delete(lt); } if (n && (GetFlag(n, "feature:ignore"))) { n = 0; diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index fd6a06ca0..079fa07fe 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -492,6 +492,186 @@ SwigType *SwigType_default(SwigType *t) { return def; } +/* ----------------------------------------------------------------------------- + * SwigType_default_create() + * + * Create the default type for this datatype. This takes a type and strips it + * down to a generic form first by resolving all typedefs. + * + * Rules: + * Pointers: p.SWIGTYPE + * References: r.SWIGTYPE + * Arrays no dimension: a().SWIGTYPE + * Arrays with dimension: a(ANY).SWIGTYPE + * Member pointer: m(CLASS).SWIGTYPE + * Function pointer: f(ANY).SWIGTYPE + * Enums: enum SWIGTYPE + * Types: SWIGTYPE + * + * Examples (also see SwigType_default_reduce): + * + * int [2][4] + * a(2).a(4).int + * a(ANY).a(ANY).SWIGTYPE + * + * struct A {}; + * typedef A *Aptr; + * Aptr const & + * r.q(const).Aptr + * r.q(const).p.SWIGTYPE + * + * enum E {e1, e2}; + * enum E const & + * r.q(const).enum E + * r.q(const).enum SWIGTYPE + * ----------------------------------------------------------------------------- */ + +SwigType *SwigType_default_create(SwigType *ty) { + SwigType *r = 0; + List *l; + Iterator it; + int numitems; + + if (!SwigType_isvarargs(ty)) { + SwigType *t = SwigType_typedef_resolve_all(ty); + r = NewStringEmpty(); + l = SwigType_split(t); + numitems = Len(l); + + if (numitems >= 1) { + String *last_subtype = Getitem(l, numitems-1); + if (SwigType_isenum(last_subtype)) + Setitem(l, numitems-1, NewString("enum SWIGTYPE")); + else + Setitem(l, numitems-1, NewString("SWIGTYPE")); + } + + for (it = First(l); it.item; it = Next(it)) { + String *subtype = it.item; + if (SwigType_isarray(subtype)) { + if (Equal(subtype, "a().")) + Append(r, NewString("a().")); + else + Append(r, NewString("a(ANY).")); + } else if (SwigType_isfunction(subtype)) { + Append(r, NewString("f(ANY).SWIGTYPE")); + break; + } else if (SwigType_ismemberpointer(subtype)) { + Append(r, NewString("m(CLASS).SWIGTYPE")); + break; + } else { + Append(r, subtype); + } + } + + Delete(l); + Delete(t); + } + + return r; +} + +/* ----------------------------------------------------------------------------- + * SwigType_default_reduce() + * + * This function implements type reduction used in the typemap matching rules + * and is very close to the type reduction used in partial template specialization. + * SWIGTYPE is used as the generic type. The basic idea is to repeatedly call + * this function to reduce the type until it is reduced to nothing. + * + * The type t must have already been converted to the default type via a call to + * SwigType_default_create() before calling this function. + * + * Example reductions (matching the examples described in SwigType_default_create): + * + * a(ANY).a(ANY).SWIGTYPE + * a(ANY).a().SWIGTYPE + * a(ANY).p.SWIGTYPE + * a(ANY).SWIGTYPE + * a().SWIGTYPE + * p.SWIGTYPE + * SWIGTYPE + * + * r.q(const).p.SWIGTYPE + * r.q(const).SWIGTYPE + * r.SWIGTYPE + * SWIGTYPE + * + * r.q(const).enum SWIGTYPE + * r.enum SWIGTYPE + * r.SWIGTYPE + * SWIGTYPE + * ----------------------------------------------------------------------------- */ + +SwigType *SwigType_default_reduce(SwigType *t) { + SwigType *r = NewStringEmpty(); + List *l; + Iterator it; + int numitems; + + l = SwigType_split(t); + + numitems = Len(l); + if (numitems >= 1) { + String *last_subtype = Getitem(l, numitems-1); + int is_enum = SwigType_isenum(last_subtype); + + if (numitems >=2 ) { + String *subtype = Getitem(l, numitems-2); /* last but one */ + if (SwigType_isarray(subtype)) { + if (is_enum) { + /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + Setitem(l, numitems-1, NewString("SWIGTYPE")); + } else { + /* array reduction, a(ANY). => a(). => p. */ + String *reduced_subtype = 0; + if (Strcmp(subtype, "a().") == 0) { + reduced_subtype = NewString("p."); + } else if (Strcmp(subtype, "a(ANY).") == 0) { + reduced_subtype = NewString("a()."); + } else { + assert(0); + } + Setitem(l, numitems-2, reduced_subtype); + } + } else if (SwigType_ismemberpointer(subtype)) { + /* member pointer reduction, m(CLASS). => p. */ + Setitem(l, numitems-2, NewString("p.")); + } else if (is_enum && !SwigType_isqualifier(subtype)) { + /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + Setitem(l, numitems-1, NewString("SWIGTYPE")); + } else { + /* simple type reduction, eg, r.p.p. => r.p. */ + /* also function pointers eg, p.f(ANY). => p. */ + Delitem(l, numitems-2); + } + } else { + if (is_enum) { + /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + Setitem(l, numitems-1, NewString("SWIGTYPE")); + } else { + /* delete the only item, we are done with reduction */ + Delitem(l, 0); + } + } + } else { + assert(0); + } + + for (it = First(l); it.item; it = Next(it)) { + Append(r, it.item); + } + + if (Len(r) == 0) { + Delete(r); + r = 0; + } + + Delete(l); + return r; +} + + /* ----------------------------------------------------------------------------- * SwigType_namestr() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index b3cb0f158..6228b2f43 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -172,6 +172,8 @@ extern "C" { extern void SwigType_array_setdim(SwigType *t, int n, const_String_or_char_ptr rep); extern SwigType *SwigType_array_type(SwigType *t); extern String *SwigType_default(SwigType *t); + extern SwigType *SwigType_default_create(SwigType *ty); + extern SwigType *SwigType_default_reduce(SwigType *t); extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep); extern SwigType *SwigType_remove_global_scope_prefix(const SwigType *t); extern SwigType *SwigType_alttype(SwigType *t, int ltmap); diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index aaf156d8e..cc32780c5 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -674,7 +674,7 @@ static Hash *typemap_search_helper(int debug_display, Hash *tm, const String *tm if (debug_display) Printf(stdout, " Looking for: %s\n", SwigType_str(ctype, 0)); if (tm) { - result = Getattr(tm, tm_method); /* See if there is simply a type match */ + result = Getattr(tm, tm_method); /* See if there is simply a type without name match */ if (result && Getattr(result, "code")) goto ret_result; if (result) @@ -779,7 +779,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type /* Hmmm. Well, no match seems to be found at all. See if there is some kind of default (SWIGTYPE) mapping */ - primitive = SwigType_default(type); + primitive = SwigType_default_create(type); while (primitive) { tm = get_typemap(ts, primitive); result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup); @@ -787,7 +787,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type goto ret_result; { - SwigType *nprim = SwigType_default(primitive); + SwigType *nprim = SwigType_default_reduce(primitive); Delete(primitive); primitive = nprim; } diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 9ccdfbf7b..a2e23e52d 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -50,6 +50,9 @@ char cvsroot_typeobj_c[] = "$Id$"; * 'q(str).' = Qualifier (such as const or volatile) (const, volatile) * 'm(qual).' = Pointer to member (qual::*) * + * The complete type representation for varargs is: + * 'v(...)' + * * The encoding follows the order that you might describe a type in words. * For example "p.a(200).int" is "A pointer to array of int's" and * "p.q(const).char" is "a pointer to a const char". @@ -177,6 +180,9 @@ SwigType *SwigType_del_element(SwigType *t) { * SwigType_pop() * * Pop one type element off the type. + * Example: t in: q(const).p.Integer + * t out: p.Integer + * result: q(const). * ----------------------------------------------------------------------------- */ SwigType *SwigType_pop(SwigType *t) { From 2a1a4309677e4574810e158335fdc868f2bc2db6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 1 Apr 2010 18:29:36 +0000 Subject: [PATCH 043/203] Remove some R debugging output git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11959 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/r.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index ad83d608a..5ae2397b2 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -556,10 +556,10 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) { ParmList *parms = SwigType_function_parms(SwigType_del_pointer(Copy(t)), n); - // if (debugMode) { + if (debugMode) { Printf(stderr, "Type: %s\n", t); Printf(stderr, "Return type: %s\n", SwigType_base(t)); - //} + } bool isVoidType = Strcmp(rettype, "void") == 0; if (debugMode) From b6c4ea90b64c9968b53000a2276824b476872a23 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 1 Apr 2010 18:33:27 +0000 Subject: [PATCH 044/203] remove old default SWIGTYPE reduction code git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11960 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/stype.c | 218 -------------------------------------------- Source/Swig/swig.h | 2 +- 2 files changed, 1 insertion(+), 219 deletions(-) diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 079fa07fe..7594a6ad6 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -274,224 +274,6 @@ int SwigType_issimple(SwigType *t) { return 1; } -/* ----------------------------------------------------------------------------- - * SwigType_default() - * - * Create the default string for this datatype. This takes a type and strips it - * down to its most primitive form--resolving all typedefs and removing operators. - * - * Rules: - * Pointers: p.SWIGTYPE - * References: r.SWIGTYPE - * Arrays: a().SWIGTYPE - * Types: SWIGTYPE - * MemberPointer: m(CLASS).SWIGTYPE - * Enums: enum SWIGTYPE - * - * Note: if this function is applied to a primitive type, it returns NULL. This - * allows recursive application for special types like arrays. - * ----------------------------------------------------------------------------- */ - -#ifdef SWIG_DEFAULT_CACHE -static Hash *default_cache = 0; -#endif - -#define SWIG_NEW_TYPE_DEFAULT -/* The new default type resolution method: - -1.- It preserves the original mixed types, then it goes 'backward' - first deleting the qualifier, then the inner types - - typedef A *Aptr; - const Aptr&; - r.q(const).Aptr -> r.q(const).p.SWIGTYPE - r.q(const).p.SWIGTYPE -> r.p.SWIGTYPE - r.p.SWIGTYPE -> r.SWIGTYPE - r.SWIGTYPE -> SWIGTYPE - - - enum Hello {}; - const Hello& hi; - r.q(const).Hello -> r.q(const).enum SWIGTYPE - r.q(const).enum SWIGTYPE -> r.enum SWIGTYPE - r.enum SWIGTYPE -> r.SWIGTYPE - r.SWIGTYPE -> SWIGTYPE - - int a[2][4]; - a(2).a(4).int -> a(ANY).a(ANY).SWIGTYPE - a(ANY).a(ANY).SWIGTYPE -> a(ANY).a().SWIGTYPE - a(ANY).a().SWIGTYPE -> a(ANY).p.SWIGTYPE - a(ANY).p.SWIGTYPE -> a(ANY).SWIGTYPE - a(ANY).SWIGTYPE -> a().SWIGTYPE - a().SWIGTYPE -> p.SWIGTYPE - p.SWIGTYPE -> SWIGTYPE -*/ - -static -void SwigType_add_default(String *def, SwigType *nr) { - if (Strcmp(nr, "SWIGTYPE") == 0) { - Append(def, "SWIGTYPE"); - } else { - String *q = SwigType_isqualifier(nr) ? SwigType_pop(nr) : 0; - if (q && strstr(Char(nr), "SWIGTYPE")) { - Append(def, nr); - } else { - String *nd = SwigType_default(nr); - if (nd) { - String *bdef = nd; - if (q) { - bdef = NewStringf("%s%s", q, nd); - if ((Strcmp(nr, bdef) == 0)) { - Delete(bdef); - bdef = nd; - } else { - Delete(nd); - } - } - Append(def, bdef); - Delete(bdef); - } else { - Append(def, nr); - } - } - Delete(q); - } -} - - -SwigType *SwigType_default(SwigType *t) { - String *r1, *def; - String *r = 0; - char *cr; - -#ifdef SWIG_DEFAULT_CACHE - if (!default_cache) - default_cache = NewHash(); - - r = Getattr(default_cache, t); - if (r) { - return Copy(r); - } -#endif - - if (SwigType_isvarargs(t)) { - return 0; - } - - r = t; - while ((r1 = SwigType_typedef_resolve(r))) { - if (r != t) - Delete(r); - r = r1; - } - if (SwigType_isqualifier(r)) { - String *q; - if (r == t) - r = Copy(t); - q = SwigType_pop(r); - if (strstr(Char(r), "SWIGTYPE")) { - Delete(q); - def = r; - return def; - } - Delete(q); - } - cr = Char(r); - if (strcmp(cr, "p.SWIGTYPE") == 0) { - def = NewString("SWIGTYPE"); - } else if (SwigType_ispointer(r)) { -#ifdef SWIG_NEW_TYPE_DEFAULT - SwigType *nr = Copy(r); - SwigType_del_pointer(nr); - def = SwigType_isfunction(nr) ? NewStringEmpty() : NewString("p."); - SwigType_add_default(def, nr); - Delete(nr); -#else - def = NewString("p.SWIGTYPE"); -#endif - } else if (strcmp(cr, "r.SWIGTYPE") == 0) { - def = NewString("SWIGTYPE"); - } else if (SwigType_isreference(r)) { -#ifdef SWIG_NEW_TYPE_DEFAULT - SwigType *nr = Copy(r); - SwigType_del_reference(nr); - def = NewString("r."); - SwigType_add_default(def, nr); - Delete(nr); -#else - def = NewString("r.SWIGTYPE"); -#endif - } else if (SwigType_isarray(r)) { - if (strcmp(cr, "a().SWIGTYPE") == 0) { - def = NewString("p.SWIGTYPE"); - } else if (strcmp(cr, "a(ANY).SWIGTYPE") == 0) { - def = NewString("a().SWIGTYPE"); - } else { - int i, empty = 0; - int ndim = SwigType_array_ndim(r); - SwigType *nr = Copy(r); - for (i = 0; i < ndim; i++) { - String *dim = SwigType_array_getdim(r, i); - if (!Len(dim)) { - char *c = Char(nr); - empty = strstr(c, "a(ANY).") != c; - } - Delete(dim); - } - if (empty) { - def = NewString("a()."); - } else { - def = NewString("a(ANY)."); - } -#ifdef SWIG_NEW_TYPE_DEFAULT - SwigType_del_array(nr); - SwigType_add_default(def, nr); -#else - Append(def, "SWIGTYPE"); -#endif - Delete(nr); - } - } else if (SwigType_ismemberpointer(r)) { - if (strcmp(cr, "m(CLASS).SWIGTYPE") == 0) { - def = NewString("p.SWIGTYPE"); - } else { - def = NewString("m(CLASS).SWIGTYPE"); - } - } else if (SwigType_isenum(r)) { - if (strcmp(cr, "enum SWIGTYPE") == 0) { - def = NewString("SWIGTYPE"); - } else { - def = NewString("enum SWIGTYPE"); - } - } else if (SwigType_isfunction(r)) { - if (strcmp(cr, "f(ANY).SWIGTYPE") == 0) { - def = NewString("p.SWIGTYPE"); - } else { - def = NewString("p.f(ANY).SWIGTYPE"); - } - } else { - def = NewString("SWIGTYPE"); - } - if (r != t) - Delete(r); - if (Equal(def, t)) { - Delete(def); - def = 0; - } -#ifdef SWIG_DEFAULT_CACHE - /* The cache produces strange results, see enum_template.i case */ - if (def) { - String *cdef = Copy(def); - Setattr(default_cache, t, cdef); - Delete(cdef); - } -#endif - - /* Printf(stderr,"type : def %s : %s\n", t, def); */ - - return def; -} - /* ----------------------------------------------------------------------------- * SwigType_default_create() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 6228b2f43..cf94acfa8 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -37,7 +37,7 @@ extern "C" { /* Global macros */ #define NSPACE_SEPARATOR "." /* Namespace separator for the nspace feature - this should be changed to a target language configurable variable */ -#define NSPACE_TODO 0 /* temporary TODO hack */ +#define NSPACE_TODO 0 /* Languages that still need to implement and test the nspace feature use this */ /* Short names for common data types */ From 482c06c28c44ab0e234a78e9850fd3835e96e3ac Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 1 Apr 2010 23:30:26 +0000 Subject: [PATCH 045/203] Remove unnecessary vector of constant pointer specialization since the improved default typemap matching rules were introduced git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11961 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/li_std_vector.i | 8 ------ Lib/csharp/std_vector.i | 40 +++++++++++++---------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/Examples/test-suite/li_std_vector.i b/Examples/test-suite/li_std_vector.i index 74b3f6e6f..a58f97ff1 100644 --- a/Examples/test-suite/li_std_vector.i +++ b/Examples/test-suite/li_std_vector.i @@ -74,12 +74,6 @@ const std::vector & vecstructptr(const std::vector & vec) { const std::vector & vecstructconstptr(const std::vector & vec) { return vec; } %} -#if defined(SWIGCSHARP) -// Also test const and non-const pointers, but not strictly necessary since std::vector was enhanced in swig-1.3.40 -%template(StructurePtrVector) std::vector; -%template(StructureConstPtrVector) std::vector; -#endif - #if !defined(SWIGR) %template(IntPtrVector) std::vector; %template(IntConstPtrVector) std::vector; @@ -88,7 +82,6 @@ const std::vector & vecstructconstptr(const std::vector; %template(StructConstPtrVector) std::vector; -#if !defined(SWIGTCL) %inline { struct MyClass {}; typedef MyClass *MyClassPtr; @@ -106,7 +99,6 @@ const std::vector & vecstructconstptr(const std::vector; diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 57abe614d..7fca7d2fd 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -25,7 +25,7 @@ %include // MACRO for use within the std::vector class body -%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE_TYPE, CTYPE...) +%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...) %typemap(csinterfaces) std::vector "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n#endif\n"; %typemap(cscode) std::vector %{ public $csclassname(System.Collections.ICollection c) : this() { @@ -208,16 +208,16 @@ public: typedef size_t size_type; typedef CTYPE value_type; - typedef CONST_REFERENCE_TYPE const_reference; + typedef CONST_REFERENCE const_reference; %rename(Clear) clear; void clear(); %rename(Add) push_back; - void push_back(const value_type& x); + void push_back(CTYPE const& x); size_type size() const; size_type capacity() const; void reserve(size_type n); %newobject GetRange(int index, int count); - %newobject Repeat(const value_type& value, int count); + %newobject Repeat(CTYPE const& value, int count); vector(); vector(const vector &other); %extend { @@ -243,7 +243,7 @@ else throw std::out_of_range("index"); } - void setitem(int index, const value_type& val) throw (std::out_of_range) { + void setitem(int index, CTYPE const& val) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()) (*$self)[index] = val; else @@ -263,7 +263,7 @@ throw std::invalid_argument("invalid range"); return new std::vector($self->begin()+index, $self->begin()+index+count); } - void Insert(int index, const value_type& x) throw (std::out_of_range) { + void Insert(int index, CTYPE const& x) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()+1) $self->insert($self->begin()+index, x); else @@ -291,7 +291,7 @@ throw std::invalid_argument("invalid range"); $self->erase($self->begin()+index, $self->begin()+index+count); } - static std::vector *Repeat(const value_type& value, int count) throw (std::out_of_range) { + static std::vector *Repeat(CTYPE const& value, int count) throw (std::out_of_range) { if (count < 0) throw std::out_of_range("count"); return new std::vector(count, value); @@ -320,31 +320,31 @@ %enddef %define SWIG_STD_VECTOR_MINIMUM(CTYPE...) -SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, const value_type&, CTYPE) +SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, CTYPE const&, CTYPE) %enddef // Extra methods added to the collection class if operator== is defined for the class being wrapped // The class will then implement IList<>, which adds extra functionality %define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE...) %extend { - bool Contains(const value_type& value) { + bool Contains(CTYPE const& value) { return std::find($self->begin(), $self->end(), value) != $self->end(); } - int IndexOf(const value_type& value) { + int IndexOf(CTYPE const& value) { int index = -1; std::vector::iterator it = std::find($self->begin(), $self->end(), value); if (it != $self->end()) index = (int)(it - $self->begin()); return index; } - int LastIndexOf(const value_type& value) { + int LastIndexOf(CTYPE const& value) { int index = -1; std::vector::reverse_iterator rit = std::find($self->rbegin(), $self->rend(), value); if (rit != $self->rend()) index = (int)($self->rend() - 1 - rit); return index; } - bool Remove(const value_type& value) { + bool Remove(CTYPE const& value) { std::vector::iterator it = std::find($self->begin(), $self->end(), value); if (it != $self->end()) { $self->erase(it); @@ -359,7 +359,7 @@ SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, const value_type&, CTYPE) %define SWIG_STD_VECTOR_ENHANCED(CTYPE...) namespace std { template<> class vector { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, CTYPE) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, CTYPE const&, CTYPE) SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE) }; } @@ -394,16 +394,12 @@ namespace std { template class vector { SWIG_STD_VECTOR_MINIMUM(T) }; - // specializations for pointers - template class vector { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, T*) - SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T*) + // specialization for pointers + template class vector { + SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, T *const&, T *) + SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *) }; - template class vector { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, const T*) - SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(const T*) - }; - // bool is a bit different in the C++ standard + // bool is specialized in the C++ standard - const_reference in particular template<> class vector { SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, bool, bool) SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool) From 662084aa06d5b3818532b87709e0b5be383a3df1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 2 Apr 2010 19:48:20 +0000 Subject: [PATCH 046/203] Lua - Fix char pointers, wchar_t pointers and char arrays so that nil can be passed as a valid value git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11963 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ Examples/test-suite/char_strings.i | 6 +++++ .../test-suite/lua/char_strings_runme.lua | 12 +++++++++ Lib/lua/luatypemaps.swg | 25 +++++++++++++------ Lib/lua/wchar.i | 4 +-- 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 Examples/test-suite/lua/char_strings_runme.lua diff --git a/CHANGES.current b/CHANGES.current index 0be45290b..a58cd68d3 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 2.0.0 (in progress) ============================ +2010-04-02: wsfulton + [Lua] Fix char pointers, wchar_t pointers and char arrays so that nil can be passed as a + valid value. Bug reported by Gedalia Pasternak. + 2010-04-01: wsfulton Numerous subtle typemap matching rule fixes when using the default type. The typemap matching rules are to take a type and find the best default typemap (SWIGTYPE, SWIGTYPE* etc), diff --git a/Examples/test-suite/char_strings.i b/Examples/test-suite/char_strings.i index 2561108c6..26f3f22a5 100644 --- a/Examples/test-suite/char_strings.i +++ b/Examples/test-suite/char_strings.i @@ -109,6 +109,12 @@ bool SetConstCharArrayStaticString(const char str[], unsigned int number) { char *CharPingPong(char *str) { return str; } +char *CharArrayPingPong(char abcstr[]) { + return abcstr; +} +char *CharArrayDimsPingPong(char abcstr[16]) { + return abcstr; +} // variables char *global_char = NULL; diff --git a/Examples/test-suite/lua/char_strings_runme.lua b/Examples/test-suite/lua/char_strings_runme.lua new file mode 100644 index 000000000..64ae6ec1c --- /dev/null +++ b/Examples/test-suite/lua/char_strings_runme.lua @@ -0,0 +1,12 @@ +require("import") -- the import fn +import("char_strings") -- import code + +assert (char_strings.CharPingPong("hi there") == "hi there") +assert (char_strings.CharPingPong(nil) == nil) + +assert (char_strings.CharArrayPingPong("hi there") == "hi there") +assert (char_strings.CharArrayPingPong(nil) == nil) + +assert (char_strings.CharArrayDimsPingPong("hi there") == "hi there") +assert (char_strings.CharArrayDimsPingPong(nil) == nil) + diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 58f42eea1..ae65cbfea 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -90,10 +90,19 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} %{ lua_pushboolean(L,(int)((*$1)!=0)); SWIG_arg++;%} // strings (char* and char[]) -%typemap(in,checkfn="lua_isstring") const char*, char* +%fragment("SWIG_lua_isnilstring", "header") { + int SWIG_lua_isnilstring(lua_State *L, int idx) { + int ret = lua_isstring(L, idx); + if (!ret) + ret = lua_isnil(L, idx); + return ret; + } +} + +%typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char*, char* %{$1 = ($ltype)lua_tostring(L, $input);%} -%typemap(in,checkfn="lua_isstring") const char[ANY], char[ANY] +%typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char[ANY], char[ANY] %{$1 = ($ltype)lua_tostring(L, $input);%} %typemap(out) const char*, char* @@ -105,14 +114,14 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} // char's // currently treating chars as small strings, not as numbers // (however signed & unsigned char's are numbers...) -%typemap(in,checkfn="lua_isstring") char +%typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") char %{$1 = (lua_tostring(L, $input))[0];%} %typemap(out) char %{ lua_pushfstring(L,"%c",$1); SWIG_arg++;%} // by const ref -%typemap(in,checkfn="lua_isstring") const char& (char temp) +%typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char& (char temp) %{temp = (lua_tostring(L, $input))[0]; $1=&temp;%} %typemap(out) const char& @@ -288,12 +297,12 @@ parmeters match which function } // special check for a char (string of length 1) -%typecheck(SWIG_TYPECHECK_CHAR) char, const char& { - $1 = lua_isstring(L,$input) && (lua_strlen(L,$input)==1); +%typecheck(SWIG_TYPECHECK_CHAR,fragment="SWIG_lua_isnilstring") char, const char& { + $1 = SWIG_lua_isnilstring(L,$input) && (lua_strlen(L,$input)==1); } -%typecheck(SWIG_TYPECHECK_STRING) char *, char[] { - $1 = lua_isstring(L,$input); +%typecheck(SWIG_TYPECHECK_STRING,fragment="SWIG_lua_isnilstring") char *, char[] { + $1 = SWIG_lua_isnilstring(L,$input); } %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE [] { diff --git a/Lib/lua/wchar.i b/Lib/lua/wchar.i index 5021c1604..02b5428be 100644 --- a/Lib/lua/wchar.i +++ b/Lib/lua/wchar.i @@ -28,13 +28,13 @@ wchar_t* str2wstr(const char* str, int len) } %} -%typemap( in, checkfn="lua_isstring" ) wchar_t* +%typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t* %{ $1 = str2wstr(lua_tostring( L, $input ),lua_strlen( L, $input )); if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;} %} -%typemap( freearg ) wchar_t* +%typemap(freearg) wchar_t* %{ free($1); %} From fb99ef318c769fdc95ee67f7452d0e21c2d36649 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 00:20:42 +0000 Subject: [PATCH 047/203] fixes for make distclean git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11964 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/Makefile.in | 4 ++-- Examples/Makefile.in | 5 +++++ Makefile.in | 12 ++++++++++-- Source/Makefile.am | 3 +++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CCache/Makefile.in b/CCache/Makefile.in index ef20f48a0..543970f9e 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -63,10 +63,10 @@ test: test.sh check: test distclean: clean distclean-docs - /bin/rm -f Makefile config.h config.sub config.log build-stamp config.status config.h.in ccache_swig_config.h + /bin/rm -f Makefile config.h config.sub config.log build-stamp config.status ccache_swig_config.h maintainer-clean: distclean - /bin/rm -f configure + /bin/rm -f configure config.h.in # FIXME: To fix this, test.sh needs to be able to take ccache from the # installed prefix, not from the source dir. diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 3516d6f28..7f11884ee 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -84,6 +84,11 @@ CXXSHARED= @CXXSHARED@ OBJS = $(SRCS:.c=.@OBJEXT@) $(CXXSRCS:.cxx=.@OBJEXT@) +distclean: + rm -f Makefile + rm -f guile/Makefile + rm -f xml/Makefile + ################################################################## ##### Tcl/Tk ###### ################################################################## diff --git a/Makefile.in b/Makefile.in index 6effe59b9..1401ea9fc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -336,9 +336,9 @@ maintainer-clean: clean-libfiles # DISTCLEAN ##################################################################### -DISTCLEAN-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log libtool +DISTCLEAN-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log libtool preinst-swig Lib/ocaml/swigp4.ml -distclean: clean-docs distclean-objects clean-examples distclean-test-suite distclean-dead distclean-ccache +distclean: clean-docs distclean-objects distclean-test-suite distclean-examples distclean-dead distclean-ccache distclean-objects: distclean-source @@ -351,6 +351,11 @@ distclean-test-suite: @echo distcleaning Examples/test-suite @$(MAKE) -k -s check-test-suite ACTION=distclean NOSKIP=1 +distclean-examples: + @echo distcleaning Examples + @$(MAKE) -k -s clean-examples + @cd Examples && $(MAKE) -k -s distclean + distclean-ccache: test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s distclean) @@ -360,6 +365,9 @@ distclean-docs-ccache: distclean-dead: rm -f $(DISTCLEAN-DEAD) +distclean-: + rm -f Lib/ocaml/swigp4.ml + ##################################################################### # Update the Lib/swigwarn.swg file # Note: Generated into the source tree rather than build tree diff --git a/Source/Makefile.am b/Source/Makefile.am index bc3222b25..3f710302a 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -104,6 +104,9 @@ clean-local: rm -f $(top_builddir)/swig@EXEEXT@ rm -f core @EXTRA_CLEAN@ +distclean: + rm -f $(top_builddir)/Source/Include/swigconfig.h + rm -f $(top_builddir)/Source/Include/stamp-h1 # Beautify the code. # Note that this works well on C code, but does some odd joining of lines for C++ code. From 96fbbc50ccd8fc9f62de335f843cda85eec2aec6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 00:30:16 +0000 Subject: [PATCH 048/203] make maintainer-clean fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11965 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/Makefile.in | 4 ++-- Doc/Manual/Makefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CCache/Makefile.in b/CCache/Makefile.in index 543970f9e..fdb316f1f 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -52,7 +52,7 @@ uninstall: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1 clean: /bin/rm -f $(OBJS) *~ $(PACKAGE_NAME)$(EXEEXT) -distclean-docs: +maintainer-clean: rm -f $(PACKAGE_NAME).1 web/ccache-man.html check : test @@ -62,7 +62,7 @@ test: test.sh check: test -distclean: clean distclean-docs +distclean: clean /bin/rm -f Makefile config.h config.sub config.log build-stamp config.status ccache_swig_config.h maintainer-clean: distclean diff --git a/Doc/Manual/Makefile b/Doc/Manual/Makefile index 7db42322c..69d361f07 100644 --- a/Doc/Manual/Makefile +++ b/Doc/Manual/Makefile @@ -50,7 +50,7 @@ swightml.book: echo "Sections.html" >> swightml.book cat chapters >> swightml.book -clean: clean-baks +maintainer-clean: clean-baks rm -f swightml.book rm -f swigpdf.book rm -f CCache.html From b53e52602aeaf3aedd94d79f16a69ec58c72c66e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 01:14:52 +0000 Subject: [PATCH 049/203] make maintainer-clean and make distclean fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11966 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/Makefile.in | 5 ++--- Makefile.in | 38 ++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/CCache/Makefile.in b/CCache/Makefile.in index fdb316f1f..b96d42a60 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -52,9 +52,6 @@ uninstall: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1 clean: /bin/rm -f $(OBJS) *~ $(PACKAGE_NAME)$(EXEEXT) -maintainer-clean: - rm -f $(PACKAGE_NAME).1 web/ccache-man.html - check : test test: test.sh @@ -67,6 +64,8 @@ distclean: clean maintainer-clean: distclean /bin/rm -f configure config.h.in + /bin/rm -f $(PACKAGE_NAME).1 web/ccache-man.html + # FIXME: To fix this, test.sh needs to be able to take ccache from the # installed prefix, not from the source dir. diff --git a/Makefile.in b/Makefile.in index 1401ea9fc..7b74870b6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -302,9 +302,6 @@ clean-source: @cd $(SOURCE) && $(MAKE) -s clean @rm -f $(TARGET) -clean-libfiles: - @rm -f $(srcdir)/Lib/swigwarn.swg - clean-examples: @$(MAKE) -k -s check-examples ACTION=clean @@ -320,27 +317,15 @@ clean-%-test-suite: clean-ccache: test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s clean) -clean-docs: clean-docs-main clean-docs-ccache - -clean-docs-main: - @echo cleaning Docs - @test -d $(DOCS) || exit 0; cd $(DOCS) && $(MAKE) clean - -clean-docs-ccache: - @# Use distclean-docs-ccache, else a user requires the yodl tools to generate the docs after a clean - -maintainer-clean: clean-libfiles - @cd $(SOURCE) && $(MAKE) maintainer-clean - ##################################################################### -# DISTCLEAN +# DISTCLEAN - clean what configure built ##################################################################### DISTCLEAN-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log libtool preinst-swig Lib/ocaml/swigp4.ml -distclean: clean-docs distclean-objects distclean-test-suite distclean-examples distclean-dead distclean-ccache +distclean-helper: distclean-test-suite distclean-examples distclean-dead distclean-ccache -distclean-objects: distclean-source +distclean: distclean-source distclean-helper distclean-source: @echo distcleaning Source @@ -365,8 +350,21 @@ distclean-docs-ccache: distclean-dead: rm -f $(DISTCLEAN-DEAD) -distclean-: - rm -f Lib/ocaml/swigp4.ml +##################################################################### +# MAINTAINER CLEAN - clean what the maintainer builds and ships in +# the distributed tarball - should not delete anything needed to run +# ./configure && make +##################################################################### + +maintainer-clean: + @echo maintainer-cleaning source + @cd $(SOURCE) && $(MAKE) -k -s maintainer-clean + @echo maintainer-cleaning docs + @cd $(DOCS) && $(MAKE) -k -s maintainer-clean + @echo maintainer-cleaning Lib files + @rm -f $(srcdir)/Lib/swigwarn.swg + @echo distcleaning + @$(MAKE) -k -s distclean-helper ##################################################################### # Update the Lib/swigwarn.swg file From d090cadb4c86da2af96cfb7bc3c96c7ee037258f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 10:11:01 +0000 Subject: [PATCH 050/203] more distclean fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11967 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/Makefile.in | 1 + Makefile.in | 1 + Source/Makefile.am | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CCache/Makefile.in b/CCache/Makefile.in index b96d42a60..fd7ee7eb0 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -61,6 +61,7 @@ check: test distclean: clean /bin/rm -f Makefile config.h config.sub config.log build-stamp config.status ccache_swig_config.h + /bin/rm -rf autom4te.cache maintainer-clean: distclean /bin/rm -f configure config.h.in diff --git a/Makefile.in b/Makefile.in index 7b74870b6..228b9201d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -349,6 +349,7 @@ distclean-docs-ccache: distclean-dead: rm -f $(DISTCLEAN-DEAD) + rm -rf autom4te.cache ##################################################################### # MAINTAINER CLEAN - clean what the maintainer builds and ships in diff --git a/Source/Makefile.am b/Source/Makefile.am index 3f710302a..26f37b2fe 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -104,7 +104,7 @@ clean-local: rm -f $(top_builddir)/swig@EXEEXT@ rm -f core @EXTRA_CLEAN@ -distclean: +distclean-local: rm -f $(top_builddir)/Source/Include/swigconfig.h rm -f $(top_builddir)/Source/Include/stamp-h1 From 3289c7d897144ad99f05ef8d196212adbc0919c2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 10:34:34 +0000 Subject: [PATCH 051/203] more distclean and maintainer-clean fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11968 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/Makefile.in | 1 - Makefile.in | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CCache/Makefile.in b/CCache/Makefile.in index fd7ee7eb0..e1014d230 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -64,7 +64,6 @@ distclean: clean /bin/rm -rf autom4te.cache maintainer-clean: distclean - /bin/rm -f configure config.h.in /bin/rm -f $(PACKAGE_NAME).1 web/ccache-man.html diff --git a/Makefile.in b/Makefile.in index 228b9201d..48ebafc65 100644 --- a/Makefile.in +++ b/Makefile.in @@ -342,10 +342,7 @@ distclean-examples: @cd Examples && $(MAKE) -k -s distclean distclean-ccache: - test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s distclean) - -distclean-docs-ccache: - @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) distclean-docs) + @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s distclean) distclean-dead: rm -f $(DISTCLEAN-DEAD) @@ -360,6 +357,8 @@ distclean-dead: maintainer-clean: @echo maintainer-cleaning source @cd $(SOURCE) && $(MAKE) -k -s maintainer-clean + @echo maintainer-cleaning CCache + @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s maintainer-clean) @echo maintainer-cleaning docs @cd $(DOCS) && $(MAKE) -k -s maintainer-clean @echo maintainer-cleaning Lib files From 07621c122a1d176ee9178b9adc9c977eadb8ef41 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 11:36:54 +0000 Subject: [PATCH 052/203] more maintainer-clean fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11969 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index 48ebafc65..923c34321 100644 --- a/Makefile.in +++ b/Makefile.in @@ -323,9 +323,9 @@ clean-ccache: DISTCLEAN-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log libtool preinst-swig Lib/ocaml/swigp4.ml -distclean-helper: distclean-test-suite distclean-examples distclean-dead distclean-ccache +distclean-helper: distclean-test-suite distclean-examples distclean-dead -distclean: distclean-source distclean-helper +distclean: distclean-source distclean-ccache distclean-helper distclean-source: @echo distcleaning Source From 0080d1e031e7dc9e41b6e187aa35b80fa7ec8d4e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 12:04:28 +0000 Subject: [PATCH 053/203] display to user ccache-swig install files git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11970 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/Makefile.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CCache/Makefile.in b/CCache/Makefile.in index e1014d230..d8f9042fe 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -40,8 +40,11 @@ web/ccache-man.html: ccache.yo yodl2html -o web/ccache-man.html ccache.yo install: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1 + @echo "Installing $(PACKAGE_NAME)" + @echo "Installing $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT)" ${INSTALLCMD} -d $(DESTDIR)${bindir} ${INSTALLCMD} -m 755 $(PACKAGE_NAME)$(EXEEXT) $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT) + @echo "Installing $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1" ${INSTALLCMD} -d $(DESTDIR)${mandir}/man1 ${INSTALLCMD} -m 644 ${srcdir}/$(PACKAGE_NAME).1 $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1 From 5b3b15ae15e6d404341ebc51606f1404fbbff81b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 12:05:16 +0000 Subject: [PATCH 054/203] Minor robustness tweaks to building distribution git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11971 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/mkdist.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 9e25d3827..bd7872fb0 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -46,17 +46,18 @@ os.system("rm -Rf "+dirname+"/debian") == 0 or failed() # Go build the system print "Building system" -os.system("cd "+dirname+"; ./autogen.sh") == 0 or failed() -os.system("cd "+dirname+"/Tools/WAD; autoconf") == 0 or failed() -os.system("cd "+dirname+"/Source/CParse; bison -y -d parser.y; mv y.tab.c parser.c; mv y.tab.h parser.h") == 0 or failed() -os.system("cd "+dirname+"; make -f Makefile.in libfiles srcdir=./") == 0 or failed() +os.system("cd "+dirname+" && ./autogen.sh") == 0 or failed() +os.system("cd "+dirname+"/Tools/WAD && autoconf") == 0 or failed() +os.system("cd "+dirname+"/Source/CParse && bison -y -d parser.y && mv y.tab.c parser.c && mv y.tab.h parser.h") == 0 or failed() +os.system("cd "+dirname+" && make -f Makefile.in libfiles srcdir=./") == 0 or failed() # Remove autoconf files os.system("find "+dirname+" -name autom4te.cache -exec rm -rf {} \\;") # Build documentation -print "Building documentation" +print "Building html documentation" os.system("cd "+dirname+"/Doc/Manual && make all clean-baks") == 0 or failed() +print "Building man pages" os.system("cd "+dirname+"/CCache && yodl2man -o ccache-swig.1 ccache.yo") == 0 or failed() # Build the tar-ball From e75d8d44639e442f75cda8e1bbc0ed3ba0cfbe55 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 12:15:10 +0000 Subject: [PATCH 055/203] quieter ccache-swig install git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11972 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 923c34321..9f6c23499 100644 --- a/Makefile.in +++ b/Makefile.in @@ -436,7 +436,7 @@ install-lib: done install-ccache: - test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) install) + @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s install) ##################################################################### From 5494c4295bbd3782d64abd6f838ae7efdc05bb79 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 12:22:23 +0000 Subject: [PATCH 056/203] Show success at end of distribution build git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11973 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/mkdist.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index bd7872fb0..6972eb829 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -64,3 +64,5 @@ os.system("cd "+dirname+"/CCache && yodl2man -o ccache-swig.1 ccache.yo") == 0 o os.system("tar -cf "+dirname+".tar "+dirname) == 0 or failed() os.system("gzip "+dirname+".tar") == 0 or failed() +print "Finished building "+dirname+".tar.gz" + From 7a1551e0c45843a2c02961932fde7cd04deed48c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 12:44:17 +0000 Subject: [PATCH 057/203] fix make clean git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11974 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 9f6c23499..0beb7cbdd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -293,7 +293,7 @@ broken-%-test-suite: # CLEAN ##################################################################### -clean: clean-objects clean-libfiles clean-examples clean-test-suite clean-docs +clean: clean-objects clean-examples clean-test-suite clean-objects: clean-source clean-ccache From ab62df21e800c183df96d706524ecbe94c323ed4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 3 Apr 2010 12:47:50 +0000 Subject: [PATCH 058/203] add fix distclean and maintainer-clean targets to CHANGES file git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11975 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index a58cd68d3..f85338ed1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-04-03: wsfulton + Fix Makefile targets: distclean and maintainer-clean + 2010-04-02: wsfulton [Lua] Fix char pointers, wchar_t pointers and char arrays so that nil can be passed as a valid value. Bug reported by Gedalia Pasternak. From 964382336ee3058ab1544709367f22ae2483899c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 4 Apr 2010 20:37:20 +0000 Subject: [PATCH 059/203] remove std::map specializations - not needed since the typemap matching rules were changed to follow type deducation used in template specialization git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11978 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/csharp/std_map.i | 6 +- Lib/java/std_map.i | 122 ++++------------------------------------- Lib/ocaml/std_map.i | 121 ++++------------------------------------ Lib/perl5/std_map.i | 122 ++++------------------------------------- Lib/php/std_map.i | 128 ++++--------------------------------------- Lib/tcl/std_map.i | 122 ++++------------------------------------- 6 files changed, 53 insertions(+), 568 deletions(-) diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 24efbe26f..2db6ddf5b 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -296,14 +296,14 @@ namespace std { // Legacy macros (deprecated) %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) -#warning specialize_std_map_on_key ignored - macro is deprecated and no longer necessary +#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" %enddef %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) -#warning specialize_std_map_on_value ignored - macro is deprecated and no longer necessary +#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" %enddef %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) -#warning specialize_std_map_on_both ignored - macro is deprecated and no longer necessary +#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" %enddef diff --git a/Lib/java/std_map.i b/Lib/java/std_map.i index a7020532c..e7812f38a 100644 --- a/Lib/java/std_map.i +++ b/Lib/java/std_map.i @@ -58,119 +58,17 @@ namespace std { } }; +// Legacy macros (deprecated) +%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" +%enddef - // specializations for built-ins +%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" +%enddef - %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) - - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T& get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, const T& x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T get(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(const K& key, T x) { - (*self)[key] = x; - } - void del(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, - T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) - template<> class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, T x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - // add specializations here +%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) +#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" +%enddef } diff --git a/Lib/ocaml/std_map.i b/Lib/ocaml/std_map.i index d7bf1e0f7..924120f24 100644 --- a/Lib/ocaml/std_map.i +++ b/Lib/ocaml/std_map.i @@ -53,118 +53,17 @@ namespace std { } }; +// Legacy macros (deprecated) +%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" +%enddef - // specializations for built-ins +%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" +%enddef - %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) +%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) +#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" +%enddef - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T& get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, const T& x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T get(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(const K& key, T x) { - (*self)[key] = x; - } - void del(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, - T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) - template<> class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, T x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - // add specializations here } diff --git a/Lib/perl5/std_map.i b/Lib/perl5/std_map.i index ab0d3816d..898c84484 100644 --- a/Lib/perl5/std_map.i +++ b/Lib/perl5/std_map.i @@ -54,119 +54,17 @@ namespace std { } }; +// Legacy macros (deprecated) +%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" +%enddef - // specializations for built-ins +%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" +%enddef - %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) - - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T& get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, const T& x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T get(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(const K& key, T x) { - (*self)[key] = x; - } - void del(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, - T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) - template<> class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, T x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - // add specializations here +%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) +#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" +%enddef } diff --git a/Lib/php/std_map.i b/Lib/php/std_map.i index b6b417da7..ff74b7b0b 100644 --- a/Lib/php/std_map.i +++ b/Lib/php/std_map.i @@ -56,125 +56,17 @@ namespace std { } }; +// Legacy macros (deprecated) +%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" +%enddef - // specializations for built-ins +%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" +%enddef - %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) - - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - void clear(); - %extend { - T& get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, const T& x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - bool is_empty() const { - return self->empty(); - } - } - }; - %enddef - - %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - void clear(); - %extend { - T get(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(const K& key, T x) { - (*self)[key] = x; - } - void del(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - bool is_empty() const { - return self->empty(); - } - } - }; - %enddef - - %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, - T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) - template<> class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - void clear(); - %extend { - T get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, T x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - bool is_empty() const { - return self->empty(); - } - } - }; - %enddef - - // add specializations here +%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) +#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" +%enddef } diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i index 9d27e0f39..e36cc96f2 100644 --- a/Lib/tcl/std_map.i +++ b/Lib/tcl/std_map.i @@ -55,119 +55,17 @@ namespace std { } }; +// Legacy macros (deprecated) +%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" +%enddef - // specializations for built-ins +%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) +#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" +%enddef - %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) - - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T& get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, const T& x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) - template class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T get(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(const K& key, T x) { - (*self)[key] = x; - } - void del(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, - T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) - template<> class map { - // add typemaps here - public: - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T get(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(K key, T x) { - (*self)[key] = x; - } - void del(K key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } - } - }; - %enddef - - // add specializations here +%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) +#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" +%enddef } From 85ac524d37c88493dda55df827ad4d50791c0e3a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 4 Apr 2010 22:27:10 +0000 Subject: [PATCH 060/203] formatting change of const _TP * -> _TP const* merely to aid difference debugging with vector of non-const pointers std::vector specialization git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11979 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/std/std_vector.i | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/std/std_vector.i b/Lib/std/std_vector.i index b0bb714d4..147f7449d 100644 --- a/Lib/std/std_vector.i +++ b/Lib/std/std_vector.i @@ -138,11 +138,11 @@ namespace std { // const pointer specialization // *** template - class vector { + class vector<_Tp const *, _Alloc > { public: typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef const _Tp * value_type; + typedef _Tp const * value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type reference; @@ -151,32 +151,32 @@ namespace std { %traits_swigtype(_Tp); - %fragment(SWIG_Traits_frag(std::vector), "header", + %fragment(SWIG_Traits_frag(std::vector<_Tp const*, _Alloc >), "header", fragment=SWIG_Traits_frag(_Tp), fragment="StdVectorTraits") { namespace swig { - template <> struct traits > { + template <> struct traits > { typedef value_category category; static const char* type_name() { - return "std::vector"; + return "std::vector<" #_Tp " const*," #_Alloc " >"; } }; } } - %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp const*, _Alloc >); #ifdef %swig_vector_methods_val // Add swig/language extra methods - %swig_vector_methods_val(std::vector); + %swig_vector_methods_val(std::vector<_Tp const*, _Alloc >); #endif %std_vector_methods_val(vector); }; - // *** // *** // bool specialization + // *** template class vector { From a743d54665ccb154be5c999c38474393d724e046 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 8 Apr 2010 06:46:18 +0000 Subject: [PATCH 061/203] Fix segfault when using Python's -threads options and exceptions are thrown git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11980 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++ Examples/test-suite/common.mk | 1 + .../python/threads_exception_runme.py | 36 +++++++++++++ Examples/test-suite/threads_exception.i | 54 +++++++++++++++++++ Source/Modules/emit.cxx | 34 +++++++----- Source/Modules/python.cxx | 19 ++++--- 6 files changed, 127 insertions(+), 21 deletions(-) create mode 100755 Examples/test-suite/python/threads_exception_runme.py create mode 100755 Examples/test-suite/threads_exception.i diff --git a/CHANGES.current b/CHANGES.current index f85338ed1..ab92524ca 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 2.0.0 (in progress) ============================ +2010-04-03: wsfulton + [Python] Fix exceptions being thrown with the -threads option based on patch from Arto Vuori. + Fixes bug #2818499. + 2010-04-03: wsfulton Fix Makefile targets: distclean and maintainer-clean diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index db162487f..a902166b5 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -375,6 +375,7 @@ CPP_TEST_CASES += \ template_virtual \ template_whitespace \ threads \ + threads_exception \ throw_exception \ typedef_array_member \ typedef_class \ diff --git a/Examples/test-suite/python/threads_exception_runme.py b/Examples/test-suite/python/threads_exception_runme.py new file mode 100755 index 000000000..9fbc6a9b2 --- /dev/null +++ b/Examples/test-suite/python/threads_exception_runme.py @@ -0,0 +1,36 @@ +import threads_exception + +t = threads_exception.Test() +try: + t.unknown() +except RuntimeError,e: + pass + +try: + t.simple() +except RuntimeError,e: + if e.args[0] != 37: + raise RuntimeError + +try: + t.message() +except RuntimeError,e: + if e.args[0] != "I died.": + raise RuntimeError + +try: + t.hosed() +except threads_exception.Exc,e: + if e.code != 42: + raise RuntimeError + if e.msg != "Hosed": + raise RuntimeError + +for i in range(1,4): + try: + t.multi(i) + except RuntimeError,e: + pass + except threads_exception.Exc,e: + pass + diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i new file mode 100755 index 000000000..9f275bd6a --- /dev/null +++ b/Examples/test-suite/threads_exception.i @@ -0,0 +1,54 @@ +// Throw a lot of exceptions + +// The Python runtime tests were previously failing with the -threads option on Windows due to SWIG_PYTHON_THREAD_BEGIN_ALLOW not being within the try block. + +%module(threads="1") threads_exception + +%{ +struct A {}; +%} + +%inline %{ +#include + +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + +class Exc { +public: + Exc(int c, const char *m) { + code = c; + strncpy(msg,m,255); + } + int code; + char msg[256]; +}; + +class Test { +public: + int simple() throw(int) { + throw(37); + return 1; + } + int message() throw(const char *) { + throw("I died."); + return 1; + } + int hosed() throw(Exc) { + throw(Exc(42,"Hosed")); + return 1; + } + int unknown() throw(A*) { + static A a; + throw &a; + return 1; + } + int multi(int x) throw(int, const char *, Exc) { + if (x == 1) throw(37); + if (x == 2) throw("Bleah!"); + if (x == 3) throw(Exc(42,"No-go-diggy-die")); + return 1; + } +}; +%} diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index ed75e4d74..0c6c6515f 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -462,32 +462,40 @@ String *emit_action(Node *n) { Printf(eaction, "try {\n"); } + String *preaction = Getattr(n, "wrap:preaction"); + if (preaction) + Printv(eaction, preaction, NIL); + Printv(eaction, action, NIL); + String *postaction = Getattr(n, "wrap:postaction"); + if (postaction) + Printv(eaction, postaction, NIL); + if (catchlist) { int unknown_catch = 0; Printf(eaction, "}\n"); for (Parm *ep = catchlist; ep; ep = nextSibling(ep)) { String *em = Swig_typemap_lookup("throws", ep, "_e", 0); if (em) { - SwigType *et = Getattr(ep, "type"); - SwigType *etr = SwigType_typedef_resolve_all(et); - if (SwigType_isreference(etr) || SwigType_ispointer(etr) || SwigType_isarray(etr)) { - Printf(eaction, "catch(%s) {", SwigType_str(et, "_e")); - } else if (SwigType_isvarargs(etr)) { - Printf(eaction, "catch(...) {"); - } else { - Printf(eaction, "catch(%s) {", SwigType_str(et, "&_e")); - } - Printv(eaction, em, "\n", NIL); - Printf(eaction, "}\n"); + SwigType *et = Getattr(ep, "type"); + SwigType *etr = SwigType_typedef_resolve_all(et); + if (SwigType_isreference(etr) || SwigType_ispointer(etr) || SwigType_isarray(etr)) { + Printf(eaction, "catch(%s) {", SwigType_str(et, "_e")); + } else if (SwigType_isvarargs(etr)) { + Printf(eaction, "catch(...) {"); + } else { + Printf(eaction, "catch(%s) {", SwigType_str(et, "&_e")); + } + Printv(eaction, em, "\n", NIL); + Printf(eaction, "}\n"); } else { Swig_warning(WARN_TYPEMAP_THROW, Getfile(n), Getline(n), "No 'throws' typemap defined for exception type '%s'\n", SwigType_str(Getattr(ep, "type"), 0)); - unknown_catch = 1; + unknown_catch = 1; } } if (unknown_catch) { - Printf(eaction, "catch(...) { throw; }\n"); + Printf(eaction, "catch(...) { throw; }\n"); } } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 3215d29aa..3639efe86 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -211,6 +211,7 @@ public: virtual void thread_begin_allow(Node *n, String *f) { if (!GetFlag(n, "feature:nothreadallow")) { String *bb = Getattr(n, "feature:threadbeginallow"); + Append(f, "{\n"); if (bb) { Append(f, bb); } else { @@ -222,11 +223,13 @@ public: virtual void thread_end_allow(Node *n, String *f) { if (!GetFlag(n, "feature:nothreadallow")) { String *eb = Getattr(n, "feature:threadendallow"); + Append(f, "\n"); if (eb) { Append(f, eb); } else { - Append(f, "SWIG_PYTHON_THREAD_END_ALLOW;\n"); + Append(f, "SWIG_PYTHON_THREAD_END_ALLOW;"); } + Append(f, "\n}"); } } @@ -2200,8 +2203,13 @@ public: Append(f->code, "try {\n"); } else { if (allow_thread) { - Append(f->code, "{\n"); - thread_begin_allow(n, f->code); + String *preaction = NewString(""); + thread_begin_allow(n, preaction); + Setattr(n,"wrap:preaction", preaction); + + String *postaction = NewString(""); + thread_end_allow(n, postaction); + Setattr(n,"wrap:postaction", postaction); } } @@ -2214,11 +2222,6 @@ public: Append(actioncode, "} catch (Swig::DirectorException&) {\n"); Append(actioncode, " SWIG_fail;\n"); Append(actioncode, "}\n"); - } else { - if (allow_thread) { - thread_end_allow(n, actioncode); - Append(actioncode, "}\n"); - } } /* This part below still needs cleanup */ From edd0a06409f019d6528a346b947ae3b21748e37b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 8 Apr 2010 20:22:03 +0000 Subject: [PATCH 062/203] fix 0 sized array compile error in test git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11981 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/constant_expr.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/constant_expr.i b/Examples/test-suite/constant_expr.i index 47db2d026..8e5c8aee6 100644 --- a/Examples/test-suite/constant_expr.i +++ b/Examples/test-suite/constant_expr.i @@ -5,7 +5,7 @@ /* % didn't work in SWIG 1.3.40 and earlier. */ const int X = 123%7; -#define FOO 12 % 6 -double d_array[12 % 6]; +#define FOO 12 % 9 +double d_array[12 % 9]; %} From 01c4ab6baf71cf7a7c73bec1497136fe5d55315d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 9 Apr 2010 21:40:23 +0000 Subject: [PATCH 063/203] Fix some terminology used in C++ template partial specialization and new typemap matching rules git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11982 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++-- Source/CParse/templ.c | 4 ++-- Source/Swig/stype.c | 38 ++++++++++++++++++++------------------ Source/Swig/swig.h | 2 +- Source/Swig/typemap.c | 2 +- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index ab92524ca..ca74f192f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -15,10 +15,10 @@ Version 2.0.0 (in progress) 2010-04-01: wsfulton Numerous subtle typemap matching rule fixes when using the default type. The typemap matching rules are to take a type and find the best default typemap (SWIGTYPE, SWIGTYPE* etc), - then look for the next best match by reducing the chosen default type. The type reduction + then look for the next best match by reducing the chosen default type. The type deduction now follows C++ template partial specialization matching rules. - Below are the set of changes made showing the default type reduction + Below are the set of changes made showing the default type deduction along with the old reduced type and the new version of the reduced type: SWIGTYPE const &[ANY] diff --git a/Source/CParse/templ.c b/Source/CParse/templ.c index 8d77cb0ee..503f725cb 100644 --- a/Source/CParse/templ.c +++ b/Source/CParse/templ.c @@ -432,7 +432,7 @@ typedef enum { ExactNoMatch = -2, PartiallySpecializedNoMatch = -1, PartiallySpe * does_parm_match() * * Template argument deduction - check if a template type matches a partially specialized - * template parameter type. Reduce 'partial_parm_type' to see if it matches 'type'. + * template parameter type. Typedef reduce 'partial_parm_type' to see if it matches 'type'. * * type - template parameter type to match against * partial_parm_type - partially specialized template type - a possible match @@ -664,7 +664,7 @@ static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) { if (posslen > 1) { /* Now go through all the possibly matched partial specialization templates and look for a non-ambiguous match. - * Exact matches rank the highest and deduced parameters are ranked by how much they are reduced, eg looking for + * Exact matches rank the highest and deduced parameters are ranked by how specialized they are, eg looking for * a match to const int *, the following rank (highest to lowest): * const int * (exact match) * const T * diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 7594a6ad6..533b8195f 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -290,7 +290,7 @@ int SwigType_issimple(SwigType *t) { * Enums: enum SWIGTYPE * Types: SWIGTYPE * - * Examples (also see SwigType_default_reduce): + * Examples (also see SwigType_default_deduce): * * int [2][4] * a(2).a(4).int @@ -354,17 +354,19 @@ SwigType *SwigType_default_create(SwigType *ty) { } /* ----------------------------------------------------------------------------- - * SwigType_default_reduce() + * SwigType_default_deduce() * - * This function implements type reduction used in the typemap matching rules - * and is very close to the type reduction used in partial template specialization. + * This function implements type deduction used in the typemap matching rules + * and is very close to the type deduction used in partial template specialization + * matching in that the most specialized type is always chosen. * SWIGTYPE is used as the generic type. The basic idea is to repeatedly call - * this function to reduce the type until it is reduced to nothing. + * this function to find a deduced type unless until nothing matches. * * The type t must have already been converted to the default type via a call to * SwigType_default_create() before calling this function. * - * Example reductions (matching the examples described in SwigType_default_create): + * Example deductions (matching the examples described in SwigType_default_create), + * where the the most specialized matches are highest in the list: * * a(ANY).a(ANY).SWIGTYPE * a(ANY).a().SWIGTYPE @@ -385,7 +387,7 @@ SwigType *SwigType_default_create(SwigType *ty) { * SWIGTYPE * ----------------------------------------------------------------------------- */ -SwigType *SwigType_default_reduce(SwigType *t) { +SwigType *SwigType_default_deduce(SwigType *t) { SwigType *r = NewStringEmpty(); List *l; Iterator it; @@ -402,37 +404,37 @@ SwigType *SwigType_default_reduce(SwigType *t) { String *subtype = Getitem(l, numitems-2); /* last but one */ if (SwigType_isarray(subtype)) { if (is_enum) { - /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + /* enum deduction, enum SWIGTYPE => SWIGTYPE */ Setitem(l, numitems-1, NewString("SWIGTYPE")); } else { - /* array reduction, a(ANY). => a(). => p. */ - String *reduced_subtype = 0; + /* array deduction, a(ANY). => a(). => p. */ + String *deduced_subtype = 0; if (Strcmp(subtype, "a().") == 0) { - reduced_subtype = NewString("p."); + deduced_subtype = NewString("p."); } else if (Strcmp(subtype, "a(ANY).") == 0) { - reduced_subtype = NewString("a()."); + deduced_subtype = NewString("a()."); } else { assert(0); } - Setitem(l, numitems-2, reduced_subtype); + Setitem(l, numitems-2, deduced_subtype); } } else if (SwigType_ismemberpointer(subtype)) { - /* member pointer reduction, m(CLASS). => p. */ + /* member pointer deduction, m(CLASS). => p. */ Setitem(l, numitems-2, NewString("p.")); } else if (is_enum && !SwigType_isqualifier(subtype)) { - /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + /* enum deduction, enum SWIGTYPE => SWIGTYPE */ Setitem(l, numitems-1, NewString("SWIGTYPE")); } else { - /* simple type reduction, eg, r.p.p. => r.p. */ + /* simple type deduction, eg, r.p.p. => r.p. */ /* also function pointers eg, p.f(ANY). => p. */ Delitem(l, numitems-2); } } else { if (is_enum) { - /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + /* enum deduction, enum SWIGTYPE => SWIGTYPE */ Setitem(l, numitems-1, NewString("SWIGTYPE")); } else { - /* delete the only item, we are done with reduction */ + /* delete the only item, we are done with deduction */ Delitem(l, 0); } } diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index cf94acfa8..2b2c7f4cf 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -173,7 +173,7 @@ extern "C" { extern SwigType *SwigType_array_type(SwigType *t); extern String *SwigType_default(SwigType *t); extern SwigType *SwigType_default_create(SwigType *ty); - extern SwigType *SwigType_default_reduce(SwigType *t); + extern SwigType *SwigType_default_deduce(SwigType *t); extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep); extern SwigType *SwigType_remove_global_scope_prefix(const SwigType *t); extern SwigType *SwigType_alttype(SwigType *t, int ltmap); diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index cc32780c5..37f8c3d82 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -787,7 +787,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type goto ret_result; { - SwigType *nprim = SwigType_default_reduce(primitive); + SwigType *nprim = SwigType_default_deduce(primitive); Delete(primitive); primitive = nprim; } From 00b1468091f3e14d7775f9b96f5b973a182ee2ba Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 9 Apr 2010 21:41:09 +0000 Subject: [PATCH 064/203] Update typemaps chapter and document new default typemap matching rules git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11983 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Typemaps.html | 208 +++++++++++++++++++++------------------ 1 file changed, 111 insertions(+), 97 deletions(-) diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index dee2bcf7f..066d9d79e 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -580,14 +580,14 @@ suppose you had a declaration like this,
        -Foo *make_Foo();
        +Foo *make_Foo(int n);
         

        -and you wanted to tell SWIG that make_Foo() returned a newly +and you wanted to tell SWIG that make_Foo(int n) returned a newly allocated object (for the purposes of providing better memory -management). Clearly, this property of make_Foo() is +management). Clearly, this property of make_Foo(int n) is not a property that would be associated with the datatype Foo * by itself. Therefore, a completely different SWIG customization mechanism (%feature) is used for this purpose. Consult the std::string and Foo::string).

        It should be noted that for scoping to work, SWIG has to know that string is a typename defined -within a particular namespace. In this example, this is done using the class declaration class string. +within a particular namespace. In this example, this is done using the forward class declaration class string.

        10.3 Pattern matching rules

        @@ -1085,16 +1085,16 @@ shows how some of the basic rules are applied: ... typemap 5 } -void A(int *x); // int *x rule (typemap 1) -void B(int *y); // int * rule (typemap 2) -void C(const int *x); // int *x rule (typemap 1) -void D(const int *z); // int * rule (typemap 3) -void E(int x[4]); // int [4] rule (typemap 4) -void F(int x[1000]); // int [ANY] rule (typemap 5) +void A(int *x); // int *x rule (typemap 1) +void B(int *y); // int * rule (typemap 2) +void C(const int *x); // int *x rule (typemap 1) +void D(const int *z); // const int *z rule (typemap 3) +void E(int x[4]); // int [4] rule (typemap 4) +void F(int x[1000]); // int [ANY] rule (typemap 5)
      -

      10.3.2 Typedef reductions

      +

      10.3.2 Typedef reductions matching

      @@ -1269,58 +1269,77 @@ void go(Struct aStruct); -

      10.3.3 Default typemaps

      +

      10.3.3 Default typemap matching rules

      +

      +If the basic pattern matching rules result in no match being made, even after typedef reductions, +the default typemap matching rules are used to look for a suitable typemap match. +These rules match a generic typemap based on the reserved SWIGTYPE base type. +For example pointers will use SWIGTYPE * and references will use SWIGTYPE &. +More precisely, the rules are based on the C++ template partial specialization matching rules used +by C++ compilers when looking for an appropriate partial template specialization. +This means that a match is chosen from the most specialized set of generic typemap types available. For example, +when looking for a match to int const *, the rules will prefer to match SWIGTYPE const * +if available before matching SWIGTYPE *, before matching SWIGTYPE. +

      +

      Most SWIG language modules use typemaps to define the default behavior of the C primitive types. This -is entirely straightforward. For example, a set of typemaps are written like this: +is entirely straightforward. For example, a set of typemaps for primitives marshalled by value or +const reference are written like this:

      -%typemap(in) int   "convert an int";
      -%typemap(in) short "convert a short";
      -%typemap(in) float "convert a float";
      +%typemap(in) int           "... convert to int ...";
      +%typemap(in) short         "... convert to short ...";
      +%typemap(in) float         "... convert to float ...";
      +...
      +%typemap(in) const int &   "... convert ...";
      +%typemap(in) const short & "... convert ...";
      +%typemap(in) const float & "... convert ...";
       ...
       

      Since typemap matching follows all typedef declarations, any sort of type that is -mapped to a primitive type through typedef will be picked up by one of these primitive typemaps. +mapped to a primitive type by value or const reference through typedef will be picked +up by one of these primitive typemaps. +Most language modules also define typemaps for char pointers and char arrays to handle strings, +so these non-default types will also be used in preference as the basic typemap matching rules +provide a better match than the default typemap matching rules.

      -The default behavior for pointers, arrays, references, and other kinds of types are handled by -specifying rules for variations of the reserved SWIGTYPE type. For example: +Below is a list of the typical default types supplied by language modules, showing what the "in" typemap would look like:

      -%typemap(in) SWIGTYPE *            { ... default pointer handling ...         }
      -%typemap(in) SWIGTYPE &            { ... default reference handling ...       }
      -%typemap(in) SWIGTYPE []           { ... default array handling ...           }
      -%typemap(in) enum SWIGTYPE         { ... default handling for enum values ... }
      -%typemap(in) SWIGTYPE (CLASS::*)   { ... default pointer member handling ...  } 
      +%typemap(in) SWIGTYPE &            { ... default reference handling ...                       };
      +%typemap(in) SWIGTYPE *            { ... default pointer handling ...                         };
      +%typemap(in) SWIGTYPE *const       { ... default pointer const handling ...                   };
      +%typemap(in) SWIGTYPE *const&      { ... default pointer const reference handling ...         };
      +%typemap(in) SWIGTYPE[ANY]         { ... 1D fixed size arrays handlling ...                   };
      +%typemap(in) SWIGTYPE []           { ... unknown sized array handling ...                     };
      +%typemap(in) enum SWIGTYPE         { ... default handling for enum values ...                 };
      +%typemap(in) const enum SWIGTYPE & { ... default handling for const enum reference values ... };
      +%typemap(in) SWIGTYPE (CLASS::*)   { ... default pointer member handling ...                  };
      +%typemap(in) SWIGTYPE              { ... simple default handling ...                          };
       

      -These rules match any kind of pointer, reference, or array--even when -multiple levels of indirection or multiple array dimensions are used. -Therefore, if you wanted to change SWIG's default handling for all -types of pointers, you would simply redefine the rule for SWIGTYPE -*. -

      - -

      -Finally, the following typemap rule is used to match against simple types that don't match any other rules: +If you wanted to change SWIG's default handling for +simple pointers, you would simply redefine the rule for SWIGTYPE *. +Note, the simple default typemap rule is used to match against simple types that don't match any other rules:

      -%typemap(in) SWIGTYPE   { ... handle an unknown type ... }
      +%typemap(in) SWIGTYPE              { ... simple default handling ...                          } 
       
      @@ -1339,7 +1358,7 @@ double dot_product(Vector a, Vector b);

      The Vector type will usually just get matched against SWIGTYPE. The default implementation of SWIGTYPE is -to convert the value into pointers (as described in chapter 3). +to convert the value into pointers (as described in this earlier section).

      @@ -1351,34 +1370,7 @@ objects into strings instead of converting them to pointers.

      -The best way to explore the default typemaps is to look at the ones -already defined for a particular language module. Typemaps -definitions are usually found in the SWIG library in a file such as -python.swg, tcl8.swg, etc. -

      - -

      10.3.4 Mixed default typemaps

      - - -

      -The default typemaps described above can be mixed with const and with each other. -For example the SWIGTYPE * typemap is for default pointer handling, but if a const SWIGTYPE * typemap -is defined it will be used instead for constant pointers. Some further examples follow: -

      - -
      -
      -%typemap(in) enum SWIGTYPE &        { ... enum references ...                       }
      -%typemap(in) const enum SWIGTYPE &  { ... const enum references ...                 }
      -%typemap(in) SWIGTYPE *&            { ... pointers passed by reference ...          }
      -%typemap(in) SWIGTYPE * const &     { ... constant pointers passed by reference ... }
      -%typemap(in) SWIGTYPE[ANY][ANY]     { ... 2D arrays ...                             }
      -
      -
      - -

      -Note that the the typedef reduction described earlier is also used with these mixed default typemaps. -For example, say the following typemaps are defined and SWIG is looking for the best match for the enum shown below: +Let's consider an example where the following typemaps are defined and SWIG is looking for the best match for the enum shown below:

      @@ -1397,12 +1389,22 @@ const Hello &hi;

      The typemap at the top of the list will be chosen, not because it is defined first, but because it is the closest match for the type being wrapped. If any of the typemaps in the above list were not defined, then the next one on the list would have precedence. -In other words the typemap chosen is the closest explicit match.

      -Compatibility note: The mixed default typemaps were introduced in SWIG-1.3.23, but were not used much in this version. -Expect to see them being used more and more within the various libraries in later versions of SWIG. +The best way to explore the default typemaps is to look at the ones +already defined for a particular language module. Typemap +definitions are usually found in the SWIG library in a file such as +java.swg, csharp.swg etc. +However, for many of the target languages the typemaps are hidden behind complicated macros, +so the best way to view the default typemaps, or any typemaps for that matter, +is to look at the preprocessed output by running swig -E on any interface file. +Finally the best way to view the typemap matching rules in action is via the debugging typemap pattern matching options covered later on. +

      + +

      +Compatibility note: The default typemap matching rules were modified in SWIG-2.0.0 from a slightly +simpler scheme to match the current C++ template partial specialization matching rules.

      @@ -1501,9 +1503,17 @@ example.h:3: Searching for a suitable 'in' typemap for: Row4 rows[10]

      showing that the best default match supplied by SWIG is the SWIGTYPE [] typemap. -As the example shows, the successful match displays just the typemap method name and type in this format: %typemap(method) type. +As the example shows, the successful match displays the used typemap source including typemap method, type and optional name in one of these simplified formats:

      + +

        +
      • Using: %typemap(method) type name +
      • Using: %typemap(method) type name = type2 name2 +
      • Using: %apply type2 name2 { type name } +
      + +

      This information might meet your debugging needs, however, you might want to analyze further. -If you next invoke SWIG with the -E option to display the preprocessed output, and search for this particular typemap, +If you next invoke SWIG with the -E option to display the preprocessed output, and search for the particular typemap used, you'll find the full typemap contents (example shown below for Python):

      @@ -1543,7 +1553,7 @@ SWIGINTERN PyObject *_wrap_foo(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {

      Searches for multi-argument typemaps are not mentioned unless a matching multi-argument typemap does actually exist. -For example, the output for the code in the previous section is as follows: +For example, the output for the code in the earlier multi-arguments section is as follows:

      @@ -1560,7 +1570,7 @@ example.h:39: Searching for a suitable 'in' typemap for: char *buffer

      The second option for debugging is -debug-tmused and this displays the typemaps used. This option is a less verbose version of the -debug-tmsearch option as it only displays each successfully found typemap on a separate single line. -The output displays the type, and name if present, the typemap method in brackets and then the actual typemap used. +The output displays the type, and name if present, the typemap method in brackets and then the actual typemap used in the same simplified format output by the -debug-tmsearch option. Below is the output for the example code at the start of this section on debugging.

      @@ -1711,12 +1721,16 @@ Occasionally, typemap code will be specified using a few alternative forms. For %typemap(in) int %{ $1 = PyInt_AsLong($input); %} +%typemap(in, noblock=1) int { +$1 = PyInt_AsLong($input); +}

      -These two forms are mainly used for cosmetics--the specified code is not enclosed inside +These three forms are mainly used for cosmetics--the specified code is not enclosed inside a block scope when it is emitted. This sometimes results in a less complicated looking wrapper function. +Note that only the third of the three typemaps have the typemap code passed through the SWIG preprocessor.

      10.4.2 Declaring new local variables

      @@ -1845,7 +1859,7 @@ wrap_foo() {

      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. +apply). At this time, only typemaps that apply to argument conversion support this (input typemaps such as the "in" typemap).

      @@ -2262,7 +2276,7 @@ When numinputs is set to 0, the argument is effectively ignored and can The argument is still required when making the C/C++ call and the above typemap shows the value used is instead obtained from a locally declared variable called temp. Usually numinputs is not specified, whereupon the default value is 1, that is, there is a one to one mapping of the number of arguments when used from the target language to the C/C++ call. -Multi-argument typemaps provide a similar concept where the number of arguments mapped from the target language to C/C++ can be changed for more tha multiple adjacent C/C++ arguments. +Multi-argument typemaps provide a similar concept where the number of arguments mapped from the target language to C/C++ can be changed for multiple adjacent C/C++ arguments.

      @@ -2293,7 +2307,7 @@ the input argument is the correct type.

      If you define new "in" typemaps and your program uses overloaded methods, you should also define a collection of -"typecheck" typemaps. More details about this follow in a later section on "Typemaps and Overloading." +"typecheck" typemaps. More details about this follow in the Typemaps and overloading section.

      10.5.3 "out" typemap

      @@ -2441,7 +2455,7 @@ return values are often appended to return value of the function.

      -See the typemaps.i library for examples. +See the typemaps.i library file for examples.

      10.5.8 "freearg" typemap

      @@ -2766,9 +2780,8 @@ You may even get a warning message like this:

      -swig -python  example.i
      -Generating wrappers for Python
      -example.i:10.  Warning. Array member value will be read-only.
      +$ swig -python  example.i
      +example.i:10: Warning 462: Unable to set variable of type float [4].
       

      @@ -2865,7 +2878,7 @@ useless and has since been eliminated. To return structure members, simply use One particularly interesting application of typemaps is the implementation of argument constraints. This can be done with the "check" typemap. When used, this allows you to provide code for -checking the values of function arguments. For example :

      +checking the values of function arguments. For example:

       %module math
      @@ -2888,7 +2901,7 @@ your program terminated with an error message.

      This kind of checking can be particularly useful when working with -pointers. For example :

      +pointers. For example:

       %typemap(check) Vector * {
      @@ -2906,10 +2919,6 @@ a NULL pointer. As a result, SWIG can often prevent a potential
       segmentation faults or other run-time problems by raising an exception
       rather than blindly passing values to the underlying C/C++ program.

      -

      -Note: A more advanced constraint checking system is in development. Stay tuned. -

      -

      10.7 Typemaps for multiple target languages

      @@ -2986,7 +2995,7 @@ struct XX {

      -The "out" typemap shown is the default typemap for C# when returning by objects by value. +The "out" typemap shown is the default typemap for C# when returning objects by value. When making a call to XX::create() from C#, the output is as follows:

      @@ -3108,7 +3117,7 @@ try {

      -It should be clear that the above code cannot be used as the argument to the copy constructor call, ie for the $1 substitution. +It should be clear that the above code cannot be used as the argument to the copy constructor call, that is, for the $1 substitution.

      @@ -3159,14 +3168,14 @@ list of strings like this:

      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. Therefore, SWIG1.3 -introduces the notion of multi-argument typemaps. +typemaps, this type of conversion is possible, but extremely painful. +Multi-argument typemaps help in this situation.

      A multi-argument typemap is a conversion rule that specifies how to -convert a single object in the target language to set of -consecutive function arguments in C/C++. For example, the following multi-argument +convert a single object in the target language to a set of +consecutive function arguments in C/C++. For example, the following multi-argument maps perform the conversion described for the above example:

      @@ -3390,7 +3399,9 @@ this, you could write a multi-argument typemap like this: This kind of technique can be used to hook into scripting-language matrix packages such as Numeric Python. However, it should also be stressed that some care is in order. For example, when crossing languages you may need to worry about issues such as row-major vs. column-major -ordering (and perform conversions if needed). +ordering (and perform conversions if needed). Note that multi-argument typemaps cannot deal +with non-consecutive C/C++ arguments; a workaround such as a helper function re-ordering +the arguments to make them consecutive will need to be written.

      10.10 The run-time type checker

      @@ -3693,7 +3704,7 @@ interface file.

      Further details about the run-time type checking can be found in the documentation for individual language modules. Reading the source code may also help. The file -Lib/swigrun.swg in the SWIG library contains all of the source code for +Lib/swigrun.swg in the SWIG library contains all of the source of the generated code for type-checking. This code is also included in every generated wrapped file so you probably just look at the output of SWIG to get a better sense for how types are managed. @@ -3703,7 +3714,9 @@ managed.

      -In many target languages, SWIG fully supports C++ overloaded methods and functions. For example, +This section does not apply to the statically typed languages like Java and C#, where overloading +of the types is handled much like C++ by generating overloaded methods in the target language. +In many of the other target languages, SWIG still fully supports C++ overloaded methods and functions. For example, if you have a collection of functions like this:

      @@ -4215,7 +4228,7 @@ sure that the typemaps sharing information have exactly the same types and names

      -All the rules discussed for Typemaps apply to C++ as well as C. +All the rules discussed for typemaps apply to C++ as well as C. However in addition C++ passes an extra parameter into every non-static class method -- the this pointer. Occasionally it can be useful to apply a typemap to this pointer (for example to check @@ -4235,7 +4248,8 @@ For example, if wrapping for Java generation:

       %typemap(check) SWIGTYPE *self %{
       if (!$1) {
      -  SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "swigCPtr null");
      +  SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException,
      +    "invalid native object; delete() likely already called");
         return $null;
       }
       %}
      @@ -4260,14 +4274,14 @@ The generated code will look something like:
             "invalid native object; delete() likely already called");
           return ;
         }
      -  (arg1)->wrappedFunction(...);
      +  (arg1)->wrappedFunction(...);
       

      Note that if you have a parameter named self then it will also match the typemap. One work around is to create an interface file that wraps -the method, but give the argument a name other than self. +the method, but gives the argument a name other than self.

      10.16 Where to go for more information?

      From 9dd763d4d3edf7946d9ccb7c09db8dbecbc9c0a7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 9 Apr 2010 22:02:09 +0000 Subject: [PATCH 065/203] Fix #2887254 and #2946032 - SWIG_Lua_typename using wrong stack index. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11984 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/lua/luarun.swg | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index ca74f192f..d2f5f0372 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-04-09: wsfulton + [Lua] Fix #2887254 and #2946032 - SWIG_Lua_typename using wrong stack index. + 2010-04-03: wsfulton [Python] Fix exceptions being thrown with the -threads option based on patch from Arto Vuori. Fixes bug #2818499. diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index b4e979531..89b762637 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -661,7 +661,7 @@ SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp) swig_lua_userdata* usr; if (lua_isuserdata(L,tp)) { - usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */ + usr=(swig_lua_userdata*)lua_touserdata(L,tp); /* get data */ if (usr && usr->type && usr->type->str) return usr->type->str; return "userdata (unknown type)"; From 5a626898dfcee189183451284755422627b67aff Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 9 Apr 2010 22:22:06 +0000 Subject: [PATCH 066/203] Apply patch #2952374 - fix Python directors and the -nortti option. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11985 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Source/Modules/lang.cxx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index d2f5f0372..c05a530c5 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-04-09: wsfulton + [Python] Apply patch #2952374 - fix directors and the -nortti option. + 2010-04-09: wsfulton [Lua] Fix #2887254 and #2946032 - SWIG_Lua_typename using wrong stack index. diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 2bfddc764..fb3d58ce4 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1924,7 +1924,7 @@ int Language::classDirectorDisown(Node *n) { Delete(type); type = NewString("void"); String *action = NewString(""); - Printv(action, "{\n", "Swig::Director *director = dynamic_cast(arg1);\n", "if (director) director->swig_disown();\n", "}\n", NULL); + Printv(action, "{\n", "Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n", "if (director) director->swig_disown();\n", "}\n", NULL); Setfile(disown, Getfile(n)); Setline(disown, Getline(n)); Setattr(disown, "wrap:action", action); From 242689aed533bd50acff56dcf9253697d4f32c91 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 9 Apr 2010 23:04:59 +0000 Subject: [PATCH 067/203] Apply Ubuntu patch to fix Mzscheme std::map wrappers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11986 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/mzscheme/std_map.i | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index c05a530c5..296416c6b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 2.0.0 (in progress) ============================ +2010-04-09: wsfulton + [Mzscheme] Apply Ubuntu patch to fix std::map wrappers: + https://bugs.launchpad.net/ubuntu/+source/swig1.3/+bug/203876 + 2010-04-09: wsfulton [Python] Apply patch #2952374 - fix directors and the -nortti option. diff --git a/Lib/mzscheme/std_map.i b/Lib/mzscheme/std_map.i index b2c894509..ffd76d213 100644 --- a/Lib/mzscheme/std_map.i +++ b/Lib/mzscheme/std_map.i @@ -247,8 +247,8 @@ namespace std { } Scheme_Object* keys() { Scheme_Object* result = scheme_null; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map::reverse_iterator i=self->rbegin(); + i!=self->rend(); ++i) { K* key = new K(i->first); Scheme_Object* k = SWIG_NewPointerObj(key,$descriptor(K *), 1); result = scheme_make_pair(k,result); @@ -467,8 +467,8 @@ namespace std { } Scheme_Object* keys() { Scheme_Object* result = scheme_null; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map::reverse_iterator i=self->rbegin(); + i!=self->rend(); ++i) { Scheme_Object* k = CONVERT_TO(i->first); result = scheme_make_pair(k,result); } @@ -679,8 +679,8 @@ namespace std { } Scheme_Object* keys() { Scheme_Object* result = scheme_null; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map::reverse_iterator i=self->rbegin(); + i!=self->rend(); ++i) { K* key = new K(i->first); Scheme_Object* k = SWIG_NewPointerObj(key,$descriptor(K *), 1); result = scheme_make_pair(k,result); @@ -891,8 +891,8 @@ namespace std { } Scheme_Object* keys() { Scheme_Object* result = scheme_null; - for (std::map::reverse_iterator i=$1.rbegin(); - i!=$1.rend(); ++i) { + for (std::map::reverse_iterator i=self->rbegin(); + i!=self->rend(); ++i) { Scheme_Object* k = CONVERT_K_TO(i->first); result = scheme_make_pair(k,result); } From 894f89fe9735a3850b552f100f069c72bfeb7e57 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 9 Apr 2010 23:27:40 +0000 Subject: [PATCH 068/203] Apply Ubuntu patch to fix Ruby and std::vector wrappers with -minherit. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11987 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/minherit.i | 5 +++++ Source/Modules/ruby.cxx | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 296416c6b..76afade79 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 2.0.0 (in progress) ============================ +2010-04-09: wsfulton + [Ruby] Apply Ubuntu patch to fix Ruby and std::vector wrappers with -minherit. + https://bugs.launchpad.net/ubuntu/+source/swig1.3/+bug/522874 + 2010-04-09: wsfulton [Mzscheme] Apply Ubuntu patch to fix std::map wrappers: https://bugs.launchpad.net/ubuntu/+source/swig1.3/+bug/203876 diff --git a/Examples/test-suite/minherit.i b/Examples/test-suite/minherit.i index 24092b6c6..fed8b029c 100644 --- a/Examples/test-suite/minherit.i +++ b/Examples/test-suite/minherit.i @@ -75,3 +75,8 @@ int wget(SpamPtr f) { #endif + +// Was causing runtime error in Ruby +%include +%template(IntVector) std::vector; + diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index ce89f9c63..8fc41813f 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -1248,7 +1248,11 @@ public: Iterator alias = First(aliases); while (alias.item) { if (Len(alias.item) > 0) { - Printv(klass->init, tab4, "rb_define_alias(", klass->vname, ", \"", alias.item, "\", \"", iname, "\");\n", NIL); + if (multipleInheritance) { + Printv(klass->init, tab4, "rb_define_alias(", klass->mImpl, ", \"", alias.item, "\", \"", iname, "\");\n", NIL); + } else { + Printv(klass->init, tab4, "rb_define_alias(", klass->vname, ", \"", alias.item, "\", \"", iname, "\");\n", NIL); + } } alias = Next(alias); } From fc3873befc38ed224161326eb268a8de1914b4de Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 9 Apr 2010 23:47:55 +0000 Subject: [PATCH 069/203] Update Ruby and std::vector wrappers with -minherit bug info git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11988 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 76afade79..6db583a33 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,7 +2,8 @@ Version 2.0.0 (in progress) ============================ 2010-04-09: wsfulton - [Ruby] Apply Ubuntu patch to fix Ruby and std::vector wrappers with -minherit. + [Ruby] Fix #2048064 and #2408020. + Apply Ubuntu patch to fix Ruby and std::vector wrappers with -minherit. https://bugs.launchpad.net/ubuntu/+source/swig1.3/+bug/522874 2010-04-09: wsfulton From f9caea4b295aa6ac57c264e546008bd9c0b86f7a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 10 Apr 2010 00:04:28 +0000 Subject: [PATCH 070/203] Add SWIG_DIRECTOR_CAST recently added to languages needing it git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11989 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/ocaml/director.swg | 2 ++ Lib/octave/octrun.swg | 2 ++ Lib/python/director.swg | 8 ++++---- Lib/ruby/director.swg | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Lib/ocaml/director.swg b/Lib/ocaml/director.swg index a21f62102..77b2fd3c0 100644 --- a/Lib/ocaml/director.swg +++ b/Lib/ocaml/director.swg @@ -10,6 +10,8 @@ #include +# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) + namespace Swig { /* base class for director exceptions */ class DirectorException { diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index be2dc9653..8013dcb6e 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -106,6 +106,8 @@ SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *point typedef octave_value_list(*octave_func) (const octave_value_list &, int); class octave_swig_type; +# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) + namespace Swig { class Director; diff --git a/Lib/python/director.swg b/Lib/python/director.swg index a57df7315..8514365a9 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -85,13 +85,13 @@ namespace Swig { } # endif /* SWIG_DIRECTOR_RTDIR */ -# define SWIG_DIRECTOR_CAST(Arg) Swig::get_rtdir(static_cast(Arg)) -# define SWIG_DIRECTOR_RGTR(Arg1, Arg2) Swig::set_rtdir(static_cast(Arg1), Arg2) +# define SWIG_DIRECTOR_CAST(ARG) Swig::get_rtdir(static_cast(ARG)) +# define SWIG_DIRECTOR_RGTR(ARG1, ARG2) Swig::set_rtdir(static_cast(ARG1), ARG2) #else -# define SWIG_DIRECTOR_CAST(Arg) dynamic_cast(Arg) -# define SWIG_DIRECTOR_RGTR(Arg1, Arg2) +# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) +# define SWIG_DIRECTOR_RGTR(ARG1, ARG2) #endif /* SWIG_DIRECTOR_NORTTI */ diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index de6289cc5..cdc4baea1 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -21,6 +21,8 @@ #include #include +# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) + namespace Swig { /* memory handler */ struct GCItem From bdea09ed83828592b08b1151e0f14517cccd8b68 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 14 Apr 2010 22:22:16 +0000 Subject: [PATCH 071/203] Make typemap fragments official - move the documentation in fragments.swg into Typemaps.html git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11992 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 + Doc/Manual/Contents.html | 13 +- Doc/Manual/Typemaps.html | 435 +++++++++++++++++++++++++++++-------- Lib/typemaps/fragments.swg | 241 +------------------- 4 files changed, 363 insertions(+), 329 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6db583a33..387ad224b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-04-14: wsfulton + Typemap fragments are now official and documented in Typemaps.html. + 2010-04-09: wsfulton [Ruby] Fix #2048064 and #2408020. Apply Ubuntu patch to fix Ruby and std::vector wrappers with -minherit. diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 5bd3210bf..a99fd1885 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -349,9 +349,8 @@
    • Pattern matching rules @@ -390,14 +389,18 @@
    • Typemaps for multiple target languages
    • Optimal code generation when returning by value
    • Multi-argument typemaps -
    • The run-time type checker +
    • Typemap fragments + +
    • The run-time type checker
    • Typemaps and overloading
    • More about %apply and %clear -
    • Reducing wrapper code size
    • Passing data between typemaps
    • C++ "this" pointer
    • Where to go for more information? diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 066d9d79e..71c2c43ec 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -31,9 +31,8 @@
    • Pattern matching rules @@ -72,14 +71,18 @@
    • Typemaps for multiple target languages
    • Optimal code generation when returning by value
    • Multi-argument typemaps -
    • The run-time type checker +
    • Typemap fragments + +
    • The run-time type checker
    • Typemaps and overloading
    • More about %apply and %clear -
    • Reducing wrapper code size
    • Passing data between typemaps
    • C++ "this" pointer
    • Where to go for more information? @@ -1408,7 +1411,7 @@ simpler scheme to match the current C++ template partial specialization matching

      -

      10.3.5 Multi-arguments typemaps

      +

      10.3.4 Multi-arguments typemaps

      @@ -1438,7 +1441,7 @@ but all subsequent arguments must match exactly.

      -

      10.3.6 Debugging typemap pattern matching

      +

      10.3.5 Debugging typemap pattern matching

      @@ -3404,7 +3407,335 @@ with non-consecutive C/C++ arguments; a workaround such as a helper function re- the arguments to make them consecutive will need to be written.

      -

      10.10 The run-time type checker

      +

      10.10 Typemap fragments

      + + +

      +The primary purpose of fragments is to reduce code bloat that repeated use of typemap code can lead to. +Fragments are snippets of code that can be thought of as code dependencies of a typemap. +If a fragment is used by more than one typemap, then the snippet of code within the fragment is only generated once. +Code bloat is typically reduced by moving typemap code into a support function +and then placing the support function into a fragment. +

      + +

      +For example, if you have a very long typemap +

      + +
      +
      +%typemap(in) MyClass * {
      +  MyClass *value = 0;
      +
      +  ... many lines of marshalling code  ...
      +
      +  $result = value;
      +}
      +
      +
      + +

      +the same marshalling code is often repeated in several typemaps, such as "in", "varin", "directorout", etc. +SWIG copies the code for each argument that requires the typemap code, easily leading to code bloat +in the generated code. +To eliminate this, define a fragment that includes the common marshalling code: +

      + +
      +
      +%fragment("AsMyClass", "header") {
      +  MyClass *AsMyClass(PyObject *obj) {
      +    MyClass *value = 0;
      +
      +    ... many lines of marshalling code  ...
      +
      +    return value;
      +  }
      +}
      +
      +%typemap(in, fragment="AsMyClass") MyClass * {
      +  $result = AsMyClass($input);
      +}
      +
      +%typemap(varin, fragment="AsMyClass") MyClass * {
      +  $result = AsMyClass($input);
      +}
      +
      +
      + +

      +When the "in" or "varin" typemaps for MyClass are required, the +contents of the fragment called "AsMyClass" is added to the "header" section within the generated code, and then the +typemap code is emitted. Hence, the method AsMyClass will be +generated into the wrapper code before any typemap code that calls it. +

      + +

      +To define a fragment you need a fragment name, a section name for generating the fragment code into, and the code itself. +See Code insertion blocks for a full list of section names. +Usually the section name used is "header". Both string and curly braces can be used: +

      + +
      +
      +%fragment("my_name", "header") { ... }
      +%fragment("my_name", "header") " ... "
      +
      +
      + +

      +The following are some rules and guidelines for using fragments: +

      + +
        +
      1. +

        +A fragment is added to the wrapping code only once. When using the MyClass * typemaps above and wrapping the method: +

        + +
        +
        +void foo(MyClass *a, MyClass *b);
        +
        +
        + +

        +the generated code will look something like: +

        + +
        +
        +MyClass *AsMyClass(PyObject *obj) {
        +  ...
        +}
        +
        +void _wrap_foo(...) {
        +  ....
        +  arg1 = AsMyClass(obj1);
        +  arg2 = AsMyClass(obj2);
        +  ...
        +  foo(arg1, arg2);
        +}
        +
        +
        + +

        +even as there is duplicated typemap code to process both a and +b, the AsMyClass method will be defined only once. +

        + +
      2. +

        +A fragment should only be defined once. If there is more than +one definition, the first definition is the one used. +All other definitions are silently ignored. For example, if you have +

        + + +
        +
        +%fragment("AsMyClass", "header") { ...definition 1... }
        +....
        +%fragment("AsMyClass", "header") { ...definition 2... }
        +
        +
        + +

        +only the first definition is used. In this way +you can override the default fragments in a SWIG library by defining your fragment before the library %include. +Note that this behavior is the opposite to typemaps, where the last typemap defined/applied prevails. +Fragments follow the first-in-first-out convention since they are intended to be global, +while typemaps are intended to be locally specialized. +

        + +
      3. +

        +Fragment names cannot contain commas. +

        + + +
      4. +

        +A fragment can use one or more additional fragments, for example: +

        + +
        +
        +%fragment("<limits.h>", "header")  {
        +  #include <limits.h>
        +}
        +
        +
        +%fragment("AsMyClass", "header", fragment="<limits.h>") {
        +  MyClass *AsMyClass(PyObject *obj) {
        +    MyClass *value = 0;
        +
        +    ... some marshalling code  ...
        +
        +    if  (ival < CHAR_MIN /*defined in <limits.h>*/) {
        +       ...
        +    } else {
        +       ...
        +    }
        +    ...
        +    return value;
        +  }
        +}
        +
        +
        + +

        +in this case, when the "AsMyClass" fragment is emitted, it also +triggers the inclusion of the "<limits.h>" fragment. +

        + +
      5. +

        +A fragment can have dependencies on a number of other fragments, for example: +

        + +
        +
        +%fragment("bigfragment", "header", fragment="frag1", fragment="frag2", fragment="frag3") "";
        +
        +
        + +

        +When the "bigfragment" is used, the three dependent fragments "frag1", +"frag2" and "frag3" are also pulled in. Note that as "bigframent" is +empty (the empty string - ""), it does not add any code itself, but merely triggers the +inclusion of the other fragments. +

        + +
      6. +

        +A typemap can also use more than one fragment, but since the +syntax is different, you need to specify the dependent fragments in a comma separated +list. Consider: +

        + +
        +
        +%typemap(in, fragment="frag1,frag2,frag3") {...}
        +
        +
        + +

        +which is equivalent to: +

        + +
        +
        +%typemap(in, fragment="bigfragment") {...}
        +
        +
        + +

        +when used with the "bigfragment" defined above. +

        + +
      7. +

        +Finally, you can force the inclusion of a fragment at any point in the generated code as follows: +

        + +
        +
        +%fragment("bigfragment");
        +
        +
        + +

        +which is very useful inside a template class, for example. +

        +
      + +

      +Most readers will probably want to skip the next two sub-sections on advanced +fragment usage unless a desire to really get to grips +with some powerful but tricky macro and fragment usage that is used in parts of the SWIG typemap library. +

      + +

      10.10.1 Fragment type specialization

      + + +

      +Fragments can be type specialized. The syntax is as follows: +

      + +
      +
      +%fragment("name", "header") { ...a type independent fragment... }
      +%fragment("name"{type}, "header") { ...a type dependent fragment...  }
      +
      +
      + +

      +where type is a C/C++ type. Like typemaps, fragments can also be used inside templates, for example: +

      + +
      +
      +template <class T>
      +struct A {
      +  %fragment("incode"{A<T>}, "header") {
      +    ... 'incode' specialized fragment ...
      +  }
      +
      +  %typemap(in, fragment="incode"{A<T>}) {
      +     ... here we use the 'type specialized' fragment "incode"{A<T>} ...
      +  }
      +};
      +
      +
      + +

      10.10.2 Fragments and automatic typemap specialization

      + + +

      +Since fragments can be type specialized, they can be elegantly used +to specialize typemaps. For example, if you have something like: +

      + +
      +
      +%fragment("incode"{float}, "header") {
      +  float in_method_float(PyObject *obj) {
      +    ...
      +  }
      +}
      +
      +%fragment("incode"{long}, "header") {
      +  float in_method_long(PyObject *obj) {
      +    ...
      +  }
      +}
      +
      +// %my_typemaps macro definition
      +%define %my_typemaps(Type) 
      +%typemap(in, fragment="incode"{Type}) Type {
      +  value = in_method_##Type(obj);
      +}
      +%enddef
      +
      +%my_typemaps(float);
      +%my_typemaps(long);
      +
      +
      + +

      +then the proper "incode"{float} or "incode"{long} fragment will be used, +and the in_method_float and in_method_long methods will be called whenever +the float or long types are used as input parameters. +

      + +

      +This feature is used a lot in the typemaps shipped in the SWIG library for some scripting languages. +The interested (or very brave) reader can take a look at the fragments.swg file shipped with SWIG to see this in action. +

      + + +

      10.11 The run-time type checker

      @@ -3430,7 +3761,7 @@ language modules.

    • Modules can be unloaded from the type system.
    -

    10.10.1 Implementation

    +

    10.11.1 Implementation

    @@ -3616,7 +3947,7 @@ structures rather than creating new ones. These swig_module_info structures are chained together in a circularly linked list.

    -

    10.10.2 Usage

    +

    10.11.2 Usage

    This section covers how to use these functions from typemaps. To learn how to @@ -3710,7 +4041,7 @@ probably just look at the output of SWIG to get a better sense for how types are managed.

    -

    10.11 Typemaps and overloading

    +

    10.12 Typemaps and overloading

    @@ -4021,7 +4352,7 @@ Subsequent "in" typemaps would then perform more extensive type-checking.

  • -

    10.12 More about %apply and %clear

    +

    10.13 More about %apply and %clear

    @@ -4106,86 +4437,6 @@ example: -

    10.13 Reducing wrapper code size

    - - -

    -Since the code supplied to a typemap is inlined directly into wrapper functions, typemaps can result -in a tremendous amount of code bloat. For example, consider this typemap for an array: -

    - -
    -
    -%typemap(in) float [ANY] {
    -  int i;
    -  if (!PySequence_Check($input)) {
    -    PyErr_SetString(PyExc_ValueError,"Expected a sequence");
    -    return NULL;
    -  }
    -  if (PySequence_Length($input) != $1_dim0) {
    -    PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected $1_dim0 elements");
    -    return NULL;
    -  }
    -  $1 = (float) malloc($1_dim0*sizeof(float));
    -  for (i = 0; i < $1_dim0; i++) {
    -    PyObject *o = PySequence_GetItem($input,i);
    -    if (PyNumber_Check(o)) {
    -      $1[i] = (float) PyFloat_AsDouble(o);
    -    } else {
    -      PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");      
    -      free(result);
    -      return NULL;
    -    }
    -  }
    -}
    -
    -
    - -

    -If you had a large interface with hundreds of functions all accepting -array parameters, this typemap would be replicated -repeatedly--generating a huge amount of code. A better approach might -be to consolidate some of the typemap into a function. For example: -

    - -
    -
    -%{
    -/* Define a helper function */
    -static float *
    -convert_float_array(PyObject *input, int size) {
    -  int i;
    -  float *result;
    -  if (!PySequence_Check(input)) {
    -    PyErr_SetString(PyExc_ValueError,"Expected a sequence");
    -    return NULL;
    -  }
    -  if (PySequence_Length(input) != size) {
    -    PyErr_SetString(PyExc_ValueError,"Size mismatch. ");
    -    return NULL;
    -  }
    -  result = (float) malloc(size*sizeof(float));
    -  for (i = 0; i < size; i++) {
    -    PyObject *o = PySequence_GetItem(input,i);
    -    if (PyNumber_Check(o)) {
    -      result[i] = (float) PyFloat_AsDouble(o);
    -    } else {
    -      PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");
    -      free(result);       
    -      return NULL;
    -    }
    -  }
    -  return result;
    -}
    -%}
    -
    -%typemap(in) float [ANY] {
    -    $1 = convert_float_array($input, $1_dim0);
    -    if (!$1) return NULL;
    -}
    -%}
    -
    -

    10.14 Passing data between typemaps

    diff --git a/Lib/typemaps/fragments.swg b/Lib/typemaps/fragments.swg index ef6a346cc..099bb4729 100644 --- a/Lib/typemaps/fragments.swg +++ b/Lib/typemaps/fragments.swg @@ -1,238 +1,15 @@ /* - Fragments: - ========== + Fragments + ========= + See the "Typemap fragments" section in the documentation for understanding + fragments. Below is some info on how fragments and automatic type + specialization is used. - Second to typemaps, fragments are one the most powerful and - dangerous swig features. So, if you are starting to read about them, - make sure you read all of this document. + Macros that make the automatic generation of typemaps easier are provided. - Basics: - ======= + Consider the following code: - Fragments provide a way to include or generate code into "on-demand" - as the typemaps could require. - - For example, if you have a very long typemap - - %typemap(in) MyClass * { - MyClass *value = 0; - - - .... - value = somewhere_converted_from_input_object_here($input); - ... - - - $result = value; - } - - very soon you will discover yourself copying the same long - conversion code in several typemaps, such as varin, directorout, - etc. Also, you will discover that swig copes verbatim the same very - long conversion code for every argument that requires it, making the - code very large too. - - To eliminate this automatic or manual code copying, we define a - fragment that includes the common conversion code: - - %fragment("AsMyClass","header") { - MyClass *AsMyClass(PyObject *obj) { - MyClass *value = 0; - - .... - value = somewhere_converted_from_input_object_here(obj); - ... - - - return value; - } - } - - %typemap(in,fragment="AsMyClass") MyClass * { - $result = AsMyClass($input); - } - - %typemap(varin,fragment="AsMyClass") MyClass * { - $result = AsMyClass($input); - } - - When the 'in' or 'varin' typemaps for MyClass are invoked, the - fragment "AsMyClass" is added to the "header" section, and then the - typemap code is emitted. Hence, the method AsMyClass will be - included in the wrapping code and it will be available at the time - the typemap is applied. - - To define a fragment then you need a name, a section where it goes, - and the code. Usually the section refers to the "header" part, and - both string and braces forms are accepted, ie: - - %fragment("my_name","header") { ... } - %fragment("my_name","header") "..."; - - To ensure all the fragment/typemap engine works as expected, there - are some rules that fragments follow: - - 1.- A fragment is added to the wrapping code only once, ie, for the - method: - - int foo(MyClass *a, MyClass *b); - - the wrapped code will look as much as: - - MyClass *AsMyClass(PyObject *obj) { - ..... - } - - int _wrap_foo(...) { - .... - arg1 = AsMyClass(obj1); - arg2 = AsMyClass(obj2); - ... - result = foo(arg1, arg2); - } - - - even when there will be duplicated typemap to process 'a' and - 'b', the 'AsMyClass' method will be defined only once. - - - 2.- A fragment can only defined once, and the first definition - is the only one taking in account. All other definitions of the - same fragments are silently ignored. For example, you can have - - - %fragment("AsMyClass","header") { } - .... - %fragment("AsMyClass","header") { } - - and then only the first definition is considered. In this way - you can change the 'system' fragments by including yours first. - - Note that this behavior is opposite to the typemaps, where the - last typemap applied or defined prevails. Fragment follows the - first-in-first-out convention since they are intended to be - "global", while typemaps intend to be "locally" specialized. - - 3.- Fragments names can not contain commas. - - - A fragment can include one or more additional fragments, for example: - - %fragment("", "header") { - #include - } - - - %fragment("AsMyClass", "header", fragment="") { - MyClass *AsMyClass(PyObject *obj) { - MyClass *value = 0; - int ival = somewhere_converted_from_input_object_here(obj) - ... - if (ival < CHAR_MIN) { - value = something_from_ival(ival); - } else { - ... - } - ... - return value; - } - } - - in this case, when the "AsMyClass" fragment is emitted, it also - trigger the inclusion of the "" fragment. - - You can add as many fragments as you want, for example - - %fragment("bigfragment","header", fragment="frag1", fragment="frag2", fragment="frag3") ""; - - here, when the "bigfragment" is included, the three fragments "frag1", - "frag2" and "frag3" are included. Note that as "bigframent" is defined - empty, "", it does not add any code by itself, buy only trigger the - inclusion of the other fragments. - - In a typemap you can also include more than one fragment, but since the - syntax is different, you need to specify them in a 'comma separated' - list, for example, considering the previous example: - - %typemap(in,fragment="frag1,frag2,frag3") {...} - - is equivalent to - - %typemap(in,fragment="bigfragment") {...} - - - Finally, you can force the inclusion of a fragment at any moment as follow: - - %fragment("bigfragment"); - - which is very useful inside a template class, for example. - - - Fragment type specialization - ============================ - - Fragments can be "type specialized". The syntax is as follows - - %fragment("name","header") { a type independent fragment } - %fragment("name" {Type}, "header") { a type dependent fragment } - - and they can also, as typemaps, be used inside templates, for exampe: - - template - struct A { - %fragment("incode"{A},"header") { - 'incode' specialized fragment - } - - %typemap(in,fragment="incode"{A}) { - here we use the 'type specialized' - fragment "incode"{A} - } - }; - - which could seems a not much interesting feature, but is - fundamental for automatic typemap and template specialization. - - - Fragments and automatic typemap specialization: - =============================================== - - Since fragments can be type specialized, they can be elegantly used - to specialized typemaps . - - For example, if you have something like: - - %fragment("incode"{float}, "header") { - float in_method_float(PyObject *obj) { - ... - } - } - - %fragment("incode"{long}, "header") { - float in_method_long(PyObject *obj) { - ... - } - } - - %define %my_typemaps(Type) - %typemaps(in,fragment="incode"{Type}) { - value = in_method_##Type(obj); - } - %enddef - - %my_typemaps(float); - %my_typemaps(long); - - then the proper "incode"{float,double} fragment will be included, - and the proper in_method_{float,double} will be called. - - Since this is a recurrent fragment use, we provide a couple of - macros that make the automatic generation of typemaps easier: - - - Consider for example the following code: - - %fragment(SWIG_From_frag(bool),"header") { + %fragment(SWIG_From_frag(bool), "header") { static PyObject* SWIG_From_dec(bool)(bool value) { @@ -242,7 +19,7 @@ } } - %typemap(out,fragment=SWIG_From_frag(bool)) bool { + %typemap(out, fragment=SWIG_From_frag(bool)) bool { $result = SWIG_From(bool)($1)); } From 2535297efbc72e857ac0865a4bd3e0e4ca331ca2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Apr 2010 06:44:47 +0000 Subject: [PATCH 072/203] minor formatting change git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11995 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/allegrocl/allegrocl.swg | 6 +++--- Lib/chicken/std_string.i | 5 ++--- Lib/guile/std_string.i | 7 +++---- Lib/lua/lua.swg | 2 +- Lib/lua/luatypemaps.swg | 10 +++++----- Lib/lua/wchar.i | 8 ++++---- Lib/python/argcargv.i | 2 +- Lib/r/r.swg | 6 +++--- 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Lib/allegrocl/allegrocl.swg b/Lib/allegrocl/allegrocl.swg index cc23a1f90..87e030ce4 100644 --- a/Lib/allegrocl/allegrocl.swg +++ b/Lib/allegrocl/allegrocl.swg @@ -203,20 +203,20 @@ SWIG_TYPECHECK_STRING_ARRAY 1140 %typemap(in) wchar_t "$1 = $input;"; %typemap(lin,numinputs=1) wchar_t "(cl::let (($out (cl:char-code $in)))\n $body)"; -%typemap(lin,numinputs=1) wchar_t* "(excl:with-native-string ($out $in +%typemap(lin,numinputs=1) wchar_t * "(excl:with-native-string ($out $in :external-format #+little-endian :fat-le #-little-endian :fat)\n $body)" %typemap(out) wchar_t "$result = $1;"; %typemap(lout) wchar_t "(cl::setq ACL_ffresult (cl::code-char $body))"; -%typemap(lout) wchar_t* "(cl::setq ACL_ffresult (excl:native-to-string $body +%typemap(lout) wchar_t * "(cl::setq ACL_ffresult (excl:native-to-string $body :external-format #+little-endian :fat-le #-little-endian :fat))"; %typemap(ffitype) wchar_t ":unsigned-short"; %typemap(lisptype) wchar_t ""; %typemap(ctype) wchar_t "wchar_t"; %typemap(lispclass) wchar_t "cl:character"; -%typemap(lispclass) wchar_t* "cl:string"; +%typemap(lispclass) wchar_t * "cl:string"; ////////////////////////////////////////////////////////////// /* Array reference typemaps */ diff --git a/Lib/chicken/std_string.i b/Lib/chicken/std_string.i index ce24cba32..9907a58bc 100644 --- a/Lib/chicken/std_string.i +++ b/Lib/chicken/std_string.i @@ -30,7 +30,7 @@ namespace std { %typemap(typecheck) string = char *; %typemap(typecheck) const string & = char *; - %typemap(in) string (char* tempptr) { + %typemap(in) string (char * tempptr) { if ($input == C_SCHEME_FALSE) { $1.resize(0); } else { @@ -44,8 +44,7 @@ namespace std { } } - %typemap(in) const string& (std::string temp, - char* tempptr) { + %typemap(in) const string& (std::string temp, char *tempptr) { if ($input == C_SCHEME_FALSE) { temp.resize(0); diff --git a/Lib/guile/std_string.i b/Lib/guile/std_string.i index c10806e98..65ab6efbf 100644 --- a/Lib/guile/std_string.i +++ b/Lib/guile/std_string.i @@ -26,7 +26,7 @@ namespace std { %typemap(typecheck) string = char *; %typemap(typecheck) const string & = char *; - %typemap(in) string (char* tempptr) { + %typemap(in) string (char * tempptr) { if (gh_string_p($input)) { tempptr = SWIG_scm2str($input); $1.assign(tempptr); @@ -36,8 +36,7 @@ namespace std { } } - %typemap(in) const string & (std::string temp, - char* tempptr) { + %typemap(in) const string & (std::string temp, char *tempptr) { if (gh_string_p($input)) { tempptr = SWIG_scm2str($input); temp.assign(tempptr); @@ -48,7 +47,7 @@ namespace std { } } - %typemap(in) string * (char* tempptr) { + %typemap(in) string * (char *tempptr) { if (gh_string_p($input)) { tempptr = SWIG_scm2str($input); $1 = new std::string(tempptr); diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index 5218bf0a8..a15f14148 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -176,7 +176,7 @@ use %include instead %{lua_pushnumber(L,(lua_Number)(int)$1);SWIG_fail; %} // strings are just sent as errors -%typemap(throws) char*, const char* +%typemap(throws) char *, const char * %{lua_pushstring(L,$1);SWIG_fail;%} // char is changed to a string diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index ae65cbfea..aff116192 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -89,7 +89,7 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} %typemap(out) const bool& %{ lua_pushboolean(L,(int)((*$1)!=0)); SWIG_arg++;%} -// strings (char* and char[]) +// strings (char * and char[]) %fragment("SWIG_lua_isnilstring", "header") { int SWIG_lua_isnilstring(lua_State *L, int idx) { int ret = lua_isstring(L, idx); @@ -99,17 +99,17 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} } } -%typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char*, char* +%typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char *, char * %{$1 = ($ltype)lua_tostring(L, $input);%} %typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char[ANY], char[ANY] %{$1 = ($ltype)lua_tostring(L, $input);%} -%typemap(out) const char*, char* -%{ lua_pushstring(L,(const char*)$1); SWIG_arg++;%} +%typemap(out) const char *, char * +%{ lua_pushstring(L,(const char *)$1); SWIG_arg++;%} %typemap(out) const char[ANY], char[ANY] -%{ lua_pushstring(L,(const char*)$1); SWIG_arg++;%} +%{ lua_pushstring(L,(const char *)$1); SWIG_arg++;%} // char's // currently treating chars as small strings, not as numbers diff --git a/Lib/lua/wchar.i b/Lib/lua/wchar.i index 02b5428be..92f7ed0e2 100644 --- a/Lib/lua/wchar.i +++ b/Lib/lua/wchar.i @@ -12,11 +12,11 @@ %{ #include -wchar_t* str2wstr(const char* str, int len) +wchar_t* str2wstr(const char *str, int len) { wchar_t* p; if (str==0 || len<1) return 0; - p=(wchar*)malloc((len+1)*sizeof(wchar_t)); + p=(wchar *)malloc((len+1)*sizeof(wchar_t)); if (p==0) return 0; if (mbstowcs(p, str, len)==-1) { @@ -28,13 +28,13 @@ wchar_t* str2wstr(const char* str, int len) } %} -%typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t* +%typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t * %{ $1 = str2wstr(lua_tostring( L, $input ),lua_strlen( L, $input )); if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;} %} -%typemap(freearg) wchar_t* +%typemap(freearg) wchar_t * %{ free($1); %} diff --git a/Lib/python/argcargv.i b/Lib/python/argcargv.i index d5d008ae5..717fe7334 100644 --- a/Lib/python/argcargv.i +++ b/Lib/python/argcargv.i @@ -60,7 +60,7 @@ SWIG_AsArgcArgv(PyObject *input, } /* - This typemap works with either a char**, a python list or a python + This typemap works with either a char **, a python list or a python tuple */ diff --git a/Lib/r/r.swg b/Lib/r/r.swg index b70d80581..121797e33 100644 --- a/Lib/r/r.swg +++ b/Lib/r/r.swg @@ -144,11 +144,11 @@ SWIG_InitializeModule(0); $1 = %reinterpret_cast(INTEGER($input), $1_ltype); } -%typemap(in,noblock=1,fragment="SWIG_strdup") char* { +%typemap(in,noblock=1,fragment="SWIG_strdup") char * { $1 = %reinterpret_cast(SWIG_strdup(CHAR(STRING_ELT($input, 0))), $1_ltype); } -%typemap(freearg,noblock=1) char* { +%typemap(freearg,noblock=1) char * { free($1); } @@ -189,7 +189,7 @@ else strcpy($1, ""); %} -%typemap(out,noblock=1) char* +%typemap(out,noblock=1) char * { $result = $1 ? Rf_mkString(%reinterpret_cast($1,char *)) : R_NilValue; } %typemap(in,noblock=1) char { From ff8f6b5c66a2bba42f5f7c134ea8128ddb46dc3c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Apr 2010 18:16:31 +0000 Subject: [PATCH 073/203] minor formatting changes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11996 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/typemaps/cstrings.swg | 3 +-- Lib/typemaps/strings.swg | 15 ++++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Lib/typemaps/cstrings.swg b/Lib/typemaps/cstrings.swg index c60ef6496..7fe6a3f8f 100644 --- a/Lib/typemaps/cstrings.swg +++ b/Lib/typemaps/cstrings.swg @@ -147,8 +147,7 @@ */ %define Name ## _mutable(TYPEMAP,EXP...) -%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP - (int res, Char* t = 0, size_t n = 0, int alloc = 0, size_t expansion = 0) { +%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP (int res, Char *t = 0, size_t n = 0, int alloc = 0, size_t expansion = 0) { #if #EXP != "" expansion += EXP; #endif diff --git a/Lib/typemaps/strings.swg b/Lib/typemaps/strings.swg index 04fa28f5d..7c5f59ae2 100644 --- a/Lib/typemaps/strings.swg +++ b/Lib/typemaps/strings.swg @@ -54,7 +54,7 @@ /* out */ -%typemap(out,noblock=1,fragment=#SWIG_FromCharPtr) Char *, const Char* { +%typemap(out,noblock=1,fragment=#SWIG_FromCharPtr) Char *, const Char * { %set_output(SWIG_FromCharPtr((const Char *)$1)); } @@ -98,7 +98,7 @@ /* varout */ -%typemap(varout,noblock=1,fragment=#SWIG_FromCharPtr) Char*, const Char* { +%typemap(varout,noblock=1,fragment=#SWIG_FromCharPtr) Char *, const Char * { %set_varoutput(SWIG_FromCharPtr($1)); } @@ -165,8 +165,7 @@ /* directorout */ -%typemap(directorout,noblock=1,fragment=#SWIG_AsCharPtr,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) - Char * (int res, Char* buf = 0, int alloc = SWIG_NEWOBJ) { +%typemap(directorout,noblock=1,fragment=#SWIG_AsCharPtr,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) Char * (int res, Char *buf = 0, int alloc = SWIG_NEWOBJ) { res = SWIG_AsCharPtr($input, &buf, &alloc); if (!SWIG_IsOK(res)) { %dirout_fail(res, "$type"); @@ -184,9 +183,7 @@ } -%typemap(directorout,noblock=1,fragment=#SWIG_AsCharPtr,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) - Char * const& (int res, Char* buf = 0, int alloc = SWIG_NEWOBJ), - Char const* const& (int res, Char* buf = 0, int alloc = SWIG_NEWOBJ) { +%typemap(directorout,noblock=1,fragment=#SWIG_AsCharPtr,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) Char *const& (int res, Char *buf = 0, int alloc = SWIG_NEWOBJ), Char const*const& (int res, Char *buf = 0, int alloc = SWIG_NEWOBJ) { res = SWIG_AsCharPtr($input, &buf, &alloc); if (!SWIG_IsOK(res)) { %dirout_fail(res, "$type"); @@ -226,8 +223,8 @@ * Unknown size const Character array Char[ANY] handling * ------------------------------------------------------------ */ -%apply Char* { Char [] }; -%apply const Char* { const Char [] }; +%apply Char * { Char [] }; +%apply const Char * { const Char [] }; %typemap(varin,noblock=1,warning="462:Unable to set variable of type Char []") Char [] { From 2450c4b108da7d3cd231ccd14b478c48c3b0f391 Mon Sep 17 00:00:00 2001 From: Haoyu Bai Date: Sun, 25 Apr 2010 14:07:14 +0000 Subject: [PATCH 074/203] fix regression of Python constructor renaming introduced by py3k work git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11997 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Examples/test-suite/common.mk | 1 + Examples/test-suite/constructor_rename.i | 12 ++++++++++++ .../test-suite/python/constructor_rename_runme.py | 3 +++ Source/Modules/python.cxx | 5 +++-- 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/constructor_rename.i create mode 100644 Examples/test-suite/python/constructor_rename_runme.py diff --git a/CHANGES.current b/CHANGES.current index 387ad224b..0a707a918 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-04-25: bhy + [Python] Fix #2985655 - broken constructor renaming. + 2010-04-14: wsfulton Typemap fragments are now official and documented in Typemaps.html. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index a902166b5..308ff9f1e 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -131,6 +131,7 @@ CPP_TEST_CASES += \ constructor_exception \ constructor_explicit \ constructor_ignore \ + constructor_rename \ constructor_value \ contract \ conversion \ diff --git a/Examples/test-suite/constructor_rename.i b/Examples/test-suite/constructor_rename.i new file mode 100644 index 000000000..401b07d65 --- /dev/null +++ b/Examples/test-suite/constructor_rename.i @@ -0,0 +1,12 @@ +%module constructor_rename + +%{ +struct Foo { + Foo() {} +}; +%} + +struct Foo { + %rename(RenamedConstructor) Foo(); + Foo() {} +}; diff --git a/Examples/test-suite/python/constructor_rename_runme.py b/Examples/test-suite/python/constructor_rename_runme.py new file mode 100644 index 000000000..cf3f88b81 --- /dev/null +++ b/Examples/test-suite/python/constructor_rename_runme.py @@ -0,0 +1,3 @@ +from constructor_rename import * + +x = RenamedConstructor() diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 3639efe86..93679084c 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3257,6 +3257,7 @@ public: String *classname = Swig_class_name(parent); String *rclassname = Swig_class_name(getCurrentClass()); assert(rclassname); + String *parms = make_pyParmList(n, true, false, allow_kwargs); /* Pass 'self' only if using director */ @@ -3300,8 +3301,8 @@ public: Printv(f_shadow_stubs, pycode, "\n", NIL); Delete(pycode); } else { - String *parms = make_pyParmList(n, true, false, allow_kwargs); - String *callParms = make_pyParmList(n, true, true, allow_kwargs); + String *parms = make_pyParmList(n, false, false, allow_kwargs); + String *callParms = make_pyParmList(n, false, true, allow_kwargs); Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); if (have_docstring(n)) From 89a8bd2abf0bc92a1102813aa7bc0b4f920766f5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 29 Apr 2010 19:46:14 +0000 Subject: [PATCH 075/203] Remove confusion about ignoring header include guards git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11998 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 9ad450425..e4a2a8c42 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1672,7 +1672,7 @@ directive as shown :

    // interface.i %rename(my_print) print; -extern void print(char *); +extern void print(const char *); %rename(foo) a_really_long_and_annoying_name; extern int a_really_long_and_annoying_name; @@ -1725,9 +1725,10 @@ to ignore declarations that match a given identifier. For example:
     %ignore print;         // Ignore all declarations named print
    -%ignore _HAVE_FOO_H;   // Ignore an include guard constant
    +%ignore MYMACRO;       // Ignore a macro
     ...
    -%include "foo.h"       // Grab a header file
    +#define MYMACRO 123
    +void print(const char *);
     ...
     
    @@ -1752,7 +1753,7 @@ For example:
    -%name(output) extern void print(char *);
    +%name(output) extern void print(const char *);
     
    From eef90444774d02fa0d3a10dc9713df4f8fc933c1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 1 May 2010 10:01:26 +0000 Subject: [PATCH 076/203] More string tests: char const*const git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12005 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/char_strings.i | 14 +++++++++++++- Examples/test-suite/csharp/char_strings_runme.cs | 10 ++++++++++ Examples/test-suite/java/char_strings_runme.java | 10 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/char_strings.i b/Examples/test-suite/char_strings.i index 26f3f22a5..cc59815b2 100644 --- a/Examples/test-suite/char_strings.i +++ b/Examples/test-suite/char_strings.i @@ -21,7 +21,7 @@ below. static char *global_str = NULL; const int UINT_DIGITS = 10; // max unsigned int is 4294967295 -bool check(const char *str, unsigned int number) { +bool check(const char *const str, unsigned int number) { static char expected[256]; sprintf(expected, "%s%d", OTHERLAND_MSG, number); bool matches = (strcmp(str, expected) == 0); @@ -105,6 +105,18 @@ bool SetConstCharArrayStaticString(const char str[], unsigned int number) { return check(static_str, number); } +bool SetCharConstStaticString(char *const str, unsigned int number) { + static char static_str[] = CPLUSPLUS_MSG; + strcpy(static_str, str); + return check(static_str, number); +} + +bool SetConstCharConstStaticString(const char *const str, unsigned int number) { + static char static_str[] = CPLUSPLUS_MSG; + strcpy(static_str, str); + return check(static_str, number); +} + // get set function char *CharPingPong(char *str) { return str; diff --git a/Examples/test-suite/csharp/char_strings_runme.cs b/Examples/test-suite/csharp/char_strings_runme.cs index 59bcc64df..414d32b7a 100644 --- a/Examples/test-suite/csharp/char_strings_runme.cs +++ b/Examples/test-suite/csharp/char_strings_runme.cs @@ -76,6 +76,16 @@ public class char_strings_runme { throw new Exception("Test char set 6 failed, iteration " + i); } + for (i=0; i Date: Sat, 1 May 2010 10:02:23 +0000 Subject: [PATCH 077/203] Remove incorrect documentation about %ref and %unref git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12006 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index e898fb359..aa50630be 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2124,8 +2124,8 @@ Object 'RCObj', which implements the ref/unref idiom.

    To tell SWIG that 'RCObj' and all its derived classes are reference -counted objects, you use the "ref" and "unref" features, or -%ref and %unref directives (since 1.3.28). For example: +counted objects, you use the "ref" and "unref" features. +For example:

    @@ -2143,25 +2143,6 @@ counted objects, you use the "ref" and "unref" features, or -or, using the directive form: - - -
    -
    -%module example
    -...
    -
    -%ref   RCObj "$this->ref();"
    -%unref RCObj "$this->unref();"
    -
    -%include "rcobj.h"
    -%include "A.h"
    -...
    -
    -
    - - -

    where the code passed to the "ref" and "unref" features will be executed as needed whenever a new object is passed to python, or when From efd200ffe2bc9b3f620e73c2b6cda51b1960a38a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 2 May 2010 21:35:02 +0000 Subject: [PATCH 078/203] Typemap matching rules enhancement for non-default typemaps. Previously all qualifiers were stripped in one step, now they are stripped one at a time starting with the left most qualifier. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12007 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 10 +- Doc/Manual/Contents.html | 1 + Doc/Manual/Typemaps.html | 181 +++++++++++++++++- Examples/test-suite/common.mk | 1 + .../python/typemap_qualifier_strip_runme.py | 54 ++++++ Examples/test-suite/typemap_qualifier_strip.i | 76 ++++++++ Source/Swig/stype.c | 4 +- Source/Swig/swig.h | 1 + Source/Swig/typemap.c | 49 +++-- Source/Swig/typeobj.c | 59 ++++++ 10 files changed, 398 insertions(+), 38 deletions(-) create mode 100644 Examples/test-suite/python/typemap_qualifier_strip_runme.py create mode 100644 Examples/test-suite/typemap_qualifier_strip.i diff --git a/CHANGES.current b/CHANGES.current index 0a707a918..287a97e8f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,14 @@ Version 2.0.0 (in progress) ============================ +2010-05-01: wsfulton + Typemap matching enhancement for non-default typemaps. Previously all + qualifiers were stripped in one step, now they are stripped one at a time + starting with the left most qualifier. For example, int const*const + is first stripped to int *const then int *. + + *** POTENTIAL INCOMPATIBILITY *** + 2010-04-25: bhy [Python] Fix #2985655 - broken constructor renaming. @@ -37,7 +45,7 @@ Version 2.0.0 (in progress) Numerous subtle typemap matching rule fixes when using the default type. The typemap matching rules are to take a type and find the best default typemap (SWIGTYPE, SWIGTYPE* etc), then look for the next best match by reducing the chosen default type. The type deduction - now follows C++ template partial specialization matching rules. + now follows C++ class template partial specialization matching rules. Below are the set of changes made showing the default type deduction along with the old reduced type and the new version of the reduced type: diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index a99fd1885..242b86429 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -351,6 +351,7 @@

  • Basic matching rules
  • Typedef reductions matching
  • Default typemap matching rules +
  • Matching comparison with C++ templates
  • Multi-arguments typemaps
  • Debugging typemap pattern matching diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 71c2c43ec..76cc770b2 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -33,6 +33,7 @@
  • Basic matching rules
  • Typedef reductions matching
  • Default typemap matching rules +
  • Matching comparison with C++ templates
  • Multi-arguments typemaps
  • Debugging typemap pattern matching @@ -1026,8 +1027,10 @@ is used.

    -If TYPE includes qualifiers (const, volatile, etc.), they are stripped to form a new stripped type +If TYPE includes qualifiers (const, volatile, etc.), each qualifier is stripped one at a time to form a new stripped type and the matching rules above are repeated on the stripped type. +The left-most qualifier is stripped first, resulting in the right-most (or top-level) qualifier being stripped last. +For example int const*const is first stripped to int *const then int *.

    @@ -1056,8 +1059,8 @@ To find a typemap for the argument const char *s, SWIG will search for

     const char *s           Exact type and name match
     const char *            Exact type match
    -char *s                 Type and name match (stripped qualifiers)
    -char *                  Type match (stripped qualifiers)
    +char *s                 Type and name match (qualifier stripped)
    +char *                  Type match (qualifier stripped)
     
    @@ -1097,6 +1100,11 @@ void F(int x[1000]); // int [ANY] rule (typemap 5) +

    +Compatibility note: SWIG-2.0.0 introduced stripping the qualifiers one step at a time. Prior versions +stripped all qualifiers in one step. +

    +

    10.3.2 Typedef reductions matching

    @@ -1280,7 +1288,7 @@ If the basic pattern matching rules result in no match being made, even after ty the default typemap matching rules are used to look for a suitable typemap match. These rules match a generic typemap based on the reserved SWIGTYPE base type. For example pointers will use SWIGTYPE * and references will use SWIGTYPE &. -More precisely, the rules are based on the C++ template partial specialization matching rules used +More precisely, the rules are based on the C++ class template partial specialization matching rules used by C++ compilers when looking for an appropriate partial template specialization. This means that a match is chosen from the most specialized set of generic typemap types available. For example, when looking for a match to int const *, the rules will prefer to match SWIGTYPE const * @@ -1407,11 +1415,10 @@ Finally the best way to view the typemap matching rules in action is via the Compatibility note: The default typemap matching rules were modified in SWIG-2.0.0 from a slightly -simpler scheme to match the current C++ template partial specialization matching rules. +simpler scheme to match the current C++ class template partial specialization matching rules.

    - -

    10.3.4 Multi-arguments typemaps

    +

    10.3.5 Multi-arguments typemaps

    @@ -1441,7 +1448,165 @@ but all subsequent arguments must match exactly.

    -

    10.3.5 Debugging typemap pattern matching

    +

    10.3.4 Matching rules compared to C++ templates

    + +

    +For those intimately familiar with C++ templates, a comparison of the typemap matching rules and template type deduction is interesting. +The two areas considered are firstly the default typemaps and their similarities to partial template specialization and secondly, non-default typemaps and their similarities to full template specialization. +

    + +

    +For default (SWIGTYPE) typemaps the rules are inspired by C++ class template +partial specialization. For example, given partial specialization for T const& : +

    + +
    +
    +template <typename T> struct X             { void a(); };
    +template <typename T> struct X< T const& > { void b(); };
    +
    +
    + +

    +The full (unspecialized) template is matched with most types, such as: +

    + +
    +
    +X< int & >            x1;  x1.a();
    +
    +
    + +

    +and the following all match the T const& partial specialization: +

    + +
    +
    +X< int *const& >      x2;  x2.b();
    +X< int const*const& > x3;  x3.b();
    +X< int const& >       x4;  x4.b();
    +
    +
    + +

    +Now, given just these two default typemaps, where T is analogous to SWIGTYPE: +

    + +
    +
    +%typemap(...) SWIGTYPE        { ... }
    +%typemap(...) SWIGTYPE const& { ... }
    +
    +
    + +

    +The generic default typemap SWIGTYPE is used with most types, such as +

    + +
    +
    +int &
    +
    +
    + +

    +and the following all match the SWIGTYPE const& typemap, just like the partial template matching: +

    + +
    +
    +int *const&
    +int const*const&
    +int const&
    +
    +
    + +

    +Note that the template and typemap matching rules are not identical for all default typemaps though, for example, with arrays. +

    + +

    +For non-default typemaps, one might expect SWIG to follow the fully specialized template rules. +This is nearly the case, but not quite. +Consider a very similar example to the earlier partially specialized template but this time there is a fully specialized template: +

    + +
    +
    +template <typename T> struct Y       { void a(); };
    +template <> struct Y< int const & >  { void b(); };
    +
    +
    + +

    +Only the one type matches the specialized template exactly: +

    + +
    +
    +Y< int & >             y1;  y1.a();
    +Y< int *const& >       y2;  y2.a();
    +Y< int const *const& > y3;  y3.a();
    +Y< int const& >        y4;  y4.b(); // fully specialized match
    +
    +
    + +

    +Given typemaps with the same types used for the template declared above, where T is again analogous to SWIGTYPE: +

    + +
    +
    +%typemap(...) SWIGTYPE        { ... }
    +%typemap(...) int const&      { ... }
    +
    +
    + +

    +The comparison between non-default typemaps and fully specialized single parameter templates turns out to be the same, as just the one type will match the non-default typemap: +

    + +
    +
    +int &
    +int *const&
    +int const*const&
    +int const&        // matches non-default typemap int const&
    +
    +
    + +

    +However, if a non-const type is used instead: +

    + +
    +
    +%typemap(...) SWIGTYPE        { ... }
    +%typemap(...) int &           { ... }
    +
    +
    + +

    +then there is a clear difference to template matching as both the const and non-const types match the typemap: +

    + +
    +
    +int &             // matches non-default typemap int &
    +int *const&
    +int const*const&
    +int const&        // matches non-default typemap int &
    +
    +
    + +

    +There are other subtle differences such as typedef handling, but at least it should be clear that the typemap matching rules +are similar to those for specialized template handling. +

    + + +

    10.3.6 Debugging typemap pattern matching

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 308ff9f1e..64dea58b7 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -393,6 +393,7 @@ CPP_TEST_CASES += \ typemap_numinputs \ typemap_template \ typemap_out_optimal \ + typemap_qualifier_strip \ typemap_variables \ typemap_various \ typename \ diff --git a/Examples/test-suite/python/typemap_qualifier_strip_runme.py b/Examples/test-suite/python/typemap_qualifier_strip_runme.py new file mode 100644 index 000000000..5e466cf69 --- /dev/null +++ b/Examples/test-suite/python/typemap_qualifier_strip_runme.py @@ -0,0 +1,54 @@ +import typemap_qualifier_strip + +val = typemap_qualifier_strip.create_int(111) +if typemap_qualifier_strip.testA1(val) != 1234: + raise RuntimeError + +if typemap_qualifier_strip.testA2(val) != 1234: + raise RuntimeError + +if typemap_qualifier_strip.testA3(val) != 1234: + raise RuntimeError + +if typemap_qualifier_strip.testA4(val) != 1234: + raise RuntimeError + + +if typemap_qualifier_strip.testB1(val) != 111: + raise RuntimeError + +if typemap_qualifier_strip.testB2(val) != 111: + raise RuntimeError + +if typemap_qualifier_strip.testB3(val) != 111: + raise RuntimeError + +if typemap_qualifier_strip.testB4(val) != 111: + raise RuntimeError + + +if typemap_qualifier_strip.testC1(val) != 5678: + raise RuntimeError + +if typemap_qualifier_strip.testC2(val) != 111: + raise RuntimeError + +if typemap_qualifier_strip.testC3(val) != 5678: + raise RuntimeError + +if typemap_qualifier_strip.testC4(val) != 111: + raise RuntimeError + + +if typemap_qualifier_strip.testD1(val) != 111: + raise RuntimeError + +if typemap_qualifier_strip.testD2(val) != 3456: + raise RuntimeError + +if typemap_qualifier_strip.testD3(val) != 111: + raise RuntimeError + +if typemap_qualifier_strip.testD4(val) != 111: + raise RuntimeError + diff --git a/Examples/test-suite/typemap_qualifier_strip.i b/Examples/test-suite/typemap_qualifier_strip.i new file mode 100644 index 000000000..d91a7b109 --- /dev/null +++ b/Examples/test-suite/typemap_qualifier_strip.i @@ -0,0 +1,76 @@ +%module typemap_qualifier_strip + +%typemap(in) int *ptr { + int temp = 1234; + $1 = &temp; +} + +%typemap(in) int *const ptrConst { + int temp = 5678; + $1 = &temp; +} + +%typemap(in) int const* constPtr { + int temp = 3456; + $1 = &temp; +} + +%inline %{ +int *create_int(int newval) { + static int val = 0; + val = newval; + return &val; +} +int testA1(int const*const ptr) { + return *ptr; +} +int testA2(int const* ptr) { + return *ptr; +} +int testA3(int *const ptr) { + return *ptr; +} +int testA4(int * ptr) { + return *ptr; +} + +int testB1(int const*const p) { + return *p; +} +int testB2(int const* p) { + return *p; +} +int testB3(int *const p) { + return *p; +} +int testB4(int * p) { + return *p; +} + +int testC1(int const*const ptrConst) { + return *ptrConst; +} +int testC2(int const* ptrConst) { + return *ptrConst; +} +int testC3(int *const ptrConst) { + return *ptrConst; +} +int testC4(int * ptrConst) { + return *ptrConst; +} + +int testD1(int const*const constPtr) { + return *constPtr; +} +int testD2(int const* constPtr) { + return *constPtr; +} +int testD3(int *const constPtr) { + return *constPtr; +} +int testD4(int * constPtr) { + return *constPtr; +} +%} + diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index 533b8195f..c984d639b 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -357,8 +357,8 @@ SwigType *SwigType_default_create(SwigType *ty) { * SwigType_default_deduce() * * This function implements type deduction used in the typemap matching rules - * and is very close to the type deduction used in partial template specialization - * matching in that the most specialized type is always chosen. + * and is very close to the type deduction used in partial template class + * specialization matching in that the most specialized type is always chosen. * SWIGTYPE is used as the generic type. The basic idea is to repeatedly call * this function to find a deduced type unless until nothing matches. * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 2b2c7f4cf..f90a5ffb1 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -159,6 +159,7 @@ extern "C" { extern int SwigType_isenum(SwigType *t); extern int SwigType_check_decl(SwigType *t, const_String_or_char_ptr decl); extern SwigType *SwigType_strip_qualifiers(SwigType *t); + extern SwigType *SwigType_strip_single_qualifier(SwigType *t); extern SwigType *SwigType_functionpointer_decompose(SwigType *t); extern String *SwigType_base(const SwigType *t); extern String *SwigType_namestr(const SwigType *t); diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 37f8c3d82..cbe881577 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -698,11 +698,11 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type Hash *backup = 0; SwigType *primitive = 0; SwigType *ctype = 0; + SwigType *ctype_unstripped = 0; int ts; int isarray; const String *cname = 0; const String *cqualifiedname = 0; - SwigType *unstripped = 0; String *tm_method = typemap_method_name(tmap_method); int debug_display = (in_typemap_search_multi == 0) && typemap_search_debug; @@ -718,7 +718,8 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type Delete(typestr); } while (ts >= 0) { - ctype = type; + ctype = Copy(type); + ctype_unstripped = Copy(ctype); while (ctype) { /* Try to get an exact type-match */ tm = get_typemap(ts, ctype); @@ -751,29 +752,25 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type goto ret_result; } - /* No match so far. If the type is unstripped, we'll strip its - qualifiers and check. Otherwise, we'll try to resolve a typedef */ - - if (!unstripped) { - unstripped = ctype; - ctype = SwigType_strip_qualifiers(ctype); - if (!Equal(ctype, unstripped)) - continue; /* Types are different */ - Delete(ctype); - ctype = unstripped; - unstripped = 0; - } + /* No match so far - try with a qualifier stripped (strip one qualifier at a time until none remain) + * The order of stripping in SwigType_strip_single_qualifier is used to provide some sort of consistency + * with the default (SWIGTYPE) typemap matching rules for the first qualifier to be stripped. */ { - String *octype; - if (unstripped) { - Delete(ctype); - ctype = unstripped; - unstripped = 0; + SwigType *oldctype = ctype; + ctype = SwigType_strip_single_qualifier(oldctype); + if (!Equal(ctype, oldctype)) { + Delete(oldctype); + continue; } - octype = ctype; - ctype = SwigType_typedef_resolve(ctype); - if (octype != type) - Delete(octype); + Delete(oldctype); + } + + /* Once all qualifiers are stripped try resolve a typedef */ + { + SwigType *oldctype = ctype; + ctype = SwigType_typedef_resolve(ctype_unstripped); + Delete(oldctype); + ctype_unstripped = Copy(ctype); } } @@ -802,12 +799,10 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type ret_result: Delete(primitive); - if ((unstripped) && (unstripped != type)) - Delete(unstripped); if (matchtype) *matchtype = Copy(ctype); - if (type != ctype) - Delete(ctype); + Delete(ctype); + Delete(ctype_unstripped); return result; } diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index a2e23e52d..074bbf904 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -1125,3 +1125,62 @@ SwigType *SwigType_strip_qualifiers(SwigType *t) { } return r; } + +/* ----------------------------------------------------------------------------- + * SwigType_strip_single_qualifier() + * + * If the type contains a qualifier, strip one qualifier and return a new type. + * The left most qualifier is stripped first (when viewed as C source code) but + * this is the equivalent to the right most qualifier using SwigType notation. + * Example: + * r.q(const).p.q(const).int => r.q(const).p.int + * r.q(const).p.int => r.p.int + * r.p.int => r.p.int + * ----------------------------------------------------------------------------- */ + +SwigType *SwigType_strip_single_qualifier(SwigType *t) { + static Hash *memoize_stripped = 0; + SwigType *r = 0; + List *l; + int numitems; + + if (!memoize_stripped) + memoize_stripped = NewHash(); + r = Getattr(memoize_stripped, t); + if (r) + return Copy(r); + + l = SwigType_split(t); + + numitems = Len(l); + if (numitems >= 2) { + int item; + /* iterate backwards from last but one item */ + for (item = numitems - 2; item >= 0; --item) { + String *subtype = Getitem(l, item); + if (SwigType_isqualifier(subtype)) { + Iterator it; + Delitem(l, item); + r = NewStringEmpty(); + for (it = First(l); it.item; it = Next(it)) { + Append(r, it.item); + } + break; + } + } + } + if (!r) + r = Copy(t); + + Delete(l); + { + String *key, *value; + key = Copy(t); + value = Copy(r); + Setattr(memoize_stripped, key, value); + Delete(key); + Delete(value); + } + return r; +} + From 03bd7005bbbb6190280877b61a1f209b2c67bb22 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 3 May 2010 22:58:27 +0000 Subject: [PATCH 079/203] Fix typemap delete regression introduced in rev 11838 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12008 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + .../test-suite/python/typemap_delete_runme.py | 5 +++++ Examples/test-suite/typemap_delete.i | 16 ++++++++++++++++ Source/Swig/typemap.c | 8 ++++---- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 Examples/test-suite/python/typemap_delete_runme.py create mode 100644 Examples/test-suite/typemap_delete.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 64dea58b7..831b1b78f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -387,6 +387,7 @@ CPP_TEST_CASES += \ typedef_scope \ typedef_sizet \ typedef_struct \ + typemap_delete \ typemap_global_scope \ typemap_namespace \ typemap_ns_using \ diff --git a/Examples/test-suite/python/typemap_delete_runme.py b/Examples/test-suite/python/typemap_delete_runme.py new file mode 100644 index 000000000..582a2167c --- /dev/null +++ b/Examples/test-suite/python/typemap_delete_runme.py @@ -0,0 +1,5 @@ +import typemap_delete + +r = typemap_delete.Rect(123) +if r.val != 123: + raise RuntimeError diff --git a/Examples/test-suite/typemap_delete.i b/Examples/test-suite/typemap_delete.i new file mode 100644 index 000000000..eb6abe73c --- /dev/null +++ b/Examples/test-suite/typemap_delete.i @@ -0,0 +1,16 @@ +%module typemap_delete + +%typemap(in) Rect* (Rect temp) { + $1 = 0; + will_not_compile +} + +%typemap(in) Rect*; + +%inline %{ +struct Rect +{ + int val; + Rect(int v) : val(v) {} +}; +%} diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index cbe881577..2bf806e66 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -724,7 +724,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type /* Try to get an exact type-match */ tm = get_typemap(ts, ctype); result = typemap_search_helper(debug_display, tm, tm_method, ctype, cqualifiedname, cname, &backup); - if (result) + if (result && Getattr(result, "code")) goto ret_result; { @@ -734,7 +734,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type tm = get_typemap(ts, template_prefix); result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup); Delete(template_prefix); - if (result) + if (result && Getattr(result, "code")) goto ret_result; } } @@ -748,7 +748,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type tm = get_typemap(ts, noarrays); result = typemap_search_helper(debug_display, tm, tm_method, noarrays, cqualifiedname, cname, &backup); Delete(noarrays); - if (result) + if (result && Getattr(result, "code")) goto ret_result; } @@ -780,7 +780,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type while (primitive) { tm = get_typemap(ts, primitive); result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup); - if (result) + if (result && Getattr(result, "code")) goto ret_result; { From f76fcb4eb4490cb244a31f17697f05b2f7f30676 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 5 May 2010 05:01:22 +0000 Subject: [PATCH 080/203] Memory leak fix handling const std::string & inputs, reported by Will Nolan. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12009 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/r/rfragments.swg | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 287a97e8f..7c57b7040 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +2010-05-05: wsfulton + [R] Memory leak fix handling const std::string & inputs, reported by Will Nolan. + 2010-05-01: wsfulton Typemap matching enhancement for non-default typemaps. Previously all qualifiers were stripped in one step, now they are stripped one at a time diff --git a/Lib/r/rfragments.swg b/Lib/r/rfragments.swg index f6191dfeb..7c8da2a5f 100644 --- a/Lib/r/rfragments.swg +++ b/Lib/r/rfragments.swg @@ -122,7 +122,7 @@ SWIGINTERN int SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc) { if (cptr && Rf_isString(obj)) { - const char *cstr = CHAR(STRING_ELT(obj, 0)); + char *cstr = %const_cast(CHAR(STRING_ELT(obj, 0)), char *); int len = strlen(cstr); if (alloc) { @@ -130,9 +130,7 @@ SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc) *cptr = %new_copy_array(cstr, len + 1, char); *alloc = SWIG_NEWOBJ; } else { - *cptr = %reinterpret_cast(malloc(len + 1), char *); - *cptr = strcpy(*cptr, cstr); - *alloc = SWIG_OLDOBJ; + *cptr = cstr; } } else { *cptr = %reinterpret_cast(malloc(len + 1), char *); From 5ff1e34ee66707e84f71926f403b23c60d43c68a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 May 2010 18:13:15 +0000 Subject: [PATCH 081/203] fix my perl keyword warning git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12012 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/enums.i | 4 ++-- Examples/test-suite/octave/enums_runme.m | 2 +- Examples/test-suite/python/enums_runme.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/enums.i b/Examples/test-suite/enums.i index 40be28e94..5632b5e97 100644 --- a/Examples/test-suite/enums.i +++ b/Examples/test-suite/enums.i @@ -90,8 +90,8 @@ enum Exclamation { enum ContainYourself { slap = 10, - my, + mine, thigh -} Slap = slap, My = my, Thigh = thigh, *pThigh = &Thigh, arrayContainYourself[3] = {slap, my, thigh}; +} Slap = slap, Mine = mine, Thigh = thigh, *pThigh = &Thigh, arrayContainYourself[3] = {slap, mine, thigh}; %} diff --git a/Examples/test-suite/octave/enums_runme.m b/Examples/test-suite/octave/enums_runme.m index 789f7c9e4..b654d9d04 100644 --- a/Examples/test-suite/octave/enums_runme.m +++ b/Examples/test-suite/octave/enums_runme.m @@ -13,7 +13,7 @@ if (enums.cvar.Slap != 10) error endif -if (enums.cvar.My != 11) +if (enums.cvar.Mine != 11) error endif diff --git a/Examples/test-suite/python/enums_runme.py b/Examples/test-suite/python/enums_runme.py index e8dbe6942..8d491baf4 100644 --- a/Examples/test-suite/python/enums_runme.py +++ b/Examples/test-suite/python/enums_runme.py @@ -11,7 +11,7 @@ if _enums.cvar.enumInstance != 2: if _enums.cvar.Slap != 10: raise RuntimeError -if _enums.cvar.My != 11: +if _enums.cvar.Mine != 11: raise RuntimeError if _enums.cvar.Thigh != 12: From 68308583b7d9e86a215e06c18eb09fa942f45ec0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 May 2010 19:10:41 +0000 Subject: [PATCH 082/203] Apply patch #2955146 from Sergey Satskiy to fix expressions containing divide by operator in constructor initialization lists. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12013 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/common.mk | 1 + Examples/test-suite/expressions.i | 10 ++++++++++ Source/Swig/scanner.c | 4 ++++ 4 files changed, 19 insertions(+) create mode 100644 Examples/test-suite/expressions.i diff --git a/CHANGES.current b/CHANGES.current index 7c57b7040..a9d580153 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 2.0.0 (in progress) ============================ +2010-05-07: wsfulton + Apply patch #2955146 from Sergey Satskiy to fix expressions containing divide by + operator in constructor initialization lists. + 2010-05-05: wsfulton [R] Memory leak fix handling const std::string & inputs, reported by Will Nolan. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 831b1b78f..1701dd8ba 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -193,6 +193,7 @@ CPP_TEST_CASES += \ extern_c \ extern_namespace \ extern_throws \ + expressions \ features \ fragments \ friends \ diff --git a/Examples/test-suite/expressions.i b/Examples/test-suite/expressions.i new file mode 100644 index 000000000..7b907ec3b --- /dev/null +++ b/Examples/test-suite/expressions.i @@ -0,0 +1,10 @@ +%module expressions + +%inline %{ +struct A +{ + A() : k( 20/(5-1) ) {} + A(int i) : k( 20/(5-1)*i /* comment */ ) {} + int k; +}; +%} diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index db7f0a06e..7f6e3e149 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -1182,6 +1182,10 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { state = 11; else if (c == '*') state = 12; + else if (c == startchar) { + state = 0; + num_levels++;; + } else state = 0; break; From 3d5d3a5bdbe2f7bda9a77dead6d729d83a618b8c Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 9 May 2010 15:39:31 +0000 Subject: [PATCH 083/203] change call for R to use mkCharLen where it exists (R versions >= 2.7.0). This is necessary because later versions of R (>= 2.8.0) depreciate creation of strings through vectors because this does not allow R to use character caches git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12014 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/r/rfragments.swg | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/r/rfragments.swg b/Lib/r/rfragments.swg index 7c8da2a5f..8a0d85580 100644 --- a/Lib/r/rfragments.swg +++ b/Lib/r/rfragments.swg @@ -162,9 +162,20 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size) { SEXP t, c; if (!carray) return R_NilValue; +/* See R internals document 1.10. + MkCharLen was introduced in 2.7.0. Use that instead of hand + creating vector. + + Starting in 2.8.0 creating strings via vectors was deprecated in + order to allow for use of CHARSXP caches. */ + Rf_protect(t = Rf_allocVector(STRSXP, 1)); +#if R_VERSION >= R_Version(2,7,0) + c = Rf_mkCharLen(carray, size); +#else c = Rf_allocVector(CHARSXP, size); strncpy((char *)CHAR(c), carray, size); +#endif SET_STRING_ELT(t, 0, c); Rf_unprotect(1); return t; From 948748f8e8d9a15d400f5f4c39b3ed148b5b7709 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 9 May 2010 15:41:24 +0000 Subject: [PATCH 084/203] update with r mkcharexp change git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12015 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index a9d580153..8ad55f8a7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 2.0.0 (in progress) ============================ +2010-05-09: drjoe + Fix bug reported by Wil Nolan change creation of string so + that R 2.7.0+ can use char hashes + 2010-05-07: wsfulton Apply patch #2955146 from Sergey Satskiy to fix expressions containing divide by operator in constructor initialization lists. From 02b31416f6a7ea62a5959b391f17d78ada1590b1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 May 2010 17:58:06 +0000 Subject: [PATCH 085/203] Some octave SWIG test-suite warning fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12017 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/operator_overload.i | 2 ++ Lib/octave/std_basic_string.i | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Examples/test-suite/operator_overload.i b/Examples/test-suite/operator_overload.i index b62bf5179..80facff76 100644 --- a/Examples/test-suite/operator_overload.i +++ b/Examples/test-suite/operator_overload.i @@ -45,6 +45,8 @@ see bottom for a set of possible tests %rename(MinusMinusPostfix) operator--(int); #endif +%rename(IndexInto) *::operator[](unsigned idx); // some languages have a %rename *::operator[] already in place, which seems to takes precedence over the above %rename operator[]. + #ifdef SWIGCSHARP %csmethodmodifiers operator++() "protected"; %csmethodmodifiers operator++(int) "private"; diff --git a/Lib/octave/std_basic_string.i b/Lib/octave/std_basic_string.i index 9fc0b0730..19712e8d0 100644 --- a/Lib/octave/std_basic_string.i +++ b/Lib/octave/std_basic_string.i @@ -32,6 +32,8 @@ SWIGINTERNINLINE octave_value } } +%ignore std::basic_string::operator +=; + %include %typemaps_asptrfromn(%checkcode(STRING), std::basic_string); From 64641c97504d71db5c3f5c29a3ccaa6539bab75a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 May 2010 18:21:34 +0000 Subject: [PATCH 086/203] Fix compile errors in Octave std::map wrappers. Remove li_std_map_runme.oct which looks like Python code git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12018 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/octave/li_std_map_runme.m | 61 ------------------- Lib/octave/std_map.i | 8 +-- 2 files changed, 4 insertions(+), 65 deletions(-) delete mode 100644 Examples/test-suite/octave/li_std_map_runme.m diff --git a/Examples/test-suite/octave/li_std_map_runme.m b/Examples/test-suite/octave/li_std_map_runme.m deleted file mode 100644 index f37c78012..000000000 --- a/Examples/test-suite/octave/li_std_map_runme.m +++ /dev/null @@ -1,61 +0,0 @@ -li_std_map - -a1 = li_std_map.A(3); -a2 = li_std_map.A(7); - - -p0 = li_std_map.pairii(1,2); -p1 = li_std_map.pairA(1,a1.this); -m = {}; -m{1} = a1; -m{2} = a2; - -pp1 = li_std_map.p_identa(p1); -mm = li_std_map.m_identa(m); - - - -m = li_std_map.mapA(); -m{1} = a1; -m{2} = a2; - - -pm ={}; -for k in m, - pm{k} = m{k}; -endfor - -for k in m, - if (swig_this(pm{k}) != swig_this(m{k})) - error - endif -endfor - - - -m = {}; -m{1} = [1,2]; -m["foo"] = "hello"; - -pm = li_std_map.pymap(); - -for k in m, - pm{k} = m{k}; -endfor - -for k in pm, - if (pm{k} != m{k}) - error - endif -endfor - -mii = li_std_map.IntIntMap(); - -mii{1} = 1; -mii{1} = 2; - -if (mii[1] != 2) - error -endif - - diff --git a/Lib/octave/std_map.i b/Lib/octave/std_map.i index 20003df58..6c476ce53 100644 --- a/Lib/octave/std_map.i +++ b/Lib/octave/std_map.i @@ -92,10 +92,10 @@ }; template - struct OctMapIterator_T : SwigPyIteratorClosed_T + struct OctMapIterator_T : OctSwigIteratorClosed_T { OctMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, octave_value seq) - : SwigPyIteratorClosed_T(curr, first, last, seq) + : OctSwigIteratorClosed_T(curr, first, last, seq) { } }; @@ -112,7 +112,7 @@ }; template - inline SwigPyIterator* + inline OctSwigIterator* make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, octave_value seq = octave_value()) { return new OctMapKeyIterator_T(current, begin, end, seq); @@ -130,7 +130,7 @@ template - inline SwigPyIterator* + inline OctSwigIterator* make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, octave_value seq = 0) { return new OctMapValueIterator_T(current, begin, end, seq); From e854baabec278d2235f4cef3cee69ae113ab0c64 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 11 May 2010 22:48:56 +0000 Subject: [PATCH 087/203] Change Octave to run C tests in SWIG C mode, not C++ mode git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12021 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 2 +- Examples/test-suite/octave/Makefile.in | 3 ++- Examples/test-suite/octave/octave_empty.c | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/octave/octave_empty.c diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 7f11884ee..cb8b7f4d4 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -346,7 +346,7 @@ OCTAVE_SO = @OCTAVE_SO@ octave: $(SRCS) $(SWIG) -octave $(SWIGOPT) $(INTERFACEPATH) $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(INCLUDES) -I$(OCTAVE_INCLUDE) - $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(INCLUDES) + $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CSRCS) $(INCLUDES) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO) # ----------------------------------------------------------------- diff --git a/Examples/test-suite/octave/Makefile.in b/Examples/test-suite/octave/Makefile.in index a9a7649ec..0dbb6a1e5 100644 --- a/Examples/test-suite/octave/Makefile.in +++ b/Examples/test-suite/octave/Makefile.in @@ -32,6 +32,7 @@ include $(srcdir)/../common.mk # Overridden variables here LIBS = -L. +CSRCS = octave_empty.c # Custom tests - tests with additional commandline options # none! @@ -44,7 +45,7 @@ LIBS = -L. %.ctest: $(setup) - +$(swig_and_compile_cpp) + +$(swig_and_compile_c) $(run_testcase) %.multicpptest: diff --git a/Examples/test-suite/octave/octave_empty.c b/Examples/test-suite/octave/octave_empty.c new file mode 100644 index 000000000..9bb690bbd --- /dev/null +++ b/Examples/test-suite/octave/octave_empty.c @@ -0,0 +1 @@ +/* empty C file for the Octave test-suite C tests is needed - build system workaround as the generated files for Octave are C++ files */ From 3cf41050b56fcf5f3bea0d4368825e93e2111604 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 11 May 2010 22:53:33 +0000 Subject: [PATCH 088/203] Fix Octave C enums wrapping when the generated code is C++ compiled git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12022 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Octave.html | 20 ++++++++++++++------ Source/Modules/octave.cxx | 3 ++- Source/Modules/typepass.cxx | 6 +++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 7409d78f1..63663a474 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -58,17 +58,18 @@ Also, there are a dozen or so examples in the Examples/octave directory, and hun

    -The current SWIG implemention is based on Octave 2.9.12. Support for other versions (in particular the recent 3.0) has not been tested, nor has support for any OS other than Linux. +The SWIG implemention was first based on Octave 2.9.12, so this is the minimum version required. Testing has only been done on Linux.

    27.2 Running SWIG

    -Let's start with a very simple SWIG interface file: +Let's start with a very simple SWIG interface file, example.i:

    -
    %module example
    +
    +%module example
     %{
     #include "example.h"
     %}
    @@ -76,13 +77,20 @@ int gcd(int x, int y);
     extern double Foo; 

    -To build an Octave module, run SWIG using the -octave option. The -c++ option is required (for now) as Octave itself is written in C++ and thus the wrapper code must also be. +To build an Octave module when wrapping C code, run SWIG using the -octave option:

    +
    $ swig -octave example.i 
    + +

    +The -c++ option is also required when wrapping C++ code: +

    + +
    $ swig -octave -c++ example.i 

    -This creates a C/C++ source file 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 (in this case, the gcd implementation) to create an extension module. +This creates a C++ source file example_wrap.cxx. A C++ file is generated even when wrapping C code as Octave is itself written in C++ and requires wrapper code to be in the same language. The generated C++ source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application (in this case, the gcd implementation) to create an extension module.

    @@ -811,7 +819,7 @@ In the case where one wishes for the C++ side to own an object that was created

    -This is some skeleton support for various STL containers. +Various STL library files are provided for wrapping STL containers.

    27.3.17 Matrix typemaps

    diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 16adddcce..db9592ad6 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -760,6 +760,7 @@ public: SwigType *type = Getattr(n, "type"); String *rawval = Getattr(n, "rawval"); String *value = rawval ? rawval : Getattr(n, "value"); + String *cppvalue = Getattr(n, "cppvalue"); String *tm; if (!addSymbol(iname, n)) @@ -775,7 +776,7 @@ public: if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { Replaceall(tm, "$source", value); Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); + Replaceall(tm, "$value", cppvalue ? cppvalue : value); Replaceall(tm, "$nsname", iname); Printf(f_init, "%s\n", tm); } else { diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index a975e350c..e63b58a10 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -807,11 +807,15 @@ class TypePass:private Dispatcher { value = name; if (Strcmp(value, name) == 0) { String *new_value; - if (((nsname) || (inclass)) && cparse_cplusplus) { + if ((nsname || inclass) && cparse_cplusplus) { new_value = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value); } else { new_value = NewString(value); } + if ((nsname || inclass) && !cparse_cplusplus) { + String *cppvalue = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value); + Setattr(n, "cppvalue", cppvalue); /* for target languages that always generate C++ code even when wrapping C code */ + } Setattr(n, "value", new_value); Delete(new_value); } From 70c557e8e3bb09f221f2624b2146f812c45c1bf5 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Wed, 12 May 2010 04:12:42 +0000 Subject: [PATCH 089/203] add R garbage collection and newfree git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12023 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Source/Modules/r.cxx | 24 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 8ad55f8a7..5e1544160 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 2.0.0 (in progress) ============================ +2010-05-12: drjoe + [R] Add two more changes from Wil Nolan. Get garbage + collection to work. Implement newfree + 2010-05-09: drjoe Fix bug reported by Wil Nolan change creation of string so that R 2.7.0+ can use char hashes diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 5ae2397b2..e4b246c4e 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1673,7 +1673,7 @@ int R::functionWrapper(Node *n) { } p = nextSibling(p); } - + String *unresolved_return_type = Copy(type); if (expandTypedef(type) && @@ -1731,7 +1731,7 @@ int R::functionWrapper(Node *n) { Wrapper *f = NewWrapper(); Wrapper *sfun = NewWrapper(); - + int isVoidReturnType = (Strcmp(type, "void") == 0); // Need to use the unresolved return type since // typedef resolution removes the const which causes a @@ -2036,7 +2036,13 @@ int R::functionWrapper(Node *n) { Printv(f->code, cleanup, NIL); Delete(cleanup); - + /* Look to see if there is any newfree cleanup code */ + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); /* deprecated */ + Printf(f->code, "%s\n", tm); + } + } Printv(f->code, UnProtectWrapupCode, NIL); @@ -2053,7 +2059,17 @@ int R::functionWrapper(Node *n) { Printv(sfun->code, ";", (Len(tm) ? "ans = " : ""), ".Call('", wname, "', ", sargs, "PACKAGE='", Rpackage, "');\n", NIL); if(Len(tm)) - Printf(sfun->code, "%s\n\nans;\n", tm); + { + Printf(sfun->code, "%s\n\n", tm); + if (constructor) + { + String *finalizer = NewString(iname); + Replace(finalizer, "new_", "", DOH_REPLACE_FIRST); + Printf(sfun->code, "reg.finalizer(ans, delete_%s)\n", finalizer); + } + Printf(sfun->code, "ans\n"); + } + if (destructor) Printv(f->code, "R_ClearExternalPtr(self);\n", NIL); From 108f826a76c7a1b1dbd63c66c6c0b5238d81933a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 12 May 2010 23:56:38 +0000 Subject: [PATCH 090/203] Fix typo in example in comment. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12024 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/typesys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 8d35c9746..f8cec14c9 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -79,7 +79,7 @@ char cvsroot_typesys_c[] = "$Id$"; * * class Bar : public Foo { * void blah(Integer x); - * } + * }; * * The argument type of Bar::blah will be set to Foo::Integer. * From 6a9a167e8e619d04b260c1c7152ca77e9e980fd1 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 May 2010 04:10:19 +0000 Subject: [PATCH 091/203] Fix typo in comment. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12025 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/typesys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index f8cec14c9..2436e005c 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1773,7 +1773,7 @@ void SwigType_inherit_equiv(File *out) { continue; } - /* This type has subclasses. We now need to walk through these subtypes and generate pointer converion functions */ + /* This type has subclasses. We now need to walk through these subtypes and generate pointer conversion functions */ rh = Getattr(r_resolved, rk.key); rlist = NewList(); From 1f4abe162d952e35e663eaf52c5ea2ee583e150b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 May 2010 06:14:18 +0000 Subject: [PATCH 092/203] clarification on SWIG_VERSION coding git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12026 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Preprocessor.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html index d7917c41a..8d41efccf 100644 --- a/Doc/Manual/Preprocessor.html +++ b/Doc/Manual/Preprocessor.html @@ -102,7 +102,7 @@ by SWIG when it is parsing the interface:
     SWIG                            Always defined when SWIG is processing a file
     SWIGIMPORTED                    Defined when SWIG is importing a file with %import
    -SWIG_VERSION                    Hexadecimal number containing SWIG version,
    +SWIG_VERSION                    Hexadecimal (binary-coded decimal) number containing SWIG version,
                                     such as 0x010311 (corresponding to SWIG-1.3.11).
     
     SWIGALLEGROCL                   Defined when using Allegro CL
    
    From 227f2e2e0aa07b750ae976c3dda35fb442769a8a Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Fri, 14 May 2010 08:22:28 +0000
    Subject: [PATCH 093/203] [PHP] Fix wrapping of global variables which was
     producing uncompilable code in some cases.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12027 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current        | 4 ++++
     Source/Modules/php.cxx | 2 --
     2 files changed, 4 insertions(+), 2 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 5e1544160..28b80ad54 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -1,6 +1,10 @@
     Version 2.0.0 (in progress)
     ============================
     
    +2010-05-14: olly
    +	    [PHP] Fix wrapping of global variables which was producing
    +	    uncompilable code in some cases.
    +
     2010-05-12: drjoe
     	    [R] Add two more changes from Wil Nolan.  Get garbage
     	    collection to work.  Implement newfree
    diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
    index 09eb21dcd..700358ee4 100644
    --- a/Source/Modules/php.cxx
    +++ b/Source/Modules/php.cxx
    @@ -1779,8 +1779,6 @@ done:
         if (!addSymbol(iname, n))
           return SWIG_ERROR;
     
    -    SwigType_remember(t);
    -
         /* First link C variables to PHP */
     
         tm = Swig_typemap_lookup("varinit", n, name, 0);
    
    From 8a169eb0cb80b85d656f728b6659c6937dca9148 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 14 May 2010 18:46:20 +0000
    Subject: [PATCH 094/203] Fix wrapping of C++ enum boolean values
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12028 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current                |  4 ++++
     Examples/test-suite/cpp_enum.i | 13 ++++++++++++-
     Source/CParse/parser.y         |  6 +++---
     Source/Modules/csharp.cxx      |  7 +++++++
     4 files changed, 26 insertions(+), 4 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 28b80ad54..2cc874bb1 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -1,6 +1,10 @@
     Version 2.0.0 (in progress)
     ============================
     
    +2010-05-14: wsfulton
    +            Fix wrapping of C++ enum boolean values reported by Torsten Landschoff:
    +              typedef enum { PLAY = true, STOP = false } play_state;
    +
     2010-05-14: olly
     	    [PHP] Fix wrapping of global variables which was producing
     	    uncompilable code in some cases.
    diff --git a/Examples/test-suite/cpp_enum.i b/Examples/test-suite/cpp_enum.i
    index e6eef6d0c..cb212615a 100644
    --- a/Examples/test-suite/cpp_enum.i
    +++ b/Examples/test-suite/cpp_enum.i
    @@ -24,7 +24,6 @@ struct StructWithEnums {
         enum SOME_ENUM& enum_test8() { return some_enum; };
     };
     
    -
      struct Foo
      {   
        enum {Hi, Hello } hola;
    @@ -41,3 +40,15 @@ extern "C"
     }
     
     %}
    +
    +// Using true and false in enums is legal in C++. Quoting the standard:
    +// [dcl.enum]
    +//     ... The constant-expression shall be of integral or enumeration type.
    +// [basic.fundamental]
    +//     ... Types bool, char, wchar_t, and the signed and unsigned integer
    +//     types are collectively called integral types.
    +// So this shouldn't lead to a warning, at least in C++ mode.
    +%inline %{
    +typedef enum { PLAY = true, STOP = false } play_state;
    +%}
    +
    diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
    index 1990a66c6..6e41fa565 100644
    --- a/Source/CParse/parser.y
    +++ b/Source/CParse/parser.y
    @@ -5601,7 +5601,7 @@ edecl          :  ID {
     		     Setattr($$,"type",type);
     		     Delete(type);
     		   } else {
    -		     SwigType *type = NewSwigType(T_INT);
    +		     SwigType *type = NewSwigType($3.type == T_BOOL ? T_BOOL : T_INT);
     		     Setattr($$,"value",$1);
     		     Setattr($$,"type",type);
     		     Delete(type);
    @@ -5617,8 +5617,8 @@ etype            : expr {
     		       ($$.type != T_LONG) && ($$.type != T_ULONG) &&
     		       ($$.type != T_SHORT) && ($$.type != T_USHORT) &&
     		       ($$.type != T_SCHAR) && ($$.type != T_UCHAR) &&
    -		       ($$.type != T_CHAR)) {
    -		     Swig_error(cparse_file,cparse_line,"Type error. Expecting an int\n");
    +		       ($$.type != T_CHAR) && ($$.type != T_BOOL)) {
    +		     Swig_error(cparse_file,cparse_line,"Type error. Expecting an integral type\n");
     		   }
     		   if ($$.type == T_CHAR) $$.type = T_INT;
                     }
    diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
    index f70403326..3dd51aabf 100644
    --- a/Source/Modules/csharp.cxx
    +++ b/Source/Modules/csharp.cxx
    @@ -1282,6 +1282,13 @@ public:
         // Note that this is used in enumValue() amongst other places
         Setattr(n, "value", tmpValue);
     
    +    // Deal with enum values that are bools
    +    if (SwigType_type(Getattr(n, "type")) == T_BOOL) {
    +      String *boolValue = NewStringf("%s ? 1 : 0", Getattr(n, "enumvalue"));
    +      Setattr(n, "enumvalue", boolValue);
    +      Delete(boolValue);
    +    }
    +
         {
           EnumFeature enum_feature = decodeEnumFeature(parent);
     
    
    From 76bbd7373d469149b8cfa091c32cf35d34861da3 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 14 May 2010 19:03:01 +0000
    Subject: [PATCH 095/203] Fix wrapping of C++ enum boolean values when using
     %javaconst(1)
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12029 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/java_enums.i | 6 ++++++
     Source/Modules/java.cxx          | 7 +++++++
     2 files changed, 13 insertions(+)
    
    diff --git a/Examples/test-suite/java_enums.i b/Examples/test-suite/java_enums.i
    index 4d2fe92c8..855913d06 100644
    --- a/Examples/test-suite/java_enums.i
    +++ b/Examples/test-suite/java_enums.i
    @@ -58,3 +58,9 @@ static const int FOUR = 4;
     %inline %{
     enum Numero { Quattro = FOUR };
     %}
    +
    +// Test boolean enums
    +%inline %{
    +typedef enum { PLAY = true, STOP = false } play_state;
    +%}
    +
    diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx
    index 5fecf8208..234af4c8e 100644
    --- a/Source/Modules/java.cxx
    +++ b/Source/Modules/java.cxx
    @@ -1352,6 +1352,13 @@ public:
         // Note that this is used in enumValue() amongst other places
         Setattr(n, "value", tmpValue);
     
    +    // Deal with enum values that are bools
    +    if (SwigType_type(Getattr(n, "type")) == T_BOOL) {
    +      String *boolValue = NewStringf("%s ? 1 : 0", Getattr(n, "enumvalue"));
    +      Setattr(n, "enumvalue", boolValue);
    +      Delete(boolValue);
    +    }
    +
         {
           EnumFeature enum_feature = decodeEnumFeature(parent);
     
    
    From d324633cfa25dfdcb66290c4bba2315adc07da5e Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 14 May 2010 19:47:39 +0000
    Subject: [PATCH 096/203] Fix php limited precision test fix when dealing with
     large long long numbers
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12030 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Examples/test-suite/php/primitive_ref_runme.php | 15 ++++++++++++---
     1 file changed, 12 insertions(+), 3 deletions(-)
    
    diff --git a/Examples/test-suite/php/primitive_ref_runme.php b/Examples/test-suite/php/primitive_ref_runme.php
    index ab23fb1cc..263a28074 100644
    --- a/Examples/test-suite/php/primitive_ref_runme.php
    +++ b/Examples/test-suite/php/primitive_ref_runme.php
    @@ -3,6 +3,16 @@
     require "tests.php";
     require "primitive_ref.php";
     
    +# A large long long number is too big, so PHP makes treats it as a double, but SWIG opts to return it as a string.
    +# The conversion to double can lose precision so this isn't an exact comparison.
    +function long_long_equal($a,$b,$message) {
    +  if (! ($a===$b))
    +    if (! ((double)$a===$b))
    +      return check::fail($message . ": '$a'!=='$b'");
    +  return TRUE;
    +}
    +
    +
     check::equal(ref_over(3), 3, "ref_over failed");
     
     check::equal(ref_int(3), 3, "ref_int failed");
    @@ -17,9 +27,8 @@ check::equal(ref_bool(true), true, "ref_bool failed");
     check::equal(ref_float(3.5), 3.5, "ref_float failed");
     check::equal(ref_double(3.5), 3.5, "ref_double failed");
     check::equal(ref_char('x'), 'x', "ref_char failed");
    -check::equal(ref_longlong(0x123456789ABCDEF0), 0x123456789ABCDEF0, "ref_longlong failed");
    -# 0xF23456789ABCDEF0 won't fit in a long, so PHP makes it a double, but SWIG opts to return it as a string.
    -check::equal((double)ref_ulonglong(0xF23456789ABCDEF0), 0xF23456789ABCDEF0, "ref_ulonglong failed");
    +long_long_equal(ref_longlong(0x123456789ABCDEF0), 0x123456789ABCDEF0, "ref_longlong failed");
    +long_long_equal(ref_ulonglong(0xF23456789ABCDEF0), 0xF23456789ABCDEF0, "ref_ulonglong failed");
     
     check::done();
     ?>
    
    From 9df4479a08811b4e201fbfab972bb69dd41717f2 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Tue, 18 May 2010 21:18:43 +0000
    Subject: [PATCH 097/203] Fix member pointers on 64 bit platforms for Java
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12031 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current   |   3 ++
     Lib/java/java.swg | 101 +++++++++++++++++++++++++++++++++++++++++-----
     2 files changed, 95 insertions(+), 9 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 2cc874bb1..15883747d 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -1,6 +1,9 @@
     Version 2.0.0 (in progress)
     ============================
     
    +2010-05-18: wsfulton
    +            [Java] Fix member pointers on 64 bit platforms.
    +
     2010-05-14: wsfulton
                 Fix wrapping of C++ enum boolean values reported by Torsten Landschoff:
                   typedef enum { PLAY = true, STOP = false } play_state;
    diff --git a/Lib/java/java.swg b/Lib/java/java.swg
    index 0fadf1604..44e1337bc 100644
    --- a/Lib/java/java.swg
    +++ b/Lib/java/java.swg
    @@ -11,6 +11,49 @@
      * The jtype typemap contains the Java type used in the JNI intermediary class. 
      * The jstype typemap contains the Java type used in the Java proxy classes, type wrapper classes and module class. */
     
    +/* Fragments */
    +%fragment("SWIG_PackData", "header") {
    +/* Pack binary data into a string */
    +SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
    +  static const char hex[17] = "0123456789abcdef";
    +  register const unsigned char *u = (unsigned char *) ptr;
    +  register const unsigned char *eu =  u + sz;
    +  for (; u != eu; ++u) {
    +    register unsigned char uu = *u;
    +    *(c++) = hex[(uu & 0xf0) >> 4];
    +    *(c++) = hex[uu & 0xf];
    +  }
    +  return c;
    +}
    +}
    +
    +%fragment("SWIG_UnPackData", "header") {
    +/* Unpack binary data from a string */
    +SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
    +  register unsigned char *u = (unsigned char *) ptr;
    +  register const unsigned char *eu = u + sz;
    +  for (; u != eu; ++u) {
    +    register char d = *(c++);
    +    register unsigned char uu;
    +    if ((d >= '0') && (d <= '9'))
    +      uu = ((d - '0') << 4);
    +    else if ((d >= 'a') && (d <= 'f'))
    +      uu = ((d - ('a'-10)) << 4);
    +    else 
    +      return (char *) 0;
    +    d = *(c++);
    +    if ((d >= '0') && (d <= '9'))
    +      uu |= (d - '0');
    +    else if ((d >= 'a') && (d <= 'f'))
    +      uu |= (d - ('a'-10));
    +    else 
    +      return (char *) 0;
    +    *u = uu;
    +  }
    +  return c;
    +}
    +}
    +
     /* Primitive types */
     %typemap(jni) bool,               const bool &               "jboolean"
     %typemap(jni) char,               const char &               "jchar"
    @@ -143,8 +186,8 @@
     %typemap(jstype) SWIGTYPE & "$javaclassname"
     
     /* pointer to a class member */
    -%typemap(jni) SWIGTYPE (CLASS::*) "jlong"
    -%typemap(jtype) SWIGTYPE (CLASS::*) "long"
    +%typemap(jni) SWIGTYPE (CLASS::*) "jstring"
    +%typemap(jtype) SWIGTYPE (CLASS::*) "String"
     %typemap(jstype) SWIGTYPE (CLASS::*) "$javaclassname"
     
     /* The following are the in, out, freearg, argout typemaps. These are the JNI code generating typemaps for converting from Java to C and visa versa. */
    @@ -592,20 +635,39 @@
     %typemap(javadirectorout) SWIGTYPE "$&javaclassname.getCPtr($javacall)"
     
     /* Generic pointers and references */
    -%typemap(in) SWIGTYPE *, SWIGTYPE (CLASS::*) %{ $1 = *($&1_ltype)&$input; %}
    +%typemap(in) SWIGTYPE * %{ $1 = *($&1_ltype)&$input; %}
    +%typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) { 
    +  const char *temp = 0;
    +  if ($input) {
    +    temp = JCALL2(GetStringUTFChars, jenv, $input, 0);
    +    if (!temp) return $null;
    +  }
    +  SWIG_UnpackData(temp, (void *)&$1, sizeof($1));
    +}
     %typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input;
       if (!$1) {
         SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
         return $null;
       } %}
    -%typemap(out) SWIGTYPE *, SWIGTYPE (CLASS::*)
    +%typemap(out) SWIGTYPE *
     %{ *($&1_ltype)&$result = $1; %} 
    +%typemap(out, fragment="SWIG_PackData", noblock=1) SWIGTYPE (CLASS::*) {
    +  char buf[128];
    +  char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
    +  *data = '\0';
    +  $result = JCALL1(NewStringUTF, jenv, buf);
    +}
     %typemap(out) SWIGTYPE &
     %{ *($&1_ltype)&$result = $1; %} 
     
    -%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *, SWIGTYPE (CLASS::*)
    +%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *
     %{ $result = *($&1_ltype)&$input; %}
    -%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE *, SWIGTYPE (CLASS::*)
    +%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*)
    +%{ $result = *($&1_ltype)&$input; %}
    +
    +%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE *
    +%{ *(($&1_ltype)&$input) = ($1_ltype) $1; %}
    +%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE (CLASS::*)
     %{ *(($&1_ltype)&$input) = ($1_ltype) $1; %}
     
     %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &
    @@ -967,7 +1029,8 @@
                      jobjectArray
         "$javainput"
     %typemap(javain) SWIGTYPE "$&javaclassname.getCPtr($javainput)"
    -%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "$javaclassname.getCPtr($javainput)"
    +%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$javaclassname.getCPtr($javainput)"
    +%typemap(javain) SWIGTYPE (CLASS::*) "$javaclassname.getCMemberPtr($javainput)"
     
     /* The javaout typemap is used for converting function return types from the return type
      * used in the JNI class to the type returned by the proxy, module or type wrapper class. */
    @@ -1020,10 +1083,14 @@
     %typemap(javaout) SWIGTYPE & {
         return new $javaclassname($jnicall, $owner);
       }
    -%typemap(javaout) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) {
    +%typemap(javaout) SWIGTYPE *, SWIGTYPE [] {
         long cPtr = $jnicall;
         return (cPtr == 0) ? null : new $javaclassname(cPtr, $owner);
       }
    +%typemap(javaout) SWIGTYPE (CLASS::*) {
    +    String cMemberPtr = $jnicall;
    +    return (cMemberPtr == null) ? null : new $javaclassname(cMemberPtr, $owner);
    +  }
     
     /* Pointer reference typemaps */
     %typemap(jni) SWIGTYPE *const& "jlong"
    @@ -1086,7 +1153,7 @@
     SWIG_JAVABODY_METHODS(public, public, SWIGTYPE)
     
     // Typewrapper classes
    -%typemap(javabody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
    +%typemap(javabody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
       private long swigCPtr;
     
       protected $javaclassname(long cPtr, boolean futureUse) {
    @@ -1102,6 +1169,22 @@ SWIG_JAVABODY_METHODS(public, public, SWIGTYPE)
       }
     %}
     
    +%typemap(javabody) SWIGTYPE (CLASS::*) %{
    +  private String swigCMemberPtr;
    +
    +  protected $javaclassname(String cMemberPtr, boolean futureUse) {
    +    swigCMemberPtr = cMemberPtr;
    +  }
    +
    +  protected $javaclassname() {
    +    swigCMemberPtr = null;
    +  }
    +
    +  protected static String getCMemberPtr($javaclassname obj) {
    +    return obj.swigCMemberPtr;
    +  }
    +%}
    +
     %typemap(javafinalize) SWIGTYPE %{
       protected void finalize() {
         delete();
    
    From e51209335836dcfdc9946a8fc23034ce798602f7 Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Fri, 21 May 2010 07:07:15 +0000
    Subject: [PATCH 098/203] [PHP] Stop generating a bogus line of code in certain
     constructors. This was mostly harmless, but caused a PHP notice to be issued,
     if enabled (SF#2985684).
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12033 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current        |  5 +++++
     Source/Modules/php.cxx | 14 ++++++++------
     2 files changed, 13 insertions(+), 6 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 15883747d..68732468c 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -1,6 +1,11 @@
     Version 2.0.0 (in progress)
     ============================
     
    +2010-05-21: olly
    +	    [PHP] Stop generating a bogus line of code in certain constructors.
    +	    This was mostly harmless, but caused a PHP notice to be issued, if
    +	    enabled (SF#2985684).
    +
     2010-05-18: wsfulton
                 [Java] Fix member pointers on 64 bit platforms.
     
    diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
    index 700358ee4..c6f01c3e3 100644
    --- a/Source/Modules/php.cxx
    +++ b/Source/Modules/php.cxx
    @@ -1495,7 +1495,7 @@ public:
     	      Printf(prepare, "case %d: ", ++last_handled_i);
     	    }
     	    if (Cmp(d, "void") != 0) {
    -		if ((!directorsEnabled() || !Swig_directorclass(n)) && !newobject) {
    +	      if ((!directorsEnabled() || !Swig_directorclass(n)) && !newobject) {
     		Append(prepare, "$r=");
     	      } else {
     		Printf(prepare, "$this->%s=", SWIG_PTR);
    @@ -1631,11 +1631,13 @@ public:
     	Printf(output, "%s", prepare);
           if (constructor) {
     	if (!directorsEnabled() || !Swig_directorclass(n)) {
    -	  if (strcmp(methodname, "__construct") == 0) {
    -	    Printf(output, "\t\t$this->%s=%s;\n", SWIG_PTR, invoke);
    -	  } else {
    -	    String *classname = Swig_class_name(current_class);
    -	    Printf(output, "\t\treturn new %s(%s);\n", classname, invoke);
    +	  if (!Len(prepare)) {
    +	    if (strcmp(methodname, "__construct") == 0) {
    +	      Printf(output, "\t\t$this->%s=%s;\n", SWIG_PTR, invoke);
    +	    } else {
    +	      String *classname = Swig_class_name(current_class);
    +	      Printf(output, "\t\treturn new %s(%s);\n", classname, invoke);
    +	    }
     	  }
     	} else {
     	  Node *parent = Swig_methodclass(n);
    
    From bf1d3f0714f14bc91cc74b87d404f393bc48272a Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Fri, 21 May 2010 07:10:12 +0000
    Subject: [PATCH 099/203] Remove superfluous semicolons.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12034 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Source/Modules/chicken.cxx  | 2 +-
     Source/Modules/csharp.cxx   | 2 +-
     Source/Modules/guile.cxx    | 2 +-
     Source/Modules/java.cxx     | 2 +-
     Source/Modules/mzscheme.cxx | 2 +-
     Source/Modules/ocaml.cxx    | 2 +-
     Source/Modules/octave.cxx   | 4 ++--
     Source/Preprocessor/cpp.c   | 2 +-
     Source/Swig/scanner.c       | 2 +-
     9 files changed, 10 insertions(+), 10 deletions(-)
    
    diff --git a/Source/Modules/chicken.cxx b/Source/Modules/chicken.cxx
    index 9cac92dcb..07deb261a 100644
    --- a/Source/Modules/chicken.cxx
    +++ b/Source/Modules/chicken.cxx
    @@ -677,7 +677,7 @@ int CHICKEN::variableWrapper(Node *n) {
       String *wname = NewString("");
       String *mangle = NewString("");
       String *tm;
    -  String *tm2 = NewString("");;
    +  String *tm2 = NewString("");
       String *argnum = NewString("0");
       String *arg = NewString("argv[0]");
       Wrapper *f;
    diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
    index 3dd51aabf..bedaae7f2 100644
    --- a/Source/Modules/csharp.cxx
    +++ b/Source/Modules/csharp.cxx
    @@ -3886,7 +3886,7 @@ public:
     
       int classDirectorConstructor(Node *n) {
         Node *parent = parentNode(n);
    -    String *decl = Getattr(n, "decl");;
    +    String *decl = Getattr(n, "decl");
         String *supername = Swig_class_name(parent);
         String *classname = directorClassName(parent);
         String *sub = NewString("");
    diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx
    index 9e0f43daf..029978ede 100644
    --- a/Source/Modules/guile.cxx
    +++ b/Source/Modules/guile.cxx
    @@ -657,7 +657,7 @@ public:
         Parm *p;
         String *proc_name = 0;
         char source[256];
    -    Wrapper *f = NewWrapper();;
    +    Wrapper *f = NewWrapper();
         String *cleanup = NewString("");
         String *outarg = NewString("");
         String *signature = NewString("");
    diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx
    index 234af4c8e..ee68af948 100644
    --- a/Source/Modules/java.cxx
    +++ b/Source/Modules/java.cxx
    @@ -4066,7 +4066,7 @@ public:
     
       int classDirectorConstructor(Node *n) {
         Node *parent = parentNode(n);
    -    String *decl = Getattr(n, "decl");;
    +    String *decl = Getattr(n, "decl");
         String *supername = Swig_class_name(parent);
         String *classname = directorClassName(parent);
         String *sub = NewString("");
    diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx
    index 5eb0a58c9..0bc3c8a68 100644
    --- a/Source/Modules/mzscheme.cxx
    +++ b/Source/Modules/mzscheme.cxx
    @@ -514,7 +514,7 @@ public:
     
         String *proc_name = NewString("");
         String *tm;
    -    String *tm2 = NewString("");;
    +    String *tm2 = NewString("");
         String *argnum = NewString("0");
         String *arg = NewString("argv[0]");
         Wrapper *f;
    diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx
    index 7aa7286e9..4c266a7ab 100644
    --- a/Source/Modules/ocaml.cxx
    +++ b/Source/Modules/ocaml.cxx
    @@ -778,7 +778,7 @@ public:
     
         String *proc_name = NewString("");
         String *tm;
    -    String *tm2 = NewString("");;
    +    String *tm2 = NewString("");
         String *argnum = NewString("0");
         String *arg = NewString("SWIG_Field(args,0)");
         Wrapper *f;
    diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx
    index db9592ad6..6c89794ec 100644
    --- a/Source/Modules/octave.cxx
    +++ b/Source/Modules/octave.cxx
    @@ -973,12 +973,12 @@ public:
           Delete(self);
         }
     
    -    return Language::constructorHandler(n);;
    +    return Language::constructorHandler(n);
       }
     
       virtual int destructorHandler(Node *n) {
         have_destructor = 1;
    -    return Language::destructorHandler(n);;
    +    return Language::destructorHandler(n);
       }
     
       virtual int staticmemberfunctionHandler(Node *n) {
    diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c
    index feaa82ff8..5dd320994 100644
    --- a/Source/Preprocessor/cpp.c
    +++ b/Source/Preprocessor/cpp.c
    @@ -191,7 +191,7 @@ void Preprocessor_init(void) {
       Preprocessor_expr_init();	/* Initialize the expression evaluator */
       included_files = NewHash();
     
    -  id_scan = NewScanner();;
    +  id_scan = NewScanner();
     
     }
     
    diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c
    index 7f6e3e149..9b5b35f96 100644
    --- a/Source/Swig/scanner.c
    +++ b/Source/Swig/scanner.c
    @@ -1184,7 +1184,7 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) {
     	state = 12;
           else if (c == startchar) {
     	state = 0;
    -	num_levels++;;
    +	num_levels++;
           }
           else
     	state = 0;
    
    From 1fe29bae873b2c389a5bcdbfbc54dae9e7851d1b Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Fri, 21 May 2010 07:37:40 +0000
    Subject: [PATCH 100/203] Remove superfluous semicolons
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12035 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Lib/lua/typemaps.i | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/Lib/lua/typemaps.i b/Lib/lua/typemaps.i
    index 084726e58..c96814613 100644
    --- a/Lib/lua/typemaps.i
    +++ b/Lib/lua/typemaps.i
    @@ -199,10 +199,10 @@ There probably is some compiler that its not true for, so the code is left here
     %{
     #ifdef __cplusplus	/* generic alloc/dealloc fns*/
     #define SWIG_ALLOC_ARRAY(TYPE,LEN) 	new TYPE[LEN]
    -#define SWIG_FREE_ARRAY(PTR)		delete[] PTR;
    +#define SWIG_FREE_ARRAY(PTR)		delete[] PTR
     #else
     #define SWIG_ALLOC_ARRAY(TYPE,LEN) 	(TYPE *)malloc(LEN*sizeof(TYPE))
    -#define SWIG_FREE_ARRAY(PTR)		free(PTR);
    +#define SWIG_FREE_ARRAY(PTR)		free(PTR)
     #endif
     /* counting the size of arrays:*/
     SWIGINTERN int SWIG_itable_size(lua_State* L, int index)
    
    From 12cfc251e423a526811b84ccb0f11fd7684cbc56 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sat, 22 May 2010 22:49:47 +0000
    Subject: [PATCH 101/203] Fix #2408232. Improve shared_ptr and intrusive_ptr
     wrappers for classes in an inheritance hierarchy. No special treatment is
     needed for derived classes, the SWIG_SHARED_PTR_DERIVED macro is deprecated.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12036 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current                              |  6 +++
     Examples/test-suite/li_boost_intrusive_ptr.i |  9 ++--
     Examples/test-suite/li_boost_shared_ptr.i    | 17 ++-----
     Lib/csharp/boost_shared_ptr.i                |  5 +-
     Lib/intrusive_ptr.i                          | 38 +-------------
     Lib/java/boost_intrusive_ptr.i               |  4 +-
     Lib/java/boost_shared_ptr.i                  |  6 +--
     Lib/octave/boost_shared_ptr.i                |  3 --
     Lib/python/boost_shared_ptr.i                |  3 --
     Lib/shared_ptr.i                             | 18 +------
     Source/Modules/csharp.cxx                    | 36 ++++++++++++--
     Source/Modules/java.cxx                      | 52 ++++++++++++++++----
     Source/Modules/typepass.cxx                  | 31 ++++++++++++
     13 files changed, 124 insertions(+), 104 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 68732468c..9e70c291e 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -1,6 +1,12 @@
     Version 2.0.0 (in progress)
     ============================
     
    +2010-05-22: wsfulton
    +            Fix #2408232. Improve shared_ptr and intrusive_ptr wrappers for classes in an
    +            inheritance hierarchy. No special treatment is needed for derived classes, the
    +            SWIG_SHARED_PTR_DERIVED macro is deprecated and SWIG_SHARED_PTR should be used
    +            instead.
    +
     2010-05-21: olly
     	    [PHP] Stop generating a bogus line of code in certain constructors.
     	    This was mostly harmless, but caused a PHP notice to be issued, if
    diff --git a/Examples/test-suite/li_boost_intrusive_ptr.i b/Examples/test-suite/li_boost_intrusive_ptr.i
    index 47b64682a..23d78bcdc 100644
    --- a/Examples/test-suite/li_boost_intrusive_ptr.i
    +++ b/Examples/test-suite/li_boost_intrusive_ptr.i
    @@ -46,8 +46,8 @@
     %include 
     SWIG_INTRUSIVE_PTR(Klass, Space::Klass)
     SWIG_INTRUSIVE_PTR_NO_WRAP(KlassWithoutRefCount, Space::KlassWithoutRefCount)
    -SWIG_INTRUSIVE_PTR_DERIVED(KlassDerived, Space::KlassWithoutRefCount, Space::KlassDerived)
    -SWIG_INTRUSIVE_PTR_DERIVED(KlassDerivedDerived, Space::KlassDerived, Space::KlassDerivedDerived)
    +SWIG_INTRUSIVE_PTR(KlassDerived, Space::KlassDerived)
    +SWIG_INTRUSIVE_PTR(KlassDerivedDerived, Space::KlassDerivedDerived)
     
     //For the use_count shared_ptr functions
     %typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & ($*1_ltype tempnull) %{ 
    @@ -390,9 +390,7 @@ Space::Klass & GlobalReference = GlobalValue;
     
     // Note: %template after the intrusive_ptr typemaps
     SWIG_INTRUSIVE_PTR(BaseIntDouble, Base)
    -// Note: cannot use Base in the macro below because of the comma in the type, 
    -// so we use a typedef instead. Alternatively use %arg(Base). %arg is defined in swigmacros.swg.
    -SWIG_INTRUSIVE_PTR_DERIVED(PairIntDouble, BaseIntDouble_t, Pair)
    +SWIG_INTRUSIVE_PTR(PairIntDouble, Pair)
     
     #endif
     
    @@ -409,7 +407,6 @@ template  struct Base {
       void release(void) const { if (--count == 0) delete this; }
       int use_count(void) const { return count; }
     };
    -typedef Base BaseIntDouble_t;
     %}
     
     %template(BaseIntDouble) Base;
    diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i
    index 7a9468e4f..886a8d9c8 100644
    --- a/Examples/test-suite/li_boost_shared_ptr.i
    +++ b/Examples/test-suite/li_boost_shared_ptr.i
    @@ -42,15 +42,9 @@
     
     %include 
     SWIG_SHARED_PTR(Klass, Space::Klass)
    -SWIG_SHARED_PTR_DERIVED(KlassDerived, Space::Klass, Space::KlassDerived)
    -SWIG_SHARED_PTR_DERIVED(Klass2ndDerived, Space::Klass, Space::Klass2ndDerived)
    -SWIG_SHARED_PTR_DERIVED(Klass3rdDerived, Space::Klass2ndDerived, Space::Klass3rdDerived)
    -
    -// TEMP for python
    -%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< Space::Klass3rdDerived > = SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< Space::Klass >) {
    -  *newmemory = SWIG_CAST_NEW_MEMORY;
    -  return (void *) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< Space::Klass >(*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< Space::Klass3rdDerived > *)$from);
    -}
    +SWIG_SHARED_PTR(KlassDerived, Space::KlassDerived)
    +SWIG_SHARED_PTR(Klass2ndDerived, Space::Klass2ndDerived)
    +SWIG_SHARED_PTR(Klass3rdDerived, Space::Klass3rdDerived)
     
     #endif
     
    @@ -324,9 +318,7 @@ Space::Klass & GlobalReference = GlobalValue;
     
     // Note: %template after the shared_ptr typemaps
     SWIG_SHARED_PTR(BaseIntDouble, Base)
    -// Note: cannot use Base in the macro below because of the comma in the type, 
    -// so we use a typedef instead. Alternatively use %arg(Base). %arg is defined in swigmacros.swg.
    -SWIG_SHARED_PTR_DERIVED(PairIntDouble, BaseIntDouble_t, Pair)
    +SWIG_SHARED_PTR(PairIntDouble, Pair)
     
     #endif
     
    @@ -339,7 +331,6 @@ template  struct Base {
       Base(T1 t1, T2 t2) : baseVal1(t1*2), baseVal2(t2*2) {}
       virtual std::string getValue() const { return "Base<>"; };
     };
    -typedef Base BaseIntDouble_t;
     %}
     
     %template(BaseIntDouble) Base;
    diff --git a/Lib/csharp/boost_shared_ptr.i b/Lib/csharp/boost_shared_ptr.i
    index 86a62c33c..8463c2b81 100644
    --- a/Lib/csharp/boost_shared_ptr.i
    +++ b/Lib/csharp/boost_shared_ptr.i
    @@ -190,7 +190,7 @@
       private HandleRef swigCPtr;
       private bool swigCMemOwnDerived;
     
    -  internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclassname_SWIGSharedPtrUpcast(cPtr), true) {
    +  internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclassname_SWIGSmartPtrUpcast(cPtr), true) {
         swigCMemOwnDerived = cMemoryOwn;
         swigCPtr = new HandleRef(this, cPtr);
       }
    @@ -227,9 +227,6 @@
         }
       }
     
    -%typemap(imtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "IntPtr"
    -%typemap(csin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "PROXYCLASS.getCPtr($csinput).Handle"
    -
     
     %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
     %enddef
    diff --git a/Lib/intrusive_ptr.i b/Lib/intrusive_ptr.i
    index 43e78f986..a7c922fea 100644
    --- a/Lib/intrusive_ptr.i
    +++ b/Lib/intrusive_ptr.i
    @@ -45,51 +45,17 @@ struct SWIG_null_deleter {
     }
     
     // Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types
    -// For plain classes, do not use for derived classes
     %define SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE...)
    +%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
     SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
     SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
     %enddef
     
    -// Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types
    -// For derived classes
    -%define SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...)
    -SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
    -SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
    -%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > = SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >) %{
    -  *newmemory = SWIG_CAST_NEW_MEMORY;
    -  return (void *) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >(*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *)$from);
    -  %}
    -%extend TYPE {
    -  static SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) {
    -    return swigSharedPtrUpcast;
    -  }
    -}
    -%enddef
    -
     // Extra user macro for including classes in intrusive_ptr typemaps for both const and non-const pointer types
     // This caters for classes which cannot be wrapped by intrusive_ptrs but are still part of the class hierarchy
    -// For plain classes, do not use for derived classes
     %define SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE...)
    +%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
     SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, , TYPE)
     SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, const, TYPE)
     %enddef
     
    -// Extra user macro for including classes in intrusive_ptr typemaps for both const and non-const pointer types
    -// This caters for classes which cannot be wrapped by intrusive_ptrs but are still part of the class hierarchy
    -// For derived classes
    -%define SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE...)
    -SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, , TYPE)
    -SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, const, TYPE)
    -%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > = SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >) %{
    -  *newmemory = SWIG_CAST_NEW_MEMORY;
    -  return (void *) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >(*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *)$from);
    -%}
    -%extend TYPE {
    -  static SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) {
    -    return swigSharedPtrUpcast;
    -  }
    -}
    -%enddef
    -
    -
    diff --git a/Lib/java/boost_intrusive_ptr.i b/Lib/java/boost_intrusive_ptr.i
    index f7b7da32f..28446908f 100644
    --- a/Lib/java/boost_intrusive_ptr.i
    +++ b/Lib/java/boost_intrusive_ptr.i
    @@ -272,7 +272,7 @@
       private boolean swigCMemOwnDerived;
     
       protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    -    super($imclassname.$javaclassname_SWIGSharedPtrUpcast(cPtr), true);
    +    super($imclassname.$javaclassname_SWIGSmartPtrUpcast(cPtr), true);
         swigCMemOwnDerived = cMemoryOwn;
         swigCPtr = cPtr;
       }
    @@ -422,7 +422,7 @@
       private boolean swigCMemOwnDerived;
     
       protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    -    super($imclassname.$javaclassname_SWIGSharedPtrUpcast(cPtr), true);
    +    super($imclassname.$javaclassname_SWIGSmartPtrUpcast(cPtr), true);
         swigCMemOwnDerived = cMemoryOwn;
         swigCPtr = cPtr;
       }
    diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i
    index 1c74a2453..5b89cafb7 100644
    --- a/Lib/java/boost_shared_ptr.i
    +++ b/Lib/java/boost_shared_ptr.i
    @@ -158,7 +158,7 @@
       private boolean swigCMemOwnDerived;
     
       protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    -    super($imclassname.$javaclassname_SWIGSharedPtrUpcast(cPtr), true);
    +    super($imclassname.$javaclassname_SWIGSmartPtrUpcast(cPtr), true);
         swigCMemOwnDerived = cMemoryOwn;
         swigCPtr = cPtr;
       }
    @@ -189,10 +189,6 @@
         super.delete();
       }
     
    -// CONST version needed ???? also for C#
    -%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "long"
    -%typemap(jtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "long"
    -
     
     %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
     %enddef
    diff --git a/Lib/octave/boost_shared_ptr.i b/Lib/octave/boost_shared_ptr.i
    index d702108a6..e475b2308 100644
    --- a/Lib/octave/boost_shared_ptr.i
    +++ b/Lib/octave/boost_shared_ptr.i
    @@ -12,9 +12,6 @@
     //"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
                                    "(void)arg1; delete smartarg1;"
     
    -// Feature to adapt the code generated in the swigregister functions for smart pointers
    -%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
    -
     // Typemap customisations...
     
     // plain value
    diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i
    index 59a3a9298..a3006e36a 100644
    --- a/Lib/python/boost_shared_ptr.i
    +++ b/Lib/python/boost_shared_ptr.i
    @@ -18,9 +18,6 @@
     //"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
                                    "(void)arg1; delete smartarg1;"
     
    -// Feature to adapt the code generated in the swigregister functions for smart pointers
    -%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
    -
     // Typemap customisations...
     
     // plain value
    diff --git a/Lib/shared_ptr.i b/Lib/shared_ptr.i
    index ffff2b40b..877330721 100644
    --- a/Lib/shared_ptr.i
    +++ b/Lib/shared_ptr.i
    @@ -41,25 +41,9 @@ struct SWIG_null_deleter {
     
     
     // Main user macro for defining shared_ptr typemaps for both const and non-const pointer types
    -// For plain classes, do not use for derived classes
     %define SWIG_SHARED_PTR(PROXYCLASS, TYPE...)
    +%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
     SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
     SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
     %enddef
     
    -// Main user macro for defining shared_ptr typemaps for both const and non-const pointer types
    -// For derived classes
    -%define SWIG_SHARED_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...)
    -SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
    -SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
    -%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > = SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >) %{
    -  *newmemory = SWIG_CAST_NEW_MEMORY;
    -  return (void *) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE >(*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *)$from);
    -%}
    -%extend TYPE {
    -  static SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) {
    -    return swigSharedPtrUpcast;
    -  }
    -}
    -%enddef
    -
    diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
    index bedaae7f2..ba8f34b47 100644
    --- a/Source/Modules/csharp.cxx
    +++ b/Source/Modules/csharp.cxx
    @@ -1817,7 +1817,8 @@ public:
     
         // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy)
         if (derived) {
    -      String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGUpcast");
    +      String *smartptr = Getattr(n, "feature:smartptr");
    +      String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, smartptr != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast");
           String *wname = Swig_name_wrapper(upcast_method);
     
           Printv(imclass_cppcasts_code, "\n  [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL);
    @@ -1825,10 +1826,35 @@ public:
     
           Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name);
     
    -      Printv(upcasts_code,
    -	     "SWIGEXPORT ", c_baseclass, " * SWIGSTDCALL ", wname,
    -	     "(", c_classname, " *jarg1) {\n", "    return (", c_baseclass, " *)jarg1;\n" "}\n", "\n", NIL);
    -
    +      if (smartptr) {
    +	SwigType *spt = Swig_cparse_type(smartptr);
    +	if (spt) {
    +	  SwigType *smart = SwigType_typedef_resolve_all(spt);
    +	  Delete(spt);
    +	  SwigType *bsmart = Copy(smart);
    +	  SwigType *rclassname = SwigType_typedef_resolve_all(c_classname);
    +	  SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass);
    +	  Replaceall(bsmart, rclassname, rbaseclass);
    +	  Delete(rclassname);
    +	  Delete(rbaseclass);
    +	  String *smartnamestr = SwigType_namestr(smart);
    +	  String *bsmartnamestr = SwigType_namestr(bsmart);
    +	  Printv(upcasts_code,
    +		 "SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", wname, "(", smartnamestr, " *jarg1) {\n",
    +		 "    return jarg1 ? new ", bsmartnamestr, "(*jarg1) : 0;\n"
    +		 "}\n", "\n", NIL);
    +	  Delete(bsmartnamestr);
    +	  Delete(smartnamestr);
    +	  Delete(bsmart);
    +	} else {
    +	  Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, c_classname);
    +	}
    +      } else {
    +	Printv(upcasts_code,
    +	       "SWIGEXPORT ", c_baseclass, " * SWIGSTDCALL ", wname, "(", c_classname, " *jarg1) {\n",
    +	       "    return (", c_baseclass, " *)jarg1;\n"
    +	       "}\n", "\n", NIL);
    +      }
           Delete(wname);
           Delete(upcast_method);
         }
    diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx
    index ee68af948..8c4770a9e 100644
    --- a/Source/Modules/java.cxx
    +++ b/Source/Modules/java.cxx
    @@ -1825,19 +1825,51 @@ public:
     
         // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy)
         if (derived) {
    -      String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, "SWIGUpcast");
    +      String *smartptr = Getattr(n, "feature:smartptr");
    +      String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, smartptr != 0 ? "SWIGSmartPtrUpcast" : "SWIGUpcast");
           String *jniname = makeValidJniName(upcast_method);
           String *wname = Swig_name_wrapper(jniname);
    -
           Printf(imclass_cppcasts_code, "  public final static native long %s(long jarg1);\n", upcast_method);
    -
    -      Printv(upcasts_code,
    -	     "SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n",
    -	     "    jlong baseptr = 0;\n"
    -	     "    (void)jenv;\n" "    (void)jcls;\n" "    *(", c_baseclass, " **)&baseptr = *(", c_classname, " **)&jarg1;\n"
    -	     "    return baseptr;\n"
    -	     "}\n", "\n", NIL);
    -
    +      if (smartptr) {
    +	SwigType *spt = Swig_cparse_type(smartptr);
    +	if (spt) {
    +	  SwigType *smart = SwigType_typedef_resolve_all(spt);
    +	  Delete(spt);
    +	  SwigType *bsmart = Copy(smart);
    +	  SwigType *rclassname = SwigType_typedef_resolve_all(c_classname);
    +	  SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass);
    +	  Replaceall(bsmart, rclassname, rbaseclass);
    +	  Delete(rclassname);
    +	  Delete(rbaseclass);
    +	  String *smartnamestr = SwigType_namestr(smart);
    +	  String *bsmartnamestr = SwigType_namestr(bsmart);
    +	  Printv(upcasts_code,
    +		 "SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n",
    +		 "    jlong baseptr = 0;\n"
    +		 "    ", smartnamestr, " *argp1;\n"
    +		 "    ", bsmartnamestr, " result;\n"
    +		 "    (void)jenv;\n"
    +		 "    (void)jcls;\n"
    +		 "    argp1 = *(", smartnamestr, " **)&jarg1;\n"
    +		 "    *(", bsmartnamestr, " **)&baseptr = argp1 ? new ", bsmartnamestr, "(*argp1) : 0;\n"
    +		 "    return baseptr;\n"
    +		 "}\n", "\n", NIL);
    +	  Delete(bsmartnamestr);
    +	  Delete(smartnamestr);
    +	  Delete(bsmart);
    +	} else {
    +	  Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, c_classname);
    +	}
    +      } else {
    +	Printv(upcasts_code,
    +	       "SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n",
    +	       "    jlong baseptr = 0;\n"
    +	       "    (void)jenv;\n"
    +	       "    (void)jcls;\n"
    +	       "    *(", c_baseclass, " **)&baseptr = *(", c_classname, " **)&jarg1;\n"
    +	       "    return baseptr;\n"
    +	       "}\n", "\n", NIL);
    +      }
           Delete(wname);
           Delete(jniname);
           Delete(upcast_method);
    diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx
    index e63b58a10..57a7663eb 100644
    --- a/Source/Modules/typepass.cxx
    +++ b/Source/Modules/typepass.cxx
    @@ -231,6 +231,37 @@ class TypePass:private Dispatcher {
           Node *bclass = n;		/* Getattr(n,"class"); */
           Hash *scopes = Getattr(bclass, "typescope");
           SwigType_inherit(clsname, bname, cast, 0);
    +      String *smartptr = Getattr(first, "feature:smartptr");
    +      if (smartptr) {
    +	SwigType *smart = 0;
    +	SwigType *spt = Swig_cparse_type(smartptr);
    +	if (spt) {
    +	  smart = SwigType_typedef_resolve_all(spt);
    +	  Delete(spt);
    +	  /* Record a (fake) inheritance relationship between smart pointer
    +	     and smart pointer to base class, so that smart pointer upcasts
    +	     are automatically generated. */
    +          SwigType *bsmart = Copy(smart);
    +          SwigType *rclsname = SwigType_typedef_resolve_all(clsname);
    +          SwigType *rbname = SwigType_typedef_resolve_all(bname);
    +	  Replaceall(bsmart, rclsname, rbname);
    +          Delete(rclsname);
    +          Delete(rbname);
    +	  String *smartnamestr = SwigType_namestr(smart);
    +	  String *bsmartnamestr = SwigType_namestr(bsmart);
    +	  /* construct casting code */
    +	  String *convcode = NewStringf("\n    *newmemory = SWIG_CAST_NEW_MEMORY;\n    return (void *) new %s(*(%s *)$from);\n", bsmartnamestr, smartnamestr);
    +	  Delete(bsmartnamestr);
    +	  Delete(smartnamestr);
    +	  /* setup inheritance relationship between smart pointer templates */
    +	  SwigType_inherit(smart, bsmart, 0, convcode);
    +	  Delete(convcode);
    +	  Delete(bsmart);
    +	  Delete(smart);
    +	} else {
    +	  Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, clsname);
    +	}
    +      }
           if (!importmode) {
     	String *btype = Copy(bname);
     	SwigType_add_pointer(btype);
    
    From 3dfac02269f5390ef44b98e5977b47d2eff883e8 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sat, 22 May 2010 23:57:19 +0000
    Subject: [PATCH 102/203] shared_ptr improvements so the proxy class does not
     need to be specified - SWIG_SHARED_PTR macro deprecated and replaced by
     %shared_ptr
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12037 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     CHANGES.current                               | 17 ++++++--
     Examples/test-suite/li_boost_intrusive_ptr.i  | 12 +++---
     Examples/test-suite/li_boost_shared_ptr.i     | 12 +++---
     .../test-suite/li_boost_shared_ptr_bits.i     |  2 +-
     Lib/csharp/boost_shared_ptr.i                 | 27 ++++++-------
     Lib/intrusive_ptr.i                           | 37 +++++++++++++----
     Lib/java/boost_intrusive_ptr.i                | 40 +++++++++----------
     Lib/java/boost_shared_ptr.i                   | 22 +++++-----
     Lib/octave/boost_shared_ptr.i                 |  2 +-
     Lib/python/boost_shared_ptr.i                 |  2 +-
     Lib/shared_ptr.i                              | 19 +++++++--
     11 files changed, 117 insertions(+), 75 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 9e70c291e..53ac43291 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -1,11 +1,20 @@
     Version 2.0.0 (in progress)
     ============================
     
    -2010-05-22: wsfulton
    +2010-05-23: wsfulton
                 Fix #2408232. Improve shared_ptr and intrusive_ptr wrappers for classes in an
    -            inheritance hierarchy. No special treatment is needed for derived classes, the
    -            SWIG_SHARED_PTR_DERIVED macro is deprecated and SWIG_SHARED_PTR should be used
    -            instead.
    +            inheritance hierarchy. No special treatment is needed for derived classes.
    +            The proxy class also no longer needs to be specified, it is automatically
    +            deduced. The following macros are deprecated:
    +              SWIG_SHARED_PTR(PROXYCLASS, TYPE)
    +              SWIG_SHARED_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE)
    +            and have been replaced by
    +              %shared_ptr(TYPE)
    +            Similarly for intrusive_ptr wrappers, the following macro is deprecated:
    +              SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE)
    +              SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE)
    +            and have been replaced by
    +              %intrusive_ptr(TYPE)
     
     2010-05-21: olly
     	    [PHP] Stop generating a bogus line of code in certain constructors.
    diff --git a/Examples/test-suite/li_boost_intrusive_ptr.i b/Examples/test-suite/li_boost_intrusive_ptr.i
    index 23d78bcdc..a84af4d45 100644
    --- a/Examples/test-suite/li_boost_intrusive_ptr.i
    +++ b/Examples/test-suite/li_boost_intrusive_ptr.i
    @@ -44,10 +44,10 @@
     #if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED)
     
     %include 
    -SWIG_INTRUSIVE_PTR(Klass, Space::Klass)
    -SWIG_INTRUSIVE_PTR_NO_WRAP(KlassWithoutRefCount, Space::KlassWithoutRefCount)
    -SWIG_INTRUSIVE_PTR(KlassDerived, Space::KlassDerived)
    -SWIG_INTRUSIVE_PTR(KlassDerivedDerived, Space::KlassDerivedDerived)
    +%intrusive_ptr(Space::Klass)
    +%intrusive_ptr_no_wrap(Space::KlassWithoutRefCount)
    +%intrusive_ptr(Space::KlassDerived)
    +%intrusive_ptr(Space::KlassDerivedDerived)
     
     //For the use_count shared_ptr functions
     %typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & ($*1_ltype tempnull) %{ 
    @@ -389,8 +389,8 @@ Space::Klass & GlobalReference = GlobalValue;
     #if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED)
     
     // Note: %template after the intrusive_ptr typemaps
    -SWIG_INTRUSIVE_PTR(BaseIntDouble, Base)
    -SWIG_INTRUSIVE_PTR(PairIntDouble, Pair)
    +%intrusive_ptr(Base)
    +%intrusive_ptr(Pair)
     
     #endif
     
    diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i
    index 886a8d9c8..f92df23a9 100644
    --- a/Examples/test-suite/li_boost_shared_ptr.i
    +++ b/Examples/test-suite/li_boost_shared_ptr.i
    @@ -41,10 +41,10 @@
     #if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
     
     %include 
    -SWIG_SHARED_PTR(Klass, Space::Klass)
    -SWIG_SHARED_PTR(KlassDerived, Space::KlassDerived)
    -SWIG_SHARED_PTR(Klass2ndDerived, Space::Klass2ndDerived)
    -SWIG_SHARED_PTR(Klass3rdDerived, Space::Klass3rdDerived)
    +%shared_ptr(Space::Klass)
    +%shared_ptr(Space::KlassDerived)
    +%shared_ptr(Space::Klass2ndDerived)
    +%shared_ptr(Space::Klass3rdDerived)
     
     #endif
     
    @@ -317,8 +317,8 @@ Space::Klass & GlobalReference = GlobalValue;
     #if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
     
     // Note: %template after the shared_ptr typemaps
    -SWIG_SHARED_PTR(BaseIntDouble, Base)
    -SWIG_SHARED_PTR(PairIntDouble, Pair)
    +%shared_ptr(Base)
    +%shared_ptr(Pair)
     
     #endif
     
    diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i
    index 85ce1d6ab..4e144093e 100644
    --- a/Examples/test-suite/li_boost_shared_ptr_bits.i
    +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i
    @@ -7,7 +7,7 @@
     #if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
     
     %include 
    -SWIG_SHARED_PTR(NonDynamic, NonDynamic)
    +%shared_ptr(NonDynamic)
     
     #endif
     
    diff --git a/Lib/csharp/boost_shared_ptr.i b/Lib/csharp/boost_shared_ptr.i
    index 8463c2b81..f574f61d8 100644
    --- a/Lib/csharp/boost_shared_ptr.i
    +++ b/Lib/csharp/boost_shared_ptr.i
    @@ -1,7 +1,7 @@
     %include 
     
     // Language specific macro implementing all the customisations for handling the smart pointer
    -%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
    +%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
     
     // %naturalvar is as documented for member variables
     %naturalvar TYPE;
    @@ -96,51 +96,51 @@
     %typemap (cstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, 
                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
    -                  SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "PROXYCLASS"
    +                  SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(cstype, TYPE)"
     
     %typemap(csin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, 
                    SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
                    SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
    -               SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "PROXYCLASS.getCPtr($csinput)"
    +               SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(cstype, TYPE).getCPtr($csinput)"
     
     %typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
         IntPtr cPtr = $imcall;
    -    PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
    +    $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
         return ret;
       }
     %typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
         IntPtr cPtr = $imcall;
    -    PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
    +    $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
         return ret;
       }
     %typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
         IntPtr cPtr = $imcall;
    -    PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
    +    $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
         return ret;
       }
     %typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
         IntPtr cPtr = $imcall;
    -    PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
    +    $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
         return ret;
       }
     
     
     %typemap(csout, excode=SWIGEXCODE) CONST TYPE {
    -    PROXYCLASS ret = new PROXYCLASS($imcall, true);$excode
    +    $typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
         return ret;
       }
     %typemap(csout, excode=SWIGEXCODE) CONST TYPE & {
    -    PROXYCLASS ret = new PROXYCLASS($imcall, true);$excode
    +    $typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode
         return ret;
       }
     %typemap(csout, excode=SWIGEXCODE) CONST TYPE * {
         IntPtr cPtr = $imcall;
    -    PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
    +    $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
         return ret;
       }
     %typemap(csout, excode=SWIGEXCODE) TYPE *CONST& {
         IntPtr cPtr = $imcall;
    -    PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
    +    $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
         return ret;
       }
     
    @@ -159,13 +159,13 @@
     %typemap(csvarout, excode=SWIGEXCODE2) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
         get {
           IntPtr cPtr = $imcall;
    -      PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
    +      $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
           return ret;
         } %}
     %typemap(csvarout, excode=SWIGEXCODE2) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
         get {
           IntPtr cPtr = $imcall;
    -      PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode
    +      $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
           return ret;
         } %}
     
    @@ -227,7 +227,6 @@
         }
       }
     
    -
     %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
     %enddef
     
    diff --git a/Lib/intrusive_ptr.i b/Lib/intrusive_ptr.i
    index a7c922fea..eed750c79 100644
    --- a/Lib/intrusive_ptr.i
    +++ b/Lib/intrusive_ptr.i
    @@ -44,18 +44,39 @@ struct SWIG_null_deleter {
     %#define SWIG_NO_NULL_DELETER_1
     }
     
    +// Workaround empty first macro argument bug
    +#define SWIGEMPTYHACK
     // Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types
    +%define %intrusive_ptr(TYPE...)
    +%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
    +SWIG_INTRUSIVE_PTR_TYPEMAPS(SWIGEMPTYHACK, TYPE)
    +SWIG_INTRUSIVE_PTR_TYPEMAPS(const, TYPE)
    +%enddef
    +
    +%define %intrusive_ptr_no_wrap(TYPE...)
    +%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
    +SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(SWIGEMPTYHACK, TYPE)
    +SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(const, TYPE)
    +%enddef
    +
    +// Legacy macros
     %define SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE...)
    -%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
    -SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
    -SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
    +#warning "SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE) is deprecated. Please use %intrusive_ptr(TYPE) instead."
    +%intrusive_ptr(TYPE)
    +%enddef
    +
    +%define SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...)
    +#warning "SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE) is deprecated. Please use %intrusive_ptr(TYPE) instead."
    +%intrusive_ptr(TYPE)
     %enddef
     
    -// Extra user macro for including classes in intrusive_ptr typemaps for both const and non-const pointer types
    -// This caters for classes which cannot be wrapped by intrusive_ptrs but are still part of the class hierarchy
     %define SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE...)
    -%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
    -SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, , TYPE)
    -SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, const, TYPE)
    +#warning "SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE) is deprecated. Please use %intrusive_ptr_no_wrap(TYPE) instead."
    +%intrusive_ptr_no_wrap(TYPE)
    +%enddef
    +
    +%define SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE...)
    +#warning "SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE) is deprecated. Please use %intrusive_ptr_no_wrap(TYPE) instead."
    +%intrusive_ptr_no_wrap(TYPE)
     %enddef
     
    diff --git a/Lib/java/boost_intrusive_ptr.i b/Lib/java/boost_intrusive_ptr.i
    index 28446908f..52cf42b44 100644
    --- a/Lib/java/boost_intrusive_ptr.i
    +++ b/Lib/java/boost_intrusive_ptr.i
    @@ -1,7 +1,7 @@
     %include 
     
     // Language specific macro implementing all the customisations for handling the smart pointer
    -%define SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
    +%define SWIG_INTRUSIVE_PTR_TYPEMAPS(CONST, TYPE...)
     
     // %naturalvar is as documented for member variables
     %naturalvar TYPE;
    @@ -207,48 +207,48 @@
                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
                       SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
                       SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
    -                  SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "PROXYCLASS"
    +                  SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(jstype, TYPE)"
     %typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
                      SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
                      SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
                      SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
    -                 SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "PROXYCLASS.getCPtr($javainput)"
    +                 SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(jstype, TYPE).getCPtr($javainput)"
     
     %typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     
     
     %typemap(javaout) CONST TYPE {
    -    return new PROXYCLASS($jnicall, true);
    +    return new $typemap(jstype, TYPE)($jnicall, true);
       }
     %typemap(javaout) CONST TYPE & {
    -    return new PROXYCLASS($jnicall, true);
    +    return new $typemap(jstype, TYPE)($jnicall, true);
       }
     %typemap(javaout) CONST TYPE * {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) TYPE *CONST& {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     
     // Base proxy classes
    @@ -314,7 +314,7 @@
     
     %include 
     
    -%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, CONST, TYPE...)
    +%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(CONST, TYPE...)
     
     %naturalvar TYPE;
     %naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
    @@ -379,26 +379,26 @@
     
     %typemap (jni)    SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "jlong"
     %typemap (jtype)  SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "long"
    -%typemap (jstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "PROXYCLASS"
    -%typemap (javain) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "PROXYCLASS.getCPtr($javainput)"
    +%typemap (jstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(jstype, TYPE)"
    +%typemap (javain) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(jstype, TYPE).getCPtr($javainput)"
     %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     
     %typemap(javaout) CONST TYPE {
    -    return new PROXYCLASS($jnicall, true);
    +    return new $typemap(jstype, TYPE)($jnicall, true);
       }
     %typemap(javaout) CONST TYPE & {
    -    return new PROXYCLASS($jnicall, true);
    +    return new $typemap(jstype, TYPE)($jnicall, true);
       }
     %typemap(javaout) CONST TYPE * {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) TYPE *CONST& {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     
     // Base proxy classes
    diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i
    index 5b89cafb7..06d839e2e 100644
    --- a/Lib/java/boost_shared_ptr.i
    +++ b/Lib/java/boost_shared_ptr.i
    @@ -1,7 +1,7 @@
     %include 
     
     // Language specific macro implementing all the customisations for handling the smart pointer
    -%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
    +%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
     
     // %naturalvar is as documented for member variables
     %naturalvar TYPE;
    @@ -97,44 +97,44 @@
     %typemap (jstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, 
                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
    -                  SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "PROXYCLASS"
    +                  SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(jstype, TYPE)"
     
     %typemap(javain) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, 
                      SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
                      SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
    -                 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "PROXYCLASS.getCPtr($javainput)"
    +                 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(jstype, TYPE).getCPtr($javainput)"
     
     %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     
     
     %typemap(javaout) CONST TYPE {
    -    return new PROXYCLASS($jnicall, true);
    +    return new $typemap(jstype, TYPE)($jnicall, true);
       }
     %typemap(javaout) CONST TYPE & {
    -    return new PROXYCLASS($jnicall, true);
    +    return new $typemap(jstype, TYPE)($jnicall, true);
       }
     %typemap(javaout) CONST TYPE * {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)/*ha*/(cPtr, true);
       }
     %typemap(javaout) TYPE *CONST& {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     
     // Base proxy classes
    diff --git a/Lib/octave/boost_shared_ptr.i b/Lib/octave/boost_shared_ptr.i
    index e475b2308..93b1a896f 100644
    --- a/Lib/octave/boost_shared_ptr.i
    +++ b/Lib/octave/boost_shared_ptr.i
    @@ -1,7 +1,7 @@
     %include 
     
     // Language specific macro implementing all the customisations for handling the smart pointer
    -%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
    +%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
     
     // %naturalvar is as documented for member variables
     %naturalvar TYPE;
    diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i
    index a3006e36a..e8c536026 100644
    --- a/Lib/python/boost_shared_ptr.i
    +++ b/Lib/python/boost_shared_ptr.i
    @@ -7,7 +7,7 @@
     #endif
     
     // Language specific macro implementing all the customisations for handling the smart pointer
    -%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
    +%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
     
     // %naturalvar is as documented for member variables
     %naturalvar TYPE;
    diff --git a/Lib/shared_ptr.i b/Lib/shared_ptr.i
    index 877330721..77e868de2 100644
    --- a/Lib/shared_ptr.i
    +++ b/Lib/shared_ptr.i
    @@ -40,10 +40,23 @@ struct SWIG_null_deleter {
     }
     
     
    +// Workaround empty first macro argument bug
    +#define SWIGEMPTYHACK
     // Main user macro for defining shared_ptr typemaps for both const and non-const pointer types
    -%define SWIG_SHARED_PTR(PROXYCLASS, TYPE...)
    +%define %shared_ptr(TYPE...)
     %feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
    -SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
    -SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
    +SWIG_SHARED_PTR_TYPEMAPS(SWIGEMPTYHACK, TYPE)
    +SWIG_SHARED_PTR_TYPEMAPS(const, TYPE)
    +%enddef
    +
    +// Legacy macros
    +%define SWIG_SHARED_PTR(PROXYCLASS, TYPE...)
    +#warning "SWIG_SHARED_PTR(PROXYCLASS, TYPE) is deprecated. Please use %shared_ptr(TYPE) instead."
    +%shared_ptr(TYPE)
    +%enddef
    +
    +%define SWIG_SHARED_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...)
    +#warning "SWIG_SHARED_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE) is deprecated. Please use %shared_ptr(TYPE) instead."
    +%shared_ptr(TYPE)
     %enddef
     
    
    From 9c53d41e0fb61671896b44baefe980ac3017d566 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sun, 23 May 2010 00:29:58 +0000
    Subject: [PATCH 103/203] nspace fixes for smart pointers
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12038 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Lib/csharp/boost_shared_ptr.i  |  2 +-
     Lib/java/boost_intrusive_ptr.i | 12 ++++++------
     Lib/java/boost_shared_ptr.i    |  8 ++++----
     3 files changed, 11 insertions(+), 11 deletions(-)
    
    diff --git a/Lib/csharp/boost_shared_ptr.i b/Lib/csharp/boost_shared_ptr.i
    index f574f61d8..54c2a6e87 100644
    --- a/Lib/csharp/boost_shared_ptr.i
    +++ b/Lib/csharp/boost_shared_ptr.i
    @@ -190,7 +190,7 @@
       private HandleRef swigCPtr;
       private bool swigCMemOwnDerived;
     
    -  internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclassname_SWIGSmartPtrUpcast(cPtr), true) {
    +  internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) {
         swigCMemOwnDerived = cMemoryOwn;
         swigCPtr = new HandleRef(this, cPtr);
       }
    diff --git a/Lib/java/boost_intrusive_ptr.i b/Lib/java/boost_intrusive_ptr.i
    index 52cf42b44..8e7a57426 100644
    --- a/Lib/java/boost_intrusive_ptr.i
    +++ b/Lib/java/boost_intrusive_ptr.i
    @@ -256,7 +256,7 @@
       private long swigCPtr;
       private boolean swigCMemOwnBase;
     
    -  protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    +  public $javaclassname(long cPtr, boolean cMemoryOwn) {
         swigCMemOwnBase = cMemoryOwn;
         swigCPtr = cPtr;
       }
    @@ -271,8 +271,8 @@
       private long swigCPtr;
       private boolean swigCMemOwnDerived;
     
    -  protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    -    super($imclassname.$javaclassname_SWIGSmartPtrUpcast(cPtr), true);
    +  public $javaclassname(long cPtr, boolean cMemoryOwn) {
    +    super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
         swigCMemOwnDerived = cMemoryOwn;
         swigCPtr = cPtr;
       }
    @@ -406,7 +406,7 @@
       private long swigCPtr;
       private boolean swigCMemOwnBase;
     
    -  protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    +  public $javaclassname(long cPtr, boolean cMemoryOwn) {
         swigCMemOwnBase = cMemoryOwn;
         swigCPtr = cPtr;
       }
    @@ -421,8 +421,8 @@
       private long swigCPtr;
       private boolean swigCMemOwnDerived;
     
    -  protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    -    super($imclassname.$javaclassname_SWIGSmartPtrUpcast(cPtr), true);
    +  public $javaclassname(long cPtr, boolean cMemoryOwn) {
    +    super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
         swigCMemOwnDerived = cMemoryOwn;
         swigCPtr = cPtr;
       }
    diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i
    index 06d839e2e..dd7344ea6 100644
    --- a/Lib/java/boost_shared_ptr.i
    +++ b/Lib/java/boost_shared_ptr.i
    @@ -130,7 +130,7 @@
       }
     %typemap(javaout) CONST TYPE * {
         long cPtr = $jnicall;
    -    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)/*ha*/(cPtr, true);
    +    return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
       }
     %typemap(javaout) TYPE *CONST& {
         long cPtr = $jnicall;
    @@ -142,7 +142,7 @@
       private long swigCPtr;
       private boolean swigCMemOwnBase;
     
    -  protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    +  public $javaclassname(long cPtr, boolean cMemoryOwn) {
         swigCMemOwnBase = cMemoryOwn;
         swigCPtr = cPtr;
       }
    @@ -157,8 +157,8 @@
       private long swigCPtr;
       private boolean swigCMemOwnDerived;
     
    -  protected $javaclassname(long cPtr, boolean cMemoryOwn) {
    -    super($imclassname.$javaclassname_SWIGSmartPtrUpcast(cPtr), true);
    +  public $javaclassname(long cPtr, boolean cMemoryOwn) {
    +    super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true);
         swigCMemOwnDerived = cMemoryOwn;
         swigCPtr = cPtr;
       }
    
    From 51bbc83fdd2cff376b5814c24f94e1e0b40bc17a Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Sun, 23 May 2010 03:32:20 +0000
    Subject: [PATCH 104/203] Fix typo
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12039 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Doc/Manual/Modules.html | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/Doc/Manual/Modules.html b/Doc/Manual/Modules.html
    index 094d4fd5d..5ce448ce6 100644
    --- a/Doc/Manual/Modules.html
    +++ b/Doc/Manual/Modules.html
    @@ -29,7 +29,7 @@
     

    Each invocation of SWIG requires a module name to be specified. The module name is used to name the resulting target language extension module. -Exactly what this means and and what the name is used for +Exactly what this means and what the name is used for depends on the target language, for example the name can define a target language namespace or merely be a useful name for naming files or helper classes. Essentially, a module comprises target language wrappers for a chosen collection of global variables/functions, structs/classes and other C/C++ types. From 3f47ff6988c5e48617f5b4b43a50582a56c72919 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 23 May 2010 03:43:31 +0000 Subject: [PATCH 105/203] Fix more doubled word typos git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12040 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Allegrocl.html | 2 +- Doc/Manual/CSharp.html | 2 +- Doc/Manual/Customization.html | 2 +- Doc/Manual/Introduction.html | 2 +- Doc/Manual/Java.html | 8 ++++---- Doc/Manual/Lua.html | 4 ++-- Doc/Manual/Octave.html | 2 +- Doc/Manual/Pike.html | 2 +- Doc/Manual/Python.html | 4 ++-- Doc/Manual/Ruby.html | 4 ++-- Doc/Manual/SWIG.html | 2 +- Doc/Manual/Windows.html | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html index 5cedee26b..5d00c4cd0 100644 --- a/Doc/Manual/Allegrocl.html +++ b/Doc/Manual/Allegrocl.html @@ -1777,7 +1777,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)

    - These three typemaps are specifically employed by the the + These three typemaps are specifically employed by the Allegro CL interface generator. SWIG also implements a number of other typemaps that can be used for generating code in the C/C++ wrappers. You can read about diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 21b319e29..ea8b66e65 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -511,7 +511,7 @@ In the P/Invoke default marshalling scheme, one needs to designate whether the i array parameter as input, output, or both. When the function is invoked, the CLR allocates a separate chunk of memory as big as the given managed array, which is automatically released at the end of the function call. If the array parameter is marked as being input, the content of the managed array is copied into this buffer when the call is made. Correspondingly, if the array parameter is marked as being output, the contents of the reserved buffer are copied -back into the managed array after the call returns. A pointer to to this buffer +back into the managed array after the call returns. A pointer to this buffer is passed to the native function.

    diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index 734067475..b43075991 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -775,7 +775,7 @@ involving %feature:

    The name matching rules outlined in the Ambiguity resolution and renaming section applies to all %feature directives. -In fact the the %rename directive is just a special form of %feature. +In fact the %rename directive is just a special form of %feature. The matching rules mean that features are very flexible and can be applied with pinpoint accuracy to specific declarations if needed. Additionally, if no declaration name is given, a global feature is said to be defined. diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html index df8d03fdf..4b954040b 100644 --- a/Doc/Manual/Introduction.html +++ b/Doc/Manual/Introduction.html @@ -365,7 +365,7 @@ possible to support different types of interfaces depending on the application.

    SWIG is a command line tool and as such can be incorporated into any build system that supports invoking external tools/compilers. -SWIG is most commonly invoked from within a Makefile, but is also known to be invoked from from popular IDEs such as +SWIG is most commonly invoked from within a Makefile, but is also known to be invoked from popular IDEs such as Microsoft Visual Studio.

    diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 857363840..366736eb7 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -1094,7 +1094,7 @@ C++ enums defined within a C++ class are generated into a static final inner Jav

    -Typesafe enums have their advantages over using plain integers in that they they can be used in a typesafe manner. +Typesafe enums have their advantages over using plain integers in that they can be used in a typesafe manner. However, there are limitations. For example, they cannot be used in switch statements and serialization is an issue. Please look at the following references for further information: @@ -2270,7 +2270,7 @@ For example, let's change the intermediary JNI class access to just the default

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

    21.4.2 The Java module class

    @@ -2758,7 +2758,7 @@ You can encourage the garbage collector to call the finalizers, for example, add }

    Although this usually works, the documentation doesn't guarantee that runFinalization() will actually call the finalizers. -As the the shutdown hook is guaranteed you could also make a JNI call to clean up any resources that are being tracked by the C/C++ code.

    +As the shutdown hook is guaranteed you could also make a JNI call to clean up any resources that are being tracked by the C/C++ code.

  • @@ -4521,7 +4521,7 @@ code.

    This section describes how you can modify SWIG's default wrapping behavior for various C/C++ datatypes using the %typemap directive. -You are advised to be familiar with the the material in the "Typemaps" chapter. +You are advised to be familiar with the material in the "Typemaps" chapter. While not absolutely essential knowledge, this section assumes some familiarity with the Java Native Interface (JNI). JNI documentation can be consulted either online at Sun's Java web site or from a good JNI book. The following two books are recommended:

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 53687d3de..a1544d21e 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -334,7 +334,7 @@ extern double Foo; %mutable;

    -SWIG will allow the the reading of Foo but when a set attempt is made, an error function will be called. +SWIG will allow the reading of Foo but when a set attempt is made, an error function will be called.

     > print(e.Foo) -- reading works ok
    @@ -1099,7 +1099,7 @@ userdata: 0003D880
     

    -Note: is is also possible (though tedious) to have a function throw several different kinds of exceptions. To process this +Note: it is also possible (though tedious) to have a function throw several different kinds of exceptions. To process this will require a pcall, followed by a set of if statements checking the type of the error.

    diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 63663a474..de28a1427 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -239,7 +239,7 @@ extern double Foo;

    - SWIG will allow the the reading of Foo but when a set attempt is made, an error function will be called. + SWIG will allow the reading of Foo but when a set attempt is made, an error function will be called.

    octave:1> example
    diff --git a/Doc/Manual/Pike.html b/Doc/Manual/Pike.html
    index a47d07865..ad8976a14 100644
    --- a/Doc/Manual/Pike.html
    +++ b/Doc/Manual/Pike.html
    @@ -172,7 +172,7 @@ exactly as you'd expect it to:
     
     
     

    -Global variables are currently wrapped as a pair of of functions, one to get +Global variables are currently wrapped as a pair of functions, one to get the current value of the variable and another to set it. For example, the declaration

    diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index aa50630be..8f876316e 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -1282,7 +1282,7 @@ something like this:

    This object is actually a Python instance that has been wrapped around a pointer to the low-level C structure. This instance doesn't actually do anything--it just serves as a proxy. -The pointer to the C object can be found in the the .this +The pointer to the C object can be found in the .this attribute. For example:

    @@ -3101,7 +3101,7 @@ customization features.

    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 do do this. First, to +in SWIG provides some features that enable you to do this. First, to entirely replace a proxy function you can use %feature("shadow"). For example:

    diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 8684c355f..8b43962c5 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -10204,7 +10204,7 @@ the same underlying C++ object. This can cause problems. For example:
    -

    After the the garbage collector runs, as a result of our call +

    After the garbage collector runs, as a result of our call to GC.start, callingtiger2.get_name() causes a segmentation fault. The problem is that when tiger1 is garbage collected, it frees the underlying C++ object. Thus, when tiger2 @@ -10649,7 +10649,7 @@ initialization a normal Ruby interpreter will call the ruby_init() function which in turn will call a function called Init_stack or similar.  This function will store a pointer to the location where -the stack points at at that point in time.

    +the stack points at that point in time.

    diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index e4a2a8c42..b4f332b14 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -92,7 +92,7 @@ chapters.

    -To run SWIG, use the swig command with options options and a filename like this: +To run SWIG, use the swig command with options and a filename like this:

    diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html
    index 5d16a8b9f..e295fe307 100644
    --- a/Doc/Manual/Windows.html
    +++ b/Doc/Manual/Windows.html
    @@ -272,7 +272,7 @@ Execute the steps in the order shown and don't use spaces in path names. In fact
       
    • Answer y to the "do you wish to continue with the post install?"
    • Answer y to the "do you have MinGW installed?"
    • -
    • Type in the the folder in which you installed MinGW (C:/MinGW is default)
    • +
    • Type in the folder in which you installed MinGW (C:/MinGW is default)
  • From b89a0b24a96520a9ddef44a01b8e295a07383570 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 23 May 2010 03:56:15 +0000 Subject: [PATCH 106/203] More typo fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12041 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Devel/cmdopt.html | 2 +- Doc/Devel/scanner.html | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Doc/Devel/cmdopt.html b/Doc/Devel/cmdopt.html index c5f207c03..5e90d2aba 100644 --- a/Doc/Devel/cmdopt.html +++ b/Doc/Devel/cmdopt.html @@ -36,7 +36,7 @@ functions to mark whether or not a particular command line option was used. Thi

    Argument Marking

    -As command line options are are processed by language modules, the following functions are used +As command line options are processed by language modules, the following functions are used to mark the arguments as used:

    diff --git a/Doc/Devel/scanner.html b/Doc/Devel/scanner.html index 272216475..65ef1d8e9 100644 --- a/Doc/Devel/scanner.html +++ b/Doc/Devel/scanner.html @@ -77,7 +77,7 @@ string prior to using this function. Pushes a token into the scanner. This exact token will be returned by the next call to Scanner_token(). tokvalue is the integer token value to return and val is the token text to return. This function is only used to handle very special parsing cases. For instance, if you need the scanner to -return a ficticious token into order to enter a special parsing case. +return a fictitious token into order to enter a special parsing case.

    @@ -238,7 +238,7 @@ SWIG_TOKEN_PERIOD . SWIG_TOKEN_AT @ SWIG_TOKEN_DOLLAR $ SWIG_TOKEN_ENDLINE Literal newline -SWIG_TOKEN_ID identifer +SWIG_TOKEN_ID identifier SWIG_TOKEN_FLOAT Floating point with F suffix (e.g., 3.1415F) SWIG_TOKEN_DOUBLE Floating point (e.g., 3.1415 ) SWIG_TOKEN_INT Integer (e.g., 314) @@ -281,8 +281,3 @@ using these functions to write a yacc-compatible lexer. - - - - - From 17a6b5424a491a57ea8b6ae329668f087761356b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 23 May 2010 04:08:44 +0000 Subject: [PATCH 107/203] Update to reflect current directory structure. Drop unwritten sections on differences from 1.1 (if nobody has yet written it, it seems unlikely anyone will), and plans for 2.0 (since we're about to release it). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12042 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Devel/internals.html | 87 ++++++++++++---------------------------- 1 file changed, 26 insertions(+), 61 deletions(-) diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html index 5f774c095..6ac3947f7 100644 --- a/Doc/Devel/internals.html +++ b/Doc/Devel/internals.html @@ -42,11 +42,9 @@ David M. Beazley

  • 3. Types and Typemaps
  • 4. Parsing -
  • 5. Difference Between SWIG 1.1 and SWIG 1.3 -
  • 6. Plans for SWIG 2.0 -
  • 7. C/C++ Wrapper Support Functions -
  • 8. Symbol Naming Guidelines for Generated C/C++ Code -
  • 9. Debugging SWIG +
  • 5. C/C++ Wrapper Support Functions +
  • 6. Symbol Naming Guidelines for Generated C/C++ Code +
  • 7. Debugging SWIG @@ -96,55 +94,35 @@ info. Source -SWIG source code is in this subdir tree. Directories marked w/ "(*)" -are used in building the swig executable. +The C and C++ source code for the swig executable is in this +subdir tree. - + + containers. - - - - - + - - + + - - - - + language has a .cxx and a .h file). - - + + - - - - - - - - - - + @@ -153,7 +131,7 @@ are used in building the swig executable. - + @@ -172,14 +150,14 @@ to look for code:
      -
    • Modules1.1/swigmain.cxx:main() is the program entry +
    • Modules/swigmain.cxx:main() is the program entry point. It parses the language-specifying command-line option (for example, -java), creating a new language-specific wrapping object (each language is a C++ class derived from base class Language). This object and the command-line is passed to SWIG_main(), whose return value is the program exit value. -
    • SWIG1.1/main.cxx:SWIG_main() is the "real" main. It +
    • Modules/main.cxx:SWIG_main() is the "real" main. It initializes the preprocessor and typemap machinery, defines some preprocessor symbols, locates the SWIG library, processes common command-line options, and then calls the language-specific command-line @@ -202,7 +180,7 @@ included -freeze, go into an infinite loop; otherwise return the error count.
    • The language-specific parse() (and all other -language-specific code) lives in Modules1.1/foo.{h,cxx} for +language-specific code) lives in Modules/foo.{h,cxx} for language Foo. Typically, FOO::parse() calls FOO::headers() and then the global function yyparse(), which uses the callbacks registered by SWIG_main() above. @@ -552,8 +530,7 @@ list item: listval5 The representation and manipulation of types is currently in the process of being reorganized and (hopefully) simplified. The following list describes the current set of functions that are used to -manipulate datatypes. These functions are different than in -SWIG1.1 and may change names in the final SWIG1.3 release. +manipulate datatypes.
      • SwigType_str(SwigType *t, char *name).
        @@ -709,19 +686,7 @@ repeated calls without making any copies. [TODO] -

        5. Difference Between SWIG 1.1 and SWIG 1.3

        -
        - -[TODO] - - -

        6. Plans for SWIG 2.0

        -
        - -[TODO] - - -

        7. The C/C++ Wrapping Layer

        +

        5. The C/C++ Wrapping Layer

        Added: Dave Beazley (July 22, 2000) @@ -1000,8 +965,8 @@ for specifying local variable declarations and argument conversions. - -

        8. Symbol Naming Guidelines for Generated C/C++ Code

        +
        +

        6. Symbol Naming Guidelines for Generated C/C++ Code

        The C++ standard (ISO/IEC 14882:1998(E)) states:
        @@ -1047,8 +1012,8 @@ For code compiled as C or C++ that attempts to mangle a wrapped symbol: In the past SWIG has generated many symbols which flout the standard especially double underscores. In fact they may not all be rooted out yet, so please fix them when you see them. - -

        9. Debugging SWIG

        +
        +

        7. Debugging SWIG

        Warning. Debugging SWIG is for the very patient.

        @@ -1099,7 +1064,7 @@ Please also read the Debugging Functions section in SWIG Par


        -Copyright (C) 1999-2004 SWIG Development Team. +Copyright (C) 1999-2010 SWIG Development Team. From a363a0361bb2965310c327194b1e02ab7af1ff4b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 23 May 2010 04:58:40 +0000 Subject: [PATCH 108/203] Clean up the Modula-3 docs a bit. Refocus the introduction on matters that people reading it will actually want to know. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12043 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Modula3.html | 193 ++++++++-------------------------------- 1 file changed, 35 insertions(+), 158 deletions(-) diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index 228c181c0..ef15132b7 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -11,10 +11,7 @@
        • Overview
        • Conception
            @@ -49,7 +46,7 @@

            This chapter describes SWIG's support of -Modula-3. +Modula-3. You should be familiar with the basics of SWIG, @@ -59,14 +56,18 @@ especially

            24.1 Overview

            +

            +Modula-3 is a compiled language in the tradition of Niklaus Wirth's Modula 2, +which is in turn a successor to Pascal. +

            -The Modula-3 support is very basic and highly experimental! +SWIG's Modula-3 support is currently very basic and highly experimental! Many features are still not designed satisfyingly and I need more discussion about the odds and ends. Don't rely on any feature, incompatible changes are likely in the future! -The Modula-3 generator was already useful for interfacing -to the libraries +However, the Modula-3 generator was already useful for interfacing +to the libraries:

              @@ -78,130 +79,33 @@ PLPlot
            1. FFTW - . +
            +

            24.1.3 Motivation

            -I took some more time to explain -why I think it's right what I'm doing. -So the introduction got a bit longer than it should ... ;-) -

            - - -

            24.1.1 Why not scripting ?

            - - -

            -SWIG started as wrapper from the fast compiled languages C and C++ -to high level scripting languages like Python. -Although scripting languages are designed -to make programming life easier -by hiding machine internals from the programmer -there are several aspects of today's scripting languages -that are unfavourable in my opinion. +Although it is possible to write Modula-3 code that performs as well as C/C++ +most existing libraries are not written in Modula-3 but in C or C++, and +even libraries in other languages may provide C header files.

            -Besides C, C++, Cluster (a Modula derivate for Amiga computers) -I evaluated several scripting like languages in the past: -Different dialects of BASIC, -Perl, ARexx (a variant of Rexx for Amiga computers), -shell scripts. -I found them too inconsistent, -too weak in distinguishing types, -too weak in encapsulating pieces of code. -Eventually I have started several projects in Python -because of the fine syntax. -But when projects became larger -I lost the track. -I got convinced that one can not have -maintainable code in a language -that is not statically typed. -In fact the main advantages of scripting languages -e.g. matching regular expressions, -complex built-in datatypes like lists, dictionaries, -are not advantages of the language itself -but can be provided by function libraries. -

            - -

            24.1.2 Why Modula-3 ?

            - - -

            -Modula-3 is a compiler language -in the tradition of Niklaus Wirth's Modula 2, -which is in turn a successor of the popular Pascal. -I have chosen Modula-3 -because of its -logical syntax, -strong modularization, -the type system which is very detailed -for machine types compared to other languages. -Of course it supports all of the modern games -like exceptions, objects, garbage collection, threads. -While C++ programmers must -control three languages, -namely the preprocessor, C and ++, -Modula-3 is made in one go -and the language definition is really compact. +Fortunately Modula-3 can call C functions, but you have to write Modula-3 +interfaces to them, and to make things comfortable you will also need +wrappers that convert between high-level features of Modula-3 (garbage +collecting, exceptions) and the explicit tracking of allocated memory and +exception codes used by C APIs.

            -On the one hand Modula-3 can be safe -(but probably less efficient) in normal modules -while providing much static and dynamic safety. -On the other hand you can write efficient -but less safe code in the style of C -within UNSAFE modules. +SWIG converts C headers to Modula-3 interfaces for you, and using typemaps +you can pass TEXTs or open arrays, and convert error return codes +into exceptions.

            -Unfortunately Modula's safety and strength -requires more writing than scripting languages do. -Today if I want to safe characters -I prefer Haskell (similar to OCAML) - -it's statically typed, too. -

            - - -

            24.1.3 Why C / C++ ?

            - - -

            -Although it is no problem to write Modula-3 programs -that performs as fast as C -most libraries are not written in Modula-3 but in C. -Fortunately the binary interface of most function libraries -can be addressed by Modula-3. -Even more fortunately even non-C libraries may provide C header files. -This is where SWIG becomes helpful. -

            - -

            24.1.4 Why SWIG ?

            - - -

            -The C headers and the possibility to interface to C libraries -still leaves the work for you -to write Modula-3 interfaces to them. -To make things comfortable you will also need -wrappers that convert between high-level features of Modula-3 -(garbage collecting, exceptions) -and the low level of the C libraries. -

            - -

            -SWIG converts C headers to Modula-3 interfaces for you. -You could call the C functions without loss -of efficiency but it won't be joy -because you could not pass TEXTs -or open arrays and -you would have to process error return codes -rather then exceptions. -But using some typemaps SWIG will also generate -wrappers that bring the whole Modula-3 comfort to you. If the library API is ill designed writing appropriate typemaps can be still time-consuming. E.g. C programmers are very creative to work-around @@ -211,47 +115,20 @@ otherwise you lose static safety and consistency.

            - -But you have still a problem: -C library interfaces are often ill. -They lack for certain information -because C compilers wouldn't care about. -You should integrate detailed type information -by adding typedefs and consts -and you should persuade the C library programmer -to add this information to his interface. -Only this way other language users can benefit from your work -and only this way you can easily update your interfaces -when a new library version is released. - -You will realise that writing good SWIG interfaces -is very costly and it will only amortise -when considering evolving libraries. -

            - - -

            -Without SWIG you would probably never consider -to call C++ libraries from Modula-3. -But with SWIG this is worth a consideration. -SWIG can write C wrappers to C++ functions and object methods -that may throw exceptions. -In fact it breaks down C++ libraries to C interfaces -which can be in turn called from Modula-3. -To make it complete you can hide the C interface -with Modula-3 classes and exceptions. +Without SWIG you would probably never consider trying to call C++ libraries +from Modula-3, but with SWIG this is becomes feasible. +SWIG can generate C wrappers to C++ functions and object methods +that may throw exceptions, and then wrap these C wrappers for Module-3. +To make it complete you can then hide the C interface with Modula-3 classes and +exceptions.

            -Although SWIG does the best it can do -it can only serve as a one-way strategy. -That means you can use C++ libraries -with Modula-3 (even with call back functions), -but it's certainly not possible to smoothly -integrate Modula-3 code into a C / C++ project. +SWIG allows you to call C and C++ libraries from Modula-3 (even with call back +functions), but it doesn't allow you to easily integrate a Module-3 module into +a C/C++ project.

            -

            24.2 Conception

            @@ -259,7 +136,7 @@ integrate Modula-3 code into a C / C++ project.

            -Modula-3 has an integrated support for calling C functions. +Modula-3 has integrated support for calling C functions. This is also extensively used by the standard Modula-3 libraries to call OS functions. The Modula-3 part of SWIG and the corresponding SWIG library @@ -417,7 +294,7 @@ with a C interface.

            Here's a scheme of how the function calls to Modula-3 wrappers -a redirected to C library functions: +are redirected to C library functions:

    DOH (*)
    DOH C library providing memory allocation, file access and generic - containers. Result: libdoh.a
    Experiment[TODO]
    Include (*)
    Include Configuration .h files
    LParseParser (lex / yacc) files and support [why not (*)?!]
    CParseParser (lex / yacc) files and support
    Modules[TODO]
    Modules1.1 (*) Language-specific callbacks that does actual code generation (each - language has a .cxx and a .h file). Result: libmodules11.a
    Preprocessor (*)SWIG-specialized C/C++ preprocessor. Result: libcpp.a
    PreprocessorSWIG-specialized C/C++ preprocessor.
    SWIG1.1 (*)Parts of SWIG that are not language-specific, including option - processing and the type-mapping system. Result: libswig11.a. - Note: This directory is currently being phased out.
    SWIG1.3[TODO] [funny, nothing here is presently used for swig-1.3]. - This directory might turn into a compatibility interface between - SWIG1.3 and the SWIG1.1 modules.
    Swig (*)This directory contains the new ANSI C core of the system +
    SwigThis directory contains the ANSI C core of the system and contains generic functions related to types, file handling, scanning, and so forth.
    ToolsLibtool support and the mkdist.py script.The mkdist.py script and other tools.
    Win
    @@ -1058,8 +935,8 @@ where almost everything is generated by a typemap:
    • The Modula-3 part of SWIG doesn't try to generate nicely formatted code. -Use m3pp to postprocess the Modula files, -it does a very good job here. +If you need to read the generated code, use m3pp to postprocess the +Modula files.
    From a4febe779909fe257f14fa54967db1629286a2c8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 23 May 2010 22:24:36 +0000 Subject: [PATCH 109/203] Fix #2957375 (C#) - SWIGStringHelper and SWIGExceptionHelper not always being initialized before use in .NET 4 as the intermediary class was not marked as beforefieldinit. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12044 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 16 ++++++++++++++++ Lib/csharp/csharphead.swg | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 53ac43291..9839e13bc 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,22 @@ Version 2.0.0 (in progress) ============================ +2010-05-23: wsfulton + [C#] Fix #2957375 - SWIGStringHelper and SWIGExceptionHelper not always being + initialized before use in .NET 4 as the classes were not marked beforefieldinit. + A static constructor has been added to the intermediary class like this: + + %pragma(csharp) imclasscode=%{ + static $imclassname() { + } + %} + + If you had added your own custom static constructor to the intermediary class in + the same way as above, you will have to modify your approach to use static variable + initialization or define SWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR - See csharphead.swg. + + *** POTENTIAL INCOMPATIBILITY *** + 2010-05-23: wsfulton Fix #2408232. Improve shared_ptr and intrusive_ptr wrappers for classes in an inheritance hierarchy. No special treatment is needed for derived classes. diff --git a/Lib/csharp/csharphead.swg b/Lib/csharp/csharphead.swg index 9b144d6a5..a1c56a4b3 100644 --- a/Lib/csharp/csharphead.swg +++ b/Lib/csharp/csharphead.swg @@ -319,6 +319,14 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_CSharpString %} #endif // SWIG_CSHARP_NO_STRING_HELPER +#if !defined(SWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR) +// Ensure the class is not marked beforefieldinit +%pragma(csharp) imclasscode=%{ + static $imclassname() { + } +%} +#endif + %insert(runtime) %{ /* Contract support */ From 1be936380fe678fe81f951acc88d9ca7842a9ec0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 24 May 2010 06:02:11 +0000 Subject: [PATCH 110/203] S_ISDIR is defined for mingw gcc but not visual c++ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12045 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/misc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index f845d1a03..2ba7827a1 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -22,8 +22,10 @@ char cvsroot_misc_c[] = "$Id$"; #ifdef _WIN32 #include +#ifndef S_ISDIR #define S_ISDIR(mode) (((mode) & S_IFDIR) == S_IFDIR) #endif +#endif static char *fake_version = 0; From dc33d167bf35975062eacbff21149c81cdb0e15b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 25 May 2010 06:08:08 +0000 Subject: [PATCH 111/203] Fix to work with PHP5 wrappers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12046 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/proxy/runme.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/php/proxy/runme.php b/Examples/php/proxy/runme.php index dea80e358..e70ab229f 100644 --- a/Examples/php/proxy/runme.php +++ b/Examples/php/proxy/runme.php @@ -9,10 +9,10 @@ include("example.php"); # ----- Object creation ----- print "Creating some objects:\n"; -$c = CircleFactory(10); -print " Created circle $c with area ". $c->area() ."\n"; +$c = example::CircleFactory(10); +print " Created circle \$c with area ". $c->area() ."\n"; $s = new Square(10); -print " Created square $s\n"; +print " Created square \$s\n"; # ----- Access a static member ----- @@ -37,7 +37,7 @@ print " Square = (" . $s->x . "," . $s->y . ")\n"; print "\nHere are some properties of the shapes:\n"; foreach (array($c,$s) as $o) { - print " ".get_class($o)." $o\n"; + print " ".get_class($o)." \$o\n"; print " x = " . $o->x . "\n"; print " y = " . $o->y . "\n"; print " area = " . $o->area() . "\n"; From 744bfd6118be34caef135e9d4770b39207f246b7 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 25 May 2010 06:24:03 +0000 Subject: [PATCH 112/203] Fix to work with PHP5 wrappers. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12047 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/disown/runme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/php/disown/runme.php b/Examples/php/disown/runme.php index 73d50786b..d90b03a9d 100644 --- a/Examples/php/disown/runme.php +++ b/Examples/php/disown/runme.php @@ -10,9 +10,9 @@ require("example.php"); print "Creating some objects:\n"; $c = new Circle(10); -print " Created circle $c\n"; +print " Created circle \$c\n"; $s = new Square(10); -print " Created square $s\n"; +print " Created square \$s\n"; # ----- Create the ShapeContainer ---- From ae8ac072da2b9824abd297dad9d3b7c87dca07f0 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 25 May 2010 06:25:28 +0000 Subject: [PATCH 113/203] Fix to work with PHP5 wrappers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12048 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/overloading/runme.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/php/overloading/runme.php b/Examples/php/overloading/runme.php index 5aa69048d..01044445f 100644 --- a/Examples/php/overloading/runme.php +++ b/Examples/php/overloading/runme.php @@ -10,9 +10,9 @@ include("example.php"); print "Creating some objects:\n"; $c = new Circle(10); -print " Created circle $c\n"; +print " Created circle \$c\n"; $s = new Square(10); -print " Created square $s\n"; +print " Created square \$s\n"; # ----- Access a static member ----- @@ -37,7 +37,7 @@ print " Square = (" . $s->x . "," . $s->y . ")\n"; print "\nHere are some properties of the shapes:\n"; foreach (array(1, 2.1, "quick brown fox", $c, $s) as $o) { - print " ".get_class($o)." $o\n"; + print " ".get_class($o)." \$o\n"; print " overloaded = " . overloaded($o) . "\n"; } From 314d4f17de0b2ae6807ae588b4e42de8ca22779c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 25 May 2010 06:43:21 +0000 Subject: [PATCH 114/203] Fix running R examples and update docs about R CMD SHLIB git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12049 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/R.html | 34 +++++++++++++++++++++++++++------- Examples/Makefile.in | 4 ++-- Examples/r/class/Makefile | 5 +---- Examples/r/simple/Makefile | 7 +++---- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html index 0ed43fc52..e8cee6448 100644 --- a/Doc/Manual/R.html +++ b/Doc/Manual/R.html @@ -56,28 +56,48 @@ example.c is the name of the file with the functions in them
     swig -r example.i
    -PKG_LIBS="example.c" R CMD SHLIB example_wrap.c
    +R CMD SHLIB example_wrap.c example.c
     

    -The corresponding comments for C++ mode are +The corresponding options for C++ mode are

     swig -c++ -r -o example_wrap.cpp example.i
    -PKG_LIBS="example.cxx" R CMD SHLIB example_wrap.cpp
    +R CMD SHLIB example_wrap.cpp example.cpp
     

    -Note that R is sensitive to the name of the file and to the file -extension in C and C++ mode. The name of the wrapper file must be the -name of the library. Also in C++ mode, the file extension must be .cpp -rather than .cxx for the R compile command to recognize it. +Note that R is sensitive to the names of the files. +The name of the wrapper file must be the +name of the library unless you use the -o option to R when building the library, for example:

    +
    +
    +swig -c++ -r -o example_wrap.cpp example.i
    +R CMD SHLIB -o example.so example_wrap.cpp example.cpp
    +
    +
    + +

    +R is also sensitive to the name of the file +extension in C and C++ mode. In C++ mode, the file extension must be .cpp +rather than .cxx for the R compile command to recognize it. If your C++ code is +in a file using something other than a .cpp extension, then it may still work using PKG_LIBS: +

    + +
    +
    +swig -c++ -r -o example_wrap.cpp example.i
    +PKG_LIBS="example.cxx" R CMD SHLIB -o example example_wrap.cpp
    +
    +
    +

    The commands produces two files. A dynamic shared object file called example.so, or example.dll, and an R wrapper file called example.R. To load these diff --git a/Examples/Makefile.in b/Examples/Makefile.in index cb8b7f4d4..9dee0347f 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1129,11 +1129,11 @@ RRSRC = $(INTERFACE:.i=.R) r: $(SRCS) $(SWIG) -r $(SWIGOPT) $(INTERFACEPATH) - +( PKG_LIBS="$(SRCS)" PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -fPIC -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) ) + +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(SRCS) ) r_cpp: $(CXXSRCS) $(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) - +( PKG_LIBS="$(CXXSRCS)" PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -fPIC -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) ) + +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(SRCS) $(CXXSRCS)) r_clean: rm -f *_wrap* *~ .~* diff --git a/Examples/r/class/Makefile b/Examples/r/class/Makefile index 6bed3ce53..0cd8ed3d3 100644 --- a/Examples/r/class/Makefile +++ b/Examples/r/class/Makefile @@ -3,16 +3,13 @@ SWIG = $(TOP)/../preinst-swig CXXSRCS = example.cxx TARGET = example INTERFACE = example.i -LIBS = -lm -ARGS = SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' all:: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r_cpp clean:: - $(MAKE) -f $(TOP)/Makefile $(ARGS) r_clean + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean check: all R CMD BATCH runme.R diff --git a/Examples/r/simple/Makefile b/Examples/r/simple/Makefile index e01d35925..5ef29565a 100644 --- a/Examples/r/simple/Makefile +++ b/Examples/r/simple/Makefile @@ -3,14 +3,13 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -ARGS = SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' all:: - $(MAKE) -f $(TOP)/Makefile $(ARGS) r + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r clean:: - $(MAKE) -f $(TOP)/Makefile $(ARGS) r_clean + $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean check: all R CMD BATCH runme.R From 9f55943801a5451e7b9367bb3aa76c9913ab8103 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 25 May 2010 18:13:32 +0000 Subject: [PATCH 115/203] Fix RUNTOOL in the test-suite for php and add an example for using RUNTOOL to invoke a debugger git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12050 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Extending.html | 8 ++++++++ Examples/test-suite/common.mk | 7 +++++-- Examples/test-suite/php/Makefile.in | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index ff8751540..bb50d3878 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3469,6 +3469,14 @@ SWIG can be analyzed for bad memory accesses using: make ret_by_value.ctest SWIGTOOL="valgrind --tool=memcheck --trace-children=yes" +

    +A debugger can also be invoked easily on an individual test, for example gdb: +

    + +
    +make ret_by_value.ctest RUNTOOL="gdb --args"
    +
    +

    35.10.13 Documentation

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 1701dd8ba..97708be47 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -29,14 +29,17 @@ # # Note that the RUNTOOL, COMPILETOOL and SWIGTOOL variables can be used # for invoking tools for the runtime tests and target language -# compiler (eg javac) respectively. For example, valgrind can be used -# for memory checking of the runtime tests using: +# compiler (eg javac), and on SWIG respectively. For example, valgrind +# can be used for memory checking of the runtime tests using: # make RUNTOOL="valgrind --leak-check=full" # and valgrind can be used when invoking SWIG using: # make SWIGTOOL="valgrind --tool=memcheck --trace-children=yes" # Note: trace-children needed because of preinst-swig shell wrapper # to the swig executable. # +# An individual test run can be debugged easily: +# make director_string.cpptest RUNTOOL="gdb --args" +# # The variables below can be overridden after including this makefile ####################################################################### diff --git a/Examples/test-suite/php/Makefile.in b/Examples/test-suite/php/Makefile.in index 963051258..bf227da63 100644 --- a/Examples/test-suite/php/Makefile.in +++ b/Examples/test-suite/php/Makefile.in @@ -48,9 +48,9 @@ missingtests: missingcpptests missingctests # found, runs testcase.php, except for multicpptests. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHPSCRIPT=$(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL=$(RUNTOOL) php_run; \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHPSCRIPT=$(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL="$(RUNTOOL)" php_run; \ elif [ -f $(srcdir)/$(SCRIPTPREFIX)$*.php -a ! -f $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list ]; then \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHPSCRIPT=$(srcdir)/$(SCRIPTPREFIX)$*.php RUNTOOL=$(RUNTOOL) php_run; \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHPSCRIPT=$(srcdir)/$(SCRIPTPREFIX)$*.php RUNTOOL="$(RUNTOOL)" php_run; \ fi # Clean: remove the generated .php file From 465373d92d211e64c83c5e4cf405a4974d547452 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 25 May 2010 18:35:21 +0000 Subject: [PATCH 116/203] Fix R keyword warning git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12051 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/director_enum.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/director_enum.i b/Examples/test-suite/director_enum.i index c7932d1dc..e57734e74 100644 --- a/Examples/test-suite/director_enum.i +++ b/Examples/test-suite/director_enum.i @@ -48,7 +48,7 @@ namespace EnumDirector { %inline %{ namespace EnumDirector { -enum FType{ SA = -1, NA=0, EA=1}; +enum FType{ SA = -1, NA_=0, EA=1}; struct A{ A(const double a, const double b, const FType c) @@ -71,7 +71,7 @@ struct B : public A{ %inline %{ namespace EnumDirector { struct A2{ - A2(const FType c = NA) {} + A2(const FType c = NA_) {} virtual ~A2() {} From 08cdb5a7eeae460f52859ea0186ec309454b8e2e Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 25 May 2010 21:46:23 +0000 Subject: [PATCH 117/203] Set string contents when we allocate it for a small efficiency gain. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12052 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/std_string.i | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index 656765194..f6b036bd8 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -71,8 +71,7 @@ namespace std { %typemap(directorout) string & (std::string *temp) %{ convert_to_string_ex($input); - temp = new std::string; - temp->assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); + temp = new std::string(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); swig_acquire_ownership(temp); $result = temp; %} From 9207a2fe37be54d53c03871e6ee7dc2dd4649440 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 25 May 2010 23:38:44 +0000 Subject: [PATCH 118/203] [PHP] Add missing directorin typemap for const std::string &. Fixes SF#3006404 reported by t-Legiaw. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12053 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/php/std_string.i | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 9839e13bc..68b92fbbd 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 2.0.0 (in progress) ============================ +2010-05-25: olly + [PHP] Add missing directorin typemap for const std::string &. + Fixes SF#3006404 reported by t-Legiaw. + 2010-05-23: wsfulton [C#] Fix #2957375 - SWIGStringHelper and SWIGExceptionHelper not always being initialized before use in .NET 4 as the classes were not marked beforefieldinit. diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index f6b036bd8..6eb8ac22a 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -53,6 +53,10 @@ namespace std { ZVAL_STRINGL($result, const_cast($1->data()), $1->size(), 1); %} + %typemap(directorin) const string & %{ + ZVAL_STRINGL($input, const_cast($1_name.data()), $1_name.size(), 1); + %} + %typemap(throws) string %{ SWIG_PHP_Error(E_ERROR, (char *)$1.c_str()); %} From ed98187e3bd3f2e23e1cce128bace99d36ba5c3a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 26 May 2010 00:19:08 +0000 Subject: [PATCH 119/203] Tidy up typemaps, combining variants with the same code. Use const_cast to remove const-ness from const char * for stupid PHP API in %throws typemap. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12054 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/std_string.i | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index 6eb8ac22a..de4e15c4e 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -23,8 +23,8 @@ namespace std { class string; - %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string %{ - $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0; + %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string, const string& %{ + $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0; %} %typemap(in) string %{ @@ -37,15 +37,11 @@ namespace std { $result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); %} - %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) const string& %{ - $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0; - %} - %typemap(out) string %{ ZVAL_STRINGL($result, const_cast($1.data()), $1.size(), 1); %} - %typemap(directorin) string %{ + %typemap(directorin) string, const string& %{ ZVAL_STRINGL($input, const_cast($1_name.data()), $1_name.size(), 1); %} @@ -53,16 +49,8 @@ namespace std { ZVAL_STRINGL($result, const_cast($1->data()), $1->size(), 1); %} - %typemap(directorin) const string & %{ - ZVAL_STRINGL($input, const_cast($1_name.data()), $1_name.size(), 1); - %} - - %typemap(throws) string %{ - SWIG_PHP_Error(E_ERROR, (char *)$1.c_str()); - %} - - %typemap(throws) const string& %{ - SWIG_PHP_Error(E_ERROR, (char *)$1.c_str()); + %typemap(throws) string, const string& %{ + SWIG_PHP_Error(E_ERROR, const_cast($1.c_str())); %} /* These next two handle a function which takes a non-const reference to From 1392a6e497b8cc15b73585620b9f465d905d7a02 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 26 May 2010 07:32:20 +0000 Subject: [PATCH 120/203] [PHP] When using %throws or %catches, SWIG-generated PHP5 wrappers now throw PHP Exception objects instead of giving a PHP error of type E_ERROR. This change shouldn't cause incompatibility issues, since you can't set an error handler for E_ERROR, so previously PHP would just exit which also happens for unhandled exceptions. The benefit is you can now catch them if you want to. Fixes SF#2545578 and SF#2955522. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12055 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 12 ++++++ Examples/test-suite/php/Makefile.in | 9 ++++ .../test-suite/php/exception_order_runme.php | 39 +++++++++++++++++ .../php/threads_exception_runme.php | 43 +++++++++++++++++++ Lib/php/php.swg | 11 ++--- Lib/php/phprun.swg | 1 + Lib/php/std_string.i | 3 +- 7 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 Examples/test-suite/php/exception_order_runme.php create mode 100755 Examples/test-suite/php/threads_exception_runme.php diff --git a/CHANGES.current b/CHANGES.current index 68b92fbbd..b294f9664 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,18 @@ Version 2.0.0 (in progress) ============================ +2010-05-26: olly + [PHP] When using %throws or %catches, SWIG-generated PHP5 wrappers + now throw PHP Exception objects instead of giving a PHP error of + type E_ERROR. + + This change shouldn't cause incompatibility issues, since you can't + set an error handler for E_ERROR, so previously PHP would just exit + which also happens for unhandled exceptions. The benefit is you can + now catch them if you want to. + + Fixes SF#2545578 and SF#2955522. + 2010-05-25: olly [PHP] Add missing directorin typemap for const std::string &. Fixes SF#3006404 reported by t-Legiaw. diff --git a/Examples/test-suite/php/Makefile.in b/Examples/test-suite/php/Makefile.in index bf227da63..5340751e7 100644 --- a/Examples/test-suite/php/Makefile.in +++ b/Examples/test-suite/php/Makefile.in @@ -44,6 +44,15 @@ missingtests: missingcpptests missingctests +$(swig_and_compile_multi_cpp) +$(run_testcase) +# Smart target +%.test: + @echo ' $(C_TEST_CASES) '|grep -F -v ' $* ' >/dev/null ||\ + $(MAKE) $*.ctest + @echo ' $(CPP_TEST_CASES) '|grep -F -v ' $* ' >/dev/null ||\ + $(MAKE) $*.cpptest + @echo ' $(MULTICPP_TEST_CASES) '|grep -F -v ' $* ' >/dev/null ||\ + $(MAKE) $*.multicpptest + # Runs the testcase. Tries to run testcase_runme.php, and if that's not # found, runs testcase.php, except for multicpptests. run_testcase = \ diff --git a/Examples/test-suite/php/exception_order_runme.php b/Examples/test-suite/php/exception_order_runme.php new file mode 100644 index 000000000..a83598170 --- /dev/null +++ b/Examples/test-suite/php/exception_order_runme.php @@ -0,0 +1,39 @@ +foo(); +} catch (Exception $e) { + check::equal($e->getMessage(), 'C++ E1 exception thrown', ''); +} + +try { + $a->bar(); +} catch (Exception $e) { + check::equal($e->getMessage(), 'C++ E2 exception thrown', ''); +} + +try { + $a->foobar(); +} catch (Exception $e) { + check::equal($e->getMessage(), 'postcatch unknown', ''); +} + +try { + $a->barfoo(1); +} catch (Exception $e) { + check::equal($e->getMessage(), 'C++ E1 exception thrown', ''); +} + +try { + $a->barfoo(2); +} catch (Exception $e) { + check::equal($e->getMessage(), 'C++ E2 * exception thrown', ''); +} +?> diff --git a/Examples/test-suite/php/threads_exception_runme.php b/Examples/test-suite/php/threads_exception_runme.php new file mode 100755 index 000000000..31148a1e1 --- /dev/null +++ b/Examples/test-suite/php/threads_exception_runme.php @@ -0,0 +1,43 @@ +unknown(); +} catch (Exception $e) { + check::equal($e->getMessage(), 'C++ A * exception thrown', ''); +} + +try { + $t->simple(); +} catch (Exception $e) { + check::equal($e->getCode(), 37, ''); +} + +try { + $t->message(); +} catch (Exception $e) { + check::equal($e->getMessage(), 'I died.', ''); +} + +try { + $t->hosed(); +} catch (Exception $e) { + check::equal($e->getMessage(), 'C++ Exc exception thrown', ''); +} + +foreach (Array(1,2,3,4) as $i) { + try { + $t->multi($i); + } catch (Exception $e) { + } +} diff --git a/Lib/php/php.swg b/Lib/php/php.swg index ff4001d7e..2471a0992 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -461,18 +461,19 @@ unsigned int, unsigned long, unsigned short { - char error_msg[256]; - sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1); - SWIG_PHP_Error(E_ERROR, error_msg); + zend_throw_exception(NULL, const_cast("C++ $1_type exception thrown"), $1 TSRMLS_CC); + return; } %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{ (void)$1; - SWIG_PHP_Error(E_ERROR, "C++ $1_type exception thrown"); + zend_throw_exception(NULL, const_cast("C++ $1_type exception thrown"), 0 TSRMLS_CC); + return; %} %typemap(throws) char * %{ - SWIG_PHP_Error(E_ERROR, (char *)$1); + zend_throw_exception(NULL, const_cast($1), 0 TSRMLS_CC); + return; %} /* Array reference typemaps */ diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a48a30b20..e76f7033a 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -9,6 +9,7 @@ extern "C" { #endif #include "zend.h" #include "zend_API.h" +#include "zend_exceptions.h" #include "php.h" #include "ext/standard/php_string.h" diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index de4e15c4e..5b82fde53 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -50,7 +50,8 @@ namespace std { %} %typemap(throws) string, const string& %{ - SWIG_PHP_Error(E_ERROR, const_cast($1.c_str())); + zend_throw_exception(NULL, const_cast($1.c_str()), 0 TSRMLS_CC); + return; %} /* These next two handle a function which takes a non-const reference to From 71dddaa2de7298d002a37538e84f5be00cca080c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 26 May 2010 08:21:03 +0000 Subject: [PATCH 121/203] Fix %attribute2ref not to produce a syntax error if the last argument (AccessorMethod) is omitted. Patch from David Piepgras in SF#2235756. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12056 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Lib/typemaps/attribute.swg | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index b294f9664..a1e7ed6e2 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,11 @@ Version 2.0.0 (in progress) ============================ +2010-05-26: olly + Fix %attribute2ref not to produce a syntax error if the last + argument (AccessorMethod) is omitted. Patch from David Piepgras + in SF#2235756. + 2010-05-26: olly [PHP] When using %throws or %catches, SWIG-generated PHP5 wrappers now throw PHP Exception objects instead of giving a PHP error of diff --git a/Lib/typemaps/attribute.swg b/Lib/typemaps/attribute.swg index 4dcf15e2d..214133edc 100644 --- a/Lib/typemaps/attribute.swg +++ b/Lib/typemaps/attribute.swg @@ -221,7 +221,7 @@ #if #AccessorMethod != "" %attribute_custom(Class, AttributeType, AttributeName, AccessorMethod, AccessorMethod, &self_->AccessorMethod(), self_->AccessorMethod() = *val_) #else - %attribute_custom(Class, AttributeType, AccessorMethod, AccessorMethod, AccessorMethod, &self_->AccessorMethod(), self_->AccessorMethod() = *val_) + %attribute_custom(Class, AttributeType, AccessorName, AccessorName, AccessorName, &self_->AccessorName(), self_->AccessorName() = *val_) #endif %enddef From 7b2c6b477abff9a81da8b10549ed9a758ad7a2ef Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 26 May 2010 19:01:12 +0000 Subject: [PATCH 122/203] Fix segfault attempting illegal javaclassname and csclassname special variable substitution git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12058 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp_typemaps.i | 9 +++++++++ Examples/test-suite/java_typemaps_typewrapper.i | 7 +++++++ Source/Modules/csharp.cxx | 6 ++++-- Source/Modules/java.cxx | 6 ++++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/csharp_typemaps.i b/Examples/test-suite/csharp_typemaps.i index dcef278f6..b940f25a3 100644 --- a/Examples/test-suite/csharp_typemaps.i +++ b/Examples/test-suite/csharp_typemaps.i @@ -101,3 +101,12 @@ Number times12(const Number* num) { %inline %{ int myInt = 0; %} + + +// Illegal special variable crash +%typemap(cstype) WasCrashing "$csclassname /*cstype $*csclassname*/" // $*csclassname was causing crash +%inline %{ +struct WasCrashing {}; +void hoop(WasCrashing was) {} +%} + diff --git a/Examples/test-suite/java_typemaps_typewrapper.i b/Examples/test-suite/java_typemaps_typewrapper.i index 8c772ae81..a99ca7b65 100644 --- a/Examples/test-suite/java_typemaps_typewrapper.i +++ b/Examples/test-suite/java_typemaps_typewrapper.i @@ -63,3 +63,10 @@ class Farewell {}; Greeting* solong(Farewell* f) { return NULL; } %} +// Illegal special variable crash +%typemap(jstype) WasCrashing "$javaclassname /*jstype $*javaclassname*/" // $*javaclassname was causing crash +%inline %{ +struct WasCrashing {}; +void hoop(WasCrashing was) {} +%} + diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index ba8f34b47..e1c8d5415 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3085,8 +3085,10 @@ public: if (Strstr(tm, "$*csclassname")) { SwigType *classnametype = Copy(strippedtype); Delete(SwigType_pop(classnametype)); - substituteClassnameSpecialVariable(classnametype, tm, "$*csclassname"); - substitution_performed = true; + if (Len(classnametype) > 0) { + substituteClassnameSpecialVariable(classnametype, tm, "$*csclassname"); + substitution_performed = true; + } Delete(classnametype); } if (Strstr(tm, "$&csclassname")) { diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 8c4770a9e..11cfe8184 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -2943,8 +2943,10 @@ public: if (Strstr(tm, "$*javaclassname")) { SwigType *classnametype = Copy(strippedtype); Delete(SwigType_pop(classnametype)); - substituteClassnameSpecialVariable(classnametype, tm, "$*javaclassname", jnidescriptor); - substitution_performed = true; + if (Len(classnametype) > 0) { + substituteClassnameSpecialVariable(classnametype, tm, "$*javaclassname", jnidescriptor); + substitution_performed = true; + } Delete(classnametype); } if (Strstr(tm, "$&javaclassname")) { From e2ce97f397c7d59d2d99ee3907dd5db930a9287e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 26 May 2010 23:22:49 +0000 Subject: [PATCH 123/203] Add the ability for special variable macros to call other special variable macros. Also added additional diagnostics when using -debug-tmsearch. Add tests for std::vector of shared_ptr. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12059 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 27 +++++++++++++++++++ .../csharp/li_boost_shared_ptr_bits_runme.cs | 17 ++++++++++++ .../java/li_boost_shared_ptr_bits_runme.java | 24 +++++++++++++++++ .../test-suite/li_boost_shared_ptr_bits.i | 25 +++++++++++++++++ .../python/li_boost_shared_ptr_bits_runme.py | 11 ++++++++ Source/Swig/typemap.c | 17 ++++++++---- 6 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs create mode 100644 Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java diff --git a/CHANGES.current b/CHANGES.current index a1e7ed6e2..c52179d45 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,33 @@ Version 2.0.0 (in progress) ============================ +2010-05-27: wsfulton + Add the ability for $typemap special variable macros to call other $typemap + special variable macros, for example: + + %typemap(cstype) CC "CC" + %typemap(cstype) BB "$typemap(cstype, CC)" + %typemap(cstype) AA "$typemap(cstype, BB)" + void hah(AA aa); + + This also fixes C# std::vector containers of shared_ptr and %shared_ptr. + + Also added diagnostics for $typemap with -debug-tmsearch, for example, the + above displays additional diagnostic lines starting "Containing: ": + + example.i:34: Searching for a suitable 'cstype' typemap for: AA aa + Looking for: AA aa + Looking for: AA + Using: %typemap(cstype) AA + Containing: $typemap(cstype, BB) + example.i:31: Searching for a suitable 'cstype' typemap for: BB + Looking for: BB + Using: %typemap(cstype) BB + Containing: $typemap(cstype, CC) + example.i:29: Searching for a suitable 'cstype' typemap for: CC + Looking for: CC + Using: %typemap(cstype) CC + 2010-05-26: olly Fix %attribute2ref not to produce a syntax error if the last argument (AccessorMethod) is omitted. Patch from David Piepgras diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs new file mode 100644 index 000000000..2b8c84e1b --- /dev/null +++ b/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs @@ -0,0 +1,17 @@ +using System; +using li_boost_shared_ptr_bitsNamespace; + +public class runme +{ + static void Main() + { + VectorIntHolder v = new VectorIntHolder(); + v.Add(new IntHolder(11)); + v.Add(new IntHolder(22)); + v.Add(new IntHolder(33)); + + int sum = li_boost_shared_ptr_bits.sum(v); + if (sum != 66) + throw new ApplicationException("sum is wrong"); + } +} diff --git a/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java new file mode 100644 index 000000000..ffa0c5e64 --- /dev/null +++ b/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java @@ -0,0 +1,24 @@ +import li_boost_shared_ptr_bits.*; + +public class li_boost_shared_ptr_bits_runme { + static { + try { + System.loadLibrary("li_boost_shared_ptr_bits"); + } 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[]) + { + VectorIntHolder v = new VectorIntHolder(); + v.add(new IntHolder(11)); + v.add(new IntHolder(22)); + v.add(new IntHolder(33)); + + int sum = li_boost_shared_ptr_bits.sum(v); + if (sum != 66) + throw new RuntimeException("sum is wrong"); + } +} diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i index 4e144093e..b43e1b137 100644 --- a/Examples/test-suite/li_boost_shared_ptr_bits.i +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -23,3 +23,28 @@ struct NonDynamic { boost::shared_ptr boing(boost::shared_ptr b) { return b; } %} +// vector of shared_ptr +%include "std_vector.i" + +#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) + +%shared_ptr(IntHolder); + +#endif + +%inline %{ +#include "boost/shared_ptr.hpp" +struct IntHolder { + int val; + IntHolder(int a) : val(a) {} +}; +int sum(std::vector< boost::shared_ptr > v) { + int sum = 0; + for (size_t i=0; ival; + return sum; +} +%} + +%template(VectorIntHolder) std::vector< boost::shared_ptr >; + diff --git a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py index c6bd2f97a..9e5668e57 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py @@ -18,3 +18,14 @@ check(nd) b = boing(nd) check(b) +################################ + +v = VectorIntHolder() +v.push_back(IntHolder(11)) +v.push_back(IntHolder(22)) +v.push_back(IntHolder(33)) + +sum = sum(v) +if sum != 66: + raise "sum is wrong" + diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 2bf806e66..607ab6d10 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1940,10 +1940,16 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper #ifdef SWIG_DEBUG Printf(stdout, "Swig_typemap_attach_parms: embedded\n"); #endif - if (!already_substituting) { - already_substituting = 1; + if (already_substituting < 10) { + already_substituting++; + if ((in_typemap_search_multi == 0) && typemap_search_debug) { + String *dtypemap = NewString(dollar_typemap); + Replaceall(dtypemap, "$TYPEMAP", "$typemap"); + Printf(stdout, " Containing: %s\n", dtypemap); + Delete(dtypemap); + } Swig_typemap_attach_parms(tmap_method, to_match_parms, f); - already_substituting = 0; + already_substituting--; /* Look for the typemap code */ attr = NewStringf("tmap:%s", tmap_method); @@ -1974,10 +1980,11 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper } Delete(attr); } else { - /* simple recursive call check, but prevents using an embedded typemap that contains another embedded typemap */ + /* Simple recursive call check to prevent infinite recursion - this strategy only allows a limited + * number of calls by a embedded typemaps to other embedded typemaps though */ String *dtypemap = NewString(dollar_typemap); Replaceall(dtypemap, "$TYPEMAP", "$typemap"); - Swig_error(Getfile(s), Getline(s), "Recursive $typemap calls not supported - %s\n", dtypemap); + Swig_error(Getfile(s), Getline(s), "Likely recursive $typemap calls containing %s. Use -debug-tmsearch to debug.\n", dtypemap); Delete(dtypemap); } syntax_error = 0; From 00d07a77c153650b75766ade8058e3ae01e484c0 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 27 May 2010 07:14:20 +0000 Subject: [PATCH 124/203] Fix a couple of typos git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12060 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 509484e2f..cad14004b 100644 --- a/CHANGES +++ b/CHANGES @@ -956,7 +956,7 @@ Version 1.3.35 (7 April 2008) 03/17/2008: olly Fix memory leak in SWIG's parser (based on patch from Russell - Bryant in SF#1914023).` + Bryant in SF#1914023). 03/12/2008: wsfulton Fix bug #1878285 - unnecessary cast for C struct creation wrappers. @@ -8256,7 +8256,7 @@ Version 1.3.22 (September 4, 2004) When needed, use %inlcude std_string.i // 'char' strings - %inlcude std_wstring.i // 'wchar_t; strings + %inlcude std_wstring.i // 'wchar_t' strings 04/10/2004: mmatus (Marcelo Matus) From 5dfa9c048da9e45e42c8b61164e4c950caccaf80 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 27 May 2010 20:12:58 +0000 Subject: [PATCH 125/203] some warning fixes on solaris git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12061 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/global_scope_types.i | 2 +- Examples/test-suite/typemap_global_scope.i | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/global_scope_types.i b/Examples/test-suite/global_scope_types.i index 4c73dfa72..05aa43b77 100644 --- a/Examples/test-suite/global_scope_types.i +++ b/Examples/test-suite/global_scope_types.i @@ -39,6 +39,6 @@ namespace Spac { } -void funcptrtest( void (*)(::Dingaling) ) {} +extern "C" void funcptrtest( void (*)(::Dingaling) ) {} %} diff --git a/Examples/test-suite/typemap_global_scope.i b/Examples/test-suite/typemap_global_scope.i index 92170363f..421ed9dd0 100644 --- a/Examples/test-suite/typemap_global_scope.i +++ b/Examples/test-suite/typemap_global_scope.i @@ -12,7 +12,7 @@ // Structs ///////////////////////////////////////////////////////////////////// -%typemap(in) Test1, ::Test2, Space::Test3, ::Space::Test4 "/*in typemap for $type*/" +%typemap(in) Test1, ::Test2, Space::Test3, ::Space::Test4 "$1 = $type(); /*in typemap for $type*/" %typemap(in) const Test1 &, const ::Test2 &, const Space::Test3 &, const ::Space::Test4 & "/*in typemap for $type*/" %inline %{ struct Test1 {}; @@ -55,7 +55,7 @@ namespace Space { struct XX {}; %} -%typemap(in) TemplateTest1< ::XX >, ::TemplateTest2< ::XX >, Space::TemplateTest3< ::XX >, ::Space::TemplateTest4< ::XX > "/* in typemap for $type */" +%typemap(in) TemplateTest1< ::XX >, ::TemplateTest2< ::XX >, Space::TemplateTest3< ::XX >, ::Space::TemplateTest4< ::XX > "$1 = $type(); /* in typemap for $type */" %typemap(in) const TemplateTest1< XX > &, const ::TemplateTest2< XX > &, const Space::TemplateTest3< XX > &, const ::Space::TemplateTest4< XX > & "/* in typemap for $type */" %inline %{ template struct TemplateTest1 { T m_t; }; @@ -99,7 +99,7 @@ namespace Space { // Enums ///////////////////////////////////////////////////////////////////// -%typemap(in) Enum1, ::Enum2, Space::Enum3, ::Space::Enum4 "/*in typemap for $type*/" +%typemap(in) Enum1, ::Enum2, Space::Enum3, ::Space::Enum4 "$1 = $1_type(); /*in typemap for $type*/" %typemap(in) const Enum1 &, const ::Enum2 &, const Space::Enum3 &, const ::Space::Enum4 & "/*in typemap for $type*/" %inline %{ enum Enum1 { enum_1 }; From bb41eeb343e956da1a0e76480a6f259ac5525b34 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 27 May 2010 20:55:24 +0000 Subject: [PATCH 126/203] Fix potential name clashes with symbols in the Director class git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12062 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/director.swg | 12 ++++++------ Lib/python/director.swg | 20 ++++++++++---------- Lib/ruby/director.swg | 16 ++++++++-------- Source/Modules/php.cxx | 2 +- Source/Modules/python.cxx | 12 ++++++------ 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 5c1d8d08f..163cd7fb6 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -100,19 +100,19 @@ namespace Swig { class Director { protected: zval *swig_self; - typedef std::map ownership_map; - mutable ownership_map owner; + typedef std::map swig_ownership_map; + mutable swig_ownership_map swig_owner; public: Director(zval* self) : swig_self(self) { } ~Director() { - for (ownership_map::iterator i = owner.begin(); i != owner.end(); i++) { - owner.erase(i); + for (swig_ownership_map::iterator i = swig_owner.begin(); i != swig_owner.end(); i++) { + swig_owner.erase(i); } } - bool is_overriden_method(char *cname, char *lc_fname) { + bool swig_is_overridden_method(char *cname, char *lc_fname) { zval classname; zend_class_entry **ce; zend_function *mptr; @@ -133,7 +133,7 @@ namespace Swig { void swig_acquire_ownership(Type *vptr) const { if (vptr) { - owner[vptr] = new GCItem_T(vptr); + swig_owner[vptr] = new GCItem_T(vptr); } } }; diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 8514365a9..fcd174711 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -404,17 +404,17 @@ namespace Swig { } /* methods to implement pseudo protected director members */ - virtual bool swig_get_inner(const char* /* name */) const { + virtual bool swig_get_inner(const char* /* protected_method_name */) const { return true; } - virtual void swig_set_inner(const char* /* name */, bool /* val */) const { + virtual void swig_set_inner(const char* /* protected_method_name */, bool /* val */) const { } /* ownership management */ private: - typedef std::map ownership_map; - mutable ownership_map owner; + typedef std::map swig_ownership_map; + mutable swig_ownership_map swig_owner; #ifdef __THREAD__ static PyThread_type_lock swig_mutex_own; #endif @@ -425,7 +425,7 @@ namespace Swig { { if (vptr) { SWIG_GUARD(swig_mutex_own); - owner[vptr] = new GCArray_T(vptr); + swig_owner[vptr] = new GCArray_T(vptr); } } @@ -434,7 +434,7 @@ namespace Swig { { if (vptr) { SWIG_GUARD(swig_mutex_own); - owner[vptr] = new GCItem_T(vptr); + swig_owner[vptr] = new GCItem_T(vptr); } } @@ -442,7 +442,7 @@ namespace Swig { { if (vptr && own) { SWIG_GUARD(swig_mutex_own); - owner[vptr] = new GCItem_Object(own); + swig_owner[vptr] = new GCItem_Object(own); } } @@ -451,10 +451,10 @@ namespace Swig { int own = 0; if (vptr) { SWIG_GUARD(swig_mutex_own); - ownership_map::iterator iter = owner.find(vptr); - if (iter != owner.end()) { + swig_ownership_map::iterator iter = swig_owner.find(vptr); + if (iter != swig_owner.end()) { own = iter->second->get_own(); - owner.erase(iter); + swig_owner.erase(iter); } } return own; diff --git a/Lib/ruby/director.swg b/Lib/ruby/director.swg index cdc4baea1..9807b11bb 100644 --- a/Lib/ruby/director.swg +++ b/Lib/ruby/director.swg @@ -327,8 +327,8 @@ namespace Swig { /* ownership management */ private: - typedef std::map ownership_map; - mutable ownership_map owner; + typedef std::map swig_ownership_map; + mutable swig_ownership_map swig_owner; #ifdef __PTHREAD__ static pthread_mutex_t swig_mutex_own; #endif @@ -339,7 +339,7 @@ namespace Swig { { if (vptr) { SWIG_GUARD(swig_mutex_own); - owner[vptr] = new GCArray_T(vptr); + swig_owner[vptr] = new GCArray_T(vptr); } } @@ -348,7 +348,7 @@ namespace Swig { { if (vptr) { SWIG_GUARD(swig_mutex_own); - owner[vptr] = new GCItem_T(vptr); + swig_owner[vptr] = new GCItem_T(vptr); } } @@ -356,7 +356,7 @@ namespace Swig { { if (vptr && own) { SWIG_GUARD(swig_mutex_own); - owner[vptr] = new GCItem_Object(own); + swig_owner[vptr] = new GCItem_Object(own); } } @@ -365,10 +365,10 @@ namespace Swig { ruby_owntype own = 0; if (vptr) { SWIG_GUARD(swig_mutex_own); - ownership_map::iterator iter = owner.find(vptr); - if (iter != owner.end()) { + swig_ownership_map::iterator iter = swig_owner.find(vptr); + if (iter != swig_owner.end()) { own = iter->second->get_own(); - owner.erase(iter); + swig_owner.erase(iter); } } return own; diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index c6f01c3e3..bd751f767 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -799,7 +799,7 @@ public: 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->is_overriden_method((char *)\"%s\", (char *)\"%s\");\n", + Printf(f->code, "upcall = !director->swig_is_overridden_method((char *)\"%s\", (char *)\"%s\");\n", Swig_class_name(Swig_methodclass(n)), name); } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 93679084c..42a6b234f 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -2721,15 +2721,15 @@ public: Printf(f_directors_h, "\n\n"); Printf(f_directors_h, "/* Internal Director utilities */\n"); Printf(f_directors_h, "public:\n"); - Printf(f_directors_h, " bool swig_get_inner(const char* name) const {\n"); - Printf(f_directors_h, " std::map::const_iterator iv = inner.find(name);\n"); - Printf(f_directors_h, " return (iv != inner.end() ? iv->second : false);\n"); + Printf(f_directors_h, " bool swig_get_inner(const char* protected_method_name) const {\n"); + Printf(f_directors_h, " std::map::const_iterator iv = swig_inner.find(protected_method_name);\n"); + Printf(f_directors_h, " return (iv != swig_inner.end() ? iv->second : false);\n"); Printf(f_directors_h, " }\n\n"); - Printf(f_directors_h, " void swig_set_inner(const char* name, bool val) const\n"); - Printf(f_directors_h, " { inner[name] = val;}\n\n"); + Printf(f_directors_h, " void swig_set_inner(const char* protected_method_name, bool val) const\n"); + Printf(f_directors_h, " { swig_inner[protected_method_name] = val;}\n\n"); Printf(f_directors_h, "private:\n"); - Printf(f_directors_h, " mutable std::map inner;\n"); + Printf(f_directors_h, " mutable std::map swig_inner;\n"); } if (director_method_index) { From 5bcfc81c12f6cc081da5519fed9664735ab77405 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 27 May 2010 20:59:29 +0000 Subject: [PATCH 127/203] Fix potential name clashes with symbols in the Director class git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12063 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 8013dcb6e..5b90d91b3 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1132,24 +1132,24 @@ namespace Swig { namespace Swig { class Director { octave_swig_type *self; - bool disowned; + bool swig_disowned; Director(const Director &x); Director &operator=(const Director &rhs); public: - Director(void *vptr):self(0), disowned(false) { + Director(void *vptr):self(0), swig_disowned(false) { set_rtdir(vptr, this); } ~Director() { swig_director_destroyed(self, this); - if (disowned) + if (swig_disowned) self->decref(); } void swig_set_self(octave_swig_type *new_self) { - assert(!disowned); + assert(!swig_disowned); self = new_self; } @@ -1158,9 +1158,9 @@ namespace Swig { } void swig_disown() { - if (disowned) + if (swig_disowned) return; - disowned = true; + swig_disowned = true; self->incref(); } }; From 45f20c73635e64ebcb8cb776075234aebcb3bdc1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 May 2010 22:24:11 +0000 Subject: [PATCH 128/203] Fix constants wrapper warnings for visual c++ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12064 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 2 +- Source/Modules/java.cxx | 2 +- Source/Modules/modula3.cxx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index e1c8d5415..8ffd9768a 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -941,7 +941,7 @@ public: // below based on Swig_VargetToFunction() SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); - Setattr(n, "wrap:action", NewStringf("result = (%s) %s;", SwigType_lstr(ty, 0), Getattr(n, "value"))); + Setattr(n, "wrap:action", NewStringf("result = (%s)(%s);", SwigType_lstr(ty, 0), Getattr(n, "value"))); } Swig_director_emit_dynamic_cast(n, f); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 11cfe8184..4a6abd569 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1024,7 +1024,7 @@ public: // below based on Swig_VargetToFunction() SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); - Setattr(n, "wrap:action", NewStringf("result = (%s) %s;", SwigType_lstr(ty, 0), Getattr(n, "value"))); + Setattr(n, "wrap:action", NewStringf("result = (%s)(%s);", SwigType_lstr(ty, 0), Getattr(n, "value"))); } // Now write code to make the function call diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index fc26dff85..602b43d4f 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -1422,7 +1422,7 @@ MODULA3(): // below based on Swig_VargetToFunction() SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); - Setattr(n, "wrap:action", NewStringf("result = (%s) %s;", SwigType_lstr(ty, 0), Getattr(n, "value"))); + Setattr(n, "wrap:action", NewStringf("result = (%s)(%s);", SwigType_lstr(ty, 0), Getattr(n, "value"))); } Setattr(n, "wrap:name", wname); From 859cfff732b9deefaad6b4d7e14ad6abd7820056 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 May 2010 22:46:50 +0000 Subject: [PATCH 129/203] chapter numbering update git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12065 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 7 ++----- Doc/Manual/Modula3.html | 4 +++- Doc/Manual/Typemaps.html | 7 ++++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 242b86429..549f6da3d 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -351,8 +351,8 @@
  • Basic matching rules
  • Typedef reductions matching
  • Default typemap matching rules -
  • Matching comparison with C++ templates
  • Multi-arguments typemaps +
  • Matching rules compared to C++ templates
  • Debugging typemap pattern matching
  • Code generation rules @@ -963,10 +963,7 @@
    • Overview
    • Conception
    • Code generation rules @@ -1418,7 +1418,7 @@ Finally the best way to view the typemap matching rules in action is via the -

      10.3.5 Multi-arguments typemaps

      +

      10.3.4 Multi-arguments typemaps

      @@ -1448,7 +1448,8 @@ but all subsequent arguments must match exactly.

      -

      10.3.4 Matching rules compared to C++ templates

      +

      10.3.5 Matching rules compared to C++ templates

      +

      For those intimately familiar with C++ templates, a comparison of the typemap matching rules and template type deduction is interesting. From 6eb118801ef75995e531a9fd6158c93149e88c03 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 May 2010 23:42:53 +0000 Subject: [PATCH 130/203] Update autoconf links git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12066 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Introduction.html | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html index 4b954040b..3bac9484e 100644 --- a/Doc/Manual/Introduction.html +++ b/Doc/Manual/Introduction.html @@ -37,7 +37,7 @@

      SWIG is a software development tool that simplifies the task of interfacing different languages to C and C++ programs. In a -nutshell, SWIG is a compiler that takes C declarations and creates +nutshell, SWIG is a compiler that takes C/C++ declarations and creates the wrappers needed to access those declarations from other languages including including Perl, Python, Tcl, Ruby, Guile, and Java. SWIG normally requires no modifications to existing code and can often be used to @@ -68,7 +68,8 @@ a dedicated IDL compiler). Although this style of development isn't appropriate for every project, it is particularly well suited to software development in the small; especially the research and development work that is commonly found -in scientific and engineering projects. +in scientific and engineering projects. However, nowadays SWIG is known to be used in many +large open source and commercial projects.

      2.2 Why use SWIG?

      @@ -375,10 +376,10 @@ If you are using the GNU Autotools Automake/ Libtool) to configure SWIG use in your project, the SWIG Autoconf macros can be used. -The primary macro is ac_pkg_swig, see -http://www.gnu.org/software/ac-archive/htmldoc/ac_pkg_swig.html. -The ac_python_devel macro is also helpful for generating Python extensions. See the -Autoconf Macro Archive +The primary macro is ax_pkg_swig, see +http://www.gnu.org/software/autoconf-archive/ax_pkg_swig.html#ax_pkg_swig. +The ax_python_devel macro is also helpful for generating Python extensions. See the +Autoconf Archive for further information on this and other Autoconf macros.

      From 8e496434d195d61ae3ee608e8a3dd8ff4abfc696 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 28 May 2010 23:53:49 +0000 Subject: [PATCH 131/203] Update docs for first 2.0 release git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12067 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Guile.html | 2 - Doc/Manual/Preface.html | 81 +++++++++++++--------------------------- Doc/Manual/Sections.html | 21 +---------- Doc/Manual/Windows.html | 4 +- 4 files changed, 29 insertions(+), 79 deletions(-) diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index cc063c436..8f3c5f85c 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -767,8 +767,6 @@ guile-modules. For example,

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

      TODO: Renaming class name prefixes?

      -

      20.10.2 Linking

      diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index 630657a9a..ae2e1b7d9 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -49,31 +49,19 @@ has since evolved into a general purpose tool that is used in a wide variety of applications--in fact almost anything where C/C++ programming is involved. -

      1.2 Special Introduction for Version 1.3

      - - -

      -Since SWIG was released in 1996, its user base and applicability has -continued to grow. Although its rate of development has varied, an -active development effort has continued to make improvements to the -system. Today, nearly a dozen developers are working to create -SWIG-2.0---a system that aims to provide wrapping support for nearly -all of the ANSI C++ standard and approximately ten target languages -including Guile, Java, Mzscheme, Ocaml, Perl, Pike, PHP, Python, Ruby, -and Tcl. -

      -

      1.3 SWIG Versions

      -For several years, the most stable version of SWIG has been release -1.1p5. Starting with version 1.3, a new version numbering scheme has -been adopted. Odd version numbers (1.3, 1.5, etc.) represent -development versions of SWIG. Even version numbers (1.4, 1.6, etc.) -represent stable releases. Currently, developers are working to -create a stable SWIG-2.0 release. Don't let the development status -of SWIG-1.3 scare you---it is much more stable (and capable) than SWIG-1.1p5. +In the late 1990's, the most stable version of SWIG was release +1.1p5. Versions 1.3.x were officially development versions and these were released +over a period of 10 years starting from the year 2000. The final version in the 1.3.x +series was 1.3.40, but in truth the 1.3.x series had been stable for many years. +An official stable version was released along with the decision to make SWIG +license changes and this gave rise to version 2.0.0 in 2010. The license was clarified +so that the code that SWIG generated could be distributed +under license terms of the user's choice/requirements and at the same time the SWIG +source was placed under the GNU General Public License version 3.

      1.4 SWIG resources

      @@ -106,7 +94,7 @@ SWIG along with information about beta releases and future work.

      -SVN access to the latest version of SWIG is also available. More information +Subversion access to the latest version of SWIG is also available. More information about this can be obtained at:

      @@ -132,7 +120,7 @@ writing a normal C program.

      -Recent SWIG releases have become significantly more capable in +Over time SWIG releases have become significantly more capable in their C++ handling--especially support for advanced features like namespaces, overloaded operators, and templates. Whenever possible, this manual tries to cover the technicalities of this interface. @@ -149,8 +137,7 @@ provide an overview of its capabilities. The remaining chapters are devoted to specific SWIG language modules and are self contained. Thus, if you are using SWIG to build Python interfaces, you can probably skip to that chapter and find almost everything you need -to know. Caveat: we are currently working on a documentation rewrite and many -of the older language module chapters are still somewhat out of date. +to know.

      1.7 How to avoid reading the manual

      @@ -165,24 +152,19 @@ The SWIG distribution also comes with a large directory of examples that illustrate different topics.

      -

      1.8 Backwards Compatibility

      +

      1.8 Backwards compatibility

      -If you are a previous user of SWIG, don't expect recent versions of -SWIG to provide backwards compatibility. In fact, backwards -compatibility issues may arise even between successive 1.3.x releases. -Although these incompatibilities are regrettable, SWIG-1.3 is an active -development project. The primary goal of this effort is to make SWIG +If you are a previous user of SWIG, don't expect +SWIG to provide complete backwards compatibility. +Although the developers strive to the utmost to keep backwards compatibility, +this isn't always possible as the +primary goal over time is to make SWIG better---a process that would simply be impossible if the developers are constantly bogged down with backwards compatibility issues. -

      - -

      -On a positive note, a few incompatibilities are a small price to pay -for the large number of new features that have been -added---namespaces, templates, smart pointers, overloaded methods, -operators, and more. +Potential incompatibilities are clearly marked in the detailed release notes +(CHANGES files).

      @@ -211,26 +193,15 @@ wrapper file. The SWIG preprocessor has defined SWIG_VERSION since SWIG-1.3.11.

      SWIG is an unfunded project that would not be possible without the -contributions of many people. Most recent SWIG development has been -supported by Matthias Köppe, William Fulton, Lyle Johnson, -Richard Palmer, Thien-Thi Nguyen, Jason Stewart, Loic Dachary, Masaki -Fukushima, Luigi Ballabio, Sam Liddicott, Art Yerkes, Marcelo Matus, -Harco de Hilster, John Lenz, and Surendra Singhi. +contributions of many people working in their spare time. +If you have benefitted from using SWIG, please consider +Donating to SWIG to keep development going. +There have been a large varied number of people +who have made contributions at all levels over time. Contributors +are mentioned either in the COPYRIGHT file or CHANGES files shipped with SWIG or in submitted bugs.

      -Historically, the following people contributed to early versions of SWIG. -Peter Lomdahl, Brad Holian, Shujia Zhou, Niels Jensen, and Tim Germann -at Los Alamos National Laboratory were the first users. Patrick -Tullmann at the University of Utah suggested the idea of automatic -documentation generation. John Schmidt and Kurtis Bleeker at the -University of Utah tested out the early versions. Chris Johnson -supported SWIG's developed at the University of Utah. John Buckman, -Larry Virden, and Tom Schwaller provided valuable input on the first -releases and improving the portability of SWIG. David Fletcher and -Gary Holt have provided a great deal of input on improving SWIG's -Perl5 implementation. Kevin Butler contributed the first Windows NT -port.

      1.10 Bug reports

      diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index e26e4d31d..2d795595c 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -4,20 +4,12 @@ SWIG-1.3 Documentation -

      SWIG-1.3 Development Documentation

      +

      SWIG-2.0 Documentation

      Last update : SWIG-2.0.0 (in progress)

      Sections

      -

      -The SWIG documentation is being updated to reflect new SWIG -features and enhancements. However, this update process is not quite -finished--there is a lot of old SWIG-1.1 documentation and it is taking -some time to update all of it. Please pardon our dust (or volunteer -to help!). -

      -

      SWIG Core Documentation

      -

      Documentation that has not yet been updated

      - -

      -This documentation has not been completely updated from SWIG-1.1, but most of the topics -still apply to the current release. Make sure you read the -SWIG Basics chapter before reading -any of these chapters. Also, SWIG-1.3.10 features extensive changes to the -implementation of typemaps. Make sure you read the Typemaps -chapter above if you are using this feature. -

      - diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index e295fe307..da8a5d6bf 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -67,7 +67,7 @@ SWIG does not come with the usual Windows type installation program, however it

      -The swigwin distribution contains the SWIG Windows executable, swig.exe, which will run on 32 bit versions of Windows, ie Windows 95/98/ME/NT/2000/XP. +The swigwin distribution contains the SWIG Windows executable, swig.exe, which will run on 32 bit versions of Windows, ie Windows 95 and later. If you want to build your own swig.exe have a look at Building swig.exe on Windows.

      @@ -78,7 +78,7 @@ If you want to build your own swig.exe have a look at diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 366736eb7..c5778c432 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -1098,6 +1098,7 @@ Typesafe enums have their advantages over using plain integers in that they can However, there are limitations. For example, they cannot be used in switch statements and serialization is an issue. Please look at the following references for further information: + http://java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums Replace Enums with Classes in Effective Java Programming on the Sun website, Create enumerated constants in Java JavaWorld article, Java Tip 133: More on typesafe enums and @@ -2360,7 +2361,7 @@ See The intermediary JNI class pragmas secti

      A Java proxy class is generated for each structure, union or C++ class that is wrapped. -Proxy classes have also been called peer classes. +Proxy classes have also been called peer classes. The default proxy class for our previous example looks like this:

      diff --git a/Doc/Manual/Modules.html b/Doc/Manual/Modules.html index 5ce448ce6..69cc58c30 100644 --- a/Doc/Manual/Modules.html +++ b/Doc/Manual/Modules.html @@ -244,7 +244,7 @@ is empty. Only modules compiled with the same pair will share type information.

      15.4 External access to the runtime

      -

      As described in The run-time type checker, +

      As described in The run-time type checker, the functions SWIG_TypeQuery, SWIG_NewPointerObj, and others sometimes need to be called. Calling these functions from a typemap is supported, since the typemap code is embedded into the _wrap.c file, which has those declarations available. If you need diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index ae2e1b7d9..2680328dd 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -11,13 +11,12 @@

      @@ -49,7 +48,7 @@ has since evolved into a general purpose tool that is used in a wide variety of applications--in fact almost anything where C/C++ programming is involved. -

      1.3 SWIG Versions

      +

      1.2 SWIG Versions

      @@ -64,7 +63,7 @@ under license terms of the user's choice/requirements and at the same time the S source was placed under the GNU General Public License version 3.

      -

      1.4 SWIG resources

      +

      1.3 SWIG resources

      @@ -103,7 +102,7 @@ about this can be obtained at:

      -

      1.5 Prerequisites

      +

      1.4 Prerequisites

      @@ -128,7 +127,7 @@ However, this isn't meant to be a tutorial on C++ programming. For many of the gory details, you will almost certainly want to consult a good C++ reference. If you don't program in C++, you may just want to skip those parts of the manual. -

      1.6 Organization of this manual

      +

      1.5 Organization of this manual

      @@ -140,7 +139,7 @@ can probably skip to that chapter and find almost everything you need to know.

      -

      1.7 How to avoid reading the manual

      +

      1.6 How to avoid reading the manual

      @@ -152,7 +151,7 @@ The SWIG distribution also comes with a large directory of examples that illustrate different topics.

      -

      1.8 Backwards compatibility

      +

      1.7 Backwards compatibility

      @@ -188,7 +187,7 @@ Note: The version symbol is not defined in the generated SWIG wrapper file. The SWIG preprocessor has defined SWIG_VERSION since SWIG-1.3.11.

      -

      1.9 Credits

      +

      1.8 Credits

      @@ -203,7 +202,7 @@ are mentioned either in the COPYRIGHT file or CHANGES files shipped with SWIG or

      -

      1.10 Bug reports

      +

      1.9 Bug reports

      From 27056fbd9f7e246aea3a6f85dcd0304679f5210e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 29 May 2010 21:24:08 +0000 Subject: [PATCH 133/203] Tidy up for first 2.0 release. Move release notes summary into new file RELEASENOTES git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12069 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 13 +- COPYRIGHT | 13 ++ FUTURE | 335 ----------------------------------------------- Misc/fileheader | 10 -- NEW | 267 ------------------------------------- README | 342 ++++-------------------------------------------- RELEASENOTES | 223 +++++++++++++++++++++++++++++++ swig.spec.in | 2 +- 8 files changed, 268 insertions(+), 937 deletions(-) delete mode 100644 FUTURE delete mode 100644 Misc/fileheader delete mode 100644 NEW create mode 100644 RELEASENOTES diff --git a/ANNOUNCE b/ANNOUNCE index 2595f7a55..1327eb124 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -2,13 +2,10 @@ http://www.swig.org - -We're pleased to announce SWIG-2.0.0, the latest installment in the -SWIG development effort. SWIG-2.0.0 includes a number of bug fixes -and enhancements. +We're pleased to announce SWIG-2.0.0, the latest SWIG release. What is SWIG? -------------- +============= SWIG is a software development tool that reads C/C++ header files and generates the wrapper code needed to make C and C++ code accessible @@ -20,8 +17,8 @@ SWIG include generation of scripting language extension modules, rapid prototyping, testing, and user interface development for large C/C++ systems. -Availability: -------------- +Availability +============ The release is available for download on Sourceforge at http://prdownloads.sourceforge.net/swig/swig-2.0.0.tar.gz @@ -30,7 +27,7 @@ A Windows version is also available at http://prdownloads.sourceforge.net/swig/swigwin-2.0.0.zip -Please report problems with this release to the swig-dev mailing list, +Please report problems with this release to the swig-devel mailing list, details at http://www.swig.org/mail.html. --- The SWIG Developers diff --git a/COPYRIGHT b/COPYRIGHT index 0e660ba3a..5296b3b48 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -61,3 +61,16 @@ Past contributors include: Kovuk, Oleg Tolmatcev, Tal Shalif, Lluis Padro, Chris Seatory, Igor Bely, Robin Dunn (See CHANGES and CHANGES.current for a more complete list). +Historically, the following people contributed to early versions of SWIG. +Peter Lomdahl, Brad Holian, Shujia Zhou, Niels Jensen, and Tim Germann +at Los Alamos National Laboratory were the first users. Patrick +Tullmann at the University of Utah suggested the idea of automatic +documentation generation. John Schmidt and Kurtis Bleeker at the +University of Utah tested out the early versions. Chris Johnson +supported SWIG's developed at the University of Utah. John Buckman, +Larry Virden, and Tom Schwaller provided valuable input on the first +releases and improving the portability of SWIG. David Fletcher and +Gary Holt have provided a great deal of input on improving SWIG's +Perl5 implementation. Kevin Butler contributed the first Windows NT +port. + diff --git a/FUTURE b/FUTURE deleted file mode 100644 index 997de9b4c..000000000 --- a/FUTURE +++ /dev/null @@ -1,335 +0,0 @@ -SWIG-1.3.12, SWIG 2.0, and Beyond -================================= - -With the release of SWIG-1.3.12, I thought I'd take a few moments of -everyone's time to talk about the past, the present, and the future of -SWIG development. I'm really quite excited about the current release -because I think it represents a huge turning point in SWIG's -development. Furthermore, it is only the beginning of bigger and -better things to come. However, we definitely need your help. - -To put a little perspective on the discussion, I'd start with a few -development statistics. In the last 12 months, there have been over -300 entries added to the CHANGES log and over 4000 CVS commits. -Although that may not sound like a lot compared to a huge software -project, it is significant in the context of SWIG. As a point of -comparison, there has been more SWIG development this year than in any -other year of the project and more than in the previous three years -combined. This even includes the first few years of development in -which there was also a lot of activity. Furthermore, many of the -recent changes have been extremely non-trivial (e.g., templates, -namespaces, type system, operators, etc.). As a result, SWIG is more -capable than I ever imagined possible. - -Regrettably, I must admit that I've been a little negligent in -discussing the roadmap for where I thought this flurry of SWIG -development was actually headed. In part, this is because I've been -buried in work. However, the real reason is that I didn't really know -where we were going---except that in a time far far far away in the -future, we might arrive at some kind of "stable" release with a -version number other than "1.3.x". Needless to say, that's not a very -compelling story. - -That said, I've spent a lot of time thinking about SWIG and trying to -wrap my brain around it. Specifically, just what is (or should be) -the primary focus of this project and what are we really trying to do? -That's what the rest of this message is about. - -SWIG Prehistory ---------------- -The first version of SWIG was written in 1995. The original system -was developed to help with some software wrapping problems I -encountered while writing molecular dynamics software at Los -Alamos. Later that year, I became interested in extending the wrapper -generator to support other scripting languages so it was rewritten in -C++ and modified with multiple backends (Tcl, Perl, and Guile). This -led to a first public release in February, 1996. Feedback from this -release led to a series of enhancements and the release of SWIG 1.0 in -September 1996. Throughout this process, my intent was to create a -tool that I would want to use---I never viewed the project as an -CS experiment in programming languages or software engineering. - -SWIG 1.1 --------- -SWIG-1.1 (June, 1997) represented a series of enhancements that were -added in response to feedback at conferences and from users. Shadow -classes, exception handling, typemaps, and a number of more useful -features were added. However, the overall structure of the system was -relatively unchanged from the initial version. Following the release -of 1.1, a series of minor patch releases were made. This resulted in -the release of SWIG-1.1p5 in February, 1998. Unfortunately, this -release would remain the last "stable" release for quite a long -time---in fact, it is still listed as the last "stable" release on the -SWIG web page! - -SWIG Hell ---------- -Even during the development of SWIG-1.1, it was clear that the whole -design of the system was deeply flawed. The implementation was a mess -and the C/C++ support was full of holes and nasty corner cases. -Furthermore, there was no unifying principle that tied all of the -different SWIG directives together. Not only that, fixing these -problems appeared to be nothing short of impossible---requiring a -total ground-up rewrite at best. The only redeeming quality was that -the system basically worked "well enough," it was extensively -documented, and its flaws mostly known. People could use it and there -were work-arounds for most common problems. - -To deal with the design problem, there were at least four attempts to -completely rewrite SWIG, some of which were attempted in parallel with -the work on SWIG-1.1. Unfortunately, none of these were ever -completed. The primary problem was a strong "second system" effect and -a desire to make SWIG do everything that one might conceivably want to -do with a wrapper generator (somehow). Clearly, this was a recipe for -disaster. In fact, all such attempts to rewrite SWIG were eventually -abandoned several years ago. In hindsight, I think the real problem -was that these rewrite efforts focused far too much attention on -implementation technique rather than principles. In short, the -failure of these efforts was due to a lack of clarity in understanding -how SWIG ought to work (regardless of how it was actually -implemented). - -SWIG Restart (1.3a1-1.3a5) --------------------------- -Having languished for several years, the SWIG1.1p5 release had a -growing pile of maintenance issues. It didn't work for newer versions -of certain language modules and a lot of minor bug reports and feature -requests had been building up. With a lot of help from Loic Dachary and -Thien-Thi Nguyen, we put together the 1.3a1 release (February, -2000). This was mostly a bug fix release to 1.1p5 except that the -preprocessor module from SWIG1.2 was added and a lot of minor -enhancements were added. - -For the next six months, a massive effort was made to rewrite all of -SWIG's internal data structures (strings, lists, hashes, etc.). This -work was all going on underneath the covers while we tried to keep -SWIG in an operational state. The primary focus of this work was -really one of cleanup. Having given up on a total rewrite, perhaps -we could settle with making the implementation incrementally better -than before. In addition this, Matthias Koppe jumped on board to -reimplement the Guile module and to make other improvements to the system. - -An important aspect of these releases was that many parts of the -system not directly related to wrapper code generation were removed. -This included the documentation system and Objective-C support. These -were not removed because they weren't useful. Instead, the -documentation system was removed because it accounted for nearly half -of the special SWIG directives, yet had no direct bearing on what SWIG -actually did. Obective-C support was removed because it was tangled -with C++ support in a way that was very difficult to understand and -maintain. The removal of these features was seen as a way to vastly -simplify cleanup--and to buy some time where we could rethink their -role in a future release. - -SWIG Redux (1.3.6-1.3.11) -------------------------- -This work, started in February 2001, is the beginning of the current -SWIG implementation. With the help of William Fulton, Matthias Koppe, -Lyle Johnson, Luigi Ballabio, Jason Stewart, Richard Palmer, Sam -Liddicot, and others, this work can best be described as the wholesale -destruction of everything remaining from SWIG-1.1. The language -module API, type system, the parser, numerous SWIG directives, and -SWIG library files---all destroyed or rewritten. Not only that, we -started introducing significant incompatibilities with -SWIG-1.1---mostly in an effort to correct past wrongs and get -ourselves out of the tangled mess of earlier versions. A huge number -of long-standing bugs and difficult feature requests have also been -resolved. - -The general goal of this development could best be described as an -attempt to reduce SWIG to an easily described set of general "ideas" -about how it should operate. Special SWIG directives have been -eliminated or combined with others. Different parts of the system have -been better integrated. Features not directly related to wrapper code -generation have been removed and the system has become more -focused. Changes in internal data structures and APIs have allowed -SWIG to capture more information from interface files and to resolve -hard corner cases. More often than not, these are things that you -never notice unless you are an old user and you suddenly realize that -a problem you had several years back has disappeared. - -Along with the destruction of old code, this work has quietly -introduced a new core--the most significant features of which are a -new C++ type system and multi-pass compilation. More importantly, -this work has really tried to provide a more principled foundation for -future SWIG development. However, just what is this "more principled -foundation?" - -Convergence (1.3.12) --------------------- -With the upcoming 1.3.12 release, SWIG is about to take a big leap -forward. Almost all of this is due to one realization---that almost -every hard problem in past SWIG releases has been directly related to -errors and limitations in its type system. Types are the key to -understanding the structure of C and C++ code. They are at the heart -of understanding advanced language features like namespaces, nested -classes, and templates. They are directly related to the data -marshalling that occurs in wrappers. Not only that, they interact -with nearly every SWIG directive. A proper type system *is* the -necessary foundation for moving SWIG forward. - -To be honest, I don't think that the emphasis on types is entirely -obvious. In fact, a great deal of work in past SWIG rewrites has -focused on the problem of C++ parsing. For instance, modifying the -parser to handle more advanced C++ code or representing parse trees as -XML. Furthermore, if one looks at the SWIG mailing list, you can find -a *lot* of messages related to issues of C++ parsing whereas almost no -one ever talks about types (well, other than typemaps). Even other -wrapper generation tools seems to spend a lot of time dealing with the -parsing issue. Although parsing is clearly important, I don't think it -has ever been the real problem in SWIG. This is because even though a -parser can tell you what's in a header file, it doesn't tell you -anything about how the different pieces of the system behave or how -they might interact. To do that, you need to do a lot more than just -parsing--and that's really the whole point. - -Although earlier 1.3 releases have made big improvements to the type -system, SWIG-1.3.12 is the first release that really tries to tackle -the type-system issue in a major way. We have patched nearly all -remaining holes in the type system and we have added full support for -C++ namespaces. Not only that, we have completely reimplemented C++ -template support in a way that supports templates, member templates, -and template specialization. Luigi and I are currently using this to -work on proper SWIG library support for parts of the C++ standard -library and the Standard Template Library (STL). Although some crusty -C programmers (present company excepted), might balk at such apparent -insanity, this work has impacted all parts of SWIG at all levels. -Even a variety of subtle errors in C support have been fixed by this -work. - -In addition to the type system work, SWIG-1.3.12 contains continued -reduction in the implementation. Directives have been removed, -refined, renamed, or consolidated. We're still narrowing the focus of -the system and working towards some kind of convergence. "Convergence -to what?!?", you ask. - -So, what is SWIG? ------------------ -In a nutshell, SWIG is a C/C++ declaration compiler that generates -wrapper code (okay, so you knew that much). However, to really -understand what SWIG is doing and where SWIG-1.3.x is headed, it is -useful to know that the whole system is essentially being built around -three extensions to the C++ type system: - - - Typemaps. Typemaps are rules that define the process by which - data is converted between languages. They are fully integrated - with the C++ type system and they are applied using a type-based - pattern matching mechanism. All data conversion SWIG is - defined by typemaps and is fully reconfigurable. - - - Declaration annotation. There are special directives that modify - the wrapping behavior of individual declarations. Declarations - can be selectively identified and decorated with arbitrary - attributes that affect wrapper generation. Like typemaps, - declaration matching is fully integrated with the C++ type system. - Almost all SWIG customization directives are a form of declaration - annotation. - - - Class extension. The ability to extend classes and structures - with new methods/attributes when building wrappers. Classes - are part of the type system so class extension is naturally - integrated with the C++ type system as well (big surprise). - -And that's it--this is the end-game of SWIG-1.3.x development. When -stabilized and documented it will become SWIG-2.0. - -The Bigger Picture ------------------- -I really want to emphasize that all of this work is part of a much -bigger picture. SWIG is used by a surprising number of people in -industry, government, and academia. It's used to build systems used -by millions of people every day. It has even shown up in video games -and other unlikely settings. Although SWIG doesn't have the same -visibility as many large software projects, over 12000 people have -downloaded SWIG-1.3.11 in the last 4 months. Clearly someone is using -it for something! Because of this, I think it is important for us to -work on moving SWIG towards a more solid foundation. Doing so will -give the system more credibility and long term viability---and it will -be a lot more fun to use! - -It's also worth noting that there are some rather interesting CS -connections at work here. Extensions to the type system and typemaps -have some interesting relations to work in programming languages. The -SWIG declaration annotation system and class extension feature seem -oddly similar to work in the emerging area of Aspect Oriented -Programming (AOP). There are undoubtedly connections to other areas -of software engineering and architecture. - -The key point is that SWIG isn't going to connect to anything if -no-one can quite describe what it is or how it works. - -SWIG-2.0 and the Future ------------------------ -SWIG-1.3.12 still represents work in progress. There are bugs, the -documentation is still incomplete, and there are parts of the -implementation that are rather ugly. We are also still working out a -few very hard problems like nested classes, callback functions, and -overloading. A few old features are still missing (Objective-C, -documentation). However, I believe the end of the 1.3.x series is -near and achievable. - -Over the summer, a few more 1.3.x releases may appear but the current -plan is to aim for a SWIG-2.0 release in September. This release is -really moving towards the design principles described above and will -be a very major enhancement over SWIG-1.1. - -As for the future, a number of interesting ideas are on the table. I -want to add support for contracts/assertions in order to solve some -reliability issues that arise when retrofitting legacy codes with a -scripting interface. Support for an extension language has been -promoted by David Fletcher and was suggested by someone else on the -mailing list rather recently. I have a graduate student working on -SWIG support for the Microsoft CLR and .NET languages. Other work -might include support for alternative parsers, dynamically loadable -language modules, and so forth. However, none of this is really going -to materialize if we can't get the 2.0 release stablized. In fact, I -see SWIG-2.0 as a necessary step for moving forward with these ideas. - -We need your help! Yes, you. ----------------------------- -Nobody gets paid to work on SWIG. The developers are volunteers who -work in their spare time. Furthermore, SWIG is not supported by -investors, a large corporation, or research grants. I work on it -because it's fun, challenging, and useful. I presume that other -developers do the same. However, we only have limited resources and -we need your help. - -- If you like SWIG and find it useful, we need you to try new versions. - We want you to torture test the releases and to break them. We need - bug reports. No bug is too obscure or unimportant---we *will* fix it - if we can. We also need feedback about things that are annoying or - compatibility features that might help in going from 1.1 to 2.0. - -- We need help with documentation, examples, testing, libraries, and all - sorts of other aspects of the release. Even if you have never - written a SWIG language module or dived into its implementation, - there are many ways that you can help. Consider writing a case study - about how you wrapped a big library. Contribute tests that break the - implementation in horrible ways. Help with the web page or FAQ. - -- Most of the SWIG-1.3.x work has focused on the SWIG core. However, as - the 2.0 release nears, we will be working on a variety of enhancements - to the language modules. If there are things you would like to see - in any of the language modules, you need to let us know. - -- There are SWIG language modules that have not made it into the - distribution. Examples that I know about include ITCL, Swig-Eiffel, - and Swig-Lua. We would gladly make these part of the standard SWIG - distribution. However, we also need help to do it. Porting from - SWIG-1.1 is no easy task, but we're more than willing to help. It's - not as bad as one might imagine. - -- We are always looking for developers. Subscribe to - the swig-dev mailing list, details at http://www.swig.org/mail.html, - or send me email to get involved. - -Acknowledgements ----------------- -I'd just like to thank everyone who has submitted feedback, bugs, made -contributions, and put up with my occasional thrashing over the years. -I welcome any comments about this document and how we can make SWIG even -better. - -Dave Beazley (beazley@cs.uchicago.edu) -June 2, 2002 - diff --git a/Misc/fileheader b/Misc/fileheader deleted file mode 100644 index dcdbdeb75..000000000 --- a/Misc/fileheader +++ /dev/null @@ -1,10 +0,0 @@ -/* ----------------------------------------------------------------------------- - * file.c - * - * This file does a bunch of stuff. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1999-2000. The University of Chicago - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ diff --git a/NEW b/NEW deleted file mode 100644 index b329eb89a..000000000 --- a/NEW +++ /dev/null @@ -1,267 +0,0 @@ -New Features and Important Changes, v1.3 - -Author(s) : David Beazley - -March 21, 2003 - -1. Introduction ---------------- -This document briefly explains some of the most important changes made -since the release of SWIG1.1. The goal is to provide information for -people who want to upgrade an older SWIG interface to the new version. - -Most changes pertain to the internal implementation of SWIG and the -organization of the core, parser, and language modules. As a SWIG -user, almost all of these changes are hidden from view except for a -few important cases where changes to the core have dramatically -altered SWIG's old behavior. - -2. Types and typemaps ---------------------- -2.1 Variables of the form 'const type *' are no longer wrapped as - constants, but as C global variables. The earlier SWIG behavior - was incorrect due to Dave's misinterpretation of 'const' in the C - language specification. - - If you have written an interface that expects to create - constants using 'const type *' you will need to rewrite those - specifications using a new %constant directive like this: - - %constant(type *) name = value; - -2.2 SWIG generally has better support for pointers, 'const', - arrays, and pointers to functions. - -2.3 Typemaps are now applied to a more precisely defined set - of datatypes. For example, consider the following - typemap: - - %typemap(in) foo * { - ... get a foo ... - } - - In SWIG1.1, this typemap would get applied to 'foo *', - 'foo &', 'foo []', 'foo[][]', and so forth. - - In SWIG1.3, this typemap *only* gets applied to 'foo *' and - 'const foo *'. It does *NOT* get mapped to the other - variants listed above. - -2.4 Bug fix. SWIG now correctly handles typemaps of the form - - %typemap(in) Object { - ... get an object ... - } - -2.5 The memberout typemap is no longer available and is withdrawn. - The old implementation was essentially useless because of the - way in which code was generated. - -2.6 The memberin typemap is now inserted inline in the generated - wrapper code. This provides access to scripting-specific - variables in the wrapper function. - -2.7 SWIG-1.3.10 features a total rewrite of the typemap system. - Typemaps now use a different variable naming scheme. Typemaps - for arguments look like this: - - %typemap(in) sometype { - $1 = convert value ($input); - } - - The variable $1 replaces $target and the variable $input replaces - $source. - - For output values, typemaps look like this: - - %typemap(out) sometype { - $result = create result ($1); - } - - The variable $1 replaces $source and the variable $result replaces - $target. - - See Doc/Manual/Typemaps.html for a full description of the new - typemap system. - -2.8 Multi-argument typemaps are now supported. This solves a common - problem that occurs with functions like this - - void foo(char *buffer, int len); - - where you would like to make the two arguments operate as a single - object in the target language. - -2.9 Types such as 'const int &', 'const double &', are passed as - values instead of pointers. - -2.10 C++ namespaces are now supported. - -3. Type checking ----------------- - -SWIG no longer uses the functions SWIG_GetPtr() and SWIG_MakePtr() to -parse datatypes in wrapper code. This is because the type of a -pointer is no longer associated with a string, but with a special -"swig_type_info *" object. If you are not using typemaps, this change -should cause no noticable effects. However, if you have written -typemaps to handle pointers, here are the essential details: - -3.1 Type name mangling is different in SWIG1.3. For a type of - "int **", SWIG1.1 used to produce a name of the form - "_int_pp". SWIG1.3 on the other hand, produces a name - of the form "_p_p_int". There are a number of reasons for - changing the format, but I'd rather not go into it here. You'll - just have to learn to live with it :-). - -3.2 Types are described by a special "swig_type_info *" object. Everywhere - a string was used before, an object of this type will be used. - The "swig_type_info *" for a given type can always be obtained - using macros involving the mangled typename in 3.1. For example, - the type object of of 'int **' is 'SWIGTYPE_p_p_int'. - -3.3 Instead of SWIG_GetPtr, a function of the following form is used: - - int SWIG_ConvertPtr(ScriptObj *o, void **ptr, swig_type_info *ty, int flags); - - Note: the function name may differ in certain implementations (read - the source). For example: - - int SWIG_ConvertPtr(ScriptObj *o, void **ptr, SWIGTYPE_p_p_int,0); - - Passing a value of '0' for the type will accept any pointer. This - works kind of like 'void *'. The flags argument is reserved for - future expansion. - -3.4. To create a pointer object, one uses a function similar to - - ScriptObj *SWIG_NewPointer(void *ptr, swig_type_info *ty, int flags); - - It works in a similar manner: - - p = SWIG_NewPointer(ptr, SWIGTYPE_p_p_int, 0); - - You will have to read the source to get the exact function name - used. The flags argument is implementation specific and reserved - for future expansion. - -3.5. If, for whatever reason, you need to obtain the 'swig_type_info *' - outside the context of a wrapper file, you can use the - SWIG_TypeQuery() function. For example: - - swig_type_info *ty = SWIG_TypeQuery("int **"); - - this function returns an appropriate type_info structure or NULL - if no such type is registered. - -3.6 SWIG does not generate swig_type_info structures for types that are - not actually used in an interface file. As a result, the type - checking tables for SWIG1.3 tend to be much smaller than for SWIG1.1. - -*** Note: The old string-based type checking scheme is not going to -return to SWIG so do not ask for backwards compatibility. The new -scheme is substantially faster, it is less error-prone, it requires no -dynamic memory allocation, it works better with the runtime libraries, -and it is simpler to implement than the old string based approach. - -4. Deprecated Features (incomplete list) ----------------------------------------- - -4.1 Documentation system. The old documentation system has been removed - entirely. I expect it to return someday, but it will have a much - different form (probably influenced by XML). - -4.2 The %val and %out directives. These directives used to attach - properties to function parameters such as - - void foo(%val int *ptr); - - The same effect can now be achieved with typemaps: - - void foo(int *INPUT); - - -4.3 Extensions to the %module and %init directive are no longer - supported. For example: - - %module example, foo, bar - - This used to perform a special kind of multi-module - initialization for static linking. If you really - need to do this, you will have to manually insert - code into the module initialization function. - -4.4 %ifdef, %ifndef, %endif, %if, %elif, %else directives are - withdrawn. SWIG now has a real preprocessor. - -4.5 %checkout directive removed. - -4.6 %except and %new are deprecated. - -4.7 %readonly and %readwrite are deprecated. Use %immutable instead. - -4.8 The %addmethods directive has been renamed to %extend. - -5. Language specific changes ----------------------------- - -5.1 Python shadow classes are much more efficient and pass the shadow objects - directly to the C wrappers. - -5.2 Tcl code generation is substantially improved--especially for C++. - -5.3 Tcl module can now link to global variables of any type. - -5.4 Perl shadow classes improved and optimized somewhat. - -5.5 The Guile module represents pointers as smobs. (They used to be - mangled into strings.) Memory leaks and type conversion bugs have been - fixed. The Guile module system, including dynamic loading, and - exceptions are supported. A typemap-driven procedure-documentation - system has been added (requires Guile 1.4). Procedures-with-setters - can be generated. - -5.6 The Python module now automatically creates shadow class objects from the - C wrappers. This fixes a bunch of hard problems related to typemaps, - exception handling, and more. - -6. New Features ---------------- - -6.1 Java module added - -6.2 Ruby module added - -6.3 Mzscheme module added. - -6.4 Integrated preprocessor. You can now use C macros in SWIG interface files. - -6.5 PHP module added. - -6.6 %rename directive is greatly enhanced to deal with overloaded functions. - -6.7 Support for simple templates - -6.8 Support for overloaded operators. - -6.9 %feature directive. - -6.10 Ocaml module added. - -6.11 XML module added. - -6.12 CHICKEN module added. - -6.13 C# module added. - - - - - - - - - - - - diff --git a/README b/README index 8cdc34887..19036dc02 100644 --- a/README +++ b/README @@ -12,318 +12,36 @@ code) in order to make the corresponding C/C++ libraries available to the listed languages, or to extend C/C++ programs with a scripting language. -This distribution represents the latest development release of SWIG. - Up-to-date SWIG related information can be found at http://www.swig.org A SWIG FAQ and other hints can be found on the SWIG Wiki: - http://www.dabeaz.com/cgi-bin/wiki.pl + http://www.dabeaz.com/cgi-bin/wiki.pl - -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!!!!!!! IMPORTANT !!!!!!! -!!!!!!! !!!!!!! -!!!!!!! Previous SWIG-1.1 users should read the documentation !!!!!!! -!!!!!!! file Doc/Manual/SWIG.html before trying to use SWIG-1.3!!!!!!! -!!!!!!! on existing SWIG interfaces. This is the most current !!!!!!! -!!!!!!! documentation that describes new 1.3 features and !!!!!!! -!!!!!!! incompatibilities. !!!!!!! -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -What's New? -=========== - -SWIG-1.3.40 summary: -- SWIG now supports directors for PHP. -- PHP support improved in general. -- Octave 3.2 support added. -- Various bug fixes/enhancements for Allegrocl, C#, Java, Octave, Perl, - Python, Ruby and Tcl. -- Other generic fixes and minor new features. - -SWIG-1.3.39 summary: -- Some new small feature enhancements. -- Improved C# std::vector wrappers. -- Bug fixes: mainly Python, but also Perl, MzScheme, CFFI, Allegrocl - and Ruby - -SWIG-1.3.38 summary: -- Output directory regression fix and other minor bug fixes - -SWIG-1.3.37 summary: -- Python 3 support added -- SWIG now ships with a version of ccache that can be used with SWIG. - This enables the files generated by SWIG to be cached so that repeated - use of SWIG on unchanged input files speeds up builds quite considerably. -- PHP 4 support removed and PHP support improved in general -- Improved C# array support -- Numerous Allegro CL improvements -- Bug fixes/enhancements for Python, PHP, Java, C#, Chicken, Allegro CL, - CFFI, Ruby, Tcl, Perl, R, Lua. -- Other minor generic bug fixes and enhancements - -SWIG-1.3.36 summary: -- Enhancement to directors to wrap all protected members -- Optimisation feature for objects returned by value -- A few bugs fixes in the PHP, Java, Ruby, R, C#, Python, Lua and - Perl modules -- Other minor generic bug fixes - -SWIG-1.3.35 summary: -- Octave language module added -- Bug fixes in Python, Lua, Java, C#, Perl modules -- A few other generic bugs and runtime assertions fixed - -SWIG-1.3.34 summary: -- shared_ptr support for Python -- Support for latest R - version 2.6 -- Various minor improvements/bug fixes for R, Lua, Python, Java, C# -- A few other generic bug fixes, mainly for templates and using statements - -SWIG-1.3.33 summary: -- Fix regression for Perl where C++ wrappers would not compile -- Fix regression parsing macros - -SWIG-1.3.32 summary: -- shared_ptr support for Java and C# -- Enhanced STL support for Ruby -- Windows support for R -- Fixed long-standing memory leak in PHP Module -- Numerous fixes and minor enhancements for Allegrocl, C#, cffi, Chicken, Guile, - Java, Lua, Ocaml, Perl, PHP, Python, Ruby, Tcl. -- Improved warning support - -SWIG-1.3.31 summary: -- Python modern classes regression fix - -SWIG-1.3.30 summary: -- Python-2.5 support -- New language module: R -- Director support added for C# -- Numerous director fixes and improvements -- Improved mingw/msys support -- Better constants support in Guile and chicken modules -- Support for generating PHP5 class wrappers -- Important Java premature garbage collection fix -- Minor improvements/fixes in cffi, php, allegrocl, perl, chicken, lua, ruby, - ocaml, python, java, c# and guile language modules -- Many many other bug fixes - -SWIG-1.3.29 summary: -- Numerous important bug fixes -- Few minor new features -- Some performance improvements in generated code for Python - -SWIG-1.3.28 summary: -- More powerful renaming (%rename) capability. -- More user friendly warning handling. -- Add finer control for default constructors and destructors. We discourage - the use of the 'nodefault' option, which disables both constructors and - destructors, leading to possible memory leaks. Use instead 'nodefaultctor' - and/or 'nodefaultdtor'. -- Automatic copy constructor wrapper generation via the 'copyctor' option/feature. -- Better handling of Windows extensions and types. -- Better runtime error reporting. -- Add the %catches directive to catch and dispatch exceptions. -- Add the %naturalvar directive for more 'natural' variable wrapping. -- Better default handling of std::string variables using the %naturalvar directive. -- Add the %allowexcept and %exceptionvar directives to handle exceptions when - accessing a variable. -- Add the %delobject directive to mark methods that act like destructors. -- Add the -fastdispatch option to enable smaller and faster overload dispatch - mechanism. -- Template support for %rename, %feature and %typemap improved. -- Add/doc more debug options, such as -dump_module, -debug_typemaps, etc. -- Unified typemap library (UTL) potentially providing core typemaps for all - scripting languages based on the recently evolving Python typemaps. -- New language module: Common Lisp with CFFI. -- Python, Ruby, Perl and Tcl use the new UTL, many old reported and hidden - errors with typemaps are now fixed. -- Initial Java support for languages using the UTL via GCJ, you can now use - Java libraries in your favorite script language using gcj + swig. -- Tcl support for std::wstring. -- PHP4 module update, many error fixes and actively maintained again. -- Allegrocl support for C++, also enhanced C support. -- Ruby support for bang methods. -- Ruby support for user classes as native exceptions. -- Perl improved dispatching in overloaded functions via the new cast and rank - mechanism. -- Perl improved backward compatibility, 5.004 and later tested and working. -- Python improved backward compatibility, 1.5.2 and later tested and working. -- Python can use the same cast/rank mechanism via the -castmode option. -- Python implicit conversion mechanism similar to C++, via the %implicitconv - directive (replaces and improves the implicit.i library). -- Python threading support added. -- Python STL support improved, iterators are supported and STL containers can - use now the native PyObject type. -- Python many performance options and improvements, try the -O option to test - all of them. Python runtime benchmarks show up to 20 times better performance - compared to 1.3.27 and older versions. -- Python support for 'multi-inheritance' on the python side. -- Python simplified proxy classes, now swig doesn't need to generate the - additional 'ClassPtr' classes. -- Python extended support for smart pointers. -- Python better support for static member variables. -- Python backward compatibility improved, many projects that used to work - only with swig-1.3.21 to swig-1.3.24 are working again with swig-1.3.28 -- Python test-suite is now 'valgrinded' before release, and swig also - reports memory leaks due to missing destructors. -- Minor bug fixes and improvements to the Lua, Ruby, Java, C#, Python, Guile, - Chicken, Tcl and Perl modules. - -SWIG-1.3.27 summary: -- Fix bug in anonymous typedef structures which was leading to strange behaviour - -SWIG-1.3.26 summary: -- New language modules: Lua, CLISP and Common Lisp with UFFI. -- Big overhaul to the PHP module. -- Change to the way 'extern' is handled. -- Minor bug fixes specific to C#, Java, Modula3, Ocaml, Allegro CL, - XML, Lisp s-expressions, Tcl, Ruby and Python modules. -- Other minor improvements and bug fixes. - -SWIG-1.3.25 summary: -- Improved runtime type system. Speed of module loading improved in - modules with lots of types. SWIG_RUNTIME_VERSION has been increased - from 1 to 2, but the API is exactly the same; only internal changes - were made. -- The languages that use the runtime type system now support external - access to the runtime type system. -- Various improvements with typemaps and template handling. -- Fewer warnings in generated code. -- Improved colour documentation. -- Many C# module improvements (exception handling, prevention of early - garbage collection, C# attributes support added, more flexible type - marshalling/asymmetric types.) -- Minor improvements and bug fixes specific to the C#, Java, TCL, Guile, - Chicken, MzScheme, Perl, Php, Python, Ruby and Ocaml modules). -- Various other bug fixes and memory leak fixes. - -SWIG-1.3.24 summary: -- Improved enum handling -- More runtime library options -- More bugs fixes for templates and template default arguments, directors - and other areas. -- Better smart pointer support, including data members, static members - and %extend. - -SWIG-1.3.23 summary: -- Improved support for callbacks -- Python docstring support and better error handling -- C++ default argument support for Java and C# added. -- Improved c++ default argument support for the scripting languages plus - option to use original (compact) default arguments. -- %feature and %ignore/%rename bug fixes and mods - they might need default - arguments specified to maintain compatible behaviour when using the new - default arguments wrapping. -- Runtime library changes: Runtime code can now exist in more than one module - and so need not be compiled into just one module -- Further improved support for templates and namespaces -- Overloaded templated function support added -- More powerful default typemaps (mixed default typemaps) -- Some important %extend and director code bug fixes -- Guile now defaults to using SCM API. The old interface can be obtained by - the -gh option. -- Various minor improvements and bug fixes for C#, Chicken, Guile, Java, - MzScheme, Perl, Python and Ruby -- Improved dependencies generation for constructing Makefiles. - -SWIG-1.3.22 summary: -- Improved exception handling and translation of C errors or C++ - exceptions into target language exceptions. -- Improved enum support, mapping to built-in Java 1.5 enums and C# - enums or the typesafe enum pattern for these two languages. -- Python - much better STL suppport and support for std::wstring, - wchar_t and FILE *. -- Initial support for Modula3 and Allegro CL. -- 64 bit TCL support. -- Java and C#'s proxy classes are now nearly 100% generated from - typemaps and/or features for finer control on the generated code. -- SWIG runtime library support deprecation. -- Improved documentation. SWIG now additionally provides documentation - in the form of a single HTML page as well as a pdf document. -- Enhanced C++ friend declaration support. -- Better support for reference counted classes. -- Various %fragment improvements. -- RPM fixes. -- Various minor improvements and bug fixes for C#, Chicken, Guile, Java, - MzScheme, Perl, Php, Python, Ruby and XML. - - -The SWIG-1.3.x development releases offer a huge number of improvements -over older SWIG-1.1 releases. These improvements include: - - - Support for C++ overloaded functions and methods. - - Support for C++ smart pointers. - - Support for C++ namespaces - - Support for C++ overloaded operators. - - Support for C++ templates including member templates. - - Support for C++ template specialization and partial specialization. - - Support for C++ friend declarations. - - Parsing support for almost all C/C++ datatypes. - - Automatic translation of C++ exception specifiers. - - Contract support. - - A full C preprocessor with macro expansion. Includes C99 variadic macros. - - Java, Ruby, MzScheme, PHP4, OCAML, Pike, CHICKEN, XML and C# modules - added. Guile module improved. - - Director support - upcalls for C++ virtual functions into the target - language proxy class. - - Better code generation. SWIG is better able to make optimizations - in order to generate less code. - - Testing framework part of the distribution ("make -k check" support). - - A lot of minor bug fixes and cleanup. - - Better Windows support. - -If you used SWIG-1.1, a number of old features are missing from SWIG-1.3. - - - The SWIG-1.1 documentation system is gone and hasn't been - replaced yet. This is on the long-term to-do list. - - - The Tcl7.x and Perl4 modules are deprecated and no longer - included. - - - A wide variety of old SWIG command-line options and - obscure features are gone. - - - A lot of old %pragma directives and obscure undocumented - customization features have been eliminated. The same - functionality is now available through other means. - - - Objective C support doesn't work right now. No ETA as to - when it will return. - -Although we are making some attempt to preserve backwards -compatibility with interfaces written for SWIG-1.1, SWIG-1.3 -incorporates a number of very substantial modifications to type -handling, typemaps, and wrapper code generation. Therefore, if you -are making extensive use of advanced SWIG features, interfaces written -for SWIG-1.1 may not work. We apologize for the inconvenience, but -these changes are needed in order to fix a number of annoying -"features" in SWIG-1.1. Hopefully the list of new features will -provide enough incentive for you to upgrade (and that the -modifications to your interfaces will only be minor). - -In addition, SWIG-1.3 makes no attempt to be compatible with SWIG-1.1 at -the C++ API level so language modules written for SWIG-1.1 will most -definitely not work with this release. - -See the documentation for details of the SWIG_VERSION preprocessor -symbol if you have backward compatibility issues and need to use more -than one version of SWIG. - -The files NEW and CHANGES describe in some detail all of the important -changes that have been made to the system. Experienced users would be -well advised to read this. +License +======= +Please see the LICENSE file for details of the SWIG license. Release Notes ============= Please see the CHANGES.current file for a detailed list of bug fixes and new features for the current release. The CHANGES file contains bug fixes -and new features for older versions. A summary of the changes is included -in this README file. +and new features for older versions. A summary of changes in each release +can be found in the RELEASENOTES file. + +Backwards Compatibility +======================= +The developers strive their best to preserve backwards compatibility +between releases, but this is not always possible as the overriding +aim is to provide the best wrapping experience. Where backwards +compatibility is known to be broken, it is clearly marked as an +incompatibility in the CHANGES and CHANGES.current files. + +See the documentation for details of the SWIG_VERSION preprocessor +symbol if you have backward compatibility issues and need to use more +than one version of SWIG. Windows Installation ==================== @@ -380,8 +98,9 @@ examples which build the runtime library. Notes: (1) If you checked the code out via SVN, you will have to run ./autogen.sh - before typing 'configure'. In addition, a full build of SWIG requires - the use of bison. + before typing 'configure'. In addition, a full build of SWIG requires + the a number of packages to be installed. Full instructions at + http://www.swig.org/svn.html Macintosh OS X Installation ============================ @@ -389,15 +108,13 @@ SWIG is known to work on various flavors of OS X. Follow the Unix installation instructions above. However, as of this writing, there is still great deal of inconsistency with how shared libaries are handled by various scripting languages on OS X. We've tried to resolve these differences to the extent of our knowledge. -This release was most recently checked with the Panther release of OS X on a -Macintosh G5 system. Your mileage may vary. Users of OS X should be aware that Darwin handles shared libraries and linking in a radically different way than most Unix systems. In order to test SWIG and run the examples, SWIG configures itself to use flat namespaces and to allow undefined -symbols (-flat_namespace -undefined suppress). This mostly closely follows the Unix +symbols (-flat_namespace -undefined suppress). This mostly closely follows the Unix model and makes it more likely that the SWIG examples will work with whatever -installation of software you might have. However, this is generally not the recommended +installation of software you might have. However, this is generally not the recommended technique for building larger extension modules. Instead, you should utilize Darwin's two-level namespaces. Some details about this can be found here @@ -435,7 +152,7 @@ tests may fail on older C++ compilers (for instance if your compiler does not support member templates). These errors are harmless if you don't intend to use these features in your own programs. -Note: The test-suite currently contains around 250 tests. If you +Note: The test-suite currently contains over 500 tests. If you have many different target languages installed and a slow machine, it might take more than an hour to run the test-suite. @@ -490,16 +207,11 @@ Documentation The Doc/Manual directory contains the most recent set of updated documentation for this release. The documentation is available in three different formats, each of which contains identical content. -These format are, pdf (SWIGDocumentation.pdf), single +These format are, pdf (Doc/Manual/SWIGDocumentation.pdf), single page html (Doc/Manual/SWIGDocumentation.html) or multiple page html (other files in Doc/Manual). Please select your chosen format and copy/install to wherever takes your fancy. -This is a development release and the documentation is largely, but -not entirely up to date. We are working on it, but there -was a lot of old documentation and it is taking some time to -update and complete. Please be patient or volunteer to help. - There is some technical developer documentation available in the Doc/Devel subdirectory. This is not necessarily up-to-date, but it has some information on SWIG internals. @@ -511,11 +223,9 @@ have access to a limited variety of hardware (Linux, Solaris, OS-X, and Windows). All contributions help. If you would like to join the SWIG development team or contribute a -language module to the distribution, please contact the swig-dev +language module to the distribution, please contact the swig-devel mailing list, details at http://www.swig.org/mail.html. -- The SWIG Maintainers - - diff --git a/RELEASENOTES b/RELEASENOTES new file mode 100644 index 000000000..da833574c --- /dev/null +++ b/RELEASENOTES @@ -0,0 +1,223 @@ +Release Notes +============= + +A summary of recent releases is described below. A more detailed description +is available in the CHANGES.current and CHANGES files. + +SWIG-1.3.40 summary: +- SWIG now supports directors for PHP. +- PHP support improved in general. +- Octave 3.2 support added. +- Various bug fixes/enhancements for Allegrocl, C#, Java, Octave, Perl, + Python, Ruby and Tcl. +- Other generic fixes and minor new features. + +SWIG-1.3.39 summary: +- Some new small feature enhancements. +- Improved C# std::vector wrappers. +- Bug fixes: mainly Python, but also Perl, MzScheme, CFFI, Allegrocl + and Ruby + +SWIG-1.3.38 summary: +- Output directory regression fix and other minor bug fixes + +SWIG-1.3.37 summary: +- Python 3 support added +- SWIG now ships with a version of ccache that can be used with SWIG. + This enables the files generated by SWIG to be cached so that repeated + use of SWIG on unchanged input files speeds up builds quite considerably. +- PHP 4 support removed and PHP support improved in general +- Improved C# array support +- Numerous Allegro CL improvements +- Bug fixes/enhancements for Python, PHP, Java, C#, Chicken, Allegro CL, + CFFI, Ruby, Tcl, Perl, R, Lua. +- Other minor generic bug fixes and enhancements + +SWIG-1.3.36 summary: +- Enhancement to directors to wrap all protected members +- Optimisation feature for objects returned by value +- A few bugs fixes in the PHP, Java, Ruby, R, C#, Python, Lua and + Perl modules +- Other minor generic bug fixes + +SWIG-1.3.35 summary: +- Octave language module added +- Bug fixes in Python, Lua, Java, C#, Perl modules +- A few other generic bugs and runtime assertions fixed + +SWIG-1.3.34 summary: +- shared_ptr support for Python +- Support for latest R - version 2.6 +- Various minor improvements/bug fixes for R, Lua, Python, Java, C# +- A few other generic bug fixes, mainly for templates and using statements + +SWIG-1.3.33 summary: +- Fix regression for Perl where C++ wrappers would not compile +- Fix regression parsing macros + +SWIG-1.3.32 summary: +- shared_ptr support for Java and C# +- Enhanced STL support for Ruby +- Windows support for R +- Fixed long-standing memory leak in PHP Module +- Numerous fixes and minor enhancements for Allegrocl, C#, cffi, Chicken, Guile, + Java, Lua, Ocaml, Perl, PHP, Python, Ruby, Tcl. +- Improved warning support + +SWIG-1.3.31 summary: +- Python modern classes regression fix + +SWIG-1.3.30 summary: +- Python-2.5 support +- New language module: R +- Director support added for C# +- Numerous director fixes and improvements +- Improved mingw/msys support +- Better constants support in Guile and chicken modules +- Support for generating PHP5 class wrappers +- Important Java premature garbage collection fix +- Minor improvements/fixes in cffi, php, allegrocl, perl, chicken, lua, ruby, + ocaml, python, java, c# and guile language modules +- Many many other bug fixes + +SWIG-1.3.29 summary: +- Numerous important bug fixes +- Few minor new features +- Some performance improvements in generated code for Python + +SWIG-1.3.28 summary: +- More powerful renaming (%rename) capability. +- More user friendly warning handling. +- Add finer control for default constructors and destructors. We discourage + the use of the 'nodefault' option, which disables both constructors and + destructors, leading to possible memory leaks. Use instead 'nodefaultctor' + and/or 'nodefaultdtor'. +- Automatic copy constructor wrapper generation via the 'copyctor' option/feature. +- Better handling of Windows extensions and types. +- Better runtime error reporting. +- Add the %catches directive to catch and dispatch exceptions. +- Add the %naturalvar directive for more 'natural' variable wrapping. +- Better default handling of std::string variables using the %naturalvar directive. +- Add the %allowexcept and %exceptionvar directives to handle exceptions when + accessing a variable. +- Add the %delobject directive to mark methods that act like destructors. +- Add the -fastdispatch option to enable smaller and faster overload dispatch + mechanism. +- Template support for %rename, %feature and %typemap improved. +- Add/doc more debug options, such as -dump_module, -debug_typemaps, etc. +- Unified typemap library (UTL) potentially providing core typemaps for all + scripting languages based on the recently evolving Python typemaps. +- New language module: Common Lisp with CFFI. +- Python, Ruby, Perl and Tcl use the new UTL, many old reported and hidden + errors with typemaps are now fixed. +- Initial Java support for languages using the UTL via GCJ, you can now use + Java libraries in your favorite script language using gcj + swig. +- Tcl support for std::wstring. +- PHP4 module update, many error fixes and actively maintained again. +- Allegrocl support for C++, also enhanced C support. +- Ruby support for bang methods. +- Ruby support for user classes as native exceptions. +- Perl improved dispatching in overloaded functions via the new cast and rank + mechanism. +- Perl improved backward compatibility, 5.004 and later tested and working. +- Python improved backward compatibility, 1.5.2 and later tested and working. +- Python can use the same cast/rank mechanism via the -castmode option. +- Python implicit conversion mechanism similar to C++, via the %implicitconv + directive (replaces and improves the implicit.i library). +- Python threading support added. +- Python STL support improved, iterators are supported and STL containers can + use now the native PyObject type. +- Python many performance options and improvements, try the -O option to test + all of them. Python runtime benchmarks show up to 20 times better performance + compared to 1.3.27 and older versions. +- Python support for 'multi-inheritance' on the python side. +- Python simplified proxy classes, now swig doesn't need to generate the + additional 'ClassPtr' classes. +- Python extended support for smart pointers. +- Python better support for static member variables. +- Python backward compatibility improved, many projects that used to work + only with swig-1.3.21 to swig-1.3.24 are working again with swig-1.3.28 +- Python test-suite is now 'valgrinded' before release, and swig also + reports memory leaks due to missing destructors. +- Minor bug fixes and improvements to the Lua, Ruby, Java, C#, Python, Guile, + Chicken, Tcl and Perl modules. + +SWIG-1.3.27 summary: +- Fix bug in anonymous typedef structures which was leading to strange behaviour + +SWIG-1.3.26 summary: +- New language modules: Lua, CLISP and Common Lisp with UFFI. +- Big overhaul to the PHP module. +- Change to the way 'extern' is handled. +- Minor bug fixes specific to C#, Java, Modula3, Ocaml, Allegro CL, + XML, Lisp s-expressions, Tcl, Ruby and Python modules. +- Other minor improvements and bug fixes. + +SWIG-1.3.25 summary: +- Improved runtime type system. Speed of module loading improved in + modules with lots of types. SWIG_RUNTIME_VERSION has been increased + from 1 to 2, but the API is exactly the same; only internal changes + were made. +- The languages that use the runtime type system now support external + access to the runtime type system. +- Various improvements with typemaps and template handling. +- Fewer warnings in generated code. +- Improved colour documentation. +- Many C# module improvements (exception handling, prevention of early + garbage collection, C# attributes support added, more flexible type + marshalling/asymmetric types.) +- Minor improvements and bug fixes specific to the C#, Java, TCL, Guile, + Chicken, MzScheme, Perl, Php, Python, Ruby and Ocaml modules). +- Various other bug fixes and memory leak fixes. + +SWIG-1.3.24 summary: +- Improved enum handling +- More runtime library options +- More bugs fixes for templates and template default arguments, directors + and other areas. +- Better smart pointer support, including data members, static members + and %extend. + +SWIG-1.3.23 summary: +- Improved support for callbacks +- Python docstring support and better error handling +- C++ default argument support for Java and C# added. +- Improved c++ default argument support for the scripting languages plus + option to use original (compact) default arguments. +- %feature and %ignore/%rename bug fixes and mods - they might need default + arguments specified to maintain compatible behaviour when using the new + default arguments wrapping. +- Runtime library changes: Runtime code can now exist in more than one module + and so need not be compiled into just one module +- Further improved support for templates and namespaces +- Overloaded templated function support added +- More powerful default typemaps (mixed default typemaps) +- Some important %extend and director code bug fixes +- Guile now defaults to using SCM API. The old interface can be obtained by + the -gh option. +- Various minor improvements and bug fixes for C#, Chicken, Guile, Java, + MzScheme, Perl, Python and Ruby +- Improved dependencies generation for constructing Makefiles. + +SWIG-1.3.22 summary: +- Improved exception handling and translation of C errors or C++ + exceptions into target language exceptions. +- Improved enum support, mapping to built-in Java 1.5 enums and C# + enums or the typesafe enum pattern for these two languages. +- Python - much better STL suppport and support for std::wstring, + wchar_t and FILE *. +- Initial support for Modula3 and Allegro CL. +- 64 bit TCL support. +- Java and C#'s proxy classes are now nearly 100% generated from + typemaps and/or features for finer control on the generated code. +- SWIG runtime library support deprecation. +- Improved documentation. SWIG now additionally provides documentation + in the form of a single HTML page as well as a pdf document. +- Enhanced C++ friend declaration support. +- Better support for reference counted classes. +- Various %fragment improvements. +- RPM fixes. +- Various minor improvements and bug fixes for C#, Chicken, Guile, Java, + MzScheme, Perl, Php, Python, Ruby and XML. + + diff --git a/swig.spec.in b/swig.spec.in index 14d95d22f..0f64235fb 100644 --- a/swig.spec.in +++ b/swig.spec.in @@ -50,7 +50,7 @@ rm -rf ${RPM_BUILD_ROOT} %files %defattr(-,root,root) -%doc ANNOUNCE CHANGES FUTURE INSTALL LICENSE NEW README TODO +%doc ANNOUNCE CHANGES INSTALL LICENSE LICENSE-GPL LICENSE-UNIVERSITIES README RELEASENOTES %doc Doc/* %{_bindir}/* %{prefix}/share/* From 5aaf531b5ad3220044506a0273f18c35515de3ec Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 29 May 2010 21:35:39 +0000 Subject: [PATCH 134/203] Remove WAD and swig.spec.1 - not used or maintained git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12070 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/WAD/CHANGES | 25 - Tools/WAD/COPYING | 504 ------------------ Tools/WAD/HACK | 78 --- Tools/WAD/Include/wad.h | 269 ---------- Tools/WAD/Makefile.in | 46 -- Tools/WAD/Misc/fileheader | 28 - Tools/WAD/Papers/README | 5 - Tools/WAD/Prebuilt/linux/Makefile.in | 11 - Tools/WAD/Prebuilt/solaris/Makefile.in | 11 - Tools/WAD/Python/Makefile.in | 54 -- Tools/WAD/Python/python.c | 221 -------- Tools/WAD/Python/type.c | 277 ---------- Tools/WAD/Python/wadpyinit.cxx | 45 -- Tools/WAD/README | 376 -------------- Tools/WAD/Tcl/Makefile.in | 54 -- Tools/WAD/Tcl/wadtcl.c | 122 ----- Tools/WAD/Tcl/wadtclinit.cxx | 38 -- Tools/WAD/Test/Makefile.in | 44 -- Tools/WAD/Test/README | 5 - Tools/WAD/Test/death.py | 65 --- Tools/WAD/Test/death.tcl | 65 --- Tools/WAD/Test/debug.c | 119 ----- Tools/WAD/Test/debug.i | 9 - Tools/WAD/Test/debug.py | 35 -- Tools/WAD/Test/debug.tcl | 25 - Tools/WAD/Test/foo.py | 31 -- Tools/WAD/Test/wadpm.py | 49 -- Tools/WAD/Test/wpm.py | 280 ---------- Tools/WAD/Wad/Makefile.in | 73 --- Tools/WAD/Wad/debug.c | 98 ---- Tools/WAD/Wad/default.c | 311 ----------- Tools/WAD/Wad/demangle.c | 36 -- Tools/WAD/Wad/elf.c | 428 ---------------- Tools/WAD/Wad/init.c | 113 ---- Tools/WAD/Wad/io.c | 107 ---- Tools/WAD/Wad/libwadpl.pm | 8 - Tools/WAD/Wad/main.cxx | 14 - Tools/WAD/Wad/makehandler.py | 20 - Tools/WAD/Wad/memory.c | 174 ------- Tools/WAD/Wad/object.c | 303 ----------- Tools/WAD/Wad/return.c | 69 --- Tools/WAD/Wad/segment.c | 227 -------- Tools/WAD/Wad/signal.c | 520 ------------------- Tools/WAD/Wad/stab.c | 682 ------------------------- Tools/WAD/Wad/stack.c | 309 ----------- Tools/WAD/Wad/string.c | 131 ----- Tools/WAD/Wad/vars.c | 271 ---------- Tools/WAD/Wad/wadhandler.pl | 36 -- Tools/WAD/Wad/wadpl.cxx | 176 ------- Tools/WAD/configure.in | 365 ------------- Tools/swig.spec.1 | 42 -- 51 files changed, 7404 deletions(-) delete mode 100644 Tools/WAD/CHANGES delete mode 100644 Tools/WAD/COPYING delete mode 100644 Tools/WAD/HACK delete mode 100644 Tools/WAD/Include/wad.h delete mode 100644 Tools/WAD/Makefile.in delete mode 100644 Tools/WAD/Misc/fileheader delete mode 100644 Tools/WAD/Papers/README delete mode 100644 Tools/WAD/Prebuilt/linux/Makefile.in delete mode 100644 Tools/WAD/Prebuilt/solaris/Makefile.in delete mode 100644 Tools/WAD/Python/Makefile.in delete mode 100644 Tools/WAD/Python/python.c delete mode 100644 Tools/WAD/Python/type.c delete mode 100644 Tools/WAD/Python/wadpyinit.cxx delete mode 100644 Tools/WAD/README delete mode 100644 Tools/WAD/Tcl/Makefile.in delete mode 100644 Tools/WAD/Tcl/wadtcl.c delete mode 100644 Tools/WAD/Tcl/wadtclinit.cxx delete mode 100644 Tools/WAD/Test/Makefile.in delete mode 100644 Tools/WAD/Test/README delete mode 100644 Tools/WAD/Test/death.py delete mode 100644 Tools/WAD/Test/death.tcl delete mode 100644 Tools/WAD/Test/debug.c delete mode 100644 Tools/WAD/Test/debug.i delete mode 100644 Tools/WAD/Test/debug.py delete mode 100644 Tools/WAD/Test/debug.tcl delete mode 100644 Tools/WAD/Test/foo.py delete mode 100644 Tools/WAD/Test/wadpm.py delete mode 100644 Tools/WAD/Test/wpm.py delete mode 100644 Tools/WAD/Wad/Makefile.in delete mode 100644 Tools/WAD/Wad/debug.c delete mode 100644 Tools/WAD/Wad/default.c delete mode 100644 Tools/WAD/Wad/demangle.c delete mode 100644 Tools/WAD/Wad/elf.c delete mode 100644 Tools/WAD/Wad/init.c delete mode 100644 Tools/WAD/Wad/io.c delete mode 100644 Tools/WAD/Wad/libwadpl.pm delete mode 100644 Tools/WAD/Wad/main.cxx delete mode 100755 Tools/WAD/Wad/makehandler.py delete mode 100644 Tools/WAD/Wad/memory.c delete mode 100644 Tools/WAD/Wad/object.c delete mode 100644 Tools/WAD/Wad/return.c delete mode 100644 Tools/WAD/Wad/segment.c delete mode 100644 Tools/WAD/Wad/signal.c delete mode 100644 Tools/WAD/Wad/stab.c delete mode 100644 Tools/WAD/Wad/stack.c delete mode 100644 Tools/WAD/Wad/string.c delete mode 100644 Tools/WAD/Wad/vars.c delete mode 100644 Tools/WAD/Wad/wadhandler.pl delete mode 100644 Tools/WAD/Wad/wadpl.cxx delete mode 100644 Tools/WAD/configure.in delete mode 100644 Tools/swig.spec.1 diff --git a/Tools/WAD/CHANGES b/Tools/WAD/CHANGES deleted file mode 100644 index 186d15e7b..000000000 --- a/Tools/WAD/CHANGES +++ /dev/null @@ -1,25 +0,0 @@ -WAD 0.3 - June 2, 2002 - - - Added to the SWIG distribution. - -WAD 0.2 - June 24, 2001 - - - Minor changes. Added the wadtrace file - - - Put everything under the LGPL. - -WAD 0.1 - March 23, 2001 - - - Extensive changes to WAD core. WAD now builds an exception - object that can be queried and manipulated after a fault - occurs. - - - Better collection of debugging information. WAD is now - able to determine basic datatypes and other information - from stabs data. - - - Better reliability overall. - -WAD 0.0 - January, 2001 - -beazley - Initial "release". Not much of a release really. diff --git a/Tools/WAD/COPYING b/Tools/WAD/COPYING deleted file mode 100644 index b1e3f5a26..000000000 --- a/Tools/WAD/COPYING +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/Tools/WAD/HACK b/Tools/WAD/HACK deleted file mode 100644 index dfece608d..000000000 --- a/Tools/WAD/HACK +++ /dev/null @@ -1,78 +0,0 @@ -The WAD Developers Guide - -David Beazley (beazley@cs.uchicago.edu) - -$Id$ - -1. Introduction - -This short document is intended for anyone who feels inclined to work -on WAD and make improvements. It is by no means complete. However, -it contains random commentary on the current implementation. - -2. A brief word on the execution environment - -Because WAD is embedded in the same application it is intended to -debug, it must take an extremely conservative approach to its own -execution environment. Specifically, it can not rely upon the correct -operation of C library--especially with respect to memory management -and other basic operations. Because of this, the implementation of -WAD makes every effort to be as self-contained as possible--thus -minimizing its exposure to corrupted libraries in the faulting -application. Closely related to this, WAD does not rely on any -third-party libraries (e.g., libbfd) since it is almost impossible to -fully verify the way in which such libraries might use other programming -libraries. - -With that said, you might keep the following rules in mind: - - rule 1: Trust nothing--it might be broken. - rule 2: When in doubt, see rule 1. - -(Of course, we can probably get away with assuming that the OS isn't -hosed). - -3. Memory management - -There are two problems here: first, the dynamic memory -allocator may be corrupted or broken (e.g., as might occur when -you double-free memory or free memory not allocated by malloc). -Second, the WAD signal handler prefers to execute own on its own -signal handling stack. This stack is of limited size so it is not -a reliable place to put large amounts of data. - -Small buffers and scratch areas are managed through the use of static -variables allocated in the WAD data-segment. - -For dynamic memory management, WAD provides its own memory allocator -in the function wad_malloc(). This function allocates memory by using -mmap() to grab anonymous memory regions (mapped to /dev/zero). This -memory is currently allocated in chunks of 64Kbytes as needed. - -To simplify the implementation and prevent potential memory problems -in WAD itself, WAD never releases the memory that it allocates. There -is no wad_free() operation nor is there any way to release all of the -memory previously allocated. - -Although memory is never released, WAD tries to intern commonly used -strings. An internal string hash is built as WAD runs and in most -cases, each string is mapped to a single instance of the string in -this hash table. The function wad_string_lookup(char *s) is used to -return a pointer to the string s in the hash table. If no entry -exists, it is created and a pointer is returned. - -4. I/O - -It is probably a bad idea to use buffered I/O with WAD. This may -result in implicit calls to malloc() and related functions. - - - - - - - - - - - diff --git a/Tools/WAD/Include/wad.h b/Tools/WAD/Include/wad.h deleted file mode 100644 index 9a5007394..000000000 --- a/Tools/WAD/Include/wad.h +++ /dev/null @@ -1,269 +0,0 @@ -/* ----------------------------------------------------------------------------- - * wad.h - * - * WAD header file (obviously) - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2001. University of Chicago. All rights reserved. - * - * $Id$ - * ----------------------------------------------------------------------------- */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef WAD_SOLARIS -#include - -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - /* Core datatypes */ - - typedef int int32; - typedef unsigned uint32; - typedef short int16; - typedef unsigned short uint16; - typedef signed char int8; - typedef unsigned char uint8; - - -#ifndef MAX_PATH -#define MAX_PATH 1024 -#endif - -#define WAD_SRC_WINDOW 2 - -/* --- Low level memory management functions --- */ - -extern int wad_memory_init(); -extern void *wad_malloc(int nbytes); -extern char *wad_strdup(const char *c); -extern void wad_memory_debug(); -extern void wad_memcpy(void *t, const void *s, unsigned len); - - /* --- Low level string handling --- */ - -extern char *wad_string_lookup(char *s); -extern void wad_string_debug(); -extern char *wad_strcpy(char *t, const char *s); -extern char *wad_strcat(char *t, const char *s); -extern int wad_strlen(const char *s); - -/* --- I/O, Debugging --- */ - -extern void wad_printf(const char *fmt, ...); -extern char *wad_format_hex(unsigned long u, int leading); -extern char *wad_format_unsigned(unsigned long u, int width); -extern char *wad_format_signed(long s, int width); - -/* --- Memory segments --- */ -typedef struct WadSegment { - char *base; /* Base address for symbol lookup */ - char *vaddr; /* Virtual address start */ - unsigned long size; /* Size of the segment (bytes) */ - unsigned long offset; /* Offset into mapped object */ - char *mapname; /* Filename mapped to this region */ - char *mappath; /* Full path to mapname */ - struct WadSegment *next; /* Next segment */ -} WadSegment; - -extern int wad_segment_read(); -extern WadSegment *wad_segment_find(void *vaddr); -extern int wad_segment_valid(void *vaddr); - -/* --- Object files --- */ -typedef struct WadObjectFile { - void *ptr; /* Pointer to data */ - int len; /* Length of data */ - int type; /* Type of the object file */ - char *path; /* Path name of this object */ - struct WadObjectFile *next; -} WadObjectFile; - -extern void wad_object_reset(); -extern WadObjectFile *wad_object_load(const char *path); -extern int wad_file_check(void *); - -#define SYM_LOCAL 1 -#define SYM_GLOBAL 2 - -/* Signal handling */ -extern void wad_init(); -extern void wad_signalhandler(int, siginfo_t *, void *); -extern void wad_signal_init(); -extern void wad_signal_clear(); -extern void wad_set_return(const char *name, long value); -extern void wad_set_return_value(long value); -extern void wad_set_return_func(void (*f)(void)); - -typedef struct WadLocal { - char *name; /* Name of the local */ - void *ptr; /* Pointer to the actual data (if known) */ - int size; /* Size of the data (if known) */ - int type; /* Data type */ - - /* Debugging information */ - - int loc; /* Location: register or stack */ - int stack; /* location on the stack */ - int reg; /* Register number */ - int line; /* Line number where defined */ - struct WadLocal *next; -} WadLocal; - -#define PARM_REGISTER 1 -#define PARM_STACK 2 - -/* Type codes for local variables */ - -#define WAD_TYPE_UNKNOWN 0 -#define WAD_TYPE_INT32 1 -#define WAD_TYPE_INT16 2 -#define WAD_TYPE_INT8 3 -#define WAD_TYPE_INT64 4 -#define WAD_TYPE_UINT32 5 -#define WAD_TYPE_UINT16 6 -#define WAD_TYPE_UINT8 7 -#define WAD_TYPE_UINT64 8 -#define WAD_TYPE_FLOAT 9 -#define WAD_TYPE_DOUBLE 10 -#define WAD_TYPE_POINTER 11 -#define WAD_TYPE_CHAR 12 - -extern long wad_local_as_long(WadLocal *loc); -extern double wad_local_as_double(WadLocal *loc); - -/* Data structure containing information about each stack frame */ - -typedef struct WadFrame { - long frameno; /* Frame number */ - struct WadFrame *next; /* Next frame up the stack */ - struct WadFrame *prev; /* Previous frame down the stack */ - - /* Stack context information */ - long pc; /* Real PC */ - long sp; /* Real SP */ - long fp; /* Real FP */ - char *stack; /* Pointer to where a copy of the stack frame is stored */ - int stack_size; /* Stack frame size (fp-sp) */ - - /* Loading information. Contains information from /proc as well as a pointer to - the executable or shared library in which the PC is located */ - - WadSegment *segment; /* Memory segment corresponding to PC */ - WadObjectFile *object; /* Object file corresponding to PC */ - - /* Symbol table information for PC */ - - char *sym_name; /* Symbol name */ - int sym_nlen; /* Symbol name length */ - char *sym_file; /* Source file (if any) */ - unsigned long sym_base; /* Symbol base address */ - unsigned long sym_size; /* Symbol size */ - int sym_type; /* Symbol type */ - int sym_bind; /* Symbol binding */ - - /* Location information */ - char *loc_objfile; /* Object filename */ - char *loc_srcfile; /* Source filename */ - int loc_line; /* Source line */ - - /* Debugging information */ - int debug_check; /* Checked debugging information */ - int debug_nargs; /* Number of arguments */ - WadLocal *debug_args; /* Arguments */ - WadLocal *debug_lastarg; /* Last argument */ - int debug_nlocals; /* Number of locals */ - WadLocal *debug_locals; /* Local variables */ - WadLocal *debug_lastlocal; /* Last local */ - - /* Output strings */ - char *debug_str; /* Debugging string */ - char *debug_srcstr; /* Source string */ - - int last; /* Last frame flag */ -} WadFrame; - -extern WadFrame *wad_stack_trace(unsigned long, unsigned long, unsigned long); -extern void wad_stack_debug(WadFrame *f); - -extern char *wad_strip_dir(char *); -extern void wad_default_callback(int signo, WadFrame *frame, char *ret); -extern void wad_dump_trace(int fd, int signo, WadFrame *frame, char *ret); - -extern void wad_set_callback(void (*h)(int, WadFrame *, char *)); -extern char *wad_load_source(char *, int line); -extern void wad_release_source(); -extern void wad_release_trace(); -extern long wad_steal_arg(WadFrame *f, char *symbol, int argno, int *error); -extern long wad_steal_outarg(WadFrame *f, char *symbol, int argno, int *error); - -extern char *wad_arg_string(WadFrame *f); - -typedef struct { - char name[128]; - long value; -} WadReturnFunc; - -extern void wad_set_returns(WadReturnFunc *rf); -extern WadReturnFunc *wad_check_return(const char *name); - -extern int wad_search_stab(void *stab, int size, char *stabstr, WadFrame *f); - -extern void wad_find_object(WadFrame *f); -extern void wad_find_symbol(WadFrame *f); -extern void wad_find_debug(WadFrame *f); -extern void wad_build_vars(WadFrame *f); -extern char *wad_format_var(WadLocal *l); - -extern void wad_debug_make_strings(WadFrame *f); - -/* --- Debugging Interface --- */ - -#define DEBUG_SEGMENT 0x1 -#define DEBUG_SYMBOL 0x2 -#define DEBUG_STABS 0x4 -#define DEBUG_OBJECT 0x8 -#define DEBUG_FILE 0x10 -#define DEBUG_HOLD 0x20 -#define DEBUG_RETURN 0x40 -#define DEBUG_SYMBOL_SEARCH 0x80 -#define DEBUG_INIT 0x100 -#define DEBUG_NOSTACK 0x200 -#define DEBUG_ONESHOT 0x400 -#define DEBUG_STACK 0x800 -#define DEBUG_UNWIND 0x1000 -#define DEBUG_SIGNAL 0x2000 -#define DEBUG_STRING 0x4000 -#define DEBUG_MEMORY 0x8000 - -extern int wad_debug_mode; -extern int wad_heap_overflow; - -#ifdef WAD_LINUX -#define WAD_LITTLE_ENDIAN -#endif -#ifdef WAD_SOLARIS -#define WAD_BIG_ENDIAN -#endif - -#ifdef __cplusplus -} -#endif - - - - diff --git a/Tools/WAD/Makefile.in b/Tools/WAD/Makefile.in deleted file mode 100644 index d76f1179c..000000000 --- a/Tools/WAD/Makefile.in +++ /dev/null @@ -1,46 +0,0 @@ -# Generated automatically from Makefile.in by configure. - -SHELL = /bin/sh -prefix = @prefix@ -execprefix= @exec_prefix@ -LIB = $(execprefix)/lib - -# Location of your Python installation -PYINCLUDE = @PYINCLUDE@ - -# Location of your Tcl installation -TCLINCLUDE = @TCLINCLUDE@ - -# Location of your Perl installation -PERLINCLUDE = @PERL5EXT@ - -all: wad @MAKEPYTHON@ @MAKETCL@ #@MAKEPERL@ - -wad: - @cd Wad; $(MAKE) wad - -python: - @cd Python; $(MAKE) SINCLUDE='$(PYINCLUDE)' python - -tcl: - @cd Tcl; $(MAKE) SINCLUDE='$(TCLINCLUDE)' tcl - -perl: - @cd Wad; $(MAKE) SINCLUDE='$(PERLINCLUDE)' perl - -install: - cp libwad*.so $(LIB) - chmod a+rx $(LIB)/libwad*.so - -semi: - @cd Wad; $(MAKE) semi - @cd Python; $(MAKE) semi - @cd Tcl; $(MAKE) semi - -clean: - @cd Wad; $(MAKE) clean - @cd Python; $(MAKE) clean - @cd Tcl; $(MAKE) clean - @cd Test; $(MAKE) clean - rm *.so - diff --git a/Tools/WAD/Misc/fileheader b/Tools/WAD/Misc/fileheader deleted file mode 100644 index 7b82e9e05..000000000 --- a/Tools/WAD/Misc/fileheader +++ /dev/null @@ -1,28 +0,0 @@ -/* ----------------------------------------------------------------------------- - * segment.c - * - * This file provides access to the virtual memory map of a process - * including the location of the executable, data segments, shared - * libraries, and memory mapped regions. This information is - * obtained through /proc. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ diff --git a/Tools/WAD/Papers/README b/Tools/WAD/Papers/README deleted file mode 100644 index 8eb7b81d1..000000000 --- a/Tools/WAD/Papers/README +++ /dev/null @@ -1,5 +0,0 @@ -Papers about WAD can be obtained at: - - http://systems.cs.uchicago.edu/wad - - diff --git a/Tools/WAD/Prebuilt/linux/Makefile.in b/Tools/WAD/Prebuilt/linux/Makefile.in deleted file mode 100644 index 074e65452..000000000 --- a/Tools/WAD/Prebuilt/linux/Makefile.in +++ /dev/null @@ -1,11 +0,0 @@ -# Generated automatically from Makefile.in by configure. - -SHELL = /bin/sh -prefix = @prefix@ -execprefix= @exec_prefix@ -LIB = $(execprefix)/lib - -install: - cp libwad*.so $(LIB) - chmod a+rx $(LIB)/libwad*.so - diff --git a/Tools/WAD/Prebuilt/solaris/Makefile.in b/Tools/WAD/Prebuilt/solaris/Makefile.in deleted file mode 100644 index 074e65452..000000000 --- a/Tools/WAD/Prebuilt/solaris/Makefile.in +++ /dev/null @@ -1,11 +0,0 @@ -# Generated automatically from Makefile.in by configure. - -SHELL = /bin/sh -prefix = @prefix@ -execprefix= @exec_prefix@ -LIB = $(execprefix)/lib - -install: - cp libwad*.so $(LIB) - chmod a+rx $(LIB)/libwad*.so - diff --git a/Tools/WAD/Python/Makefile.in b/Tools/WAD/Python/Makefile.in deleted file mode 100644 index 2859039af..000000000 --- a/Tools/WAD/Python/Makefile.in +++ /dev/null @@ -1,54 +0,0 @@ -####################################################################### -# WAD Makefile -# -# David Beazley -# January 1, 2001 -####################################################################### - -# These are the files that make up the WAD core -SRCS = type.c python.c -OBJS = type.o python.o -INCLUDE = -I../Include -I. $(SINCLUDE) -WADOPT = @WADOPT@ - -# Location of your Python installation -PYINCLUDE = @PYINCLUDE@ -PYSRCS = wadpyinit.cxx -PYOBJS = wadpyinit.o - -# C Compiler -CC = @CC@ -CFLAGS = #@CCSHARED@ - -# C++ Compiler -CXX = @CXX@ -CXXFLAGS = #@CXXSHARED@ - -# Linking options -CLINK = -CXXLINK = @CXXLINK@ - -# Rules for creation of a .o file from .cxx -.SUFFIXES: .cxx -.cxx.o: - $(CXX) $(CXXFLAGS) $(WADOPT) $(INCLUDE) -c -o $*.o $< - -.c.o: - $(CC) $(CFLAGS) $(PYINCLUDE) $(WADOPT) $(INCLUDE) -c -o $*.o $< - -python: $(OBJS) $(PYOBJS) - $(CXXLINK) $(OBJS) $(PYOBJS) -o libwadpy.so -L.. -lwadcore - cp libwadpy.so .. - -wc:: - wc $(SRCS) - -semi:: - @egrep ";" $(SRCS) $(PYSRCS) | wc - -clean:: - rm -f *.o *.so *~ - - - - diff --git a/Tools/WAD/Python/python.c b/Tools/WAD/Python/python.c deleted file mode 100644 index 9f4686587..000000000 --- a/Tools/WAD/Python/python.c +++ /dev/null @@ -1,221 +0,0 @@ -/* ----------------------------------------------------------------------------- - * python.c - * - * Dynamically loadable python module for wad. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "Python.h" -#include "wad.h" - -static char cvs[] = "$Id$"; - -/* These are the python exception objects we will add - SegFault, BusError, AbortError */ - -static PyObject *segfault_exc = 0; -static PyObject *buserror_exc = 0; -static PyObject *abort_exc = 0; -static PyObject *illegal_exc = 0; - -extern PyObject *new_wadobject(WadFrame *f,int); - -/* Function return points and values */ - -static WadReturnFunc retpts[] = { - {"call_builtin", 0}, - {"_PyImport_LoadDynamicModule", 0}, - {"PyEval_EvalCode", 0}, - {"PyObject_GetAttrString", 0}, - {"PyObject_SetAttrString", -1}, - {"PyObject_Repr", 0}, - {"PyObject_Print", -1}, - {"PyObject_CallFunction", 0}, - {"PyObject_CallMethod", 0}, - {"PyObject_CallObject", 0}, - {"PyObject_Cmp", -1}, - {"PyObject_Compare", -1}, - {"PyObject_DelAttrString",-1}, - {"PyObject_DelItem",-1}, - {"PyObject_GetItem",0}, - {"PyObject_SetItem",-1}, - {"PyObject_HasAttrString",-1}, - {"PyObject_Hash",-1}, - {"PyObject_Length",-1}, - {"PyObject_Str",0}, - {"PyObject_Type", 0}, - - {"PyNumber_Absolute", 0}, - {"PyNumber_Add",0}, - {"PyNumber_And",0}, - {"PyNumber_Coerce",0}, - {"PyNumber_Divide",0}, - {"PyNumber_Divmod",0}, - {"PyNumber_Float",0}, - {"PyNumber_Int",0}, - {"PyNumber_Invert",0}, - {"PyNumber_Long",0}, - {"PyNumber_Lshift",0}, - {"PyNumber_Multiply", 0}, - {"PyNumber_Negative", 0}, - {"PyNumber_Or",0}, - {"PyNumber_Positive", 0}, - {"PyNumber_Power",0}, - {"PyNumber_Remainder",0}, - {"PyNumber_Rshift",0}, - {"PyNumber_Subtract",0}, - {"PyNumber_Xor",0}, - - {"PySequence_Concat",0}, - {"PySequence_Count",-1}, - {"PySequence_Delitem",-1}, - {"PySequence_DelSlice",-1}, - {"PySequence_Getitem",0}, - {"PySequence_GetSlice",0}, - {"PySequence_In",-1}, - {"PySequence_Index",-1}, - {"PySequence_Repeat",0}, - {"PySequence_SetItem",-1}, - {"PySequence_SetSlice",-1}, - {"PySequence_Tuple",0}, - - {"PyMapping_Clear",-1}, - {"PyMapping_DelItem",-1}, - {"PyMapping_DelItemString",-1}, - {"PyMapping_GetItemString",0}, - {"PyMapping_HasKey",-1}, - {"PyMapping_HasKeyString",-1}, - {"PyMapping_Items",0}, - {"PyMapping_Keys",0}, - {"PyMapping_Length", -1}, - {"PyMapping_SetItemString", -1}, - {"PyMapping_Values", 0}, - {"",0}}; - -/* Handler function */ -static void handler(int signo, WadFrame *frame, char *ret) { - static char message[65536]; - static char temp[1024]; - int len = 0; - PyObject *type; - char *name; - WadFrame *f; - WadFrame *fline = 0; - char *srcstr = 0; - - /* printf("python handler.\n"); */ - if (!ret) { - wad_default_callback(signo, frame, ret); - return; - } - - strcpy(message,"[ C stack trace ]\n\n"); - switch(signo) { - case SIGSEGV: - type = segfault_exc; - break; - case SIGBUS: - type = buserror_exc; - break; - case SIGABRT: - type = abort_exc; - break; - case SIGFPE: - type = PyExc_FloatingPointError; - break; - case SIGILL: - type = illegal_exc; - break; - default: - type = PyExc_RuntimeError; - break; - } - -#ifdef OLD - f = frame; - /* Find the last exception frame */ - while (!f->last) { - f= f->next; - } - /* Now work backwards */ - f = f->prev; - while (f) { - strcat(message, f->debug_str); - if (f->debug_srcstr) srcstr = f->debug_srcstr; - f = f->prev; - } - if (srcstr) { - strcat(message,"\n"); - strcat(message, srcstr); - strcat(message,"\n"); - } -#endif - - if (wad_heap_overflow) { - write(2, "WAD: Heap overflow detected.\n", 30); - wad_default_callback(signo, frame, ret); - } - - /* Note: if the heap is blown, there is a very good chance that this - function will not succeed and we'll dump core. However, the check - above should dump a stack trace to stderr just in case we don't make it - back. */ - -#ifdef OLD - PyErr_SetString(type, message); -#endif - PyErr_SetObject(type, new_wadobject(frame,0)); - -} - -void pywadinit() { - PyObject *d, *m; - m = PyImport_ImportModule((char *)"__builtin__"); - d = PyModule_GetDict(m); - printf("WAD Enabled\n"); - - segfault_exc = PyErr_NewException((char *)"exceptions.SegFault", NULL, NULL); - PyDict_SetItemString(d,(char *)"SegFault",segfault_exc); - - buserror_exc = PyErr_NewException((char *)"exceptions.BusError", NULL, NULL); - PyDict_SetItemString(d,(char *)"BusError",buserror_exc); - - abort_exc = PyErr_NewException((char*)"exceptions.AbortError", NULL, NULL); - PyDict_SetItemString(d,(char *)"AbortError",abort_exc); - - illegal_exc = PyErr_NewException((char *)"exceptions.IllegalInstruction", NULL, NULL); - PyDict_SetItemString(d,(char *)"IllegalInstruction",illegal_exc); - - wad_init(); - wad_set_callback(handler); - wad_set_returns(retpts); -} - -static PyMethodDef wadmethods[] = { - {0,0}, -}; - -void initlibwadpy() { - Py_InitModule((char *)"libwadpy",wadmethods); -} - - diff --git a/Tools/WAD/Python/type.c b/Tools/WAD/Python/type.c deleted file mode 100644 index 7d8248e0b..000000000 --- a/Tools/WAD/Python/type.c +++ /dev/null @@ -1,277 +0,0 @@ -/* ----------------------------------------------------------------------------- - * type.c - * - * This file defines a new python type that contains information from - * the WAD stack trace. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - - -#include "wad.h" -#include "Python.h" - -static char cvs[] = "$Id$"; - -typedef struct { - PyObject_HEAD - WadFrame *frame; /* Wad Stack frame object */ - int count; /* Number of frames */ -} wadobject; - -staticforward PyTypeObject WadObjectType; - - -PyObject * -new_wadobject(WadFrame *f, int count) { - wadobject *self; - self = PyObject_NEW(wadobject, &WadObjectType); - if (self == NULL) return NULL; - - self->frame = f; - if (count > 0) { - self->count = count; - } else { - self->count = 0; - while (f) { - self->count++; - f = f->next; - } - } - return (PyObject *) self; -} - -/* release a wad object */ -static void -wadobject_dealloc(wadobject *self) { - PyObject_Del(self); -} - -static char message[65536]; -static PyObject * -wadobject_repr(wadobject *self) { - char *srcstr = 0; - WadFrame *fp = 0; - int n; - WadFrame *f = self->frame; - - message[0] = 0; - /* Find the last exception frame */ - n = self->count; - while (f && n) { - fp = f; - f= f->next; - n--; - } - - if (fp) { - /* Now work backwards */ - f = fp; - while (f) { - strcat(message, f->debug_str); - if (f->debug_srcstr) srcstr = f->debug_srcstr; - if (f == self->frame) break; - f = f->prev; - } - if (srcstr) { - strcat(message,"\n"); - strcat(message, srcstr); - strcat(message,"\n"); - } - } - return PyString_FromString(message); -} - -static PyObject * -wadobject_str(wadobject *self) { - char *srcstr = 0; - int n; - - WadFrame *f = self->frame; - n = self->count; - strcpy(message,"[ C stack trace ]\n\n"); - /* Find the last exception frame */ - while (!f->last && n) { - f= f->next; - n--; - } - /* Now work backwards */ - if (n <= 0) { - f = f->prev; - } - while (f) { - strcat(message, f->debug_str); - if (f->debug_srcstr) srcstr = f->debug_srcstr; - if (self->frame == f) break; - f = f->prev; - } - if (srcstr) { - strcat(message,"\n"); - strcat(message, srcstr); - strcat(message,"\n"); - } - return PyString_FromString(message); -} - -static int -wadobject_len(wadobject *self) { - int n = 0; - WadFrame *f = self->frame; - while (f) { - n++; - f = f->next; - } - return n; -} - -static PyObject * -wadobject_getitem(wadobject *self, int n) { - int i; - WadFrame *f; - if (n < 0) { - n = self->count + n; - } - if ((n < 0) || (n >= self->count)) { - PyErr_SetString(PyExc_IndexError,"Stack frame out of range"); - return NULL; - } - f = self->frame; - for (i = 0; i next; - } - return new_wadobject(f,1); -} - -static PyObject * -wadobject_getslice(wadobject *self, int start, int end) { - int i; - WadFrame *f; - - f = self->frame; - for (i = 0; i < start; i++) { - f = f->next; - } - return new_wadobject(f,(end-start)); -} - -static PyObject * -wadobject_getattr(wadobject *self, char *name) { - if (strcmp(name,"__NAME__") == 0) { - return Py_BuildValue("z", self->frame->sym_name); - } else if (strcmp(name,"__EXE__") == 0) { - return Py_BuildValue("z", self->frame->object->path); - } else if (strcmp(name,"__FILE__") == 0) { - return Py_BuildValue("z", self->frame->loc_srcfile); - } else if (strcmp(name,"__OBJECT__") == 0) { - return Py_BuildValue("z", self->frame->loc_objfile); - } else if (strcmp(name,"__LINE__") == 0) { - return Py_BuildValue("i", self->frame->loc_line); - } else if (strcmp(name,"__SOURCE__") == 0) { - return Py_BuildValue("z",self->frame->debug_srcstr); - } else if (strcmp(name,"__PC__") == 0) { - return PyLong_FromUnsignedLong(self->frame->pc); - } else if (strcmp(name,"__SP__") == 0) { - return PyLong_FromUnsignedLong(self->frame->sp); - } else if (strcmp(name,"__FP__") == 0) { - return PyLong_FromUnsignedLong(self->frame->fp); - } else if (strcmp(name,"__STACK__") == 0) { - return PyString_FromStringAndSize(self->frame->stack, self->frame->stack_size); - } else if (strcmp(name,"__NARGS__") == 0) { - return PyInt_FromLong(self->frame->debug_nargs); - } else if (strcmp(name,"__LAST__") == 0) { - return PyInt_FromLong(self->frame->last); - } else if (strcmp(name,"__WHERE__") == 0) { - return Py_BuildValue("z",self->frame->debug_str); - } else if (strcmp(name,"__WAD__") == 0) { - return PyInt_FromLong(1); - } - - - /* Put a check for local variables */ - { - int i; - for (i = 0; i < 2; i++) { - WadLocal *loc; - if (i == 0) loc = self->frame->debug_locals; - else loc = self->frame->debug_args; - while (loc) { - if (strcmp(name,loc->name) == 0) { - switch(loc->type) { - case WAD_TYPE_INT32: - case WAD_TYPE_INT16: - case WAD_TYPE_INT8: - return PyLong_FromLong(wad_local_as_long(loc)); - break; - case WAD_TYPE_UINT8: - case WAD_TYPE_UINT16: - case WAD_TYPE_UINT32: - return PyLong_FromUnsignedLong((unsigned long) wad_local_as_long(loc)); - break; - case WAD_TYPE_CHAR: - return Py_BuildValue("c", (char) (PyLong_FromLong(wad_local_as_long(loc)))); - break; - case WAD_TYPE_FLOAT: - case WAD_TYPE_DOUBLE: - return PyFloat_FromDouble(wad_local_as_double(loc)); - break; - default: - return PyLong_FromUnsignedLong((unsigned long) wad_local_as_long(loc)); - } - } - loc = loc->next; - } - } - } - - PyErr_SetString(PyExc_NameError,"Unknown attribute."); - return NULL; -} -static PySequenceMethods wadobject_as_sequence = { - (inquiry) wadobject_len, - 0, - 0, - (intargfunc) wadobject_getitem, /* get item */ - (intintargfunc) wadobject_getslice, /* get slice */ - 0, - 0 -}; - -static PyTypeObject WadObjectType = { - PyObject_HEAD_INIT(&PyType_Type) - 0, - "WadObject", - sizeof(wadobject), - 0, - (destructor) wadobject_dealloc, - 0, /* printfunc */ - (getattrfunc) wadobject_getattr, - (setattrfunc) 0, - (cmpfunc) 0, - (reprfunc) wadobject_repr, - - 0, /* number */ - &wadobject_as_sequence, /* sequence */ - 0, /* mapping */ - 0, /* hash */ - 0, /* call */ - (reprfunc) wadobject_str, /* str */ -}; - diff --git a/Tools/WAD/Python/wadpyinit.cxx b/Tools/WAD/Python/wadpyinit.cxx deleted file mode 100644 index b97009402..000000000 --- a/Tools/WAD/Python/wadpyinit.cxx +++ /dev/null @@ -1,45 +0,0 @@ -/* ----------------------------------------------------------------------------- - * wadpyinit.cxx - * - * C++ automatic initializer for Python module. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -extern "C" void pywadinit(); - -/* This hack is used to auto-initialize wad regardless of whether we are - used as an imported module or as a link-library for another module */ - -class wadinitializer { -public: - wadinitializer() { - pywadinit(); - } -}; - -static wadinitializer wi; - - diff --git a/Tools/WAD/README b/Tools/WAD/README deleted file mode 100644 index c777c4efb..000000000 --- a/Tools/WAD/README +++ /dev/null @@ -1,376 +0,0 @@ -WAD (Wrapped Application Debugger) - -Author(s): - David M. Beazley (beazley@cs.uchicago.edu) - -Copyright (C) 2001 -University of Chicago - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -See the file COPYING for a complete copy of the LGPL. - -$Id$ - -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!!!!!!!! DISCLAIMER !!!!!!!! -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -THIS IS EXPERIMENTAL UNMAINTAINED RESEARCH SOFTWARE THAT REPRESENTS -WORK IN PROGRESS. IT IS NOT PORTABLE, IT HAS NOT BEEN EXHAUSTIVELY -TESTED, AND IT MIGHT NOT WORK AT ALL. PLEASE KEEP AWAY FROM SMALL -CHILDREN, PETS, NUCLEAR REACTORS, AIR-TRAFFIC CONTROL, AND VOTING -MACHINES. - -0. Supported Platforms - -This software is currently only known to work with 32-bit applications -on Sun Sparc Solaris 2.8 and recent i386-Linux systems. In addition, -there are numerous issues concerning the interaction of this software -with signal handling, thread libraries, and compilers. Please read -this entire document before proceeding. - -1. Introduction - -WAD is an embedded error-recovery mechanism that attempts to convert -fatal errors such as SIGSEGV, SIGBUS, and SIGFPE into sensible error -messages and exceptions. It is primarily designed to support -scripting language extension programming although it can also be used -with stand-alone C programs. - -The primary goal of this system is to explore an alternative approach -to mixed scripting-compiled debugging. It requires no modifications -or recompilation of existing software. Therefore, it should be -relatively easy to try out. Feedback is welcome. Contributions and -modifications are even more welcome. - -2. Compilation and Installation - -WAD is not particularly portable and at this time, only two platforms -are supported: Sun Sparc Solaris and i386-Linux. - -Installation is as follows: - - ./configure - make - make install - -The build process creates the following shared libraries: - - libwad.so - Standalone WAD. Can be linked with C/C++ - programs. - - libwadpy.so - Python WAD. Can be linked to Python extension - modules or imported on its own as 'import libwadpy' - - libwadtcl.so - Tcl WAD. Can be linked to Tcl extension - modules or loaded as 'load libwadtcl.so'. - - libwadpl.so - Perl WAD. Can be linked to Perl extension - modules or loaded as 'libwadpl'. - -To install the libraries, simply type 'make install'. This copies the libraries -to /usr/local/lib (unless you modify the makefile). - -Notes: - - - The Sun version of WAD has only been tested when compiled with the - Sun Workshop C/C++ compilers. However WAD works with other programs - that have been compiled with gcc. If gcc is installed on your - machine, you may want to set the following environment variables - before running configure: - - setenv CC cc - setenv CXX CC - ./configure - - - You may need to modify the Makefile to point to the installed locations - of various scripting language libraries if you have installed - them in non-traditional locations. - - - The Linux version has only been tested with 2.2-12 and 2.2-14 kernels - and the RedHat 6.x distribution. Your mileage may vary. There - may be some compatibility issues related to glibc and other parts - of the system as well. - -3. Using WAD - -WAD has no functional API nor does it have any command line options so -it's pretty easy to describe---simply link the appropriate WAD library with -your C code. For example: - - % cc blah.c -lwad - -Once linked, fatal errors will now produce stack traces. For example: - -% ./a.out seg -starting. -Segmentation fault. -#2 0x400571eb in __libc_start_main() in 'libc-start.c', line 90 -#1 0x08048b39 in main(argc=0x2,argv=0xbffffce4) in 'debug.c', line 62 -#0 0x080489b3 in seg_crash(n=0x0) in 'debug.c', line 9 - -/r0/beazley/Projects/WAD/Wad/debug.c, line 9 - - int *a = 0; - if (n > 0) seg_crash(n-1); - => *a = 3; - return 1; - } - -For scripting languages, WAD works in a similar manner--simply link -your scripting language extension module with the appropriate WAD library -(wadpy, wadtcl, wadpl). For example: - - % ld -G $(OBJS) -lwadpy -o pymodule.so - -When the scripting module is loaded into the interpreter, WAD should -automatically initialize. - -4. Debugging Modes - -Due to WAD's experimental nature, a number of debugging modes can be set -through the use of environment variables. These variables control WAD's -runtime behavior and cause the system to dump debugging information for -various stages of error recovery. A lot of this data is pretty ugly and -probably only of interest to you if you are trying to debug WAD itself. - -WAD_DEBUG_SEGMENT - Displays information about the virtual memory - map and mapping of addresses to segments. - -WAD_DEBUG_SYMBOL - Symbol table mapping. - -WAD_DEBUG_OBJECT - Loading/Unloading of object files. - -WAD_DEBUG_FILE - Loading/Unloading of raw files. - -WAD_DEBUG_HOLD - Freezes WAD before it returns from the signal handler. - Useful if you need to attach a debugger to WAD itself. - -WAD_DEBUG_STABS - Display stabs data. - -WAD_DEBUG_RETURN - Display information about WAD return points. - -WAD_DEBUG_SYMBOL_SEARCH - Display all symbols in the symbol table that are - searched. - -WAD_DEBUG_UNWIND - Display information about stack unwinding. - -WAD_DEBUG_SIGNAL - Display information about signal handling. - -WAD_DEBUG_INIT - Print initialization information. - -WAD_NOSTACK - Do NOT use an alternative signal handling stack. - This may be necessary on certain Linux systems when - threads are being used. - -WAD_ONESHOT - Disable WAD signal handler after first signal has - been received. - -WAD_DEBUG_MEMORY - Print information about WAD memory use. - -WAD_DEBUG_STRINGS - Print information about WAD string manager. - -5. Platform Specific Issues - -General: - - - WAD does not gracefully recover from errors that corrupt the call - stack (i.e., buffer overlow). - - - Errors that destroy the process heap may or may not be recoverable - depending on what has been destroyed. - - - WAD does not currently support 64 bit applications on any platform. - - - If executables have been stripped, their symbol tables might not - have enough information to recover from errors. Therefore, if you - are using Python, Tcl, or Perl from a binary distribution, you - may want to rebuild non-stripped versions of these packages yourself. - - - WAD only works with programs that utilize the ELF32 linking format - and stabs debugging data. Newer formats such as DWARF2 are not - supported at this time. - - - WAD does not correctly report argument values for structures or - floating point numbers yet. - - - Overly aggressive compiler optimization may lead to very strange - WAD output. - -Solaris: - - - WAD is extremely slow at collecting debugging information - from large applications. - -Linux: - - - The interaction of threads and signals are particularly problematic - on this platform and may cause WAD not to work at all. Here are - some specific thread-based issues that may arise: - - 1. WAD causes the program to crash immediately upon startup. - This appears to be caused by a bug in in the implementation - of sigaction() and the initialization of signals. This - only occurs if WAD is directly linked to an executable - using threads. It does not occur when WAD is dynamically - loaded into a threaded application. - - 2. Programs may lock up when an error occurs. This is sometimes - caused by an apparently broken implementation of sigaltstack(). - One solution to this is to set the following environment - variable: - - setenv WAD_NOSTACK - - in which case the WAD signal handler will use the same - stack as the thread/process that generates the error. - - 3. WAD just crashes altogether and doesn't seem to do anything. - It appears that some versions of Linux threads do *not* - pass CPU context information correctly to signal handlers - defined in threaded programs. There is no known fix to - this at this time. Upgrade your system. - - - WAD does not work if it is compiled as PIC code. The WAD libraries - should be compiled *without* the -fpic option. - - - WAD has to rely upon a heuristic register recovery scheme when it - returns to scripting language interpreters. It seems to - work, but it relies upon a very specific compiler code generation - convention for saving registers in function prologues. It also - relies upon the register save conventions described in the Linux - Assembly HOWTO. - - - If you are using WAD with pre-installed binaries for Python, Tcl, - and other scripting languages, it may not work correctly due to - stripped symbol tables. Most Linux installs such as Redhat strip - symbol tables from executables. This makes it difficult for WAD - to determine context correctly (although it may still work since - the dynamic loading symbol table is still available in most cases). - -6. Language specific issues - -If WAD is linked with a normal C/C++ program, errors simply produce a stack trace -that is printed on standard error. - -Python: - -WAD tries to raise a Python exception and return. At this time, the exception -merely contains a traceback string. However, in future versions, it may be -possible to access a complete exception object. - -Tcl: - -WAD returns a Tcl and places the stack trace into the Tcl variable $errorInfo. -The wish shell uses this to dump error information. - -Perl: - -Perl doesn't seem to have a very well-defined exception handling -mechanism. Standard functions tend to just exit. The WAD handler -produces a C stack trace and produces a Perl stack trace using some -code derived from the sigtrap module. - -Note: 3/23/01 - Perl support is currently broken. - -7. Testing and Examples - -The Test directory contains some very simple code for testing WAD. In the -most simple form, compile the stand-along test program 'debug' as follows: - -% cd Test -% make - -Now, running it: - -% debug -WAD debug program. - -Usage: debug type - seg - Fail with an uninitialized pointer. - bus - Fail with a bus error. - abort - Fail with an assertion error. - math - Fail with a math error. - heap - Blow the process heap. - overflow - Buffer overflow on the stack. - -% debug seg -WAD debug program. -Segmentation fault. -#2 0x400581eb in __libc_start_main() in 'libc-start.c', line 90 -#1 0x08048b61 in main(argc=0x2,argv=0xbffffc54) in 'debug.c', line 85 -#0 0x080489d0 in seg_crash() in 'debug.c', line 15 - -/r0/beazley/Projects/WAD/Test/debug.c, line 15 - - int seg_crash() { - int *a = 0; - => *a = 3; - return 1; - } - -Additional targets 'make python', 'make tcl', and 'make perl' are also available. -The scripts debug.py, debug.tcl, debug.pl can be used to test these extensions. - -8. Documentation - -No official documentation exists at this time. However, details -of WAD's design and implementation can be found in papers presented -at the Ninth International Python Conference and the 2000 USENIX -Technical Conference. Both papers can be obtained at: - - http://systems.cs.uchicago.edu/wad - - -9. To-Do - -If you find WAD to be interesting or useful, there are a variety of -ways to contribute. Here is the short to-do list: - - - Better register management. Try to implement in a more portable - way. Add some support code for recovering local variables - that happen to be stored in registers. - - - Add heuristic for recovering functions called through an - -fomit-frame-pointer compiler optimization scheme. This - can probably be determined by looking at the function preamble - machine code. Then one can back-trace to the calling function - and look at it's preamble. - - - Continued clean up and modularization of the core. Many of the - internal APIs could be greatly improved. - - - Support for ELF64 linking format. - - - Support for DWARF2 debugging data. - - - Improved support for stack-overflow and heap-corruption. Although WAD - probably won't be able to recover, it still might be able to produce some - informative diagnostics. - - - Removal of printf() and other high-level library calls which may not - operate with a corrupted heap. - - - Better integration with scripting languages. - - - Support for new platforms. - - - Support for new scripting languages. - -Please contact me if you are interested in working on any of these projects. - -Dave Beazley (beazley@cs.uchicago.edu) -June 24, 2001 diff --git a/Tools/WAD/Tcl/Makefile.in b/Tools/WAD/Tcl/Makefile.in deleted file mode 100644 index b734a8c5f..000000000 --- a/Tools/WAD/Tcl/Makefile.in +++ /dev/null @@ -1,54 +0,0 @@ -####################################################################### -# WAD Makefile -# -# David Beazley -# January 1, 2001 -####################################################################### - -# These are the files that make up the WAD core -SRCS = wadtcl.c -OBJS = wadtcl.o -INCLUDE = -I../Include -I. $(SINCLUDE) -WADOPT = @WADOPT@ - -# Location of your Tcl installation -TCLINCLUDE = @TCLINCLUDE@ -TCLSRCS = wadtclinit.cxx -TCLOBJS = wadtclinit.o - -# C Compiler -CC = @CC@ -CFLAGS = #@CCSHARED@ - -# C++ Compiler -CXX = @CXX@ -CXXFLAGS = #@CXXSHARED@ - -# Linking options -CLINK = -CXXLINK = @CXXLINK@ - -# Rules for creation of a .o file from .cxx -.SUFFIXES: .cxx -.cxx.o: - $(CXX) $(CXXFLAGS) $(WADOPT) $(INCLUDE) -c -o $*.o $< - -.c.o: - $(CC) $(CFLAGS) $(TCLINCLUDE) $(WADOPT) $(INCLUDE) -c -o $*.o $< - -tcl: $(OBJS) $(TCLOBJS) - $(CXXLINK) $(OBJS) $(TCLOBJS) -o libwadtcl.so -L.. -lwadcore - cp libwadtcl.so .. - -wc:: - wc $(SRCS) - -semi:: - @egrep ";" $(SRCS) $(TCLSRCS) | wc - -clean:: - rm -f *.o *.so *~ - - - - diff --git a/Tools/WAD/Tcl/wadtcl.c b/Tools/WAD/Tcl/wadtcl.c deleted file mode 100644 index df68f7473..000000000 --- a/Tools/WAD/Tcl/wadtcl.c +++ /dev/null @@ -1,122 +0,0 @@ -/* ----------------------------------------------------------------------------- - * wadtcl.c - * - * Dynamically loadable Tcl module for wad. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include -#include "wad.h" -#include - -static char cvs[] = "$Id$"; - -/* Handler function */ -static void handler(int signo, WadFrame *frame, char *ret) { - static char message[65536]; - static char temp[1024]; - int len = 0; - char *name; - WadFrame *f; - WadFrame *fline = 0; - char *srcstr= 0; - Tcl_Interp *interp; - int err; - char *type; - - if (!ret) { - wad_default_callback(signo, frame, ret); - return; - } - - strcpy(message,"[ C stack trace ]\n\n"); - switch(signo) { - case SIGSEGV: - type = (char*)"Segmentation fault."; - break; - case SIGBUS: - type = (char*)"Bus error."; - break; - case SIGABRT: - type = (char*)"Abort."; - break; - case SIGFPE: - type = (char*)"Floating point exception."; - break; - default: - type = (char*)"Unknown."; - break; - } - - f = frame; - /* Find the last exception frame */ - while (!f->last) { - f= f->next; - } - /* Now work backwards */ - f = f->prev; - while (f) { - strcat(message, f->debug_str); - if (f->debug_srcstr) srcstr = f->debug_srcstr; - f = f->prev; - } - if (srcstr) { - strcat(message,"\n"); - strcat(message, srcstr); - strcat(message,"\n"); - } - - if (wad_heap_overflow) { - write(2, "WAD: Heap overflow detected.\n", 30); - wad_default_callback(signo, frame, ret); - } - - /* Note: if the heap is blown, there is a very good chance that this - function will not succeed and we'll dump core. However, the check - above should dump a stack trace to stderr just in case we don't make it - back. */ - - /* Try to get the Tcl interpreter through magic */ - if (ret) { - interp = (Tcl_Interp *) wad_steal_outarg(frame,ret,1,&err); - if (err == 0) { - Tcl_SetResult(interp,type,TCL_STATIC); - Tcl_AddErrorInfo(interp,message); - } - } -} - -void tclwadinit() { - printf("WAD Enabled\n"); - wad_init(); - wad_set_callback(handler); - wad_set_return("TclExecuteByteCode", TCL_ERROR); - wad_set_return("EvalObjv", TCL_ERROR); -} - -int Wad_Init(Tcl_Interp *interp) { - return TCL_OK; -} - -int Wadtcl_Init(Tcl_Interp *interp) { - return TCL_OK; -} diff --git a/Tools/WAD/Tcl/wadtclinit.cxx b/Tools/WAD/Tcl/wadtclinit.cxx deleted file mode 100644 index 30c288cea..000000000 --- a/Tools/WAD/Tcl/wadtclinit.cxx +++ /dev/null @@ -1,38 +0,0 @@ -/* ----------------------------------------------------------------------------- - * wadtclinit.cxx - * - * C++ initializer for Tcl wad. - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ -static char cvs[] = "$Id$"; - -extern "C" void tclwadinit(); - -/* This hack is used to auto-initialize wad regardless of whether we are - used as an imported module or as a link-library for another module */ - -class wadinitializer { -public: - wadinitializer() { - tclwadinit(); - } -}; - -static wadinitializer wi; diff --git a/Tools/WAD/Test/Makefile.in b/Tools/WAD/Test/Makefile.in deleted file mode 100644 index c6e808275..000000000 --- a/Tools/WAD/Test/Makefile.in +++ /dev/null @@ -1,44 +0,0 @@ -####################################################################### -# WAD Test makefile -# -# Build some WAD test programs. -####################################################################### - -CC= @CC@ -CCSHARED = @CCSHARED@ -LDSHARED = @LDSHARED@ -RPATH = @RPATH@ - -PYINCLUDE = @PYINCLUDE@ -TCLINCLUDE = @TCLINCLUDE@ -PERLINCLUDE = @PERL5EXT@ -INCLUDE = -I../Include -WADLIB = .. -WADLINK = -L$(WADLIB) $(RPATH)$(WADLIB) - -test: - $(CC) -g -DNEED_MAIN debug.c $(INCLUDE) $(WADLINK) -lwad -o debug - -python: pydebug.c - $(CC) $(CCSHARED) -c -g debug.c pydebug.c $(PYINCLUDE) - $(LDSHARED) debug.o pydebug.o $(WADLINK) -lwadpy -o debugmodule.so - -tcl: tcldebug.c - $(CC) $(CCSHARED) -c -g debug.c tcldebug.c $(TCLINCLUDE) - $(LDSHARED) debug.o tcldebug.o $(WADLINK) -lwadtcl -o debug.so - -perl: pldebug.c - $(CC) $(CCSHARED) -c -Dbool=char -g debug.c pldebug.c $(PERLINCLUDE) - $(LDSHARED) debug.o pldebug.o $(WADLINK) -lwadpl -o debug.so - -pydebug.c: - swig -python -o pydebug.c debug.i - -tcldebug.c: - swig -tcl -o tcldebug.c debug.i - -pldebug.c: - swig -perl5 -o pldebug.c debug.i - -clean: - rm -f *.so *.o debug *_wrap* diff --git a/Tools/WAD/Test/README b/Tools/WAD/Test/README deleted file mode 100644 index 6a04a7e8a..000000000 --- a/Tools/WAD/Test/README +++ /dev/null @@ -1,5 +0,0 @@ -Simple test programs for WAD. This is currently incomplete. - -Note: To completely rebuild the Python, Perl, and Tcl tests, -you need to have SWIG installed (www.swig.org). - diff --git a/Tools/WAD/Test/death.py b/Tools/WAD/Test/death.py deleted file mode 100644 index ba1de20a3..000000000 --- a/Tools/WAD/Test/death.py +++ /dev/null @@ -1,65 +0,0 @@ -import debug -from Tkinter import * - -def death_by_segmentation(): - debug.seg_crash() - -def death_by_bus(): - debug.bus_crash() - -def death_by_abort(): - debug.abort_crash(-1) - -def death_by_math(): - debug.math_crash(37,0) - -def death_by_buffer(): - debug.overflow_crash() - -def death(f): - ty = f.tvar.get() - if ty == 1: - death_by_segmentation() - elif ty == 2: - death_by_abort() - elif ty == 3: - death_by_math() - elif ty == 4: - death_by_bus() - elif ty == 5: - death_by_buffer() - -class death_options(Frame): - def __init__(self): - Frame.__init__(self) - tvar = IntVar() - Radiobutton(self,text="Segmentation fault", variable=tvar, value=1).pack(anchor=W) - Radiobutton(self,text="Failed assertion", variable=tvar, value=2).pack(anchor=W) - Radiobutton(self,text="Math error", variable=tvar, value=3).pack(anchor=W) - Radiobutton(self,text="Bus error", variable=tvar, value=4).pack(anchor=W) - Radiobutton(self,text="Stack overflow", variable=tvar, value=5).pack(anchor=W) - Button(self,text="Die", command=lambda x=self: death(x)).pack(expand=1, fill=BOTH) - self.tvar = tvar - tvar.set(1) - -def death_wizard(): - root = Tk() - l = Label(text="How would you like to die today?") - l.pack() - death_options().pack() - root.title("Death Wizard") -death_wizard() - -#root.mainloop() - - - - - - - - - - - - diff --git a/Tools/WAD/Test/death.tcl b/Tools/WAD/Test/death.tcl deleted file mode 100644 index e52fa9ec2..000000000 --- a/Tools/WAD/Test/death.tcl +++ /dev/null @@ -1,65 +0,0 @@ -load ./debug[info sharedlibextension] - -proc death_by_segmentation { } { - seg_crash -} - -proc death_by_bus { } { - bus_crash -} - -proc death_by_abort { } { - abort_crash -1 -} - -proc death_by_math { } { - math_crash 37 0 -} - -proc death_by_buffer { } { - overflow_crash -} - -set method 1 -proc death {} { - global method - if { $method == 1 } { - death_by_segmentation - } - if { $method == 2 } { - death_by_abort - } - if { $method == 3 } { - death_by_math - } - if { $method == 4 } { - death_by_bus - } - if { $method == 5 } { - death_by_buffer - } -} - -label .l -text "How would you like to die today?" -pack .l - -radiobutton .r1 -text "Segmentation fault" -variable method -value 1 -pack .r1 -anchor w - -radiobutton .r2 -text "Failed assertion" -variable method -value 2 -pack .r2 -anchor w - -radiobutton .r3 -text "Math error" -variable method -value 3 -pack .r3 -anchor w - -radiobutton .r4 -text "Bus error" -variable method -value 4 -pack .r4 -anchor w - -radiobutton .r5 -text "Stack overflow" -variable method -value 5 -pack .r5 -anchor w - -button .b -text "Die" -command death -pack .b -fill both -expand 1 - -wm title . "Death Wizard" - diff --git a/Tools/WAD/Test/debug.c b/Tools/WAD/Test/debug.c deleted file mode 100644 index b95b539f0..000000000 --- a/Tools/WAD/Test/debug.c +++ /dev/null @@ -1,119 +0,0 @@ -/* ----------------------------------------------------------------------------- - * debug.c - * - * This file contains a variety of different programming errors to test with - * WAD. - * ----------------------------------------------------------------------------- */ - -#include -#include -#include - -typedef double Real; -typedef Real Float; - -char buffer[256]; - -/* A simple segmentation fault on an uninitialized pointer */ -int seg_crash() { - int *a = 0; - *a = 3; - return 1; -} - -/* Blow the process heap */ - -int blowheap_crash() { - int i; - int *a = (int *) malloc(sizeof(int)); - - for (i = 0;; i++) { - a[i] = i; - } -} - -/* Buffer overflow crash on the stack */ -int overflow_crash() { - int a[512]; - int i; - - for (i = 0; i < 1024; i++) { - a[i] = i; - } -} - -/* A simple bus error. */ -int bus_crash() { - double *a = (double *) (buffer+1); - *a = 3.4; - return 1; -} - -/* An assertion */ -int abort_crash(int n) { - assert(n > 0); - return 1; -} - -/* A math error (maybe) */ -int math_crash(int x, int y) { - return x/y; -} - -void type_crash(int a, short b, char c, unsigned long d, float f, double g) { - int la; - short lb; - char lc; - long ld; - float lf; - double lg; - long ll; - - la = a; - lb = b; - lc = c; - ld = ld; - lf = lf; - lg = lg; - assert(0); -} - -#ifdef NEED_MAIN - -static const char *usage="\n\ -Usage: debug type\n\ - seg - Fail with an uninitialized pointer.\n\ - bus - Fail with a bus error.\n\ - abort - Fail with an assertion error.\n\ - math - Fail with a math error.\n\ - heap - Blow the process heap.\n\ - overflow - Buffer overflow on the stack.\n\ -"; - -int main(int argc, char **argv) { - int n; - - printf("WAD debug program.\n"); - - if (argc < 2) { - printf("%s\n", usage); - exit(0); - } - if (strcmp(argv[1],"abort") == 0) { - abort_crash(-4); - } else if (strcmp(argv[1],"seg") ==0) { - seg_crash(); - } else if (strcmp(argv[1],"bus") == 0) { - bus_crash(); - } else if (strcmp(argv[1],"math") == 0) { - math_crash(3,0); - } else if (strcmp(argv[1],"heap") == 0) { - blowheap_crash(); - } else if (strcmp(argv[1],"overflow") == 0) { - overflow_crash(); - } else if (strcmp(argv[1],"type") == 0) { - type_crash(0,2,'x',420000,3.14159,2.1828); - } -} - -#endif diff --git a/Tools/WAD/Test/debug.i b/Tools/WAD/Test/debug.i deleted file mode 100644 index 1823161fc..000000000 --- a/Tools/WAD/Test/debug.i +++ /dev/null @@ -1,9 +0,0 @@ -%module debug - -extern int seg_crash(); -extern int bus_crash(); -extern int blowheap_crash(); -extern int overflow_crash(); -extern int abort_crash(int); -extern int math_crash(int x, int y); -extern void type_crash(int, short, char, unsigned long, float, double); diff --git a/Tools/WAD/Test/debug.py b/Tools/WAD/Test/debug.py deleted file mode 100644 index 07d9453a8..000000000 --- a/Tools/WAD/Test/debug.py +++ /dev/null @@ -1,35 +0,0 @@ -# WAD debugging module for python - -import debug -import sys - -try: - name = sys.argv[1] -except: - print """ -usage: debug.py test - - seg - Segmentation fault due to uninitialized pointer. - bus - Bus error. - abort - Failed assertion. - math - Math error. - heap - Blown heap. - overflow - Buffer overflow. -""" - sys.exit(1) - -if name == "seg": - debug.seg_crash() -elif name == "bus": - debug.bus_crash() -elif name == "abort": - debug.abort_crash(-2) -elif name == "math": - debug.math_crash(3,0) -elif name == "heap": - debug.blowheap_crash() -elif name == "overflow": - debug.overflow_crash() -elif name == "type": - debug.type_crash(37,42, 'x', 420000, 3.14159, 2.1828) - diff --git a/Tools/WAD/Test/debug.tcl b/Tools/WAD/Test/debug.tcl deleted file mode 100644 index ab5cd16aa..000000000 --- a/Tools/WAD/Test/debug.tcl +++ /dev/null @@ -1,25 +0,0 @@ -# WAD debugging module for Tcl. This should be executed with wish - -load ./debug[info sharedlibextension] - -message .t -text "This program tests various program faults. Note: Not all of these errors can be gracefully handled." - -button .b1 -text "Segmentation fault" -command "seg_crash" -button .b2 -text "Bus error (not on Linux)" -command "bus_crash" -button .b3 -text "Abort" -command "abort_crash -1" -button .b4 -text "Math" -command "math_crash 3 0" -button .b5 -text "Blow Heap" -command "blowheap_crash" -button .b6 -text "Buffer overflow" -command "overflow_crash" -button .q -text "Quit" -command "exit" - -pack .t -fill x - -pack .b1 -fill x -pack .b2 -fill x -pack .b3 -fill x -pack .b4 -fill x -pack .b5 -fill x -pack .b6 -fill x -pack .q -fill x - - diff --git a/Tools/WAD/Test/foo.py b/Tools/WAD/Test/foo.py deleted file mode 100644 index dee2e7d57..000000000 --- a/Tools/WAD/Test/foo.py +++ /dev/null @@ -1,31 +0,0 @@ -import debug - -def foo(): - debug.abort_crash(-1) - -def bar(): - foo() - -def spam(): - bar() - -from Tkinter import * - -root = Tk() - -button = Button(text="Press me", command=spam) -button.pack() - -#root.mainloop() - - - - - - - - - - - - diff --git a/Tools/WAD/Test/wadpm.py b/Tools/WAD/Test/wadpm.py deleted file mode 100644 index 8a633129e..000000000 --- a/Tools/WAD/Test/wadpm.py +++ /dev/null @@ -1,49 +0,0 @@ -# ----------------------------------------------------------------------------- -# Wad port-mortem debugger -# -# David Beazley -# ----------------------------------------------------------------------------- - -import sys - -_last_exc = None -_last_level = 0 - -print "WAD port-mortem" - -class where_impl: - def __repr__(self): - global _last_exc, _last_level - if sys.last_value: - if sys.last_value[0] != _last_exc: - _last_exc = sys.last_value[0] - _last_level = 0 - else: - raise RuntimeError,"No pending error." - print repr(_last_exc) - return "" - -where = where_impl() - -class up_impl: - def __repr__(self): - global _last_exc, _last_level - if not _last_exc: - return "" - _last_level += 1 - print repr(_last_exc[_last_level]) - return "" - -up = up_impl() - -class down_impl: - def __repr__(self): - global _last_exc, _last_level - if not _last_exc: - return "" - _last_level -= 1 - print repr(_last_exc[_last_level]) - return "" - -down = down_impl() - diff --git a/Tools/WAD/Test/wpm.py b/Tools/WAD/Test/wpm.py deleted file mode 100644 index f849e3167..000000000 --- a/Tools/WAD/Test/wpm.py +++ /dev/null @@ -1,280 +0,0 @@ -# ----------------------------------------------------------------------------- -# WAD Post-mortem debugger -# -# This program can be used to walk up and down the call stack of a mixed -# Python-C program. The following commands are supported: -# -# w - A stack traceback -# u - Go up the call stack -# d - Go down the call stack -# e - Edit a file -# c - Clear the debugger. -# -# David Beazley -# Copyright (C) 2001 -# University of Chicago -# All Rights Reserved -# ----------------------------------------------------------------------------- - -import sys -import os -import traceback -import types -import linecache - - -print "**************************************************" -print "* WAD Debugger *" -print "**************************************************" - -# Save a local copy of the last exception and value objects from sys - -_last_type = sys.last_type -_last_value = sys.last_value -_last_traceback = sys.last_traceback -_last_level = 0 - -_cstack = None # Stack of C-only code -_pystack = None # Stack of Python only code -_combined_stack = None # Combined C-python stack - -_allmode = 0 # Show entire C stack - -# Generalized object for holding stack frames - -class wad_frame: - def __init__(self,frame, n = 0): - if isinstance(frame,types.TupleType): - # A Python traceback object - self.__FILE__ = frame[0] - self.__LINE__ = frame[1] - self.__NAME__ = frame[2] - self.__ARGSTR__ = frame[3] - self.__FRAMENO__ = n - # Make the debugging string - self.__DEBUGSTR__ = "#%-3d [ Python ] in %s in %s, line %d" % (self.__FRAMENO__, self.__ARGSTR__, self.__FILE__, self.__LINE__) - - # Try to get source data - self.__SOURCE__ = "%s, Line %d\n\n" % (self.__FILE__, self.__LINE__) - for i in range(self.__LINE__-2,self.__LINE__+3): - l = linecache.getline(self.__FILE__,i) - if not l: l = '\n' - if (i == self.__LINE__): - self.__SOURCE__ += " => " - else: - self.__SOURCE__ += " " - self.__SOURCE__ += l - self.__frame__ = None - - elif hasattr(frame,"__WAD__"): - # A WAD traceback object - self.__FILE__ = frame.__FILE__ - self.__LINE__ = frame.__LINE__ - self.__NAME__ = frame.__NAME__ - self.__DEBUGSTR__ = frame.__WHERE__ - self.__SOURCE__ = frame.__SOURCE__ - self.__frame__ = frame - - def __str__(self): - return self.__DEBUGSTR__.strip() - - def __getattr__(self,name): - if self.__frame__: - return getattr(self.__frame__,name) - raise AttributeError - - def output(self): - print self - if self.__SOURCE__: - print "\n%s" % (self.__SOURCE__) - - -def wad_build_info(): - global _last_type,_last_value, _last_traceback, _cstack, _combined_stack,_pystack - - _last_type = None - _last_value = None - _last_traceback = None - _cstack = None - _combined_stack = [] - - # Check to see if any exception is defined - if not sys.last_type: - print "No exception has occurred." - return - - # Save a copy of previous exception - _last_type = sys.last_type - _last_value = sys.last_value - _last_traceback = sys.last_traceback - _last_level = 0 - - start_frame = 0 - # Test to see what kind of object it is - if issubclass(_last_type,StandardError): - # Python exception - print "Python exception" - elif hasattr(_last_value[0],"__WAD__"): - # A wad exception frame object - w = sys.last_value[0] - i = 0 - _cstack = [] - while not w[i].__LAST__: - start_frame += 1 - wf = wad_frame(w[i]) - _cstack.append(wf) - i = i + 1 - -# wf = wad_frame(w[i]) -# _cstack.append(wf) -# start_frame += 1 - - # Build the rest of the c stack - _combined_stack = _cstack[:] - while i < len(w): - wf = wad_frame(w[i]) - _cstack.append(wf) - i = i + 1 - - else: - print "Unknown error" - - # Build the Python call stack - _pystack = [] - t = sys.last_traceback - tp = None - while hasattr(t,"tb_frame"): - tp = t - t = t.tb_next - - fr = traceback.extract_stack(tp.tb_frame) - for i in range(len(fr),0,-1): - f = wad_frame(fr[i-1], start_frame) - start_frame += 1 - _pystack.append(f) - _combined_stack.extend(_pystack) - - -wad_build_info() - -class where_impl: - def __init__(self): - self.all = 0; - self.cstack = 0 - - def __repr__(self): - global _combined_stack, _cstack, _last_level - if (self.cstack): - stack = _cstack - else: - stack = _combined_stack - - if not stack: - print "No current exception." - return "" - - last_source = None - for i in range(len(stack),0,-1): - f = stack[i-1] - print f - if (f.__SOURCE__): - last_source = f.__SOURCE__ - _last_level = i-1 - if last_source: print "\n%s" % last_source - return "" - - def __getitem__(self,n): - global _last_level, _cstack, _combined_stack - if (self.cstack): - stack = _cstack - else: - stack = _combined_stack - _last_level = n - stack[_last_level].output() - return None - - def __len__(self): - return len(frame) - - -where = where_impl() -w = where - -class up_impl: - def __repr__(self): - global _last_level, _combined_stack, _cstack - if where.cstack: - stack = _cstack - else: - stack = _combined_stack - - if not stack: - return "" - _last_level += 1 - stack[_last_level].output() - return "" - -up = up_impl() -u = up - -class down_impl: - def __repr__(self): - global _last_level, _combined_stack, _cstack - if where.cstack: - stack = _cstack - else: - stack = _combined_stack - - if not stack: - return "" - _last_level -= 1 - stack[_last_level].output() - return "" - -down = down_impl() -d = down - -class clear_impl: - def __repr__(self): - global _last_exc, _last_level, frame - _last_exc = None - frame = None - -clear = clear_impl() -c = clear - -class edit_impl: - def __repr__(self): - global _last_level, _combined_stack, _cstack - if where.cstack: - stack = _cstack - else: - stack = _combined_stack - - if not stack: - return "" - f = stack[_last_level] - e = os.getenv("EDITOR","vi") - if f.__FILE__: - os.system("%s +%d %s" % (e,f.__LINE__,f.__FILE__)) - return "" - -edit = edit_impl() -e = edit - -class var_impl: - def __getattr__(self,name): - if (w.cstack): - stack = _cstack - else: - stack = _combined_stack - - return getattr(stack[_last_level],name) - - -v = var_impl() - - -repr(w) - - diff --git a/Tools/WAD/Wad/Makefile.in b/Tools/WAD/Wad/Makefile.in deleted file mode 100644 index b933dfa23..000000000 --- a/Tools/WAD/Wad/Makefile.in +++ /dev/null @@ -1,73 +0,0 @@ -####################################################################### -# WAD Makefile -# -# David Beazley -# January 1, 2001 -####################################################################### - -# These are the files that make up the WAD core -WADSRCS = string.c vars.c io.c memory.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c -WADOBJS = string.o vars.o io.o memory.o return.o default.o stack.o stab.o elf.o object.o signal.o segment.o init.o -INCLUDE = -I../Include -I. $(SINCLUDE) -WADOPT = @WADOPT@ - - -# Location of your Perl installation -PERLINCLUDE = @PERL5EXT@ -PERLSRCS = wadpl.cxx -PERLOBJS = wadpl.o - -# C Compiler -CC = @CC@ -CFLAGS = #@CCSHARED@ - -# C++ Compiler -CXX = @CXX@ -CXXFLAGS = #@CXXSHARED@ - -# Linking options -CLINK = -CXXLINK = @CXXLINK@ - -# AR -AR = @AR@ - -# Rules for creation of a .o file from .cxx -.SUFFIXES: .cxx -.cxx.o: - $(CXX) $(CXXFLAGS) $(WADOPT) $(INCLUDE) -c -o $*.o $< - -.c.o: - $(CC) $(CFLAGS) $(WADOPT) $(INCLUDE) -c -o $*.o $< - -wad: $(WADOBJS) main.o - $(CXXLINK) $(WADOBJS) main.o -o libwad.so - $(AR) cr libwadcore.a $(WADOBJS) - cp libwad.so .. - cp libwadcore.a .. - -perl: wad_perl_handler.c $(WADOBJS) $(PERLOBJS) - $(CXXLINK) $(WADOBJS) $(PERLOBJS) -o libwadpl.so - cp libwadpl.so .. - -wad_perl_handler.c: - python makehandler.py - -debug:: - cc -g debug.c $(INCLUDE) -L. -R. -lwad - -plus:: - CC -g debug.cxx $(INCLUDE) -L. -R. -lwad - -wc:: - wc $(SRCS) - -semi:: - @egrep ";" $(WADSRCS) plat/*.c | wc - -clean:: - rm -f *.o *.so *~ - - - - diff --git a/Tools/WAD/Wad/debug.c b/Tools/WAD/Wad/debug.c deleted file mode 100644 index fcdb87a60..000000000 --- a/Tools/WAD/Wad/debug.c +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include "wad.h" -#include - -typedef struct Foo { - double a; - double b; - float c; -} Foo; - -static int type_crash(int n, short m, char c, double x, float y, Foo f, void *ptr) { - int *a = 0; - *a = 3; - return 1; -} -static int seg_crash(int n, double x, - float y) { - int *a = 0; - if (n > 0) seg_crash(n-1,x,y); - *a = 3; - return 1; -} - -int bus_crash(int n) { - int b; - int *a = &b; - a = (int *) ((int) a | 0x1); - if (n > 0) bus_crash(n-1); - *a = 3; - printf("well, well, well.\n"); - return 1; -} - -int abort_crash(int n) { - assert(n > 0); - abort_crash(n-1); - return 1; -} - -double double_crash(double a, double b) { - double *c; - *c = a+b; - return *c; -} - -int math_crash(int x, int y) { - return x/y; -} - -int call_func(int n, int (*f)(int)) { - - int ret; - ret = (*f)(n); - if (ret <= 0) { - printf("An error occurred!\n"); - } - return 0; -} - -static int multi(char a, short b, int c, double d) { - a = 'x'; - b = 15236; - c = 12345678; - d = 3.14159; - return c; -} - -static int test(int x, int (*f)(int)) { - return (*f)(-x); -} - -int main(int argc, char **argv) { - int n; - int (*f)(int); - Foo foo = { 3.14, 28.18, 1.0 }; - - printf("starting.\n"); - - if (strcmp(argv[1],"abort") == 0) { - abort_crash(0); - } else if (strcmp(argv[1],"seg") ==0) { - seg_crash(0,1,2); - } else if (strcmp(argv[1],"bus") == 0) { - bus_crash(0); - } else if (strcmp(argv[1],"ret") == 0) { - call_func(4,abort_crash); - } else if (strcmp(argv[1],"test") == 0) { - test(-1000,abort_crash); - } else if (strcmp(argv[1],"double") == 0) { - double_crash(3.14159,2.1828); - } else if (strcmp(argv[1],"math") == 0) { - math_crash(3,0); - } else if (strcmp(argv[1],"type") == 0) { - type_crash(34,42,17, 3.14159, 2.1828, foo, &foo); - } - multi(3,5,10,3.14); -} diff --git a/Tools/WAD/Wad/default.c b/Tools/WAD/Wad/default.c deleted file mode 100644 index fc72a9e08..000000000 --- a/Tools/WAD/Wad/default.c +++ /dev/null @@ -1,311 +0,0 @@ -/* ----------------------------------------------------------------------------- - * default.c - * - * Default signal handler. Just prints a stack trace and returns. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -#include - - -/* This function tries to produce some kind of sensible argument - string for a stack frame. If no debugging information is available, - we'll just dump the %i0-%i5 registers in hex. If debugging information - is available, we'll try to do something a little more sensible */ - -char *wad_arg_string(WadFrame *frame) { - static char str[1024]; - WadLocal *wp; - long *stack; - long *nextstack; - long *prevstack; - int i; - WadFrame *nf; - WadFrame *pf; - - nf = frame->next; - if (nf) - nextstack = (long *) nf->stack; - else - nextstack = 0; - - pf = frame->prev; - if (pf) - prevstack = (long *) pf->stack; - else - prevstack = 0; - - str[0] = 0; - stack = (long *) frame->stack; - - -#ifdef WAD_LINUX - if (!nf) { - return ""; - } -#endif - - if ((frame->debug_nargs < 0) || (0)){ - /* No argument information is available. If we are on SPARC, we'll dump - the %in registers since these usually hold input parameters. On - Linux, we do nothing */ - -#ifdef WAD_SOLARIS - for (i = 0; i < 6; i++) { - wad_strcat(str,"0x"); - wad_strcat(str,wad_format_hex((unsigned long) stack[8+i],0)); - if (i < 5) - wad_strcat(str,","); - } -#endif - } else { - /* We were able to get some argument information out the debugging table */ - wp = frame->debug_args; - for (i = 0; i < frame->debug_nargs; i++, wp = wp->next) { - wad_strcat(str,wp->name); - wad_strcat(str,"="); - wad_strcat(str,wad_format_var(wp)); - if (i < (frame->debug_nargs-1)) wad_strcat(str,","); - } - } - return str; - -} - -char *wad_strip_dir(char *name) { - char *c; - /* printf("strip: '%s'\n", name); */ - c = name + strlen(name); - while (c != name) { - if (*c == '/') { - c++; - return c; - } - c--; - } - return name; -} - - - -static char *src_file = 0; -static int src_len = 0; -static char src_path[1024] = ""; - -/* Opens up a source file and tries to locate a specific line number */ - -char *wad_load_source(char *path, int line) { - int fd; - char *c; - char *start; - int n; - - if (strcmp(src_path,path)) { - if (src_file) { - munmap(src_file, src_len); - src_file = 0; - src_len = 0; - } - fd = open(path, O_RDONLY); - if (fd < 0) return 0; - src_len = lseek(fd, 0, SEEK_END); - lseek(fd,0,SEEK_SET); - src_file = (char *)mmap(NULL,src_len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (src_file == MAP_FAILED) { - close(fd); - return 0; - } - close(fd); - wad_strcpy(src_path,path); - } - n = 0; - start = src_file; - c = src_file; - while (n < src_len) { - if (*c == '\n') { - line--; - if (line == 0) { - return start; - } - start = c+1; - } - c++; - n++; - } - return 0; -} - -void wad_release_source() { - if (src_file) { - munmap(src_file,src_len); - src_file = 0; - src_len = 0; - src_path[0] = 0; - } -} - -/* ----------------------------------------------------------------------------- - * wad_debug_src_code(WadFrame *f) - * - * Get source code for a frame - * ----------------------------------------------------------------------------- */ - -char *wad_debug_src_string(WadFrame *f, int window) { - static char temp[16384]; - - if (f->loc_srcfile && strlen(f->loc_srcfile) && (f->loc_line > 0)) { - char *line, *c; - int i; - int first, last; - first = f->loc_line - window; - last = f->loc_line + window; - if (first < 1) first = 1; - line = wad_load_source(f->loc_srcfile,first); - if (line) { - wad_strcpy(temp,f->loc_srcfile); - wad_strcat(temp,", line "); - wad_strcat(temp,wad_format_signed(f->loc_line,-1)); - wad_strcat(temp,"\n\n"); - for (i = first; i <= last; i++) { - if (i == f->loc_line) wad_strcat(temp," => "); - else wad_strcat(temp," "); - c = strchr(line,'\n'); - if (c) { - *c = 0; - wad_strcat(temp,line); - wad_strcat(temp,"\n"); - *c = '\n'; - } else { - wad_strcat(temp,line); - wad_strcat(temp,"\n"); - break; - } - line = c+1; - } - f->debug_srcstr = wad_strdup(temp); - return f->debug_srcstr; - } - } - f->debug_srcstr = 0; - return 0; -} - -/* ----------------------------------------------------------------------------- - * wad_debug_make_strings(WadFrame *f) - * - * This function walks the stack trace and tries to generate a debugging string - * ----------------------------------------------------------------------------- */ - -void -wad_debug_make_strings(WadFrame *f) { - static char msg[16384]; - while (f) { - wad_strcpy(msg,"#"); - wad_strcat(msg,wad_format_signed(f->frameno,3)); - wad_strcat(msg," 0x"); - wad_strcat(msg,wad_format_hex(f->pc,1)); - wad_strcat(msg," in "); - wad_strcat(msg, f->sym_name ? f->sym_name : "?"); - wad_strcat(msg,"("); - wad_strcat(msg,wad_arg_string(f)); - wad_strcat(msg,")"); - if (f->loc_srcfile && strlen(f->loc_srcfile)) { - wad_strcat(msg," in '"); - wad_strcat(msg, wad_strip_dir(f->loc_srcfile)); - wad_strcat(msg,"'"); - if (f->loc_line > 0) { - wad_strcat(msg,", line "); - wad_strcat(msg,wad_format_signed(f->loc_line,-1)); - /* Try to locate the source file */ - wad_debug_src_string(f, WAD_SRC_WINDOW); - } - } else { - if (f->loc_objfile && strlen(f->loc_objfile)) { - wad_strcat(msg," from '"); - wad_strcat(msg, wad_strip_dir(f->loc_objfile)); - wad_strcat(msg,"'"); - } - } - wad_strcat(msg,"\n"); - f->debug_str = wad_strdup(msg); - f = f->next; - } -} - -/* Dump trace to a file */ -void wad_dump_trace(int fd, int signo, WadFrame *f, char *ret) { - static char buffer[128]; - char *srcstr = 0; - - switch(signo) { - case SIGSEGV: - write(fd,"WAD: Segmentation fault.\n", 25); - break; - case SIGBUS: - write(fd,"WAD: Bus error.\n",17); - break; - case SIGABRT: - write(fd,"WAD: Abort.\n",12); - break; - case SIGFPE: - write(fd,"WAD: Floating point exception.\n", 31); - break; - case SIGILL: - write(fd,"WAD: Illegal instruction.\n", 26); - break; - default: - sprintf(buffer,"WAD: Signal %d\n", signo); - write(fd,buffer,strlen(buffer)); - break; - } - /* Find the last exception frame */ - - while (f && !(f->last)) { - f = f->next; - } - - while (f) { - write(fd,f->debug_str,strlen(f->debug_str)); - if (f->debug_srcstr) { - srcstr = f->debug_srcstr; - } - f = f->prev; - } - if (srcstr) { - write(fd,"\n",1); - write(fd,srcstr,strlen(srcstr)); - write(fd,"\n",1); - } -} - -/* ----------------------------------------------------------------------------- - * Default callback - * ----------------------------------------------------------------------------- */ - -void wad_default_callback(int signo, WadFrame *f, char *ret) { - wad_dump_trace(2,signo,f,ret); -} - diff --git a/Tools/WAD/Wad/demangle.c b/Tools/WAD/Wad/demangle.c deleted file mode 100644 index 6b8b541a2..000000000 --- a/Tools/WAD/Wad/demangle.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ----------------------------------------------------------------------------- - * demangle.c - * - * This file performs C++ partial name demangling to the extent that it - * seems reasonable. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -char *wad_cplus_demangle(WadSymbol *ws) { - static char buffer[4096]; - strcpy(buffer,ws->name); - return buffer; -} diff --git a/Tools/WAD/Wad/elf.c b/Tools/WAD/Wad/elf.c deleted file mode 100644 index 5a2947b02..000000000 --- a/Tools/WAD/Wad/elf.c +++ /dev/null @@ -1,428 +0,0 @@ -/* ----------------------------------------------------------------------------- - * elf.c - * - * ELF file management. This file contains functions for accessing ELF - * file data from a raw memory mapped ELF file (as performed by the - * functions in object.c). - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -#ifdef WAD_SOLARIS -#include -#endif -#ifdef WAD_LINUX -#include -#endif - -/* --- What's needed here (high level interface) : - - Mapping of addresses to symbols - - Mapping of symbols to file+line -*/ - - -/* ----------------------------------------------------------------------------- - * wad_elf_check() - * - * Checks to see if an object file is an ELF file. Returns 1 on success and - * changes the type flag of wo to indicate the type of ELF file. - * ----------------------------------------------------------------------------- */ - -int -wad_elf_check(WadObjectFile *wo) { - if (strncmp((char *)wo->ptr,ELFMAG, SELFMAG) != 0) - return 0; - - /* Probably need to put some kind of 32/64 bit check here */ - return 1; -} - -/* ----------------------------------------------------------------------------- - * wad_elf_phdrcnt() - * - * Return number of entries in the ELF program header section - * ----------------------------------------------------------------------------- */ - -int -wad_elf_phdrcnt(WadObjectFile *wo) { - Elf32_Ehdr *eh; - - eh = (Elf32_Ehdr *) wo->ptr; - return eh->e_phnum; -} - -/* ----------------------------------------------------------------------------- - * wad_elf_phdrpos() - * - * Return the location of the ELF program header. - * ----------------------------------------------------------------------------- */ - -void * -wad_elf_phdrpos(WadObjectFile *wo) { - Elf32_Ehdr *eh; - char *c; - eh = (Elf32_Ehdr *) wo->ptr; - c = (char *) wo->ptr; - return (void *) (c+eh->e_phoff); -} - -/* ----------------------------------------------------------------------------- - * wad_elf_shdrcnt() - * - * Return number of entries in the ELF section header - * ----------------------------------------------------------------------------- */ - -int -wad_elf_shdrcnt(WadObjectFile *wo) { - Elf32_Ehdr *eh; - - eh = (Elf32_Ehdr *) wo->ptr; - return eh->e_shnum; -} - - -/* ----------------------------------------------------------------------------- - * wad_elf_shdrpos() - * - * Return the location of the section headers - * ----------------------------------------------------------------------------- */ - -void * -wad_elf_shdrpos(WadObjectFile *wo) { - Elf32_Ehdr *eh; - char *c; - eh = (Elf32_Ehdr *) wo->ptr; - c = (char *) wo->ptr; - return (void *) (c+eh->e_shoff); -} - -/* ----------------------------------------------------------------------------- - * wad_elf_section_header() - * - * Get a specific section number - * ----------------------------------------------------------------------------- */ - -void *wad_elf_section_header(WadObjectFile *wo, int sn) { - Elf32_Ehdr *eh; - char *r; - - eh = (Elf32_Ehdr *) wo->ptr; - if ((sn < 0) || (sn >= eh->e_shnum)) return 0; - - r = (char *) wad_elf_shdrpos(wo) + (sn*eh->e_shentsize); - return (void *) r; -} - -/* ----------------------------------------------------------------------------- - * wad_elf_section_data() - * - * Get section data - * ----------------------------------------------------------------------------- */ - -void *wad_elf_section_data(WadObjectFile *wo, int sn) { - Elf32_Shdr *sh; - char *r; - - sh = (Elf32_Shdr *) wad_elf_section_header(wo,sn); - if (!sh) return 0; - - r = ((char *) wo->ptr) + sh->sh_offset; - return r; -} - -/* ----------------------------------------------------------------------------- - * wad_elf_section_size() - * Return section size - * ----------------------------------------------------------------------------- */ - -int wad_elf_section_size(WadObjectFile *wo, int sn) { - Elf32_Shdr *sh; - - sh = (Elf32_Shdr *) wad_elf_section_header(wo,sn); - if (!sh) return -1; - return sh->sh_size; -} - -/* ----------------------------------------------------------------------------- - * wad_elf_section_name() - * - * Returns the name of an ELF section - * ----------------------------------------------------------------------------- */ - -char *wad_elf_section_name(WadObjectFile *wo, int sn) { - Elf32_Ehdr *eh; - Elf32_Shdr *sh; - char *sectionstr; - - eh = (Elf32_Ehdr *) wo->ptr; - - /* Get the string table */ - sectionstr = (char *) wad_elf_section_data(wo,eh->e_shstrndx); - if (!sectionstr) { - return 0; - } - - /* Get the section header for the section */ - sh = (Elf32_Shdr *) wad_elf_section_header(wo,sn); - if (!sh) return 0; - return sectionstr + sh->sh_name; -} - -/* ----------------------------------------------------------------------------- - * wad_elf_section_byname() - * - * Get section data given a section name - * ----------------------------------------------------------------------------- */ - -int -wad_elf_section_byname(WadObjectFile *wo, char *name) { - int i; - char *sn; - int n; - - n = wad_elf_shdrcnt(wo); - for (i = 0; i pc; - base = (unsigned long) f->segment->base; - - nsymtab = wad_elf_section_byname(f->object,secname); - if (nsymtab < 0) return 0; - nstrtab = wad_elf_section_byname(f->object,strname); - if (nstrtab < 0) return 0; - - symtab_size = wad_elf_section_size(f->object,nsymtab); - sym = (Elf32_Sym *) wad_elf_section_data(f->object,nsymtab); - str = (char *) wad_elf_section_data(f->object,nstrtab); - - nsym = (symtab_size/sizeof(Elf32_Sym)); - for (i = 0; i < nsym; i++) { - name = str + sym[i].st_name; - /* Look for filename in case the symbol maps to a local symbol */ - if (ELF32_ST_TYPE(sym[i].st_info) == STT_FILE) { - localfile = name; - } - if (wad_debug_mode & DEBUG_SYMBOL_SEARCH) { - wad_printf("%x(%x): %s %x + %x, %x, %x\n", base, vaddr, name, sym[i].st_value, sym[i].st_size, sym[i].st_info, sym[i].st_shndx); - } - if (((base + sym[i].st_value) <= vaddr) && (vaddr <= (base+sym[i].st_value + sym[i].st_size))) { -#ifdef WAD_LINUX - /* If the section index is 0, the symbol is undefined */ - if (sym[i].st_shndx == 0) continue; -#endif - f->sym_name = name; - f->sym_nlen = strlen(name); - f->sym_base = base + sym[i].st_value; - f->sym_size = sym[i].st_size; - if (ELF32_ST_BIND(sym[i].st_info) == STB_LOCAL) { - f->sym_file = localfile; - f->sym_bind = SYM_LOCAL; - } else { - f->sym_bind = SYM_GLOBAL; - } - return 1; - } - } - return 0; -} - -void -wad_elf_find_symbol(WadFrame *f) { - /* We simply try a few possible sections */ - if (elf_search_section_sym(f,".symtab",".strtab")) return; - if (elf_search_section_sym(f,".dynsym",".dynstr")) return; - - /* Hmmm. No match found. Oh well */ - return; -} - -/* ----------------------------------------------------------------------------- - * wad_elf_debug_info() - * - * Gather debugging information about a function (if possible) - * ----------------------------------------------------------------------------- */ - -int -wad_elf_debug_info(WadFrame *f) { - int nstab, nstabstr, nstabindex, nstabindexstr, nstabexcl, nstabexclstr; - int ret; - void *stab; - char *stabstr; - int stabsize; - - nstab = wad_elf_section_byname(f->object,".stab"); - nstabstr = wad_elf_section_byname(f->object,".stabstr"); - nstabindex = wad_elf_section_byname(f->object,".stab.index"); - nstabindexstr = wad_elf_section_byname(f->object,".stab.indexstr"); - nstabexcl = wad_elf_section_byname(f->object,".stab.excl"); - nstabexclstr = wad_elf_section_byname(f->object,".stab.exclstr"); - -#ifdef DEBUG_DEBUG - wad_printf("nstab = %d\n", nstab); - wad_printf("nstabstr = %d\n", nstabstr); - wad_printf("nstabindex = %d\n", nstabindex); - wad_printf("nstabindexstr = %d\n", nstabindexstr); - wad_printf("nstabexcl = %d\n", nstabexcl); - wad_printf("nstabexclstr = %d\n", nstabexclstr); -#endif - - /* Now start searching stabs */ - - /* Look in the .stab section */ - if (nstab > 0) { - stab = wad_elf_section_data(f->object,nstab); - stabsize = wad_elf_section_size(f->object,nstab); - stabstr = (char *) wad_elf_section_data(f->object,nstabstr); - - - if (wad_search_stab(stab,stabsize,stabstr, f)) return 1; - } - - /* Look in the .stab.excl section. A solaris oddity? */ - - if (nstabexcl > 0) { - stab = wad_elf_section_data(f->object,nstabexcl); - stabsize = wad_elf_section_size(f->object, nstabexcl); - stabstr = (char *) wad_elf_section_data(f->object, nstabexclstr); - - if (wad_search_stab(stab,stabsize,stabstr, f)) return 1; - } - - /* Look in the .stab.index section. A Solaris oddity? */ - if (nstabindex > 0) { - - stab = wad_elf_section_data(f->object,nstabindex); - stabsize = wad_elf_section_size(f->object, nstabindex); - stabstr = (char *) wad_elf_section_data(f->object, nstabindexstr); - - if (wad_search_stab(stab,stabsize,stabstr, f)) { - /* Hmmm. Might be in a different file */ - WadObjectFile *wo1, *wold; - char objfile[MAX_PATH]; - /* printf("DEBUG %s\n", f->sym_name); */ - wad_strcpy(objfile, f->loc_objfile); - wo1 = wad_object_load(objfile); - if (wo1) { - wold = f->object; - f->object = wo1; - wad_find_debug(f); - f->object = wold; - return ret; - } else { - /* wad_printf("couldn't load %s\n", objfile); */ - } - /* if (!ret) return wad_search_stab(stab,stabsize,stabstr,f);*/ - return ret; - } - } - return 0; -} - -/* ----------------------------------------------------------------------------- - * wad_elf_debug() - * - * Print some debugging information about an object - * ----------------------------------------------------------------------------- */ - -void -wad_elf_debug(WadObjectFile *wo) { - int i; - wad_printf("ELF Debug : obj = %x (%s)\n", wo, wo->path); - wad_printf(" phdrcnt = %d\n", wad_elf_phdrcnt(wo)); - wad_printf(" phdrpos = %x\n", wad_elf_phdrpos(wo)); - wad_printf(" shdrcnt = %d\n", wad_elf_shdrcnt(wo)); - wad_printf(" shdrpos = %x\n", wad_elf_shdrpos(wo)); - for (i = 0; i < wad_elf_shdrcnt(wo); i++) { - wad_printf(" section '%s': data = 0x%x, size = %d\n", - wad_elf_section_name(wo,i), - wad_elf_section_data(wo,i), - wad_elf_section_size(wo,i)); - } -} - -/* general purpose functions exposed to the outside world */ - -/* ----------------------------------------------------------------------------- - * wad_find_symbol() - * ----------------------------------------------------------------------------- */ - -void -wad_find_symbol(WadFrame *f) { - if (wad_debug_mode & DEBUG_SYMBOL) { - wad_printf("wad: Searching for 0x%08x --> ", f->pc); - } - if (f->object) - wad_elf_find_symbol(f); - if (wad_debug_mode & DEBUG_SYMBOL) { - if (f->sym_name) { - wad_printf("%s", f->sym_name); - if (f->sym_file) - wad_printf(" in '%s'\n", f->sym_file); - else - wad_printf("\n"); - } else { - wad_printf("?\n"); - } - } -} - -void -wad_find_debug(WadFrame *f) { - /* if (f->debug_check) return; */ - if (f->object) { - wad_elf_debug_info(f); - } - /* f->debug_check = 1; */ -} - - - diff --git a/Tools/WAD/Wad/init.c b/Tools/WAD/Wad/init.c deleted file mode 100644 index fb44b8d1c..000000000 --- a/Tools/WAD/Wad/init.c +++ /dev/null @@ -1,113 +0,0 @@ -/* ----------------------------------------------------------------------------- - * init.c - * - * Initialize the wad system. This sets up a signal handler for catching - * SIGSEGV, SIGBUS, and SIGABRT. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -/* Debugging flag */ -int wad_debug_mode = 0; - -/* Initialize wad */ -void wad_init() { - static int init = 0; - - wad_memory_init(); - if (getenv("WAD_DEBUG_SEGMENT")) { - wad_debug_mode |= DEBUG_SEGMENT; - } - if (getenv("WAD_DEBUG_SYMBOL")) { - wad_debug_mode |= DEBUG_SYMBOL; - } - - if (getenv("WAD_DEBUG_OBJECT")) { - wad_debug_mode |= DEBUG_OBJECT; - } - - if (getenv("WAD_DEBUG_FILE")) { - wad_debug_mode |= DEBUG_FILE; - } - - if (getenv("WAD_DEBUG_HOLD")) { - wad_debug_mode |= DEBUG_HOLD; - } - - if (getenv("WAD_DEBUG_STABS")) { - wad_debug_mode |= DEBUG_STABS; - } - - if (getenv("WAD_DEBUG_RETURN")) { - wad_debug_mode |= DEBUG_RETURN; - } - - if (getenv("WAD_DEBUG_SYMBOL_SEARCH")) { - wad_debug_mode |= DEBUG_SYMBOL_SEARCH; - } - - if (getenv("WAD_DEBUG_INIT")) { - wad_debug_mode |= DEBUG_INIT; - } - - if (getenv("WAD_DEBUG_STACK")) { - wad_debug_mode |= DEBUG_STACK; - } - - if (getenv("WAD_DEBUG_UNWIND")) { - wad_debug_mode |= DEBUG_UNWIND; - } - - if (getenv("WAD_DEBUG_SIGNAL")) { - wad_debug_mode |= DEBUG_SIGNAL; - } - - if (getenv("WAD_NOSTACK")) { - wad_debug_mode |= DEBUG_NOSTACK; - } - - if (getenv("WAD_ONESHOT")) { - wad_debug_mode |= DEBUG_ONESHOT; - } - - if (getenv("WAD_DEBUG_STRING")) { - wad_debug_mode |= DEBUG_STRING; - } - - if (getenv("WAD_DEBUG_MEMORY")) { - wad_debug_mode |= DEBUG_MEMORY; - } - - if (wad_debug_mode & DEBUG_INIT) { - wad_printf("WAD: initializing\n"); - } - - - if (!init) { - wad_signal_init(); - wad_object_reset(); - } - init = 1; -} diff --git a/Tools/WAD/Wad/io.c b/Tools/WAD/Wad/io.c deleted file mode 100644 index afbb3093a..000000000 --- a/Tools/WAD/Wad/io.c +++ /dev/null @@ -1,107 +0,0 @@ -/* ----------------------------------------------------------------------------- - * io.c - * - * This file provides some I/O routines so that WAD can produce - * debugging output without using buffered I/O. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" -#include - -static char cvs[] = "$Id$"; - -/* Utility functions used to generate strings that are guaranteed not to - rely upon malloc() and related functions */ - -char *wad_format_hex(unsigned long u, int leading) { - static char result[64]; - int i; - char *c; - c = &result[63]; - *c = 0; - for (i = 0; i < (sizeof(unsigned long)*2); i++) { - int d; - d = (int) (u & 0xf); - c--; - if (d < 10) { - *c = '0' + d; - } else { - *c = 'a' + (d-10); - } - if (!u && !leading) break; - u = u >> 4; - } - return c; -} - -char *wad_format_unsigned(unsigned long u, int width) { - static char result[128]; - static char digits[] = "0123456789"; - char *c, *w; - int count = 0; - int i; - c = &result[64]; - while (u) { - int digit = u % 10; - *(--c) = digits[digit]; - count++; - u = u / 10; - } - if (!count) { - *(--c) = '0'; - count++; - } - w = &result[64]; - for (i = count; i < width; i++) { - *(w++) = ' '; - } - *w = 0; - return c; -} - -char *wad_format_signed(signed long s, int width) { - static char result[128]; - unsigned long u; - char *c = result; - if (s < 0) { - *(c++) = '-'; - width--; - u = (unsigned long) (-s); - if (u == 0) { - u = (unsigned long) s; - } - } else { - u = (unsigned long) s; - } - *c = 0; - wad_strcat(result, wad_format_unsigned(u,width)); - return result; -} - - -void wad_printf(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - vfprintf(stderr,fmt,ap); - va_end(ap); -} diff --git a/Tools/WAD/Wad/libwadpl.pm b/Tools/WAD/Wad/libwadpl.pm deleted file mode 100644 index 21a01db46..000000000 --- a/Tools/WAD/Wad/libwadpl.pm +++ /dev/null @@ -1,8 +0,0 @@ -package libwadpl; -require Exporter; -require DynaLoader; -@ISA = qw(Exporter DynaLoader); -package libwadpl; -bootstrap libwadpl; -@EXPORT = qw( ); -1; diff --git a/Tools/WAD/Wad/main.cxx b/Tools/WAD/Wad/main.cxx deleted file mode 100644 index 1cf5ce958..000000000 --- a/Tools/WAD/Wad/main.cxx +++ /dev/null @@ -1,14 +0,0 @@ -extern "C" { -#include "wad.h" -} - -/* This is a sick hack to force initialization upon loading */ - -class StartDebug { -public: - StartDebug() { - wad_init(); - } -}; - -static StartDebug s; diff --git a/Tools/WAD/Wad/makehandler.py b/Tools/WAD/Wad/makehandler.py deleted file mode 100755 index c4e23a654..000000000 --- a/Tools/WAD/Wad/makehandler.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/local/bin/python -import string -f = open("wadhandler.pl") -data = f.read() -f.close() - -data = string.replace(data,"\\", "\\\\") -data = string.replace(data,"\"", "\\\"") -data = string.replace(data,"\n", "\\n\\\n") - -f = open("wad_perl_handler.c","w") - -f.write("static char wad_perl_handler[] = \"") -f.write(data) -f.write("\";\n"); -f.close() - - - - diff --git a/Tools/WAD/Wad/memory.c b/Tools/WAD/Wad/memory.c deleted file mode 100644 index 0260cb89e..000000000 --- a/Tools/WAD/Wad/memory.c +++ /dev/null @@ -1,174 +0,0 @@ -/* ----------------------------------------------------------------------------- - * memory.c - * - * This file provides simple mmap() based memory management for WAD. Since - * the process heap-allocator might be corrupted when WAD is invoked, we - * have to do all of our own memory management. However, since WAD mostly - * just collects data, we only provide the function wad_malloc(). To - * release all allocated memory, the wad_release_memory() function should - * be used. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -typedef struct _WadMemory { - int npages; /* Number of pages */ - int last; /* Last offset in page */ - struct _WadMemory *next; /* Pointer to next allocation */ -} WadMemory; - -static WadMemory *current = 0; /* Current memory block */ -static int pagesize = 0; /* System page size */ -static int devzero = 0; -static int npalloc = 8; /* Number of pages per alloc */ - -/* ----------------------------------------------------------------------------- - * wad_memory_init() - * - * Initialize the WAD allocator. - * ----------------------------------------------------------------------------- */ - -int wad_memory_init() { - pagesize = getpagesize(); - devzero = open("/dev/zero", O_RDWR); - if (devzero < 0) { - wad_printf("WAD: couldn't open /dev/zero.\n"); - return -1; - } - return 0; -} - -/* ----------------------------------------------------------------------------- - * wad_page_alloc() - * - * Allocate pages using mmap - * ----------------------------------------------------------------------------- */ - -void *wad_page_alloc(int npages) { - void *m; - m = mmap(NULL, npages*pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, devzero, 0); - if (((long) m) == -1) return 0; - /* printf("page_alloc: %x - %x\n", m, ((char *) m) + npages*pagesize); */ - return m; -} - -/* ----------------------------------------------------------------------------- - * wad_malloc() - * - * Allocate memory using mmap(). If the allocation is smaller than half a page, - * We'll look at current to see if there is enough space. If so, we'll just - * use that memory. Otherwise, we'll allocate a new page. If the allocation - * request is larger than a page, we'll round up to the nearest page size and - * do a special allocation. - * ----------------------------------------------------------------------------- */ - -void *wad_malloc(int nbytes) { - void *ptr; - WadMemory *wm; - char *c; - int npages; - /* wad_printf("wad_malloc: %d\n", nbytes); */ - if (nbytes >= ((npalloc*pagesize) >> 2)) { - /* Large allocation. */ - npages = ((nbytes + sizeof(WadMemory))/pagesize) + 1; - ptr = wad_page_alloc(npages); - if (!ptr) return 0; - wm = (WadMemory *)ptr; - wm->npages = npages; - wm->last = sizeof(WadMemory) + 8; - wm->next = current; - current = wm; - c = (char *) current + (current->last); - current->last += ((nbytes & ~0x7) + 8); - return c; - } - /* Small allocation. See if there are any regions big enough */ - wm = current; - while (wm) { - if (((wm->npages*pagesize) - wm->last) > nbytes) { - /* Yep. Found a region */ - break; - } - wm = wm->next; - } - if (!wm) { - /* wad_printf("wad_malloc: new page\n", nbytes);*/ - wm = (WadMemory *) wad_page_alloc(npalloc); - if (!wm) return 0; - wm->npages = npalloc; - wm->last = sizeof(WadMemory) + 8; - wm->next = current; - current = wm; - } - c = ((char *) wm) + (wm->last); - wm->last += ((nbytes & ~0x7) + 8); - return c; -} - -/* ----------------------------------------------------------------------------- - * wad_strdup() - * - * Duplicate a string - * ----------------------------------------------------------------------------- */ - -char *wad_strdup(const char *c) { - char *t; - if (!c) c = ""; - t = (char *) wad_malloc(strlen(c)+1); - wad_strcpy(t,c); - return t; -} - -/* ----------------------------------------------------------------------------- - * wad_memcpy() - * ----------------------------------------------------------------------------- */ - -void wad_memcpy(void *t, const void *s, unsigned len) { - char *tc, *sc; - int i; - tc = (char *) t; - sc = (char *) s; - for (i = 0; i < len; i++, tc++, sc++) - *tc = *sc; -} - -/* ----------------------------------------------------------------------------- - * wad_memory_debug() - * ----------------------------------------------------------------------------- */ - -void wad_memory_debug() { - int total_alloc = 0; - int inuse = 0; - WadMemory *m; - if (wad_debug_mode & DEBUG_MEMORY) { - m = current; - while (m) { - total_alloc += (m->npages)*pagesize; - inuse += m->last; - m = m->next; - } - wad_printf("WAD: memory allocated %d bytes (%d bytes used).\n", total_alloc, inuse); - } -} diff --git a/Tools/WAD/Wad/object.c b/Tools/WAD/Wad/object.c deleted file mode 100644 index f13d6b320..000000000 --- a/Tools/WAD/Wad/object.c +++ /dev/null @@ -1,303 +0,0 @@ -/* ----------------------------------------------------------------------------- - * object.c - * - * This file provides access to raw object files, executables, and - * library files. Memory management is handled through mmap() to - * avoid the use of heap/stack space. - * - * All of the files and objects created by this module persist - * until the process exits. Since WAD may be invoked multiple times - * over the course of program execution, it makes little sense to keep - * loading and unloading files---subsequent invocations of the handler - * can simply used previously loaded copies. Caveat: things probably - * won't work right if a program is doing lots of low-level manipulation - * of the dynamic loader. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -#include - -typedef struct WadFile { - void *addr; /* Base address of the file */ - int size; /* Size in bytes */ - char *path; /* Path name */ - struct WadFile *next; /* Next file */ -} WadFile; - -static WadFile *wad_files = 0; /* Linked list of loaded files */ - -/* private function to manage the loading of raw files into memory */ -static WadFile * -load_file(const char *path) { - int fd; - WadFile *wf = wad_files; - - if (wad_debug_mode & DEBUG_FILE) { - wad_printf("wad: Loading file '%s' ... ", path); - } - while (wf) { - if (strcmp(wf->path,path) == 0) { - if (wad_debug_mode & DEBUG_FILE) wad_printf("cached.\n"); - return wf; - } - wf = wf->next; - } - fd = open(path, O_RDONLY); - if (fd < 0) { - if (wad_debug_mode & DEBUG_FILE) wad_printf("not found!\n"); - return 0; /* Doesn't exist. Oh well */ - } - if (wad_debug_mode & DEBUG_FILE) wad_printf("loaded.\n"); - wf = (WadFile *) wad_malloc(sizeof(WadFile)); - wf->path = wad_strdup(path); - - /* Get file length */ - wf->size = lseek(fd,0,SEEK_END); - lseek(fd,0,SEEK_SET); - - /* Try to mmap the file */ - wf->addr = mmap(NULL,wf->size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); - close(fd); - if (wf->addr == MAP_FAILED) { - if (wad_debug_mode & DEBUG_FILE) wad_printf("wad: Couldn't mmap '%s'\n", path); - return 0; - } - wf->next = wad_files; - wad_files = wf; - return wf; -} - -static WadObjectFile *wad_objects = 0; /* Linked list of object files */ - -/* ----------------------------------------------------------------------------- - * wad_object_cleanup() - * - * Reset the object file loader. This unmaps the files themselves, but - * memory will leak for object files pointers themselves. - * ----------------------------------------------------------------------------- */ - -void -wad_object_reset() { - WadFile *f = wad_files; - if (wad_debug_mode & DEBUG_OBJECT) { - wad_printf("wad: Releasing all files.\n"); - } - /* Unmap all of the loaded files */ - while (f) { - if (f->addr) { - munmap(f->addr, f->size); - } - f = f->next; - } - /* Reset the linked lists */ - wad_files = 0; - wad_objects = 0; -} - -/* ----------------------------------------------------------------------------- - * wad_object_load() - * - * Load an object file into memory using mmap. Returns 0 if the object does - * not exist or if we're out of memory. - * ----------------------------------------------------------------------------- */ - -WadObjectFile * -wad_object_load(const char *path) { - WadObjectFile *wo; - WadFile *wf; - WadObjectFile *wad_arobject_load(const char *path, const char *name); - - if (wad_debug_mode & DEBUG_OBJECT) { - wad_printf("wad: Loading object '%s'", path); - } - for (wo = wad_objects; wo; wo=wo->next) { - if (strcmp(wo->path,path) == 0) { - if (wad_debug_mode & DEBUG_OBJECT) { - wad_printf(" (cached)\n"); - } - return wo; - } - } - if (wad_debug_mode & DEBUG_OBJECT) { - wad_printf("\n"); - } - /* Didn't find it. Now we need to go load some files */ - - /* If this is an archive reference like /path/libfoo.a(blah.o), we need to - split up the name a little bit */ - { - char realfile[MAX_PATH]; - char *objfile; - char *c; - c = strchr(path,'('); - if (c) { - wad_strcpy(realfile,path); - c = strchr(realfile,'('); - *c = 0; - objfile = c+1; - c = strchr(objfile,')'); - *c = 0; - - /* Okay, I'm going to attempt to map this as a library file */ - wo = wad_arobject_load(realfile,objfile); - if (wo) { - /* Reset the path */ - wo->path = wad_strdup(path); - wo->next = wad_objects; - wad_objects = wo; - return wo; - } - } - } - wf = load_file(path); - if (!wf) return 0; - - wo = (WadObjectFile *) wad_malloc(sizeof(WadObjectFile)); - wo->path = wad_strdup(path); - wo->ptr = wf->addr; - wo->len = wf->size; - wo->next = wad_objects; - wad_objects = wo; - return wo; -} - -/* ----------------------------------------------------------------------------- - * wad_arobject_load() - * - * Load an object file stored in an archive file created with an archive. The - * pathname should be the path of the .a file and robjname should be the name - * of the object file stored in the object file. - * ----------------------------------------------------------------------------- */ - -WadObjectFile * -wad_arobject_load(const char *arpath, const char *robjname) { - WadObjectFile *wo; - WadFile *wf; - int arlen; - char *arptr; - struct ar_hdr *ah; - int offset; - int msize; - char *strtab = 0; - int sobjname; - char objname[MAX_PATH]; - - wad_strcpy(objname,robjname); - wad_strcat(objname,"/"); - sobjname = strlen(objname); - - wf = load_file(arpath); - if (!wf) return 0; /* Doesn't exit */ - - arptr = (char *) wf->addr; - arlen = wf->size; - - /* Now take a look at the archive */ - if (strncmp(arptr,ARMAG,SARMAG) == 0) { - /* printf("Got an archive\n"); */ - } else { - return 0; - } - - /* Search the archive for the request member */ - strtab = 0; - offset = SARMAG; - while (offset < arlen) { - char mname[MAX_PATH]; - ah = (struct ar_hdr *) (arptr + offset); - if (strncmp(ah->ar_name,"// ", 3) == 0) { - strtab = arptr + offset + sizeof(struct ar_hdr); - } - msize = atoi(ah->ar_size); - - offset += sizeof(struct ar_hdr); - /* Try to figure out the filename */ - if ((ah->ar_name[0] == '/') && (isdigit(ah->ar_name[1]))) { - int soff; - char *e; - /* Must be in the string offset table */ - soff = atoi(ah->ar_name+1); - if (!strtab) { - /* No offset table */ - return 0; - } - e = strchr(strtab+soff,'\n'); - if (e) { - strncpy(mname, strtab+soff, (e - (strtab+soff))); - mname[e-(strtab+soff)] = 0; - } else { - mname[0] = 0; - } - } else { - /* Name must be in the name field */ - strncpy(mname,ah->ar_name,16); - mname[16] = 0; - } - /* Compare the names */ - if (strncmp(mname,objname,sobjname) == 0) { - /* Found the archive */ - wo = (WadObjectFile *) wad_malloc(sizeof(WadObjectFile)); - wo->ptr = (void *) (arptr + offset); - wo->len = msize; - wo->path = 0; - return wo; - } - offset += msize; - } - return 0; -} - -/* ----------------------------------------------------------------------------- - * wad_find_object(WadFrame *f) - * - * Given a stack frame. Try to locate the object file - * ----------------------------------------------------------------------------- */ - -void wad_find_object(WadFrame *f) { - if (f->segment) { - f->object = wad_object_load(f->segment->mappath); - } -} - -/* ----------------------------------------------------------------------------- - * wad_file_check(void *addr) - * - * Given an address, this function checks to see if it corresponds to a file - * we already mapped. - * ----------------------------------------------------------------------------- */ - -int -wad_file_check(void *addr) { - WadFile *f = wad_files; - while (f) { - if ((((char *) f->addr) <= ((char *) addr)) && - (((char *) addr) < (((char *) f->addr) + f->size))) { - return 1; - } - f = f->next; - } - return 0; -} diff --git a/Tools/WAD/Wad/return.c b/Tools/WAD/Wad/return.c deleted file mode 100644 index 909cba314..000000000 --- a/Tools/WAD/Wad/return.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ----------------------------------------------------------------------------- - * return.c - * - * This file manages the set of return-points for the WAD signal handler. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -/* Maximum number of return points */ -#define WAD_NUMBER_RETURN 128 - -static WadReturnFunc return_points[WAD_NUMBER_RETURN]; -static int num_return = 0; - -void wad_set_return(const char *name, long value) { - WadReturnFunc *rp; - rp = &return_points[num_return]; - wad_strcpy(rp->name,name); - rp->value = value; - num_return++; - if (wad_debug_mode & DEBUG_RETURN) { - printf("wad: Setting return ('%s', %d)\n", name,value); - } -} - -void wad_set_returns(WadReturnFunc *rf) { - int i = 0; - while (strlen(rf[i].name)) { - wad_set_return(rf[i].name, rf[i].value); - i++; - } -} - -WadReturnFunc *wad_check_return(const char *name) { - int i; - if (!name) return 0; - for (i = 0; i < num_return; i++) { - if (strcmp(name,return_points[i].name) == 0) { - if (wad_debug_mode & DEBUG_RETURN) { - printf("wad: Found return ('%s', %d)\n", return_points[i].name, return_points[i].value); - } - return &return_points[i]; - } - } - return 0; -} - diff --git a/Tools/WAD/Wad/segment.c b/Tools/WAD/Wad/segment.c deleted file mode 100644 index ec4cf134f..000000000 --- a/Tools/WAD/Wad/segment.c +++ /dev/null @@ -1,227 +0,0 @@ -/* ----------------------------------------------------------------------------- - * segment.c - * - * This file provides access to the virtual memory map of a process - * including the location of the executable, data segments, shared - * libraries, and memory mapped regions. - * - * The primary purpose of this module is to collect this information - * and store it in a form that hides platform specific details (the - * WadSegment structure). - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -/* Include the proper code for reading the segment map */ - -#ifdef WAD_SOLARIS - -/* This code is used to read the process virtual memory map on Solaris machines */ - -static int -segment_open() { - int f; - f = open("/proc/self/map", O_RDONLY); - return f; -} - -static int -segment_read(int fs, WadSegment *s) { - int dz; - int n; - prmap_t pmap; - - n = read(fs, &pmap, sizeof(prmap_t)); - if (n <= 0) return 0; - s->mapname = wad_strdup(pmap.pr_mapname); - s->mappath = (char *) wad_malloc(20+strlen(pmap.pr_mapname)); - wad_strcpy(s->mappath,"/proc/self/object/"); - strcat(s->mappath,pmap.pr_mapname); - s->vaddr = (char *) pmap.pr_vaddr; - - /* This is a solaris oddity. a.out section starts 1 page up, but - symbols are relative to a base of 0 */ - - if (strcmp(s->mapname,"a.out") == 0) s->base = 0; - else s->base = s->vaddr; - - s->size = pmap.pr_size; - s->offset = pmap.pr_offset; - return 1; -} - -#endif /* WAD_SOLARIS */ - -#ifdef WAD_LINUX -static char linux_firstsegment[1024]; -static int linux_first = 1; - -static int -segment_open() { - FILE *f; - f = fopen("/proc/self/maps", "r"); - linux_first =1; - return (int) f; -} - -static int -segment_read(int fd, WadSegment *s) -{ - char pbuffer[1024]; - char *c; - int len; - FILE *fs = (FILE *) fd; - c = fgets(pbuffer,1024,fs); - if (!c) return 0; - - pbuffer[strlen(pbuffer)-1] = 0; /* Chop off endline */ - - /* Break up the field into records */ - /* 0-8 : Starting address - 9-17 : Ending Address - 18 : r - 19 : w - 20 : x - 21 : p - 23-31 : Offset - 49- : Filename */ - - len = strlen(pbuffer); - pbuffer[8] = 0; - pbuffer[17] = 0; - pbuffer[31] = 0; - if (len >= 49) { - s->mapname = wad_strdup(pbuffer+49); - s->mappath = s->mapname; - } else { - s->mapname = ""; - s->mappath = s->mapname; - } - if (linux_first) { - wad_strcpy(linux_firstsegment, s->mappath); - linux_first = 0; - } - s->vaddr = (char *) strtoul(pbuffer,NULL,16); - s->size = strtoul(pbuffer+9,NULL,16) - (long) (s->vaddr); - s->offset = strtoul(pbuffer+23,NULL,16); - if (strcmp(linux_firstsegment, s->mappath) == 0) { - s->base = 0; - } else { - s->base = s->vaddr; - } - s++; - return 1; -} - -#endif /* WAD_LINUX */ - -static WadSegment *segments = 0; /* Linked list of segments */ - -/* ----------------------------------------------------------------------------- - * wad_segment_read() - * - * Read all of the memory segments into a linked list. Any previous segment - * map is simply lost. The only way to reclaim this memory is to call - * wad_release_memory(). - * ----------------------------------------------------------------------------- */ - -int -wad_segment_read() { - int fs; - int n; - WadSegment *s, *lasts; - - segments = 0; - lasts = 0; - fs = segment_open(); - - while (1) { - s = (WadSegment *) wad_malloc(sizeof(WadSegment)); - skip: - n = segment_read(fs,s); - if (n <= 0) break; - if (wad_file_check(s->vaddr)) goto skip; /* Skip files we already loaded */ - s->next = 0; - if (!lasts) { - segments = s; - lasts = s; - } else { - lasts->next = s; - lasts = s; - } - if (wad_debug_mode & DEBUG_SEGMENT) { - wad_printf("wad_segment: read : %08x-%08x, base=%x in %s\n", s->vaddr, ((char *) s->vaddr) + s->size, s->base, s->mappath); - } - } - close(fs); - return 0; -} - -/* ----------------------------------------------------------------------------- - * wad_segment_find() - * - * Try to find the virtual memory segment corresponding to a virtual address. - * If a segment is mapped to a file, this function actually returns the *first* - * segment that is mapped. This is because symbol relocations are always - * performed relative to the beginning of the file (so we need the base address) - * ----------------------------------------------------------------------------- */ - -WadSegment * -wad_segment_find(void *vaddr) { - WadSegment *ls; - WadSegment *s; - char *addr = (char *)vaddr; - - s = segments; - ls = segments; - while (s) { - if (strcmp(s->mapname,ls->mapname) || (!strlen(ls->mapname))) { - ls = s; /* First segment for a given name */ - } - if ((addr >= s->vaddr) && (addr < (s->vaddr + s->size))) { - if (wad_debug_mode & DEBUG_SEGMENT) { - wad_printf("wad_segment: %08x --> %08x-%08x in %s\n", vaddr, s->vaddr, ((char *) s->vaddr) + s->size, s->mappath); - } - return ls; - } - s = s->next; - } - return 0; -} - -/* ----------------------------------------------------------------------------- - * wad_segment_valid() - * - * Checks to see if a memory address is valid or not based on data in the - * segment map - * ----------------------------------------------------------------------------- */ - -int wad_segment_valid(void *vaddr) { - return wad_segment_find(vaddr) ? 1 : 0; -} - - - - diff --git a/Tools/WAD/Wad/signal.c b/Tools/WAD/Wad/signal.c deleted file mode 100644 index 36f89c3c7..000000000 --- a/Tools/WAD/Wad/signal.c +++ /dev/null @@ -1,520 +0,0 @@ -/* ----------------------------------------------------------------------------- - * signal.c - * - * WAD signal handler. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -extern void wad_stab_debug(); - -/* For some odd reason, certain linux distributions do not seem to define the - register constants in a way that is easily accessible to us. This is a hack */ - -#ifdef WAD_LINUX -#ifndef ESP -#define ESP 7 -#endif -#ifndef EBP -#define EBP 6 -#endif -#ifndef EIP -#define EIP 14 -#endif -#ifndef ESI -#define ESI 5 -#endif -#ifndef EDI -#define EDI 4 -#endif -#ifndef EBX -#define EBX 8 -#endif - -#endif - -/* Signal handling stack */ -#define STACK_SIZE 4*SIGSTKSZ -char wad_sig_stack[STACK_SIZE]; - -/* This variable is set if the signal handler thinks that the - heap has overflowed */ - -int wad_heap_overflow = 0; - -static void (*sig_callback)(int signo, WadFrame *data, char *ret) = 0; - -void wad_set_callback(void (*s)(int,WadFrame *,char *ret)) { - sig_callback = s; -} - -/* This bit of nastiness is used to make a non-local return from the - signal handler to a configurable location on the call stack. In a nutshell, - this works by repeatedly calling "restore" to roll back the - register windows and stack pointer. Then we fake a return value and - return to the caller as if the function had actually completed - normally. */ - -int wad_nlr_levels = 0; -static volatile int *volatile nlr_p = &wad_nlr_levels; -long wad_nlr_value = 0; -void (*wad_nlr_func)(void) = 0; - -/* Set the return value from another module */ -void wad_set_return_value(long value) { - wad_nlr_value = value; -} - -/* Set the return function */ -void wad_set_return_func(void(*f)(void)) { - wad_nlr_func = f; -} - -#ifdef WAD_SOLARIS -static void nonlocalret() { - long a; - - a = wad_nlr_value; - /* We never call this procedure as a function. This code - causes an immediate return if someone does this */ - - asm("jmp %i7 + 8"); - asm("restore"); - - /* This is the real entry point */ - /* asm(".globl _returnsignal");*/ - asm(".type _returnsignal,2"); - asm("_returnsignal:"); - - while (*nlr_p > 0) { - (*nlr_p)--; - asm("restore"); - } - - asm("sethi %hi(wad_nlr_value), %o0"); - asm("or %o0, %lo(wad_nlr_value), %o0"); - asm("ld [%o0], %i0"); - - /* If there is a non-local return function. We're going to go ahead - and transfer control to it */ - - if (wad_nlr_func) - (*wad_nlr_func)(); - - asm("jmp %i7 + 8"); - asm("restore"); - asm(".size _returnsignal,(.-_returnsignal)"); -} -#endif - -#ifdef WAD_LINUX - -/* Saved values of the machine registers */ - -long wad_saved_esi = 0; -long wad_saved_edi = 0; -long wad_saved_ebx = 0; - -static void nonlocalret() { - asm("_returnsignal:"); - while (*nlr_p > 0) { - (*nlr_p)--; - asm("leave"); - } - - if (wad_nlr_func) - (*wad_nlr_func)(); - - /* Restore the registers */ - asm("movl wad_saved_esi, %esi"); - asm("movl wad_saved_edi, %edi"); - asm("movl wad_saved_ebx, %ebx"); - asm("movl wad_nlr_value, %eax"); - asm("leave"); - asm("ret"); -} - -/* This function uses a heuristic to restore the callee-save registers on i386. - According to the Linux Assembly HOWTO, the %esi, %edi, %ebx, and %ebp registers - are callee-saved. All others are caller saved. To restore the callee-save - registers, we use the fact that the C compiler saves the callee-save registers - (if any) at the beginning of function execution. Therefore, we can scan the - instructions at the start of each function in the stack trace to try and find - where they are. - - The following heuristic is used: - - 1. Each function starts with a preamble like this which saves the %ebp - register: - - 55 89 e5 ---> push %ebp - mov %esp, %ebp - - 2. Next, space is allocated for local variables, using one of two schemes: - - 83 ec xx ---> Less than 256 bytes of local storage - ^^^ - length - - 81 ec xx xx xx xx --> More than 256 bytes of local storage - ^^^^^^^^^^^ - length - - 3. After this, a collection of 1-byte stack push op codes might appear - - 56 = pushl %esi - 57 = pushl %edi - 53 = pushl %ebx - - - Based on the size of local variable storage and the order in which - the %esi, %edi, and %ebx registers are pushed on the stack, we can - determine where in memory the registers are saved and restore them to - their proper values. -*/ - -void wad_restore_i386_registers(WadFrame *f, int nlevels) { - WadFrame *lastf = f; - int localsize = 0; - unsigned char *pc; - unsigned long *saved; - int i, j; - int pci; - for (i = 0; i <= nlevels; i++, f=f->next) { - - /* This gets the starting instruction for the stack frame */ - pc = (unsigned char *) f->sym_base; - /* printf("pc = %x, base = %x, %s\n", f->pc, f->sym_base, SYMBOL(f)); */ - if (!pc) continue; - - /* Look for the standard prologue 0x55 0x89 0xe5 */ - if ((pc[0] == 0x55) && (pc[1] == 0x89) && (pc[2] == 0xe5)) { - /* Determine the size */ - pci = 3; - if ((pc[3] == 0x83) && (pc[4] == 0xec)) { - /* printf("8-bit size\n");*/ - localsize = (int) pc[5]; - pci = 6; - } - if ((pc[3] == 0x81) && (pc[4] == 0xec)) { - /* printf("32-bit size\n"); */ - localsize = (int) *((long *) (pc+5)); - pci = 10; - } - saved = (long *) (f->fp - localsize - sizeof(long)); - /* printf("saved = %x, fp = %x\n", saved, f->fp); - printf("localsize = %d\n", localsize); - */ - for (j = 0; j < 3; j++, saved--, pci++) { - if (pc[pci] == 0x57) { - wad_saved_edi = *saved; - /* printf("restored edi = %x\n", wad_saved_edi); */ - } - else if (pc[pci] == 0x56) { - wad_saved_esi = *saved; - /* printf("restored esi = %x\n", wad_saved_esi); */ - } - else if (pc[pci] == 0x53) { - wad_saved_ebx = *saved; - /* printf("restored ebx = %x\n", wad_saved_ebx); */ - } - else break; - } - } - } -} - -#endif - -void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) { - greg_t *pc; - greg_t *npc; - greg_t *sp; - greg_t *fp; -#ifdef WAD_LINUX - greg_t *esi; - greg_t *edi; - greg_t *ebx; -#endif - - unsigned long addr; - ucontext_t *context; - unsigned long p_sp; /* process stack pointer */ - unsigned long p_pc; /* Process program counter */ - unsigned long p_fp; /* Process frame pointer */ - int nlevels = 0; - int found = 0; - void _returnsignal(); - WadFrame *frame, *origframe; - char *framedata; - char *retname = 0; - unsigned long current_brk; - - /* Reset all of the signals while running WAD */ - wad_signal_clear(); - - wad_nlr_func = 0; - - context = (ucontext_t *) vcontext; - - wad_printf("WAD: Collecting debugging information...\n"); - - /* Read the segments */ - if (wad_segment_read() < 0) { - wad_printf("WAD: Unable to read segment map\n"); - return; - } - - if (wad_debug_mode & DEBUG_SIGNAL) { - wad_printf("WAD: siginfo = %x, context = %x\n", si, vcontext); - } - - current_brk = (long) sbrk(0); - - /* Get some information about the current context */ - -#ifdef WAD_SOLARIS - pc = &((context->uc_mcontext).gregs[REG_PC]); - npc = &((context->uc_mcontext).gregs[REG_nPC]); - sp = &((context->uc_mcontext).gregs[REG_SP]); -#endif - -#ifdef WAD_LINUX - sp = &((context->uc_mcontext).gregs[ESP]); /* Top of stack */ - fp = &((context->uc_mcontext).gregs[EBP]); /* Stack base - frame pointer */ - pc = &((context->uc_mcontext).gregs[EIP]); /* Current instruction */ - esi = &((context->uc_mcontext).gregs[ESI]); - edi = &((context->uc_mcontext).gregs[EDI]); - ebx = &((context->uc_mcontext).gregs[EBX]); - - wad_saved_esi = (unsigned long) (*esi); - wad_saved_edi = (unsigned long) (*edi); - wad_saved_ebx = (unsigned long) (*ebx); - - /* printf("esi = %x, edi = %x, ebx = %x\n", wad_saved_esi, wad_saved_edi, wad_saved_ebx); */ - - /* printf("&sp = %x, &pc = %x\n", sp, pc); */ -#endif - - /* Get some information out of the signal handler stack */ - addr = (unsigned long) si->si_addr; - - /* See if this might be a stack overflow */ - - p_pc = (unsigned long) (*pc); - p_sp = (unsigned long) (*sp); -#ifdef WAD_LINUX - p_fp = (unsigned long) (*fp); -#endif -#ifdef WAD_SOLARIS - p_fp = (unsigned long) *(((long *) p_sp) + 14); -#endif - - if (wad_debug_mode & DEBUG_SIGNAL) { - wad_printf("fault at address %x, pc = %x, sp = %x, fp = %x\n", addr, p_pc, p_sp, p_fp); - } - frame = wad_stack_trace(p_pc, p_sp, p_fp); - - if (!frame) { - /* We're really hosed. Not possible to generate a stack trace */ - wad_printf("WAD: Unable to generate stack trace.\n"); - wad_printf("WAD: Maybe the call stack has been corrupted by buffer overflow.\n"); - wad_signal_clear(); - return; - } - - { - WadFrame *f = frame; - while (f) { - wad_find_object(f); - wad_find_symbol(f); - f = f->next; - } - f = frame; - while (f) { - wad_find_debug(f); - wad_build_vars(f); - f = f->next; - } - } - wad_heap_overflow = 0; - if (sig == SIGSEGV) { - if (addr >= current_brk) wad_heap_overflow = 1; - } - - wad_stack_debug(frame); - - /* Generate debugging strings */ - wad_debug_make_strings(frame); - - wad_stab_debug(); - - /* Walk the exception frames and try to find a return point */ - origframe = frame; - while (frame) { - WadReturnFunc *wr = wad_check_return(frame->sym_name); - if (wr) { - found = 1; - wad_nlr_value = wr->value; - retname = wr->name; - } - if (found) { - frame->last = 1; /* Cut off top of the stack trace */ - break; - } - frame = frame->next; - nlevels++; - } - - - if (found) { - wad_nlr_levels = nlevels - 1; -#ifdef WAD_LINUX - wad_restore_i386_registers(origframe, wad_nlr_levels); -#endif - } else { - wad_nlr_levels = -1; - } - - wad_string_debug(); - wad_memory_debug(); - - /* Before we do anything with callbacks, we are going - to attempt to dump a wad-core */ - - { - int fd; - static int already = 0; - fd = open("wadtrace",O_WRONLY | O_CREAT | (already*O_APPEND) | ((already==0)*O_TRUNC),0666); - if (fd > 0) { - wad_dump_trace(fd,sig,origframe,retname); - close(fd); - already=1; - } - } - - if (sig_callback) { - (*sig_callback)(sig,origframe,retname); - } else { - /* No signal handler defined. Go invoke the default */ - - wad_default_callback(sig, origframe,retname); - } - - if (wad_debug_mode & DEBUG_HOLD) while(1); - - /* If we found a function to which we should return, we jump to - an alternative piece of code that unwinds the stack and - initiates a non-local return. */ - - if (wad_nlr_levels >= 0) { - *(pc) = (greg_t) _returnsignal; -#ifdef WAD_SOLARIS - *(npc) = *(pc) + 4; -#endif - if (!(wad_debug_mode & DEBUG_ONESHOT)) { - wad_signal_init(); - } - return; - } - exit(1); -} - - -/* ----------------------------------------------------------------------------- - * wad_signal_init() - * - * Resets the signal handler. - * ----------------------------------------------------------------------------- */ - -void wad_signal_init() { - struct sigaction newvec; - static stack_t sigstk; - static int initstack = 0; - - if (wad_debug_mode & DEBUG_INIT) { - wad_printf("WAD: Initializing signal handler.\n"); - } - /* This is buggy in Linux and threads. disabled by default */ - -#ifndef WAD_LINUX - - if (!initstack) { - /* Set up an alternative stack */ - - sigstk.ss_sp = (char *) wad_sig_stack; - sigstk.ss_size = STACK_SIZE; - sigstk.ss_flags = 0; - if (!(wad_debug_mode & DEBUG_NOSTACK)) { - if (sigaltstack(&sigstk, (stack_t*)0) < 0) { - perror("sigaltstack"); - } - } - initstack=1; - } -#endif - - sigemptyset(&newvec.sa_mask); - sigaddset(&newvec.sa_mask, SIGSEGV); - sigaddset(&newvec.sa_mask, SIGBUS); - sigaddset(&newvec.sa_mask, SIGABRT); - sigaddset(&newvec.sa_mask, SIGILL); - sigaddset(&newvec.sa_mask, SIGFPE); - newvec.sa_flags = SA_SIGINFO; - - if (wad_debug_mode & DEBUG_ONESHOT) { - newvec.sa_flags |= SA_RESETHAND; - } -#ifndef WAD_LINUX - if (!(wad_debug_mode & DEBUG_NOSTACK)) { - newvec.sa_flags |= SA_ONSTACK; - } -#endif - newvec.sa_sigaction = ((void (*)(int,siginfo_t *, void *)) wad_signalhandler); - if (sigaction(SIGSEGV, &newvec, NULL) < 0) goto werror; - if (sigaction(SIGBUS, &newvec, NULL) < 0) goto werror; - if (sigaction(SIGABRT, &newvec, NULL) < 0) goto werror; - if (sigaction(SIGFPE, &newvec, NULL) < 0) goto werror; - if (sigaction(SIGILL, &newvec, NULL) < 0) goto werror; - - return; - werror: - wad_printf("WAD: Couldn't install signal handler!\n"); -} - -/* ----------------------------------------------------------------------------- - * clear signals - * ----------------------------------------------------------------------------- */ - -void wad_signal_clear() { - signal(SIGSEGV, SIG_DFL); - signal(SIGBUS, SIG_DFL); - signal(SIGILL, SIG_DFL); - signal(SIGFPE, SIG_DFL); - signal(SIGABRT, SIG_DFL); -} - - - diff --git a/Tools/WAD/Wad/stab.c b/Tools/WAD/Wad/stab.c deleted file mode 100644 index 29626ae99..000000000 --- a/Tools/WAD/Wad/stab.c +++ /dev/null @@ -1,682 +0,0 @@ -/* ----------------------------------------------------------------------------- - * stab.c - * - * This file reads stabs data and looks for various properties of a - * given symbol. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -/* stabs data structure. This appears to be somewhat universal. */ -typedef struct Stab { - unsigned n_strx; /* index into file string table */ - unsigned char n_type; /* type flag (N_TEXT,..) */ - char n_other; /* used by N_SLINE stab */ - unsigned short n_desc; /* see stabs documentation */ - unsigned n_value; /* value of symbol (or sdb offset) */ -} Stab; - -/* stabs data types used by this module */ - -#define N_UNDF 0x0 /* undefined */ -#define N_FUN 0x24 /* function */ -#define N_OBJ 0x38 /* object file path */ -#define N_RSYM 0x40 /* Register symbol */ -#define N_SLINE 0x44 /* Source line */ -#define N_SO 0x64 /* Source file name */ -#define N_LSYM 0x80 /* Local symbol */ -#define N_PSYM 0xa0 /* Parameter */ -#define N_LBRAC 0xc0 /* Left brace */ -#define N_RBRAC 0xe0 /* Right brace */ - -/* ----------------------------------------------------------------------------- - * stabs type handler - * - * Type names are defined as N_LSYM types. We need to keep a hash table of - * logical type names and stabs type names. - * - * We also need to keep a hash table of stabs types. - * ----------------------------------------------------------------------------- */ - -typedef struct stabtype { - char *name; - char *value; - struct stabtype *next; - int visit; -} stabtype; - -#define HASH_SIZE 113 - -static int stab_type_init = 0; -static stabtype *lnames[HASH_SIZE]; /* Hash of local names */ -static stabtype *deadnames[HASH_SIZE]; /* Hash of dead names */ - -/* Initialize the hash table */ - -static void init_hash() { - int i; - stabtype *s, *sp = 0; - - for (i = 0; i < HASH_SIZE; i++) { - if (stab_type_init) { - /* Add stabs to dead list */ - s = lnames[i]; - sp = 0; - while (s) { - sp = s; - s = s->next; - } - if (sp) { - sp->next = deadnames[i]; - deadnames[i] = lnames[i]; - } - } - lnames[i] = 0; - } - stab_type_init = 1; -} - -static int thash(char *name) { - unsigned int h = 0; - int i; - for (i = 0; i < 8 && (*name); i++, name++) { - h = ((h << 7) + *name); - } - return (h % HASH_SIZE); -} - -/* Add a symbol to the hash */ - -static void type_add(char *name, char *value) { - int h; - stabtype *s; - char sc =0; - char *v; - char *vr; - char *split; - - if (!stab_type_init) { - init_hash(); - stab_type_init = 1; - } - - /* Split the "value" up into a type name and a value */ - - split = strchr(value,'='); - if (value[0] != '(') split = 0; - if (split) { - sc = *split; - v = value; - *split = 0; - vr = split+1; - } else { - v = value; - sc = 0; - vr = 0; - } - - h = thash(name); - s = lnames[h]; - while (s) { - if (strcmp(s->name,name) == 0) { - if (strcmp(s->value,v)) { - s->value = wad_string_lookup(v); - } - goto add_more; - } - s = s->next; - } - s = deadnames[h]; - if (!s) { - s = (stabtype *) wad_malloc(sizeof(stabtype)); - } else { - deadnames[h] = s->next; - } - s->name = wad_string_lookup(name); - s->value = wad_string_lookup(v); - s->next = lnames[h]; - s->visit = 0; - lnames[h] = s; - - /* Now take a look at the value. If it is contains other types, we might be able to define more stuff */ - add_more: - if (vr) { - /* There is a mapping to another type */ - type_add(v,vr); - } -} - -static -char *type_resolve(char *name) { - int h; - stabtype *s; - h = thash(name); - s = lnames[h]; - while(s) { - if (strcmp(s->name,name) == 0) { - if (!s->visit) { - char *c; - /* The visit flag is set so that we don't get in infinite loops */ - s->visit = 1; - c = type_resolve(s->value); - s->visit = 0; - return c; - } else { - return name; - } - } - s = s->next; - } - return name; -} - -/* This function tries to resolve base stabs types into a machine equivalent */ -static -int type_typecode(char *name) { - char *range; - - if (name[0] == '*') { - return WAD_TYPE_POINTER; - } - - range = strchr(name,';'); - if (!range) return WAD_TYPE_UNKNOWN; - range++; - - if (name[0] == 'r') { - /* GNU-style range specifiers */ - if ( - (strcmp(range,"0000000000000;0037777777777;") == 0) - ) { - return WAD_TYPE_UINT32; - } - if ( - (strcmp(range,"0020000000000;0017777777777;") == 0) - ) { - return WAD_TYPE_INT32; - } - if ( - (strcmp(range,"-32768;32767;") == 0) - ) { - return WAD_TYPE_INT16; - } - if ( - (strcmp(range,"0;65535;") == 0) - ) { - return WAD_TYPE_UINT16; - } - if ( - (strcmp(range,"0;127;") == 0) - ) { - return WAD_TYPE_CHAR; - } - if ( - (strcmp(range,"-128;127;") == 0) - ) { - return WAD_TYPE_INT8; - } - if ( - (strcmp(range,"0;255;") == 0) - ) { - return WAD_TYPE_UINT8; - } - if ( - (strcmp(range,"4;0;") == 0) - ) { - return WAD_TYPE_FLOAT; - } - if ( - (strcmp(range,"8;0;") == 0) - ) { - return WAD_TYPE_DOUBLE; - } - } - /* Traditional built-in types */ - if (strcmp(name,"bs4;0;32;") == 0) { - return WAD_TYPE_INT32; - } - if (strcmp(name,"bs2;0;16;") == 0) { - return WAD_TYPE_INT16; - } - if (strcmp(name,"bs1;0;8;") == 0) { - return WAD_TYPE_INT8; - } - if (strcmp(name,"bsc1;0;8;") == 0) { - return WAD_TYPE_CHAR; - } - if (strcmp(name,"bu4;0;32;") == 0) { - return WAD_TYPE_UINT32; - } - if (strcmp(name,"bu2;0;16;") == 0) { - return WAD_TYPE_UINT16; - } - if (strcmp(name,"bu1;0;8;") == 0) { - return WAD_TYPE_UINT8; - } - if (strcmp(name,"R1;4;") == 0) { - return WAD_TYPE_FLOAT; - } - if (strcmp(name,"R2;8;") == 0) { - return WAD_TYPE_DOUBLE; - } - return WAD_TYPE_UNKNOWN; -} - -static void types_print() { - stabtype *s; - int i; - for (i = 0; i < HASH_SIZE; i++) { - s = lnames[i]; - while (s) { - wad_printf("%20s %s\n", s->name, s->value); - s = s->next; - } - } -} - -void wad_stab_debug() { - /* types_print();*/ -} - -/* ----------------------------------------------------------------------------- - * match_stab_symbol() - * - * Match a stabs symbol name against a stab string. The stab string may contain - * extra information delimited by a colon which is not used in the comparsion. - * Returns 1 on match, 0 on mismatch. - * ----------------------------------------------------------------------------- */ - -static int -match_stab_symbol(char *symbol, char *stabtext, int slen) { - if (strcmp(symbol,stabtext) == 0) { - return 1; - } - if ((strncmp(symbol, stabtext, slen) == 0) && (*(stabtext+slen) == ':')) return 1; - return 0; -} - -static char * -stab_string_parm(char *str) { - return strchr(str,':'); -} - -/* ----------------------------------------------------------------------------- - * stab_symbol(Stab *s, char *stabstr) - * - * Process stab symbol specifier N_LSYM - * ----------------------------------------------------------------------------- */ - -static void -stab_symbol(Stab *s, char *stabstr) { - char *str; - char *pstr; - char name[1024]; - char value[65536]; - - str = stabstr+s->n_strx; - pstr = stab_string_parm(str); - if (!pstr) return; - - strncpy(name,str, pstr-str); - name[(int)(pstr-str)] = 0; - if ((pstr[1] == 't') || (pstr[1] == 'p') || (pstr[1] == 'r')) { - /* A stabs type definition */ - /* printf("stab lsym: other=%d, desc=%d, value=%d, str='%s'\n", s->n_other,s->n_desc,s->n_value, - stabstr+s->n_strx); */ - /* wad_printf("name = '%s', pstr='%s'\n", name, pstr+2); */ - wad_strcpy(value,pstr+2); - type_add(name,value); - } -} - - -/* ----------------------------------------------------------------------------- - * scan_function() - * - * Collect stabs data for a function definition. - * ----------------------------------------------------------------------------- */ - -static int -scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) { - int i; - unsigned long offset; - int get_parms = 1; - int nbrace = 0; - - offset = f->pc - f->sym_base; - if (wad_debug_mode & DEBUG_STABS) { - wad_printf("---[ %s ] --------------\n", f->sym_name); - } - - for (i = 0; i < ns; i++,s++) { - if (wad_debug_mode & DEBUG_STABS) { - wad_printf(" %10d %10x %10d %10d %10d: '%s'\n", s->n_strx, s->n_type, s->n_other, s->n_desc, s->n_value, - stabstr+s->n_strx); - - } - - if ((s->n_type == N_UNDF) || (s->n_type == N_SO) || /* (s->n_type == N_FUN) || */ - (s->n_type == N_OBJ)) return i; - - if ((s->n_type == N_FUN) && !(strlen(stabstr+s->n_strx))) return 1; - - if (s->n_type == N_LBRAC) { - nbrace++; - get_parms = 0; - } - if (s->n_type == N_RBRAC) { - nbrace--; - if (nbrace <= 0) return i; - } - /* Local variable declaration */ - - if (s->n_type == N_LSYM) { - /* This might be a local variable definition */ - /* wad_printf("local: n_value = %d, offset = %d\n", s->n_value, offset);*/ - if (s->n_desc <= f->loc_line) - { - /* Okay. We can pay attention to it */ - char *pname; - char *c; - int len; - WadLocal *arg, *a; - pname = stabstr+s->n_strx; - c = strchr(pname,':'); - if (*(c+1) != '(') continue; - if (c) { - len = (c-pname); - } else { - len = strlen(pname); - } - /* printf("local\n"); */ - stab_symbol(s,stabstr); - a = f->debug_locals; - while (a) { - if ((strncmp(a->name,pname,len) == 0) && (strlen(a->name) == len)) { - /* We already saw this argument. Given a choice between a register and a stack - argument. We will choose the stack version */ - a->loc = PARM_STACK; - a->stack = s->n_value; - break; - } - a = a->next; - } - if (a) continue; /* We got an argument match. Just skip to the next stab */ - arg = (WadLocal *) wad_malloc(sizeof(WadLocal)); - { - char t = pname[len]; - pname[len] = 0; - arg->name = wad_string_lookup(pname); - pname[len] = t; - } - arg->loc = PARM_STACK; - arg->line = s->n_desc; - arg->stack = s->n_value; - arg->type = 0; - arg->next = 0; - { - char tname[128]; - char *t = tname; - - c+=1; - while ((*c) && (*c != '=')) { - *t++ = *c++; - } - *t = 0; - t = type_resolve(tname); - arg->type = type_typecode(t); - if (wad_debug_mode & DEBUG_STABS) { - wad_printf("type_resolve '%s' -> '%s' (%d)\n", tname, t, arg->type); - } - } - if (f->debug_locals) { - f->debug_lastlocal->next = arg; - f->debug_lastlocal = arg; - } else { - f->debug_locals = arg; - f->debug_lastlocal = arg; - f->debug_nlocals= 0; - } - f->debug_nlocals++; - } - } - - if (s->n_type == N_SLINE) { - get_parms = 0; - if (s->n_value <= offset) { - f->loc_line = s->n_desc; - } - } else if (((s->n_type == N_PSYM) || (s->n_type == N_RSYM)) && get_parms) { - /* Parameter counting */ - char *pname; - char *c; - int len; - WadLocal *arg; - pname = stabstr+s->n_strx; - c = strchr(pname,':'); - if (c) { - len = (c-pname); - } else { - len = strlen(pname); - } - /* Get type information */ - - stab_symbol(s,stabstr); - - /* Check if the argument was already used */ - /* In this case, the first stab simply identifies an argument. The second - one identifies its location for the debugger */ - - { - /* Need to do some fix up for linux here */ - WadLocal *a = f->debug_args; - while (a) { - if ((strncmp(a->name,pname,len) == 0) && (strlen(a->name) == len)) { - /* We already saw this argument. Given a choice between a register and a stack - argument. We will choose the stack version */ - - if (a->loc == PARM_STACK) { - break; - } - /* Go ahead and use the new argument */ - if (s->n_type == N_RSYM) { - a->loc = PARM_REGISTER; - a->reg = s->n_value; - } else { - a->loc = PARM_STACK; - a->stack = s->n_value; - } - break; - } - a = a->next; - } - if (a) continue; /* We got an argument match. Just skip to the next stab */ - } - - arg = (WadLocal *) wad_malloc(sizeof(WadLocal)); - { - char t = pname[len]; - pname[len] = 0; - arg->name = wad_string_lookup(pname); - pname[len] = t; - } - if (s->n_type == N_RSYM) { - arg->loc = PARM_REGISTER; - arg->reg = s->n_value; - arg->stack = 0; - } else { - arg->loc = PARM_STACK; - arg->line = s->n_desc; - arg->stack = s->n_value; - } - arg->type = 0; - arg->next = 0; - { - char tname[128]; - char *t = tname; - - c+=2; - while ((*c) && (*c != '=')) { - *t++ = *c++; - } - *t = 0; - t = type_resolve(tname); - arg->type = type_typecode(t); - if (wad_debug_mode & DEBUG_STABS) { - wad_printf("type_resolve '%s' -> '%s' (%d)\n", tname, t, arg->type); - } - } - if (f->debug_args) { - f->debug_lastarg->next = arg; - f->debug_lastarg = arg; - } else { - f->debug_args = arg; - f->debug_lastarg = arg; - f->debug_nargs= 0; - } - f->debug_nargs++; - } - } - return i; -} - -/* Given a stabs data segment (obtained somehow), this function tries to - collect as much information as it can about a given symbol. - - s points to the stab data. stabstr points to the stab string section, - ns is the size of the stab section, symbol is the item of interest, - and offset is the offset in the object file of the symbol - - Note: this function may recurse upon itself if there are multiple - stabs sections. - - Note: If a symbol corresponds to a local symbol, it's entirely possible - that the only stabs data we will find is a file specifier. In this case, - */ - -int -wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) { - Stab *s; - int ns; - int i; - int found = 0; - - char *file, *lastfile = 0; - - char srcfile[MAX_PATH]; - char objfile[MAX_PATH]; - - /* It appears to be necessary to clear the types table on each new stabs section */ - - init_hash(); - - if (!f->sym_name) return 0; - - s = (Stab *) sp; /* Stabs data */ - ns = size/sizeof(Stab); /* number of stabs */ - - srcfile[0] = 0; - objfile[0] = 0; - - for (i = 0; i < ns; i++, s++) { - if (wad_debug_mode & DEBUG_STABS) { - /* wad_printf(" %10d %10x %10d %10d %10d: '%s'\n", s->n_strx, s->n_type, s->n_other, s->n_desc, s->n_value, - stabstr+s->n_strx); */ - - } - if (s->n_type == N_LSYM) { - stab_symbol(s,stabstr); - continue; - } - if ((s->n_type == N_UNDF)) { /* && (s->n_desc >= 0)) { */ - /* New stabs section. We need to be a little careful here. Do a recursive - search of the subsection. */ - - if (wad_search_stab(s+1,s->n_desc*sizeof(Stab), stabstr, f)) { - return 1; - } - - /* On solaris, each stabs section seems to increment the stab string pointer. On Linux, - the linker seems to do a certain amount of optimization that results in a single - string table. */ - -#ifdef WAD_SOLARIS - stabstr += s->n_value; /* Update the string table location*/ -#endif - i += s->n_desc; - s += s->n_desc; - objfile[0] = 0; - srcfile[0] = 0; - continue; - } else if (s->n_type == N_SO) { - /* Source file specification */ - /* Look for directory */ - file = stabstr+s->n_strx; - if (strlen(file) && (file[strlen(file)-1] == '/')) { - wad_strcpy(srcfile,file); - } else { - wad_strcat(srcfile,file); - } - objfile[0] = 0; - /* If we have a file match, we might be looking for a local symbol. If so, - we'll go ahead and set the srcfile field of the frame */ - - /* We're going to check for a file match. Maybe we're looking for a local symbol */ - if (f->sym_file && strcmp(f->sym_file,file) == 0) { - found = 1; - } - lastfile = file; - } else if (s->n_type == N_OBJ) { - /* Object file specifier */ - if (objfile[0]) { - wad_strcat(objfile,"/"); - } - wad_strcat(objfile,stabstr+s->n_strx); - } else if (s->n_type == N_FUN) { - if (match_stab_symbol(f->sym_name, stabstr+s->n_strx, f->sym_nlen)) { - if (!f->sym_file || (strcmp(f->sym_file,lastfile) == 0)) { - int n; - /* Go find debugging information for the function */ - n = scan_function(s+1, stabstr, ns -i - 1, f); - f->loc_srcfile = wad_string_lookup(srcfile); - f->loc_objfile = wad_string_lookup(objfile); - return 1; - } - } - } - } - /* If found, but no other debugging information was filled in, go ahead and copy the - source and objfile information */ - - if ((found) && (!f->debug_check)) { - f->loc_srcfile = wad_string_lookup(srcfile); - f->loc_objfile = wad_string_lookup(objfile); - } - return found; -} - - - - diff --git a/Tools/WAD/Wad/stack.c b/Tools/WAD/Wad/stack.c deleted file mode 100644 index 68a55a77f..000000000 --- a/Tools/WAD/Wad/stack.c +++ /dev/null @@ -1,309 +0,0 @@ -/* ----------------------------------------------------------------------------- - * stack.c - * - * This file unwinds the C call stack and creates a list of stack frames. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -/* ----------------------------------------------------------------------------- - * new_frame() - * - * Create a new stack frame object and initialize all of the fields. - * ----------------------------------------------------------------------------- */ - -static WadFrame * -new_frame() { - WadFrame *f; - f = (WadFrame *) wad_malloc(sizeof(WadFrame)); - f->frameno = 0; - f->segment = 0; - f->object = 0; - f->pc = 0; - f->sp = 0; - f->sp = 0; - f->stack = 0; - f->stack_size = 0; - - f->sym_name = 0; - f->sym_nlen = 0; - f->sym_file = 0; - f->sym_base = 0; - f->sym_size = 0; - f->sym_type = 0; - f->sym_bind = 0; - - f->loc_objfile = 0; - f->loc_srcfile = 0; - f->loc_line = 0; - - f->debug_check = 0; - f->debug_nargs = -1; - f->debug_args = 0; - f->debug_lastarg = 0; - f->debug_nlocals = 0; - f->debug_locals = 0; - f->debug_lastlocal = 0; - f->debug_str = 0; - f->debug_srcstr = 0; - - f->last = 0; - f->next = 0; - f->prev = 0; - return f; -} - -/* ----------------------------------------------------------------------------- - * stack_unwind() - * - * This function performs a single level of stack unwinding given the stack pointer - * frame pointer and program counter. Validations are made to make sure the stack - * and frame pointers are in valid memory. Updates the values of the sp, pc, and fp - * in-place. Returns a stack frame object on success, 0 if memory is invalid - * or the end of the stack has been reached. - * ----------------------------------------------------------------------------- */ - -static WadFrame * -stack_unwind(unsigned long *pc, unsigned long *sp, unsigned long *fp) { - WadSegment *sp_seg, *fp_seg; - WadFrame *f; - unsigned long fake_fp; - - if (wad_debug_mode & DEBUG_UNWIND) { - wad_printf("::: stack unwind : pc = %x, sp = %x, fp = %x\n", *pc, *sp, *fp); - } - - /* Verify that the sp and fp are in mapped memory */ - sp_seg = wad_segment_find((void *) *sp); - fp_seg = wad_segment_find((void *) *fp); - - /* Make sure the stack pointer is in memory */ - if (!sp_seg) { - return 0; - } - - if (!fp_seg) { - /* Hmmm. If no frame pointer, we must be off the top of the call stack */ - fake_fp = (unsigned long) (sp_seg->vaddr + sp_seg->size); - fp_seg = sp_seg; - } else { - fake_fp = *fp; - } - if (sp_seg != fp_seg) { - /* Whoa. Stack pointer and frame pointer are in different memory segments. */ - wad_printf("WAD: Warning. Stack pointer and frame pointer are in different regions.\n"); - return 0; - } - - /* Check to see if the PC is valid */ - if (!wad_segment_valid((void *) *pc)) { - return 0; - } - - f = new_frame(); - f->pc = *pc; - f->sp = *sp; - f->fp = fake_fp; - f->segment = wad_segment_find((void *) *pc); - f->stack_size = fake_fp - *sp; - /* Make a copy of the call stack */ - f->stack = (char *) wad_malloc(f->stack_size); - wad_memcpy(f->stack,(void *) *sp, f->stack_size); - - /* Update the sp, fp, and pc */ - -#ifdef WAD_SOLARIS - *pc = *((unsigned long *) *sp+15); /* %i7 - Return address */ - *sp = *((unsigned long *) *sp+14); /* %i6 - frame pointer */ - if (wad_segment_valid((void *) *sp)) { - *fp = *((unsigned long *) *sp+14); - } else { - *fp = 0; - } -#endif - -#ifdef WAD_LINUX - if (wad_segment_valid((void *) ((unsigned long *) *fp+1))) { - *pc = *((unsigned long *) *fp+1); - *sp = *fp; - } else { - *sp = 0; - } - if (wad_segment_valid((void *) ((unsigned long *) *fp))) { - *fp = *((unsigned long *) *fp); - } else { - *fp = 0; - } -#endif - return f; -} - -/* ----------------------------------------------------------------------------- - * wad_stack_trace() - * - * Create a stack trace of the process. Returns a linked list of stack frames - * with a limited about debugging information and other details. - * ----------------------------------------------------------------------------- */ - -WadFrame * -wad_stack_trace(unsigned long pc, unsigned long sp, unsigned long fp) { - WadFrame *firstframe=0, *lastframe=0, *frame=0; - unsigned long p_pc; - unsigned long p_sp; - unsigned long p_fp; - int n = 0; - - /* Try to do a stack traceback */ - - p_pc = pc; - p_sp = sp; - p_fp = fp; - - while ((frame = stack_unwind(&p_pc, &p_sp, &p_fp))) { - /* Got a frame successfully */ - frame->frameno = n; - if (lastframe) { - lastframe->next = frame; - frame->prev = lastframe; - lastframe = frame; - } else { - firstframe = frame; - lastframe = frame; - } - n++; - } - if (lastframe) - lastframe->last = 1; - return firstframe; -} - -/* ----------------------------------------------------------------------------- - * wad_stack_debug() - * - * Make a dump of a stack trace - * ----------------------------------------------------------------------------- */ - -void wad_stack_debug(WadFrame *frame) { - if (wad_debug_mode & DEBUG_STACK) { - /* Walk the exception frames and try to find a return point */ - while (frame) { - /* Print out detailed stack trace information */ - wad_printf("::: Stack frame - 0x%08x :::\n", frame); - wad_printf(" pc = %x\n", frame->pc); - wad_printf(" sp = %x\n", frame->sp); - wad_printf(" fp = %x\n", frame->fp); - wad_printf(" stack = %x\n", frame->stack); - wad_printf(" size = %x\n", frame->stack_size); - wad_printf(" segment = %x (%s)\n", frame->segment, frame->segment ? frame->segment->mappath : "?"); - wad_printf(" object = %x (%s)\n", frame->object, frame->object ? frame->object->path : "?"); - - if (frame->sym_name) { - wad_printf(" sym_name = %s\n", frame->sym_name); - wad_printf(" sym_base = %x\n", frame->sym_base); - wad_printf(" sym_size = %x\n", frame->sym_size); - wad_printf(" sym_bind = %x\n", frame->sym_bind); - wad_printf(" sym_file = %s\n", frame->sym_file ? frame->sym_file : ""); - } - - if (frame->loc_srcfile) { - wad_printf(" loc_srcfile = %s\n", frame->loc_srcfile); - } - - if (frame->loc_objfile) { - wad_printf(" loc_objfile = %s\n", frame->loc_objfile); - } - wad_printf(" loc_line = %d\n", frame->loc_line); - - - wad_printf(" debug_nargs = %d\n", frame->debug_nargs); - if (frame->debug_args) { - int i = 0; - WadLocal *p = frame->debug_args; - wad_printf(" debug_args = [ \n"); - while (p) { - wad_printf(" arg[%d] : name = '%s', loc = %d, type = %d, stack = %d, reg = %d, line=%d, ptr=%x(%d)\n", i, p->name, p->loc, p->type, p->stack,p->reg,p->line,p->ptr,p->size); - p = p->next; - } - } - wad_printf(" ]\n"); - - wad_printf(" debug_nlocal = %d\n", frame->debug_nlocals); - if (frame->debug_locals) { - int i = 0; - WadLocal *p = frame->debug_locals; - wad_printf(" debug_locals = [ \n"); - while (p) { - wad_printf(" loc[%d] : name = '%s', loc = %d, type = %d, stack = %d, reg = %d, line=%d, ptr=%x(%d)\n", i, p->name, p->loc, p->type, p->stack,p->reg,p->line,p->ptr,p->size); - p = p->next; - } - } - wad_printf(" ]\n"); - - frame = frame->next; - } - } -} - - -/* ----------------------------------------------------------------------------- - * wad_steal_outarg() - * - * Steal an output argument - * ----------------------------------------------------------------------------- */ - -long -wad_steal_outarg(WadFrame *f, char *symbol, int argno, int *error) { - long *regs; - WadFrame *lastf = 0; - - *error = 0; - /* Start searching */ - while (f) { - if (f->sym_name && (strcmp(f->sym_name,symbol) == 0)) { - /* Got a match */ - if (lastf) { -#ifdef WAD_SOLARIS - regs = (long *) lastf->stack; - return regs[8+argno]; -#endif -#ifdef WAD_LINUX - regs = (long *) f->stack; - return regs[argno+2]; -#endif - } - } - lastf = f; - f = f->next; - } - *error = -1; - return 0; -} - - - - - - - diff --git a/Tools/WAD/Wad/string.c b/Tools/WAD/Wad/string.c deleted file mode 100644 index 1a15878ee..000000000 --- a/Tools/WAD/Wad/string.c +++ /dev/null @@ -1,131 +0,0 @@ -/* ----------------------------------------------------------------------------- - * string.c - * - * This file provides support for string storage in WAD. Since strings are - * used frequently in WAD, this file implements string interning and - * some lookup functions that can be used to return a previously stored - * string rather than making a new copy. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -/* Hash table containing stab strings and such */ -typedef struct stringtype { - char *str; - struct stringtype *next; -} stringtype; - -#define STRING_HASH_SIZE 1013 - -static stringtype *strings[STRING_HASH_SIZE]; -static int strings_init = 0; - -static int shash(char *name) { - unsigned int h = 0; - char *c; - int i; - c = name; - for (i = 0; (i < 16) && (*c); i++, c++) { - h = ((h^~i) << 6) + *c; - } - return h % STRING_HASH_SIZE; -} - -char * -wad_string_lookup(char *s) { - int h; - int i; - stringtype *st; - - if (!strings_init) { - for (i = 0; i < STRING_HASH_SIZE; i++) { - strings[i] = 0; - } - strings_init = 1; - } - - h = shash(s); - st = strings[h]; - while (st) { - if (strcmp(st->str,s) == 0) return st->str; - st = st->next; - } - - /* Not found. Add the string to the hash table */ - st = (stringtype *) wad_malloc(sizeof(stringtype)); - st->str = wad_strdup(s); - st->next = strings[h]; - strings[h] = st; - return st->str; -} - -void wad_string_debug() { - if (wad_debug_mode & DEBUG_STRING) { - int maxdepth = 0; - int total = 0; - int stringlen = 0; - int i; - - for (i = 0; i < STRING_HASH_SIZE; i++) { - stringtype *s; - int c = 0; - s = strings[i]; - while (s) { - c++; - stringlen += strlen(s->str); - s = s->next; - } - /* wad_printf("WAD: stringhash[%d] = %d\n", i, c);*/ - if (c > maxdepth) maxdepth = c; - total += c; - } - wad_printf("WAD: nstrings = %d (%d bytes)\n", total, stringlen + total*sizeof(stringtype)); - wad_printf("WAD: maxdepth = %d\n", maxdepth); - } -} - -/* Our own string copy */ -char *wad_strcpy(char *t, const char *s) { - if (s) - for (; *s; s++, t++) *t = *s; - *t = 0; - return t; -} - -char * -wad_strcat(char *t, const char *s) { - while (*t) t++; - return wad_strcpy(t,s); -} - -int -wad_strlen(const char *s) { - int count = 0; - while (*(s++)) count++; - return count; -} - - - diff --git a/Tools/WAD/Wad/vars.c b/Tools/WAD/Wad/vars.c deleted file mode 100644 index b22f71758..000000000 --- a/Tools/WAD/Wad/vars.c +++ /dev/null @@ -1,271 +0,0 @@ -/* ----------------------------------------------------------------------------- - * vars.c - * - * This file examines the stack trace and tries to make some sense out of - * collected debugging information. This includes locating the data on - * the stack and/or registers. - * - * This feature is detached from the debugging info collector to make - * it independent of debugging formats. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * See the file COPYING for a complete copy of the LGPL. - * ----------------------------------------------------------------------------- */ - -#include "wad.h" - -static char cvs[] = "$Id$"; - -/* ----------------------------------------------------------------------------- - * wad_build_vars() - * - * Build variable information for a single stack frame - * ----------------------------------------------------------------------------- */ - -void wad_build_vars(WadFrame *f) { - char *stack = 0; - char *nstack = 0; - char *pstack = 0; - WadLocal *loc; - int n; - - stack = (char *) f->stack; - if (f->next) { - nstack = (char *) f->next->stack; - } - if (f->prev) { - pstack = (char *) f->prev->stack; - } - - for (n = 0; n < 2; n++) { - if (n == 0) loc = f->debug_args; - else loc = f->debug_locals; - - while (loc) { - loc->ptr = 0; - if (loc->loc == PARM_STACK) { - if ((loc->stack >= 0) && (nstack)) { - loc->ptr = (void *) (nstack + loc->stack); - } else if (loc->stack < 0) { - loc->ptr = (void *) (stack + f->stack_size + loc->stack); - } - loc->size = sizeof(long); - } - if (loc->loc == PARM_REGISTER) { - /* Parameter is located in a register */ -#ifdef WAD_SOLARIS - if ((loc->reg >= 24) && (loc->reg < 32)) { - /* Value is located in the %in registers. */ - loc->ptr = (void *) (stack + (loc->reg - 16)*sizeof(int)); - loc->size = sizeof(int); - } else if ((loc->reg >= 8) && (loc->reg < 16)) { - - /* Value is located in the %on registers */ - if (nstack) { - loc->ptr = (void *) (stack + (loc->reg)*sizeof(int)); - loc->size = sizeof(int); - } - } else if ((loc->reg >= 16) && (loc->reg < 24)) { - /* Value has been placed in the %ln registers */ - loc->ptr = (void *) (stack + (loc->reg - 16)*sizeof(int)); - loc->size = sizeof(int); - } -#endif - } - loc = loc->next; - } - } -} - -/* This function creates a formatted integer given a pointer, size, and sign flag */ -static -char *wad_format_int(char *ptr, int nbytes, int sgn) { - static char fmt[128]; - unsigned char *s; - int incr; - unsigned long value = 0; - int i; - -#ifdef WAD_LITTLE_ENDIAN - s = (unsigned char *) (ptr + nbytes - 1); - incr = -1; -#else - s = (unsigned char *) (ptr); - incr = +1; -#endif - for (i = 0; i < nbytes; i++, s += incr) { - value = (value << 8) + *s; - } - if (sgn) { - return wad_format_signed((long) value,-1); - } else { - return wad_format_unsigned((unsigned long) value, -1); - } - return fmt; -} - -/* Try to make a formatted version of a local */ -char *wad_format_var(WadLocal *l) { - static char hexdigits[] = "0123456789abcdef"; - static char buffer[1024]; - double dval; - float fval; - - buffer[0] = 0; - - switch(l->type) { - case WAD_TYPE_INT32: - wad_strcpy(buffer,wad_format_int(l->ptr,4,1)); - break; - case WAD_TYPE_UINT32: - wad_strcpy(buffer,wad_format_int(l->ptr,4,0)); - break; - case WAD_TYPE_INT16: - wad_strcpy(buffer,wad_format_int(l->ptr,2,1)); - break; - case WAD_TYPE_UINT16: - wad_strcpy(buffer,wad_format_int(l->ptr,2,0)); - break; - case WAD_TYPE_INT8: - wad_strcpy(buffer,wad_format_int(l->ptr,1,1)); - break; - case WAD_TYPE_UINT8: - wad_strcpy(buffer,wad_format_int(l->ptr,1,0)); - break; - case WAD_TYPE_CHAR: - buffer[0] = '\''; - buffer[1] = *((char *) l->ptr); - buffer[2] = '\''; - buffer[3] = 0; - break; - case WAD_TYPE_FLOAT: - wad_memcpy(&fval,l->ptr,sizeof(float)); - sprintf(buffer,"%g",fval); - break; - case WAD_TYPE_DOUBLE: - wad_memcpy(&dval,l->ptr,sizeof(double)); - sprintf(buffer,"%g",dval); - break; - case WAD_TYPE_UNKNOWN: - case WAD_TYPE_POINTER: - default: - /* Hmmm. Unknown data type. We'll just treat it as a word */ - if (l->ptr) { - int incr,i; - int b; - int leading = 1; - char *c; - char *ptr; - -#ifdef WAD_LITTLE_ENDIAN - ptr = ((char *) l->ptr) + 3; - incr = -1; -#else - ptr = (char *) l->ptr; - incr =1 ; -#endif - wad_strcat(buffer,"0x"); - c = buffer+2; - for (i = 0; i < sizeof(void *); i++) { - b = (int) *ptr; - if (!leading || (b)) { - if (!leading || (b & 0xf0)) - *(c++) = hexdigits[(b & 0xf0) >> 4]; - *(c++) = hexdigits[(b & 0xf)]; - leading = 0; - } - ptr += incr; - } - if (leading) - *(c++) = '0'; - - *c = 0; - } - } - return buffer; -} - -/* Convert a wad local variable to a long */ -long wad_local_as_long(WadLocal *loc) { - long value = 0; - int32 i32; - int16 i16; - int8 i8; - uint32 u32; - uint16 u16; - uint8 u8; - - switch(loc->type) { - case WAD_TYPE_INT32: - wad_memcpy(&i32,loc->ptr,4); - value = (long) i32; - break; - case WAD_TYPE_UINT32: - wad_memcpy(&u32,loc->ptr,4); - value = (long) u32; - break; - case WAD_TYPE_INT16: - wad_memcpy(&i16,loc->ptr,2); - value = (long) i16; - break; - case WAD_TYPE_UINT16: - wad_memcpy(&u16,loc->ptr,2); - value = (long) u16; - break; - case WAD_TYPE_INT8: - case WAD_TYPE_CHAR: - wad_memcpy(&i8, loc->ptr,1); - value = (long) i8; - break; - case WAD_TYPE_UINT8: - wad_memcpy(&u8, loc->ptr,1); - value = (long) u8; - break; - default: - wad_memcpy(&u32,loc->ptr,4); - value = (long) u32; - } - return value; -} - -/* Convert a wad local variable to a long */ -double wad_local_as_double(WadLocal *loc) { - double value = 0; - float fval; - - switch(loc->type) { - case WAD_TYPE_DOUBLE: - wad_memcpy(&value,loc->ptr,8); - break; - case WAD_TYPE_FLOAT: - wad_memcpy(&fval,loc->ptr,4); - value = (double) fval; - break; - default: - value = 0; - } - return value; -} - - - - - - diff --git a/Tools/WAD/Wad/wadhandler.pl b/Tools/WAD/Wad/wadhandler.pl deleted file mode 100644 index e29240b69..000000000 --- a/Tools/WAD/Wad/wadhandler.pl +++ /dev/null @@ -1,36 +0,0 @@ -package libwadpl; -sub wad_handler_traceback { - package DB; - my $es = ""; - ($pack,$file,$line) = caller(1); - - for ($i = 2; ($p,$f,$l,$s,$h,$w,$e,$r) = caller($i); $i++) { - @a = (); - for $arg (@args) { - $_ = "$arg"; - s/([\'\\])/\\$1/g; - s/([^\0]*)/'$1'/ - unless /^(?: -?[\d.]+ | \*[\w:]* )$/x; - s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg; - s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg; - push(@a, $_); - } - $w = $w ? '@ = ' : '$ = '; - $a = $h ? '(' . join(', ', @a) . ')' : ''; - $e =~ s/\n\s*\;\s*\Z// if $e; - $e =~ s/[\\\']/\\$1/g if $e; - if ($r) { - $s = "require '$e'"; - } elsif (defined $r) { - $s = "eval '$e'"; - } elsif ($s eq '(eval)') { - $s = "eval {...}"; - } - $f = "file `$f'" unless $f eq '-e'; - $mess = "$w$s$a called from $f line $l\n"; - $es = $mess . $es; - - } - $es = "Signal at $file line $line\n" . $es; - return $es; -} diff --git a/Tools/WAD/Wad/wadpl.cxx b/Tools/WAD/Wad/wadpl.cxx deleted file mode 100644 index 25ca5bb74..000000000 --- a/Tools/WAD/Wad/wadpl.cxx +++ /dev/null @@ -1,176 +0,0 @@ -/* ----------------------------------------------------------------------------- - * wadpl.cxx - * - * Dynamically loadable module for Perl. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 2000. The University of Chicago - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#endif -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" - -#include "wad.h" -#ifdef __cplusplus -} -#endif - -#include - -#include "wad_perl_handler.c" - -/* Error message returned to perl */ - -static char message[65536]; -static int global_signo = 0; - -static void returnfunc(void) { - SV *s; - s = perl_eval_pv((char*)"libwadpl::wad_handler_traceback(0)", 0); - croak("%s\n%s",SvPV(s,PL_na),message); - return; -} - -/* Handler function */ -static void handler(int signo, WadFrame *frame, char *ret) { - - static char temp[1024]; - int len = 0; - char *name; - char *fd; - WadFrame *f; - WadFrame *fline = 0; - int err; - char *type; - - if (!ret) { - wad_default_callback(signo, frame, ret); - return; - } - - - switch(signo) { - case SIGSEGV: - type = (char*)"Segmentation fault."; - break; - case SIGBUS: - type = (char*)"Bus error."; - break; - case SIGABRT: - type = (char*)"Abort."; - break; - case SIGFPE: - type = (char*)"Math."; - default: - break; - } - strcpy(message,type); - strcat(message,"\n[ C stack trace ]\n\n"); - fd = (char *) frame; - f = (WadFrame *) fd; - - /* Find the last exception frame */ - while (!f->last) { - fd = fd + f->size; - f = (WadFrame *) fd; - } - /* Now work backwards */ - fd = fd - f->lastsize; - f = (WadFrame *) fd; - while (1) { - sprintf(temp,"#%-3d 0x%08x in ", f->frameno, f->pc); - strcat(message,temp); - strcat(message,*(fd + f->sym_off) ? fd+f->sym_off : "?"); - strcat(message,"()"); - if (strlen(SRCFILE(f))) { - strcat(message," in '"); - strcat(message, wad_strip_dir(SRCFILE(f))); - strcat(message,"'"); - if (f->line_number > 0) { - sprintf(temp,", line %d", f->line_number); - strcat(message,temp); - fline = f; - } - } else { - if (strlen(fd+f->obj_off)) { - strcat(message," from '"); - strcat(message, wad_strip_dir(OBJFILE(f))); - strcat(message,"'"); - } - } - strcat(message,"\n"); - if (!f->lastsize) break; - fd = fd - f->lastsize; - f = (WadFrame *) fd; - } - if (fline) { - int first; - int last; - char *line, *c; - int i; - first = fline->line_number - 2; - last = fline->line_number + 2; - if (first < 1) first = 1; - - line = wad_load_source(SRCFILE(fline),first); - if (line) { - strcat(message,"\n"); - strcat(message, SRCFILE(fline)); - sprintf(temp,", line %d\n\n", fline->line_number); - strcat(message, temp); - for (i = first; i <= last; i++) { - if (i == fline->line_number) strcat(message," => "); - else strcat(message," "); - c = strchr(line,'\n'); - if (c) { - *c = 0; - strcat(message,line); - strcat(message,"\n"); - *c = '\n'; - } else { - strcat(message,line); - strcat(message,"\n"); - break; - } - line = c+1; - } - wad_release_source(); - strcat(message,"\n"); - } - } - wad_set_return_func(returnfunc); - wad_release_trace(); -} - -static void perlwadinit() { - printf("WAD Enabled\n"); - wad_init(); - wad_set_callback(handler); - wad_set_return("Perl_pp_entersub", 0); - perl_eval_pv(wad_perl_handler, 0); -} - -/* This hack is used to auto-initialize wad regardless of whether we are - used as an imported module or as a link-library for another module */ - -class wadinitializer { -public: - wadinitializer() { - perlwadinit(); - } -}; - -static wadinitializer wi; - -extern "C" -XS(boot_libwadpl) { - dXSARGS; - ST(0) = &PL_sv_yes; - XSRETURN(1); -} diff --git a/Tools/WAD/configure.in b/Tools/WAD/configure.in deleted file mode 100644 index 1a8dcdbed..000000000 --- a/Tools/WAD/configure.in +++ /dev/null @@ -1,365 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. - -dnl NOTES: -dnl * As of 1.34, we no longer use and test for "nope" to indicate -dnl an empty variable. Instead, we use `VAR=' (set the variable -dnl to nothing) and `test -z "$VAR"' or `test -n "$VAR"' as the -dnl case may be. --ttn, 2000/08/04 12:11:26 - -AC_INIT -AC_CONFIG_SRCDIR([Include/wad.h]) -AC_PREREQ(2.53) - -# Set name for machine-dependent library files -AC_SUBST(MACHDEP) -AC_MSG_CHECKING(MACHDEP) -if test -z "$MACHDEP" -then - if test -f /usr/lib/NextStep/software_version; then - set X `hostinfo | grep 'NeXT Mach.*:' | \ - sed -e 's/://' -e 's/\./_/'` && \ - ac_sys_system=next && ac_sys_release=$4 - MACHDEP="$ac_sys_system$ac_sys_release$ac_sys_cpu" - else - ac_sys_system=`uname -s` - if test "$ac_sys_system" = "AIX" ; then - ac_sys_release=`uname -v` - else - ac_sys_release=`uname -r` - fi - ac_md_system=`echo $ac_sys_system | - tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'` - ac_md_release=`echo $ac_sys_release | - tr -d '[/ ]' | sed 's/\..*//'` - MACHDEP="$ac_md_system$ac_md_release" - fi - case MACHDEP in - '') MACHDEP=unknown;; - esac -fi -AC_MSG_RESULT($MACHDEP) - -AC_PROG_CC -AC_PROG_CXX -AC_PROG_RANLIB - -dnl Checks for programs. - -AC_SUBST(AR) -AC_CHECK_PROGS(AR, ar aal, ar) - -dnl Checks for header files. -AC_HEADER_STDC -dnl Checks for library functions. - -# Set info about shared libraries. -AC_SUBST(SO) -AC_SUBST(LDSHARED) -AC_SUBST(CCSHARED) - -# SO is the extension of shared libraries `(including the dot!) -# -- usually .so, .sl on HP-UX -AC_MSG_CHECKING(SO) -if test -z "$SO" -then - case $ac_sys_system in - hp*|HP*) SO=.sl;; - *) SO=.so;; - esac -fi -AC_MSG_RESULT($SO) - -# WAD Options -AC_SUBST(WADOPT) -AC_MSG_CHECKING(WADOPT) -if test -z "$WADOPT" -then - case $ac_sys_system/$ac_sys_release in - SunOS/5*) WADOPT="-DWAD_SOLARIS";; - Linux*) WADOPT="-DWAD_LINUX";; - *) WADOPT="-DWAD_UNKWOWN";; - esac -fi -AC_MSG_RESULT($WADOPT) - - -# LDSHARED is the ld *command* used to create shared library -# -- "ld" on SunOS 4.x.x, "ld -G" on SunOS 5.x, "ld -shared" on IRIX 5 -# (Shared libraries in this instance are shared modules to be loaded into -# Python, as opposed to building Python itself as a shared library.) -AC_MSG_CHECKING(LDSHARED) -if test -z "$LDSHARED" -then - case $ac_sys_system/$ac_sys_release in - AIX*) LDSHARED="\$(srcdir)/ld_so_aix \$(CC)";; - IRIX/5*) LDSHARED="ld -shared";; - IRIX*/6*) LDSHARED="ld ${SGI_ABI} -shared -all";; - SunOS/4*) LDSHARED="ld";; - SunOS/5*) LDSHARED="ld -G";; - hp*|HP*) LDSHARED="ld -b";; - OSF*) LDSHARED="ld -shared -expect_unresolved \"*\"";; - DYNIX/ptx*) LDSHARED="ld -G";; - next/*) - if test "$ns_dyld" - then LDSHARED='$(CC) $(LDFLAGS) -bundle -prebind' - else LDSHARED='$(CC) $(CFLAGS) -nostdlib -r'; - fi - if test "$with_next_framework" ; then - LDSHARED="$LDSHARED \$(LDLIBRARY)" - fi ;; - Linux*) LDSHARED="gcc -shared";; - dgux*) LDSHARED="ld -G";; - FreeBSD*/3*) LDSHARED="gcc -shared";; - FreeBSD*|OpenBSD*) LDSHARED="ld -Bshareable";; - NetBSD*) - if [[ "`$CC -dM -E - ], , TCLINCLUDE="") -if test -z "$TCLINCLUDE"; then - dirs="$prefix/include /usr/local/include /usr/include /opt/local/include /home/sci/local/include" - for i in $dirs ; do - if test -r $i/tcl.h; then - AC_MSG_RESULT($i) - TCLINCLUDE="-I$i" - MAKETCL="tcl" - break - fi - done -fi -if test -z "$TCLINCLUDE"; then - TCLINCLUDE="" - MAKETCL="" - AC_MSG_RESULT(not found) -fi -else - AC_MSG_RESULT($TCLINCLUDE) -fi - -AC_SUBST(TCLINCLUDE) -AC_SUBST(MAKETCL) - -#---------------------------------------------------------------- -# Look for Python -#---------------------------------------------------------------- - -PYINCLUDE= -MAKEPYTHON= -PYLIB= -PYPACKAGE= - -AC_ARG_WITH(py,[ --with-py=path Set location of Python],[ - PYPACKAGE="$withval"], [PYPACKAGE=]) -AC_ARG_WITH(pyincl,[ --with-pyincl=path Set location of Python include directory],[ - PYINCLUDE="$withval"], [PYINCLUDE=]) -AC_ARG_WITH(pylib,[ --with-pylib=path Set location of Python library directory],[ - PYLIB="$withval"], [PYLIB=]) - -if test -z "$PYINCLUDE"; then - if test -n "$PYPACKAGE"; then - PYINCLUDE="$PYPACKAGE/include" - fi -fi - -if test -z "$PYLIB"; then - if test -n "$PYPACKAGE"; then - PYLIB="$PYPACKAGE/lib" - fi -fi - - -AC_MSG_CHECKING(for Python header files) - -dirs="$PYINCLUDE $PYINCLUDE/python2.0 $PYINCLUDE/python1.6 $PYINCLUDE/python1.5 $prefix/include/python2.0 $prefix/include/python1.6 $prefix/include/python1.5 /usr/local/include/python2.0 /usr/local/include/python1.6 /usr/local/include/python1.5 /usr/include/python1.5" -for i in $dirs ; do - if test -r $i/Python.h; then - AC_MSG_RESULT($i) - PYINCLUDE="-I$i" - MAKEPYTHON="python" - break - fi -done -if test -z "$PYINCLUDE"; then - PYINCLUDE="" - MAKEPYTHON="" - AC_MSG_RESULT(not found) -fi - -AC_SUBST(PYINCLUDE) -AC_SUBST(PYLINK) -AC_SUBST(MAKEPYTHON) - -#---------------------------------------------------------------- -# Look for Perl5 -#---------------------------------------------------------------- - -PERLBIN= -MAKEPERL= - -AC_ARG_WITH(perl5,[ --with-perl5=path Set location of Perl5 executable],[ PERLBIN="$withval"], [PERLBIN=]) - -# First figure out what the name of Perl5 is - -if test -z "$PERLBIN"; then -AC_CHECK_PROGS(PERL, perl5.004 perl5.003 perl5.002 perl5.001 perl5 perl) -else -PERL="$PERLBIN" -fi -AC_MSG_CHECKING(for Perl5 header files) -if test -n "$PERL"; then - PERL5DIR=`($PERL -e 'use Config; print $Config{archlib};') 2>/dev/null` - if test "$PERL5DIR" != ""; then - dirs="$PERL5DIR $PERL5DIR/CORE" - PERL5EXT=none - for i in $dirs; do - if test -r $i/perl.h; then - AC_MSG_RESULT($i) - PERL5EXT="-I$i" - MAKEPERL="perl" - break; - fi - done - if test "$PERL5EXT" = none; then - PERL5EXT="" - MAKEPERL="" - AC_MSG_RESULT(could not locate perl.h...using $PERL5EXT) - fi - else - AC_MSG_RESULT(unable to determine perl5 configuration) - PERL5EXT="" - MAKEPERL="" - fi - else - AC_MSG_RESULT(could not figure out how to run perl5) - PERL5EXT="" - MAKEPERL="" - fi - -AC_SUBST(PERL5EXT) -AC_SUBST(MAKEPERL) - -dnl We use the following in `AC_CONFIG_FILES' and "make distclean". -configure_substituted_files=`echo \ - Wad/Makefile \ - Python/Makefile \ - Tcl/Makefile \ - Test/Makefile \ - Prebuilt/linux/Makefile \ - Prebuilt/solaris/Makefile \ - Makefile \ -` -AC_SUBST(configure_substituted_files) - -AC_CONFIG_FILES([$configure_substituted_files]) -AC_OUTPUT - -dnl configure.in ends here - diff --git a/Tools/swig.spec.1 b/Tools/swig.spec.1 deleted file mode 100644 index 7af0440cd..000000000 --- a/Tools/swig.spec.1 +++ /dev/null @@ -1,42 +0,0 @@ -%define version 1.3.7 -%define release 1 - -# Preamble -Summary: Simplified Wrapper and Interface Generator -Name: swig -Version: %{version} -Release: %{release} -Copyright: BSD -URL: http://www.swig.org -Group: System Environment/Daemons -Source0: http://download.sourceforge.net/swig/swig-%{version}.tar.gz -Packager: Dustin Mitchell -BuildRoot: /var/tmp/rpm/swig-root -Prefix: /usr - -%description -SWIG is an interface compiler that connects programs written in C, -C++, and Objective-C with scripting languages including Perl, Python, -and Tcl/Tk. It works by taking the declarations commonly found in -C/C++ header files and using them to generate the glue code (wrappers) -that scripting languages need to access the underlying C/C++ code - -# PREP -%prep -%setup -n SWIG-%{version} - -# BUILD -%build -./configure --prefix=%prefix -make - -# INSTALL -%install -rm -rf ${RPM_BUILD_ROOT} -install -d -m 755 ${RPM_BUILD_ROOT} -make prefix=${RPM_BUILD_ROOT}%prefix install - -# FILES -%files -%prefix/lib/* -%prefix/bin/swig From 78224af80b3225858cfd8aa2ca49d3e6f76759b9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 29 May 2010 23:44:05 +0000 Subject: [PATCH 135/203] Add 2.0.0 release notes summary git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12071 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- RELEASENOTES | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/RELEASENOTES b/RELEASENOTES index da833574c..86daf285f 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -1,8 +1,28 @@ Release Notes ============= -A summary of recent releases is described below. A more detailed description -is available in the CHANGES.current and CHANGES files. +A detailed description of changes are available in the CHANGES.current +and CHANGES files. The summaries below contain just a brief overview of +the changes made in each release. + +SWIG-2.0.0 summary: +- Much better nested class/struct support. +- Much improved template partial specialization and explicit + specialization handling. +- Namespace support improved with the 'nspace' feature where namespaces + can be automatically translated into Java packages or C# namespaces. +- Improved typemap and symbol table debugging. +- Numerous subtle typemap matching rule changes when using the default + (SWIGTYPE) type. These now work much like C++ class template partial + specialization matching. +- Other small enhancements for typemaps. Typemap fragments are also now + official and documented. +- Warning and error display refinements. +- Wrapping of shared_ptr is improved and documented now. +- Numerous C++ unary scope operator (::) fixes. +- Better support for boolean expressions. +- Various bug fixes and improvements in the Allegrocl, C#, Java, Lua, + Octave, PHP, Python, R, Ruby and XML modules. SWIG-1.3.40 summary: - SWIG now supports directors for PHP. From 4144eaa214ad5cebcde10a968da1551fb02c3869 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 1 Jun 2010 06:24:48 +0000 Subject: [PATCH 136/203] Remove PHP4 hangover. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12072 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/reference/runme-proxy.php4 | 79 ------------------------- 1 file changed, 79 deletions(-) delete mode 100644 Examples/php/reference/runme-proxy.php4 diff --git a/Examples/php/reference/runme-proxy.php4 b/Examples/php/reference/runme-proxy.php4 deleted file mode 100644 index 9d216f78b..000000000 --- a/Examples/php/reference/runme-proxy.php4 +++ /dev/null @@ -1,79 +0,0 @@ -print() . "\n"; -print " Created b: $b " . $b->print() . "\n"; - -# ----- Call an overloaded operator ----- - -# This calls the wrapper we placed around -# -# operator+(const Vector &a, const Vector &) -# -# It returns a new allocated object. - -print "Adding a+b\n"; -$c = addv($a,$b); -print " a+b =". $c->print()."\n"; - -# Note: Unless we free the result, a memory leak will occur -$c = 0; - -# ----- Create a vector array ----- - -# Note: Using the high-level interface here -print "Creating an array of vectors\n"; -$va = new VectorArray(10); - -print " va: $va size=".$va->size()."\n"; - -# ----- Set some values in the array ----- - -# These operators copy the value of $a and $b to the vector array -$va->set(0,$a); -$va->set(1,$b); - -$va->get(0); -# This will work, but it will cause a memory leak! - -$va->set(2,addv($a,$b)); - -# The non-leaky way to do it - -$c = addv($a,$b); -$va->set(3,$c); -$c = NULL; - -# Get some values from the array - -print "Getting some array values\n"; -for ($i = 0; $i < 5; $i++) { -print "do $i\n"; - $v = $va->get($i); - print " va($i) = ". $v->print(). "\n"; -} - -# Watch under resource meter to check on this -#print "Making sure we don't leak memory.\n"; -#for ($i = 0; $i < 1000000; $i++) { -# $c = VectorArray_get($va,$i % 10); -#} - -# ----- Clean up ----- -print "Cleaning up\n"; -# wants fixing FIXME -#delete_VectorArray($va); -#delete_Vector($a); -#delete_Vector($b); - -?> From 09c9bf881ddb6bfba2659137a068e72b96398720 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 1 Jun 2010 06:29:16 +0000 Subject: [PATCH 137/203] Remove PHP4 hangover git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12073 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/variables/runme.php4.old | 80 --------------------------- 1 file changed, 80 deletions(-) delete mode 100644 Examples/php/variables/runme.php4.old diff --git a/Examples/php/variables/runme.php4.old b/Examples/php/variables/runme.php4.old deleted file mode 100644 index 9a6bfb386..000000000 --- a/Examples/php/variables/runme.php4.old +++ /dev/null @@ -1,80 +0,0 @@ - - From 507ae344529fea9cd904484efce71b27529414c1 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 1 Jun 2010 15:14:29 +0000 Subject: [PATCH 138/203] Fix typos in __disown__() example git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12074 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 8f876316e..1cef3683a 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2782,12 +2782,12 @@ public:

       >>> c = FooContainer()
      ->>> a = Foo().__disown()__
      +>>> a = Foo().__disown__()
       >>> c.addFoo(a)
       >>> b = Foo()
      ->>> b = b.__disown()__
      +>>> b = b.__disown__()
       >>> c.addFoo(b)
      ->>> c.addFoo(Foo().__disown()__)
      +>>> c.addFoo(Foo().__disown__())
       
      From 515ec7311ff7933bb1db587c52a999be3cb0ba99 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 19:00:19 +0000 Subject: [PATCH 139/203] remove run test which doesn't do anything git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12075 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../octave/li_boost_shared_ptr_runme.m | 478 ------------------ 1 file changed, 478 deletions(-) delete mode 100644 Examples/test-suite/octave/li_boost_shared_ptr_runme.m diff --git a/Examples/test-suite/octave/li_boost_shared_ptr_runme.m b/Examples/test-suite/octave/li_boost_shared_ptr_runme.m deleted file mode 100644 index ca09316bc..000000000 --- a/Examples/test-suite/octave/li_boost_shared_ptr_runme.m +++ /dev/null @@ -1,478 +0,0 @@ -li_boost_shared_ptr - -debug = false; - -function main() - if (debug) - printf("Started\n") - endif - - li_boost_shared_ptr.cvar.debug_shared = debug; - - # Change loop count to run for a long time to monitor memory - loopCount = 1; #5000 - for i=0:loopCount, - self.runtest(); - endfor - - if (li_boost_shared_ptr.Klass.getTotal_count() != 0) - error("Klass.total_count=", li_boost_shared_ptr.Klass.getTotal_count()) - endif - - wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count(); - if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING) - if (wrapper_count != 0) - error("shared_ptr wrapper count not zero: %i", wrapper_count) - endif - endif - - if (debug) - error("Finished") - endif -endfunction - -function runtest() - # simple shared_ptr usage - created in C++ - k = li_boost_shared_ptr.Klass("me oh my"); - val = k.getValue(); - self.verifyValue("me oh my", val); - self.verifyCount(1, k); - - # simple shared_ptr usage - not created in C++ - k = li_boost_shared_ptr.factorycreate(); - val = k.getValue(); - self.verifyValue("factorycreate", val); - self.verifyCount(1, k); - - # pass by shared_ptr - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.smartpointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my smartpointertest", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # pass by shared_ptr pointer - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.smartpointerpointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my smartpointerpointertest", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # pass by shared_ptr reference - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.smartpointerreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my smartpointerreftest", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # pass by shared_ptr pointer reference - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.smartpointerpointerreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my smartpointerpointerreftest", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # const pass by shared_ptr - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.constsmartpointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # const pass by shared_ptr pointer - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.constsmartpointerpointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # const pass by shared_ptr reference - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.constsmartpointerreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # pass by value - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.valuetest(k); - val = kret.getValue(); - self.verifyValue("me oh my valuetest", val); - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # pass by pointer - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.pointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my pointertest", val); - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # pass by reference - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.reftest(k); - val = kret.getValue(); - self.verifyValue("me oh my reftest", val); - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # pass by pointer reference - k = li_boost_shared_ptr.Klass("me oh my"); - kret = li_boost_shared_ptr.pointerreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my pointerreftest", val); - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # null tests - k = None; - - if (li_boost_shared_ptr.smartpointertest(k) != None) - error("return was not null") - endif - - if (li_boost_shared_ptr.smartpointerpointertest(k) != None) - error("return was not null") - endif - - if (li_boost_shared_ptr.smartpointerreftest(k) != None) - error("return was not null") - endif - - if (li_boost_shared_ptr.smartpointerpointerreftest(k) != None) - error("return was not null") - endif - - if (li_boost_shared_ptr.nullsmartpointerpointertest(None) != "null pointer") - error("not null smartpointer pointer") - endif - - try - li_boost_shared_ptr.valuetest(k) - error("Failed to catch null pointer") - catch - end_try_catch - - if (li_boost_shared_ptr.pointertest(k) != None) - error("return was not null") - endif - - try - li_boost_shared_ptr.reftest(k) - error("Failed to catch null pointer") - catch - end_try_catch - - # $owner - k = li_boost_shared_ptr.pointerownertest(); - val = k.getValue(); - self.verifyValue("pointerownertest", val); - self.verifyCount(1, k); - k = li_boost_shared_ptr.smartpointerpointerownertest(); - val = k.getValue(); - self.verifyValue("smartpointerpointerownertest", val); - self.verifyCount(1, k); - - # //////////////////////////////// Derived class //////////////////////////////////////// - # derived pass by shared_ptr - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.derivedsmartptrtest(k); - val = kret.getValue(); - self.verifyValue("me oh my derivedsmartptrtest-Derived", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # derived pass by shared_ptr pointer - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.derivedsmartptrpointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my derivedsmartptrpointertest-Derived", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # derived pass by shared_ptr ref - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.derivedsmartptrreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my derivedsmartptrreftest-Derived", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # derived pass by shared_ptr pointer ref - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.derivedsmartptrpointerreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # derived pass by pointer - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.derivedpointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my derivedpointertest-Derived", val); - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # derived pass by ref - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.derivedreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my derivedreftest-Derived", val); - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # //////////////////////////////// Derived and base class mixed //////////////////////////////////////// - # pass by shared_ptr (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.smartpointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my smartpointertest-Derived", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # pass by shared_ptr pointer (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.smartpointerpointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my smartpointerpointertest-Derived", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # pass by shared_ptr reference (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.smartpointerreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my smartpointerreftest-Derived", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # pass by shared_ptr pointer reference (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.smartpointerpointerreftest(k); - val = kret.getValue(); - self.verifyValue("me oh my smartpointerpointerreftest-Derived", val); - self.verifyCount(2, k); - self.verifyCount(2, kret); - - # pass by value (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.valuetest(k); - val = kret.getValue(); - self.verifyValue("me oh my valuetest", val); # note slicing - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # pass by pointer (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.pointertest(k); - val = kret.getValue(); - self.verifyValue("me oh my pointertest-Derived", val); - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # pass by ref (mixed) - k = li_boost_shared_ptr.KlassDerived("me oh my"); - kret = li_boost_shared_ptr.reftest(k); - val = kret.getValue(); - self.verifyValue("me oh my reftest-Derived", val); - self.verifyCount(1, k); - self.verifyCount(1, kret); - - # //////////////////////////////// Overloading tests //////////////////////////////////////// - # Base class - k = li_boost_shared_ptr.Klass("me oh my"); - self.verifyValue(li_boost_shared_ptr.overload_rawbyval(k), "rawbyval"); - self.verifyValue(li_boost_shared_ptr.overload_rawbyref(k), "rawbyref"); - self.verifyValue(li_boost_shared_ptr.overload_rawbyptr(k), "rawbyptr"); - self.verifyValue(li_boost_shared_ptr.overload_rawbyptrref(k), "rawbyptrref"); - - self.verifyValue(li_boost_shared_ptr.overload_smartbyval(k), "smartbyval"); - self.verifyValue(li_boost_shared_ptr.overload_smartbyref(k), "smartbyref"); - self.verifyValue(li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr"); - self.verifyValue(li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref"); - - # Derived class - k = li_boost_shared_ptr.KlassDerived("me oh my"); - self.verifyValue(li_boost_shared_ptr.overload_rawbyval(k), "rawbyval"); - self.verifyValue(li_boost_shared_ptr.overload_rawbyref(k), "rawbyref"); - self.verifyValue(li_boost_shared_ptr.overload_rawbyptr(k), "rawbyptr"); - self.verifyValue(li_boost_shared_ptr.overload_rawbyptrref(k), "rawbyptrref"); - - self.verifyValue(li_boost_shared_ptr.overload_smartbyval(k), "smartbyval"); - self.verifyValue(li_boost_shared_ptr.overload_smartbyref(k), "smartbyref"); - self.verifyValue(li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr"); - self.verifyValue(li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref"); - - # //////////////////////////////// Member variables //////////////////////////////////////// - # smart pointer by value - m = li_boost_shared_ptr.MemberVariables(); - k = li_boost_shared_ptr.Klass("smart member value"); - m.SmartMemberValue = k; - val = k.getValue(); - self.verifyValue("smart member value", val); - self.verifyCount(2, k); - - kmember = m.SmartMemberValue; - val = kmember.getValue(); - self.verifyValue("smart member value", val); - self.verifyCount(3, kmember); - self.verifyCount(3, k); - - clear m; - self.verifyCount(2, kmember); - self.verifyCount(2, k); - - # smart pointer by pointer - m = li_boost_shared_ptr.MemberVariables(); - k = li_boost_shared_ptr.Klass("smart member pointer"); - m.SmartMemberPointer = k; - val = k.getValue(); - self.verifyValue("smart member pointer", val); - self.verifyCount(1, k); - - kmember = m.SmartMemberPointer; - val = kmember.getValue(); - self.verifyValue("smart member pointer", val); - self.verifyCount(2, kmember); - self.verifyCount(2, k); - - clear m; - self.verifyCount(2, kmember); - self.verifyCount(2, k); - - # smart pointer by reference - m = li_boost_shared_ptr.MemberVariables(); - k = li_boost_shared_ptr.Klass("smart member reference"); - m.SmartMemberReference = k; - val = k.getValue(); - self.verifyValue("smart member reference", val); - self.verifyCount(2, k); - - kmember = m.SmartMemberReference; - val = kmember.getValue(); - self.verifyValue("smart member reference", val); - self.verifyCount(3, kmember); - self.verifyCount(3, k); - - # The C++ reference refers to SmartMemberValue... - kmemberVal = m.SmartMemberValue; - val = kmember.getValue(); - self.verifyValue("smart member reference", val); - self.verifyCount(4, kmemberVal); - self.verifyCount(4, kmember); - self.verifyCount(4, k); - - clear m; - self.verifyCount(3, kmemberVal); - self.verifyCount(3, kmember); - self.verifyCount(3, k); - - # plain by value - m = li_boost_shared_ptr.MemberVariables(); - k = li_boost_shared_ptr.Klass("plain member value"); - m.MemberValue = k; - val = k.getValue(); - self.verifyValue("plain member value", val); - self.verifyCount(1, k); - - kmember = m.MemberValue; - val = kmember.getValue(); - self.verifyValue("plain member value", val); - self.verifyCount(1, kmember); - self.verifyCount(1, k); - - clear m; - self.verifyCount(1, kmember); - self.verifyCount(1, k); - - # plain by pointer - m = li_boost_shared_ptr.MemberVariables(); - k = li_boost_shared_ptr.Klass("plain member pointer"); - m.MemberPointer = k; - val = k.getValue(); - self.verifyValue("plain member pointer", val); - self.verifyCount(1, k); - - kmember = m.MemberPointer; - val = kmember.getValue(); - self.verifyValue("plain member pointer", val); - self.verifyCount(1, kmember); - self.verifyCount(1, k); - - clear m; - self.verifyCount(1, kmember); - self.verifyCount(1, k); - - # plain by reference - m = li_boost_shared_ptr.MemberVariables(); - k = li_boost_shared_ptr.Klass("plain member reference"); - m.MemberReference = k; - val = k.getValue(); - self.verifyValue("plain member reference", val); - self.verifyCount(1, k); - - kmember = m.MemberReference; - val = kmember.getValue(); - self.verifyValue("plain member reference", val); - self.verifyCount(1, kmember); - self.verifyCount(1, k); - - clear m; - self.verifyCount(1, kmember); - self.verifyCount(1, k); - - # null member variables - m = li_boost_shared_ptr.MemberVariables(); - - # shared_ptr by value - k = m.SmartMemberValue; - if (k != None) - error("expected null") - endif - m.SmartMemberValue = None; - k = m.SmartMemberValue; - if (k != None) - error("expected null") - endif - self.verifyCount(0, k); - - # plain by value - try - m.MemberValue = None; - error("Failed to catch null pointer"); - catch - end_try_catch - - # templates - pid = li_boost_shared_ptr.PairIntDouble(10, 20.2) - if (pid.baseVal1 != 20 || pid.baseVal2 != 40.4) - error("Base values wrong") - endif - if (pid.val1 != 10 || pid.val2 != 20.2) - error("Derived Values wrong") - endif -endfunction - -function verifyValue(expected,got) - if (expected != got) - error("verify value failed. Expected: %i, Got %i\n",expected,got) - endif -endfunction - -function verifyCount(expected,k) - got = li_boost_shared_ptr.use_count(k); - if (expected != got) - error("verify value failed. Expected: %i, Got %i\n",expected,got) - endif -endfunction - - From 84985fa2056f3f9f2719a69c6fcf616c232b4519 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 19:00:54 +0000 Subject: [PATCH 140/203] remove WAD from distribution git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12076 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/mkdist.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 6972eb829..f2a04542c 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -47,7 +47,6 @@ os.system("rm -Rf "+dirname+"/debian") == 0 or failed() print "Building system" os.system("cd "+dirname+" && ./autogen.sh") == 0 or failed() -os.system("cd "+dirname+"/Tools/WAD && autoconf") == 0 or failed() os.system("cd "+dirname+"/Source/CParse && bison -y -d parser.y && mv y.tab.c parser.c && mv y.tab.h parser.h") == 0 or failed() os.system("cd "+dirname+" && make -f Makefile.in libfiles srcdir=./") == 0 or failed() From 36c2e97a1c4d761fdc89fa374830edea33db95b4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 19:03:55 +0000 Subject: [PATCH 141/203] Add std_shared_ptr.i and document shared_ptr library git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12077 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 10 +++ Doc/Manual/Library.html | 138 ++++++++++++++++++++++++++++++++---- Doc/Manual/SWIGPlus.html | 4 +- Lib/csharp/std_shared_ptr.i | 2 + Lib/java/std_shared_ptr.i | 2 + Lib/python/std_shared_ptr.i | 2 + Lib/shared_ptr.i | 2 + 7 files changed, 143 insertions(+), 17 deletions(-) create mode 100644 Lib/csharp/std_shared_ptr.i create mode 100644 Lib/java/std_shared_ptr.i create mode 100644 Lib/python/std_shared_ptr.i diff --git a/CHANGES.current b/CHANGES.current index c52179d45..a2987e392 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,16 @@ Version 2.0.0 (in progress) ============================ +2010-06-01: wsfulton + Add in std_shared_ptr.i for wrapping std::shared_ptr. Requires the %shared_ptr + macro like in the boost_shared_ptr.i library. std::tr1::shared_ptr can also be + wrapped if the following macro is defined: + + #define SWIG_SHARED_PTR_SUBNAMESPACE tr1 + %include + + shared_ptr is also documented in Library.html now. + 2010-05-27: wsfulton Add the ability for $typemap special variable macros to call other $typemap special variable macros, for example: diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index c003151ac..8ea8a7a31 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -27,8 +27,8 @@
  • STL/C++ Library
  • Utility Libraries @@ -1383,6 +1383,7 @@ The following table shows which C++ classes are supported and the equivalent SWI
  • +
    std::set set std_set.i
    std::string string std_string.i
    std::vector vector std_vector.i
    std::shared_ptr shared_ptr std_shared_ptr.i
    @@ -1392,7 +1393,7 @@ Please look for the library files in the appropriate language library directory.

    -

    8.4.1 std_string.i

    +

    std::string

    @@ -1476,16 +1477,11 @@ void foo(string s, const String &t); // std_string typemaps still applie -

    -Note: The std_string library is incompatible with Perl on some platforms. -We're looking into it. -

    - -

    8.4.2 std_vector.i

    +

    std::vector

    -The std_vector.i library provides support for the C++ vector class in the STL. +The std_vector.i library provides support for the C++ std::vector class in the STL. Using this library involves the use of the %template directive. All you need to do is to instantiate different versions of vector for the types that you want to use. For example:

    @@ -1660,11 +1656,6 @@ if you want to make their head explode. details and the public API exposed to the interpreter vary.

    -

    -Note: std_vector.i was written by Luigi "The Amazing" Ballabio. -

    - -

    8.4.3 STL exceptions

    @@ -1715,6 +1706,123 @@ The %exception directive can be used by placing the following code befo Any thrown STL exceptions will then be gracefully handled instead of causing a crash.

    +

    shared_ptr smart pointer

    + +

    +Some target languages have support for handling the widely used boost::shared_ptr smart pointer. +This smart pointer is also available as std::tr1::shared_ptr before it becomes fully standardized as std::shared_ptr. +The boost_shared_ptr.i library provides support for boost::shared_ptr and std_shared_ptr.i provides support for std::shared_ptr, but if the following macro is defined as shown, it can be used for std::tr1::shared_ptr: +

    + +
    +
    +#define SWIG_SHARED_PTR_SUBNAMESPACE tr1
    +%include <std_shared_ptr.i>
    +
    +
    + +

    +You can only use one of these variants of shared_ptr in your interface file at a time. +and all three variants must be used in conjunction with the %shared_ptr(T) macro, +where T is the underlying pointer type equating to usage shared_ptr<T>. +The type T must be non-primitive. +A simple example demonstrates usage: +

    + +
    +
    +%module example
    +%include <boost_shared_ptr.i>
    +%shared_ptr(IntValue)
    +
    +%inline %{
    +#include <boost/shared_ptr.hpp>
    +
    +struct IntValue {
    +  int value;
    +  IntValue(int v) : value(v) {}
    +};
    +
    +static int extractValue(const IntValue &t) {
    +  return t.value;
    +}
    +
    +static int extractValueSmart(boost::shared_ptr<IntValue> t) {
    +  return t->value;
    +}
    +%}
    +
    +
    + +

    +Note that the %shared_ptr(IntValue) declaration occurs after the inclusion of the boost_shared_ptr.i +library which provides the macro and, very importantly, before any usage or declaration of the type, IntValue. +The %shared_ptr macro provides, a few things for handling this smart pointer, but mostly a number of +typemaps. These typemaps override the default typemaps so that the underlying proxy class is stored and passed around +as a pointer to a shared_ptr instead of a plain pointer to the underlying type. +This approach means that any instantiation of the type can be passed to methods taking the type by value, reference, pointer +or as a smart pointer. +The interested reader might want to look at the generated code, however, usage is simple and no different +handling is required from the target language. +For example, a simple use case of the above code from Java would be: +

    + +
    +
    +IntValue iv = new IntValue(1234);
    +int val1 = example.extractValue(iv);
    +int val2 = example.extractValueSmart(iv);
    +System.out.println(val1 + " " + val2);
    +
    +
    + +

    +This shared_ptr library works quite differently to SWIG's normal, but somewhat limited, +smart pointer handling. +The shared_ptr library does not generate extra wrappers, just for smart pointer handling, in addition to the proxy class. +The normal proxy class including inheritance relationships is generated as usual. +The only real change introduced by the %shared_ptr macro is that the proxy class stores a pointer to the shared_ptr instance instead of a raw pointer to the instance. +A proxy class derived from a base which is being wrapped with shared_ptr can and must be wrapped as a shared_ptr too. +In other words all classes in an inheritance hierarchy must all be used with the %shared_ptr macro. +For example the following code can be used with the base class shown earlier: +

    + +
    +
    +%shared_ptr(DerivedIntValue)
    +%inline %{
    +struct DerivedIntValue : IntValue {
    +  DerivedIntValue(int value) : IntValue(value) {}
    +  ...
    +};
    +%}
    +
    +
    + +

    +Note that if the %shared_ptr macro is omitted for any class in the inheritance hierarchy, it will +result in a C++ compiler error. +For example if the above %shared_ptr(DerivedIntValue) is omitted, the following is typical of the compiler error that will result: +

    + +
    +
    +example_wrap.cxx: In function ‘void Java_exampleJNI_delete_1DerivedIntValue(JNIEnv*, _jclass*, jlong)’:
    +example_wrap.cxx:3169: error: ‘smartarg1’ was not declared in this scope
    +
    +
    + +

    +A shared_ptr of the derived class can now be passed to a method where the base is expected in the target language, just as it can in C++: +

    + +
    +
    +DerivedIntValue div = new DerivedIntValue(5678);
    +int val3 = example.extractValue(div);
    +int val4 = example.extractValueSmart(div);
    +
    +

    8.5 Utility Libraries

    diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 47ed38186..f9bfc8ec6 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -56,7 +56,7 @@
  • Exception specifications
  • Exception handling with %catches
  • Pointers to Members -
  • Smart pointers and operator->() +
  • Smart pointers and operator->()
  • Using declarations and inheritance
  • Nested classes
  • A brief rant about const-correctness @@ -4408,7 +4408,7 @@ when checking types. However, no such support is currently provided for member pointers.

    -

    6.24 Smart pointers and operator->()

    +

    6.24 Smart pointers and operator->()

    diff --git a/Lib/csharp/std_shared_ptr.i b/Lib/csharp/std_shared_ptr.i new file mode 100644 index 000000000..df873679c --- /dev/null +++ b/Lib/csharp/std_shared_ptr.i @@ -0,0 +1,2 @@ +#define SWIG_SHARED_PTR_NAMESPACE std +%include diff --git a/Lib/java/std_shared_ptr.i b/Lib/java/std_shared_ptr.i new file mode 100644 index 000000000..df873679c --- /dev/null +++ b/Lib/java/std_shared_ptr.i @@ -0,0 +1,2 @@ +#define SWIG_SHARED_PTR_NAMESPACE std +%include diff --git a/Lib/python/std_shared_ptr.i b/Lib/python/std_shared_ptr.i new file mode 100644 index 000000000..df873679c --- /dev/null +++ b/Lib/python/std_shared_ptr.i @@ -0,0 +1,2 @@ +#define SWIG_SHARED_PTR_NAMESPACE std +%include diff --git a/Lib/shared_ptr.i b/Lib/shared_ptr.i index 77e868de2..450493db4 100644 --- a/Lib/shared_ptr.i +++ b/Lib/shared_ptr.i @@ -1,3 +1,5 @@ +// This is a helper file for shared_ptr and should not be included directly. + // The main implementation detail in using this smart pointer of a type is to customise the code generated // to use a pointer to the smart pointer of the type, rather than the usual pointer to the underlying type. // So for some type T, shared_ptr * is used rather than T *. From 978080846c130e011f0b4e172a164235ae55997a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 19:19:17 +0000 Subject: [PATCH 142/203] html fixes and chapter renumbering git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12078 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 7 ++++--- Doc/Manual/Library.html | 12 +++++++----- Doc/Manual/Preface.html | 2 -- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 9d353636a..8612ef237 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -236,7 +236,7 @@

  • Exception specifications
  • Exception handling with %catches
  • Pointers to Members -
  • Smart pointers and operator->() +
  • Smart pointers and operator->()
  • Using declarations and inheritance
  • Nested classes
  • A brief rant about const-correctness @@ -287,9 +287,10 @@
  • STL/C++ Library
  • Utility Libraries
  • Utility Libraries
      @@ -1393,7 +1394,7 @@ Please look for the library files in the appropriate language library directory.

      -

      std::string

      +

      8.4.1 std::string

      @@ -1477,7 +1478,7 @@ void foo(string s, const String &t); // std_string typemaps still applie -

      std::vector

      +

      8.4.2 std::vector

      @@ -1706,7 +1707,8 @@ The %exception directive can be used by placing the following code befo Any thrown STL exceptions will then be gracefully handled instead of causing a crash.

      -

      shared_ptr smart pointer

      +

      8.4.4 shared_ptr smart pointer

      +

      Some target languages have support for handling the widely used boost::shared_ptr smart pointer. @@ -1807,8 +1809,8 @@ For example if the above %shared_ptr(DerivedIntValue) is omitted, the f

      -example_wrap.cxx: In function ‘void Java_exampleJNI_delete_1DerivedIntValue(JNIEnv*, _jclass*, jlong)’:
      -example_wrap.cxx:3169: error: ‘smartarg1’ was not declared in this scope
      +example_wrap.cxx: In function 'void Java_exampleJNI_delete_1DerivedIntValue(JNIEnv*, _jclass*, jlong)':
      +example_wrap.cxx:3169: error: 'smartarg1' was not declared in this scope
       
      diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index 2680328dd..2d0aa093e 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -200,8 +200,6 @@ who have made contributions at all levels over time. Contributors are mentioned either in the COPYRIGHT file or CHANGES files shipped with SWIG or in submitted bugs.

      -

      -

      1.9 Bug reports

      From cccd7d605c84608708d21ca4654c1f5b2516b6f0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 20:03:26 +0000 Subject: [PATCH 143/203] Refer each of the changes/release notes files to each other git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12079 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 3 ++- CHANGES.current | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index cad14004b..721a49269 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,7 @@ SWIG (Simplified Wrapper and Interface Generator) -See CHANGES.current for current version. +See CHANGES.current for changes in the current version. +See RELEASENOTES for a summary of changes in each release. Version 1.3.40 (18 August 2009) =============================== diff --git a/CHANGES.current b/CHANGES.current index a2987e392..19f477d5b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 2.0.0 (in progress) ============================ +See CHANGES for changes in older releases. +See RELEASENOTES for a summary of changes in each release. + 2010-06-01: wsfulton Add in std_shared_ptr.i for wrapping std::shared_ptr. Requires the %shared_ptr macro like in the boost_shared_ptr.i library. std::tr1::shared_ptr can also be From b802e37ad215542c291b8c06b2f18a23cad46f0b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 22:43:34 +0000 Subject: [PATCH 144/203] Add license changes to release notes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12080 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ RELEASENOTES | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 19f477d5b..d0ff785eb 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -399,6 +399,10 @@ See RELEASENOTES for a summary of changes in each release. and line number related to the type. This is effectively a condensed form of the -debug-tmsearch option. Documented in Typemaps.html. +2009-12-27: wsfulton + License code changes: SWIG Source is GPL-v3 and library code license is now clearer + and is provided under a very permissive license. See http://www.swig.org/legal.html. + 2009-12-23: wsfulton Fix for %javaexception and directors so that all the appropriate throws clauses are generated. Problem reported by Peter Greenwood. diff --git a/RELEASENOTES b/RELEASENOTES index 86daf285f..74e043ae7 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -6,6 +6,7 @@ and CHANGES files. The summaries below contain just a brief overview of the changes made in each release. SWIG-2.0.0 summary: +- License changes, see LICENSE file and http://www.swig.org/legal.html. - Much better nested class/struct support. - Much improved template partial specialization and explicit specialization handling. From d25121a0ed3f2b3104bd50a991e917099dd12380 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 23:10:22 +0000 Subject: [PATCH 145/203] Fix SWIG_STD_VECTOR_ENHANCED macro used in C# std::vector to work with commas git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12081 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 6 ++++ .../csharp/li_std_combinations_runme.cs | 31 +++++++++++++++++++ Examples/test-suite/li_std_combinations.i | 8 +++++ Lib/csharp/csharp.swg | 3 ++ Lib/csharp/std_vector.i | 8 ++--- 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 Examples/test-suite/csharp/li_std_combinations_runme.cs diff --git a/CHANGES.current b/CHANGES.current index d0ff785eb..f24856b49 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,12 @@ Version 2.0.0 (in progress) See CHANGES for changes in older releases. See RELEASENOTES for a summary of changes in each release. +2010-06-02: wsfulton + [C#] Fix SWIG_STD_VECTOR_ENHANCED macro used in std::vector to work with + types containing commas, for example: + + SWIG_STD_VECTOR_ENHANCED(std::pair< double, std::string >) + 2010-06-01: wsfulton Add in std_shared_ptr.i for wrapping std::shared_ptr. Requires the %shared_ptr macro like in the boost_shared_ptr.i library. std::tr1::shared_ptr can also be diff --git a/Examples/test-suite/csharp/li_std_combinations_runme.cs b/Examples/test-suite/csharp/li_std_combinations_runme.cs new file mode 100644 index 000000000..ced9d17a3 --- /dev/null +++ b/Examples/test-suite/csharp/li_std_combinations_runme.cs @@ -0,0 +1,31 @@ +using System; +using li_std_combinationsNamespace; + +public class li_std_combinations_runme { + public static void Main() { + VectorPairIntString vpis = new VectorPairIntString(); + vpis.Add(new PairIntString(123, "one hundred and twenty three")); + + VectorString vs = new VectorString(); + vs.Add("hi"); + PairIntVectorString pivs = new PairIntVectorString(456, vs); + if (pivs.second[0] != "hi") + throw new ApplicationException("PairIntVectorString"); + + VectorVectorString vvs = new VectorVectorString(); + vvs.Add(vs); + + PairIntPairIntString pipis = new PairIntPairIntString(12, new PairIntString(3, "4")); + if (pipis.first != 12) + throw new ApplicationException("PairIntPairIntString"); + + PairDoubleString pds = new PairDoubleString(12.34, "okay"); + VectorPairDoubleString vpds = new VectorPairDoubleString(); + vpds.Add(pds); + + // Check SWIG_STD_VECTOR_ENHANCED macro - it provides the Contains method + if (!vpds.Contains(pds)) + throw new ApplicationException("VectorPairDoubleString"); + } +} + diff --git a/Examples/test-suite/li_std_combinations.i b/Examples/test-suite/li_std_combinations.i index d760fa44e..9acc8f23d 100644 --- a/Examples/test-suite/li_std_combinations.i +++ b/Examples/test-suite/li_std_combinations.i @@ -13,3 +13,11 @@ %template(VectorVectorString) std::vector< std::vector >; %template(PairIntPairIntString) std::pair< int, std::pair >; + +#if defined(SWIGCSHARP) +// Checks macro containing a type with a comma +SWIG_STD_VECTOR_ENHANCED(std::pair< double, std::string >) +#endif +%template(PairDoubleString) std::pair< double, std::string >; +%template(VectorPairDoubleString) std::vector< std::pair >; + diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 57998b9db..d16584565 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -963,6 +963,9 @@ using System.Runtime.InteropServices; // Default enum handling %include +// For vararg handling in macros, from swigmacros.swg +#define %arg(X...) X + /* // Alternative char * typemaps. %pragma(csharp) imclasscode=%{ diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 7fca7d2fd..f270b7f59 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -319,10 +319,6 @@ } %enddef -%define SWIG_STD_VECTOR_MINIMUM(CTYPE...) -SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, CTYPE const&, CTYPE) -%enddef - // Extra methods added to the collection class if operator== is defined for the class being wrapped // The class will then implement IList<>, which adds extra functionality %define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE...) @@ -359,7 +355,7 @@ SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, CTYPE const&, CTYPE) %define SWIG_STD_VECTOR_ENHANCED(CTYPE...) namespace std { template<> class vector { - SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, CTYPE const&, CTYPE) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, %arg(CTYPE const&), %arg(CTYPE)) SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE) }; } @@ -392,7 +388,7 @@ namespace std { // primary (unspecialized) class template for std::vector // does not require operator== to be defined template class vector { - SWIG_STD_VECTOR_MINIMUM(T) + SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, T const&, T) }; // specialization for pointers template class vector { From 570b9154e4f629f055ce41bd5bc3a20c233f4732 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 23:14:42 +0000 Subject: [PATCH 146/203] Correct license change date git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12082 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f24856b49..cde7a5e53 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -294,6 +294,10 @@ See RELEASENOTES for a summary of changes in each release. [Python] Remove -dirvtable from the optimizations included by -O as it this option currently leads to memory leaks as reported by Johan Blake. +2010-02-27: wsfulton + License code changes: SWIG Source is GPL-v3 and library code license is now clearer + and is provided under a very permissive license. See http://www.swig.org/legal.html. + 2010-02-13: wsfulton [Ruby] A few fixes for compiling under ruby-1.9.x including patch from 'Nibble'. @@ -405,10 +409,6 @@ See RELEASENOTES for a summary of changes in each release. and line number related to the type. This is effectively a condensed form of the -debug-tmsearch option. Documented in Typemaps.html. -2009-12-27: wsfulton - License code changes: SWIG Source is GPL-v3 and library code license is now clearer - and is provided under a very permissive license. See http://www.swig.org/legal.html. - 2009-12-23: wsfulton Fix for %javaexception and directors so that all the appropriate throws clauses are generated. Problem reported by Peter Greenwood. From cc9b81128180d03e7ba8122a68c93e634f84579b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 1 Jun 2010 23:36:08 +0000 Subject: [PATCH 147/203] Add spaces to avoid unintended <: digraph in SWIG_STD_VECTOR_ENHANCED git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12083 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/csharp/std_vector.i | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index f270b7f59..5a21ad399 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -26,8 +26,8 @@ // MACRO for use within the std::vector class body %define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...) -%typemap(csinterfaces) std::vector "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n#endif\n"; -%typemap(cscode) std::vector %{ +%typemap(csinterfaces) std::vector< CTYPE > "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n#endif\n"; +%typemap(cscode) std::vector< CTYPE > %{ public $csclassname(System.Collections.ICollection c) : this() { if (c == null) throw new ArgumentNullException("c"); @@ -222,9 +222,9 @@ vector(const vector &other); %extend { vector(int capacity) throw (std::out_of_range) { - std::vector* pv = 0; + std::vector< CTYPE >* pv = 0; if (capacity >= 0) { - pv = new std::vector(); + pv = new std::vector< CTYPE >(); pv->reserve(capacity); } else { throw std::out_of_range("capacity"); @@ -250,18 +250,18 @@ throw std::out_of_range("index"); } // Takes a deep copy of the elements unlike ArrayList.AddRange - void AddRange(const std::vector& values) { + void AddRange(const std::vector< CTYPE >& values) { $self->insert($self->end(), values.begin(), values.end()); } // Takes a deep copy of the elements unlike ArrayList.GetRange - std::vector *GetRange(int index, int count) throw (std::out_of_range, std::invalid_argument) { + std::vector< CTYPE > *GetRange(int index, int count) throw (std::out_of_range, std::invalid_argument) { if (index < 0) throw std::out_of_range("index"); if (count < 0) throw std::out_of_range("count"); if (index >= (int)$self->size()+1 || index+count > (int)$self->size()) throw std::invalid_argument("invalid range"); - return new std::vector($self->begin()+index, $self->begin()+index+count); + return new std::vector< CTYPE >($self->begin()+index, $self->begin()+index+count); } void Insert(int index, CTYPE const& x) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()+1) @@ -270,7 +270,7 @@ throw std::out_of_range("index"); } // Takes a deep copy of the elements unlike ArrayList.InsertRange - void InsertRange(int index, const std::vector& values) throw (std::out_of_range) { + void InsertRange(int index, const std::vector< CTYPE >& values) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()+1) $self->insert($self->begin()+index, values.begin(), values.end()); else @@ -291,10 +291,10 @@ throw std::invalid_argument("invalid range"); $self->erase($self->begin()+index, $self->begin()+index+count); } - static std::vector *Repeat(CTYPE const& value, int count) throw (std::out_of_range) { + static std::vector< CTYPE > *Repeat(CTYPE const& value, int count) throw (std::out_of_range) { if (count < 0) throw std::out_of_range("count"); - return new std::vector(count, value); + return new std::vector< CTYPE >(count, value); } void Reverse() { std::reverse($self->begin(), $self->end()); @@ -309,7 +309,7 @@ std::reverse($self->begin()+index, $self->begin()+index+count); } // Takes a deep copy of the elements unlike ArrayList.SetRange - void SetRange(int index, const std::vector& values) throw (std::out_of_range) { + void SetRange(int index, const std::vector< CTYPE >& values) throw (std::out_of_range) { if (index < 0) throw std::out_of_range("index"); if (index+values.size() > $self->size()) @@ -328,20 +328,20 @@ } int IndexOf(CTYPE const& value) { int index = -1; - std::vector::iterator it = std::find($self->begin(), $self->end(), value); + std::vector< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value); if (it != $self->end()) index = (int)(it - $self->begin()); return index; } int LastIndexOf(CTYPE const& value) { int index = -1; - std::vector::reverse_iterator rit = std::find($self->rbegin(), $self->rend(), value); + std::vector< CTYPE >::reverse_iterator rit = std::find($self->rbegin(), $self->rend(), value); if (rit != $self->rend()) index = (int)($self->rend() - 1 - rit); return index; } bool Remove(CTYPE const& value) { - std::vector::iterator it = std::find($self->begin(), $self->end(), value); + std::vector< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value); if (it != $self->end()) { $self->erase(it); return true; @@ -354,7 +354,7 @@ // Macros for std::vector class specializations/enhancements %define SWIG_STD_VECTOR_ENHANCED(CTYPE...) namespace std { - template<> class vector { + template<> class vector< CTYPE > { SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, %arg(CTYPE const&), %arg(CTYPE)) SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE) }; From 490f3a838bd15a8513fdc43a6ff5008facb61998 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 20:00:20 +0000 Subject: [PATCH 148/203] mv contributors from website to COPYRIGHT file git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12084 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- COPYRIGHT | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index 5296b3b48..40d09a1d6 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -58,8 +58,16 @@ Past SWIG developers and major contributors include: Past contributors include: James Michael DuPont, Clark McGrew, Dustin Mitchell, Ian Cooke, Catalin Dumitrescu, Baran - Kovuk, Oleg Tolmatcev, Tal Shalif, Lluis Padro, Chris Seatory, Igor Bely, Robin Dunn - (See CHANGES and CHANGES.current for a more complete list). + Kovuk, Oleg Tolmatcev, Tal Shalif, Lluis Padro, Chris Seatory, Igor Bely, Robin Dunn, + Edward Zimmermann, David Ascher, Dominique Dumont, Pier Giorgio Esposito, Hasan Baran Kovuk, + Klaus Wiederänders + (See CHANGES and CHANGES.current and the bug tracker for a more complete list). + +Past students: + Songyan Feng (Chicago). + Xinghua Shi (Chicago). + Jing Cao (Chicago). + Aquinas Hobor (Chicago). Historically, the following people contributed to early versions of SWIG. Peter Lomdahl, Brad Holian, Shujia Zhou, Niels Jensen, and Tim Germann @@ -74,3 +82,18 @@ Gary Holt have provided a great deal of input on improving SWIG's Perl5 implementation. Kevin Butler contributed the first Windows NT port. +Early bug reports and patches: +Adam Hupp, Arthur Smyles, Brad Clements, Brett Williams, Buck Hodges, +Burkhard Kloss, Chia-Liang Kao, Craig Files, Dennis Marsa, Dieter Baron, +Drake Diedrich, Fleur Diana Dragan, Gary Pennington, Geoffrey Hort, Gerald Williams, +Greg Anderson, Greg Kochanski, Greg Troxel, Henry Rowley, Irina Kotlova, +Israel Taller, James Bailey, Jim Fulton, Joel Reed, Jon Travis, +Junio Hamano, Justin Heyes-Jones, Karl Forner, Keith Davidson, +Krzysztof Kozminski, Larry Virden, Luke J Crook, Magnus Ljung, Marc Zonzon, +Mark Howson, Micahel Scharf, Michel Sanner, Mike Romberg, Mike Simons, +Mike Weiblen, Paul Brannan, Ram Bhamidipaty, Reinhard Fobbe, Rich Wales, +Richard Salz, Roy Lecates, Rudy Albachten, Scott Drummonds +Scott Michel, Shaun Lowry, Steve Galser, Tarn Weisner Burton, +Thomas Weidner, Tony Seward, Uwe Steinmann, Vadim Chugunov, Wyss Clemens, +Zhong Ren. + From 289cfef4b4766ff266f3b1bdda8ca3a952e5a047 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 20:04:06 +0000 Subject: [PATCH 149/203] 2.0.0 release date added git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12085 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 2 +- CHANGES.current | 4 ++-- Doc/Manual/Sections.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 1327eb124..d9a401553 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 2.0.0 (in progress) *** +*** ANNOUNCE: SWIG 2.0.0 (2 June 2010) *** http://www.swig.org diff --git a/CHANGES.current b/CHANGES.current index cde7a5e53..fe0eaf958 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,5 +1,5 @@ -Version 2.0.0 (in progress) -============================ +Version 2.0.0 (2 June 2010) +=========================== See CHANGES for changes in older releases. See RELEASENOTES for a summary of changes in each release. diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 2d795595c..5e36106b5 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

      SWIG-2.0 Documentation

      -Last update : SWIG-2.0.0 (in progress) +Last update : SWIG-2.0.0 (2 June 2010)

      Sections

      From 2ef2219fe5a027ac04c802b0f8f1c1193979d5cd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 20:29:48 +0000 Subject: [PATCH 150/203] add release date to README file git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12087 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 19036dc02..d9288cdae 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.0 (in progress) +Version: 2.0.0 (2 June 2010) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, From 2b325a6347fa47d619c907c92f2912fc06604dc8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 20:45:16 +0000 Subject: [PATCH 151/203] minor tweaks for release notes uploaded to SF git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12088 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 4 ++-- CHANGES.current | 4 ++-- Tools/mkrelease.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 721a49269..83888c235 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,7 @@ SWIG (Simplified Wrapper and Interface Generator) -See CHANGES.current for changes in the current version. -See RELEASENOTES for a summary of changes in each release. +See CHANGES.current file for changes in the current version. +See RELEASENOTES file for a summary of changes in each release. Version 1.3.40 (18 August 2009) =============================== diff --git a/CHANGES.current b/CHANGES.current index fe0eaf958..d463d1657 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,8 +1,8 @@ Version 2.0.0 (2 June 2010) =========================== -See CHANGES for changes in older releases. -See RELEASENOTES for a summary of changes in each release. +See CHANGES file for changes in older releases. +See RELEASENOTES file for a summary of changes in each release. 2010-06-02: wsfulton [C#] Fix SWIG_STD_VECTOR_ENHANCED macro used in std::vector to work with diff --git a/Tools/mkrelease.py b/Tools/mkrelease.py index 4b5e7e2e1..7d4c6599e 100755 --- a/Tools/mkrelease.py +++ b/Tools/mkrelease.py @@ -37,7 +37,7 @@ swigwin_dir_sf = username + ",swig@frs.sourceforge.net:/home/frs/project/s/sw/sw release_notes_file = "release-notes-" + version + ".txt" os.system("rm -f " + release_notes_file) -os.system("cat swig-" + version + "/README " + "swig-" + version + "/CHANGES.current > " + release_notes_file) +os.system("cat swig-" + version + "/README " + "swig-" + version + "/CHANGES.current " + "swig-" + version + "/RELEASENOTES " + "> " + release_notes_file) os.system("rsync --archive --verbose -P --times -e ssh " + "swig-" + version + ".tar.gz " + release_notes_file + " " + swig_dir_sf) and failed("") os.system("rsync --archive --verbose -P --times -e ssh " + "swigwin-" + version + ".zip " + swigwin_dir_sf) and failed("") From 88c4336ec2b4638eca32b570b1876a2f9bd7693b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 21:15:38 +0000 Subject: [PATCH 152/203] mention tagging is being done in mkrelease.py git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12090 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/mkrelease.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/mkrelease.py b/Tools/mkrelease.py index 7d4c6599e..fc404d43f 100755 --- a/Tools/mkrelease.py +++ b/Tools/mkrelease.py @@ -42,6 +42,7 @@ os.system("cat swig-" + version + "/README " + "swig-" + version + "/CHANGES.cur os.system("rsync --archive --verbose -P --times -e ssh " + "swig-" + version + ".tar.gz " + release_notes_file + " " + swig_dir_sf) and failed("") os.system("rsync --archive --verbose -P --times -e ssh " + "swigwin-" + version + ".zip " + swigwin_dir_sf) and failed("") +print "Tagging release" os.system("svn copy -m \"rel-" + version + "\" https://swig.svn.sourceforge.net/svnroot/swig/trunk https://swig.svn.sourceforge.net/svnroot/swig/tags/rel-" + version + "/") print "Finished" From 2ebbdfc47d653535dd636967f5cabbd521903cd2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 22:38:41 +0000 Subject: [PATCH 153/203] 1.3 => 2.0 for documentation headings git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12094 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Sections.html | 2 +- Doc/Manual/Typemaps.html | 3 ++- Doc/Manual/index.html | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 5e36106b5..e957318e8 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -1,7 +1,7 @@ -SWIG-1.3 Documentation +SWIG-2.0 Documentation

      SWIG-2.0 Documentation

      diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 5b97c9bae..cacfd5f2f 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -1672,7 +1672,8 @@ example.h:3: Searching for a suitable 'in' typemap for: Row4 rows[10]

      showing that the best default match supplied by SWIG is the SWIGTYPE [] typemap. -As the example shows, the successful match displays the used typemap source including typemap method, type and optional name in one of these simplified formats:

      +As the example shows, the successful match displays the used typemap source including typemap method, type and optional name in one of these simplified formats: +

      • Using: %typemap(method) type name diff --git a/Doc/Manual/index.html b/Doc/Manual/index.html index 8560a9199..30c69578f 100644 --- a/Doc/Manual/index.html +++ b/Doc/Manual/index.html @@ -1,10 +1,10 @@ -SWIG-1.3 Documentation +SWIG-2.0 Documentation -

        SWIG-1.3 Development Documentation

        +

        SWIG-2.0 Documentation

        The SWIG documentation is available in one of the following formats.
          From 293426b02a05c3a58ce02c74dc4018fe88b6c9f6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Jun 2010 06:34:15 +0000 Subject: [PATCH 154/203] Bump version to 2.0.1 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12096 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 8 +- CHANGES | 666 +++++++++++++++++++++++++++++++++++++- CHANGES.current | 667 +-------------------------------------- Doc/Manual/Sections.html | 2 +- README | 2 +- RELEASENOTES | 8 +- configure.in | 2 +- 7 files changed, 681 insertions(+), 674 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index d9a401553..ad3e8f8d6 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.0 (2 June 2010) *** +*** ANNOUNCE: SWIG 2.0.1 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-2.0.0, the latest SWIG release. +We're pleased to announce SWIG-2.0.1, 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-2.0.0.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.1.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.0.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.1.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 83888c235..bd65df32b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,8 +1,672 @@ SWIG (Simplified Wrapper and Interface Generator) -See CHANGES.current file for changes in the current version. +See the CHANGES.current file for changes in the current version. +See the RELEASENOTES file for a summary of changes in each release. + +Version 2.0.0 (2 June 2010) +=========================== + +See CHANGES file for changes in older releases. See RELEASENOTES file for a summary of changes in each release. +2010-06-02: wsfulton + [C#] Fix SWIG_STD_VECTOR_ENHANCED macro used in std::vector to work with + types containing commas, for example: + + SWIG_STD_VECTOR_ENHANCED(std::pair< double, std::string >) + +2010-06-01: wsfulton + Add in std_shared_ptr.i for wrapping std::shared_ptr. Requires the %shared_ptr + macro like in the boost_shared_ptr.i library. std::tr1::shared_ptr can also be + wrapped if the following macro is defined: + + #define SWIG_SHARED_PTR_SUBNAMESPACE tr1 + %include + + shared_ptr is also documented in Library.html now. + +2010-05-27: wsfulton + Add the ability for $typemap special variable macros to call other $typemap + special variable macros, for example: + + %typemap(cstype) CC "CC" + %typemap(cstype) BB "$typemap(cstype, CC)" + %typemap(cstype) AA "$typemap(cstype, BB)" + void hah(AA aa); + + This also fixes C# std::vector containers of shared_ptr and %shared_ptr. + + Also added diagnostics for $typemap with -debug-tmsearch, for example, the + above displays additional diagnostic lines starting "Containing: ": + + example.i:34: Searching for a suitable 'cstype' typemap for: AA aa + Looking for: AA aa + Looking for: AA + Using: %typemap(cstype) AA + Containing: $typemap(cstype, BB) + example.i:31: Searching for a suitable 'cstype' typemap for: BB + Looking for: BB + Using: %typemap(cstype) BB + Containing: $typemap(cstype, CC) + example.i:29: Searching for a suitable 'cstype' typemap for: CC + Looking for: CC + Using: %typemap(cstype) CC + +2010-05-26: olly + Fix %attribute2ref not to produce a syntax error if the last + argument (AccessorMethod) is omitted. Patch from David Piepgras + in SF#2235756. + +2010-05-26: olly + [PHP] When using %throws or %catches, SWIG-generated PHP5 wrappers + now throw PHP Exception objects instead of giving a PHP error of + type E_ERROR. + + This change shouldn't cause incompatibility issues, since you can't + set an error handler for E_ERROR, so previously PHP would just exit + which also happens for unhandled exceptions. The benefit is you can + now catch them if you want to. + + Fixes SF#2545578 and SF#2955522. + +2010-05-25: olly + [PHP] Add missing directorin typemap for const std::string &. + Fixes SF#3006404 reported by t-Legiaw. + +2010-05-23: wsfulton + [C#] Fix #2957375 - SWIGStringHelper and SWIGExceptionHelper not always being + initialized before use in .NET 4 as the classes were not marked beforefieldinit. + A static constructor has been added to the intermediary class like this: + + %pragma(csharp) imclasscode=%{ + static $imclassname() { + } + %} + + If you had added your own custom static constructor to the intermediary class in + the same way as above, you will have to modify your approach to use static variable + initialization or define SWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR - See csharphead.swg. + + *** POTENTIAL INCOMPATIBILITY *** + +2010-05-23: wsfulton + Fix #2408232. Improve shared_ptr and intrusive_ptr wrappers for classes in an + inheritance hierarchy. No special treatment is needed for derived classes. + The proxy class also no longer needs to be specified, it is automatically + deduced. The following macros are deprecated: + SWIG_SHARED_PTR(PROXYCLASS, TYPE) + SWIG_SHARED_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE) + and have been replaced by + %shared_ptr(TYPE) + Similarly for intrusive_ptr wrappers, the following macro is deprecated: + SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE) + SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE) + and have been replaced by + %intrusive_ptr(TYPE) + +2010-05-21: olly + [PHP] Stop generating a bogus line of code in certain constructors. + This was mostly harmless, but caused a PHP notice to be issued, if + enabled (SF#2985684). + +2010-05-18: wsfulton + [Java] Fix member pointers on 64 bit platforms. + +2010-05-14: wsfulton + Fix wrapping of C++ enum boolean values reported by Torsten Landschoff: + typedef enum { PLAY = true, STOP = false } play_state; + +2010-05-14: olly + [PHP] Fix wrapping of global variables which was producing + uncompilable code in some cases. + +2010-05-12: drjoe + [R] Add two more changes from Wil Nolan. Get garbage + collection to work. Implement newfree + +2010-05-09: drjoe + Fix bug reported by Wil Nolan change creation of string so + that R 2.7.0+ can use char hashes + +2010-05-07: wsfulton + Apply patch #2955146 from Sergey Satskiy to fix expressions containing divide by + operator in constructor initialization lists. + +2010-05-05: wsfulton + [R] Memory leak fix handling const std::string & inputs, reported by Will Nolan. + +2010-05-01: wsfulton + Typemap matching enhancement for non-default typemaps. Previously all + qualifiers were stripped in one step, now they are stripped one at a time + starting with the left most qualifier. For example, int const*const + is first stripped to int *const then int *. + + *** POTENTIAL INCOMPATIBILITY *** + +2010-04-25: bhy + [Python] Fix #2985655 - broken constructor renaming. + +2010-04-14: wsfulton + Typemap fragments are now official and documented in Typemaps.html. + +2010-04-09: wsfulton + [Ruby] Fix #2048064 and #2408020. + Apply Ubuntu patch to fix Ruby and std::vector wrappers with -minherit. + https://bugs.launchpad.net/ubuntu/+source/swig1.3/+bug/522874 + +2010-04-09: wsfulton + [Mzscheme] Apply Ubuntu patch to fix std::map wrappers: + https://bugs.launchpad.net/ubuntu/+source/swig1.3/+bug/203876 + +2010-04-09: wsfulton + [Python] Apply patch #2952374 - fix directors and the -nortti option. + +2010-04-09: wsfulton + [Lua] Fix #2887254 and #2946032 - SWIG_Lua_typename using wrong stack index. + +2010-04-03: wsfulton + [Python] Fix exceptions being thrown with the -threads option based on patch from Arto Vuori. + Fixes bug #2818499. + +2010-04-03: wsfulton + Fix Makefile targets: distclean and maintainer-clean + +2010-04-02: wsfulton + [Lua] Fix char pointers, wchar_t pointers and char arrays so that nil can be passed as a + valid value. Bug reported by Gedalia Pasternak. + +2010-04-01: wsfulton + Numerous subtle typemap matching rule fixes when using the default type. The typemap + matching rules are to take a type and find the best default typemap (SWIGTYPE, SWIGTYPE* etc), + then look for the next best match by reducing the chosen default type. The type deduction + now follows C++ class template partial specialization matching rules. + + Below are the set of changes made showing the default type deduction + along with the old reduced type and the new version of the reduced type: + + SWIGTYPE const &[ANY] + new: SWIGTYPE const &[] + old: SWIGTYPE (&)[ANY] + + SWIGTYPE *const [ANY] + new: SWIGTYPE const [ANY] + old: SWIGTYPE *[ANY] + + SWIGTYPE const *const [ANY] + new: SWIGTYPE *const [ANY] + old: SWIGTYPE const *[ANY] + + SWIGTYPE const *const & + new: SWIGTYPE *const & + old: SWIGTYPE const *& + + SWIGTYPE *const * + new: SWIGTYPE const * + old: SWIGTYPE ** + + SWIGTYPE *const & + new: SWIGTYPE const & + old: SWIGTYPE *& + + Additionally, a const SWIGTYPE lookup is used now for any constant type. Some examples, where + T is some reduced type, eg int, struct Foo: + + T const + new: SWIGTYPE const + old: SWIGTYPE + + T *const + new: SWIGTYPE *const + old: SWIGTYPE * + + T const[] + new: SWIGTYPE const[] + old: SWIGTYPE[] + + enum T const + new: enum SWIGTYPE const + old: enum SWIGTYPE + + T (*const )[] + new: SWIGTYPE (*const )[] + old: SWIGTYPE (*)[] + + Reminder: the typemap matching rules can now be seen for any types being wrapped by using + either the -debug-tmsearch or -debug-tmused options. + + In practice this leads to some subtle matching rule changes and the majority of users + won't notice any changes, except in the prime area of motivation for this change: Improve + STL containers of const pointers and passing const pointers by reference. This is fixed + because many of the STL containers use a type 'T const&' as parameters and when T is + a const pointer, for example, 'K const*', then the full type is 'K const*const&'. This + means that the 'SWIGTYPE *const&' typemaps now match when T is either a non-const or + const pointer. Furthermore, some target languages incorrectly had 'SWIGTYPE *&' typemaps + when these should have been 'SWIGTYPE *const&'. These have been corrected (Java, C#, Lua, PHP). + + *** POTENTIAL INCOMPATIBILITY *** + +2010-03-13: wsfulton + [Java] Some very old deprecated pragma warnings are now errors. + +2010-03-13: wsfulton + Improve handling of file names and directories containing double/multiple path separators. + +2010-03-10: mutandiz (Mikel Bancroft) + [allegrocl] Use fully qualified symbol name of cl::identity in emit_defun(). + +2010-03-06: wsfulton + [Java] The intermediary JNI class modifiers are now public by default meaning these + intermediary low level functions are now accessible by default from outside any package + used. The proxy class pointer constructor and getCPtr() methods are also now public. + These are needed in order for the nspace option to work without any other mods. + The previous default of protected access can be restored using: + + SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE) + %pragma(java) jniclassclassmodifiers = "class" + +2010-03-06: wsfulton + [C#] Added the nspace feature for C#. Documentation for the nspace feature is now available. + +2010-03-04: wsfulton + Added the nspace feature. This adds some improved namespace support. Currently only Java + is supported for target languages, where C++ namespaces are automatically translated into + Java packages. The feature only applies to classes,struct,unions and enums declared within + a namespace. Methods and variables declared in namespaces still effectively have their + namespaces flattened. Example usage: + + %feature(nspace) Outer::Inner1::Color; + %feature(nspace) Outer::Inner2::Color; + + namespace Outer { + namespace Inner1 { + struct Color { + ... + }; + } + namespace Inner2 { + struct Color { + ... + }; + } + } + + For Java, the -package option is also required when using the nspace feature. Say + we use -package com.myco, the two classes can then be accessed as follows from Java: + + com.myco.Outer.Inner1.Color and com.myco.Outer.Inner2.Color. + +2010-02-27: wsfulton + [Python] Remove -dirvtable from the optimizations included by -O as it this option + currently leads to memory leaks as reported by Johan Blake. + +2010-02-27: wsfulton + License code changes: SWIG Source is GPL-v3 and library code license is now clearer + and is provided under a very permissive license. See http://www.swig.org/legal.html. + +2010-02-13: wsfulton + [Ruby] A few fixes for compiling under ruby-1.9.x including patch from 'Nibble'. + +2010-02-13: wsfulton + [Ruby] Apply patch from Patrick Bennett to fix RARRAY_LEN and RARRAY_PTR usage for Ruby 1.9.x + used in various STL wrappers. + +2010-02-13: wsfulton + [C#, Java] Fix incorrect multiply defined symbol name error when an enum item + and class name have the same name, as reported by Nathan Krieger. Example: + + class Vector {}; + namespace Text { + enum Preference { Vector }; + } + + This also fixes other incorrect corner case target language symbol name clashes. + +2010-02-11: wsfulton + Add the -debug-lsymbols option for displaying the target language layer symbols. + +2010-02-09: wsfulton + Fix -MM and -MMD options on Windows. They were not omitting files in the SWIG library as + they should be. + +2010-02-08: wsfulton + Fix #1807329 - When Makefile dependencies are being generated using the -M family of options + on Windows, the file paths have been corrected to use single backslashes rather than double + backslashes as path separators. + +2010-02-06: wsfulton + Fix #2918902 - language specific files not being generated in correct directory on + Windows when using forward slashes for -o, for example: + swig -python -c++ -o subdirectory/theinterface_wrap.cpp subdirectory/theinterface.i + +2010-02-05: wsfulton + Fix #2894405 - assertion when using -xmlout. + +2010-01-28: wsfulton + Fix typemap matching bug when a templated type has a typemap both specialized and not + specialized. For example: + + template struct XX { ... }; + %typemap(in) const XX & "..." + %typemap(in) const XX< int > & "..." + + resulted in the 2nd typemap being applied for all T in XX< T >. + +2010-01-22: wsfulton + Fix #2933129 - typemaps not being found when the unary scope operator (::) is used to denote + global scope, the typemap is now used in situations like this: + + struct X {}; + %typemap(in) const X & "..." + void m(const ::X &); + + and this: + + struct X {}; + %typemap(in) const ::X & "..." + void m(const X &); + +2010-01-20: wsfulton + Fix some unary scope operator (::) denoting global scope problems in the types generated + into the C++ layer. Previously the unary scope operator was dropped in the generated code + if the type had any sort of qualifier, for example when using pointers, references, like + ::foo*, ::foo&, bar< ::foo* >. + +2010-01-13: olly + [PHP] Add datetime to the list of PHP predefined classes (patch + from David Fletcher in SF#2931042). + +2010-01-11: wsfulton + Slight change to warning, error and diagnostic reporting. The warning number is no + longer shown within brackets. This is to help default parsing of warning messages by + other tools, vim on Unix in particular. + + Example original display using -Fstandard: + example.i:20: Warning(401): Nothing known about base class 'B'. Ignored. + New display: + example.i:20: Warning 401: Nothing known about base class 'B'. Ignored. + + Also subtle fix to -Fmicrosoft format adding in missing space. Example original display: + example.i(20): Warning(401): Nothing known about base class 'Base'. Ignored. + New display: + example.i(20) : Warning 401: Nothing known about base class 'Base'. Ignored. + +2010-01-10: wsfulton + Fix a few inconsistencies in reporting of file/line numberings including modifying + the overload warnings 509, 512, 516, 474, 475 to now be two line warnings. + +2010-01-10: wsfulton + Modify -debug-tags output to use standard file name/line reporting so that editors + can easily navigate to the appropriate lines. + Was typically: + . top . include . include (/usr/share/swig/temp/trunk/Lib/swig.swg:312) + . top . include . include . include (/usr/share/swig/temp/trunk/Lib/swigwarnings.swg:39) + now: + /usr/share/swig/temp/trunk/Lib/swig.swg:312: . top . include . include + /usr/share/swig/temp/trunk/Lib/swigwarnings.swg:39: . top . include . include . include + +2010-01-03: wsfulton + Fix missing file/line numbers for typemap warnings and in output from the + -debug-tmsearch/-debug-tmused options. + +2010-01-03: wsfulton + Add typemaps used debugging option (-debug-tmused). When used each line displays + the typemap used for each type for which code is being generated including the file + and line number related to the type. This is effectively a condensed form of the + -debug-tmsearch option. Documented in Typemaps.html. + +2009-12-23: wsfulton + Fix for %javaexception and directors so that all the appropriate throws clauses + are generated. Problem reported by Peter Greenwood. + +2009-12-20: wsfulton + Add -debug-tmsearch option for debugging the typemap pattern matching rules. + Documented in Typemaps.html. + +2009-12-12: wsfulton + [Octave] Remove the -api option and use the new OCTAVE_API_VERSION_NUMBER + macro provided in the octave headers for determining the api version instead. + +2009-12-04: olly + [Ruby] Improve support for Ruby 1.9 under GCC. Addresses part of + SF#2859614. + +2009-12-04: olly + Fix handling of modulo operator (%) in constant expressions + (SF#2818562). + +2009-12-04: olly + [PHP] "empty" is a reserved word in PHP, so rename empty() method + on STL classes to "is_empty()" (previously this was automatically + renamed to "c_empty()"). + *** POTENTIAL INCOMPATIBILITY *** + +2009-12-03: olly + [PHP] Add typemaps for long long and unsigned long long, and for + pointer to method. + +2009-12-02: olly + [PHP] Fix warning and rename of reserved class name to be case + insensitive. + +2009-12-01: wsfulton + Revert support for %extend and memberin typemaps added in swig-1.3.39. The + memberin typemaps are ignored again for member variables within a %extend block. + Documentation inconsistency reported by Torsten Landschoff. + +2009-11-29: wsfulton + [Java, C#] Fix generated quoting when using %javaconst(1)/%csconst(1) for + static const char member variables. + + %javaconst(1) A; + %csconst(1) A; + struct X { + static const char A = 'A'; + }; + +2009-11-26: wsfulton + [Java, C#] Fix %javaconst(1)/%csconst(1) for static const member variables to + use the actual constant value if it is specified, rather than the C++ code to + access the member. + + %javaconst(1) EN; + %csconst(1) EN; + struct X { + static const int EN = 2; + }; + +2009-11-23: wsfulton + C++ nested typedef classes can now be handled too, for example: + struct Outer { + typedef Foo { } FooTypedef1, FooTypedef2; + }; + +2009-11-18: wsfulton + The wrappers for C nested structs are now generated in the same order as declared + in the parsed code. + +2009-11-18: wsfulton + Fix #491476 - multiple declarations of nested structs, for example: + struct Outer { + struct { + int val; + } inner1, inner2, *inner3, inner4[1]; + } outer; + +2009-11-17: wsfulton + Fix parsing of enum declaration and initialization, for example: + + enum ABC { + a, + b, + c + } A = a, *pC = &C, array[3] = {a, b, c}; + +2009-11-17: wsfulton + Fix parsing of struct declaration and initialization, for example: + + struct S { + int x; + } instance = { 10 }; + +2009-11-15: wsfulton + Fix #1960977 - Syntax error parsing derived nested class declaration and member + variable instance. + +2009-11-14: wsfulton + 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 + is generated. + +2009-11-13: olly + [php] Fix place where class prefix (as specified with -prefix) + 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 + template class is now treated like a normal nested classes, that is, as an opaque type + unless the nestedworkaround feature is used. + +2009-11-12: wsfulton + Replace SWIGWARN_PARSE_NESTED_CLASS with SWIGWARN_PARSE_NAMED_NESTED_CLASS and + SWIGWARN_PARSE_UNNAMED_NESTED_CLASS for named and unnamed nested classes respectively. + + Named nested class ignored warnings can now be suppressed by name using %warnfilter, eg: + + %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::Inner; + + but clearly unnamed nested classes cannot and the global suppression is still required, eg: + + #pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS + +2009-11-11: wsfulton + Added the nestedworkaround feature as a way to use the full functionality of a nested class + (C++ mode only). It removes the nested class from SWIG's type information so it is as if SWIG + had never parsed the nested class. The documented nested class workarounds using a global + fake class stopped working when SWIG treated the nested class as an opaque pointer, and + this feature reverts this behaviour. The documentation has been updated with details of how + to use and implement it, see the "Nested classes" section in SWIGPlus.html. + +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 + 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 + as an opaque type by default, resulting in generated code that should always compile. + + *** POTENTIAL INCOMPATIBILITY *** + +2009-11-09: drjoe + Fix R for -fcompact and add std_map.i + +2009-11-08: wsfulton + Fix inconsistency for nested structs/unions/classes. Uncompileable 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: + + struct Outer { + struct InnerStruct { int x; }; + InnerStruct* getInnerStruct(); + }; + +2009-11-08: wsfulton + 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 + 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. + +2009-11-07: wsfulton + Add new debug options: + -debug-symtabs - Display symbol tables information + -debug-symbols - Display target language symbols in the symbol tables + -debug-csymbols - Display C symbols in the symbol tables + +2009-11-03: wsfulton + Fix some usage of unary scope operator (::) denoting global scope, for example: + + namespace AA { /* ... */ } + using namespace ::AA; + + and bug #1816802 - SwigValueWrapper should be used: + + struct CC { + CC(int); // no default constructor + }; + ::CC x(); + + and in template parameter specializations: + + struct S {}; + template struct X { void a() {}; }; + template <> struct X { void b() {}; }; + %template(MyTConcrete) X< ::S >; + + plus probably some other corner case usage of ::. + +2009-11-02: olly + [Python] Fix potential memory leak in initialisation code for the + generated module. + +2009-10-23: wsfulton + Fix seg fault when using a named nested template instantiation using %template(name) + within a class. A warning that these are not supported is now issued plus processing + continues as if no name was given. + +2009-10-20: wsfulton + [Python] Fix std::vector. This would previously compile, but not run correctly. + +2009-10-20: wsfulton + Fixed previously fairly poor template partial specialization and explicit + specialization support. Numerous bugs in this area have been fixed including: + + - Template argument deduction implemented for template type arguments, eg this now + works: + template class X {}; + template class X {}; + %template(X1) X; // Chooses T * specialization + + and more complex cases with multiple parameters and a mix of template argument + deduction and explicitly specialised parameters, eg: + template struct TwoParm { void a() {} }; + template struct TwoParm { void e() {} }; + %template(E) TwoParm; + + Note that the primary template must now be in scope, like in C++, when + an explicit or partial specialization is instantiated with %template. + + *** POTENTIAL INCOMPATIBILITY *** + +2009-09-14: wsfulton + [C#] Add %csattributes for adding C# attributes to enum values, see docs for example. + +2009-09-11: wsfulton + Fix memmove regression in cdata.i as reported by Adriaan Renting. + +2009-09-07: wsfulton + Fix constant expressions containing <= or >=. + +2009-09-02: wsfulton + The following operators in constant expressions now result in type bool for C++ + wrappers and remain as type int for C wrappers, as per each standard: + + && || == != < > <= >= (Actually the last 4 are still broken). For example: + + #define A 10 + #define B 10 + #define A_EQ_B A == B // now wrapped as type bool for C++ + #define A_AND_B A && B // now wrapped as type bool for C++ + +2009-09-02: wsfulton + Fix #2845746. true and false are now recognised keywords (only when wrapping C++). + Constants such as the following are now wrapped (as type bool): + #define FOO true + #define BAR FOO && false + Version 1.3.40 (18 August 2009) =============================== diff --git a/CHANGES.current b/CHANGES.current index d463d1657..9982286c2 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,664 +1,7 @@ -Version 2.0.0 (2 June 2010) +This file contains 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 2.0.1 (in progress) =========================== -See CHANGES file for changes in older releases. -See RELEASENOTES file for a summary of changes in each release. - -2010-06-02: wsfulton - [C#] Fix SWIG_STD_VECTOR_ENHANCED macro used in std::vector to work with - types containing commas, for example: - - SWIG_STD_VECTOR_ENHANCED(std::pair< double, std::string >) - -2010-06-01: wsfulton - Add in std_shared_ptr.i for wrapping std::shared_ptr. Requires the %shared_ptr - macro like in the boost_shared_ptr.i library. std::tr1::shared_ptr can also be - wrapped if the following macro is defined: - - #define SWIG_SHARED_PTR_SUBNAMESPACE tr1 - %include - - shared_ptr is also documented in Library.html now. - -2010-05-27: wsfulton - Add the ability for $typemap special variable macros to call other $typemap - special variable macros, for example: - - %typemap(cstype) CC "CC" - %typemap(cstype) BB "$typemap(cstype, CC)" - %typemap(cstype) AA "$typemap(cstype, BB)" - void hah(AA aa); - - This also fixes C# std::vector containers of shared_ptr and %shared_ptr. - - Also added diagnostics for $typemap with -debug-tmsearch, for example, the - above displays additional diagnostic lines starting "Containing: ": - - example.i:34: Searching for a suitable 'cstype' typemap for: AA aa - Looking for: AA aa - Looking for: AA - Using: %typemap(cstype) AA - Containing: $typemap(cstype, BB) - example.i:31: Searching for a suitable 'cstype' typemap for: BB - Looking for: BB - Using: %typemap(cstype) BB - Containing: $typemap(cstype, CC) - example.i:29: Searching for a suitable 'cstype' typemap for: CC - Looking for: CC - Using: %typemap(cstype) CC - -2010-05-26: olly - Fix %attribute2ref not to produce a syntax error if the last - argument (AccessorMethod) is omitted. Patch from David Piepgras - in SF#2235756. - -2010-05-26: olly - [PHP] When using %throws or %catches, SWIG-generated PHP5 wrappers - now throw PHP Exception objects instead of giving a PHP error of - type E_ERROR. - - This change shouldn't cause incompatibility issues, since you can't - set an error handler for E_ERROR, so previously PHP would just exit - which also happens for unhandled exceptions. The benefit is you can - now catch them if you want to. - - Fixes SF#2545578 and SF#2955522. - -2010-05-25: olly - [PHP] Add missing directorin typemap for const std::string &. - Fixes SF#3006404 reported by t-Legiaw. - -2010-05-23: wsfulton - [C#] Fix #2957375 - SWIGStringHelper and SWIGExceptionHelper not always being - initialized before use in .NET 4 as the classes were not marked beforefieldinit. - A static constructor has been added to the intermediary class like this: - - %pragma(csharp) imclasscode=%{ - static $imclassname() { - } - %} - - If you had added your own custom static constructor to the intermediary class in - the same way as above, you will have to modify your approach to use static variable - initialization or define SWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR - See csharphead.swg. - - *** POTENTIAL INCOMPATIBILITY *** - -2010-05-23: wsfulton - Fix #2408232. Improve shared_ptr and intrusive_ptr wrappers for classes in an - inheritance hierarchy. No special treatment is needed for derived classes. - The proxy class also no longer needs to be specified, it is automatically - deduced. The following macros are deprecated: - SWIG_SHARED_PTR(PROXYCLASS, TYPE) - SWIG_SHARED_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE) - and have been replaced by - %shared_ptr(TYPE) - Similarly for intrusive_ptr wrappers, the following macro is deprecated: - SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE) - SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE) - and have been replaced by - %intrusive_ptr(TYPE) - -2010-05-21: olly - [PHP] Stop generating a bogus line of code in certain constructors. - This was mostly harmless, but caused a PHP notice to be issued, if - enabled (SF#2985684). - -2010-05-18: wsfulton - [Java] Fix member pointers on 64 bit platforms. - -2010-05-14: wsfulton - Fix wrapping of C++ enum boolean values reported by Torsten Landschoff: - typedef enum { PLAY = true, STOP = false } play_state; - -2010-05-14: olly - [PHP] Fix wrapping of global variables which was producing - uncompilable code in some cases. - -2010-05-12: drjoe - [R] Add two more changes from Wil Nolan. Get garbage - collection to work. Implement newfree - -2010-05-09: drjoe - Fix bug reported by Wil Nolan change creation of string so - that R 2.7.0+ can use char hashes - -2010-05-07: wsfulton - Apply patch #2955146 from Sergey Satskiy to fix expressions containing divide by - operator in constructor initialization lists. - -2010-05-05: wsfulton - [R] Memory leak fix handling const std::string & inputs, reported by Will Nolan. - -2010-05-01: wsfulton - Typemap matching enhancement for non-default typemaps. Previously all - qualifiers were stripped in one step, now they are stripped one at a time - starting with the left most qualifier. For example, int const*const - is first stripped to int *const then int *. - - *** POTENTIAL INCOMPATIBILITY *** - -2010-04-25: bhy - [Python] Fix #2985655 - broken constructor renaming. - -2010-04-14: wsfulton - Typemap fragments are now official and documented in Typemaps.html. - -2010-04-09: wsfulton - [Ruby] Fix #2048064 and #2408020. - Apply Ubuntu patch to fix Ruby and std::vector wrappers with -minherit. - https://bugs.launchpad.net/ubuntu/+source/swig1.3/+bug/522874 - -2010-04-09: wsfulton - [Mzscheme] Apply Ubuntu patch to fix std::map wrappers: - https://bugs.launchpad.net/ubuntu/+source/swig1.3/+bug/203876 - -2010-04-09: wsfulton - [Python] Apply patch #2952374 - fix directors and the -nortti option. - -2010-04-09: wsfulton - [Lua] Fix #2887254 and #2946032 - SWIG_Lua_typename using wrong stack index. - -2010-04-03: wsfulton - [Python] Fix exceptions being thrown with the -threads option based on patch from Arto Vuori. - Fixes bug #2818499. - -2010-04-03: wsfulton - Fix Makefile targets: distclean and maintainer-clean - -2010-04-02: wsfulton - [Lua] Fix char pointers, wchar_t pointers and char arrays so that nil can be passed as a - valid value. Bug reported by Gedalia Pasternak. - -2010-04-01: wsfulton - Numerous subtle typemap matching rule fixes when using the default type. The typemap - matching rules are to take a type and find the best default typemap (SWIGTYPE, SWIGTYPE* etc), - then look for the next best match by reducing the chosen default type. The type deduction - now follows C++ class template partial specialization matching rules. - - Below are the set of changes made showing the default type deduction - along with the old reduced type and the new version of the reduced type: - - SWIGTYPE const &[ANY] - new: SWIGTYPE const &[] - old: SWIGTYPE (&)[ANY] - - SWIGTYPE *const [ANY] - new: SWIGTYPE const [ANY] - old: SWIGTYPE *[ANY] - - SWIGTYPE const *const [ANY] - new: SWIGTYPE *const [ANY] - old: SWIGTYPE const *[ANY] - - SWIGTYPE const *const & - new: SWIGTYPE *const & - old: SWIGTYPE const *& - - SWIGTYPE *const * - new: SWIGTYPE const * - old: SWIGTYPE ** - - SWIGTYPE *const & - new: SWIGTYPE const & - old: SWIGTYPE *& - - Additionally, a const SWIGTYPE lookup is used now for any constant type. Some examples, where - T is some reduced type, eg int, struct Foo: - - T const - new: SWIGTYPE const - old: SWIGTYPE - - T *const - new: SWIGTYPE *const - old: SWIGTYPE * - - T const[] - new: SWIGTYPE const[] - old: SWIGTYPE[] - - enum T const - new: enum SWIGTYPE const - old: enum SWIGTYPE - - T (*const )[] - new: SWIGTYPE (*const )[] - old: SWIGTYPE (*)[] - - Reminder: the typemap matching rules can now be seen for any types being wrapped by using - either the -debug-tmsearch or -debug-tmused options. - - In practice this leads to some subtle matching rule changes and the majority of users - won't notice any changes, except in the prime area of motivation for this change: Improve - STL containers of const pointers and passing const pointers by reference. This is fixed - because many of the STL containers use a type 'T const&' as parameters and when T is - a const pointer, for example, 'K const*', then the full type is 'K const*const&'. This - means that the 'SWIGTYPE *const&' typemaps now match when T is either a non-const or - const pointer. Furthermore, some target languages incorrectly had 'SWIGTYPE *&' typemaps - when these should have been 'SWIGTYPE *const&'. These have been corrected (Java, C#, Lua, PHP). - - *** POTENTIAL INCOMPATIBILITY *** - -2010-03-13: wsfulton - [Java] Some very old deprecated pragma warnings are now errors. - -2010-03-13: wsfulton - Improve handling of file names and directories containing double/multiple path separators. - -2010-03-10: mutandiz (Mikel Bancroft) - [allegrocl] Use fully qualified symbol name of cl::identity in emit_defun(). - -2010-03-06: wsfulton - [Java] The intermediary JNI class modifiers are now public by default meaning these - intermediary low level functions are now accessible by default from outside any package - used. The proxy class pointer constructor and getCPtr() methods are also now public. - These are needed in order for the nspace option to work without any other mods. - The previous default of protected access can be restored using: - - SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE) - %pragma(java) jniclassclassmodifiers = "class" - -2010-03-06: wsfulton - [C#] Added the nspace feature for C#. Documentation for the nspace feature is now available. - -2010-03-04: wsfulton - Added the nspace feature. This adds some improved namespace support. Currently only Java - is supported for target languages, where C++ namespaces are automatically translated into - Java packages. The feature only applies to classes,struct,unions and enums declared within - a namespace. Methods and variables declared in namespaces still effectively have their - namespaces flattened. Example usage: - - %feature(nspace) Outer::Inner1::Color; - %feature(nspace) Outer::Inner2::Color; - - namespace Outer { - namespace Inner1 { - struct Color { - ... - }; - } - namespace Inner2 { - struct Color { - ... - }; - } - } - - For Java, the -package option is also required when using the nspace feature. Say - we use -package com.myco, the two classes can then be accessed as follows from Java: - - com.myco.Outer.Inner1.Color and com.myco.Outer.Inner2.Color. - -2010-02-27: wsfulton - [Python] Remove -dirvtable from the optimizations included by -O as it this option - currently leads to memory leaks as reported by Johan Blake. - -2010-02-27: wsfulton - License code changes: SWIG Source is GPL-v3 and library code license is now clearer - and is provided under a very permissive license. See http://www.swig.org/legal.html. - -2010-02-13: wsfulton - [Ruby] A few fixes for compiling under ruby-1.9.x including patch from 'Nibble'. - -2010-02-13: wsfulton - [Ruby] Apply patch from Patrick Bennett to fix RARRAY_LEN and RARRAY_PTR usage for Ruby 1.9.x - used in various STL wrappers. - -2010-02-13: wsfulton - [C#, Java] Fix incorrect multiply defined symbol name error when an enum item - and class name have the same name, as reported by Nathan Krieger. Example: - - class Vector {}; - namespace Text { - enum Preference { Vector }; - } - - This also fixes other incorrect corner case target language symbol name clashes. - -2010-02-11: wsfulton - Add the -debug-lsymbols option for displaying the target language layer symbols. - -2010-02-09: wsfulton - Fix -MM and -MMD options on Windows. They were not omitting files in the SWIG library as - they should be. - -2010-02-08: wsfulton - Fix #1807329 - When Makefile dependencies are being generated using the -M family of options - on Windows, the file paths have been corrected to use single backslashes rather than double - backslashes as path separators. - -2010-02-06: wsfulton - Fix #2918902 - language specific files not being generated in correct directory on - Windows when using forward slashes for -o, for example: - swig -python -c++ -o subdirectory/theinterface_wrap.cpp subdirectory/theinterface.i - -2010-02-05: wsfulton - Fix #2894405 - assertion when using -xmlout. - -2010-01-28: wsfulton - Fix typemap matching bug when a templated type has a typemap both specialized and not - specialized. For example: - - template struct XX { ... }; - %typemap(in) const XX & "..." - %typemap(in) const XX< int > & "..." - - resulted in the 2nd typemap being applied for all T in XX< T >. - -2010-01-22: wsfulton - Fix #2933129 - typemaps not being found when the unary scope operator (::) is used to denote - global scope, the typemap is now used in situations like this: - - struct X {}; - %typemap(in) const X & "..." - void m(const ::X &); - - and this: - - struct X {}; - %typemap(in) const ::X & "..." - void m(const X &); - -2010-01-20: wsfulton - Fix some unary scope operator (::) denoting global scope problems in the types generated - into the C++ layer. Previously the unary scope operator was dropped in the generated code - if the type had any sort of qualifier, for example when using pointers, references, like - ::foo*, ::foo&, bar< ::foo* >. - -2010-01-13: olly - [PHP] Add datetime to the list of PHP predefined classes (patch - from David Fletcher in SF#2931042). - -2010-01-11: wsfulton - Slight change to warning, error and diagnostic reporting. The warning number is no - longer shown within brackets. This is to help default parsing of warning messages by - other tools, vim on Unix in particular. - - Example original display using -Fstandard: - example.i:20: Warning(401): Nothing known about base class 'B'. Ignored. - New display: - example.i:20: Warning 401: Nothing known about base class 'B'. Ignored. - - Also subtle fix to -Fmicrosoft format adding in missing space. Example original display: - example.i(20): Warning(401): Nothing known about base class 'Base'. Ignored. - New display: - example.i(20) : Warning 401: Nothing known about base class 'Base'. Ignored. - -2010-01-10: wsfulton - Fix a few inconsistencies in reporting of file/line numberings including modifying - the overload warnings 509, 512, 516, 474, 475 to now be two line warnings. - -2010-01-10: wsfulton - Modify -debug-tags output to use standard file name/line reporting so that editors - can easily navigate to the appropriate lines. - Was typically: - . top . include . include (/usr/share/swig/temp/trunk/Lib/swig.swg:312) - . top . include . include . include (/usr/share/swig/temp/trunk/Lib/swigwarnings.swg:39) - now: - /usr/share/swig/temp/trunk/Lib/swig.swg:312: . top . include . include - /usr/share/swig/temp/trunk/Lib/swigwarnings.swg:39: . top . include . include . include - -2010-01-03: wsfulton - Fix missing file/line numbers for typemap warnings and in output from the - -debug-tmsearch/-debug-tmused options. - -2010-01-03: wsfulton - Add typemaps used debugging option (-debug-tmused). When used each line displays - the typemap used for each type for which code is being generated including the file - and line number related to the type. This is effectively a condensed form of the - -debug-tmsearch option. Documented in Typemaps.html. - -2009-12-23: wsfulton - Fix for %javaexception and directors so that all the appropriate throws clauses - are generated. Problem reported by Peter Greenwood. - -2009-12-20: wsfulton - Add -debug-tmsearch option for debugging the typemap pattern matching rules. - Documented in Typemaps.html. - -2009-12-12: wsfulton - [Octave] Remove the -api option and use the new OCTAVE_API_VERSION_NUMBER - macro provided in the octave headers for determining the api version instead. - -2009-12-04: olly - [Ruby] Improve support for Ruby 1.9 under GCC. Addresses part of - SF#2859614. - -2009-12-04: olly - Fix handling of modulo operator (%) in constant expressions - (SF#2818562). - -2009-12-04: olly - [PHP] "empty" is a reserved word in PHP, so rename empty() method - on STL classes to "is_empty()" (previously this was automatically - renamed to "c_empty()"). - *** POTENTIAL INCOMPATIBILITY *** - -2009-12-03: olly - [PHP] Add typemaps for long long and unsigned long long, and for - pointer to method. - -2009-12-02: olly - [PHP] Fix warning and rename of reserved class name to be case - insensitive. - -2009-12-01: wsfulton - Revert support for %extend and memberin typemaps added in swig-1.3.39. The - memberin typemaps are ignored again for member variables within a %extend block. - Documentation inconsistency reported by Torsten Landschoff. - -2009-11-29: wsfulton - [Java, C#] Fix generated quoting when using %javaconst(1)/%csconst(1) for - static const char member variables. - - %javaconst(1) A; - %csconst(1) A; - struct X { - static const char A = 'A'; - }; - -2009-11-26: wsfulton - [Java, C#] Fix %javaconst(1)/%csconst(1) for static const member variables to - use the actual constant value if it is specified, rather than the C++ code to - access the member. - - %javaconst(1) EN; - %csconst(1) EN; - struct X { - static const int EN = 2; - }; - -2009-11-23: wsfulton - C++ nested typedef classes can now be handled too, for example: - struct Outer { - typedef Foo { } FooTypedef1, FooTypedef2; - }; - -2009-11-18: wsfulton - The wrappers for C nested structs are now generated in the same order as declared - in the parsed code. - -2009-11-18: wsfulton - Fix #491476 - multiple declarations of nested structs, for example: - struct Outer { - struct { - int val; - } inner1, inner2, *inner3, inner4[1]; - } outer; - -2009-11-17: wsfulton - Fix parsing of enum declaration and initialization, for example: - - enum ABC { - a, - b, - c - } A = a, *pC = &C, array[3] = {a, b, c}; - -2009-11-17: wsfulton - Fix parsing of struct declaration and initialization, for example: - - struct S { - int x; - } instance = { 10 }; - -2009-11-15: wsfulton - Fix #1960977 - Syntax error parsing derived nested class declaration and member - variable instance. - -2009-11-14: wsfulton - 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 - is generated. - -2009-11-13: olly - [php] Fix place where class prefix (as specified with -prefix) - 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 - template class is now treated like a normal nested classes, that is, as an opaque type - unless the nestedworkaround feature is used. - -2009-11-12: wsfulton - Replace SWIGWARN_PARSE_NESTED_CLASS with SWIGWARN_PARSE_NAMED_NESTED_CLASS and - SWIGWARN_PARSE_UNNAMED_NESTED_CLASS for named and unnamed nested classes respectively. - - Named nested class ignored warnings can now be suppressed by name using %warnfilter, eg: - - %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::Inner; - - but clearly unnamed nested classes cannot and the global suppression is still required, eg: - - #pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS - -2009-11-11: wsfulton - Added the nestedworkaround feature as a way to use the full functionality of a nested class - (C++ mode only). It removes the nested class from SWIG's type information so it is as if SWIG - had never parsed the nested class. The documented nested class workarounds using a global - fake class stopped working when SWIG treated the nested class as an opaque pointer, and - this feature reverts this behaviour. The documentation has been updated with details of how - to use and implement it, see the "Nested classes" section in SWIGPlus.html. - -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 - 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 - as an opaque type by default, resulting in generated code that should always compile. - - *** POTENTIAL INCOMPATIBILITY *** - -2009-11-09: drjoe - Fix R for -fcompact and add std_map.i - -2009-11-08: wsfulton - Fix inconsistency for nested structs/unions/classes. Uncompileable 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: - - struct Outer { - struct InnerStruct { int x; }; - InnerStruct* getInnerStruct(); - }; - -2009-11-08: wsfulton - 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 - 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. - -2009-11-07: wsfulton - Add new debug options: - -debug-symtabs - Display symbol tables information - -debug-symbols - Display target language symbols in the symbol tables - -debug-csymbols - Display C symbols in the symbol tables - -2009-11-03: wsfulton - Fix some usage of unary scope operator (::) denoting global scope, for example: - - namespace AA { /* ... */ } - using namespace ::AA; - - and bug #1816802 - SwigValueWrapper should be used: - - struct CC { - CC(int); // no default constructor - }; - ::CC x(); - - and in template parameter specializations: - - struct S {}; - template struct X { void a() {}; }; - template <> struct X { void b() {}; }; - %template(MyTConcrete) X< ::S >; - - plus probably some other corner case usage of ::. - -2009-11-02: olly - [Python] Fix potential memory leak in initialisation code for the - generated module. - -2009-10-23: wsfulton - Fix seg fault when using a named nested template instantiation using %template(name) - within a class. A warning that these are not supported is now issued plus processing - continues as if no name was given. - -2009-10-20: wsfulton - [Python] Fix std::vector. This would previously compile, but not run correctly. - -2009-10-20: wsfulton - Fixed previously fairly poor template partial specialization and explicit - specialization support. Numerous bugs in this area have been fixed including: - - - Template argument deduction implemented for template type arguments, eg this now - works: - template class X {}; - template class X {}; - %template(X1) X; // Chooses T * specialization - - and more complex cases with multiple parameters and a mix of template argument - deduction and explicitly specialised parameters, eg: - template struct TwoParm { void a() {} }; - template struct TwoParm { void e() {} }; - %template(E) TwoParm; - - Note that the primary template must now be in scope, like in C++, when - an explicit or partial specialization is instantiated with %template. - - *** POTENTIAL INCOMPATIBILITY *** - -2009-09-14: wsfulton - [C#] Add %csattributes for adding C# attributes to enum values, see docs for example. - -2009-09-11: wsfulton - Fix memmove regression in cdata.i as reported by Adriaan Renting. - -2009-09-07: wsfulton - Fix constant expressions containing <= or >=. - -2009-09-02: wsfulton - The following operators in constant expressions now result in type bool for C++ - wrappers and remain as type int for C wrappers, as per each standard: - - && || == != < > <= >= (Actually the last 4 are still broken). For example: - - #define A 10 - #define B 10 - #define A_EQ_B A == B // now wrapped as type bool for C++ - #define A_AND_B A && B // now wrapped as type bool for C++ - -2009-09-02: wsfulton - Fix #2845746. true and false are now recognised keywords (only when wrapping C++). - Constants such as the following are now wrapped (as type bool): - #define FOO true - #define BAR FOO && false - diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index e957318e8..e514f726d 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

          SWIG-2.0 Documentation

          -Last update : SWIG-2.0.0 (2 June 2010) +Last update : SWIG-2.0.1 (in progress)

          Sections

          diff --git a/README b/README index d9288cdae..3c6ee27a0 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.0 (2 June 2010) +Version: 2.0.1 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, diff --git a/RELEASENOTES b/RELEASENOTES index 74e043ae7..5f41df04f 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -1,10 +1,10 @@ +This file contains a brief overview of the changes made in each release. +A detailed description of changes are available in the CHANGES.current +and CHANGES files. + Release Notes ============= -A detailed description of changes are available in the CHANGES.current -and CHANGES files. The summaries below contain just a brief overview of -the changes made in each release. - SWIG-2.0.0 summary: - License changes, see LICENSE file and http://www.swig.org/legal.html. - Much better nested class/struct support. diff --git a/configure.in b/configure.in index 49076ec8c..fe95fa7c0 100644 --- a/configure.in +++ b/configure.in @@ -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],[2.0.0],[http://www.swig.org]) +AC_INIT([swig],[2.0.1],[http://www.swig.org]) AC_PREREQ(2.58) AC_CONFIG_SRCDIR([Source/Swig/swig.h]) AC_CONFIG_AUX_DIR([Tools/config]) From d30054b5f63a75d2688518b82b90b10507a62259 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Jun 2010 17:41:36 +0000 Subject: [PATCH 155/203] Remove duplicate intro git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12097 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGES b/CHANGES index bd65df32b..f243ff7c6 100644 --- a/CHANGES +++ b/CHANGES @@ -6,9 +6,6 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.0 (2 June 2010) =========================== -See CHANGES file for changes in older releases. -See RELEASENOTES file for a summary of changes in each release. - 2010-06-02: wsfulton [C#] Fix SWIG_STD_VECTOR_ENHANCED macro used in std::vector to work with types containing commas, for example: From 257ce20f30b2535fff7b52f18df5595be6b4ec9b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Jun 2010 17:44:42 +0000 Subject: [PATCH 156/203] Fix uncompileable code when %rename results in two enum items with the same name git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12098 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Examples/test-suite/common.mk | 1 + Examples/test-suite/enum_rename.i | 12 ++++++++++++ Source/Modules/typepass.cxx | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/enum_rename.i diff --git a/CHANGES.current b/CHANGES.current index 9982286c2..331e9d8dd 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,3 +5,6 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-06-03: wsfulton + Fix uncompileable code when %rename results in two enum items + with the same name. Reported by Vadim Zeitlin. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 97708be47..5033f1957 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -180,6 +180,7 @@ CPP_TEST_CASES += \ disown \ dynamic_cast \ empty \ + enum_rename \ enum_scope_template \ enum_template \ enum_thorough \ diff --git a/Examples/test-suite/enum_rename.i b/Examples/test-suite/enum_rename.i new file mode 100644 index 000000000..455826f8b --- /dev/null +++ b/Examples/test-suite/enum_rename.i @@ -0,0 +1,12 @@ +%module enum_rename + +%warnfilter(SWIGWARN_PARSE_REDEFINED) S_May; + +// %rename with rxspencer can do the equivalent of these two renames, which was resulting in uncompileable code +%rename(May) M_May; +%rename(May) S_May; + +%inline %{ + enum Month { M_Jan, M_May, M_Dec }; + enum Severity { S_May, S_Can, S_Must }; +%} diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 57a7663eb..e0e06d54e 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -796,7 +796,7 @@ class TypePass:private Dispatcher { bool reset; String *enumvalue = Getattr(c, "enumvalue"); - if (GetFlag(c, "feature:ignore")) { + if (GetFlag(c, "feature:ignore") || !Getattr(c, "sym:name")) { reset = enumvalue ? true : false; previous_ignored = true; } else { From 9622d908ae0e9cbfcad7eb3bb4b8c894fd2e311c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 4 Jun 2010 05:14:14 +0000 Subject: [PATCH 157/203] Fix typo reported in SF#3011286 by Ben Ceschi. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12100 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Php.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index fbe31b9e3..e9190a837 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -857,7 +857,7 @@ either %init or %minit.

          To insert code into the PHP_MSHUTDOWN_FUNCTION, one can use -either %init or %minit. +either %shutdown or %mshutdown.

          
          From 229ce6196d92e2023ae786ff0243c508399a379d Mon Sep 17 00:00:00 2001
          From: William S Fulton 
          Date: Mon, 7 Jun 2010 18:56:59 +0000
          Subject: [PATCH 158/203] remove reference to old version of Perl
          
          git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12103 626c5289-ae23-0410-ae9c-e8d60b6d4f22
          ---
           Examples/perl5/index.html | 5 ++---
           1 file changed, 2 insertions(+), 3 deletions(-)
          
          diff --git a/Examples/perl5/index.html b/Examples/perl5/index.html
          index 5648c587d..db46023c4 100644
          --- a/Examples/perl5/index.html
          +++ b/Examples/perl5/index.html
          @@ -68,9 +68,8 @@ Please see the Windows page in the m
           
           

          Due to wide variations in the Perl C API and differences between versions such as the ActivePerl release for Windows, -the code generated by SWIG is extremely messy. We have made every attempt to maintain compatibility with -many Perl releases going as far back as 5.003 and as recent as 5.6. However, your mileage may vary. -If you experience a problem, please let us know by +the code generated by SWIG is extremely messy. +If the code doesn't compile or work with your version of Perl, please let us know by contacting us on the mailing lists. Better yet, send us a patch. From 9f99c73221753aa5c2c425ca58d8e42f91556a41 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 8 Jun 2010 05:37:49 +0000 Subject: [PATCH 159/203] minor clarification in Php docs git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12104 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Php.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index e9190a837..f3bf720d9 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -868,8 +868,8 @@ either %shutdown or %mshutdown.

          -The %rinit and %rshutdown statements insert code -into the request init and shutdown code respectively. +The %rinit and %rshutdown statements are very similar but insert code +into the request init (PHP_RINIT_FUNCTION) and request shutdown (PHP_RSHUTDOWN_FUNCTION) code respectively.

          29.3 Cross language polymorphism

          From 09f14197ac1df83e9b428d84782238abec0500bd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 8 Jun 2010 06:02:56 +0000 Subject: [PATCH 160/203] Add section on Aspect Oriented Programming after discussion on swig-devel git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12105 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 1 + Doc/Manual/Typemaps.html | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 8612ef237..27337ea7a 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -336,6 +336,7 @@
        • Reusing typemaps
        • What can be done with typemaps?
        • What can't be done with typemaps? +
        • Similarities to Aspect Oriented Programming
        • The rest of this chapter
      • Typemap specifications diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index cacfd5f2f..1568c082e 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -18,6 +18,7 @@
      • Reusing typemaps
      • What can be done with typemaps?
      • What can't be done with typemaps? +
      • Similarities to Aspect Oriented Programming
      • The rest of this chapter
    • Typemap specifications @@ -115,7 +116,7 @@ chapter with only a vague idea of what SWIG already does by default.

      One of the most important problems in wrapper code generation is the -conversion of datatypes between programming languages. Specifically, +conversion or marshalling of datatypes between programming languages. Specifically, for every C/C++ declaration, SWIG must somehow generate wrapper code that allows values to be passed back and forth between languages. Since every programming language represents data differently, this is @@ -637,7 +638,25 @@ void wrap_foo(char *s, int x) { -

      10.1.7 The rest of this chapter

      +

      10.1.7 Similarities to Aspect Oriented Programming

      + + +

      +SWIG has parallels to Aspect Oriented Software Development (AOP). +The AOP terminology with respect to SWIG typemaps can be viewed as follows: +

      +
        +
      • Cross-cutting concerns: The cross-cutting concerns are the modularization of the functionality that the typemaps implement, which is primarily marshalling of types from/to the target language and C/C++. +
      • Advice: The typemap body contains code which is executed whenever the marshalling is required. +
      • Pointcut: The pointcuts are the positions in the wrapper code that the typemap code is generated into. +
      • Aspect: Aspects are the combination of the pointcut and the advice, hence each typemap is an aspect. +
      +

      +SWIG can also be viewed as has having a second set of aspects based around %feature. +Features such as %exception are also cross-cutting concerns as they encapsulate code that can be used to add logging or exception handling to any function. +

      + +

      10.1.8 The rest of this chapter

      From 5af2978f77cad0eec048ba1ea09b07e8ad7abbfa Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 10 Jun 2010 01:13:31 +0000 Subject: [PATCH 161/203] Add support for the Go programming language. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12108 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Go.html | 463 ++ Doc/Manual/SWIG.html | 1 + Doc/Manual/Sections.html | 1 + Doc/Manual/chapters | 1 + Examples/Makefile.in | 71 + Examples/go/callback/Makefile | 18 + Examples/go/callback/example.cxx | 4 + Examples/go/callback/example.go | 188 + Examples/go/callback/example.h | 23 + Examples/go/callback/example.i | 13 + Examples/go/callback/index.html | 81 + Examples/go/callback/runme.go | 41 + Examples/go/check.list | 13 + Examples/go/class/Makefile | 16 + Examples/go/class/example.cxx | 28 + Examples/go/class/example.go | 284 + Examples/go/class/example.h | 39 + Examples/go/class/example.i | 10 + Examples/go/class/index.html | 203 + Examples/go/class/runme.go | 63 + Examples/go/constants/Makefile | 16 + Examples/go/constants/example.go | 44 + Examples/go/constants/example.i | 25 + Examples/go/constants/index.html | 55 + Examples/go/constants/runme.go | 18 + Examples/go/enum/Makefile | 18 + Examples/go/enum/example.cxx | 37 + Examples/go/enum/example.go | 93 + Examples/go/enum/example.h | 13 + Examples/go/enum/example.i | 11 + Examples/go/enum/index.html | 42 + Examples/go/enum/runme.go | 32 + Examples/go/extend/Makefile | 18 + Examples/go/extend/example.cxx | 4 + Examples/go/extend/example.go | 397 ++ Examples/go/extend/example.h | 56 + Examples/go/extend/example.i | 15 + Examples/go/extend/index.html | 27 + Examples/go/extend/runme.go | 77 + Examples/go/funcptr/Makefile | 18 + Examples/go/funcptr/example.c | 19 + Examples/go/funcptr/example.go | 54 + Examples/go/funcptr/example.h | 9 + Examples/go/funcptr/example.i | 16 + Examples/go/funcptr/index.html | 89 + Examples/go/funcptr/runme.go | 25 + Examples/go/index.html | 89 + Examples/go/multimap/Makefile | 18 + Examples/go/multimap/example.c | 53 + Examples/go/multimap/example.go | 55 + Examples/go/multimap/example.i | 110 + Examples/go/multimap/runme.go | 26 + Examples/go/pointer/Makefile | 18 + Examples/go/pointer/example.c | 16 + Examples/go/pointer/example.go | 68 + Examples/go/pointer/example.i | 30 + Examples/go/pointer/index.html | 143 + Examples/go/pointer/runme.go | 47 + Examples/go/reference/Makefile | 18 + Examples/go/reference/example.cxx | 46 + Examples/go/reference/example.go | 126 + Examples/go/reference/example.h | 26 + Examples/go/reference/example.i | 42 + Examples/go/reference/index.html | 143 + Examples/go/reference/runme.go | 71 + Examples/go/simple/Makefile | 15 + Examples/go/simple/example.c | 18 + Examples/go/simple/example.go | 48 + Examples/go/simple/example.i | 7 + Examples/go/simple/index.html | 126 + Examples/go/simple/runme.go | 25 + Examples/go/template/Makefile | 18 + Examples/go/template/example.go | 150 + Examples/go/template/example.h | 32 + Examples/go/template/example.i | 17 + Examples/go/template/index.html | 113 + Examples/go/template/runme.go | 43 + Examples/go/variables/Makefile | 18 + Examples/go/variables/example.c | 91 + Examples/go/variables/example.go | 198 + Examples/go/variables/example.h | 6 + Examples/go/variables/example.i | 49 + Examples/go/variables/index.html | 87 + Examples/go/variables/runme.go | 67 + Examples/test-suite/dynamic_cast.i | 14 +- Examples/test-suite/go/Makefile.in | 110 + .../test-suite/go/abstract_access_runme.go | 10 + .../test-suite/go/abstract_typedef2_runme.go | 7 + .../test-suite/go/abstract_typedef_runme.go | 11 + .../test-suite/go/abstract_virtual_runme.go | 8 + Examples/test-suite/go/array_member_runme.go | 26 + Examples/test-suite/go/arrays_global_runme.go | 22 + Examples/test-suite/go/class_ignore_runme.go | 10 + .../test-suite/go/class_scope_weird_runme.go | 11 + .../test-suite/go/compactdefaultargs_runme.go | 29 + Examples/test-suite/go/constover_runme.go | 50 + .../test-suite/go/constructor_copy_runme.go | 34 + Examples/test-suite/go/contract_runme.go | 208 + Examples/test-suite/go/cpp_enum_runme.go | 27 + Examples/test-suite/go/cpp_namespace_runme.go | 57 + Examples/test-suite/go/cpp_static_runme.go | 13 + Examples/test-suite/go/default_args_runme.go | 26 + .../go/default_constructor_runme.go | 35 + .../test-suite/go/director_abstract_runme.go | 62 + .../test-suite/go/director_basic_runme.go | 115 + .../test-suite/go/director_classic_runme.go | 135 + .../test-suite/go/director_default_runme.go | 11 + .../test-suite/go/director_detect_runme.go | 46 + Examples/test-suite/go/director_enum_runme.go | 17 + .../test-suite/go/director_exception_runme.go | 95 + .../test-suite/go/director_extend_runme.go | 18 + .../test-suite/go/director_finalizer_runme.go | 37 + Examples/test-suite/go/director_frob_runme.go | 12 + .../test-suite/go/director_nested_runme.go | 79 + .../test-suite/go/director_profile_runme.go | 49 + .../test-suite/go/director_protected_runme.go | 48 + .../test-suite/go/director_string_runme.go | 39 + .../test-suite/go/director_thread_runme.go | 28 + .../test-suite/go/director_unroll_runme.go | 21 + Examples/test-suite/go/disown_runme.go | 10 + Examples/test-suite/go/dynamic_cast_runme.go | 16 + Examples/test-suite/go/empty_runme.go | 6 + Examples/test-suite/go/enum_template_runme.go | 11 + Examples/test-suite/go/enums_runme.go | 25 + .../test-suite/go/exception_order_runme.go | 58 + .../test-suite/go/extend_placement_runme.go | 47 + .../test-suite/go/extend_template_ns_runme.go | 14 + .../test-suite/go/extend_template_runme.go | 14 + .../test-suite/go/extend_variable_runme.go | 9 + Examples/test-suite/go/extern_c_runme.go | 7 + Examples/test-suite/go/friends_runme.go | 50 + Examples/test-suite/go/fvirtual_runme.go | 13 + Examples/test-suite/go/global_ns_arg_runme.go | 8 + Examples/test-suite/go/grouping_runme.go | 19 + .../test-suite/go/import_nomodule_runme.go | 12 + Examples/test-suite/go/imports_runme.go | 17 + Examples/test-suite/go/inctest_runme.go | 18 + .../test-suite/go/inherit_missing_runme.go | 26 + Examples/test-suite/go/input_runme.go | 14 + .../test-suite/go/keyword_rename_runme.go | 8 + Examples/test-suite/go/li_attribute_runme.go | 90 + Examples/test-suite/go/li_carrays_runme.go | 14 + Examples/test-suite/go/li_cdata_runme.go | 13 + Examples/test-suite/go/li_cmalloc_runme.go | 25 + Examples/test-suite/go/li_cpointer_runme.go | 14 + Examples/test-suite/go/li_std_map_runme.go | 30 + .../test-suite/go/member_pointer_runme.go | 49 + .../test-suite/go/memberin_extend_c_runme.go | 11 + Examples/test-suite/go/minherit_runme.go | 82 + Examples/test-suite/go/mod_runme.go | 10 + Examples/test-suite/go/multi_import_runme.go | 29 + .../test-suite/go/namespace_class_runme.go | 19 + .../test-suite/go/namespace_typemap_runme.go | 116 + .../go/namespace_virtual_method_runme.go | 7 + Examples/test-suite/go/naturalvar_runme.go | 17 + .../test-suite/go/nested_workaround_runme.go | 19 + .../go/overload_complicated_runme.go | 62 + Examples/test-suite/go/overload_copy_runme.go | 8 + .../test-suite/go/overload_extend_runme.go | 22 + .../test-suite/go/overload_extendc_runme.go | 33 + .../test-suite/go/overload_rename_runme.go | 10 + .../test-suite/go/overload_simple_runme.go | 125 + .../test-suite/go/overload_subtype_runme.go | 16 + .../go/overload_template_fast_runme.go | 187 + .../test-suite/go/overload_template_runme.go | 188 + Examples/test-suite/go/preproc_runme.go | 21 + Examples/test-suite/go/primitive_ref_runme.go | 57 + Examples/test-suite/go/profiletest_runme.go | 38 + Examples/test-suite/go/refcount_runme.go | 32 + .../go/reference_global_vars_runme.go | 98 + Examples/test-suite/go/rename_scope_runme.go | 18 + .../go/rename_strip_encoder_runme.go | 9 + Examples/test-suite/go/ret_by_value_runme.go | 14 + .../test-suite/go/return_const_value_runme.go | 15 + .../go/smart_pointer_extend_runme.go | 40 + .../go/smart_pointer_member_runme.go | 30 + .../go/smart_pointer_multi_runme.go | 20 + .../go/smart_pointer_multi_typedef_runme.go | 20 + .../go/smart_pointer_overload_runme.go | 28 + .../go/smart_pointer_rename_runme.go | 20 + .../go/smart_pointer_simple_runme.go | 19 + .../smart_pointer_templatevariables_runme.go | 22 + .../go/smart_pointer_typedef_runme.go | 19 + Examples/test-suite/go/sneaky1_runme.go | 10 + .../go/special_variable_macros_runme.go | 25 + .../go/static_const_member_2_runme.go | 18 + .../go/struct_initialization_runme.go | 29 + Examples/test-suite/go/struct_rename_runme.go | 7 + Examples/test-suite/go/struct_value_runme.go | 17 + .../go/template_default_arg_runme.go | 107 + .../test-suite/go/template_extend1_runme.go | 16 + .../test-suite/go/template_extend2_runme.go | 16 + .../test-suite/go/template_inherit_runme.go | 72 + Examples/test-suite/go/template_ns4_runme.go | 10 + Examples/test-suite/go/template_ns_runme.go | 26 + .../test-suite/go/template_opaque_runme.go | 9 + .../test-suite/go/template_ref_type_runme.go | 9 + .../test-suite/go/template_rename_runme.go | 16 + .../test-suite/go/template_static_runme.go | 7 + .../go/template_tbase_template_runme.go | 10 + .../go/template_type_namespace_runme.go | 8 + .../go/template_typedef_cplx3_runme.go | 29 + .../go/template_typedef_cplx4_runme.go | 29 + .../go/template_typedef_import_runme.go | 30 + .../test-suite/go/threads_exception_runme.go | 66 + Examples/test-suite/go/typedef_class_runme.go | 11 + .../test-suite/go/typedef_inherit_runme.go | 31 + Examples/test-suite/go/typedef_scope_runme.go | 16 + .../test-suite/go/typemap_namespace_runme.go | 13 + .../test-suite/go/typemap_ns_using_runme.go | 9 + .../go/typemap_out_optimal_runme.go | 8 + Examples/test-suite/go/typename_runme.go | 13 + Examples/test-suite/go/unions_runme.go | 51 + Examples/test-suite/go/using1_runme.go | 9 + Examples/test-suite/go/using2_runme.go | 9 + .../test-suite/go/using_composition_runme.go | 44 + Examples/test-suite/go/using_extend_runme.go | 30 + Examples/test-suite/go/using_inherit_runme.go | 59 + Examples/test-suite/go/using_private_runme.go | 20 + .../test-suite/go/using_protected_runme.go | 12 + Examples/test-suite/go/varargs_runme.go | 26 + .../test-suite/go/virtual_derivation_runme.go | 12 + Examples/test-suite/go/virtual_poly_runme.go | 43 + Examples/test-suite/go/voidtest_runme.go | 26 + Examples/test-suite/go/wrapmacro_runme.go | 11 + Examples/test-suite/keyword_rename.i | 4 + Examples/test-suite/minherit.i | 2 +- Examples/test-suite/name_warnings.i | 2 + Examples/test-suite/namespace_typemap.i | 26 + Examples/test-suite/null_pointer.i | 2 + Examples/test-suite/overload_simple.i | 2 + Examples/test-suite/return_const_value.i | 9 +- Examples/test-suite/rname.i | 5 + Examples/test-suite/typemap_namespace.i | 5 +- Examples/test-suite/typemap_subst.i | 4 +- Examples/test-suite/union_parameter.i | 2 + Lib/go/cdata.i | 135 + Lib/go/exception.i | 7 + Lib/go/go.swg | 514 ++ Lib/go/gokw.swg | 31 + Lib/go/goruntime.swg | 208 + Lib/go/std_common.i | 4 + Lib/go/std_deque.i | 1 + Lib/go/std_except.i | 29 + Lib/go/std_map.i | 64 + Lib/go/std_pair.i | 34 + Lib/go/std_string.i | 55 + Lib/go/std_vector.i | 78 + Lib/go/stl.i | 9 + Lib/go/typemaps.i | 335 ++ Makefile.in | 17 +- Source/Makefile.am | 1 + Source/Modules/allegrocl.cxx | 2 + Source/Modules/go.cxx | 4824 +++++++++++++++++ Source/Modules/overload.cxx | 2 +- Source/Modules/r.cxx | 2 + Source/Modules/swigmain.cxx | 2 + Source/Modules/swigmod.h | 1 + configure.in | 36 + 259 files changed, 16159 insertions(+), 14 deletions(-) create mode 100644 Doc/Manual/Go.html create mode 100644 Examples/go/callback/Makefile create mode 100644 Examples/go/callback/example.cxx create mode 100644 Examples/go/callback/example.go create mode 100644 Examples/go/callback/example.h create mode 100644 Examples/go/callback/example.i create mode 100644 Examples/go/callback/index.html create mode 100644 Examples/go/callback/runme.go create mode 100644 Examples/go/check.list create mode 100644 Examples/go/class/Makefile create mode 100644 Examples/go/class/example.cxx create mode 100644 Examples/go/class/example.go create mode 100644 Examples/go/class/example.h create mode 100644 Examples/go/class/example.i create mode 100644 Examples/go/class/index.html create mode 100644 Examples/go/class/runme.go create mode 100644 Examples/go/constants/Makefile create mode 100644 Examples/go/constants/example.go create mode 100644 Examples/go/constants/example.i create mode 100644 Examples/go/constants/index.html create mode 100644 Examples/go/constants/runme.go create mode 100644 Examples/go/enum/Makefile create mode 100644 Examples/go/enum/example.cxx create mode 100644 Examples/go/enum/example.go create mode 100644 Examples/go/enum/example.h create mode 100644 Examples/go/enum/example.i create mode 100644 Examples/go/enum/index.html create mode 100644 Examples/go/enum/runme.go create mode 100644 Examples/go/extend/Makefile create mode 100644 Examples/go/extend/example.cxx create mode 100644 Examples/go/extend/example.go create mode 100644 Examples/go/extend/example.h create mode 100644 Examples/go/extend/example.i create mode 100644 Examples/go/extend/index.html create mode 100644 Examples/go/extend/runme.go create mode 100644 Examples/go/funcptr/Makefile create mode 100644 Examples/go/funcptr/example.c create mode 100644 Examples/go/funcptr/example.go create mode 100644 Examples/go/funcptr/example.h create mode 100644 Examples/go/funcptr/example.i create mode 100644 Examples/go/funcptr/index.html create mode 100644 Examples/go/funcptr/runme.go create mode 100644 Examples/go/index.html create mode 100644 Examples/go/multimap/Makefile create mode 100644 Examples/go/multimap/example.c create mode 100644 Examples/go/multimap/example.go create mode 100644 Examples/go/multimap/example.i create mode 100644 Examples/go/multimap/runme.go create mode 100644 Examples/go/pointer/Makefile create mode 100644 Examples/go/pointer/example.c create mode 100644 Examples/go/pointer/example.go create mode 100644 Examples/go/pointer/example.i create mode 100644 Examples/go/pointer/index.html create mode 100644 Examples/go/pointer/runme.go create mode 100644 Examples/go/reference/Makefile create mode 100644 Examples/go/reference/example.cxx create mode 100644 Examples/go/reference/example.go create mode 100644 Examples/go/reference/example.h create mode 100644 Examples/go/reference/example.i create mode 100644 Examples/go/reference/index.html create mode 100644 Examples/go/reference/runme.go create mode 100644 Examples/go/simple/Makefile create mode 100644 Examples/go/simple/example.c create mode 100644 Examples/go/simple/example.go create mode 100644 Examples/go/simple/example.i create mode 100644 Examples/go/simple/index.html create mode 100644 Examples/go/simple/runme.go create mode 100644 Examples/go/template/Makefile create mode 100644 Examples/go/template/example.go create mode 100644 Examples/go/template/example.h create mode 100644 Examples/go/template/example.i create mode 100644 Examples/go/template/index.html create mode 100644 Examples/go/template/runme.go create mode 100644 Examples/go/variables/Makefile create mode 100644 Examples/go/variables/example.c create mode 100644 Examples/go/variables/example.go create mode 100644 Examples/go/variables/example.h create mode 100644 Examples/go/variables/example.i create mode 100644 Examples/go/variables/index.html create mode 100644 Examples/go/variables/runme.go create mode 100644 Examples/test-suite/go/Makefile.in create mode 100644 Examples/test-suite/go/abstract_access_runme.go create mode 100644 Examples/test-suite/go/abstract_typedef2_runme.go create mode 100644 Examples/test-suite/go/abstract_typedef_runme.go create mode 100644 Examples/test-suite/go/abstract_virtual_runme.go create mode 100644 Examples/test-suite/go/array_member_runme.go create mode 100644 Examples/test-suite/go/arrays_global_runme.go create mode 100644 Examples/test-suite/go/class_ignore_runme.go create mode 100644 Examples/test-suite/go/class_scope_weird_runme.go create mode 100644 Examples/test-suite/go/compactdefaultargs_runme.go create mode 100644 Examples/test-suite/go/constover_runme.go create mode 100644 Examples/test-suite/go/constructor_copy_runme.go create mode 100644 Examples/test-suite/go/contract_runme.go create mode 100644 Examples/test-suite/go/cpp_enum_runme.go create mode 100644 Examples/test-suite/go/cpp_namespace_runme.go create mode 100644 Examples/test-suite/go/cpp_static_runme.go create mode 100644 Examples/test-suite/go/default_args_runme.go create mode 100644 Examples/test-suite/go/default_constructor_runme.go create mode 100644 Examples/test-suite/go/director_abstract_runme.go create mode 100644 Examples/test-suite/go/director_basic_runme.go create mode 100644 Examples/test-suite/go/director_classic_runme.go create mode 100644 Examples/test-suite/go/director_default_runme.go create mode 100644 Examples/test-suite/go/director_detect_runme.go create mode 100644 Examples/test-suite/go/director_enum_runme.go create mode 100644 Examples/test-suite/go/director_exception_runme.go create mode 100644 Examples/test-suite/go/director_extend_runme.go create mode 100644 Examples/test-suite/go/director_finalizer_runme.go create mode 100644 Examples/test-suite/go/director_frob_runme.go create mode 100644 Examples/test-suite/go/director_nested_runme.go create mode 100644 Examples/test-suite/go/director_profile_runme.go create mode 100644 Examples/test-suite/go/director_protected_runme.go create mode 100644 Examples/test-suite/go/director_string_runme.go create mode 100644 Examples/test-suite/go/director_thread_runme.go create mode 100644 Examples/test-suite/go/director_unroll_runme.go create mode 100644 Examples/test-suite/go/disown_runme.go create mode 100644 Examples/test-suite/go/dynamic_cast_runme.go create mode 100644 Examples/test-suite/go/empty_runme.go create mode 100644 Examples/test-suite/go/enum_template_runme.go create mode 100644 Examples/test-suite/go/enums_runme.go create mode 100644 Examples/test-suite/go/exception_order_runme.go create mode 100644 Examples/test-suite/go/extend_placement_runme.go create mode 100644 Examples/test-suite/go/extend_template_ns_runme.go create mode 100644 Examples/test-suite/go/extend_template_runme.go create mode 100644 Examples/test-suite/go/extend_variable_runme.go create mode 100644 Examples/test-suite/go/extern_c_runme.go create mode 100644 Examples/test-suite/go/friends_runme.go create mode 100644 Examples/test-suite/go/fvirtual_runme.go create mode 100644 Examples/test-suite/go/global_ns_arg_runme.go create mode 100644 Examples/test-suite/go/grouping_runme.go create mode 100644 Examples/test-suite/go/import_nomodule_runme.go create mode 100644 Examples/test-suite/go/imports_runme.go create mode 100644 Examples/test-suite/go/inctest_runme.go create mode 100644 Examples/test-suite/go/inherit_missing_runme.go create mode 100644 Examples/test-suite/go/input_runme.go create mode 100644 Examples/test-suite/go/keyword_rename_runme.go create mode 100644 Examples/test-suite/go/li_attribute_runme.go create mode 100644 Examples/test-suite/go/li_carrays_runme.go create mode 100644 Examples/test-suite/go/li_cdata_runme.go create mode 100644 Examples/test-suite/go/li_cmalloc_runme.go create mode 100644 Examples/test-suite/go/li_cpointer_runme.go create mode 100644 Examples/test-suite/go/li_std_map_runme.go create mode 100644 Examples/test-suite/go/member_pointer_runme.go create mode 100644 Examples/test-suite/go/memberin_extend_c_runme.go create mode 100644 Examples/test-suite/go/minherit_runme.go create mode 100644 Examples/test-suite/go/mod_runme.go create mode 100644 Examples/test-suite/go/multi_import_runme.go create mode 100644 Examples/test-suite/go/namespace_class_runme.go create mode 100644 Examples/test-suite/go/namespace_typemap_runme.go create mode 100644 Examples/test-suite/go/namespace_virtual_method_runme.go create mode 100644 Examples/test-suite/go/naturalvar_runme.go create mode 100644 Examples/test-suite/go/nested_workaround_runme.go create mode 100644 Examples/test-suite/go/overload_complicated_runme.go create mode 100644 Examples/test-suite/go/overload_copy_runme.go create mode 100644 Examples/test-suite/go/overload_extend_runme.go create mode 100644 Examples/test-suite/go/overload_extendc_runme.go create mode 100644 Examples/test-suite/go/overload_rename_runme.go create mode 100644 Examples/test-suite/go/overload_simple_runme.go create mode 100644 Examples/test-suite/go/overload_subtype_runme.go create mode 100644 Examples/test-suite/go/overload_template_fast_runme.go create mode 100644 Examples/test-suite/go/overload_template_runme.go create mode 100644 Examples/test-suite/go/preproc_runme.go create mode 100644 Examples/test-suite/go/primitive_ref_runme.go create mode 100644 Examples/test-suite/go/profiletest_runme.go create mode 100644 Examples/test-suite/go/refcount_runme.go create mode 100644 Examples/test-suite/go/reference_global_vars_runme.go create mode 100644 Examples/test-suite/go/rename_scope_runme.go create mode 100644 Examples/test-suite/go/rename_strip_encoder_runme.go create mode 100644 Examples/test-suite/go/ret_by_value_runme.go create mode 100644 Examples/test-suite/go/return_const_value_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_extend_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_member_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_multi_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_multi_typedef_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_overload_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_rename_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_simple_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_templatevariables_runme.go create mode 100644 Examples/test-suite/go/smart_pointer_typedef_runme.go create mode 100644 Examples/test-suite/go/sneaky1_runme.go create mode 100644 Examples/test-suite/go/special_variable_macros_runme.go create mode 100644 Examples/test-suite/go/static_const_member_2_runme.go create mode 100644 Examples/test-suite/go/struct_initialization_runme.go create mode 100644 Examples/test-suite/go/struct_rename_runme.go create mode 100644 Examples/test-suite/go/struct_value_runme.go create mode 100644 Examples/test-suite/go/template_default_arg_runme.go create mode 100644 Examples/test-suite/go/template_extend1_runme.go create mode 100644 Examples/test-suite/go/template_extend2_runme.go create mode 100644 Examples/test-suite/go/template_inherit_runme.go create mode 100644 Examples/test-suite/go/template_ns4_runme.go create mode 100644 Examples/test-suite/go/template_ns_runme.go create mode 100644 Examples/test-suite/go/template_opaque_runme.go create mode 100644 Examples/test-suite/go/template_ref_type_runme.go create mode 100644 Examples/test-suite/go/template_rename_runme.go create mode 100644 Examples/test-suite/go/template_static_runme.go create mode 100644 Examples/test-suite/go/template_tbase_template_runme.go create mode 100644 Examples/test-suite/go/template_type_namespace_runme.go create mode 100644 Examples/test-suite/go/template_typedef_cplx3_runme.go create mode 100644 Examples/test-suite/go/template_typedef_cplx4_runme.go create mode 100644 Examples/test-suite/go/template_typedef_import_runme.go create mode 100644 Examples/test-suite/go/threads_exception_runme.go create mode 100644 Examples/test-suite/go/typedef_class_runme.go create mode 100644 Examples/test-suite/go/typedef_inherit_runme.go create mode 100644 Examples/test-suite/go/typedef_scope_runme.go create mode 100644 Examples/test-suite/go/typemap_namespace_runme.go create mode 100644 Examples/test-suite/go/typemap_ns_using_runme.go create mode 100644 Examples/test-suite/go/typemap_out_optimal_runme.go create mode 100644 Examples/test-suite/go/typename_runme.go create mode 100644 Examples/test-suite/go/unions_runme.go create mode 100644 Examples/test-suite/go/using1_runme.go create mode 100644 Examples/test-suite/go/using2_runme.go create mode 100644 Examples/test-suite/go/using_composition_runme.go create mode 100644 Examples/test-suite/go/using_extend_runme.go create mode 100644 Examples/test-suite/go/using_inherit_runme.go create mode 100644 Examples/test-suite/go/using_private_runme.go create mode 100644 Examples/test-suite/go/using_protected_runme.go create mode 100644 Examples/test-suite/go/varargs_runme.go create mode 100644 Examples/test-suite/go/virtual_derivation_runme.go create mode 100644 Examples/test-suite/go/virtual_poly_runme.go create mode 100644 Examples/test-suite/go/voidtest_runme.go create mode 100644 Examples/test-suite/go/wrapmacro_runme.go create mode 100644 Lib/go/cdata.i create mode 100644 Lib/go/exception.i create mode 100644 Lib/go/go.swg create mode 100644 Lib/go/gokw.swg create mode 100644 Lib/go/goruntime.swg create mode 100644 Lib/go/std_common.i create mode 100644 Lib/go/std_deque.i create mode 100644 Lib/go/std_except.i create mode 100644 Lib/go/std_map.i create mode 100644 Lib/go/std_pair.i create mode 100644 Lib/go/std_string.i create mode 100644 Lib/go/std_vector.i create mode 100644 Lib/go/stl.i create mode 100644 Lib/go/typemaps.i create mode 100644 Source/Modules/go.cxx diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html new file mode 100644 index 000000000..7d2ce9db8 --- /dev/null +++ b/Doc/Manual/Go.html @@ -0,0 +1,463 @@ + + + +SWIG and Go + + + +

      20 SWIG and Go

      + + + + + + +

      +This chapter describes SWIG's support of Go. For more information on +the Go programming language +see golang.org. +

      + +

      20.1 Overview

      + + +

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

      + +

      +There are (at least) two different Go compilers. One is the gc +compiler, normally invoked under the names 6g, 8g, or 5g. The other +is the gccgo compiler, which is a frontend to the gcc compiler suite. +The interface to C/C++ code is completely different for the two Go +compilers. SWIG supports both, selected by a command line option. +

      + +

      +Because Go is a type-safe compiled language, SWIG's runtime type +checking and runtime library are not used with Go. This should be +borne in mind when reading the rest of the SWIG documentation. +

      + +

      20.2 Running SWIG with Go

      + + +

      +To generate Go code, use the -go option with SWIG. By +default SWIG will generate code for the gc compilers. To generate +code for gccgo, you should use the -gccgo option. +

      + +

      20.2.1 Additional Commandline Options

      + + +

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

      + +
      +swig -go -help
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Go specific options
      -gccgoGenerate code for gccgo. The default is to generate code for + 6g/8g/6g.
      -package <name>Set the name of the Go package to <name>. The default + package name is the SWIG module name.
      -go-prefix <prefix>When generating code for gccgo, set the prefix to use. This + corresponds to the -fgo-prefix option to gccgo.
      -long-type-size <s>Set the size for the C/C++ type long. This controls + whether long is converted to the Go type int32 + or int64. The <s> argument should be 32 or 64.
      -rename <old>=<new>Rename <old%gt; to <new> when processing the C/C++ code + and also the SWIG input file. This is a convenient way to rename + names in the C/C++ code which are the same expect for the first + letter, to avoid conflicts when applying the Go renaming rules + described below.
      + +

      20.2.2 Go Output Files

      + + +

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

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

      +A typical command sequence would look like this: +

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

      20.3 A tour of basic C/C++ wrapping

      + + +

      +By default, SWIG attempts to build a natural Go interface to your +C/C++ code. However, the languages are somewhat different, so some +modifications have to occur. This section briefly covers the +essential aspects of this wrapping. +

      + +

      20.3.1 Go Package Name

      + + +

      +All Go source code lives in a package. The name of this package will +default to the name of the module from SWIG's %module +directive. You may override this by using SWIG's -package +command line option. +

      + +

      20.3.2 Go Names

      + + +

      +In Go, a function is only visible outside the current package if the +first letter of the name is uppercase. This is quite different from +C/C++. Because of this, C/C++ names are modified when generating the +Go interface: the first letter is forced to be uppercase if it is not +already. This affects the names of functions, methods, variables, +constants, enums, and classes. +

      + +

      +C/C++ variables are wrapped with setter and getter functions in Go. +First the first letter of the variable name will be forced to +uppercase, and then Get or Set will be prepended. +For example, if the C/C++ variable is called var, then SWIG +will define the functions GetVar and SetVar. If a +variable is declared as const, or if +SWIG's +%immutable directive is used for the variable, then only +the getter will be defined. +

      + +

      +C++ classes will be discussed further below. Here we'll note that the +first letter of the class name will be forced to uppercase to give the +name of a type in Go. A constructor will be named New +followed by that name, and the destructor will be +named Delete followed by that name. +

      + +

      20.3.3 Go Constants

      + + +

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

      20.3.4 Go Enumerations

      + + +

      +C/C++ enumeration types will cause SWIG to define an integer type with +the name of the enumeration (with first letter forced to uppercase as +usual). The values of the enumeration will become variables in Go; +code should avoid modifying those variables. +

      + +

      20.3.5 Go Classes

      + + +

      +Go has interfaces, methods and inheritance, but it does not have +classes in the same sense as C++. This sections describes how SWIG +represents C++ classes represented in Go. +

      + +

      +For a C++ class ClassName, SWIG will define two types in Go: +an underlying type, which will just hold a pointer to the C++ type, +and an interface type. The interface type will be +named ClassName. SWIG will define a +function NewClassName which will take any constructor +arguments and return a value of the interface +type ClassName. SWIG will also define a +destructor DeleteClassName. +

      + +

      +SWIG will represent any methods of the C++ class as methods on the +underlying type, and also as methods of the interface type. Thus C++ +methods may be invoked directly using the +usual val.MethodName syntax. Public members of the C++ class +will be given getter and setter functions defined as methods of the +class. +

      + +

      +SWIG will represent static methods of C++ classes as ordinary Go +functions. SWIG will use names like ClassName_MethodName. +SWIG will give static members getter and setter functions with names +like GetClassName_VarName. +

      + +

      +Given a value of the interface type, Go code can retrieve the pointer +to the C++ type by calling the Swigcptr method. This will +return a value of type SwigcptrClassName, which is just a +name for uintptr. A Go type conversion can be used to +convert this value to a different C++ type, but note that this +conversion will not be type checked and is essentially equivalent +to reinterpret_cast. This should only be used for very +special cases, such as where C++ would use a dynamic_cast. +

      + +

      20.3.5.1 Go Class Inheritance

      + + +

      +C++ class inheritance is automatically represented in Go due to its +use of interfaces. The interface for a child class will be a superset +of the interface of its parent class. Thus a value of the child class +type in Go may be passed to a function which expects the parent class. +Doing the reverse will require an explicit type assertion, which will +be checked dynamically. +

      + +

      20.3.6 Go Templates

      + + +

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

      20.3.7 Go Director Classes

      + + +

      +SWIG's director feature permits a Go type to act as the subclass of a +C++ class with virtual methods. This is complicated by the fact that +C++ and Go define inheritance differently. In Go, structs can inherit +methods via anonymous field embedding. However, when a method is +called for an embedded struct, if that method calls any other methods, +they are called for the embedded struct, not for the original type. +Therefore, SWIG must use Go interfaces to represent C++ inheritance. +

      + +

      +In order to use the director feature in Go, you must define a type in +your Go code. You must then add methods for the type. Define a +method in Go for each C++ virtual function that you want to override. +You must then create a value of your new type, and pass a pointer to +it to the function NewDirectorClassName, +where ClassName is the name of the C++ class. That will +return a value of type ClassName. +

      + +

      +For example: +

      + +
      +
      +type GoClass struct { }
      +func (p *GoClass) VirtualFunction() { }
      +func MakeClass() ClassName {
      +	return NewDirectorClassName(&GoClass{})
      +}
      +
      +
      + +

      +Any call in C++ code to the virtual function will wind up calling the +method defined in Go. The Go code may of course call other methods on +itself, and those methods may be defined either in Go or in C++. +

      + +

      20.3.8 Default Go primitive type mappings

      + + +

      +The following table lists the default type mapping from C/C++ to Go. +This table will tell you which Go type to expect for a function which +uses a given C/C++ type. +

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      C/C++ typeGo type
      boolbool
      charbyte
      signed charint8
      unsigned charbyte
      shortint16
      unsigned shortuint16
      intint
      unsigned intuint
      longint32 or int64, depending on -long-type-size
      unsigned longuint32 or uint64, depending on -long-type-size
      long longint64
      unsigned long longuint64
      floatfloat32
      doublefloat64
      char *
      char []
      string
      + +

      +Note that SWIG wraps the C char type as a character. Pointers +and arrays of this type are wrapped as strings. The signed +char type can be used if you want to treat char as a +signed number rather than a character. Also note that all const +references to primitive types are treated as if they are passed by +value. +

      + +

      +These type mappings are defined by the "go" typemap. You may change +that typemap, or add new values, to control how C/C++ types are mapped +into Go types. +

      + + + diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index b4f332b14..d523bee77 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -113,6 +113,7 @@ can be obtained by typing swig -help or swig -clisp Generate CLISP wrappers -cffi Generate CFFI wrappers -csharp Generate C# wrappers +-go Generate Go wrappers -guile Generate Guile wrappers -java Generate Java wrappers -lua Generate Lua wrappers diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index e514f726d..8693adc07 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -36,6 +36,7 @@ Last update : SWIG-2.0.1 (in progress)
    • Allegro CL support
    • C# support
    • Chicken support
    • +
    • Go support
    • Guile support
    • Java support
    • Lua support
    • diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index bf180f1b4..cd399996b 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -17,6 +17,7 @@ CCache.html Allegrocl.html CSharp.html Chicken.html +Go.html Guile.html Java.html Lisp.html diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 9dee0347f..5960d79fb 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1141,3 +1141,74 @@ r_clean: rm -f *.@OBJEXT@ *@SO@ NAMESPACE rm -f $(RRSRC) runme.Rout .RData +################################################################## +##### Go ###### +################################################################## + +GO = @GO@ +GOGCC = @GOGCC@ + +GOSWIGARG = `if $(GOGCC) ; then echo -gccgo; fi` +GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; fi` + +GOSRCS = $(INTERFACE:.i=.go) +GOCSRCS = $(INTERFACE:.i=_gc.c) + +GOC = $(GO:g=c) +GOLD = $(GO:g=l) + +GOPACKAGE = $(INTERFACE:.i=.a) + +GOOBJEXT = $(GO:g=) +GOGCOBJS = $(GOSRCS:.go=.$(GOOBJEXT)) +GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@) + +# ---------------------------------------------------------------- +# Build a Go dynamically loadable module (C) +# ---------------------------------------------------------------- + +go: $(SRCS) + $(SWIG) -go $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) + $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) + $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(GO) -I . $(GOCOMPILEARG) $(GOSRCS) + if ! $(GOGCC) ; then \ + $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ + gopack grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + fi + +# ---------------------------------------------------------------- +# Build a Go dynamically loadable module (C++) +# ---------------------------------------------------------------- + +go_cpp: $(SRCS) + $(SWIG) -go -c++ $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) + $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(GO) -I . $(GOCOMPILEARG) $(GOSRCS) + if ! $(GOGCC) ; then \ + $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ + gopack grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + else true; fi + +# ----------------------------------------------------------------- +# Running a Go example +# ----------------------------------------------------------------- + +go_run: runme.go + $(GO) $(GOCOMPILEARG) runme.go + if $(GOGCC) ; then \ + $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(LIBPREFIX)$(TARGET)$(SO); \ + else \ + $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ + fi + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH ./runme + +# ----------------------------------------------------------------- +# Cleaning the Go examples +# ----------------------------------------------------------------- + +go_clean: + rm -f *_wrap* *_gc* .~* runme + rm -f core @EXTRA_CLEAN@ + rm -f *.@OBJEXT@ *.[568] *.a *@SO@ diff --git a/Examples/go/callback/Makefile b/Examples/go/callback/Makefile new file mode 100644 index 000000000..9dc8b8851 --- /dev/null +++ b/Examples/go/callback/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/callback/example.cxx b/Examples/go/callback/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/go/callback/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/go/callback/example.go b/Examples/go/callback/example.go new file mode 100644 index 000000000..5c0cfb051 --- /dev/null +++ b/Examples/go/callback/example.go @@ -0,0 +1,188 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +type _swig_DirectorCallback struct { + SwigcptrCallback + v interface{} +} + +func (p *_swig_DirectorCallback) Swigcptr() uintptr { + return p.SwigcptrCallback.Swigcptr() +} + +func (p *_swig_DirectorCallback) SwigIsCallback() { +} + +func (p *_swig_DirectorCallback) DirectorInterface() interface{} { + return p.v +} + +func _swig_NewDirectorCallbackCallback(*_swig_DirectorCallback) SwigcptrCallback + +func NewDirectorCallback(v interface{}) Callback { + p := &_swig_DirectorCallback{0, v} + p.SwigcptrCallback = _swig_NewDirectorCallbackCallback(p) + return p +} + +func _swig_wrap_DeleteDirectorCallback(uintptr) + +func DeleteDirectorCallback(arg1 Callback) { + _swig_wrap_DeleteDirectorCallback(arg1.Swigcptr()) +} + +func Swiggo_DeleteDirector_Callback(p *_swig_DirectorCallback) { + p.SwigcptrCallback = 0 +} + +type _swig_DirectorInterfaceCallbackRun interface { + Run() +} + +func _swig_wrap__swig_DirectorCallback_upcall_Run(SwigcptrCallback) +func (swig_p *_swig_DirectorCallback) Run() { + if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceCallbackRun); swig_ok { + swig_g.Run() + return + } + _swig_wrap__swig_DirectorCallback_upcall_Run(swig_p.SwigcptrCallback) +} + +func DirectorCallbackRun(p Callback) { + _swig_wrap__swig_DirectorCallback_upcall_Run(p.(*_swig_DirectorCallback).SwigcptrCallback) +} + +func Swig_DirectorCallback_callback_run(p *_swig_DirectorCallback) { + p.Run() +} + +type SwigcptrCallback uintptr + +func (p SwigcptrCallback) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrCallback) SwigIsCallback() { +} + +func (p SwigcptrCallback) DirectorInterface() interface{} { + return nil +} + +func _swig_wrap_delete_Callback(uintptr) + +func DeleteCallback(arg1 Callback) { + _swig_wrap_delete_Callback(arg1.Swigcptr()) +} + +func _swig_wrap_Callback_run(SwigcptrCallback) + +func (arg1 SwigcptrCallback) Run() { + _swig_wrap_Callback_run(arg1) +} + +func _swig_wrap_new_Callback() SwigcptrCallback + +func NewCallback() Callback { + return _swig_wrap_new_Callback() +} + +type Callback interface { + Swigcptr() uintptr + SwigIsCallback() + DirectorInterface() interface{} + Run() +} + +type SwigcptrCaller uintptr + +func (p SwigcptrCaller) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrCaller) SwigIsCaller() { +} + +func _swig_wrap_new_Caller() SwigcptrCaller + +func NewCaller() Caller { + return _swig_wrap_new_Caller() +} + +func _swig_wrap_delete_Caller(uintptr) + +func DeleteCaller(arg1 Caller) { + _swig_wrap_delete_Caller(arg1.Swigcptr()) +} + +func _swig_wrap_Caller_delCallback(SwigcptrCaller) + +func (arg1 SwigcptrCaller) DelCallback() { + _swig_wrap_Caller_delCallback(arg1) +} + +func _swig_wrap_Caller_setCallback(SwigcptrCaller, uintptr) + +func (arg1 SwigcptrCaller) SetCallback(arg2 Callback) { + _swig_wrap_Caller_setCallback(arg1, arg2.Swigcptr()) +} + +func _swig_wrap_Caller_call(SwigcptrCaller) + +func (arg1 SwigcptrCaller) Call() { + _swig_wrap_Caller_call(arg1) +} + +type Caller interface { + Swigcptr() uintptr + SwigIsCaller() + DelCallback() + SetCallback(arg2 Callback) + Call() +} + + +type SwigcptrSwigDirector_Callback uintptr +type SwigDirector_Callback interface { + Swigcptr() uintptr; +} +func (p SwigcptrSwigDirector_Callback) Swigcptr() uintptr { + return uintptr(p) +} + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/callback/example.h b/Examples/go/callback/example.h new file mode 100644 index 000000000..1a0e8c432 --- /dev/null +++ b/Examples/go/callback/example.h @@ -0,0 +1,23 @@ +/* File : example.h */ + +#include +#include + +class Callback { +public: + virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; } + virtual void run() { std::cout << "Callback::run()" << std::endl; } +}; + + +class Caller { +private: + Callback *_callback; +public: + Caller(): _callback(0) {} + ~Caller() { delCallback(); } + void delCallback() { delete _callback; _callback = 0; } + void setCallback(Callback *cb) { delCallback(); _callback = cb; } + void call() { if (_callback) _callback->run(); } +}; + diff --git a/Examples/go/callback/example.i b/Examples/go/callback/example.i new file mode 100644 index 000000000..90beda01a --- /dev/null +++ b/Examples/go/callback/example.i @@ -0,0 +1,13 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* turn on director wrapping Callback */ +%feature("director") Callback; + +%include "example.h" + diff --git a/Examples/go/callback/index.html b/Examples/go/callback/index.html new file mode 100644 index 000000000..b053cf547 --- /dev/null +++ b/Examples/go/callback/index.html @@ -0,0 +1,81 @@ + + +SWIG:Examples:go:callback + + + + + +SWIG/Examples/go/callback/ +
      + +

      Implementing C++ callbacks in Go

      + +

      +This example illustrates how to use directors to implement C++ +callbacks in Go. +

      + +

      +Because Go and C++ use inheritance differently, you must call a +different function to create a class which uses callbacks. Instead of +calling the usual constructor function whose name is New +followed by the capitalized name of the class, you call a function +named NewDirector followed by the capitalized name of the +class. +

      + +

      +The first argument to the NewDirector function is an instance +of a type. The NewDirector function will return an interface +value as usual. However, when calling any method on the returned +value, the program will first check whether the value passed +to NewDirector implements that method. If it does, the +method will be called in Go. This is true whether the method is +called from Go code or C++ code. +

      + +

      +Note that the Go code will be called with just the Go value, not the +C++ value. If the Go code needs to call a C++ method on itself, you +need to get a copy of the C++ object. This is typically done as +follows: + +

      +
      +type Child struct { abi Parent }
      +func (p *Child) ChildMethod() {
      +	p.abi.ParentMethod()
      +}
      +func f() {
      +	p := &Child{nil}
      +	d := NewDirectorParent(p)
      +	p.abi = d
      +	...
      +}
      +
      +
      + +In other words, we first create the Go value. We pass that to +the NewDirector function to create the C++ value; this C++ +value will be created with an association to the Go value. We then +store the C++ value in the Go value, giving us the reverse +association. That permits us to call parent methods from the child. + +

      + +

      +To delete a director object, use the function DeleteDirector +followed by the capitalized name of the class. +

      + +

      +

      + +
      + + diff --git a/Examples/go/callback/runme.go b/Examples/go/callback/runme.go new file mode 100644 index 000000000..ffa4b3874 --- /dev/null +++ b/Examples/go/callback/runme.go @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + . "./example" +) + +func main() { + fmt.Println("Adding and calling a normal C++ callback") + fmt.Println("----------------------------------------") + + caller := NewCaller() + callback := NewCallback() + + caller.SetCallback(callback) + caller.Call() + caller.DelCallback() + + callback = NewDirectorCallback(new(GoCallback)) + + fmt.Println() + fmt.Println("Adding and calling a Go callback") + fmt.Println("------------------------------------") + + caller.SetCallback(callback) + caller.Call() + caller.DelCallback() + + // Test that a double delete does not occur as the object has + // already been deleted from the C++ layer. + DeleteDirectorCallback(callback) + + fmt.Println() + fmt.Println("Go exit") +} + +type GoCallback struct{} + +func (p *GoCallback) Run() { + fmt.Println("GoCallback.Run") +} diff --git a/Examples/go/check.list b/Examples/go/check.list new file mode 100644 index 000000000..5399b8979 --- /dev/null +++ b/Examples/go/check.list @@ -0,0 +1,13 @@ +# see top-level Makefile.in +callback +class +constants +enum +extend +funcptr +multimap +pointer +reference +simple +template +variables diff --git a/Examples/go/class/Makefile b/Examples/go/class/Makefile new file mode 100644 index 000000000..53d31d1a4 --- /dev/null +++ b/Examples/go/class/Makefile @@ -0,0 +1,16 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +LIBS = -lm + +all:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/class/example.cxx b/Examples/go/class/example.cxx new file mode 100644 index 000000000..1e8e203dd --- /dev/null +++ b/Examples/go/class/example.cxx @@ -0,0 +1,28 @@ +/* File : example.c */ + +#include "example.h" +#define M_PI 3.14159265358979323846 + +/* Move the shape to a new location */ +void Shape::move(double dx, double dy) { + x += dx; + y += dy; +} + +int Shape::nshapes = 0; + +double Circle::area(void) { + return M_PI*radius*radius; +} + +double Circle::perimeter(void) { + return 2*M_PI*radius; +} + +double Square::area(void) { + return width*width; +} + +double Square::perimeter(void) { + return 4*width; +} diff --git a/Examples/go/class/example.go b/Examples/go/class/example.go new file mode 100644 index 000000000..ec8113ad4 --- /dev/null +++ b/Examples/go/class/example.go @@ -0,0 +1,284 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +type SwigcptrShape uintptr + +func (p SwigcptrShape) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrShape) SwigIsShape() { +} + +func _swig_wrap_delete_Shape(uintptr) + +func DeleteShape(arg1 Shape) { + _swig_wrap_delete_Shape(arg1.Swigcptr()) +} + +func _swig_wrap_Shape_x_set(SwigcptrShape, float64) + +func (arg1 SwigcptrShape) SetX(arg2 float64) { + _swig_wrap_Shape_x_set(arg1, arg2) +} + +func _swig_wrap_Shape_x_get(SwigcptrShape) float64 + +func (arg1 SwigcptrShape) GetX() float64 { + return _swig_wrap_Shape_x_get(arg1) +} + +func _swig_wrap_Shape_y_set(SwigcptrShape, float64) + +func (arg1 SwigcptrShape) SetY(arg2 float64) { + _swig_wrap_Shape_y_set(arg1, arg2) +} + +func _swig_wrap_Shape_y_get(SwigcptrShape) float64 + +func (arg1 SwigcptrShape) GetY() float64 { + return _swig_wrap_Shape_y_get(arg1) +} + +func _swig_wrap_Shape_move(SwigcptrShape, float64, float64) + +func (arg1 SwigcptrShape) Move(arg2 float64, arg3 float64) { + _swig_wrap_Shape_move(arg1, arg2, arg3) +} + +func _swig_wrap_Shape_area(SwigcptrShape) float64 + +func (arg1 SwigcptrShape) Area() float64 { + return _swig_wrap_Shape_area(arg1) +} + +func _swig_wrap_Shape_perimeter(SwigcptrShape) float64 + +func (arg1 SwigcptrShape) Perimeter() float64 { + return _swig_wrap_Shape_perimeter(arg1) +} + +func _swig_wrap_Shape_nshapes_set(int) + +func SetShapeNshapes(arg1 int) { + _swig_wrap_Shape_nshapes_set(arg1) +} + +func GetShapeNshapes() int +type Shape interface { + Swigcptr() uintptr + SwigIsShape() + SetX(arg2 float64) + GetX() float64 + SetY(arg2 float64) + GetY() float64 + Move(arg2 float64, arg3 float64) + Area() float64 + Perimeter() float64 +} + +type SwigcptrCircle uintptr + +func (p SwigcptrCircle) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrCircle) SwigIsCircle() { +} + +func _swig_wrap_new_Circle(float64) SwigcptrCircle + +func NewCircle(arg1 float64) Circle { + return _swig_wrap_new_Circle(arg1) +} + +func _swig_wrap_Circle_area(SwigcptrCircle) float64 + +func (arg1 SwigcptrCircle) Area() float64 { + return _swig_wrap_Circle_area(arg1) +} + +func _swig_wrap_Circle_perimeter(SwigcptrCircle) float64 + +func (arg1 SwigcptrCircle) Perimeter() float64 { + return _swig_wrap_Circle_perimeter(arg1) +} + +func _swig_wrap_delete_Circle(uintptr) + +func DeleteCircle(arg1 Circle) { + _swig_wrap_delete_Circle(arg1.Swigcptr()) +} + +func _swig_wrap_SetCircle_X(SwigcptrCircle, float64) + +func (_swig_base SwigcptrCircle) SetX(arg1 float64) { + _swig_wrap_SetCircle_X(_swig_base, arg1) +} + +func _swig_wrap_GetCircle_X(SwigcptrCircle) float64 + +func (_swig_base SwigcptrCircle) GetX() float64 { + return _swig_wrap_GetCircle_X(_swig_base) +} + +func _swig_wrap_SetCircle_Y(SwigcptrCircle, float64) + +func (_swig_base SwigcptrCircle) SetY(arg1 float64) { + _swig_wrap_SetCircle_Y(_swig_base, arg1) +} + +func _swig_wrap_GetCircle_Y(SwigcptrCircle) float64 + +func (_swig_base SwigcptrCircle) GetY() float64 { + return _swig_wrap_GetCircle_Y(_swig_base) +} + +func _swig_wrap_Circle_move(SwigcptrCircle, float64, float64) + +func (_swig_base SwigcptrCircle) Move(arg1 float64, arg2 float64) { + _swig_wrap_Circle_move(_swig_base, arg1, arg2) +} + +func (p SwigcptrCircle) SwigIsShape() { +} + +func (p SwigcptrCircle) SwigGetShape() Shape { + return SwigcptrShape(p.Swigcptr()) +} + +type Circle interface { + Swigcptr() uintptr + SwigIsCircle() + Area() float64 + Perimeter() float64 + SetX(arg1 float64) + GetX() float64 + SetY(arg1 float64) + GetY() float64 + Move(arg1 float64, arg2 float64) + SwigIsShape() + SwigGetShape() Shape +} + +type SwigcptrSquare uintptr + +func (p SwigcptrSquare) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrSquare) SwigIsSquare() { +} + +func _swig_wrap_new_Square(float64) SwigcptrSquare + +func NewSquare(arg1 float64) Square { + return _swig_wrap_new_Square(arg1) +} + +func _swig_wrap_Square_area(SwigcptrSquare) float64 + +func (arg1 SwigcptrSquare) Area() float64 { + return _swig_wrap_Square_area(arg1) +} + +func _swig_wrap_Square_perimeter(SwigcptrSquare) float64 + +func (arg1 SwigcptrSquare) Perimeter() float64 { + return _swig_wrap_Square_perimeter(arg1) +} + +func _swig_wrap_delete_Square(uintptr) + +func DeleteSquare(arg1 Square) { + _swig_wrap_delete_Square(arg1.Swigcptr()) +} + +func _swig_wrap_SetSquare_X(SwigcptrSquare, float64) + +func (_swig_base SwigcptrSquare) SetX(arg1 float64) { + _swig_wrap_SetSquare_X(_swig_base, arg1) +} + +func _swig_wrap_GetSquare_X(SwigcptrSquare) float64 + +func (_swig_base SwigcptrSquare) GetX() float64 { + return _swig_wrap_GetSquare_X(_swig_base) +} + +func _swig_wrap_SetSquare_Y(SwigcptrSquare, float64) + +func (_swig_base SwigcptrSquare) SetY(arg1 float64) { + _swig_wrap_SetSquare_Y(_swig_base, arg1) +} + +func _swig_wrap_GetSquare_Y(SwigcptrSquare) float64 + +func (_swig_base SwigcptrSquare) GetY() float64 { + return _swig_wrap_GetSquare_Y(_swig_base) +} + +func _swig_wrap_Square_move(SwigcptrSquare, float64, float64) + +func (_swig_base SwigcptrSquare) Move(arg1 float64, arg2 float64) { + _swig_wrap_Square_move(_swig_base, arg1, arg2) +} + +func (p SwigcptrSquare) SwigIsShape() { +} + +func (p SwigcptrSquare) SwigGetShape() Shape { + return SwigcptrShape(p.Swigcptr()) +} + +type Square interface { + Swigcptr() uintptr + SwigIsSquare() + Area() float64 + Perimeter() float64 + SetX(arg1 float64) + GetX() float64 + SetY(arg1 float64) + GetY() float64 + Move(arg1 float64, arg2 float64) + SwigIsShape() + SwigGetShape() Shape +} + + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/class/example.h b/Examples/go/class/example.h new file mode 100644 index 000000000..46d901361 --- /dev/null +++ b/Examples/go/class/example.h @@ -0,0 +1,39 @@ +/* File : example.h */ + +class Shape { +public: + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + }; + double x, y; + void move(double dx, double dy); + virtual double area(void) = 0; + virtual double perimeter(void) = 0; + static int nshapes; +}; + +class Circle : public Shape { +private: + double radius; +public: + Circle(double r) : radius(r) { }; + virtual double area(void); + virtual double perimeter(void); +}; + +class Square : public Shape { +private: + double width; +public: + Square(double w) : width(w) { }; + virtual double area(void); + virtual double perimeter(void); +}; + + + + + diff --git a/Examples/go/class/example.i b/Examples/go/class/example.i new file mode 100644 index 000000000..75700b305 --- /dev/null +++ b/Examples/go/class/example.i @@ -0,0 +1,10 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" + diff --git a/Examples/go/class/index.html b/Examples/go/class/index.html new file mode 100644 index 000000000..b39119d12 --- /dev/null +++ b/Examples/go/class/index.html @@ -0,0 +1,203 @@ + + +SWIG:Examples:go:class + + + + + +SWIG/Examples/go/class/ +
      + +

      Wrapping a simple C++ class

      + +

      +This example illustrates the most primitive form of C++ class wrapping +performed by SWIG. In this case, C++ classes are simply transformed +into a collection of C-style functions that provide access to class +members. + +

      The C++ Code

      + +Suppose you have some C++ classes described by the following (and +admittedly lame) header file: + +
      +
      +/* File : example.h */
      +
      +class Shape {
      +public:
      +  Shape() {
      +    nshapes++;
      +  }
      +  virtual ~Shape() {
      +    nshapes--;
      +  };
      +  double  x, y;   
      +  void    move(double dx, double dy);
      +  virtual double area() = 0;
      +  virtual double perimeter() = 0;
      +  static  int nshapes;
      +};
      +
      +class Circle : public Shape {
      +private:
      +  double radius;
      +public:
      +  Circle(double r) : radius(r) { };
      +  virtual double area();
      +  virtual double perimeter();
      +};
      +
      +class Square : public Shape {
      +private:
      +  double width;
      +public:
      +  Square(double w) : width(w) { };
      +  virtual double area();
      +  virtual double perimeter();
      +};
      +
      +
      + +

      The SWIG interface

      + +A simple SWIG interface for this can be built by simply grabbing the +header file like this: + +
      +
      +/* File : example.i */
      +%module example
      +
      +%{
      +#include "example.h"
      +%}
      +
      +/* Let's just grab the original header file here */
      +%include "example.h"
      +
      +
      + +Note: when creating a C++ extension, you must run SWIG with +the -c++ option like this: +
      +
      +% swig -c++ -go example.i
      +
      +
      + +

      A sample Go script

      + +See example.go for a program that calls the +C++ functions from Go. + +

      Key points

      + +
        +
      • To create a new object, you call a constructor like this: + +
        +
        +c := example.NewCircle(10.0)
        +
        +
        + +The name of the constructor is New followed by the name of +the class, capitalized. + +

        +

      • +The constructor returns a value of interface type. The methods of the +interface will be the methods of the C++ class, plus member accessor +functions. + +

        +

      • To access member data, a pair of accessor methods are used. For +example: + +
        +
        +c.SetX(15)          # Set member data
        +x := c.GetX()       # Get member data.
        +
        +
        + +These are methods on the type returned by the constructor. The getter +is named Get followed by the name of the member, +capitalized. The setter is similar but uses Set. + +

        +

      • To invoke a member function, you simply do this + +
        +
        +fmt.Println("The area is", example.c.Area())
        +
        +
        + +
      • To invoke a destructor, simply do this + +
        +
        +example.DeleteShape(c)     # Deletes a shape
        +
        +
        + +The name of the destructor is Delete followed by the name of +the class, capitalized. (Note: destructors are currently not +inherited. This might change later). + +

        +

      • Static member variables are wrapped much like C global variables. +For example: + +
        +
        +n := GetShapeNshapes()     # Get a static data member
        +SetShapeNshapes(13)        # Set a static data member
        +
        +
        + +The name is Get or Set, followed by the name of the +class, capitalized, followed by the name of the member, capitalized. + +
      + +

      General Comments

      + +
        +
      • This low-level interface is not the only way to handle C++ code. +Director classes provide a much higher-level interface. + +

        +

      • Because C++ and Go implement inheritance quite differently, you +can not simply upcast an object in Go code when using multiple +inheritance. When using only single inheritance, you can simply pass +a class to a function expecting a parent class. When using multiple +inheritance, you have to call an automatically generated getter +function named Get followed by the capitalized name of the +immediate parent. This will return the same object converted to the + parent class. + +

        +

      • +Overloaded methods should normally work. However, when calling an +overloaded method you must explicitly convert constants to the +expected type when it is not int or float. In +particular, a floating point constant will default to +type float, but C++ functions typically expect the C++ +type double which is equivalent to the Go +type float64 So calling an overloaded method with a floating +point constant typically requires an explicit conversion +to float64. + +

        +

      • Namespaces are not supported in any very coherent way. + +
      + +
      + + diff --git a/Examples/go/class/runme.go b/Examples/go/class/runme.go new file mode 100644 index 000000000..ff64bb4be --- /dev/null +++ b/Examples/go/class/runme.go @@ -0,0 +1,63 @@ +// This example illustrates how C++ classes can be used from Go using SWIG. + +package main + +import ( + "fmt" + . "./example" +) + +func main() { + // ----- Object creation ----- + + fmt.Println("Creating some objects:") + c := NewCircle(10) + fmt.Println(" Created circle", c) + s := NewSquare(10) + fmt.Println(" Created square", s) + + // ----- Access a static member ----- + + fmt.Println("\nA total of", GetShapeNshapes(), "shapes were created") + + // ----- Member data access ----- + + // Notice how we can do this using functions specific to + // the 'Circle' class. + c.SetX(20) + c.SetY(30) + + // Now use the same functions in the base class + var shape Shape = s + shape.SetX(-10) + shape.SetY(5) + + fmt.Println("\nHere is their current position:") + fmt.Println(" Circle = (", c.GetX(), " ", c.GetY(), ")") + fmt.Println(" Square = (", s.GetX(), " ", s.GetY(), ")") + + // ----- Call some methods ----- + + fmt.Println("\nHere are some properties of the shapes:") + shapes := []Shape{c, s} + for i := 0; i < len(shapes); i++ { + fmt.Println(" ", shapes[i]) + fmt.Println(" area = ", shapes[i].Area()) + fmt.Println(" perimeter = ", shapes[i].Perimeter()) + } + + // Notice how the area() and perimeter() functions really + // invoke the appropriate virtual method on each object. + + // ----- Delete everything ----- + + fmt.Println("\nGuess I'll clean up now") + + // Note: this invokes the virtual destructor + // You could leave this to the garbage collector + DeleteCircle(c) + DeleteSquare(s) + + fmt.Println(GetShapeNshapes(), " shapes remain") + fmt.Println("Goodbye") +} diff --git a/Examples/go/constants/Makefile b/Examples/go/constants/Makefile new file mode 100644 index 000000000..71d4d73a4 --- /dev/null +++ b/Examples/go/constants/Makefile @@ -0,0 +1,16 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/constants/example.go b/Examples/go/constants/example.go new file mode 100644 index 000000000..0e5e66418 --- /dev/null +++ b/Examples/go/constants/example.go @@ -0,0 +1,44 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +const ICONST int = 42 +const FCONST float64 = 2.1828 +const CCONST byte = 'x' +func _swig_getCCONST2() byte +var CCONST2 byte = _swig_getCCONST2() +const SCONST string = "Hello World" +func _swig_getSCONST2() string +var SCONST2 string = _swig_getSCONST2() +func _swig_getEXPR() float64 +var EXPR float64 = _swig_getEXPR() +const Iconst int = 37 +const Fconst float64 = 3.14 + diff --git a/Examples/go/constants/example.i b/Examples/go/constants/example.i new file mode 100644 index 000000000..daca042df --- /dev/null +++ b/Examples/go/constants/example.i @@ -0,0 +1,25 @@ +/* File : example.i */ +%module example + +/* A few preprocessor macros */ + +#define ICONST 42 +#define FCONST 2.1828 +#define CCONST 'x' +#define CCONST2 '\n' +#define SCONST "Hello World" +#define SCONST2 "\"Hello World\"" + +/* This should work just fine */ +#define EXPR ICONST + 3*(FCONST) + +/* This shouldn't do anything */ +#define EXTERN extern + +/* Neither should this (BAR isn't defined) */ +#define FOO (ICONST + BAR) + +/* The following directives also produce constants */ + +%constant int iconst = 37; +%constant double fconst = 3.14; diff --git a/Examples/go/constants/index.html b/Examples/go/constants/index.html new file mode 100644 index 000000000..b1397ab2d --- /dev/null +++ b/Examples/go/constants/index.html @@ -0,0 +1,55 @@ + + +SWIG:Examples:go:constants + + + + +SWIG/Examples/go/constants/ +
      + +

      Wrapping C Constants

      + +

      +When SWIG encounters C preprocessor macros and C declarations that +look like constants, it creates a Go constant with an identical value. +Click here to see a SWIG interface with some +constant declarations in it. + + +

      Accessing Constants from Go

      +Click here for +the section on constants in the SWIG and Go documentation. +

      + +Click here to see a Go program that prints out +the values of the constants contained in the above file.

      +

      Key points

      +
        +
      • All names are capitalized to make them visible. +
      • The values of preprocessor macros are converted into Go constants. +
      • C string literals such as "Hello World" are converted into Go strings. +
      • Macros that are not fully defined are simply ignored. For example: +
        +
        +#define EXTERN extern
        +
        +
        +is ignored because SWIG has no idea what type of variable this would be. + +

        +

      • Expressions are allowed provided that all of their components are +defined. Otherwise, the constant is ignored. + +
      • Certain C declarations involving 'const' are also turned into Go +constants. +
      • The constants that appear in a SWIG interface file do not have to +appear in any sort of matching C source file since the creation of a +constant does not require linkage to a stored value (i.e., a value +held in a C global variable or memory location). +
      + +
      + + + diff --git a/Examples/go/constants/runme.go b/Examples/go/constants/runme.go new file mode 100644 index 000000000..78a047e20 --- /dev/null +++ b/Examples/go/constants/runme.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "./example" +) + +func main() { + fmt.Println("ICONST = ", example.ICONST, " (should be 42)") + fmt.Println("FCONST = ", example.FCONST, " (should be 2.1828)") + fmt.Printf("CCONST = %c (should be 'x')\n", example.CCONST) + fmt.Printf("CCONST2 = %c(this should be on a new line)\n", example.CCONST2) + fmt.Println("SCONST = ", example.SCONST, " (should be 'Hello World')") + fmt.Println("SCONST2 = ", example.SCONST2, " (should be '\"Hello World\"')") + fmt.Println("EXPR = ", example.EXPR, " (should be 48.5484)") + fmt.Println("iconst = ", example.Iconst, " (should be 37)") + fmt.Println("fconst = ", example.Fconst, " (should be 3.14)") +} diff --git a/Examples/go/enum/Makefile b/Examples/go/enum/Makefile new file mode 100644 index 000000000..9dc8b8851 --- /dev/null +++ b/Examples/go/enum/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/enum/example.cxx b/Examples/go/enum/example.cxx new file mode 100644 index 000000000..df7bb6328 --- /dev/null +++ b/Examples/go/enum/example.cxx @@ -0,0 +1,37 @@ +/* File : example.cxx */ + +#include "example.h" +#include + +void Foo::enum_test(speed s) { + if (s == IMPULSE) { + printf("IMPULSE speed\n"); + } else if (s == WARP) { + printf("WARP speed\n"); + } else if (s == LUDICROUS) { + printf("LUDICROUS speed\n"); + } else { + printf("Unknown speed\n"); + } +} + +void enum_test(color c, Foo::speed s) { + if (c == RED) { + printf("color = RED, "); + } else if (c == BLUE) { + printf("color = BLUE, "); + } else if (c == GREEN) { + printf("color = GREEN, "); + } else { + printf("color = Unknown color!, "); + } + if (s == Foo::IMPULSE) { + printf("speed = IMPULSE speed\n"); + } else if (s == Foo::WARP) { + printf("speed = WARP speed\n"); + } else if (s == Foo::LUDICROUS) { + printf("speed = LUDICROUS speed\n"); + } else { + printf("speed = Unknown speed!\n"); + } +} diff --git a/Examples/go/enum/example.go b/Examples/go/enum/example.go new file mode 100644 index 000000000..4653ab57a --- /dev/null +++ b/Examples/go/enum/example.go @@ -0,0 +1,93 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +type Color int +func _swig_getRED() Color +var RED Color = _swig_getRED() +func _swig_getBLUE() Color +var BLUE Color = _swig_getBLUE() +func _swig_getGREEN() Color +var GREEN Color = _swig_getGREEN() +type SwigcptrFoo uintptr + +func (p SwigcptrFoo) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrFoo) SwigIsFoo() { +} + +func _swig_wrap_new_Foo() SwigcptrFoo + +func NewFoo() Foo { + return _swig_wrap_new_Foo() +} + +type FooSpeed int +func _swig_getFoo_IMPULSE_Foo() FooSpeed +var FooIMPULSE FooSpeed = _swig_getFoo_IMPULSE_Foo() +func _swig_getFoo_WARP_Foo() FooSpeed +var FooWARP FooSpeed = _swig_getFoo_WARP_Foo() +func _swig_getFoo_LUDICROUS_Foo() FooSpeed +var FooLUDICROUS FooSpeed = _swig_getFoo_LUDICROUS_Foo() +func _swig_wrap_Foo_enum_test(SwigcptrFoo, FooSpeed) + +func (arg1 SwigcptrFoo) Enum_test(arg2 FooSpeed) { + _swig_wrap_Foo_enum_test(arg1, arg2) +} + +func _swig_wrap_delete_Foo(uintptr) + +func DeleteFoo(arg1 Foo) { + _swig_wrap_delete_Foo(arg1.Swigcptr()) +} + +type Foo interface { + Swigcptr() uintptr + SwigIsFoo() + Enum_test(arg2 FooSpeed) +} + +func _swig_wrap_enum_test(Color, FooSpeed) + +func Enum_test(arg1 Color, arg2 FooSpeed) { + _swig_wrap_enum_test(arg1, arg2) +} + + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/enum/example.h b/Examples/go/enum/example.h new file mode 100644 index 000000000..9119cd9fc --- /dev/null +++ b/Examples/go/enum/example.h @@ -0,0 +1,13 @@ +/* File : example.h */ + +enum color { RED, BLUE, GREEN }; + +class Foo { + public: + Foo() { } + enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 }; + void enum_test(speed s); +}; + +void enum_test(color c, Foo::speed s); + diff --git a/Examples/go/enum/example.i b/Examples/go/enum/example.i new file mode 100644 index 000000000..23ee8a822 --- /dev/null +++ b/Examples/go/enum/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ + +%include "example.h" + diff --git a/Examples/go/enum/index.html b/Examples/go/enum/index.html new file mode 100644 index 000000000..868efe6ad --- /dev/null +++ b/Examples/go/enum/index.html @@ -0,0 +1,42 @@ + + +SWIG:Examples:go:enum + + + + + +SWIG/Examples/go/enum/ +
      + +

      Wrapping enumerations

      + +

      +This example tests SWIG's ability to wrap enumerations. +

        +
      • +Enum values are expressed as constants or variables in GO. +
      • +If the enum is named, then that name, capitalized, as defined as a new +type name for int. All the enum values will be defined to +have that type. +
      • +If the enum is declared at global level, then the name in Go is simply +the enum value, capitalized. +
      • +If the enum is declared within a C++ class or struct, then the name in +Go is the capitalized name of the class or struct followed by the +capitalized name of the enum value. +
      • +
      + +

      +

      + +
      + + diff --git a/Examples/go/enum/runme.go b/Examples/go/enum/runme.go new file mode 100644 index 000000000..419df5f93 --- /dev/null +++ b/Examples/go/enum/runme.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + . "./example" +) + +func main() { + // Print out the value of some enums + fmt.Println("*** color ***") + fmt.Println(" RED = ", RED) + fmt.Println(" BLUE = ", BLUE) + fmt.Println(" GREEN = ", GREEN) + + fmt.Println("\n*** Foo::speed ***") + fmt.Println(" Foo::IMPULSE = ", FooIMPULSE) + fmt.Println(" Foo::WARP = ", FooWARP) + fmt.Println(" Foo::LUDICROUS = ", FooLUDICROUS) + + fmt.Println("\nTesting use of enums with functions\n") + + Enum_test(RED, FooIMPULSE) + Enum_test(BLUE, FooWARP) + Enum_test(GREEN, FooLUDICROUS) + + fmt.Println("\nTesting use of enum with class method") + f := NewFoo() + + f.Enum_test(FooIMPULSE) + f.Enum_test(FooWARP) + f.Enum_test(FooLUDICROUS) +} diff --git a/Examples/go/extend/Makefile b/Examples/go/extend/Makefile new file mode 100644 index 000000000..9dc8b8851 --- /dev/null +++ b/Examples/go/extend/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/extend/example.cxx b/Examples/go/extend/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/go/extend/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/go/extend/example.go b/Examples/go/extend/example.go new file mode 100644 index 000000000..08f21e6ab --- /dev/null +++ b/Examples/go/extend/example.go @@ -0,0 +1,397 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +type _swig_DirectorEmployee struct { + SwigcptrEmployee + v interface{} +} + +func (p *_swig_DirectorEmployee) Swigcptr() uintptr { + return p.SwigcptrEmployee.Swigcptr() +} + +func (p *_swig_DirectorEmployee) SwigIsEmployee() { +} + +func (p *_swig_DirectorEmployee) DirectorInterface() interface{} { + return p.v +} + +func _swig_NewDirectorEmployeeEmployee(*_swig_DirectorEmployee, string) SwigcptrEmployee + +func NewDirectorEmployee(v interface{}, arg1 string) Employee { + p := &_swig_DirectorEmployee{0, v} + p.SwigcptrEmployee = _swig_NewDirectorEmployeeEmployee(p, arg1) + return p +} + +type _swig_DirectorInterfaceEmployeeGetTitle interface { + GetTitle() string +} + +func _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(SwigcptrEmployee) string +func (swig_p *_swig_DirectorEmployee) GetTitle() string { + if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetTitle); swig_ok { + return swig_g.GetTitle() + } + return _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(swig_p.SwigcptrEmployee) +} + +func DirectorEmployeeGetTitle(p Employee) string { + return _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(p.(*_swig_DirectorEmployee).SwigcptrEmployee) +} + +func Swig_DirectorEmployee_callback_getTitle(p *_swig_DirectorEmployee) (swig_result string) { + return p.GetTitle() +} + +type _swig_DirectorInterfaceEmployeeGetName interface { + GetName() string +} + +func _swig_wrap__swig_DirectorEmployee_upcall_GetName(SwigcptrEmployee) string +func (swig_p *_swig_DirectorEmployee) GetName() string { + if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetName); swig_ok { + return swig_g.GetName() + } + return _swig_wrap__swig_DirectorEmployee_upcall_GetName(swig_p.SwigcptrEmployee) +} + +func DirectorEmployeeGetName(p Employee) string { + return _swig_wrap__swig_DirectorEmployee_upcall_GetName(p.(*_swig_DirectorEmployee).SwigcptrEmployee) +} + +func Swig_DirectorEmployee_callback_getName(p *_swig_DirectorEmployee) (swig_result string) { + return p.GetName() +} + +type _swig_DirectorInterfaceEmployeeGetPosition interface { + GetPosition() string +} + +func _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(SwigcptrEmployee) string +func (swig_p *_swig_DirectorEmployee) GetPosition() string { + if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetPosition); swig_ok { + return swig_g.GetPosition() + } + return _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(swig_p.SwigcptrEmployee) +} + +func DirectorEmployeeGetPosition(p Employee) string { + return _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(p.(*_swig_DirectorEmployee).SwigcptrEmployee) +} + +func Swig_DirectorEmployee_callback_getPosition(p *_swig_DirectorEmployee) (swig_result string) { + return p.GetPosition() +} + +func _swig_wrap_DeleteDirectorEmployee(uintptr) + +func DeleteDirectorEmployee(arg1 Employee) { + _swig_wrap_DeleteDirectorEmployee(arg1.Swigcptr()) +} + +func Swiggo_DeleteDirector_Employee(p *_swig_DirectorEmployee) { + p.SwigcptrEmployee = 0 +} + +type SwigcptrEmployee uintptr + +func (p SwigcptrEmployee) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrEmployee) SwigIsEmployee() { +} + +func (p SwigcptrEmployee) DirectorInterface() interface{} { + return nil +} + +func _swig_wrap_new_Employee(string) SwigcptrEmployee + +func NewEmployee(arg1 string) Employee { + return _swig_wrap_new_Employee(arg1) +} + +func _swig_wrap_Employee_getTitle(SwigcptrEmployee) string + +func (arg1 SwigcptrEmployee) GetTitle() string { + return _swig_wrap_Employee_getTitle(arg1) +} + +func _swig_wrap_Employee_getName(SwigcptrEmployee) string + +func (arg1 SwigcptrEmployee) GetName() string { + return _swig_wrap_Employee_getName(arg1) +} + +func _swig_wrap_Employee_getPosition(SwigcptrEmployee) string + +func (arg1 SwigcptrEmployee) GetPosition() string { + return _swig_wrap_Employee_getPosition(arg1) +} + +func _swig_wrap_delete_Employee(uintptr) + +func DeleteEmployee(arg1 Employee) { + _swig_wrap_delete_Employee(arg1.Swigcptr()) +} + +type Employee interface { + Swigcptr() uintptr + SwigIsEmployee() + DirectorInterface() interface{} + GetTitle() string + GetName() string + GetPosition() string +} + +type _swig_DirectorManager struct { + SwigcptrManager + v interface{} +} + +func (p *_swig_DirectorManager) Swigcptr() uintptr { + return p.SwigcptrManager.Swigcptr() +} + +func (p *_swig_DirectorManager) SwigIsManager() { +} + +func (p *_swig_DirectorManager) DirectorInterface() interface{} { + return p.v +} + +func _swig_NewDirectorManagerManager(*_swig_DirectorManager, string) SwigcptrManager + +func NewDirectorManager(v interface{}, arg1 string) Manager { + p := &_swig_DirectorManager{0, v} + p.SwigcptrManager = _swig_NewDirectorManagerManager(p, arg1) + return p +} + +type _swig_DirectorInterfaceManagerGetTitle interface { + GetTitle() string +} + +func _swig_wrap__swig_DirectorManager_upcall_GetTitle(SwigcptrManager) string +func (swig_p *_swig_DirectorManager) GetTitle() string { + if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetTitle); swig_ok { + return swig_g.GetTitle() + } + return _swig_wrap__swig_DirectorManager_upcall_GetTitle(swig_p.SwigcptrManager) +} + +func DirectorManagerGetTitle(p Manager) string { + return _swig_wrap__swig_DirectorManager_upcall_GetTitle(p.(*_swig_DirectorManager).SwigcptrManager) +} + +func Swig_DirectorManager_callback_getTitle(p *_swig_DirectorManager) (swig_result string) { + return p.GetTitle() +} + +type _swig_DirectorInterfaceManagerGetName interface { + GetName() string +} + +func _swig_wrap__swig_DirectorManager_upcall_GetName(SwigcptrManager) string +func (swig_p *_swig_DirectorManager) GetName() string { + if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetName); swig_ok { + return swig_g.GetName() + } + return _swig_wrap__swig_DirectorManager_upcall_GetName(swig_p.SwigcptrManager) +} + +func DirectorManagerGetName(p Manager) string { + return _swig_wrap__swig_DirectorManager_upcall_GetName(p.(*_swig_DirectorManager).SwigcptrManager) +} + +func Swig_DirectorManager_callback_getName(p *_swig_DirectorManager) (swig_result string) { + return p.GetName() +} + +type _swig_DirectorInterfaceManagerGetPosition interface { + GetPosition() string +} + +func _swig_wrap__swig_DirectorManager_upcall_GetPosition(SwigcptrManager) string +func (swig_p *_swig_DirectorManager) GetPosition() string { + if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetPosition); swig_ok { + return swig_g.GetPosition() + } + return _swig_wrap__swig_DirectorManager_upcall_GetPosition(swig_p.SwigcptrManager) +} + +func DirectorManagerGetPosition(p Manager) string { + return _swig_wrap__swig_DirectorManager_upcall_GetPosition(p.(*_swig_DirectorManager).SwigcptrManager) +} + +func Swig_DirectorManager_callback_getPosition(p *_swig_DirectorManager) (swig_result string) { + return p.GetPosition() +} + +func _swig_wrap_DeleteDirectorManager(uintptr) + +func DeleteDirectorManager(arg1 Manager) { + _swig_wrap_DeleteDirectorManager(arg1.Swigcptr()) +} + +func Swiggo_DeleteDirector_Manager(p *_swig_DirectorManager) { + p.SwigcptrManager = 0 +} + +type SwigcptrManager uintptr + +func (p SwigcptrManager) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrManager) SwigIsManager() { +} + +func (p SwigcptrManager) DirectorInterface() interface{} { + return nil +} + +func _swig_wrap_new_Manager(string) SwigcptrManager + +func NewManager(arg1 string) Manager { + return _swig_wrap_new_Manager(arg1) +} + +func _swig_wrap_Manager_getPosition(SwigcptrManager) string + +func (arg1 SwigcptrManager) GetPosition() string { + return _swig_wrap_Manager_getPosition(arg1) +} + +func _swig_wrap_delete_Manager(uintptr) + +func DeleteManager(arg1 Manager) { + _swig_wrap_delete_Manager(arg1.Swigcptr()) +} + +func _swig_wrap_Manager_getTitle(SwigcptrManager) string + +func (_swig_base SwigcptrManager) GetTitle() string { + return _swig_wrap_Manager_getTitle(_swig_base) +} + +func _swig_wrap_Manager_getName(SwigcptrManager) string + +func (_swig_base SwigcptrManager) GetName() string { + return _swig_wrap_Manager_getName(_swig_base) +} + +func (p SwigcptrManager) SwigIsEmployee() { +} + +func (p SwigcptrManager) SwigGetEmployee() Employee { + return SwigcptrEmployee(p.Swigcptr()) +} + +type Manager interface { + Swigcptr() uintptr + SwigIsManager() + DirectorInterface() interface{} + GetPosition() string + GetTitle() string + GetName() string + SwigIsEmployee() + SwigGetEmployee() Employee +} + +type SwigcptrEmployeeList uintptr + +func (p SwigcptrEmployeeList) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrEmployeeList) SwigIsEmployeeList() { +} + +func _swig_wrap_new_EmployeeList() SwigcptrEmployeeList + +func NewEmployeeList() EmployeeList { + return _swig_wrap_new_EmployeeList() +} + +func _swig_wrap_EmployeeList_addEmployee(SwigcptrEmployeeList, uintptr) + +func (arg1 SwigcptrEmployeeList) AddEmployee(arg2 Employee) { + _swig_wrap_EmployeeList_addEmployee(arg1, arg2.Swigcptr()) +} + +func _swig_wrap_EmployeeList_get_item(SwigcptrEmployeeList, int) SwigcptrEmployee + +func (arg1 SwigcptrEmployeeList) Get_item(arg2 int) Employee { + return _swig_wrap_EmployeeList_get_item(arg1, arg2) +} + +func _swig_wrap_delete_EmployeeList(uintptr) + +func DeleteEmployeeList(arg1 EmployeeList) { + _swig_wrap_delete_EmployeeList(arg1.Swigcptr()) +} + +type EmployeeList interface { + Swigcptr() uintptr + SwigIsEmployeeList() + AddEmployee(arg2 Employee) + Get_item(arg2 int) Employee +} + + +type SwigcptrSwigDirector_Manager uintptr +type SwigDirector_Manager interface { + Swigcptr() uintptr; +} +func (p SwigcptrSwigDirector_Manager) Swigcptr() uintptr { + return uintptr(p) +} + +type SwigcptrSwigDirector_Employee uintptr +type SwigDirector_Employee interface { + Swigcptr() uintptr; +} +func (p SwigcptrSwigDirector_Employee) Swigcptr() uintptr { + return uintptr(p) +} + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/extend/example.h b/Examples/go/extend/example.h new file mode 100644 index 000000000..b27ab9711 --- /dev/null +++ b/Examples/go/extend/example.h @@ -0,0 +1,56 @@ +/* File : example.h */ + +#include +#include +#include +#include +#include + +class Employee { +private: + std::string name; +public: + Employee(const char* n): name(n) {} + virtual std::string getTitle() { return getPosition() + " " + getName(); } + virtual std::string getName() { return name; } + virtual std::string getPosition() const { return "Employee"; } + virtual ~Employee() { printf("~Employee() @ %p\n", this); } +}; + + +class Manager: public Employee { +public: + Manager(const char* n): Employee(n) {} + virtual std::string getPosition() const { return "Manager"; } +}; + + +class EmployeeList { + std::vector list; +public: + EmployeeList() { + list.push_back(new Employee("Bob")); + list.push_back(new Employee("Jane")); + list.push_back(new Manager("Ted")); + } + void addEmployee(Employee *p) { + list.push_back(p); + std::cout << "New employee added. Current employees are:" << std::endl; + std::vector::iterator i; + for (i=list.begin(); i!=list.end(); i++) { + std::cout << " " << (*i)->getTitle() << std::endl; + } + } + const Employee *get_item(int i) { + return list[i]; + } + ~EmployeeList() { + std::vector::iterator i; + std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; + for (i=list.begin(); i!=list.end(); i++) { + delete *i; + } + std::cout << "~EmployeeList empty." << std::endl; + } +}; + diff --git a/Examples/go/extend/example.i b/Examples/go/extend/example.i new file mode 100644 index 000000000..c8ec32e09 --- /dev/null +++ b/Examples/go/extend/example.i @@ -0,0 +1,15 @@ +/* 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/go/extend/index.html b/Examples/go/extend/index.html new file mode 100644 index 000000000..471fa9cdc --- /dev/null +++ b/Examples/go/extend/index.html @@ -0,0 +1,27 @@ + + +SWIG:Examples:go:extend + + + + + +SWIG/Examples/go/extend/ +
      + +

      Extending a simple C++ class in Go

      + +

      +This example illustrates the extending of a C++ class with cross +language polymorphism. + +

      +

      + +
      + + diff --git a/Examples/go/extend/runme.go b/Examples/go/extend/runme.go new file mode 100644 index 000000000..796c5ce68 --- /dev/null +++ b/Examples/go/extend/runme.go @@ -0,0 +1,77 @@ +// This file illustrates the cross language polymorphism using directors. + +package main + +import ( + "fmt" + . "./example" +) + +type CEO struct{} + +func (p *CEO) GetPosition() string { + return "CEO" +} + +func main() { + // Create an instance of CEO, a class derived from the Go + // proxy of the underlying C++ class. The calls to getName() + // and getPosition() are standard, the call to getTitle() uses + // the director wrappers to call CEO.getPosition(). + + e := NewDirectorManager(new(CEO), "Alice") + fmt.Println(e.GetName(), " is a ", e.GetPosition()) + fmt.Println("Just call her \"", e.GetTitle(), "\"") + fmt.Println("----------------------") + + + // Create a new EmployeeList instance. This class does not + // have a C++ director wrapper, but can be used freely with + // other classes that do. + + list := NewEmployeeList() + + // EmployeeList owns its items, so we must surrender ownership + // of objects we add. + // e.DisownMemory() + list.AddEmployee(e) + fmt.Println("----------------------") + + // Now we access the first four items in list (three are C++ + // objects that EmployeeList's constructor adds, the last is + // our CEO). The virtual methods of all these instances are + // treated the same. For items 0, 1, and 2, all methods + // resolve in C++. For item 3, our CEO, GetTitle calls + // GetPosition which resolves in Go. The call to GetPosition + // is slightly different, however, because of the overidden + // GetPosition() call, since now the object reference has been + // "laundered" by passing through EmployeeList as an + // Employee*. Previously, Go resolved the call immediately in + // CEO, but now Go thinks the object is an instance of class + // Employee. So the call passes through the Employee proxy + // class and on to the C wrappers and C++ director, eventually + // ending up back at the Java CEO implementation of + // getPosition(). The call to GetTitle() for item 3 runs the + // C++ Employee::getTitle() method, which in turn calls + // GetPosition(). This virtual method call passes down + // through the C++ director class to the Java implementation + // in CEO. All this routing takes place transparently. + + fmt.Println("(position, title) for items 0-3:") + + fmt.Println(" ", list.Get_item(0).GetPosition(), ", \"", list.Get_item(0).GetTitle(), "\"") + fmt.Println(" ", list.Get_item(1).GetPosition(), ", \"", list.Get_item(1).GetTitle(), "\"") + fmt.Println(" ", list.Get_item(2).GetPosition(), ", \"", list.Get_item(2).GetTitle(), "\"") + fmt.Println(" ", list.Get_item(3).GetPosition(), ", \"", list.Get_item(3).GetTitle(), "\"") + fmt.Println("----------------------") + + // Time to delete the EmployeeList, which will delete all the + // Employee* items it contains. The last item is our CEO, + // which gets destroyed as well. + DeleteEmployeeList(list) + fmt.Println("----------------------") + + // All done. + + fmt.Println("Go exit") +} diff --git a/Examples/go/funcptr/Makefile b/Examples/go/funcptr/Makefile new file mode 100644 index 000000000..b0aa9c970 --- /dev/null +++ b/Examples/go/funcptr/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/funcptr/example.c b/Examples/go/funcptr/example.c new file mode 100644 index 000000000..5c4a3dabf --- /dev/null +++ b/Examples/go/funcptr/example.c @@ -0,0 +1,19 @@ +/* File : example.c */ + +int do_op(int a, int b, int (*op)(int,int)) { + return (*op)(a,b); +} + +int add(int a, int b) { + return a+b; +} + +int sub(int a, int b) { + return a-b; +} + +int mul(int a, int b) { + return a*b; +} + +int (*funcvar)(int,int) = add; diff --git a/Examples/go/funcptr/example.go b/Examples/go/funcptr/example.go new file mode 100644 index 000000000..b059bae8d --- /dev/null +++ b/Examples/go/funcptr/example.go @@ -0,0 +1,54 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +func Do_op(int, int, _swig_fnptr) int +func _swig_getADD() _swig_fnptr +var ADD _swig_fnptr = _swig_getADD() +func _swig_getSUB() _swig_fnptr +var SUB _swig_fnptr = _swig_getSUB() +func _swig_getMUL() _swig_fnptr +var MUL _swig_fnptr = _swig_getMUL() +func _swig_wrap_funcvar_set(_swig_fnptr) + +func SetFuncvar(arg1 _swig_fnptr) { + _swig_wrap_funcvar_set(arg1) +} + +func GetFuncvar() _swig_fnptr + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/funcptr/example.h b/Examples/go/funcptr/example.h new file mode 100644 index 000000000..9936e24fc --- /dev/null +++ b/Examples/go/funcptr/example.h @@ -0,0 +1,9 @@ +/* file: example.h */ + +extern int do_op(int,int, int (*op)(int,int)); +extern int add(int,int); +extern int sub(int,int); +extern int mul(int,int); + +extern int (*funcvar)(int,int); + diff --git a/Examples/go/funcptr/example.i b/Examples/go/funcptr/example.i new file mode 100644 index 000000000..8b3bef678 --- /dev/null +++ b/Examples/go/funcptr/example.i @@ -0,0 +1,16 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +/* Wrap a function taking a pointer to a function */ +extern int do_op(int a, int b, int (*op)(int, int)); + +/* Now install a bunch of "ops" as constants */ +%constant int (*ADD)(int,int) = add; +%constant int (*SUB)(int,int) = sub; +%constant int (*MUL)(int,int) = mul; + +extern int (*funcvar)(int,int); + diff --git a/Examples/go/funcptr/index.html b/Examples/go/funcptr/index.html new file mode 100644 index 000000000..4212260a9 --- /dev/null +++ b/Examples/go/funcptr/index.html @@ -0,0 +1,89 @@ + + +SWIG:Examples:go:funcptr + + + + + +SWIG/Examples/go/funcptr/ +
      + +

      Pointers to Functions

      + +

      +Okay, just what in the heck does SWIG do with a declaration like this? + +

      +
      +int do_op(int a, int b, int (*op)(int, int));
      +
      +
      + +Well, it creates a wrapper as usual. Of course, that does raise some +questions about the third argument (the pointer to a function). + +

      +In this case, SWIG will wrap the function pointer as it does for all +other pointers. However, in order to actually call this function from +a Go program, you will need to pass some kind of C function pointer +object. In C, this is easy, you just supply a function name as an +argument like this: + +

      +
      +/* Some callback function */
      +int add(int a, int b) {
      +   return a+b;
      +} 
      +...
      +int r = do_op(x,y,add);
      +
      +
      + +To make this work with SWIG, you will need to do a little extra work. +Specifically, you need to create some function pointer objects using +the %constant directive like this: + +
      +
      +%constant(int (*)(int,int)) ADD = add;
      +
      +
      + +Now, in a Go program, you would do this: + +
      +
      +int r = do_op(x,y, example.ADD)
      +
      +
      +where example is the module name. + +

      An Example

      + +Here are some files that illustrate this with a simple example: + + + +

      Notes

      + +
        +
      • The value of a function pointer must correspond to a function +written in C or C++. It is not possible to pass an arbitrary Go +function in as a substitute for a C function pointer. + +
      + +
      + + + + + + diff --git a/Examples/go/funcptr/runme.go b/Examples/go/funcptr/runme.go new file mode 100644 index 000000000..73ecbb805 --- /dev/null +++ b/Examples/go/funcptr/runme.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + . "./example" +) + +func main() { + a := 37 + b := 42 + + // Now call our C function with a bunch of callbacks + + fmt.Println("Trying some C callback functions") + fmt.Println(" a = ", a) + fmt.Println(" b = ", b) + fmt.Println(" ADD(a,b) = ", Do_op(a, b, ADD)) + fmt.Println(" SUB(a,b) = ", Do_op(a, b, SUB)) + fmt.Println(" MUL(a,b) = ", Do_op(a, b, MUL)) + + fmt.Println("Here is what the C callback function classes are called in Go") + fmt.Println(" ADD = ", ADD) + fmt.Println(" SUB = ", SUB) + fmt.Println(" MUL = ", MUL) +} diff --git a/Examples/go/index.html b/Examples/go/index.html new file mode 100644 index 000000000..21dda21b5 --- /dev/null +++ b/Examples/go/index.html @@ -0,0 +1,89 @@ + + +SWIG:Examples:Go + + + +

      SWIG Go Examples

      + +

      +The following examples illustrate the use of SWIG with Go. + +

        +
      • simple. A minimal example showing how SWIG can +be used to wrap a C function, a global variable, and a constant. +
      • constants. This shows how preprocessor macros and +certain C declarations are turned into constants. +
      • variables. An example showing how to access C global variables from Go. +
      • enum. Wrapping enumerations. +
      • class. Wrapping a simple C++ class. +
      • reference. C++ references. +
      • pointer. Simple pointer handling. +
      • funcptr. Pointers to functions. +
      • template. C++ templates. +
      • callback. C++ callbacks using directors. +
      • extend. Polymorphism using directors. +
      + +

      Compilation Issues

      + +
        +
      • To create a Go extension, SWIG is run with the following options: + +
        +
        +% swig -go interface.i
        +
        +
        + +
      • On Unix the compilation of examples is done using the +file Example/Makefile. This makefile performs a manual +module compilation which is platform specific. When using +the 6g or 8g compiler, the steps look like this +(GNU/Linux): + +
        +
        +% swig -go interface.i
        +% gcc -fpic -c interface_wrap.c
        +% gcc -shared interface_wrap.o $(OBJS) -o interfacemodule.so 
        +% 6g interface.go
        +% 6c interface_gc.c
        +% gopack grc interface.a interface.6 interface_gc.6
        +% 6l program.6
        +
        +
        + +
      • When using the gccgo compiler, the steps look like this: + +
        +
        +% swig -go interface.i
        +% gcc -c interface_wrap.c
        +% gccgo -c interface.go
        +% gccgo program.o interface.o interface_wrap.o
        +
        +
        + +

        Compatibility

        + +The examples have been extensively tested on the following platforms: + +
          +
        • GNU/Linux +
        + +All of the examples were last tested with the following configuration +(10 May 2010): + +
          +
        • Ubuntu Hardy +
        • gcc-4.2.4 +
        + +Your mileage may vary. If you experience a problem, please let us know by +contacting us on the mailing lists. + + diff --git a/Examples/go/multimap/Makefile b/Examples/go/multimap/Makefile new file mode 100644 index 000000000..b0aa9c970 --- /dev/null +++ b/Examples/go/multimap/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/multimap/example.c b/Examples/go/multimap/example.c new file mode 100644 index 000000000..b8360fa8a --- /dev/null +++ b/Examples/go/multimap/example.c @@ -0,0 +1,53 @@ +/* File : example.c */ +#include +#include +#include + +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + +int gcdmain(int argc, char *argv[]) { + int x,y; + if (argc != 3) { + printf("usage: gcd x y\n"); + return -1; + } + x = atoi(argv[1]); + y = atoi(argv[2]); + printf("gcd(%d,%d) = %d\n", x,y,gcd(x,y)); + return 0; +} + +int count(char *bytes, int len, char c) { + int i; + int count = 0; + for (i = 0; i < len; i++) { + if (bytes[i] == c) count++; + } + return count; +} + +void capitalize(char *str, int len) { + int i; + for (i = 0; i < len; i++) { + str[i] = (char)toupper(str[i]); + } +} + +void circle(double x, double y) { + double a = x*x + y*y; + if (a > 1.0) { + printf("Bad points %g, %g\n", x,y); + } else { + printf("Good points %g, %g\n", x,y); + } +} diff --git a/Examples/go/multimap/example.go b/Examples/go/multimap/example.go new file mode 100644 index 000000000..59ed9eaad --- /dev/null +++ b/Examples/go/multimap/example.go @@ -0,0 +1,55 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +func Gcd(int, int) int +func Gcdmain([]string) int +func Count(string, byte) int +func _swig_wrap_capitalize([]string) + +func Capitalize(arg1 []string) { + _swig_wrap_capitalize(arg1) +} + +func _swig_wrap_circle(float64, float64) + +func Circle(arg1 float64, arg2 float64) { + _swig_wrap_circle(arg1, arg2) +} + + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/multimap/example.i b/Examples/go/multimap/example.i new file mode 100644 index 000000000..04d6eea20 --- /dev/null +++ b/Examples/go/multimap/example.i @@ -0,0 +1,110 @@ +/* File : example.i */ +%module example + +%{ +extern int gcd(int x, int y); +extern int gcdmain(int argc, char *argv[]); +extern int count(char *bytes, int len, char c); +extern void capitalize (char *str, int len); +extern void circle (double cx, double cy); +extern int squareCubed (int n, int *OUTPUT); +%} + +extern int gcd(int x, int y); + +%typemap(go) (int argc, char *argv[]) "[]string" + +%typemap(in) (int argc, char *argv[]) +%{ + { + int i; + _gostring_* a; + + $1 = $input.len; + a = (_gostring_*) $input.array; + $2 = (char **) malloc (($1 + 1) * sizeof (char *)); + for (i = 0; i < $1; i++) { + _gostring_ *ps = &a[i]; + $2[i] = (char *) ps->p; + } + $2[i] = NULL; + } +%} + +%typemap(argout) (int argc, char *argv[]) "" /* override char *[] default */ + +%typemap(freearg) (int argc, char *argv[]) +%{ + free($2); +%} + +extern int gcdmain(int argc, char *argv[]); + +%typemap(go) (char *bytes, int len) "string" + +%typemap(in) (char *bytes, int len) +%{ + $1 = $input.p; + $2 = $input.n; +%} + +extern int count(char *bytes, int len, char c); + +/* This example shows how to wrap a function that mutates a c string. A one + * element Go string slice is used so that the string can be returned + * modified. + */ + +%typemap(go) (char *str, int len) "[]string" + +%typemap(in) (char *str, int len) +%{ + { + _gostring_ *a; + char *p; + int n; + + a = (_gostring_*) $input.array; + p = a[0].p; + n = a[0].n; + $1 = malloc(n + 1); + $2 = n; + memcpy($1, p, n); + } +%} + +/* Return the mutated string as a modified element in the array. */ +%typemap(argout) (char *str, int len) +%{ + { + _gostring_ *a; + + a = (_gostring_*) $input.array; + a[0] = _swig_makegostring($1, $2); + } +%} + +%typemap(freearg) (char *str, int len) +%{ + free($1); +%} + +extern void capitalize(char *str, int len); + +/* A multi-valued constraint. Force two arguments to lie + inside the unit circle */ + +%typemap(check) (double cx, double cy) +%{ + { + double a = $1*$1 + $2*$2; + if (a > 1.0) { + _swig_gopanic("$1_name and $2_name must be in unit circle"); + return; + } + } +%} + +extern void circle(double cx, double cy); + + diff --git a/Examples/go/multimap/runme.go b/Examples/go/multimap/runme.go new file mode 100644 index 000000000..94c29127c --- /dev/null +++ b/Examples/go/multimap/runme.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + . "./example" +) + +func main() { + // Call our gcd() function + x := 42 + y := 105 + g := Gcd(x, y) + fmt.Println("The gcd of ", x, " and ", y, " is ", g) + + // Call the gcdmain() function + args := []string{"gcdmain", "42", "105"} + Gcdmain(args) + + // Call the count function + fmt.Println(Count("Hello World", 'l')) + + // Call the capitalize function + capitalizeMe := []string{"hello world"} + Capitalize(capitalizeMe) + fmt.Println(capitalizeMe[0]) +} diff --git a/Examples/go/pointer/Makefile b/Examples/go/pointer/Makefile new file mode 100644 index 000000000..b0aa9c970 --- /dev/null +++ b/Examples/go/pointer/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/pointer/example.c b/Examples/go/pointer/example.c new file mode 100644 index 000000000..b877d9a5b --- /dev/null +++ b/Examples/go/pointer/example.c @@ -0,0 +1,16 @@ +/* File : example.c */ + +void add(int *x, int *y, int *result) { + *result = *x + *y; +} + +void sub(int *x, int *y, int *result) { + *result = *x - *y; +} + +int divide(int n, int d, int *r) { + int q; + q = n/d; + *r = n - q*d; + return q; +} diff --git a/Examples/go/pointer/example.go b/Examples/go/pointer/example.go new file mode 100644 index 000000000..567c41c32 --- /dev/null +++ b/Examples/go/pointer/example.go @@ -0,0 +1,68 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +func _swig_wrap_add(*int, *int, *int) + +func Add(arg1 *int, arg2 *int, arg3 *int) { + _swig_wrap_add(arg1, arg2, arg3) +} + +func New_intp() *int +func Copy_intp(int) *int +func _swig_wrap_delete_intp(*int) + +func Delete_intp(arg1 *int) { + _swig_wrap_delete_intp(arg1) +} + +func _swig_wrap_intp_assign(*int, int) + +func Intp_assign(arg1 *int, arg2 int) { + _swig_wrap_intp_assign(arg1, arg2) +} + +func Intp_value(*int) int +func _swig_wrap_sub(int, int, []int) + +func Sub(arg1 int, arg2 int, arg3 []int) { + _swig_wrap_sub(arg1, arg2, arg3) +} + +func Divide(int, int, []int) int + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/pointer/example.i b/Examples/go/pointer/example.i new file mode 100644 index 000000000..a8ac79499 --- /dev/null +++ b/Examples/go/pointer/example.i @@ -0,0 +1,30 @@ +/* File : example.i */ +%module example + +%{ +extern void add(int *, int *, int *); +extern void sub(int *, int *, int *); +extern int divide(int, int, int *); +%} + +/* This example illustrates a couple of different techniques + for manipulating C pointers */ + +/* First we'll use the pointer library */ +extern void add(int *x, int *y, int *result); +%include cpointer.i +%pointer_functions(int, intp); + +/* Next we'll use some typemaps */ + +%include typemaps.i +extern void sub(int *INPUT, int *INPUT, int *OUTPUT); + +/* Next we'll use typemaps and the %apply directive */ + +%apply int *OUTPUT { int *r }; +extern int divide(int n, int d, int *r); + + + + diff --git a/Examples/go/pointer/index.html b/Examples/go/pointer/index.html new file mode 100644 index 000000000..cfa8a3acc --- /dev/null +++ b/Examples/go/pointer/index.html @@ -0,0 +1,143 @@ + + +SWIG:Examples:go:pointer + + + + +SWIG/Examples/go/pointer/ +
        + +

        Simple Pointer Handling

        + +

        +This example illustrates a couple of techniques for handling simple +pointers in SWIG. The prototypical example is a C function that +operates on pointers such as this: + +

        +
        +void add(int *x, int *y, int *r) { 
        +    *r = *x + *y;
        +}
        +
        +
        + +By default, SWIG wraps this function exactly as specified and creates +an interface that expects pointer objects for arguments. This only +works when there is a precise correspondence between the C type and +some Go type. +

        + +

        Other approaches

        + +

        +

      • The SWIG pointer library provides a different, safer, way to + handle pointers. For example, in the interface file you would do + this: + +
        +
        +%include cpointer.i
        +%pointer_functions(int, intp);
        +
        +
        + +and from Go you would use pointers like this: + +
        +
        +a := example.New_intp()
        +b := example.New_intp()
        +c := example.New_intp()
        +Intp_Assign(a, 37)
        +Intp_Assign(b, 42)
        +
        +fmt.Println("     a =", a)
        +fmt.Println("     b =", b)
        +fmt.Println("     c =", c)
        +
        +// Call the add() function with some pointers
        +example.Add(a,b,c)
        +
        +// Now get the result
        +res := example.Intp_value(c)
        +fmt.Println("     37 + 42 =", res)
        +
        +// Clean up the pointers
        +example.Delete_intp(a)
        +example.Delete_intp(b)
        +example.Delete_intp(c)
        +
        +
        + +

        +

      • Use the SWIG typemap library. This library allows you to +completely change the way arguments are processed by SWIG. For +example: + +
        +
        +%include "typemaps.i"
        +void add(int *INPUT, int *INPUT, int *OUTPUT);
        +
        +
        + +And in a Go program: + +
        +
        +r := []int{0}
        +example.Sub(37,42,r)
        +fmt.Println("Result =", r[0])
        +
        +
        +Needless to say, this is substantially easier although a bit unusual. + +

        +

      • A final alternative is to use the typemaps library in combination +with the %apply directive. This allows you to change the names of parameters +that behave as input or output parameters. For example: + +
        +
        +%include "typemaps.i"
        +%apply int *INPUT {int *x, int *y};
        +%apply int *OUTPUT {int *r};
        +
        +void add(int *x, int *y, int *r);
        +void sub(int *x, int *y, int *r);
        +void mul(int *x, int *y, int *r);
        +... etc ...
        +
        +
        + +
      + +

      Example

      + +The following example illustrates the use of these features for pointer +extraction. + + + +

      Notes

      + +
        +
      • Since pointers are used for so many different things (arrays, output values, +etc...) the complexity of pointer handling can be as complicated as you want to +make it. + +

        +

      • More documentation on the typemaps.i and cpointer.i library files can be +found in the SWIG user manual. The files also contain documentation. + +
      + +
      + + diff --git a/Examples/go/pointer/runme.go b/Examples/go/pointer/runme.go new file mode 100644 index 000000000..9cbcda489 --- /dev/null +++ b/Examples/go/pointer/runme.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + . "./example" +) + +func main() { + // First create some objects using the pointer library. + fmt.Println("Testing the pointer library") + a := New_intp() + b := New_intp() + c := New_intp() + Intp_assign(a, 37) + Intp_assign(b, 42) + + fmt.Println(" a =", a) + fmt.Println(" b =", b) + fmt.Println(" c =", c) + + // Call the add() function with some pointers + Add(a, b, c) + + // Now get the result + res := Intp_value(c) + fmt.Println(" 37 + 42 =", res) + + // Clean up the pointers + Delete_intp(a) + Delete_intp(b) + Delete_intp(c) + + // Now try the typemap library + // Now it is no longer necessary to manufacture pointers. + // Instead we use a single element array which in Java is modifiable. + + fmt.Println("Trying the typemap library") + r := []int{0} + Sub(37, 42, r) + fmt.Println(" 37 - 42 = ", r[0]) + + // Now try the version with return value + + fmt.Println("Testing return value") + q := Divide(42, 37, r) + fmt.Println(" 42/37 = ", q, " remainder ", r[0]) +} diff --git a/Examples/go/reference/Makefile b/Examples/go/reference/Makefile new file mode 100644 index 000000000..9dc8b8851 --- /dev/null +++ b/Examples/go/reference/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/reference/example.cxx b/Examples/go/reference/example.cxx new file mode 100644 index 000000000..8a513bf49 --- /dev/null +++ b/Examples/go/reference/example.cxx @@ -0,0 +1,46 @@ +/* File : example.cxx */ + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +#include "example.h" +#include +#include + +Vector operator+(const Vector &a, const Vector &b) { + Vector r; + r.x = a.x + b.x; + r.y = a.y + b.y; + r.z = a.z + b.z; + return r; +} + +char *Vector::print() { + static char temp[512]; + sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + return temp; +} + +VectorArray::VectorArray(int size) { + items = new Vector[size]; + maxsize = size; +} + +VectorArray::~VectorArray() { + delete [] items; +} + +Vector &VectorArray::operator[](int index) { + if ((index < 0) || (index >= maxsize)) { + printf("Panic! Array index out of bounds.\n"); + exit(1); + } + return items[index]; +} + +int VectorArray::size() { + return maxsize; +} + diff --git a/Examples/go/reference/example.go b/Examples/go/reference/example.go new file mode 100644 index 000000000..fb98f8a18 --- /dev/null +++ b/Examples/go/reference/example.go @@ -0,0 +1,126 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +type SwigcptrVector uintptr + +func (p SwigcptrVector) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrVector) SwigIsVector() { +} + +func _swig_wrap_new_Vector(float64, float64, float64) SwigcptrVector + +func NewVector(arg1 float64, arg2 float64, arg3 float64) Vector { + return _swig_wrap_new_Vector(arg1, arg2, arg3) +} + +func _swig_wrap_delete_Vector(uintptr) + +func DeleteVector(arg1 Vector) { + _swig_wrap_delete_Vector(arg1.Swigcptr()) +} + +func _swig_wrap_Vector_print(SwigcptrVector) string + +func (arg1 SwigcptrVector) Print() string { + return _swig_wrap_Vector_print(arg1) +} + +type Vector interface { + Swigcptr() uintptr + SwigIsVector() + Print() string +} + +func _swig_wrap_addv(uintptr, uintptr) SwigcptrVector + +func Addv(arg1 Vector, arg2 Vector) Vector { + return _swig_wrap_addv(arg1.Swigcptr(), arg2.Swigcptr()) +} + +type SwigcptrVectorArray uintptr + +func (p SwigcptrVectorArray) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrVectorArray) SwigIsVectorArray() { +} + +func _swig_wrap_new_VectorArray(int) SwigcptrVectorArray + +func NewVectorArray(arg1 int) VectorArray { + return _swig_wrap_new_VectorArray(arg1) +} + +func _swig_wrap_delete_VectorArray(uintptr) + +func DeleteVectorArray(arg1 VectorArray) { + _swig_wrap_delete_VectorArray(arg1.Swigcptr()) +} + +func _swig_wrap_VectorArray_size(SwigcptrVectorArray) int + +func (arg1 SwigcptrVectorArray) Size() int { + return _swig_wrap_VectorArray_size(arg1) +} + +func _swig_wrap_VectorArray_get(SwigcptrVectorArray, int) SwigcptrVector + +func (arg1 SwigcptrVectorArray) Get(arg2 int) Vector { + return _swig_wrap_VectorArray_get(arg1, arg2) +} + +func _swig_wrap_VectorArray_set(SwigcptrVectorArray, int, uintptr) + +func (arg1 SwigcptrVectorArray) Set(arg2 int, arg3 Vector) { + _swig_wrap_VectorArray_set(arg1, arg2, arg3.Swigcptr()) +} + +type VectorArray interface { + Swigcptr() uintptr + SwigIsVectorArray() + Size() int + Get(arg2 int) Vector + Set(arg2 int, arg3 Vector) +} + + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/reference/example.h b/Examples/go/reference/example.h new file mode 100644 index 000000000..4915adb1b --- /dev/null +++ b/Examples/go/reference/example.h @@ -0,0 +1,26 @@ +/* File : example.h */ + +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) { }; + friend Vector operator+(const Vector &a, const Vector &b); + char *print(); +}; + +class VectorArray { +private: + Vector *items; + int maxsize; +public: + VectorArray(int maxsize); + ~VectorArray(); + Vector &operator[](int); + int size(); +}; + + + + diff --git a/Examples/go/reference/example.i b/Examples/go/reference/example.i new file mode 100644 index 000000000..1cf19c82c --- /dev/null +++ b/Examples/go/reference/example.i @@ -0,0 +1,42 @@ +/* File : example.i */ + +/* This file has a few "typical" uses of C++ references. */ + +%module example + +%{ +#include "example.h" +%} + +class Vector { +public: + Vector(double x, double y, double z); + ~Vector(); + char *print(); +}; + +/* This helper function calls an overloaded operator */ +%inline %{ +Vector addv(Vector &a, Vector &b) { + return a+b; +} +%} + +/* Wrapper around an array of vectors class */ + +class VectorArray { +public: + VectorArray(int maxsize); + ~VectorArray(); + int size(); + + /* This wrapper provides an alternative to the [] operator */ + %extend { + Vector &get(int index) { + return (*$self)[index]; + } + void set(int index, Vector &a) { + (*$self)[index] = a; + } + } +}; diff --git a/Examples/go/reference/index.html b/Examples/go/reference/index.html new file mode 100644 index 000000000..5e8589349 --- /dev/null +++ b/Examples/go/reference/index.html @@ -0,0 +1,143 @@ + + +SWIG:Examples:go:reference + + + + + +SWIG/Examples/go/reference/ +
      + +

      C++ Reference Handling

      + +

      +This example tests SWIG's handling of C++ references. A reference in +C++ is much like a pointer. Go represents C++ classes as pointers +which are stored in interface values. Therefore, a reference to a +class in C++ simply becomes an object of the class type in Go. For +types which are not classes, a reference in C++ is represented as a +pointer in Go. + +

      Some examples

      + +References are most commonly used as function parameters. For +example, you might have a function like this: + +
      +
      +Vector addv(const Vector &a, const Vector &b) {
      +   Vector result;
      +   result.x = a.x + b.x;
      +   result.y = a.y + b.y;
      +   result.z = a.z + b.z;
      +   return result;
      +}
      +
      +
      + +In these cases, SWIG transforms everything into a pointer and creates +a wrapper that looks like this in C++. + +
      +
      +Vector wrap_addv(Vector *a, Vector *b);
      +
      +
      + +or like this in Go: + +
      +
      +func Addv(arg1 Vector, arg2 Vector) Vector
      +
      +
      + +Occasionally, a reference is used as a return value of a function +when the return result is to be used as an lvalue in an expression. +The prototypical example is an operator like this: + +
      +
      +Vector &operator[](int index);
      +
      +
      + +or a method: + +
      +
      +Vector &get(int index);
      +
      +
      + +For functions returning references, a wrapper like this is created: + +
      +
      +Vector *wrap_Object_get(Object *self, int index) {
      +    Vector &result = self->get(index);
      +    return &result;
      +}
      +
      +
      + +The following header file contains some class +definitions with some operators and use of references. + +

      SWIG Interface

      + +SWIG does NOT support overloaded operators so it can not directly +build an interface to the classes in the above file. However, a +number of workarounds can be made. For example, an overloaded +operator can be stuck behind a function call such as the addv +function above. Array access can be handled with a pair of set/get +functions like this: + +
      +
      +class VectorArray {
      +public:
      + ...
      +   %addmethods {
      +    Vector &get(int index) {
      +      return (*self)[index];
      +    }
      +    void set(int index, Vector &a) {
      +      (*self)[index] = a;
      +    }
      +   }
      +   ...
      +}
      +
      +
      + +Click here to see a SWIG interface file with +these additions. + +

      Sample Go program

      + +Click here to see a Go program that manipulates +some C++ references. + +

      Notes:

      + +
        +
      • C++ references primarily provide notational convenience for C++ +source code. However, Go only supports the 'x.a' notation so it +doesn't much matter. + +

        +

      • When a program returns a reference, a pointer is returned. Unlike +return by value, memory is not allocated to hold the return result. + +

        +

      • SWIG has particular trouble handling various combinations of +references and pointers. This is side effect of an old parsing scheme +and type representation that will be replaced in future versions. + +
      + +
      + + diff --git a/Examples/go/reference/runme.go b/Examples/go/reference/runme.go new file mode 100644 index 000000000..3683d6144 --- /dev/null +++ b/Examples/go/reference/runme.go @@ -0,0 +1,71 @@ +// This example illustrates the manipulation of C++ references in Java. + +package main + +import ( + "fmt" + . "./example" +) + +func main() { + fmt.Println("Creating some objects:") + a := NewVector(3, 4, 5) + b := NewVector(10, 11, 12) + + fmt.Println(" Created ", a.Print()) + fmt.Println(" Created ", b.Print()) + + // ----- Call an overloaded operator ----- + + // This calls the wrapper we placed around + // + // operator+(const Vector &a, const Vector &) + // + // It returns a new allocated object. + + fmt.Println("Adding a+b") + c := Addv(a, b) + fmt.Println(" a+b = " + c.Print()) + + // Because addv returns a reference, Addv will return a + // pointer allocated using Go's memory allocator. That means + // that it will be freed by Go's garbage collector, and we can + // not use DeleteVector to release it. + + c = nil + + // ----- Create a vector array ----- + + fmt.Println("Creating an array of vectors") + va := NewVectorArray(10) + fmt.Println(" va = ", va) + + // ----- Set some values in the array ----- + + // These operators copy the value of Vector a and Vector b to + // the vector array + va.Set(0, a) + va.Set(1, b) + + va.Set(2, Addv(a, b)) + + // Get some values from the array + + fmt.Println("Getting some array values") + for i := 0; i < 5; i++ { + fmt.Println(" va(", i, ") = ", va.Get(i).Print()) + } + + // Watch under resource meter to check on this + fmt.Println("Making sure we don't leak memory.") + for i := 0; i < 1000000; i++ { + c = va.Get(i % 10) + } + + // ----- Clean up ----- This could be omitted. The garbage + // collector would then clean up for us. + fmt.Println("Cleaning up") + DeleteVectorArray(va) + DeleteVector(a) + DeleteVector(b) +} diff --git a/Examples/go/simple/Makefile b/Examples/go/simple/Makefile new file mode 100644 index 000000000..e67fa8bb6 --- /dev/null +++ b/Examples/go/simple/Makefile @@ -0,0 +1,15 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/simple/example.c b/Examples/go/simple/example.c new file mode 100644 index 000000000..1c2af789c --- /dev/null +++ b/Examples/go/simple/example.c @@ -0,0 +1,18 @@ +/* File : example.c */ + +/* A global variable */ +double Foo = 3.0; + +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + + diff --git a/Examples/go/simple/example.go b/Examples/go/simple/example.go new file mode 100644 index 000000000..df0e70564 --- /dev/null +++ b/Examples/go/simple/example.go @@ -0,0 +1,48 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +func Gcd(int, int) int +func _swig_wrap_Foo_set(float64) + +func SetFoo(arg1 float64) { + _swig_wrap_Foo_set(arg1) +} + +func GetFoo() float64 + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/simple/example.i b/Examples/go/simple/example.i new file mode 100644 index 000000000..24093b9bf --- /dev/null +++ b/Examples/go/simple/example.i @@ -0,0 +1,7 @@ +/* File : example.i */ +%module example + +%inline %{ +extern int gcd(int x, int y); +extern double Foo; +%} diff --git a/Examples/go/simple/index.html b/Examples/go/simple/index.html new file mode 100644 index 000000000..82372ef37 --- /dev/null +++ b/Examples/go/simple/index.html @@ -0,0 +1,126 @@ + + +SWIG:Examples:go:simple + + + + + +SWIG/Examples/go/simple/ +
      + +

      Simple Go Example

      + +

      +This example illustrates how you can hook Go to a very simple C program containing +a function and a global variable. + +

      The C Code

      + +Suppose you have the following C code: + +
      +
      +/* File : example.c */
      +
      +/* A global variable */
      +double Foo = 3.0;
      +
      +/* Compute the greatest common divisor of positive integers */
      +int gcd(int x, int y) {
      +  int g;
      +  g = y;
      +  while (x > 0) {
      +    g = x;
      +    x = y % x;
      +    y = g;
      +  }
      +  return g;
      +}
      +
      +
      + +

      The SWIG interface

      + +Here is a simple SWIG interface file: + +
      +
      +/* File: example.i */
      +%module example
      +
      +extern int gcd(int x, int y);
      +extern double Foo;
      +
      +
      + +

      Compilation

      + +These are the instructions if you are using 6g/8g +rather than gccgo. + +
        +
      1. Run swig -go example.i. This + will create the three + files example.go, example_gc.c, + and example_wrap.c. +
      2. Compile example.go + using 6g or 8g; e.g., 6g example.go. +
      3. Compile example_gc.c + using 6c or 8c; e.g., 6c example_gc.c. +
      4. Put the two object files together into an archive + named example.a; e.g., gopack grc example.a example.6 + example_gc.6. +
      5. Compile the example_wrap.c + file using your standard C compiler with the -fpic option; + e.g., gcc -c -O -fpic example_wrap.c. +
      6. Put the gcc compiled object file into a shared library; + e.g., gcc -shared -o example.so example_wrap.o. +
      7. Compile the program which demonstrates how to use the library; + e.g., 6g runme.go. +
      8. Link the program; e.g., 6l -o runme runme.6. +
      9. Now you should have a program runme. +
      + +

      Using the extension

      + +The Go program which demonstrates calling the C functions from Go +is runme.go. + +

      Key points

      + +
        +
      • Use the import statement to load your extension module from Go. For example: +
        +
        +import "example"
        +
        +
        + +
      • C functions work just like Go functions. However, the function + names are automatically capitalized in order to make the names + visible from other Go packages. For example: +
        +
        +g := example.Gcd(42,105)
        +
        +
        + +(If there are name conflicts, you can use the %rename +directive in the .i file or the -rename option to Go to +rename one or the other symbol). + +
      • C global variables are accessed using getter and setter + functions. The getter function is named Get followed by + the capitalized name of the C variable. The Setter function + uses Set instead of Get. +
        +
        +a = example.GetFoo()
        +
        +
        +
      + +
      + + diff --git a/Examples/go/simple/runme.go b/Examples/go/simple/runme.go new file mode 100644 index 000000000..c829ad21a --- /dev/null +++ b/Examples/go/simple/runme.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "./example" +) + +func main() { + // Call our gcd() function + x := 42 + y := 105 + g := example.Gcd(x, y) + fmt.Println("The gcd of", x, "and", y, "is", g) + + // Manipulate the Foo global variable + + // Output its current value + fmt.Println("Foo =", example.GetFoo()) + + // Change its value + example.SetFoo(3.1415926) + + // See if the change took effect + fmt.Println("Foo =", example.GetFoo()) +} diff --git a/Examples/go/template/Makefile b/Examples/go/template/Makefile new file mode 100644 index 000000000..b9278b53e --- /dev/null +++ b/Examples/go/template/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_cpp + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/template/example.go b/Examples/go/template/example.go new file mode 100644 index 000000000..671b5c2ba --- /dev/null +++ b/Examples/go/template/example.go @@ -0,0 +1,150 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +func Maxint(int, int) int +func Maxdouble(float64, float64) float64 +type SwigcptrVecint uintptr + +func (p SwigcptrVecint) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrVecint) SwigIsVecint() { +} + +func _swig_wrap_new_vecint(int) SwigcptrVecint + +func NewVecint(arg1 int) Vecint { + return _swig_wrap_new_vecint(arg1) +} + +func _swig_wrap_vecint_get(SwigcptrVecint, int) *int + +func (arg1 SwigcptrVecint) Get(arg2 int) *int { + return _swig_wrap_vecint_get(arg1, arg2) +} + +func _swig_wrap_vecint_set(SwigcptrVecint, int, *int) + +func (arg1 SwigcptrVecint) Set(arg2 int, arg3 *int) { + _swig_wrap_vecint_set(arg1, arg2, arg3) +} + +func _swig_wrap_vecint_getitem(SwigcptrVecint, int) int + +func (arg1 SwigcptrVecint) Getitem(arg2 int) int { + return _swig_wrap_vecint_getitem(arg1, arg2) +} + +func _swig_wrap_vecint_setitem(SwigcptrVecint, int, int) + +func (arg1 SwigcptrVecint) Setitem(arg2 int, arg3 int) { + _swig_wrap_vecint_setitem(arg1, arg2, arg3) +} + +func _swig_wrap_delete_vecint(uintptr) + +func DeleteVecint(arg1 Vecint) { + _swig_wrap_delete_vecint(arg1.Swigcptr()) +} + +type Vecint interface { + Swigcptr() uintptr + SwigIsVecint() + Get(arg2 int) *int + Set(arg2 int, arg3 *int) + Getitem(arg2 int) int + Setitem(arg2 int, arg3 int) +} + +type SwigcptrVecdouble uintptr + +func (p SwigcptrVecdouble) Swigcptr() uintptr { + return (uintptr)(p) +} + +func (p SwigcptrVecdouble) SwigIsVecdouble() { +} + +func _swig_wrap_new_vecdouble(int) SwigcptrVecdouble + +func NewVecdouble(arg1 int) Vecdouble { + return _swig_wrap_new_vecdouble(arg1) +} + +func _swig_wrap_vecdouble_get(SwigcptrVecdouble, int) *float64 + +func (arg1 SwigcptrVecdouble) Get(arg2 int) *float64 { + return _swig_wrap_vecdouble_get(arg1, arg2) +} + +func _swig_wrap_vecdouble_set(SwigcptrVecdouble, int, *float64) + +func (arg1 SwigcptrVecdouble) Set(arg2 int, arg3 *float64) { + _swig_wrap_vecdouble_set(arg1, arg2, arg3) +} + +func _swig_wrap_vecdouble_getitem(SwigcptrVecdouble, int) float64 + +func (arg1 SwigcptrVecdouble) Getitem(arg2 int) float64 { + return _swig_wrap_vecdouble_getitem(arg1, arg2) +} + +func _swig_wrap_vecdouble_setitem(SwigcptrVecdouble, int, float64) + +func (arg1 SwigcptrVecdouble) Setitem(arg2 int, arg3 float64) { + _swig_wrap_vecdouble_setitem(arg1, arg2, arg3) +} + +func _swig_wrap_delete_vecdouble(uintptr) + +func DeleteVecdouble(arg1 Vecdouble) { + _swig_wrap_delete_vecdouble(arg1.Swigcptr()) +} + +type Vecdouble interface { + Swigcptr() uintptr + SwigIsVecdouble() + Get(arg2 int) *float64 + Set(arg2 int, arg3 *float64) + Getitem(arg2 int) float64 + Setitem(arg2 int, arg3 float64) +} + + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/template/example.h b/Examples/go/template/example.h new file mode 100644 index 000000000..7401df650 --- /dev/null +++ b/Examples/go/template/example.h @@ -0,0 +1,32 @@ +/* File : example.h */ + +// Some template definitions + +template T max(T a, T b) { return a>b ? a : b; } + +template class vector { + T *v; + int sz; + public: + vector(int _sz) { + v = new T[_sz]; + sz = _sz; + } + T &get(int index) { + return v[index]; + } + void set(int index, T &val) { + v[index] = val; + } +#ifdef SWIG + %extend { + T getitem(int index) { + return $self->get(index); + } + void setitem(int index, T val) { + $self->set(index,val); + } + } +#endif +}; + diff --git a/Examples/go/template/example.i b/Examples/go/template/example.i new file mode 100644 index 000000000..8f94c4da1 --- /dev/null +++ b/Examples/go/template/example.i @@ -0,0 +1,17 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" + +/* Now instantiate some specific template declarations */ + +%template(maxint) max; +%template(maxdouble) max; +%template(vecint) vector; +%template(vecdouble) vector; + diff --git a/Examples/go/template/index.html b/Examples/go/template/index.html new file mode 100644 index 000000000..a14e3b29a --- /dev/null +++ b/Examples/go/template/index.html @@ -0,0 +1,113 @@ + + +SWIG:Examples:go:template + + + + + +SWIG/Examples/go/template/ +
      + +

      C++ template support

      + +

      +This example illustrates how C++ templates can be used from Go using +SWIG. + +

      The C++ Code

      + +Lets take a templated function and a templated class as follows: + +
      +
      +/* File : example.h */
      +
      +// Some template definitions
      +
      +template T max(T a, T b) { return  a>b ? a : b; }
      +
      +template class vector {
      +  T *v;
      +  int sz;
      + public:
      +  vector(int _sz) {
      +    v = new T[_sz];
      +    sz = _sz;
      +  }
      +  T &get(int index) {
      +    return v[index];
      +  }
      +  void set(int index, T &val) {
      +    v[index] = val;
      +  }
      +#ifdef SWIG
      +  %addmethods {
      +    T getitem(int index) {
      +      return self->get(index);
      +    }
      +    void setitem(int index, T val) {
      +      self->set(index,val);
      +    }
      +  }
      +#endif
      +};
      +
      +
      +The %addmethods is used for a neater interface from Go as the +functions get and set use C++ references to +primitive types. These are tricky to use from Go as they end up as +pointers, which only work when the C++ and Go types correspond +precisely. + +

      The SWIG interface

      + +A simple SWIG interface for this can be built by simply grabbing the +header file like this: + +
      +
      +/* File : example.i */
      +%module example
      +
      +%{
      +#include "example.h"
      +%}
      +
      +/* Let's just grab the original header file here */
      +%include "example.h"
      +
      +/* Now instantiate some specific template declarations */
      +
      +%template(maxint) max;
      +%template(maxdouble) max;
      +%template(vecint) vector;
      +%template(vecdouble) vector;
      +
      +
      + +Note that SWIG parses the templated function max and +templated class vector and so knows about them. However to +generate code for use from Go, SWIG has to be told which class/type to +use as the template parameter. The SWIG directive %template is used +for this. + +

      A sample Go program

      + +Click here to see a Go program that calls the +C++ functions from Go. + +

      Notes

      Use templated classes just like you would any other +SWIG generated Go class. Use the classnames specified by the %template +directive. + +
      +
      +vecdouble dv = new vecdouble(1000);
      +dv.setitem(i, 12.34));
      +
      +
      + +
      + + diff --git a/Examples/go/template/runme.go b/Examples/go/template/runme.go new file mode 100644 index 000000000..8b3d4000e --- /dev/null +++ b/Examples/go/template/runme.go @@ -0,0 +1,43 @@ +// This example illustrates how C++ templates can be used from Go. + +package main + +import ( + "fmt" + . "./example" +) + +func main() { + + // Call some templated functions + fmt.Println(Maxint(3, 7)) + fmt.Println(Maxdouble(3.14, 2.18)) + + // Create some class + iv := NewVecint(100) + dv := NewVecdouble(1000) + + for i := 0; i < 100; i++ { + iv.Setitem(i, 2*i) + } + + for i := 0; i < 1000; i++ { + dv.Setitem(i, 1.0/float64(i+1)) + } + + { + sum := 0 + for i := 0; i < 100; i++ { + sum = sum + iv.Getitem(i) + } + fmt.Println(sum) + } + + { + sum := float64(0.0) + for i := 0; i < 1000; i++ { + sum = sum + dv.Getitem(i) + } + fmt.Println(sum) + } +} diff --git a/Examples/go/variables/Makefile b/Examples/go/variables/Makefile new file mode 100644 index 000000000..b0aa9c970 --- /dev/null +++ b/Examples/go/variables/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i +SWIGOPT = + +all:: go + +go:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go + +clean:: + $(MAKE) -f $(TOP)/Makefile go_clean + +check: all + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run diff --git a/Examples/go/variables/example.c b/Examples/go/variables/example.c new file mode 100644 index 000000000..aa4ffe9b3 --- /dev/null +++ b/Examples/go/variables/example.c @@ -0,0 +1,91 @@ +/* File : example.c */ + +/* I'm a file containing some C global variables */ + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +#include +#include +#include "example.h" + +int ivar = 0; +short svar = 0; +long lvar = 0; +unsigned int uivar = 0; +unsigned short usvar = 0; +unsigned long ulvar = 0; +signed char scvar = 0; +unsigned char ucvar = 0; +char cvar = 0; +float fvar = 0; +double dvar = 0; +char *strvar = 0; +const char cstrvar[] = "Goodbye"; +int *iptrvar = 0; +char name[256] = "Dave"; +char path[256] = "/home/beazley"; + + +/* Global variables involving a structure */ +Point *ptptr = 0; +Point pt = { 10, 20 }; + +/* A variable that we will make read-only in the interface */ +int status = 1; + +/* A debugging function to print out their values */ + +void print_vars() { + printf("ivar = %d\n", ivar); + printf("svar = %d\n", svar); + printf("lvar = %ld\n", lvar); + printf("uivar = %u\n", uivar); + printf("usvar = %u\n", usvar); + printf("ulvar = %lu\n", ulvar); + printf("scvar = %d\n", scvar); + printf("ucvar = %u\n", ucvar); + printf("fvar = %g\n", fvar); + printf("dvar = %g\n", dvar); + printf("cvar = %c\n", cvar); + printf("strvar = %s\n", strvar ? strvar : "(null)"); + printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("iptrvar = %p\n", iptrvar); + printf("name = %s\n", name); + printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("pt = (%d, %d)\n", pt.x, pt.y); + printf("status = %d\n", status); +} + +/* A function to create an integer (to test iptrvar) */ + +int *new_int(int value) { + int *ip = (int *) malloc(sizeof(int)); + *ip = value; + return ip; +} + +/* A function to create a point */ + +Point *new_Point(int x, int y) { + Point *p = (Point *) malloc(sizeof(Point)); + p->x = x; + p->y = y; + return p; +} + +char * Point_print(Point *p) { + static char buffer[256]; + if (p) { + sprintf(buffer,"(%d,%d)", p->x,p->y); + } else { + sprintf(buffer,"null"); + } + return buffer; +} + +void pt_print() { + printf("(%d, %d)\n", pt.x, pt.y); +} diff --git a/Examples/go/variables/example.go b/Examples/go/variables/example.go new file mode 100644 index 000000000..f4f299b73 --- /dev/null +++ b/Examples/go/variables/example.go @@ -0,0 +1,198 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.1 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +package example + + +type _swig_fnptr *byte +type _swig_memberptr *byte + + +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} + +func _swig_wrap_ivar_set(int) + +func SetIvar(arg1 int) { + _swig_wrap_ivar_set(arg1) +} + +func GetIvar() int +func _swig_wrap_svar_set(int16) + +func SetSvar(arg1 int16) { + _swig_wrap_svar_set(arg1) +} + +func GetSvar() int16 +func _swig_wrap_lvar_set(int32) + +func SetLvar(arg1 int32) { + _swig_wrap_lvar_set(arg1) +} + +func GetLvar() int32 +func _swig_wrap_uivar_set(uint) + +func SetUivar(arg1 uint) { + _swig_wrap_uivar_set(arg1) +} + +func GetUivar() uint +func _swig_wrap_usvar_set(uint16) + +func SetUsvar(arg1 uint16) { + _swig_wrap_usvar_set(arg1) +} + +func GetUsvar() uint16 +func _swig_wrap_ulvar_set(uint32) + +func SetUlvar(arg1 uint32) { + _swig_wrap_ulvar_set(arg1) +} + +func GetUlvar() uint32 +func _swig_wrap_scvar_set(int8) + +func SetScvar(arg1 int8) { + _swig_wrap_scvar_set(arg1) +} + +func GetScvar() int8 +func _swig_wrap_ucvar_set(byte) + +func SetUcvar(arg1 byte) { + _swig_wrap_ucvar_set(arg1) +} + +func GetUcvar() byte +func _swig_wrap_cvar_set(byte) + +func SetCvar(arg1 byte) { + _swig_wrap_cvar_set(arg1) +} + +func GetCvar() byte +func _swig_wrap_fvar_set(float32) + +func SetFvar(arg1 float32) { + _swig_wrap_fvar_set(arg1) +} + +func GetFvar() float32 +func _swig_wrap_dvar_set(float64) + +func SetDvar(arg1 float64) { + _swig_wrap_dvar_set(arg1) +} + +func GetDvar() float64 +func _swig_wrap_strvar_set(string) + +func SetStrvar(arg1 string) { + _swig_wrap_strvar_set(arg1) +} + +func GetStrvar() string +func GetCstrvar() string +func _swig_wrap_iptrvar_set(*int) + +func SetIptrvar(arg1 *int) { + _swig_wrap_iptrvar_set(arg1) +} + +func GetIptrvar() *int +func _swig_wrap_name_set(string) + +func SetName(arg1 string) { + _swig_wrap_name_set(arg1) +} + +func GetName() string +func _swig_wrap_ptptr_set(uintptr) + +func SetPtptr(arg1 Point) { + _swig_wrap_ptptr_set(arg1.Swigcptr()) +} + +func _swig_wrap_ptptr_get() SwigcptrPoint + +func GetPtptr() Point { + return _swig_wrap_ptptr_get() +} + +func _swig_wrap_pt_set(uintptr) + +func SetPt(arg1 Point) { + _swig_wrap_pt_set(arg1.Swigcptr()) +} + +func _swig_wrap_pt_get() SwigcptrPoint + +func GetPt() Point { + return _swig_wrap_pt_get() +} + +func GetStatus() int +func GetPath() string +func _swig_wrap_print_vars() + +func Print_vars() { + _swig_wrap_print_vars() +} + +func New_int(int) *int +func _swig_wrap_new_Point(int, int) SwigcptrPoint + +func New_Point(arg1 int, arg2 int) Point { + return _swig_wrap_new_Point(arg1, arg2) +} + +func _swig_wrap_Point_print(uintptr) string + +func Point_print(arg1 Point) string { + return _swig_wrap_Point_print(arg1.Swigcptr()) +} + +func _swig_wrap_pt_print() + +func Pt_print() { + _swig_wrap_pt_print() +} + + +type SwigcptrPoint uintptr +type Point interface { + Swigcptr() uintptr; +} +func (p SwigcptrPoint) Swigcptr() uintptr { + return uintptr(p) +} + +type SwigcptrVoid uintptr +type Void interface { + Swigcptr() uintptr; +} +func (p SwigcptrVoid) Swigcptr() uintptr { + return uintptr(p) +} + diff --git a/Examples/go/variables/example.h b/Examples/go/variables/example.h new file mode 100644 index 000000000..0f7e89594 --- /dev/null +++ b/Examples/go/variables/example.h @@ -0,0 +1,6 @@ +/* File: example.h */ + +typedef struct { + int x,y; +} Point; + diff --git a/Examples/go/variables/example.i b/Examples/go/variables/example.i new file mode 100644 index 000000000..591b871ed --- /dev/null +++ b/Examples/go/variables/example.i @@ -0,0 +1,49 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +/* Some global variable declarations */ +%inline %{ +extern int ivar; +extern short svar; +extern long lvar; +extern unsigned int uivar; +extern unsigned short usvar; +extern unsigned long ulvar; +extern signed char scvar; +extern unsigned char ucvar; +extern char cvar; +extern float fvar; +extern double dvar; +extern char *strvar; +extern const char cstrvar[]; +extern int *iptrvar; +extern char name[256]; + +extern Point *ptptr; +extern Point pt; +%} + + +/* Some read-only variables */ + +%immutable; + +%inline %{ +extern int status; +extern char path[256]; +%} + +%mutable; + +/* Some helper functions to make it easier to test */ +%inline %{ +extern void print_vars(); +extern int *new_int(int value); +extern Point *new_Point(int x, int y); +extern char *Point_print(Point *p); +extern void pt_print(); +%} + diff --git a/Examples/go/variables/index.html b/Examples/go/variables/index.html new file mode 100644 index 000000000..5a11194df --- /dev/null +++ b/Examples/go/variables/index.html @@ -0,0 +1,87 @@ + + +SWIG:Examples:go:variables + + + + +SWIG/Examples/go/variables/ +
      + +

      Wrapping C Global Variables

      + +

      +When a C global variable appears in an interface file, SWIG provides +getter and setter functions for the variable. The getter function is +named Get followed by the capitalized name of the variable. +The setter variable starts with Set instead. The getter +function takes no parameters and returns the value of the variable. +The setter function takes a single parameter with the same type as the +variable, and returns nothing. + +

      Click here to see a SWIG interface with +some variable declarations in it. + +

      Manipulating Variables from Go

      + +For example, if the package is called example, the global +variable + +
      +
      +double foo;
      +
      +
      + +will be accessed from Go as +
      +
      +example.GetFoo();
      +example.SetFoo(12.3);
      +
      +
      + +Click here to see the example program that +updates and prints out the values of the variables using this +technique. + +

      Key points

      + +
        +
      • The name of the variable is capitalized. +
      • When a global variable has the type "char *", SWIG +manages it as a character string. +
      • signed char and unsigned char are handled as +small 8-bit integers. +
      • String array variables such as 'char name[256]' are +managed as Go strings, but when setting the value, the result is +truncated to the maximum length of the array. Furthermore, the string +is assumed to be null-terminated. +
      • When structures and classes are used as global variables, they are +mapped into pointers. Getting the "value" returns a pointer to the +global variable. Setting the value of a structure results in a memory +copy from a pointer to the global. +
      + +

      Creating read-only variables

      + +The %immutable and %mutable directives can be used +to specify a collection of read-only variables. A read only variable +will have a getter function but no setter function. For example: + +
      +
      +%immutable;
      +int    status;
      +double blah;
      +...
      +%mutable;
      +
      +
      + +The %immutable directive remains in effect until it is +explicitly disabled using the %mutable directive. + + + +
      diff --git a/Examples/go/variables/runme.go b/Examples/go/variables/runme.go new file mode 100644 index 000000000..26cad4b3c --- /dev/null +++ b/Examples/go/variables/runme.go @@ -0,0 +1,67 @@ +// This example illustrates global variable access from Go. + +package main + +import ( + "fmt" + "./example" +) + +func main() { + // Try to set the values of some global variables + + example.SetIvar(42) + example.SetSvar(-31000) + example.SetLvar(65537) + example.SetUivar(123456) + example.SetUsvar(61000) + example.SetUlvar(654321) + example.SetScvar(-13) + example.SetUcvar(251) + example.SetCvar('S') + example.SetFvar(3.14159) + example.SetDvar(2.1828) + example.SetStrvar("Hello World") + example.SetIptrvar(example.New_int(37)) + example.SetPtptr(example.New_Point(37, 42)) + example.SetName("Bill") + + // Now print out the values of the variables + + fmt.Println("Variables (values printed from Go)") + + fmt.Println("ivar =", example.GetIvar()) + fmt.Println("svar =", example.GetSvar()) + fmt.Println("lvar =", example.GetLvar()) + fmt.Println("uivar =", example.GetUivar()) + fmt.Println("usvar =", example.GetUsvar()) + fmt.Println("ulvar =", example.GetUlvar()) + fmt.Println("scvar =", example.GetScvar()) + fmt.Println("ucvar =", example.GetUcvar()) + fmt.Println("fvar =", example.GetFvar()) + fmt.Println("dvar =", example.GetDvar()) + fmt.Printf("cvar = %c\n", example.GetCvar()) + fmt.Println("strvar =", example.GetStrvar()) + fmt.Println("cstrvar =", example.GetCstrvar()) + fmt.Println("iptrvar =", example.GetIptrvar()) + fmt.Println("name =", example.GetName()) + fmt.Println("ptptr =", example.GetPtptr(), example.Point_print(example.GetPtptr())) + fmt.Println("pt =", example.GetPt(), example.Point_print(example.GetPt())) + + fmt.Println("\nVariables (values printed from C)") + + example.Print_vars() + + // This line would not compile: since status is marked with + // %immutable, there is no SetStatus function. + // fmt.Println("\nNow I'm going to try and modify some read only variables") + // example.SetStatus(0) + + fmt.Println("\nI'm going to try and update a structure variable.\n") + + example.SetPt(example.GetPtptr()) + + fmt.Println("The new value is") + example.Pt_print() + fmt.Println("You should see the value", example.Point_print(example.GetPtptr())) +} diff --git a/Examples/test-suite/dynamic_cast.i b/Examples/test-suite/dynamic_cast.i index 5d4fbb0b6..ccbaa5b47 100644 --- a/Examples/test-suite/dynamic_cast.i +++ b/Examples/test-suite/dynamic_cast.i @@ -1,7 +1,7 @@ /* File : example.i */ %module dynamic_cast -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) %apply SWIGTYPE *DYNAMIC { Foo * }; #endif @@ -17,7 +17,7 @@ public: }; %} -#if defined(SWIGJAVA) || defined(SWIGCSHARP) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) %typemap(out) Foo *blah { Bar *downcast = dynamic_cast($1); *(Bar **)&$result = downcast; @@ -37,6 +37,14 @@ public: } #endif +#if defined(SWIGGO) +%insert(go_runtime) %{ +func FooToBar(f Foo) Bar { + return SwigcptrBar(f.Swigcptr()) +} +%} +#endif + %inline %{ class Bar : public Foo { @@ -54,7 +62,7 @@ char *do_test(Bar *b) { } %} -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) // A general purpose function for dynamic casting of a Foo * %{ static swig_type_info * diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in new file mode 100644 index 000000000..d666c81bf --- /dev/null +++ b/Examples/test-suite/go/Makefile.in @@ -0,0 +1,110 @@ +####################################################################### +# Makefile for Go test-suite +####################################################################### + +LANGUAGE = go +GO = 6g +GOGCC = false +SCRIPTSUFFIX = _runme.go + +GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; fi` +GOC = $(GO:g=c) +GOLD = $(GO:g=l) + +GOOBJEXT = $(GO:g=) + +SO = @SO@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ + +include $(srcdir)/../common.mk + +# Custom tests - tests with additional commandline options +constant_pointers.cpptest: SWIGOPT += -rename foo=foofn +director_enum.cpptest: SWIGOPT += -rename Hello=Helloe +director_finalizer.cpptest: SWIGOPT += -rename deleteFoo=deleteFooFn +enum_thorough.cpptest: SWIGOPT += -rename One=Onee -rename Two=Twoe +mixed_types.cpptest: SWIGOPT += -rename Hello=Helloe +overload_simple.cpptest: SWIGOPT += -rename foo=foofn +smart_pointer_extend.cpptest: SWIGOPT += -rename CPtrFoo=CPtrFoos +smart_pointer_member.cpptest: SWIGOPT += -rename Foo=Foos +special_variable_macros.cpptest: SWIGOPT += -rename Name=Names +template_partial_specialization.cpptest: SWIGOPT += -rename b=bfn +template_partial_specialization_typedef.cpptest: SWIGOPT += -rename b=bfn +template_specialization_enum.cpptest: SWIGOPT += -rename Hello=Helloe +preproc.ctest: SWIGOPT += -rename a5=a5c -rename a6=a6c +mod.multicpptest: SWIGOPT += -rename GetC=GetCFn + +.SUFFIXES: .cpptest .ctest .multicpptest + +# Rules for the different types of tests +%.cpptest: + $(setup) + +$(swig_and_compile_cpp) + $(run_testcase) + +%.ctest: + $(setup) + +$(swig_and_compile_c) + $(run_testcase) + +%.multicpptest: + $(setup) + +$(swig_and_compile_multi_cpp) + $(run_multi_testcase) + +multi_import.multicpptest: + $(setup) + for f in multi_import_b multi_import_a; do \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CXXSRCS="$(CXXSRCS)" \ + SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \ + INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \ + TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$$f.i" \ + $(LANGUAGE)$(VARIANT)_cpp; \ + done + $(run_multi_testcase) + +# Runs the testcase. +run_testcase = \ + if test -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ + $(GO) -I . $(GOCOMPILEARG) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + if $(GOGCC) ; then \ + $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*$(SO); \ + else \ + $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + fi && \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH ./$*_runme; \ + fi + +run_multi_testcase = \ + if test -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ + $(GO) -I . $(GOCOMPILEARG) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + if $(GOGCC) ; then \ + files=`cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; \ + $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.@OBJEXT@ $$f$(SO); done`; \ + else \ + $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + fi && \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH ./$*_runme; \ + fi + +%.clean: + @rm -f $*.go $*_gc.c $*_wrap.* $*_runme + +clean: + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile go_clean + rm -f mod_a.go mod_b.go imports_a.go imports_b.go + rm -f clientdata_prop_a.go clientdata_prop_b.go + rm -f multi_import_a.go multi_import_b.go + rm -f packageoption_a.go packageoption_b.go packageoption_c.go + +cvsignore: + @echo '*_gc.c *_wrap.* *.so *.dll *.exp *.lib' + @echo Makefile + @echo mod_a.go mod_b.go imports_a.go imports_b.go + @echo clientdata_prop_a.go clientdata_prop_b.go + @echo multi_import_a.go multi_import_b.go + @echo packageoption_a.go packageoption_b.go packageoption_c.go + @for i in ${CPP_TEST_CASES} ${C_TEST_CASES}; do echo $$i.go; done diff --git a/Examples/test-suite/go/abstract_access_runme.go b/Examples/test-suite/go/abstract_access_runme.go new file mode 100644 index 000000000..a2cfeda92 --- /dev/null +++ b/Examples/test-suite/go/abstract_access_runme.go @@ -0,0 +1,10 @@ +package main + +import "./abstract_access" + +func main() { + d := abstract_access.NewD() + if d.Do_x() != 1 { + panic(d.Do_x()) + } +} diff --git a/Examples/test-suite/go/abstract_typedef2_runme.go b/Examples/test-suite/go/abstract_typedef2_runme.go new file mode 100644 index 000000000..ef760e45d --- /dev/null +++ b/Examples/test-suite/go/abstract_typedef2_runme.go @@ -0,0 +1,7 @@ +package main + +import "./abstract_typedef2" + +func main() { + abstract_typedef2.NewA_UF() +} diff --git a/Examples/test-suite/go/abstract_typedef_runme.go b/Examples/test-suite/go/abstract_typedef_runme.go new file mode 100644 index 000000000..99ff94ded --- /dev/null +++ b/Examples/test-suite/go/abstract_typedef_runme.go @@ -0,0 +1,11 @@ +package main + +import "./abstract_typedef" + +func main() { + e := abstract_typedef.NewEngine() + a := abstract_typedef.NewA() + if !a.Write(e) { + panic("failed") + } +} diff --git a/Examples/test-suite/go/abstract_virtual_runme.go b/Examples/test-suite/go/abstract_virtual_runme.go new file mode 100644 index 000000000..b87cf9b5c --- /dev/null +++ b/Examples/test-suite/go/abstract_virtual_runme.go @@ -0,0 +1,8 @@ +package main + +import "./abstract_virtual" + +func main() { + abstract_virtual.NewD() + abstract_virtual.NewE() +} diff --git a/Examples/test-suite/go/array_member_runme.go b/Examples/test-suite/go/array_member_runme.go new file mode 100644 index 000000000..d8a8fac2b --- /dev/null +++ b/Examples/test-suite/go/array_member_runme.go @@ -0,0 +1,26 @@ +package main + +import . "./array_member" + +func main() { + f := NewFoo() + f.SetData(GetGlobal_data()) + + for i := 0; i < 8; i++ { + if Get_value(f.GetData(), i) != Get_value(GetGlobal_data(), i) { + panic("Bad array assignment") + } + } + + for i := 0; i < 8; i++ { + Set_value(f.GetData(), i, -i) + } + + SetGlobal_data(f.GetData()) + + for i := 0; i < 8; i++ { + if Get_value(f.GetData(), i) != Get_value(GetGlobal_data(), i) { + panic("Bad array assignment") + } + } +} diff --git a/Examples/test-suite/go/arrays_global_runme.go b/Examples/test-suite/go/arrays_global_runme.go new file mode 100644 index 000000000..0ff40090c --- /dev/null +++ b/Examples/test-suite/go/arrays_global_runme.go @@ -0,0 +1,22 @@ +package main + +import . "./arrays_global" + +func main() { + SetArray_i(GetArray_const_i()) + + GetBeginString_FIX44a() + GetBeginString_FIX44b() + GetBeginString_FIX44c() + GetBeginString_FIX44d() + GetBeginString_FIX44d() + SetBeginString_FIX44b("12\00045") + GetBeginString_FIX44b() + GetBeginString_FIX44d() + GetBeginString_FIX44e() + GetBeginString_FIX44f() + + Test_a("hello", "hi", "chello", "chi") + + Test_b("1234567", "hi") +} diff --git a/Examples/test-suite/go/class_ignore_runme.go b/Examples/test-suite/go/class_ignore_runme.go new file mode 100644 index 000000000..82e52eff5 --- /dev/null +++ b/Examples/test-suite/go/class_ignore_runme.go @@ -0,0 +1,10 @@ +package main + +import "./class_ignore" + +func main() { + a := class_ignore.NewBar() + if class_ignore.Do_blah(a) != "Bar::blah" { + panic(class_ignore.Do_blah(a)) + } +} diff --git a/Examples/test-suite/go/class_scope_weird_runme.go b/Examples/test-suite/go/class_scope_weird_runme.go new file mode 100644 index 000000000..332586f31 --- /dev/null +++ b/Examples/test-suite/go/class_scope_weird_runme.go @@ -0,0 +1,11 @@ +package main + +import "./class_scope_weird" + +func main() { + f := class_scope_weird.NewFoo() + class_scope_weird.NewFoo(3) + if f.Bar(3) != 3 { + panic(f.Bar(3)) + } +} diff --git a/Examples/test-suite/go/compactdefaultargs_runme.go b/Examples/test-suite/go/compactdefaultargs_runme.go new file mode 100644 index 000000000..8818dce07 --- /dev/null +++ b/Examples/test-suite/go/compactdefaultargs_runme.go @@ -0,0 +1,29 @@ +package main + +import . "./compactdefaultargs" + +func main() { + defaults1 := NewDefaults1(1000) + defaults1 = NewDefaults1() + + if defaults1.Ret(float64(10.0)) != 10.0 { + println(1, defaults1.Ret(float64(10.0))) + panic(defaults1.Ret(float64(10.0))) + } + + if defaults1.Ret() != -1.0 { + println(2, defaults1.Ret()) + panic(defaults1.Ret()) + } + + defaults2 := NewDefaults2(1000) + defaults2 = NewDefaults2() + + if defaults2.Ret(float64(10.0)) != 10.0 { + panic(defaults2.Ret(float64(10.0))) + } + + if defaults2.Ret() != -1.0 { + panic(defaults2.Ret()) + } +} diff --git a/Examples/test-suite/go/constover_runme.go b/Examples/test-suite/go/constover_runme.go new file mode 100644 index 000000000..e649140a6 --- /dev/null +++ b/Examples/test-suite/go/constover_runme.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "os" + "./constover" +) + +func main() { + error := 0 + + p := constover.Test("test") + if p != "test" { + fmt.Println("test failed!") + error = 1 + } + + p = constover.Test_pconst("test") + if p != "test_pconst" { + fmt.Println("test_pconst failed!") + error = 1 + } + + f := constover.NewFoo() + p = f.Test("test") + if p != "test" { + fmt.Println("member-test failed!") + error = 1 + } + + p = f.Test_pconst("test") + if p != "test_pconst" { + fmt.Println("member-test_pconst failed!") + error = 1 + } + + p = f.Test_constm("test") + if p != "test_constmethod" { + fmt.Println("member-test_constm failed!") + error = 1 + } + + p = f.Test_pconstm("test") + if p != "test_pconstmethod" { + fmt.Println("member-test_pconstm failed!") + error = 1 + } + + os.Exit(error) +} diff --git a/Examples/test-suite/go/constructor_copy_runme.go b/Examples/test-suite/go/constructor_copy_runme.go new file mode 100644 index 000000000..d9b77a9db --- /dev/null +++ b/Examples/test-suite/go/constructor_copy_runme.go @@ -0,0 +1,34 @@ +package main + +import . "./constructor_copy" + +func main() { + f1 := NewFoo1(3) + f11 := NewFoo1(f1) + + if f1.GetX() != f11.GetX() { + panic("f1/f11 x mismatch") + } + + bi := NewBari(5) + bc := NewBari(bi) + + if bi.GetX() != bc.GetX() { + panic("bi/bc x mismatch") + } + + bd := NewBard(5) + good := false + func() { + defer func() { + if recover() != nil { + good = true + } + }() + NewBard(bd) + }() + + if !good { + panic("bd !good") + } +} diff --git a/Examples/test-suite/go/contract_runme.go b/Examples/test-suite/go/contract_runme.go new file mode 100644 index 000000000..d86110be2 --- /dev/null +++ b/Examples/test-suite/go/contract_runme.go @@ -0,0 +1,208 @@ +package main + +import "./contract" + +func main() { + contract.Test_preassert(1, 2) + contract.Test_postassert(3) + func() { + defer func() { + if recover() == nil { + panic("Failed! Postassertions are broken") + } + }() + contract.Test_postassert(-3) + }() + + contract.Test_prepost(2, 3) + contract.Test_prepost(5, -4) + func() { + defer func() { + if recover() == nil { + panic("Failed! Preassertions are broken") + } + }() + contract.Test_prepost(-3, 4) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Postassertions are broken") + } + }() + contract.Test_prepost(4, -10) + }() + + f := contract.NewFoo() + f.Test_preassert(4, 5) + func() { + defer func() { + if recover() == nil { + panic("Failed! Method preassertion.") + } + }() + f.Test_preassert(-2, 3) + }() + + f.Test_postassert(4) + func() { + defer func() { + if recover() == nil { + panic("Failed! Method postassertion") + } + }() + f.Test_postassert(-4) + }() + + f.Test_prepost(3, 4) + f.Test_prepost(4, -3) + func() { + defer func() { + if recover() == nil { + panic("Failed! Method preassertion.") + } + }() + f.Test_prepost(-4, 2) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Method postassertion.") + } + }() + f.Test_prepost(4, -10) + }() + + contract.FooStest_prepost(4, 0) + func() { + defer func() { + if recover() == nil { + panic("Failed! Static method preassertion") + } + }() + contract.FooStest_prepost(-4, 2) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Static method posteassertion") + } + }() + contract.FooStest_prepost(4, -10) + }() + + b := contract.NewBar() + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion.") + } + }() + b.Test_prepost(2, -4) + }() + + d := contract.NewD() + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Foo(-1, 1, 1, 1, 1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Foo(1, -1, 1, 1, 1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Foo(1, 1, -1, 1, 1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Foo(1, 1, 1, -1, 1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Foo(1, 1, 1, 1, -1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Bar(-1, 1, 1, 1, 1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Bar(1, -1, 1, 1, 1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Bar(1, 1, -1, 1, 1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Bar(1, 1, 1, -1, 1) + }() + + func() { + defer func() { + if recover() == nil { + panic("Failed! Inherited preassertion (D).") + } + }() + d.Bar(1, 1, 1, 1, -1) + }() + + //Namespace + my := contract.NewMyClass(1) + func() { + defer func() { + if recover() == nil { + panic("Failed! constructor preassertion") + } + }() + my = contract.NewMyClass(0) + }() +} diff --git a/Examples/test-suite/go/cpp_enum_runme.go b/Examples/test-suite/go/cpp_enum_runme.go new file mode 100644 index 000000000..7d7db953d --- /dev/null +++ b/Examples/test-suite/go/cpp_enum_runme.go @@ -0,0 +1,27 @@ +package main + +import "./cpp_enum" + +func main() { + f := cpp_enum.NewFoo() + + if f.GetHola() != cpp_enum.FooHello { + panic(f.GetHola()) + } + + f.SetHola(cpp_enum.FooHi) + if f.GetHola() != cpp_enum.FooHi { + panic(f.GetHola()) + } + + f.SetHola(cpp_enum.FooHello) + + if f.GetHola() != cpp_enum.FooHello { + panic(f.GetHola()) + } + + cpp_enum.SetHi(cpp_enum.Hello) + if cpp_enum.GetHi() != cpp_enum.Hello { + panic(cpp_enum.Hi) + } +} diff --git a/Examples/test-suite/go/cpp_namespace_runme.go b/Examples/test-suite/go/cpp_namespace_runme.go new file mode 100644 index 000000000..8482b043f --- /dev/null +++ b/Examples/test-suite/go/cpp_namespace_runme.go @@ -0,0 +1,57 @@ +// Note: This example assumes that namespaces are flattened +package main + +import "./cpp_namespace" + +func main() { + n := cpp_namespace.Fact(4) + if n != 24 { + panic("Bad return value!") + } + + if cpp_namespace.GetFoo() != 42 { + panic("Bad variable value!") + } + + t := cpp_namespace.NewTest() + if t.Method() != "Test::method" { + panic("Bad method return value!") + } + + if cpp_namespace.Do_method(t) != "Test::method" { + panic("Bad return value!") + } + + if cpp_namespace.Do_method2(t) != "Test::method" { + panic("Bad return value!") + } + + cpp_namespace.Weird("hello", 4) + + cpp_namespace.DeleteTest(t) + + t2 := cpp_namespace.NewTest2() + t3 := cpp_namespace.NewTest3() + t4 := cpp_namespace.NewTest4() + t5 := cpp_namespace.NewTest5() + + if cpp_namespace.Foo3(42) != 42 { + panic("Bad return value!") + } + + if cpp_namespace.Do_method3(t2, 40) != "Test2::method" { + panic("Bad return value!") + } + + if cpp_namespace.Do_method3(t3, 40) != "Test3::method" { + panic("Bad return value!") + } + + if cpp_namespace.Do_method3(t4, 40) != "Test4::method" { + panic("Bad return value!") + } + + if cpp_namespace.Do_method3(t5, 40) != "Test5::method" { + panic("Bad return value!") + } +} diff --git a/Examples/test-suite/go/cpp_static_runme.go b/Examples/test-suite/go/cpp_static_runme.go new file mode 100644 index 000000000..ead433466 --- /dev/null +++ b/Examples/test-suite/go/cpp_static_runme.go @@ -0,0 +1,13 @@ +package main + +import . "./cpp_static" + +func main() { + StaticFunctionTestStatic_func() + StaticFunctionTestStatic_func_2(1) + StaticFunctionTestStatic_func_3(1, 2) + SetStaticMemberTestStatic_int(10) + if GetStaticMemberTestStatic_int() != 10 { + panic(GetStaticMemberTestStatic_int()) + } +} diff --git a/Examples/test-suite/go/default_args_runme.go b/Examples/test-suite/go/default_args_runme.go new file mode 100644 index 000000000..38243ac44 --- /dev/null +++ b/Examples/test-suite/go/default_args_runme.go @@ -0,0 +1,26 @@ +package main + +import "./default_args" + +func main() { + if default_args.StaticsStaticmethod() != 60 { + panic(0) + } + + if default_args.Cfunc1(1) != 2 { + panic(0) + } + + if default_args.Cfunc2(1) != 3 { + panic(0) + } + + if default_args.Cfunc3(1) != 4 { + panic(0) + } + + f := default_args.NewFoo() + + f.Newname() + f.Newname(1) +} diff --git a/Examples/test-suite/go/default_constructor_runme.go b/Examples/test-suite/go/default_constructor_runme.go new file mode 100644 index 000000000..e5e325475 --- /dev/null +++ b/Examples/test-suite/go/default_constructor_runme.go @@ -0,0 +1,35 @@ +package main + +import dc "./default_constructor" + +func main() { + a := dc.NewA() + dc.DeleteA(a) + + aa := dc.NewAA() + dc.DeleteAA(aa) + + cc := dc.NewCC() + dc.DeleteCC(cc) + + e := dc.NewE() + dc.DeleteE(e) + + ee := dc.NewEE() + dc.DeleteEE(ee) + + f := dc.NewF() + f.Destroy() + + ff := dc.NewFFF() + ff.Destroy() + + g := dc.NewG() + + dc.GDestroy(g) + + gg := dc.NewGG() + dc.DeleteGG(gg) + + dc.NewHH(1, 1) +} diff --git a/Examples/test-suite/go/director_abstract_runme.go b/Examples/test-suite/go/director_abstract_runme.go new file mode 100644 index 000000000..37279383a --- /dev/null +++ b/Examples/test-suite/go/director_abstract_runme.go @@ -0,0 +1,62 @@ +package main + +import "./director_abstract" + +type MyFoo struct{} + +func (p *MyFoo) Ping() string { + return "MyFoo::ping()" +} + +func f1() { + a := director_abstract.NewDirectorFoo(&MyFoo{}) + + if a.Ping() != "MyFoo::ping()" { + panic(a.Ping()) + } + + if a.Pong() != "Foo::pong();MyFoo::ping()" { + panic(a.Pong()) + } +} + +type MyExample1 struct{} + +func (p *MyExample1) Color(r, g, b byte) int { + return int(r) +} + +type MyExample2 struct{} + +func (p *MyExample2) Color(r, g, b byte) int { + return int(g) +} + +type MyExample3 struct{} + +func (p *MyExample3) Color(r, g, b byte) int { + return int(b) +} + +func f2() { + me1 := director_abstract.NewDirectorExample1(&MyExample1{}) + if director_abstract.Example1Get_color(me1, 1, 2, 3) != 1 { + println(director_abstract.Example1Get_color(me1, 1, 2, 3)) + panic(0) + } + + me2 := director_abstract.NewDirectorExample2(&MyExample2{}, 1, 2) + if director_abstract.Example2Get_color(me2, 1, 2, 3) != 2 { + panic(0) + } + + me3 := director_abstract.NewDirectorExample3_i(&MyExample3{}) + if director_abstract.Example3_iGet_color(me3, 1, 2, 3) != 3 { + panic(0) + } +} + +func main() { + f1() + f2() +} diff --git a/Examples/test-suite/go/director_basic_runme.go b/Examples/test-suite/go/director_basic_runme.go new file mode 100644 index 000000000..1995452ce --- /dev/null +++ b/Examples/test-suite/go/director_basic_runme.go @@ -0,0 +1,115 @@ +package main + +import "./director_basic" + +type GoFoo struct{} + +func (p *GoFoo) Ping() string { + return "GoFoo::ping()" +} + +func f1() { + a := director_basic.NewDirectorFoo(&GoFoo{}) + + if a.Ping() != "GoFoo::ping()" { + panic(a.Ping()) + } + + if a.Pong() != "Foo::pong();GoFoo::ping()" { + panic(a.Pong()) + } + + b := director_basic.NewFoo() + + if b.Ping() != "Foo::ping()" { + panic(b.Ping()) + } + + if b.Pong() != "Foo::pong();Foo::ping()" { + panic(b.Pong()) + } + + a1 := director_basic.NewA1(1) + + if a1.Rg(2) != 2 { + panic(0) + } +} + +type GoClass struct { + cmethod int +} + +func (p *GoClass) Method(uintptr) { + p.cmethod = 7 +} +func (p *GoClass) Vmethod(b director_basic.Bar) director_basic.Bar { + b.SetX(b.GetX() + 31) + return b +} + +var bc director_basic.Bar + +func f2() { + b := director_basic.NewBar(3) + d := director_basic.NewMyClass() + pc := &GoClass{0} + c := director_basic.NewDirectorMyClass(pc) + + cc := director_basic.MyClassGet_self(c) + dd := director_basic.MyClassGet_self(d) + + bc = cc.Cmethod(b) + bd := dd.Cmethod(b) + + cc.Method(b.Swigcptr()) + if pc.cmethod != 7 { + panic(pc.cmethod) + } + + if bc.GetX() != 34 { + panic(bc.GetX()) + } + + if bd.GetX() != 16 { + panic(bd.GetX()) + } +} + +type GoMulti struct { + GoClass +} + +func (p *GoMulti) Vmethod(b director_basic.Bar) director_basic.Bar { + b.SetX(b.GetX() + 31) + return b +} +func (p *GoMulti) Ping() string { + return "GoFoo::ping()" +} + +func f3() { + for i := 0; i < 100; i++ { + p := &GoMulti{GoClass{0}} + gomult := director_basic.NewDirectorFoo(p) + gomult.Pong() + director_basic.DeleteDirectorFoo(gomult) + } + + p := &GoMulti{GoClass{0}} + gomult := director_basic.NewDirectorMyClass(p) + fgomult := director_basic.NewDirectorFoo(gomult) + + p1 := director_basic.FooGet_self(fgomult.(director_basic.Foo)) + p2 := director_basic.MyClassGet_self(gomult.(director_basic.MyClass)) + + p1.Ping() + p2.Vmethod(bc) +} + + +func main() { + f1() + f2() + f3() +} diff --git a/Examples/test-suite/go/director_classic_runme.go b/Examples/test-suite/go/director_classic_runme.go new file mode 100644 index 000000000..45e89eac5 --- /dev/null +++ b/Examples/test-suite/go/director_classic_runme.go @@ -0,0 +1,135 @@ +package main + +import "fmt" +import . "./director_classic" + +type TargetLangPerson struct{} // From Person +func (p *TargetLangPerson) Id() string { + return "TargetLangPerson" +} + +type TargetLangChild struct{} // Form Child +func (p *TargetLangChild) Id() string { + return "TargetLangChild" +} + +type TargetLangGrandChild struct{} // From Grandchild +func (p *TargetLangGrandChild) Id() string { + return "TargetLangGrandChild" +} + +// Semis - don't override id() in target language + +type TargetLangSemiPerson struct{} // From Person + +type TargetLangSemiChild struct{} // From Child + +type TargetLangSemiGrandChild struct{} // From GrandChild + +// Orphans - don't override id() in C++ + +type TargetLangOrphanPerson struct{} // From OrphanPerson +func (p *TargetLangOrphanPerson) Id() string { + return "TargetLangOrphanPerson" +} + +type TargetLangOrphanChild struct{} // From OrphanChild +func (p *TargetLangOrphanChild) Id() string { + return "TargetLangOrphanChild" +} + +func check(person Person, expected string) { + debug := false + + // Normal target language polymorphic call + ret := person.Id() + if debug { + fmt.Println(ret) + } + if ret != expected { + panic("Failed. Received: " + ret + " Expected: " + expected) + } + + // Polymorphic call from C++ + caller := NewCaller() + caller.SetCallback(person) + ret = caller.Call() + if debug { + fmt.Println(ret) + } + if ret != expected { + panic("Failed. Received: " + ret + " Expected: " + expected) + } + + // Polymorphic call of object created in target language and + // passed to C++ and back again + baseclass := caller.BaseClass() + ret = baseclass.Id() + if debug { + fmt.Println(ret) + } + if ret != expected { + panic("Failed. Received: " + ret + " Expected: " + expected) + } + + caller.ResetCallback() + if debug { + fmt.Println("----------------------------------------") + } +} + +func main() { + person := NewPerson() + check(person, "Person") + DeletePerson(person) + + person = NewChild() + check(person, "Child") + DeletePerson(person) + + person = NewGrandChild() + check(person, "GrandChild") + DeletePerson(person) + + person = NewDirectorPerson(&TargetLangPerson{}) + check(person, "TargetLangPerson") + DeleteDirectorPerson(person) + + person = NewDirectorChild(&TargetLangChild{}) + check(person, "TargetLangChild") + DeleteDirectorChild(person.(Child)) + + person = NewDirectorGrandChild(&TargetLangGrandChild{}) + check(person, "TargetLangGrandChild") + DeleteDirectorGrandChild(person.(GrandChild)) + + // Semis - don't override id() in target language + person = NewDirectorPerson(&TargetLangSemiPerson{}) + check(person, "Person") + DeleteDirectorPerson(person) + + person = NewDirectorChild(&TargetLangSemiChild{}) + check(person, "Child") + DeleteDirectorChild(person.(Child)) + + person = NewDirectorGrandChild(&TargetLangSemiGrandChild{}) + check(person, "GrandChild") + DeleteDirectorGrandChild(person.(GrandChild)) + + // Orphans - don't override id() in C++ + person = NewOrphanPerson() + check(person, "Person") + DeleteOrphanPerson(person.(OrphanPerson)) + + person = NewOrphanChild() + check(person, "Child") + DeleteOrphanChild(person.(OrphanChild)) + + person = NewDirectorOrphanPerson(&TargetLangOrphanPerson{}) + check(person, "TargetLangOrphanPerson") + DeleteDirectorOrphanPerson(person.(OrphanPerson)) + + person = NewDirectorOrphanChild(&TargetLangOrphanChild{}) + check(person, "TargetLangOrphanChild") + DeleteDirectorOrphanChild(person.(OrphanChild)) +} diff --git a/Examples/test-suite/go/director_default_runme.go b/Examples/test-suite/go/director_default_runme.go new file mode 100644 index 000000000..2f963b239 --- /dev/null +++ b/Examples/test-suite/go/director_default_runme.go @@ -0,0 +1,11 @@ +package main + +import . "./director_default" + +func main() { + NewFoo() + NewFoo(1) + + NewBar() + NewBar(1) +} diff --git a/Examples/test-suite/go/director_detect_runme.go b/Examples/test-suite/go/director_detect_runme.go new file mode 100644 index 000000000..9f1ad94a9 --- /dev/null +++ b/Examples/test-suite/go/director_detect_runme.go @@ -0,0 +1,46 @@ +package main + +import "./director_detect" + +type MyBar struct { + val int +} // From director_detect.Bar + +func NewMyBar() director_detect.Bar { + return director_detect.NewDirectorBar(&MyBar{2}) +} + +func (p *MyBar) Get_value() int { + p.val++ + return p.val +} + +func (p *MyBar) Get_class() director_detect.A { + p.val++ + return director_detect.NewA() +} + +func (p *MyBar) Just_do_it() { + p.val++ +} + +func (p *MyBar) Clone() director_detect.Bar { + return director_detect.NewDirectorBar(&MyBar{p.val}) +} + +func main() { + b := NewMyBar() + + f := b.Baseclass() + + v := f.Get_value() + _ = f.Get_class() + f.Just_do_it() + + c := b.DirectorInterface().(*MyBar).Clone() + vc := c.Get_value() + + if (v != 3) || (b.DirectorInterface().(*MyBar).val != 5) || (vc != 6) { + panic("Bad virtual detection") + } +} diff --git a/Examples/test-suite/go/director_enum_runme.go b/Examples/test-suite/go/director_enum_runme.go new file mode 100644 index 000000000..e0dad900b --- /dev/null +++ b/Examples/test-suite/go/director_enum_runme.go @@ -0,0 +1,17 @@ +package main + +import "./director_enum" + +type MyFoo struct{} // From director_enum.Foo +func (p *MyFoo) Say_hi(val director_enum.EnumDirectorHelloe) director_enum.EnumDirectorHelloe { + return val +} + +func main() { + b := director_enum.NewFoo() + a := director_enum.NewDirectorFoo(&MyFoo{}) + + if a.Say_hi(director_enum.Hello) != b.Say_hello(director_enum.Hi) { + panic(0) + } +} diff --git a/Examples/test-suite/go/director_exception_runme.go b/Examples/test-suite/go/director_exception_runme.go new file mode 100644 index 000000000..29df3e40b --- /dev/null +++ b/Examples/test-suite/go/director_exception_runme.go @@ -0,0 +1,95 @@ +package main + +import . "./director_exception" + +type Exception struct { + msg string +} + +func NewException(a, b string) *Exception { + return &Exception{a + b} +} + +type MyFoo struct{} // From Foo +func (p *MyFoo) Ping() string { + panic("MyFoo::ping() EXCEPTION") +} + +type MyFoo2 struct{} // From Foo +func (p *MyFoo2) Ping() bool { + return true // should return a string +} + +type MyFoo3 struct{} // From Foo +func (p *MyFoo3) Ping() string { + panic(NewException("foo", "bar")) +} + +func main() { + // Check that the NotImplementedError raised by MyFoo.ping() + // is returned by MyFoo.pong(). + ok := false + a := NewDirectorFoo(&MyFoo{}) + b := Launder(a) + func() { + defer func() { + e := recover() + if e.(string) == "MyFoo::ping() EXCEPTION" { + ok = true + } else { + panic("Unexpected error message: " + e.(string)) + } + }() + b.Pong() + }() + if !ok { + panic(0) + } + + // Check that if the method has the wrong return type it is + // not called. + ok = false + a = NewDirectorFoo(&MyFoo2{}) + b = Launder(a) + e := b.Pong() + if e != "Foo::pong();"+"Foo::ping()" { + panic(e) + } + + // Check that the director can return an exception which + // requires two arguments to the constructor, without mangling + // it. + ok = false + a = NewDirectorFoo(&MyFoo3{}) + b = Launder(a) + func() { + defer func() { + e := recover() + if e.(*Exception).msg == "foobar" { + ok = true + } else { + panic("Unexpected error message: " + e.(string)) + } + }() + b.Pong() + }() + if !ok { + panic(0) + } + + func() { + defer func() { + e := recover() + _ = e.(Exception2) + }() + panic(NewException2()) + }() + + func() { + defer func() { + e := recover() + _ = e.(Exception1) + }() + panic(NewException1()) + }() +} diff --git a/Examples/test-suite/go/director_extend_runme.go b/Examples/test-suite/go/director_extend_runme.go new file mode 100644 index 000000000..70e2ab41b --- /dev/null +++ b/Examples/test-suite/go/director_extend_runme.go @@ -0,0 +1,18 @@ +// Test case from bug #1506850 "When threading is enabled, the +// interpreter will infinitely wait on a mutex the second time this +// type of extended method is called. Attached is an example program +// that waits on the mutex to be unlocked." + +package main + +import . "./director_extend" + +func main() { + m := NewSpObject() + if m.Dummy() != 666 { + panic("1st call") + } + if m.Dummy() != 666 { + panic("2nd call") + } +} diff --git a/Examples/test-suite/go/director_finalizer_runme.go b/Examples/test-suite/go/director_finalizer_runme.go new file mode 100644 index 000000000..96fcf860e --- /dev/null +++ b/Examples/test-suite/go/director_finalizer_runme.go @@ -0,0 +1,37 @@ +package main + +import . "./director_finalizer" + +type MyFoo struct{} // From Foo +func DeleteMyFoo(p Foo) { + p.OrStatus(2) + DeleteFoo(p) +} + +func main() { + ResetStatus() + + a := NewDirectorFoo(&MyFoo{}) + DeleteMyFoo(a) + + if GetStatus() != 3 { + panic(0) + } + + ResetStatus() + + a = NewDirectorFoo(&MyFoo{}) + Launder(a) + + if GetStatus() != 0 { + panic(0) + } + + DeleteMyFoo(a) + + if GetStatus() != 3 { + panic(0) + } + + ResetStatus() +} diff --git a/Examples/test-suite/go/director_frob_runme.go b/Examples/test-suite/go/director_frob_runme.go new file mode 100644 index 000000000..a6afedf69 --- /dev/null +++ b/Examples/test-suite/go/director_frob_runme.go @@ -0,0 +1,12 @@ +package main + +import . "./director_frob" + +func main() { + foo := NewBravo() + s := foo.Abs_method() + + if s != "Bravo::abs_method()" { + panic(s) + } +} diff --git a/Examples/test-suite/go/director_nested_runme.go b/Examples/test-suite/go/director_nested_runme.go new file mode 100644 index 000000000..2d3bc77e1 --- /dev/null +++ b/Examples/test-suite/go/director_nested_runme.go @@ -0,0 +1,79 @@ +package main + +import . "./director_nested" + +type A struct{} // From FooBar_int +func (p *A) Do_step() string { + return "A::do_step;" +} +func (p *A) Get_value() string { + return "A::get_value" +} + +func f1() { + a := NewDirectorFooBar_int(&A{}) + if a.Step() != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;" { + panic("Bad A virtual resolution") + } +} + +type B struct{} // From FooBar_int +func (p *B) Do_advance() string { + return "B::do_advance;" + p.Do_step() +} +func (p *B) Do_step() string { + return "B::do_step;" +} +func (p *B) Get_value() int { + return 1 +} + +func f2() { + b := NewDirectorFooBar_int(&B{}) + + if b.Step() != "Bar::step;Foo::advance;B::do_advance;B::do_step;" { + panic("Bad B virtual resolution") + } +} + +type C struct { + fbi FooBar_int +} // From FooBar_int + +func (p *C) Do_advance() string { + return "C::do_advance;" + DirectorFooBar_intDo_advance(p.fbi) +} + +func (p *C) Do_step() string { + return "C::do_step;" +} + +func (p *C) Get_value() int { + return 2 +} + +func (p *C) Get_name() string { + return DirectorFooBar_intGet_name(p.fbi) + " hello" +} + +func f3() { + m := &C{nil} + cc := NewDirectorFooBar_int(m) + m.fbi = cc + c := FooBar_intGet_self(cc) + c.Advance() + + if c.Get_name() != "FooBar::get_name hello" { + panic(0) + } + + if c.Name() != "FooBar::get_name hello" { + panic(0) + } +} + +func main() { + f1() + f2() + f3() +} diff --git a/Examples/test-suite/go/director_profile_runme.go b/Examples/test-suite/go/director_profile_runme.go new file mode 100644 index 000000000..87edcbe26 --- /dev/null +++ b/Examples/test-suite/go/director_profile_runme.go @@ -0,0 +1,49 @@ +package main + +import "fmt" +import "./director_profile" + +type MyB struct{} // From director_profile.B +func (p *MyB) Vfi(a int) int { + return a + 3 +} + +func main() { + _ = director_profile.NewA() + myb := director_profile.NewDirectorB(&MyB{}) + b := director_profile.BGet_self(myb) + + fi := func(a int) int { + return b.Fi(a) + } + + i := 50000 + a := 1 + for i != 0 { + a = fi(a) // 1 + a = fi(a) // 2 + a = fi(a) // 3 + a = fi(a) // 4 + a = fi(a) // 5 + a = fi(a) // 6 + a = fi(a) // 7 + a = fi(a) // 8 + a = fi(a) // 9 + a = fi(a) // 10 + a = fi(a) // 1 + a = fi(a) // 2 + a = fi(a) // 3 + a = fi(a) // 4 + a = fi(a) // 5 + a = fi(a) // 6 + a = fi(a) // 7 + a = fi(a) // 8 + a = fi(a) // 9 + a = fi(a) // 20 + i -= 1 + } + + if false { + fmt.Println(a) + } +} diff --git a/Examples/test-suite/go/director_protected_runme.go b/Examples/test-suite/go/director_protected_runme.go new file mode 100644 index 000000000..3ffc1fbfa --- /dev/null +++ b/Examples/test-suite/go/director_protected_runme.go @@ -0,0 +1,48 @@ +package main + +import . "./director_protected" + +type FooBar struct{} // From Bar +func (p *FooBar) Ping() string { + return "FooBar::ping();" +} + +type FooBar2 struct{} // From Bar +func (p *FooBar2) Ping() string { + return "FooBar2::ping();" +} +func (p *FooBar2) Pang() string { + return "FooBar2::pang();" +} + +func main() { + b := NewBar() + f := b.Create() + fb := NewDirectorBar(&FooBar{}) + fb2 := NewDirectorBar(&FooBar2{}) + + s := fb.Used() + if s != "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();" { + panic(0) + } + + s = fb2.Used() + if s != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();" { + panic(0) + } + + s = b.Pong() + if s != "Bar::pong();Foo::pong();Bar::ping();" { + panic(0) + } + + s = f.Pong() + if s != "Bar::pong();Foo::pong();Bar::ping();" { + panic(0) + } + + s = fb.Pong() + if s != "Bar::pong();Foo::pong();FooBar::ping();" { + panic(0) + } +} diff --git a/Examples/test-suite/go/director_string_runme.go b/Examples/test-suite/go/director_string_runme.go new file mode 100644 index 000000000..c5201ab96 --- /dev/null +++ b/Examples/test-suite/go/director_string_runme.go @@ -0,0 +1,39 @@ +package main + +import . "./director_string" + +type B struct { // From A + abi A + smem string +} + +func NewB(s string) A { + p := &B{nil, ""} + ret := NewDirectorA(p, s) + p.abi = ret + return ret +} + +func (p *B) Get_first() string { + return DirectorAGet_first(p.abi) + " world!" +} + +func (p *B) Process_text(s string) { + DirectorAProcess_text(p.abi, s) + p.smem = "hello" +} + +func main() { + b := NewB("hello") + + b.Get(0) + if b.Get_first() != "hello world!" { + panic(b.Get_first()) + } + + b.Call_process_func() + + if b.DirectorInterface().(*B).smem != "hello" { + panic(b.DirectorInterface().(*B).smem) + } +} diff --git a/Examples/test-suite/go/director_thread_runme.go b/Examples/test-suite/go/director_thread_runme.go new file mode 100644 index 000000000..ddfacedbe --- /dev/null +++ b/Examples/test-suite/go/director_thread_runme.go @@ -0,0 +1,28 @@ +package main + +import . "./director_thread" + +type Derived struct { + abi Foo +} // From Foo +func (p *Derived) Do_foo() { + p.abi.SetVal(p.abi.GetVal() - 1) +} + +func main() { + + // FIXME: This test fails until we fix callbacks from a + // different thread. + return + + p := &Derived{nil} + d := NewDirectorFoo(p) + p.abi = d + d.Run() + + if d.GetVal() >= 0 { + panic(d.GetVal()) + } + + d.Stop() +} diff --git a/Examples/test-suite/go/director_unroll_runme.go b/Examples/test-suite/go/director_unroll_runme.go new file mode 100644 index 000000000..6d2894a72 --- /dev/null +++ b/Examples/test-suite/go/director_unroll_runme.go @@ -0,0 +1,21 @@ +package main + +import "./director_unroll" + +type MyFoo struct{} // From director_unroll.Foo +func (p *MyFoo) Ping() string { + return "MyFoo::ping()" +} + +func main() { + a := director_unroll.NewDirectorFoo(&MyFoo{}) + + b := director_unroll.NewBar() + + b.Set(a) + c := b.Get() + + if c.Ping() != "MyFoo::ping()" { + panic(c.Ping()) + } +} diff --git a/Examples/test-suite/go/disown_runme.go b/Examples/test-suite/go/disown_runme.go new file mode 100644 index 000000000..3e853de59 --- /dev/null +++ b/Examples/test-suite/go/disown_runme.go @@ -0,0 +1,10 @@ +package main + +import . "./disown" + +func main() { + a := NewA() + + b := NewB() + b.Acquire(a) +} diff --git a/Examples/test-suite/go/dynamic_cast_runme.go b/Examples/test-suite/go/dynamic_cast_runme.go new file mode 100644 index 000000000..476734805 --- /dev/null +++ b/Examples/test-suite/go/dynamic_cast_runme.go @@ -0,0 +1,16 @@ +package main + +import "./dynamic_cast" + +func main() { + f := dynamic_cast.NewFoo() + b := dynamic_cast.NewBar() + + _ = f.Blah() + y := b.Blah() + + a := dynamic_cast.Do_test(dynamic_cast.FooToBar(y)) + if a != "Bar::test" { + panic("Failed!!") + } +} diff --git a/Examples/test-suite/go/empty_runme.go b/Examples/test-suite/go/empty_runme.go new file mode 100644 index 000000000..f74285cb0 --- /dev/null +++ b/Examples/test-suite/go/empty_runme.go @@ -0,0 +1,6 @@ +package main + +import _ "./empty" + +func main() { +} diff --git a/Examples/test-suite/go/enum_template_runme.go b/Examples/test-suite/go/enum_template_runme.go new file mode 100644 index 000000000..269fe7d5b --- /dev/null +++ b/Examples/test-suite/go/enum_template_runme.go @@ -0,0 +1,11 @@ +package main + +import "./enum_template" + +func main() { + if enum_template.MakeETest() != 1 { + panic(0) + } + + enum_template.TakeETest(0) +} diff --git a/Examples/test-suite/go/enums_runme.go b/Examples/test-suite/go/enums_runme.go new file mode 100644 index 000000000..ab193f74b --- /dev/null +++ b/Examples/test-suite/go/enums_runme.go @@ -0,0 +1,25 @@ +package main + +import "./enums" + +func main() { + enums.Bar2(1) + enums.Bar3(1) + enums.Bar1(1) + + if enums.GetEnumInstance() != 2 { + panic(0) + } + + if enums.GetSlap() != 10 { + panic(0) + } + + if enums.GetMine() != 11 { + panic(0) + } + + if enums.GetThigh() != 12 { + panic(0) + } +} diff --git a/Examples/test-suite/go/exception_order_runme.go b/Examples/test-suite/go/exception_order_runme.go new file mode 100644 index 000000000..626a826f8 --- /dev/null +++ b/Examples/test-suite/go/exception_order_runme.go @@ -0,0 +1,58 @@ +package main + +import "strings" +import . "./exception_order" + +func main() { + a := NewA() + + func() { + defer func() { + e := recover() + if strings.Index(e.(string), "E1") == -1 { + panic(e.(string)) + } + }() + a.Foo() + }() + + func() { + defer func() { + e := recover() + if strings.Index(e.(string), "E2") == -1 { + panic(e.(string)) + } + }() + a.Bar() + }() + + func() { + defer func() { + e := recover() + if e.(string) != "postcatch unknown" { + panic("bad exception order") + } + }() + a.Foobar() + }() + + func() { + defer func() { + e := recover() + if strings.Index(e.(string), "E1") == -1 { + panic(e.(string)) + } + }() + a.Barfoo(1) + }() + + func() { + defer func() { + e := recover() + if strings.Index(e.(string), "E2") == -1 { + panic(e.(string)) + } + }() + a.Barfoo(2) + }() +} diff --git a/Examples/test-suite/go/extend_placement_runme.go b/Examples/test-suite/go/extend_placement_runme.go new file mode 100644 index 000000000..f74831c7d --- /dev/null +++ b/Examples/test-suite/go/extend_placement_runme.go @@ -0,0 +1,47 @@ +package main + +import "./extend_placement" + +func main() { + foo := extend_placement.NewFoo() + foo = extend_placement.NewFoo(1) + foo = extend_placement.NewFoo(1, 1) + foo.Spam() + foo.Spam("hello") + foo.Spam(1) + foo.Spam(1, 1) + foo.Spam(1, 1, 1) + foo.Spam(extend_placement.NewFoo()) + foo.Spam(extend_placement.NewFoo(), float64(1.0)) + + bar := extend_placement.NewBar() + bar = extend_placement.NewBar(1) + bar.Spam() + bar.Spam("hello") + bar.Spam(1) + bar.Spam(1, 1) + bar.Spam(1, 1, 1) + bar.Spam(extend_placement.NewBar()) + bar.Spam(extend_placement.NewBar(), float64(1.0)) + + footi := extend_placement.NewFooTi() + footi = extend_placement.NewFooTi(1) + footi = extend_placement.NewFooTi(1, 1) + footi.Spam() + footi.Spam("hello") + footi.Spam(1) + footi.Spam(1, 1) + footi.Spam(1, 1, 1) + footi.Spam(extend_placement.NewFoo()) + footi.Spam(extend_placement.NewFoo(), float64(1.0)) + + barti := extend_placement.NewBarTi() + barti = extend_placement.NewBarTi(1) + barti.Spam() + barti.Spam("hello") + barti.Spam(1) + barti.Spam(1, 1) + barti.Spam(1, 1, 1) + barti.Spam(extend_placement.NewBar()) + barti.Spam(extend_placement.NewBar(), float64(1.0)) +} diff --git a/Examples/test-suite/go/extend_template_ns_runme.go b/Examples/test-suite/go/extend_template_ns_runme.go new file mode 100644 index 000000000..164a31b26 --- /dev/null +++ b/Examples/test-suite/go/extend_template_ns_runme.go @@ -0,0 +1,14 @@ +package main + +import . "./extend_template_ns" + +func main() { + f := NewFoo_One() + if f.Test1(37) != 37 { + panic(0) + } + + if f.Test2(42) != 42 { + panic(0) + } +} diff --git a/Examples/test-suite/go/extend_template_runme.go b/Examples/test-suite/go/extend_template_runme.go new file mode 100644 index 000000000..5adb4b3c2 --- /dev/null +++ b/Examples/test-suite/go/extend_template_runme.go @@ -0,0 +1,14 @@ +package main + +import "./extend_template" + +func main() { + f := extend_template.NewFoo_0() + if f.Test1(37) != 37 { + panic(0) + } + + if f.Test2(42) != 42 { + panic(0) + } +} diff --git a/Examples/test-suite/go/extend_variable_runme.go b/Examples/test-suite/go/extend_variable_runme.go new file mode 100644 index 000000000..c6428c467 --- /dev/null +++ b/Examples/test-suite/go/extend_variable_runme.go @@ -0,0 +1,9 @@ +package main + +import . "./extend_variable" + +func main() { + if FooBar != 42 { + panic(0) + } +} diff --git a/Examples/test-suite/go/extern_c_runme.go b/Examples/test-suite/go/extern_c_runme.go new file mode 100644 index 000000000..0fb5b21cc --- /dev/null +++ b/Examples/test-suite/go/extern_c_runme.go @@ -0,0 +1,7 @@ +package main + +import "./extern_c" + +func main() { + extern_c.RealFunction(2) +} diff --git a/Examples/test-suite/go/friends_runme.go b/Examples/test-suite/go/friends_runme.go new file mode 100644 index 000000000..80177bae8 --- /dev/null +++ b/Examples/test-suite/go/friends_runme.go @@ -0,0 +1,50 @@ +package main + +import "./friends" + +func main() { + a := friends.NewA(2) + + if friends.Get_val1(a).(int) != 2 { + panic(0) + } + if friends.Get_val2(a) != 4 { + panic(0) + } + if friends.Get_val3(a) != 6 { + panic(0) + } + + // nice overload working fine + if friends.Get_val1(1, 2, 3).(int) != 1 { + panic(0) + } + + b := friends.NewB(3) + + // David's case + if friends.Mix(a, b) != 5 { + panic(0) + } + + di := friends.NewD_d(2) + dd := friends.NewD_d(3.3) + + // incredible template overloading working just fine + if friends.Get_val1(di).(float64) != 2 { + panic(0) + } + if friends.Get_val1(dd).(float64) != 3.3 { + panic(0) + } + + friends.Set(di, float64(4.0)) + friends.Set(dd, float64(1.3)) + + if friends.Get_val1(di).(float64) != 4 { + panic(0) + } + if friends.Get_val1(dd).(float64) != 1.3 { + panic(0) + } +} diff --git a/Examples/test-suite/go/fvirtual_runme.go b/Examples/test-suite/go/fvirtual_runme.go new file mode 100644 index 000000000..8810d5cbb --- /dev/null +++ b/Examples/test-suite/go/fvirtual_runme.go @@ -0,0 +1,13 @@ +package main + +import . "./fvirtual" + +func main() { + sw := NewNodeSwitch() + n := NewNode() + i := sw.AddChild(n) + + if i != 2 { + panic("addChild") + } +} diff --git a/Examples/test-suite/go/global_ns_arg_runme.go b/Examples/test-suite/go/global_ns_arg_runme.go new file mode 100644 index 000000000..f4c8a7ed5 --- /dev/null +++ b/Examples/test-suite/go/global_ns_arg_runme.go @@ -0,0 +1,8 @@ +package main + +import . "./global_ns_arg" + +func main() { + Foo(1) + Bar() +} diff --git a/Examples/test-suite/go/grouping_runme.go b/Examples/test-suite/go/grouping_runme.go new file mode 100644 index 000000000..c63d6fb12 --- /dev/null +++ b/Examples/test-suite/go/grouping_runme.go @@ -0,0 +1,19 @@ +package main + +import "./grouping" + +func main() { + x := grouping.Test1(42) + if x != 42 { + panic(0) + } + + grouping.Test2(42) + + x = grouping.Do_unary(37, grouping.NEGATE) + if x != -37 { + panic(0) + } + + grouping.SetTest3(42) +} diff --git a/Examples/test-suite/go/import_nomodule_runme.go b/Examples/test-suite/go/import_nomodule_runme.go new file mode 100644 index 000000000..a6bbd7de5 --- /dev/null +++ b/Examples/test-suite/go/import_nomodule_runme.go @@ -0,0 +1,12 @@ +package main + +import . "./import_nomodule" + +func main() { + f := Create_Foo() + Test1(f, 42) + Delete_Foo(f) + + b := NewBar() + Test1(b, 37) +} diff --git a/Examples/test-suite/go/imports_runme.go b/Examples/test-suite/go/imports_runme.go new file mode 100644 index 000000000..896036cbf --- /dev/null +++ b/Examples/test-suite/go/imports_runme.go @@ -0,0 +1,17 @@ +// This is the import runtime testcase. + +package main + +import "imports_b" +import "imports_a" + +func main() { + x := imports_b.NewB() + x.Hello() + + _ = imports_a.NewA() + + c := imports_b.NewC() + _ = c.Get_a(c) + _ = c.Get_a_type(c) +} diff --git a/Examples/test-suite/go/inctest_runme.go b/Examples/test-suite/go/inctest_runme.go new file mode 100644 index 000000000..f8a2c116c --- /dev/null +++ b/Examples/test-suite/go/inctest_runme.go @@ -0,0 +1,18 @@ +package main + +import "./inctest" + +func main() { + inctest.NewA() + inctest.NewB() + + // Check the import in subdirectory worked + if inctest.Importtest1(5) != 15 { + panic("import test 1 failed") + } + + a := []byte("black") + if inctest.Importtest2(string(a)) != "white" { + panic("import test 2 failed") + } +} diff --git a/Examples/test-suite/go/inherit_missing_runme.go b/Examples/test-suite/go/inherit_missing_runme.go new file mode 100644 index 000000000..ba9a2a516 --- /dev/null +++ b/Examples/test-suite/go/inherit_missing_runme.go @@ -0,0 +1,26 @@ +package main + +import "./inherit_missing" + +func main() { + a := inherit_missing.New_Foo() + b := inherit_missing.NewBar() + c := inherit_missing.NewSpam() + + x := inherit_missing.Do_blah(a) + if x != "Foo::blah" { + panic(x) + } + + x = inherit_missing.Do_blah(b) + if x != "Bar::blah" { + panic(x) + } + + x = inherit_missing.Do_blah(c) + if x != "Spam::blah" { + panic(x) + } + + inherit_missing.Delete_Foo(a) +} diff --git a/Examples/test-suite/go/input_runme.go b/Examples/test-suite/go/input_runme.go new file mode 100644 index 000000000..207bdaa28 --- /dev/null +++ b/Examples/test-suite/go/input_runme.go @@ -0,0 +1,14 @@ +package main + +import . "./input" + +func main() { + f := NewFoo() + if f.Foo(2) != 4 { + panic(0) + } + + if Sfoo("Hello") != "Hello world" { + panic(0) + } +} diff --git a/Examples/test-suite/go/keyword_rename_runme.go b/Examples/test-suite/go/keyword_rename_runme.go new file mode 100644 index 000000000..e36bc5968 --- /dev/null +++ b/Examples/test-suite/go/keyword_rename_runme.go @@ -0,0 +1,8 @@ +package main + +import "./keyword_rename" + +func main() { + keyword_rename.Xgo(1) + keyword_rename.Xchan(1) +} diff --git a/Examples/test-suite/go/li_attribute_runme.go b/Examples/test-suite/go/li_attribute_runme.go new file mode 100644 index 000000000..5d2c3d0c3 --- /dev/null +++ b/Examples/test-suite/go/li_attribute_runme.go @@ -0,0 +1,90 @@ +package main + +import "./li_attribute" + +func main() { + aa := li_attribute.NewA(1, 2, 3) + + if aa.GetA() != 1 { + panic(0) + } + aa.SetA(3) + if aa.GetA() != 3 { + panic(aa.GetA()) + } + + if aa.GetB() != 2 { + panic(aa.GetB()) + } + aa.SetB(5) + if aa.GetB() != 5 { + panic(0) + } + + if aa.GetD() != aa.GetB() { + panic(0) + } + + if aa.GetC() != 3 { + panic(0) + } + + pi := li_attribute.NewParam_i(7) + if pi.GetValue() != 7 { + panic(0) + } + pi.SetValue(3) + if pi.GetValue() != 3 { + panic(0) + } + + b := li_attribute.NewB(aa) + + if b.GetA().GetC() != 3 { + panic(0) + } + + // class/struct attribute with get/set methods using + // return/pass by reference + myFoo := li_attribute.NewMyFoo() + myFoo.SetX(8) + myClass := li_attribute.NewMyClass() + myClass.SetFoo(myFoo) + if myClass.GetFoo().GetX() != 8 { + panic(0) + } + + // class/struct attribute with get/set methods using + // return/pass by value + myClassVal := li_attribute.NewMyClassVal() + if myClassVal.GetReadWriteFoo().GetX() != -1 { + panic(0) + } + if myClassVal.GetReadOnlyFoo().GetX() != -1 { + panic(0) + } + myClassVal.SetReadWriteFoo(myFoo) + if myClassVal.GetReadWriteFoo().GetX() != 8 { + panic(0) + } + if myClassVal.GetReadOnlyFoo().GetX() != 8 { + panic(0) + } + + // string attribute with get/set methods using return/pass by + // value + myStringyClass := li_attribute.NewMyStringyClass("initial string") + if myStringyClass.GetReadWriteString() != "initial string" { + panic(0) + } + if myStringyClass.GetReadOnlyString() != "initial string" { + panic(0) + } + myStringyClass.SetReadWriteString("changed string") + if myStringyClass.GetReadWriteString() != "changed string" { + panic(0) + } + if myStringyClass.GetReadOnlyString() != "changed string" { + panic(0) + } +} diff --git a/Examples/test-suite/go/li_carrays_runme.go b/Examples/test-suite/go/li_carrays_runme.go new file mode 100644 index 000000000..0cbe92cd8 --- /dev/null +++ b/Examples/test-suite/go/li_carrays_runme.go @@ -0,0 +1,14 @@ +package main + +import . "./li_carrays" + +func main() { + d := NewDoubleArray(10) + + d.Setitem(0, 7) + d.Setitem(5, d.Getitem(0)+3) + + if d.Getitem(5)+d.Getitem(0) != 17 { + panic(0) + } +} diff --git a/Examples/test-suite/go/li_cdata_runme.go b/Examples/test-suite/go/li_cdata_runme.go new file mode 100644 index 000000000..f71a3a2c3 --- /dev/null +++ b/Examples/test-suite/go/li_cdata_runme.go @@ -0,0 +1,13 @@ +package main + +import . "./li_cdata" + +func main() { + s := "ABC abc" + m := Malloc(256) + Memmove(m, s, len(s)) + ss := Cdata(m, 7) + if string(ss) != "ABC abc" { + panic("failed") + } +} diff --git a/Examples/test-suite/go/li_cmalloc_runme.go b/Examples/test-suite/go/li_cmalloc_runme.go new file mode 100644 index 000000000..45f47b45f --- /dev/null +++ b/Examples/test-suite/go/li_cmalloc_runme.go @@ -0,0 +1,25 @@ +package main + +import . "./li_cmalloc" + +func main() { + p := Malloc_int() + Free_int(p) + + ok := false + func() { + defer func() { + if recover() != nil { + ok = true + } + }() + p = Calloc_int(-1) + if p == nil { + ok = true + } + Free_int(p) + }() + if !ok { + panic(0) + } +} diff --git a/Examples/test-suite/go/li_cpointer_runme.go b/Examples/test-suite/go/li_cpointer_runme.go new file mode 100644 index 000000000..57493b122 --- /dev/null +++ b/Examples/test-suite/go/li_cpointer_runme.go @@ -0,0 +1,14 @@ +package main + +import . "./li_cpointer" + +func main() { + p := New_intp() + Intp_assign(p, 3) + + if Intp_value(p) != 3 { + panic(0) + } + + Delete_intp(p) +} diff --git a/Examples/test-suite/go/li_std_map_runme.go b/Examples/test-suite/go/li_std_map_runme.go new file mode 100644 index 000000000..66e74dd60 --- /dev/null +++ b/Examples/test-suite/go/li_std_map_runme.go @@ -0,0 +1,30 @@ +package main + +import "./li_std_map" + +func main() { + a1 := li_std_map.NewA(3) + a2 := li_std_map.NewA(7) + + _ = li_std_map.NewPairii(1, 2) + p1 := li_std_map.NewPairA(1, a1) + m := li_std_map.NewMapA() + m.Set(1, a1) + m.Set(2, a2) + + _ = li_std_map.P_identa(p1) + _ = li_std_map.M_identa(m) + + m = li_std_map.NewMapA() + m.Set(1, a1) + m.Set(2, a2) + + mii := li_std_map.NewIntIntMap() + + mii.Set(1, 1) + mii.Set(1, 2) + + if mii.Get(1) != 2 { + panic(0) + } +} diff --git a/Examples/test-suite/go/member_pointer_runme.go b/Examples/test-suite/go/member_pointer_runme.go new file mode 100644 index 000000000..9a55bc4b9 --- /dev/null +++ b/Examples/test-suite/go/member_pointer_runme.go @@ -0,0 +1,49 @@ +// Example using pointers to member functions + +package main + +import "fmt" +import . "./member_pointer" + +func check(what string, expected float64, actual float64) { + if expected != actual { + panic(fmt.Sprintf("Failed: %s Expected: %f Actual; %f", what, expected, actual)) + } +} + +func main() { + // Get the pointers + + area_pt := Areapt() + perim_pt := Perimeterpt() + + // Create some objects + + s := NewSquare(10) + + // Do some calculations + + check("Square area ", 100.0, Do_op(s, area_pt)) + check("Square perim", 40.0, Do_op(s, perim_pt)) + + _ = GetAreavar() + _ = GetPerimetervar() + + // Try the variables + check("Square area ", 100.0, Do_op(s, GetAreavar())) + check("Square perim", 40.0, Do_op(s, GetPerimetervar())) + + // Modify one of the variables + SetAreavar(perim_pt) + + check("Square perimeter", 40.0, Do_op(s, GetAreavar())) + + // Try the constants + + _ = AREAPT + _ = PERIMPT + _ = NULLPT + + check("Square area ", 100.0, Do_op(s, AREAPT)) + check("Square perim", 40.0, Do_op(s, PERIMPT)) +} diff --git a/Examples/test-suite/go/memberin_extend_c_runme.go b/Examples/test-suite/go/memberin_extend_c_runme.go new file mode 100644 index 000000000..ec8b11e60 --- /dev/null +++ b/Examples/test-suite/go/memberin_extend_c_runme.go @@ -0,0 +1,11 @@ +package main + +import "./memberin_extend_c" + +func main() { + t := memberin_extend_c.NewPerson() + t.SetName("Fred Bloggs") + if t.GetName() != "FRED BLOGGS" { + panic("name wrong") + } +} diff --git a/Examples/test-suite/go/minherit_runme.go b/Examples/test-suite/go/minherit_runme.go new file mode 100644 index 000000000..c69fe92c1 --- /dev/null +++ b/Examples/test-suite/go/minherit_runme.go @@ -0,0 +1,82 @@ +package main + +import "fmt" +import "./minherit" + +func main() { + a := minherit.NewFoo() + b := minherit.NewBar() + c := minherit.NewFooBar() + d := minherit.NewSpam() + + if a.Xget() != 1 { + panic("1 Bad attribute value") + } + + if b.Yget() != 2 { + panic("2 Bad attribute value") + } + + if c.Xget() != 1 || c.Yget() != 2 || c.Zget() != 3 { + panic("3 Bad attribute value") + } + + if d.Xget() != 1 || d.Yget() != 2 || d.Zget() != 3 || d.Wget() != 4 { + panic("4 Bad attribute value") + } + + if minherit.Xget(a) != 1 { + panic(fmt.Sprintf("5 Bad attribute value %d", minherit.Xget(a))) + } + + if minherit.Yget(b) != 2 { + panic(fmt.Sprintf("6 Bad attribute value %d", minherit.Yget(b))) + } + + if minherit.Xget(c) != 1 || minherit.Yget(c.SwigGetBar()) != 2 || minherit.Zget(c) != 3 { + panic(fmt.Sprintf("7 Bad attribute value %d %d %d", minherit.Xget(c), minherit.Yget(c.SwigGetBar()), minherit.Zget(c))) + } + + if minherit.Xget(d) != 1 || minherit.Yget(d.SwigGetBar()) != 2 || minherit.Zget(d) != 3 || minherit.Wget(d) != 4 { + panic(fmt.Sprintf("8 Bad attribute value %d %d %d %d", minherit.Xget(d), minherit.Yget(d.SwigGetBar()), minherit.Zget(d), minherit.Wget(d))) + } + + // Cleanse all of the pointers and see what happens + + aa := minherit.ToFooPtr(a) + bb := minherit.ToBarPtr(b) + cc := minherit.ToFooBarPtr(c) + dd := minherit.ToSpamPtr(d) + + if aa.Xget() != 1 { + panic("9 Bad attribute value") + } + + if bb.Yget() != 2 { + panic("10 Bad attribute value") + } + + if cc.Xget() != 1 || cc.Yget() != 2 || cc.Zget() != 3 { + panic("11 Bad attribute value") + } + + if dd.Xget() != 1 || dd.Yget() != 2 || dd.Zget() != 3 || dd.Wget() != 4 { + panic("12 Bad attribute value") + } + + if minherit.Xget(aa) != 1 { + panic(fmt.Sprintf("13 Bad attribute value %d", minherit.Xget(aa))) + } + + if minherit.Yget(bb) != 2 { + panic(fmt.Sprintf("14 Bad attribute value %d", minherit.Yget(bb))) + } + + if minherit.Xget(cc) != 1 || minherit.Yget(cc.SwigGetBar()) != 2 || minherit.Zget(cc) != 3 { + panic(fmt.Sprintf("15 Bad attribute value %d %d %d", minherit.Xget(cc), minherit.Yget(cc.SwigGetBar()), minherit.Zget(cc))) + } + + if minherit.Xget(dd) != 1 || minherit.Yget(dd.SwigGetBar()) != 2 || minherit.Zget(dd) != 3 || minherit.Wget(dd) != 4 { + panic(fmt.Sprintf("16 Bad attribute value %d %d %d %d", minherit.Xget(dd), minherit.Yget(dd.SwigGetBar()), minherit.Zget(dd), minherit.Wget(dd))) + } +} diff --git a/Examples/test-suite/go/mod_runme.go b/Examples/test-suite/go/mod_runme.go new file mode 100644 index 000000000..581c83918 --- /dev/null +++ b/Examples/test-suite/go/mod_runme.go @@ -0,0 +1,10 @@ +package main + +import "mod_a" +import "mod_b" + +func main() { + c := mod_b.NewC() + d := mod_b.NewD() + d.DoSomething(mod_a.SwigcptrA(c.Swigcptr())) +} diff --git a/Examples/test-suite/go/multi_import_runme.go b/Examples/test-suite/go/multi_import_runme.go new file mode 100644 index 000000000..973af1e7b --- /dev/null +++ b/Examples/test-suite/go/multi_import_runme.go @@ -0,0 +1,29 @@ +package main + +import "multi_import_a" +import "multi_import_b" + +func main() { + x := multi_import_b.NewXXX() + if x.Testx() != 0 { + panic(0) + } + + y := multi_import_b.NewYYY() + if y.Testx() != 0 { + panic(0) + } + if y.Testy() != 1 { + panic(0) + } + + z := multi_import_a.NewZZZ() + if z.Testx() != 0 { + println("z.Testx", z.Testx(), z.Testz()) + panic(0) + } + if z.Testz() != 2 { + println("z.Testz", z.Testz()) + panic(0) + } +} diff --git a/Examples/test-suite/go/namespace_class_runme.go b/Examples/test-suite/go/namespace_class_runme.go new file mode 100644 index 000000000..2ed5567f7 --- /dev/null +++ b/Examples/test-suite/go/namespace_class_runme.go @@ -0,0 +1,19 @@ +package main + +import . "./namespace_class" + +func main() { + EulerT3DToFrame(1, 1, 1) + + _ = NewBooT_i() + _ = NewBooT_H() + + f1 := NewFooT_i() + f1.Quack(1) + + f2 := NewFooT_d() + f2.Moo(1) + + f3 := NewFooT_H() + f3.Foo(Hi) +} diff --git a/Examples/test-suite/go/namespace_typemap_runme.go b/Examples/test-suite/go/namespace_typemap_runme.go new file mode 100644 index 000000000..95311a37a --- /dev/null +++ b/Examples/test-suite/go/namespace_typemap_runme.go @@ -0,0 +1,116 @@ +package main + +import . "./namespace_typemap" + +func main() { + if Stest1("hello") != "hello" { + panic(0) + } + + if Stest2("hello") != "hello" { + panic(0) + } + + if Stest3("hello") != "hello" { + panic(0) + } + + if Stest4("hello") != "hello" { + panic(0) + } + + if Stest5("hello") != "hello" { + panic(0) + } + + if Stest6("hello") != "hello" { + panic(0) + } + + if Stest7("hello") != "hello" { + panic(0) + } + + if Stest8("hello") != "hello" { + panic(0) + } + + if Stest9("hello") != "hello" { + panic(0) + } + + if Stest10("hello") != "hello" { + panic(0) + } + + if Stest11("hello") != "hello" { + panic(0) + } + + if Stest12("hello") != "hello" { + panic(0) + } + + c := cmplx(float64(2), float64(3)) + r := real(c) + + if Ctest1(c) != r { + println(Ctest1(c)) + panic(Ctest1(c)) + } + + if Ctest2(c) != r { + panic(0) + } + + if Ctest3(c) != r { + panic(0) + } + + if Ctest4(c) != r { + panic(0) + } + + if Ctest5(c) != r { + panic(0) + } + + if Ctest6(c) != r { + panic(0) + } + + if Ctest7(c) != r { + panic(0) + } + + if Ctest8(c) != r { + panic(0) + } + + if Ctest9(c) != r { + panic(0) + } + + if Ctest10(c) != r { + panic(0) + } + + if Ctest11(c) != r { + panic(0) + } + + if Ctest12(c) != r { + panic(0) + } + + ok := false + func() { + defer func() { + ok = recover() != nil + }() + Ttest1(-14) + }() + if !ok { + panic(0) + } +} diff --git a/Examples/test-suite/go/namespace_virtual_method_runme.go b/Examples/test-suite/go/namespace_virtual_method_runme.go new file mode 100644 index 000000000..3f8e774c6 --- /dev/null +++ b/Examples/test-suite/go/namespace_virtual_method_runme.go @@ -0,0 +1,7 @@ +package main + +import "./namespace_virtual_method" + +func main() { + _ = namespace_virtual_method.NewSpam() +} diff --git a/Examples/test-suite/go/naturalvar_runme.go b/Examples/test-suite/go/naturalvar_runme.go new file mode 100644 index 000000000..e3723e6ab --- /dev/null +++ b/Examples/test-suite/go/naturalvar_runme.go @@ -0,0 +1,17 @@ +package main + +import . "./naturalvar" + +func main() { + f := NewFoo() + b := NewBar() + + b.SetF(f) + + SetS("hello") + b.SetS("hello") + + if b.GetS() != GetS() { + panic(0) + } +} diff --git a/Examples/test-suite/go/nested_workaround_runme.go b/Examples/test-suite/go/nested_workaround_runme.go new file mode 100644 index 000000000..5737aaaf7 --- /dev/null +++ b/Examples/test-suite/go/nested_workaround_runme.go @@ -0,0 +1,19 @@ +package main + +import . "./nested_workaround" + +func main() { + inner := NewInner(5) + outer := NewOuter() + newInner := outer.DoubleInnerValue(inner) + if newInner.GetValue() != 10 { + panic(0) + } + + outer = NewOuter() + inner = outer.CreateInner(3) + newInner = outer.DoubleInnerValue(inner) + if outer.GetInnerValue(newInner) != 6 { + panic(0) + } +} diff --git a/Examples/test-suite/go/overload_complicated_runme.go b/Examples/test-suite/go/overload_complicated_runme.go new file mode 100644 index 000000000..e3911c218 --- /dev/null +++ b/Examples/test-suite/go/overload_complicated_runme.go @@ -0,0 +1,62 @@ +package main + +import . "./overload_complicated" + +func main() { + var pInt *int + + // Check the correct constructors are available + p := NewPop(pInt) + + p = NewPop(pInt, false) + + // Check overloaded in const only and pointers/references + // which target languages cannot disambiguate + if p.Hip(false) != 701 { + panic("Test 1 failed") + } + + if p.Hip(pInt) != 702 { + panic("Test 2 failed") + } + + // Reverse the order for the above + if p.Hop(pInt) != 805 { + panic("Test 3 failed") + } + + if p.Hop(false) != 801 { + panic("Test 4 failed") + } + + // Few more variations and order shuffled + if p.Pop(false) != 901 { + panic("Test 5 failed") + } + + if p.Pop(pInt) != 902 { + panic("Test 6 failed") + } + + if p.Pop() != 905 { + panic("Test 7 failed") + } + + // Overload on const only + if p.Bop(pInt) != 1001 { + panic("Test 8 failed") + } + + if p.Bip(pInt) != 2001 { + panic("Test 9 failed") + } + + // Globals + if Muzak(false) != 3001 { + panic("Test 10 failed") + } + + if Muzak(pInt) != 3002 { + panic("Test 11 failed") + } +} diff --git a/Examples/test-suite/go/overload_copy_runme.go b/Examples/test-suite/go/overload_copy_runme.go new file mode 100644 index 000000000..d35ff70b1 --- /dev/null +++ b/Examples/test-suite/go/overload_copy_runme.go @@ -0,0 +1,8 @@ +package main + +import . "./overload_copy" + +func main() { + f := NewFoo() + _ = NewFoo(f) +} diff --git a/Examples/test-suite/go/overload_extend_runme.go b/Examples/test-suite/go/overload_extend_runme.go new file mode 100644 index 000000000..228dfe89c --- /dev/null +++ b/Examples/test-suite/go/overload_extend_runme.go @@ -0,0 +1,22 @@ +package main + +import "./overload_extend" + +func main() { + f := overload_extend.NewFoo() + if f.Test().(int) != 0 { + panic(0) + } + if f.Test(3).(int) != 1 { + panic(0) + } + if f.Test("hello").(int) != 2 { + panic(0) + } + if f.Test(float64(3), float64(2)).(float64) != 5 { + panic(0) + } + if f.Test(float64(3.0)).(float64) != 1003 { + panic(0) + } +} diff --git a/Examples/test-suite/go/overload_extendc_runme.go b/Examples/test-suite/go/overload_extendc_runme.go new file mode 100644 index 000000000..aec8935f5 --- /dev/null +++ b/Examples/test-suite/go/overload_extendc_runme.go @@ -0,0 +1,33 @@ +package main + +import "./overload_extendc" + +func main() { + f := overload_extendc.NewFoo() + if f.Test(3) != 1 { + panic(0) + } + if f.Test("hello") != 2 { + panic(0) + } + if f.Test(float64(3.5), float64(2.5)) != 3 { + panic(0) + } + if f.Test("hello", 20) != 1020 { + panic(0) + } + if f.Test("hello", 20, 100) != 120 { + panic(0) + } + + // C default args + if f.Test(f) != 30 { + panic(0) + } + if f.Test(f, 100) != 120 { + panic(0) + } + if f.Test(f, 100, 200) != 300 { + panic(0) + } +} diff --git a/Examples/test-suite/go/overload_rename_runme.go b/Examples/test-suite/go/overload_rename_runme.go new file mode 100644 index 000000000..dca5843c3 --- /dev/null +++ b/Examples/test-suite/go/overload_rename_runme.go @@ -0,0 +1,10 @@ +package main + +import "./overload_rename" + +func main() { + _ = overload_rename.NewFoo(float32(1)) + _ = overload_rename.NewFoo(float32(1), float32(1)) + _ = overload_rename.NewFoo_int(float32(1), 1) + _ = overload_rename.NewFoo_int(float32(1), 1, float32(1)) +} diff --git a/Examples/test-suite/go/overload_simple_runme.go b/Examples/test-suite/go/overload_simple_runme.go new file mode 100644 index 000000000..58fe46dab --- /dev/null +++ b/Examples/test-suite/go/overload_simple_runme.go @@ -0,0 +1,125 @@ +package main + +import . "./overload_simple" + +func main() { + if Foofn(3) != "foo:int" { + panic("foo(int)") + } + + if Foofn(float64(3.0)) != "foo:double" { + panic("foo(double)") + } + + if Foofn("hello") != "foo:char *" { + panic("foo(char *)") + } + + f := NewFoo() + b := NewBar() + + if Foofn(f) != "foo:Foo *" { + panic("foo(Foo *)") + } + + if Foofn(b) != "foo:Bar *" { + panic("foo(Bar *)") + } + + v := Malloc_void(32) + + if Foofn(v) != "foo:void *" { + panic("foo(void *)") + } + s := NewSpam() + + if s.Foofn(3) != "foo:int" { + panic("Spam::foo(int)") + } + + if s.Foofn(float64(3.0)) != "foo:double" { + panic("Spam::foo(double)") + } + + if s.Foofn("hello") != "foo:char *" { + panic("Spam::foo(char *)") + } + + if s.Foofn(f) != "foo:Foo *" { + panic("Spam::foo(Foo *)") + } + + if s.Foofn(b) != "foo:Bar *" { + panic("Spam::foo(Bar *)") + } + + if s.Foofn(v) != "foo:void *" { + panic("Spam::foo(void *)") + } + + if SpamBar(3) != "bar:int" { + panic("Spam::bar(int)") + } + + if SpamBar(float64(3.0)) != "bar:double" { + panic("Spam::bar(double)") + } + + if SpamBar("hello") != "bar:char *" { + panic("Spam::bar(char *)") + } + + if SpamBar(f) != "bar:Foo *" { + panic("Spam::bar(Foo *)") + } + + if SpamBar(b) != "bar:Bar *" { + panic("Spam::bar(Bar *)") + } + + if SpamBar(v) != "bar:void *" { + panic("Spam::bar(void *)") + } + + // Test constructors + + s = NewSpam() + if s.GetXtype() != "none" { + panic("Spam()") + } + + s = NewSpam(3) + if s.GetXtype() != "int" { + panic("Spam(int)") + } + + s = NewSpam(float64(3.4)) + if s.GetXtype() != "double" { + panic("Spam(double)") + } + + s = NewSpam("hello") + if s.GetXtype() != "char *" { + panic("Spam(char *)") + } + + s = NewSpam(f) + if s.GetXtype() != "Foo *" { + panic("Spam(Foo *)") + } + + s = NewSpam(b) + if s.GetXtype() != "Bar *" { + panic("Spam(Bar *)") + } + + s = NewSpam(v) + if s.GetXtype() != "void *" { + panic("Spam(void *)") + } + + Free_void(v) + + a := NewClassA() + _ = a.Method1(1) +} diff --git a/Examples/test-suite/go/overload_subtype_runme.go b/Examples/test-suite/go/overload_subtype_runme.go new file mode 100644 index 000000000..dc56d1ca7 --- /dev/null +++ b/Examples/test-suite/go/overload_subtype_runme.go @@ -0,0 +1,16 @@ +package main + +import . "./overload_subtype" + +func main() { + f := NewFoo() + b := NewBar() + + if Spam(f) != 1 { + panic("foo") + } + + if Spam(b) != 2 { + panic("bar") + } +} diff --git a/Examples/test-suite/go/overload_template_fast_runme.go b/Examples/test-suite/go/overload_template_fast_runme.go new file mode 100644 index 000000000..8fc7c364c --- /dev/null +++ b/Examples/test-suite/go/overload_template_fast_runme.go @@ -0,0 +1,187 @@ +package main + +import . "./overload_template_fast" + +func main() { + _ = Foo() + + _ = Maximum(3, 4) + _ = Maximum(float64(3.4), float64(5.2)) + + // mix 1 + if Mix1("hi") != 101 { + panic("mix1(const char*)") + } + + if Mix1(float64(1.0), float64(1.0)) != 102 { + panic("mix1(double, const double &)") + } + + if Mix1(float64(1.0)) != 103 { + panic("mix1(double)") + } + + // mix 2 + if Mix2("hi") != 101 { + panic("mix2(const char*)") + } + + if Mix2(float64(1.0), float64(1.0)) != 102 { + panic("mix2(double, const double &)") + } + + if Mix2(float64(1.0)) != 103 { + panic("mix2(double)") + } + + // mix 3 + if Mix3("hi") != 101 { + panic("mix3(const char*)") + } + + if Mix3(float64(1.0), float64(1.0)) != 102 { + panic("mix3(double, const double &)") + } + + if Mix3(float64(1.0)) != 103 { + panic("mix3(double)") + } + + // Combination 1 + if Overtparams1(100) != 10 { + panic("overtparams1(int)") + } + + if Overtparams1(float64(100.0), 100) != 20 { + panic("overtparams1(double, int)") + } + + // Combination 2 + if Overtparams2(float64(100.0), 100) != 40 { + panic("overtparams2(double, int)") + } + + // Combination 3 + if Overloaded() != 60 { + panic("overloaded()") + } + + if Overloaded(float64(100.0), 100) != 70 { + panic("overloaded(double, int)") + } + + // Combination 4 + if Overloadedagain("hello") != 80 { + panic("overloadedagain(const char *)") + } + + if Overloadedagain() != 90 { + panic("overloadedagain(double)") + } + + // specializations + if Specialization(10) != 202 { + panic("specialization(int)") + } + + if Specialization(float64(10.0)) != 203 { + panic("specialization(double)") + } + + if Specialization(10, 10) != 204 { + panic("specialization(int, int)") + } + + if Specialization(float64(10.0), float64(10.0)) != 205 { + panic("specialization(double, double)") + } + + if Specialization("hi", "hi") != 201 { + panic("specialization(const char *, const char *)") + } + + // simple specialization + Xyz() + Xyz_int() + Xyz_double() + + // a bit of everything + if Overload("hi") != 0 { + panic("overload()") + } + + if Overload(1) != 10 { + panic("overload(int t)") + } + + if Overload(1, 1) != 20 { + panic("overload(int t, const int &)") + } + + if Overload(1, "hello") != 30 { + panic("overload(int t, const char *)") + } + + k := NewKlass() + if Overload(k) != 10 { + panic("overload(Klass t)") + } + + if Overload(k, k) != 20 { + panic("overload(Klass t, const Klass &)") + } + + if Overload(k, "hello") != 30 { + panic("overload(Klass t, const char *)") + } + + if Overload(float64(10.0), "hi") != 40 { + panic("overload(double t, const char *)") + } + + if Overload() != 50 { + panic("overload(const char *)") + } + + + // everything put in a namespace + if Nsoverload("hi") != 1000 { + panic("nsoverload()") + } + + if Nsoverload(1) != 1010 { + panic("nsoverload(int t)") + } + + if Nsoverload(1, 1) != 1020 { + panic("nsoverload(int t, const int &)") + } + + if Nsoverload(1, "hello") != 1030 { + panic("nsoverload(int t, const char *)") + } + + if Nsoverload(k) != 1010 { + panic("nsoverload(Klass t)") + } + + if Nsoverload(k, k) != 1020 { + panic("nsoverload(Klass t, const Klass &)") + } + + if Nsoverload(k, "hello") != 1030 { + panic("nsoverload(Klass t, const char *)") + } + + if Nsoverload(float64(10.0), "hi") != 1040 { + panic("nsoverload(double t, const char *)") + } + + if Nsoverload() != 1050 { + panic("nsoverload(const char *)") + } + + AFoo(1) + b := NewB() + b.Foo(1) +} diff --git a/Examples/test-suite/go/overload_template_runme.go b/Examples/test-suite/go/overload_template_runme.go new file mode 100644 index 000000000..124402f37 --- /dev/null +++ b/Examples/test-suite/go/overload_template_runme.go @@ -0,0 +1,188 @@ +package main + +import . "./overload_template" + +func main() { + _ = Foo() + + _ = Maximum(3, 4) + _ = Maximum(float64(3.4), float64(5.2)) + + // mix 1 + if Mix1("hi") != 101 { + panic("mix1(const char*)") + } + + if Mix1(float64(1.0), float64(1.0)) != 102 { + panic("mix1(double, const double &)") + } + + if Mix1(float64(1.0)) != 103 { + panic("mix1(double)") + } + + // mix 2 + if Mix2("hi") != 101 { + panic("mix2(const char*)") + } + + if Mix2(float64(1.0), float64(1.0)) != 102 { + panic("mix2(double, const double &)") + } + + if Mix2(float64(1.0)) != 103 { + panic("mix2(double)") + } + + // mix 3 + if Mix3("hi") != 101 { + panic("mix3(const char*)") + } + + if Mix3(float64(1.0), float64(1.0)) != 102 { + panic("mix3(double, const double &)") + } + + if Mix3(float64(1.0)) != 103 { + panic("mix3(double)") + } + + // Combination 1 + if Overtparams1(100) != 10 { + panic("overtparams1(int)") + } + + if Overtparams1(float64(100.0), 100) != 20 { + panic("overtparams1(double, int)") + } + + // Combination 2 + if Overtparams2(float64(100.0), 100) != 40 { + panic("overtparams2(double, int)") + } + + // Combination 3 + if Overloaded() != 60 { + panic("overloaded()") + } + + if Overloaded(float64(100.0), 100) != 70 { + panic("overloaded(double, int)") + } + + // Combination 4 + if Overloadedagain("hello") != 80 { + panic("overloadedagain(const char *)") + } + + if Overloadedagain() != 90 { + panic("overloadedagain(double)") + } + + // specializations + if Specialization(10) != 202 { + panic("specialization(int)") + } + + if Specialization(float64(10.0)) != 203 { + panic("specialization(double)") + } + + if Specialization(10, 10) != 204 { + panic("specialization(int, int)") + } + + if Specialization(float64(10.0), float64(10.0)) != 205 { + panic("specialization(double, double)") + } + + if Specialization("hi", "hi") != 201 { + panic("specialization(const char *, const char *)") + } + + + // simple specialization + Xyz() + Xyz_int() + Xyz_double() + + // a bit of everything + if Overload("hi") != 0 { + panic("overload()") + } + + if Overload(1) != 10 { + panic("overload(int t)") + } + + if Overload(1, 1) != 20 { + panic("overload(int t, const int &)") + } + + if Overload(1, "hello") != 30 { + panic("overload(int t, const char *)") + } + + k := NewKlass() + if Overload(k) != 10 { + panic("overload(Klass t)") + } + + if Overload(k, k) != 20 { + panic("overload(Klass t, const Klass &)") + } + + if Overload(k, "hello") != 30 { + panic("overload(Klass t, const char *)") + } + + if Overload(float64(10.0), "hi") != 40 { + panic("overload(double t, const char *)") + } + + if Overload() != 50 { + panic("overload(const char *)") + } + + + // everything put in a namespace + if Nsoverload("hi") != 1000 { + panic("nsoverload()") + } + + if Nsoverload(1) != 1010 { + panic("nsoverload(int t)") + } + + if Nsoverload(1, 1) != 1020 { + panic("nsoverload(int t, const int &)") + } + + if Nsoverload(1, "hello") != 1030 { + panic("nsoverload(int t, const char *)") + } + + if Nsoverload(k) != 1010 { + panic("nsoverload(Klass t)") + } + + if Nsoverload(k, k) != 1020 { + panic("nsoverload(Klass t, const Klass &)") + } + + if Nsoverload(k, "hello") != 1030 { + panic("nsoverload(Klass t, const char *)") + } + + if Nsoverload(float64(10.0), "hi") != 1040 { + panic("nsoverload(double t, const char *)") + } + + if Nsoverload() != 1050 { + panic("nsoverload(const char *)") + } + + AFoo(1) + b := NewB() + b.Foo(1) +} diff --git a/Examples/test-suite/go/preproc_runme.go b/Examples/test-suite/go/preproc_runme.go new file mode 100644 index 000000000..a15062241 --- /dev/null +++ b/Examples/test-suite/go/preproc_runme.go @@ -0,0 +1,21 @@ +package main + +import "./preproc" + +func main() { + if preproc.GetEndif() != 1 { + panic(0) + } + + if preproc.GetDefine() != 1 { + panic(0) + } + + if preproc.GetDefined() != 1 { + panic(0) + } + + if 2*preproc.One != preproc.Two { + panic(0) + } +} diff --git a/Examples/test-suite/go/primitive_ref_runme.go b/Examples/test-suite/go/primitive_ref_runme.go new file mode 100644 index 000000000..973806955 --- /dev/null +++ b/Examples/test-suite/go/primitive_ref_runme.go @@ -0,0 +1,57 @@ +package main + +import . "./primitive_ref" + +func main() { + if Ref_int(3) != 3 { + panic(0) + } + + if Ref_uint(3) != 3 { + panic(0) + } + + if Ref_short(3) != 3 { + panic(0) + } + + if Ref_ushort(3) != 3 { + panic(0) + } + + if Ref_long(3) != 3 { + panic(0) + } + + if Ref_ulong(3) != 3 { + panic(0) + } + + if Ref_schar(3) != 3 { + panic(0) + } + + if Ref_uchar(3) != 3 { + panic(0) + } + + if Ref_float(3.5) != 3.5 { + panic(0) + } + + if Ref_double(3.5) != 3.5 { + panic(0) + } + + if Ref_bool(true) != true { + panic(0) + } + + if Ref_char('x') != 'x' { + panic(0) + } + + if Ref_over(0) != 0 { + panic(0) + } +} diff --git a/Examples/test-suite/go/profiletest_runme.go b/Examples/test-suite/go/profiletest_runme.go new file mode 100644 index 000000000..30b6cee69 --- /dev/null +++ b/Examples/test-suite/go/profiletest_runme.go @@ -0,0 +1,38 @@ +package main + +import "fmt" +import "./profiletest" + +func main() { + a := profiletest.NewA() + if false { + fmt.Println(a) + } + + b := profiletest.NewB() + fn := func(a profiletest.A) profiletest.A { return b.Fn(a) } + i := 50000 + for i != 0 { + a = fn(a) //1 + a = fn(a) //2 + a = fn(a) //3 + a = fn(a) //4 + a = fn(a) //5 + a = fn(a) //6 + a = fn(a) //7 + a = fn(a) //8 + a = fn(a) //9 + a = fn(a) //10 + a = fn(a) //1 + a = fn(a) //2 + a = fn(a) //3 + a = fn(a) //4 + a = fn(a) //5 + a = fn(a) //6 + a = fn(a) //7 + a = fn(a) //8 + a = fn(a) //9 + a = fn(a) //20 + i -= 1 + } +} diff --git a/Examples/test-suite/go/refcount_runme.go b/Examples/test-suite/go/refcount_runme.go new file mode 100644 index 000000000..fdb271cc6 --- /dev/null +++ b/Examples/test-suite/go/refcount_runme.go @@ -0,0 +1,32 @@ +package main + +import . "./refcount" + +// very innocent example + +func main() { + a := NewA3() + _ = NewB(a) + b2 := BCreate(a) + + if a.Ref_count() != 3 { + panic("This program will crash... now") + } + + rca := b2.Get_rca() + // _ = BCreate(rca) + _ = rca + + if a.Ref_count() != 4 { + panic("This program will crash... now") + } + + /* Requires smart pointer support. + v := NewVector_A(2) + v.Set(0, a) + v.Set(1, a) + + _ = v.Get(0) + DeleteVector_A(v) + */ +} diff --git a/Examples/test-suite/go/reference_global_vars_runme.go b/Examples/test-suite/go/reference_global_vars_runme.go new file mode 100644 index 000000000..b8cbb304a --- /dev/null +++ b/Examples/test-suite/go/reference_global_vars_runme.go @@ -0,0 +1,98 @@ +package main + +import . "./reference_global_vars" + +func main() { + // const class reference variable + if GetconstTC().GetNum() != 33 { + panic(0) + } + + // primitive reference variables + SetVar_bool(Createref_bool(false)) + if Value_bool(GetVar_bool()) != false { + println(1, GetVar_bool(), Value_bool(GetVar_bool())) + panic(0) + } + + SetVar_bool(Createref_bool(true)) + if Value_bool(GetVar_bool()) != true { + println(2, GetVar_bool(), Value_bool(GetVar_bool())) + panic(0) + } + + SetVar_char(Createref_char('w')) + if Value_char(GetVar_char()) != 'w' { + println(3, GetVar_char(), Value_char(GetVar_char())) + panic(0) + } + + SetVar_unsigned_char(Createref_unsigned_char(10)) + if Value_unsigned_char(GetVar_unsigned_char()) != 10 { + println(4, GetVar_unsigned_char(), Value_unsigned_char(GetVar_unsigned_char())) + panic(0) + } + + SetVar_signed_char(Createref_signed_char(10)) + if Value_signed_char(GetVar_signed_char()) != 10 { + panic(0) + } + + SetVar_short(Createref_short(10)) + if Value_short(GetVar_short()) != 10 { + panic(0) + } + + SetVar_unsigned_short(Createref_unsigned_short(10)) + if Value_unsigned_short(GetVar_unsigned_short()) != 10 { + panic(0) + } + + SetVar_int(Createref_int(10)) + if Value_int(GetVar_int()) != 10 { + panic(0) + } + + SetVar_unsigned_int(Createref_unsigned_int(10)) + if Value_unsigned_int(GetVar_unsigned_int()) != 10 { + panic(0) + } + + SetVar_long(Createref_long(10)) + if Value_long(GetVar_long()) != 10 { + panic(0) + } + + SetVar_unsigned_long(Createref_unsigned_long(10)) + if Value_unsigned_long(GetVar_unsigned_long()) != 10 { + panic(0) + } + + SetVar_long_long(Createref_long_long(0x6FFFFFFFFFFFFFF8)) + if Value_long_long(GetVar_long_long()) != 0x6FFFFFFFFFFFFFF8 { + panic(0) + } + + //ull = abs(0xFFFFFFF2FFFFFFF0) + ull := uint64(55834574864) + SetVar_unsigned_long_long(Createref_unsigned_long_long(ull)) + if Value_unsigned_long_long(GetVar_unsigned_long_long()) != ull { + panic(0) + } + + SetVar_float(Createref_float(10.5)) + if Value_float(GetVar_float()) != 10.5 { + panic(0) + } + + SetVar_double(Createref_double(10.5)) + if Value_double(GetVar_double()) != 10.5 { + panic(0) + } + + // class reference variable + SetVar_TestClass(Createref_TestClass(NewTestClass(20))) + if Value_TestClass(GetVar_TestClass()).GetNum() != 20 { + panic(0) + } +} diff --git a/Examples/test-suite/go/rename_scope_runme.go b/Examples/test-suite/go/rename_scope_runme.go new file mode 100644 index 000000000..995f8c64d --- /dev/null +++ b/Examples/test-suite/go/rename_scope_runme.go @@ -0,0 +1,18 @@ +package main + +import . "./rename_scope" + +func main() { + a := NewNatural_UP() + b := NewNatural_BP() + + if a.Rtest() != 1 { + panic(0) + } + + if b.Rtest() != 1 { + panic(0) + } + + _ = Equals +} diff --git a/Examples/test-suite/go/rename_strip_encoder_runme.go b/Examples/test-suite/go/rename_strip_encoder_runme.go new file mode 100644 index 000000000..1d0bcb660 --- /dev/null +++ b/Examples/test-suite/go/rename_strip_encoder_runme.go @@ -0,0 +1,9 @@ +package main + +import . "./rename_strip_encoder" + +func main() { + _ = NewSomeWidget() + a := NewAnotherWidget() + a.DoSomething() +} diff --git a/Examples/test-suite/go/ret_by_value_runme.go b/Examples/test-suite/go/ret_by_value_runme.go new file mode 100644 index 000000000..44743d2b7 --- /dev/null +++ b/Examples/test-suite/go/ret_by_value_runme.go @@ -0,0 +1,14 @@ +package main + +import "./ret_by_value" + +func main() { + a := ret_by_value.Get_test() + if a.GetMyInt() != 100 { + panic(0) + } + + if a.GetMyShort() != 200 { + panic(0) + } +} diff --git a/Examples/test-suite/go/return_const_value_runme.go b/Examples/test-suite/go/return_const_value_runme.go new file mode 100644 index 000000000..790921b74 --- /dev/null +++ b/Examples/test-suite/go/return_const_value_runme.go @@ -0,0 +1,15 @@ +package main + +import "./return_const_value" + +func main() { + p := return_const_value.Foo_ptrGetPtr() + if p.GetVal() != 17 { + panic("Runtime test1 failed") + } + + p = return_const_value.Foo_ptrGetConstPtr() + if p.GetVal() != 17 { + panic("Runtime test2 failed") + } +} diff --git a/Examples/test-suite/go/smart_pointer_extend_runme.go b/Examples/test-suite/go/smart_pointer_extend_runme.go new file mode 100644 index 000000000..ee5ce0538 --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_extend_runme.go @@ -0,0 +1,40 @@ +package main + +import . "./smart_pointer_extend" + +func main() { + f := NewFoo() + b := NewBar(f) + + if b.Extension() != f.Extension() { + panic(0) + } + + b2 := NewCBase() + d := NewCDerived() + p := NewCPtr() + + if b2.Bar() != p.Bar() { + panic(0) + } + + if d.Foo() != p.Foo() { + panic(0) + } + + if CBaseHello() != p.Hello() { + panic(0) + } + + d2 := NewDFoo() + + dp := NewDPtrFoo(d2) + + if DFooSExt(1) != dp.SExt(1) { + panic(0) + } + + if d2.Ext(1) != dp.Ext(1) { + panic(0) + } +} diff --git a/Examples/test-suite/go/smart_pointer_member_runme.go b/Examples/test-suite/go/smart_pointer_member_runme.go new file mode 100644 index 000000000..d0da83cef --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_member_runme.go @@ -0,0 +1,30 @@ +package main + +import "fmt" +import . "./smart_pointer_member" + +func main() { + f := NewFoos() + f.SetY(1) + + if f.GetY() != 1 { + panic(0) + } + + b := NewBar(f) + b.SetY(2) + + if f.GetY() != 2 { + fmt.Println(f.GetY()) + fmt.Println(b.GetY()) + panic(0) + } + + if b.GetX() != f.GetX() { + panic(0) + } + + if b.GetZ() != GetFoosZ() { + panic(0) + } +} diff --git a/Examples/test-suite/go/smart_pointer_multi_runme.go b/Examples/test-suite/go/smart_pointer_multi_runme.go new file mode 100644 index 000000000..d1a5f92f4 --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_multi_runme.go @@ -0,0 +1,20 @@ +package main + +import . "./smart_pointer_multi" + +func main() { + f := NewFoo() + b := NewBar(f) + s := NewSpam(b) + g := NewGrok(b) + + s.SetX(3) + if s.Getx() != 3 { + panic(0) + } + + g.SetX(4) + if g.Getx() != 4 { + panic(0) + } +} diff --git a/Examples/test-suite/go/smart_pointer_multi_typedef_runme.go b/Examples/test-suite/go/smart_pointer_multi_typedef_runme.go new file mode 100644 index 000000000..f71740bbb --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_multi_typedef_runme.go @@ -0,0 +1,20 @@ +package main + +import . "./smart_pointer_multi_typedef" + +func main() { + f := NewFoo() + b := NewBar(f) + s := NewSpam(b) + g := NewGrok(b) + + s.SetX(3) + if s.Getx() != 3 { + panic(0) + } + + g.SetX(4) + if g.Getx() != 4 { + panic(0) + } +} diff --git a/Examples/test-suite/go/smart_pointer_overload_runme.go b/Examples/test-suite/go/smart_pointer_overload_runme.go new file mode 100644 index 000000000..0a06aa080 --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_overload_runme.go @@ -0,0 +1,28 @@ +package main + +import . "./smart_pointer_overload" + +func main() { + f := NewFoo() + b := NewBar(f) + + if f.Test(3) != 1 { + panic(0) + } + if f.Test(float64(3.5)) != 2 { + panic(0) + } + if f.Test("hello") != 3 { + panic(0) + } + + if b.Test(3) != 1 { + panic(0) + } + if b.Test(float64(3.5)) != 2 { + panic(0) + } + if b.Test("hello") != 3 { + panic(0) + } +} diff --git a/Examples/test-suite/go/smart_pointer_rename_runme.go b/Examples/test-suite/go/smart_pointer_rename_runme.go new file mode 100644 index 000000000..678c305c8 --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_rename_runme.go @@ -0,0 +1,20 @@ +package main + +import . "./smart_pointer_rename" + +func main() { + f := NewFoo() + b := NewBar(f) + + if b.Test() != 3 { + panic(0) + } + + if b.Ftest1(1) != 1 { + panic(0) + } + + if b.Ftest2(2, 3) != 2 { + panic(0) + } +} diff --git a/Examples/test-suite/go/smart_pointer_simple_runme.go b/Examples/test-suite/go/smart_pointer_simple_runme.go new file mode 100644 index 000000000..328654225 --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_simple_runme.go @@ -0,0 +1,19 @@ +package main + +import . "./smart_pointer_simple" + +func main() { + f := NewFoo() + b := NewBar(f) + + b.SetX(3) + if b.Getx() != 3 { + panic(0) + } + + fp := b.X__deref__() + fp.SetX(4) + if fp.Getx() != 4 { + panic(0) + } +} diff --git a/Examples/test-suite/go/smart_pointer_templatevariables_runme.go b/Examples/test-suite/go/smart_pointer_templatevariables_runme.go new file mode 100644 index 000000000..bf58ba52c --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_templatevariables_runme.go @@ -0,0 +1,22 @@ +package main + +import . "./smart_pointer_templatevariables" + +func main() { + d := NewDiffImContainerPtr_D(Create(1234, 5678)) + + if d.GetId() != 1234 { + panic(0) + } + //if (d.xyz != 5678): + // panic(0) + + d.SetId(4321) + //d.xyz = 8765 + + if d.GetId() != 4321 { + panic(0) + } + //if (d.xyz != 8765): + // panic(0) +} diff --git a/Examples/test-suite/go/smart_pointer_typedef_runme.go b/Examples/test-suite/go/smart_pointer_typedef_runme.go new file mode 100644 index 000000000..a67a0ccda --- /dev/null +++ b/Examples/test-suite/go/smart_pointer_typedef_runme.go @@ -0,0 +1,19 @@ +package main + +import . "./smart_pointer_typedef" + +func main() { + f := NewFoo() + b := NewBar(f) + + b.SetX(3) + if b.Getx() != 3 { + panic(0) + } + + fp := b.X__deref__() + fp.SetX(4) + if fp.Getx() != 4 { + panic(0) + } +} diff --git a/Examples/test-suite/go/sneaky1_runme.go b/Examples/test-suite/go/sneaky1_runme.go new file mode 100644 index 000000000..ee38ae21b --- /dev/null +++ b/Examples/test-suite/go/sneaky1_runme.go @@ -0,0 +1,10 @@ +package main + +import "./sneaky1" + +func main() { + _ = sneaky1.Add(3, 4) + _ = sneaky1.Subtract(3, 4) + _ = sneaky1.Mul(3, 4) + _ = sneaky1.Divide(3, 4) +} diff --git a/Examples/test-suite/go/special_variable_macros_runme.go b/Examples/test-suite/go/special_variable_macros_runme.go new file mode 100644 index 000000000..366575551 --- /dev/null +++ b/Examples/test-suite/go/special_variable_macros_runme.go @@ -0,0 +1,25 @@ +package main + +import "./special_variable_macros" + +func main() { + name := special_variable_macros.NewNames() + if special_variable_macros.TestFred(name) != "none" { + panic("test failed") + } + if special_variable_macros.TestJack(name) != "$specialname" { + panic("test failed") + } + if special_variable_macros.TestJill(name) != "jilly" { + panic("test failed") + } + if special_variable_macros.TestMary(name) != "SWIGTYPE_p_NameWrap" { + panic("test failed") + } + if special_variable_macros.TestJim(name) != "multiname num" { + panic("test failed") + } + if special_variable_macros.TestJohn(special_variable_macros.NewPairIntBool(10, false)) != 123 { + panic("test failed") + } +} diff --git a/Examples/test-suite/go/static_const_member_2_runme.go b/Examples/test-suite/go/static_const_member_2_runme.go new file mode 100644 index 000000000..0d345c3d6 --- /dev/null +++ b/Examples/test-suite/go/static_const_member_2_runme.go @@ -0,0 +1,18 @@ +package main + +import . "./static_const_member_2" + +func main() { + _ = NewTest_int() + + _ = CavityPackFlagsForward_field + _ = Test_intCurrent_profile + _ = Test_intRightIndex + _ = CavityPackFlagsBackward_field + _ = Test_intLeftIndex + // _ = GetTest_int_Cavity_flags() + + if GetFooBAZ().GetVal() != 2*GetFooBAR().GetVal() { + panic(0) + } +} diff --git a/Examples/test-suite/go/struct_initialization_runme.go b/Examples/test-suite/go/struct_initialization_runme.go new file mode 100644 index 000000000..58ac25010 --- /dev/null +++ b/Examples/test-suite/go/struct_initialization_runme.go @@ -0,0 +1,29 @@ +package main + +import . "./struct_initialization" + +func main() { + if GetInstanceC1().GetX() != 10 { + panic(0) + } + + if GetInstanceD1().GetX() != 10 { + panic(0) + } + + if GetInstanceD2().GetX() != 20 { + panic(0) + } + + if GetInstanceD3().GetX() != 30 { + panic(0) + } + + if GetInstanceE1().GetX() != 1 { + panic(0) + } + + if GetInstanceF1().GetX() != 1 { + panic(0) + } +} diff --git a/Examples/test-suite/go/struct_rename_runme.go b/Examples/test-suite/go/struct_rename_runme.go new file mode 100644 index 000000000..845dac5be --- /dev/null +++ b/Examples/test-suite/go/struct_rename_runme.go @@ -0,0 +1,7 @@ +package main + +import "./struct_rename" + +func main() { + _ = struct_rename.NewBar() +} diff --git a/Examples/test-suite/go/struct_value_runme.go b/Examples/test-suite/go/struct_value_runme.go new file mode 100644 index 000000000..d0b60bd23 --- /dev/null +++ b/Examples/test-suite/go/struct_value_runme.go @@ -0,0 +1,17 @@ +package main + +import "./struct_value" + +func main() { + b := struct_value.NewBar() + + b.GetA().SetX(3) + if b.GetA().GetX() != 3 { + panic(0) + } + + b.GetB().SetX(3) + if b.GetB().GetX() != 3 { + panic(0) + } +} diff --git a/Examples/test-suite/go/template_default_arg_runme.go b/Examples/test-suite/go/template_default_arg_runme.go new file mode 100644 index 000000000..5be7f6d56 --- /dev/null +++ b/Examples/test-suite/go/template_default_arg_runme.go @@ -0,0 +1,107 @@ +package main + +import "./template_default_arg" + +func main() { + helloInt := template_default_arg.NewHello_int() + helloInt.Foo(template_default_arg.Hello_intHi) + + x := template_default_arg.NewX_int() + if x.Meth(float64(20.0), 200).(int) != 200 { + panic("X_int test 1 failed") + } + if x.Meth(20).(int) != 20 { + panic("X_int test 2 failed") + } + if x.Meth().(int) != 0 { + panic("X_int test 3 failed") + } + + y := template_default_arg.NewY_unsigned() + if y.Meth(float64(20.0), uint(200)).(uint) != 200 { + panic("Y_unsigned test 1 failed") + } + if y.Meth(uint(20)).(uint) != 20 { + panic("Y_unsigned test 2 failed") + } + if y.Meth().(uint) != 0 { + panic("Y_unsigned test 3 failed") + } + + _ = template_default_arg.NewX_longlong() + _ = template_default_arg.NewX_longlong(float64(20.0)) + _ = template_default_arg.NewX_longlong(float64(20.0), int64(200)) + + _ = template_default_arg.NewX_int() + _ = template_default_arg.NewX_int(float64(20.0)) + _ = template_default_arg.NewX_int(float64(20.0), 200) + + _ = template_default_arg.NewX_hello_unsigned() + _ = template_default_arg.NewX_hello_unsigned(float64(20.0)) + _ = template_default_arg.NewX_hello_unsigned(float64(20.0), template_default_arg.NewHello_int()) + + yy := template_default_arg.NewY_hello_unsigned() + yy.Meth(float64(20.0), template_default_arg.NewHello_int()) + yy.Meth(template_default_arg.NewHello_int()) + yy.Meth() + + fz := template_default_arg.NewFoo_Z_8() + xz := template_default_arg.NewX_Foo_Z_8() + _ = xz.Meth(fz) + + + // Templated functions + + // plain function: int ott(Foo) + if template_default_arg.Ott(template_default_arg.NewFoo_int()) != 30 { + panic("ott test 1 failed") + } + + // %template(ott) ott + if template_default_arg.Ott() != 10 { + panic("ott test 2 failed") + } + if template_default_arg.Ott(1) != 10 { + panic("ott test 3 failed") + } + if template_default_arg.Ott(1, 1) != 10 { + panic("ott test 4 failed") + } + + if template_default_arg.Ott("hi") != 20 { + panic("ott test 5 failed") + } + if template_default_arg.Ott("hi", 1) != 20 { + panic("ott test 6 failed") + } + if template_default_arg.Ott("hi", 1, 1) != 20 { + panic("ott test 7 failed") + } + + // %template(ott) ott + if template_default_arg.Ottstring(template_default_arg.NewHello_int(), "hi") != 40 { + panic("ott test 8 failed") + } + + if template_default_arg.Ottstring(template_default_arg.NewHello_int()) != 40 { + panic("ott test 9 failed") + } + + // %template(ott) ott + if template_default_arg.Ottint(template_default_arg.NewHello_int(), 1) != 50 { + panic("ott test 10 failed") + } + + if template_default_arg.Ottint(template_default_arg.NewHello_int()) != 50 { + panic("ott test 11 failed") + } + + // %template(ott) ott + if template_default_arg.Ott(template_default_arg.NewHello_int(), float64(1.0)) != 60 { + panic("ott test 12 failed") + } + + if template_default_arg.Ott(template_default_arg.NewHello_int()) != 60 { + panic("ott test 13 failed") + } +} diff --git a/Examples/test-suite/go/template_extend1_runme.go b/Examples/test-suite/go/template_extend1_runme.go new file mode 100644 index 000000000..5d6d376f5 --- /dev/null +++ b/Examples/test-suite/go/template_extend1_runme.go @@ -0,0 +1,16 @@ +package main + +import "./template_extend1" + +func main() { + a := template_extend1.NewLBaz() + b := template_extend1.NewDBaz() + + if a.Foo() != "lBaz::foo" { + panic(0) + } + + if b.Foo() != "dBaz::foo" { + panic(0) + } +} diff --git a/Examples/test-suite/go/template_extend2_runme.go b/Examples/test-suite/go/template_extend2_runme.go new file mode 100644 index 000000000..312410e27 --- /dev/null +++ b/Examples/test-suite/go/template_extend2_runme.go @@ -0,0 +1,16 @@ +package main + +import "./template_extend2" + +func main() { + a := template_extend2.NewLBaz() + b := template_extend2.NewDBaz() + + if a.Foo() != "lBaz::foo" { + panic(0) + } + + if b.Foo() != "dBaz::foo" { + panic(0) + } +} diff --git a/Examples/test-suite/go/template_inherit_runme.go b/Examples/test-suite/go/template_inherit_runme.go new file mode 100644 index 000000000..c0aca77c4 --- /dev/null +++ b/Examples/test-suite/go/template_inherit_runme.go @@ -0,0 +1,72 @@ +package main + +import . "./template_inherit" + +func main() { + a := NewFooInt() + b := NewFooDouble() + c := NewBarInt() + d := NewBarDouble() + e := NewFooUInt() + f := NewBarUInt() + + if a.Blah() != "Foo" { + panic(0) + } + + if b.Blah() != "Foo" { + panic(0) + } + + if e.Blah() != "Foo" { + panic(0) + } + + if c.Blah() != "Bar" { + panic(0) + } + + if d.Blah() != "Bar" { + panic(0) + } + + if f.Blah() != "Bar" { + panic(0) + } + + if c.Foomethod() != "foomethod" { + panic(0) + } + + if d.Foomethod() != "foomethod" { + panic(0) + } + + if f.Foomethod() != "foomethod" { + panic(0) + } + + if Invoke_blah_int(a) != "Foo" { + panic(0) + } + + if Invoke_blah_int(c) != "Bar" { + panic(0) + } + + if Invoke_blah_double(b) != "Foo" { + panic(0) + } + + if Invoke_blah_double(d) != "Bar" { + panic(0) + } + + if Invoke_blah_uint(e) != "Foo" { + panic(0) + } + + if Invoke_blah_uint(f) != "Bar" { + panic(0) + } +} diff --git a/Examples/test-suite/go/template_ns4_runme.go b/Examples/test-suite/go/template_ns4_runme.go new file mode 100644 index 000000000..4caf8f587 --- /dev/null +++ b/Examples/test-suite/go/template_ns4_runme.go @@ -0,0 +1,10 @@ +package main + +import . "./template_ns4" + +func main() { + d := Make_Class_DD() + if d.Test() != "test" { + panic(0) + } +} diff --git a/Examples/test-suite/go/template_ns_runme.go b/Examples/test-suite/go/template_ns_runme.go new file mode 100644 index 000000000..5d463f814 --- /dev/null +++ b/Examples/test-suite/go/template_ns_runme.go @@ -0,0 +1,26 @@ +package main + +import . "./template_ns" + +func main() { + p1 := NewPairii(2, 3) + p2 := NewPairii(p1) + + if p2.GetFirst() != 2 { + panic(0) + } + if p2.GetSecond() != 3 { + panic(0) + } + + p3 := NewPairdd(float64(3.5), float64(2.5)) + p4 := NewPairdd(p3) + + if p4.GetFirst() != 3.5 { + panic(0) + } + + if p4.GetSecond() != 2.5 { + panic(0) + } +} diff --git a/Examples/test-suite/go/template_opaque_runme.go b/Examples/test-suite/go/template_opaque_runme.go new file mode 100644 index 000000000..c22b71946 --- /dev/null +++ b/Examples/test-suite/go/template_opaque_runme.go @@ -0,0 +1,9 @@ +package main + +import "./template_opaque" + +func main() { + v := template_opaque.NewOpaqueVectorType(10) + + template_opaque.FillVector(v) +} diff --git a/Examples/test-suite/go/template_ref_type_runme.go b/Examples/test-suite/go/template_ref_type_runme.go new file mode 100644 index 000000000..e4bf626fb --- /dev/null +++ b/Examples/test-suite/go/template_ref_type_runme.go @@ -0,0 +1,9 @@ +package main + +import "./template_ref_type" + +func main() { + xr := template_ref_type.NewXC() + y := template_ref_type.NewY() + y.Find(xr) +} diff --git a/Examples/test-suite/go/template_rename_runme.go b/Examples/test-suite/go/template_rename_runme.go new file mode 100644 index 000000000..757ac7355 --- /dev/null +++ b/Examples/test-suite/go/template_rename_runme.go @@ -0,0 +1,16 @@ +package main + +import "./template_rename" + +func main() { + i := template_rename.NewIFoo() + d := template_rename.NewDFoo() + + _ = i.Blah_test(4) + _ = i.Spam_test(5) + _ = i.Groki_test(6) + + _ = d.Blah_test(7) + _ = d.Spam(8) + _ = d.Grok_test(9) +} diff --git a/Examples/test-suite/go/template_static_runme.go b/Examples/test-suite/go/template_static_runme.go new file mode 100644 index 000000000..7fa50760a --- /dev/null +++ b/Examples/test-suite/go/template_static_runme.go @@ -0,0 +1,7 @@ +package main + +import . "./template_static" + +func main() { + FooBar_double(1) +} diff --git a/Examples/test-suite/go/template_tbase_template_runme.go b/Examples/test-suite/go/template_tbase_template_runme.go new file mode 100644 index 000000000..9a52e2fac --- /dev/null +++ b/Examples/test-suite/go/template_tbase_template_runme.go @@ -0,0 +1,10 @@ +package main + +import . "./template_tbase_template" + +func main() { + a := Make_Class_dd() + if a.Test() != "test" { + panic(0) + } +} diff --git a/Examples/test-suite/go/template_type_namespace_runme.go b/Examples/test-suite/go/template_type_namespace_runme.go new file mode 100644 index 000000000..a3712ff59 --- /dev/null +++ b/Examples/test-suite/go/template_type_namespace_runme.go @@ -0,0 +1,8 @@ +package main + +import . "./template_type_namespace" + +func main() { + if Foo().Get(0) == "" { + } +} diff --git a/Examples/test-suite/go/template_typedef_cplx3_runme.go b/Examples/test-suite/go/template_typedef_cplx3_runme.go new file mode 100644 index 000000000..f827d7a1e --- /dev/null +++ b/Examples/test-suite/go/template_typedef_cplx3_runme.go @@ -0,0 +1,29 @@ +package main + +import . "./template_typedef_cplx3" + +func main() { + // this is OK + + + s := NewSin() + s.Get_base_value() + s.Get_value() + s.Get_arith_value() + My_func_r(s) + Make_Multiplies_double_double_double_double(s, s) + + z := NewCSin() + z.Get_base_value() + z.Get_value() + z.Get_arith_value() + My_func_c(z) + Make_Multiplies_complex_complex_complex_complex(z, z) + + // Here we fail + d := Make_Identity_double() + My_func_r(d) + + c := Make_Identity_complex() + My_func_c(c) +} diff --git a/Examples/test-suite/go/template_typedef_cplx4_runme.go b/Examples/test-suite/go/template_typedef_cplx4_runme.go new file mode 100644 index 000000000..9021cf135 --- /dev/null +++ b/Examples/test-suite/go/template_typedef_cplx4_runme.go @@ -0,0 +1,29 @@ +package main + +import . "./template_typedef_cplx4" + +func main() { + // this is OK + + + s := NewSin() + s.Get_base_value() + s.Get_value() + s.Get_arith_value() + My_func_r(s) + Make_Multiplies_double_double_double_double(s, s) + + z := NewCSin() + z.Get_base_value() + z.Get_value() + z.Get_arith_value() + My_func_c(z) + Make_Multiplies_complex_complex_complex_complex(z, z) + + // Here we fail + d := Make_Identity_double() + My_func_r(d) + + c := Make_Identity_complex() + My_func_c(c) +} diff --git a/Examples/test-suite/go/template_typedef_import_runme.go b/Examples/test-suite/go/template_typedef_import_runme.go new file mode 100644 index 000000000..8528b9a93 --- /dev/null +++ b/Examples/test-suite/go/template_typedef_import_runme.go @@ -0,0 +1,30 @@ +package main + +import "template_typedef_cplx2" +import "template_typedef_import" + +func main() { + // this is OK + + + s := template_typedef_import.NewSin() + s.Get_base_value() + s.Get_value() + s.Get_arith_value() + template_typedef_import.My_func_r(s) + template_typedef_cplx2.Make_Multiplies_double_double_double_double(s, s) + + z := template_typedef_import.NewCSin() + z.Get_base_value() + z.Get_value() + z.Get_arith_value() + template_typedef_import.My_func_c(z) + template_typedef_cplx2.Make_Multiplies_complex_complex_complex_complex(z, z) + + // Here we fail + d := template_typedef_cplx2.Make_Identity_double() + template_typedef_import.My_func_r(d) + + c := template_typedef_cplx2.Make_Identity_complex() + template_typedef_import.My_func_c(c) +} diff --git a/Examples/test-suite/go/threads_exception_runme.go b/Examples/test-suite/go/threads_exception_runme.go new file mode 100644 index 000000000..742a827bd --- /dev/null +++ b/Examples/test-suite/go/threads_exception_runme.go @@ -0,0 +1,66 @@ +package main + +import "strings" +import "./threads_exception" + +func main() { + t := threads_exception.NewTest() + + error := true + func() { + defer func() { + error = recover() == nil + }() + t.Unknown() + }() + if error { + panic(0) + } + + error = true + func() { + defer func() { + error = strings.Index(recover().(string), "int exception") == -1 + }() + t.Simple() + }() + if error { + panic(0) + } + + error = true + func() { + defer func() { + error = recover().(string) != "I died." + }() + t.Message() + }() + if error { + panic(0) + } + + error = true + func() { + defer func() { + e := recover().(string) + error = strings.Index(e, "Exc exception") == -1 + }() + t.Hosed() + }() + if error { + panic(0) + } + + for i := 1; i < 4; i++ { + error = true + func() { + defer func() { + error = recover() == nil + }() + t.Multi(i) + }() + if error { + panic(0) + } + } +} diff --git a/Examples/test-suite/go/typedef_class_runme.go b/Examples/test-suite/go/typedef_class_runme.go new file mode 100644 index 000000000..ec25162de --- /dev/null +++ b/Examples/test-suite/go/typedef_class_runme.go @@ -0,0 +1,11 @@ +package main + +import "./typedef_class" + +func main() { + a := typedef_class.NewRealA() + a.SetA(3) + + b := typedef_class.NewB() + b.TestA(a) +} diff --git a/Examples/test-suite/go/typedef_inherit_runme.go b/Examples/test-suite/go/typedef_inherit_runme.go new file mode 100644 index 000000000..49097999c --- /dev/null +++ b/Examples/test-suite/go/typedef_inherit_runme.go @@ -0,0 +1,31 @@ +package main + +import "./typedef_inherit" + +func main() { + a := typedef_inherit.NewFoo() + b := typedef_inherit.NewBar() + + x := typedef_inherit.Do_blah(a) + if x != "Foo::blah" { + panic(x) + } + + x = typedef_inherit.Do_blah(b) + if x != "Bar::blah" { + panic(x) + } + + c := typedef_inherit.NewSpam() + d := typedef_inherit.NewGrok() + + x = typedef_inherit.Do_blah2(c) + if x != "Spam::blah" { + panic(x) + } + + x = typedef_inherit.Do_blah2(d) + if x != "Grok::blah" { + panic(x) + } +} diff --git a/Examples/test-suite/go/typedef_scope_runme.go b/Examples/test-suite/go/typedef_scope_runme.go new file mode 100644 index 000000000..1c4314427 --- /dev/null +++ b/Examples/test-suite/go/typedef_scope_runme.go @@ -0,0 +1,16 @@ +package main + +import "./typedef_scope" + +func main() { + b := typedef_scope.NewBar() + x := b.Test1(42, "hello") + if x != 42 { + panic("Failed!!") + } + + xb := b.Test2(42, "hello") + if xb != "hello" { + panic("Failed!!") + } +} diff --git a/Examples/test-suite/go/typemap_namespace_runme.go b/Examples/test-suite/go/typemap_namespace_runme.go new file mode 100644 index 000000000..45184fd1e --- /dev/null +++ b/Examples/test-suite/go/typemap_namespace_runme.go @@ -0,0 +1,13 @@ +package main + +import . "./typemap_namespace" + +func main() { + if Test1("hello") != "hello" { + panic(0) + } + + if Test2("hello") != "hello" { + panic(0) + } +} diff --git a/Examples/test-suite/go/typemap_ns_using_runme.go b/Examples/test-suite/go/typemap_ns_using_runme.go new file mode 100644 index 000000000..877e44b3a --- /dev/null +++ b/Examples/test-suite/go/typemap_ns_using_runme.go @@ -0,0 +1,9 @@ +package main + +import "./typemap_ns_using" + +func main() { + if typemap_ns_using.Spam(37) != 37 { + panic(0) + } +} diff --git a/Examples/test-suite/go/typemap_out_optimal_runme.go b/Examples/test-suite/go/typemap_out_optimal_runme.go new file mode 100644 index 000000000..7cbd0ad9b --- /dev/null +++ b/Examples/test-suite/go/typemap_out_optimal_runme.go @@ -0,0 +1,8 @@ +package main + +import . "./typemap_out_optimal" + +func main() { + SetXXDebug(false) + _ = XXCreate() +} diff --git a/Examples/test-suite/go/typename_runme.go b/Examples/test-suite/go/typename_runme.go new file mode 100644 index 000000000..0bc15f11a --- /dev/null +++ b/Examples/test-suite/go/typename_runme.go @@ -0,0 +1,13 @@ +package main + +import "./typename" + +func main() { + f := typename.NewFoo() + b := typename.NewBar() + + var x float64 = typename.TwoFoo(f) + var y int = typename.TwoBar(b) + _ = x + _ = y +} diff --git a/Examples/test-suite/go/unions_runme.go b/Examples/test-suite/go/unions_runme.go new file mode 100644 index 000000000..ba9c27b17 --- /dev/null +++ b/Examples/test-suite/go/unions_runme.go @@ -0,0 +1,51 @@ +// This is the union runtime testcase. It ensures that values within a +// union embedded within a struct can be set and read correctly. + +package main + +import "./unions" + +func main() { + // Create new instances of SmallStruct and BigStruct for later use + small := unions.NewSmallStruct() + small.SetJill(200) + + big := unions.NewBigStruct() + big.SetSmallstruct(small) + big.SetJack(300) + + // Use SmallStruct then BigStruct to setup EmbeddedUnionTest. + // Ensure values in EmbeddedUnionTest are set correctly for each. + eut := unions.NewEmbeddedUnionTest() + + // First check the SmallStruct in EmbeddedUnionTest + eut.SetNumber(1) + eut.GetUni().SetSmall(small) + Jill1 := eut.GetUni().GetSmall().GetJill() + if Jill1 != 200 { + panic("Runtime test1 failed") + } + + Num1 := eut.GetNumber() + if Num1 != 1 { + panic("Runtime test2 failed") + } + + // Secondly check the BigStruct in EmbeddedUnionTest + eut.SetNumber(2) + eut.GetUni().SetBig(big) + Jack1 := eut.GetUni().GetBig().GetJack() + if Jack1 != 300 { + panic("Runtime test3 failed") + } + + Jill2 := eut.GetUni().GetBig().GetSmallstruct().GetJill() + if Jill2 != 200 { + panic("Runtime test4 failed") + } + + Num2 := eut.GetNumber() + if Num2 != 2 { + panic("Runtime test5 failed") + } +} diff --git a/Examples/test-suite/go/using1_runme.go b/Examples/test-suite/go/using1_runme.go new file mode 100644 index 000000000..8cc571288 --- /dev/null +++ b/Examples/test-suite/go/using1_runme.go @@ -0,0 +1,9 @@ +package main + +import "./using1" + +func main() { + if using1.Spam(37) != 37 { + panic(0) + } +} diff --git a/Examples/test-suite/go/using2_runme.go b/Examples/test-suite/go/using2_runme.go new file mode 100644 index 000000000..f679b0c40 --- /dev/null +++ b/Examples/test-suite/go/using2_runme.go @@ -0,0 +1,9 @@ +package main + +import "./using2" + +func main() { + if using2.Spam(37) != 37 { + panic(0) + } +} diff --git a/Examples/test-suite/go/using_composition_runme.go b/Examples/test-suite/go/using_composition_runme.go new file mode 100644 index 000000000..1602e9627 --- /dev/null +++ b/Examples/test-suite/go/using_composition_runme.go @@ -0,0 +1,44 @@ +package main + +import . "./using_composition" + +func main() { + f := NewFooBar() + if f.Blah(3).(int) != 3 { + panic("FooBar::blah(int)") + } + + if f.Blah(float64(3.5)).(float64) != 3.5 { + panic("FooBar::blah(double)") + } + + if f.Blah("hello").(string) != "hello" { + panic("FooBar::blah(char *)") + } + + f2 := NewFooBar2() + if f2.Blah(3).(int) != 3 { + panic("FooBar2::blah(int)") + } + + if f2.Blah(float64(3.5)).(float64) != 3.5 { + panic("FooBar2::blah(double)") + } + + if f2.Blah("hello").(string) != "hello" { + panic("FooBar2::blah(char *)") + } + + f3 := NewFooBar3() + if f3.Blah(3).(int) != 3 { + panic("FooBar3::blah(int)") + } + + if f3.Blah(float64(3.5)).(float64) != 3.5 { + panic("FooBar3::blah(double)") + } + + if f3.Blah("hello").(string) != "hello" { + panic("FooBar3::blah(char *)") + } +} diff --git a/Examples/test-suite/go/using_extend_runme.go b/Examples/test-suite/go/using_extend_runme.go new file mode 100644 index 000000000..144fac47d --- /dev/null +++ b/Examples/test-suite/go/using_extend_runme.go @@ -0,0 +1,30 @@ +package main + +import . "./using_extend" + +func main() { + f := NewFooBar() + if f.Blah(3).(int) != 3 { + panic("blah(int)") + } + + if f.Blah(float64(3.5)).(float64) != 3.5 { + panic("blah(double)") + } + + if f.Blah("hello").(string) != "hello" { + panic("blah(char *)") + } + + if f.Blah(3, 4).(int) != 7 { + panic("blah(int,int)") + } + + if f.Blah(float64(3.5), float64(7.5)).(float64) != (3.5 + 7.5) { + panic("blah(double,double)") + } + + if f.Duh(3) != 3 { + panic("duh(int)") + } +} diff --git a/Examples/test-suite/go/using_inherit_runme.go b/Examples/test-suite/go/using_inherit_runme.go new file mode 100644 index 000000000..669ed4d5f --- /dev/null +++ b/Examples/test-suite/go/using_inherit_runme.go @@ -0,0 +1,59 @@ +package main + +import . "./using_inherit" + +func main() { + b := NewBar() + if b.Test(3).(int) != 3 { + panic("Bar::test(int)") + } + + if b.Test(float64(3.5)).(float64) != 3.5 { + panic("Bar::test(double)") + } + + b2 := NewBar2() + if b2.Test(3).(int) != 6 { + panic("Bar2::test(int)") + } + + if b2.Test(float64(3.5)).(float64) != 7.0 { + panic("Bar2::test(double)") + } + + b3 := NewBar3() + if b3.Test(3).(int) != 6 { + panic("Bar3::test(int)") + } + + if b3.Test(float64(3.5)).(float64) != 7.0 { + panic("Bar3::test(double)") + } + + b4 := NewBar4() + if b4.Test(3).(int) != 6 { + panic("Bar4::test(int)") + } + + if b4.Test(float64(3.5)).(float64) != 7.0 { + panic("Bar4::test(double)") + } + + bf1 := NewFred1() + if bf1.Test(3).(int) != 3 { + panic("Fred1::test(int)") + } + + if bf1.Test(float64(3.5)).(float64) != 7.0 { + panic("Fred1::test(double)") + } + + bf2 := NewFred2() + if bf2.Test(3).(int) != 3 { + panic("Fred2::test(int)") + } + + if bf2.Test(float64(3.5)).(float64) != 7.0 { + panic("Fred2::test(double)") + } +} diff --git a/Examples/test-suite/go/using_private_runme.go b/Examples/test-suite/go/using_private_runme.go new file mode 100644 index 000000000..d683ef856 --- /dev/null +++ b/Examples/test-suite/go/using_private_runme.go @@ -0,0 +1,20 @@ +package main + +import . "./using_private" + +func main() { + f := NewFooBar() + f.SetX(3) + + if f.Blah(4) != 4 { + panic("blah(int)") + } + + if f.Defaulted() != -1 { + panic("defaulted()") + } + + if f.Defaulted(222) != 222 { + panic("defaulted(222)") + } +} diff --git a/Examples/test-suite/go/using_protected_runme.go b/Examples/test-suite/go/using_protected_runme.go new file mode 100644 index 000000000..65edb5001 --- /dev/null +++ b/Examples/test-suite/go/using_protected_runme.go @@ -0,0 +1,12 @@ +package main + +import . "./using_protected" + +func main() { + f := NewFooBar() + f.SetX(3) + + if f.Blah(4) != 4 { + panic("blah(int)") + } +} diff --git a/Examples/test-suite/go/varargs_runme.go b/Examples/test-suite/go/varargs_runme.go new file mode 100644 index 000000000..4009c3ed3 --- /dev/null +++ b/Examples/test-suite/go/varargs_runme.go @@ -0,0 +1,26 @@ +package main + +import "./varargs" + +func main() { + if varargs.Test("Hello") != "Hello" { + panic("Failed") + } + + f := varargs.NewFoo("Greetings") + if f.GetStr() != "Greetings" { + panic("Failed") + } + + if f.Test("Hello") != "Hello" { + panic("Failed") + } + + if varargs.Test_def("Hello", 1) != "Hello" { + panic("Failed") + } + + if varargs.Test_def("Hello") != "Hello" { + panic("Failed") + } +} diff --git a/Examples/test-suite/go/virtual_derivation_runme.go b/Examples/test-suite/go/virtual_derivation_runme.go new file mode 100644 index 000000000..48a7033a2 --- /dev/null +++ b/Examples/test-suite/go/virtual_derivation_runme.go @@ -0,0 +1,12 @@ +package main + +import . "./virtual_derivation" + +// very innocent example + +func main() { + b := NewB(3) + if b.Get_a() != b.Get_b() { + panic("something is really wrong") + } +} diff --git a/Examples/test-suite/go/virtual_poly_runme.go b/Examples/test-suite/go/virtual_poly_runme.go new file mode 100644 index 000000000..7048ba8cf --- /dev/null +++ b/Examples/test-suite/go/virtual_poly_runme.go @@ -0,0 +1,43 @@ +package main + +import "./virtual_poly" + +func main() { + d := virtual_poly.NewNDouble(3.5) + i := virtual_poly.NewNInt(2) + + // the copy methods return the right polymorphic types + dc := d.Copy() + ic := i.Copy() + + if d.Get() != dc.Get() { + panic(0) + } + + if i.Get() != ic.Get() { + panic(0) + } + + virtual_poly.Incr(ic) + + if (i.Get() + 1) != ic.Get() { + panic(0) + } + + dr := d.Ref_this() + if d.Get() != dr.Get() { + panic(0) + } + + + // 'narrowing' also works + ddc := virtual_poly.NDoubleNarrow(d.Nnumber()) + if d.Get() != ddc.Get() { + panic(0) + } + + dic := virtual_poly.NIntNarrow(i.Nnumber()) + if i.Get() != dic.Get() { + panic(0) + } +} diff --git a/Examples/test-suite/go/voidtest_runme.go b/Examples/test-suite/go/voidtest_runme.go new file mode 100644 index 000000000..0a685f081 --- /dev/null +++ b/Examples/test-suite/go/voidtest_runme.go @@ -0,0 +1,26 @@ +package main + +import "./voidtest" + +func main() { + voidtest.Globalfunc() + f := voidtest.NewFoo() + f.Memberfunc() + + voidtest.FooStaticmemberfunc() + + v1 := voidtest.Vfunc1(f.Swigcptr()) + v2 := voidtest.Vfunc2(f) + if v1 != v2 { + panic(0) + } + + v3 := voidtest.Vfunc3(v1) + + v4 := voidtest.Vfunc1(f.Swigcptr()) + if v4 != v1 { + panic(0) + } + + v3.Memberfunc() +} diff --git a/Examples/test-suite/go/wrapmacro_runme.go b/Examples/test-suite/go/wrapmacro_runme.go new file mode 100644 index 000000000..4d3791be8 --- /dev/null +++ b/Examples/test-suite/go/wrapmacro_runme.go @@ -0,0 +1,11 @@ +package main + +import "./wrapmacro" + +func main() { + a := 2 + b := -1 + wrapmacro.Maximum(a, b) + wrapmacro.Maximum(a/7.0, -b*256) + wrapmacro.GUINT16_SWAP_LE_BE_CONSTANT(1) +} diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index da9328868..6a6082ff9 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -27,6 +27,10 @@ KW(synchronized, final) KW(string, out) struct sealed {int i;}; +/* Go Keywords */ +KW(go, defer) +KW(chan, fallthrough) + %} diff --git a/Examples/test-suite/minherit.i b/Examples/test-suite/minherit.i index fed8b029c..82d1f3cce 100644 --- a/Examples/test-suite/minherit.i +++ b/Examples/test-suite/minherit.i @@ -6,7 +6,7 @@ %module(ruby_minherit="1") minherit -#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGOCAML) || defined(SWIGOCTAVE) || defined(SWIGPERL) +#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGOCAML) || defined(SWIGOCTAVE) || defined(SWIGPERL) || defined(SWIGGO) %inline %{ diff --git a/Examples/test-suite/name_warnings.i b/Examples/test-suite/name_warnings.i index 4032f20e1..3455c03bf 100644 --- a/Examples/test-suite/name_warnings.i +++ b/Examples/test-suite/name_warnings.i @@ -40,7 +40,9 @@ namespace std #endif virtual ~A() {} +#ifndef SWIGGO // func is a keyword in Go. virtual int func() = 0; +#endif private: typedef complex False; }; diff --git a/Examples/test-suite/namespace_typemap.i b/Examples/test-suite/namespace_typemap.i index 984b93a6f..4952aa7ad 100644 --- a/Examples/test-suite/namespace_typemap.i +++ b/Examples/test-suite/namespace_typemap.i @@ -70,6 +70,15 @@ namespace test { delete $1; } #endif +#ifdef SWIGGO +%typemap(go) test::test_complex * "complex128" +%typemap(in) test::test_complex * { + $1 = new test_complex(__real__ $input, __imag__ $input); +} +%typemap(freearg) test::test_complex * { + delete $1; +} +#endif namespace test { class string_class; @@ -97,6 +106,15 @@ namespace test { delete $1; } #endif +#ifdef SWIGGO + %typemap(go) string_class * "string" + %typemap(in) string_class * { + $1 = new string_class($input.p); + } + %typemap(freearg) string_class * { + delete $1; + } +#endif } %inline %{ @@ -240,6 +258,14 @@ namespace Split { } } #endif +#ifdef SWIGGO + %typemap(in) PosInteger { + $1 = $input; + if ($1 < 0) { + _swig_gopanic("domain error"); + } + } +#endif } %inline %{ diff --git a/Examples/test-suite/null_pointer.i b/Examples/test-suite/null_pointer.i index 59d554c2b..0bd7a9b92 100644 --- a/Examples/test-suite/null_pointer.i +++ b/Examples/test-suite/null_pointer.i @@ -1,5 +1,7 @@ %module null_pointer +%warnfilter(SWIGWARN_PARSE_KEYWORD) func; // 'func' is a Go keyword, renamed as 'Xfunc' + %inline { struct A {}; diff --git a/Examples/test-suite/overload_simple.i b/Examples/test-suite/overload_simple.i index be7602083..b08777854 100644 --- a/Examples/test-suite/overload_simple.i +++ b/Examples/test-suite/overload_simple.i @@ -14,6 +14,8 @@ %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fid; #endif +%warnfilter(SWIGWARN_PARSE_KEYWORD) type; // 'type' is a Go keyword, renamed as 'Xtype' + #ifndef SWIG_NO_OVERLOAD %immutable Spam::type; diff --git a/Examples/test-suite/return_const_value.i b/Examples/test-suite/return_const_value.i index 1d688d175..473878521 100644 --- a/Examples/test-suite/return_const_value.i +++ b/Examples/test-suite/return_const_value.i @@ -4,6 +4,8 @@ It was reported in bug 899332 by Jermey Brown (jhbrown94) */ %module return_const_value +%ignore Foo_ptr::operator=(const Foo_ptr&); + %inline %{ class Foo { @@ -35,7 +37,12 @@ public: { f._own = 0; } - + + Foo_ptr& operator=(const Foo_ptr& f) { + _ptr = f._ptr; + _own = f._own; + f._own = 0; + } ~Foo_ptr() { if(_own) delete _ptr; diff --git a/Examples/test-suite/rname.i b/Examples/test-suite/rname.i index dde71f203..31b99833d 100644 --- a/Examples/test-suite/rname.i +++ b/Examples/test-suite/rname.i @@ -22,7 +22,12 @@ %rename (newname) Base::oldname(double d) const; /* Rename derived class method only */ +#ifndef SWIGGO %rename (func) Derived::fn(Base baseValue, Base* basePtr, Base& baseRef); +#else +/* func is a keyword in Go. */ +%rename (Xfunc) Derived::fn(Base baseValue, Base* basePtr, Base& baseRef); +#endif %inline %{ class Bar { diff --git a/Examples/test-suite/typemap_namespace.i b/Examples/test-suite/typemap_namespace.i index b3fa1a733..6bf53e989 100644 --- a/Examples/test-suite/typemap_namespace.i +++ b/Examples/test-suite/typemap_namespace.i @@ -25,9 +25,12 @@ namespace Foo { %typemap(jstype) Str1 * = char *; %typemap(javain) Str1 * = char *; %typemap(javaout) Str1 * = char *; +#endif +#ifdef SWIGGO + %typemap(go) Str1 * = char *; #endif %typemap(in) Str1 * = char *; -#if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML)) +#if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGGO)) %typemap(freearg) Str1 * = char *; #endif %typemap(typecheck) Str1 * = char *; diff --git a/Examples/test-suite/typemap_subst.i b/Examples/test-suite/typemap_subst.i index d5a8416db..1b1f8a3f4 100644 --- a/Examples/test-suite/typemap_subst.i +++ b/Examples/test-suite/typemap_subst.i @@ -61,8 +61,8 @@ $1 = ($ltype) temp; } -/* Java and C# modules don't use SWIG's runtime type system */ -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) +/* Java, C# and Go modules don't use SWIG's runtime type system */ +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) %inline %{ void foo(const struct xyzzy **TEST) {} %} diff --git a/Examples/test-suite/union_parameter.i b/Examples/test-suite/union_parameter.i index bb010d3fa..ed7bcacf8 100644 --- a/Examples/test-suite/union_parameter.i +++ b/Examples/test-suite/union_parameter.i @@ -1,5 +1,7 @@ %module union_parameter +%warnfilter(SWIGWARN_PARSE_KEYWORD) type; // 'type' is a Go keyword, renamed as 'Xtype' + %inline %{ typedef unsigned char Uint8; diff --git a/Lib/go/cdata.i b/Lib/go/cdata.i new file mode 100644 index 000000000..c3307945a --- /dev/null +++ b/Lib/go/cdata.i @@ -0,0 +1,135 @@ +/* ----------------------------------------------------------------------------- + * cdata.i + * + * SWIG library file containing macros for manipulating raw C data as strings. + * ----------------------------------------------------------------------------- */ + +%{ +typedef struct SWIGCDATA { + char *data; + int len; +} SWIGCDATA; +%} + +%typemap(go) SWIGCDATA %{ []byte %} +%typemap(out) SWIGCDATA (swigcdata argp) { + argp = _swig_makegobyteslice($1.data, $1.len); + $result.data = (char*)argp.data; + $result.len = (int)argp.len; +} + +/* The makegobyteslice function. */ + +%insert(runtime) %{ +typedef struct { + char *data; + int len; +} swigcdata; + +%} + +#ifndef SWIGGO_GCCGO +%insert(runtime) %{ +extern +#ifdef __cplusplus +"C" +#endif +void _swig_gc_makegobyteslice(void *, int); +static swigcdata _swig_makegobyteslice(const char *data, int len) { + struct { + const char *data; + int len; + swigcdata ret; + } a; + a.data = data; + a.len = len; + crosscall2(_swig_gc_makegobyteslice, &a, (int) sizeof a); + return a.ret; +} +%} + +%insert(gc_header) %{ +typedef struct { + byte *data; + int32 len; +} swigcdata; +extern void ·_swig_internal_makegobyteslice(void); +#pragma dynexport _swig_gc_makegobyteslice _swig_gc_makegobyteslice +void _swig_gc_makegobyteslice(void *a, int32 n) { + cgocallback(·_swig_internal_makegobyteslice, a, n); +} +void ·_swig_allocategobyteslice(byte *data, int32 len, swigcdata ret) { + ret.data = mal(len); + mcpy(ret.data, data, len); + ret.len = len; + FLUSH(&ret); +} +%} + +%insert(go_header) %{ +type swigcdata struct { data *byte; len int } +func _swig_allocategobyteslice(*byte, int) swigcdata +func _swig_internal_makegobyteslice(data *byte, len int) swigcdata { + return _swig_allocategobyteslice(data, len) +} +%} + +#else + +%insert(runtime) %{ +static swigcdata _swig_makegobyteslice(const char *data, int len) { + swigcdata ret; + ret.data = (char*)__go_alloc(len); + memcpy(ret.data, data, len); + ret.len = (int)len; + return ret; +} + +%} + +#endif + +/* ----------------------------------------------------------------------------- + * %cdata(TYPE [, NAME]) + * + * Convert raw C data to a binary string. + * ----------------------------------------------------------------------------- */ + +%define %cdata(TYPE,NAME...) + +%insert("header") { +#if #NAME == "" +static SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements) { +#else +static SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements) { +#endif + SWIGCDATA d; + d.data = (char *) ptr; +#if #TYPE != "void" + d.len = nelements*sizeof(TYPE); +#else + d.len = nelements; +#endif + return d; +} +} + +%typemap(default) int nelements "$1 = 1;" + +#if #NAME == "" +SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements); +#else +SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements); +#endif +%enddef + +%typemap(default) int nelements; + +%rename(cdata) ::cdata_void(void *ptr, int nelements); + +%cdata(void); + +/* Memory move function. Due to multi-argument typemaps this appears + to be wrapped as + void memmove(void *data, const char *s); */ +void memmove(void *data, char *indata, int inlen); diff --git a/Lib/go/exception.i b/Lib/go/exception.i new file mode 100644 index 000000000..5abd306a4 --- /dev/null +++ b/Lib/go/exception.i @@ -0,0 +1,7 @@ +%typemap(throws,noblock=1) (...) { + SWIG_exception(SWIG_RuntimeError,"unknown exception"); +} + +%insert("runtime") %{ +#define SWIG_exception(code, msg) _swig_gopanic(msg) +%} diff --git a/Lib/go/go.swg b/Lib/go/go.swg new file mode 100644 index 000000000..b1b8860df --- /dev/null +++ b/Lib/go/go.swg @@ -0,0 +1,514 @@ +/* ------------------------------------------------------------ + * go.swg + * + * Go configuration module. + * ------------------------------------------------------------ */ + +/* Basic types */ + +%typemap(go) bool, const bool & "bool" +%typemap(go) char, const char & "byte" +%typemap(go) signed char, const signed char & "int8" +%typemap(go) unsigned char, const unsigned char & "byte" +%typemap(go) short, const short & "int16" +%typemap(go) unsigned short, const unsigned short & "uint16" +%typemap(go) int, const int & "int" +%typemap(go) unsigned int, const unsigned int & "uint" +#if SWIGGO_LONG_TYPE_SIZE == 32 +%typemap(go) long, const long & "int32" +%typemap(go) unsigned long, const unsigned long & "uint32" +#elif SWIGGO_LONG_TYPE_SIZE == 64 +%typemap(go) long, const long & "int64" +%typemap(go) unsigned long, const unsigned long & "uint64" +#else +#error "SWIGGO_LONG_TYPE_SIZE not 32 or 64" +#endif +%typemap(go) long long, const long long & "int64" +%typemap(go) unsigned long long, const unsigned long long & "uint64" +%typemap(go) float, const float & "float32" +%typemap(go) double, const double & "float64" + +%typemap(in) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +%{ $1 = ($1_ltype)$input; %} + +%typemap(in) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +%{ $1 = ($1_ltype)&$input; %} + +%typemap(out) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +%{ $result = $1; %} + +%typemap(out) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +%{ $result = ($*1_ltype)*$1; %} + +%typemap(out) void "" + +%typemap(directorin) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +%{ $input = ($1_ltype)$1_name; %} + +%typemap(directorin) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +%{ $input = ($*1_ltype)$1_name; %} + +%typemap(directorout) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +%{ $result = ($1_ltype)$input; %} + +%typemap(directorout) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +%{ + $result = ($1_ltype)_swig_allocate(sizeof($*1_ltype)); + *$result = *($1_ltype)$input; +%} + +/* The size_t type. */ + +#if SWIGGO_LONG_TYPE_SIZE == 32 +%typemap(go) size_t, const size_t & %{int%} +#else +%typemap(go) size_t, const size_t & %{int64%} +#endif + +%typemap(in) size_t +%{ $1 = (size_t)$input; %} + +%typemap(in) const size_t & +%{ $1 = ($1_ltype)&$input; %} + +%typemap(out) size_t +%{ $result = $1; %} + +%typemap(out) const size_t & +%{ $result = ($*1_ltype)*$1; %} + +%typemap(directorin) size_t +%{ $input = (size_t)$1_name; %} + +%typemap(directorin) const size_t & +%{ $input = ($*1_ltype)$1_name; %} + +%typemap(directorout) size_t +%{ $result = ($1_ltype)$input; %} + +%typemap(directorout) const size_t & +%{ + $result = ($1_ltype)_swig_allocate(sizeof($*1_ltype)); + *$result = *($1_ltype)$input; +%} + +/* Member pointers. */ + +%typemap(go) SWIGTYPE (CLASS::*) +%{$gotypename%} + +%typemap(in) SWIGTYPE (CLASS::*) +%{ $1 = *($&1_ltype)$input; %} + +%typemap(out) SWIGTYPE (CLASS::*) +%{ + $result = _swig_allocate(sizeof($1_ltype)); + *($&1_ltype)$result = $1; +%} + +%typemap(directorin) SWIGTYPE (CLASS::*) +%{ $input = *($&1_ltype)$1_name; %} + +%typemap(directorout) SWIGTYPE (CLASS::*) +%{ + $result = _swig_allocate(sizeof($1_ltype)); + *($&1_ltype)$result = $input; +%} + +/* Pointers. */ + +/* We can't translate pointers using a typemap, so that is handled in + the C++ code. */ +%typemap(go) SWIGTYPE * +%{$gotypename%} + +%typemap(in) SWIGTYPE * +%{ $1 = *($&1_ltype)&$input; %} + +%typemap(out) SWIGTYPE * +%{ *($&1_ltype)&$result = $1; %} + +%typemap(directorin) SWIGTYPE * +%{ $input = ($1_ltype)$1_name; %} + +%typemap(directorout) SWIGTYPE * +%{ $result = ($1_ltype)$input; %} + +%apply SWIGTYPE * { SWIGTYPE *const } + +/* Pointer references. */ + +%typemap(go) SWIGTYPE *const& +%{$gotypename%} + +%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) +%{ + temp = *($1_ltype)&$input; + $1 = ($1_ltype)&temp; +%} + +%typemap(out) SWIGTYPE *const& +%{ *($1_ltype)&$result = *$1; %} + +/* Function pointers are translated by the code in go.cxx into + _swig_fnptr. Member pointers are translated to _swig_memberptr. */ + +%insert(go_header) %{ +type _swig_fnptr *byte +type _swig_memberptr *byte +%} + +/* References. */ + +/* Converting a C++ reference to Go has to be handled in the C++ + code. */ +%typemap(go) SWIGTYPE & +%{$gotypename%} + +%typemap(in) SWIGTYPE & +%{ $1 = *($&1_ltype)&$input; %} + +%typemap(out) SWIGTYPE & +%{ *($&1_ltype)&$result = $1; %} + +%typemap(directorin) SWIGTYPE & +%{ $input = ($1_ltype)&$1_name; %} + +%typemap(directorout) SWIGTYPE & +%{ *($&1_ltype)&$result = $input; %} + +/* C arrays turn into Go pointers. If we know the length we can use a + slice. */ + +%typemap(go) SWIGTYPE [] +%{$gotypename%} + +%typemap(in) SWIGTYPE [] +%{ $1 = *($&1_ltype)&$input; %} + +%typemap(out) SWIGTYPE [] +%{ *($&1_ltype)&$result = $1; %} + +%typemap(directorin) SWIGTYPE [] +%{ $input = *($1_ltype)&$1_name; %} + +%typemap(directorout) SWIGTYPE [] +%{ *($&1_ltype)&$result = $input; %} + +/* Strings. */ + +%typemap(go) + char *, char *&, char[ANY], char[], + signed char *, signed char *&, signed char[ANY], signed char[], + unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +"string" + +/* Needed to avoid confusion with the way the go module handles + references. */ +%typemap(go) char&, unsigned char& "*byte" +%typemap(go) signed char& "*int8" + +%typemap(in) + char *, char[ANY], char[], + signed char *, signed char[ANY], signed char[], + unsigned char *, unsigned char[ANY], unsigned char[] +%{ $1 = ($1_ltype)$input.p; %} + +%typemap(in) char *&, signed char *&, unsigned char *& +%{ $1 = ($1_ltype)$input.p; %} + +%typemap(out) + char *, char *&, char[ANY], char[], + signed char *, signed char *&, signed char[ANY], signed char[], + unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +%{ $result = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0); %} + +%typemap(directorin) + char *, char *&, char[ANY], char[], + signed char *, signed char *&, signed char[ANY], signed char[], + unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +%{ + $input = _swig_makegostring((char*)$1_name, $1_name ? strlen((char*)$1_name) : 0); +%} + +%typemap(directorout) + char *, char *&, char[ANY], char[], + signed char *, signed char *&, signed char[ANY], signed char[], + unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +%{ $result = ($1_ltype)$input.p; %} + +/* Enums. We can't do the right thing for enums in typemap(go) so we + deliberately don't define them. The right thing would be to + capitalize the name. This is instead done in go.cxx. */ + +%typemap(go) enum SWIGTYPE +%{$gotypename%} + +%typemap(in) enum SWIGTYPE +%{ $1 = ($1_ltype)$input; %} + +%typemap(out) enum SWIGTYPE +%{ $result = $1; %} + +%typemap(directorin) enum SWIGTYPE +%{ $input = ($1_ltype)$1_name; %} + +%typemap(directorout) enum SWIGTYPE +%{ $result = ($1_ltype)$input; %} + +/* Arbitrary type. This is a type passed by value in the C/C++ code. + We convert it to a pointer for the Go code. Note that all basic + types are explicitly handled above. */ + +%typemap(go) SWIGTYPE +%{$gotypename%} + +%typemap(in) SWIGTYPE ($&1_type argp) +%{ + argp = ($&1_ltype)$input; + if (argp == NULL) { + _swig_gopanic("Attempt to dereference null $1_type"); + } + $1 = ($1_ltype)*argp; +%} + +%typemap(out) SWIGTYPE +#ifdef __cplusplus +%{ *($&1_ltype*)&$result = new $1_ltype($1); %} +#else +{ + $&1_ltype $1ptr = ($&1_ltype)malloc(sizeof($1_ltype)); + memmove($1ptr, &$1, sizeof($1_type)); + *($&1_ltype*)&$result = $1ptr; +} +#endif + +%typemap(directorin) SWIGTYPE +%{ $input = ($&1_ltype)&$1_name; %} + +%typemap(directorout) SWIGTYPE +%{ $result = *($&1_ltype)$input; %} + +/* Exception handling */ + +%typemap(throws) char * +%{ _swig_gopanic($1); %} + +%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] +%{ + (void)$1; + _swig_gopanic("C++ $1_type exception thrown"); +%} + +/* Typecheck typemaps. The purpose of these is merely to issue a + warning for overloaded C++ functions * that cannot be overloaded in + Go as more than one C++ type maps to a single Go type. */ + +%typecheck(SWIG_TYPECHECK_BOOL) /* Go bool */ + bool, + const bool & + "" + +%typecheck(SWIG_TYPECHECK_CHAR) /* Go byte */ + char, + const char &, + unsigned char, + const unsigned char & + "" + +%typecheck(SWIG_TYPECHECK_INT8) /* Go int8 */ + signed char, + const signed char & + "" + +%typecheck(SWIG_TYPECHECK_INT16) /* Go int16 */ + short, + const short & + "" + +%typecheck(SWIG_TYPECHECK_INT16) /* Go uint16 */ + unsigned short, + const unsigned short & + "" + +%typecheck(SWIG_TYPECHECK_INT32) /* Go int */ + int, + const int & + "" + +%typecheck(SWIG_TYPECHECK_INT32) /* Go uint */ + unsigned int, + const unsigned int & + "" + +#if SWIGGO_LONG_TYPE_SIZE == 32 +%typecheck(SWIG_TYPECHECK_INT32) /* Go int32 */ + long, + const long & + "" + +%typecheck(SWIG_TYPECHECK_INT32) /* Go uint32 */ + unsigned long, + const unsigned long & + "" +#endif + +%typecheck(SWIG_TYPECHECK_INT64) /* Go int64 */ +#if SWIGGO_LONG_TYPE_SIZE == 64 + long, + const long &, +#endif + long long, + const long long & + "" + +%typecheck(SWIG_TYPECHECK_INT64) /* Go uint64 */ +#if SWIGGO_LONG_TYPE_SIZE == 64 + unsigned long, + const unsigned long &, +#endif + unsigned long long, + const unsigned long long & + "" + +%typecheck(SWIG_TYPECHECK_FLOAT) /* Go float32 */ + float, + const float & + "" + +%typecheck(SWIG_TYPECHECK_DOUBLE) /* Go float64 */ + double, + const double & + "" + +%typecheck(SWIG_TYPECHECK_STRING) /* Go string */ + char *, + char *&, + char[ANY], + char [], + signed char *, + signed char *&, + signed char[ANY], + signed char [], + unsigned char *, + unsigned char *&, + unsigned char[ANY], + unsigned char [] + "" + +%typecheck(SWIG_TYPECHECK_POINTER) + SWIGTYPE, + SWIGTYPE *, + SWIGTYPE &, + SWIGTYPE *const&, + SWIGTYPE [], + SWIGTYPE (CLASS::*) + "" +/* Go keywords. */ +%include + +%include diff --git a/Lib/go/gokw.swg b/Lib/go/gokw.swg new file mode 100644 index 000000000..e7506d053 --- /dev/null +++ b/Lib/go/gokw.swg @@ -0,0 +1,31 @@ +/* Rename keywords. */ + +#define GOKW(x) %keywordwarn("'" `x` "' is a Go keyword, renaming to 'X"`x`"'",rename="X%s") `x` + +GOKW(break); +GOKW(case); +GOKW(chan); +GOKW(const); +GOKW(continue); +GOKW(default); +GOKW(defer); +GOKW(else); +GOKW(fallthrough); +GOKW(for); +GOKW(func); +GOKW(go); +GOKW(goto); +GOKW(if); +GOKW(import); +GOKW(interface); +GOKW(map); +GOKW(package); +GOKW(range); +GOKW(return); +GOKW(select); +GOKW(struct); +GOKW(switch); +GOKW(type); +GOKW(var); + +#undef GOKW diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg new file mode 100644 index 000000000..5a51fd4b6 --- /dev/null +++ b/Lib/go/goruntime.swg @@ -0,0 +1,208 @@ +/* ------------------------------------------------------------ + * goruntime.swg + * + * Go runtime code for the various generated files. + * ------------------------------------------------------------ */ + +%insert(runtime) %{ +#include +#include +#include + +typedef struct { char *p; int n; } _gostring_; +typedef struct { void* array; unsigned int len; unsigned int cap; } _goslice_; + +%} + +#ifndef SWIGGO_GCCGO +/* Boilerplate for C/C++ code when using 6g/8g. This code is compiled + with gcc. */ +%insert(runtime) %{ + +#define __goswig_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; +#define __goswig_size_assert(t, n) __goswig_size_assert_eq(sizeof(t), n, _goswig_sizeof_##t##_is_not_##n) + +__goswig_size_assert(char, 1) +__goswig_size_assert(short, 2) +__goswig_size_assert(int, 4) +typedef long long __goswig_long_long; +__goswig_size_assert(__goswig_long_long, 8) +__goswig_size_assert(float, 4) +__goswig_size_assert(double, 8) + +extern +#ifdef __cplusplus +"C" +#endif +void crosscall2(void (*fn)(void *, int), void *, int); + +extern +#ifdef __cplusplus +"C" +#endif +void _swig_gc_allocate(void *, int); +static void *_swig_allocate(int len) { + struct { + int len; + void *ret; + } a; + a.len = len; + crosscall2(_swig_gc_allocate, &a, (int) sizeof a); + return a.ret; +} + +extern +#ifdef __cplusplus +"C" +#endif +void _swig_gc_makegostring(void *, int); +static _gostring_ _swig_makegostring(const char *p, size_t l) { + struct { + const char *p; + int l; + _gostring_ ret; + } a; + a.p = p; + a.l = l; + crosscall2(_swig_gc_makegostring, &a, (int) sizeof a); + return a.ret; +} + +extern +#ifdef __cplusplus +"C" +#endif +void _swig_gc_gopanic(void *, int); +static void _swig_gopanic(const char *p) { + struct { + const char *p; + int l; + } a; + a.p = p; + a.l = strlen(p); + crosscall2(_swig_gc_gopanic, &a, (int) sizeof a); +} + +%} + +/* Boilerplate for C code when using 6g/8g. This code is compiled + with 6c/8c. */ +%insert(gc_header) %{ +#include "runtime.h" +#include "cgocall.h" + +#pragma dynimport initcgo initcgo "libcgo.so" +#pragma dynimport libcgo_thread_start libcgo_thread_start "libcgo.so" +#pragma dynimport libcgo_set_scheduler libcgo_set_scheduler "libcgo.so" + +#ifdef _64BIT +#define SWIG_PARM_SIZE 8 +#else +#define SWIG_PARM_SIZE 4 +#endif +%} + +/* 6g/8g C boilerplate that is only needed once in a program. This + only gets added to the file if nothing is imported. */ +%insert(gc_once) %{ + +extern void ·_swig_internal_allocate(void); +#pragma dynexport _swig_gc_allocate _swig_gc_allocate +void _swig_gc_allocate(void *a, int32 n) { + cgocallback(·_swig_internal_allocate, a, n); +} + +void ·_swig_allocatememory(int32 len, byte *ret) { + ret = mal(len); + FLUSH(&ret); +} + +extern void ·_swig_internal_makegostring(void); +#pragma dynexport _swig_gc_makegostring _swig_gc_makegostring +void _swig_gc_makegostring(void *a, int32 n) { + cgocallback(·_swig_internal_makegostring, a, n); +} + +void ·_swig_allocatestring(byte *p, int32 l, String ret) { + ret.str = mal(l+1); + mcpy(ret.str, p, l); + ret.len = l; + FLUSH(&ret); +} + +extern void ·_swig_internal_gopanic(void); +#pragma dynexport _swig_gc_gopanic _swig_gc_gopanic +void _swig_gc_gopanic(void *a, int32 n) { + cgocallback(·_swig_internal_gopanic, a, n); +} + +%} + +/* Go code that is only needed once in a program. This is only added + to the file if nothing is imported. */ +%insert(go_once) %{ +func _swig_allocatememory(int) *byte +func _swig_internal_allocate(len int) *byte { + return _swig_allocatememory(len) +} + +func _swig_allocatestring(*byte, int) string +func _swig_internal_makegostring(p *byte, l int) string { + return _swig_allocatestring(p, l) +} + +func _swig_internal_gopanic(p *byte, l int) { + panic(_swig_allocatestring(p, l)) +} +%} + +#else + +/* Boilerplate for C/C++ code when using gccgo. */ +%insert(runtime) %{ +#define SWIGGO_GCCGO + +extern +#ifdef __cplusplus +"C" +#endif +void *__go_alloc (size_t); + +static void *_swig_allocate(int len) { + return __go_alloc(len); +} + +static _gostring_ _swig_makegostring(const char *p, size_t l) { + _gostring_ ret; + ret.p = (char*)__go_alloc(l); + memcpy(ret.p, p, l); + ret.n = l; + return ret; +} + +extern +#ifdef __cplusplus +"C" +#endif +void __go_panic_msg(const char *); +#define _swig_gopanic __go_panic_msg + +%} + +#endif + +%insert(runtime) %{ +#define SWIG_contract_assert(expr, msg) \ + if (!(expr)) { _swig_gopanic(msg); } else +%} + +#ifdef __cplusplus +/* We don't need a Swig::Director class, but the Swig testsuite + expects one. */ +%insert(runtime) %{ +namespace Swig { + typedef int Director; +} +%} + +#endif diff --git a/Lib/go/std_common.i b/Lib/go/std_common.i new file mode 100644 index 000000000..c010facac --- /dev/null +++ b/Lib/go/std_common.i @@ -0,0 +1,4 @@ +%include + +%apply size_t { std::size_t }; +%apply const size_t& { const std::size_t& }; diff --git a/Lib/go/std_deque.i b/Lib/go/std_deque.i new file mode 100644 index 000000000..cb98f6c2f --- /dev/null +++ b/Lib/go/std_deque.i @@ -0,0 +1 @@ +%include diff --git a/Lib/go/std_except.i b/Lib/go/std_except.i new file mode 100644 index 000000000..789a335f7 --- /dev/null +++ b/Lib/go/std_except.i @@ -0,0 +1,29 @@ +/* ----------------------------------------------------------------------------- + * std_except.i + * + * Typemaps used by the STL wrappers that throw exceptions. + * These typemaps are used when methods are declared with an STL exception specification, such as + * size_t at() const throw (std::out_of_range); + * ----------------------------------------------------------------------------- */ + +%{ +#include +%} + +namespace std +{ + %ignore exception; + struct exception {}; +} + +%typemap(throws) std::bad_exception %{_swig_gopanic($1.what());%} +%typemap(throws) std::domain_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::exception %{_swig_gopanic($1.what());%} +%typemap(throws) std::invalid_argument %{_swig_gopanic($1.what());%} +%typemap(throws) std::length_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::logic_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::out_of_range %{_swig_gopanic($1.what());%} +%typemap(throws) std::overflow_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::range_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::runtime_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::underflow_error %{_swig_gopanic($1.what());%} diff --git a/Lib/go/std_map.i b/Lib/go/std_map.i new file mode 100644 index 000000000..e37a9e676 --- /dev/null +++ b/Lib/go/std_map.i @@ -0,0 +1,64 @@ +/* ----------------------------------------------------------------------------- + * std_map.i + * + * SWIG typemaps for std::map + * ----------------------------------------------------------------------------- */ + +%include + +// ------------------------------------------------------------------------ +// std::map +// ------------------------------------------------------------------------ + +// "map" is a keyword in Go. +#define map cmap + +%{ +#define map cmap +#include +#include +#include +%} + +// exported class + +namespace std { + + template class map { + // add typemaps here + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef K key_type; + typedef T mapped_type; + map(); + map(const map &); + + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + const T& get(const K& key) throw (std::out_of_range) { + std::map::iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); + } + void set(const K& key, const T& x) { + (*self)[key] = x; + } + void del(const K& key) throw (std::out_of_range) { + std::map::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + bool has_key(const K& key) { + std::map::iterator i = self->find(key); + return i != self->end(); + } + } + }; +} diff --git a/Lib/go/std_pair.i b/Lib/go/std_pair.i new file mode 100644 index 000000000..fe45ee676 --- /dev/null +++ b/Lib/go/std_pair.i @@ -0,0 +1,34 @@ +/* ----------------------------------------------------------------------------- + * std_pair.i + * + * SWIG typemaps for std::pair + * ----------------------------------------------------------------------------- */ + +%include +%include + +// ------------------------------------------------------------------------ +// std::pair +// ------------------------------------------------------------------------ + +%{ +#include +%} + +namespace std { + + template struct pair { + + pair(); + pair(T first, U second); + pair(const pair& p); + + template pair(const pair &p); + + T first; + U second; + }; + + // add specializations here + +} diff --git a/Lib/go/std_string.i b/Lib/go/std_string.i new file mode 100644 index 000000000..3c94cbe10 --- /dev/null +++ b/Lib/go/std_string.i @@ -0,0 +1,55 @@ +/* ----------------------------------------------------------------------------- + * std_string.i + * + * Typemaps for std::string and const std::string& + * These are mapped to a Go string and are passed around by value. + * + * To use non-const std::string references use the following %apply. Note + * that they are passed by value. + * %apply const std::string & {std::string &}; + * ----------------------------------------------------------------------------- */ + +%{ +#include +%} + +namespace std { + +%naturalvar string; + +class string; + +%typemap(go) string, const string & "string" + +%typemap(in) string +%{ $1.assign($input.p, $input.n); %} + +%typemap(directorout) string +%{ $result.assign($input.p, $input.n); %} + +%typemap(out) string +%{ $result = _swig_makegostring($1.data(), $1.length()); %} + +%typemap(directorin) string +%{ $input = _swig_makegostring($1_name.data(), $1_name.length()); %} + +%typemap(in) const string & +%{ + std::string $1_str($input.p, $input.n); + $1 = &$1_str; +%} + +%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string & +%{ + static std::string $1_str; + $1_str.assign($input.p, $input.n); + $result = &$1_str; +%} + +%typemap(out) const string & +%{ $result = _swig_makegostring((*$1).data(), (*$1).length()); %} + +%typemap(directorin) const string & +%{ $input = _swig_makegostring($1_name.data(), $1_name.length()); %} + +} diff --git a/Lib/go/std_vector.i b/Lib/go/std_vector.i new file mode 100644 index 000000000..f4ce8431c --- /dev/null +++ b/Lib/go/std_vector.i @@ -0,0 +1,78 @@ +/* ----------------------------------------------------------------------------- + * std_vector.i + * ----------------------------------------------------------------------------- */ + +%{ +#include +#include +%} + +namespace std { + + template class vector { + public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; + vector(); + vector(size_type n); + size_type size() const; + size_type capacity() const; + void reserve(size_type n); + %rename(isEmpty) empty; + bool empty() const; + void clear(); + %rename(add) push_back; + void push_back(const value_type& x); + %extend { + const_reference get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && isize()); + if (i>=0 && i class vector { + public: + typedef size_t size_type; + typedef bool value_type; + typedef bool const_reference; + vector(); + vector(size_type n); + size_type size() const; + size_type capacity() const; + void reserve(size_type n); + %rename(isEmpty) empty; + bool empty() const; + void clear(); + %rename(add) push_back; + void push_back(const value_type& x); + %extend { + const_reference get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && isize()); + if (i>=0 && i +%include +%include +%include +%include diff --git a/Lib/go/typemaps.i b/Lib/go/typemaps.i new file mode 100644 index 000000000..17da80c23 --- /dev/null +++ b/Lib/go/typemaps.i @@ -0,0 +1,335 @@ +/* ----------------------------------------------------------------------------- + * typemaps.i + * + * Pointer and reference handling typemap library + * + * These mappings provide support for input/output arguments and common + * uses for C/C++ pointers and C++ references. + * ----------------------------------------------------------------------------- */ + +/* +INPUT typemaps +-------------- + +These typemaps remap a C pointer or C++ reference to be an "INPUT" value which is +passed by value instead of reference. + +The following typemaps can be applied to turn a pointer or reference into a simple +input value. That is, instead of passing a pointer or reference to an object, +you would use a real value instead. + + bool *INPUT, bool &INPUT + signed char *INPUT, signed char &INPUT + unsigned char *INPUT, unsigned char &INPUT + short *INPUT, short &INPUT + unsigned short *INPUT, unsigned short &INPUT + int *INPUT, int &INPUT + unsigned int *INPUT, unsigned int &INPUT + long *INPUT, long &INPUT + unsigned long *INPUT, unsigned long &INPUT + long long *INPUT, long long &INPUT + unsigned long long *INPUT, unsigned long long &INPUT + float *INPUT, float &INPUT + double *INPUT, double &INPUT + +To use these, suppose you had a C function like this : + + double fadd(double *a, double *b) { + return *a+*b; + } + +You could wrap it with SWIG as follows : + + %include + double fadd(double *INPUT, double *INPUT); + +or you can use the %apply directive : + + %include + %apply double *INPUT { double *a, double *b }; + double fadd(double *a, double *b); + +In Go you could then use it like this: + answer := modulename.Fadd(10.0, 20.0) + +There are no char *INPUT typemaps, however you can apply the signed +char * typemaps instead: + %include + %apply signed char *INPUT {char *input}; + void f(char *input); +*/ + +%define INPUT_TYPEMAP(TYPE, GOTYPE) +%typemap(go) TYPE *INPUT, TYPE &INPUT "GOTYPE" + +%typemap(in) TYPE *INPUT +%{ $1 = ($1_ltype)&$input; %} + +%typemap(in) TYPE &INPUT +%{ $1 = ($1_ltype)$input; %} + +%typemap(freearg) TYPE *INPUT, TYPE &INPUT "" + +%typemap(directorout) TYPE *INPUT +%{ $result = ($1_ltype)&$input; %} + +%typemap(directorout) TYPE &INPUT +%{ $result = ($1_ltype)$input; %} + +%typemap(directorin) TYPE &INPUT +%{ $1 = ($input_ltype)&$input; %} + +// %typemap(typecheck) TYPE *INPUT = TYPE; +// %typemap(typecheck) TYPE &INPUT = TYPE; +%enddef + +INPUT_TYPEMAP(bool, bool); +INPUT_TYPEMAP(signed char, int8); +INPUT_TYPEMAP(char, byte); +INPUT_TYPEMAP(unsigned char, byte); +INPUT_TYPEMAP(short, int16); +INPUT_TYPEMAP(unsigned short, uint16); +INPUT_TYPEMAP(int, int); +INPUT_TYPEMAP(unsigned int, uint); +INPUT_TYPEMAP(long, int64); +INPUT_TYPEMAP(unsigned long, uint64); +INPUT_TYPEMAP(long long, int64); +INPUT_TYPEMAP(unsigned long long, uint64); +INPUT_TYPEMAP(float, float); +INPUT_TYPEMAP(double, float64); + +#undef INPUT_TYPEMAP + +// OUTPUT typemaps. These typemaps are used for parameters that +// are output only. An array replaces the c pointer or reference parameter. +// The output value is returned in this array passed in. + +/* +OUTPUT typemaps +--------------- + +The following typemaps can be applied to turn a pointer or reference +into an "output" value. When calling a function, no input value would +be given for a parameter, but an output value would be returned. This +works by a Go slice being passed as a parameter where a c pointer or +reference is required. As with any Go function, the array is passed +by reference so that any modifications to the array will be picked up +in the calling function. Note that the array passed in MUST have at +least one element, but as the c function does not require any input, +the value can be set to anything. + + bool *OUTPUT, bool &OUTPUT + signed char *OUTPUT, signed char &OUTPUT + unsigned char *OUTPUT, unsigned char &OUTPUT + short *OUTPUT, short &OUTPUT + unsigned short *OUTPUT, unsigned short &OUTPUT + int *OUTPUT, int &OUTPUT + unsigned int *OUTPUT, unsigned int &OUTPUT + long *OUTPUT, long &OUTPUT + unsigned long *OUTPUT, unsigned long &OUTPUT + long long *OUTPUT, long long &OUTPUT + unsigned long long *OUTPUT, unsigned long long &OUTPUT + float *OUTPUT, float &OUTPUT + double *OUTPUT, double &OUTPUT + +For example, suppose you were trying to wrap the modf() function in the +C math library which splits x into integral and fractional parts (and +returns the integer part in one of its parameters): + + double modf(double x, double *ip); + +You could wrap it with SWIG as follows : + + %include + double modf(double x, double *OUTPUT); + +or you can use the %apply directive : + + %include + %apply double *OUTPUT { double *ip }; + double modf(double x, double *ip); + +The Go output of the function would be the function return value and the +value in the single element array. In Go you would use it like this: + + ptr := []float64{0.0} + fraction := modulename.Modf(5.0,ptr) + +There are no char *OUTPUT typemaps, however you can apply the signed +char * typemaps instead: + %include + %apply signed char *OUTPUT {char *output}; + void f(char *output); +*/ + +%define OUTPUT_TYPEMAP(TYPE, GOTYPE) +%typemap(go) TYPE *OUTPUT, TYPE &OUTPUT %{[]GOTYPE%} + +%typemap(in) TYPE *OUTPUT($*1_ltype temp) +{ + if ($input.len == 0) { + _swig_gopanic("array must contain at least 1 element"); + } + $1 = &temp; +} + +%typemap(in) TYPE &OUTPUT($*1_ltype temp) +{ + if ($input->len == 0) { + _swig_gopanic("array must contain at least 1 element"); + } + $1 = &temp; +} + +%typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT "" + +%typemap(argout) TYPE *OUTPUT +{ + TYPE* a = (TYPE *) $input.array; + a[0] = temp$argnum; +} + +%typemap(argout) TYPE &OUTPUT +{ + TYPE* a = (TYPE *) $input->array; + a[0] = temp$argnum; +} + +%typemap(directorout,warning="Need to provide TYPE *OUTPUT directorout typemap") TYPE *OUTPUT, TYPE &OUTPUT { +} + +%typemap(directorin) TYPE &OUTPUT +%{ *(($&1_ltype) $input = &$1; %} + +%typemap(directorin,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT +{ +} + +%enddef + +OUTPUT_TYPEMAP(bool, bool); +OUTPUT_TYPEMAP(signed char, int8); +OUTPUT_TYPEMAP(char, byte); +OUTPUT_TYPEMAP(unsigned char, byte); +OUTPUT_TYPEMAP(short, int16); +OUTPUT_TYPEMAP(unsigned short, uint16); +OUTPUT_TYPEMAP(int, int); +OUTPUT_TYPEMAP(unsigned int, uint); +OUTPUT_TYPEMAP(long, int64); +OUTPUT_TYPEMAP(unsigned long, uint64); +OUTPUT_TYPEMAP(long long, int64); +OUTPUT_TYPEMAP(unsigned long long, uint64); +OUTPUT_TYPEMAP(float, float); +OUTPUT_TYPEMAP(double, float64); + +#undef OUTPUT_TYPEMAP + +/* +INOUT typemaps +-------------- + +Mappings for a parameter that is both an input and an output parameter + +The following typemaps can be applied to make a function parameter both +an input and output value. This combines the behavior of both the +"INPUT" and "OUTPUT" typemaps described earlier. Output values are +returned as an element in a Go slice. + + bool *INOUT, bool &INOUT + signed char *INOUT, signed char &INOUT + unsigned char *INOUT, unsigned char &INOUT + short *INOUT, short &INOUT + unsigned short *INOUT, unsigned short &INOUT + int *INOUT, int &INOUT + unsigned int *INOUT, unsigned int &INOUT + long *INOUT, long &INOUT + unsigned long *INOUT, unsigned long &INOUT + long long *INOUT, long long &INOUT + unsigned long long *INOUT, unsigned long long &INOUT + float *INOUT, float &INOUT + double *INOUT, double &INOUT + +For example, suppose you were trying to wrap the following function : + + void neg(double *x) { + *x = -(*x); + } + +You could wrap it with SWIG as follows : + + %include + void neg(double *INOUT); + +or you can use the %apply directive : + + %include + %apply double *INOUT { double *x }; + void neg(double *x); + +This works similarly to C in that the mapping directly modifies the +input value - the input must be an array with a minimum of one element. +The element in the array is the input and the output is the element in +the array. + + x := []float64{5.0} + Neg(x); + +The implementation of the OUTPUT and INOUT typemaps is different to +other languages in that other languages will return the output value +as part of the function return value. This difference is due to Go +being a typed language. + +There are no char *INOUT typemaps, however you can apply the signed +char * typemaps instead: + %include + %apply signed char *INOUT {char *inout}; + void f(char *inout); +*/ + +%define INOUT_TYPEMAP(TYPE, GOTYPE) +%typemap(go) TYPE *INOUT, TYPE &INOUT %{[]GOTYPE%} + +%typemap(in) TYPE *INOUT { + if ($input.len == 0) { + _swig_gopanic("array must contain at least 1 element"); + } + $1 = ($1_ltype) $input.array; +} + +%typemap(in) TYPE &INOUT { + if ($input->len == 0) { + _swig_gopanic("array must contain at least 1 element"); + } + $1 = ($1_ltype) $input->array; +} + +%typemap(freearg) TYPE *INOUT, TYPE &INOUT "" + +%typemap(directorout,warning="Need to provide TYPE *INOUT directorout typemap") TYPE *INOUT, TYPE &INOUT { +} + +%typemap(directorin) TYPE &INOUT +%{ *(($&1_ltype)&$input) = &$1; %} + +%typemap(directorin,warning="Need to provide TYPE *INOUT directorin typemap, TYPE array length is unknown") TYPE *INOUT, TYPE &INOUT +{ +} + +%enddef + +INOUT_TYPEMAP(bool, bool); +INOUT_TYPEMAP(signed char, int8); +INOUT_TYPEMAP(char, byte); +INOUT_TYPEMAP(unsigned char, byte); +INOUT_TYPEMAP(short, int16); +INOUT_TYPEMAP(unsigned short, uint16); +INOUT_TYPEMAP(int, int); +INOUT_TYPEMAP(unsigned int, uint); +INOUT_TYPEMAP(long, int64); +INOUT_TYPEMAP(unsigned long, uint64); +INOUT_TYPEMAP(long long, int64); +INOUT_TYPEMAP(unsigned long long, uint64); +INOUT_TYPEMAP(float, float); +INOUT_TYPEMAP(double, float64); + +#undef INOUT_TYPEMAP diff --git a/Makefile.in b/Makefile.in index 0beb7cbdd..180ad3451 100644 --- a/Makefile.in +++ b/Makefile.in @@ -75,6 +75,7 @@ skip-clisp = test -n "@SKIP_CLISP@" skip-cffi = test -n "@SKIP_CFFI@" skip-uffi = test -n "@SKIP_UFFI@" skip-r = test -n "@SKIP_R@" +skip-go = test -n "@SKIP_GO@" # Additional dependencies for some tests skip-gcj = test -n "@SKIP_GCJ@" @@ -110,6 +111,7 @@ check-aliveness: @$(skip-modula3) || ./$(TARGET) -modula3 -help @$(skip-lua) || ./$(TARGET) -lua -help @$(skip-r) || ./$(TARGET) -r -help + @$(skip-go) || ./$(TARGET) -go -help check-ccache: test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) check) @@ -135,7 +137,8 @@ check-examples: \ check-clisp-examples \ check-uffi-examples \ check-cffi-examples \ - check-r-examples + check-r-examples \ + check-go-examples tcl_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/tcl/check.list) perl5_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/perl5/check.list) @@ -157,6 +160,7 @@ clisp_examples := uffi_examples := cffi_examples := r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list) +go_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/go/check.list) # all examples check-%-examples : @@ -206,7 +210,8 @@ check-test-suite: \ check-uffi-test-suite \ check-cffi-test-suite \ check-chicken-test-suite \ - check-r-test-suite + check-r-test-suite \ + check-go-test-suite check-%-test-suite: @if test -z "$(skip-$*)"; then \ @@ -257,7 +262,8 @@ all-test-suite: \ all-uffi-test-suite \ all-cffi-test-suite \ all-chicken-test-suite \ - all-r-test-suite + all-r-test-suite \ + all-go-test-suite all-%-test-suite: @$(MAKE) -k -s check-$*-test-suite ACTION=all @@ -284,7 +290,8 @@ broken-test-suite: \ broken-uffi-test-suite \ broken-cffi-test-suite \ broken-chicken-test-suite \ - broken-r-test-suite + broken-r-test-suite \ + broken-go-test-suite broken-%-test-suite: @$(MAKE) -k -s check-$*-test-suite ACTION=broken @@ -401,7 +408,7 @@ install-main: @$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/`echo $(TARGET_NOEXE) | sed '$(transform)'`@EXEEXT@ lib-languages = gcj typemaps tcl perl5 python guile java mzscheme ruby php ocaml octave \ - pike chicken csharp modula3 allegrocl clisp lua cffi uffi r + pike chicken csharp modula3 allegrocl clisp lua cffi uffi r go lib-modules = std diff --git a/Source/Makefile.am b/Source/Makefile.am index 26f37b2fe..4677002e6 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -44,6 +44,7 @@ eswig_SOURCES = CParse/cscanner.c \ Modules/csharp.cxx \ Modules/directors.cxx \ Modules/emit.cxx \ + Modules/go.cxx \ Modules/guile.cxx \ Modules/java.cxx \ Modules/lang.cxx \ diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index de4a7bfa9..93ca6d8f3 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1709,6 +1709,8 @@ int ALLEGROCL::top(Node *n) { We don't need a dispatch function in the C++ wrapper code; we want it over on the lisp side. */ +#define Swig_overload_rank Allegrocl_swig_overload_rank + #define MAX_OVERLOAD 256 /* Overload "argc" and "argv" */ diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx new file mode 100644 index 000000000..91a0f457b --- /dev/null +++ b/Source/Modules/go.cxx @@ -0,0 +1,4824 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * go.cxx + * + * Go language module for SWIG. + * ----------------------------------------------------------------------------- */ + +char cvsroot_go_cxx[] = "$Id"; + +#include "swigmod.h" +#include "cparse.h" +#include +#include + +class GO:public Language { + static const char * const usage; + + // Go package name. + String *package; + // Flag for generating gccgo output. + bool gccgo_flag; + // Prefix to use with gccgo. + String *go_prefix; + // Name of shared library to import. + String *soname; + // Size in bits of the C type "long". + int long_type_size; + // Rename directives. + String *renames; + + /* Output files */ + File *f_c_begin; + File *f_go_begin; + File *f_gc_begin; + + /* Output fragments */ + File *f_c_runtime; + File *f_c_header; + File *f_c_wrappers; + File *f_c_init; + File *f_c_directors; + File *f_c_directors_h; + File *f_go_runtime; + File *f_go_header; + File *f_go_wrappers; + File *f_go_once; + File *f_gc_runtime; + File *f_gc_header; + File *f_gc_wrappers; + File *f_gc_once; + + // True if we imported a module. + bool saw_import; + // If not NULL, name of import package being processed. + String *imported_package; + // Build interface methods while handling a class. This is only + // non-NULL when we are handling methods. + String *interfaces; + // The class node while handling a class. This is only non-NULL + // when we are handling methods. + Node *class_node; + // The class name while handling a class. This is only non-NULL + // when we are handling methods. This is the name of the class as + // SWIG sees it. + String *class_name; + // The receiver name while handling a class. This is only non-NULL + // when we are handling methods. This is the name of the class + // as run through goCPointerType. + String *class_receiver; + // A hash table of method names that we have seen when processing a + // class. This lets us detect base class methods that we don't want + // to use. + Hash *class_methods; + // True when we are generating the wrapper functions for a variable. + bool making_variable_wrappers; + // True when working with a static member function. + bool is_static_member_function; + // A hash table of types that we have seen but which may not have + // been defined. The index is a SwigType. + Hash *undefined_types; + // A hash table of classes which were defined. The index is a Go + // type name. + Hash *defined_types; + +public: + GO():package(NULL), + gccgo_flag(false), + go_prefix(NULL), + soname(NULL), + long_type_size(32), + renames(NULL), + f_c_begin(NULL), + f_go_begin(NULL), + f_gc_begin(NULL), + f_c_runtime(NULL), + f_c_header(NULL), + f_c_wrappers(NULL), + f_c_init(NULL), + f_c_directors(NULL), + f_c_directors_h(NULL), + f_go_runtime(NULL), + f_go_header(NULL), + f_go_wrappers(NULL), + f_go_once(NULL), + f_gc_runtime(NULL), + f_gc_header(NULL), + f_gc_wrappers(NULL), + f_gc_once(NULL), + saw_import(false), + imported_package(NULL), + interfaces(NULL), + class_receiver(NULL), + class_methods(NULL), + making_variable_wrappers(false), + is_static_member_function(false), + undefined_types(NULL), + defined_types(NULL) + { + director_multiple_inheritance = 1; + director_language = 1; + director_prot_ctor_code = NewString("_swig_gopanic(\"accessing abstract class or protected constructor\");"); + } + +private: + /* ------------------------------------------------------------ + * main() + * ------------------------------------------------------------ */ + virtual void main(int argc, char *argv[]) { + + SWIG_library_directory("go"); + + // Process command line options. + for (int i = 1; i < argc; i++) { + if (argv[i]) { + if (strcmp(argv[i], "-package") == 0) { + if (argv[i + 1] != NULL) { + package = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-gccgo") == 0) { + Swig_mark_arg(i); + gccgo_flag = true; + } else if (strcmp(argv[i], "-go-prefix") == 0) { + if (argv[i + 1] != NULL) { + go_prefix = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-soname") == 0) { + if (argv[i + 1] != NULL) { + soname = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-longsize") == 0) { + if (argv[i + 1] != NULL) { + long_type_size = atoi(argv[i + 1]); + if (long_type_size != 32 && long_type_size != 64) { + Printf(stderr, "-longsize not 32 or 64\n"); + Swig_arg_error(); + } + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + ++i; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-rename") == 0) { + if (argv[i + 1] != NULL) { + String *d = NewString(argv[i + 1]); + Replace(d, "=", " ", DOH_REPLACE_FIRST); + Preprocessor_define(d, 0); + if (renames == NULL) { + renames = NewString(""); + } + Printv(renames, "#define ", d, "\n", NULL); + Delete(d); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + ++i; + // Prevent SWIG from trying to define this for the + // preprocessor, which breaks if there are multiple + // -rename options. + argv[i] = NULL; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-help") == 0) { + Printf(stdout, "%s\n", usage); + } + } + } + + if (gccgo_flag && go_prefix == NULL) { + go_prefix = NewString("go"); + } + + // Add preprocessor symbol to parser. + Preprocessor_define("SWIGGO 1", 0); + + if (gccgo_flag) { + Preprocessor_define("SWIGGO_GCCGO 1", 0); + } + + if (long_type_size == 32) { + Preprocessor_define("SWIGGO_LONG_TYPE_SIZE 32", 0); + } else { + Preprocessor_define("SWIGGO_LONG_TYPE_SIZE 64", 0); + } + + // Add typemap definitions. + SWIG_typemap_lang("go"); + SWIG_config_file("go.swg"); + + allow_overloading(); + } + + /* --------------------------------------------------------------------- + * top() + * + * For 6g/8g, we are going to create the following files: + * + * 1) A .c or .cxx file compiled with gcc. This file will contain + * function wrappers. Each wrapper will take a pointer to a + * struct holding the arguments, unpack them, and call the real + * function. + * + * 2) A .go file which defines the Go form of all types, and which + * defines Go function wrappers. Each wrapper will call the C + * function wrapper in the second file. + * + * 3) A .c file compiled with 6c/8c. This file will define + * Go-callable C function wrappers. Each wrapper will use + * cgocall to call the function wrappers in the first file. + * + * When generating code for gccgo, we don't need the third file, and + * the function wrappers in the first file have a different form. + * + * --------------------------------------------------------------------- */ + + virtual int top(Node *n) { + Node *optionsnode = Getattr(Getattr(n, "module"), "options"); + if (optionsnode != NULL) { + if (Getattr(optionsnode, "directors")) { + allow_directors(); + } + if (Getattr(optionsnode, "dirprot")) { + allow_dirprot(); + } + allow_allprotected(GetFlag(optionsnode, "allprotected")); + } + + String *module = Getattr(n, "name"); + if (package == NULL) { + package = Copy(module); + } + if (soname == NULL) { + soname = Copy(package); + Append(soname, ".so"); + } + + // Get filenames. + + String *c_filename = Getattr(n, "outfile"); + String *c_filename_h = Getattr(n, "outfile_h"); + + String *go_filename = NewString(""); + Printf(go_filename, "%s%s.go", SWIG_output_directory(), module); + + String *gc_filename = NULL; + if (!gccgo_flag) { + gc_filename = NewString(""); + Printf(gc_filename, "%s%s_gc.c", SWIG_output_directory(), module); + } + + // Open files. + + f_c_begin = NewFile(c_filename, "w", SWIG_output_files()); + if (!f_c_begin) { + FileErrorDisplay(c_filename); + SWIG_exit(EXIT_FAILURE); + } + + if (directorsEnabled()) { + if (!c_filename_h) { + Printf(stderr, "Unable to determine outfile_h\n"); + SWIG_exit(EXIT_FAILURE); + } + f_c_directors_h = NewFile(c_filename_h, "w", SWIG_output_files()); + if (!f_c_directors_h) { + FileErrorDisplay(c_filename_h); + SWIG_exit(EXIT_FAILURE); + } + } + + f_go_begin = NewFile(go_filename, "w", SWIG_output_files()); + if (!f_go_begin) { + FileErrorDisplay(go_filename); + SWIG_exit(EXIT_FAILURE); + } + + if (!gccgo_flag) { + f_gc_begin = NewFile(gc_filename, "w", SWIG_output_files()); + if (!f_gc_begin) { + FileErrorDisplay(gc_filename); + SWIG_exit(EXIT_FAILURE); + } + } + + f_c_runtime = NewString(""); + f_c_header = NewString(""); + f_c_wrappers = NewString(""); + f_c_init = NewString(""); + f_c_directors = NewString(""); + f_go_runtime = NewString(""); + f_go_header = NewString(""); + f_go_wrappers = NewString(""); + f_go_once = NewString(""); + if (!gccgo_flag) { + f_gc_runtime = NewString(""); + f_gc_header = NewString(""); + f_gc_wrappers = NewString(""); + f_gc_once = NewString(""); + } + + Swig_register_filebyname("begin", f_c_begin); + Swig_register_filebyname("runtime", f_c_runtime); + Swig_register_filebyname("header", f_c_header); + Swig_register_filebyname("wrapper", f_c_wrappers); + Swig_register_filebyname("init", f_c_init); + Swig_register_filebyname("director", f_c_directors); + Swig_register_filebyname("director_h", f_c_directors_h); + Swig_register_filebyname("go_begin", f_go_begin); + Swig_register_filebyname("go_runtime", f_go_runtime); + Swig_register_filebyname("go_header", f_go_header); + Swig_register_filebyname("go_wrapper", f_go_wrappers); + Swig_register_filebyname("go_once", f_go_once); + if (!gccgo_flag) { + Swig_register_filebyname("gc_begin", f_gc_begin); + Swig_register_filebyname("gc_runtime", f_gc_runtime); + Swig_register_filebyname("gc_header", f_gc_header); + Swig_register_filebyname("gc_wrapper", f_gc_wrappers); + Swig_register_filebyname("gc_once", f_gc_once); + } + + Swig_banner(f_c_begin); + if (!gccgo_flag) { + Printf(f_c_begin, "\n/* This file should be compiled with gcc. */\n"); + } + if (renames != NULL) { + Printf(f_c_begin, "%s\n", renames); + } + + if (directorsEnabled()) { + Printf(f_c_runtime, "#define SWIG_DIRECTORS\n"); + + Swig_banner(f_c_directors_h); + Printf(f_c_directors_h, + "\n/* This file should be compiled with gcc. */\n"); + Printf(f_c_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module); + Printf(f_c_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module); + + Printf(f_c_directors, "\n// C++ director class methods.\n"); + Printf(f_c_directors, "#include \"%s\"\n\n", + Swig_file_filename(c_filename_h)); + } + + Swig_banner(f_go_begin); + + if (!gccgo_flag) { + Swig_banner(f_gc_begin); + Printf(f_gc_begin, "\n/* This file should be compiled with 6c/8c. */\n"); + } + + // Output module initialization code. + + Printf(f_go_begin, "\npackage %s\n\n", package); + + // Set up the hash table for types not defined by SWIG. + + undefined_types = NewHash(); + defined_types = NewHash(); + + // Emit code. + + Language::top(n); + + // Write out definitions for the types not defined by SWIG. + + Printv(f_go_wrappers, "\n", NULL); + for (Iterator p = First(undefined_types); p.key != NULL; p = Next(p)) { + String *ty = goType(NULL, p.key); + if (Getattr(defined_types, ty) == NULL) { + String *cp = goCPointerType(p.key, false); + if (Getattr(defined_types, cp) == NULL) { + Printv(f_go_wrappers, "type ", cp, " uintptr\n", NULL); + Printv(f_go_wrappers, "type ", ty, " interface {\n", NULL); + Printv(f_go_wrappers, "\tSwigcptr() uintptr;\n", NULL); + Printv(f_go_wrappers, "}\n", NULL); + Printv(f_go_wrappers, "func (p ", cp, ") Swigcptr() uintptr {\n", + NULL); + Printv(f_go_wrappers, "\treturn uintptr(p)\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + } + Delete(cp); + } + Delete(ty); + } + Delete(undefined_types); + Delete(defined_types); + + /* Write and cleanup */ + + Dump(f_c_header, f_c_runtime); + + if (directorsEnabled()) { + Printf(f_c_directors_h, "#endif\n"); + Close(f_c_directors_h); + Delete(f_c_directors_h); + f_c_directors_h = NULL; + + Dump(f_c_directors, f_c_runtime); + Close(f_c_directors); + Delete(f_c_directors); + f_c_directors = NULL; + } + + Dump(f_c_runtime, f_c_begin); + Dump(f_c_wrappers, f_c_begin); + Dump(f_c_init, f_c_begin); + Dump(f_go_header, f_go_begin); + if (!saw_import) { + Dump(f_go_once, f_go_begin); + } + Dump(f_go_runtime, f_go_begin); + Dump(f_go_wrappers, f_go_begin); + if (!gccgo_flag) { + Dump(f_gc_header, f_gc_begin); + if (!saw_import) { + Dump(f_gc_once, f_gc_begin); + } + Dump(f_gc_runtime, f_gc_begin); + Dump(f_gc_wrappers, f_gc_begin); + } + + Delete(f_c_runtime); + Delete(f_c_header); + Delete(f_c_wrappers); + Delete(f_c_init); + Delete(f_go_runtime); + Delete(f_go_header); + Delete(f_go_wrappers); + if (!gccgo_flag) { + Delete(f_gc_runtime); + Delete(f_gc_header); + Delete(f_gc_wrappers); + } + + Close(f_c_begin); + Delete(f_c_begin); + Close(f_go_begin); + Delete(f_go_begin); + if (!gccgo_flag) { + Close(f_gc_begin); + Delete(f_gc_begin); + } + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * importDirective() + * + * Handle a SWIG import statement by generating a Go import + * statement. + * ------------------------------------------------------------ */ + + virtual int importDirective(Node *n) { + String *hold_import = imported_package; + String *modname = Getattr(n, "module"); + if (modname != NULL) { + Printv(f_go_begin, "import \"", modname, "\"\n", NULL); + imported_package = modname; + saw_import = true; + } + int r = Language::importDirective(n); + imported_package = hold_import; + return r; + } + + /* ---------------------------------------------------------------------- + * functionWrapper() + * + * Implement a function. + * ---------------------------------------------------------------------- */ + + virtual int functionWrapper(Node *n) { + if (GetFlag(n, "feature:ignore")) { + return SWIG_OK; + } + + // We don't need explicit calls. + if (GetFlag(n, "explicitcall")) { + return SWIG_OK; + } + + String *name = Getattr(n, "sym:name"); + String *nodetype = Getattr(n, "nodeType"); + bool is_static = is_static_member_function || isStatic(n); + bool is_friend = isFriend(n); + bool is_ctor_dtor = false; + + SwigType *result = Getattr(n, "type"); + + // For some reason SWIG changs the "type" value during the call to + // functionWrapper. We need to remember the type for possible + // overload processing. + Setattr(n, "go:type", Copy(result)); + + String *go_name; + + String *r1 = NULL; + if (making_variable_wrappers) { + // Change the name of the variable setter and getter functions + // to be more Go like. + + bool is_set = Strcmp(Char(name) + Len(name) - 4, "_set") == 0; + assert(is_set || Strcmp(Char(name) + Len(name) - 4, "_get") == 0); + + // Start with Set or Get. + go_name = NewString(is_set ? "Set" : "Get"); + + // If this is a static variable, put in the class name, + // capitalized. + if (is_static && class_name != NULL) { + String *ccn = exportedName(class_name); + Append(go_name, ccn); + Delete(ccn); + } + + // Add the rest of the name, capitalized, dropping the _set or + // _get. + String *c1 = removeClassname(name); + String *c2 = exportedName(c1); + char *p = Char(c2); + int len = Len(p); + for (int i = 0; i < len - 4; ++i) { + Putc(p[i], go_name); + } + Delete(c2); + Delete(c1); + } else if (Cmp(nodetype, "constructor") == 0) { + is_ctor_dtor = true; + + // Change the name of a constructor to be more Go like. Change + // new_ to New, and capitalize the class name. + assert(Strncmp(name, "new_", 4) == 0); + String *c1 = NewString(Char(name) + 4); + String *c2 = exportedName(c1); + go_name = NewString("New"); + Append(go_name, c2); + Delete(c2); + Delete(c1); + + if (Swig_methodclass(n) != NULL + && Swig_directorclass(n) + && Strcmp(Char(Getattr(n, "wrap:action")), + director_prot_ctor_code) != 0) { + // The core SWIG code skips the first parameter when + // generating the $nondirector_new string. Recreate the + // action in this case. But don't it if we are using the + // special code for an abstract class. + String *call = Swig_cppconstructor_call(getClassType(), + Getattr(n, "parms")); + SwigType *type = Copy(getClassType()); + SwigType_add_pointer(type); + String *cres = Swig_cresult(type, "result", call); + Setattr(n, "wrap:action", cres); + } + } else if (Cmp(nodetype, "destructor") == 0) { + // No need to emit protected destructors. + if (!is_public(n)) { + return SWIG_OK; + } + + is_ctor_dtor = true; + + // Change the name of a destructor to be more Go like. Change + // delete_ to Delete and capitalize the class name. + assert(Strncmp(name, "delete_", 7) == 0); + String *c1 = NewString(Char(name) + 7); + String *c2 = exportedName(c1); + go_name = NewString("Delete"); + Append(go_name, c2); + Delete(c2); + Delete(c1); + + result = NewString("void"); + r1 = result; + } else { + if (!is_public(n)) { + return SWIG_OK; + } + + go_name = buildGoName(name, is_static, is_friend); + } + + String *overname = NULL; + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); + } else if (class_name == NULL || is_static) { + if (!addSymbol(go_name, n)) { + return SWIG_ERROR; + } + } else { + String *c = Copy(class_name); + Putc('+', c); + Append(c, go_name); + if (!addSymbol(c, n)) { + return SWIG_ERROR; + } + Delete(c); + } + + String *wname = Swig_name_wrapper(name); + if (overname != NULL) { + Append(wname, overname); + } + Setattr(n, "wrap:name", wname); + + ParmList *parms = Getattr(n, "parms"); + Setattr(n, "wrap:parms", parms); + + int r = makeWrappers(n, name, go_name, overname, wname, NULL, parms, + result, is_static); + if (r != SWIG_OK) { + return r; + } + + if (Getattr(n, "sym:overloaded") && Getattr(n, "sym:nextSibling") == NULL) { + String *receiver = class_receiver; + if (is_static || is_ctor_dtor) { + receiver = NULL; + } + r = makeDispatchFunction(n, go_name, receiver, is_static, NULL, false); + if (r != SWIG_OK) { + return r; + } + } + + Delete(wname); + Delete(go_name); + if (r1 != NULL) { + Delete(r1); + } + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * staticmemberfunctionHandler + * + * For some reason the language code removes the "storage" attribute + * for a static function before calling functionWrapper, which means + * that we have no way of knowing whether a function is static or + * not. That makes no sense in the Go context. Here we note that a + * function is static. + * ---------------------------------------------------------------------- */ + + int staticmemberfunctionHandler(Node *n) { + assert(!is_static_member_function); + is_static_member_function = true; + int r = Language::staticmemberfunctionHandler(n); + is_static_member_function = false; + return r; + } + + /* ---------------------------------------------------------------------- + * makeWrappers() + * + * Write out the various function wrappers. + * N: The function we are emitting. + * NAME: The function name. + * GO_NAME: The name of the function in Go. + * OVERNAME: The overload string for overloaded function. + * WNAME: The SWIG wrapped name--the name of the C function. + * BASE: A list of the names of base classes, in the case where this + * is is a vritual method not defined in the current class. + * PARMS: The parameters. + * RESULT: The result type. + * IS_STATIC: Whether this is a static method or member. + * ---------------------------------------------------------------------- */ + + int makeWrappers(Node *n, String *name, String *go_name, String *overname, + String *wname, List *base, ParmList *parms, + SwigType *result, bool is_static) { + + assert(result != NULL); + + bool needs_wrapper; + int r = goFunctionWrapper(n, name, go_name, overname, wname, base, parms, + result, is_static, &needs_wrapper); + if (r != SWIG_OK) { + return r; + } + + if (!gccgo_flag) { + r = gcFunctionWrapper(n, name, go_name, overname, wname, parms, result, + is_static, needs_wrapper); + if (r != SWIG_OK) { + return r; + } + r = gccFunctionWrapper(n, base, wname, parms, result); + if (r != SWIG_OK) { + return r; + } + } else { + r = gccgoFunctionWrapper(n, base, wname, parms, result); + if (r != SWIG_OK) { + return r; + } + } + + if (class_methods != NULL) { + Setattr(class_methods, Getattr(n, "name"), NewString("")); + } + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * goFunctionWrapper() + * + * Write out a function wrapper in Go. When not implementing a + * method, the actual code is all in C; here we just declare the C + * function. When implementing a method, we have to call the C + * function, because it will have a different name. If base is not + * NULL, then we are being called to forward a virtual method to a + * base class. + * ---------------------------------------------------------------------- */ + + int goFunctionWrapper(Node *n, String *name, String *go_name, + String *overname, String *wname, List *base, + ParmList *parms, SwigType *result, bool is_static, + bool *p_needs_wrapper) { + Wrapper *dummy = NewWrapper(); + emit_attach_parmmaps(parms, dummy); + Swig_typemap_attach_parms("default", parms, dummy); + Swig_typemap_attach_parms("go", parms, dummy); + int parm_count = emit_num_arguments(parms); + int required_count = emit_num_required(parms); + + String *receiver = class_receiver; + if (receiver != NULL && is_static) { + receiver = NULL; + } + + String *nodetype = Getattr(n, "nodeType"); + bool is_constructor = Cmp(nodetype, "constructor") == 0; + bool is_destructor = Cmp(nodetype, "destructor") == 0; + if (is_constructor || is_destructor) { + assert(class_receiver != NULL); + assert(base == NULL); + receiver = NULL; + } + + bool add_to_interface = (interfaces != NULL + && !is_constructor + && !is_destructor + && !is_static + && overname == NULL + && is_public(n)); + + bool needs_wrapper = (gccgo_flag + || receiver != NULL + || 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); + } + } + if (goTypeIsInterface(NULL, result)) { + needs_wrapper = true; + } + + *p_needs_wrapper = needs_wrapper; + + // If this is a method, first declare the C function we will call. + // If we do not need a wrapper, then we will only be writing a + // declaration. + String *wrapper_name = NULL; + if (needs_wrapper) { + wrapper_name = buildGoWrapperName(name, overname); + + Printv(f_go_wrappers, "func ", wrapper_name, "(", NULL); + if (parm_count > required_count) { + Printv(f_go_wrappers, "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); + ++i; + p = nextParm(p); + } else if (receiver != NULL && (base != NULL || !is_constructor)) { + if (parm_count > required_count) { + Printv(f_go_wrappers, ", ", NULL); + } + Printv(f_go_wrappers, receiver, NULL); + if (base == NULL) { + ++i; + p = nextParm(p); + } + } + 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 != NULL && receiver != NULL) + || parm_count > required_count) { + Printv(f_go_wrappers, ", ", NULL); + } + String *tm = goWrapperType(p, Getattr(p, "type"), false); + Printv(f_go_wrappers, tm, NULL); + Delete(tm); + p = nextParm(p); + } + Printv(f_go_wrappers, ")", NULL); + if (is_constructor) { + Printv(f_go_wrappers, " ", class_receiver, NULL); + } else { + if (SwigType_type(result) != T_VOID) { + String *tm = goWrapperType(n, result, true); + Printv(f_go_wrappers, " ", tm, NULL); + Delete(tm); + } + } + + if (gccgo_flag) { + Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", wname, "\")", + NULL); + } + + Printv(f_go_wrappers, "\n\n", NULL); + } + + // Start defining the Go function. + + Printv(f_go_wrappers, "func ", NULL); + + Parm *p = parms; + int pi = 0; + + // Add the receiver if this is a method. + if (receiver != NULL) { + Printv(f_go_wrappers, "(", NULL); + if (base != NULL && receiver != NULL) { + Printv(f_go_wrappers, "_swig_base", NULL); + } else { + Printv(f_go_wrappers, Getattr(p, "lname"), NULL); + p = nextParm(p); + ++pi; + } + Printv(f_go_wrappers, " ", receiver, ") ", NULL); + } + + Printv(f_go_wrappers, go_name, NULL); + if (overname != NULL) { + Printv(f_go_wrappers, overname, NULL); + } + Printv(f_go_wrappers, "(", NULL); + + // If we are doing methods, add this function to the interface. + if (add_to_interface) { + Printv(interfaces, "\t", go_name, "(", NULL); + } + + // Write out the parameters to both the function definition and + // the interface. + + String *parm_print = NewString(""); + + for (; pi < parm_count; ++pi) { + p = getParm(p); + if (pi == 0 && is_destructor) { + String *cl = exportedName(class_name); + Printv(parm_print, Getattr(p, "lname"), " ", cl, NULL); + Delete(cl); + } else { + if (pi > (receiver != NULL && base == NULL ? 1 : 0)) { + Printv(parm_print, ", ", NULL); + } + if (pi >= required_count) { + Printv(parm_print, "_swig_args ...interface{}", NULL); + break; + } + if (needs_wrapper) { + Printv(parm_print, Getattr(p, "lname"), " ", NULL); + } + String *tm = goType(p, Getattr(p, "type")); + Printv(parm_print, tm, NULL); + Delete(tm); + } + p = nextParm(p); + } + + Printv(parm_print, ")", NULL); + + // Write out the result type. + if (is_constructor) { + String *cl = exportedName(class_name); + Printv(parm_print, " ", cl, NULL); + Delete(cl); + } else { + if (SwigType_type(result) != T_VOID) { + String *tm = goType(n, result); + Printv(parm_print, " ", tm, NULL); + Delete(tm); + } + } + + Printv(f_go_wrappers, parm_print, NULL); + if (add_to_interface) { + Printv(interfaces, parm_print, "\n", NULL); + } + + // If this is a wrapper, we need to actually call the C function. + if (needs_wrapper) { + Printv(f_go_wrappers, " {\n", NULL); + + if (parm_count > required_count) { + Parm *p = parms; + int i; + for (i = 0; i < required_count; ++i) { + p = getParm(p); + p = nextParm(p); + } + for (; i < parm_count; ++i) { + p = getParm(p); + String *tm = goType(p, Getattr(p, "type")); + Printv(f_go_wrappers, "\tvar ", Getattr(p, "lname"), " ", tm, "\n", + NULL); + Printf(f_go_wrappers, "\tif len(_swig_args) > %d {\n", + i - required_count); + Printf(f_go_wrappers, "\t\t%s = _swig_args[%d].(%s)\n", + Getattr(p, "lname"), i - required_count, tm); + Printv(f_go_wrappers, "\t}\n", NULL); + Delete(tm); + p = nextParm(p); + } + } + + Printv(f_go_wrappers, "\t", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(f_go_wrappers, "return ", NULL); + } + + Printv(f_go_wrappers, wrapper_name, "(", NULL); + + if (parm_count > required_count) { + Printv(f_go_wrappers, "len(_swig_args)", NULL); + } + + if (base != NULL && receiver != NULL) { + if (parm_count > required_count) { + Printv(f_go_wrappers, ", ", NULL); + } + Printv(f_go_wrappers, "_swig_base", NULL); + } + + Parm *p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + if (i > 0 + || (base != NULL && receiver != NULL) + || parm_count > required_count) { + Printv(f_go_wrappers, ", ", 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 == NULL || base != NULL || is_constructor) + && goTypeIsInterface(p, Getattr(p, "type")))) { + Printv(f_go_wrappers, ".Swigcptr()", NULL); + } + + p = nextParm(p); + } + Printv(f_go_wrappers, ")\n", NULL); + Printv(f_go_wrappers, "}\n", NULL); + } else { + if (gccgo_flag) { + Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", + wname, "\")\n", NULL); + } + } + + Printv(f_go_wrappers, "\n", NULL); + + Delete(wrapper_name); + DelWrapper(dummy); + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * gcFunctionWrapper() + * + * This is used for 6g/8g, not for gccgo. Write out the function + * wrapper which will be compiled with 6c/8c. + * ---------------------------------------------------------------------- */ + + int gcFunctionWrapper(Node *n, String *name, String *go_name, + String *overname, String *wname, ParmList *parms, + SwigType *result, bool is_static, bool needs_wrapper) { + Wrapper *f = NewWrapper(); + + Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"", + soname, "\"\n", NULL); + Printv(f->def, "void (*", wname, ")(void*);\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 != NULL && !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 != NULL) { + Append(fn_name, overname); + } + } else { + fn_name = buildGoWrapperName(name, overname); + } + + // \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, "\tcgocall(", wname, ", &p);\n", NULL); + Printv(f->code, "}\n", NULL); + Printv(f->code, "\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. The + // length and capacity are always 4 bytes. + Append(orig, "(SWIG_PARM_SIZE + 8)"); + } else if (Strcmp(go, "float") == 0 || Strcmp(go, "float64") == 0) { + Append(orig, "8"); + } else if (Strcmp(go, "complex") == 0 || 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() + * + * This is used for 6g/8g, not for gccgo. Write out the function + * wrapper which will be compiled with gcc. If the base parameter + * is not NULL, this is calls the base class method rather than + * executing the SWIG wrapper code. + * ---------------------------------------------------------------------- */ + + int gccFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, + SwigType *result) { + Wrapper *f = NewWrapper(); + + Swig_save("gccFunctionWrapper", n, "parms", NULL); + + Parm *base_parm = NULL; + if (base != NULL && !isStatic(n)) { + SwigType *base_type = Copy(Getattr(class_node, "classtype")); + SwigType_add_pointer(base_type); + base_parm = NewParm(base_type, NewString("arg1"), n); + set_nextSibling(base_parm, parms); + parms = base_parm; + } + + emit_parameter_variables(parms, f); + emit_attach_parmmaps(parms, f); + int parm_count = emit_num_arguments(parms); + int required_count = emit_num_required(parms); + + emit_return_variable(n, result, f); + + // Start the function definition. + + Printv(f->def, + "#ifdef __cplusplus\n", + "extern \"C\"\n", + "#endif\n", + NULL); + + Printv(f->def, "void\n", wname, "(void *swig_v)\n", "{\n", NULL); + + // The single function parameter is a pointer to the real argument + // values. Define the structure that it points to. + + Printv(f->code, "\tstruct swigargs {\n", NULL); + + if (parm_count > required_count) { + Printv(f->code, "\t\tint _swig_optargc;\n", NULL); + } + + 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); + p = nextParm(p); + } + if (SwigType_type(result) != T_VOID) { + Printv(f->code, "\t\tint : 0;\n", NULL); + String *ln = NewString("result"); + String *ct = gcCTypeForGoValue(n, result, ln); + Delete(ln); + Printv(f->code, "\t\t", ct, ";\n", NULL); + Delete(ct); + } + 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. + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + + String *tm = Getattr(p, "tmap:in"); + if (tm == NULL) { + 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); + if (i < required_count) { + Printv(f->code, "\t", tm, "\n", NULL); + } else { + Printf(f->code, "\tif (swig_a->_swig_optargc > %d) {\n", + i - required_count); + Printv(f->code, "\t\t", tm, "\n", NULL); + Printv(f->code, "\t}\n", NULL); + } + } + p = nextParm(p); + } + + Printv(f->code, "\n", NULL); + + // Do the real work of the function. + + checkConstraints(parms, f); + + emitGoAction(n, base, parms, result, f); + + argout(parms, f); + + cleanupFunction(n, f, parms); + + Printv(f->code, "}\n", NULL); + + Wrapper_print(f, f_c_wrappers); + + Swig_restore(n); + + DelWrapper(f); + if (base_parm != NULL) { + Delete(base_parm); + } + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * gccgoFunctionWrapper() + * + * This is used for gccgo, not 6g/8g. Write out the function + * wrapper which will be compiled with gcc. If the base parameter + * is not NULL, this is calls the base class method rather than + * executing the SWIG wrapper code. + * ---------------------------------------------------------------------- */ + + int gccgoFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, + SwigType *result) { + Wrapper *f = NewWrapper(); + + Swig_save("gccgoFunctionWrapper", n, "parms", NULL); + + Parm *base_parm = NULL; + if (base != NULL && !isStatic(n)) { + SwigType *base_type = Copy(Getattr(class_node, "classtype")); + SwigType_add_pointer(base_type); + base_parm = NewParm(base_type, NewString("arg1"), n); + set_nextSibling(base_parm, parms); + parms = base_parm; + } + + emit_parameter_variables(parms, f); + emit_attach_parmmaps(parms, f); + int parm_count = emit_num_arguments(parms); + int required_count = emit_num_required(parms); + + emit_return_variable(n, result, f); + + // Start the function definition. + + Printv(f->def, + "#ifdef __cplusplus\n", + "extern \"C\"\n", + "#endif\n", + NULL); + + String *fnname = NewString(""); + Printv(fnname, go_prefix, "_", wname, "(", NULL); + + if (parm_count > required_count) { + Printv(fnname, "int _swig_optargc", NULL); + } + + Parm *p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + SwigType *pt = Getattr(p, "type"); + String *pn = NewString("g"); + Append(pn, Getattr(p, "lname")); + String *ct = gccgoCTypeForGoValue(p, pt, pn); + if (i > 0 || parm_count > required_count) { + Printv(fnname, ", ", NULL); + } + Printv(fnname, ct, NULL); + Delete(ct); + Delete(pn); + p = nextParm(p); + } + + Printv(fnname, ")", NULL); + + if (SwigType_type(result) == T_VOID) { + Printv(f->def, "void ", fnname, NULL); + } else { + String *ct = gccgoCTypeForGoValue(n, result, fnname); + Printv(f->def, ct, NULL); + Delete(ct); + } + + Printv(f->def, " {\n", NULL); + + Delete(fnname); + + if (SwigType_type(result) != T_VOID) { + String *ln = NewString("go_result"); + String *ct = gccgoCTypeForGoValue(n, result, ln); + Wrapper_add_local(f, "go_result", ct); + Delete(ct); + Delete(ln); + } + + // Copy the parameters into the variables which hold their values, + // applying appropriate transformations. + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + + String *tm = Getattr(p, "tmap:in"); + if (tm == NULL) { + 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 *pn = NewString("g"); + Append(pn, ln); + Replaceall(tm, "$input", pn); + Setattr(p, "emit:input", pn); + if (i < required_count) { + Printv(f->code, " ", tm, "\n", NULL); + } else { + Printf(f->code, " if (_swig_optargc > %d) {\n", i - required_count); + Printv(f->code, " ", tm, "\n", NULL); + Printv(f->code, " }\n", NULL); + } + } + + p = nextParm(p); + } + + Printv(f->code, "\n", NULL); + + // Do the real work of the function. + + checkConstraints(parms, f); + + emitGoAction(n, base, parms, result, f); + + argout(parms, f); + + cleanupFunction(n, f, parms); + + if (SwigType_type(result) != T_VOID) { + Printv(f->code, " return go_result;\n", NULL); + } + + Printv(f->code, "}\n", NULL); + + Wrapper_print(f, f_c_wrappers); + + Swig_restore(n); + + DelWrapper(f); + if (base_parm != NULL) { + Delete(base_parm); + } + + return SWIG_OK; + } + + /* ----------------------------------------------------------------------- + * checkConstraints() + * + * Check parameter constraints if any. This is used for the C/C++ + * function. This assumes that each parameter has an "emit:input" + * property with the name to use to refer to that parameter. + * ----------------------------------------------------------------------- */ + + void checkConstraints(ParmList *parms, Wrapper *f) { + Parm *p = parms; + while (p != NULL) { + String *tm = Getattr(p, "tmap:check"); + if (tm == NULL) { + p = nextSibling(p); + } else { + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(f->code, tm, "\n\n", NULL); + p = Getattr(p, "tmap:check:next"); + } + } + } + + /* ----------------------------------------------------------------------- + * getGoAction() + * + * Get the action of the function. This is used for C/C++ function. + * ----------------------------------------------------------------------- */ + + void emitGoAction(Node *n, List *base, ParmList *parms, SwigType *result, + Wrapper *f) { + String *actioncode; + if (base == NULL || isStatic(n)) { + Swig_director_emit_dynamic_cast(n, f); + actioncode = emit_action(n); + } else { + // Call the base class method. + actioncode = NewString(""); + + String *current = NewString(""); + if (!gccgo_flag) { + Printv(current, "swig_a->", NULL); + } + Printv(current, Getattr(parms, "lname"), NULL); + + String *last = NULL; + int vc = 0; + for (Iterator bi = First(base); bi.item != NULL; bi = Next(bi)) { + Printf(actioncode, " %s *swig_b%d = (%s *)%s;\n", bi.item, vc, + bi.item, current); + Delete(current); + current = NewString(""); + Printf(current, "swig_b%d", vc); + ++vc; + last = bi.item; + } + + String *code = Copy(Getattr(n, "wrap:action")); + Replaceall(code, Getattr(parms, "lname"), current); + Printv(actioncode, code, "\n", NULL); + } + + Swig_save("emitGoAction", n, "type", "tmap:out", NULL); + + Setattr(n, "type", result); + + String *tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode); + if (tm == NULL) { + 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) { + Replaceall(tm, "$result", "swig_a->result"); + } else { + Replaceall(tm, "$result", "go_result"); + } + if (GetFlag(n, "feature:new")) { + Replaceall(tm, "$owner", "1"); + } else { + Replaceall(tm, "$owner", "0"); + } + Printv(f->code, tm, "\n", NULL); + Delete(tm); + } + + Swig_restore(n); + } + + /* ----------------------------------------------------------------------- + * argout() + * + * Handle argument output code if any. This is used for the C/C++ + * function. This assumes that each parameter has an "emit:input" + * property with the name to use to refer to that parameter. + * ----------------------------------------------------------------------- */ + + void argout(ParmList *parms, Wrapper *f) { + Parm *p = parms; + while (p != NULL) { + String *tm = Getattr(p, "tmap:argout"); + if (tm == NULL) { + p = nextSibling(p); + } else { + Replaceall(tm, "$result", "result"); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(f->code, tm, "\n", NULL); + p = Getattr(p, "tmap:argout:next"); + } + } + } + + /* ----------------------------------------------------------------------- + * freearg() + * + * Handle argument cleanup code if any. This is used for the C/C++ + * function. This assumes that each parameter has an "emit:input" + * property with the name to use to refer to that parameter. + * ----------------------------------------------------------------------- */ + + String *freearg(ParmList *parms) { + String *ret = NewString(""); + Parm *p = parms; + while (p != NULL) { + String *tm = Getattr(p, "tmap:freearg"); + if (tm == NULL) { + p = nextSibling(p); + } else { + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(ret, tm, "\n", NULL); + p = Getattr(p, "tmap:freearg:next"); + } + } + return ret; + } + + /* ----------------------------------------------------------------------- + * cleanupFunction() + * + * Final function cleanup code. + * ----------------------------------------------------------------------- */ + + void cleanupFunction(Node *n, Wrapper *f, ParmList *parms) { + String *cleanup = freearg(parms); + Printv(f->code, cleanup, NULL); + + if (GetFlag(n, "feature:new")) { + String *tm = Swig_typemap_lookup("newfree", n, "result", 0); + if (tm != NULL) { + Replaceall(tm, "$source", "result"); + Printv(f->code, tm, "\n", NULL); + Delete(tm); + } + } + + Replaceall(f->code, "$cleanup", cleanup); + Delete(cleanup); + + Replaceall(f->code, "$symname", Getattr(n, "sym:name")); + } + + /* ----------------------------------------------------------------------- + * variableHandler() + * + * This exists just to set the making_variable_wrappers flag. + * ----------------------------------------------------------------------- */ + + virtual int variableHandler(Node *n) { + assert(!making_variable_wrappers); + making_variable_wrappers = true; + int r = Language::variableHandler(n); + making_variable_wrappers = false; + return r; + } + + /* ----------------------------------------------------------------------- + * constantWrapper() + * + * Product a const declaration. + * ------------------------------------------------------------------------ */ + + virtual int constantWrapper(Node *n) { + SwigType *type = Getattr(n, "type"); + + if (!SwigType_issimple(type) && SwigType_type(type) != T_STRING) { + return goComplexConstant(n, type); + } + + if (Getattr(n, "storage") != NULL + && Strcmp(Getattr(n, "storage"), "static") == 0) { + return goComplexConstant(n, type); + } + + String *go_name = buildGoName(Getattr(n, "sym:name"), false, false); + + if (!addSymbol(go_name, n)) { + Delete(go_name); + return SWIG_ERROR; + } + + String *tm = goType(n, type); + String *value = Getattr(n, "value"); + + String *copy = NULL; + if (SwigType_type(type) == T_BOOL) { + if (Cmp(value, "true") != 0 && Cmp(value, "false") != 0) { + return goComplexConstant(n, type); + } + } else if (SwigType_type(type) == T_STRING + || SwigType_type(type) == T_CHAR) { + // Backslash sequences are somewhat different in Go and C/C++. + if (Strchr(value, '\\') != NULL) { + return goComplexConstant(n, type); + } + } else { + // Accept a 0x prefix, and strip combinations of u and l + // suffixes. Otherwise accept digits, decimal point, and + // exponentiation. Treat anything else as too complicated to + // handle as a Go constant. + char *p = Char(value); + int len = strlen(p); + bool need_copy = false; + while (len > 0) { + char c = p[len - 1]; + if (c != 'l' && c != 'L' && c != 'u' && c != 'U') { + break; + } + --len; + need_copy = true; + } + bool is_hex = false; + int i = 0; + if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { + i = 2; + is_hex = true; + } + for (; i < len; ++i) { + switch (p[i]) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + break; + case 'a': case 'b': case 'c': case 'd': case 'f': + case 'A': case 'B': case 'C': case 'D': case 'F': + if (!is_hex) { + return goComplexConstant(n, type); + } + break; + case '.': case 'e': case 'E': case '+': case '-': + break; + default: + return goComplexConstant(n, type); + } + } + if (need_copy) { + copy = Copy(value); + Replaceall(copy, p + len, ""); + value = copy; + } + } + + Printv(f_go_wrappers, "const ", go_name, " ", tm, " = ", NULL); + if (SwigType_type(type) == T_STRING) { + Printv(f_go_wrappers, "\"", value, "\"", NULL); + } else if (SwigType_type(type) == T_CHAR) { + Printv(f_go_wrappers, "'", value, "'", NULL); + } else { + Printv(f_go_wrappers, value, NULL); + } + + Printv(f_go_wrappers, "\n", NULL); + + Delete(tm); + Delete(go_name); + if (copy != NULL) { + Delete(copy); + } + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * enumDeclaration() + * + * A C++ enum type turns into a Named go int type. + * ---------------------------------------------------------------------- */ + + virtual int enumDeclaration(Node *n) { + String *name = goEnumName(n); + if (Strcmp(name, "int") != 0) { + if (!ImportMode || imported_package == NULL) { + Printv(f_go_wrappers, "type ", name, " int\n", NULL); + } else { + String *nw = NewString(""); + Printv(nw, imported_package, ".", name, NULL); + Setattr(n, "go:enumname", nw); + } + } + Delete(name); + + return Language::enumDeclaration(n); + } + + /* ----------------------------------------------------------------------- + * enumvalueDeclaration() + * + * Declare a single value of an enum type. We fetch the value by + * calling a C/C++ function. + * ------------------------------------------------------------------------ */ + + virtual int enumvalueDeclaration(Node *n) { + if (!is_public(n)) { + return SWIG_OK; + } + if (Getattr(parentNode(n), "unnamed") != NULL) { + Setattr(n, "type", NewString("int")); + } else { + Setattr(n, "type", Getattr(parentNode(n), "enumtype")); + } + return goComplexConstant(n, Getattr(n, "type")); + } + + /* ----------------------------------------------------------------------- + * goComplexConstant() + * + * Handle a const declaration for something which is not a Go constant. + * ------------------------------------------------------------------------ */ + + int goComplexConstant(Node *n, SwigType *type) { + String *get = NewString(""); + Printv(get, "result = ", NULL); + + char quote; + if (Getattr(n, "wrappedasconstant") != NULL) { + quote = '\0'; + } else if (SwigType_type(type) == T_CHAR) { + quote = '\''; + } else if (SwigType_type(type) == T_STRING) { + quote = '"'; + } else { + quote = '\0'; + } + + if (quote != '\0') { + Printf(get, "%c", quote); + } + + Printv(get, Getattr(n, "value"), NULL); + + if (quote != '\0') { + Printf(get, "%c", quote); + } + + Printv(get, ";\n", NULL); + Setattr(n, "wrap:action", get); + + String* symname = Getattr(n, "sym:name"); + if (symname == NULL) { + symname = Getattr(n, "name"); + } + + String *sname = Copy(symname); + if (class_name != NULL) { + Append(sname, "_"); + Append(sname, class_name); + } + + String *go_name = NewString("_swig_get"); + if (class_name != NULL) { + Append(go_name, class_name); + Append(go_name, "_"); + } + Append(go_name, sname); + + String *wname = Swig_name_wrapper(sname); + Setattr(n, "wrap:name", wname); + + int r = makeWrappers(n, sname, go_name, NULL, wname, NULL, NULL, type, + true); + + if (r != SWIG_OK) { + return r; + } + + String *varname = buildGoName(symname, true, false); + String *t = goType(n, type); + Printv(f_go_wrappers, "var ", varname, " ", t, " = ", go_name, "()\n", + NULL); + + Delete(varname); + Delete(t); + Delete(go_name); + Delete(sname); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * classHandler() + * + * For a C++ class, in Go we generate both a struct and an + * interface. The interface will declare all the class public + * methods. We will define all the methods on the struct, so that + * the struct meets the interface. We then expect users of the + * class to use the interface. + * ------------------------------------------------------------ */ + + virtual int classHandler(Node *n) { + class_node = n; + + List *baselist = Getattr(n, "bases"); + bool has_base_classes = baselist != NULL && Len(baselist) > 0; + + String *name = Getattr(n, "sym:name"); + + String *go_name = exportedName(name); + + String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true); + + class_name = name; + class_receiver = go_type_name; + class_methods = NewHash(); + + int isdir = GetFlag(n, "feature:director"); + int isnodir = GetFlag(n, "feature:nodirector"); + bool is_director = isdir && !isnodir; + + Printv(f_go_wrappers, "type ", go_type_name, " uintptr\n\n", NULL); + + // A method to return the pointer to the C++ class. This is used + // by generated code to convert between the interface and the C++ + // value. + Printv(f_go_wrappers, "func (p ", go_type_name, ") Swigcptr() uintptr {\n", + NULL); + Printv(f_go_wrappers, "\treturn (uintptr)(p)\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + // A method used as a marker for the class, to avoid invalid + // interface conversions when using multiple inheritance. + Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigIs", go_name, + "() {\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + if (is_director) { + // Return the interface passed to the NewDirector function. + Printv(f_go_wrappers, "func (p ", go_type_name, + ") DirectorInterface() interface{} {\n", NULL); + Printv(f_go_wrappers, "\treturn nil\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + } + + // We have seen a definition for this type. + Setattr(defined_types, go_name, go_name); + Setattr(defined_types, go_type_name, go_type_name); + + interfaces = NewString(""); + + int r = Language::classHandler(n); + if (r != SWIG_OK) { + return r; + } + + if (has_base_classes) { + // For each method defined in a base class but not defined in + // this class, we need to define the method in this class. We + // can't use anonymous field inheritance because it works + // differently in Go and in C++. + + Hash *local = NewHash(); + for (Node *ni = Getattr(n, "firstChild"); + ni != NULL; + ni = nextSibling(ni)) { + + if (!is_public(ni)) { + continue; + } + + String *type = Getattr(ni, "nodeType"); + if (Cmp(type, "constructor") == 0 || Cmp(type, "destructor") == 0) { + continue; + } + + String *cname = Getattr(ni, "sym:name"); + if (cname == NULL) { + cname = Getattr(ni, "name"); + } + if (cname != NULL) { + Setattr(local, cname, NewString("")); + } + } + + for (Iterator b = First(baselist); b.item != NULL; b = Next(b)) { + List *bases = NewList(); + Append(bases, Getattr(b.item, "classtype")); + int r = addBase(n, b.item, bases, local); + if (r != SWIG_OK) { + return r; + } + Delete(bases); + } + + Delete(local); + + Hash *parents = NewHash(); + addFirstBaseInterface(n, parents, baselist); + int r = addExtraBaseInterfaces(n, parents, baselist); + Delete(parents); + if (r != SWIG_OK) { + return r; + } + } + + Printv(f_go_wrappers, "type ", go_name, " interface {\n", NULL); + Printv(f_go_wrappers, "\tSwigcptr() uintptr\n", NULL); + Printv(f_go_wrappers, "\tSwigIs", go_name, "()\n", NULL); + + if (is_director) { + Printv(f_go_wrappers, "\tDirectorInterface() interface{}\n", NULL); + } + + Append(f_go_wrappers, interfaces); + Printf(f_go_wrappers, "}\n\n", NULL); + Delete(interfaces); + + interfaces = NULL; + class_name = NULL; + class_receiver = NULL; + class_node = NULL; + Delete(class_methods); + class_methods = NULL; + + Delete(go_type_name); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * addBase() + * + * Implement methods and members defined in a parent class for a + * child class. + * ------------------------------------------------------------ */ + + int addBase(Node *n, Node *base, List *bases, Hash *local) { + if (GetFlag(base, "feature:ignore")) { + return SWIG_OK; + } + + for (Node *ni = Getattr(base, "firstChild"); + ni != NULL; + ni = nextSibling(ni)) { + + if (GetFlag(ni, "feature:ignore")) { + continue; + } + + if (!is_public(ni)) { + continue; + } + + String *type = Getattr(ni, "nodeType"); + if (Strcmp(type, "constructor") == 0 + || Strcmp(type, "destructor") == 0 + || Strcmp(type, "enum") == 0 + || Strcmp(type, "using") == 0) { + continue; + } + String *storage = Getattr(ni, "storage"); + if (Strcmp(storage, "typedef") == 0 || Strcmp(storage, "friend") == 0) { + continue; + } + + String *mname = Getattr(ni, "sym:name"); + if (mname == NULL) { + continue; + } + + String *lname = Getattr(ni, "name"); + if (Getattr(class_methods, lname) != NULL) { + continue; + } + if (Getattr(local, lname) != NULL) { + continue; + } + Setattr(local, lname, NewString("")); + + String *ty = NewString(Getattr(ni, "type")); + SwigType_push(ty, Getattr(ni, "decl")); + String *fullty = SwigType_typedef_resolve_all(ty); + bool is_function = SwigType_isfunction(fullty); + Delete(ty); + Delete(fullty); + + if (is_function) { + int r = goBaseMethod(n, bases, ni); + if (r != SWIG_OK) { + return r; + } + + if (Getattr(ni, "sym:overloaded") != NULL) { + for (Node *on = Getattr(ni, "sym:nextSibling"); + on != NULL; + on = Getattr(on, "sym:nextSibling")) { + r = goBaseMethod(n, bases, on); + if (r != SWIG_OK) { + return r; + } + } + + String *receiver = class_receiver; + bool is_static = isStatic(ni); + if (is_static) { + receiver = NULL; + } + String *go_name = buildGoName(Getattr(ni, "sym:name"), is_static, + false); + r = makeDispatchFunction(ni, go_name, receiver, is_static, NULL, + false); + Delete(go_name); + if (r != SWIG_OK) { + return r; + } + } + } else { + int r = goBaseVariable(n, bases, ni); + if (r != SWIG_OK) { + return r; + } + } + } + + List *baselist = Getattr(base, "bases"); + if (baselist != NULL && Len(baselist) > 0) { + for (Iterator b = First(baselist); b.item != NULL; b = Next(b)) { + List *nb = Copy(bases); + Append(nb, Getattr(b.item, "classtype")); + int r = addBase(n, b.item, nb, local); + Delete(nb); + if (r != SWIG_OK) { + return r; + } + } + } + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * goBaseMethod() + * + * Implement a method defined in a parent class for a child class. + * ------------------------------------------------------------ */ + + int goBaseMethod(Node *method_class, List *bases, Node *method) { + String *symname = Getattr(method, "sym:name"); + if (!validIdentifier(symname)) { + return SWIG_OK; + } + + String *name = NewString(""); + Printv(name, Getattr(method_class, "sym:name"), "_", symname, NULL); + + bool is_static = isStatic(method); + + String *go_name = buildGoName(name, is_static, false); + + String *overname = NULL; + if (Getattr(method, "sym:overloaded")) { + overname = Getattr(method, "sym:overname"); + } + String *wname = Swig_name_wrapper(name); + if (overname != NULL) { + Append(wname, overname); + } + + String *result = NewString(Getattr(method, "type")); + SwigType_push(result, Getattr(method, "decl")); + if (SwigType_isqualifier(result)) { + Delete(SwigType_pop(result)); + } + Delete(SwigType_pop_function(result)); + + // If the base method is imported, wrap:action may not be set. + Swig_save("goBaseMethod", method, "wrap:action", "parms", NULL); + if (Getattr(method, "wrap:action") == NULL) { + if (!is_static) { + Swig_MethodToFunction(method, getNSpace(), getClassType(), + (Getattr(method, "template") != NULL + ? SmartPointer + : Extend | SmartPointer), + NULL, false); + // Remove any self parameter that was just added. + ParmList *parms = Getattr(method, "parms"); + if (parms != NULL && Getattr(parms, "self") != NULL) { + parms = CopyParmList(nextSibling(parms)); + Setattr(method, "parms", parms); + } + } else { + String *call = Swig_cfunction_call(Getattr(method, "name"), + Getattr(method, "parms")); + Setattr(method, "wrap:action", Swig_cresult(Getattr(method, "type"), + "result", call)); + } + } + + int r = makeWrappers(method, name, go_name, overname, wname, bases, + Getattr(method, "parms"), result, is_static); + + Swig_restore(method); + + Delete(result); + Delete(go_name); + Delete(name); + + return r; + } + + /* ------------------------------------------------------------ + * goBaseVariable() + * + * Add accessors for a member variable defined in a parent class for + * a child class. + * ------------------------------------------------------------ */ + + int goBaseVariable(Node *var_class, List *bases, Node *var) { + if (isStatic(var)) { + return SWIG_OK; + } + + String *var_name = buildGoName(Getattr(var, "sym:name"), false, false); + + Swig_save("goBaseVariable", var, "type", "wrap:action", NULL); + + // For a pointer type we apparently have to wrap in the decl. + SwigType *var_type = NewString(Getattr(var, "type")); + SwigType_push(var_type, Getattr(var, "decl")); + Setattr(var, "type", var_type); + + SwigType *vt = Copy(var_type); + if (SwigType_isclass(vt)) { + SwigType_add_pointer(vt); + } + + int flags = Extend | SmartPointer | use_naturalvar_mode(var); + if (is_non_virtual_protected_access(var)) { + flags |= CWRAP_ALL_PROTECTED_ACCESS; + } + + String *mname = Swig_name_member(getNSpace(), + Getattr(var_class, "sym:name"), + var_name); + + if (is_assignable(var)) { + for (Iterator ki = First(var); ki.key != NULL; ki = Next(ki)) { + if (Strncmp(ki.key, "tmap:", 5) == 0) { + Delattr(var, ki.key); + } + } + Swig_save("goBaseVariableSet", var, "name", "sym:name", "type", NULL); + + String *mname_set = NewString("Set"); + Append(mname_set, mname); + + String *go_name = NewString("Set"); + Append(go_name, var_name); + + Swig_MembersetToFunction(var, class_name, flags); + + String *wname = Swig_name_wrapper(mname_set); + ParmList *parms = NewParm(vt, var_name, var); + String *result = NewString("void"); + int r = makeWrappers(var, mname_set, go_name, NULL, wname, bases, parms, + result, false); + if (r != SWIG_OK) { + return r; + } + Delete(wname); + Delete(parms); + Delete(result); + Delete(go_name); + Delete(mname_set); + + Swig_restore(var); + for (Iterator ki = First(var); ki.key != NULL; ki = Next(ki)) { + if (Strncmp(ki.key, "tmap:", 5) == 0) { + Delattr(var, ki.key); + } + } + } + + Swig_MembergetToFunction(var, class_name, flags); + + String *mname_get = NewString("Get"); + Append(mname_get, mname); + + String *go_name = NewString("Get"); + Append(go_name, var_name); + + String *wname = Swig_name_wrapper(mname_get); + + int r = makeWrappers(var, mname_get, go_name, NULL, wname, bases, NULL, + vt, false); + if (r != SWIG_OK) { + return r; + } + + Delete(wname); + Delete(mname_get); + Delete(go_name); + Delete(mname); + Delete(var_name); + Delete(var_type); + Delete(vt); + + Swig_restore(var); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * addFirstBaseInterface() + * + * When a C++ class uses multiple inheritance, we can use the C++ + * pointer for the first base class but not for any subsequent base + * classes. However, the Go interface will match the interface for + * all the base classes. To avoid accidentally treating a class as + * a pointer to a base class other than the first one, we use an + * isClassname method. This function adds those methods as + * required. + * + * For convenience when using multiple inheritance, we also add + * functions to retrieve the base class pointers. + * ------------------------------------------------------------ */ + + void addFirstBaseInterface(Node *n, Hash *parents, List *bases) { + if (bases == NULL || Len(bases) == 0) { + return; + } + Iterator b = First(bases); + if (!GetFlag(b.item, "feature:ignore")) { + String *go_name = buildGoName(Getattr(n, "sym:name"), false, false); + String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true); + String *go_base_name = exportedName(Getattr(b.item, "sym:name")); + String *go_base_type = goType(n, Getattr(b.item, "classtypeobj")); + String *go_base_type_name = goCPointerType(Getattr(b.item, + "classtypeobj"), + true); + + Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigIs", go_base_name, + "() {\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + Printv(interfaces, "\tSwigIs", go_base_name, "()\n", NULL); + + Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", go_base_name, + "() ", go_base_type, " {\n", NULL); + Printv(f_go_wrappers, "\treturn ", go_base_type_name, + "(p.Swigcptr())\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + Printv(interfaces, "\tSwigGet", go_base_name, "() ", go_base_type, "\n", + NULL); + + Setattr(parents, go_base_name, NewString("")); + + Delete(go_name); + Delete(go_type_name); + Delete(go_base_type); + Delete(go_base_type_name); + } + + addFirstBaseInterface(n, parents, Getattr(b.item, "bases")); + } + + /* ------------------------------------------------------------ + * addExtraBaseInterfaces() + * + * Add functions to retrieve the base class pointers for all base + * classes other than the first. + * ------------------------------------------------------------ */ + + int addExtraBaseInterfaces(Node *n, Hash *parents, List *bases) { + Iterator b = First(bases); + + Node *fb = b.item; + + for (b = Next(b); b.item != NULL; b = Next(b)) { + if (GetFlag(b.item, "feature:ignore")) { + continue; + } + + String *go_base_name = exportedName(Getattr(b.item, "sym:name")); + + Swig_save("addExtraBaseInterface", n, "wrap:action", "wrap:name", + "wrap:parms", NULL); + + SwigType *type = Copy(Getattr(n, "classtypeobj")); + SwigType_add_pointer(type); + Parm *parm = NewParm(type, "self", n); + Setattr(n, "wrap:parms", parm); + + String *pn = Swig_cparm_name(parm, 0); + String *action = NewString(""); + Printv(action, "result = (", Getattr(b.item, "classtype"), "*)", pn, + ";", NULL); + Delete(pn); + + Setattr(n, "wrap:action", action); + + String *name = Copy(class_name); + Append(name, "_SwigGet"); + Append(name, go_base_name); + + String *go_name = NewString("SwigGet"); + String *c1 = exportedName(go_base_name); + Append(go_name, c1); + Delete(c1); + + String *wname = Swig_name_wrapper(name); + Setattr(n, "wrap:name", wname); + + SwigType *result = Copy(Getattr(b.item, "classtypeobj")); + SwigType_add_pointer(result); + + int r = makeWrappers(n, name, go_name, NULL, wname, NULL, parm, result, + false); + if (r != SWIG_OK) { + return r; + } + + Swig_restore(n); + + Setattr(parents, go_base_name, NewString("")); + + Delete(go_name); + Delete(type); + Delete(parm); + Delete(action); + Delete(result); + + String *ns = NewString(""); + addParentExtraBaseInterfaces(n, parents, b.item, false, ns); + Delete(ns); + } + + if (!GetFlag(fb, "feature:ignore")) { + String *ns = NewString(""); + addParentExtraBaseInterfaces(n, parents, fb, true, ns); + Delete(ns); + } + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * addParentExtraBaseInterfaces() + * + * Add functions to retrieve the base class pointers for all base + * classes of parents other than the first base class at each level. + * ------------------------------------------------------------ */ + + void addParentExtraBaseInterfaces(Node *n, Hash *parents, Node *base, + bool is_base_first, String *sofar) { + List *baselist = Getattr(base, "bases"); + if (baselist == NULL || Len(baselist) == 0) { + return; + } + + String *go_this_base_name = exportedName(Getattr(base, "sym:name")); + + String *sf = NewString(""); + Printv(sf, sofar, ".SwigGet", go_this_base_name, "()", NULL); + + Iterator b = First(baselist); + + if (is_base_first) { + if (!GetFlag(b.item, "feature:ignore")) { + addParentExtraBaseInterfaces(n, parents, b.item, true, sf); + } + + b = Next(b); + if (b.item == NULL) { + return; + } + } + + String *go_name = buildGoName(Getattr(n, "sym:name"), false, false); + String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true); + + for (; b.item != NULL; b = Next(b)) { + if (GetFlag(b.item, "feature:ignore")) { + continue; + } + + String *go_base_name = exportedName(Getattr(b.item, "sym:name")); + + if (Getattr(parents, go_base_name) == NULL) { + Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", + go_base_name, "() ", go_base_name, " {\n", NULL); + Printv(f_go_wrappers, "\treturn p", sf, ".SwigGet", go_base_name, + "()\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + Printv(interfaces, "\tSwigGet", go_base_name, "() ", go_base_name, "\n", + NULL); + + addParentExtraBaseInterfaces(n, parents, b.item, false, sf); + + Setattr(parents, go_base_name, NewString("")); + } + } + + Delete(go_name); + Delete(go_type_name); + Delete(go_this_base_name); + Delete(sf); + } + + /* ------------------------------------------------------------ + * classDirectorInit + * + * Add support for a director class. + * + * Virtual inheritance is different in Go and C++. We implement + * director classes by defining a new function in Go, + * NewDirectorClassname, which takes a empty interface value and + * creates an instance of a new child class. The new child class + * refers all methods back to Go. The Go code checks whether the + * value passed to NewDirectorClassname implements that method; if + * it does, it calls it, otherwise it calls back into C++. + * ------------------------------------------------------------ */ + + int classDirectorInit(Node *n) { + // Because we use a different function to handle inheritance in + // Go, ordinary creations of the object should not create a + // director object. + Delete(director_ctor_code); + director_ctor_code = NewString("$nondirector_new"); + + class_node = n; + + String *name = Getattr(n, "sym:name"); + + assert(class_name == NULL); + class_name = name; + + String *go_name = exportedName(name); + + String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true); + + assert(class_receiver == NULL); + class_receiver = go_type_name; + + String *director_struct_name = NewString("_swig_Director"); + Append(director_struct_name, go_name); + + String* cxx_director_name = NewString("SwigDirector_"); + Append(cxx_director_name, name); + + // The Go type of the director class. + Printv(f_go_wrappers, "type ", director_struct_name, " struct {\n", NULL); + Printv(f_go_wrappers, "\t", go_type_name, "\n", NULL); + Printv(f_go_wrappers, "\tv interface{}\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + Printv(f_go_wrappers, "func (p *", director_struct_name, + ") Swigcptr() uintptr {\n", NULL); + Printv(f_go_wrappers, "\treturn p.", go_type_name, ".Swigcptr()\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + Printv(f_go_wrappers, "func (p *", director_struct_name, ") SwigIs", + go_name, "() {\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + Printv(f_go_wrappers, "func (p *", director_struct_name, + ") DirectorInterface() interface{} {\n", NULL); + Printv(f_go_wrappers, "\treturn p.v\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + // Start defining the director class. + Printv(f_c_directors_h, "class ", cxx_director_name, " : public ", + Getattr(n, "classtype"), "\n", NULL); + Printv(f_c_directors_h, "{\n", NULL); + Printv(f_c_directors_h, " public:\n", NULL); + + Delete(director_struct_name); + Delete(cxx_director_name); + + class_methods = NewHash(); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * classDirectorConstructor + * + * Emit a constructor for a director class. + * ------------------------------------------------------------ */ + + int classDirectorConstructor(Node *n) { + bool is_ignored = GetFlag(n, "feature:ignore"); + + String *name = Getattr(n, "sym:name"); + if (name == NULL) { + assert(is_ignored); + name = Getattr(n, "name"); + } + + String *overname = NULL; + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); + } + + String *go_name = exportedName(name); + + ParmList *parms = Getattr(n, "parms"); + Setattr(n, "wrap:parms", parms); + + String *cn = exportedName(Getattr(parentNode(n), "sym:name")); + + String *go_type_name = goCPointerType(Getattr(parentNode(n), + "classtypeobj"), + true); + + String *director_struct_name = NewString("_swig_Director"); + Append(director_struct_name, cn); + + String *fn_name = NewString("_swig_NewDirector"); + Append(fn_name, cn); + Append(fn_name, go_name); + + if (overname == NULL && !is_ignored) { + if (!addSymbol(fn_name, n)) { + return SWIG_ERROR; + } + } + + String *wname = Swig_name_wrapper(fn_name); + + if (overname != NULL) { + Append(wname, overname); + } + Setattr(n, "wrap:name", wname); + + bool is_static = isStatic(n); + + Wrapper *dummy = NewWrapper(); + emit_attach_parmmaps(parms, dummy); + DelWrapper(dummy); + + Swig_typemap_attach_parms("go", parms, NULL); + int parm_count = emit_num_arguments(parms); + + String *func_name = NewString("NewDirector"); + Append(func_name, go_name); + + String *func_with_over_name = Copy(func_name); + if (overname != NULL) { + Append(func_with_over_name, overname); + } + + SwigType *first_type = NewString("void"); + SwigType_add_pointer(first_type); + Parm *first_parm = NewParm(first_type, "swig_p", n); + set_nextSibling(first_parm, parms); + Setattr(first_parm, "lname", "p"); + + Parm *p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + Swig_cparm_name(p, i); + p = nextParm(p); + } + + if (!is_ignored) { + // Declare the C++ wrapper. + Printv(f_go_wrappers, "func ", fn_name, NULL); + if (overname != NULL) { + Printv(f_go_wrappers, overname, NULL); + } + Printv(f_go_wrappers, "(*", 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); + Delete(tm); + p = nextParm(p); + } + + Printv(f_go_wrappers, ") ", go_type_name, NULL); + + if (gccgo_flag) { + Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", wname, "\")", + NULL); + } + + Printv(f_go_wrappers, "\n\n", NULL); + + Printv(f_go_wrappers, "func ", func_with_over_name, "(v interface{}", + NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + // Set the lname parameter. + Printv(f_go_wrappers, ", ", Getattr(p, "lname"), " ", NULL); + String *tm = goType(p, Getattr(p, "type")); + Printv(f_go_wrappers, tm, NULL); + Delete(tm); + p = nextParm(p); + } + + Printv(f_go_wrappers, ") ", cn, " {\n", NULL); + + Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", + NULL); + Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL); + if (overname != NULL) { + Printv(f_go_wrappers, overname, NULL); + } + Printv(f_go_wrappers, "(p", NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + Printv(f_go_wrappers, ", ", Getattr(p, "lname"), NULL); + p = nextParm(p); + } + + Printv(f_go_wrappers, ")\n", NULL); + Printv(f_go_wrappers, "\treturn p\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + SwigType *result = Copy(Getattr(parentNode(n), "classtypeobj")); + SwigType_add_pointer(result); + + Swig_save("classDirectorConstructor", n, "wrap:name", "wrap:action", + NULL); + + Setattr(n, "wrap:name", Swig_name_wrapper(name)); + + String *action = NewString(""); + Printv(action, "result = new SwigDirector_", class_name, "(", NULL); + String *pname = Swig_cparm_name(NULL, 0); + Printv(action, pname, NULL); + Delete(pname); + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + String *pname = Swig_cparm_name(NULL, i + 1); + Printv(action, ", ", NULL); + if (SwigType_isreference(Getattr(p, "type"))) { + Printv(action, "*", NULL); + } + Printv(action, pname, NULL); + Delete(pname); + p = nextParm(p); + } + Printv(action, ");", NULL); + Setattr(n, "wrap:action", action); + + if (!gccgo_flag) { + int r = gcFunctionWrapper(n, fn_name, fn_name, overname, wname, + first_parm, result, is_static, false); + if (r != SWIG_OK) { + return r; + } + r = gccFunctionWrapper(n, NULL, wname, first_parm, result); + if (r != SWIG_OK) { + return r; + } + } else { + int r = gccgoFunctionWrapper(n, NULL, wname, first_parm, result); + if (r != SWIG_OK) { + return r; + } + } + + Swig_restore(n); + + Delete(result); + } + + String *cxx_director_name = NewString("SwigDirector_"); + Append(cxx_director_name, class_name); + + String *decl = Swig_method_decl(NULL, Getattr(n, "decl"), + cxx_director_name, first_parm, 0, 0); + Printv(f_c_directors_h, " ", decl, ";\n", NULL); + Delete(decl); + + decl = Swig_method_decl(NULL, Getattr(n, "decl"), + cxx_director_name, first_parm, 0, 0); + Printv(f_c_directors, cxx_director_name, "::", decl, "\n", NULL); + Delete(decl); + + Printv(f_c_directors, " : ", Getattr(parentNode(n), "classtype"), "(", + NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + if (i > 0) { + Printv(f_c_directors, ", ", NULL); + } + String *pn = Getattr(p, "name"); + assert(pn != NULL); + Printv(f_c_directors, pn, NULL); + p = nextParm(p); + } + Printv(f_c_directors, "),\n", NULL); + Printv(f_c_directors, " go_val(swig_p)\n", NULL); + Printv(f_c_directors, "{ }\n\n", NULL); + + if (Getattr(n, "sym:overloaded") && Getattr(n, "sym:nextSibling") == NULL) { + int r = makeDispatchFunction(n, func_name, cn, is_static, + Getattr(parentNode(n), "classtypeobj"), + false); + if (r != SWIG_OK) { + return r; + } + } + + Delete(cxx_director_name); + Delete(go_name); + Delete(cn); + Delete(go_type_name); + Delete(director_struct_name); + Delete(fn_name); + Delete(func_name); + Delete(func_with_over_name); + Delete(wname); + Delete(first_type); + Delete(first_parm); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * classDirectorDestructor + * + * Emit a destructor for a director class. + * ------------------------------------------------------------ */ + + int classDirectorDestructor(Node *n) { + if (!is_public(n)) { + return SWIG_OK; + } + + bool is_ignored = GetFlag(n, "feature:ignore"); + + if (!is_ignored) { + String *fnname = NewString("DeleteDirector"); + String *c1 = exportedName(class_name); + Append(fnname, c1); + Delete(c1); + + String *wname = Swig_name_wrapper(fnname); + + Setattr(n, "wrap:name", fnname); + + Swig_DestructorToFunction(n, getNSpace(), + Getattr(parentNode(n), "classtype"), + CPlusPlus, Extend); + + ParmList *parms = Getattr(n, "parms"); + Setattr(n, "wrap:parms", parms); + + String *result = NewString("void"); + int r = makeWrappers(n, fnname, fnname, NULL, wname, NULL, parms, result, + isStatic(n)); + if (r != SWIG_OK) { + return r; + } + + Delete(result); + Delete(fnname); + Delete(wname); + } + + // Generate the destructor for the C++ director class. Since the + // Go code is keeping a pointer to the C++ object, we need to call + // back to the Go code to let it know that the C++ object is gone. + + String *wname = NewString("_swiggo_wrap_DeleteDirector_"); + Append(wname, class_name); + + String *go_name = NewString("Swiggo_DeleteDirector_"); + Append(go_name, class_name); + + String *cn = exportedName(class_name); + + String *director_struct_name = NewString("_swig_Director"); + Append(director_struct_name, cn); + + Printv(f_c_directors_h, " virtual ~SwigDirector_", class_name, "()", + NULL); + + String *throws = buildThrow(n); + if (throws != NULL) { + Printv(f_c_directors_h, " ", throws, NULL); + } + + Printv(f_c_directors_h, ";\n", NULL); + + if (!is_ignored) { + if (!gccgo_flag) { + Printv(f_c_directors, "extern \"C\" void ", wname, "(void*, int);\n", + NULL); + } else { + Printv(f_c_directors, "extern \"C\" void ", wname, "(void*) __asm__(\"", + go_prefix, ".", package, ".", go_name, "\");\n", NULL); + } + } + + Printv(f_c_directors, "SwigDirector_", class_name, "::~SwigDirector_", + class_name, "()", NULL); + + if (throws != NULL) { + Printv(f_c_directors, " ", throws, NULL); + Delete(throws); + } + + Printv(f_c_directors, "\n", NULL); + Printv(f_c_directors, "{\n", NULL); + + if (!is_ignored) { + if (!gccgo_flag) { + Printv(f_c_directors, " struct { void *p; } a;\n", NULL); + Printv(f_c_directors, " a.p = go_val;\n", NULL); + Printv(f_c_directors, " crosscall2(", wname, + ", &a, (int) sizeof a);\n", NULL); + + Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", + NULL); + Printv(f_gc_wrappers, "extern void \xc2\xb7", go_name, "();\n", NULL); + Printv(f_gc_wrappers, "void\n", NULL); + Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL); + Printv(f_gc_wrappers, "{\n", NULL); + Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", go_name, ", a, n);\n", + NULL); + Printv(f_gc_wrappers, "}\n\n", NULL); + } else { + Printv(f_c_directors, " ", wname, "(go_val);\n", NULL); + } + } + + Printv(f_c_directors, "}\n\n", NULL); + + if (!is_ignored) { + Printv(f_go_wrappers, "func ", go_name, "(p *", director_struct_name, + ") {\n", NULL); + Printv(f_go_wrappers, "\tp.", class_receiver, " = 0\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + } + + Delete(wname); + Delete(go_name); + Delete(cn); + Delete(director_struct_name); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * classDirectorMethod + * + * Emit a method for a director class, plus its overloads. + * ------------------------------------------------------------ */ + + int classDirectorMethod(Node *n, Node *parent, String *super) { + (void) super; + + bool is_ignored = GetFlag(n, "feature:ignore"); + bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 + && Cmp(Getattr(n, "value"), "0") == 0); + + // We don't need explicit calls. + if (GetFlag(n, "explicitcall")) { + return SWIG_OK; + } + + String *name = Getattr(n, "sym:name"); + if (name == NULL) { + assert(is_ignored); + name = Getattr(n, "name"); + } + + if (Getattr(class_methods, name) != NULL) { + // We need to emit a pure virtual function, even if it is + // overloaded. Otherwise we won't be able to create an instance + // of the director class. The function doesn't need to actually + // do anything. + if (!is_pure_virtual || Getattr(n, "sym:overloaded") != NULL) { + return SWIG_OK; + } + } + Setattr(class_methods, name, NewString("")); + + if (Getattr(n, "sym:overloaded") == NULL) { + int r = oneClassDirectorMethod(n, parent); + if (r != SWIG_OK) { + return r; + } + } else { + // Handle overloaded methods here, because otherwise we will + // reject them in the class_methods hash table. We need to use + // class_methods so that we correctly handle cases where a + // function in one class hides a function of the same name in a + // parent class. + for (Node *on = Getattr(n, "sym:overloaded"); + on != NULL; + on = Getattr(on, "sym:nextSibling")) { + int r = oneClassDirectorMethod(on, parent); + if (r != SWIG_OK) { + return r; + } + + // Swig_overload_rank expects wrap:name and wrap:parms to be + // set. + String *wn = Swig_name_wrapper(Getattr(on, "sym:name")); + Append(wn, Getattr(on, "sym:overname")); + Setattr(on, "wrap:name", wn); + Delete(wn); + Setattr(on, "wrap:parms", Getattr(on, "parms")); + } + + bool is_static = isStatic(n); + + String *cn = exportedName(Getattr(parent, "sym:name")); + String *go_name = buildGoName(name, is_static, false); + + String *director_struct_name = NewString("_swig_Director"); + Append(director_struct_name, cn); + + int r = makeDispatchFunction(n, go_name, director_struct_name, is_static, + director_struct_name, false); + if (r != SWIG_OK) { + return r; + } + + String *go_upcall = NewString("Director"); + Append(go_upcall, cn); + Append(go_upcall, go_name); + r = makeDispatchFunction(n, go_upcall, director_struct_name, is_static, + director_struct_name, true); + if (r != SWIG_OK) { + return r; + } + + Delete(cn); + Delete(go_name); + Delete(director_struct_name); + Delete(go_upcall); + } + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * oneClassDirectorMethod + * + * Emit a method for a director class. + * ------------------------------------------------------------ */ + + int oneClassDirectorMethod(Node *n, Node *parent) { + bool is_ignored = GetFlag(n, "feature:ignore"); + bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 + && Cmp(Getattr(n, "value"), "0") == 0); + + String *name = Getattr(n, "sym:name"); + if (name == NULL) { + assert(is_ignored); + name = Getattr(n, "name"); + } + + String *overname = NULL; + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); + } + + String *cn = exportedName(Getattr(parent, "sym:name")); + + String *go_type_name = goCPointerType(Getattr(parent, "classtypeobj"), + true); + + String *director_struct_name = NewString("_swig_Director"); + Append(director_struct_name, cn); + + bool is_static = isStatic(n); + + String *go_name = buildGoName(name, is_static, false); + + ParmList *parms = Getattr(n, "parms"); + Setattr(n, "wrap:parms", parms); + + Wrapper *dummy = NewWrapper(); + emit_attach_parmmaps(parms, dummy); + DelWrapper(dummy); + + Swig_typemap_attach_parms("go", parms, NULL); + int parm_count = emit_num_arguments(parms); + + SwigType *result = Getattr(n, "returntype"); + if (result == NULL) { + // This can happen when following overloads. + result = NewString(Getattr(n, "type")); + SwigType_push(result, Getattr(n, "decl")); + if (SwigType_isqualifier(result)) { + Delete(SwigType_pop(result)); + } + Delete(SwigType_pop_function(result)); + Setattr(n, "returntype", result); + } + + // Save the type for overload processing. + Setattr(n, "go:type", result); + + String *interface_name = NewString("_swig_DirectorInterface"); + Append(interface_name, cn); + Append(interface_name, go_name); + if (overname != NULL) { + Append(interface_name, overname); + } + + String *callback_name = Copy(director_struct_name); + Append(callback_name, "_callback_"); + Append(callback_name, name); + Replace(callback_name, "_swig", "Swig", DOH_REPLACE_FIRST); + if (overname != NULL) { + Append(callback_name, overname); + } + + String *callback_wname = Swig_name_wrapper(callback_name); + + String *upcall_name = Copy(director_struct_name); + Append(upcall_name, "_upcall_"); + Append(upcall_name, go_name); + + String *upcall_wname = Swig_name_wrapper(upcall_name); + + String *go_with_over_name = Copy(go_name); + if (overname != NULL) { + Append(go_with_over_name, overname); + } + + Wrapper *f = NewWrapper(); + + Parm *p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + Swig_cparm_name(p, i); + if (Getattr(p, "name") == NULL) { + String *pn = NewString(""); + Printf(pn, "arg%d", i); + Setattr(p, "name", pn); + } + p = nextParm(p); + } + + Swig_typemap_attach_parms("directorin", parms, f); + + if (!is_ignored) { + // We use an interface to see if this method is defined in Go. + Printv(f_go_wrappers, "type ", interface_name, " interface {\n", NULL); + Printv(f_go_wrappers, "\t", 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); + } + String *tm = goType(p, Getattr(p, "type")); + Printv(f_go_wrappers, tm, NULL); + Delete(tm); + p = nextParm(p); + } + + Printv(f_go_wrappers, ")", NULL); + + if (SwigType_type(result) != T_VOID) { + String *tm = goType(n, result); + Printv(f_go_wrappers, " ", tm, NULL); + Delete(tm); + } + + Printv(f_go_wrappers, "\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + // Declare the upcall function, which calls the method on the + // parent class. + + if (overname != NULL) { + Append(upcall_wname, overname); + } + + String *upcall_gc_name = buildGoWrapperName(upcall_name, overname); + + Printv(f_go_wrappers, "func ", upcall_gc_name, "(", + 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); + Delete(tm); + p = nextParm(p); + } + + Printv(f_go_wrappers, ")", NULL); + + if (SwigType_type(result) != T_VOID) { + String *tm = goWrapperType(n, result, true); + Printv(f_go_wrappers, " ", tm, NULL); + Delete(tm); + } + + if (gccgo_flag) { + Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", upcall_wname, + "\")", NULL); + } + + Printv(f_go_wrappers, "\n", NULL); + + // Define the method on the director class in Go. + + Printv(f_go_wrappers, "func (swig_p *", director_struct_name, ") ", + 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(f_go_wrappers, Getattr(p, "lname"), " ", NULL); + String *tm = goType(p, Getattr(p, "type")); + Printv(f_go_wrappers, tm, NULL); + Delete(tm); + p = nextParm(p); + } + + Printv(f_go_wrappers, ")", NULL); + + if (SwigType_type(result) != T_VOID) { + String *tm = goType(n, result); + Printv(f_go_wrappers, " ", tm, NULL); + Delete(tm); + } + + Printv(f_go_wrappers, " {\n", NULL); + + Printv(f_go_wrappers, "\tif swig_g, swig_ok := swig_p.v.(", + interface_name, "); swig_ok {\n", NULL); + Printv(f_go_wrappers, "\t\t", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(f_go_wrappers, "return ", NULL); + } + Printv(f_go_wrappers, "swig_g.", 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(f_go_wrappers, Getattr(p, "lname"), NULL); + p = nextParm(p); + } + + Printv(f_go_wrappers, ")\n", NULL); + if (SwigType_type(result) == T_VOID) { + Printv(f_go_wrappers, "\t\treturn\n", NULL); + } + Printv(f_go_wrappers, "\t}\n", NULL); + Printv(f_go_wrappers, "\t", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(f_go_wrappers, "return ", NULL); + } + 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); + } + p = nextParm(p); + } + + Printv(f_go_wrappers, ")\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + // Define a method in the C++ director class that the C++ upcall + // function can call. This permits an upcall to a protected + // method. + + String *upcall_method_name = NewString("_swig_upcall_"); + Append(upcall_method_name, name); + if (overname != NULL) { + Append(upcall_method_name, overname); + } + String *upcall_decl = Swig_method_decl(Getattr(n, "type"), + Getattr(n, "decl"), + upcall_method_name, parms, 0, 0); + Printv(f_c_directors_h, " ", upcall_decl, " {\n", NULL); + Delete(upcall_decl); + + Printv(f_c_directors_h, " ", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(f_c_directors_h, "return ", NULL); + } + Printv(f_c_directors_h, Getattr(parent, "classtype"), "::", + Getattr(n, "name"), "(", NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + if (i > 0) { + Printv(f_c_directors_h, ", ", NULL); + } + String *pn = Getattr(p, "name"); + assert(pn != NULL); + Printv(f_c_directors_h, pn, NULL); + p = nextParm(p); + } + + Printv(f_c_directors_h, ");\n", NULL); + Printv(f_c_directors_h, " }\n", NULL); + + + // Define the C++ function that the Go function calls. + + SwigType *first_type = NULL; + Parm *first_parm = parms; + if (!is_static) { + first_type = NewString("SwigDirector_"); + Append(first_type, class_name); + SwigType_add_pointer(first_type); + first_parm = NewParm(first_type, "p", n); + set_nextSibling(first_parm, parms); + } + + Swig_save("classDirectorMethod", n, "wrap:name", "wrap:action", NULL); + + Setattr(n, "wrap:name", upcall_wname); + + String *action = NewString(""); + if (SwigType_type(result) != T_VOID) { + Printv(action, "result = (", SwigType_lstr(result, 0), ")", NULL); + if (SwigType_isreference(result)) { + Printv(action, "&", NULL); + } + } + Printv(action, Swig_cparm_name(NULL, 0), "->", upcall_method_name, "(", + NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + String *pname = Swig_cparm_name(NULL, i + 1); + if (i > 0) { + Printv(action, ", ", NULL); + } + // A parameter whose type is a reference is converted into a + // pointer type by gcCTypeForGoValue. We are calling a + // function which expects a reference so we need to convert + // back. + if (SwigType_isreference(Getattr(p, "type"))) { + Printv(action, "*", NULL); + } + Printv(action, pname, NULL); + Delete(pname); + p = nextParm(p); + } + Printv(action, ");", NULL); + Setattr(n, "wrap:action", action); + + 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); + if (r != SWIG_OK) { + return r; + } + r = gccFunctionWrapper(n, NULL, upcall_wname, first_parm, result); + if (r != SWIG_OK) { + return r; + } + } else { + int r = gccgoFunctionWrapper(n, NULL, upcall_wname, first_parm, result); + if (r != SWIG_OK) { + return r; + } + } + + if (first_type != NULL) { + Delete(first_type); + } + if (first_parm != parms) { + Delete(first_parm); + } + + Swig_restore(n); + + // Define a function which uses the Go director type that other + // methods in the Go type can call to get parent methods. + + Printv(f_go_wrappers, "func Director", cn, go_with_over_name, "(p ", cn, + NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + Printv(f_go_wrappers, ", ", Getattr(p, "lname"), " ", NULL); + String *tm = goType(p, Getattr(p, "type")); + Printv(f_go_wrappers, tm, NULL); + Delete(tm); + p = nextParm(p); + } + + Printv(f_go_wrappers, ")", NULL); + + if (SwigType_type(result) != T_VOID) { + String *tm = goType(n, result); + Printv(f_go_wrappers, " ", tm, NULL); + Delete(tm); + } + + Printv(f_go_wrappers, " {\n", NULL); + + Printv(f_go_wrappers, "\t", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(f_go_wrappers, "return ", NULL); + } + Printv(f_go_wrappers, upcall_gc_name, "(p.(*", + director_struct_name, ").", 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); + } + p = nextParm(p); + } + + Printv(f_go_wrappers, ")\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + // The Go function which invokes the method. This is called + // from by the C++ method on the director class. + + Printv(f_go_wrappers, "func ", callback_name, "(p *", + director_struct_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, ", ", Getattr(p, "lname"), " ", tm, NULL); + Delete(tm); + p = nextParm(p); + } + + Printv(f_go_wrappers, ") ", NULL); + String *result_wrapper = NULL; + if (SwigType_type(result) != T_VOID) { + result_wrapper = goWrapperType(n, result, true); + Printv(f_go_wrappers, "(swig_result ", result_wrapper, ") ", NULL); + } + Printv(f_go_wrappers, "{\n", NULL); + Printv(f_go_wrappers, "\t", NULL); + + if (is_ignored) { + Printv(f_go_wrappers, "return\n", NULL); + } else { + bool result_is_interface = false; + if (SwigType_type(result) != T_VOID) { + Printv(f_go_wrappers, "return ", NULL); + result_is_interface = goTypeIsInterface(NULL, result); + if (result_is_interface) { + Printv(f_go_wrappers, result_wrapper, "(", NULL); + } + } + Printv(f_go_wrappers, "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); + } + SwigType *pt = Getattr(p, "type"); + + // If the Go representation is an interface type class, then + // we are receiving a uintptr, and must convert to the + // interface. + bool is_interface = goTypeIsInterface(p, pt); + if (is_interface) { + // 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); + Delete(wt); + } + + Printv(f_go_wrappers, Getattr(p, "lname"), NULL); + + if (is_interface) { + Printv(f_go_wrappers, ")", NULL); + } + + p = nextParm(p); + } + + Printv(f_go_wrappers, ")", NULL); + + if (result_is_interface) { + Printv(f_go_wrappers, ".Swigcptr())", NULL); + } + + Printv(f_go_wrappers, "\n", NULL); + + Delete(upcall_gc_name); + } + + Printv(f_go_wrappers, "}\n\n", NULL); + + if (result_wrapper != NULL) { + Delete(result_wrapper); + } + + // Build the C++ functions. + + Delete(upcall_wname); + + if (!gccgo_flag) { + Printv(f_c_directors, "extern \"C\" void ", callback_wname, + "(void*, int);\n", NULL); + } else { + Printv(f_c_directors, "extern \"C\" ", NULL); + + String *fnname = NewString(""); + Printv(fnname, callback_wname, "(void*", NULL); + + p = parms; + while (p != NULL) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } + String *cg = gccgoCTypeForGoValue(p, Getattr(p, "type"), + Getattr(p, "lname")); + Printv(fnname, ", ", cg, NULL); + Delete(cg); + p = Getattr(p, "tmap:directorin:next"); + } + + Printv(fnname, ")", NULL); + + if (SwigType_type(result) == T_VOID) { + Printv(f_c_directors, "void ", fnname, NULL); + } else { + String *tm = gccgoCTypeForGoValue(n, result, fnname); + Printv(f_c_directors, tm, NULL); + Delete(tm); + } + + Delete(fnname); + + Printv(f_c_directors, " __asm__(\"", go_prefix, ".", package, ".", + callback_name, "\");\n", NULL); + } + + Delete(upcall_method_name); + Delete(go_with_over_name); + } + + if (!is_ignored || is_pure_virtual) { + // Declare the method for the director class. + + SwigType *rtype = (Getattr(n, "conversion_operator") + ? NULL + : Getattr(n, "type")); + String *decl = Swig_method_decl(rtype, Getattr(n, "decl"), + Getattr(n, "name"), parms, + 0, 0); + Printv(f_c_directors_h, " virtual ", decl, NULL); + Delete(decl); + + String *qname = NewString(""); + Printv(qname, "SwigDirector_", class_name, "::", Getattr(n, "name"), + NULL); + decl = Swig_method_decl(rtype, Getattr(n, "decl"), qname, parms, 0, 0); + Printv(f->def, decl, NULL); + Delete(decl); + Delete(qname); + + String *throws = buildThrow(n); + if (throws != NULL) { + Printv(f_c_directors_h, " ", throws, NULL); + Printv(f->def, " ", throws, NULL); + Delete(throws); + } + + Printv(f_c_directors_h, ";\n", NULL); + + Printv(f->def, " {\n", NULL); + + if (SwigType_type(result) != T_VOID) { + Wrapper_add_local(f, "c_result", + SwigType_lstr(Getattr(n, "returntype"), "c_result")); + } + + if (!is_ignored) { + if (!gccgo_flag) { + Printv(f->code, " struct {\n", NULL); + Printv(f->code, " void *go_val;\n", NULL); + + p = parms; + while (p != NULL) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } + String *ln = Getattr(p, "lname"); + String *cg = gcCTypeForGoValue(p, Getattr(p, "type"), ln); + Printv(f->code, " ", cg, ";\n", NULL); + Delete(cg); + p = Getattr(p, "tmap:directorin:next"); + } + if (SwigType_type(result) != T_VOID) { + Printv(f->code, " int : 0;\n", NULL); + String *rname = NewString("result"); + String *cg = gcCTypeForGoValue(n, result, rname); + Printv(f->code, " ", cg, ";\n", NULL); + Delete(cg); + Delete(rname); + } + + Printv(f->code, " } swig_a;\n", NULL); + Printv(f->code, " swig_a.go_val = go_val;\n", NULL); + + p = parms; + while (p != NULL) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } + String *tm = Getattr(p, "tmap:directorin"); + if (tm == NULL) { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, + line_number, + "Unable to use type %s as director method argument\n", + SwigType_str(Getattr(p, "type"), 0)); + } else { + String *ln = Getattr(p, "lname"); + String *input = NewString(""); + Printv(input, "swig_a.", ln, NULL); + Replaceall(tm, "$input", input); + Replaceall(tm, "$owner", "0"); + Delete(input); + Printv(f->code, "\t", tm, "\n", NULL); + } + p = Getattr(p, "tmap:directorin:next"); + } + + Printv(f->code, " crosscall2(", callback_wname, + ", &swig_a, (int) sizeof swig_a);\n", NULL); + + if (SwigType_type(result) != T_VOID) { + String *rname = NewString("c_result"); + Parm *rp = NewParm(Getattr(n, "returntype"), rname, n); + String *tm = Swig_typemap_lookup("directorout", rp, rname, NULL); + if (tm == NULL) { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use type %s as director method result\n", + SwigType_str(result, 0)); + } else { + Replaceall(tm, "$input", "swig_a.result"); + Replaceall(tm, "$result", "c_result"); + Printv(f->code, " ", tm, "\n", NULL); + String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), + "c_result"); + Printv(f->code, " return ", retstr, ";\n", NULL); + Delete(retstr); + Delete(tm); + } + Delete(rp); + Delete(rname); + } + + // The C wrapper code which calls the Go function. + Printv(f_gc_wrappers, "#pragma dynexport ", callback_wname, " ", + callback_wname, "\n", NULL); + Printv(f_gc_wrappers, "extern void \xc2\xb7", callback_name, "();\n", + NULL); + Printv(f_gc_wrappers, "void\n", NULL); + Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL); + Printv(f_gc_wrappers, "{\n", NULL); + Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", callback_name, + ", a, n);\n", NULL); + Printv(f_gc_wrappers, "}\n\n", NULL); + } else { + if (SwigType_type(result) != T_VOID) { + String *r = NewString("result"); + String *tm = gccgoCTypeForGoValue(n, result, r); + Wrapper_add_local(f, r, tm); + Delete(tm); + Delete(r); + } + + String *args = NewString(""); + + p = parms; + while (p != NULL) { + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); + } + + String *pn = NewString("g"); + Append(pn, Getattr(p, "lname")); + Setattr(p, "emit:input", pn); + + String *tm = gccgoCTypeForGoValue(n, Getattr(p, "type"), pn); + Wrapper_add_local(f, pn, tm); + Delete(tm); + + tm = Getattr(p, "tmap:directorin"); + if (tm == NULL) { + 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 { + Replaceall(tm, "$input", pn); + Replaceall(tm, "$owner", 0); + Printv(f->code, " ", tm, "\n", NULL); + + Printv(args, ", ", pn, NULL); + } + + p = Getattr(p, "tmap:directorin:next"); + } + + Printv(f->code, " ", NULL); + if (SwigType_type(result) != T_VOID) { + Printv(f->code, "result = ", NULL); + } + Printv(f->code, callback_wname, "(go_val", args, ");\n", NULL); + + if (SwigType_type(result) != T_VOID) { + String *rname = NewString("c_result"); + Parm *rp = NewParm(Getattr(n, "returntype"), rname, n); + String *tm = Swig_typemap_lookup("directorout", rp, rname, NULL); + if (tm == NULL) { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use type %s as director method result\n", + SwigType_str(result, 0)); + } else { + Replaceall(tm, "$input", "result"); + Replaceall(tm, "$result", "c_result"); + Printv(f->code, " ", tm, "\n", NULL); + String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), + "c_result"); + Printv(f->code, " return ", retstr, ";\n", NULL); + Delete(retstr); + Delete(tm); + } + Delete(rp); + Delete(rname); + } + } + } else { + assert(is_pure_virtual); + Printv(f->code, " _swig_gopanic(\"call to pure virtual function ", + Getattr(parent, "sym:name"), name, "\");\n"); + if (SwigType_type(result) != T_VOID) { + String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), + "c_result"); + Printv(f->code, " return ", retstr, ";\n", NULL); + Delete(retstr); + } + } + + Printv(f->code, "}", NULL); + + Wrapper_print(f, f_c_directors); + + DelWrapper(f); + } + + Delete(cn); + Delete(go_type_name); + Delete(director_struct_name); + Delete(interface_name); + Delete(upcall_name); + Delete(callback_wname); + Delete(go_name); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * classDirectorEnd + * + * Complete support for a director class. + * ------------------------------------------------------------ */ + + int classDirectorEnd(Node *n) { + (void) n; + + Printv(f_c_directors_h, " private:\n", NULL); + Printv(f_c_directors_h, " void *go_val;\n", NULL); + Printv(f_c_directors_h, "};\n\n", NULL); + + class_name = NULL; + class_node = NULL; + + Delete(class_receiver); + class_receiver = NULL; + + Delete(class_methods); + class_methods = NULL; + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * classDirectorDisown + * + * I think Go does not require a disown method. + * ------------------------------------------------------------ */ + + int classDirectorDisown(Node *n) { + (void) n; + return SWIG_OK; + } + + /*---------------------------------------------------------------------- + * buildThrow() + * + * Build and return a throw clause if needed. + *--------------------------------------------------------------------*/ + + String *buildThrow(Node *n) { + ParmList *throw_parm_list = Getattr(n, "throws"); + if (throw_parm_list == NULL && Getattr(n, "throw") == NULL) + return NULL; + String *ret = NewString("throw("); + if (throw_parm_list != NULL) { + Swig_typemap_attach_parms("throws", throw_parm_list, NULL); + } + bool first = true; + for (Parm *p = throw_parm_list; p != NULL; p = nextSibling(p)) { + if (Getattr(p, "tmap:throws") != NULL) { + if (first) { + first = false; + } else { + Printv(ret, ", ", NULL); + } + String *s = SwigType_str(Getattr(p, "type"), 0); + Printv(ret, s, NULL); + Delete(s); + } + } + Printv(ret, ")", NULL); + return ret; + } + + /*---------------------------------------------------------------------- + * extraDirectorProtectedCPPMethodsRequired() + * + * We don't need to check upcall when calling methods. + *--------------------------------------------------------------------*/ + + bool extraDirectorProtectedCPPMethodsRequired() const { + return false; + } + + /*---------------------------------------------------------------------- + * makeDispatchFunction + * + * Make a dispatch function for an overloaded C++ function. The + * receiver parameter is the receiver for a method, unless is_upcall + * is true. If is_upcall is true, then the receiver parameter is + * the type of the first argument to the function. + *--------------------------------------------------------------------*/ + + int makeDispatchFunction(Node *n, String *go_name, String *receiver, + bool is_static, SwigType *director_struct, + bool is_upcall) { + bool is_director = director_struct != NULL; + + String *nodetype = Getattr(n, "nodeType"); + bool is_constructor = Cmp(nodetype, "constructor") == 0; + bool is_destructor = Cmp(nodetype, "destructor") == 0; + + bool can_use_receiver = (!is_constructor + && !is_destructor + && !is_upcall); + + bool use_receiver = (!is_static + && can_use_receiver); + + bool add_to_interface = (interfaces != NULL + && !is_constructor + && !is_destructor + && !is_static + && !is_upcall); + + List *dispatch = Swig_overload_rank(n, false); + int nfunc = Len(dispatch); + + SwigType *all_result; + bool mismatch; + if (is_constructor) { + assert(!is_upcall); + if (!is_director) { + all_result = Getattr(class_node, "classtypeobj"); + } else { + all_result = director_struct; + } + mismatch = false; + } else { + all_result = NULL; + mismatch = false; + bool any_void = false; + for (int i = 0; i < nfunc; ++i) { + Node *ni = Getitem(dispatch, i); + SwigType *result = Getattr(ni, "go:type"); + assert(result != NULL); + + if (SwigType_type(result) == T_VOID) { + if (all_result != NULL) { + mismatch = true; + } + any_void = true; + } else { + if (any_void) { + mismatch = true; + } else if (all_result == NULL) { + all_result = Copy(result); + } else if (Cmp(result, all_result) != 0) { + mismatch = true; + } + } + } + if (mismatch) { + if (all_result != NULL) { + Delete(all_result); + } + all_result = NULL; + } else if (all_result != NULL) { + ; + } else { + all_result = NewString("void"); + } + } + + Printv(f_go_wrappers, "func ", NULL); + + if (receiver != NULL && use_receiver) { + Printv(f_go_wrappers, "(p ", receiver, ") ", NULL); + } + + Printv(f_go_wrappers, go_name, "(", NULL); + if (is_director && is_constructor) { + Printv(f_go_wrappers, "abi interface{}, ", NULL); + assert(!add_to_interface); + } + if (is_upcall) { + Printv(f_go_wrappers, "p *", receiver, ", ", NULL); + assert(!add_to_interface); + } + Printv(f_go_wrappers, "a ...interface{})", NULL); + + if (add_to_interface) { + Printv(interfaces, "\t", go_name, "(a ...interface{})", NULL); + } + + if (mismatch) { + Printv(f_go_wrappers, " interface{}", NULL); + if (add_to_interface) { + Printv(interfaces, " interface{}", NULL); + } + } else if (all_result != NULL && SwigType_type(all_result) != T_VOID) { + if (is_director && is_constructor) { + Printv(f_go_wrappers, " ", receiver, NULL); + if (add_to_interface) { + Printv(interfaces, " ", receiver, NULL); + } + } else { + String *tm = goType(n, all_result); + Printv(f_go_wrappers, " ", tm, NULL); + if (add_to_interface) { + Printv(interfaces, " ", tm, NULL); + } + Delete(tm); + } + } + Printv(f_go_wrappers, " {\n", NULL); + if (add_to_interface) { + Printv(interfaces, "\n", NULL); + } + + Printv(f_go_wrappers, "\targc := len(a)\n", NULL); + + for (int i = 0; i < nfunc; ++i) { + int fn = 0; + Node *ni = Getitem(dispatch, i); + Parm *pi = Getattr(ni, "wrap:parms"); + + // If we are using a receiver, we want to ignore a leading self + // parameter. Because of the way this is called, there may or + // may not be a self parameter at this point. + if (use_receiver && pi != NULL && Getattr(pi, "self") != NULL) { + pi = getParm(pi); + if (pi != NULL) { + pi = nextParm(pi); + } + } + + int num_required = emit_num_required(pi); + int num_arguments = emit_num_arguments(pi); + bool varargs = emit_isvarargs(pi); + + if (varargs) { + Printf(f_go_wrappers, "\tif argc >= %d {\n", num_required); + } else { + if (num_required == num_arguments) { + Printf(f_go_wrappers, "\tif argc == %d {\n", num_required); + } else { + Printf(f_go_wrappers, "\tif argc >= %d && argc <= %d {\n", + num_required, num_arguments); + } + } + + // Build list of collisions with the same number of arguments. + List *coll = NewList(); + for (int k = i + 1; k < nfunc; ++k) { + Node *nk = Getitem(dispatch, k); + Parm *pk = Getattr(nk, "wrap:parms"); + if (use_receiver && pk != NULL && Getattr(pk, "self") != NULL) { + pk = getParm(pk); + if (pk != NULL) { + pk = nextParm(pk); + } + } + int nrk = emit_num_required(pk); + int nak = emit_num_arguments(pk); + if ((nrk >= num_required && nrk <= num_arguments) + || (nak >= num_required && nak <= num_arguments) + || (nrk <= num_required && nak >= num_arguments)) { + Append(coll, nk); + } + } + + int num_braces = 0; + if (Len(coll) > 0 && num_arguments > 0) { + int j = 0; + Parm *pj = pi; + while (pj != NULL) { + pj = getParm(pj); + if (pj == NULL) { + break; + } + + // If all the wrappers have the same type in this position, + // we can omit the check. + SwigType *tm = goWrapperType(pj, Getattr(pj, "type"), true); + bool emitcheck = false; + for (int k = 0; k < Len(coll) && !emitcheck; ++k) { + Node *nk = Getitem(coll, k); + Parm *pk = Getattr(nk, "wrap:parms"); + if (use_receiver && pk != NULL && Getattr(pk, "self") != NULL) { + pk = getParm(pk); + if (pk != NULL) { + pk = nextParm(pk); + } + } + int nak = emit_num_arguments(pk); + if (nak <= j) + continue; + int l = 0; + Parm *pl = pk; + while (pl != NULL && l <= j) { + pl = getParm(pl); + if (pl == NULL) { + break; + } + if (l == j) { + SwigType *tml = goWrapperType(pl, Getattr(pl, "type"), true); + if (Cmp(tm, tml) != 0) { + emitcheck = true; + } + Delete(tml); + } + pl = nextParm(pl); + ++l; + } + } + + if (emitcheck) { + if (j >= num_required) { + Printf(f_go_wrappers, "\t\tif argc > %d {\n", j); + ++num_braces; + } + + fn = i + 1; + Printf(f_go_wrappers, "\t\tif _, ok := a[%d].(%s); !ok {\n", j, tm); + Printf(f_go_wrappers, "\t\t\tgoto check_%d\n", fn); + Printv(f_go_wrappers, "\t\t}\n", NULL); + } + + Delete(tm); + + pj = nextParm(pj); + + ++j; + } + } + + for (; num_braces > 0; --num_braces) { + Printv(f_go_wrappers, "\t\t}\n", NULL); + } + + // We may need to generate multiple calls if there are variable + // argument lists involved. Build the start of the call. + + String *start = NewString(""); + + SwigType *result = Getattr(ni, "go:type"); + + if (is_constructor) { + result = all_result; + } else if (is_destructor) { + result = NULL; + } + + if (result != NULL + && SwigType_type(result) != T_VOID + && (all_result == NULL + || SwigType_type(all_result) != T_VOID)) { + Printv(start, "return ", NULL); + } + + bool advance_parm = false; + + if (receiver != NULL && use_receiver) { + Printv(start, "p.", go_name, NULL); + } else if (can_use_receiver + && !isStatic(ni) + && pi != NULL + && Getattr(pi, "self") != NULL) { + // This is an overload of a static function and a non-static + // function. + assert(num_required > 0); + SwigType *tm = goWrapperType(pi, Getattr(pi, "type"), true); + String *nm = buildGoName(Getattr(ni, "sym:name"), false, + isFriend(ni)); + Printv(start, "a[0].(", tm, ").", nm, NULL); + Delete(nm); + Delete(tm); + advance_parm = true; + } else { + Printv(start, go_name, NULL); + } + + Printv(start, Getattr(ni, "sym:overname"), "(", NULL); + + bool need_comma = false; + + if (is_director && is_constructor) { + Printv(start, "abi", NULL); + need_comma = true; + } + if (is_upcall) { + Printv(start, "p", NULL); + need_comma = true; + } + Parm *p = pi; + int pn = 0; + if (advance_parm) { + p = getParm(p); + if (p != NULL) { + p = nextParm(p); + } + ++pn; + } + while (pn < num_required) { + p = getParm(p); + + if (need_comma) { + Printv(start, ", ", NULL); + } + + SwigType *tm = goType(p, Getattr(p, "type")); + Printf(start, "a[%d].(%s)", pn, tm); + Delete(tm); + + need_comma = true; + ++pn; + p = nextParm(p); + } + + String *end = NULL; + if (result == NULL + || SwigType_type(result) == T_VOID + || (all_result != NULL && SwigType_type(all_result) == T_VOID)) { + end = NewString(""); + Printv(end, "return", NULL); + if (all_result == NULL || SwigType_type(all_result) != T_VOID) { + Printv(end, " 0", NULL); + } + } + + if (num_required == num_arguments) { + Printv(f_go_wrappers, "\t\t", start, ")\n", NULL); + if (end != NULL) { + Printv(f_go_wrappers, "\t\t", end, "\n", NULL); + } + } else { + Printv(f_go_wrappers, "\t\tswitch argc {\n", NULL); + for (int j = num_required; j <= num_arguments; ++j) { + Printf(f_go_wrappers, "\t\tcase %d:\n", j); + Printv(f_go_wrappers, "\t\t\t", start, NULL); + bool nc = need_comma; + for (int k = num_required; k < j; ++k) { + if (nc) { + Printv(f_go_wrappers, ", ", NULL); + } + Printf(f_go_wrappers, "a[%d]", k); + nc = true; + } + Printv(f_go_wrappers, ")\n", NULL); + if (end != NULL) { + Printv(f_go_wrappers, "\t\t\t", end, "\n", NULL); + } + } + Printv(f_go_wrappers, "\t\t}\n", NULL); + } + + Printv(f_go_wrappers, "\t}\n", NULL); + + if (fn != 0) { + Printf(f_go_wrappers, "check_%d:\n", fn); + } + + Delete(coll); + } + + Printv(f_go_wrappers, "fail:\n", NULL); + Printv(f_go_wrappers, + "\tpanic(\"No match for overloaded function call\")\n", NULL); + Printv(f_go_wrappers, "}\n\n", NULL); + + if (all_result != NULL) { + Delete(all_result); + } + Delete(dispatch); + + return SWIG_OK; + } + + /* ---------------------------------------------------------------------- + * exportedName() + * + * Given a C/C++ name, return a name in Go which will be exported. + * If the first character is an upper case letter, this returns a + * copy of its argment. If the first character is a lower case + * letter, this forces it to upper case. Otherwise, this prepends + * 'X'. + * ---------------------------------------------------------------------- */ + + String *exportedName(String *name) { + String *copy = Copy(name); + char c = *Char(copy); + if (islower(c)) { + char l[2]; + char u[2]; + l[0] = c; + l[1] = '\0'; + u[0] = toupper(c); + u[1] = '\0'; + Replace(copy, l, u, DOH_REPLACE_FIRST); + } else if (!isalpha(c)) { + char l[2]; + char u[3]; + l[0] = c; + l[1] = '\0'; + u[0] = 'X'; + u[1] = c; + u[2] = '\0'; + Replace(copy, l, u, DOH_REPLACE_FIRST); + } + String *ret = Swig_name_mangle(copy); + Delete(copy); + return ret; + } + + /* ---------------------------------------------------------------------- + * removeClassname() + * + * If the name starts with the current class name, followed by an + * underscore, remove it. If there is no current class name, this + * simply returns a copy of the name. This undoes Swig's way of + * recording the class name in a member name. + * ---------------------------------------------------------------------- */ + + String *removeClassname(String *name) { + String *copy = Copy(name); + if (class_name != NULL) { + char *p = Char(name); + if (Strncmp(name, class_name, Len(class_name)) == 0 + && p[Len(class_name)] == '_') { + Replace(copy, class_name, "", DOH_REPLACE_FIRST); + Replace(copy, "_", "", DOH_REPLACE_FIRST); + } + } + return copy; + } + + /* ---------------------------------------------------------------------- + * buildGoName() + * + * Build the name to use for an ordinary function, variable, or + * whatever in Go. The name argument is something like the sym:name + * attribute of the node. If is_static is false, this could be a + * method, and the returned name will be the name of the + * method--i.e., it will not include the class name. + * ---------------------------------------------------------------------- */ + + String *buildGoName(String *name, bool is_static, bool is_friend) { + String *nw = NewString(""); + if (is_static && !is_friend && class_name != NULL) { + String *c1 = exportedName(class_name); + Append(nw, c1); + Delete(c1); + } + String *c2 = removeClassname(name); + String *c3 = exportedName(c2); + Append(nw, c3); + Delete(c2); + Delete(c3); + String *ret = Swig_name_mangle(nw); + Delete(nw); + return ret; + } + + /* ---------------------------------------------------------------------- + * buildGoWrapperName() + * + * Build the name to use for a Go wrapper function. This is a + * function called by the real Go function in order to convert C++ + * classes from interfaces to pointers, and other such conversions + * between the Go type and the C++ type. + * ---------------------------------------------------------------------- */ + + String *buildGoWrapperName(String *name, String *overname) { + String *s1 = NewString("_swig_wrap_"); + Append(s1, name); + String *s2 = Swig_name_mangle(s1); + Delete(s1); + if (overname != NULL) { + Append(s2, overname); + } + return s2; + } + + /* ---------------------------------------------------------------------- + * goType() + * + * Given a SWIG type, return a string for the type in Go. + * ---------------------------------------------------------------------- */ + + String *goType(Node *n, SwigType *type) { + return goTypeWithInfo(n, type, NULL); + } + + /* ---------------------------------------------------------------------- + * goTypeWithInfo() + * + * Like goType, but return some more information. + * + * 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 + * code needs to make some adjustments when passing values back and + * forth with C/C++. + * ---------------------------------------------------------------------- */ + + String *goTypeWithInfo(Node *n, SwigType *type, bool *p_is_interface) { + if (p_is_interface != NULL) { + *p_is_interface = false; + } + + String *ret; + if (n != NULL && Cmp(type, Getattr(n, "type")) == 0) { + ret = NULL; + if (Strcmp(Getattr(n, "nodeType"), "parm") == 0) { + ret = Getattr(n, "tmap:go"); + } + if (ret == NULL) { + ret = Swig_typemap_lookup("go", n, "", NULL); + } + } else { + Parm *p = NewParmWithoutFileLineInfo(type, "goType"); + ret = Swig_typemap_lookup("go", p, "", NULL); + Delete(p); + } + + if (Strstr(ret, "$gotypename") != NULL) { + ret = NULL; + } + + if (ret != NULL) { + return Copy(ret); + } + + SwigType *t = SwigType_typedef_resolve_all(type); + + Node *e = Language::enumLookup(t); + if (e != NULL) { + ret = goEnumName(e); + } else if (Strcmp(t, "enum ") == 0) { + ret = NewString("int"); + } else if (SwigType_isfunctionpointer(type) || SwigType_isfunction(type)) { + ret = NewString("_swig_fnptr"); + } else if (SwigType_ismemberpointer(type)) { + ret = NewString("_swig_memberptr"); + } else if (SwigType_issimple(t)) { + Node *cn = classLookup(t); + if (cn != NULL) { + ret = Getattr(cn, "sym:name"); + if (ret == NULL) { + ret = Getattr(cn, "name"); + } + ret = exportedName(ret); + + Node *cnmod = Getattr(cn, "module"); + if (cnmod == NULL || Strcmp(Getattr(cnmod, "name"), package) == 0) { + Setattr(undefined_types, t, t); + } else { + String *nw = NewString(""); + Printv(nw, Getattr(cnmod, "name"), ".", ret, NULL); + Delete(ret); + ret = nw; + } + } else { + // SWIG does not know about this type. + ret = exportedName(t); + Setattr(undefined_types, t, t); + } + if (p_is_interface != NULL) { + *p_is_interface = true; + } + } else if (SwigType_ispointer(t) || SwigType_isarray(t)) { + SwigType *r = Copy(t); + if (SwigType_ispointer(r)) { + SwigType_del_pointer(r); + } else { + SwigType_del_array(r); + } + + if (SwigType_type(r) == T_VOID) { + ret = NewString("uintptr"); + } else { + bool is_interface; + String *base = goTypeWithInfo(n, r, &is_interface); + + // At the Go level, an unknown or class type is handled as an + // interface wrapping a pointer. This means that if a + // function returns the C type X, we will be wrapping the C + // type X*. In Go we will call that type X. That means that + // if a C function expects X*, we can pass the Go type X. And + // that means that when we see the C type X*, we should use + // the Go type X. + + // The is_interface variable tells us this. However, it will + // be true both for the case of X and for the case of X*. If + // r is a pointer here, then we are looking at X**. There is + // really no good way for us to handle that. + bool is_pointer_to_pointer = false; + if (is_interface) { + SwigType *c = Copy(r); + if (SwigType_isqualifier(c)) { + SwigType_del_qualifier(c); + if (SwigType_ispointer(c) || SwigType_isarray(c)) { + is_pointer_to_pointer = true; + } + } + Delete(c); + } + + if (is_interface) { + if (!is_pointer_to_pointer) { + ret = base; + if (p_is_interface != NULL) { + *p_is_interface = true; + } + } else { + ret = NewString("uintptr"); + } + } else { + ret = NewString("*"); + Append(ret, base); + Delete(base); + } + } + + Delete(r); + } else if (SwigType_isreference(t)) { + SwigType *r = Copy(t); + SwigType_del_reference(r); + + // If this is a const reference, and we are looking at a pointer + // to it, then we just use the pointer we already have. + bool add_pointer = true; + if (SwigType_isqualifier(r)) { + String *q = SwigType_parm(r); + if (Strcmp(q, "const") == 0) { + SwigType *c = Copy(r); + SwigType_del_qualifier(c); + if (SwigType_ispointer(c)) { + add_pointer = false; + } + Delete(c); + } + } + if (add_pointer) { + SwigType_add_pointer(r); + } + ret = goTypeWithInfo(n, r, 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); + Delete(r); + } + + Delete(t); + + if (ret == NULL) { + Swig_warning(WARN_LANG_NATIVE_UNIMPL, input_file, line_number, + "No Go typemap defined for %s\n", + SwigType_str(type, 0)); + ret = NewString("uintptr"); + } + + return ret; + } + + /* ---------------------------------------------------------------------- + * goWrapperType() + * + * Given a type, return a string for the type to use for the wrapped + * Go function. This function exists because for a C++ class we + * need to convert interface and reference types. + * ---------------------------------------------------------------------- */ + + String *goWrapperType(Node *n, SwigType *type, bool is_result) { + bool is_interface; + String *ret = goTypeWithInfo(n, type, &is_interface); + + // If this is an interface, we want to pass the real type. + if (is_interface) { + Delete(ret); + if (!is_result) { + ret = NewString("uintptr"); + } else { + SwigType *ty = SwigType_typedef_resolve_all(type); + while (true) { + if (SwigType_ispointer(ty)) { + SwigType_del_pointer(ty); + } else if (SwigType_isarray(ty)) { + SwigType_del_array(ty); + } else if (SwigType_isreference(ty)) { + SwigType_del_reference(ty); + } else if (SwigType_isqualifier(ty)) { + SwigType_del_qualifier(ty); + } else { + break; + } + } + assert(SwigType_issimple(ty)); + String *p = goCPointerType(ty, true); + Delete(ty); + ret = p; + } + } + + return ret; + } + + /* ---------------------------------------------------------------------- + * goCPointerType() + * + * Return the name of the Go type to use for the C pointer value. + * The regular C type is the name of an interface type which wraps a + * pointer whose name is returned by this function. + * ---------------------------------------------------------------------- */ + + String *goCPointerType(SwigType *type, bool add_to_hash) { + SwigType *ty = SwigType_typedef_resolve_all(type); + Node *cn = classLookup(ty); + String *ex; + String *ret; + if (cn == NULL) { + if (add_to_hash) { + Setattr(undefined_types, ty, ty); + } + ret = NewString("Swigcptr"); + ex = exportedName(ty); + Append(ret, ex); + } else { + String *cname = Getattr(cn, "sym:name"); + if (cname == NULL) { + cname = Getattr(cn, "name"); + } + ex = exportedName(cname); + Node *cnmod = Getattr(cn, "module"); + if (cnmod == NULL || Strcmp(Getattr(cnmod, "name"), package) == 0) { + if (add_to_hash) { + Setattr(undefined_types, ty, ty); + } + ret = NewString("Swigcptr"); + Append(ret, ex); + } else { + ret = NewString(""); + Printv(ret, Getattr(cnmod, "name"), ".Swigcptr", ex, NULL); + } + } + Delete(ty); + Delete(ex); + return ret; + } + + /* ---------------------------------------------------------------------- + * gcCTypeForGoValue() + * + * Given a type, return the C/C++ type which will be used to catch + * the value in Go. This is the 6g/8g version. + * ---------------------------------------------------------------------- */ + + String *gcCTypeForGoValue(Node *n, SwigType *type, String *name) { + bool is_interface; + String *gt = goTypeWithInfo(n, type, &is_interface); + bool is_string = Strcmp(gt, "string") == 0; + bool is_slice = Strncmp(gt, "[]", 2) == 0; + bool is_function = Strcmp(gt, "_swig_fnptr") == 0; + bool is_member = Strcmp(gt, "_swig_memberptr") == 0; + bool is_complex = Strcmp(gt, "complex") == 0; + bool is_complex64 = Strcmp(gt, "complex64") == 0; + bool is_complex128 = Strcmp(gt, "complex128") == 0; + Delete(gt); + + String *ret; + 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); + return ret; + } else if (is_slice) { + ret = NewString("_goslice_ "); + } else if (is_function || is_member) { + ret = NewString("void *"); + Append(ret, name); + return ret; + } else if (is_complex || is_complex64) { + ret = NewString("_Complex float "); + } else if (is_complex128) { + ret = NewString("_Complex double "); + } else if (is_interface) { + SwigType *t = SwigType_typedef_resolve_all(type); + SwigType_strip_qualifiers(t); + if (SwigType_ispointer(t)) { + SwigType_del_pointer(t); + SwigType_strip_qualifiers(t); + } + if (SwigType_isreference(t)) { + SwigType_del_reference(t); + SwigType_strip_qualifiers(t); + } + SwigType_add_pointer(t); + ret = SwigType_lstr(t, name); + Delete(t); + return ret; + } else { + SwigType *t = SwigType_typedef_resolve_all(type); + if (SwigType_isreference(t)) { + // A const reference to a known type, or to a pointer, is not + // mapped to a pointer. + SwigType_del_reference(t); + if (SwigType_isqualifier(t)) { + String *q = SwigType_parm(t); + if (Strcmp(q, "const") == 0) { + SwigType_del_qualifier(t); + if (hasGoTypemap(t) || SwigType_ispointer(t)) { + ret = SwigType_lstr(t, name); + Delete(q); + Delete(t); + return ret; + } + } + Delete(q); + } + } + Delete(t); + return SwigType_lstr(type, name); + } + + if (SwigType_isreference(type)) { + Append(ret, "* "); + } + Append(ret, name); + return ret; + } + + /* ---------------------------------------------------------------------- + * gcCTypeForGoValue() + * + * Given a type, return the C/C++ type which will be used to catch + * the value in Go. This is the gccgo version. + * ---------------------------------------------------------------------- */ + + String *gccgoCTypeForGoValue(Node *n, SwigType *type, String *name) { + return gcCTypeForGoValue(n, type, name); + } + + /* ------------------------------------------------------------ + * goTypeIsInterface + * + * Return whether this C++ type is represented as an interface type + * in Go. These types require adjustments in the Go code when + * passing them back and forth between Go and C++. + * ------------------------------------------------------------ */ + + bool goTypeIsInterface(Node *n, SwigType *type) { + bool is_interface; + Delete(goTypeWithInfo(n, type, &is_interface)); + return is_interface; + } + + /* ------------------------------------------------------------ + * hasGoTypemap + * + * Return whether a type has a "go" typemap entry. + * ------------------------------------------------------------ */ + + bool hasGoTypemap(SwigType *type) { + Parm *p = NewParmWithoutFileLineInfo(type, "test"); + SwigType *tm = Swig_typemap_lookup("go", p, "", NULL); + Delete(p); + if (tm != NULL && Strstr(tm, "$gotypename") == NULL) { + Delete(tm); + return true; + } + if (tm != NULL) { + Delete(tm); + } + return false; + } + + /* ---------------------------------------------------------------------- + * goEnumName() + * + * Given an enum node, return a string to use for the enum type in + * Go. + * ---------------------------------------------------------------------- */ + + String *goEnumName(Node *n) { + String *ret = Getattr(n, "go:enumname"); + if (ret != NULL) { + return Copy(ret); + } + + if (Strcmp(Getattr(n, "type"), "enum ") == 0) { + return NewString("int"); + } + + String *type = Getattr(n, "enumtype"); + assert(type != NULL); + char *p = Char(type); + int len = Len(type); + String *s = NewString(""); + bool capitalize = true; + for (int i = 0; i < len; ++i, ++p) { + if (*p == ':') { + ++i; + ++p; + assert(*p == ':'); + capitalize = true; + } else if (capitalize) { + Putc(toupper(*p), s); + capitalize = false; + } else { + Putc(*p, s); + } + } + + ret = Swig_name_mangle(s); + Delete(s); + return ret; + } + + + /* ------------------------------------------------------------ + * getParm() + * + * Get the real parameter to use. + * ------------------------------------------------------------ */ + + Parm *getParm(Parm *p) { + while (p != NULL && checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + } + return p; + } + + /* ------------------------------------------------------------ + * nextParm() + * + * Return the next parameter. + * ------------------------------------------------------------ */ + + Parm *nextParm(Parm *p) { + if (p == NULL) { + return NULL; + } else if (Getattr(p, "tmap:in") != NULL) { + return Getattr(p, "tmap:in:next"); + } else { + return nextSibling(p); + } + } + + /* ------------------------------------------------------------ + * isStatic + * + * Return whether a node should be considered as static rather than + * as a member. + * ------------------------------------------------------------ */ + + bool isStatic(Node *n) { + String *storage = Getattr(n, "storage"); + return (storage != NULL + && (Strcmp(storage, "static") == 0 + || Strcmp(storage, "friend") == 0) + && (!SmartPointer + || Getattr(n, "allocate:smartpointeraccess") == NULL)); + } + + /* ------------------------------------------------------------ + * isFriend + * + * Return whether a node is a friend. + * ------------------------------------------------------------ */ + + bool isFriend(Node *n) { + String *storage = Getattr(n, "storage"); + return storage != NULL && Strcmp(storage, "friend") == 0; + } + +}; /* class GO */ + +/* ----------------------------------------------------------------------------- + * swig_go() - Instantiate module + * ----------------------------------------------------------------------------- */ + +static Language *new_swig_go() { + return new GO(); +} +extern "C" Language *swig_go(void) { + return new_swig_go(); +} + +/* ----------------------------------------------------------------------------- + * Static member variables + * ----------------------------------------------------------------------------- */ + +// Usage message. +const char * const GO::usage = (char *) "\ +Go Options (available with -go)\n\ + -package - set name of the Go package to \n\ + -gccgo - generate code for gccgo rather than 6g/8g\n\ + -go-prefix

      - like gccgo -fgo-prefix option\n\ + -soname - name for shared library holding C/C++ code\n\ + -longsize - set size of C/C++ long type--32 or 64 bits\n\ + -rename = - rename symbols\n\ +\n"; diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index 65deee2de..a62bdc1bf 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -59,7 +59,7 @@ void Wrapper_cast_dispatch_mode_set(int flag) { * languages ignore the first method parsed. * ----------------------------------------------------------------------------- */ -static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { +List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { Overloaded nodes[MAX_OVERLOAD]; int nnodes = 0; Node *o = Getattr(n, "sym:overloaded"); diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index e4b246c4e..8f5503743 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1299,6 +1299,8 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, Printf(stderr, "Adding accessor: %s (%s) => %s\n", memberName, name, tmp); } +#define Swig_overload_rank R_swig_overload_rank + #define MAX_OVERLOAD 256 struct Overloaded { diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx index 1ed85e82e..86cccdf88 100644 --- a/Source/Modules/swigmain.cxx +++ b/Source/Modules/swigmain.cxx @@ -51,6 +51,7 @@ extern "C" { Language *swig_cffi(void); Language *swig_uffi(void); Language *swig_r(void); + Language *swig_go(void); } struct swig_module { @@ -69,6 +70,7 @@ static swig_module modules[] = { {"-clisp", swig_clisp, "CLISP"}, {"-cffi", swig_cffi, "CFFI"}, {"-csharp", swig_csharp, "C#"}, + {"-go", swig_go, "Go"}, {"-guile", swig_guile, "Guile"}, {"-java", swig_java, "Java"}, {"-lua", swig_lua, "Lua"}, diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 016ccc8d4..b0b488d6f 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -344,6 +344,7 @@ void Swig_overload_check(Node *n); String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *); String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *); String *Swig_overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int *); +List *Swig_overload_rank(Node *n, bool script_lang_wrapping); SwigType *cplus_value_type(SwigType *t); /* directors.cxx start */ diff --git a/configure.in b/configure.in index fe95fa7c0..f08ad4615 100644 --- a/configure.in +++ b/configure.in @@ -1950,6 +1950,35 @@ fi AC_SUBST(RBIN) +#---------------------------------------------------------------- +# Look for Go compilers +#---------------------------------------------------------------- + +AC_ARG_WITH(go, AS_HELP_STRING([--without-go], [Disable Go]) +AS_HELP_STRING([--with-go=path], [Set location of Go compiler]),[GOBIN="$withval"], [GOBIN=yes]) + +if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then +AC_MSG_NOTICE([Disabling Go]) +GO= +GOGCC=false +else + + if test "x$GOBIN" = xyes; then + AC_CHECK_PROGS(GO, 6g 8g gccgo) + else + GO="$GOBIN" + fi + + GOGCC=false + if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then + GOGCC=true + fi + +fi + +AC_SUBST(GOGCC) +AC_SUBST(GO) + #---------------------------------------------------------------- # Determine which languages to use for examples/test-suite #---------------------------------------------------------------- @@ -2100,6 +2129,12 @@ SKIP_UFFI= #fi AC_SUBST(SKIP_UFFI) +SKIP_GO= +if test -z "$GO" ; then + SKIP_GO="1" +fi +AC_SUBST(SKIP_GO) + #---------------------------------------------------------------- # Additional language dependencies #---------------------------------------------------------------- @@ -2178,6 +2213,7 @@ AC_CONFIG_FILES([ \ Examples/test-suite/cffi/Makefile \ Examples/test-suite/uffi/Makefile \ Examples/test-suite/r/Makefile \ + Examples/test-suite/go/Makefile \ Lib/ocaml/swigp4.ml ]) AC_CONFIG_FILES([preinst-swig], [chmod +x preinst-swig]) From c7a6e3dad4d41c111b81b75f92a1b8cf56a85991 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 10 Jun 2010 02:34:25 +0000 Subject: [PATCH 162/203] Fix // comments to /* */ in typemaps which should be usable from C code. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12109 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/globalvar.i | 2 +- Lib/php/phprun.swg | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index 3463691d5..17f4995a6 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -96,7 +96,7 @@ MAKE_STD_ZVAL(z_var); z_var->type = IS_STRING; if ($1) { - // varinit char [ANY] + /* varinit char [ANY] */ ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1); } zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL); diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index e76f7033a..a7573f35d 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -24,11 +24,11 @@ extern "C" { #endif #ifndef Z_SET_ISREF_P -// For PHP < 5.3 +/* For PHP < 5.3 */ # define Z_SET_ISREF_P(z) (z)->is_ref = 1 #endif #ifndef Z_SET_REFCOUNT_P -// For PHP < 5.3 +/* For PHP < 5.3 */ # define Z_SET_REFCOUNT_P(z, rc) (z)->refcount = (rc) #endif From f67c0fa12c35026d804bf9ccafa0ca464106a403 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 10 Jun 2010 04:41:11 +0000 Subject: [PATCH 163/203] [PHP] Fix directors to correctly call a method with has a different name in PHP to C++ (we were always using the C++ name in this case). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12110 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Source/Modules/php.cxx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 331e9d8dd..471a9c5f4 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-06-10: olly + [PHP] Fix directors to correctly call a method with has a + different name in PHP to C++ (we were always using the C++ name + in this case). + 2010-06-03: wsfulton Fix uncompileable code when %rename results in two enum items with the same name. Reported by Vadim Zeitlin. diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index bd751f767..e82c5041d 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2565,7 +2565,7 @@ done: } Append(w->code, "zval *result, funcname;\n"); Append(w->code, "MAKE_STD_ZVAL(result);\n"); - Printf(w->code, "ZVAL_STRING(&funcname, (char *)\"%s\", 0);\n", name); + Printf(w->code, "ZVAL_STRING(&funcname, (char *)\"%s\", 0);\n", GetChar(n, "sym:name")); Append(w->code, "if (!swig_self) {\n"); Append(w->code, " SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");"); Append(w->code, "}\n\n"); From 1a317ff3dbc032a5410437ce2f86c3712434c984 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 10 Jun 2010 06:06:12 +0000 Subject: [PATCH 164/203] Add C# example showing how to modify the underlying enum type git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12111 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/CSharp.html | 33 +++++++++++++++++++++++++++ Examples/test-suite/csharp_typemaps.i | 7 ++++++ 2 files changed, 40 insertions(+) diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index ea8b66e65..909357f37 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -38,6 +38,7 @@

    • A date example demonstrating marshalling of C# properties
    • Turning wrapped classes into partial classes
    • Extending proxy classes with additional C# code +
    • Underlying type for enums
    @@ -2400,6 +2401,38 @@ public class ExtendMe : IDisposable { +

    18.6.7 Underlying type for enums

    + + +

    +C# enums use int as the underlying type for each enum item. +If you wish to change the underlying type to something else, then use the csbase typemap. +For example when your C++ code uses a value larget than int, this is necessary as the C# compiler will not compile values which are too large to fit into an int. +Here is an example: +

    + +
    +
    +%typemap(csbase) BigNumbers "uint"
    +%inline %{
    +  enum BigNumbers { big=0x80000000, bigger };
    +%}
    +
    +
    + +

    +The generated enum will then use the given underlying type and compile correctly: +

    + +
    +
    +public enum BigNumbers : uint {
    +  big = 0x80000000,
    +  bigger
    +}
    +
    +
    + diff --git a/Examples/test-suite/csharp_typemaps.i b/Examples/test-suite/csharp_typemaps.i index b940f25a3..18896456e 100644 --- a/Examples/test-suite/csharp_typemaps.i +++ b/Examples/test-suite/csharp_typemaps.i @@ -110,3 +110,10 @@ struct WasCrashing {}; void hoop(WasCrashing was) {} %} + +// Enum underlying type +%typemap(csbase) BigNumbers "uint" +%inline %{ +enum BigNumbers { big=0x80000000, bigger }; +%} + From 863aab5b4c388342a5839c4728458ca2ea5a2608 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 10 Jun 2010 06:10:55 +0000 Subject: [PATCH 165/203] Chapter renumbering after Go added git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12112 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 62 +++++++++--- Doc/Manual/Extending.html | 100 +++++++++---------- Doc/Manual/Guile.html | 42 ++++---- Doc/Manual/Java.html | 204 +++++++++++++++++++------------------- Doc/Manual/Lisp.html | 22 ++-- Doc/Manual/Lua.html | 74 +++++++------- Doc/Manual/Modula3.html | 40 ++++---- Doc/Manual/Mzscheme.html | 4 +- Doc/Manual/Ocaml.html | 62 ++++++------ Doc/Manual/Octave.html | 46 ++++----- Doc/Manual/Perl5.html | 94 +++++++++--------- Doc/Manual/Php.html | 48 ++++----- Doc/Manual/Pike.html | 24 ++--- Doc/Manual/Python.html | 146 +++++++++++++-------------- Doc/Manual/R.html | 16 +-- Doc/Manual/Ruby.html | 196 ++++++++++++++++++------------------ Doc/Manual/Tcl.html | 92 ++++++++--------- 17 files changed, 651 insertions(+), 621 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 27337ea7a..25d2dbf9c 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -657,6 +657,7 @@
  • A date example demonstrating marshalling of C# properties
  • Turning wrapped classes into partial classes
  • Extending proxy classes with additional C# code +
  • Underlying type for enums @@ -700,7 +701,36 @@ -

    20 SWIG and Guile

    +

    20 SWIG and Go

    + + + + + +

    21 SWIG and Guile

    @@ -735,7 +765,7 @@
    -

    21 SWIG and Java

    +

    22 SWIG and Java

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

    22 SWIG and Common Lisp

    +

    23 SWIG and Common Lisp

    @@ -900,7 +930,7 @@
    -

    23 SWIG and Lua

    +

    24 SWIG and Lua

    @@ -957,7 +987,7 @@
    -

    24 SWIG and Modula-3

    +

    25 SWIG and Modula-3

    @@ -995,7 +1025,7 @@
    -

    25 SWIG and MzScheme

    +

    26 SWIG and MzScheme

    @@ -1005,7 +1035,7 @@
    -

    26 SWIG and Ocaml

    +

    27 SWIG and Ocaml

    @@ -1056,7 +1086,7 @@
    -

    27 SWIG and Octave

    +

    28 SWIG and Octave

    @@ -1091,7 +1121,7 @@
    -

    28 SWIG and Perl5

    +

    29 SWIG and Perl5

    @@ -1158,7 +1188,7 @@
    -

    29 SWIG and PHP

    +

    30 SWIG and PHP

    @@ -1198,7 +1228,7 @@
    -

    30 SWIG and Pike

    +

    31 SWIG and Pike

    @@ -1222,7 +1252,7 @@
    -

    31 SWIG and Python

    +

    32 SWIG and Python

    @@ -1325,7 +1355,7 @@
    -

    32 SWIG and Ruby

    +

    33 SWIG and Ruby

    @@ -1459,7 +1489,7 @@
    -

    33 SWIG and Tcl

    +

    34 SWIG and Tcl

    @@ -1525,7 +1555,7 @@
    -

    34 SWIG and R

    +

    35 SWIG and R

    @@ -1541,7 +1571,7 @@
    -

    35 Extending SWIG to support new languages

    +

    36 Extending SWIG to support new languages

    diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index bb50d3878..c554d9f05 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -6,7 +6,7 @@ -

    35 Extending SWIG to support new languages

    +

    36 Extending SWIG to support new languages

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

      35.1 Introduction

      +

      36.1 Introduction

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

      -

      35.2 Prerequisites

      +

      36.2 Prerequisites

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

      -

      35.3 The Big Picture

      +

      36.3 The Big Picture

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

      -

      35.4 Execution Model

      +

      36.4 Execution Model

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

      -

      35.4.1 Preprocessing

      +

      36.4.1 Preprocessing

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

      -

      35.4.2 Parsing

      +

      36.4.2 Parsing

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

      -

      35.4.3 Parse Trees

      +

      36.4.3 Parse Trees

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

    -

    35.4.4 Attribute namespaces

    +

    36.4.4 Attribute namespaces

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

    -

    35.4.5 Symbol Tables

    +

    36.4.5 Symbol Tables

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

    -

    35.4.6 The %feature directive

    +

    36.4.6 The %feature directive

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

    -

    35.4.7 Code Generation

    +

    36.4.7 Code Generation

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

    -

    35.4.8 SWIG and XML

    +

    36.4.8 SWIG and XML

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

    -

    35.5 Primitive Data Structures

    +

    36.5 Primitive Data Structures

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

    35.5.1 Strings

    +

    36.5.1 Strings

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

    35.5.2 Hashes

    +

    36.5.2 Hashes

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

    35.5.3 Lists

    +

    36.5.3 Lists

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

    35.5.4 Common operations

    +

    36.5.4 Common operations

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

    35.5.5 Iterating over Lists and Hashes

    +

    36.5.5 Iterating over Lists and Hashes

    To iterate over the elements of a list or a hash table, the following functions are used: @@ -1394,7 +1394,7 @@ for (j = First(j); j.item; j= Next(j)) { -

    35.5.6 I/O

    +

    36.5.6 I/O

    Special I/O functions are used for all internal I/O. These operations @@ -1531,7 +1531,7 @@ Similarly, the preprocessor and parser all operate on string-files. -

    35.6 Navigating and manipulating parse trees

    +

    36.6 Navigating and manipulating parse trees

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

    35.7 Working with attributes

    +

    36.7 Working with attributes

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

    35.8 Type system

    +

    36.8 Type system

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

    -

    35.8.1 String encoding of types

    +

    36.8.1 String encoding of types

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

    -

    35.8.2 Type construction

    +

    36.8.2 Type construction

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

    35.8.3 Type tests

    +

    36.8.3 Type tests

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

    35.8.4 Typedef and inheritance

    +

    36.8.4 Typedef and inheritance

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

    35.8.5 Lvalues

    +

    36.8.5 Lvalues

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

    35.8.6 Output functions

    +

    36.8.6 Output functions

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

    35.9 Parameters

    +

    36.9 Parameters

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

    35.10 Writing a Language Module

    +

    36.10 Writing a Language Module

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

    -

    35.10.1 Execution model

    +

    36.10.1 Execution model

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

    -

    35.10.2 Starting out

    +

    36.10.2 Starting out

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

    -

    35.10.3 Command line options

    +

    36.10.3 Command line options

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

    -

    35.10.4 Configuration and preprocessing

    +

    36.10.4 Configuration and preprocessing

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

    -

    35.10.5 Entry point to code generation

    +

    36.10.5 Entry point to code generation

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

    35.10.6 Module I/O and wrapper skeleton

    +

    36.10.6 Module I/O and wrapper skeleton

    @@ -2895,7 +2895,7 @@ functionWrapper : void Shape_y_set(Shape *self,double y) -

    35.10.7 Low-level code generators

    +

    36.10.7 Low-level code generators

    @@ -3049,7 +3049,7 @@ but without the typemaps, there is still work to do.

    -

    35.10.8 Configuration files

    +

    36.10.8 Configuration files

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

    35.10.9 Runtime support

    +

    36.10.9 Runtime support

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

    -

    35.10.10 Standard library files

    +

    36.10.10 Standard library files

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

    -

    35.10.11 User examples

    +

    36.10.11 User examples

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

    -

    35.10.12 Test driven development and the test-suite

    +

    36.10.12 Test driven development and the test-suite

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

    -

    35.10.12.1 Running the test-suite

    +

    36.10.12.1 Running the test-suite

    @@ -3477,7 +3477,7 @@ A debugger can also be invoked easily on an individual test, for example gdb: make ret_by_value.ctest RUNTOOL="gdb --args" -

    35.10.13 Documentation

    +

    36.10.13 Documentation

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

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

    +

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

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

    -

    35.10.15 Coding style guidelines

    +

    36.10.15 Coding style guidelines

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

    -

    35.11 Debugging Options

    +

    36.11 Debugging Options

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

    -

    35.12 Guide to parse tree nodes

    +

    36.12 Guide to parse tree nodes

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

    35.13 Further Development Information

    +

    36.13 Further Development Information

    diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 8f3c5f85c..75c3d3473 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -8,7 +8,7 @@ -

    20 SWIG and Guile

    +

    21 SWIG and Guile

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

      This section details guile-specific support in SWIG. -

      20.1 Meaning of "Module"

      +

      21.1 Meaning of "Module"

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

      20.2 Using the SCM or GH Guile API

      +

      21.2 Using the SCM or GH Guile API

      The guile module can currently export wrapper files that use the guile GH interface or the @@ -103,7 +103,7 @@ for the specific API. Currently only the guile language module has created a ma but there is no reason other languages (like mzscheme or chicken) couldn't also use this. If that happens, there is A LOT less code duplication in the standard typemaps.

      -

      20.3 Linkage

      +

      21.3 Linkage

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

      20.3.1 Simple Linkage

      +

      21.3.1 Simple Linkage

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

      20.3.2 Passive Linkage

      +

      21.3.2 Passive Linkage

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

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

      20.3.3 Native Guile Module Linkage

      +

      21.3.3 Native Guile Module Linkage

      SWIG can also generate wrapper code that does all the Guile module @@ -257,7 +257,7 @@ Newer Guile versions have a shorthand procedure for this:

    -

    20.3.4 Old Auto-Loading Guile Module Linkage

    +

    21.3.4 Old Auto-Loading Guile Module Linkage

    Guile used to support an autoloading facility for object-code @@ -283,7 +283,7 @@ option, SWIG generates an exported module initialization function with an appropriate name. -

    20.3.5 Hobbit4D Linkage

    +

    21.3.5 Hobbit4D Linkage

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

    -

    20.4 Underscore Folding

    +

    21.4 Underscore Folding

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

    20.5 Typemaps

    +

    21.5 Typemaps

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

    -

    20.6 Representation of pointers as smobs

    +

    21.6 Representation of pointers as smobs

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

    20.6.1 GH Smobs

    +

    21.6.1 GH Smobs

    @@ -462,7 +462,7 @@ that created them, so the first module we check will most likely be correct. Once we have a swig_type_info structure, we loop through the linked list of casts, using pointer comparisons.

    -

    20.6.2 SCM Smobs

    +

    21.6.2 SCM Smobs

    The SCM interface (using the "-scm" argument to swig) uses swigrun.swg. @@ -477,7 +477,7 @@ in the smob tag. If a generated GOOPS module has been loaded, smobs will be wra GOOPS class.

    -

    20.6.3 Garbage Collection

    +

    21.6.3 Garbage Collection

    Garbage collection is a feature of the new SCM interface, and it is automatically included @@ -491,7 +491,7 @@ is exactly like described in 20.7 Exception Handling +

    21.7 Exception Handling

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

    20.8 Procedure documentation

    +

    21.8 Procedure documentation

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

    20.9 Procedures with setters

    +

    21.9 Procedures with setters

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

    20.10 GOOPS Proxy Classes

    +

    21.10 GOOPS Proxy Classes

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

    -

    20.10.1 Naming Issues

    +

    21.10.1 Naming Issues

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

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

    20.10.2 Linking

    +

    21.10.2 Linking

    The guile-modules generated above all need to be linked together. GOOPS support requires diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index c5778c432..f572ffa32 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -5,7 +5,7 @@ -

    21 SWIG and Java

    +

    22 SWIG and Java

      @@ -154,7 +154,7 @@ It covers most SWIG features, but certain low-level details are covered in less

      -

      21.1 Overview

      +

      22.1 Overview

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

      -

      21.2 Preliminaries

      +

      22.2 Preliminaries

      @@ -205,7 +205,7 @@ Run make -k check from the SWIG root directory after installing SWIG on The Java module requires your system to support shared libraries and dynamic loading. This is the commonly used method to load JNI code so your system will more than likely support this.

      -

      21.2.1 Running SWIG

      +

      22.2.1 Running SWIG

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

      -

      21.2.2 Additional Commandline Options

      +

      22.2.2 Additional Commandline Options

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

      -

      21.2.3 Getting the right header files

      +

      22.2.3 Getting the right header files

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

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

      -

      21.2.4 Compiling a dynamic module

      +

      22.2.4 Compiling a dynamic module

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

      -

      21.2.5 Using your module

      +

      22.2.5 Using your module

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

      -

      21.2.6 Dynamic linking problems

      +

      22.2.6 Dynamic linking problems

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

      -

      21.2.7 Compilation problems and compiling with C++

      +

      22.2.7 Compilation problems and compiling with C++

      @@ -527,7 +527,7 @@ Finally make sure the version of JDK header files matches the version of Java th

      -

      21.2.8 Building on Windows

      +

      22.2.8 Building on Windows

      @@ -536,7 +536,7 @@ You will want to produce a DLL that can be loaded by the Java Virtual Machine. This section covers the process of using SWIG with Microsoft Visual C++ 6 although the procedure may be similar with other compilers. In order for everything to work, you will need to have a JDK installed on your machine in order to read the JNI header files.

      -

      21.2.8.1 Running SWIG from Visual Studio

      +

      22.2.8.1 Running SWIG from Visual Studio

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

      -

      21.2.8.2 Using NMAKE

      +

      22.2.8.2 Using NMAKE

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

      -

      21.3 A tour of basic C/C++ wrapping

      +

      22.3 A tour of basic C/C++ wrapping

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

      -

      21.3.1 Modules, packages and generated Java classes

      +

      22.3.1 Modules, packages and generated Java classes

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

      -

      21.3.2 Functions

      +

      22.3.2 Functions

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

    -

    21.3.3 Global variables

    +

    22.3.3 Global variables

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

    21.3.4 Constants

    +

    22.3.4 Constants

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

    -

    21.3.5 Enumerations

    +

    22.3.5 Enumerations

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

    -

    21.3.5.1 Anonymous enums

    +

    22.3.5.1 Anonymous enums

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

    -

    21.3.5.2 Typesafe enums

    +

    22.3.5.2 Typesafe enums

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

    -

    21.3.5.3 Proper Java enums

    +

    22.3.5.3 Proper Java enums

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

    -

    21.3.5.4 Type unsafe enums

    +

    22.3.5.4 Type unsafe enums

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

    -

    21.3.5.5 Simple enums

    +

    22.3.5.5 Simple enums

    @@ -1232,7 +1232,7 @@ SWIG-1.3.21 and earlier versions wrapped all enums using this approach. The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.

    -

    21.3.6 Pointers

    +

    22.3.6 Pointers

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

    -

    21.3.7 Structures

    +

    22.3.7 Structures

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

    21.3.8 C++ classes

    +

    22.3.8 C++ classes

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

    21.3.9 C++ inheritance

    +

    22.3.9 C++ inheritance

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

    -

    21.3.10 Pointers, references, arrays and pass by value

    +

    22.3.10 Pointers, references, arrays and pass by value

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

    -

    21.3.10.1 Null pointers

    +

    22.3.10.1 Null pointers

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

    -

    21.3.11 C++ overloaded functions

    +

    22.3.11 C++ overloaded functions

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

    21.3.12 C++ default arguments

    +

    22.3.12 C++ default arguments

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

    -

    21.3.13 C++ namespaces

    +

    22.3.13 C++ namespaces

    @@ -1927,7 +1927,7 @@ with -package - Java does not support types declared in a named package accessin -

    21.3.14 C++ templates

    +

    22.3.14 C++ templates

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

    -

    21.3.15 C++ Smart Pointers

    +

    22.3.15 C++ Smart Pointers

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

    21.4 Further details on the generated Java classes

    +

    22.4 Further details on the generated Java classes

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

    -

    21.4.1 The intermediary JNI class

    +

    22.4.1 The intermediary JNI class

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

    -

    21.4.1.1 The intermediary JNI class pragmas

    +

    22.4.1.1 The intermediary JNI class pragmas

    @@ -2274,7 +2274,7 @@ For example, let's change the intermediary JNI class access to just the default All the methods in the intermediary JNI class will then not be callable outside of the package as the method modifiers have been changed from public access to default access. This is useful if you want to prevent users calling these low level functions.

    -

    21.4.2 The Java module class

    +

    22.4.2 The Java module class

    @@ -2305,7 +2305,7 @@ example.egg(new Foo()); The primary reason for having the module class wrapping the calls in the intermediary JNI class is to implement static type checking. In this case only a Foo can be passed to the egg function, whereas any long can be passed to the egg function in the intermediary JNI class.

    -

    21.4.2.1 The Java module class pragmas

    +

    22.4.2.1 The Java module class pragmas

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

    -

    21.4.3 Java proxy classes

    +

    22.4.3 Java proxy classes

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

    21.4.3.1 Memory management

    +

    22.4.3.1 Memory management

    @@ -2594,7 +2594,7 @@ and

    -

    21.4.3.2 Inheritance

    +

    22.4.3.2 Inheritance

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

    22.4.3.3 Proxy classes and garbage collection

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

    -

    21.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

    +

    22.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

    @@ -2915,7 +2915,7 @@ For example: Compatibility note: The generation of this additional parameter did not occur in versions prior to SWIG-1.3.30.

    -

    21.4.3.5 Single threaded applications and thread safety

    +

    22.4.3.5 Single threaded applications and thread safety

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

    21.4.4 Type wrapper classes

    +

    22.4.4 Type wrapper classes

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

    21.4.5 Enum classes

    +

    22.4.5 Enum classes

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

    -

    21.4.5.1 Typesafe enum classes

    +

    22.4.5.1 Typesafe enum classes

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

    -

    21.4.5.2 Proper Java enum classes

    +

    22.4.5.2 Proper Java enum classes

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

    -

    21.4.5.3 Type unsafe enum classes

    +

    22.4.5.3 Type unsafe enum classes

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

    21.5 Cross language polymorphism using directors

    +

    22.5 Cross language polymorphism using directors

    @@ -3314,7 +3314,7 @@ The upshot is that C++ classes can be extended in Java and from C++ these extens Neither C++ code nor Java code needs to know where a particular method is implemented: the combination of proxy classes, director classes, and C wrapper functions transparently takes care of all the cross-language method routing.

    -

    21.5.1 Enabling directors

    +

    22.5.1 Enabling directors

    @@ -3385,7 +3385,7 @@ public: -

    21.5.2 Director classes

    +

    22.5.2 Director classes

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

    -

    21.5.3 Overhead and code bloat

    +

    22.5.3 Overhead and code bloat

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

    -

    21.5.4 Simple directors example

    +

    22.5.4 Simple directors example

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

    21.5.5 Director threading issues

    +

    22.5.5 Director threading issues

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

    21.6 Accessing protected members

    +

    22.6 Accessing protected members

    @@ -3611,7 +3611,7 @@ class MyProtectedBase extends ProtectedBase -

    21.7 Common customization features

    +

    22.7 Common customization features

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

    -

    21.7.1 C/C++ helper functions

    +

    22.7.1 C/C++ helper functions

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

    -

    21.7.2 Class extension with %extend

    +

    22.7.2 Class extension with %extend

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

    -

    21.7.3 Exception handling with %exception and %javaexception

    +

    22.7.3 Exception handling with %exception and %javaexception

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

    -

    21.7.4 Method access with %javamethodmodifiers

    +

    22.7.4 Method access with %javamethodmodifiers

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

    21.8 Tips and techniques

    +

    22.8 Tips and techniques

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

    -

    21.8.1 Input and output parameters using primitive pointers and references

    +

    22.8.1 Input and output parameters using primitive pointers and references

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

    -

    21.8.2 Simple pointers

    +

    22.8.2 Simple pointers

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

    -

    21.8.3 Wrapping C arrays with Java arrays

    +

    22.8.3 Wrapping C arrays with Java arrays

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

    -

    21.8.4 Unbounded C Arrays

    +

    22.8.4 Unbounded C Arrays

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

    -

    21.8.5 Overriding new and delete to allocate from Java heap

    +

    22.8.5 Overriding new and delete to allocate from Java heap

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

    -

    21.9 Java typemaps

    +

    22.9 Java typemaps

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

    21.9.1 Default primitive type mappings

    +

    22.9.1 Default primitive type mappings

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

    -

    21.9.2 Default typemaps for non-primitive types

    +

    22.9.2 Default typemaps for non-primitive types

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

    -

    21.9.3 Sixty four bit JVMs

    +

    22.9.3 Sixty four bit JVMs

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

    -

    21.9.4 What is a typemap?

    +

    22.9.4 What is a typemap?

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

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

    +

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

    @@ -5100,7 +5100,7 @@ These are listed below: -

    21.9.6 Java typemap attributes

    +

    22.9.6 Java typemap attributes

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

    -

    21.9.7 Java special variables

    +

    22.9.7 Java special variables

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

    -

    21.9.8 Typemaps for both C and C++ compilation

    +

    22.9.8 Typemaps for both C and C++ compilation

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

    -

    21.9.9 Java code typemaps

    +

    22.9.9 Java code typemaps

    @@ -5540,7 +5540,7 @@ For the typemap to be used in all type wrapper classes, all the different types Again this is the same that is in "java.swg", barring the method modifier for getCPtr.

    -

    21.9.10 Director specific typemaps

    +

    22.9.10 Director specific typemaps

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

    21.10 Typemap Examples

    +

    22.10 Typemap Examples

    @@ -5775,7 +5775,7 @@ the SWIG library.

    -

    21.10.1 Simpler Java enums for enums without initializers

    +

    22.10.1 Simpler Java enums for enums without initializers

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

    -

    21.10.2 Handling C++ exception specifications as Java exceptions

    +

    22.10.2 Handling C++ exception specifications as Java exceptions

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

    -

    21.10.3 NaN Exception - exception handling for a particular type

    +

    22.10.3 NaN Exception - exception handling for a particular type

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

    -

    21.10.4 Converting Java String arrays to char **

    +

    22.10.4 Converting Java String arrays to char **

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

    -

    21.10.5 Expanding a Java object to multiple arguments

    +

    22.10.5 Expanding a Java object to multiple arguments

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

    21.10.6 Using typemaps to return arguments

    +

    22.10.6 Using typemaps to return arguments

    @@ -6478,7 +6478,7 @@ $ java runme 1 12.0 340.0 -

    21.10.7 Adding Java downcasts to polymorphic return types

    +

    22.10.7 Adding Java downcasts to polymorphic return types

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

    -

    21.10.8 Adding an equals method to the Java classes

    +

    22.10.8 Adding an equals method to the Java classes

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

    21.10.9 Void pointers and a common Java base class

    +

    22.10.9 Void pointers and a common Java base class

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

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

    21.10.10 Struct pointer to pointer

    +

    22.10.10 Struct pointer to pointer

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

    -

    21.10.11 Memory management when returning references to member variables

    +

    22.10.11 Memory management when returning references to member variables

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

    -

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

    +

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

    @@ -7206,7 +7206,7 @@ The 'javacode' typemap simply adds in the specified code into the Java proxy cla -

    21.10.13 Date marshalling using the javain typemap and associated attributes

    +

    22.10.13 Date marshalling using the javain typemap and associated attributes

    @@ -7383,7 +7383,7 @@ A few things to note: -

    21.11 Living with Java Directors

    +

    22.11 Living with Java Directors

    @@ -7564,10 +7564,10 @@ public abstract class UserVisibleFoo extends Foo {

  • -

    21.12 Odds and ends

    +

    22.12 Odds and ends

    -

    21.12.1 JavaDoc comments

    +

    22.12.1 JavaDoc comments

    @@ -7623,7 +7623,7 @@ public class Barmy { -

    21.12.2 Functional interface without proxy classes

    +

    22.12.2 Functional interface without proxy classes

    @@ -7684,7 +7684,7 @@ All destructors have to be called manually for example the delete_Foo(foo) -

    21.12.3 Using your own JNI functions

    +

    22.12.3 Using your own JNI functions

    @@ -7734,7 +7734,7 @@ This directive is only really useful if you want to mix your own hand crafted JN

    -

    21.12.4 Performance concerns and hints

    +

    22.12.4 Performance concerns and hints

    @@ -7755,7 +7755,7 @@ However, you will have to be careful about memory management and make sure that This method normally calls the C++ destructor or free() for C code.

    -

    21.12.5 Debugging

    +

    22.12.5 Debugging

    @@ -7777,7 +7777,7 @@ The -verbose:jni and -verbose:gc are also useful options for monitoring code beh

    -

    21.13 Examples

    +

    22.13 Examples

    diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index aa62250b9..b9b5b6c1e 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -6,7 +6,7 @@ -

    22 SWIG and Common Lisp

    +

    23 SWIG and Common Lisp

      @@ -41,7 +41,7 @@ Lisp, Common Foreign Function Interface(CFFI), CLisp and UFFI foreign function interfaces.

      -

      22.1 Allegro Common Lisp

      +

      23.1 Allegro Common Lisp

      @@ -50,7 +50,7 @@ here

      -

      22.2 Common Foreign Function Interface(CFFI)

      +

      23.2 Common Foreign Function Interface(CFFI)

      @@ -77,7 +77,7 @@ swig -cffi -module module-name file-name files and the various things which you can do with them.

      -

      22.2.1 Additional Commandline Options

      +

      23.2.1 Additional Commandline Options

      @@ -118,7 +118,7 @@ swig -cffi -help -

      22.2.2 Generating CFFI bindings

      +

      23.2.2 Generating CFFI bindings

      As we mentioned earlier the ideal way to use SWIG is to use interface @@ -392,7 +392,7 @@ The feature intern_function ensures that all C names are
    -

    22.2.3 Generating CFFI bindings for C++ code

    +

    23.2.3 Generating CFFI bindings for C++ code

    This feature to SWIG (for CFFI) is very new and still far from @@ -568,7 +568,7 @@ If you have any questions, suggestions, patches, etc., related to CFFI module feel free to contact us on the SWIG mailing list, and also please add a "[CFFI]" tag in the subject line. -

    22.2.4 Inserting user code into generated files

    +

    23.2.4 Inserting user code into generated files

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

    -

    22.3 CLISP

    +

    23.3 CLISP

    @@ -638,7 +638,7 @@ swig -clisp -module module-name file-name interface file for the CLISP module. The CLISP module tries to produce code which is both human readable and easily modifyable.

    -

    22.3.1 Additional Commandline Options

    +

    23.3.1 Additional Commandline Options

    @@ -671,7 +671,7 @@ and global variables will be created otherwise only definitions for
    -

    22.3.2 Details on CLISP bindings

    +

    23.3.2 Details on CLISP bindings

    @@ -795,7 +795,7 @@ struct bar { -

    22.4 UFFI

    +

    23.4 UFFI

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index a1544d21e..c07fe66c8 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -6,7 +6,7 @@ -

    23 SWIG and Lua

    +

    24 SWIG and Lua

      @@ -67,13 +67,13 @@

      Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight configuration language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++). Its also a really tiny language, less than 6000 lines of code, which compiles to <100 kilobytes of binary code. It can be found at http://www.lua.org

      -

      23.1 Preliminaries

      +

      24.1 Preliminaries

      The current SWIG implementation is designed to work with Lua 5.0.x and Lua 5.1.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. ((Currently SWIG generated code has only been tested on Windows with MingW, though given the nature of Lua, is should not have problems on other OS's)). It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms).

      -

      23.2 Running SWIG

      +

      24.2 Running SWIG

      @@ -105,7 +105,7 @@ This creates a C/C++ source file example_wrap.c or example_wrap.cxx

      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 wrappered module will export one function "int luaopen_example(lua_State* L)" which must be called to register the module with the Lua interpreter. The name "luaopen_example" depends upon the name of the module.

      -

      23.2.1 Compiling and Linking and Interpreter

      +

      24.2.1 Compiling and Linking and Interpreter

      @@ -152,7 +152,7 @@ $ gcc -c example.c -o example.o $ gcc -I/usr/include/lua -L/usr/lib/lua min.o example_wrap.o example.o -o my_lua

    -

    23.2.2 Compiling a dynamic module

    +

    24.2.2 Compiling a dynamic module

    @@ -220,7 +220,7 @@ Is quite obvious (Go back and consult the Lua documents on how to enable loadlib -

    23.2.3 Using your module

    +

    24.2.3 Using your module

    @@ -238,19 +238,19 @@ $ ./my_lua > -

    23.3 A tour of basic C/C++ wrapping

    +

    24.3 A tour of basic C/C++ wrapping

    By default, SWIG tries to build a very natural Lua interface to your C/C++ code. This section briefly covers the essential aspects of this wrapping.

    -

    23.3.1 Modules

    +

    24.3.1 Modules

    The SWIG module directive specifies the name of the Lua module. If you specify `module example', then everything is wrapped into a Lua table 'example' containing all the functions and variables. When choosing a module name, make sure you don't use the same name as a built-in Lua command or standard module name.

    -

    23.3.2 Functions

    +

    24.3.2 Functions

    @@ -288,7 +288,7 @@ It is also possible to rename the module with an assignment. 24 -

    23.3.3 Global variables

    +

    24.3.3 Global variables

    @@ -362,7 +362,7 @@ nil 3.142 -

    23.3.4 Constants and enums

    +

    24.3.4 Constants and enums

    @@ -385,7 +385,7 @@ example.SUNDAY=0

    Constants are not guaranteed to remain constant in Lua. The name of the constant could be accidentally reassigned to refer to some other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.

    -

    23.3.5 Pointers

    +

    24.3.5 Pointers

    @@ -423,7 +423,7 @@ Lua enforces the integrity of its userdata, so it is virtually impossible to cor nil -

    23.3.6 Structures

    +

    24.3.6 Structures

    @@ -509,7 +509,7 @@ Because the pointer points inside the structure, you can modify the contents and > x.a = 3 -- Modifies the same structure -

    23.3.7 C++ classes

    +

    24.3.7 C++ classes

    @@ -570,7 +570,7 @@ It is not (currently) possible to access static members of an instance: -- does NOT work -

    23.3.8 C++ inheritance

    +

    24.3.8 C++ inheritance

    @@ -595,7 +595,7 @@ then the function spam() accepts a Foo pointer or a pointer to any clas

    It is safe to use multiple inheritance with SWIG.

    -

    23.3.9 Pointers, references, values, and arrays

    +

    24.3.9 Pointers, references, values, and arrays

    @@ -626,7 +626,7 @@ Foo spam7();

    then all three functions will return a pointer to some Foo object. Since the third function (spam7) returns a value, newly allocated memory is used to hold the result and a pointer is returned (Lua will release this memory when the return value is garbage collected). The other two are pointers which are assumed to be managed by the C code and so will not be garbage collected.

    -

    23.3.10 C++ overloaded functions

    +

    24.3.10 C++ overloaded functions

    @@ -712,7 +712,7 @@ Please refer to the "SWIG and C++" chapter for more information about overloadin

    Dealing with the Lua coercion mechanism, the priority is roughly (integers, floats, strings, userdata). But it is better to rename the functions rather than rely upon the ordering.

    -

    23.3.11 C++ operators

    +

    24.3.11 C++ operators

    @@ -824,7 +824,7 @@ It is also possible to overload the operator[], but currently this cann }; -

    23.3.12 Class extension with %extend

    +

    24.3.12 Class extension with %extend

    @@ -879,7 +879,7 @@ true

    Extend works with both C and C++ code, on classes and structs. It does not modify the underlying object in any way---the extensions only show up in the Lua interface. The only item to take note of is the code has to use the '$self' instead of 'this', and that you cannot access protected/private members of the code (as you are not officially part of the class).

    -

    23.3.13 C++ templates

    +

    24.3.13 C++ templates

    @@ -914,7 +914,7 @@ In Lua:

    Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter. Some more complicated examples will appear later.

    -

    23.3.14 C++ Smart Pointers

    +

    24.3.14 C++ Smart Pointers

    @@ -966,7 +966,7 @@ If you ever need to access the underlying pointer returned by operator->( > f = p:__deref__() -- Returns underlying Foo * -

    23.3.15 C++ Exceptions

    +

    24.3.15 C++ Exceptions

    @@ -1110,12 +1110,12 @@ add exception specification to functions or globally (respectively).

    -

    23.4 Typemaps

    +

    24.4 Typemaps

    This section explains what typemaps are and the usage of them. The default wrappering behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrappering. This section will be explaining how to use typemaps to best effect

    -

    23.4.1 What is a typemap?

    +

    24.4.1 What is a typemap?

    A typemap is nothing more than a code generation rule that is attached to a specific C datatype. For example, to convert integers from Lua to C, you might define a typemap like this:

    @@ -1143,7 +1143,7 @@ Received an integer : 6 720 -

    23.4.2 Using typemaps

    +

    24.4.2 Using typemaps

    There are many ready written typemaps built into SWIG for all common types (int, float, short, long, char*, enum and more), which SWIG uses automatically, with no effort required on your part.

    @@ -1196,7 +1196,7 @@ void swap(int *sx, int *sy);

    Note: C++ references must be handled exactly the same way. However SWIG will automatically wrap a const int& as an input parameter (since that it obviously input).

    -

    23.4.3 Typemaps and arrays

    +

    24.4.3 Typemaps and arrays

    Arrays present a challenge for SWIG, because like pointers SWIG does not know whether these are input or output values, nor @@ -1260,7 +1260,7 @@ and Lua tables to be 1..N, (the indexing follows the norm for the language). In

    Note: SWIG also can support arrays of pointers in a similar manner.

    -

    23.4.4 Typemaps and pointer-pointer functions

    +

    24.4.4 Typemaps and pointer-pointer functions

    Several C++ libraries use a pointer-pointer functions to create its objects. These functions require a pointer to a pointer which is then filled with the pointer to the new object. Microsoft's COM and DirectX as well as many other libraries have this kind of function. An example is given below:

    @@ -1294,7 +1294,7 @@ int Create_Math(iMath** pptr); // its creator (assume it mallocs) ptr=nil -- the iMath* will be GC'ed as normal -

    23.5 Writing typemaps

    +

    24.5 Writing typemaps

    This section describes how you can modify SWIG's default wrapping behavior for various C/C++ datatypes using the %typemap directive. This is an advanced topic that assumes familiarity with the Lua C API as well as the material in the "Typemaps" chapter.

    @@ -1303,7 +1303,7 @@ ptr=nil -- the iMath* will be GC'ed as normal

    Before proceeding, you should read the previous section on using typemaps, as well as read the ready written typemaps found in luatypemaps.swg and typemaps.i. These are both well documented and fairly easy to read. You should not attempt to write your own typemaps until you have read and can understand both of these files (they may well also give you a idea to base your worn on).

    -

    23.5.1 Typemaps you can write

    +

    24.5.1 Typemaps you can write

    There are many different types of typemap that can be written, the full list can be found in the "Typemaps" chapter. However the following are the most commonly used ones.

    @@ -1316,7 +1316,7 @@ ptr=nil -- the iMath* will be GC'ed as normal (the syntax for the typecheck is different from the typemap, see typemaps for details). -

    23.5.2 SWIG's Lua-C API

    +

    24.5.2 SWIG's Lua-C API

    This section explains the SWIG specific Lua-C API. It does not cover the main Lua-C api, as this is well documented and not worth covering.

    @@ -1365,7 +1365,7 @@ This macro, when called within the context of a SWIG wrappered function, will di
    Similar to SWIG_fail_arg, except that it will display the swig_type_info information instead.
    -

    23.6 Customization of your Bindings

    +

    24.6 Customization of your Bindings

    @@ -1374,7 +1374,7 @@ This section covers adding of some small extra bits to your module to add the la -

    23.6.1 Writing your own custom wrappers

    +

    24.6.1 Writing your own custom wrappers

    @@ -1393,7 +1393,7 @@ int native_function(lua_State*L) // my native code The %native directive in the above example, tells SWIG that there is a function int native_function(lua_State*L); which is to be added into the module under the name 'my_func'. SWIG will not add any wrappering for this function, beyond adding it into the function table. How you write your code is entirely up to you.

    -

    23.6.2 Adding additional Lua code

    +

    24.6.2 Adding additional Lua code

    @@ -1431,7 +1431,7 @@ Good uses for this feature is adding of new code, or writing helper functions to See Examples/lua/arrays for an example of this code.

    -

    23.7 Details on the Lua binding

    +

    24.7 Details on the Lua binding

    @@ -1442,7 +1442,7 @@ See Examples/lua/arrays for an example of this code.

    -

    23.7.1 Binding global data into the module.

    +

    24.7.1 Binding global data into the module.

    @@ -1502,7 +1502,7 @@ end

    That way when you call 'a=example.Foo', the interpreter looks at the table 'example' sees that there is no field 'Foo' and calls __index. This will in turn check in '.get' table and find the existence of 'Foo' and then return the value of the C function call 'Foo_get()'. Similarly for the code 'example.Foo=10', the interpreter will check the table, then call the __newindex which will then check the '.set' table and call the C function 'Foo_set(10)'.

    -

    23.7.2 Userdata and Metatables

    +

    24.7.2 Userdata and Metatables

    @@ -1582,7 +1582,7 @@ Note: Both the opaque structures (like the FILE*) and normal wrappered classes/s

    Note: Operator overloads are basically done in the same way, by adding functions such as '__add' & '__call' to the classes metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.

    -

    23.7.3 Memory management

    +

    24.7.3 Memory management

    diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index ee7d2785d..71611e3c5 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -5,7 +5,7 @@ -

    24 SWIG and Modula-3

    +

    25 SWIG and Modula-3

      @@ -54,7 +54,7 @@ especially typemaps.

      -

      24.1 Overview

      +

      25.1 Overview

      @@ -84,7 +84,7 @@ FFTW -

      24.1.1 Motivation

      +

      25.1.1 Motivation

      @@ -131,10 +131,10 @@ functions), but it doesn't allow you to easily integrate a Module-3 module into a C/C++ project.

      -

      24.2 Conception

      +

      25.2 Conception

      -

      24.2.1 Interfaces to C libraries

      +

      25.2.1 Interfaces to C libraries

      @@ -283,7 +283,7 @@ and the principal type must be renamed (%typemap).

      -

      24.2.2 Interfaces to C++ libraries

      +

      25.2.2 Interfaces to C++ libraries

      @@ -384,10 +384,10 @@ There is no C++ library I wrote a SWIG interface for, so I'm not sure if this is possible or sensible, yet.

      -

      24.3 Preliminaries

      +

      25.3 Preliminaries

      -

      24.3.1 Compilers

      +

      25.3.1 Compilers

      @@ -401,7 +401,7 @@ For testing examples I use Critical Mass cm3.

      -

      24.3.2 Additional Commandline Options

      +

      25.3.2 Additional Commandline Options

      @@ -478,10 +478,10 @@ Instead generate templates for some basic typemaps. -

      24.4 Modula-3 typemaps

      +

      25.4 Modula-3 typemaps

      -

      24.4.1 Inputs and outputs

      +

      25.4.1 Inputs and outputs

      @@ -697,7 +697,7 @@ consist of the following parts: -

      24.4.2 Subranges, Enumerations, Sets

      +

      25.4.2 Subranges, Enumerations, Sets

      @@ -749,7 +749,7 @@ that I'd like to automate.

      -

      24.4.3 Objects

      +

      25.4.3 Objects

      @@ -762,7 +762,7 @@ is not really useful, yet.

      -

      24.4.4 Imports

      +

      25.4.4 Imports

      @@ -797,7 +797,7 @@ IMPORT M3toC;

    -

    24.4.5 Exceptions

    +

    25.4.5 Exceptions

    @@ -821,7 +821,7 @@ you should declare %typemap("m3wrapinconv:throws") blah * %{OSError.E%}.

    -

    24.4.6 Example

    +

    25.4.6 Example

    @@ -868,10 +868,10 @@ where almost everything is generated by a typemap: -

    24.5 More hints to the generator

    +

    25.5 More hints to the generator

    -

    24.5.1 Features

    +

    25.5.1 Features

    @@ -908,7 +908,7 @@ where almost everything is generated by a typemap:
    -

    24.5.2 Pragmas

    +

    25.5.2 Pragmas

    @@ -931,7 +931,7 @@ where almost everything is generated by a typemap:
    -

    24.6 Remarks

    +

    25.6 Remarks

      diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html index 008e3aeb3..4351e34a7 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -8,7 +8,7 @@ -

      25 SWIG and MzScheme

      +

      26 SWIG and MzScheme

        @@ -22,7 +22,7 @@

        This section contains information on SWIG's support of MzScheme. -

        25.1 Creating native MzScheme structures

        +

        26.1 Creating native MzScheme structures

        diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index b65831192..6cbfa5510 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -6,7 +6,7 @@ -

        26 SWIG and Ocaml

        +

        27 SWIG and Ocaml

          @@ -80,7 +80,7 @@ If you're not familiar with the Objective Caml language, you can visit The Ocaml Website.

          -

          26.1 Preliminaries

          +

          27.1 Preliminaries

          @@ -99,7 +99,7 @@ file Examples/Makefile illustrate how to compile and link SWIG modules that will be loaded dynamically. This has only been tested on Linux so far.

          -

          26.1.1 Running SWIG

          +

          27.1.1 Running SWIG

          @@ -122,7 +122,7 @@ you will compile the file example_wrap.c with ocamlc or the resulting .ml and .mli files as well, and do the final link with -custom (not needed for native link).

          -

          26.1.2 Compiling the code

          +

          27.1.2 Compiling the code

          @@ -158,7 +158,7 @@ the user more freedom with respect to custom typing.

        -

        26.1.3 The camlp4 module

        +

        27.1.3 The camlp4 module

        @@ -234,7 +234,7 @@ let b = C_string (getenv "PATH") -

        26.1.4 Using your module

        +

        27.1.4 Using your module

        @@ -248,7 +248,7 @@ When linking any ocaml bytecode with your module, use the -custom option is not needed when you build native code.

        -

        26.1.5 Compilation problems and compiling with C++

        +

        27.1.5 Compilation problems and compiling with C++

        @@ -259,7 +259,7 @@ liberal with pointer types may not compile under the C++ compiler. Most code meant to be compiled as C++ will not have problems.

        -

        26.2 The low-level Ocaml/C interface

        +

        27.2 The low-level Ocaml/C interface

        @@ -360,7 +360,7 @@ is that you must append them to the return list with swig_result = caml_list_a signature for a function that uses value in this way.

        -

        26.2.1 The generated module

        +

        27.2.1 The generated module

        @@ -394,7 +394,7 @@ it describes the output SWIG will generate for class definitions. -

        26.2.2 Enums

        +

        27.2.2 Enums

        @@ -457,7 +457,7 @@ val x : Enum_test.c_obj = C_enum `a

      -

      26.2.2.1 Enum typing in Ocaml

      +

      27.2.2.1 Enum typing in Ocaml

      @@ -470,10 +470,10 @@ functions imported from different modules. You must convert values to master values using the swig_val function before sharing them with another module.

      -

      26.2.3 Arrays

      +

      27.2.3 Arrays

      -

      26.2.3.1 Simple types of bounded arrays

      +

      27.2.3.1 Simple types of bounded arrays

      @@ -494,7 +494,7 @@ arrays of simple types with known bounds in your code, but this only works for arrays whose bounds are completely specified.

      -

      26.2.3.2 Complex and unbounded arrays

      +

      27.2.3.2 Complex and unbounded arrays

      @@ -507,7 +507,7 @@ SWIG can't predict which of these methods will be used in the array, so you have to specify it for yourself in the form of a typemap.

      -

      26.2.3.3 Using an object

      +

      27.2.3.3 Using an object

      @@ -521,7 +521,7 @@ Consider writing an object when the ending condition of your array is complex, such as using a required sentinel, etc.

      -

      26.2.3.4 Example typemap for a function taking float * and int

      +

      27.2.3.4 Example typemap for a function taking float * and int

      @@ -572,7 +572,7 @@ void printfloats( float *tab, int len ); -

      26.2.4 C++ Classes

      +

      27.2.4 C++ Classes

      @@ -615,7 +615,7 @@ the underlying pointer, so using create_[x]_from_ptr alters the returned value for the same object.

      -

      26.2.4.1 STL vector and string Example

      +

      27.2.4.1 STL vector and string Example

      @@ -695,7 +695,7 @@ baz # -

      26.2.4.2 C++ Class Example

      +

      27.2.4.2 C++ Class Example

      @@ -725,7 +725,7 @@ public: }; -

      26.2.4.3 Compiling the example

      +

      27.2.4.3 Compiling the example

      @@ -743,7 +743,7 @@ bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \
         -L$QTPATH/lib -cclib -lqt
       
      -

      26.2.4.4 Sample Session

      +

      27.2.4.4 Sample Session

      @@ -770,10 +770,10 @@ Assuming you have a working installation of QT, you will see a window
       containing the string "hi" in a button.  
       

      -

      26.2.5 Director Classes

      +

      27.2.5 Director Classes

      -

      26.2.5.1 Director Introduction

      +

      27.2.5.1 Director Introduction

      @@ -800,7 +800,7 @@ class foo { };

      -

      26.2.5.2 Overriding Methods in Ocaml

      +

      27.2.5.2 Overriding Methods in Ocaml

      @@ -828,7 +828,7 @@ In this example, I'll examine the objective caml code involved in providing an overloaded class. This example is contained in Examples/ocaml/shapes.

      -

      26.2.5.3 Director Usage Example

      +

      27.2.5.3 Director Usage Example

      @@ -887,7 +887,7 @@ in a more effortless style in ocaml, while leaving the "engine" part of the program in C++.

      -

      26.2.5.4 Creating director objects

      +

      27.2.5.4 Creating director objects

      @@ -928,7 +928,7 @@ object from causing a core dump, as long as the object is destroyed properly.

      -

      26.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      +

      27.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      @@ -939,7 +939,7 @@ well as a function return value in the same way you provide function arguments, and to receive arguments the same way you normally receive function returns.

      -

      26.2.5.6 directorin typemap

      +

      27.2.5.6 directorin typemap

      @@ -950,7 +950,7 @@ code receives when you are called. In general, a simple directorin typ can use the same body as a simple out typemap.

      -

      26.2.5.7 directorout typemap

      +

      27.2.5.7 directorout typemap

      @@ -961,7 +961,7 @@ for the same type, except when there are special requirements for object ownership, etc.

      -

      26.2.5.8 directorargout typemap

      +

      27.2.5.8 directorargout typemap

      @@ -978,7 +978,7 @@ In the event that you don't specify all of the necessary values, integral values will read zero, and struct or object returns have undefined results.

      -

      26.2.6 Exceptions

      +

      27.2.6 Exceptions

      diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index de28a1427..be512f0ce 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -8,7 +8,7 @@ -

      27 SWIG and Octave

      +

      28 SWIG and Octave

        @@ -54,14 +54,14 @@ More information can be found at www.octave.org< Also, there are a dozen or so examples in the Examples/octave directory, and hundreds in the test suite (Examples/test-suite and Examples/test-suite/octave).

        -

        27.1 Preliminaries

        +

        28.1 Preliminaries

        The SWIG implemention was first based on Octave 2.9.12, so this is the minimum version required. Testing has only been done on Linux.

        -

        27.2 Running SWIG

        +

        28.2 Running SWIG

        @@ -97,7 +97,7 @@ This creates a C++ source file example_wrap.cxx. A C++ file is generate The swig command line has a number of options you can use, like to redirect it's output. Use swig --help to learn about these.

        -

        27.2.1 Compiling a dynamic module

        +

        28.2.1 Compiling a dynamic module

        @@ -124,7 +124,7 @@ $ mkoctfile example_wrap.cxx example.c

        octave:1> example
        -

        27.2.2 Using your module

        +

        28.2.2 Using your module

        @@ -142,10 +142,10 @@ octave:4> example.cvar.Foo=4; octave:5> example.cvar.Foo ans = 4

      -

      27.3 A tour of basic C/C++ wrapping

      +

      28.3 A tour of basic C/C++ wrapping

      -

      27.3.1 Modules

      +

      28.3.1 Modules

      @@ -187,7 +187,7 @@ One can also rename it by simple assignment, e.g., octave:1> some_vars = cvar; -

      27.3.2 Functions

      +

      28.3.2 Functions

      @@ -204,7 +204,7 @@ int fact(int n);

      octave:1> example.fact(4)
       24 
      -

      27.3.3 Global variables

      +

      28.3.3 Global variables

      @@ -257,7 +257,7 @@ octave:2> example.PI=3.142; octave:3> example.PI ans = 3.1420 -

      27.3.4 Constants and enums

      +

      28.3.4 Constants and enums

      @@ -279,7 +279,7 @@ example.SCONST="Hello World" example.SUNDAY=0 .... -

      27.3.5 Pointers

      +

      28.3.5 Pointers

      @@ -326,7 +326,7 @@ octave:2> f=example.fopen("not there","r"); error: value on right hand side of assignment is undefined error: evaluating assignment expression near line 2, column 2 -

      27.3.6 Structures and C++ classes

      +

      28.3.6 Structures and C++ classes

      @@ -461,7 +461,7 @@ ans = 1 Depending on the ownership setting of a swig_ref, it may call C++ destructors when its reference count goes to zero. See the section on memory management below for details.

      -

      27.3.7 C++ inheritance

      +

      28.3.7 C++ inheritance

      @@ -470,7 +470,7 @@ This information contains the full class hierarchy. When an indexing operation ( the tree is walked to find a match in the current class as well as any of its bases. The lookup is then cached in the swig_ref.

      -

      27.3.8 C++ overloaded functions

      +

      28.3.8 C++ overloaded functions

      @@ -480,7 +480,7 @@ The dispatch function selects which overload to call (if any) based on the passe typecheck typemaps are used to analyze each argument, as well as assign precedence. See the chapter on typemaps for details.

      -

      27.3.9 C++ operators

      +

      28.3.9 C++ operators

      @@ -580,7 +580,7 @@ On the C++ side, the default mappings are as follows: %rename(__brace) *::operator[]; -

      27.3.10 Class extension with %extend

      +

      28.3.10 Class extension with %extend

      @@ -610,7 +610,7 @@ octave:3> printf("%s\n",a); octave:4> a.__str() 4 -

      27.3.11 C++ templates

      +

      28.3.11 C++ templates

      @@ -687,14 +687,14 @@ ans = -

      27.3.12 C++ Smart Pointers

      +

      28.3.12 C++ Smart Pointers

      C++ smart pointers are fully supported as in other modules.

      -

      27.3.13 Directors (calling Octave from C++ code)

      +

      28.3.13 Directors (calling Octave from C++ code)

      @@ -774,14 +774,14 @@ c-side routine called octave-side routine called -

      27.3.14 Threads

      +

      28.3.14 Threads

      The use of threads in wrapped Director code is not supported; i.e., an Octave-side implementation of a C++ class must be called from the Octave interpreter's thread. Anything fancier (apartment/queue model, whatever) is left to the user. Without anything fancier, this amounts to the limitation that Octave must drive the module... like, for example, an optimization package that calls Octave to evaluate an objective function.

      -

      27.3.15 Memory management

      +

      28.3.15 Memory management

      @@ -815,14 +815,14 @@ The %newobject directive may be used to control this behavior for pointers retur In the case where one wishes for the C++ side to own an object that was created in Octave (especially a Director object), one can use the __disown() method to invert this logic. Then letting the Octave reference count go to zero will not destroy the object, but destroying the object will invalidate the Octave-side object if it still exists (and call destructors of other C++ bases in the case of multiple inheritance/subclass()'ing).

      -

      27.3.16 STL support

      +

      28.3.16 STL support

      Various STL library files are provided for wrapping STL containers.

      -

      27.3.17 Matrix typemaps

      +

      28.3.17 Matrix typemaps

      diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 777c2f6a2..0c2733c0e 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -6,7 +6,7 @@ -

      28 SWIG and Perl5

      +

      29 SWIG and Perl5

        @@ -87,7 +87,7 @@ later. Earlier versions are problematic and SWIG generated extensions may not compile or run correctly.

        -

        28.1 Overview

        +

        29.1 Overview

        @@ -108,7 +108,7 @@ described. Advanced customization features, typemaps, and other options are found near the end of the chapter.

        -

        28.2 Preliminaries

        +

        29.2 Preliminaries

        @@ -133,7 +133,7 @@ To build the module, you will need to compile the file example_wrap.c and link it with the rest of your program.

        -

        28.2.1 Getting the right header files

        +

        29.2.1 Getting the right header files

        @@ -165,7 +165,7 @@ loaded, an easy way to find out is to run Perl itself.

      -

      28.2.2 Compiling a dynamic module

      +

      29.2.2 Compiling a dynamic module

      @@ -198,7 +198,7 @@ the target should be named `example.so', `example.sl', or the appropriate dynamic module name on your system.

      -

      28.2.3 Building a dynamic module with MakeMaker

      +

      29.2.3 Building a dynamic module with MakeMaker

      @@ -232,7 +232,7 @@ the preferred approach to compilation. More information about MakeMaker can be found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen, and Randal Schwartz.

      -

      28.2.4 Building a static version of Perl

      +

      29.2.4 Building a static version of Perl

      @@ -301,7 +301,7 @@ added to it. Depending on your machine, you may need to link with additional libraries such as -lsocket, -lnsl, -ldl, etc.

      -

      28.2.5 Using the module

      +

      29.2.5 Using the module

      @@ -456,7 +456,7 @@ system configuration (this requires root access and you will need to read the man pages).

      -

      28.2.6 Compilation problems and compiling with C++

      +

      29.2.6 Compilation problems and compiling with C++

      @@ -599,7 +599,7 @@ have to find the macro that conflicts and add an #undef into the .i file. Pleas any conflicting macros you find to swig-user mailing list.

      -

      28.2.7 Compiling for 64-bit platforms

      +

      29.2.7 Compiling for 64-bit platforms

      @@ -626,7 +626,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

      -

      28.3 Building Perl Extensions under Windows

      +

      29.3 Building Perl Extensions under Windows

      @@ -637,7 +637,7 @@ section assumes you are using SWIG with Microsoft Visual C++ although the procedure may be similar with other compilers.

      -

      28.3.1 Running SWIG from Developer Studio

      +

      29.3.1 Running SWIG from Developer Studio

      @@ -700,7 +700,7 @@ print "$a\n"; -

      28.3.2 Using other compilers

      +

      29.3.2 Using other compilers

      @@ -708,7 +708,7 @@ SWIG is known to work with Cygwin and may work with other compilers on Windows. For general hints and suggestions refer to the Windows chapter.

      -

      28.4 The low-level interface

      +

      29.4 The low-level interface

      @@ -718,7 +718,7 @@ can be used to control your application. However, it is also used to construct more user-friendly proxy classes as described in the next section.

      -

      28.4.1 Functions

      +

      29.4.1 Functions

      @@ -741,7 +741,7 @@ use example; $a = &example::fact(2); -

      28.4.2 Global variables

      +

      29.4.2 Global variables

      @@ -811,7 +811,7 @@ extern char *path; // Declared later in the input -

      28.4.3 Constants

      +

      29.4.3 Constants

      @@ -851,7 +851,7 @@ print example::FOO,"\n"; -

      28.4.4 Pointers

      +

      29.4.4 Pointers

      @@ -960,7 +960,7 @@ as XS and xsubpp. Given the advancement of the SWIG typesystem and the SWIG and XS, this is no longer supported.

      -

      28.4.5 Structures

      +

      29.4.5 Structures

      @@ -1094,7 +1094,7 @@ void Bar_f_set(Bar *b, Foo *val) { -

      28.4.6 C++ classes

      +

      29.4.6 C++ classes

      @@ -1159,7 +1159,7 @@ provides direct access to C++ objects. A higher level interface using Perl prox can be built using these low-level accessors. This is described shortly.

      -

      28.4.7 C++ classes and type-checking

      +

      29.4.7 C++ classes and type-checking

      @@ -1195,7 +1195,7 @@ If necessary, the type-checker also adjusts the value of the pointer (as is nece multiple inheritance is used).

      -

      28.4.8 C++ overloaded functions

      +

      29.4.8 C++ overloaded functions

      @@ -1239,7 +1239,7 @@ example::Spam_foo_d($s,3.14); Please refer to the "SWIG Basics" chapter for more information.

      -

      28.4.9 Operators

      +

      29.4.9 Operators

      @@ -1266,7 +1266,7 @@ The following C++ operators are currently supported by the Perl module:

    • operator or
    • -

      28.4.10 Modules and packages

      +

      29.4.10 Modules and packages

      @@ -1361,7 +1361,7 @@ print Foo::fact(4),"\n"; # Call a function in package FooBar --> -

      28.5 Input and output parameters

      +

      29.5 Input and output parameters

      @@ -1580,7 +1580,7 @@ print "$c\n"; Note: The REFERENCE feature is only currently supported for numeric types (integers and floating point).

      -

      28.6 Exception handling

      +

      29.6 Exception handling

      @@ -1745,7 +1745,7 @@ This is still supported, but it is deprecated. The newer %exception di functionality, but it has additional capabilities that make it more powerful.

      -

      28.7 Remapping datatypes with typemaps

      +

      29.7 Remapping datatypes with typemaps

      @@ -1762,7 +1762,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Perl interface.

      -

      28.7.1 A simple typemap example

      +

      29.7.1 A simple typemap example

      @@ -1866,7 +1866,7 @@ example::count("e","Hello World"); -

      28.7.2 Perl5 typemaps

      +

      29.7.2 Perl5 typemaps

      @@ -1971,7 +1971,7 @@ Return of C++ member data (all languages). Check value of input parameter. -

      28.7.3 Typemap variables

      +

      29.7.3 Typemap variables

      @@ -2042,7 +2042,7 @@ properly assigned. The Perl name of the wrapper function being created. -

      28.7.4 Useful functions

      +

      29.7.4 Useful functions

      @@ -2111,7 +2111,7 @@ int sv_isa(SV *, char *0; -

      28.8 Typemap Examples

      +

      29.8 Typemap Examples

      @@ -2120,7 +2120,7 @@ might look at the files "perl5.swg" and "typemaps.i" in the SWIG library.

      -

      28.8.1 Converting a Perl5 array to a char **

      +

      29.8.1 Converting a Perl5 array to a char **

      @@ -2212,7 +2212,7 @@ print @$b,"\n"; # Print it out -

      28.8.2 Return values

      +

      29.8.2 Return values

      @@ -2241,7 +2241,7 @@ can be done using the EXTEND() macro as in : } -

      28.8.3 Returning values from arguments

      +

      29.8.3 Returning values from arguments

      @@ -2295,7 +2295,7 @@ print "multout(7,13) = @r\n"; ($x,$y) = multout(7,13); -

      28.8.4 Accessing array structure members

      +

      29.8.4 Accessing array structure members

      @@ -2358,7 +2358,7 @@ the "in" typemap in the previous section would be used to convert an to copy the converted array into a C data structure.

      -

      28.8.5 Turning Perl references into C pointers

      +

      29.8.5 Turning Perl references into C pointers

      @@ -2423,7 +2423,7 @@ print "$c\n"; -

      28.8.6 Pointer handling

      +

      29.8.6 Pointer handling

      @@ -2502,7 +2502,7 @@ For example: -

      28.9 Proxy classes

      +

      29.9 Proxy classes

      @@ -2518,7 +2518,7 @@ to the underlying code. This section describes the implementation details of the proxy interface.

      -

      28.9.1 Preliminaries

      +

      29.9.1 Preliminaries

      @@ -2540,7 +2540,7 @@ SWIG creates a collection of high-level Perl wrappers. In your scripts, you wil high level wrappers. The wrappers, in turn, interact with the low-level procedural module.

      -

      28.9.2 Structure and class wrappers

      +

      29.9.2 Structure and class wrappers

      @@ -2666,7 +2666,7 @@ $v->DESTROY(); -

      28.9.3 Object Ownership

      +

      29.9.3 Object Ownership

      @@ -2753,7 +2753,7 @@ counting, garbage collection, or advanced features one might find in sophisticated languages.

      -

      28.9.4 Nested Objects

      +

      29.9.4 Nested Objects

      @@ -2806,7 +2806,7 @@ $p->{f}->{x} = 0.0; %${$p->{v}} = ( x=>0, y=>0, z=>0); -

      28.9.5 Proxy Functions

      +

      29.9.5 Proxy Functions

      @@ -2840,7 +2840,7 @@ This function replaces the original function, but operates in an identical manner.

      -

      28.9.6 Inheritance

      +

      29.9.6 Inheritance

      @@ -2916,7 +2916,7 @@ particular, inheritance of data members is extremely tricky (and I'm not even sure if it really works).

      -

      28.9.7 Modifying the proxy methods

      +

      29.9.7 Modifying the proxy methods

      @@ -2944,7 +2944,7 @@ public: }; -

      28.10 Adding additional Perl code

      +

      29.10 Adding additional Perl code

      diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index f3bf720d9..c9ee74f38 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -7,7 +7,7 @@ -

      29 SWIG and PHP

      +

      30 SWIG and PHP

        @@ -75,7 +75,7 @@ your extension into php directly, you will need the complete PHP source tree available.

        -

        29.1 Generating PHP Extensions

        +

        30.1 Generating PHP Extensions

        @@ -122,7 +122,7 @@ and it doesn't play nicely with package system. We don't recommend this approach, or provide explicit support for it.

        -

        29.1.1 Building a loadable extension

        +

        30.1.1 Building a loadable extension

        @@ -137,7 +137,7 @@ least work for Linux though): gcc -shared example_wrap.o -o example.so

      -

      29.1.2 Using PHP Extensions

      +

      30.1.2 Using PHP Extensions

      @@ -168,7 +168,7 @@ attempts to do the dl() call for you: include("example.php"); -

      29.2 Basic PHP interface

      +

      30.2 Basic PHP interface

      @@ -178,7 +178,7 @@ possible for names of symbols in one extension module to clash with other symbols unless care is taken to %rename them.

      -

      29.2.1 Constants

      +

      30.2.1 Constants

      @@ -303,7 +303,7 @@ both point to the same value, without the case test taking place. ( Apologies, this paragraph needs rewriting to make some sense. )

      -

      29.2.2 Global Variables

      +

      30.2.2 Global Variables

      @@ -352,7 +352,7 @@ undefined. At this time SWIG does not support custom accessor methods.

      -

      29.2.3 Functions

      +

      30.2.3 Functions

      @@ -405,7 +405,7 @@ print $s; # The value of $s was not changed. --> -

      29.2.4 Overloading

      +

      30.2.4 Overloading

      @@ -461,7 +461,7 @@ taking the integer argument.

      --> -

      29.2.5 Pointers and References

      +

      30.2.5 Pointers and References

      @@ -593,7 +593,7 @@ PHP in a number of ways: by using unset on an existing variable, or assigning NULL to a variable.

      -

      29.2.6 Structures and C++ classes

      +

      30.2.6 Structures and C++ classes

      @@ -652,7 +652,7 @@ Would be used in the following way from PHP5: Member variables and methods are accessed using the -> operator.

      -

      29.2.6.1 Using -noproxy

      +

      30.2.6.1 Using -noproxy

      @@ -678,7 +678,7 @@ Complex_im_set($obj,$d); Complex_im_get($obj); -

      29.2.6.2 Constructors and Destructors

      +

      30.2.6.2 Constructors and Destructors

      @@ -719,7 +719,7 @@ the programmer can either reassign the variable or call unset($v)

      -

      29.2.6.3 Static Member Variables

      +

      30.2.6.3 Static Member Variables

      @@ -762,7 +762,7 @@ Ko::threats(10); echo "There has now been " . Ko::threats() . " threats\n"; -

      29.2.6.4 Static Member Functions

      +

      30.2.6.4 Static Member Functions

      @@ -784,7 +784,7 @@ Ko::threats(); -

      29.2.7 PHP Pragmas, Startup and Shutdown code

      +

      30.2.7 PHP Pragmas, Startup and Shutdown code

      @@ -872,7 +872,7 @@ The %rinit and %rshutdown statements are very similar but inse into the request init (PHP_RINIT_FUNCTION) and request shutdown (PHP_RSHUTDOWN_FUNCTION) code respectively.

      -

      29.3 Cross language polymorphism

      +

      30.3 Cross language polymorphism

      @@ -907,7 +907,7 @@ wrapper functions takes care of all the cross-language method routing transparently.

      -

      29.3.1 Enabling directors

      +

      30.3.1 Enabling directors

      @@ -999,7 +999,7 @@ class MyFoo extends Foo { -

      29.3.2 Director classes

      +

      30.3.2 Director classes

      @@ -1079,7 +1079,7 @@ so there is no need for the extra overhead involved with routing the calls through PHP.

      -

      29.3.3 Ownership and object destruction

      +

      30.3.3 Ownership and object destruction

      @@ -1135,7 +1135,7 @@ In this example, we are assuming that FooContainer will take care of deleting all the Foo pointers it contains at some point.

      -

      29.3.4 Exception unrolling

      +

      30.3.4 Exception unrolling

      @@ -1194,7 +1194,7 @@ Swig::DirectorMethodException is thrown, PHP will register the exception as soon as the C wrapper function returns.

      -

      29.3.5 Overhead and code bloat

      +

      30.3.5 Overhead and code bloat

      @@ -1227,7 +1227,7 @@ optimized by selectively enabling director methods (using the %feature directive) for only those methods that are likely to be extended in PHP.

      -

      29.3.6 Typemaps

      +

      30.3.6 Typemaps

      @@ -1241,7 +1241,7 @@ need to be supported.

      -

      29.3.7 Miscellaneous

      +

      30.3.7 Miscellaneous

      Director typemaps for STL classes are mostly in place, and hence you diff --git a/Doc/Manual/Pike.html b/Doc/Manual/Pike.html index ad8976a14..8f9e43735 100644 --- a/Doc/Manual/Pike.html +++ b/Doc/Manual/Pike.html @@ -6,7 +6,7 @@ -

      30 SWIG and Pike

      +

      31 SWIG and Pike

        @@ -46,10 +46,10 @@ least, make sure you read the "SWIG Basics" chapter.

        -

        30.1 Preliminaries

        +

        31.1 Preliminaries

        -

        30.1.1 Running SWIG

        +

        31.1.1 Running SWIG

        @@ -94,7 +94,7 @@ can use the -o option:

        $ swig -pike -o pseudonym.c example.i
        -

        30.1.2 Getting the right header files

        +

        31.1.2 Getting the right header files

        @@ -114,7 +114,7 @@ You're looking for files with the names global.h, program.h and so on.

        -

        30.1.3 Using your module

        +

        31.1.3 Using your module

        @@ -129,10 +129,10 @@ Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend) (1) Result: 24

      -

      30.2 Basic C/C++ Mapping

      +

      31.2 Basic C/C++ Mapping

      -

      30.2.1 Modules

      +

      31.2.1 Modules

      @@ -143,7 +143,7 @@ concerned), SWIG's %module directive doesn't really have any significance.

      -

      30.2.2 Functions

      +

      31.2.2 Functions

      @@ -168,7 +168,7 @@ exactly as you'd expect it to: (1) Result: 24 -

      30.2.3 Global variables

      +

      31.2.3 Global variables

      @@ -197,7 +197,7 @@ will result in two functions, Foo_get() and Foo_set(): (3) Result: 3.141590 -

      30.2.4 Constants and enumerated types

      +

      31.2.4 Constants and enumerated types

      @@ -205,7 +205,7 @@ Enumerated types in C/C++ declarations are wrapped as Pike constants, not as Pike enums.

      -

      30.2.5 Constructors and Destructors

      +

      31.2.5 Constructors and Destructors

      @@ -213,7 +213,7 @@ Constructors are wrapped as create() methods, and destructors are wrapped as destroy() methods, for Pike classes.

      -

      30.2.6 Static Members

      +

      31.2.6 Static Members

      diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 1cef3683a..23271e649 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -6,7 +6,7 @@ -

      31 SWIG and Python

      +

      32 SWIG and Python

        @@ -128,7 +128,7 @@ very least, make sure you read the "SWIG Basics" chapter.

        -

        31.1 Overview

        +

        32.1 Overview

        @@ -155,10 +155,10 @@ described followed by a discussion of low-level implementation details.

        -

        31.2 Preliminaries

        +

        32.2 Preliminaries

        -

        31.2.1 Running SWIG

        +

        32.2.1 Running SWIG

        @@ -256,7 +256,7 @@ The following sections have further practical examples and details on how you might go about compiling and using the generated files.

        -

        31.2.2 Using distutils

        +

        32.2.2 Using distutils

        @@ -348,7 +348,7 @@ This same approach works on all platforms if the appropriate compiler is install can even build extensions to the standard Windows Python using MingGW)

        -

        31.2.3 Hand compiling a dynamic module

        +

        32.2.3 Hand compiling a dynamic module

        @@ -396,7 +396,7 @@ module actually consists of two files; socket.py and

        -

        31.2.4 Static linking

        +

        32.2.4 Static linking

        @@ -475,7 +475,7 @@ If using static linking, you might want to rely on a different approach (perhaps using distutils).

        -

        31.2.5 Using your module

        +

        32.2.5 Using your module

        @@ -632,7 +632,7 @@ system configuration (this requires root access and you will need to read the man pages).

        -

        31.2.6 Compilation of C++ extensions

        +

        32.2.6 Compilation of C++ extensions

        @@ -724,7 +724,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

        -

        31.2.7 Compiling for 64-bit platforms

        +

        32.2.7 Compiling for 64-bit platforms

        @@ -761,7 +761,7 @@ and -m64 allow you to choose the desired binary format for your python extension.

        -

        31.2.8 Building Python Extensions under Windows

        +

        32.2.8 Building Python Extensions under Windows

        @@ -870,7 +870,7 @@ SWIG Wiki.

        -

        31.3 A tour of basic C/C++ wrapping

        +

        32.3 A tour of basic C/C++ wrapping

        @@ -879,7 +879,7 @@ to your C/C++ code. Functions are wrapped as functions, classes are wrapped as This section briefly covers the essential aspects of this wrapping.

        -

        31.3.1 Modules

        +

        32.3.1 Modules

        @@ -892,7 +892,7 @@ module name, make sure you don't use the same name as a built-in Python command or standard module name.

        -

        31.3.2 Functions

        +

        32.3.2 Functions

        @@ -916,7 +916,7 @@ like you think it does: >>>

      -

      31.3.3 Global variables

      +

      32.3.3 Global variables

      @@ -1054,7 +1054,7 @@ that starts with a leading underscore. SWIG does not create cvar if there are no global variables in a module.

      -

      31.3.4 Constants and enums

      +

      32.3.4 Constants and enums

      @@ -1094,7 +1094,7 @@ other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.

      -

      31.3.5 Pointers

      +

      32.3.5 Pointers

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

      -

      31.3.6 Structures

      +

      32.3.6 Structures

      @@ -1424,7 +1424,7 @@ everything works just like you would expect. For example: -

      31.3.7 C++ classes

      +

      32.3.7 C++ classes

      @@ -1513,7 +1513,7 @@ they are accessed through cvar like this: -

      31.3.8 C++ inheritance

      +

      32.3.8 C++ inheritance

      @@ -1568,7 +1568,7 @@ then the function spam() accepts Foo * or a pointer to any cla It is safe to use multiple inheritance with SWIG.

      -

      31.3.9 Pointers, references, values, and arrays

      +

      32.3.9 Pointers, references, values, and arrays

      @@ -1629,7 +1629,7 @@ treated as a returning value, and it will follow the same allocation/deallocation process.

      -

      31.3.10 C++ overloaded functions

      +

      32.3.10 C++ overloaded functions

      @@ -1752,7 +1752,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      31.3.11 C++ operators

      +

      32.3.11 C++ operators

      @@ -1841,7 +1841,7 @@ Also, be aware that certain operators don't map cleanly to Python. For instance overloaded assignment operators don't map to Python semantics and will be ignored.

      -

      31.3.12 C++ namespaces

      +

      32.3.12 C++ namespaces

      @@ -1908,7 +1908,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      31.3.13 C++ templates

      +

      32.3.13 C++ templates

      @@ -1962,7 +1962,7 @@ Some more complicated examples will appear later.

      -

      31.3.14 C++ Smart Pointers

      +

      32.3.14 C++ Smart Pointers

      @@ -2047,7 +2047,7 @@ simply use the __deref__() method. For example: -

      31.3.15 C++ Reference Counted Objects (ref/unref)

      +

      32.3.15 C++ Reference Counted Objects (ref/unref)

      @@ -2190,7 +2190,7 @@ python releases the proxy instance.

      -

      31.4 Further details on the Python class interface

      +

      32.4 Further details on the Python class interface

      @@ -2203,7 +2203,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

      -

      31.4.1 Proxy classes

      +

      32.4.1 Proxy classes

      @@ -2292,7 +2292,7 @@ you can attach new Python methods to the class and you can even inherit from it by Python built-in types until Python 2.2).

      -

      31.4.2 Memory management

      +

      32.4.2 Memory management

      @@ -2484,7 +2484,7 @@ It is also possible to deal with situations like this using typemaps--an advanced topic discussed later.

      -

      31.4.3 Python 2.2 and classic classes

      +

      32.4.3 Python 2.2 and classic classes

      @@ -2521,7 +2521,7 @@ class itself. In Python-2.1 and earlier, they have to be accessed as a global function or through an instance (see the earlier section).

      -

      31.5 Cross language polymorphism

      +

      32.5 Cross language polymorphism

      @@ -2555,7 +2555,7 @@ proxy classes, director classes, and C wrapper functions takes care of all the cross-language method routing transparently.

      -

      31.5.1 Enabling directors

      +

      32.5.1 Enabling directors

      @@ -2648,7 +2648,7 @@ class MyFoo(mymodule.Foo): -

      31.5.2 Director classes

      +

      32.5.2 Director classes

      @@ -2730,7 +2730,7 @@ so there is no need for the extra overhead involved with routing the calls through Python.

      -

      31.5.3 Ownership and object destruction

      +

      32.5.3 Ownership and object destruction

      @@ -2797,7 +2797,7 @@ deleting all the Foo pointers it contains at some point. Note that no hard references to the Foo objects remain in Python.

      -

      31.5.4 Exception unrolling

      +

      32.5.4 Exception unrolling

      @@ -2856,7 +2856,7 @@ Swig::DirectorMethodException is thrown, Python will register the exception as soon as the C wrapper function returns.

      -

      31.5.5 Overhead and code bloat

      +

      32.5.5 Overhead and code bloat

      @@ -2890,7 +2890,7 @@ directive) for only those methods that are likely to be extended in Python.

      -

      31.5.6 Typemaps

      +

      32.5.6 Typemaps

      @@ -2904,7 +2904,7 @@ need to be supported.

      -

      31.5.7 Miscellaneous

      +

      32.5.7 Miscellaneous

      @@ -2951,7 +2951,7 @@ methods that return const references.

      -

      31.6 Common customization features

      +

      32.6 Common customization features

      @@ -2964,7 +2964,7 @@ This section describes some common SWIG features that are used to improve your the interface to an extension module.

      -

      31.6.1 C/C++ helper functions

      +

      32.6.1 C/C++ helper functions

      @@ -3045,7 +3045,7 @@ hard to implement. It is possible to clean this up using Python code, typemaps, customization features as covered in later sections.

      -

      31.6.2 Adding additional Python code

      +

      32.6.2 Adding additional Python code

      @@ -3194,7 +3194,7 @@ public: -

      31.6.3 Class extension with %extend

      +

      32.6.3 Class extension with %extend

      @@ -3283,7 +3283,7 @@ Vector(12,14,16) in any way---the extensions only show up in the Python interface.

      -

      31.6.4 Exception handling with %exception

      +

      32.6.4 Exception handling with %exception

      @@ -3409,7 +3409,7 @@ The language-independent exception.i library file can also be used to raise exceptions. See the SWIG Library chapter.

      -

      31.7 Tips and techniques

      +

      32.7 Tips and techniques

      @@ -3419,7 +3419,7 @@ strings, binary data, and arrays. This chapter discusses the common techniques solving these problems.

      -

      31.7.1 Input and output parameters

      +

      32.7.1 Input and output parameters

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

      -

      31.7.2 Simple pointers

      +

      32.7.2 Simple pointers

      @@ -3701,7 +3701,7 @@ If you replace %pointer_functions() by %pointer_class(type,name)SWIG Library chapter for further details.

      -

      31.7.3 Unbounded C Arrays

      +

      32.7.3 Unbounded C Arrays

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

      -

      31.7.4 String handling

      +

      32.7.4 String handling

      @@ -3832,7 +3832,7 @@ If you need to return binary data, you might use the also be used to extra binary data from arbitrary pointers.

      -

      31.8 Typemaps

      +

      32.8 Typemaps

      @@ -3849,7 +3849,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Python interface or if you want to elevate your guru status.

      -

      31.8.1 What is a typemap?

      +

      32.8.1 What is a typemap?

      @@ -3965,7 +3965,7 @@ parameter is omitted): -

      31.8.2 Python typemaps

      +

      32.8.2 Python typemaps

      @@ -4006,7 +4006,7 @@ a look at the SWIG library version 1.3.20 or so.

      -

      31.8.3 Typemap variables

      +

      32.8.3 Typemap variables

      @@ -4077,7 +4077,7 @@ properly assigned. The Python name of the wrapper function being created. -

      31.8.4 Useful Python Functions

      +

      32.8.4 Useful Python Functions

      @@ -4205,7 +4205,7 @@ write me -

      31.9 Typemap Examples

      +

      32.9 Typemap Examples

      @@ -4214,7 +4214,7 @@ might look at the files "python.swg" and "typemaps.i" in the SWIG library.

      -

      31.9.1 Converting Python list to a char **

      +

      32.9.1 Converting Python list to a char **

      @@ -4294,7 +4294,7 @@ memory allocation is used to allocate memory for the array, the the C function.

      -

      31.9.2 Expanding a Python object into multiple arguments

      +

      32.9.2 Expanding a Python object into multiple arguments

      @@ -4373,7 +4373,7 @@ to supply the argument count. This is automatically set by the typemap code. F -

      31.9.3 Using typemaps to return arguments

      +

      32.9.3 Using typemaps to return arguments

      @@ -4462,7 +4462,7 @@ function can now be used as follows: >>> -

      31.9.4 Mapping Python tuples into small arrays

      +

      32.9.4 Mapping Python tuples into small arrays

      @@ -4511,7 +4511,7 @@ array, such an approach would not be recommended for huge arrays, but for small structures, this approach works fine.

      -

      31.9.5 Mapping sequences to C arrays

      +

      32.9.5 Mapping sequences to C arrays

      @@ -4600,7 +4600,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) { -

      31.9.6 Pointer handling

      +

      32.9.6 Pointer handling

      @@ -4697,7 +4697,7 @@ class object (if applicable). -

      31.10 Docstring Features

      +

      32.10 Docstring Features

      @@ -4725,7 +4725,7 @@ of your users much simpler.

      -

      31.10.1 Module docstring

      +

      32.10.1 Module docstring

      @@ -4759,7 +4759,7 @@ layout of controls on a panel, etc. to be loaded from an XML file." -

      31.10.2 %feature("autodoc")

      +

      32.10.2 %feature("autodoc")

      @@ -4786,7 +4786,7 @@ names, default values if any, and return type if any. There are also three options for autodoc controlled by the value given to the feature, described below. -

      31.10.2.1 %feature("autodoc", "0")

      +

      32.10.2.1 %feature("autodoc", "0")

      @@ -4815,7 +4815,7 @@ def function_name(*args, **kwargs): -

      31.10.2.2 %feature("autodoc", "1")

      +

      32.10.2.2 %feature("autodoc", "1")

      @@ -4840,7 +4840,7 @@ def function_name(*args, **kwargs): -

      31.10.2.3 %feature("autodoc", "docstring")

      +

      32.10.2.3 %feature("autodoc", "docstring")

      @@ -4859,7 +4859,7 @@ void GetPosition(int* OUTPUT, int* OUTPUT); -

      31.10.3 %feature("docstring")

      +

      32.10.3 %feature("docstring")

      @@ -4891,7 +4891,7 @@ with more than one line. -

      31.11 Python Packages

      +

      32.11 Python Packages

      @@ -4918,7 +4918,7 @@ and also in base class declarations, etc. if the package name is different than its own.

      -

      31.12 Python 3 Support

      +

      32.12 Python 3 Support

      @@ -4945,7 +4945,7 @@ The following are Python 3.0 new features that are currently supported by SWIG.

      -

      31.12.1 Function annotation

      +

      32.12.1 Function annotation

      @@ -4977,7 +4977,7 @@ all overloaded functions share the same function in SWIG generated proxy class. For detailed usage of function annotation, see PEP 3107.

      -

      31.12.2 Buffer interface

      +

      32.12.2 Buffer interface

      @@ -5129,7 +5129,7 @@ modify the buffer. -

      31.12.3 Abstract base classes

      +

      32.12.3 Abstract base classes

      diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html index e8cee6448..ceea32146 100644 --- a/Doc/Manual/R.html +++ b/Doc/Manual/R.html @@ -6,7 +6,7 @@ -

      34 SWIG and R

      +

      35 SWIG and R

        @@ -33,7 +33,7 @@ compile and run an R interface to QuantLib running on Mandriva Linux with gcc. The R bindings also work on Microsoft Windows using Visual C++.

        -

        34.1 Bugs

        +

        35.1 Bugs

        @@ -45,7 +45,7 @@ Currently the following features are not implemented or broken:

      • C Array wrappings
      -

      34.2 Using R and SWIG

      +

      35.2 Using R and SWIG

      @@ -119,7 +119,7 @@ Without it, inheritance of wrapped objects may fail. These two files can be loaded in any order

      -

      34.3 Precompiling large R files

      +

      35.3 Precompiling large R files

      In cases where the R file is large, one make save a lot of loading @@ -137,7 +137,7 @@ will save a large amount of loading time. -

      34.4 General policy

      +

      35.4 General policy

      @@ -146,7 +146,7 @@ wrapping over the underlying functions and rely on the R type system to provide R syntax.

      -

      34.5 Language conventions

      +

      35.5 Language conventions

      @@ -155,7 +155,7 @@ and [ are overloaded to allow for R syntax (one based indices and slices)

      -

      34.6 C++ classes

      +

      35.6 C++ classes

      @@ -167,7 +167,7 @@ keep track of the pointer object which removes the necessity for a lot of the proxy class baggage you see in other languages.

      -

      34.7 Enumerations

      +

      35.7 Enumerations

      diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 8b43962c5..b61ded8e5 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -26,7 +26,7 @@ -

      32 SWIG and Ruby

      +

      33 SWIG and Ruby

        @@ -167,7 +167,7 @@ -

        32.1 Preliminaries

        +

        33.1 Preliminaries

        SWIG 1.3 is known to work with Ruby versions 1.6 and later. @@ -190,7 +190,7 @@ of Ruby.

        -

        32.1.1 Running SWIG

        +

        33.1.1 Running SWIG

        To build a Ruby module, run SWIG using the -ruby @@ -244,7 +244,7 @@ to compile this file and link it with the rest of your program.

        -

        32.1.2 Getting the right header files

        +

        33.1.2 Getting the right header files

        In order to compile the wrapper code, the compiler needs the ruby.h @@ -288,7 +288,7 @@ installed, you can run Ruby to find out. For example:

        -

        32.1.3 Compiling a dynamic module

        +

        33.1.3 Compiling a dynamic module

        Ruby extension modules are typically compiled into shared @@ -443,7 +443,7 @@ manual pages for your compiler and linker to determine the correct set of options. You might also check the SWIG Wiki for additional information.

        -

        32.1.4 Using your module

        +

        33.1.4 Using your module

        Ruby module names must be capitalized, @@ -498,7 +498,7 @@ begins with:

        -

        32.1.5 Static linking

        +

        33.1.5 Static linking

        An alternative approach to dynamic linking is to rebuild the @@ -519,7 +519,7 @@ finally rebuilding Ruby.

        -

        32.1.6 Compilation of C++ extensions

        +

        33.1.6 Compilation of C++ extensions

        On most machines, C++ extension modules should be linked @@ -571,7 +571,7 @@ extension, e.g.

        -

        32.2 Building Ruby Extensions under Windows 95/NT

        +

        33.2 Building Ruby Extensions under Windows 95/NT

        Building a SWIG extension to Ruby under Windows 95/NT is @@ -610,7 +610,7 @@ files.

        -

        32.2.1 Running SWIG from Developer Studio

        +

        33.2.1 Running SWIG from Developer Studio

        If you are developing your application within Microsoft @@ -752,7 +752,7 @@ directory, then run the Ruby script from the DOS/Command prompt:

        -

        32.3 The Ruby-to-C/C++ Mapping

        +

        33.3 The Ruby-to-C/C++ Mapping

        This section describes the basics of how SWIG maps C or C++ @@ -762,7 +762,7 @@ declarations in your SWIG interface files to Ruby constructs.

        -

        32.3.1 Modules

        +

        33.3.1 Modules

        The SWIG %module directive specifies @@ -931,7 +931,7 @@ Ruby's built-in names.

        -

        32.3.2 Functions

        +

        33.3.2 Functions

        Global functions are wrapped as Ruby module methods. For @@ -994,7 +994,7 @@ module that can be used like so:

        -

        32.3.3 Variable Linking

        +

        33.3.3 Variable Linking

        C/C++ global variables are wrapped as a pair of singleton @@ -1094,7 +1094,7 @@ effect until it is explicitly disabled using %mutable. -

        32.3.4 Constants

        +

        33.3.4 Constants

        C/C++ constants are wrapped as module constants initialized @@ -1138,7 +1138,7 @@ constant values, e.g.

        -

        32.3.5 Pointers

        +

        33.3.5 Pointers

        "Opaque" pointers to arbitrary C/C++ types (i.e. types that @@ -1190,7 +1190,7 @@ the Ruby nil object.

        -

        32.3.6 Structures

        +

        33.3.6 Structures

        C/C++ structs are wrapped as Ruby classes, with accessor @@ -1365,7 +1365,7 @@ pointers. For example,

        -

        32.3.7 C++ classes

        +

        33.3.7 C++ classes

        Like structs, C++ classes are wrapped by creating a new Ruby @@ -1451,7 +1451,7 @@ class. -

        32.3.8 C++ Inheritance

        +

        33.3.8 C++ Inheritance

        The SWIG type-checker is fully aware of C++ inheritance. @@ -1682,7 +1682,7 @@ Typing").

        -

        32.3.9 C++ Overloaded Functions

        +

        33.3.9 C++ Overloaded Functions

        C++ overloaded functions, methods, and constructors are @@ -1882,7 +1882,7 @@ and C++" chapter for more information about overloading.

        -

        32.3.10 C++ Operators

        +

        33.3.10 C++ Operators

        For the most part, overloaded operators are handled @@ -1963,7 +1963,7 @@ on operator overloading.

        -

        32.3.11 C++ namespaces

        +

        33.3.11 C++ namespaces

        SWIG is aware of C++ namespaces, but namespace names do not @@ -2039,7 +2039,7 @@ identical symbol names, well, then you get what you deserve.

        -

        32.3.12 C++ templates

        +

        33.3.12 C++ templates

        C++ templates don't present a huge problem for SWIG. However, @@ -2083,7 +2083,7 @@ directive. For example:

        -

        32.3.13 C++ Standard Template Library (STL)

        +

        33.3.13 C++ Standard Template Library (STL)

        On a related note, the standard SWIG library contains a @@ -2336,7 +2336,7 @@ chapter.

        -

        32.3.14 C++ STL Functors

        +

        33.3.14 C++ STL Functors

        Some containers in the STL allow you to modify their default @@ -2536,7 +2536,7 @@ b
        -

        32.3.15 C++ STL Iterators

        +

        33.3.15 C++ STL Iterators

        The STL is well known for the use of iterators.  There @@ -2747,7 +2747,7 @@ i
        -

        32.3.16 C++ Smart Pointers

        +

        33.3.16 C++ Smart Pointers

        In certain C++ programs, it is common to use classes that @@ -2872,7 +2872,7 @@ method. For example:

        -

        32.3.17 Cross-Language Polymorphism

        +

        33.3.17 Cross-Language Polymorphism

        SWIG's Ruby module supports cross-language polymorphism @@ -2885,7 +2885,7 @@ using this feature with Ruby.

        -

        32.3.17.1 Exception Unrolling

        +

        33.3.17.1 Exception Unrolling

        Whenever a C++ director class routes one of its virtual @@ -2923,7 +2923,7 @@ caught here and a C++ exception is raised in its place.

        -

        32.4 Naming

        +

        33.4 Naming

        Ruby has several common naming conventions. Constants are @@ -3019,7 +3019,7 @@ planned to become the default option in future releases.

        -

        32.4.1 Defining Aliases

        +

        33.4.1 Defining Aliases

        It's a fairly common practice in the Ruby built-ins and @@ -3111,7 +3111,7 @@ Features") for more details).

        -

        32.4.2 Predicate Methods

        +

        33.4.2 Predicate Methods

        Ruby methods that return a boolean value and end in a @@ -3200,7 +3200,7 @@ Features") for more details).

        -

        32.4.3 Bang Methods

        +

        33.4.3 Bang Methods

        Ruby methods that modify an object in-place and end in an @@ -3264,7 +3264,7 @@ Features") for more details).

        -

        32.4.4 Getters and Setters

        +

        33.4.4 Getters and Setters

        Often times a C++ library will expose properties through @@ -3334,7 +3334,7 @@ methods to be exposed in Ruby as value and value=. -

        32.5 Input and output parameters

        +

        33.5 Input and output parameters

        A common problem in some C programs is handling parameters @@ -3585,10 +3585,10 @@ of %apply

        -

        32.6 Exception handling

        +

        33.6 Exception handling

        -

        32.6.1 Using the %exception directive

        +

        33.6.1 Using the %exception directive

        The SWIG %exception directive can be @@ -3683,7 +3683,7 @@ Features for more examples.

        -

        32.6.2 Handling Ruby Blocks

        +

        33.6.2 Handling Ruby Blocks

        One of the highlights of Ruby and most of its standard library @@ -3864,7 +3864,7 @@ RUBY_YIELD_SELF );

        For more information on typemaps, see Typemaps.

        -

        32.6.3 Raising exceptions

        +

        33.6.3 Raising exceptions

        There are three ways to raise exceptions from C++ code to @@ -4625,7 +4625,7 @@ the built-in Ruby exception types.

        -

        32.6.4 Exception classes

        +

        33.6.4 Exception classes

        Starting with SWIG 1.3.28, the Ruby module supports the %exceptionclass @@ -4683,7 +4683,7 @@ providing for a more natural integration between C++ code and Ruby code.

        -

        32.7 Typemaps

        +

        33.7 Typemaps

        This section describes how you can modify SWIG's default @@ -4706,7 +4706,7 @@ of the primitive C-Ruby interface.

        -

        32.7.1 What is a typemap?

        +

        33.7.1 What is a typemap?

        A typemap is nothing more than a code generation rule that is @@ -4968,7 +4968,7 @@ to be used as follows (notice how the length parameter is omitted):

        -

        32.7.2 Typemap scope

        +

        33.7.2 Typemap scope

        Once defined, a typemap remains in effect for all of the @@ -5016,7 +5016,7 @@ where the class itself is defined. For example:

        -

        32.7.3 Copying a typemap

        +

        33.7.3 Copying a typemap

        A typemap is copied by using assignment. For example:

        @@ -5118,7 +5118,7 @@ rules as for -

        32.7.4 Deleting a typemap

        +

        33.7.4 Deleting a typemap

        A typemap can be deleted by simply defining no code. For @@ -5170,7 +5170,7 @@ typemaps immediately after the clear operation.

        -

        32.7.5 Placement of typemaps

        +

        33.7.5 Placement of typemaps

        Typemap declarations can be declared in the global scope, @@ -5254,7 +5254,7 @@ string -

        32.7.6 Ruby typemaps

        +

        33.7.6 Ruby typemaps

        The following list details all of the typemap methods that @@ -5264,7 +5264,7 @@ can be used by the Ruby module:

        -

        32.7.6.1  "in" typemap

        +

        33.7.6.1  "in" typemap

        Converts Ruby objects to input @@ -5507,7 +5507,7 @@ arguments to be specified. For example:

        -

        32.7.6.2 "typecheck" typemap

        +

        33.7.6.2 "typecheck" typemap

        The "typecheck" typemap is used to support overloaded @@ -5548,7 +5548,7 @@ on "Typemaps and Overloading."

        -

        32.7.6.3  "out" typemap

        +

        33.7.6.3  "out" typemap

        Converts return value of a C function @@ -5780,7 +5780,7 @@ version of the C datatype matched by the typemap. -

        32.7.6.4 "arginit" typemap

        +

        33.7.6.4 "arginit" typemap

        The "arginit" typemap is used to set the initial value of a @@ -5805,7 +5805,7 @@ applications. For example:

        -

        32.7.6.5 "default" typemap

        +

        33.7.6.5 "default" typemap

        The "default" typemap is used to turn an argument into a @@ -5847,7 +5847,7 @@ default argument wrapping.

        -

        32.7.6.6 "check" typemap

        +

        33.7.6.6 "check" typemap

        The "check" typemap is used to supply value checking code @@ -5871,7 +5871,7 @@ arguments have been converted. For example:

        -

        32.7.6.7 "argout" typemap

        +

        33.7.6.7 "argout" typemap

        The "argout" typemap is used to return values from arguments. @@ -6029,7 +6029,7 @@ some function like SWIG_Ruby_AppendOutput.

        -

        32.7.6.8 "freearg" typemap

        +

        33.7.6.8 "freearg" typemap

        The "freearg" typemap is used to cleanup argument data. It is @@ -6065,7 +6065,7 @@ abort prematurely.

        -

        32.7.6.9 "newfree" typemap

        +

        33.7.6.9 "newfree" typemap

        The "newfree" typemap is used in conjunction with the %newobject @@ -6096,7 +6096,7 @@ ownership and %newobject for further details.

        -

        32.7.6.10 "memberin" typemap

        +

        33.7.6.10 "memberin" typemap

        The "memberin" typemap is used to copy data from an @@ -6129,7 +6129,7 @@ other objects.

        -

        32.7.6.11 "varin" typemap

        +

        33.7.6.11 "varin" typemap

        The "varin" typemap is used to convert objects in the target @@ -6140,7 +6140,7 @@ This is implementation specific.

        -

        32.7.6.12 "varout" typemap

        +

        33.7.6.12 "varout" typemap

        The "varout" typemap is used to convert a C/C++ object to an @@ -6151,7 +6151,7 @@ This is implementation specific.

        -

        32.7.6.13 "throws" typemap

        +

        33.7.6.13 "throws" typemap

        The "throws" typemap is only used when SWIG parses a C++ @@ -6210,7 +6210,7 @@ handling with %exception section.

        -

        32.7.6.14 directorin typemap

        +

        33.7.6.14 directorin typemap

        Converts C++ objects in director @@ -6464,7 +6464,7 @@ referring to the class itself. -

        32.7.6.15 directorout typemap

        +

        33.7.6.15 directorout typemap

        Converts Ruby objects in director @@ -6724,7 +6724,7 @@ exception.
        -

        32.7.6.16 directorargout typemap

        +

        33.7.6.16 directorargout typemap

        Output argument processing in director @@ -6964,7 +6964,7 @@ referring to the instance of the class itself -

        32.7.6.17 ret typemap

        +

        33.7.6.17 ret typemap

        Cleanup of function return values @@ -6974,7 +6974,7 @@ referring to the instance of the class itself -

        32.7.6.18 globalin typemap

        +

        33.7.6.18 globalin typemap

        Setting of C global variables @@ -6984,7 +6984,7 @@ referring to the instance of the class itself -

        32.7.7 Typemap variables

        +

        33.7.7 Typemap variables

        @@ -7094,7 +7094,7 @@ being created.

      -

      32.7.8 Useful Functions

      +

      33.7.8 Useful Functions

      When you write a typemap, you usually have to work directly @@ -7118,7 +7118,7 @@ across multiple languages.

      -

      32.7.8.1 C Datatypes to Ruby Objects

      +

      33.7.8.1 C Datatypes to Ruby Objects

      @@ -7174,7 +7174,7 @@ SWIG_From_float(float) -

      32.7.8.2 Ruby Objects to C Datatypes

      +

      33.7.8.2 Ruby Objects to C Datatypes

      Here, while the Ruby versions return the value directly, the SWIG @@ -7263,7 +7263,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input -

      32.7.8.3 Macros for VALUE

      +

      33.7.8.3 Macros for VALUE

      RSTRING_LEN(str)

      @@ -7326,7 +7326,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input -

      32.7.8.4 Exceptions

      +

      33.7.8.4 Exceptions

      void rb_raise(VALUE exception, const char *fmt, @@ -7493,7 +7493,7 @@ arguments are interpreted as with printf().

      -

      32.7.8.5 Iterators

      +

      33.7.8.5 Iterators

      void rb_iter_break()

      @@ -7595,7 +7595,7 @@ VALUE), VALUE value)

      -

      32.7.9 Typemap Examples

      +

      33.7.9 Typemap Examples

      This section includes a few examples of typemaps. For more @@ -7606,7 +7606,7 @@ directory.

      -

      32.7.10 Converting a Ruby array to a char **

      +

      33.7.10 Converting a Ruby array to a char **

      A common problem in many C programs is the processing of @@ -7661,7 +7661,7 @@ after the execution of the C function.

      -

      32.7.11 Collecting arguments in a hash

      +

      33.7.11 Collecting arguments in a hash

      Ruby's solution to the "keyword arguments" capability of some @@ -7940,7 +7940,7 @@ directory of the SWIG distribution.

      -

      32.7.12 Pointer handling

      +

      33.7.12 Pointer handling

      Occasionally, it might be necessary to convert pointer values @@ -8039,7 +8039,7 @@ For example:

      -

      32.7.12.1 Ruby Datatype Wrapping

      +

      33.7.12.1 Ruby Datatype Wrapping

      VALUE Data_Wrap_Struct(VALUE class, void @@ -8090,7 +8090,7 @@ and assigns that pointer to ptr.

      -

      32.7.13 Example: STL Vector to Ruby Array

      +

      33.7.13 Example: STL Vector to Ruby Array

      Another use for macros and type maps is to create a Ruby array @@ -8199,7 +8199,7 @@ the C++ Standard Template Library.
      -

      32.8 Docstring Features

      +

      33.8 Docstring Features

      @@ -8260,7 +8260,7 @@ generate ri documentation from a c wrap file, you could do:

      -

      32.8.1 Module docstring

      +

      33.8.1 Module docstring

      @@ -8311,7 +8311,7 @@ macro. For example: -

      32.8.2 %feature("autodoc")

      +

      33.8.2 %feature("autodoc")

      Since SWIG does know everything about the function it wraps, @@ -8340,7 +8340,7 @@ feature, described below. -

      32.8.2.1 %feature("autodoc", "0")

      +

      33.8.2.1 %feature("autodoc", "0")

      @@ -8388,7 +8388,7 @@ Then Ruby code like this will be generated: -

      32.8.2.2 %feature("autodoc", "1")

      +

      33.8.2.2 %feature("autodoc", "1")

      @@ -8420,7 +8420,7 @@ this: -

      32.8.2.3 %feature("autodoc", "2")

      +

      33.8.2.3 %feature("autodoc", "2")

      @@ -8436,7 +8436,7 @@ this: -

      32.8.2.4 %feature("autodoc", "3")

      +

      33.8.2.4 %feature("autodoc", "3")

      @@ -8464,7 +8464,7 @@ this: -

      32.8.2.5 %feature("autodoc", "docstring")

      +

      33.8.2.5 %feature("autodoc", "docstring")

      @@ -8492,7 +8492,7 @@ generated string. For example: -

      32.8.3 %feature("docstring")

      +

      33.8.3 %feature("docstring")

      @@ -8507,10 +8507,10 @@ docstring and they are output together.

      -

      32.9 Advanced Topics

      +

      33.9 Advanced Topics

      -

      32.9.1 Operator overloading

      +

      33.9.1 Operator overloading

      SWIG allows operator overloading with, by using the %extend @@ -9527,7 +9527,7 @@ parses the expression a != b as !(a == b). -

      32.9.2 Creating Multi-Module Packages

      +

      33.9.2 Creating Multi-Module Packages

      The chapter on Working @@ -9708,7 +9708,7 @@ initialized:

      -

      32.9.3 Specifying Mixin Modules

      +

      33.9.3 Specifying Mixin Modules

      The Ruby language doesn't support multiple inheritance, but @@ -9806,7 +9806,7 @@ Features") for more details).

      -

      32.10 Memory Management

      +

      33.10 Memory Management

      One of the most common issues in generating SWIG bindings for @@ -9853,7 +9853,7 @@ understanding of how the underlying library manages memory.

      -

      32.10.1 Mark and Sweep Garbage Collector

      +

      33.10.1 Mark and Sweep Garbage Collector

      Ruby uses a mark and sweep garbage collector. When the garbage @@ -9901,7 +9901,7 @@ this memory.

      -

      32.10.2 Object Ownership

      +

      33.10.2 Object Ownership

      As described above, memory management depends on clearly @@ -10128,7 +10128,7 @@ classes is:

      -

      32.10.3 Object Tracking

      +

      33.10.3 Object Tracking

      The remaining parts of this section will use the class library @@ -10342,7 +10342,7 @@ methods.

      -

      32.10.4 Mark Functions

      +

      33.10.4 Mark Functions

      With a bit more testing, we see that our class library still @@ -10460,7 +10460,7 @@ test suite.

      -

      32.10.5 Free Functions

      +

      33.10.5 Free Functions

      By default, SWIG creates a "free" function that is called when @@ -10615,7 +10615,7 @@ been freed, and thus raises a runtime exception.

      -

      32.10.6 Embedded Ruby and the C++ Stack

      +

      33.10.6 Embedded Ruby and the C++ Stack

      As has been said, the Ruby GC runs and marks objects before diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index b37df2853..d47dae5de 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -6,7 +6,7 @@ -

      33 SWIG and Tcl

      +

      34 SWIG and Tcl

        @@ -83,7 +83,7 @@ Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but this is no longer supported.

        -

        33.1 Preliminaries

        +

        34.1 Preliminaries

        @@ -109,7 +109,7 @@ build a Tcl extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

        -

        33.1.1 Getting the right header files

        +

        34.1.1 Getting the right header files

        @@ -127,7 +127,7 @@ this is the case, you should probably make a symbolic link so that tcl.h -

        33.1.2 Compiling a dynamic module

        +

        34.1.2 Compiling a dynamic module

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

        -

        33.1.3 Static linking

        +

        34.1.3 Static linking

        @@ -228,7 +228,7 @@ minimal in most situations (and quite frankly not worth the extra hassle in the opinion of this author).

        -

        33.1.4 Using your module

        +

        34.1.4 Using your module

        @@ -356,7 +356,7 @@ to the default system configuration (this requires root access and you will need the man pages).

        -

        33.1.5 Compilation of C++ extensions

        +

        34.1.5 Compilation of C++ extensions

        @@ -439,7 +439,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

        -

        33.1.6 Compiling for 64-bit platforms

        +

        34.1.6 Compiling for 64-bit platforms

        @@ -466,7 +466,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

        -

        33.1.7 Setting a package prefix

        +

        34.1.7 Setting a package prefix

        @@ -485,7 +485,7 @@ option will append the prefix to the name when creating a command and call it "Foo_bar".

        -

        33.1.8 Using namespaces

        +

        34.1.8 Using namespaces

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

        -

        33.2 Building Tcl/Tk Extensions under Windows 95/NT

        +

        34.2 Building Tcl/Tk Extensions under Windows 95/NT

        @@ -518,7 +518,7 @@ covers the process of using SWIG with Microsoft Visual C++. although the procedure may be similar with other compilers.

        -

        33.2.1 Running SWIG from Developer Studio

        +

        34.2.1 Running SWIG from Developer Studio

        @@ -576,7 +576,7 @@ MSDOS > tclsh80 %

      -

      33.2.2 Using NMAKE

      +

      34.2.2 Using NMAKE

      @@ -639,7 +639,7 @@ to get you started. With a little practice, you'll be making lots of Tcl extensions.

      -

      33.3 A tour of basic C/C++ wrapping

      +

      34.3 A tour of basic C/C++ wrapping

      @@ -650,7 +650,7 @@ classes. This section briefly covers the essential aspects of this wrapping.

      -

      33.3.1 Modules

      +

      34.3.1 Modules

      @@ -684,7 +684,7 @@ To fix this, supply an extra argument to load like this: -

      33.3.2 Functions

      +

      34.3.2 Functions

      @@ -709,7 +709,7 @@ like you think it does: % -

      33.3.3 Global variables

      +

      34.3.3 Global variables

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

      33.3.4 Constants and enums

      +

      34.3.4 Constants and enums

      @@ -873,7 +873,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l conversion. This allows the global statement to be omitted.

      -

      33.3.5 Pointers

      +

      34.3.5 Pointers

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

      -

      33.3.6 Structures

      +

      34.3.6 Structures

      @@ -1251,7 +1251,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the memory management section that appears shortly.

      -

      33.3.7 C++ classes

      +

      34.3.7 C++ classes

      @@ -1318,7 +1318,7 @@ In Tcl, the static member is accessed as follows: -

      33.3.8 C++ inheritance

      +

      34.3.8 C++ inheritance

      @@ -1367,7 +1367,7 @@ For instance: It is safe to use multiple inheritance with SWIG.

      -

      33.3.9 Pointers, references, values, and arrays

      +

      34.3.9 Pointers, references, values, and arrays

      @@ -1421,7 +1421,7 @@ to hold the result and a pointer is returned (Tcl will release this memory when the return value is garbage collected).

      -

      33.3.10 C++ overloaded functions

      +

      34.3.10 C++ overloaded functions

      @@ -1544,7 +1544,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      33.3.11 C++ operators

      +

      34.3.11 C++ operators

      @@ -1646,7 +1646,7 @@ There are ways to make this operator appear as part of the class using the % Keep reading.

      -

      33.3.12 C++ namespaces

      +

      34.3.12 C++ namespaces

      @@ -1710,7 +1710,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      33.3.13 C++ templates

      +

      34.3.13 C++ templates

      @@ -1762,7 +1762,7 @@ More details can be found in the SWIG and C++ -

      33.3.14 C++ Smart Pointers

      +

      34.3.14 C++ Smart Pointers

      @@ -1846,7 +1846,7 @@ simply use the __deref__() method. For example: -

      33.4 Further details on the Tcl class interface

      +

      34.4 Further details on the Tcl class interface

      @@ -1859,7 +1859,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

      -

      33.4.1 Proxy classes

      +

      34.4.1 Proxy classes

      @@ -1924,7 +1924,7 @@ function. This allows objects to be encapsulated objects that look a lot like as shown in the last section.

      -

      33.4.2 Memory management

      +

      34.4.2 Memory management

      @@ -2112,7 +2112,7 @@ typemaps--an advanced topic discussed later.

      -

      33.5 Input and output parameters

      +

      34.5 Input and output parameters

      @@ -2300,7 +2300,7 @@ set c [lindex $dim 1] -

      33.6 Exception handling

      +

      34.6 Exception handling

      @@ -2434,7 +2434,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex See the chapter on "Customization Features" for more examples.

      -

      33.7 Typemaps

      +

      34.7 Typemaps

      @@ -2451,7 +2451,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Tcl interface.

      -

      33.7.1 What is a typemap?

      +

      34.7.1 What is a typemap?

      @@ -2568,7 +2568,7 @@ parameter is omitted): -

      33.7.2 Tcl typemaps

      +

      34.7.2 Tcl typemaps

      @@ -2706,7 +2706,7 @@ Initialize an argument to a value before any conversions occur. Examples of these methods will appear shortly.

      -

      33.7.3 Typemap variables

      +

      34.7.3 Typemap variables

      @@ -2777,7 +2777,7 @@ properly assigned. The Tcl name of the wrapper function being created. -

      33.7.4 Converting a Tcl list to a char **

      +

      34.7.4 Converting a Tcl list to a char **

      @@ -2839,7 +2839,7 @@ argv[2] = Larry 3 -

      33.7.5 Returning values in arguments

      +

      34.7.5 Returning values in arguments

      @@ -2881,7 +2881,7 @@ result, a Tcl function using these typemaps will work like this : % -

      33.7.6 Useful functions

      +

      34.7.6 Useful functions

      @@ -2958,7 +2958,7 @@ int Tcl_IsShared(Tcl_Obj *obj); -

      33.7.7 Standard typemaps

      +

      34.7.7 Standard typemaps

      @@ -3042,7 +3042,7 @@ work) -

      33.7.8 Pointer handling

      +

      34.7.8 Pointer handling

      @@ -3118,7 +3118,7 @@ For example: -

      33.8 Turning a SWIG module into a Tcl Package.

      +

      34.8 Turning a SWIG module into a Tcl Package.

      @@ -3190,7 +3190,7 @@ As a final note, most SWIG examples do not yet use the to use the load command instead.

      -

      33.9 Building new kinds of Tcl interfaces (in Tcl)

      +

      34.9 Building new kinds of Tcl interfaces (in Tcl)

      @@ -3289,7 +3289,7 @@ danger of blowing something up (although it is easily accomplished with an out of bounds array access).

      -

      33.9.1 Proxy classes

      +

      34.9.1 Proxy classes

      @@ -3410,7 +3410,7 @@ short, but clever Tcl script can be combined with SWIG to do many interesting things.

      -

      33.10 Tcl/Tk Stubs

      +

      34.10 Tcl/Tk Stubs

      From 041cee306d0ea3dece381fabca6cf75ecb7d46d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 10 Jun 2010 06:14:24 +0000 Subject: [PATCH 166/203] html fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12113 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 4 ++-- Doc/Manual/Go.html | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 25d2dbf9c..66bf41264 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -720,9 +720,9 @@

    • Go Enumerations
    • Go Classes -
    • Go Templates +
    • Go Templates
    • Go Director Classes
    • Default Go primitive type mappings diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 7d2ce9db8..f6e87afb4 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -23,9 +23,9 @@
    • Go Enumerations
    • Go Classes -
    • Go Templates +
    • Go Templates
    • Go Director Classes
    • Default Go primitive type mappings @@ -289,7 +289,7 @@ to reinterpret_cast. This should only be used for very special cases, such as where C++ would use a dynamic_cast.

      -

      20.3.5.1 Go Class Inheritance

      +

      20.3.5.1 Go Class Inheritance

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

      -

      20.3.6 Go Templates

      +

      20.3.6 Go Templates

      @@ -341,7 +341,7 @@ For example: type GoClass struct { } func (p *GoClass) VirtualFunction() { } func MakeClass() ClassName { - return NewDirectorClassName(&GoClass{}) + return NewDirectorClassName(&GoClass{}) } From f10c7868fdbd12b50bed63255758d75d371acad2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 10 Jun 2010 19:21:07 +0000 Subject: [PATCH 167/203] Fix SWIG_lua_isnilstring multiply defined when using multiple modules and wrapping strings. Patch from 'Number Cruncher'. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12114 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/lua/luatypemaps.swg | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 471a9c5f4..00d1bec5b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-06-10: wsfulton + [Lua] Fix SWIG_lua_isnilstring multiply defined when using multiple + modules and wrapping strings. Patch from 'Number Cruncher'. + 2010-06-10: olly [PHP] Fix directors to correctly call a method with has a different name in PHP to C++ (we were always using the C++ name diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index aff116192..13cd66f4c 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -91,12 +91,12 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} // strings (char * and char[]) %fragment("SWIG_lua_isnilstring", "header") { - int SWIG_lua_isnilstring(lua_State *L, int idx) { - int ret = lua_isstring(L, idx); - if (!ret) - ret = lua_isnil(L, idx); - return ret; - } +SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) { + int ret = lua_isstring(L, idx); + if (!ret) + ret = lua_isnil(L, idx); + return ret; +} } %typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char *, char * From aa953c89089f769c6b4917700a3c62d72ab66586 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 10 Jun 2010 20:08:19 +0000 Subject: [PATCH 168/203] Syntactic sugar - go help display to conform to other help style git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12115 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 91a0f457b..c7a305167 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -4815,10 +4815,10 @@ extern "C" Language *swig_go(void) { // Usage message. const char * const GO::usage = (char *) "\ Go Options (available with -go)\n\ - -package - set name of the Go package to \n\ - -gccgo - generate code for gccgo rather than 6g/8g\n\ - -go-prefix

      - like gccgo -fgo-prefix option\n\ - -soname - name for shared library holding C/C++ code\n\ - -longsize - set size of C/C++ long type--32 or 64 bits\n\ - -rename = - rename symbols\n\ + -package - Set name of the Go package to \n\ + -gccgo - Generate code for gccgo rather than 6g/8g\n\ + -go-prefix

      - Like gccgo -fgo-prefix option\n\ + -soname - Set shared library holding C/C++ code to \n\ + -longsize - Set size of C/C++ long type--32 or 64 bits\n\ + -rename = - Rename symbols from to \n\ \n"; From 92f5c379b8c837ec4c2f98621d78cf5f86922303 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jun 2010 06:29:32 +0000 Subject: [PATCH 169/203] Fix 6g/8g detection git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12116 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/go/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index d666c81bf..4af612799 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -3,7 +3,7 @@ ####################################################################### LANGUAGE = go -GO = 6g +GO = @GO@ GOGCC = false SCRIPTSUFFIX = _runme.go From 02ec28ff55feb664cd25ca1f85b6814ed0206a66 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jun 2010 06:36:51 +0000 Subject: [PATCH 170/203] make beautify-file fixes and other cosmetics git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12117 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Makefile.am | 2 +- Source/Modules/go.cxx | 497 +++++++++++++----------------------------- 2 files changed, 155 insertions(+), 344 deletions(-) diff --git a/Source/Makefile.am b/Source/Makefile.am index 4677002e6..ddf8018ec 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -115,7 +115,7 @@ distclean-local: # swig executable as a way of checking before and after the 'beautifying'. # Single files can be beautified with the beautify-file target, eg: 'make beautify-file INDENTFILE=chosenfile.c' -SWIGTYPEDEFS=-T File -T DohObjInfo -T Parm -T Language -T List -T Typetab -T ModuleFactory -T ErrorMessageFormat -T Symtab -T Hash -T String -T DohBase -T Node -T String_or_char -T SwigType -T Dispatcher -T Wrapper -T DohStringMethods -T DohFileMethods -T DohListMethods -T DohHashMethods -T DOH -T DohIterator -T ParmList -T FILE -T HashNode -T DOHString_or_char +SWIGTYPEDEFS=-T bool -T File -T DohObjInfo -T Parm -T Language -T List -T Typetab -T ModuleFactory -T ErrorMessageFormat -T Symtab -T Hash -T String -T DohBase -T Node -T String_or_char -T SwigType -T Dispatcher -T Wrapper -T DohStringMethods -T DohFileMethods -T DohListMethods -T DohHashMethods -T DOH -T DohIterator -T ParmList -T FILE -T HashNode -T DOHString_or_char INDENTBAKSDIR=../IndentBaks beautify: diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index c7a305167..cb6e3ad5a 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -15,7 +15,7 @@ char cvsroot_go_cxx[] = "$Id"; #include class GO:public Language { - static const char * const usage; + static const char *const usage; // Go package name. String *package; @@ -116,8 +116,7 @@ public: making_variable_wrappers(false), is_static_member_function(false), undefined_types(NULL), - defined_types(NULL) - { + defined_types(NULL) { director_multiple_inheritance = 1; director_language = 1; director_prot_ctor_code = NewString("_swig_gopanic(\"accessing abstract class or protected constructor\");"); @@ -367,14 +366,12 @@ private: Printf(f_c_runtime, "#define SWIG_DIRECTORS\n"); Swig_banner(f_c_directors_h); - Printf(f_c_directors_h, - "\n/* This file should be compiled with gcc. */\n"); + Printf(f_c_directors_h, "\n/* This file should be compiled with gcc. */\n"); Printf(f_c_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module); Printf(f_c_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module); Printf(f_c_directors, "\n// C++ director class methods.\n"); - Printf(f_c_directors, "#include \"%s\"\n\n", - Swig_file_filename(c_filename_h)); + Printf(f_c_directors, "#include \"%s\"\n\n", Swig_file_filename(c_filename_h)); } Swig_banner(f_go_begin); @@ -409,8 +406,7 @@ private: Printv(f_go_wrappers, "type ", ty, " interface {\n", NULL); Printv(f_go_wrappers, "\tSwigcptr() uintptr;\n", NULL); Printv(f_go_wrappers, "}\n", NULL); - Printv(f_go_wrappers, "func (p ", cp, ") Swigcptr() uintptr {\n", - NULL); + Printv(f_go_wrappers, "func (p ", cp, ") Swigcptr() uintptr {\n", NULL); Printv(f_go_wrappers, "\treturn uintptr(p)\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); } @@ -574,10 +570,8 @@ private: Delete(c2); Delete(c1); - if (Swig_methodclass(n) != NULL - && Swig_directorclass(n) - && Strcmp(Char(Getattr(n, "wrap:action")), - director_prot_ctor_code) != 0) { + if (Swig_methodclass(n) != NULL && Swig_directorclass(n) + && Strcmp(Char(Getattr(n, "wrap:action")), director_prot_ctor_code) != 0) { // The core SWIG code skips the first parameter when // generating the $nondirector_new string. Recreate the // action in this case. But don't it if we are using the @@ -643,8 +637,7 @@ private: ParmList *parms = Getattr(n, "parms"); Setattr(n, "wrap:parms", parms); - int r = makeWrappers(n, name, go_name, overname, wname, NULL, parms, - result, is_static); + int r = makeWrappers(n, name, go_name, overname, wname, NULL, parms, result, is_static); if (r != SWIG_OK) { return r; } @@ -703,22 +696,18 @@ private: * IS_STATIC: Whether this is a static method or member. * ---------------------------------------------------------------------- */ - int makeWrappers(Node *n, String *name, String *go_name, String *overname, - String *wname, List *base, ParmList *parms, - SwigType *result, bool is_static) { + int makeWrappers(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { assert(result != NULL); 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, &needs_wrapper); 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(n, name, go_name, overname, wname, parms, result, is_static, needs_wrapper); if (r != SWIG_OK) { return r; } @@ -751,10 +740,7 @@ 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, bool *p_needs_wrapper) { Wrapper *dummy = NewWrapper(); emit_attach_parmmaps(parms, dummy); Swig_typemap_attach_parms("default", parms, dummy); @@ -776,18 +762,9 @@ private: receiver = NULL; } - bool add_to_interface = (interfaces != NULL - && !is_constructor - && !is_destructor - && !is_static - && overname == NULL - && is_public(n)); + bool add_to_interface = (interfaces != NULL && !is_constructor && !is_destructor && !is_static && overname == NULL && is_public(n)); - bool needs_wrapper = (gccgo_flag - || receiver != NULL - || is_constructor - || is_destructor - || parm_count > required_count); + bool needs_wrapper = (gccgo_flag || receiver != NULL || 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 @@ -845,9 +822,7 @@ private: p = getParm(p); // Give the parameter a name we will use below. Swig_cparm_name(p, i); - if (i > 0 - || (base != NULL && receiver != NULL) - || parm_count > required_count) { + if (i > 0 || (base != NULL && receiver != NULL) || parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } String *tm = goWrapperType(p, Getattr(p, "type"), false); @@ -867,8 +842,7 @@ private: } if (gccgo_flag) { - Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", wname, "\")", - NULL); + Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", wname, "\")", NULL); } Printv(f_go_wrappers, "\n\n", NULL); @@ -968,12 +942,9 @@ private: for (; i < parm_count; ++i) { p = getParm(p); String *tm = goType(p, Getattr(p, "type")); - Printv(f_go_wrappers, "\tvar ", Getattr(p, "lname"), " ", tm, "\n", - NULL); - Printf(f_go_wrappers, "\tif len(_swig_args) > %d {\n", - i - required_count); - Printf(f_go_wrappers, "\t\t%s = _swig_args[%d].(%s)\n", - Getattr(p, "lname"), i - required_count, tm); + Printv(f_go_wrappers, "\tvar ", Getattr(p, "lname"), " ", tm, "\n", NULL); + Printf(f_go_wrappers, "\tif len(_swig_args) > %d {\n", i - required_count); + Printf(f_go_wrappers, "\t\t%s = _swig_args[%d].(%s)\n", Getattr(p, "lname"), i - required_count, tm); Printv(f_go_wrappers, "\t}\n", NULL); Delete(tm); p = nextParm(p); @@ -1001,8 +972,7 @@ private: Parm *p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); - if (i > 0 - || (base != NULL && receiver != NULL) + if (i > 0 || (base != NULL && receiver != NULL) || parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } @@ -1024,8 +994,7 @@ private: Printv(f_go_wrappers, "}\n", NULL); } else { if (gccgo_flag) { - Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", - wname, "\")\n", NULL); + Printv(f_go_wrappers, " __asm__ (\"", go_prefix, "_", wname, "\")\n", NULL); } } @@ -1044,13 +1013,10 @@ private: * wrapper which will be compiled with 6c/8c. * ---------------------------------------------------------------------- */ - 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(Node *n, String *name, String *go_name, String *overname, String *wname, ParmList *parms, SwigType *result, bool is_static, bool needs_wrapper) { Wrapper *f = NewWrapper(); - Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"", - soname, "\"\n", NULL); + Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"", soname, "\"\n", NULL); Printv(f->def, "void (*", wname, ")(void*);\n", NULL); Printv(f->def, "\n", NULL); Printv(f->def, "void\n", NULL); @@ -1101,8 +1067,7 @@ private: } // \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); + Printv(f->def, "\xc2\xb7", fn_name, "(struct { uint8 x[", parm_size, "];} p)", NULL); Delete(fn_name); Delete(parm_size); @@ -1161,8 +1126,7 @@ private: * executing the SWIG wrapper code. * ---------------------------------------------------------------------- */ - int gccFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, - SwigType *result) { + int gccFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, SwigType *result) { Wrapper *f = NewWrapper(); Swig_save("gccFunctionWrapper", n, "parms", NULL); @@ -1185,11 +1149,7 @@ private: // Start the function definition. - Printv(f->def, - "#ifdef __cplusplus\n", - "extern \"C\"\n", - "#endif\n", - NULL); + Printv(f->def, "#ifdef __cplusplus\n", "extern \"C\"\n", "#endif\n", NULL); Printv(f->def, "void\n", wname, "(void *swig_v)\n", "{\n", NULL); @@ -1233,9 +1193,7 @@ private: String *tm = Getattr(p, "tmap:in"); if (tm == NULL) { - 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)); + 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(""); @@ -1245,8 +1203,7 @@ private: if (i < required_count) { Printv(f->code, "\t", tm, "\n", NULL); } else { - Printf(f->code, "\tif (swig_a->_swig_optargc > %d) {\n", - i - required_count); + Printf(f->code, "\tif (swig_a->_swig_optargc > %d) {\n", i - required_count); Printv(f->code, "\t\t", tm, "\n", NULL); Printv(f->code, "\t}\n", NULL); } @@ -1289,8 +1246,7 @@ private: * executing the SWIG wrapper code. * ---------------------------------------------------------------------- */ - int gccgoFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, - SwigType *result) { + int gccgoFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, SwigType *result) { Wrapper *f = NewWrapper(); Swig_save("gccgoFunctionWrapper", n, "parms", NULL); @@ -1313,11 +1269,7 @@ private: // Start the function definition. - Printv(f->def, - "#ifdef __cplusplus\n", - "extern \"C\"\n", - "#endif\n", - NULL); + Printv(f->def, "#ifdef __cplusplus\n", "extern \"C\"\n", "#endif\n", NULL); String *fnname = NewString(""); Printv(fnname, go_prefix, "_", wname, "(", NULL); @@ -1374,8 +1326,7 @@ private: String *tm = Getattr(p, "tmap:in"); if (tm == NULL) { 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)); + "Unable to use type %s as a function argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { String *ln = Getattr(p, "lname"); String *pn = NewString("g"); @@ -1452,8 +1403,7 @@ private: * Get the action of the function. This is used for C/C++ function. * ----------------------------------------------------------------------- */ - void emitGoAction(Node *n, List *base, ParmList *parms, SwigType *result, - Wrapper *f) { + void emitGoAction(Node *n, List *base, ParmList *parms, SwigType *result, Wrapper *f) { String *actioncode; if (base == NULL || isStatic(n)) { Swig_director_emit_dynamic_cast(n, f); @@ -1471,8 +1421,7 @@ private: String *last = NULL; int vc = 0; for (Iterator bi = First(base); bi.item != NULL; bi = Next(bi)) { - Printf(actioncode, " %s *swig_b%d = (%s *)%s;\n", bi.item, vc, - bi.item, current); + Printf(actioncode, " %s *swig_b%d = (%s *)%s;\n", bi.item, vc, bi.item, current); Delete(current); current = NewString(""); Printf(current, "swig_b%d", vc); @@ -1491,9 +1440,7 @@ private: String *tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode); if (tm == NULL) { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s\n", - SwigType_str(result, 0)); + 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) { Replaceall(tm, "$result", "swig_a->result"); @@ -1611,10 +1558,9 @@ private: return goComplexConstant(n, type); } - if (Getattr(n, "storage") != NULL - && Strcmp(Getattr(n, "storage"), "static") == 0) { + if (Getattr(n, "storage") != NULL && Strcmp(Getattr(n, "storage"), "static") == 0) { return goComplexConstant(n, type); - } + } String *go_name = buildGoName(Getattr(n, "sym:name"), false, false); @@ -1631,8 +1577,7 @@ private: if (Cmp(value, "true") != 0 && Cmp(value, "false") != 0) { return goComplexConstant(n, type); } - } else if (SwigType_type(type) == T_STRING - || SwigType_type(type) == T_CHAR) { + } else if (SwigType_type(type) == T_STRING || SwigType_type(type) == T_CHAR) { // Backslash sequences are somewhat different in Go and C/C++. if (Strchr(value, '\\') != NULL) { return goComplexConstant(n, type); @@ -1661,11 +1606,9 @@ private: } for (; i < len; ++i) { switch (p[i]) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break; - case 'a': case 'b': case 'c': case 'd': case 'f': - case 'A': case 'B': case 'C': case 'D': case 'F': + case 'a': case 'b': case 'c': case 'd': case 'f': case 'A': case 'B': case 'C': case 'D': case 'F': if (!is_hex) { return goComplexConstant(n, type); } @@ -1778,7 +1721,7 @@ private: Printv(get, ";\n", NULL); Setattr(n, "wrap:action", get); - String* symname = Getattr(n, "sym:name"); + String *symname = Getattr(n, "sym:name"); if (symname == NULL) { symname = Getattr(n, "name"); } @@ -1799,8 +1742,7 @@ private: String *wname = Swig_name_wrapper(sname); Setattr(n, "wrap:name", wname); - int r = makeWrappers(n, sname, go_name, NULL, wname, NULL, NULL, type, - true); + int r = makeWrappers(n, sname, go_name, NULL, wname, NULL, NULL, type, true); if (r != SWIG_OK) { return r; @@ -1808,8 +1750,7 @@ private: String *varname = buildGoName(symname, true, false); String *t = goType(n, type); - Printv(f_go_wrappers, "var ", varname, " ", t, " = ", go_name, "()\n", - NULL); + Printv(f_go_wrappers, "var ", varname, " ", t, " = ", go_name, "()\n", NULL); Delete(varname); Delete(t); @@ -1854,21 +1795,18 @@ private: // A method to return the pointer to the C++ class. This is used // by generated code to convert between the interface and the C++ // value. - Printv(f_go_wrappers, "func (p ", go_type_name, ") Swigcptr() uintptr {\n", - NULL); + Printv(f_go_wrappers, "func (p ", go_type_name, ") Swigcptr() uintptr {\n", NULL); Printv(f_go_wrappers, "\treturn (uintptr)(p)\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); // A method used as a marker for the class, to avoid invalid // interface conversions when using multiple inheritance. - Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigIs", go_name, - "() {\n", NULL); + Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigIs", go_name, "() {\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); if (is_director) { // Return the interface passed to the NewDirector function. - Printv(f_go_wrappers, "func (p ", go_type_name, - ") DirectorInterface() interface{} {\n", NULL); + Printv(f_go_wrappers, "func (p ", go_type_name, ") DirectorInterface() interface{} {\n", NULL); Printv(f_go_wrappers, "\treturn nil\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); } @@ -1891,9 +1829,7 @@ private: // differently in Go and in C++. Hash *local = NewHash(); - for (Node *ni = Getattr(n, "firstChild"); - ni != NULL; - ni = nextSibling(ni)) { + for (Node *ni = Getattr(n, "firstChild"); ni != NULL; ni = nextSibling(ni)) { if (!is_public(ni)) { continue; @@ -1970,9 +1906,7 @@ private: return SWIG_OK; } - for (Node *ni = Getattr(base, "firstChild"); - ni != NULL; - ni = nextSibling(ni)) { + for (Node *ni = Getattr(base, "firstChild"); ni != NULL; ni = nextSibling(ni)) { if (GetFlag(ni, "feature:ignore")) { continue; @@ -1983,10 +1917,7 @@ private: } String *type = Getattr(ni, "nodeType"); - if (Strcmp(type, "constructor") == 0 - || Strcmp(type, "destructor") == 0 - || Strcmp(type, "enum") == 0 - || Strcmp(type, "using") == 0) { + if (Strcmp(type, "constructor") == 0 || Strcmp(type, "destructor") == 0 || Strcmp(type, "enum") == 0 || Strcmp(type, "using") == 0) { continue; } String *storage = Getattr(ni, "storage"); @@ -2022,9 +1953,7 @@ private: } if (Getattr(ni, "sym:overloaded") != NULL) { - for (Node *on = Getattr(ni, "sym:nextSibling"); - on != NULL; - on = Getattr(on, "sym:nextSibling")) { + for (Node *on = Getattr(ni, "sym:nextSibling"); on != NULL; on = Getattr(on, "sym:nextSibling")) { r = goBaseMethod(n, bases, on); if (r != SWIG_OK) { return r; @@ -2036,10 +1965,8 @@ private: if (is_static) { receiver = NULL; } - String *go_name = buildGoName(Getattr(ni, "sym:name"), is_static, - false); - r = makeDispatchFunction(ni, go_name, receiver, is_static, NULL, - false); + String *go_name = buildGoName(Getattr(ni, "sym:name"), is_static, false); + r = makeDispatchFunction(ni, go_name, receiver, is_static, NULL, false); Delete(go_name); if (r != SWIG_OK) { return r; @@ -2108,11 +2035,7 @@ private: Swig_save("goBaseMethod", method, "wrap:action", "parms", NULL); if (Getattr(method, "wrap:action") == NULL) { if (!is_static) { - Swig_MethodToFunction(method, getNSpace(), getClassType(), - (Getattr(method, "template") != NULL - ? SmartPointer - : Extend | SmartPointer), - NULL, false); + Swig_MethodToFunction(method, getNSpace(), getClassType(), (Getattr(method, "template") != NULL ? SmartPointer : Extend | SmartPointer), NULL, false); // Remove any self parameter that was just added. ParmList *parms = Getattr(method, "parms"); if (parms != NULL && Getattr(parms, "self") != NULL) { @@ -2120,15 +2043,12 @@ private: Setattr(method, "parms", parms); } } else { - String *call = Swig_cfunction_call(Getattr(method, "name"), - Getattr(method, "parms")); - Setattr(method, "wrap:action", Swig_cresult(Getattr(method, "type"), - "result", call)); + String *call = Swig_cfunction_call(Getattr(method, "name"), Getattr(method, "parms")); + Setattr(method, "wrap:action", Swig_cresult(Getattr(method, "type"), "result", call)); } } - int r = makeWrappers(method, name, go_name, overname, wname, bases, - Getattr(method, "parms"), result, is_static); + int r = makeWrappers(method, name, go_name, overname, wname, bases, Getattr(method, "parms"), result, is_static); Swig_restore(method); @@ -2170,9 +2090,7 @@ private: flags |= CWRAP_ALL_PROTECTED_ACCESS; } - String *mname = Swig_name_member(getNSpace(), - Getattr(var_class, "sym:name"), - var_name); + String *mname = Swig_name_member(getNSpace(), Getattr(var_class, "sym:name"), var_name); if (is_assignable(var)) { for (Iterator ki = First(var); ki.key != NULL; ki = Next(ki)) { @@ -2193,8 +2111,7 @@ private: String *wname = Swig_name_wrapper(mname_set); ParmList *parms = NewParm(vt, var_name, var); String *result = NewString("void"); - int r = makeWrappers(var, mname_set, go_name, NULL, wname, bases, parms, - result, false); + int r = makeWrappers(var, mname_set, go_name, NULL, wname, bases, parms, result, false); if (r != SWIG_OK) { return r; } @@ -2222,8 +2139,7 @@ private: String *wname = Swig_name_wrapper(mname_get); - int r = makeWrappers(var, mname_get, go_name, NULL, wname, bases, NULL, - vt, false); + int r = makeWrappers(var, mname_get, go_name, NULL, wname, bases, NULL, vt, false); if (r != SWIG_OK) { return r; } @@ -2266,24 +2182,18 @@ private: String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true); String *go_base_name = exportedName(Getattr(b.item, "sym:name")); String *go_base_type = goType(n, Getattr(b.item, "classtypeobj")); - String *go_base_type_name = goCPointerType(Getattr(b.item, - "classtypeobj"), - true); + String *go_base_type_name = goCPointerType(Getattr(b.item, "classtypeobj"), true); - Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigIs", go_base_name, - "() {\n", NULL); + Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigIs", go_base_name, "() {\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); Printv(interfaces, "\tSwigIs", go_base_name, "()\n", NULL); - Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", go_base_name, - "() ", go_base_type, " {\n", NULL); - Printv(f_go_wrappers, "\treturn ", go_base_type_name, - "(p.Swigcptr())\n", NULL); + Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", go_base_name, "() ", go_base_type, " {\n", NULL); + Printv(f_go_wrappers, "\treturn ", go_base_type_name, "(p.Swigcptr())\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); - Printv(interfaces, "\tSwigGet", go_base_name, "() ", go_base_type, "\n", - NULL); + Printv(interfaces, "\tSwigGet", go_base_name, "() ", go_base_type, "\n", NULL); Setattr(parents, go_base_name, NewString("")); @@ -2315,8 +2225,7 @@ private: String *go_base_name = exportedName(Getattr(b.item, "sym:name")); - Swig_save("addExtraBaseInterface", n, "wrap:action", "wrap:name", - "wrap:parms", NULL); + Swig_save("addExtraBaseInterface", n, "wrap:action", "wrap:name", "wrap:parms", NULL); SwigType *type = Copy(Getattr(n, "classtypeobj")); SwigType_add_pointer(type); @@ -2325,8 +2234,7 @@ private: String *pn = Swig_cparm_name(parm, 0); String *action = NewString(""); - Printv(action, "result = (", Getattr(b.item, "classtype"), "*)", pn, - ";", NULL); + Printv(action, "result = (", Getattr(b.item, "classtype"), "*)", pn, ";", NULL); Delete(pn); Setattr(n, "wrap:action", action); @@ -2383,8 +2291,7 @@ private: * classes of parents other than the first base class at each level. * ------------------------------------------------------------ */ - void addParentExtraBaseInterfaces(Node *n, Hash *parents, Node *base, - bool is_base_first, String *sofar) { + void addParentExtraBaseInterfaces(Node *n, Hash *parents, Node *base, bool is_base_first, String *sofar) { List *baselist = Getattr(base, "bases"); if (baselist == NULL || Len(baselist) == 0) { return; @@ -2419,14 +2326,11 @@ private: String *go_base_name = exportedName(Getattr(b.item, "sym:name")); if (Getattr(parents, go_base_name) == NULL) { - Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", - go_base_name, "() ", go_base_name, " {\n", NULL); - Printv(f_go_wrappers, "\treturn p", sf, ".SwigGet", go_base_name, - "()\n", NULL); + Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", go_base_name, "() ", go_base_name, " {\n", NULL); + Printv(f_go_wrappers, "\treturn p", sf, ".SwigGet", go_base_name, "()\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); - Printv(interfaces, "\tSwigGet", go_base_name, "() ", go_base_name, "\n", - NULL); + Printv(interfaces, "\tSwigGet", go_base_name, "() ", go_base_name, "\n", NULL); addParentExtraBaseInterfaces(n, parents, b.item, false, sf); @@ -2478,7 +2382,7 @@ private: String *director_struct_name = NewString("_swig_Director"); Append(director_struct_name, go_name); - String* cxx_director_name = NewString("SwigDirector_"); + String *cxx_director_name = NewString("SwigDirector_"); Append(cxx_director_name, name); // The Go type of the director class. @@ -2487,23 +2391,19 @@ private: Printv(f_go_wrappers, "\tv interface{}\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); - Printv(f_go_wrappers, "func (p *", director_struct_name, - ") Swigcptr() uintptr {\n", NULL); + Printv(f_go_wrappers, "func (p *", director_struct_name, ") Swigcptr() uintptr {\n", NULL); Printv(f_go_wrappers, "\treturn p.", go_type_name, ".Swigcptr()\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); - Printv(f_go_wrappers, "func (p *", director_struct_name, ") SwigIs", - go_name, "() {\n", NULL); + Printv(f_go_wrappers, "func (p *", director_struct_name, ") SwigIs", go_name, "() {\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); - Printv(f_go_wrappers, "func (p *", director_struct_name, - ") DirectorInterface() interface{} {\n", NULL); + Printv(f_go_wrappers, "func (p *", director_struct_name, ") DirectorInterface() interface{} {\n", NULL); Printv(f_go_wrappers, "\treturn p.v\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); // Start defining the director class. - Printv(f_c_directors_h, "class ", cxx_director_name, " : public ", - Getattr(n, "classtype"), "\n", NULL); + Printv(f_c_directors_h, "class ", cxx_director_name, " : public ", Getattr(n, "classtype"), "\n", NULL); Printv(f_c_directors_h, "{\n", NULL); Printv(f_c_directors_h, " public:\n", NULL); @@ -2542,9 +2442,7 @@ private: String *cn = exportedName(Getattr(parentNode(n), "sym:name")); - String *go_type_name = goCPointerType(Getattr(parentNode(n), - "classtypeobj"), - true); + String *go_type_name = goCPointerType(Getattr(parentNode(n), "classtypeobj"), true); String *director_struct_name = NewString("_swig_Director"); Append(director_struct_name, cn); @@ -2616,14 +2514,12 @@ private: Printv(f_go_wrappers, ") ", go_type_name, NULL); if (gccgo_flag) { - Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", wname, "\")", - NULL); + Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", wname, "\")", NULL); } Printv(f_go_wrappers, "\n\n", NULL); - Printv(f_go_wrappers, "func ", func_with_over_name, "(v interface{}", - NULL); + Printv(f_go_wrappers, "func ", func_with_over_name, "(v interface{}", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -2638,8 +2534,7 @@ private: Printv(f_go_wrappers, ") ", cn, " {\n", NULL); - Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", - NULL); + Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL); Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL); if (overname != NULL) { Printv(f_go_wrappers, overname, NULL); @@ -2660,8 +2555,7 @@ private: SwigType *result = Copy(Getattr(parentNode(n), "classtypeobj")); SwigType_add_pointer(result); - Swig_save("classDirectorConstructor", n, "wrap:name", "wrap:action", - NULL); + Swig_save("classDirectorConstructor", n, "wrap:name", "wrap:action", NULL); Setattr(n, "wrap:name", Swig_name_wrapper(name)); @@ -2715,13 +2609,11 @@ private: Printv(f_c_directors_h, " ", decl, ";\n", NULL); Delete(decl); - decl = Swig_method_decl(NULL, Getattr(n, "decl"), - cxx_director_name, first_parm, 0, 0); + decl = Swig_method_decl(NULL, Getattr(n, "decl"), cxx_director_name, first_parm, 0, 0); Printv(f_c_directors, cxx_director_name, "::", decl, "\n", NULL); Delete(decl); - Printv(f_c_directors, " : ", Getattr(parentNode(n), "classtype"), "(", - NULL); + Printv(f_c_directors, " : ", Getattr(parentNode(n), "classtype"), "(", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -2739,9 +2631,7 @@ private: Printv(f_c_directors, "{ }\n\n", NULL); if (Getattr(n, "sym:overloaded") && Getattr(n, "sym:nextSibling") == NULL) { - int r = makeDispatchFunction(n, func_name, cn, is_static, - Getattr(parentNode(n), "classtypeobj"), - false); + int r = makeDispatchFunction(n, func_name, cn, is_static, Getattr(parentNode(n), "classtypeobj"), false); if (r != SWIG_OK) { return r; } @@ -2785,9 +2675,7 @@ private: Setattr(n, "wrap:name", fnname); - Swig_DestructorToFunction(n, getNSpace(), - Getattr(parentNode(n), "classtype"), - CPlusPlus, Extend); + Swig_DestructorToFunction(n, getNSpace(), Getattr(parentNode(n), "classtype"), CPlusPlus, Extend); ParmList *parms = Getattr(n, "parms"); Setattr(n, "wrap:parms", parms); @@ -2819,8 +2707,7 @@ private: String *director_struct_name = NewString("_swig_Director"); Append(director_struct_name, cn); - Printv(f_c_directors_h, " virtual ~SwigDirector_", class_name, "()", - NULL); + Printv(f_c_directors_h, " virtual ~SwigDirector_", class_name, "()", NULL); String *throws = buildThrow(n); if (throws != NULL) { @@ -2831,16 +2718,13 @@ private: if (!is_ignored) { if (!gccgo_flag) { - Printv(f_c_directors, "extern \"C\" void ", wname, "(void*, int);\n", - NULL); + Printv(f_c_directors, "extern \"C\" void ", wname, "(void*, int);\n", NULL); } else { - Printv(f_c_directors, "extern \"C\" void ", wname, "(void*) __asm__(\"", - go_prefix, ".", package, ".", go_name, "\");\n", NULL); + Printv(f_c_directors, "extern \"C\" void ", wname, "(void*) __asm__(\"", go_prefix, ".", package, ".", go_name, "\");\n", NULL); } } - Printv(f_c_directors, "SwigDirector_", class_name, "::~SwigDirector_", - class_name, "()", NULL); + Printv(f_c_directors, "SwigDirector_", class_name, "::~SwigDirector_", class_name, "()", NULL); if (throws != NULL) { Printv(f_c_directors, " ", throws, NULL); @@ -2854,17 +2738,14 @@ private: if (!gccgo_flag) { Printv(f_c_directors, " struct { void *p; } a;\n", NULL); Printv(f_c_directors, " a.p = go_val;\n", NULL); - Printv(f_c_directors, " crosscall2(", wname, - ", &a, (int) sizeof a);\n", NULL); + Printv(f_c_directors, " crosscall2(", wname, ", &a, (int) sizeof a);\n", NULL); - Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", - NULL); + Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", NULL); Printv(f_gc_wrappers, "extern void \xc2\xb7", go_name, "();\n", NULL); Printv(f_gc_wrappers, "void\n", NULL); Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL); Printv(f_gc_wrappers, "{\n", NULL); - Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", go_name, ", a, n);\n", - NULL); + Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL); Printv(f_gc_wrappers, "}\n\n", NULL); } else { Printv(f_c_directors, " ", wname, "(go_val);\n", NULL); @@ -2874,8 +2755,7 @@ private: Printv(f_c_directors, "}\n\n", NULL); if (!is_ignored) { - Printv(f_go_wrappers, "func ", go_name, "(p *", director_struct_name, - ") {\n", NULL); + Printv(f_go_wrappers, "func ", go_name, "(p *", director_struct_name, ") {\n", NULL); Printv(f_go_wrappers, "\tp.", class_receiver, " = 0\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); } @@ -2898,8 +2778,7 @@ private: (void) super; bool is_ignored = GetFlag(n, "feature:ignore"); - bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 - && Cmp(Getattr(n, "value"), "0") == 0); + bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 && Cmp(Getattr(n, "value"), "0") == 0); // We don't need explicit calls. if (GetFlag(n, "explicitcall")) { @@ -2934,9 +2813,7 @@ private: // class_methods so that we correctly handle cases where a // function in one class hides a function of the same name in a // parent class. - for (Node *on = Getattr(n, "sym:overloaded"); - on != NULL; - on = Getattr(on, "sym:nextSibling")) { + for (Node *on = Getattr(n, "sym:overloaded"); on != NULL; on = Getattr(on, "sym:nextSibling")) { int r = oneClassDirectorMethod(on, parent); if (r != SWIG_OK) { return r; @@ -2959,8 +2836,7 @@ private: String *director_struct_name = NewString("_swig_Director"); Append(director_struct_name, cn); - int r = makeDispatchFunction(n, go_name, director_struct_name, is_static, - director_struct_name, false); + int r = makeDispatchFunction(n, go_name, director_struct_name, is_static, director_struct_name, false); if (r != SWIG_OK) { return r; } @@ -2968,8 +2844,7 @@ private: String *go_upcall = NewString("Director"); Append(go_upcall, cn); Append(go_upcall, go_name); - r = makeDispatchFunction(n, go_upcall, director_struct_name, is_static, - director_struct_name, true); + r = makeDispatchFunction(n, go_upcall, director_struct_name, is_static, director_struct_name, true); if (r != SWIG_OK) { return r; } @@ -2991,8 +2866,7 @@ private: int oneClassDirectorMethod(Node *n, Node *parent) { bool is_ignored = GetFlag(n, "feature:ignore"); - bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 - && Cmp(Getattr(n, "value"), "0") == 0); + bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 && Cmp(Getattr(n, "value"), "0") == 0); String *name = Getattr(n, "sym:name"); if (name == NULL) { @@ -3007,8 +2881,7 @@ private: String *cn = exportedName(Getattr(parent, "sym:name")); - String *go_type_name = goCPointerType(Getattr(parent, "classtypeobj"), - true); + String *go_type_name = goCPointerType(Getattr(parent, "classtypeobj"), true); String *director_struct_name = NewString("_swig_Director"); Append(director_struct_name, cn); @@ -3123,8 +2996,7 @@ private: String *upcall_gc_name = buildGoWrapperName(upcall_name, overname); - Printv(f_go_wrappers, "func ", upcall_gc_name, "(", - go_type_name, NULL); + Printv(f_go_wrappers, "func ", upcall_gc_name, "(", go_type_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3144,16 +3016,14 @@ private: } if (gccgo_flag) { - Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", upcall_wname, - "\")", NULL); + Printv(f_go_wrappers, " __asm__(\"", go_prefix, "_", upcall_wname, "\")", NULL); } Printv(f_go_wrappers, "\n", NULL); // Define the method on the director class in Go. - Printv(f_go_wrappers, "func (swig_p *", director_struct_name, ") ", - go_with_over_name, "(", NULL); + Printv(f_go_wrappers, "func (swig_p *", director_struct_name, ") ", go_with_over_name, "(", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3178,8 +3048,7 @@ private: Printv(f_go_wrappers, " {\n", NULL); - Printv(f_go_wrappers, "\tif swig_g, swig_ok := swig_p.v.(", - interface_name, "); swig_ok {\n", NULL); + Printv(f_go_wrappers, "\tif swig_g, swig_ok := swig_p.v.(", interface_name, "); swig_ok {\n", NULL); Printv(f_go_wrappers, "\t\t", NULL); if (SwigType_type(result) != T_VOID) { Printv(f_go_wrappers, "return ", NULL); @@ -3230,9 +3099,7 @@ private: if (overname != NULL) { Append(upcall_method_name, overname); } - String *upcall_decl = Swig_method_decl(Getattr(n, "type"), - Getattr(n, "decl"), - upcall_method_name, parms, 0, 0); + String *upcall_decl = Swig_method_decl(Getattr(n, "type"), Getattr(n, "decl"), upcall_method_name, parms, 0, 0); Printv(f_c_directors_h, " ", upcall_decl, " {\n", NULL); Delete(upcall_decl); @@ -3240,8 +3107,7 @@ private: if (SwigType_type(result) != T_VOID) { Printv(f_c_directors_h, "return ", NULL); } - Printv(f_c_directors_h, Getattr(parent, "classtype"), "::", - Getattr(n, "name"), "(", NULL); + Printv(f_c_directors_h, Getattr(parent, "classtype"), "::", Getattr(n, "name"), "(", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3282,8 +3148,7 @@ private: Printv(action, "&", NULL); } } - Printv(action, Swig_cparm_name(NULL, 0), "->", upcall_method_name, "(", - NULL); + Printv(action, Swig_cparm_name(NULL, 0), "->", upcall_method_name, "(", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3309,9 +3174,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(n, upcall_name, upcall_name, overname, upcall_wname, first_parm, result, is_static, true); if (r != SWIG_OK) { return r; } @@ -3338,8 +3201,7 @@ private: // Define a function which uses the Go director type that other // methods in the Go type can call to get parent methods. - Printv(f_go_wrappers, "func Director", cn, go_with_over_name, "(p ", cn, - NULL); + Printv(f_go_wrappers, "func Director", cn, go_with_over_name, "(p ", cn, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3365,8 +3227,7 @@ private: if (SwigType_type(result) != T_VOID) { Printv(f_go_wrappers, "return ", NULL); } - Printv(f_go_wrappers, upcall_gc_name, "(p.(*", - director_struct_name, ").", go_type_name, NULL); + Printv(f_go_wrappers, upcall_gc_name, "(p.(*", director_struct_name, ").", go_type_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3385,8 +3246,7 @@ private: // The Go function which invokes the method. This is called // from by the C++ method on the director class. - Printv(f_go_wrappers, "func ", callback_name, "(p *", - director_struct_name, NULL); + Printv(f_go_wrappers, "func ", callback_name, "(p *", director_struct_name, NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3466,12 +3326,11 @@ private: } // Build the C++ functions. - + Delete(upcall_wname); if (!gccgo_flag) { - Printv(f_c_directors, "extern \"C\" void ", callback_wname, - "(void*, int);\n", NULL); + Printv(f_c_directors, "extern \"C\" void ", callback_wname, "(void*, int);\n", NULL); } else { Printv(f_c_directors, "extern \"C\" ", NULL); @@ -3502,8 +3361,7 @@ private: Delete(fnname); - Printv(f_c_directors, " __asm__(\"", go_prefix, ".", package, ".", - callback_name, "\");\n", NULL); + Printv(f_c_directors, " __asm__(\"", go_prefix, ".", package, ".", callback_name, "\");\n", NULL); } Delete(upcall_method_name); @@ -3513,18 +3371,13 @@ private: if (!is_ignored || is_pure_virtual) { // Declare the method for the director class. - SwigType *rtype = (Getattr(n, "conversion_operator") - ? NULL - : Getattr(n, "type")); - String *decl = Swig_method_decl(rtype, Getattr(n, "decl"), - Getattr(n, "name"), parms, - 0, 0); + SwigType *rtype = (Getattr(n, "conversion_operator") ? NULL : Getattr(n, "type")); + String *decl = Swig_method_decl(rtype, Getattr(n, "decl"), Getattr(n, "name"), parms, 0, 0); Printv(f_c_directors_h, " virtual ", decl, NULL); Delete(decl); String *qname = NewString(""); - Printv(qname, "SwigDirector_", class_name, "::", Getattr(n, "name"), - NULL); + Printv(qname, "SwigDirector_", class_name, "::", Getattr(n, "name"), NULL); decl = Swig_method_decl(rtype, Getattr(n, "decl"), qname, parms, 0, 0); Printv(f->def, decl, NULL); Delete(decl); @@ -3542,8 +3395,7 @@ private: Printv(f->def, " {\n", NULL); if (SwigType_type(result) != T_VOID) { - Wrapper_add_local(f, "c_result", - SwigType_lstr(Getattr(n, "returntype"), "c_result")); + Wrapper_add_local(f, "c_result", SwigType_lstr(Getattr(n, "returntype"), "c_result")); } if (!is_ignored) { @@ -3582,9 +3434,7 @@ private: String *tm = Getattr(p, "tmap:directorin"); if (tm == NULL) { 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)); + line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { String *ln = Getattr(p, "lname"); String *input = NewString(""); @@ -3597,8 +3447,7 @@ private: p = Getattr(p, "tmap:directorin:next"); } - Printv(f->code, " crosscall2(", callback_wname, - ", &swig_a, (int) sizeof swig_a);\n", NULL); + Printv(f->code, " crosscall2(", callback_wname, ", &swig_a, (int) sizeof swig_a);\n", NULL); if (SwigType_type(result) != T_VOID) { String *rname = NewString("c_result"); @@ -3606,14 +3455,12 @@ private: String *tm = Swig_typemap_lookup("directorout", rp, rname, NULL); if (tm == NULL) { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use type %s as director method result\n", - SwigType_str(result, 0)); + "Unable to use type %s as director method result\n", SwigType_str(result, 0)); } else { Replaceall(tm, "$input", "swig_a.result"); Replaceall(tm, "$result", "c_result"); Printv(f->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), - "c_result"); + String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result"); Printv(f->code, " return ", retstr, ";\n", NULL); Delete(retstr); Delete(tm); @@ -3623,15 +3470,12 @@ private: } // The C wrapper code which calls the Go function. - Printv(f_gc_wrappers, "#pragma dynexport ", callback_wname, " ", - callback_wname, "\n", NULL); - Printv(f_gc_wrappers, "extern void \xc2\xb7", callback_name, "();\n", - NULL); + Printv(f_gc_wrappers, "#pragma dynexport ", callback_wname, " ", callback_wname, "\n", NULL); + Printv(f_gc_wrappers, "extern void \xc2\xb7", callback_name, "();\n", NULL); Printv(f_gc_wrappers, "void\n", NULL); Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL); Printv(f_gc_wrappers, "{\n", NULL); - Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", callback_name, - ", a, n);\n", NULL); + Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL); Printv(f_gc_wrappers, "}\n\n", NULL); } else { if (SwigType_type(result) != T_VOID) { @@ -3661,9 +3505,7 @@ private: tm = Getattr(p, "tmap:directorin"); if (tm == NULL) { 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)); + line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { Replaceall(tm, "$input", pn); Replaceall(tm, "$owner", 0); @@ -3687,14 +3529,12 @@ private: String *tm = Swig_typemap_lookup("directorout", rp, rname, NULL); if (tm == NULL) { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use type %s as director method result\n", - SwigType_str(result, 0)); + "Unable to use type %s as director method result\n", SwigType_str(result, 0)); } else { Replaceall(tm, "$input", "result"); Replaceall(tm, "$result", "c_result"); Printv(f->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), - "c_result"); + String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result"); Printv(f->code, " return ", retstr, ";\n", NULL); Delete(retstr); Delete(tm); @@ -3705,11 +3545,9 @@ private: } } else { assert(is_pure_virtual); - Printv(f->code, " _swig_gopanic(\"call to pure virtual function ", - Getattr(parent, "sym:name"), name, "\");\n"); + Printv(f->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n"); if (SwigType_type(result) != T_VOID) { - String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), - "c_result"); + String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result"); Printv(f->code, " return ", retstr, ";\n", NULL); Delete(retstr); } @@ -3819,27 +3657,18 @@ private: * the type of the first argument to the function. *--------------------------------------------------------------------*/ - int makeDispatchFunction(Node *n, String *go_name, String *receiver, - bool is_static, SwigType *director_struct, - bool is_upcall) { + int makeDispatchFunction(Node *n, String *go_name, String *receiver, bool is_static, SwigType *director_struct, bool is_upcall) { bool is_director = director_struct != NULL; String *nodetype = Getattr(n, "nodeType"); bool is_constructor = Cmp(nodetype, "constructor") == 0; bool is_destructor = Cmp(nodetype, "destructor") == 0; - bool can_use_receiver = (!is_constructor - && !is_destructor - && !is_upcall); + bool can_use_receiver = (!is_constructor && !is_destructor && !is_upcall); - bool use_receiver = (!is_static - && can_use_receiver); + bool use_receiver = (!is_static && can_use_receiver); - bool add_to_interface = (interfaces != NULL - && !is_constructor - && !is_destructor - && !is_static - && !is_upcall); + bool add_to_interface = (interfaces != NULL && !is_constructor && !is_destructor && !is_static && !is_upcall); List *dispatch = Swig_overload_rank(n, false); int nfunc = Len(dispatch); @@ -3963,8 +3792,7 @@ private: if (num_required == num_arguments) { Printf(f_go_wrappers, "\tif argc == %d {\n", num_required); } else { - Printf(f_go_wrappers, "\tif argc >= %d && argc <= %d {\n", - num_required, num_arguments); + Printf(f_go_wrappers, "\tif argc >= %d && argc <= %d {\n", num_required, num_arguments); } } @@ -4070,10 +3898,7 @@ private: result = NULL; } - if (result != NULL - && SwigType_type(result) != T_VOID - && (all_result == NULL - || SwigType_type(all_result) != T_VOID)) { + if (result != NULL && SwigType_type(result) != T_VOID && (all_result == NULL || SwigType_type(all_result) != T_VOID)) { Printv(start, "return ", NULL); } @@ -4081,16 +3906,12 @@ private: if (receiver != NULL && use_receiver) { Printv(start, "p.", go_name, NULL); - } else if (can_use_receiver - && !isStatic(ni) - && pi != NULL - && Getattr(pi, "self") != NULL) { + } else if (can_use_receiver && !isStatic(ni) && pi != NULL && Getattr(pi, "self") != NULL) { // This is an overload of a static function and a non-static // function. assert(num_required > 0); SwigType *tm = goWrapperType(pi, Getattr(pi, "type"), true); - String *nm = buildGoName(Getattr(ni, "sym:name"), false, - isFriend(ni)); + String *nm = buildGoName(Getattr(ni, "sym:name"), false, isFriend(ni)); Printv(start, "a[0].(", tm, ").", nm, NULL); Delete(nm); Delete(tm); @@ -4137,9 +3958,7 @@ private: } String *end = NULL; - if (result == NULL - || SwigType_type(result) == T_VOID - || (all_result != NULL && SwigType_type(all_result) == T_VOID)) { + if (result == NULL || SwigType_type(result) == T_VOID || (all_result != NULL && SwigType_type(all_result) == T_VOID)) { end = NewString(""); Printv(end, "return", NULL); if (all_result == NULL || SwigType_type(all_result) != T_VOID) { @@ -4183,8 +4002,7 @@ private: } Printv(f_go_wrappers, "fail:\n", NULL); - Printv(f_go_wrappers, - "\tpanic(\"No match for overloaded function call\")\n", NULL); + Printv(f_go_wrappers, "\tpanic(\"No match for overloaded function call\")\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); if (all_result != NULL) { @@ -4244,8 +4062,7 @@ private: String *copy = Copy(name); if (class_name != NULL) { char *p = Char(name); - if (Strncmp(name, class_name, Len(class_name)) == 0 - && p[Len(class_name)] == '_') { + if (Strncmp(name, class_name, Len(class_name)) == 0 && p[Len(class_name)] == '_') { Replace(copy, class_name, "", DOH_REPLACE_FIRST); Replace(copy, "_", "", DOH_REPLACE_FIRST); } @@ -4475,9 +4292,7 @@ private: Delete(t); if (ret == NULL) { - Swig_warning(WARN_LANG_NATIVE_UNIMPL, input_file, line_number, - "No Go typemap defined for %s\n", - SwigType_str(type, 0)); + Swig_warning(WARN_LANG_NATIVE_UNIMPL, input_file, line_number, "No Go typemap defined for %s\n", SwigType_str(type, 0)); ret = NewString("uintptr"); } @@ -4662,13 +4477,13 @@ private: return gcCTypeForGoValue(n, type, name); } - /* ------------------------------------------------------------ + /* ---------------------------------------------------------------------- * goTypeIsInterface * * Return whether this C++ type is represented as an interface type * in Go. These types require adjustments in the Go code when * passing them back and forth between Go and C++. - * ------------------------------------------------------------ */ + * ---------------------------------------------------------------------- */ bool goTypeIsInterface(Node *n, SwigType *type) { bool is_interface; @@ -4676,11 +4491,11 @@ private: return is_interface; } - /* ------------------------------------------------------------ + /* ---------------------------------------------------------------------- * hasGoTypemap * * Return whether a type has a "go" typemap entry. - * ------------------------------------------------------------ */ + * ---------------------------------------------------------------------- */ bool hasGoTypemap(SwigType *type) { Parm *p = NewParmWithoutFileLineInfo(type, "test"); @@ -4699,8 +4514,7 @@ private: /* ---------------------------------------------------------------------- * goEnumName() * - * Given an enum node, return a string to use for the enum type in - * Go. + * Given an enum node, return a string to use for the enum type in Go. * ---------------------------------------------------------------------- */ String *goEnumName(Node *n) { @@ -4739,11 +4553,11 @@ private: } - /* ------------------------------------------------------------ + /* ---------------------------------------------------------------------- * getParm() * * Get the real parameter to use. - * ------------------------------------------------------------ */ + * ---------------------------------------------------------------------- */ Parm *getParm(Parm *p) { while (p != NULL && checkAttribute(p, "tmap:in:numinputs", "0")) { @@ -4752,11 +4566,11 @@ private: return p; } - /* ------------------------------------------------------------ + /* ---------------------------------------------------------------------- * nextParm() * * Return the next parameter. - * ------------------------------------------------------------ */ + * ---------------------------------------------------------------------- */ Parm *nextParm(Parm *p) { if (p == NULL) { @@ -4768,27 +4582,24 @@ private: } } - /* ------------------------------------------------------------ + /* ---------------------------------------------------------------------- * isStatic * * Return whether a node should be considered as static rather than * as a member. - * ------------------------------------------------------------ */ + * ---------------------------------------------------------------------- */ bool isStatic(Node *n) { String *storage = Getattr(n, "storage"); - return (storage != NULL - && (Strcmp(storage, "static") == 0 - || Strcmp(storage, "friend") == 0) - && (!SmartPointer - || Getattr(n, "allocate:smartpointeraccess") == NULL)); + return (storage != NULL && (Strcmp(storage, "static") == 0 || Strcmp(storage, "friend") == 0) + && (!SmartPointer || Getattr(n, "allocate:smartpointeraccess") == NULL)); } - /* ------------------------------------------------------------ + /* ---------------------------------------------------------------------- * isFriend * * Return whether a node is a friend. - * ------------------------------------------------------------ */ + * ---------------------------------------------------------------------- */ bool isFriend(Node *n) { String *storage = Getattr(n, "storage"); From 5408fe8f00b7fde3464e4497ebbf7c7c219b134e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jun 2010 19:03:53 +0000 Subject: [PATCH 171/203] minor typo fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12119 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Go.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index f6e87afb4..8d106858b 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -71,7 +71,7 @@ borne in mind when reading the rest of the SWIG documentation.

      To generate Go code, use the -go option with SWIG. By default SWIG will generate code for the gc compilers. To generate -code for gccgo, you should use the -gccgo option. +code for gccgo, you should also use the -gccgo option.

      20.2.1 Additional Commandline Options

      @@ -151,7 +151,7 @@ may be helpful to include it in your code, compiled with the usual C or C++ compiler.
    • If using the gc compiler, MODULE_gc.c will contain C code which should -be compiled with the C compiler which part of the gc compiler: 6c, 8c, +be compiled with the C compiler distributed as part of the gc compiler: 6c, 8c, or 5c. It should then be combined with the compiled MODULE.go using gopack. This file will not be generated when using gccgo. From 7e7bd74ff21412d37a694e77458e6d3db074d880 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jun 2010 19:05:30 +0000 Subject: [PATCH 172/203] Remove Go director hack just to please the SWIG test-suite git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12120 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/director_extend.i | 5 ++++- Lib/go/goruntime.swg | 10 ---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Examples/test-suite/director_extend.i b/Examples/test-suite/director_extend.i index 515866ac6..cec930a42 100644 --- a/Examples/test-suite/director_extend.i +++ b/Examples/test-suite/director_extend.i @@ -18,6 +18,8 @@ namespace Swig { #endif %} +// Some director implementations do not have Swig::director +#if !defined(SWIGGO) %extend SpObject { size_t ExceptionMethod() @@ -29,7 +31,8 @@ namespace Swig { size_t size = sizeof(Swig::Director); return size; } -}; +} +#endif %inline %{ diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 5a51fd4b6..246814818 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -196,13 +196,3 @@ void __go_panic_msg(const char *); if (!(expr)) { _swig_gopanic(msg); } else %} -#ifdef __cplusplus -/* We don't need a Swig::Director class, but the Swig testsuite - expects one. */ -%insert(runtime) %{ -namespace Swig { - typedef int Director; -} -%} - -#endif From 688db4ee295fe9f941f709005e9be07ca4cf8ef0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jun 2010 22:36:58 +0000 Subject: [PATCH 173/203] Fix std::map warning keyword hack in Go git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12121 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/li_std_map.i | 9 +++++++++ Lib/go/gokw.swg | 4 +++- Lib/go/std_map.i | 4 ---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/li_std_map.i b/Examples/test-suite/li_std_map.i index d5929d786..bf24c35e1 100644 --- a/Examples/test-suite/li_std_map.i +++ b/Examples/test-suite/li_std_map.i @@ -1,6 +1,15 @@ %module("templatereduce") li_std_map %feature("trackobjects"); +%inline %{ +namespace another { +struct map { + int val; + map(int x) : val(x) {} +}; +} +%} + %include "std_pair.i" %include "std_map.i" %include "std_string.i" diff --git a/Lib/go/gokw.swg b/Lib/go/gokw.swg index e7506d053..dd9f35aa3 100644 --- a/Lib/go/gokw.swg +++ b/Lib/go/gokw.swg @@ -1,6 +1,7 @@ /* Rename keywords. */ #define GOKW(x) %keywordwarn("'" `x` "' is a Go keyword, renaming to 'X"`x`"'",rename="X%s") `x` +#define GOBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in Go") "::"`x` GOKW(break); GOKW(case); @@ -18,7 +19,6 @@ GOKW(goto); GOKW(if); GOKW(import); GOKW(interface); -GOKW(map); GOKW(package); GOKW(range); GOKW(return); @@ -28,4 +28,6 @@ GOKW(switch); GOKW(type); GOKW(var); +GOBN(map); + #undef GOKW diff --git a/Lib/go/std_map.i b/Lib/go/std_map.i index e37a9e676..84b0c74ff 100644 --- a/Lib/go/std_map.i +++ b/Lib/go/std_map.i @@ -10,11 +10,7 @@ // std::map // ------------------------------------------------------------------------ -// "map" is a keyword in Go. -#define map cmap - %{ -#define map cmap #include #include #include From 8bf4b5a7dc180d254bfe0071954fc4d2df0140b2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 14 Jun 2010 18:33:57 +0000 Subject: [PATCH 174/203] Minor comment fix git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12122 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index cb6e3ad5a..45f6ef1da 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -684,16 +684,16 @@ private: * makeWrappers() * * Write out the various function wrappers. - * N: The function we are emitting. - * NAME: The function name. - * GO_NAME: The name of the function in Go. - * OVERNAME: The overload string for overloaded function. - * WNAME: The SWIG wrapped name--the name of the C function. - * BASE: A list of the names of base classes, in the case where this + * n: The function we are emitting. + * name: The function name. + * go_name: The name of the function in Go. + * overname: The overload string for overloaded function. + * wname: The SWIG wrapped name--the name of the C function. + * base: A list of the names of base classes, in the case where this * is is a vritual method not defined in the current class. - * PARMS: The parameters. - * RESULT: The result type. - * IS_STATIC: Whether this is a static method or member. + * parms: The parameters. + * result: The result type. + * is_static: Whether this is a static method or member. * ---------------------------------------------------------------------- */ int makeWrappers(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { From 96d86b0fec03e4e520f0a986058f9f72cb845dd3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 14 Jun 2010 19:08:11 +0000 Subject: [PATCH 175/203] Fix 'make partialcheck' for go git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12123 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/go/Makefile.in | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 4af612799..6126e77ee 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -69,25 +69,25 @@ multi_import.multicpptest: # Runs the testcase. run_testcase = \ if test -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ - $(GO) -I . $(GOCOMPILEARG) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + $(COMPILETOOL) $(GO) -I . $(GOCOMPILEARG) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ - $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*$(SO); \ + $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*$(SO); \ else \ - $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH ./$*_runme; \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi run_multi_testcase = \ if test -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ - $(GO) -I . $(GOCOMPILEARG) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ + $(COMPILETOOL) $(GO) -I . $(GOCOMPILEARG) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \ if $(GOGCC) ; then \ files=`cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; \ - $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.@OBJEXT@ $$f$(SO); done`; \ + $(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.@OBJEXT@ $$f$(SO); done`; \ else \ - $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \ fi && \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH ./$*_runme; \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi %.clean: From 07e3d62ae85e20572d0260a71db43e3dbd49647a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 15 Jun 2010 17:58:42 +0000 Subject: [PATCH 176/203] Use a single extern "C" around all the wrappers, not one per wrapper. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12126 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 45f6ef1da..e958a0a7f 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -385,6 +385,10 @@ private: Printf(f_go_begin, "\npackage %s\n\n", package); + // All the C++ wrappers should be extern "C". + + Printv(f_c_wrappers, "#ifdef __cplusplus\n", "extern \"C\" {\n", "#endif\n\n", NULL); + // Set up the hash table for types not defined by SWIG. undefined_types = NewHash(); @@ -433,6 +437,9 @@ private: f_c_directors = NULL; } + // End the extern "C". + Printv(f_c_wrappers, "#ifdef __cplusplus\n", "}\n", "#endif\n\n", NULL); + Dump(f_c_runtime, f_c_begin); Dump(f_c_wrappers, f_c_begin); Dump(f_c_init, f_c_begin); @@ -1149,8 +1156,6 @@ private: // Start the function definition. - Printv(f->def, "#ifdef __cplusplus\n", "extern \"C\"\n", "#endif\n", NULL); - Printv(f->def, "void\n", wname, "(void *swig_v)\n", "{\n", NULL); // The single function parameter is a pointer to the real argument @@ -1269,8 +1274,6 @@ private: // Start the function definition. - Printv(f->def, "#ifdef __cplusplus\n", "extern \"C\"\n", "#endif\n", NULL); - String *fnname = NewString(""); Printv(fnname, go_prefix, "_", wname, "(", NULL); From 9d466dd4088ddf256ba689e46325d55ce63d5466 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 15 Jun 2010 17:59:32 +0000 Subject: [PATCH 177/203] Rename size checking macros to avoid leading double underscore. Also change goswig to swiggo. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12127 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/go/goruntime.swg | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 246814818..057f81d01 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -19,16 +19,16 @@ typedef struct { void* array; unsigned int len; unsigned int cap; } _goslice_; with gcc. */ %insert(runtime) %{ -#define __goswig_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; -#define __goswig_size_assert(t, n) __goswig_size_assert_eq(sizeof(t), n, _goswig_sizeof_##t##_is_not_##n) +#define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; +#define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n) -__goswig_size_assert(char, 1) -__goswig_size_assert(short, 2) -__goswig_size_assert(int, 4) -typedef long long __goswig_long_long; -__goswig_size_assert(__goswig_long_long, 8) -__goswig_size_assert(float, 4) -__goswig_size_assert(double, 8) +swiggo_size_assert(char, 1) +swiggo_size_assert(short, 2) +swiggo_size_assert(int, 4) +typedef long long swiggo_long_long; +swiggo_size_assert(swiggo_long_long, 8) +swiggo_size_assert(float, 4) +swiggo_size_assert(double, 8) extern #ifdef __cplusplus From 0d80b4011db6bd3facf1dba1ebec9dfc940e9978 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 15 Jun 2010 18:06:18 +0000 Subject: [PATCH 178/203] Add run test for li_std_vector_ptr. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12128 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/go/li_std_vector_ptr_runme.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Examples/test-suite/go/li_std_vector_ptr_runme.go diff --git a/Examples/test-suite/go/li_std_vector_ptr_runme.go b/Examples/test-suite/go/li_std_vector_ptr_runme.go new file mode 100644 index 000000000..cee997ad0 --- /dev/null +++ b/Examples/test-suite/go/li_std_vector_ptr_runme.go @@ -0,0 +1,12 @@ +package main + +import . "./li_std_vector_ptr" + +func main() { + ip1 := MakeIntPtr(11) + ip2 := MakeIntPtr(22) + vi := NewIntPtrVector() + vi.Add(ip1) + vi.Add(ip2) + DisplayVector(vi) +} From da5e02f81c9f04ca66b54fa6a0608fd7c8ef3b51 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 15 Jun 2010 19:40:34 +0000 Subject: [PATCH 179/203] Rename "go" typemap to "gotype". git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12129 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Go.html | 2 +- Examples/go/multimap/example.i | 6 +-- Examples/test-suite/namespace_typemap.i | 4 +- Examples/test-suite/typemap_namespace.i | 2 +- Lib/go/cdata.i | 2 +- Lib/go/go.swg | 60 ++++++++++++------------- Lib/go/std_string.i | 2 +- Lib/go/typemaps.i | 6 +-- Source/Modules/go.cxx | 16 +++---- 9 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 8d106858b..1082a8f66 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -454,7 +454,7 @@ value.

      -These type mappings are defined by the "go" typemap. You may change +These type mappings are defined by the "gotype" typemap. You may change that typemap, or add new values, to control how C/C++ types are mapped into Go types.

      diff --git a/Examples/go/multimap/example.i b/Examples/go/multimap/example.i index 04d6eea20..8de6b0dc3 100644 --- a/Examples/go/multimap/example.i +++ b/Examples/go/multimap/example.i @@ -12,7 +12,7 @@ extern int squareCubed (int n, int *OUTPUT); extern int gcd(int x, int y); -%typemap(go) (int argc, char *argv[]) "[]string" +%typemap(gotype) (int argc, char *argv[]) "[]string" %typemap(in) (int argc, char *argv[]) %{ @@ -40,7 +40,7 @@ extern int gcd(int x, int y); extern int gcdmain(int argc, char *argv[]); -%typemap(go) (char *bytes, int len) "string" +%typemap(gotype) (char *bytes, int len) "string" %typemap(in) (char *bytes, int len) %{ @@ -55,7 +55,7 @@ extern int count(char *bytes, int len, char c); * modified. */ -%typemap(go) (char *str, int len) "[]string" +%typemap(gotype) (char *str, int len) "[]string" %typemap(in) (char *str, int len) %{ diff --git a/Examples/test-suite/namespace_typemap.i b/Examples/test-suite/namespace_typemap.i index 4952aa7ad..f25f88574 100644 --- a/Examples/test-suite/namespace_typemap.i +++ b/Examples/test-suite/namespace_typemap.i @@ -71,7 +71,7 @@ namespace test { } #endif #ifdef SWIGGO -%typemap(go) test::test_complex * "complex128" +%typemap(gotype) test::test_complex * "complex128" %typemap(in) test::test_complex * { $1 = new test_complex(__real__ $input, __imag__ $input); } @@ -107,7 +107,7 @@ namespace test { } #endif #ifdef SWIGGO - %typemap(go) string_class * "string" + %typemap(gotype) string_class * "string" %typemap(in) string_class * { $1 = new string_class($input.p); } diff --git a/Examples/test-suite/typemap_namespace.i b/Examples/test-suite/typemap_namespace.i index 6bf53e989..6614e0372 100644 --- a/Examples/test-suite/typemap_namespace.i +++ b/Examples/test-suite/typemap_namespace.i @@ -27,7 +27,7 @@ namespace Foo { %typemap(javaout) Str1 * = char *; #endif #ifdef SWIGGO - %typemap(go) Str1 * = char *; + %typemap(gotype) Str1 * = char *; #endif %typemap(in) Str1 * = char *; #if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGGO)) diff --git a/Lib/go/cdata.i b/Lib/go/cdata.i index c3307945a..decf297c1 100644 --- a/Lib/go/cdata.i +++ b/Lib/go/cdata.i @@ -11,7 +11,7 @@ typedef struct SWIGCDATA { } SWIGCDATA; %} -%typemap(go) SWIGCDATA %{ []byte %} +%typemap(gotype) SWIGCDATA %{ []byte %} %typemap(out) SWIGCDATA (swigcdata argp) { argp = _swig_makegobyteslice($1.data, $1.len); $result.data = (char*)argp.data; diff --git a/Lib/go/go.swg b/Lib/go/go.swg index b1b8860df..648e112e1 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -6,27 +6,27 @@ /* Basic types */ -%typemap(go) bool, const bool & "bool" -%typemap(go) char, const char & "byte" -%typemap(go) signed char, const signed char & "int8" -%typemap(go) unsigned char, const unsigned char & "byte" -%typemap(go) short, const short & "int16" -%typemap(go) unsigned short, const unsigned short & "uint16" -%typemap(go) int, const int & "int" -%typemap(go) unsigned int, const unsigned int & "uint" +%typemap(gotype) bool, const bool & "bool" +%typemap(gotype) char, const char & "byte" +%typemap(gotype) signed char, const signed char & "int8" +%typemap(gotype) unsigned char, const unsigned char & "byte" +%typemap(gotype) short, const short & "int16" +%typemap(gotype) unsigned short, const unsigned short & "uint16" +%typemap(gotype) int, const int & "int" +%typemap(gotype) unsigned int, const unsigned int & "uint" #if SWIGGO_LONG_TYPE_SIZE == 32 -%typemap(go) long, const long & "int32" -%typemap(go) unsigned long, const unsigned long & "uint32" +%typemap(gotype) long, const long & "int32" +%typemap(gotype) unsigned long, const unsigned long & "uint32" #elif SWIGGO_LONG_TYPE_SIZE == 64 -%typemap(go) long, const long & "int64" -%typemap(go) unsigned long, const unsigned long & "uint64" +%typemap(gotype) long, const long & "int64" +%typemap(gotype) unsigned long, const unsigned long & "uint64" #else #error "SWIGGO_LONG_TYPE_SIZE not 32 or 64" #endif -%typemap(go) long long, const long long & "int64" -%typemap(go) unsigned long long, const unsigned long long & "uint64" -%typemap(go) float, const float & "float32" -%typemap(go) double, const double & "float64" +%typemap(gotype) long long, const long long & "int64" +%typemap(gotype) unsigned long long, const unsigned long long & "uint64" +%typemap(gotype) float, const float & "float32" +%typemap(gotype) double, const double & "float64" %typemap(in) bool, char, @@ -164,9 +164,9 @@ /* The size_t type. */ #if SWIGGO_LONG_TYPE_SIZE == 32 -%typemap(go) size_t, const size_t & %{int%} +%typemap(gotype) size_t, const size_t & %{int%} #else -%typemap(go) size_t, const size_t & %{int64%} +%typemap(gotype) size_t, const size_t & %{int64%} #endif %typemap(in) size_t @@ -198,7 +198,7 @@ /* Member pointers. */ -%typemap(go) SWIGTYPE (CLASS::*) +%typemap(gotype) SWIGTYPE (CLASS::*) %{$gotypename%} %typemap(in) SWIGTYPE (CLASS::*) @@ -223,7 +223,7 @@ /* We can't translate pointers using a typemap, so that is handled in the C++ code. */ -%typemap(go) SWIGTYPE * +%typemap(gotype) SWIGTYPE * %{$gotypename%} %typemap(in) SWIGTYPE * @@ -242,7 +242,7 @@ /* Pointer references. */ -%typemap(go) SWIGTYPE *const& +%typemap(gotype) SWIGTYPE *const& %{$gotypename%} %typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) @@ -266,7 +266,7 @@ type _swig_memberptr *byte /* Converting a C++ reference to Go has to be handled in the C++ code. */ -%typemap(go) SWIGTYPE & +%typemap(gotype) SWIGTYPE & %{$gotypename%} %typemap(in) SWIGTYPE & @@ -284,7 +284,7 @@ type _swig_memberptr *byte /* C arrays turn into Go pointers. If we know the length we can use a slice. */ -%typemap(go) SWIGTYPE [] +%typemap(gotype) SWIGTYPE [] %{$gotypename%} %typemap(in) SWIGTYPE [] @@ -301,7 +301,7 @@ type _swig_memberptr *byte /* Strings. */ -%typemap(go) +%typemap(gotype) char *, char *&, char[ANY], char[], signed char *, signed char *&, signed char[ANY], signed char[], unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] @@ -309,8 +309,8 @@ type _swig_memberptr *byte /* Needed to avoid confusion with the way the go module handles references. */ -%typemap(go) char&, unsigned char& "*byte" -%typemap(go) signed char& "*int8" +%typemap(gotype) char&, unsigned char& "*byte" +%typemap(gotype) signed char& "*int8" %typemap(in) char *, char[ANY], char[], @@ -341,11 +341,11 @@ type _swig_memberptr *byte unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] %{ $result = ($1_ltype)$input.p; %} -/* Enums. We can't do the right thing for enums in typemap(go) so we - deliberately don't define them. The right thing would be to +/* Enums. We can't do the right thing for enums in typemap(gotype) so + we deliberately don't define them. The right thing would be to capitalize the name. This is instead done in go.cxx. */ -%typemap(go) enum SWIGTYPE +%typemap(gotype) enum SWIGTYPE %{$gotypename%} %typemap(in) enum SWIGTYPE @@ -364,7 +364,7 @@ type _swig_memberptr *byte We convert it to a pointer for the Go code. Note that all basic types are explicitly handled above. */ -%typemap(go) SWIGTYPE +%typemap(gotype) SWIGTYPE %{$gotypename%} %typemap(in) SWIGTYPE ($&1_type argp) diff --git a/Lib/go/std_string.i b/Lib/go/std_string.i index 3c94cbe10..fb99ccdcd 100644 --- a/Lib/go/std_string.i +++ b/Lib/go/std_string.i @@ -19,7 +19,7 @@ namespace std { class string; -%typemap(go) string, const string & "string" +%typemap(gotype) string, const string & "string" %typemap(in) string %{ $1.assign($input.p, $input.n); %} diff --git a/Lib/go/typemaps.i b/Lib/go/typemaps.i index 17da80c23..b03daf626 100644 --- a/Lib/go/typemaps.i +++ b/Lib/go/typemaps.i @@ -60,7 +60,7 @@ char * typemaps instead: */ %define INPUT_TYPEMAP(TYPE, GOTYPE) -%typemap(go) TYPE *INPUT, TYPE &INPUT "GOTYPE" +%typemap(gotype) TYPE *INPUT, TYPE &INPUT "GOTYPE" %typemap(in) TYPE *INPUT %{ $1 = ($1_ltype)&$input; %} @@ -163,7 +163,7 @@ char * typemaps instead: */ %define OUTPUT_TYPEMAP(TYPE, GOTYPE) -%typemap(go) TYPE *OUTPUT, TYPE &OUTPUT %{[]GOTYPE%} +%typemap(gotype) TYPE *OUTPUT, TYPE &OUTPUT %{[]GOTYPE%} %typemap(in) TYPE *OUTPUT($*1_ltype temp) { @@ -287,7 +287,7 @@ char * typemaps instead: */ %define INOUT_TYPEMAP(TYPE, GOTYPE) -%typemap(go) TYPE *INOUT, TYPE &INOUT %{[]GOTYPE%} +%typemap(gotype) TYPE *INOUT, TYPE &INOUT %{[]GOTYPE%} %typemap(in) TYPE *INOUT { if ($input.len == 0) { diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index e958a0a7f..29fb245da 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -751,7 +751,7 @@ private: Wrapper *dummy = NewWrapper(); emit_attach_parmmaps(parms, dummy); Swig_typemap_attach_parms("default", parms, dummy); - Swig_typemap_attach_parms("go", parms, dummy); + Swig_typemap_attach_parms("gotype", parms, dummy); int parm_count = emit_num_arguments(parms); int required_count = emit_num_required(parms); @@ -2473,7 +2473,7 @@ private: emit_attach_parmmaps(parms, dummy); DelWrapper(dummy); - Swig_typemap_attach_parms("go", parms, NULL); + Swig_typemap_attach_parms("gotype", parms, NULL); int parm_count = emit_num_arguments(parms); String *func_name = NewString("NewDirector"); @@ -2900,7 +2900,7 @@ private: emit_attach_parmmaps(parms, dummy); DelWrapper(dummy); - Swig_typemap_attach_parms("go", parms, NULL); + Swig_typemap_attach_parms("gotype", parms, NULL); int parm_count = emit_num_arguments(parms); SwigType *result = Getattr(n, "returntype"); @@ -4151,14 +4151,14 @@ private: if (n != NULL && Cmp(type, Getattr(n, "type")) == 0) { ret = NULL; if (Strcmp(Getattr(n, "nodeType"), "parm") == 0) { - ret = Getattr(n, "tmap:go"); + ret = Getattr(n, "tmap:gotype"); } if (ret == NULL) { - ret = Swig_typemap_lookup("go", n, "", NULL); + ret = Swig_typemap_lookup("gotype", n, "", NULL); } } else { Parm *p = NewParmWithoutFileLineInfo(type, "goType"); - ret = Swig_typemap_lookup("go", p, "", NULL); + ret = Swig_typemap_lookup("gotype", p, "", NULL); Delete(p); } @@ -4497,12 +4497,12 @@ private: /* ---------------------------------------------------------------------- * hasGoTypemap * - * Return whether a type has a "go" typemap entry. + * Return whether a type has a "gotype" typemap entry. * ---------------------------------------------------------------------- */ bool hasGoTypemap(SwigType *type) { Parm *p = NewParmWithoutFileLineInfo(type, "test"); - SwigType *tm = Swig_typemap_lookup("go", p, "", NULL); + SwigType *tm = Swig_typemap_lookup("gotype", p, "", NULL); Delete(p); if (tm != NULL && Strstr(tm, "$gotypename") == NULL) { Delete(tm); From 814eaab177e4720405adebebbbfdf096b011697c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 15 Jun 2010 20:15:11 +0000 Subject: [PATCH 180/203] Remove comments about compiling file with gcc. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12130 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 29fb245da..f1c7d89c1 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -355,9 +355,6 @@ private: } Swig_banner(f_c_begin); - if (!gccgo_flag) { - Printf(f_c_begin, "\n/* This file should be compiled with gcc. */\n"); - } if (renames != NULL) { Printf(f_c_begin, "%s\n", renames); } @@ -366,7 +363,6 @@ private: Printf(f_c_runtime, "#define SWIG_DIRECTORS\n"); Swig_banner(f_c_directors_h); - Printf(f_c_directors_h, "\n/* This file should be compiled with gcc. */\n"); Printf(f_c_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module); Printf(f_c_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module); From b2c07c39f337c880db3203e5ba0ae57ac99bb800 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 15 Jun 2010 21:18:30 +0000 Subject: [PATCH 181/203] Correct number of referenced paragraphs in license as pointed out by Amaury Forgeot d'Arc git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12131 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- LICENSE-UNIVERSITIES | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE-UNIVERSITIES b/LICENSE-UNIVERSITIES index fdb73d916..40042a84a 100644 --- a/LICENSE-UNIVERSITIES +++ b/LICENSE-UNIVERSITIES @@ -73,8 +73,8 @@ All Rights Reserved Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that -(1) The above copyright notice and the following two paragraphs -appear in all copies of the source code and (2) redistributions +(1) The above copyright notice and the following paragraph +appears in all copies of the source code and (2) redistributions including binaries reproduces these notices in the supporting documentation. Substantial modifications to this software may be copyrighted by their authors and need not follow the licensing terms From e7fde8c432fcbbcd80662a8696d614247ec20746 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 16 Jun 2010 15:43:05 +0000 Subject: [PATCH 182/203] Set wrap:name attribute when generating a call to a method in a base class. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12132 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index f1c7d89c1..bc219acfd 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2031,7 +2031,8 @@ private: Delete(SwigType_pop_function(result)); // If the base method is imported, wrap:action may not be set. - Swig_save("goBaseMethod", method, "wrap:action", "parms", NULL); + Swig_save("goBaseMethod", method, "wrap:name", "wrap:action", "parms", NULL); + Setattr(method, "wrap:name", wname); if (Getattr(method, "wrap:action") == NULL) { if (!is_static) { Swig_MethodToFunction(method, getNSpace(), getClassType(), (Getattr(method, "template") != NULL ? SmartPointer : Extend | SmartPointer), NULL, false); From 683dafb6d3e0f04a6f51480ab00202c6f38d11c9 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 16 Jun 2010 15:47:15 +0000 Subject: [PATCH 183/203] Update the instructions to say that you also need to compile the code itself. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12133 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/go/simple/index.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Examples/go/simple/index.html b/Examples/go/simple/index.html index 82372ef37..21dfc239e 100644 --- a/Examples/go/simple/index.html +++ b/Examples/go/simple/index.html @@ -74,8 +74,10 @@ rather than gccgo.
    • Compile the example_wrap.c file using your standard C compiler with the -fpic option; e.g., gcc -c -O -fpic example_wrap.c. -
    • Put the gcc compiled object file into a shared library; - e.g., gcc -shared -o example.so example_wrap.o. +
    • Also compile the actual code, not generated by SWIG; e.g., gcc + -c -O -fpic example.c. +
    • Put the gcc compiled object files into a shared library; + e.g., gcc -shared -o example.so example_wrap.o example.o.
    • Compile the program which demonstrates how to use the library; e.g., 6g runme.go.
    • Link the program; e.g., 6l -o runme runme.6. From 2970f53c21c406389e1e24c9cd285317a1678f2c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 17 Jun 2010 18:59:26 +0000 Subject: [PATCH 184/203] Remove the -rename option in the Go language support. Do a much better job of checking for name conflicts. Ignore conflicting names with a warning. Adjust the testsuite accordingly. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12135 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Go.html | 9 - Examples/test-suite/constant_pointers.i | 1 + Examples/test-suite/director_finalizer.i | 3 + Examples/test-suite/enum_thorough.i | 2 + Examples/test-suite/go/Makefile.in | 16 -- Examples/test-suite/go/director_enum_runme.go | 2 +- .../test-suite/go/overload_simple_runme.go | 26 +- .../go/smart_pointer_member_runme.go | 4 +- .../go/special_variable_macros_runme.go | 2 +- Examples/test-suite/mixed_types.i | 2 + Examples/test-suite/overload_simple.i | 3 + Examples/test-suite/preproc.i | 2 + Examples/test-suite/smart_pointer_member.i | 2 +- Examples/test-suite/special_variable_macros.i | 2 + .../test-suite/template_specialization_enum.i | 1 + Source/Include/swigwarn.h | 3 + Source/Modules/go.cxx | 241 ++++++++++++++---- Source/Modules/lang.cxx | 5 +- 18 files changed, 232 insertions(+), 94 deletions(-) diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 1082a8f66..5e99a5156 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -116,15 +116,6 @@ swig -go -help or int64. The <s> argument should be 32 or 64. -
    • - - - -
      -rename <old>=<new>Rename <old%gt; to <new> when processing the C/C++ code - and also the SWIG input file. This is a convenient way to rename - names in the C/C++ code which are the same expect for the first - letter, to avoid conflicts when applying the Go renaming rules - described below.

      20.2.2 Go Output Files

      diff --git a/Examples/test-suite/constant_pointers.i b/Examples/test-suite/constant_pointers.i index 277d3cc75..7d46cdb31 100644 --- a/Examples/test-suite/constant_pointers.i +++ b/Examples/test-suite/constant_pointers.i @@ -5,6 +5,7 @@ This testcase primarily test constant pointers, eg int* const. Only a getter is %module constant_pointers %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */ +%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'Foo' due to Go name ('Foo') conflict with 'foo' */ %inline %{ diff --git a/Examples/test-suite/director_finalizer.i b/Examples/test-suite/director_finalizer.i index 52cdb1f52..fb45421b9 100644 --- a/Examples/test-suite/director_finalizer.i +++ b/Examples/test-suite/director_finalizer.i @@ -1,4 +1,7 @@ %module(directors="1") director_finalizer + +%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'deleteFoo' due to Go name ('DeleteFoo') conflict with '~Foo' */ + %{ int status = 0; diff --git a/Examples/test-suite/enum_thorough.i b/Examples/test-suite/enum_thorough.i index 974227a01..cb2288574 100644 --- a/Examples/test-suite/enum_thorough.i +++ b/Examples/test-suite/enum_thorough.i @@ -43,6 +43,8 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Instances::memberinstance2; %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Instances::memberinstance3; +%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'one' due to Go name ('ObscureOne') conflict with 'Obscure::One' */ + %inline %{ enum { AnonEnum1, AnonEnum2 = 100 }; diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 6126e77ee..12a3f7919 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -21,22 +21,6 @@ top_builddir = @top_builddir@ include $(srcdir)/../common.mk -# Custom tests - tests with additional commandline options -constant_pointers.cpptest: SWIGOPT += -rename foo=foofn -director_enum.cpptest: SWIGOPT += -rename Hello=Helloe -director_finalizer.cpptest: SWIGOPT += -rename deleteFoo=deleteFooFn -enum_thorough.cpptest: SWIGOPT += -rename One=Onee -rename Two=Twoe -mixed_types.cpptest: SWIGOPT += -rename Hello=Helloe -overload_simple.cpptest: SWIGOPT += -rename foo=foofn -smart_pointer_extend.cpptest: SWIGOPT += -rename CPtrFoo=CPtrFoos -smart_pointer_member.cpptest: SWIGOPT += -rename Foo=Foos -special_variable_macros.cpptest: SWIGOPT += -rename Name=Names -template_partial_specialization.cpptest: SWIGOPT += -rename b=bfn -template_partial_specialization_typedef.cpptest: SWIGOPT += -rename b=bfn -template_specialization_enum.cpptest: SWIGOPT += -rename Hello=Helloe -preproc.ctest: SWIGOPT += -rename a5=a5c -rename a6=a6c -mod.multicpptest: SWIGOPT += -rename GetC=GetCFn - .SUFFIXES: .cpptest .ctest .multicpptest # Rules for the different types of tests diff --git a/Examples/test-suite/go/director_enum_runme.go b/Examples/test-suite/go/director_enum_runme.go index e0dad900b..5653fda40 100644 --- a/Examples/test-suite/go/director_enum_runme.go +++ b/Examples/test-suite/go/director_enum_runme.go @@ -3,7 +3,7 @@ package main import "./director_enum" type MyFoo struct{} // From director_enum.Foo -func (p *MyFoo) Say_hi(val director_enum.EnumDirectorHelloe) director_enum.EnumDirectorHelloe { +func (p *MyFoo) Say_hi(val director_enum.EnumDirectorHello) director_enum.EnumDirectorHello { return val } diff --git a/Examples/test-suite/go/overload_simple_runme.go b/Examples/test-suite/go/overload_simple_runme.go index 58fe46dab..9fca9061a 100644 --- a/Examples/test-suite/go/overload_simple_runme.go +++ b/Examples/test-suite/go/overload_simple_runme.go @@ -3,57 +3,57 @@ package main import . "./overload_simple" func main() { - if Foofn(3) != "foo:int" { + if Foo(3) != "foo:int" { panic("foo(int)") } - if Foofn(float64(3.0)) != "foo:double" { + if Foo(float64(3.0)) != "foo:double" { panic("foo(double)") } - if Foofn("hello") != "foo:char *" { + if Foo("hello") != "foo:char *" { panic("foo(char *)") } - f := NewFoo() + f := NewFoos() b := NewBar() - if Foofn(f) != "foo:Foo *" { + if Foo(f) != "foo:Foo *" { panic("foo(Foo *)") } - if Foofn(b) != "foo:Bar *" { + if Foo(b) != "foo:Bar *" { panic("foo(Bar *)") } v := Malloc_void(32) - if Foofn(v) != "foo:void *" { + if Foo(v) != "foo:void *" { panic("foo(void *)") } s := NewSpam() - if s.Foofn(3) != "foo:int" { + if s.Foo(3) != "foo:int" { panic("Spam::foo(int)") } - if s.Foofn(float64(3.0)) != "foo:double" { + if s.Foo(float64(3.0)) != "foo:double" { panic("Spam::foo(double)") } - if s.Foofn("hello") != "foo:char *" { + if s.Foo("hello") != "foo:char *" { panic("Spam::foo(char *)") } - if s.Foofn(f) != "foo:Foo *" { + if s.Foo(f) != "foo:Foo *" { panic("Spam::foo(Foo *)") } - if s.Foofn(b) != "foo:Bar *" { + if s.Foo(b) != "foo:Bar *" { panic("Spam::foo(Bar *)") } - if s.Foofn(v) != "foo:void *" { + if s.Foo(v) != "foo:void *" { panic("Spam::foo(void *)") } diff --git a/Examples/test-suite/go/smart_pointer_member_runme.go b/Examples/test-suite/go/smart_pointer_member_runme.go index d0da83cef..bf09fe5fc 100644 --- a/Examples/test-suite/go/smart_pointer_member_runme.go +++ b/Examples/test-suite/go/smart_pointer_member_runme.go @@ -4,7 +4,7 @@ import "fmt" import . "./smart_pointer_member" func main() { - f := NewFoos() + f := NewFoo() f.SetY(1) if f.GetY() != 1 { @@ -24,7 +24,7 @@ func main() { panic(0) } - if b.GetZ() != GetFoosZ() { + if b.GetZ() != GetFooZ() { panic(0) } } diff --git a/Examples/test-suite/go/special_variable_macros_runme.go b/Examples/test-suite/go/special_variable_macros_runme.go index 366575551..d049af606 100644 --- a/Examples/test-suite/go/special_variable_macros_runme.go +++ b/Examples/test-suite/go/special_variable_macros_runme.go @@ -3,7 +3,7 @@ package main import "./special_variable_macros" func main() { - name := special_variable_macros.NewNames() + name := special_variable_macros.NewName() if special_variable_macros.TestFred(name) != "none" { panic("test failed") } diff --git a/Examples/test-suite/mixed_types.i b/Examples/test-suite/mixed_types.i index 274cfcf7f..e2be55a61 100644 --- a/Examples/test-suite/mixed_types.i +++ b/Examples/test-suite/mixed_types.i @@ -3,6 +3,8 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) hi; /* Ruby, wrong constant name */ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) hello; /* Ruby, wrong constant name */ +%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'hello' due to Go name ('Hello') conflict with 'Hello' */ + %inline { const void* ref_pointer(const void*& a) { diff --git a/Examples/test-suite/overload_simple.i b/Examples/test-suite/overload_simple.i index b08777854..d23807641 100644 --- a/Examples/test-suite/overload_simple.i +++ b/Examples/test-suite/overload_simple.i @@ -14,7 +14,10 @@ %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fid; #endif +#ifdef SWIGGO %warnfilter(SWIGWARN_PARSE_KEYWORD) type; // 'type' is a Go keyword, renamed as 'Xtype' +%rename(Foos) Foo; +#endif #ifndef SWIG_NO_OVERLOAD %immutable Spam::type; diff --git a/Examples/test-suite/preproc.i b/Examples/test-suite/preproc.i index b9f357b90..fec4daeba 100644 --- a/Examples/test-suite/preproc.i +++ b/Examples/test-suite/preproc.i @@ -7,6 +7,8 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) __GMP_HAVE_PROTOTYPES; /* Ruby, wrong constant name */ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) __GMP_HAVE_TOKEN_PASTE; /* Ruby, wrong constant name */ +#pragma SWIG nowarn=890 /* lots of Go name conflicts */ + /* check __cplusplus case */ %header %{ diff --git a/Examples/test-suite/smart_pointer_member.i b/Examples/test-suite/smart_pointer_member.i index 7a776261a..e4f1ae2c6 100644 --- a/Examples/test-suite/smart_pointer_member.i +++ b/Examples/test-suite/smart_pointer_member.i @@ -1,6 +1,6 @@ %module smart_pointer_member - +%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'foo' due to Go name ('Foo') conflict with 'Foo' */ %inline %{ diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index f27bbd619..c168b4747 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -3,6 +3,8 @@ // test $typemap() special variable function // these tests are not typical of how $typemap() should be used, but it checks that it is mostly working +%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'NewName' due to Go name ('NewName') conflict with 'Name' */ + %inline %{ struct Name { Name(const char *n="none") : name(n) {} diff --git a/Examples/test-suite/template_specialization_enum.i b/Examples/test-suite/template_specialization_enum.i index 5fc51fbe0..07d73b583 100644 --- a/Examples/test-suite/template_specialization_enum.i +++ b/Examples/test-suite/template_specialization_enum.i @@ -3,6 +3,7 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Hello; /* Ruby, wrong class name */ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Hi; /* Ruby, wrong class name */ +%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'hello due to Go name ('Hello) conflict with 'Hello' */ %inline %{ diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 9f0729a98..46f5b79a5 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -258,6 +258,9 @@ /* please leave 870-889 free for PHP */ +#define WARN_GO_NAME_CONFLICT 890 + +/* please leave 890-899 free for Go */ /* Feel free to claim any number in this space that's not currently being used. Just make sure you add an entry here */ diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index bc219acfd..59e9e6f9d 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -27,8 +27,6 @@ class GO:public Language { String *soname; // Size in bits of the C type "long". int long_type_size; - // Rename directives. - String *renames; /* Output files */ File *f_c_begin; @@ -90,7 +88,6 @@ public: go_prefix(NULL), soname(NULL), long_type_size(32), - renames(NULL), f_c_begin(NULL), f_go_begin(NULL), f_gc_begin(NULL), @@ -176,26 +173,6 @@ private: } else { Swig_arg_error(); } - } else if (strcmp(argv[i], "-rename") == 0) { - if (argv[i + 1] != NULL) { - String *d = NewString(argv[i + 1]); - Replace(d, "=", " ", DOH_REPLACE_FIRST); - Preprocessor_define(d, 0); - if (renames == NULL) { - renames = NewString(""); - } - Printv(renames, "#define ", d, "\n", NULL); - Delete(d); - Swig_mark_arg(i); - Swig_mark_arg(i + 1); - ++i; - // Prevent SWIG from trying to define this for the - // preprocessor, which breaks if there are multiple - // -rename options. - argv[i] = NULL; - } else { - Swig_arg_error(); - } } else if (strcmp(argv[i], "-help") == 0) { Printf(stdout, "%s\n", usage); } @@ -355,9 +332,6 @@ private: } Swig_banner(f_c_begin); - if (renames != NULL) { - Printf(f_c_begin, "%s\n", renames); - } if (directorsEnabled()) { Printf(f_c_runtime, "#define SWIG_DIRECTORS\n"); @@ -560,6 +534,11 @@ private: } Delete(c2); Delete(c1); + + if (!checkIgnoredParameters(n, go_name)) { + Delete(go_name); + return SWIG_NOWRAP; + } } else if (Cmp(nodetype, "constructor") == 0) { is_ctor_dtor = true; @@ -612,23 +591,28 @@ private: } go_name = buildGoName(name, is_static, is_friend); + + if (!checkIgnoredParameters(n, go_name)) { + Delete(go_name); + return SWIG_NOWRAP; + } } String *overname = NULL; if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); - } else if (class_name == NULL || is_static) { - if (!addSymbol(go_name, n)) { - return SWIG_ERROR; - } } else { - String *c = Copy(class_name); - Putc('+', c); - Append(c, go_name); - if (!addSymbol(c, n)) { - return SWIG_ERROR; + String *scope; + if (class_name == NULL || is_static || is_ctor_dtor) { + scope = NULL; + } else { + scope = NewString("swiggoscope."); + Append(scope, class_name); + } + if (!checkNameConflict(go_name, n, scope)) { + Delete(go_name); + return SWIG_NOWRAP; } - Delete(c); } String *wname = Swig_name_wrapper(name); @@ -646,6 +630,18 @@ private: } if (Getattr(n, "sym:overloaded") && Getattr(n, "sym:nextSibling") == NULL) { + String *scope ; + if (class_name == NULL || is_static || is_ctor_dtor) { + scope = NULL; + } else { + scope = NewString("swiggoscope."); + Append(scope, class_name); + } + if (!checkNameConflict(go_name, n, scope)) { + Delete(go_name); + return SWIG_NOWRAP; + } + String *receiver = class_receiver; if (is_static || is_ctor_dtor) { receiver = NULL; @@ -1563,11 +1559,6 @@ private: String *go_name = buildGoName(Getattr(n, "sym:name"), false, false); - if (!addSymbol(go_name, n)) { - Delete(go_name); - return SWIG_ERROR; - } - String *tm = goType(n, type); String *value = Getattr(n, "value"); @@ -1625,6 +1616,15 @@ private: } } + if (!checkNameConflict(go_name, n, NULL)) { + Delete(tm); + Delete(go_name); + if (copy != NULL) { + Delete(copy); + } + return SWIG_NOWRAP; + } + Printv(f_go_wrappers, "const ", go_name, " ", tm, " = ", NULL); if (SwigType_type(type) == T_STRING) { Printv(f_go_wrappers, "\"", value, "\"", NULL); @@ -1655,6 +1655,10 @@ private: String *name = goEnumName(n); if (Strcmp(name, "int") != 0) { if (!ImportMode || imported_package == NULL) { + if (!checkNameConflict(name, n, NULL)) { + Delete(name); + return SWIG_NOWRAP; + } Printv(f_go_wrappers, "type ", name, " int\n", NULL); } else { String *nw = NewString(""); @@ -1693,6 +1697,18 @@ private: * ------------------------------------------------------------------------ */ int goComplexConstant(Node *n, SwigType *type) { + String *symname = Getattr(n, "sym:name"); + if (symname == NULL) { + symname = Getattr(n, "name"); + } + + String *varname = buildGoName(symname, true, false); + + if (!checkNameConflict(varname, n, NULL)) { + Delete(varname); + return SWIG_NOWRAP; + } + String *get = NewString(""); Printv(get, "result = ", NULL); @@ -1720,11 +1736,6 @@ private: Printv(get, ";\n", NULL); Setattr(n, "wrap:action", get); - String *symname = Getattr(n, "sym:name"); - if (symname == NULL) { - symname = Getattr(n, "name"); - } - String *sname = Copy(symname); if (class_name != NULL) { Append(sname, "_"); @@ -1747,7 +1758,6 @@ private: return r; } - String *varname = buildGoName(symname, true, false); String *t = goType(n, type); Printv(f_go_wrappers, "var ", varname, " ", t, " = ", go_name, "()\n", NULL); @@ -1779,6 +1789,12 @@ private: String *go_name = exportedName(name); + if (!checkNameConflict(go_name, n, NULL)) { + Delete(go_name); + SetFlag(n, "go:conflict"); + return SWIG_NOWRAP; + } + String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true); class_name = name; @@ -2452,8 +2468,8 @@ private: Append(fn_name, go_name); if (overname == NULL && !is_ignored) { - if (!addSymbol(fn_name, n)) { - return SWIG_ERROR; + if (!checkNameConflict(fn_name, n, NULL)) { + return SWIG_NOWRAP; } } @@ -4117,6 +4133,132 @@ private: return s2; } + /* ---------------------------------------------------------------------- + * checkNameConflict() + * + * Check for a name conflict on the name we are going to use in Go. + * These conflicts are likely because of the enforced + * capitalization. When we find one, issue a warning and return + * false. If the name is OK, return true. + * ---------------------------------------------------------------------- */ + + bool checkNameConflict(String* name, Node* n, const_String_or_char_ptr scope) { + Node *lk = symbolLookup(name, scope); + if (lk != NULL) { + String *n1 = Getattr(n, "sym:name"); + if (n1 == NULL) { + n1 = Getattr(n, "name"); + } + String *n2 = Getattr(lk, "sym:name"); + if (n2 == NULL) { + n2 = Getattr(lk, "name"); + } + Swig_warning(WARN_GO_NAME_CONFLICT, input_file, line_number, + "Ignoring '%s' due to Go name ('%s') conflict with '%s'\n", + n1, name, n2); + return false; + } + bool r = addSymbol(name, n, scope); + assert(r); + return true; + } + + /* ---------------------------------------------------------------------- + * checkIgnoredParameters() + * + * If any of the parameters of this function, or the return type, + * are ignored due to a name conflict, give a warning and return + * false. + * ---------------------------------------------------------------------- */ + + bool checkIgnoredParameters(Node *n, String *go_name) { + ParmList *parms = Getattr(n, "parms"); + if (parms != NULL) { + Wrapper *dummy = NewWrapper(); + emit_attach_parmmaps(parms, dummy); + int parm_count = emit_num_arguments(parms); + Parm *p = parms; + + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + if (!checkIgnoredType(n, go_name, Getattr(p, "type"))) { + DelWrapper(dummy); + return false; + } + p = nextParm(p); + } + + DelWrapper(dummy); + } + + if (!checkIgnoredType(n, go_name, Getattr(n, "type"))) { + return false; + } + + return true; + } + + /* ---------------------------------------------------------------------- + * checkIgnoredType() + * + * If this type is being ignored due to a name conflict, give a + * warning and return false. + * ---------------------------------------------------------------------- */ + + bool checkIgnoredType(Node *n, String *go_name, SwigType *type) { + if (hasGoTypemap(type)) { + return true; + } + + SwigType *t = SwigType_typedef_resolve_all(type); + + bool ret = true; + bool is_conflict = false; + Node *e = Language::enumLookup(t); + if (e != NULL) { + if (GetFlag(e, "go:conflict")) { + is_conflict = true; + } + } else if (SwigType_issimple(t)) { + Node *cn = classLookup(t); + if (cn != NULL) { + if (GetFlag(cn, "go:conflict")) { + is_conflict = true; + } + } + } else if (SwigType_ispointer(t) || SwigType_isarray(t) || SwigType_isqualifier(t) || SwigType_isreference(t)) { + SwigType *r = Copy(t); + if (SwigType_ispointer(r)) { + SwigType_del_pointer(r); + } else if (SwigType_isarray(r)) { + SwigType_del_array(r); + } else if (SwigType_isqualifier(r)) { + SwigType_del_qualifier(r); + } else { + SwigType_del_reference(r); + } + + if (!checkIgnoredType(n, go_name, r)) { + ret = false; + } + + Delete(r); + } + + if (is_conflict) { + String *s = SwigType_str(t, NULL); + Swig_warning(WARN_GO_NAME_CONFLICT, input_file, line_number, + "Ignoring '%s' (Go name '%s') due to Go name conflict for parameter or result type '%s'\n", + Getattr(n, "name"), go_name, s); + Delete(s); + ret = false; + } + + Delete(t); + + return ret; + } + /* ---------------------------------------------------------------------- * goType() * @@ -4631,5 +4773,4 @@ Go Options (available with -go)\n\ -go-prefix

      - Like gccgo -fgo-prefix option\n\ -soname - Set shared library holding C/C++ code to \n\ -longsize - Set size of C/C++ long type--32 or 64 bits\n\ - -rename = - Rename symbols from to \n\ \n"; diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index fb3d58ce4..83103180c 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2995,7 +2995,10 @@ void Language::dumpSymbols() { * ----------------------------------------------------------------------------- */ Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) { - Hash *symbols = Getattr(symtabs, scope); + Hash *symbols = Getattr(symtabs, scope ? scope : ""); + if (symbols == NULL) { + return NULL; + } return Getattr(symbols, s); } From 07ca3eb9f88562bb356a40676631f6be45e222c1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Jun 2010 23:03:18 +0000 Subject: [PATCH 185/203] remove unnecessary NULL check before calling Delete git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12136 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 59e9e6f9d..91ab66039 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -654,9 +654,7 @@ private: Delete(wname); Delete(go_name); - if (r1 != NULL) { - Delete(r1); - } + Delete(r1); return SWIG_OK; } @@ -1227,9 +1225,7 @@ private: Swig_restore(n); DelWrapper(f); - if (base_parm != NULL) { - Delete(base_parm); - } + Delete(base_parm); return SWIG_OK; } @@ -1363,9 +1359,7 @@ private: Swig_restore(n); DelWrapper(f); - if (base_parm != NULL) { - Delete(base_parm); - } + Delete(base_parm); return SWIG_OK; } @@ -1619,9 +1613,7 @@ private: if (!checkNameConflict(go_name, n, NULL)) { Delete(tm); Delete(go_name); - if (copy != NULL) { - Delete(copy); - } + Delete(copy); return SWIG_NOWRAP; } @@ -1638,9 +1630,7 @@ private: Delete(tm); Delete(go_name); - if (copy != NULL) { - Delete(copy); - } + Delete(copy); return SWIG_OK; } @@ -3205,9 +3195,7 @@ private: } } - if (first_type != NULL) { - Delete(first_type); - } + Delete(first_type); if (first_parm != parms) { Delete(first_parm); } @@ -3337,9 +3325,7 @@ private: Printv(f_go_wrappers, "}\n\n", NULL); - if (result_wrapper != NULL) { - Delete(result_wrapper); - } + Delete(result_wrapper); // Build the C++ functions. @@ -3724,9 +3710,7 @@ private: } } if (mismatch) { - if (all_result != NULL) { - Delete(all_result); - } + Delete(all_result); all_result = NULL; } else if (all_result != NULL) { ; @@ -4021,9 +4005,7 @@ private: Printv(f_go_wrappers, "\tpanic(\"No match for overloaded function call\")\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); - if (all_result != NULL) { - Delete(all_result); - } + Delete(all_result); Delete(dispatch); return SWIG_OK; @@ -4647,9 +4629,7 @@ private: Delete(tm); return true; } - if (tm != NULL) { - Delete(tm); - } + Delete(tm); return false; } From 95a3eb5a7d5b34f91dec4e52d316d0b5f4462c2b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Jun 2010 23:49:12 +0000 Subject: [PATCH 186/203] code style: fix inconsistent NULL pointer comparisons git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12137 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 365 ++++++++++++++++++------------------- Source/Modules/guile.cxx | 8 +- Source/Modules/lang.cxx | 2 +- Source/Modules/modula3.cxx | 6 +- Source/Modules/ocaml.cxx | 2 +- Source/Modules/octave.cxx | 2 +- Source/Modules/perl5.cxx | 2 +- Source/Modules/php.cxx | 6 +- Source/Modules/python.cxx | 26 +-- Source/Modules/r.cxx | 2 +- Source/Modules/ruby.cxx | 12 +- Source/Swig/misc.c | 2 +- 12 files changed, 216 insertions(+), 219 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 91ab66039..f62586b92 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -131,7 +131,7 @@ private: for (int i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-package") == 0) { - if (argv[i + 1] != NULL) { + if (argv[i + 1]) { package = NewString(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); @@ -143,7 +143,7 @@ private: Swig_mark_arg(i); gccgo_flag = true; } else if (strcmp(argv[i], "-go-prefix") == 0) { - if (argv[i + 1] != NULL) { + if (argv[i + 1]) { go_prefix = NewString(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); @@ -152,7 +152,7 @@ private: Swig_arg_error(); } } else if (strcmp(argv[i], "-soname") == 0) { - if (argv[i + 1] != NULL) { + if (argv[i + 1]) { soname = NewString(argv[i + 1]); Swig_mark_arg(i); Swig_mark_arg(i + 1); @@ -161,7 +161,7 @@ private: Swig_arg_error(); } } else if (strcmp(argv[i], "-longsize") == 0) { - if (argv[i + 1] != NULL) { + if (argv[i + 1]) { long_type_size = atoi(argv[i + 1]); if (long_type_size != 32 && long_type_size != 64) { Printf(stderr, "-longsize not 32 or 64\n"); @@ -179,7 +179,7 @@ private: } } - if (gccgo_flag && go_prefix == NULL) { + if (gccgo_flag && !go_prefix) { go_prefix = NewString("go"); } @@ -228,7 +228,7 @@ private: virtual int top(Node *n) { Node *optionsnode = Getattr(Getattr(n, "module"), "options"); - if (optionsnode != NULL) { + if (optionsnode) { if (Getattr(optionsnode, "directors")) { allow_directors(); } @@ -239,10 +239,10 @@ private: } String *module = Getattr(n, "name"); - if (package == NULL) { + if (!package) { package = Copy(module); } - if (soname == NULL) { + if (!soname) { soname = Copy(package); Append(soname, ".so"); } @@ -371,11 +371,11 @@ private: // Write out definitions for the types not defined by SWIG. Printv(f_go_wrappers, "\n", NULL); - for (Iterator p = First(undefined_types); p.key != NULL; p = Next(p)) { + for (Iterator p = First(undefined_types); p.key; p = Next(p)) { String *ty = goType(NULL, p.key); - if (Getattr(defined_types, ty) == NULL) { + if (!Getattr(defined_types, ty)) { String *cp = goCPointerType(p.key, false); - if (Getattr(defined_types, cp) == NULL) { + if (!Getattr(defined_types, cp)) { Printv(f_go_wrappers, "type ", cp, " uintptr\n", NULL); Printv(f_go_wrappers, "type ", ty, " interface {\n", NULL); Printv(f_go_wrappers, "\tSwigcptr() uintptr;\n", NULL); @@ -463,7 +463,7 @@ private: virtual int importDirective(Node *n) { String *hold_import = imported_package; String *modname = Getattr(n, "module"); - if (modname != NULL) { + if (modname) { Printv(f_go_begin, "import \"", modname, "\"\n", NULL); imported_package = modname; saw_import = true; @@ -517,7 +517,7 @@ private: // If this is a static variable, put in the class name, // capitalized. - if (is_static && class_name != NULL) { + if (is_static && class_name) { String *ccn = exportedName(class_name); Append(go_name, ccn); Delete(ccn); @@ -552,7 +552,7 @@ private: Delete(c2); Delete(c1); - if (Swig_methodclass(n) != NULL && Swig_directorclass(n) + if (Swig_methodclass(n) && Swig_directorclass(n) && Strcmp(Char(Getattr(n, "wrap:action")), director_prot_ctor_code) != 0) { // The core SWIG code skips the first parameter when // generating the $nondirector_new string. Recreate the @@ -603,7 +603,7 @@ private: overname = Getattr(n, "sym:overname"); } else { String *scope; - if (class_name == NULL || is_static || is_ctor_dtor) { + if (!class_name || is_static || is_ctor_dtor) { scope = NULL; } else { scope = NewString("swiggoscope."); @@ -616,7 +616,7 @@ private: } String *wname = Swig_name_wrapper(name); - if (overname != NULL) { + if (overname) { Append(wname, overname); } Setattr(n, "wrap:name", wname); @@ -629,9 +629,9 @@ private: return r; } - if (Getattr(n, "sym:overloaded") && Getattr(n, "sym:nextSibling") == NULL) { + if (Getattr(n, "sym:overloaded") && !Getattr(n, "sym:nextSibling")) { String *scope ; - if (class_name == NULL || is_static || is_ctor_dtor) { + if (!class_name || is_static || is_ctor_dtor) { scope = NULL; } else { scope = NewString("swiggoscope."); @@ -695,7 +695,7 @@ private: int makeWrappers(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { - assert(result != NULL); + assert(result); bool needs_wrapper; int r = goFunctionWrapper(n, name, go_name, overname, wname, base, parms, result, is_static, &needs_wrapper); @@ -719,7 +719,7 @@ private: } } - if (class_methods != NULL) { + if (class_methods) { Setattr(class_methods, Getattr(n, "name"), NewString("")); } @@ -746,7 +746,7 @@ private: int required_count = emit_num_required(parms); String *receiver = class_receiver; - if (receiver != NULL && is_static) { + if (receiver && is_static) { receiver = NULL; } @@ -754,14 +754,14 @@ private: bool is_constructor = Cmp(nodetype, "constructor") == 0; bool is_destructor = Cmp(nodetype, "destructor") == 0; if (is_constructor || is_destructor) { - assert(class_receiver != NULL); - assert(base == NULL); + assert(class_receiver); + assert(!base); receiver = NULL; } - bool add_to_interface = (interfaces != NULL && !is_constructor && !is_destructor && !is_static && overname == NULL && is_public(n)); + bool add_to_interface = (interfaces && !is_constructor && !is_destructor && !is_static && !overname && is_public(n)); - bool needs_wrapper = (gccgo_flag || receiver != NULL || is_constructor || is_destructor || parm_count > required_count); + 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 @@ -805,12 +805,12 @@ private: Printv(f_go_wrappers, "uintptr", NULL); ++i; p = nextParm(p); - } else if (receiver != NULL && (base != NULL || !is_constructor)) { + } else if (receiver && (base || !is_constructor)) { if (parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } Printv(f_go_wrappers, receiver, NULL); - if (base == NULL) { + if (!base) { ++i; p = nextParm(p); } @@ -819,7 +819,7 @@ private: p = getParm(p); // Give the parameter a name we will use below. Swig_cparm_name(p, i); - if (i > 0 || (base != NULL && receiver != NULL) || parm_count > required_count) { + if (i > 0 || (base && receiver) || parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } String *tm = goWrapperType(p, Getattr(p, "type"), false); @@ -853,9 +853,9 @@ private: int pi = 0; // Add the receiver if this is a method. - if (receiver != NULL) { + if (receiver) { Printv(f_go_wrappers, "(", NULL); - if (base != NULL && receiver != NULL) { + if (base && receiver) { Printv(f_go_wrappers, "_swig_base", NULL); } else { Printv(f_go_wrappers, Getattr(p, "lname"), NULL); @@ -866,7 +866,7 @@ private: } Printv(f_go_wrappers, go_name, NULL); - if (overname != NULL) { + if (overname) { Printv(f_go_wrappers, overname, NULL); } Printv(f_go_wrappers, "(", NULL); @@ -888,7 +888,7 @@ private: Printv(parm_print, Getattr(p, "lname"), " ", cl, NULL); Delete(cl); } else { - if (pi > (receiver != NULL && base == NULL ? 1 : 0)) { + if (pi > (receiver && !base ? 1 : 0)) { Printv(parm_print, ", ", NULL); } if (pi >= required_count) { @@ -959,7 +959,7 @@ private: Printv(f_go_wrappers, "len(_swig_args)", NULL); } - if (base != NULL && receiver != NULL) { + if (base && receiver) { if (parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } @@ -969,7 +969,7 @@ private: Parm *p = parms; for (int i = 0; i < parm_count; ++i) { p = getParm(p); - if (i > 0 || (base != NULL && receiver != NULL) + if (i > 0 || (base && receiver) || parm_count > required_count) { Printv(f_go_wrappers, ", ", NULL); } @@ -979,9 +979,7 @@ private: // 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 == NULL || base != NULL || is_constructor) - && goTypeIsInterface(p, Getattr(p, "type")))) { + if ((i == 0 && is_destructor) || ((i > 0 || !receiver || base || is_constructor) && goTypeIsInterface(p, Getattr(p, "type")))) { Printv(f_go_wrappers, ".Swigcptr()", NULL); } @@ -1031,7 +1029,7 @@ private: Append(parm_size, "SWIG_PARM_SIZE"); } - if (class_receiver != NULL && !is_static) { + if (class_receiver && !is_static) { if (Len(parm_size) > 0) { Append(parm_size, " + "); } @@ -1056,7 +1054,7 @@ private: String *fn_name; if (!needs_wrapper) { fn_name = Copy(go_name); - if (overname != NULL) { + if (overname) { Append(fn_name, overname); } } else { @@ -1129,7 +1127,7 @@ private: Swig_save("gccFunctionWrapper", n, "parms", NULL); Parm *base_parm = NULL; - if (base != NULL && !isStatic(n)) { + if (base && !isStatic(n)) { SwigType *base_type = Copy(Getattr(class_node, "classtype")); SwigType_add_pointer(base_type); base_parm = NewParm(base_type, NewString("arg1"), n); @@ -1187,7 +1185,7 @@ private: p = getParm(p); String *tm = Getattr(p, "tmap:in"); - if (tm == NULL) { + 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"); @@ -1245,7 +1243,7 @@ private: Swig_save("gccgoFunctionWrapper", n, "parms", NULL); Parm *base_parm = NULL; - if (base != NULL && !isStatic(n)) { + if (base && !isStatic(n)) { SwigType *base_type = Copy(Getattr(class_node, "classtype")); SwigType_add_pointer(base_type); base_parm = NewParm(base_type, NewString("arg1"), n); @@ -1315,7 +1313,7 @@ private: p = getParm(p); String *tm = Getattr(p, "tmap:in"); - if (tm == NULL) { + 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 { @@ -1374,9 +1372,9 @@ private: void checkConstraints(ParmList *parms, Wrapper *f) { Parm *p = parms; - while (p != NULL) { + while (p) { String *tm = Getattr(p, "tmap:check"); - if (tm == NULL) { + if (!tm) { p = nextSibling(p); } else { Replaceall(tm, "$input", Getattr(p, "emit:input")); @@ -1394,7 +1392,7 @@ private: void emitGoAction(Node *n, List *base, ParmList *parms, SwigType *result, Wrapper *f) { String *actioncode; - if (base == NULL || isStatic(n)) { + if (!base || isStatic(n)) { Swig_director_emit_dynamic_cast(n, f); actioncode = emit_action(n); } else { @@ -1409,7 +1407,7 @@ private: String *last = NULL; int vc = 0; - for (Iterator bi = First(base); bi.item != NULL; bi = Next(bi)) { + for (Iterator bi = First(base); bi.item; bi = Next(bi)) { Printf(actioncode, " %s *swig_b%d = (%s *)%s;\n", bi.item, vc, bi.item, current); Delete(current); current = NewString(""); @@ -1428,7 +1426,7 @@ private: Setattr(n, "type", result); String *tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode); - if (tm == NULL) { + 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) { @@ -1458,9 +1456,9 @@ private: void argout(ParmList *parms, Wrapper *f) { Parm *p = parms; - while (p != NULL) { + while (p) { String *tm = Getattr(p, "tmap:argout"); - if (tm == NULL) { + if (!tm) { p = nextSibling(p); } else { Replaceall(tm, "$result", "result"); @@ -1482,9 +1480,9 @@ private: String *freearg(ParmList *parms) { String *ret = NewString(""); Parm *p = parms; - while (p != NULL) { + while (p) { String *tm = Getattr(p, "tmap:freearg"); - if (tm == NULL) { + if (!tm) { p = nextSibling(p); } else { Replaceall(tm, "$input", Getattr(p, "emit:input")); @@ -1507,7 +1505,7 @@ private: if (GetFlag(n, "feature:new")) { String *tm = Swig_typemap_lookup("newfree", n, "result", 0); - if (tm != NULL) { + if (tm) { Replaceall(tm, "$source", "result"); Printv(f->code, tm, "\n", NULL); Delete(tm); @@ -1547,7 +1545,7 @@ private: return goComplexConstant(n, type); } - if (Getattr(n, "storage") != NULL && Strcmp(Getattr(n, "storage"), "static") == 0) { + if (Getattr(n, "storage") && Strcmp(Getattr(n, "storage"), "static") == 0) { return goComplexConstant(n, type); } @@ -1563,7 +1561,7 @@ private: } } else if (SwigType_type(type) == T_STRING || SwigType_type(type) == T_CHAR) { // Backslash sequences are somewhat different in Go and C/C++. - if (Strchr(value, '\\') != NULL) { + if (Strchr(value, '\\') != 0) { return goComplexConstant(n, type); } } else { @@ -1644,7 +1642,7 @@ private: virtual int enumDeclaration(Node *n) { String *name = goEnumName(n); if (Strcmp(name, "int") != 0) { - if (!ImportMode || imported_package == NULL) { + if (!ImportMode || !imported_package) { if (!checkNameConflict(name, n, NULL)) { Delete(name); return SWIG_NOWRAP; @@ -1672,7 +1670,7 @@ private: if (!is_public(n)) { return SWIG_OK; } - if (Getattr(parentNode(n), "unnamed") != NULL) { + if (Getattr(parentNode(n), "unnamed")) { Setattr(n, "type", NewString("int")); } else { Setattr(n, "type", Getattr(parentNode(n), "enumtype")); @@ -1688,7 +1686,7 @@ private: int goComplexConstant(Node *n, SwigType *type) { String *symname = Getattr(n, "sym:name"); - if (symname == NULL) { + if (!symname) { symname = Getattr(n, "name"); } @@ -1703,7 +1701,7 @@ private: Printv(get, "result = ", NULL); char quote; - if (Getattr(n, "wrappedasconstant") != NULL) { + if (Getattr(n, "wrappedasconstant")) { quote = '\0'; } else if (SwigType_type(type) == T_CHAR) { quote = '\''; @@ -1727,13 +1725,13 @@ private: Setattr(n, "wrap:action", get); String *sname = Copy(symname); - if (class_name != NULL) { + if (class_name) { Append(sname, "_"); Append(sname, class_name); } String *go_name = NewString("_swig_get"); - if (class_name != NULL) { + if (class_name) { Append(go_name, class_name); Append(go_name, "_"); } @@ -1773,7 +1771,7 @@ private: class_node = n; List *baselist = Getattr(n, "bases"); - bool has_base_classes = baselist != NULL && Len(baselist) > 0; + bool has_base_classes = baselist && Len(baselist) > 0; String *name = Getattr(n, "sym:name"); @@ -1834,7 +1832,7 @@ private: // differently in Go and in C++. Hash *local = NewHash(); - for (Node *ni = Getattr(n, "firstChild"); ni != NULL; ni = nextSibling(ni)) { + for (Node *ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) { if (!is_public(ni)) { continue; @@ -1846,15 +1844,15 @@ private: } String *cname = Getattr(ni, "sym:name"); - if (cname == NULL) { + if (!cname) { cname = Getattr(ni, "name"); } - if (cname != NULL) { + if (cname) { Setattr(local, cname, NewString("")); } } - for (Iterator b = First(baselist); b.item != NULL; b = Next(b)) { + for (Iterator b = First(baselist); b.item; b = Next(b)) { List *bases = NewList(); Append(bases, Getattr(b.item, "classtype")); int r = addBase(n, b.item, bases, local); @@ -1911,7 +1909,7 @@ private: return SWIG_OK; } - for (Node *ni = Getattr(base, "firstChild"); ni != NULL; ni = nextSibling(ni)) { + for (Node *ni = Getattr(base, "firstChild"); ni; ni = nextSibling(ni)) { if (GetFlag(ni, "feature:ignore")) { continue; @@ -1931,15 +1929,15 @@ private: } String *mname = Getattr(ni, "sym:name"); - if (mname == NULL) { + if (!mname) { continue; } String *lname = Getattr(ni, "name"); - if (Getattr(class_methods, lname) != NULL) { + if (Getattr(class_methods, lname)) { continue; } - if (Getattr(local, lname) != NULL) { + if (Getattr(local, lname)) { continue; } Setattr(local, lname, NewString("")); @@ -1957,8 +1955,8 @@ private: return r; } - if (Getattr(ni, "sym:overloaded") != NULL) { - for (Node *on = Getattr(ni, "sym:nextSibling"); on != NULL; on = Getattr(on, "sym:nextSibling")) { + if (Getattr(ni, "sym:overloaded")) { + for (Node *on = Getattr(ni, "sym:nextSibling"); on; on = Getattr(on, "sym:nextSibling")) { r = goBaseMethod(n, bases, on); if (r != SWIG_OK) { return r; @@ -1986,8 +1984,8 @@ private: } List *baselist = Getattr(base, "bases"); - if (baselist != NULL && Len(baselist) > 0) { - for (Iterator b = First(baselist); b.item != NULL; b = Next(b)) { + if (baselist && Len(baselist) > 0) { + for (Iterator b = First(baselist); b.item; b = Next(b)) { List *nb = Copy(bases); Append(nb, Getattr(b.item, "classtype")); int r = addBase(n, b.item, nb, local); @@ -2025,7 +2023,7 @@ private: overname = Getattr(method, "sym:overname"); } String *wname = Swig_name_wrapper(name); - if (overname != NULL) { + if (overname) { Append(wname, overname); } @@ -2039,12 +2037,12 @@ private: // If the base method is imported, wrap:action may not be set. Swig_save("goBaseMethod", method, "wrap:name", "wrap:action", "parms", NULL); Setattr(method, "wrap:name", wname); - if (Getattr(method, "wrap:action") == NULL) { + if (!Getattr(method, "wrap:action")) { if (!is_static) { - Swig_MethodToFunction(method, getNSpace(), getClassType(), (Getattr(method, "template") != NULL ? SmartPointer : Extend | SmartPointer), NULL, false); + Swig_MethodToFunction(method, getNSpace(), getClassType(), (Getattr(method, "template") ? SmartPointer : Extend | SmartPointer), NULL, false); // Remove any self parameter that was just added. ParmList *parms = Getattr(method, "parms"); - if (parms != NULL && Getattr(parms, "self") != NULL) { + if (parms && Getattr(parms, "self")) { parms = CopyParmList(nextSibling(parms)); Setattr(method, "parms", parms); } @@ -2099,7 +2097,7 @@ private: String *mname = Swig_name_member(getNSpace(), Getattr(var_class, "sym:name"), var_name); if (is_assignable(var)) { - for (Iterator ki = First(var); ki.key != NULL; ki = Next(ki)) { + for (Iterator ki = First(var); ki.key; ki = Next(ki)) { if (Strncmp(ki.key, "tmap:", 5) == 0) { Delattr(var, ki.key); } @@ -2128,7 +2126,7 @@ private: Delete(mname_set); Swig_restore(var); - for (Iterator ki = First(var); ki.key != NULL; ki = Next(ki)) { + for (Iterator ki = First(var); ki.key; ki = Next(ki)) { if (Strncmp(ki.key, "tmap:", 5) == 0) { Delattr(var, ki.key); } @@ -2179,7 +2177,7 @@ private: * ------------------------------------------------------------ */ void addFirstBaseInterface(Node *n, Hash *parents, List *bases) { - if (bases == NULL || Len(bases) == 0) { + if (!bases || Len(bases) == 0) { return; } Iterator b = First(bases); @@ -2224,7 +2222,7 @@ private: Node *fb = b.item; - for (b = Next(b); b.item != NULL; b = Next(b)) { + for (b = Next(b); b.item; b = Next(b)) { if (GetFlag(b.item, "feature:ignore")) { continue; } @@ -2299,7 +2297,7 @@ private: void addParentExtraBaseInterfaces(Node *n, Hash *parents, Node *base, bool is_base_first, String *sofar) { List *baselist = Getattr(base, "bases"); - if (baselist == NULL || Len(baselist) == 0) { + if (!baselist || Len(baselist) == 0) { return; } @@ -2316,7 +2314,7 @@ private: } b = Next(b); - if (b.item == NULL) { + if (!b.item) { return; } } @@ -2324,14 +2322,14 @@ private: String *go_name = buildGoName(Getattr(n, "sym:name"), false, false); String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true); - for (; b.item != NULL; b = Next(b)) { + for (; b.item; b = Next(b)) { if (GetFlag(b.item, "feature:ignore")) { continue; } String *go_base_name = exportedName(Getattr(b.item, "sym:name")); - if (Getattr(parents, go_base_name) == NULL) { + if (!Getattr(parents, go_base_name)) { Printv(f_go_wrappers, "func (p ", go_type_name, ") SwigGet", go_base_name, "() ", go_base_name, " {\n", NULL); Printv(f_go_wrappers, "\treturn p", sf, ".SwigGet", go_base_name, "()\n", NULL); Printv(f_go_wrappers, "}\n\n", NULL); @@ -2375,14 +2373,14 @@ private: String *name = Getattr(n, "sym:name"); - assert(class_name == NULL); + assert(!class_name); class_name = name; String *go_name = exportedName(name); String *go_type_name = goCPointerType(Getattr(n, "classtypeobj"), true); - assert(class_receiver == NULL); + assert(!class_receiver); class_receiver = go_type_name; String *director_struct_name = NewString("_swig_Director"); @@ -2431,7 +2429,7 @@ private: bool is_ignored = GetFlag(n, "feature:ignore"); String *name = Getattr(n, "sym:name"); - if (name == NULL) { + if (!name) { assert(is_ignored); name = Getattr(n, "name"); } @@ -2457,7 +2455,7 @@ private: Append(fn_name, cn); Append(fn_name, go_name); - if (overname == NULL && !is_ignored) { + if (!overname && !is_ignored) { if (!checkNameConflict(fn_name, n, NULL)) { return SWIG_NOWRAP; } @@ -2465,7 +2463,7 @@ private: String *wname = Swig_name_wrapper(fn_name); - if (overname != NULL) { + if (overname) { Append(wname, overname); } Setattr(n, "wrap:name", wname); @@ -2483,7 +2481,7 @@ private: Append(func_name, go_name); String *func_with_over_name = Copy(func_name); - if (overname != NULL) { + if (overname) { Append(func_with_over_name, overname); } @@ -2503,7 +2501,7 @@ private: if (!is_ignored) { // Declare the C++ wrapper. Printv(f_go_wrappers, "func ", fn_name, NULL); - if (overname != NULL) { + if (overname) { Printv(f_go_wrappers, overname, NULL); } Printv(f_go_wrappers, "(*", director_struct_name, NULL); @@ -2542,7 +2540,7 @@ private: Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL); Printv(f_go_wrappers, "\tp.", class_receiver, " = ", fn_name, NULL); - if (overname != NULL) { + if (overname) { Printv(f_go_wrappers, overname, NULL); } Printv(f_go_wrappers, "(p", NULL); @@ -2628,7 +2626,7 @@ private: Printv(f_c_directors, ", ", NULL); } String *pn = Getattr(p, "name"); - assert(pn != NULL); + assert(pn); Printv(f_c_directors, pn, NULL); p = nextParm(p); } @@ -2636,7 +2634,7 @@ private: Printv(f_c_directors, " go_val(swig_p)\n", NULL); Printv(f_c_directors, "{ }\n\n", NULL); - if (Getattr(n, "sym:overloaded") && Getattr(n, "sym:nextSibling") == NULL) { + if (Getattr(n, "sym:overloaded") && !Getattr(n, "sym:nextSibling")) { int r = makeDispatchFunction(n, func_name, cn, is_static, Getattr(parentNode(n), "classtypeobj"), false); if (r != SWIG_OK) { return r; @@ -2716,7 +2714,7 @@ private: Printv(f_c_directors_h, " virtual ~SwigDirector_", class_name, "()", NULL); String *throws = buildThrow(n); - if (throws != NULL) { + if (throws) { Printv(f_c_directors_h, " ", throws, NULL); } @@ -2732,7 +2730,7 @@ private: Printv(f_c_directors, "SwigDirector_", class_name, "::~SwigDirector_", class_name, "()", NULL); - if (throws != NULL) { + if (throws) { Printv(f_c_directors, " ", throws, NULL); Delete(throws); } @@ -2792,23 +2790,23 @@ private: } String *name = Getattr(n, "sym:name"); - if (name == NULL) { + if (!name) { assert(is_ignored); name = Getattr(n, "name"); } - if (Getattr(class_methods, name) != NULL) { + if (Getattr(class_methods, name)) { // We need to emit a pure virtual function, even if it is // overloaded. Otherwise we won't be able to create an instance // of the director class. The function doesn't need to actually // do anything. - if (!is_pure_virtual || Getattr(n, "sym:overloaded") != NULL) { + if (!is_pure_virtual || Getattr(n, "sym:overloaded")) { return SWIG_OK; } } Setattr(class_methods, name, NewString("")); - if (Getattr(n, "sym:overloaded") == NULL) { + if (!Getattr(n, "sym:overloaded")) { int r = oneClassDirectorMethod(n, parent); if (r != SWIG_OK) { return r; @@ -2819,7 +2817,7 @@ private: // class_methods so that we correctly handle cases where a // function in one class hides a function of the same name in a // parent class. - for (Node *on = Getattr(n, "sym:overloaded"); on != NULL; on = Getattr(on, "sym:nextSibling")) { + for (Node *on = Getattr(n, "sym:overloaded"); on; on = Getattr(on, "sym:nextSibling")) { int r = oneClassDirectorMethod(on, parent); if (r != SWIG_OK) { return r; @@ -2875,7 +2873,7 @@ private: bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 && Cmp(Getattr(n, "value"), "0") == 0); String *name = Getattr(n, "sym:name"); - if (name == NULL) { + if (!name) { assert(is_ignored); name = Getattr(n, "name"); } @@ -2907,7 +2905,7 @@ private: int parm_count = emit_num_arguments(parms); SwigType *result = Getattr(n, "returntype"); - if (result == NULL) { + if (!result) { // This can happen when following overloads. result = NewString(Getattr(n, "type")); SwigType_push(result, Getattr(n, "decl")); @@ -2924,7 +2922,7 @@ private: String *interface_name = NewString("_swig_DirectorInterface"); Append(interface_name, cn); Append(interface_name, go_name); - if (overname != NULL) { + if (overname) { Append(interface_name, overname); } @@ -2932,7 +2930,7 @@ private: Append(callback_name, "_callback_"); Append(callback_name, name); Replace(callback_name, "_swig", "Swig", DOH_REPLACE_FIRST); - if (overname != NULL) { + if (overname) { Append(callback_name, overname); } @@ -2945,7 +2943,7 @@ private: String *upcall_wname = Swig_name_wrapper(upcall_name); String *go_with_over_name = Copy(go_name); - if (overname != NULL) { + if (overname) { Append(go_with_over_name, overname); } @@ -2955,7 +2953,7 @@ private: for (int i = 0; i < parm_count; ++i) { p = getParm(p); Swig_cparm_name(p, i); - if (Getattr(p, "name") == NULL) { + if (!Getattr(p, "name")) { String *pn = NewString(""); Printf(pn, "arg%d", i); Setattr(p, "name", pn); @@ -2996,7 +2994,7 @@ private: // Declare the upcall function, which calls the method on the // parent class. - if (overname != NULL) { + if (overname) { Append(upcall_wname, overname); } @@ -3102,7 +3100,7 @@ private: String *upcall_method_name = NewString("_swig_upcall_"); Append(upcall_method_name, name); - if (overname != NULL) { + if (overname) { Append(upcall_method_name, overname); } String *upcall_decl = Swig_method_decl(Getattr(n, "type"), Getattr(n, "decl"), upcall_method_name, parms, 0, 0); @@ -3122,7 +3120,7 @@ private: Printv(f_c_directors_h, ", ", NULL); } String *pn = Getattr(p, "name"); - assert(pn != NULL); + assert(pn); Printv(f_c_directors_h, pn, NULL); p = nextParm(p); } @@ -3340,7 +3338,7 @@ private: Printv(fnname, callback_wname, "(void*", NULL); p = parms; - while (p != NULL) { + while (p) { while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { p = Getattr(p, "tmap:directorin:next"); } @@ -3386,7 +3384,7 @@ private: Delete(qname); String *throws = buildThrow(n); - if (throws != NULL) { + if (throws) { Printv(f_c_directors_h, " ", throws, NULL); Printv(f->def, " ", throws, NULL); Delete(throws); @@ -3406,7 +3404,7 @@ private: Printv(f->code, " void *go_val;\n", NULL); p = parms; - while (p != NULL) { + while (p) { while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { p = Getattr(p, "tmap:directorin:next"); } @@ -3429,12 +3427,12 @@ private: Printv(f->code, " swig_a.go_val = go_val;\n", NULL); p = parms; - while (p != NULL) { + while (p) { while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { p = Getattr(p, "tmap:directorin:next"); } String *tm = Getattr(p, "tmap:directorin"); - if (tm == NULL) { + if (!tm) { Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { @@ -3455,7 +3453,7 @@ private: String *rname = NewString("c_result"); Parm *rp = NewParm(Getattr(n, "returntype"), rname, n); String *tm = Swig_typemap_lookup("directorout", rp, rname, NULL); - if (tm == NULL) { + if (!tm) { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, "Unable to use type %s as director method result\n", SwigType_str(result, 0)); } else { @@ -3491,7 +3489,7 @@ private: String *args = NewString(""); p = parms; - while (p != NULL) { + while (p) { while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { p = Getattr(p, "tmap:directorin:next"); } @@ -3505,7 +3503,7 @@ private: Delete(tm); tm = Getattr(p, "tmap:directorin"); - if (tm == NULL) { + if (!tm) { Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); } else { @@ -3529,7 +3527,7 @@ private: String *rname = NewString("c_result"); Parm *rp = NewParm(Getattr(n, "returntype"), rname, n); String *tm = Swig_typemap_lookup("directorout", rp, rname, NULL); - if (tm == NULL) { + if (!tm) { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, "Unable to use type %s as director method result\n", SwigType_str(result, 0)); } else { @@ -3617,15 +3615,15 @@ private: String *buildThrow(Node *n) { ParmList *throw_parm_list = Getattr(n, "throws"); - if (throw_parm_list == NULL && Getattr(n, "throw") == NULL) + if (!throw_parm_list && !Getattr(n, "throw")) return NULL; String *ret = NewString("throw("); - if (throw_parm_list != NULL) { + if (throw_parm_list) { Swig_typemap_attach_parms("throws", throw_parm_list, NULL); } bool first = true; - for (Parm *p = throw_parm_list; p != NULL; p = nextSibling(p)) { - if (Getattr(p, "tmap:throws") != NULL) { + for (Parm *p = throw_parm_list; p; p = nextSibling(p)) { + if (Getattr(p, "tmap:throws")) { if (first) { first = false; } else { @@ -3660,7 +3658,7 @@ private: *--------------------------------------------------------------------*/ int makeDispatchFunction(Node *n, String *go_name, String *receiver, bool is_static, SwigType *director_struct, bool is_upcall) { - bool is_director = director_struct != NULL; + bool is_director = director_struct ? true : false; String *nodetype = Getattr(n, "nodeType"); bool is_constructor = Cmp(nodetype, "constructor") == 0; @@ -3670,7 +3668,7 @@ private: bool use_receiver = (!is_static && can_use_receiver); - bool add_to_interface = (interfaces != NULL && !is_constructor && !is_destructor && !is_static && !is_upcall); + bool add_to_interface = (interfaces && !is_constructor && !is_destructor && !is_static && !is_upcall); List *dispatch = Swig_overload_rank(n, false); int nfunc = Len(dispatch); @@ -3692,17 +3690,17 @@ private: for (int i = 0; i < nfunc; ++i) { Node *ni = Getitem(dispatch, i); SwigType *result = Getattr(ni, "go:type"); - assert(result != NULL); + assert(result); if (SwigType_type(result) == T_VOID) { - if (all_result != NULL) { + if (all_result) { mismatch = true; } any_void = true; } else { if (any_void) { mismatch = true; - } else if (all_result == NULL) { + } else if (!all_result) { all_result = Copy(result); } else if (Cmp(result, all_result) != 0) { mismatch = true; @@ -3712,7 +3710,7 @@ private: if (mismatch) { Delete(all_result); all_result = NULL; - } else if (all_result != NULL) { + } else if (all_result) { ; } else { all_result = NewString("void"); @@ -3721,7 +3719,7 @@ private: Printv(f_go_wrappers, "func ", NULL); - if (receiver != NULL && use_receiver) { + if (receiver && use_receiver) { Printv(f_go_wrappers, "(p ", receiver, ") ", NULL); } @@ -3745,7 +3743,7 @@ private: if (add_to_interface) { Printv(interfaces, " interface{}", NULL); } - } else if (all_result != NULL && SwigType_type(all_result) != T_VOID) { + } else if (all_result && SwigType_type(all_result) != T_VOID) { if (is_director && is_constructor) { Printv(f_go_wrappers, " ", receiver, NULL); if (add_to_interface) { @@ -3775,9 +3773,9 @@ private: // If we are using a receiver, we want to ignore a leading self // parameter. Because of the way this is called, there may or // may not be a self parameter at this point. - if (use_receiver && pi != NULL && Getattr(pi, "self") != NULL) { + if (use_receiver && pi && Getattr(pi, "self")) { pi = getParm(pi); - if (pi != NULL) { + if (pi) { pi = nextParm(pi); } } @@ -3801,9 +3799,9 @@ private: for (int k = i + 1; k < nfunc; ++k) { Node *nk = Getitem(dispatch, k); Parm *pk = Getattr(nk, "wrap:parms"); - if (use_receiver && pk != NULL && Getattr(pk, "self") != NULL) { + if (use_receiver && pk && Getattr(pk, "self")) { pk = getParm(pk); - if (pk != NULL) { + if (pk) { pk = nextParm(pk); } } @@ -3820,9 +3818,9 @@ private: if (Len(coll) > 0 && num_arguments > 0) { int j = 0; Parm *pj = pi; - while (pj != NULL) { + while (pj) { pj = getParm(pj); - if (pj == NULL) { + if (!pj) { break; } @@ -3833,9 +3831,9 @@ private: for (int k = 0; k < Len(coll) && !emitcheck; ++k) { Node *nk = Getitem(coll, k); Parm *pk = Getattr(nk, "wrap:parms"); - if (use_receiver && pk != NULL && Getattr(pk, "self") != NULL) { + if (use_receiver && pk && Getattr(pk, "self")) { pk = getParm(pk); - if (pk != NULL) { + if (pk) { pk = nextParm(pk); } } @@ -3844,9 +3842,9 @@ private: continue; int l = 0; Parm *pl = pk; - while (pl != NULL && l <= j) { + while (pl && l <= j) { pl = getParm(pl); - if (pl == NULL) { + if (!pl) { break; } if (l == j) { @@ -3898,15 +3896,15 @@ private: result = NULL; } - if (result != NULL && SwigType_type(result) != T_VOID && (all_result == NULL || SwigType_type(all_result) != T_VOID)) { + if (result && SwigType_type(result) != T_VOID && (!all_result || SwigType_type(all_result) != T_VOID)) { Printv(start, "return ", NULL); } bool advance_parm = false; - if (receiver != NULL && use_receiver) { + if (receiver && use_receiver) { Printv(start, "p.", go_name, NULL); - } else if (can_use_receiver && !isStatic(ni) && pi != NULL && Getattr(pi, "self") != NULL) { + } else if (can_use_receiver && !isStatic(ni) && pi && Getattr(pi, "self")) { // This is an overload of a static function and a non-static // function. assert(num_required > 0); @@ -3936,7 +3934,7 @@ private: int pn = 0; if (advance_parm) { p = getParm(p); - if (p != NULL) { + if (p) { p = nextParm(p); } ++pn; @@ -3958,17 +3956,17 @@ private: } String *end = NULL; - if (result == NULL || SwigType_type(result) == T_VOID || (all_result != NULL && SwigType_type(all_result) == T_VOID)) { + if (!result || SwigType_type(result) == T_VOID || (all_result && SwigType_type(all_result) == T_VOID)) { end = NewString(""); Printv(end, "return", NULL); - if (all_result == NULL || SwigType_type(all_result) != T_VOID) { + if (!all_result || SwigType_type(all_result) != T_VOID) { Printv(end, " 0", NULL); } } if (num_required == num_arguments) { Printv(f_go_wrappers, "\t\t", start, ")\n", NULL); - if (end != NULL) { + if (end) { Printv(f_go_wrappers, "\t\t", end, "\n", NULL); } } else { @@ -3985,7 +3983,7 @@ private: nc = true; } Printv(f_go_wrappers, ")\n", NULL); - if (end != NULL) { + if (end) { Printv(f_go_wrappers, "\t\t\t", end, "\n", NULL); } } @@ -4058,7 +4056,7 @@ private: String *removeClassname(String *name) { String *copy = Copy(name); - if (class_name != NULL) { + if (class_name) { char *p = Char(name); if (Strncmp(name, class_name, Len(class_name)) == 0 && p[Len(class_name)] == '_') { Replace(copy, class_name, "", DOH_REPLACE_FIRST); @@ -4080,7 +4078,7 @@ private: String *buildGoName(String *name, bool is_static, bool is_friend) { String *nw = NewString(""); - if (is_static && !is_friend && class_name != NULL) { + if (is_static && !is_friend && class_name) { String *c1 = exportedName(class_name); Append(nw, c1); Delete(c1); @@ -4109,7 +4107,7 @@ private: Append(s1, name); String *s2 = Swig_name_mangle(s1); Delete(s1); - if (overname != NULL) { + if (overname) { Append(s2, overname); } return s2; @@ -4126,13 +4124,13 @@ private: bool checkNameConflict(String* name, Node* n, const_String_or_char_ptr scope) { Node *lk = symbolLookup(name, scope); - if (lk != NULL) { + if (lk) { String *n1 = Getattr(n, "sym:name"); - if (n1 == NULL) { + if (!n1) { n1 = Getattr(n, "name"); } String *n2 = Getattr(lk, "sym:name"); - if (n2 == NULL) { + if (!n2) { n2 = Getattr(lk, "name"); } Swig_warning(WARN_GO_NAME_CONFLICT, input_file, line_number, @@ -4155,7 +4153,7 @@ private: bool checkIgnoredParameters(Node *n, String *go_name) { ParmList *parms = Getattr(n, "parms"); - if (parms != NULL) { + if (parms) { Wrapper *dummy = NewWrapper(); emit_attach_parmmaps(parms, dummy); int parm_count = emit_num_arguments(parms); @@ -4197,13 +4195,13 @@ private: bool ret = true; bool is_conflict = false; Node *e = Language::enumLookup(t); - if (e != NULL) { + if (e) { if (GetFlag(e, "go:conflict")) { is_conflict = true; } } else if (SwigType_issimple(t)) { Node *cn = classLookup(t); - if (cn != NULL) { + if (cn) { if (GetFlag(cn, "go:conflict")) { is_conflict = true; } @@ -4264,17 +4262,17 @@ private: * ---------------------------------------------------------------------- */ String *goTypeWithInfo(Node *n, SwigType *type, bool *p_is_interface) { - if (p_is_interface != NULL) { + if (p_is_interface) { *p_is_interface = false; } String *ret; - if (n != NULL && Cmp(type, Getattr(n, "type")) == 0) { + if (n && Cmp(type, Getattr(n, "type")) == 0) { ret = NULL; if (Strcmp(Getattr(n, "nodeType"), "parm") == 0) { ret = Getattr(n, "tmap:gotype"); } - if (ret == NULL) { + if (!ret) { ret = Swig_typemap_lookup("gotype", n, "", NULL); } } else { @@ -4283,18 +4281,18 @@ private: Delete(p); } - if (Strstr(ret, "$gotypename") != NULL) { + if (Strstr(ret, "$gotypename") != 0) { ret = NULL; } - if (ret != NULL) { + if (ret) { return Copy(ret); } SwigType *t = SwigType_typedef_resolve_all(type); Node *e = Language::enumLookup(t); - if (e != NULL) { + if (e) { ret = goEnumName(e); } else if (Strcmp(t, "enum ") == 0) { ret = NewString("int"); @@ -4304,15 +4302,15 @@ private: ret = NewString("_swig_memberptr"); } else if (SwigType_issimple(t)) { Node *cn = classLookup(t); - if (cn != NULL) { + if (cn) { ret = Getattr(cn, "sym:name"); - if (ret == NULL) { + if (!ret) { ret = Getattr(cn, "name"); } ret = exportedName(ret); Node *cnmod = Getattr(cn, "module"); - if (cnmod == NULL || Strcmp(Getattr(cnmod, "name"), package) == 0) { + if (!cnmod || Strcmp(Getattr(cnmod, "name"), package) == 0) { Setattr(undefined_types, t, t); } else { String *nw = NewString(""); @@ -4325,7 +4323,7 @@ private: ret = exportedName(t); Setattr(undefined_types, t, t); } - if (p_is_interface != NULL) { + if (p_is_interface) { *p_is_interface = true; } } else if (SwigType_ispointer(t) || SwigType_isarray(t)) { @@ -4369,7 +4367,7 @@ private: if (is_interface) { if (!is_pointer_to_pointer) { ret = base; - if (p_is_interface != NULL) { + if (p_is_interface) { *p_is_interface = true; } } else { @@ -4415,7 +4413,7 @@ private: Delete(t); - if (ret == NULL) { + if (!ret) { Swig_warning(WARN_LANG_NATIVE_UNIMPL, input_file, line_number, "No Go typemap defined for %s\n", SwigType_str(type, 0)); ret = NewString("uintptr"); } @@ -4478,7 +4476,7 @@ private: Node *cn = classLookup(ty); String *ex; String *ret; - if (cn == NULL) { + if (!cn) { if (add_to_hash) { Setattr(undefined_types, ty, ty); } @@ -4487,12 +4485,12 @@ private: Append(ret, ex); } else { String *cname = Getattr(cn, "sym:name"); - if (cname == NULL) { + if (!cname) { cname = Getattr(cn, "name"); } ex = exportedName(cname); Node *cnmod = Getattr(cn, "module"); - if (cnmod == NULL || Strcmp(Getattr(cnmod, "name"), package) == 0) { + if (!cnmod || Strcmp(Getattr(cnmod, "name"), package) == 0) { if (add_to_hash) { Setattr(undefined_types, ty, ty); } @@ -4625,7 +4623,7 @@ private: Parm *p = NewParmWithoutFileLineInfo(type, "test"); SwigType *tm = Swig_typemap_lookup("gotype", p, "", NULL); Delete(p); - if (tm != NULL && Strstr(tm, "$gotypename") == NULL) { + if (tm && Strstr(tm, "$gotypename") == 0) { Delete(tm); return true; } @@ -4641,7 +4639,7 @@ private: String *goEnumName(Node *n) { String *ret = Getattr(n, "go:enumname"); - if (ret != NULL) { + if (ret) { return Copy(ret); } @@ -4650,7 +4648,7 @@ private: } String *type = Getattr(n, "enumtype"); - assert(type != NULL); + assert(type); char *p = Char(type); int len = Len(type); String *s = NewString(""); @@ -4682,7 +4680,7 @@ private: * ---------------------------------------------------------------------- */ Parm *getParm(Parm *p) { - while (p != NULL && checkAttribute(p, "tmap:in:numinputs", "0")) { + while (p && checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); } return p; @@ -4695,9 +4693,9 @@ private: * ---------------------------------------------------------------------- */ Parm *nextParm(Parm *p) { - if (p == NULL) { + if (!p) { return NULL; - } else if (Getattr(p, "tmap:in") != NULL) { + } else if (Getattr(p, "tmap:in")) { return Getattr(p, "tmap:in:next"); } else { return nextSibling(p); @@ -4713,8 +4711,7 @@ private: bool isStatic(Node *n) { String *storage = Getattr(n, "storage"); - return (storage != NULL && (Strcmp(storage, "static") == 0 || Strcmp(storage, "friend") == 0) - && (!SmartPointer || Getattr(n, "allocate:smartpointeraccess") == NULL)); + return (storage && (Strcmp(storage, "static") == 0 || Strcmp(storage, "friend") == 0) && (!SmartPointer || !Getattr(n, "allocate:smartpointeraccess"))); } /* ---------------------------------------------------------------------- @@ -4725,7 +4722,7 @@ private: bool isFriend(Node *n) { String *storage = Getattr(n, "storage"); - return storage != NULL && Strcmp(storage, "friend") == 0; + return storage && Strcmp(storage, "friend") == 0; } }; /* class GO */ diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 029978ede..fc0418496 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -114,7 +114,7 @@ static String *memberfunction_name = 0; extern "C" { static int has_classname(Node *class_node) { - return Getattr(class_node, "guile:goopsclassname") != NULL; + return Getattr(class_node, "guile:goopsclassname") ? 1 : 0; } } @@ -254,7 +254,7 @@ public: } // set default value for primsuffix - if (primsuffix == NULL) + if (!primsuffix) primsuffix = NewString("primitive"); //goops support can only be enabled if passive or module linkage is used @@ -628,7 +628,7 @@ public: if (maybe_delimiter && Len(output) > 0 && Len(tm) > 0) { Printv(output, maybe_delimiter, NIL); } - const String *pn = (name == NULL) ? (const String *) Getattr(p, "name") : name; + const String *pn = !name ? (const String *) Getattr(p, "name") : name; String *pt = Getattr(p, "type"); Replaceall(tm, "$name", pn); // legacy for $parmname Replaceall(tm, "$type", SwigType_str(pt, 0)); @@ -781,7 +781,7 @@ public: if (strcmp("void", Char(pt)) != 0) { Node *class_node = Swig_symbol_clookup_check(pb, Getattr(n, "sym:symtab"), has_classname); - String *goopsclassname = (class_node == NULL) ? NULL : Getattr(class_node, "guile:goopsclassname"); + String *goopsclassname = !class_node ? NULL : Getattr(class_node, "guile:goopsclassname"); /* do input conversion */ if (goopsclassname) { Printv(method_signature, " (", argname, " ", goopsclassname, ")", NIL); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 83103180c..f5055ae4b 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2996,7 +2996,7 @@ void Language::dumpSymbols() { Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) { Hash *symbols = Getattr(symtabs, scope ? scope : ""); - if (symbols == NULL) { + if (!symbols) { return NULL; } return Getattr(symbols, s); diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index 602b43d4f..edd6690ce 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -1324,7 +1324,7 @@ MODULA3(): Parm *p; attachParameterNames(n, "tmap:name", "c:wrapname", "m3arg%d"); bool gencomma = false; - for (p = skipIgnored(l, "in"); p != NULL; p = skipIgnored(p, "in")) { + for (p = skipIgnored(l, "in"); p; p = skipIgnored(p, "in")) { String *arg = Getattr(p, "c:wrapname"); { @@ -1545,7 +1545,7 @@ MODULA3(): Parm *p; writeArgState state; attachParameterNames(n, "tmap:rawinname", "modula3:rawname", "arg%d"); - for (p = skipIgnored(l, "m3rawintype"); p != NULL; p = skipIgnored(p, "m3rawintype")) { + for (p = skipIgnored(l, "m3rawintype"); p; p = skipIgnored(p, "m3rawintype")) { /* Get argument passing mode, should be one of VALUE, VAR, READONLY */ String *mode = Getattr(p, "tmap:m3rawinmode"); @@ -1928,7 +1928,7 @@ MODULA3(): } else if (Strcmp(code, "unsafe") == 0) { unsafe_module = true; } else if (Strcmp(code, "library") == 0) { - if (targetlibrary != NULL) { + if (targetlibrary) { Delete(targetlibrary); } targetlibrary = Copy(strvalue); diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 4c266a7ab..82e3f846a 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1599,7 +1599,7 @@ public: tm = Getattr(n, "feature:director:except"); } if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { - Printf(w->code, "if (result == NULL) {\n"); + Printf(w->code, "if (!result) {\n"); Printf(w->code, " CAML_VALUE error = *caml_named_value(\"director_except\");\n"); Replaceall(tm, "$error", "error"); Printv(w->code, Str(tm), "\n", NIL); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 6c89794ec..ad425e3c8 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -1244,7 +1244,7 @@ public: idx = 0; p = l; int use_parse = 0; - while (p != NULL) { + while (p) { if (checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); continue; diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index f6ea029fe..01e557b1a 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -308,7 +308,7 @@ public: if (no_pmfile) { f_pm = NewString(0); } else { - if (pmfile == NULL) { + if (!pmfile) { char *m = Char(module) + Len(module); while (m != Char(module)) { if (*m == ':') { diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index e82c5041d..3a725ee1a 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1206,7 +1206,7 @@ public: } if (!pname_cstr) { // Unnamed parameter, e.g. int foo(int); - } else if (pname == NULL) { + } else if (!pname) { pname = NewString(pname_cstr); } else { size_t len = strlen(pname_cstr); @@ -1290,7 +1290,7 @@ public: if (errno || *p) { Clear(value); Append(value, "?"); - } else if (strchr(Char(value), '.') == NULL) { + } else if (strchr(Char(value), '.') == 0) { // Ensure value is a double constant, not an integer one. Append(value, ".0"); double val2 = strtod(Char(value), &p); @@ -2496,7 +2496,7 @@ done: idx = 0; p = l; int use_parse = 0; - while (p != NULL) { + while (p) { if (checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); continue; diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 42a6b234f..fed5205e1 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1073,7 +1073,7 @@ public: bool have_docstring(Node *n) { String *str = Getattr(n, "feature:docstring"); - return (str != NULL && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); + return (str && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); } /* ------------------------------------------------------------ @@ -1085,7 +1085,7 @@ public: String *docstring(Node *n, autodoc_t ad_type, const String *indent, bool use_triple = true) { String *str = Getattr(n, "feature:docstring"); - bool have_ds = (str != NULL && Len(str) > 0); + bool have_ds = (str && Len(str) > 0); bool have_auto = (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); const char *triple_double = use_triple ? "\"\"\"" : ""; String *autodoc = NULL; @@ -1101,7 +1101,7 @@ public: if (have_auto) { autodoc = make_autodoc(n, ad_type); - have_auto = (autodoc != NULL && Len(autodoc) > 0); + have_auto = (autodoc && Len(autodoc) > 0); } // If there is more than one line then make docstrings like this: // @@ -1116,14 +1116,14 @@ public: doc = NewString(""); Printv(doc, triple_double, "\n", pythoncode(autodoc, indent), "\n", pythoncode(str, indent), indent, triple_double, NIL); } else if (!have_auto && have_ds) { // only docstring - if (Strchr(str, '\n') == NULL) { + if (Strchr(str, '\n') == 0) { doc = NewStringf("%s%s%s", triple_double, str, triple_double); } else { doc = NewString(""); Printv(doc, triple_double, "\n", pythoncode(str, indent), indent, triple_double, NIL); } } else if (have_auto && !have_ds) { // only autodoc - if (Strchr(autodoc, '\n') == NULL) { + if (Strchr(autodoc, '\n') == 0) { doc = NewStringf("%s%s%s", triple_double, autodoc, triple_double); } else { doc = NewString(""); @@ -1361,7 +1361,7 @@ public: { // Only do the autodoc if there isn't a docstring for the class String *str = Getattr(n, "feature:docstring"); - if (str == NULL || Len(str) == 0) { + if (!str || Len(str) == 0) { if (CPlusPlus) { Printf(doc, "Proxy of C++ %s class", real_classname); } else { @@ -1557,7 +1557,7 @@ public: bool have_pythonprepend(Node *n) { String *str = Getattr(n, "feature:pythonprepend"); - return (str != NULL && Len(str) > 0); + return (str && Len(str) > 0); } /* ------------------------------------------------------------ @@ -1584,7 +1584,7 @@ public: String *str = Getattr(n, "feature:pythonappend"); if (!str) str = Getattr(n, "feature:addtofunc"); - return (str != NULL && Len(str) > 0); + return (str && Len(str) > 0); } /* ------------------------------------------------------------ @@ -2741,7 +2741,7 @@ public: Printf(f_directors_h, " if (!method) {\n"); Printf(f_directors_h, " swig::SwigVar_PyObject name = SWIG_Python_str_FromChar(method_name);\n"); Printf(f_directors_h, " method = PyObject_GetAttr(swig_get_self(), name);\n"); - Printf(f_directors_h, " if (method == NULL) {\n"); + Printf(f_directors_h, " if (!method) {\n"); Printf(f_directors_h, " std::string msg = \"Method in class %s doesn't exist, undefined \";\n", classname); Printf(f_directors_h, " msg += method_name;\n"); Printf(f_directors_h, " Swig::DirectorMethodException::raise(msg.c_str());\n"); @@ -2904,7 +2904,7 @@ public: Printf(f_shadow, ":\n"); if (have_docstring(n)) { String *str = docstring(n, AUTODOC_CLASS, tab4); - if (str != NULL && Len(str)) + if (str && Len(str)) Printv(f_shadow, tab4, str, "\n", NIL); } if (!modern) { @@ -3723,7 +3723,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { idx = 0; p = l; int use_parse = 0; - while (p != NULL) { + while (p) { if (checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); continue; @@ -3910,13 +3910,13 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { if (tm) tm = Copy(tm); } - Append(w->code, "if (result == NULL) {\n"); + Append(w->code, "if (!result) {\n"); Append(w->code, " PyObject *error = PyErr_Occurred();\n"); if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { Replaceall(tm, "$error", "error"); Printv(w->code, Str(tm), "\n", NIL); } else { - Append(w->code, " if (error != NULL) {\n"); + Append(w->code, " if (error) {\n"); Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname); Append(w->code, " }\n"); } diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 8f5503743..749797c78 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -2514,7 +2514,7 @@ int R::membervariableHandler(Node *n) { int status(Language::membervariableHandler(n)); - if(opaqueClassDeclaration == NULL && debugMode) + if(!opaqueClassDeclaration && debugMode) Printf(stderr, " %s %s\n", Getattr(n, "name"), Getattr(n, "type")); processing_member_access_function = 0; diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 8fc41813f..bcdfd69d3 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -231,7 +231,7 @@ private: bool have_docstring(Node *n) { String *str = Getattr(n, "feature:docstring"); - return (str != NULL && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); + return (str && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); } /* ------------------------------------------------------------ @@ -244,7 +244,7 @@ private: String *docstring(Node *n, autodoc_t ad_type) { String *str = Getattr(n, "feature:docstring"); - bool have_ds = (str != NULL && Len(str) > 0); + bool have_ds = (str && Len(str) > 0); bool have_auto = (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); String *autodoc = NULL; String *doc = NULL; @@ -259,7 +259,7 @@ private: if (have_auto) { autodoc = make_autodoc(n, ad_type); - have_auto = (autodoc != NULL && Len(autodoc) > 0); + have_auto = (autodoc && Len(autodoc) > 0); } // If there is more than one line then make docstrings like this: // @@ -272,14 +272,14 @@ private: doc = NewString(""); Printv(doc, "\n", autodoc, "\n", str, NIL); } else if (!have_auto && have_ds) { // only docstring - if (Strchr(str, '\n') == NULL) { + if (Strchr(str, '\n') == 0) { doc = NewString(str); } else { doc = NewString(""); Printv(doc, str, NIL); } } else if (have_auto && !have_ds) { // only autodoc - if (Strchr(autodoc, '\n') == NULL) { + if (Strchr(autodoc, '\n') == 0) { doc = NewStringf("%s", autodoc); } else { doc = NewString(""); @@ -618,7 +618,7 @@ private: { // Only do the autodoc if there isn't a docstring for the class String *str = Getattr(n, "feature:docstring"); - if (counter == 0 && (str == NULL || Len(str) == 0)) { + if (counter == 0 && (str == 0 || Len(str) == 0)) { if (CPlusPlus) { Printf(doc, " Proxy of C++ %s class", full_name); } else { diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 2ba7827a1..f0a9155eb 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1092,7 +1092,7 @@ String *Swig_string_strip(String *s) { } else { const char *cs = Char(s); const char *ce = Strchr(cs, ']'); - if (*cs != '[' || ce == NULL) { + if (*cs != '[' || !ce) { ns = NewString(s); } else { String *fmt = NewStringf("%%.%ds", ce-cs-1); From 49fb2f8550d569d25153cad1eacc825537445289 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 17 Jun 2010 23:54:21 +0000 Subject: [PATCH 187/203] Missing changes for rev 12123 to fix 'make partialcheck' for go git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12138 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 5960d79fb..582c75f29 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1171,10 +1171,10 @@ go: $(SRCS) $(SWIG) -go $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) $(CC) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) - $(GO) -I . $(GOCOMPILEARG) $(GOSRCS) + $(COMPILETOOL) $(GO) -I . $(GOCOMPILEARG) $(GOSRCS) if ! $(GOGCC) ; then \ - $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ - gopack grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + $(COMPILETOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ + $(COMPILETOOL) gopack grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ fi # ---------------------------------------------------------------- @@ -1185,11 +1185,11 @@ go_cpp: $(SRCS) $(SWIG) -go -c++ $(GOSWIGARG) $(SWIGOPT) $(INTERFACEPATH) $(CXX) -g -c $(CCSHARED) $(CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) - $(GO) -I . $(GOCOMPILEARG) $(GOSRCS) + $(COMPILETOOL) $(GO) -I . $(GOCOMPILEARG) $(GOSRCS) if ! $(GOGCC) ; then \ - $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ - gopack grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ - else true; fi + $(COMPILETOOL) $(GOC) -I $${GOROOT}/pkg/$${GOOS}_$${GOARCH} $(GOCSRCS) && \ + $(COMPILETOOL) gopack grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \ + fi # ----------------------------------------------------------------- # Running a Go example @@ -1198,11 +1198,11 @@ go_cpp: $(SRCS) go_run: runme.go $(GO) $(GOCOMPILEARG) runme.go if $(GOGCC) ; then \ - $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(LIBPREFIX)$(TARGET)$(SO); \ + $(COMPILETOOL) $(GO) -o runme runme.@OBJEXT@ $(GOGCCOBJS) $(LIBPREFIX)$(TARGET)$(SO); \ else \ - $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ + $(COMPILETOOL) $(GOLD) -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o runme runme.$(GOOBJEXT); \ fi - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH ./runme + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme # ----------------------------------------------------------------- # Cleaning the Go examples From 6bd53139fbc2ee82c5578891a01d22e19f305936 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 20 Jun 2010 15:27:34 +0000 Subject: [PATCH 188/203] Fix typo in comment git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12139 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/swigrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index a8e9ad74c..e5afb62c4 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -51,7 +51,7 @@ /* Flags/methods for returning states. - The SWIG conversion methods, as ConvertPtr, return and integer + The SWIG conversion methods, as ConvertPtr, return an integer that tells if the conversion was successful or not. And if not, an error code can be returned (see swigerrors.swg for the codes). From c4768e54cb27e01d1cc190e6849932503c59df81 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 21 Jun 2010 03:37:08 +0000 Subject: [PATCH 189/203] Fix grammatical error introduced by previous fix. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12140 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- LICENSE-UNIVERSITIES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE-UNIVERSITIES b/LICENSE-UNIVERSITIES index 40042a84a..44fcaa13f 100644 --- a/LICENSE-UNIVERSITIES +++ b/LICENSE-UNIVERSITIES @@ -74,7 +74,7 @@ Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that (1) The above copyright notice and the following paragraph -appears in all copies of the source code and (2) redistributions +appear in all copies of the source code and (2) redistributions including binaries reproduces these notices in the supporting documentation. Substantial modifications to this software may be copyrighted by their authors and need not follow the licensing terms From 9ed2d0165c4bc858ee84f39be1bf0158262e9933 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 21 Jun 2010 03:44:29 +0000 Subject: [PATCH 190/203] Fix comment typo. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12141 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/cwrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 539ae6e18..b8812563e 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -830,7 +830,7 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas These two lines just transfer the ownership of the 'this' pointer from the input to the output wrapping object. - This happens in python, but may also happens in other target + This happens in python, but may also happen in other target languages. */ if (GetFlag(n, "feature:self:disown")) { From 0bfeb75be2cd5a2080fbf365edfc9f22679b5f16 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 21 Jun 2010 06:18:54 +0000 Subject: [PATCH 191/203] update example version numbers and clarification of inputs git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12142 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/mkwindows.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tools/mkwindows.sh b/Tools/mkwindows.sh index fb2547e14..869fce01a 100755 --- a/Tools/mkwindows.sh +++ b/Tools/mkwindows.sh @@ -1,6 +1,7 @@ #!/bin/sh -# Build Windows distribution (swigwin-1.3.x.zip) -- requires running in either: +# Build Windows distribution (swigwin-2.0.x.zip) from source tarball (swig-2.0.x.tar.gz) +# Requires running in either: # - MinGW environment # - Linux using MinGW cross compiler # - Cygwin using MinGW compiler @@ -21,8 +22,8 @@ if test x$1 != x; then fi else echo "Usage: mkwindows.sh version [zip]" - echo " Build Windows distribution. Works on Cygwin, MinGW or Linux" - echo " version should be 1.3.x" + echo " Build SWIG Windows distribution from source tarball. Works on Cygwin, MinGW or Linux" + echo " version should be 2.0.x" echo " zip is full path to zip program - default is /c/cygwin/bin/zip on MinGW, zip on Linux and Cygwin" exit 1 fi From 4dd5ce25ee5f0f9ce88cc3bc759ff43f4267083f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 22 Jun 2010 11:52:44 +0000 Subject: [PATCH 192/203] Fix typo. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12143 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Customization.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index b43075991..7f164ac57 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -83,7 +83,7 @@ How the exception is handled depends on the target language, for example, Python

      When defined, the code enclosed in braces is inserted directly into the low-level wrapper functions. The special variable $action is one of a few -%exception special variable +%exception special variables supported and gets replaced with the actual operation to be performed (a function call, method invocation, attribute access, etc.). An exception handler remains in effect until it is explicitly deleted. This is done by using either %exception From 3f1b4e40f35a6da99727b82c76f368cad627cb56 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 22 Jun 2010 13:02:08 +0000 Subject: [PATCH 193/203] Fix a typo in the documentation (inlne => inline) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12144 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Arguments.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Arguments.html b/Doc/Manual/Arguments.html index 8ab51faf6..1ae9a6d2f 100644 --- a/Doc/Manual/Arguments.html +++ b/Doc/Manual/Arguments.html @@ -81,7 +81,7 @@ One way to deal with this is to use the %include "typemaps.i" %apply double *OUTPUT { double *result }; -%inlne %{ +%inline %{ extern void add(double a, double b, double *result); %} From 0d7863c8104ecb5d2b452126f3bc819021fae652 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 24 Jun 2010 14:16:16 +0000 Subject: [PATCH 194/203] Wrapping pointer to member function types is likely to be rare, so use %fragment to only pull in the required machinery if it is going to be used. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12145 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/globalvar.i | 2 +- Lib/php/php.swg | 2 +- Lib/php/phpinit.swg | 14 +++++++++++++- Lib/php/phprun.swg | 9 --------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index 17f4995a6..9a8e84d6e 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -223,7 +223,7 @@ $1 = ($1_ltype)_temp; } -%typemap(varin) SWIGTYPE (CLASS::*) +%typemap(varin, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) { zval **z_var; diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 2471a0992..4ce55b4eb 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -362,7 +362,7 @@ SWIG_SetPointerZval(return_value, (void *)&$1, $1_descriptor, $owner); } -%typemap(in) SWIGTYPE (CLASS::*) +%typemap(in, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) { void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, le_member_ptr); memcpy(&$1, p, sizeof($1)); diff --git a/Lib/php/phpinit.swg b/Lib/php/phpinit.swg index 5d8278ba4..777d7723a 100644 --- a/Lib/php/phpinit.swg +++ b/Lib/php/phpinit.swg @@ -8,6 +8,18 @@ %init %{ SWIG_php_minit { SWIG_InitializeModule(0); - le_member_ptr = zend_register_list_destructors_ex(member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number); %} +%fragment("swig_php_init_member_ptr2", "header") { +#define SWIG_MEMBER_PTR ((char*)"CLASS::*") + +static void member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { + efree(rsrc->ptr); +} + +static int le_member_ptr; +} + +%fragment("swig_php_init_member_ptr", "init", fragment="swig_php_init_member_ptr2") { + le_member_ptr = zend_register_list_destructors_ex(member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number); +} diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a7573f35d..a4417fe68 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -259,12 +259,3 @@ static void SWIG_Php_SetModule(swig_module_info *pointer) { TSRMLS_FETCH(); REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, 0); } - -#define SWIG_MEMBER_PTR ((char*)"CLASS::*") - -static void member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { - efree(rsrc->ptr); -} - -static int le_member_ptr; - From ae40eff993caca94cbb92b596350996365969202 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 24 Jun 2010 14:44:06 +0000 Subject: [PATCH 195/203] The default visibility for methods is public, so don't specify that explicitly to keep the wrapper size down. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12146 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 3a725ee1a..47afa7d1d 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1575,14 +1575,21 @@ public: } if (Getattr(n, "access") && haspublicbase) { Delete(acc); - acc = NewString("public"); + acc = NewStringEmpty(); // implicitly public Swig_warning(WARN_PHP_PUBLIC_BASE, input_file, line_number, Char(warnmsg)); Delete(warnmsg); } } - if (Cmp(acc, "") != 0) { + + if (Cmp(acc, "public") == 0) { + // The default visibility for methods is public, so don't specify + // that explicitly to keep the wrapper size down. + Delete(acc); + acc = NewStringEmpty(); + } else if (Cmp(acc, "") != 0) { Append(acc, " "); } + if (constructor) { const char * arg0; if (max_num_of_arguments > 0) { From b946430c8aee3de17dc425433520becd2f665cf0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jun 2010 19:33:21 +0000 Subject: [PATCH 196/203] Remove potential symbol clash with wrapped code (php) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12147 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/globalvar.i | 6 +++--- Lib/php/php.swg | 4 ++-- Lib/php/phpinit.swg | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index 9a8e84d6e..d0b4ffe0a 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -108,7 +108,7 @@ memcpy(p, &$1, sizeof($1)); zval * resource; MAKE_STD_ZVAL(resource); - ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr); + ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr); zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL); } @@ -228,7 +228,7 @@ zval **z_var; zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var); - void * p = (void*)zend_fetch_resource(*z_var TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, le_member_ptr); + void * p = (void*)zend_fetch_resource(*z_var TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, swig_member_ptr); memcpy(&$1, p, sizeof($1)); } @@ -350,6 +350,6 @@ deliberate error cos this code looks bogus to me memcpy(p, &$1, sizeof($1)); zval * resource; MAKE_STD_ZVAL(resource); - ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr); + ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr); zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL); } diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 4ce55b4eb..1ccf58246 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -357,14 +357,14 @@ memcpy(p, &$1, sizeof($1)); zval * resource; MAKE_STD_ZVAL(resource); - ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr); + ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr); SWIG_SetPointerZval(return_value, (void *)&$1, $1_descriptor, $owner); } %typemap(in, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) { - void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, le_member_ptr); + void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, swig_member_ptr); memcpy(&$1, p, sizeof($1)); } diff --git a/Lib/php/phpinit.swg b/Lib/php/phpinit.swg index 777d7723a..d4985c28d 100644 --- a/Lib/php/phpinit.swg +++ b/Lib/php/phpinit.swg @@ -17,9 +17,9 @@ static void member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { efree(rsrc->ptr); } -static int le_member_ptr; +static int swig_member_ptr = 0; } %fragment("swig_php_init_member_ptr", "init", fragment="swig_php_init_member_ptr2") { - le_member_ptr = zend_register_list_destructors_ex(member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number); + swig_member_ptr = zend_register_list_destructors_ex(member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number); } From b36ae8aaf4acc021ff50aa088d1f3da0b163d00f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 25 Jun 2010 01:48:33 +0000 Subject: [PATCH 197/203] Attach the swig_php_init_member_ptr fragment to all the typemaps which need it. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12148 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/globalvar.i | 4 ++-- Lib/php/php.swg | 2 +- Lib/php/phpinit.swg | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index d0b4ffe0a..45fb0223b 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -102,7 +102,7 @@ zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL); } -%typemap(varinit) SWIGTYPE (CLASS::*) +%typemap(varinit, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) { void * p = emalloc(sizeof($1)); memcpy(p, &$1, sizeof($1)); @@ -344,7 +344,7 @@ deliberate error cos this code looks bogus to me SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0); } -%typemap(varout) SWIGTYPE (CLASS::*) +%typemap(varout, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) { void * p = emalloc(sizeof($1)); memcpy(p, &$1, sizeof($1)); diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 1ccf58246..f4cc8d2b2 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -351,7 +351,7 @@ SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner); %} -%typemap(out) SWIGTYPE (CLASS::*) +%typemap(out, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) { void * p = emalloc(sizeof($1)); memcpy(p, &$1, sizeof($1)); diff --git a/Lib/php/phpinit.swg b/Lib/php/phpinit.swg index d4985c28d..6e5cc29d2 100644 --- a/Lib/php/phpinit.swg +++ b/Lib/php/phpinit.swg @@ -13,7 +13,7 @@ %fragment("swig_php_init_member_ptr2", "header") { #define SWIG_MEMBER_PTR ((char*)"CLASS::*") -static void member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { +static void swig_member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { efree(rsrc->ptr); } @@ -21,5 +21,5 @@ static int swig_member_ptr = 0; } %fragment("swig_php_init_member_ptr", "init", fragment="swig_php_init_member_ptr2") { - swig_member_ptr = zend_register_list_destructors_ex(member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number); + swig_member_ptr = zend_register_list_destructors_ex(swig_member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number); } From d0d40db326f4e8412567e1404284033a41974487 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 25 Jun 2010 02:41:27 +0000 Subject: [PATCH 198/203] Use SWIG_PTR rather than literal "_cPtr". git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12149 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 47afa7d1d..365fcd370 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1702,7 +1702,7 @@ public: Printf(output, "\t\t\treturn new $c($r);\n"); } else { Printf(output, "\t\t\t$c = new stdClass();\n"); - Printf(output, "\t\t\t$c->_cPtr = $r;\n"); + Printf(output, "\t\t\t$c->"SWIG_PTR" = $r;\n"); Printf(output, "\t\t\treturn $c;\n"); } Printf(output, "\t\t}\n\t\treturn $r;\n"); From cca92f4188b7ae98ed72b4952ee84ae67b003b34 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 7 Jul 2010 18:19:01 +0000 Subject: [PATCH 199/203] Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes the 'unref' feature when used on classes with non-public destructors. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12155 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 + .../csharp/li_boost_shared_ptr_bits_runme.cs | 3 + .../java/li_boost_shared_ptr_bits_runme.java | 3 + .../test-suite/li_boost_shared_ptr_bits.i | 78 +++++++++++++++++++ .../python/li_boost_shared_ptr_bits_runme.py | 3 + Source/Modules/lang.cxx | 2 +- 6 files changed, 92 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 00d1bec5b..510ec0dfe 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-07-08: wsfulton + Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes + the "unref" feature when used on classes with non-public destructors. + 2010-06-10: wsfulton [Lua] Fix SWIG_lua_isnilstring multiply defined when using multiple modules and wrapping strings. Patch from 'Number Cruncher'. diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs index 2b8c84e1b..b4ec47f02 100644 --- a/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs +++ b/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs @@ -13,5 +13,8 @@ public class runme int sum = li_boost_shared_ptr_bits.sum(v); if (sum != 66) throw new ApplicationException("sum is wrong"); + + HiddenDestructor hidden = HiddenDestructor.create(); + hidden.Dispose(); } } diff --git a/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java index ffa0c5e64..d1489edf4 100644 --- a/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java +++ b/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java @@ -20,5 +20,8 @@ public class li_boost_shared_ptr_bits_runme { int sum = li_boost_shared_ptr_bits.sum(v); if (sum != 66) throw new RuntimeException("sum is wrong"); + + HiddenDestructor hidden = HiddenDestructor.create(); + hidden.delete(); } } diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i index b43e1b137..7d6fa7b63 100644 --- a/Examples/test-suite/li_boost_shared_ptr_bits.i +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -48,3 +48,81 @@ int sum(std::vector< boost::shared_ptr > v) { %template(VectorIntHolder) std::vector< boost::shared_ptr >; + +///////////////////////////////////////////////// +// Test non public destructor - was leading to memory leaks as the destructor was not wrapped +// Bug 3024875 +///////////////////////////////////////////////// + +%shared_ptr(HiddenDestructor) + +%inline %{ +class HiddenDestructor; +typedef boost::shared_ptr< HiddenDestructor > FooPtr; + +class HiddenDestructor { +public: + static FooPtr create(); + virtual void doit(); + +protected: + HiddenDestructor(); + static void Foo_body( FooPtr self ); + virtual ~HiddenDestructor(); +private: + HiddenDestructor( const HiddenDestructor& ); + class Impl; + Impl* impl_; + + class FooDeleter { + public: + void operator()(HiddenDestructor* hidden) { + delete hidden; + } + }; +}; +%} + +%{ +#include +using namespace std; + +/* Impl would generally hold a weak_ptr to HiddenDestructor a.s.o, but this stripped down example should suffice */ +class HiddenDestructor::Impl { +public: + int mymember; +}; + +FooPtr HiddenDestructor::create() +{ + FooPtr hidden( new HiddenDestructor(), HiddenDestructor::FooDeleter() ); + Foo_body( hidden ); + return hidden; +} + +void HiddenDestructor::doit() +{ + // whatever +} + +HiddenDestructor::HiddenDestructor() +{ +// cout << "HiddenDestructor::HiddenDestructor()" << endl; + // always empty +} + +void HiddenDestructor::Foo_body( FooPtr self ) +{ + // init self as you would do in ctor + self->impl_ = new Impl(); +} + +HiddenDestructor::~HiddenDestructor() +{ +// cout << "HiddenDestructor::~HiddenDestructor()" << endl; + // destruct (e.g. delete Pimpl object) + delete impl_; +} +%} +//////////////////////////// + diff --git a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py index 9e5668e57..931317615 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py @@ -29,3 +29,6 @@ sum = sum(v) if sum != 66: raise "sum is wrong" +################################ +p = HiddenDestructor.create() + diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index f5055ae4b..e28fcbb89 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -2697,7 +2697,7 @@ int Language::destructorDeclaration(Node *n) { if (!CurrentClass) return SWIG_NOWRAP; - if (cplus_mode != PUBLIC) + if (cplus_mode != PUBLIC && !Getattr(CurrentClass, "feature:unref")) return SWIG_NOWRAP; if (ImportMode) return SWIG_NOWRAP; From 2d8b51684d74c206019d8d40ef0cbd9c33bd7cf8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Jul 2010 17:39:11 +0000 Subject: [PATCH 200/203] remove svn:executable property git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12156 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/python/iadd_runme.py | 0 Examples/test-suite/python/overload_complicated_runme.py | 0 Examples/test-suite/python/threads_exception_runme.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 Examples/test-suite/python/iadd_runme.py mode change 100755 => 100644 Examples/test-suite/python/overload_complicated_runme.py mode change 100755 => 100644 Examples/test-suite/python/threads_exception_runme.py diff --git a/Examples/test-suite/python/iadd_runme.py b/Examples/test-suite/python/iadd_runme.py old mode 100755 new mode 100644 diff --git a/Examples/test-suite/python/overload_complicated_runme.py b/Examples/test-suite/python/overload_complicated_runme.py old mode 100755 new mode 100644 diff --git a/Examples/test-suite/python/threads_exception_runme.py b/Examples/test-suite/python/threads_exception_runme.py old mode 100755 new mode 100644 From 568607c5ea1479084276da13bb867092741f31c8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Jul 2010 18:45:22 +0000 Subject: [PATCH 201/203] Fix wrapping of function pointers and member function pointers when the function returns by reference git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12157 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ Examples/test-suite/common.mk | 1 + Examples/test-suite/funcptr_cpp.i | 16 ++++++++++++ Examples/test-suite/member_pointer.i | 26 +++++++++++++++++++ .../test-suite/python/funcptr_cpp_runme.py | 9 +++++++ .../test-suite/python/member_pointer_runme.py | 3 +++ Source/Swig/stype.c | 12 ++++++--- 7 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 Examples/test-suite/funcptr_cpp.i create mode 100644 Examples/test-suite/python/funcptr_cpp_runme.py diff --git a/CHANGES.current b/CHANGES.current index 510ec0dfe..63af7206d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-07-16: wsfulton + Fix wrapping of function pointers and member function pointers when the function + returns by reference. + 2010-07-08: wsfulton Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes the "unref" feature when used on classes with non-public destructors. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5033f1957..1463ce63c 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -201,6 +201,7 @@ CPP_TEST_CASES += \ features \ fragments \ friends \ + funcptr_cpp \ fvirtual \ global_namespace \ global_ns_arg \ diff --git a/Examples/test-suite/funcptr_cpp.i b/Examples/test-suite/funcptr_cpp.i new file mode 100644 index 000000000..d59f970ee --- /dev/null +++ b/Examples/test-suite/funcptr_cpp.i @@ -0,0 +1,16 @@ +%module funcptr_cpp + +%inline %{ + +int addByValue(const int &a, int b) { return a+b; } +int * addByPointer(const int &a, int b) { static int val; val = a+b; return &val; } +int & addByReference(const int &a, int b) { static int val; val = a+b; return val; } + +int call1(int (*d)(const int &, int), int a, int b) { return d(a, b); } +int call2(int * (*d)(const int &, int), int a, int b) { return *d(a, b); } +int call3(int & (*d)(const int &, int), int a, int b) { return d(a, b); } +%} + +%constant int (*ADD_BY_VALUE)(const int &, int) = addByValue; +%constant int * (*ADD_BY_POINTER)(const int &, int) = addByPointer; +%constant int & (*ADD_BY_REFERENCE)(const int &, int) = addByReference; diff --git a/Examples/test-suite/member_pointer.i b/Examples/test-suite/member_pointer.i index f03528cd5..d9d5cbef5 100644 --- a/Examples/test-suite/member_pointer.i +++ b/Examples/test-suite/member_pointer.i @@ -99,3 +99,29 @@ double (Shape::*perimetervar)(void) = &Shape::perimeter; %constant double (Shape::*PERIMPT)(void) = &Shape::perimeter; %constant double (Shape::*NULLPT)(void) = 0; +/* +%inline %{ + struct Funktions { + void retByRef(int & (*d)(double)) {} + }; + void byRef(int & (Funktions::*d)(double)) {} +%} +*/ + +%inline %{ + +struct Funktions { + int addByValue(const int &a, int b) { return a+b; } + int * addByPointer(const int &a, int b) { static int val; val = a+b; return &val; } + int & addByReference(const int &a, int b) { static int val; val = a+b; return val; } +}; + +int call1(int (Funktions::*d)(const int &, int), int a, int b) { Funktions f; return (f.*d)(a, b); } +int call2(int * (Funktions::*d)(const int &, int), int a, int b) { Funktions f; return *(f.*d)(a, b); } +int call3(int & (Funktions::*d)(const int &, int), int a, int b) { Funktions f; return (f.*d)(a, b); } +%} + +%constant int (Funktions::*ADD_BY_VALUE)(const int &, int) = &Funktions::addByValue; +%constant int * (Funktions::*ADD_BY_POINTER)(const int &, int) = &Funktions::addByPointer; +%constant int & (Funktions::*ADD_BY_REFERENCE)(const int &, int) = &Funktions::addByReference; + diff --git a/Examples/test-suite/python/funcptr_cpp_runme.py b/Examples/test-suite/python/funcptr_cpp_runme.py new file mode 100644 index 000000000..ae8616e94 --- /dev/null +++ b/Examples/test-suite/python/funcptr_cpp_runme.py @@ -0,0 +1,9 @@ +from funcptr_cpp import * + +if call1(ADD_BY_VALUE, 10, 11) != 21: + raise RuntimeError +if call2(ADD_BY_POINTER, 12, 13) != 25: + raise RuntimeError +if call3(ADD_BY_REFERENCE, 14, 15) != 29: + raise RuntimeError + diff --git a/Examples/test-suite/python/member_pointer_runme.py b/Examples/test-suite/python/member_pointer_runme.py index 27e7a483d..3d68e916d 100644 --- a/Examples/test-suite/python/member_pointer_runme.py +++ b/Examples/test-suite/python/member_pointer_runme.py @@ -41,3 +41,6 @@ memberPtr = NULLPT check ("Square area ", 100.0, do_op(s,AREAPT)) check ("Square perim", 40.0, do_op(s,PERIMPT)) +check ("Add by value", 3, call1(ADD_BY_VALUE, 1, 2)) +check ("Add by pointer", 7, call2(ADD_BY_POINTER, 3, 4)) +check ("Add by reference", 11, call3(ADD_BY_REFERENCE, 5, 6)) diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index c984d639b..dd2aea688 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -735,6 +735,7 @@ String *SwigType_rcaststr(SwigType *s, const_String_or_char_ptr name) { int clear = 1; int firstarray = 1; int isreference = 0; + int isfunction = 0; int isarray = 0; result = NewStringEmpty(); @@ -835,6 +836,7 @@ String *SwigType_rcaststr(SwigType *s, const_String_or_char_ptr name) { } Append(result, ")"); Delete(parms); + isfunction = 1; } else { String *bs = SwigType_namestr(element); Insert(result, 0, " "); @@ -850,10 +852,12 @@ String *SwigType_rcaststr(SwigType *s, const_String_or_char_ptr name) { cast = NewStringf("(%s)", result); } if (name) { - if (isreference) { - if (isarray) - Clear(cast); - Append(cast, "*"); + if (!isfunction) { + if (isreference) { + if (isarray) + Clear(cast); + Append(cast, "*"); + } } Append(cast, name); } From 53ad9822f5483c1c52cc41a23cd128ef753a3b67 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 17 Jul 2010 14:48:13 +0000 Subject: [PATCH 202/203] Fix for languages that don't have %shared_ptr macro git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12158 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/li_boost_shared_ptr_bits.i | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i index 7d6fa7b63..610edb4b4 100644 --- a/Examples/test-suite/li_boost_shared_ptr_bits.i +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -54,8 +54,12 @@ int sum(std::vector< boost::shared_ptr > v) { // Bug 3024875 ///////////////////////////////////////////////// +#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) + %shared_ptr(HiddenDestructor) +#endif + %inline %{ class HiddenDestructor; typedef boost::shared_ptr< HiddenDestructor > FooPtr; From 7338f3993653f121e3fbd8158d625740a840b17b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 Jul 2010 00:06:40 +0000 Subject: [PATCH 203/203] Fix out of source builds for the test-suite which broke in 1.3.37 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12159 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 2 +- Examples/test-suite/csharp/Makefile.in | 1 - Examples/test-suite/java/Makefile.in | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 1463ce63c..c1952543f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -69,7 +69,7 @@ INCLUDES = -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE) LIBS = -L. LIBPREFIX = lib ACTION = check -INTERFACEDIR = ../ +INTERFACEDIR = $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/ # # Please keep test cases in alphabetical order. diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index afb29dfbf..5f50095a1 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -27,7 +27,6 @@ include $(srcdir)/../common.mk # Overridden variables here SWIGOPT += -namespace $*Namespace -INTERFACEDIR = ../../ CSHARPFLAGSSPECIAL = diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 3cb7c0c53..ba225f6e9 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -39,7 +39,6 @@ include $(srcdir)/../common.mk # Overridden variables here JAVA_PACKAGE = $* SWIGOPT += -package $(JAVA_PACKAGE) -INTERFACEDIR = ../../ # Custom tests - tests with additional commandline options nspace.%: JAVA_PACKAGE = $*Package